Refactoring node to be immutable

This commit is contained in:
Michael Schimmel
2025-11-05 15:24:54 +01:00
parent 25984fe61a
commit b98e7d98e6
6 changed files with 50 additions and 94 deletions
+8 -8
View File
@@ -111,10 +111,10 @@ begin
// Get the type from the descriptor (which was populated by Binder/RTL)
symbol := FCurrentDescriptor.FindSymbol(Node.Name);
adr := Node.AsBoundIdentifierNode.Address;
adr := Node.AsIdentifier.Address;
// Create a new node, copying the address and assigning the inferred type
Result := TAst.BoundIdentifier(Node.Name, adr, symbol.StaticType);
Result := TAst.Identifier(Node.Name, adr, symbol.StaticType);
end;
function TTypeChecker.VisitRecurNode(const Node: IRecurNode): IAstNode;
@@ -153,14 +153,14 @@ begin
// 3. Get the address from the bound identifier (SAFE CAST)
boundIdent := Node.Identifier;
adr := boundIdent.AsBoundIdentifierNode.Address;
adr := boundIdent.AsIdentifier.Address;
// 4. Update the type in the scope descriptor (which was set to Unknown by the binder).
if initType.Kind <> stUnknown then
FCurrentDescriptor.UpdateType(adr.SlotIndex, initType);
// 5. Create the new (typed) identifier node
newIdent := TAst.BoundIdentifier(boundIdent.Name, adr, initType);
newIdent := TAst.Identifier(boundIdent.Name, adr, initType);
// 6. Create the new VariableDeclaration node
Result := TVariableDeclarationNode.Create(newIdent.AsIdentifier, newInitializer, initType);
@@ -192,11 +192,11 @@ begin
// with the new, inferred type. This enables recursion.
if (targetType.Kind = stUnknown) and (sourceType.Kind <> stUnknown) then
begin
adr := newIdent.AsBoundIdentifierNode.Address;
adr := newIdent.AsIdentifier.Address;
FCurrentDescriptor.UpdateType(adr.SlotIndex, sourceType);
// Re-create the identifier node *with the new type*
newIdent := TAst.BoundIdentifier(newIdent.AsIdentifier.Name, adr, sourceType);
newIdent := TAst.Identifier(newIdent.AsIdentifier.Name, adr, sourceType);
targetType := sourceType;
end;
@@ -229,8 +229,8 @@ begin
// Parameters are leaves, but we must *replace* them with typed versions
// (even if they are just TTypes.Unknown for now, for type inference placeholders)
var paramIdent := boundNode.Parameters[i];
var paramAdr := paramIdent.AsBoundIdentifierNode.Address;
var newParam := TAst.BoundIdentifier(paramIdent.Name, paramAdr);
var paramAdr := paramIdent.AsIdentifier.Address;
var newParam := TAst.Identifier(paramIdent.Name, paramAdr);
newParams[i] := newParam;
paramTypes[i] := TTypes.Unknown;