AST testing
This commit is contained in:
File diff suppressed because one or more lines are too long
@@ -531,7 +531,7 @@ begin
|
||||
if (expr.Kind = akVariableDeclaration) then
|
||||
begin
|
||||
var decl := expr.AsVariableDeclaration;
|
||||
definitions.Add(decl.Identifier.Name, decl.Initializer);
|
||||
definitions.Add(decl.Target.AsIdentifier.Name, decl.Initializer);
|
||||
end
|
||||
// Handle macro definitions inside the block
|
||||
else if expr.Kind = akMacroDefinition then
|
||||
@@ -546,7 +546,7 @@ begin
|
||||
else if rootNode.Kind = akVariableDeclaration then // Handle single definition
|
||||
begin
|
||||
var decl := rootNode.AsVariableDeclaration;
|
||||
definitions.Add(decl.Identifier.Name, decl.Initializer);
|
||||
definitions.Add(decl.Target.AsIdentifier.Name, decl.Initializer);
|
||||
end
|
||||
// Handle a single macro definition
|
||||
else if rootNode.Kind = akMacroDefinition then
|
||||
@@ -825,6 +825,7 @@ begin
|
||||
);
|
||||
|
||||
// Execute with RootScope as parent.
|
||||
//TODO Endlosschleife in HandleTCO
|
||||
result := ExecuteAst(root);
|
||||
|
||||
sw.Stop;
|
||||
|
||||
@@ -375,6 +375,7 @@ type
|
||||
TVariableDeclarationNodeHandler = class(TInterfacedObject, IAuraNodeHandler)
|
||||
private
|
||||
FNode: IVariableDeclarationNode;
|
||||
FTargetNode: TAuraNode;
|
||||
FInitializerNode: TAuraNode; // Can be nil
|
||||
function GetAstNode: IAstNode;
|
||||
public
|
||||
@@ -387,6 +388,7 @@ type
|
||||
TAssignmentNodeHandler = class(TInterfacedObject, IAuraNodeHandler)
|
||||
private
|
||||
FNode: IAssignmentNode;
|
||||
FTargetNode: TAuraNode;
|
||||
FValueNode: TAuraNode;
|
||||
function GetAstNode: IAstNode;
|
||||
public
|
||||
@@ -1782,9 +1784,9 @@ begin
|
||||
OwnerNode.Orientation := loHorizontal;
|
||||
|
||||
varLabel := OwnerNode.AddLabel(OwnerNode, 'var');
|
||||
varLabel.Font.Style := varLabel.Font.Style + [TFontStyle.fsBold];
|
||||
|
||||
OwnerNode.AddLabel(OwnerNode, FNode.Identifier.Name);
|
||||
varLabel.Font.Style := varLabel.Font.Style + [TFontStyle.fsBold];
|
||||
FTargetNode := visu.CallAccept(FNode.Target);
|
||||
|
||||
if Assigned(FNode.Initializer) then
|
||||
begin
|
||||
@@ -1804,7 +1806,7 @@ begin
|
||||
initAst := FInitializerNode.CreateAst
|
||||
else
|
||||
initAst := nil;
|
||||
Result := TAst.VarDecl(TAst.Identifier(FNode.Identifier.Name), initAst);
|
||||
Result := TAst.VarDecl(FTargetNode.CreateAst, initAst);
|
||||
end;
|
||||
|
||||
{ TAssignmentNodeHandler }
|
||||
@@ -1829,7 +1831,7 @@ begin
|
||||
try
|
||||
OwnerNode.Frameless := True;
|
||||
OwnerNode.Orientation := loHorizontal;
|
||||
OwnerNode.AddLabel(OwnerNode, FNode.Identifier.Name);
|
||||
FTargetNode := visu.CallAccept(FNode.Target);
|
||||
OwnerNode.AddLabel(OwnerNode, ':=');
|
||||
FValueNode := visu.CallAccept(FNode.Value);
|
||||
finally
|
||||
@@ -1839,7 +1841,7 @@ end;
|
||||
|
||||
function TAssignmentNodeHandler.ReconstructAst(OwnerNode: TAuraNode): IAstNode;
|
||||
begin
|
||||
Result := TAst.Assign(TAst.Identifier(FNode.Identifier.Name), FValueNode.CreateAst);
|
||||
Result := TAst.Assign(FTargetNode.CreateAst, FValueNode.CreateAst);
|
||||
end;
|
||||
|
||||
{ TMacroDefinitionNodeHandler }
|
||||
|
||||
@@ -60,7 +60,7 @@ end;
|
||||
|
||||
function TAstToTextVisitor.VisitAssignment(const Node: IAssignmentNode): string;
|
||||
begin
|
||||
Result := Node.Identifier.Name + ' := ' + Accept(Node.Value);
|
||||
Result := Accept(Node.Target) + ' := ' + Accept(Node.Value);
|
||||
end;
|
||||
|
||||
function TAstToTextVisitor.VisitBlockExpression(const Node: IBlockExpressionNode): string;
|
||||
@@ -259,7 +259,7 @@ begin
|
||||
initStr := ' := ' + Accept(Node.Initializer)
|
||||
else
|
||||
initStr := '';
|
||||
Result := 'var ' + Node.Identifier.Name + initStr;
|
||||
Result := 'var ' + Accept(Node.Target) + initStr;
|
||||
end;
|
||||
|
||||
end.
|
||||
|
||||
Reference in New Issue
Block a user