Refactoring for immutable nodes
This commit is contained in:
@@ -571,28 +571,15 @@ end;
|
||||
|
||||
function TAstTransformer.VisitMacroExpansionNode(const Node: IMacroExpansionNode): IAstNode;
|
||||
var
|
||||
newBody: IAstNode;
|
||||
N: TMacroExpansionNode;
|
||||
newType: IStaticType;
|
||||
newBody: IAstTypedNode;
|
||||
begin
|
||||
N := (Node as TMacroExpansionNode);
|
||||
// Visit the body and check if it changed
|
||||
newBody := Accept(Node.ExpandedBody).AsTypedNode;
|
||||
if newBody = Node.ExpandedBody then
|
||||
exit(Node);
|
||||
|
||||
// 1. Visit the body
|
||||
newBody := Accept(N.ExpandedBody);
|
||||
|
||||
// 2. Check if the body changed (Copy-on-Write)
|
||||
if newBody = N.ExpandedBody then
|
||||
begin
|
||||
// No change, return the original immutable node
|
||||
Result := Node;
|
||||
end
|
||||
else
|
||||
begin
|
||||
// The body changed. Create a NEW wrapper node.
|
||||
// The type of the wrapper is the type of its body.
|
||||
newType := newBody.AsTypedNode.StaticType;
|
||||
Result := TMacroExpansionNode.Create(N.CallNode, newBody, newType);
|
||||
end;
|
||||
// The body changed. Create a NEW wrapper node.
|
||||
Result := TMacroExpansionNode.Create(Node.CallNode, newBody);
|
||||
end;
|
||||
|
||||
function TAstTransformer.VisitBlockExpression(const Node: IBlockExpressionNode): IAstNode;
|
||||
|
||||
Reference in New Issue
Block a user