AST testing

This commit is contained in:
Michael Schimmel
2025-11-23 00:24:43 +01:00
parent c5167b8550
commit a052dfb20f
23 changed files with 792 additions and 1260 deletions
+20 -34
View File
@@ -95,17 +95,13 @@ type
class function Block(const AExpressions: array of IAstNode; const AStaticType: IStaticType = nil): IBlockExpressionNode; static;
class function VarDecl(
const AIdentifier: IIdentifierNode;
const AIdentifier: IAstNode;
AInitializer: IAstNode = nil;
const AStaticType: IStaticType = nil;
const AIsBoxed: Boolean = False
): IVariableDeclarationNode; static;
class function Assign(
const AIdentifier: IIdentifierNode;
const AValue: IAstNode;
const AStaticType: IStaticType = nil
): IAssignmentNode; static;
class function Assign(const ATarget, AValue: IAstNode; const AStaticType: IStaticType = nil): IAssignmentNode; static;
class function AssignResult(const AValue: IAstNode): IAssignmentNode; static; deprecated;
class function Indexer(const ABase: IAstNode; const AIndex: IAstNode; const AStaticType: IStaticType = nil): IIndexerNode; static;
class function MemberAccess(
@@ -249,23 +245,17 @@ type
function AsFunctionCall: IFunctionCallNode; override;
end;
// ... (Other node definitions unchanged) ...
TVariableDeclarationNode = class(TAstTypedNode, IVariableDeclarationNode)
private
FIdentifier: IIdentifierNode;
FInitializer: IAstNode;
FTarget: IAstNode;
FIsBoxed: Boolean;
function GetIdentifier: IIdentifierNode;
function GetTarget: IAstNode;
function GetInitializer: IAstNode;
function GetIsBoxed: Boolean;
function GetKind: TAstNodeKind; override;
public
constructor Create(
const AIdentifier: IIdentifierNode;
AInitializer: IAstNode;
const AStaticType: IStaticType;
const AIsBoxed: Boolean
);
constructor Create(const ATarget: IAstNode; AInitializer: IAstNode; const AStaticType: IStaticType; const AIsBoxed: Boolean);
function Accept(const Visitor: IAstVisitor): TDataValue; override;
function AsVariableDeclaration: IVariableDeclarationNode; override;
end;
@@ -440,16 +430,16 @@ type
TAssignmentNode = class(TAstTypedNode, IAssignmentNode)
private
FIdentifier: IIdentifierNode;
FTarget: IAstNode;
FValue: IAstNode;
function GetIdentifier: IIdentifierNode;
function GetTarget: IAstNode;
function GetValue: IAstNode;
function GetKind: TAstNodeKind; override;
public
constructor Create(const AIdentifier: IIdentifierNode; const AValue: IAstNode; const AStaticType: IStaticType);
constructor Create(const ATarget: IAstNode; const AValue: IAstNode; const AStaticType: IStaticType);
function Accept(const Visitor: IAstVisitor): TDataValue; override;
function AsAssignment: IAssignmentNode; override;
property Identifier: IIdentifierNode read FIdentifier;
property Target: IAstNode read FTarget;
property Value: IAstNode read FValue;
end;
@@ -619,15 +609,11 @@ begin
);
end;
class function TAst.Assign(
const AIdentifier: IIdentifierNode;
const AValue: IAstNode;
const AStaticType: IStaticType = nil
): IAssignmentNode;
class function TAst.Assign(const ATarget, AValue: IAstNode; const AStaticType: IStaticType = nil): IAssignmentNode;
begin
Result :=
TAssignmentNode.Create(
AIdentifier,
ATarget,
AValue,
if AStaticType <> nil then AStaticType
else TTypes.Unknown
@@ -884,7 +870,7 @@ begin
end;
class function TAst.VarDecl(
const AIdentifier: IIdentifierNode;
const AIdentifier: IAstNode;
AInitializer: IAstNode = nil;
const AStaticType: IStaticType = nil;
const AIsBoxed: Boolean = False
@@ -1614,14 +1600,14 @@ end;
{ TVariableDeclarationNode }
constructor TVariableDeclarationNode.Create(
const AIdentifier: IIdentifierNode;
const ATarget: IAstNode;
AInitializer: IAstNode;
const AStaticType: IStaticType;
const AIsBoxed: Boolean
);
begin
inherited Create(AStaticType);
FIdentifier := AIdentifier;
FTarget := ATarget;
FInitializer := AInitializer;
FIsBoxed := AIsBoxed;
end;
@@ -1636,9 +1622,9 @@ begin
Result := Self;
end;
function TVariableDeclarationNode.GetIdentifier: IIdentifierNode;
function TVariableDeclarationNode.GetTarget: IAstNode;
begin
Result := FIdentifier;
Result := FTarget;
end;
function TVariableDeclarationNode.GetInitializer: IAstNode;
@@ -1658,10 +1644,10 @@ end;
{ TAssignmentNode }
constructor TAssignmentNode.Create(const AIdentifier: IIdentifierNode; const AValue: IAstNode; const AStaticType: IStaticType);
constructor TAssignmentNode.Create(const ATarget: IAstNode; const AValue: IAstNode; const AStaticType: IStaticType);
begin
inherited Create(AStaticType);
FIdentifier := AIdentifier;
FTarget := ATarget;
FValue := AValue;
end;
@@ -1675,9 +1661,9 @@ begin
Result := Self;
end;
function TAssignmentNode.GetIdentifier: IIdentifierNode;
function TAssignmentNode.GetTarget: IAstNode;
begin
Result := FIdentifier;
Result := FTarget;
end;
function TAssignmentNode.GetValue: IAstNode;