Ast list nodes

This commit is contained in:
Michael Schimmel
2025-11-29 18:59:16 +01:00
parent 250f950a68
commit 851f56c63f
24 changed files with 1819 additions and 863 deletions
+25 -8
View File
@@ -342,6 +342,7 @@ var
startCount: Integer;
hasNested: Boolean;
paramIdentity: INamedIdentity;
paramList: IParameterList;
begin
startCount := FLambdaCounter;
Inc(FLambdaCounter);
@@ -355,8 +356,10 @@ begin
try
FCurrentBuilder.Define('<self>');
SetLength(newParams, Length(Node.Parameters));
for i := 0 to High(Node.Parameters) do
// Create Array to hold transformed parameters
SetLength(newParams, Node.Parameters.Count);
for i := 0 to Node.Parameters.Count - 1 do
begin
var paramNode := Node.Parameters[i];
var paramName := paramNode.Name;
@@ -414,11 +417,15 @@ begin
hasNested := FLambdaCounter > (startCount + 1);
// Wrap the array in a List wrapper to satisfy the factory interface
// We reuse the identity of the old parameter list
paramList := TParameterList.Create(newParams, Node.Parameters.Identity);
// Rebuild Lambda using original identity
Result :=
TAst.LambdaExpr(
Node.Identity,
newParams,
paramList,
newBody,
finalLayout,
nil, // Descriptor is created in TypeChecker
@@ -433,11 +440,21 @@ begin
if Node.Callee.Kind = akKeyword then
begin
// Transform keyword call (:key obj) into member access (.key obj)
// Note: The new MemberAccess node gets the identity of the original FunctionCall
// The member keyword retains its own identity.
var memberAccess := TAst.MemberAccess(Node.Identity, Accept(Node.Arguments[0]), Node.Callee.AsKeyword);
Result := memberAccess;
exit;
// Check argument count
if Node.Arguments.Count <> 1 then
begin
if Assigned(FLog) then
FLog.AddError(Format('Keyword access :%s requires exactly one argument.', [Node.Callee.AsKeyword.Value.Name]), Node);
// Fallthrough to standard visit/recreation to avoid crash
end
else
begin
// Note: The new MemberAccess node gets the identity of the original FunctionCall
// The member keyword retains its own identity.
var memberAccess := TAst.MemberAccess(Node.Identity, Accept(Node.Arguments[0]), Node.Callee.AsKeyword);
Result := memberAccess;
exit;
end;
end;
Result := inherited VisitFunctionCall(Node);
end;