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
+9 -12
View File
@@ -545,35 +545,32 @@ end;
function TAstTransformer.VisitVariableDeclaration(const Node: IVariableDeclarationNode): IAstNode;
var
newIdent: IIdentifierNode;
newTarget: IAstNode;
newInit: IAstNode;
begin
// No longer cast to concrete class, use interface
newIdent := Accept(Node.Identifier).AsIdentifier;
newInit := Accept(Node.Initializer); // Accept handles nil
newTarget := Accept(Node.Target);
newInit := Accept(Node.Initializer);
if (newIdent = Node.Identifier) and (newInit = Node.Initializer) then
if (newTarget = Node.Target) and (newInit = Node.Initializer) then
Result := Node
else
begin
// Use TAst factory and copy properties via interface getters
Result := TAst.VarDecl(newIdent, newInit, Node.StaticType, Node.IsBoxed);
Result := TAst.VarDecl(newTarget, newInit, Node.StaticType, Node.IsBoxed);
end;
end;
function TAstTransformer.VisitAssignment(const Node: IAssignmentNode): IAstNode;
var
newIdent: IIdentifierNode;
newTarget: IAstNode;
newValue: IAstNode;
begin
newTarget := Accept(Node.Target);
newValue := Accept(Node.Value);
newIdent := Accept(Node.Identifier).AsIdentifier;
if (newValue = Node.Value) and (newIdent = Node.Identifier) then
if (newTarget = Node.Target) and (newValue = Node.Value) then
Result := Node
else
// Use TAst factory
Result := TAst.Assign(newIdent, newValue, Node.StaticType);
Result := TAst.Assign(newTarget, newValue, Node.StaticType);
end;
function TAstTransformer.VisitMacroDefinition(const Node: IMacroDefinitionNode): IAstNode;