Ast control refactoring

This commit is contained in:
Michael Schimmel
2025-09-16 19:18:40 +02:00
parent 230c4b51bf
commit b972b05a07
5 changed files with 324 additions and 264 deletions
+7 -2
View File
@@ -42,6 +42,8 @@ type
SlotIndex: Integer;
constructor Create(AKind: TAddressKind; AScopeDepth, ASlotIndex: Integer);
class operator Initialize(out Dest: TResolvedAddress);
public
class operator Equal(const A: TResolvedAddress; B: TResolvedAddress): Boolean;
end;
IValueCell = interface
@@ -112,12 +114,10 @@ type
IIdentifierNode = interface(IAstNode)
{$region 'private'}
function GetIsResolved: Boolean;
function GetAddress: TResolvedAddress;
function GetName: string;
{$endregion}
property Name: string read GetName;
property IsResolved: Boolean read GetIsResolved;
property Address: TResolvedAddress read GetAddress;
end;
@@ -269,6 +269,11 @@ begin
SlotIndex := ASlotIndex;
end;
class operator TResolvedAddress.Equal(const A: TResolvedAddress; B: TResolvedAddress): Boolean;
begin
Result := (A.Kind = B.Kind) and (A.ScopeDepth = B.ScopeDepth) and (A.SlotIndex = B.SlotIndex);
end;
class operator TResolvedAddress.Initialize(out Dest: TResolvedAddress);
begin
Dest.Kind := akUnresolved;
+1 -11
View File
@@ -112,12 +112,10 @@ type
// --- Annotation fields added for the binder ---
FResolvedAddress: TResolvedAddress;
function GetName: string;
function GetIsResolved: Boolean; inline;
function GetAddress: TResolvedAddress; inline;
public
constructor Create(AName: string);
function Accept(const Visitor: IAstVisitor): TDataValue; override;
property IsResolved: Boolean read GetIsResolved;
property Name: string read FName;
property Address: TResolvedAddress read GetAddress;
end;
@@ -437,12 +435,6 @@ begin
Result := Visitor.VisitIdentifier(Self);
end;
function TIdentifierNode.GetIsResolved: Boolean;
begin
// An identifier is resolved if its kind is not unresolved anymore.
Result := FResolvedAddress.Kind <> akUnresolved;
end;
function TIdentifierNode.GetName: string;
begin
Result := FName;
@@ -450,8 +442,6 @@ end;
function TIdentifierNode.GetAddress: TResolvedAddress;
begin
if not IsResolved then
raise EInvalidOpException.Create('Identifier not bound');
Result := FResolvedAddress;
end;
@@ -867,7 +857,7 @@ var
upvalueIndex: Integer;
begin
identNode := Node as TIdentifierNode;
if identNode.IsResolved then
if identNode.Address.Kind <> akUnresolved then
Exit;
if (FCurrentDescriptor as TScopeDescriptor).FindSymbol(identNode.Name, depth, idx) then