Static specialization WIP
Fix in ScopeDescriptor
This commit is contained in:
@@ -289,7 +289,7 @@ type
|
||||
property Value: IAstNode read GetValue;
|
||||
end;
|
||||
|
||||
IMacroDefinitionNode = interface(IAstNode)
|
||||
IMacroDefinitionNode = interface(IAstTypedNode)
|
||||
{$region 'private'}
|
||||
function GetName: IIdentifierNode;
|
||||
function GetParameters: TArray<IIdentifierNode>;
|
||||
|
||||
@@ -273,7 +273,7 @@ begin
|
||||
if Assigned(ADescriptor) then
|
||||
FDescriptor := ADescriptor
|
||||
else if Assigned(AParent) then
|
||||
FDescriptor := AParent.CreateDescriptor // Inherit descriptor if nil
|
||||
FDescriptor := TScopeDescriptor.Create(AParent.CreateDescriptor)
|
||||
else
|
||||
FDescriptor := TScope.CreateDescriptor(nil); // Create new root descriptor
|
||||
|
||||
|
||||
@@ -509,10 +509,10 @@ end;
|
||||
|
||||
function TAstTransformer.VisitMacroExpansionNode(const Node: IMacroExpansionNode): IAstNode;
|
||||
var
|
||||
newBody: IAstTypedNode;
|
||||
newBody: IAstNode;
|
||||
begin
|
||||
// Visit the body and check if it changed
|
||||
newBody := Accept(Node.ExpandedBody).AsTypedNode;
|
||||
newBody := Accept(Node.ExpandedBody);
|
||||
if newBody = Node.ExpandedBody then
|
||||
exit(Node);
|
||||
|
||||
|
||||
+12
-13
@@ -298,7 +298,7 @@ type
|
||||
property Value: IKeyword read FValue;
|
||||
end;
|
||||
|
||||
TMacroDefinitionNode = class(TAstNode, IMacroDefinitionNode)
|
||||
TMacroDefinitionNode = class(TAstTypedNode, IMacroDefinitionNode)
|
||||
private
|
||||
FName: IIdentifierNode;
|
||||
FParameters: TArray<IIdentifierNode>;
|
||||
@@ -355,16 +355,16 @@ type
|
||||
TMacroExpansionNode = class(TAstTypedNode, IMacroExpansionNode)
|
||||
private
|
||||
FCallNode: IFunctionCallNode;
|
||||
FExpandedBody: IAstTypedNode;
|
||||
FExpandedBody: IAstNode;
|
||||
function GetCallNode: IFunctionCallNode;
|
||||
function GetExpandedBody: IAstNode;
|
||||
function GetKind: TAstNodeKind; override;
|
||||
public
|
||||
constructor Create(const ACallNode: IFunctionCallNode; const AExpandedBody: IAstTypedNode);
|
||||
constructor Create(const ACallNode: IFunctionCallNode; const AExpandedBody: IAstNode);
|
||||
function Accept(const Visitor: IAstVisitor): TDataValue; override;
|
||||
function AsMacroExpansion: IMacroExpansionNode; override;
|
||||
property CallNode: IFunctionCallNode read GetCallNode;
|
||||
property ExpandedBody: IAstTypedNode read FExpandedBody;
|
||||
property ExpandedBody: IAstNode read FExpandedBody;
|
||||
end;
|
||||
|
||||
TRecurNode = class(TAstTypedNode, IRecurNode)
|
||||
@@ -788,11 +788,7 @@ end;
|
||||
|
||||
class function TAst.MacroExpansionNode(const AOriginalCallNode: IFunctionCallNode; const AExpandedBody: IAstNode): IMacroExpansionNode;
|
||||
begin
|
||||
// A MacroExpansionNode MUST have a typed body.
|
||||
if not AExpandedBody.IsTyped then
|
||||
raise ETypeException.Create('MacroExpansionNode cannot be created with an untyped body.');
|
||||
|
||||
Result := TMacroExpansionNode.Create(AOriginalCallNode, AExpandedBody.AsTypedNode);
|
||||
Result := TMacroExpansionNode.Create(AOriginalCallNode, AExpandedBody);
|
||||
end;
|
||||
|
||||
class function TAst.MemberAccess(
|
||||
@@ -1316,7 +1312,7 @@ end;
|
||||
|
||||
constructor TMacroDefinitionNode.Create(const AName: IIdentifierNode; const AParameters: TArray<IIdentifierNode>; const ABody: IAstNode);
|
||||
begin
|
||||
inherited Create;
|
||||
inherited Create(TTypes.Void);
|
||||
FName := AName;
|
||||
FParameters := AParameters;
|
||||
FBody := ABody;
|
||||
@@ -1490,10 +1486,13 @@ end;
|
||||
|
||||
{ TMacroExpansionNode }
|
||||
|
||||
constructor TMacroExpansionNode.Create(const ACallNode: IFunctionCallNode; const AExpandedBody: IAstTypedNode);
|
||||
constructor TMacroExpansionNode.Create(const ACallNode: IFunctionCallNode; const AExpandedBody: IAstNode);
|
||||
begin
|
||||
// The StaticType of the wrapper *is* the StaticType of the body
|
||||
inherited Create(AExpandedBody.StaticType);
|
||||
if AExpandedBody.IsTyped then
|
||||
inherited Create(AExpandedBody.AsTypedNode.StaticType)
|
||||
else
|
||||
inherited Create(TTypes.Unknown);
|
||||
|
||||
FExpandedBody := AExpandedBody;
|
||||
FCallNode := ACallNode;
|
||||
end;
|
||||
|
||||
Reference in New Issue
Block a user