Immutable infered types
This commit is contained in:
+163
-112
@@ -70,13 +70,13 @@ type
|
||||
const ALookback: IAstNode = nil
|
||||
): IAddSeriesItemNode; static;
|
||||
class function SeriesLength(const ASeries: IIdentifierNode): ISeriesLengthNode; static;
|
||||
|
||||
class function BoundIdentifier(AName: string; const Address: TResolvedAddress): IBoundIdentifierNode; static;
|
||||
end;
|
||||
|
||||
// Common base class for AST nodes to reduce boilerplate.
|
||||
TAstNode = class(TInterfacedObject, IAstNode)
|
||||
private
|
||||
FStaticType: IStaticType;
|
||||
procedure SetStaticType(const AValue: IStaticType);
|
||||
function GetKind: TAstNodeKind; virtual; abstract;
|
||||
public
|
||||
constructor Create;
|
||||
@@ -110,30 +110,40 @@ type
|
||||
function AsNop: INopNode; virtual; // Added Nop
|
||||
|
||||
function AsBoundIdentifierNode: IBoundIdentifierNode; virtual;
|
||||
function AsTypedNode: IAstTypedNode; virtual;
|
||||
|
||||
property StaticType: IStaticType read FStaticType write SetStaticType;
|
||||
property Kind: TAstNodeKind read GetKind;
|
||||
end;
|
||||
|
||||
TConstantNode = class(TAstNode, IConstantNode)
|
||||
TAstTypedNode = class(TAstNode, IAstTypedNode)
|
||||
private
|
||||
FStaticType: IStaticType;
|
||||
function GetStaticType: IStaticType;
|
||||
public
|
||||
constructor Create(const AStaticType: IStaticType);
|
||||
function AsTypedNode: IAstTypedNode; override;
|
||||
property StaticType: IStaticType read GetStaticType;
|
||||
end;
|
||||
|
||||
TConstantNode = class(TAstTypedNode, IConstantNode)
|
||||
private
|
||||
FValue: TDataValue;
|
||||
function GetValue: TDataValue;
|
||||
function GetKind: TAstNodeKind; override;
|
||||
public
|
||||
constructor Create(const AValue: TDataValue);
|
||||
constructor Create(const AValue: TDataValue; const AStaticType: IStaticType);
|
||||
function Accept(const Visitor: IAstVisitor): TDataValue; override;
|
||||
function AsConstant: IConstantNode; override;
|
||||
property Value: TDataValue read GetValue; // Value ist immutable
|
||||
end;
|
||||
|
||||
TIdentifierNode = class(TAstNode, IIdentifierNode)
|
||||
TIdentifierNode = class(TAstTypedNode, IIdentifierNode)
|
||||
private
|
||||
FName: string;
|
||||
function GetName: string;
|
||||
function GetKind: TAstNodeKind; override;
|
||||
public
|
||||
constructor Create(const AName: string);
|
||||
constructor Create(const AName: string; const AStaticType: IStaticType);
|
||||
function Accept(const Visitor: IAstVisitor): TDataValue; override;
|
||||
function AsIdentifier: IIdentifierNode; override;
|
||||
property Name: string read FName; // Name ist immutable
|
||||
@@ -145,12 +155,12 @@ type
|
||||
function GetAddress: TResolvedAddress;
|
||||
function GetKind: TAstNodeKind; override;
|
||||
public
|
||||
constructor Create(const AName: string; const AAddress: TResolvedAddress);
|
||||
constructor Create(const AName: string; const AAddress: TResolvedAddress; const AStaticType: IStaticType);
|
||||
function AsBoundIdentifierNode: IBoundIdentifierNode; override;
|
||||
property Address: TResolvedAddress read GetAddress;
|
||||
end;
|
||||
|
||||
TKeywordNode = class(TAstNode, IKeywordNode)
|
||||
TKeywordNode = class(TAstTypedNode, IKeywordNode)
|
||||
private
|
||||
FValue: IKeyword;
|
||||
function GetValue: IKeyword;
|
||||
@@ -162,7 +172,7 @@ type
|
||||
property Value: IKeyword read FValue; // Value ist immutable
|
||||
end;
|
||||
|
||||
TBinaryExpressionNode = class(TAstNode, IBinaryExpressionNode)
|
||||
TBinaryExpressionNode = class(TAstTypedNode, IBinaryExpressionNode)
|
||||
private
|
||||
FLeft: IAstNode;
|
||||
FOperator: TScalar.TBinaryOp;
|
||||
@@ -172,7 +182,7 @@ type
|
||||
function GetRight: IAstNode;
|
||||
function GetKind: TAstNodeKind; override;
|
||||
public
|
||||
constructor Create(const ALeft: IAstNode; AOperator: TScalar.TBinaryOp; const ARight: IAstNode);
|
||||
constructor Create(const ALeft: IAstNode; AOperator: TScalar.TBinaryOp; const ARight: IAstNode; const AStaticType: IStaticType);
|
||||
function Accept(const Visitor: IAstVisitor): TDataValue; override;
|
||||
function AsBinaryExpression: IBinaryExpressionNode; override;
|
||||
property Left: IAstNode read FLeft write FLeft; // Writeable
|
||||
@@ -180,7 +190,7 @@ type
|
||||
property Right: IAstNode read FRight write FRight; // Writeable
|
||||
end;
|
||||
|
||||
TUnaryExpressionNode = class(TAstNode, IUnaryExpressionNode)
|
||||
TUnaryExpressionNode = class(TAstTypedNode, IUnaryExpressionNode)
|
||||
private
|
||||
FOperator: TScalar.TUnaryOp;
|
||||
FRight: IAstNode;
|
||||
@@ -188,14 +198,14 @@ type
|
||||
function GetRight: IAstNode;
|
||||
function GetKind: TAstNodeKind; override;
|
||||
public
|
||||
constructor Create(const AOperator: TScalar.TUnaryOp; const ARight: IAstNode);
|
||||
constructor Create(const AOperator: TScalar.TUnaryOp; const ARight: IAstNode; const AStaticType: IStaticType);
|
||||
function Accept(const Visitor: IAstVisitor): TDataValue; override;
|
||||
function AsUnaryExpression: IUnaryExpressionNode; override;
|
||||
property Operator: TScalar.TUnaryOp read FOperator write FOperator; // Writeable
|
||||
property Right: IAstNode read FRight write FRight; // Writeable
|
||||
end;
|
||||
|
||||
TIfExpressionNode = class(TAstNode, IIfExpressionNode)
|
||||
TIfExpressionNode = class(TAstTypedNode, IIfExpressionNode)
|
||||
private
|
||||
FCondition: IAstNode;
|
||||
FThenBranch: IAstNode;
|
||||
@@ -205,7 +215,7 @@ type
|
||||
function GetElseBranch: IAstNode;
|
||||
function GetKind: TAstNodeKind; override;
|
||||
public
|
||||
constructor Create(const ACondition, AThenBranch, AElseBranch: IAstNode);
|
||||
constructor Create(const ACondition, AThenBranch, AElseBranch: IAstNode; const AStaticType: IStaticType);
|
||||
function Accept(const Visitor: IAstVisitor): TDataValue; override;
|
||||
function AsIfExpression: IIfExpressionNode; override;
|
||||
property Condition: IAstNode read FCondition write FCondition; // Writeable
|
||||
@@ -213,7 +223,7 @@ type
|
||||
property ElseBranch: IAstNode read FElseBranch write FElseBranch; // Writeable
|
||||
end;
|
||||
|
||||
TTernaryExpressionNode = class(TAstNode, ITernaryExpressionNode)
|
||||
TTernaryExpressionNode = class(TAstTypedNode, ITernaryExpressionNode)
|
||||
private
|
||||
FCondition: IAstNode;
|
||||
FThenBranch: IAstNode;
|
||||
@@ -223,7 +233,7 @@ type
|
||||
function GetElseBranch: IAstNode;
|
||||
function GetKind: TAstNodeKind; override;
|
||||
public
|
||||
constructor Create(const ACondition, AThenBranch, AElseBranch: IAstNode);
|
||||
constructor Create(const ACondition, AThenBranch, AElseBranch: IAstNode; const AStaticType: IStaticType);
|
||||
function Accept(const Visitor: IAstVisitor): TDataValue; override;
|
||||
function AsTernaryExpression: ITernaryExpressionNode; override;
|
||||
property Condition: IAstNode read FCondition write FCondition; // Writeable
|
||||
@@ -231,7 +241,7 @@ type
|
||||
property ElseBranch: IAstNode read FElseBranch write FElseBranch; // Writeable
|
||||
end;
|
||||
|
||||
TLambdaExpressionNode = class(TAstNode, ILambdaExpressionNode)
|
||||
TLambdaExpressionNode = class(TAstTypedNode, ILambdaExpressionNode)
|
||||
private
|
||||
FParameters: TArray<IIdentifierNode>;
|
||||
FBody: IAstNode;
|
||||
@@ -242,7 +252,7 @@ type
|
||||
function GetBody: IAstNode;
|
||||
function GetKind: TAstNodeKind; override;
|
||||
public
|
||||
constructor Create(const AParameters: TArray<IIdentifierNode>; const ABody: IAstNode);
|
||||
constructor Create(const AParameters: TArray<IIdentifierNode>; const ABody: IAstNode; const AStaticType: IStaticType);
|
||||
destructor Destroy; override;
|
||||
function Accept(const Visitor: IAstVisitor): TDataValue; override;
|
||||
function AsLambdaExpression: ILambdaExpressionNode; override;
|
||||
@@ -307,7 +317,7 @@ type
|
||||
property Expression: IQuasiquoteNode read GetExpression write FExpression;
|
||||
end;
|
||||
|
||||
TFunctionCallNode = class(TAstNode, IFunctionCallNode)
|
||||
TFunctionCallNode = class(TAstTypedNode, IFunctionCallNode)
|
||||
private
|
||||
FCallee: IAstNode;
|
||||
FArguments: TArray<IAstNode>;
|
||||
@@ -316,7 +326,7 @@ type
|
||||
function GetArguments: TArray<IAstNode>;
|
||||
function GetKind: TAstNodeKind; override;
|
||||
public
|
||||
constructor Create(const ACallee: IAstNode; const AArguments: TArray<IAstNode>);
|
||||
constructor Create(const ACallee: IAstNode; const AArguments: TArray<IAstNode>; const AStaticType: IStaticType);
|
||||
function Accept(const Visitor: IAstVisitor): TDataValue; override;
|
||||
function AsFunctionCall: IFunctionCallNode; override;
|
||||
property Callee: IAstNode read FCallee write FCallee; // Writeable
|
||||
@@ -324,13 +334,13 @@ type
|
||||
property IsTailCall: Boolean read FIsTailCall write FIsTailCall;
|
||||
end;
|
||||
|
||||
TRecurNode = class(TAstNode, IRecurNode)
|
||||
TRecurNode = class(TAstTypedNode, IRecurNode)
|
||||
private
|
||||
FArguments: TArray<IAstNode>;
|
||||
function GetArguments: TArray<IAstNode>;
|
||||
function GetKind: TAstNodeKind; override;
|
||||
public
|
||||
constructor Create(const AArguments: TArray<IAstNode>);
|
||||
constructor Create(const AArguments: TArray<IAstNode>; const AStaticType: IStaticType);
|
||||
function Accept(const Visitor: IAstVisitor): TDataValue; override;
|
||||
function AsRecur: IRecurNode; override;
|
||||
property Arguments: TArray<IAstNode> read FArguments write FArguments; // Writeable
|
||||
@@ -342,24 +352,25 @@ type
|
||||
function GetExpandedBody: IAstNode;
|
||||
function GetKind: TAstNodeKind; override;
|
||||
public
|
||||
constructor Create(const AOriginalCallNode: IFunctionCallNode; const AExpandedBody: IAstNode);
|
||||
constructor Create(const AOriginalCallNode: IFunctionCallNode; const AExpandedBody: IAstNode; const AStaticType: IStaticType);
|
||||
function Accept(const Visitor: IAstVisitor): TDataValue; override;
|
||||
function AsMacroExpansion: IMacroExpansionNode; override;
|
||||
property ExpandedBody: IAstNode read FExpandedBody write FExpandedBody; // Writeable
|
||||
end;
|
||||
TBlockExpressionNode = class(TAstNode, IBlockExpressionNode)
|
||||
|
||||
TBlockExpressionNode = class(TAstTypedNode, IBlockExpressionNode)
|
||||
private
|
||||
FExpressions: TArray<IAstNode>;
|
||||
function GetExpressions: TArray<IAstNode>;
|
||||
function GetKind: TAstNodeKind; override;
|
||||
public
|
||||
constructor Create(const AExpressions: array of IAstNode);
|
||||
constructor Create(const AExpressions: array of IAstNode; const AStaticType: IStaticType);
|
||||
function Accept(const Visitor: IAstVisitor): TDataValue; override;
|
||||
function AsBlockExpression: IBlockExpressionNode; override;
|
||||
property Expressions: TArray<IAstNode> read FExpressions write FExpressions; // Writeable
|
||||
end;
|
||||
|
||||
TVariableDeclarationNode = class(TAstNode, IVariableDeclarationNode)
|
||||
TVariableDeclarationNode = class(TAstTypedNode, IVariableDeclarationNode)
|
||||
private
|
||||
FIdentifier: IIdentifierNode;
|
||||
FInitializer: IAstNode;
|
||||
@@ -368,7 +379,7 @@ type
|
||||
function GetInitializer: IAstNode;
|
||||
function GetKind: TAstNodeKind; override;
|
||||
public
|
||||
constructor Create(const AIdentifier: IIdentifierNode; AInitializer: IAstNode);
|
||||
constructor Create(const AIdentifier: IIdentifierNode; AInitializer: IAstNode; const AStaticType: IStaticType);
|
||||
function Accept(const Visitor: IAstVisitor): TDataValue; override;
|
||||
function AsVariableDeclaration: IVariableDeclarationNode; override;
|
||||
property Identifier: IIdentifierNode read FIdentifier write FIdentifier; // Writeable
|
||||
@@ -376,7 +387,7 @@ type
|
||||
property IsBoxed: Boolean read FIsBoxed write FIsBoxed;
|
||||
end;
|
||||
|
||||
TAssignmentNode = class(TAstNode, IAssignmentNode)
|
||||
TAssignmentNode = class(TAstTypedNode, IAssignmentNode)
|
||||
private
|
||||
FIdentifier: IIdentifierNode;
|
||||
FValue: IAstNode;
|
||||
@@ -384,14 +395,14 @@ type
|
||||
function GetValue: IAstNode;
|
||||
function GetKind: TAstNodeKind; override;
|
||||
public
|
||||
constructor Create(const AIdentifier: IIdentifierNode; const AValue: IAstNode);
|
||||
constructor Create(const AIdentifier: IIdentifierNode; const AValue: IAstNode; const AStaticType: IStaticType);
|
||||
function Accept(const Visitor: IAstVisitor): TDataValue; override;
|
||||
function AsAssignment: IAssignmentNode; override;
|
||||
property Identifier: IIdentifierNode read FIdentifier write FIdentifier;
|
||||
property Value: IAstNode read FValue write FValue; // Writeable
|
||||
end;
|
||||
|
||||
TIndexerNode = class(TAstNode, IIndexerNode)
|
||||
TIndexerNode = class(TAstTypedNode, IIndexerNode)
|
||||
private
|
||||
FBase: IAstNode;
|
||||
FIndex: IAstNode;
|
||||
@@ -399,14 +410,14 @@ type
|
||||
function GetIndex: IAstNode;
|
||||
function GetKind: TAstNodeKind; override;
|
||||
public
|
||||
constructor Create(const ABase: IAstNode; const AIndex: IAstNode);
|
||||
constructor Create(const ABase: IAstNode; const AIndex: IAstNode; const AStaticType: IStaticType);
|
||||
function Accept(const Visitor: IAstVisitor): TDataValue; override;
|
||||
function AsIndexer: IIndexerNode; override;
|
||||
property Base: IAstNode read FBase write FBase; // Writeable
|
||||
property Index: IAstNode read FIndex write FIndex; // Writeable
|
||||
end;
|
||||
|
||||
TMemberAccessNode = class(TAstNode, IMemberAccessNode)
|
||||
TMemberAccessNode = class(TAstTypedNode, IMemberAccessNode)
|
||||
private
|
||||
FBase: IAstNode;
|
||||
FMember: IKeywordNode;
|
||||
@@ -414,21 +425,21 @@ type
|
||||
function GetMember: IKeywordNode;
|
||||
function GetKind: TAstNodeKind; override;
|
||||
public
|
||||
constructor Create(const ABase: IAstNode; const AMember: IKeywordNode);
|
||||
constructor Create(const ABase: IAstNode; const AMember: IKeywordNode; const AStaticType: IStaticType);
|
||||
function Accept(const Visitor: IAstVisitor): TDataValue; override;
|
||||
function AsMemberAccess: IMemberAccessNode; override;
|
||||
property Base: IAstNode read FBase write FBase; // Writeable
|
||||
property Member: IKeywordNode read FMember write FMember;
|
||||
end;
|
||||
|
||||
TRecordLiteralNode = class(TAstNode, IRecordLiteralNode)
|
||||
TRecordLiteralNode = class(TAstTypedNode, IRecordLiteralNode)
|
||||
private
|
||||
FFields: TArray<TRecordFieldLiteral>;
|
||||
FDefinition: IScalarRecordDefinition;
|
||||
function GetFields: TArray<TRecordFieldLiteral>;
|
||||
function GetKind: TAstNodeKind; override;
|
||||
public
|
||||
constructor Create(const AFields: TArray<TRecordFieldLiteral>);
|
||||
constructor Create(const AFields: TArray<TRecordFieldLiteral>; const AStaticType: IStaticType);
|
||||
function Accept(const Visitor: IAstVisitor): TDataValue; override;
|
||||
function AsRecordLiteral: IRecordLiteralNode; override;
|
||||
property Fields: TArray<TRecordFieldLiteral> read FFields write FFields; // Writeable
|
||||
@@ -439,22 +450,22 @@ type
|
||||
private
|
||||
FGenericDefinition: IGenericRecordDefinition;
|
||||
public
|
||||
constructor Create(const AFields: TArray<TRecordFieldLiteral>);
|
||||
constructor Create(const AFields: TArray<TRecordFieldLiteral>; const AStaticType: IStaticType);
|
||||
property GenericDefinition: IGenericRecordDefinition read FGenericDefinition write FGenericDefinition;
|
||||
end;
|
||||
|
||||
TCreateSeriesNode = class(TAstNode, ICreateSeriesNode)
|
||||
TCreateSeriesNode = class(TAstTypedNode, ICreateSeriesNode)
|
||||
private
|
||||
FDefinition: String;
|
||||
function GetDefinition: String;
|
||||
function GetKind: TAstNodeKind; override;
|
||||
public
|
||||
constructor Create(const ADefinition: String);
|
||||
constructor Create(const ADefinition: String; const AStaticType: IStaticType);
|
||||
function Accept(const Visitor: IAstVisitor): TDataValue; override;
|
||||
function AsCreateSeries: ICreateSeriesNode; override;
|
||||
end;
|
||||
|
||||
TAddSeriesItemNode = class(TAstNode, IAddSeriesItemNode)
|
||||
TAddSeriesItemNode = class(TAstTypedNode, IAddSeriesItemNode)
|
||||
private
|
||||
FSeries: IIdentifierNode;
|
||||
FValue: IAstNode;
|
||||
@@ -464,7 +475,12 @@ type
|
||||
function GetLookback: IAstNode;
|
||||
function GetKind: TAstNodeKind; override;
|
||||
public
|
||||
constructor Create(const ASeries: IIdentifierNode; const AValue: IAstNode; const ALookback: IAstNode);
|
||||
constructor Create(
|
||||
const ASeries: IIdentifierNode;
|
||||
const AValue: IAstNode;
|
||||
const ALookback: IAstNode;
|
||||
const AStaticType: IStaticType
|
||||
);
|
||||
function Accept(const Visitor: IAstVisitor): TDataValue; override;
|
||||
function AsAddSeriesItem: IAddSeriesItemNode; override;
|
||||
property Series: IIdentifierNode read FSeries write FSeries;
|
||||
@@ -472,13 +488,13 @@ type
|
||||
property Lookback: IAstNode read FLookback write FLookback; // Writeable
|
||||
end;
|
||||
|
||||
TSeriesLengthNode = class(TAstNode, ISeriesLengthNode)
|
||||
TSeriesLengthNode = class(TAstTypedNode, ISeriesLengthNode)
|
||||
private
|
||||
FSeries: IIdentifierNode;
|
||||
function GetSeries: IIdentifierNode;
|
||||
function GetKind: TAstNodeKind; override;
|
||||
public
|
||||
constructor Create(const ASeries: IIdentifierNode);
|
||||
constructor Create(const ASeries: IIdentifierNode; const AStaticType: IStaticType);
|
||||
function Accept(const Visitor: IAstVisitor): TDataValue; override;
|
||||
function AsSeriesLength: ISeriesLengthNode; override;
|
||||
property Series: IIdentifierNode read FSeries write FSeries;
|
||||
@@ -516,7 +532,7 @@ end;
|
||||
|
||||
class function TAst.CreateSeries(const ADefinition: String): ICreateSeriesNode;
|
||||
begin
|
||||
Result := TCreateSeriesNode.Create(ADefinition);
|
||||
Result := TCreateSeriesNode.Create(ADefinition, TTypes.Unknown);
|
||||
end;
|
||||
|
||||
class function TAst.AddSeriesItem(
|
||||
@@ -525,44 +541,44 @@ class function TAst.AddSeriesItem(
|
||||
const ALookback: IAstNode = nil
|
||||
): IAddSeriesItemNode;
|
||||
begin
|
||||
Result := TAddSeriesItemNode.Create(ASeries, AValue, ALookback);
|
||||
Result := TAddSeriesItemNode.Create(ASeries, AValue, ALookback, TTypes.Unknown);
|
||||
end;
|
||||
|
||||
class function TAst.SeriesLength(const ASeries: IIdentifierNode): ISeriesLengthNode;
|
||||
begin
|
||||
Result := TSeriesLengthNode.Create(ASeries);
|
||||
Result := TSeriesLengthNode.Create(ASeries, TTypes.Unknown);
|
||||
end;
|
||||
|
||||
class function TAst.Assign(const AIdentifier: IIdentifierNode; const AValue: IAstNode): IAssignmentNode;
|
||||
begin
|
||||
Result := TAssignmentNode.Create(AIdentifier, AValue);
|
||||
Result := TAssignmentNode.Create(AIdentifier, AValue, TTypes.Unknown);
|
||||
end;
|
||||
|
||||
class function TAst.AssignResult(const AValue: IAstNode): IAssignmentNode;
|
||||
begin
|
||||
// The parser ensures 'Result' is a valid identifier, so we create one.
|
||||
// The binder will resolve it.
|
||||
Result := TAssignmentNode.Create(TAst.Identifier('Result'), AValue);
|
||||
Result := TAssignmentNode.Create(TAst.Identifier('Result'), AValue, TTypes.Unknown);
|
||||
end;
|
||||
|
||||
class function TAst.BinaryExpr(ALeft: IAstNode; AOperator: TScalar.TBinaryOp; ARight: IAstNode): IBinaryExpressionNode;
|
||||
begin
|
||||
Result := TBinaryExpressionNode.Create(ALeft, AOperator, ARight);
|
||||
Result := TBinaryExpressionNode.Create(ALeft, AOperator, ARight, TTypes.Unknown);
|
||||
end;
|
||||
|
||||
class function TAst.Block(const AExpressions: array of IAstNode): IBlockExpressionNode;
|
||||
begin
|
||||
Result := TBlockExpressionNode.Create(AExpressions);
|
||||
Result := TBlockExpressionNode.Create(AExpressions, TTypes.Unknown);
|
||||
end;
|
||||
|
||||
class function TAst.Constant(const AValue: TDataValue): IConstantNode;
|
||||
begin
|
||||
Result := TConstantNode.Create(AValue);
|
||||
Result := TConstantNode.Create(AValue, TTypes.Unknown);
|
||||
end;
|
||||
|
||||
class function TAst.Constant(const AValue: String): IConstantNode;
|
||||
begin
|
||||
Result := TConstantNode.Create(AValue);
|
||||
Result := TConstantNode.Create(AValue, TTypes.Unknown);
|
||||
end;
|
||||
|
||||
class constructor TAst.Create;
|
||||
@@ -575,6 +591,11 @@ begin
|
||||
FLibraries.Free;
|
||||
end;
|
||||
|
||||
class function TAst.BoundIdentifier(AName: string; const Address: TResolvedAddress): IBoundIdentifierNode;
|
||||
begin
|
||||
Result := TBoundIdentifierNode.Create(AName, Address, TTypes.Unknown);
|
||||
end;
|
||||
|
||||
class procedure TAst.RegisterLibrary(const AProc: TRegisterLibraryProc);
|
||||
begin
|
||||
FLibraries.Add(AProc);
|
||||
@@ -582,22 +603,22 @@ end;
|
||||
|
||||
class function TAst.FunctionCall(const ACallee: IAstNode; const AArguments: TArray<IAstNode>): IFunctionCallNode;
|
||||
begin
|
||||
Result := TFunctionCallNode.Create(ACallee, AArguments);
|
||||
Result := TFunctionCallNode.Create(ACallee, AArguments, TTypes.Unknown);
|
||||
end;
|
||||
|
||||
class function TAst.Identifier(AName: string): IIdentifierNode;
|
||||
begin
|
||||
Result := TIdentifierNode.Create(AName);
|
||||
Result := TIdentifierNode.Create(AName, TTypes.Unknown);
|
||||
end;
|
||||
|
||||
class function TAst.IfExpr(const ACondition: IAstNode; const AThenBranch, AElseBranch: IAstNode): IIfExpressionNode;
|
||||
begin
|
||||
Result := TIfExpressionNode.Create(ACondition, AThenBranch, AElseBranch);
|
||||
Result := TIfExpressionNode.Create(ACondition, AThenBranch, AElseBranch, TTypes.Unknown);
|
||||
end;
|
||||
|
||||
class function TAst.Indexer(const ABase: IAstNode; const AIndex: IAstNode): IIndexerNode;
|
||||
begin
|
||||
Result := TIndexerNode.Create(ABase, AIndex);
|
||||
Result := TIndexerNode.Create(ABase, AIndex, TTypes.Unknown);
|
||||
end;
|
||||
|
||||
class function TAst.Keyword(const AName: string): IKeywordNode;
|
||||
@@ -607,7 +628,7 @@ end;
|
||||
|
||||
class function TAst.LambdaExpr(const AParameters: TArray<IIdentifierNode>; const ABody: IAstNode): ILambdaExpressionNode;
|
||||
begin
|
||||
Result := TLambdaExpressionNode.Create(AParameters, ABody);
|
||||
Result := TLambdaExpressionNode.Create(AParameters, ABody, TTypes.Unknown);
|
||||
end;
|
||||
|
||||
class function TAst.MacroDef(
|
||||
@@ -621,12 +642,12 @@ end;
|
||||
|
||||
class function TAst.MacroExpansionNode(const AOriginalCallNode: IFunctionCallNode; const AExpandedBody: IAstNode): IMacroExpansionNode;
|
||||
begin
|
||||
Result := TMacroExpansionNode.Create(AOriginalCallNode, AExpandedBody);
|
||||
Result := TMacroExpansionNode.Create(AOriginalCallNode, AExpandedBody, TTypes.Unknown);
|
||||
end;
|
||||
|
||||
class function TAst.MemberAccess(const ABase: IAstNode; const AMember: IKeywordNode): IMemberAccessNode;
|
||||
begin
|
||||
Result := TMemberAccessNode.Create(ABase, AMember);
|
||||
Result := TMemberAccessNode.Create(ABase, AMember, TTypes.Unknown);
|
||||
end;
|
||||
|
||||
class function TAst.Nop: IAstNode;
|
||||
@@ -646,7 +667,7 @@ begin
|
||||
SetLength(args, Length(AArguments));
|
||||
for var i := 0 to High(AArguments) do
|
||||
args[i] := AArguments[i];
|
||||
Result := TRecurNode.Create(args);
|
||||
Result := TRecurNode.Create(args, TTypes.Unknown);
|
||||
end;
|
||||
|
||||
class function TAst.RecordLiteral(const AFields: TArray<TRecordFieldLiteral>): IRecordLiteralNode;
|
||||
@@ -654,17 +675,17 @@ begin
|
||||
// By default, the parser creates the generic (most flexible) node type.
|
||||
// The TypeChecker (Phase 3) is responsible for "lowering" this to a
|
||||
// TRecordLiteralNode if it determines all fields are scalar.
|
||||
Result := TGenericRecordLiteralNode.Create(AFields);
|
||||
Result := TGenericRecordLiteralNode.Create(AFields, TTypes.Unknown);
|
||||
end;
|
||||
|
||||
class function TAst.TernaryExpr(const ACondition: IAstNode; const AThenBranch, AElseBranch: IAstNode): ITernaryExpressionNode;
|
||||
begin
|
||||
Result := TTernaryExpressionNode.Create(ACondition, AThenBranch, AElseBranch);
|
||||
Result := TTernaryExpressionNode.Create(ACondition, AThenBranch, AElseBranch, TTypes.Unknown);
|
||||
end;
|
||||
|
||||
class function TAst.UnaryExpr(const AOperator: TScalar.TUnaryOp; const ARight: IAstNode): IUnaryExpressionNode;
|
||||
begin
|
||||
Result := TUnaryExpressionNode.Create(AOperator, ARight);
|
||||
Result := TUnaryExpressionNode.Create(AOperator, ARight, TTypes.Unknown);
|
||||
end;
|
||||
|
||||
class function TAst.Unquote(const AExpression: IAstNode): IUnquoteNode;
|
||||
@@ -679,7 +700,7 @@ end;
|
||||
|
||||
class function TAst.VarDecl(const AIdentifier: IIdentifierNode; AInitializer: IAstNode = nil): IVariableDeclarationNode;
|
||||
begin
|
||||
Result := TVariableDeclarationNode.Create(AIdentifier, AInitializer);
|
||||
Result := TVariableDeclarationNode.Create(AIdentifier, AInitializer, TTypes.Unknown);
|
||||
end;
|
||||
|
||||
{ TNopNode }
|
||||
@@ -687,8 +708,6 @@ end;
|
||||
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;
|
||||
@@ -711,7 +730,6 @@ end;
|
||||
constructor TAstNode.Create;
|
||||
begin
|
||||
inherited Create;
|
||||
FStaticType := TTypes.Unknown; // Default
|
||||
end;
|
||||
|
||||
function TAstNode.AsAddSeriesItem: IAddSeriesItemNode;
|
||||
@@ -825,6 +843,11 @@ begin
|
||||
raise ETypeException.Create('Node is not a TernaryExpression');
|
||||
end;
|
||||
|
||||
function TAstNode.AsTypedNode: IAstTypedNode;
|
||||
begin
|
||||
raise ETypeException.Create('Node has no type');
|
||||
end;
|
||||
|
||||
function TAstNode.AsUnaryExpression: IUnaryExpressionNode;
|
||||
begin
|
||||
raise ETypeException.Create('Node is not an UnaryExpression');
|
||||
@@ -845,16 +868,30 @@ begin
|
||||
raise ETypeException.Create('Node is not a VariableDeclaration');
|
||||
end;
|
||||
|
||||
procedure TAstNode.SetStaticType(const AValue: IStaticType);
|
||||
{ TAstTypedNode }
|
||||
|
||||
constructor TAstTypedNode.Create(const AStaticType: IStaticType);
|
||||
begin
|
||||
FStaticType := AValue;
|
||||
inherited Create;
|
||||
FStaticType := AStaticType;
|
||||
Assert(FStaticType <> nil);
|
||||
end;
|
||||
|
||||
function TAstTypedNode.AsTypedNode: IAstTypedNode;
|
||||
begin
|
||||
Result := Self;
|
||||
end;
|
||||
|
||||
function TAstTypedNode.GetStaticType: IStaticType;
|
||||
begin
|
||||
Result := FStaticType;
|
||||
end;
|
||||
|
||||
{ TConstantNode }
|
||||
|
||||
constructor TConstantNode.Create(const AValue: TDataValue);
|
||||
constructor TConstantNode.Create(const AValue: TDataValue; const AStaticType: IStaticType);
|
||||
begin
|
||||
inherited Create;
|
||||
inherited Create(AStaticType);
|
||||
FValue := AValue;
|
||||
end;
|
||||
|
||||
@@ -880,9 +917,9 @@ end;
|
||||
|
||||
{ TIdentifierNode }
|
||||
|
||||
constructor TIdentifierNode.Create(const AName: string);
|
||||
constructor TIdentifierNode.Create(const AName: string; const AStaticType: IStaticType);
|
||||
begin
|
||||
inherited Create;
|
||||
inherited Create(AStaticType);
|
||||
FName := AName;
|
||||
end;
|
||||
|
||||
@@ -910,7 +947,7 @@ end;
|
||||
|
||||
constructor TKeywordNode.Create(const AValue: IKeyword);
|
||||
begin
|
||||
inherited Create;
|
||||
inherited Create(TTypes.Keyword);
|
||||
FValue := AValue;
|
||||
end;
|
||||
|
||||
@@ -936,9 +973,14 @@ end;
|
||||
|
||||
{ TBinaryExpressionNode }
|
||||
|
||||
constructor TBinaryExpressionNode.Create(const ALeft: IAstNode; AOperator: TScalar.TBinaryOp; const ARight: IAstNode);
|
||||
constructor TBinaryExpressionNode.Create(
|
||||
const ALeft: IAstNode;
|
||||
AOperator: TScalar.TBinaryOp;
|
||||
const ARight: IAstNode;
|
||||
const AStaticType: IStaticType
|
||||
);
|
||||
begin
|
||||
inherited Create;
|
||||
inherited Create(AStaticType);
|
||||
FLeft := ALeft;
|
||||
FOperator := AOperator;
|
||||
FRight := ARight;
|
||||
@@ -976,9 +1018,9 @@ end;
|
||||
|
||||
{ TUnaryExpressionNode }
|
||||
|
||||
constructor TUnaryExpressionNode.Create(const AOperator: TScalar.TUnaryOp; const ARight: IAstNode);
|
||||
constructor TUnaryExpressionNode.Create(const AOperator: TScalar.TUnaryOp; const ARight: IAstNode; const AStaticType: IStaticType);
|
||||
begin
|
||||
inherited Create;
|
||||
inherited Create(AStaticType);
|
||||
FOperator := AOperator;
|
||||
FRight := ARight;
|
||||
end;
|
||||
@@ -1010,9 +1052,9 @@ end;
|
||||
|
||||
{ TIfExpressionNode }
|
||||
|
||||
constructor TIfExpressionNode.Create(const ACondition, AThenBranch, AElseBranch: IAstNode);
|
||||
constructor TIfExpressionNode.Create(const ACondition, AThenBranch, AElseBranch: IAstNode; const AStaticType: IStaticType);
|
||||
begin
|
||||
inherited Create;
|
||||
inherited Create(AStaticType);
|
||||
FCondition := ACondition;
|
||||
FThenBranch := AThenBranch;
|
||||
FElseBranch := AElseBranch;
|
||||
@@ -1050,9 +1092,9 @@ end;
|
||||
|
||||
{ TTernaryExpressionNode }
|
||||
|
||||
constructor TTernaryExpressionNode.Create(const ACondition, AThenBranch, AElseBranch: IAstNode);
|
||||
constructor TTernaryExpressionNode.Create(const ACondition, AThenBranch, AElseBranch: IAstNode; const AStaticType: IStaticType);
|
||||
begin
|
||||
inherited Create;
|
||||
inherited Create(AStaticType);
|
||||
FCondition := ACondition;
|
||||
FThenBranch := AThenBranch;
|
||||
FElseBranch := AElseBranch;
|
||||
@@ -1090,9 +1132,9 @@ end;
|
||||
|
||||
{ TLambdaExpressionNode }
|
||||
|
||||
constructor TLambdaExpressionNode.Create(const AParameters: TArray<IIdentifierNode>; const ABody: IAstNode);
|
||||
constructor TLambdaExpressionNode.Create(const AParameters: TArray<IIdentifierNode>; const ABody: IAstNode; const AStaticType: IStaticType);
|
||||
begin
|
||||
inherited Create;
|
||||
inherited Create(AStaticType);
|
||||
FParameters := AParameters;
|
||||
FBody := ABody;
|
||||
end;
|
||||
@@ -1254,9 +1296,9 @@ end;
|
||||
|
||||
{ TFunctionCallNode }
|
||||
|
||||
constructor TFunctionCallNode.Create(const ACallee: IAstNode; const AArguments: TArray<IAstNode>);
|
||||
constructor TFunctionCallNode.Create(const ACallee: IAstNode; const AArguments: TArray<IAstNode>; const AStaticType: IStaticType);
|
||||
begin
|
||||
inherited Create;
|
||||
inherited Create(AStaticType);
|
||||
FCallee := ACallee;
|
||||
FArguments := AArguments;
|
||||
FIsTailCall := False;
|
||||
@@ -1289,10 +1331,14 @@ end;
|
||||
|
||||
{ TMacroExpansionNode }
|
||||
|
||||
constructor TMacroExpansionNode.Create(const AOriginalCallNode: IFunctionCallNode; const AExpandedBody: IAstNode);
|
||||
constructor TMacroExpansionNode.Create(
|
||||
const AOriginalCallNode: IFunctionCallNode;
|
||||
const AExpandedBody: IAstNode;
|
||||
const AStaticType: IStaticType
|
||||
);
|
||||
begin
|
||||
// Copy properties from the original call node
|
||||
inherited Create(AOriginalCallNode.Callee, AOriginalCallNode.Arguments);
|
||||
inherited Create(AOriginalCallNode.Callee, AOriginalCallNode.Arguments, AStaticType);
|
||||
FExpandedBody := AExpandedBody;
|
||||
end;
|
||||
|
||||
@@ -1318,9 +1364,9 @@ end;
|
||||
|
||||
{ TRecurNode }
|
||||
|
||||
constructor TRecurNode.Create(const AArguments: TArray<IAstNode>);
|
||||
constructor TRecurNode.Create(const AArguments: TArray<IAstNode>; const AStaticType: IStaticType);
|
||||
begin
|
||||
inherited Create;
|
||||
inherited Create(AStaticType);
|
||||
FArguments := AArguments;
|
||||
end;
|
||||
|
||||
@@ -1346,11 +1392,11 @@ end;
|
||||
|
||||
{ TBlockExpressionNode }
|
||||
|
||||
constructor TBlockExpressionNode.Create(const AExpressions: array of IAstNode);
|
||||
constructor TBlockExpressionNode.Create(const AExpressions: array of IAstNode; const AStaticType: IStaticType);
|
||||
var
|
||||
i: Integer;
|
||||
begin
|
||||
inherited Create;
|
||||
inherited Create(AStaticType);
|
||||
SetLength(FExpressions, Length(AExpressions));
|
||||
for i := 0 to High(AExpressions) do
|
||||
FExpressions[i] := AExpressions[i];
|
||||
@@ -1378,9 +1424,9 @@ end;
|
||||
|
||||
{ TVariableDeclarationNode }
|
||||
|
||||
constructor TVariableDeclarationNode.Create(const AIdentifier: IIdentifierNode; AInitializer: IAstNode);
|
||||
constructor TVariableDeclarationNode.Create(const AIdentifier: IIdentifierNode; AInitializer: IAstNode; const AStaticType: IStaticType);
|
||||
begin
|
||||
inherited Create;
|
||||
inherited Create(AStaticType);
|
||||
FIdentifier := AIdentifier;
|
||||
FInitializer := AInitializer;
|
||||
FIsBoxed := False;
|
||||
@@ -1413,9 +1459,9 @@ end;
|
||||
|
||||
{ TAssignmentNode }
|
||||
|
||||
constructor TAssignmentNode.Create(const AIdentifier: IIdentifierNode; const AValue: IAstNode);
|
||||
constructor TAssignmentNode.Create(const AIdentifier: IIdentifierNode; const AValue: IAstNode; const AStaticType: IStaticType);
|
||||
begin
|
||||
inherited Create;
|
||||
inherited Create(AStaticType);
|
||||
FIdentifier := AIdentifier;
|
||||
FValue := AValue;
|
||||
end;
|
||||
@@ -1447,9 +1493,9 @@ end;
|
||||
|
||||
{ TIndexerNode }
|
||||
|
||||
constructor TIndexerNode.Create(const ABase: IAstNode; const AIndex: IAstNode);
|
||||
constructor TIndexerNode.Create(const ABase: IAstNode; const AIndex: IAstNode; const AStaticType: IStaticType);
|
||||
begin
|
||||
inherited Create;
|
||||
inherited Create(AStaticType);
|
||||
FBase := ABase;
|
||||
FIndex := AIndex;
|
||||
end;
|
||||
@@ -1481,9 +1527,9 @@ end;
|
||||
|
||||
{ TMemberAccessNode }
|
||||
|
||||
constructor TMemberAccessNode.Create(const ABase: IAstNode; const AMember: IKeywordNode);
|
||||
constructor TMemberAccessNode.Create(const ABase: IAstNode; const AMember: IKeywordNode; const AStaticType: IStaticType);
|
||||
begin
|
||||
inherited Create;
|
||||
inherited Create(AStaticType);
|
||||
FBase := ABase;
|
||||
FMember := AMember;
|
||||
end;
|
||||
@@ -1515,9 +1561,9 @@ end;
|
||||
|
||||
{ TRecordLiteralNode }
|
||||
|
||||
constructor TRecordLiteralNode.Create(const AFields: TArray<TRecordFieldLiteral>);
|
||||
constructor TRecordLiteralNode.Create(const AFields: TArray<TRecordFieldLiteral>; const AStaticType: IStaticType);
|
||||
begin
|
||||
inherited Create;
|
||||
inherited Create(AStaticType);
|
||||
FFields := AFields;
|
||||
end;
|
||||
|
||||
@@ -1543,16 +1589,16 @@ end;
|
||||
|
||||
{ TGenericRecordLiteralNode }
|
||||
|
||||
constructor TGenericRecordLiteralNode.Create(const AFields: TArray<TRecordFieldLiteral>);
|
||||
constructor TGenericRecordLiteralNode.Create(const AFields: TArray<TRecordFieldLiteral>; const AStaticType: IStaticType);
|
||||
begin
|
||||
inherited Create(AFields);
|
||||
inherited Create(AFields, AStaticType);
|
||||
end;
|
||||
|
||||
{ TCreateSeriesNode }
|
||||
|
||||
constructor TCreateSeriesNode.Create(const ADefinition: String);
|
||||
constructor TCreateSeriesNode.Create(const ADefinition: String; const AStaticType: IStaticType);
|
||||
begin
|
||||
inherited Create;
|
||||
inherited Create(AStaticType);
|
||||
FDefinition := ADefinition;
|
||||
end;
|
||||
|
||||
@@ -1578,9 +1624,14 @@ end;
|
||||
|
||||
{ TAddSeriesItemNode }
|
||||
|
||||
constructor TAddSeriesItemNode.Create(const ASeries: IIdentifierNode; const AValue: IAstNode; const ALookback: IAstNode);
|
||||
constructor TAddSeriesItemNode.Create(
|
||||
const ASeries: IIdentifierNode;
|
||||
const AValue: IAstNode;
|
||||
const ALookback: IAstNode;
|
||||
const AStaticType: IStaticType
|
||||
);
|
||||
begin
|
||||
inherited Create;
|
||||
inherited Create(AStaticType);
|
||||
FSeries := ASeries;
|
||||
FValue := AValue;
|
||||
FLookback := ALookback;
|
||||
@@ -1618,9 +1669,9 @@ end;
|
||||
|
||||
{ TSeriesLengthNode }
|
||||
|
||||
constructor TSeriesLengthNode.Create(const ASeries: IIdentifierNode);
|
||||
constructor TSeriesLengthNode.Create(const ASeries: IIdentifierNode; const AStaticType: IStaticType);
|
||||
begin
|
||||
inherited Create;
|
||||
inherited Create(AStaticType);
|
||||
FSeries := ASeries;
|
||||
end;
|
||||
|
||||
@@ -1646,9 +1697,9 @@ end;
|
||||
|
||||
{ TBoundIdentifierNode }
|
||||
|
||||
constructor TBoundIdentifierNode.Create(const AName: string; const AAddress: TResolvedAddress);
|
||||
constructor TBoundIdentifierNode.Create(const AName: string; const AAddress: TResolvedAddress; const AStaticType: IStaticType);
|
||||
begin
|
||||
inherited Create(AName);
|
||||
inherited Create(AName, AStaticType);
|
||||
FAddress := AAddress;
|
||||
end;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user