Making AST node inmmutable - WIP

This commit is contained in:
Michael Schimmel
2025-11-04 20:12:12 +01:00
parent 48ccb23060
commit d82a75aba6
6 changed files with 123 additions and 56 deletions
+43 -4
View File
@@ -109,6 +109,8 @@ type
function AsRecur: IRecurNode; virtual;
function AsNop: INopNode; virtual; // Added Nop
function AsBoundIdentifierNode: IBoundIdentifierNode; virtual;
property StaticType: IStaticType read FStaticType write SetStaticType;
property Kind: TAstNodeKind read GetKind;
end;
@@ -128,15 +130,24 @@ type
TIdentifierNode = class(TAstNode, IIdentifierNode)
private
FName: string;
FAddress: TResolvedAddress;
function GetName: string;
function GetKind: TAstNodeKind; override;
public
constructor Create(AName: string);
constructor Create(const AName: string);
function Accept(const Visitor: IAstVisitor): TDataValue; override;
function AsIdentifier: IIdentifierNode; override;
property Name: string read FName; // Name ist immutable
property Address: TResolvedAddress read FAddress write FAddress;
end;
TBoundIdentifierNode = class(TIdentifierNode, IBoundIdentifierNode)
private
FAddress: TResolvedAddress;
function GetAddress: TResolvedAddress;
function GetKind: TAstNodeKind; override;
public
constructor Create(const AName: string; const AAddress: TResolvedAddress);
function AsBoundIdentifierNode: IBoundIdentifierNode; override;
property Address: TResolvedAddress read GetAddress;
end;
TKeywordNode = class(TAstNode, IKeywordNode)
@@ -724,6 +735,11 @@ begin
raise ETypeException.Create('Node is not a BlockExpression');
end;
function TAstNode.AsBoundIdentifierNode: IBoundIdentifierNode;
begin
raise ETypeException.Create('Node is not a bound identifier');
end;
function TAstNode.AsConstant: IConstantNode;
begin
raise ETypeException.Create('Node is not a Constant');
@@ -865,7 +881,7 @@ end;
{ TIdentifierNode }
constructor TIdentifierNode.Create(AName: string);
constructor TIdentifierNode.Create(const AName: string);
begin
inherited Create;
FName := AName;
@@ -1629,4 +1645,27 @@ begin
Result := akSeriesLength;
end;
{ TBoundIdentifierNode }
constructor TBoundIdentifierNode.Create(const AName: string; const AAddress: TResolvedAddress);
begin
inherited Create(AName);
FAddress := AAddress;
end;
function TBoundIdentifierNode.AsBoundIdentifierNode: IBoundIdentifierNode;
begin
Result := Self;
end;
function TBoundIdentifierNode.GetAddress: TResolvedAddress;
begin
Result := FAddress;
end;
function TBoundIdentifierNode.GetKind: TAstNodeKind;
begin
Result := akBoundIdentifier;
end;
end.