AST Identities
This commit is contained in:
@@ -75,7 +75,7 @@ function TAstTCO.Execute(const RootNode: IAstNode): IAstNode;
|
||||
begin
|
||||
Result := Accept(RootNode);
|
||||
if not Assigned(Result) then
|
||||
Result := TAst.Block([]);
|
||||
Result := TAst.Block([], nil);
|
||||
end;
|
||||
|
||||
function TAstTCO.Accept(const Node: IAstNode): IAstNode;
|
||||
@@ -117,7 +117,8 @@ begin
|
||||
if newExprs = Node.Expressions then
|
||||
Result := Node
|
||||
else
|
||||
Result := TAst.Block(newExprs, Node.StaticType);
|
||||
// CoW: Reuse Identity
|
||||
Result := TAst.Block(Node.Identity, newExprs, Node.StaticType);
|
||||
end;
|
||||
|
||||
function TAstTCO.VisitIfExpression(const Node: IIfExpressionNode): IAstNode;
|
||||
@@ -139,7 +140,8 @@ begin
|
||||
if (newCond = Node.Condition) and (newThen = Node.ThenBranch) and (newElse = Node.ElseBranch) then
|
||||
Result := Node
|
||||
else
|
||||
Result := TAst.IfExpr(newCond, newThen, newElse, Node.StaticType);
|
||||
// CoW: Reuse Identity
|
||||
Result := TAst.IfExpr(Node.Identity, newCond, newThen, newElse, Node.StaticType);
|
||||
end;
|
||||
|
||||
function TAstTCO.VisitTernaryExpression(const Node: ITernaryExpressionNode): IAstNode;
|
||||
@@ -161,7 +163,8 @@ begin
|
||||
if (newCond = Node.Condition) and (newThen = Node.ThenBranch) and (newElse = Node.ElseBranch) then
|
||||
Result := Node
|
||||
else
|
||||
Result := TAst.TernaryExpr(newCond, newThen, newElse, Node.StaticType);
|
||||
// CoW: Reuse Identity
|
||||
Result := TAst.TernaryExpr(Node.Identity, newCond, newThen, newElse, Node.StaticType);
|
||||
end;
|
||||
|
||||
function TAstTCO.VisitLambdaExpression(const Node: ILambdaExpressionNode): IAstNode;
|
||||
@@ -183,8 +186,10 @@ begin
|
||||
begin
|
||||
// Rebuild using factory.
|
||||
// IMPORTANT: Pass Layout AND Descriptor (TCO runs after TypeChecker).
|
||||
// CoW: Reuse Identity
|
||||
Result :=
|
||||
TAst.LambdaExpr(
|
||||
Node.Identity,
|
||||
newParams,
|
||||
newBody,
|
||||
Node.Layout,
|
||||
@@ -211,7 +216,8 @@ begin
|
||||
if newArgs = Node.Arguments then
|
||||
Result := Node
|
||||
else
|
||||
Result := TAst.Recur(newArgs, Node.StaticType);
|
||||
// CoW: Reuse Identity
|
||||
Result := TAst.Recur(Node.Identity, newArgs, Node.StaticType);
|
||||
end;
|
||||
|
||||
function TAstTCO.VisitMacroExpansionNode(const Node: IMacroExpansionNode): IAstNode;
|
||||
@@ -225,7 +231,8 @@ begin
|
||||
if newBody = Node.ExpandedBody then
|
||||
Result := Node
|
||||
else
|
||||
Result := TAst.MacroExpansionNode(Node.CallNode, newBody);
|
||||
// CoW: Reuse Identity
|
||||
Result := TAst.MacroExpansionNode(Node.Identity, Node.CallNode, newBody);
|
||||
end;
|
||||
|
||||
function TAstTCO.VisitFunctionCall(const Node: IFunctionCallNode): IAstNode;
|
||||
@@ -249,8 +256,10 @@ begin
|
||||
end;
|
||||
|
||||
// Use factory to create new node, passing the *new* TCO status
|
||||
// CoW: Reuse Identity
|
||||
Result :=
|
||||
TAst.FunctionCall(
|
||||
Node.Identity,
|
||||
newCallee,
|
||||
newArgs,
|
||||
Node.StaticType,
|
||||
|
||||
Reference in New Issue
Block a user