Refactoring node to be immutable
This commit is contained in:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user