Nop-Node
This commit is contained in:
@@ -28,6 +28,10 @@ type
|
||||
class procedure RegisterLibrary(const AProc: TRegisterLibraryProc); static;
|
||||
class function CreateScope(Parent: IExecutionScope; const Descriptor: IScopeDescriptor = nil): IExecutionScope; static;
|
||||
|
||||
// A No-Operation node, used as a placeholder/stub (e.g., for UI drop targets).
|
||||
// This node is illegal in the compiler (Binder/TypeChecker will reject it).
|
||||
class function Nop: IAstNode; static;
|
||||
|
||||
// --- Factory functions ---
|
||||
class function Constant(const AValue: TDataValue): IConstantNode; overload; static;
|
||||
class function Constant(const AValue: String): IConstantNode; overload; static;
|
||||
@@ -103,6 +107,7 @@ type
|
||||
function AsAddSeriesItem: IAddSeriesItemNode; virtual;
|
||||
function AsSeriesLength: ISeriesLengthNode; virtual;
|
||||
function AsRecur: IRecurNode; virtual;
|
||||
function AsNop: INopNode; virtual; // Added Nop
|
||||
|
||||
property StaticType: IStaticType read FStaticType write SetStaticType;
|
||||
property Kind: TAstNodeKind read GetKind;
|
||||
@@ -474,6 +479,17 @@ implementation
|
||||
uses
|
||||
System.Generics.Defaults;
|
||||
|
||||
// Added Nop
|
||||
type
|
||||
TNopNode = class(TAstNode, INopNode)
|
||||
private
|
||||
function GetKind: TAstNodeKind; override;
|
||||
public
|
||||
constructor Create;
|
||||
function Accept(const Visitor: IAstVisitor): TDataValue; override;
|
||||
function AsNop: INopNode; override;
|
||||
end;
|
||||
|
||||
{ TAst }
|
||||
|
||||
class function TAst.CreateScope(Parent: IExecutionScope; const Descriptor: IScopeDescriptor): IExecutionScope;
|
||||
@@ -603,6 +619,12 @@ begin
|
||||
Result := TMemberAccessNode.Create(ABase, AMember);
|
||||
end;
|
||||
|
||||
class function TAst.Nop: IAstNode;
|
||||
begin
|
||||
// Factory function for the new Nop node
|
||||
Result := TNopNode.Create;
|
||||
end;
|
||||
|
||||
class function TAst.Quasiquote(const AExpression: IAstNode): IQuasiquoteNode;
|
||||
begin
|
||||
Result := TQuasiquoteNode.Create(AExpression);
|
||||
@@ -650,6 +672,30 @@ begin
|
||||
Result := TVariableDeclarationNode.Create(AIdentifier, AInitializer);
|
||||
end;
|
||||
|
||||
{ TNopNode }
|
||||
|
||||
constructor TNopNode.Create;
|
||||
begin
|
||||
inherited Create;
|
||||
// Nop nodes are 'Void' by default, though TypeChecker will reject them anyway.
|
||||
StaticType := TTypes.Void;
|
||||
end;
|
||||
|
||||
function TNopNode.Accept(const Visitor: IAstVisitor): TDataValue;
|
||||
begin
|
||||
Result := Visitor.VisitNop(Self);
|
||||
end;
|
||||
|
||||
function TNopNode.AsNop: INopNode;
|
||||
begin
|
||||
Result := Self;
|
||||
end;
|
||||
|
||||
function TNopNode.GetKind: TAstNodeKind;
|
||||
begin
|
||||
Result := akNop;
|
||||
end;
|
||||
|
||||
{ TAstNode }
|
||||
|
||||
constructor TAstNode.Create;
|
||||
@@ -733,6 +779,12 @@ begin
|
||||
raise ETypeException.Create('Node is not a MemberAccess');
|
||||
end;
|
||||
|
||||
function TAstNode.AsNop: INopNode;
|
||||
begin
|
||||
// Added Nop implementation
|
||||
raise ETypeException.Create('Node is not a Nop');
|
||||
end;
|
||||
|
||||
function TAstNode.AsQuasiquote: IQuasiquoteNode;
|
||||
begin
|
||||
raise ETypeException.Create('Node is not a Quasiquote');
|
||||
|
||||
Reference in New Issue
Block a user