AST development

This commit is contained in:
Michael Schimmel
2025-08-30 15:39:35 +02:00
parent 59e71b6d7b
commit f00676a935
6 changed files with 169 additions and 93 deletions
+3 -3
View File
@@ -5,9 +5,9 @@
<FrameworkType>FMX</FrameworkType> <FrameworkType>FMX</FrameworkType>
<Base>True</Base> <Base>True</Base>
<Config Condition="'$(Config)'==''">Debug</Config> <Config Condition="'$(Config)'==''">Debug</Config>
<Platform Condition="'$(Platform)'==''">Win32</Platform> <Platform Condition="'$(Platform)'==''">Win64</Platform>
<ProjectName Condition="'$(ProjectName)'==''">ASTPlayground</ProjectName> <ProjectName Condition="'$(ProjectName)'==''">ASTPlayground</ProjectName>
<TargetedPlatforms>3</TargetedPlatforms> <TargetedPlatforms>2</TargetedPlatforms>
<AppType>Application</AppType> <AppType>Application</AppType>
<MainSource>ASTPlayground.dpr</MainSource> <MainSource>ASTPlayground.dpr</MainSource>
</PropertyGroup> </PropertyGroup>
@@ -1142,7 +1142,7 @@
<ProjectRoot Platform="Win64x" Name="$(PROJECTNAME)"/> <ProjectRoot Platform="Win64x" Name="$(PROJECTNAME)"/>
</Deployment> </Deployment>
<Platforms> <Platforms>
<Platform value="Win32">True</Platform> <Platform value="Win32">False</Platform>
<Platform value="Win64">True</Platform> <Platform value="Win64">True</Platform>
</Platforms> </Platforms>
</BorlandProject> </BorlandProject>
Binary file not shown.
+1
View File
@@ -88,6 +88,7 @@ begin
FWorkspace := TAuraWorkspace.Create(Panel2); FWorkspace := TAuraWorkspace.Create(Panel2);
FWorkspace.Parent := Panel2; FWorkspace.Parent := Panel2;
FWorkspace.Align := TAlignLayout.Client; FWorkspace.Align := TAlignLayout.Client;
FWorkspace.ClipChildren := true;
FWorkspace.OnMouseDown := WorkspaceMouseDown; FWorkspace.OnMouseDown := WorkspaceMouseDown;
+162 -87
View File
@@ -16,21 +16,33 @@ uses
DraggablePanel; DraggablePanel;
type type
// Record to store a connection between two pins // ... TPinConnection, TPinShape, TPinAlignment, TAuraWorkspace ...
TPinConnection = record TPinConnection = record
OutputPin: TControl; OutputPin: TControl;
InputPin: TControl; InputPin: TControl;
constructor Create(AOutputPin, AInputPin: TControl); constructor Create(AOutputPin, AInputPin: TControl);
end; end;
// Defines the shape of a pin.
TPinShape = (psCircle, psTriangle); TPinShape = (psCircle, psTriangle);
// Defines the horizontal alignment of a pin on a node.
TPinAlignment = (paLeft, paRight); TPinAlignment = (paLeft, paRight);
TAuraWorkspace = class; TAuraWorkspace = class;
TAstToAuraNodeVisitor = class(TInterfacedObject, IAstVisitor) TAstToAuraNodeVisitor = class(TInterfacedObject, IAstVisitor)
const
// Pin Visuals
cPinSize = 10;
cDataPinColor = TAlphaColors.Dodgerblue;
cExecPinColor = TAlphaColors.Lightgreen;
// Node Layout
cHorizontalPadding = 25; // Padding inside the node title bar
cPinOffsetY = 18; // Vertical distance between pins
cVerticalPadding = 20; // General vertical padding inside container nodes
// Specific Node Heights
cDefaultNodeHeight = 45; // Default height for simple nodes like BinaryExpr
cIfNodeHeight = 60; // Taller height for If nodes with more pins
private private
FWorkspace: TAuraWorkspace; FWorkspace: TAuraWorkspace;
FParentControl: TControl; FParentControl: TControl;
@@ -46,9 +58,15 @@ type
AColor: TAlphaColor; AColor: TAlphaColor;
const ATag: string; const ATag: string;
AOffsetY: Single = 0 AOffsetY: Single = 0
): TControl; ): TShape;
function CreateInput(AParentNode: TAuraNode; const ACaption: string; AOffsetY: Single = 0): TControl;
function CreateOutput(AParentNode: TAuraNode; AOffsetY: Single = 0): TControl;
function CreateEntry(AParentNode: TAuraNode; AOffsetY: Single = 0): TControl;
function CreateExit(AParentNode: TAuraNode; const ACaption: string; AOffsetY: Single = 0): TControl;
function FindPinByTag(AParentNode: TAuraNode; const ATag: string): TControl; function FindPinByTag(AParentNode: TAuraNode; const ATag: string): TControl;
function ConnectPins(InputPin: TControl; OutputNode: TAuraNode; const Tag: string): TControl; function ConnectData(InputPin: TControl; OutputNode: TAuraNode): TControl;
public public
constructor Create( constructor Create(
AWorkspace: TAuraWorkspace; AWorkspace: TAuraWorkspace;
@@ -148,17 +166,39 @@ begin
FConnections := AConnections; FConnections := AConnections;
end; end;
function TAstToAuraNodeVisitor.ConnectPins(InputPin: TControl; OutputNode: TAuraNode; const Tag: string): TControl; function TAstToAuraNodeVisitor.ConnectData(InputPin: TControl; OutputNode: TAuraNode): TControl;
begin begin
Result := FindPinByTag(OutputNode, Tag); Result := FindPinByTag(OutputNode, 'data.out');
if Assigned(Result) then if Assigned(Result) then
FConnections.Add(TPinConnection.Create(Result, InputPin)); FConnections.Add(TPinConnection.Create(Result, InputPin));
end; end;
function TAstToAuraNodeVisitor.CreateInput(AParentNode: TAuraNode; const ACaption: string; AOffsetY: Single = 0): TControl;
begin
Result := CreatePin(AParentNode, psCircle, paLeft, cDataPinColor, 'data.in.' + ACaption, AOffsetY);
Result.Hint := ACaption;
Result.ShowHint := ACaption <> '';
end;
function TAstToAuraNodeVisitor.CreateOutput(AParentNode: TAuraNode; AOffsetY: Single = 0): TControl;
begin
Result := CreatePin(AParentNode, psCircle, paRight, cDataPinColor, 'data.out', AOffsetY);
end;
function TAstToAuraNodeVisitor.CreateEntry(AParentNode: TAuraNode; AOffsetY: Single = 0): TControl;
begin
Result := CreatePin(AParentNode, psTriangle, paLeft, cExecPinColor, 'exec.in', AOffsetY);
end;
function TAstToAuraNodeVisitor.CreateExit(AParentNode: TAuraNode; const ACaption: string; AOffsetY: Single = 0): TControl;
begin
var cap := ACaption;
if cap <> '' then
cap := '.' + cap;
Result := CreatePin(AParentNode, psTriangle, paRight, cExecPinColor, 'exec.out' + cap, AOffsetY);
end;
function TAstToAuraNodeVisitor.CreateNodeControl(const ATitle, ADetails: string): TAuraNode; function TAstToAuraNodeVisitor.CreateNodeControl(const ATitle, ADetails: string): TAuraNode;
const
// Horizontal padding on each side of the title to ensure text and pins are fully visible.
cHorizontalPadding = 25;
var var
LFullTitle: string; LFullTitle: string;
LTextWidth: Single; LTextWidth: Single;
@@ -199,10 +239,8 @@ function TAstToAuraNodeVisitor.CreatePin(
AAlignment: TPinAlignment; AAlignment: TPinAlignment;
AColor: TAlphaColor; AColor: TAlphaColor;
const ATag: string; const ATag: string;
AOffsetY: Single AOffsetY: Single = 0
): TControl; ): TShape;
const
cPinSize = 10;
var var
LPosX, LPosY: Single; LPosX, LPosY: Single;
begin begin
@@ -240,7 +278,7 @@ begin
// Common properties // Common properties
Result.Parent := AParentNode; Result.Parent := AParentNode;
Result.SetBounds(LPosX, LPosY, cPinSize, cPinSize); Result.SetBounds(LPosX, LPosY, cPinSize, cPinSize);
Result.HitTest := False; Result.HitTest := true;
// Use TagString to identify the control as a pin and describe its function. // Use TagString to identify the control as a pin and describe its function.
Result.TagString := ATag; Result.TagString := ATag;
@@ -265,9 +303,6 @@ begin
end; end;
function TAstToAuraNodeVisitor.VisitAssignment(const Node: IAssignmentNode): TAstValue; function TAstToAuraNodeVisitor.VisitAssignment(const Node: IAssignmentNode): TAstValue;
const
cExecPinColor = TAlphaColors.Lightgreen;
cDataPinColor = TAlphaColors.Dodgerblue;
var var
LAssignmentNode, LValueNode: TAuraNode; LAssignmentNode, LValueNode: TAuraNode;
LInputPin: TControl; LInputPin: TControl;
@@ -285,12 +320,12 @@ begin
// Create the assignment node and its pins // Create the assignment node and its pins
LAssignmentNode := CreateNodeControl('Assignment', Node.Identifier.Name); LAssignmentNode := CreateNodeControl('Assignment', Node.Identifier.Name);
CreatePin(LAssignmentNode, psTriangle, paLeft, cExecPinColor, 'Pin.Exec.In', -8); CreateEntry(LAssignmentNode, 0);
CreatePin(LAssignmentNode, psTriangle, paRight, cExecPinColor, 'Pin.Exec.Out'); CreateExit(LAssignmentNode, '', 0);
LInputPin := CreatePin(LAssignmentNode, psCircle, paLeft, cDataPinColor, 'Pin.Data.In', 8); LInputPin := CreateInput(LAssignmentNode, Node.Identifier.Name, 0);
// Connect the value to the assignment // Connect the value to the assignment
ConnectPins(LInputPin, LValueNode, 'Pin.Data.Out'); ConnectData(LInputPin, LValueNode);
// Finalize visitor state // Finalize visitor state
FCurrentPos.X := LStartPosition.X; FCurrentPos.X := LStartPosition.X;
@@ -301,9 +336,6 @@ begin
end; end;
function TAstToAuraNodeVisitor.VisitBinaryExpression(const Node: IBinaryExpressionNode): TAstValue; function TAstToAuraNodeVisitor.VisitBinaryExpression(const Node: IBinaryExpressionNode): TAstValue;
const
cDataPinColor = TAlphaColors.Dodgerblue;
cDefaultHeight = 45;
var var
LBinaryExprNode, LLeftNode, LRightNode: TAuraNode; LBinaryExprNode, LLeftNode, LRightNode: TAuraNode;
LInputPin1, LInputPin2: TControl; LInputPin1, LInputPin2: TControl;
@@ -329,20 +361,21 @@ begin
// Vertically center the binary expression node between its children // Vertically center the binary expression node between its children
var LTotalChildHeight := LRightEndY - LStartPosition.Y; var LTotalChildHeight := LRightEndY - LStartPosition.Y;
var LNodeCenterY := LStartPosition.Y + (LTotalChildHeight / 2); var LNodeCenterY := LStartPosition.Y + (LTotalChildHeight / 2);
FCurrentPos.Y := LNodeCenterY - (cDefaultHeight / 2); FCurrentPos.Y := LNodeCenterY - (cDefaultNodeHeight / 2);
LBinaryExprNode := CreateNodeControl(Node.Operator.ToString, ''); LBinaryExprNode := CreateNodeControl(Node.Operator.ToString, '');
LBinaryExprNode.TitleFont.Size := 20;
// Create pins for the binary expression node // Create pins for the binary expression node
LInputPin1 := CreatePin(LBinaryExprNode, psCircle, paLeft, cDataPinColor, 'Pin.Data.In.1', -8); LInputPin1 := CreateInput(LBinaryExprNode, LLeftNode.Name, -8);
LInputPin2 := CreatePin(LBinaryExprNode, psCircle, paLeft, cDataPinColor, 'Pin.Data.In.2', 8); LInputPin2 := CreateInput(LBinaryExprNode, LRightNode.Name, 8);
CreatePin(LBinaryExprNode, psCircle, paRight, cDataPinColor, 'Pin.Data.Out', 0); CreateOutput(LBinaryExprNode, 0);
// Connect the output of the left child to the first input of the binary node // Connect the output of the left child to the first input of the binary node
ConnectPins(LInputPin1, LLeftNode, 'Pin.Data.Out'); ConnectData(LInputPin1, LLeftNode);
// Connect the output of the right child to the second input of the binary node // Connect the output of the right child to the second input of the binary node
ConnectPins(LInputPin2, LRightNode, 'Pin.Data.Out'); ConnectData(LInputPin2, LRightNode);
// Finalize visitor state for the next node at this level // Finalize visitor state for the next node at this level
FCurrentPos.X := LStartPosition.X; FCurrentPos.X := LStartPosition.X;
@@ -404,67 +437,109 @@ begin
end; end;
function TAstToAuraNodeVisitor.VisitConstant(const Node: IConstantNode): TAstValue; function TAstToAuraNodeVisitor.VisitConstant(const Node: IConstantNode): TAstValue;
const
cDataPinColor = TAlphaColors.Dodgerblue;
var var
LConstantNode: TAuraNode; LConstantNode: TAuraNode;
begin begin
// A constant has a data output pin. // A constant has a data output pin.
// Data outputs are round and on the right side of the box. // Data outputs are round and on the right side of the box.
LConstantNode := CreateNodeControl('Constant', Node.Value.ToString); LConstantNode := CreateNodeControl('Constant', Node.Value.ToString);
CreatePin(LConstantNode, psCircle, paRight, cDataPinColor, 'Pin.Data.Out', 0); CreateOutput(LConstantNode, 0);
Result := TAstValue.Void; Result := TAstValue.Void;
end; end;
function TAstToAuraNodeVisitor.VisitFunctionCall(const Node: IFunctionCallNode): TAstValue; function TAstToAuraNodeVisitor.VisitFunctionCall(const Node: IFunctionCallNode): TAstValue;
var var
Arg: IExpressionNode; LFuncCallNode: TAuraNode;
LInputResultNodes: TList<TAuraNode>;
LInputNode: IExpressionNode;
LStartPosition: TPointF;
LEndY, LMaxChildWidth: Single;
i: Integer;
LCalleePin: TControl;
LArgPin: array of TControl;
LCurrentInputOffsetY, LCurrentOutputOffsetY: Single;
begin begin
CreateNodeControl('FunctionCall', ''); LStartPosition := FCurrentPos;
FCurrentPos.X := FCurrentPos.X + FSpacing.X; LInputResultNodes := TList<TAuraNode>.Create;
try try
// Callee // 1. Visit all input nodes first (Callee + Arguments) and collect their visual representations.
CreateNodeControl('Callee', ''); Node.Callee.Accept(Self);
FCurrentPos.X := FCurrentPos.X + FSpacing.X; LInputResultNodes.Add(FLastNode);
try
Node.Callee.Accept(Self); for LInputNode in Node.Arguments do
finally begin
FCurrentPos.X := FCurrentPos.X - FSpacing.X; LInputNode.Accept(Self);
LInputResultNodes.Add(FLastNode);
end;
LEndY := FCurrentPos.Y;
// 2. Determine the layout bounds of the input nodes.
LMaxChildWidth := 0;
for var LNode in LInputResultNodes do
LMaxChildWidth := Max(LMaxChildWidth, LNode.Position.X + LNode.Width);
// 3. Position and create the 'FunctionCall' node to the right of the inputs.
FCurrentPos.X := LMaxChildWidth + FSpacing.X;
// Calculate dynamic height based on the number of pins
var LNumInputPins := 2 + Node.Arguments.Count;
var LNumOutputPins := 2;
var LMaxPins := Max(LNumInputPins, LNumOutputPins);
var LNodeHeight := cVerticalPadding + (LMaxPins - 1) * cPinOffsetY;
var LTotalInputHeight := LEndY - LStartPosition.Y;
var LNodeCenterY := LStartPosition.Y + (LTotalInputHeight / 2);
FCurrentPos.Y := LNodeCenterY - (LNodeHeight / 2);
LFuncCallNode := CreateNodeControl('FunctionCall', '');
LFuncCallNode.Height := LNodeHeight;
// 4. Create all necessary pins on the 'FunctionCall' node with proper spacing.
// Left side (Inputs)
LCurrentInputOffsetY := -(LNumInputPins - 1) / 2.0 * cPinOffsetY;
CreateEntry(LFuncCallNode, LCurrentInputOffsetY);
LCurrentInputOffsetY := LCurrentInputOffsetY + cPinOffsetY;
LCalleePin := CreateInput(LFuncCallNode, LInputResultNodes[0].Name, LCurrentInputOffsetY);
LCurrentInputOffsetY := LCurrentInputOffsetY + cPinOffsetY;
SetLength(LArgPin, Node.Arguments.Count);
for i := 0 to Node.Arguments.Count - 1 do
begin
LArgPin[i] := CreateInput(LFuncCallNode, LInputResultNodes[i + 1].Name + i.ToString, LCurrentInputOffsetY);
LCurrentInputOffsetY := LCurrentInputOffsetY + cPinOffsetY;
end; end;
// Arguments // Right side (Outputs)
if Node.Arguments.Count > 0 then LCurrentOutputOffsetY := -(LNumOutputPins - 1) / 2.0 * cPinOffsetY;
begin CreateExit(LFuncCallNode, '', LCurrentOutputOffsetY);
CreateNodeControl('Arguments', ''); LCurrentOutputOffsetY := LCurrentOutputOffsetY + cPinOffsetY;
FCurrentPos.X := FCurrentPos.X + FSpacing.X; CreateOutput(LFuncCallNode, LCurrentOutputOffsetY);
try
for Arg in Node.Arguments do // 5. Connect the inputs.
Arg.Accept(Self); ConnectData(LCalleePin, LInputResultNodes[0]);
finally for i := 0 to Node.Arguments.Count - 1 do
FCurrentPos.X := FCurrentPos.X - FSpacing.X; ConnectData(LArgPin[i], LInputResultNodes[i + 1]);
end;
end;
finally finally
FCurrentPos.X := FCurrentPos.X - FSpacing.X; LInputResultNodes.Free;
end; end;
// 6. Finalize visitor state.
FCurrentPos.X := LStartPosition.X;
FCurrentPos.Y := Max(LEndY, LFuncCallNode.Position.Y + LFuncCallNode.Height + FSpacing.Y);
FLastNode := LFuncCallNode;
Result := TAstValue.Void; Result := TAstValue.Void;
end; end;
function TAstToAuraNodeVisitor.VisitIdentifier(const Node: IIdentifierNode): TAstValue; function TAstToAuraNodeVisitor.VisitIdentifier(const Node: IIdentifierNode): TAstValue;
const
cDataPinColor = TAlphaColors.Dodgerblue;
begin begin
CreateNodeControl('Identifier', Node.Name); CreateNodeControl('Identifier', Node.Name);
// Add a data output pin on the right side. // Add a data output pin on the right side.
CreatePin(FLastNode, psCircle, paRight, cDataPinColor, 'Pin.Data.Out'); CreateOutput(FLastNode, 0);
Result := TAstValue.Void; Result := TAstValue.Void;
end; end;
function TAstToAuraNodeVisitor.VisitIfExpression(const Node: IIfExpressionNode): TAstValue; function TAstToAuraNodeVisitor.VisitIfExpression(const Node: IIfExpressionNode): TAstValue;
const
cExecPinColor = TAlphaColors.Lightgreen;
cDataPinColor = TAlphaColors.Dodgerblue;
cDefaultHeight = 60; // Taller to accommodate more pins
var var
LIfNode, LConditionNode, LThenNode, LElseNode: TAuraNode; LIfNode, LConditionNode, LThenNode, LElseNode: TAuraNode;
LConditionInputPin, LThenOutputPin, LElseOutputPin: TControl; LConditionInputPin, LThenOutputPin, LElseOutputPin: TControl;
@@ -481,20 +556,20 @@ begin
// Position and create the 'If' node to the right of the condition's subtree. // Position and create the 'If' node to the right of the condition's subtree.
LMaxChildWidth := LConditionNode.Position.X + LConditionNode.Width; LMaxChildWidth := LConditionNode.Position.X + LConditionNode.Width;
FCurrentPos.X := LMaxChildWidth + FSpacing.X; FCurrentPos.X := LMaxChildWidth + FSpacing.X;
FCurrentPos.Y := LStartPosition.Y + (LConditionNode.Position.Y + LConditionNode.Height / 2) - LStartPosition.Y - (cDefaultHeight / 2); FCurrentPos.Y := LStartPosition.Y + (LConditionNode.Position.Y + LConditionNode.Height / 2) - LStartPosition.Y - (cIfNodeHeight / 2);
LIfNode := CreateNodeControl('If', ''); LIfNode := CreateNodeControl('If', '');
LIfNode.Height := cDefaultHeight; LIfNode.Height := cIfNodeHeight;
CreatePin(LIfNode, psTriangle, paLeft, cExecPinColor, 'Pin.Exec.In', -12); CreateEntry(LIfNode, -12);
LConditionInputPin := CreatePin(LIfNode, psCircle, paLeft, cDataPinColor, 'Pin.Data.In.Condition', 12); LConditionInputPin := CreateInput(LIfNode, 'Condition', 12);
LThenOutputPin := CreatePin(LIfNode, psTriangle, paRight, cExecPinColor, 'Pin.Exec.Out.Then', -12); LThenOutputPin := CreateExit(LIfNode, 'Then', -12);
if Assigned(Node.ElseBranch) then if Assigned(Node.ElseBranch) then
LElseOutputPin := CreatePin(LIfNode, psTriangle, paRight, cExecPinColor, 'Pin.Exec.Out.Else', 12) LElseOutputPin := CreateExit(LIfNode, 'Else', 12)
else else
LElseOutputPin := nil; LElseOutputPin := nil;
// Connect the condition's output to the 'If' node's data input. // Connect the condition's output to the 'If' node's data input.
ConnectPins(LConditionInputPin, LConditionNode, 'Pin.Data.Out'); ConnectData(LConditionInputPin, LConditionNode);
// Visit the 'Then' and 'Else' execution branches, placing them to the right of the 'If' node. // Visit the 'Then' and 'Else' execution branches, placing them to the right of the 'If' node.
var LBranchStartX := LIfNode.Position.X + LIfNode.Width + FSpacing.X; var LBranchStartX := LIfNode.Position.X + LIfNode.Width + FSpacing.X;
@@ -505,7 +580,7 @@ begin
Node.ThenBranch.Accept(Self); Node.ThenBranch.Accept(Self);
LThenNode := FLastNode; LThenNode := FLastNode;
LThenEndY := FCurrentPos.Y; LThenEndY := FCurrentPos.Y;
// ConnectPins(FindPinByTag(LThenNode, 'Pin.Exec.In'), LIfNode, 'Pin.Exec.Out.Then'); // ConnectData(FindPinByTag(LThenNode, 'Pin.Exec.In'), LIfNode, 'Pin.Exec.Out.Then');
// Else branch (if it exists) // Else branch (if it exists)
LElseEndY := LThenEndY; LElseEndY := LThenEndY;
@@ -516,7 +591,7 @@ begin
Node.ElseBranch.Accept(Self); Node.ElseBranch.Accept(Self);
LElseNode := FLastNode; LElseNode := FLastNode;
LElseEndY := FCurrentPos.Y; LElseEndY := FCurrentPos.Y;
// ConnectPins(FindPinByTag(LElseNode, 'Pin.Exec.In'), LIfNode, 'Pin.Exec.Out.Else'); // ConnectData(FindPinByTag(LElseNode, 'Pin.Exec.In'), LIfNode, 'Pin.Exec.Out.Else');
end; end;
// Finalize visitor state. // Finalize visitor state.
@@ -528,9 +603,6 @@ begin
end; end;
function TAstToAuraNodeVisitor.VisitLambdaExpression(const Node: ILambdaExpressionNode): TAstValue; function TAstToAuraNodeVisitor.VisitLambdaExpression(const Node: ILambdaExpressionNode): TAstValue;
const
cExecPinColor = TAlphaColors.Lightgreen;
cDataPinColor = TAlphaColors.Dodgerblue;
var var
ParamStr: String; ParamStr: String;
LLambdaNode: TAuraNode; LLambdaNode: TAuraNode;
@@ -578,7 +650,7 @@ begin
LLambdaNode.Height := Max(LLambdaNode.Height, LMaxBottom + FSpacing.Y); LLambdaNode.Height := Max(LLambdaNode.Height, LMaxBottom + FSpacing.Y);
// Add a data output pin for the resulting closure. // Add a data output pin for the resulting closure.
CreatePin(LLambdaNode, psCircle, paRight, cDataPinColor, 'Pin.Data.Out'); CreateOutput(LLambdaNode, 0);
// Update the current Y position of the main visitor to be below the now correctly sized lambda node. // Update the current Y position of the main visitor to be below the now correctly sized lambda node.
FCurrentPos.Y := LLambdaNode.Position.Y + LLambdaNode.Height + FSpacing.Y; FCurrentPos.Y := LLambdaNode.Position.Y + LLambdaNode.Height + FSpacing.Y;
@@ -599,10 +671,6 @@ begin
end; end;
function TAstToAuraNodeVisitor.VisitVariableDeclaration(const Node: IVariableDeclarationNode): TAstValue; function TAstToAuraNodeVisitor.VisitVariableDeclaration(const Node: IVariableDeclarationNode): TAstValue;
const
cExecPinColor = TAlphaColors.Lightgreen;
cDataPinColor = TAlphaColors.Dodgerblue;
cInitializerTreeWidth = 150;
var var
LVarDeclNode, LInitializerNode: TAuraNode; LVarDeclNode, LInitializerNode: TAuraNode;
LStartPosition: TPointF; LStartPosition: TPointF;
@@ -619,20 +687,27 @@ begin
LInitializerNode := FLastNode; LInitializerNode := FLastNode;
LInitializerEndY := FCurrentPos.Y; LInitializerEndY := FCurrentPos.Y;
FCurrentPos.X := LStartPosition.X + cInitializerTreeWidth + FSpacing.X;
// Position the VarDecl node dynamically to the right of the initializer's visual tree.
FCurrentPos.X := LInitializerNode.Position.X + LInitializerNode.Width + FSpacing.X;
FCurrentPos.Y := LStartPosition.Y; FCurrentPos.Y := LStartPosition.Y;
end; end;
LVarDeclNode := CreateNodeControl('VarDecl', Node.Identifier.Name); LVarDeclNode := CreateNodeControl('VarDecl', Node.Identifier.Name);
LVarDeclNodeEndY := FCurrentPos.Y; LVarDeclNodeEndY := FCurrentPos.Y;
CreatePin(LVarDeclNode, psTriangle, paLeft, cExecPinColor, 'Pin.Exec.In', -8); CreateEntry(LVarDeclNode, -8);
CreatePin(LVarDeclNode, psTriangle, paRight, cExecPinColor, 'Pin.Exec.Out', -8); CreateExit(LVarDeclNode, '', -8);
if Assigned(Node.Initializer) then if Assigned(Node.Initializer) then
begin begin
LInputPin := CreatePin(LVarDeclNode, psCircle, paLeft, cDataPinColor, 'Pin.Data.In', 8); LInputPin := CreateInput(LVarDeclNode, LInitializerNode.Name, 8);
ConnectPins(LInputPin, LInitializerNode, 'Pin.Data.Out'); ConnectData(LInputPin, LInitializerNode);
// Vertically center the VarDecl node relative to the initializer's visual tree.
var LInitializerHeight := LInitializerEndY - LStartPosition.Y;
LVarDeclNode.Position.Y := LStartPosition.Y + (LInitializerHeight / 2) - (LVarDeclNode.Height / 2);
LVarDeclNodeEndY := LVarDeclNode.Position.Y + LVarDeclNode.Height + FSpacing.Y;
FCurrentPos.Y := Max(LInitializerEndY, LVarDeclNodeEndY); FCurrentPos.Y := Max(LInitializerEndY, LVarDeclNodeEndY);
FCurrentPos.X := LStartPosition.X; FCurrentPos.X := LStartPosition.X;
@@ -693,7 +768,7 @@ begin
LPath := TPathData.Create; LPath := TPathData.Create;
try try
LDeltaX := LEndPoint.X - LStartPoint.X; LDeltaX := LEndPoint.X - LStartPoint.X;
LControlOffset := Max(50, Abs(LDeltaX) / 2); LControlOffset := Abs(LDeltaX) / 2;
LControlPoint1 := TPointF.Create(LStartPoint.X + LControlOffset, LStartPoint.Y); LControlPoint1 := TPointF.Create(LStartPoint.X + LControlOffset, LStartPoint.Y);
LControlPoint2 := TPointF.Create(LEndPoint.X - LControlOffset, LEndPoint.Y); LControlPoint2 := TPointF.Create(LEndPoint.X - LControlOffset, LEndPoint.Y);
+2 -2
View File
@@ -273,9 +273,9 @@ begin
end; end;
if boolResult then if boolResult then
Result := TAstValue.FromScalar(TScalar.FromInt64(1)) Result := TAstValue.FromScalar(TScalar.FromBoolean(true))
else else
Result := TAstValue.FromScalar(TScalar.FromInt64(0)); Result := TAstValue.FromScalar(TScalar.FromBoolean(false));
end; end;
function TEvaluatorVisitor.VisitUnaryExpression(const Node: IUnaryExpressionNode): TAstValue; function TEvaluatorVisitor.VisitUnaryExpression(const Node: IUnaryExpressionNode): TAstValue;
+1 -1
View File
@@ -313,7 +313,7 @@ begin
case Self of case Self of
boAdd: Result := '+'; boAdd: Result := '+';
boSubtract: Result := '-'; boSubtract: Result := '-';
boMultiply: Result := '*'; boMultiply: Result := #$2A2F;
boDivide: Result := '/'; boDivide: Result := '/';
boEqual: Result := '=='; boEqual: Result := '==';
boNotEqual: Result := '!='; boNotEqual: Result := '!=';