Ast series indexer
This commit is contained in:
@@ -127,6 +127,7 @@ type
|
||||
function VisitBlockExpression(const Node: IBlockExpressionNode): TAstValue;
|
||||
function VisitVariableDeclaration(const Node: IVariableDeclarationNode): TAstValue;
|
||||
function VisitAssignment(const Node: IAssignmentNode): TAstValue;
|
||||
function VisitIndexer(const Node: IIndexerNode): TAstValue;
|
||||
end;
|
||||
|
||||
TAuraWorkspace = class(TStyledControl)
|
||||
@@ -198,6 +199,7 @@ type
|
||||
function VisitBlockExpression(const Node: IBlockExpressionNode): TAstValue;
|
||||
function VisitVariableDeclaration(const Node: IVariableDeclarationNode): TAstValue;
|
||||
function VisitAssignment(const Node: IAssignmentNode): TAstValue;
|
||||
function VisitIndexer(const Node: IIndexerNode): TAstValue;
|
||||
end;
|
||||
|
||||
constructor TAstToTextVisitor.Create;
|
||||
@@ -264,6 +266,15 @@ begin
|
||||
Result := TAstValue.FromText(Node.Condition.Accept(Self).AsText);
|
||||
end;
|
||||
|
||||
function TAstToTextVisitor.VisitIndexer(const Node: IIndexerNode): TAstValue;
|
||||
var
|
||||
baseStr, indexStr: string;
|
||||
begin
|
||||
baseStr := Node.Base.Accept(Self).AsText;
|
||||
indexStr := Node.Index.Accept(Self).AsText;
|
||||
Result := TAstValue.FromText(Format('%s[%s]', [baseStr, indexStr]));
|
||||
end;
|
||||
|
||||
function TAstToTextVisitor.VisitLambdaExpression(const Node: ILambdaExpressionNode): TAstValue;
|
||||
var
|
||||
i: Integer;
|
||||
@@ -942,6 +953,46 @@ begin
|
||||
Result := TAstValue.Void;
|
||||
end;
|
||||
|
||||
function TAstToAuraNodeVisitor.VisitIndexer(const Node: IIndexerNode): TAstValue;
|
||||
var
|
||||
details: String;
|
||||
begin
|
||||
if (FMode = vmControlFlow) and TryGetDescr(Node, details) then
|
||||
begin
|
||||
var indexerNode := CreateNodeControl('Expression', details);
|
||||
FLastResult.OutputPin := CreateOutput(indexerNode);
|
||||
FinalizeNodeLayout(indexerNode);
|
||||
end
|
||||
else
|
||||
begin
|
||||
VisitOperatorNode(
|
||||
[Node.Base, Node.Index],
|
||||
function(const InputResults: TAuraNodeResultList): TAuraNodeResult
|
||||
var
|
||||
indexerNode: TAuraNode;
|
||||
basePin, indexPin, outPin: TControl;
|
||||
begin
|
||||
indexerNode := BuildNodeControl('[]', '');
|
||||
indexerNode.TitleFont.Size := 20;
|
||||
|
||||
basePin := CreateInput(indexerNode, 'Base');
|
||||
indexPin := CreateInput(indexerNode, 'Index');
|
||||
outPin := CreateOutput(indexerNode);
|
||||
|
||||
if Assigned(InputResults[0].OutputPin) then
|
||||
FConnections.Add(TPinConnection.Create(InputResults[0].OutputPin, basePin));
|
||||
if Assigned(InputResults[1].OutputPin) then
|
||||
FConnections.Add(TPinConnection.Create(InputResults[1].OutputPin, indexPin));
|
||||
|
||||
FinalizeNodeLayout(indexerNode);
|
||||
Result.LayoutNode := indexerNode;
|
||||
Result.OutputPin := outPin;
|
||||
end
|
||||
);
|
||||
end;
|
||||
Result := TAstValue.Void;
|
||||
end;
|
||||
|
||||
function TAstToAuraNodeVisitor.VisitLambdaExpression(const Node: ILambdaExpressionNode): TAstValue;
|
||||
var
|
||||
paramStr: String;
|
||||
@@ -1122,13 +1173,12 @@ end;
|
||||
|
||||
function TAstToAuraNodeVisitor.VisitVariableDeclaration(const Node: IVariableDeclarationNode): TAstValue;
|
||||
var
|
||||
varDeclNode: TAuraNode;
|
||||
outPin: TControl;
|
||||
begin
|
||||
var details: String;
|
||||
if (FMode = vmControlFlow) and TryGetDescr(Node, details) then
|
||||
begin
|
||||
varDeclNode := CreateNodeControl('VarDecl', details);
|
||||
var varDeclNode := CreateNodeControl('VarDecl', details);
|
||||
CreateEntry(varDeclNode);
|
||||
CreateExit(varDeclNode, '');
|
||||
FinalizeNodeLayout(varDeclNode);
|
||||
@@ -1137,40 +1187,39 @@ begin
|
||||
begin
|
||||
if Assigned(Node.Initializer) then
|
||||
begin
|
||||
varDeclNode :=
|
||||
VisitOperatorNode(
|
||||
[Node.Initializer],
|
||||
function(const InputResults: TAuraNodeResultList): TAuraNodeResult
|
||||
var
|
||||
varDeclNode: TAuraNode;
|
||||
inputPin: TControl;
|
||||
initializerResult: TAuraNodeResult;
|
||||
outPin: TControl; // variable for the output pin
|
||||
begin
|
||||
initializerResult := InputResults[0];
|
||||
varDeclNode := BuildNodeControl('VarDecl', Node.Identifier.Name);
|
||||
VisitOperatorNode(
|
||||
[Node.Initializer],
|
||||
function(const InputResults: TAuraNodeResultList): TAuraNodeResult
|
||||
var
|
||||
varDeclNode: TAuraNode;
|
||||
inputPin: TControl;
|
||||
initializerResult: TAuraNodeResult;
|
||||
outPin: TControl; // variable for the output pin
|
||||
begin
|
||||
initializerResult := InputResults[0];
|
||||
varDeclNode := BuildNodeControl('VarDecl', Node.Identifier.Name);
|
||||
|
||||
CreateEntry(varDeclNode);
|
||||
inputPin := CreateInput(varDeclNode, 'Value');
|
||||
CreateExit(varDeclNode, '');
|
||||
CreateEntry(varDeclNode);
|
||||
inputPin := CreateInput(varDeclNode, 'Value');
|
||||
CreateExit(varDeclNode, '');
|
||||
|
||||
// Create the output pin before finalizing the layout.
|
||||
outPin := CreateOutput(varDeclNode);
|
||||
// Create the output pin before finalizing the layout.
|
||||
outPin := CreateOutput(varDeclNode);
|
||||
|
||||
if Assigned(initializerResult.OutputPin) then
|
||||
FConnections.Add(TPinConnection.Create(initializerResult.OutputPin, inputPin));
|
||||
if Assigned(initializerResult.OutputPin) then
|
||||
FConnections.Add(TPinConnection.Create(initializerResult.OutputPin, inputPin));
|
||||
|
||||
// Now finalize, all pins are present.
|
||||
FinalizeNodeLayout(varDeclNode);
|
||||
Result.LayoutNode := varDeclNode;
|
||||
Result.OutputPin := outPin;
|
||||
end
|
||||
);
|
||||
// Now finalize, all pins are present.
|
||||
FinalizeNodeLayout(varDeclNode);
|
||||
Result.LayoutNode := varDeclNode;
|
||||
Result.OutputPin := outPin;
|
||||
end
|
||||
);
|
||||
end
|
||||
else
|
||||
begin
|
||||
// Case without initializer is a simple sequential node.
|
||||
varDeclNode := CreateNodeControl('VarDecl', Node.Identifier.Name);
|
||||
var varDeclNode := CreateNodeControl('VarDecl', Node.Identifier.Name);
|
||||
CreateEntry(varDeclNode);
|
||||
CreateExit(varDeclNode, '');
|
||||
// Create the output pin before finalizing the layout.
|
||||
|
||||
Reference in New Issue
Block a user