Ast series indexer
This commit is contained in:
@@ -33,6 +33,8 @@ type
|
||||
class function VarDecl(const AIdentifier: IIdentifierNode; AInitializer: IExpressionNode): IVariableDeclarationNode; static;
|
||||
class function Assign(const AIdentifier: IIdentifierNode; const AValue: IExpressionNode): IAssignmentNode; static;
|
||||
class function AssignResult(const AValue: IExpressionNode): IAssignmentNode; static;
|
||||
// Added factory for the new indexer node.
|
||||
class function Indexer(const ABase: IExpressionNode; const AIndex: IExpressionNode): IIndexerNode; static;
|
||||
end;
|
||||
|
||||
implementation
|
||||
@@ -183,6 +185,19 @@ type
|
||||
function Accept(const Visitor: IAstVisitor): TAstValue; override;
|
||||
end;
|
||||
|
||||
{ TIndexerNode }
|
||||
// Concrete implementation for the indexer node.
|
||||
TIndexerNode = class(TAstNode, IIndexerNode)
|
||||
private
|
||||
FBase: IExpressionNode;
|
||||
FIndex: IExpressionNode;
|
||||
function GetBase: IExpressionNode;
|
||||
function GetIndex: IExpressionNode;
|
||||
public
|
||||
constructor Create(const ABase: IExpressionNode; const AIndex: IExpressionNode);
|
||||
function Accept(const Visitor: IAstVisitor): TAstValue; override;
|
||||
end;
|
||||
|
||||
{ TConstantNode }
|
||||
|
||||
constructor TConstantNode.Create(AValue: TScalar);
|
||||
@@ -467,6 +482,30 @@ begin
|
||||
Result := FValue;
|
||||
end;
|
||||
|
||||
{ TIndexerNode }
|
||||
|
||||
constructor TIndexerNode.Create(const ABase, AIndex: IExpressionNode);
|
||||
begin
|
||||
inherited Create;
|
||||
FBase := ABase;
|
||||
FIndex := AIndex;
|
||||
end;
|
||||
|
||||
function TIndexerNode.Accept(const Visitor: IAstVisitor): TAstValue;
|
||||
begin
|
||||
Result := Visitor.VisitIndexer(Self);
|
||||
end;
|
||||
|
||||
function TIndexerNode.GetBase: IExpressionNode;
|
||||
begin
|
||||
Result := FBase;
|
||||
end;
|
||||
|
||||
function TIndexerNode.GetIndex: IExpressionNode;
|
||||
begin
|
||||
Result := FIndex;
|
||||
end;
|
||||
|
||||
{ TAst }
|
||||
|
||||
class function TAst.Assign(const AIdentifier: IIdentifierNode; const AValue: IExpressionNode): IAssignmentNode;
|
||||
@@ -509,6 +548,11 @@ begin
|
||||
Result := TIfExpressionNode.Create(ACondition, AThenBranch, AElseBranch);
|
||||
end;
|
||||
|
||||
class function TAst.Indexer(const ABase, AIndex: IExpressionNode): IIndexerNode;
|
||||
begin
|
||||
Result := TIndexerNode.Create(ABase, AIndex);
|
||||
end;
|
||||
|
||||
class function TAst.TernaryExpr(const ACondition, AThenBranch, AElseBranch: IExpressionNode): ITernaryExpressionNode;
|
||||
begin
|
||||
Result := TTernaryExpressionNode.Create(ACondition, AThenBranch, AElseBranch);
|
||||
|
||||
Reference in New Issue
Block a user