AST development
This commit is contained in:
@@ -29,6 +29,8 @@ type
|
|||||||
FTitle: string;
|
FTitle: string;
|
||||||
FTitleFont: TFont;
|
FTitleFont: TFont;
|
||||||
FTitleFontColor: TAlphaColor;
|
FTitleFontColor: TAlphaColor;
|
||||||
|
// If true, the node is drawn without a border and with a transparent background.
|
||||||
|
FFrameless: Boolean;
|
||||||
|
|
||||||
procedure SetBorderColor(const Value: TAlphaColor);
|
procedure SetBorderColor(const Value: TAlphaColor);
|
||||||
procedure SetBorderWidth(const Value: Single);
|
procedure SetBorderWidth(const Value: Single);
|
||||||
@@ -37,6 +39,7 @@ type
|
|||||||
procedure SetTitleFont(const Value: TFont);
|
procedure SetTitleFont(const Value: TFont);
|
||||||
procedure SetTitleFontColor(const Value: TAlphaColor);
|
procedure SetTitleFontColor(const Value: TAlphaColor);
|
||||||
procedure TitleFontChanged(Sender: TObject);
|
procedure TitleFontChanged(Sender: TObject);
|
||||||
|
procedure SetFrameless(const Value: Boolean);
|
||||||
protected
|
protected
|
||||||
procedure Paint; override;
|
procedure Paint; override;
|
||||||
procedure MouseDown(Button: TMouseButton; Shift: TShiftState; X, Y: Single); override;
|
procedure MouseDown(Button: TMouseButton; Shift: TShiftState; X, Y: Single); override;
|
||||||
@@ -56,6 +59,9 @@ type
|
|||||||
property TitleFont: TFont read FTitleFont write SetTitleFont;
|
property TitleFont: TFont read FTitleFont write SetTitleFont;
|
||||||
property TitleFontColor: TAlphaColor read FTitleFontColor write SetTitleFontColor;
|
property TitleFontColor: TAlphaColor read FTitleFontColor write SetTitleFontColor;
|
||||||
|
|
||||||
|
// Behavior properties
|
||||||
|
property Frameless: Boolean read FFrameless write SetFrameless;
|
||||||
|
|
||||||
// Standard control properties
|
// Standard control properties
|
||||||
property Align;
|
property Align;
|
||||||
property Anchors;
|
property Anchors;
|
||||||
@@ -104,7 +110,7 @@ begin
|
|||||||
// Default border settings
|
// Default border settings
|
||||||
FBorderColor := TAlphaColors.Gray;
|
FBorderColor := TAlphaColors.Gray;
|
||||||
FBorderWidth := 1;
|
FBorderWidth := 1;
|
||||||
FBorderRadius := 0; // Sharp corners by default
|
FBorderRadius := 9; // Sharp corners by default
|
||||||
|
|
||||||
// Default title settings
|
// Default title settings
|
||||||
FTitle := 'Node';
|
FTitle := 'Node';
|
||||||
@@ -115,6 +121,9 @@ begin
|
|||||||
FTitleFont.OnChanged := TitleFontChanged;
|
FTitleFont.OnChanged := TitleFontChanged;
|
||||||
FTitleFontColor := TAlphaColors.Black;
|
FTitleFontColor := TAlphaColors.Black;
|
||||||
|
|
||||||
|
// Default state for frameless mode
|
||||||
|
FFrameless := False;
|
||||||
|
|
||||||
Width := 80;
|
Width := 80;
|
||||||
Height := 45;
|
Height := 45;
|
||||||
|
|
||||||
@@ -130,6 +139,62 @@ begin
|
|||||||
inherited;
|
inherited;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
procedure TAuraNode.Paint;
|
||||||
|
var
|
||||||
|
rect, titleRect: TRectF;
|
||||||
|
effectiveBorderWidth: Single;
|
||||||
|
begin
|
||||||
|
inherited; // Allow styled painting to occur first (if any)
|
||||||
|
|
||||||
|
if FFrameless then
|
||||||
|
begin
|
||||||
|
Canvas.Fill.Kind := TBrushKind.Solid;
|
||||||
|
Canvas.Fill.Color := $20C0C0C0; // Transparent Silver
|
||||||
|
Canvas.Stroke.Kind := TBrushKind.None;
|
||||||
|
|
||||||
|
// In frameless mode, draw a transparent background and ignore the border.
|
||||||
|
Canvas.FillRect(TRectF.Create(0, 0, Width, Height), 0, 0, [], 1.0);
|
||||||
|
effectiveBorderWidth := 0;
|
||||||
|
end
|
||||||
|
else
|
||||||
|
begin
|
||||||
|
// Custom painting for the border
|
||||||
|
if (FBorderWidth > 0) and (FBorderColor <> TAlphaColors.Null) then
|
||||||
|
begin
|
||||||
|
rect := TRectF.Create(0, 0, Width, Height);
|
||||||
|
// Inflate inwards so the border is fully visible within the control's bounds
|
||||||
|
rect.Inflate(-FBorderWidth / 2, -FBorderWidth / 2);
|
||||||
|
|
||||||
|
Canvas.Stroke.Kind := TBrushKind.Solid;
|
||||||
|
Canvas.Stroke.Color := FBorderColor;
|
||||||
|
Canvas.Stroke.Thickness := FBorderWidth;
|
||||||
|
|
||||||
|
if FFrameless then
|
||||||
|
begin
|
||||||
|
Canvas.Fill.Kind := TBrushKind.Solid;
|
||||||
|
Canvas.Fill.Color := $20C0C0C0; // Transparent Silver
|
||||||
|
Canvas.FillRect(rect, FBorderRadius, FBorderRadius, AllCorners, 1.0, TCornerType.Round);
|
||||||
|
end
|
||||||
|
else
|
||||||
|
Canvas.DrawRect(rect, FBorderRadius, FBorderRadius, AllCorners, 1.0, TCornerType.Round);
|
||||||
|
end;
|
||||||
|
effectiveBorderWidth := FBorderWidth;
|
||||||
|
end;
|
||||||
|
|
||||||
|
// Draw the title
|
||||||
|
if not FTitle.IsEmpty then
|
||||||
|
begin
|
||||||
|
// Define the rectangle for the title at the top of the control
|
||||||
|
titleRect := TRectF.Create(0, effectiveBorderWidth, Width, effectiveBorderWidth + FTitleFont.Size * 1.8);
|
||||||
|
|
||||||
|
Canvas.Font.Assign(FTitleFont);
|
||||||
|
Canvas.Fill.Color := FTitleFontColor;
|
||||||
|
|
||||||
|
// Draw the text centered horizontally and vertically within the title rectangle
|
||||||
|
Canvas.FillText(titleRect, FTitle, False, 1.0, [], TTextAlign.Center, TTextAlign.Center);
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
procedure TAuraNode.SetBorderColor(const Value: TAlphaColor);
|
procedure TAuraNode.SetBorderColor(const Value: TAlphaColor);
|
||||||
begin
|
begin
|
||||||
if FBorderColor <> Value then
|
if FBorderColor <> Value then
|
||||||
@@ -139,6 +204,15 @@ begin
|
|||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
procedure TAuraNode.SetBorderRadius(const Value: Single);
|
||||||
|
begin
|
||||||
|
if FBorderRadius <> Value then
|
||||||
|
begin
|
||||||
|
FBorderRadius := Value;
|
||||||
|
Repaint;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
procedure TAuraNode.SetBorderWidth(const Value: Single);
|
procedure TAuraNode.SetBorderWidth(const Value: Single);
|
||||||
begin
|
begin
|
||||||
if FBorderWidth <> Value then
|
if FBorderWidth <> Value then
|
||||||
@@ -148,11 +222,11 @@ begin
|
|||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TAuraNode.SetBorderRadius(const Value: Single);
|
procedure TAuraNode.SetFrameless(const Value: Boolean);
|
||||||
begin
|
begin
|
||||||
if FBorderRadius <> Value then
|
if FFrameless <> Value then
|
||||||
begin
|
begin
|
||||||
FBorderRadius := Value;
|
FFrameless := Value;
|
||||||
Repaint;
|
Repaint;
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
@@ -185,41 +259,6 @@ begin
|
|||||||
Repaint;
|
Repaint;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TAuraNode.Paint;
|
|
||||||
var
|
|
||||||
rect, titleRect: TRectF;
|
|
||||||
begin
|
|
||||||
inherited; // Allow styled painting to occur first (if any)
|
|
||||||
|
|
||||||
// Custom painting for the border
|
|
||||||
if (FBorderWidth > 0) and (FBorderColor <> TAlphaColors.Null) then
|
|
||||||
begin
|
|
||||||
rect := TRectF.Create(0, 0, Width, Height);
|
|
||||||
// Inflate inwards so the border is fully visible within the control's bounds
|
|
||||||
rect.Inflate(-FBorderWidth / 2, -FBorderWidth / 2);
|
|
||||||
|
|
||||||
Canvas.Stroke.Kind := TBrushKind.Solid;
|
|
||||||
Canvas.Stroke.Color := FBorderColor;
|
|
||||||
Canvas.Stroke.Thickness := FBorderWidth;
|
|
||||||
|
|
||||||
// Use DrawRoundRect to support both sharp and rounded corners
|
|
||||||
Canvas.DrawRect(rect, FBorderRadius, FBorderRadius, AllCorners, 1.0, TCornerType.Round);
|
|
||||||
end;
|
|
||||||
|
|
||||||
// Draw the title
|
|
||||||
if not FTitle.IsEmpty then
|
|
||||||
begin
|
|
||||||
// Define the rectangle for the title at the top of the control
|
|
||||||
titleRect := TRectF.Create(0, FBorderWidth, Width, FBorderWidth + FTitleFont.Size * 1.8);
|
|
||||||
|
|
||||||
Canvas.Font.Assign(FTitleFont);
|
|
||||||
Canvas.Fill.Color := FTitleFontColor;
|
|
||||||
|
|
||||||
// Draw the text centered horizontally and vertically within the title rectangle
|
|
||||||
Canvas.FillText(titleRect, FTitle, False, 1.0, [], TTextAlign.Center, TTextAlign.Center);
|
|
||||||
end;
|
|
||||||
end;
|
|
||||||
|
|
||||||
procedure TAuraNode.MouseDown(Button: TMouseButton; Shift: TShiftState; X, Y: Single);
|
procedure TAuraNode.MouseDown(Button: TMouseButton; Shift: TShiftState; X, Y: Single);
|
||||||
begin
|
begin
|
||||||
inherited;
|
inherited;
|
||||||
|
|||||||
@@ -369,6 +369,7 @@ begin
|
|||||||
Memo1.Lines.Add('--- Factory Pattern Demo ---');
|
Memo1.Lines.Add('--- Factory Pattern Demo ---');
|
||||||
|
|
||||||
sw.Start;
|
sw.Start;
|
||||||
|
|
||||||
root :=
|
root :=
|
||||||
TAst.Block(
|
TAst.Block(
|
||||||
[
|
[
|
||||||
|
|||||||
@@ -30,9 +30,15 @@ type
|
|||||||
TAstToAuraNodeVisitor = class(TInterfacedObject, IAstVisitor)
|
TAstToAuraNodeVisitor = class(TInterfacedObject, IAstVisitor)
|
||||||
public
|
public
|
||||||
type
|
type
|
||||||
|
// Holds the result of a node visitation, separating layout and connection concerns.
|
||||||
|
TAuraNodeResult = record
|
||||||
|
LayoutNode: TAuraNode;
|
||||||
|
OutputPin: TControl;
|
||||||
|
end;
|
||||||
|
TAuraNodeResultList = TList<TAuraNodeResult>;
|
||||||
TChildVisitorProc = reference to procedure(const Visitor: IAstVisitor);
|
TChildVisitorProc = reference to procedure(const Visitor: IAstVisitor);
|
||||||
TAuraNodeList = TList<TAuraNode>;
|
// The lambda now returns the full result, including the output pin reference.
|
||||||
TCreateParentNodeProc = reference to function(const InputNodes: TAuraNodeList): TAuraNode;
|
TCreateParentNodeProc = reference to function(const InputNodes: TAuraNodeResultList): TAuraNodeResult;
|
||||||
TVerticalAlignment = (vaCenter, vaTop);
|
TVerticalAlignment = (vaCenter, vaTop);
|
||||||
|
|
||||||
private
|
private
|
||||||
@@ -56,7 +62,7 @@ type
|
|||||||
FParentControl: TControl;
|
FParentControl: TControl;
|
||||||
FCurrentPos: TPointF;
|
FCurrentPos: TPointF;
|
||||||
FSpacing: TPointF;
|
FSpacing: TPointF;
|
||||||
FLastNode: TAuraNode;
|
FLastResult: TAuraNodeResult;
|
||||||
FConnections: TList<TPinConnection>;
|
FConnections: TList<TPinConnection>;
|
||||||
FCurrentExec: TList<TControl>;
|
FCurrentExec: TList<TControl>;
|
||||||
|
|
||||||
@@ -88,8 +94,6 @@ type
|
|||||||
function CreateEntry(ParentNode: TAuraNode; OffsetY: Single = 0; connect: Boolean = true): TControl;
|
function CreateEntry(ParentNode: TAuraNode; OffsetY: Single = 0; connect: Boolean = true): TControl;
|
||||||
function CreateExit(ParentNode: TAuraNode; const Caption: string; OffsetY: Single = 0): TControl;
|
function CreateExit(ParentNode: TAuraNode; const Caption: string; OffsetY: Single = 0): TControl;
|
||||||
|
|
||||||
function FindPinByTag(ParentNode: TAuraNode; const Tag: string): TControl;
|
|
||||||
function ConnectData(InputPin: TControl; OutputNode: TAuraNode): TControl;
|
|
||||||
public
|
public
|
||||||
constructor Create(
|
constructor Create(
|
||||||
AWorkspace: TAuraWorkspace;
|
AWorkspace: TAuraWorkspace;
|
||||||
@@ -192,6 +196,8 @@ begin
|
|||||||
FSpacing := TPointF.Create(20, 10); // Horizontal indent, Vertical spacing
|
FSpacing := TPointF.Create(20, 10); // Horizontal indent, Vertical spacing
|
||||||
FConnections := AConnections;
|
FConnections := AConnections;
|
||||||
FCurrentExec := TList<TControl>.Create(ACurrentExec);
|
FCurrentExec := TList<TControl>.Create(ACurrentExec);
|
||||||
|
FLastResult.LayoutNode := nil;
|
||||||
|
FLastResult.OutputPin := nil;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
destructor TAstToAuraNodeVisitor.Destroy;
|
destructor TAstToAuraNodeVisitor.Destroy;
|
||||||
@@ -228,13 +234,6 @@ begin
|
|||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function TAstToAuraNodeVisitor.ConnectData(InputPin: TControl; OutputNode: TAuraNode): TControl;
|
|
||||||
begin
|
|
||||||
Result := FindPinByTag(OutputNode, 'data.out');
|
|
||||||
if Assigned(Result) then
|
|
||||||
FConnections.Add(TPinConnection.Create(Result, InputPin));
|
|
||||||
end;
|
|
||||||
|
|
||||||
function TAstToAuraNodeVisitor.CreateInput(ParentNode: TAuraNode; const Caption: string; OffsetY: Single = 0): TControl;
|
function TAstToAuraNodeVisitor.CreateInput(ParentNode: TAuraNode; const Caption: string; OffsetY: Single = 0): TControl;
|
||||||
begin
|
begin
|
||||||
var cap := Caption;
|
var cap := Caption;
|
||||||
@@ -253,7 +252,8 @@ begin
|
|||||||
// Advance vertical position for the next node
|
// Advance vertical position for the next node
|
||||||
FCurrentPos.Y := FCurrentPos.Y + Result.Height + FSpacing.Y;
|
FCurrentPos.Y := FCurrentPos.Y + Result.Height + FSpacing.Y;
|
||||||
|
|
||||||
FLastNode := Result;
|
FLastResult.LayoutNode := Result;
|
||||||
|
FLastResult.OutputPin := nil; // Default: a new node has no specific data output pin
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function TAstToAuraNodeVisitor.CreateOutput(ParentNode: TAuraNode; OffsetY: Single = 0): TControl;
|
function TAstToAuraNodeVisitor.CreateOutput(ParentNode: TAuraNode; OffsetY: Single = 0): TControl;
|
||||||
@@ -334,42 +334,28 @@ begin
|
|||||||
Result.TagString := Tag;
|
Result.TagString := Tag;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function TAstToAuraNodeVisitor.FindPinByTag(ParentNode: TAuraNode; const Tag: string): TControl;
|
|
||||||
var
|
|
||||||
control: TControl;
|
|
||||||
begin
|
|
||||||
Result := nil;
|
|
||||||
if not Assigned(ParentNode) then
|
|
||||||
exit;
|
|
||||||
|
|
||||||
for control in ParentNode.Controls do
|
|
||||||
begin
|
|
||||||
if control.TagString = Tag then
|
|
||||||
begin
|
|
||||||
Result := control;
|
|
||||||
exit;
|
|
||||||
end;
|
|
||||||
end;
|
|
||||||
end;
|
|
||||||
|
|
||||||
function TAstToAuraNodeVisitor.VisitAssignment(const Node: IAssignmentNode): TAstValue;
|
function TAstToAuraNodeVisitor.VisitAssignment(const Node: IAssignmentNode): TAstValue;
|
||||||
begin
|
begin
|
||||||
VisitOperatorNode(
|
VisitOperatorNode(
|
||||||
[Node.Value],
|
[Node.Value],
|
||||||
function(const InputNodes: TAuraNodeList): TAuraNode
|
function(const InputResults: TAuraNodeResultList): TAuraNodeResult
|
||||||
var
|
var
|
||||||
assignmentNode, valueNode: TAuraNode;
|
assignmentNode: TAuraNode;
|
||||||
inputPin: TControl;
|
inputPin: TControl;
|
||||||
|
valueResult: TAuraNodeResult;
|
||||||
begin
|
begin
|
||||||
valueNode := InputNodes[0];
|
valueResult := InputResults[0];
|
||||||
assignmentNode := BuildNodeControl('Assignment', Node.Identifier.Name);
|
assignmentNode := BuildNodeControl('Assignment', Node.Identifier.Name);
|
||||||
|
|
||||||
CreateEntry(assignmentNode, -8);
|
CreateEntry(assignmentNode, -8);
|
||||||
CreateExit(assignmentNode, '', 0);
|
CreateExit(assignmentNode, '', 0);
|
||||||
inputPin := CreateInput(assignmentNode, Node.Identifier.Name, 8);
|
inputPin := CreateInput(assignmentNode, Node.Identifier.Name, 8);
|
||||||
ConnectData(inputPin, valueNode);
|
|
||||||
|
|
||||||
Result := assignmentNode;
|
if Assigned(valueResult.OutputPin) then
|
||||||
|
FConnections.Add(TPinConnection.Create(valueResult.OutputPin, inputPin));
|
||||||
|
|
||||||
|
Result.LayoutNode := assignmentNode;
|
||||||
|
Result.OutputPin := nil; // An assignment has no data output
|
||||||
end,
|
end,
|
||||||
vaTop
|
vaTop
|
||||||
);
|
);
|
||||||
@@ -380,25 +366,30 @@ function TAstToAuraNodeVisitor.VisitBinaryExpression(const Node: IBinaryExpressi
|
|||||||
begin
|
begin
|
||||||
VisitOperatorNode(
|
VisitOperatorNode(
|
||||||
[Node.Left, Node.Right],
|
[Node.Left, Node.Right],
|
||||||
function(const InputNodes: TAuraNodeList): TAuraNode
|
function(const InputResults: TAuraNodeResultList): TAuraNodeResult
|
||||||
var
|
var
|
||||||
binaryExprNode, leftNode, rightNode: TAuraNode;
|
binaryExprNode: TAuraNode;
|
||||||
inputPin1, inputPin2: TControl;
|
inputPin1, inputPin2: TControl;
|
||||||
|
leftResult, rightResult: TAuraNodeResult;
|
||||||
|
outPin: TControl;
|
||||||
begin
|
begin
|
||||||
leftNode := InputNodes[0];
|
leftResult := InputResults[0];
|
||||||
rightNode := InputNodes[1];
|
rightResult := InputResults[1];
|
||||||
|
|
||||||
binaryExprNode := BuildNodeControl(Node.Operator.ToString, '');
|
binaryExprNode := BuildNodeControl(Node.Operator.ToString, '');
|
||||||
binaryExprNode.TitleFont.Size := 20;
|
binaryExprNode.TitleFont.Size := 20;
|
||||||
|
|
||||||
inputPin1 := CreateInput(binaryExprNode, '', -8); // Caption is in Hint
|
inputPin1 := CreateInput(binaryExprNode, '', -8); // Caption is in Hint
|
||||||
inputPin2 := CreateInput(binaryExprNode, '', 8);
|
inputPin2 := CreateInput(binaryExprNode, '', 8);
|
||||||
CreateOutput(binaryExprNode, 0);
|
outPin := CreateOutput(binaryExprNode, 0);
|
||||||
|
|
||||||
ConnectData(inputPin1, leftNode);
|
if Assigned(leftResult.OutputPin) then
|
||||||
ConnectData(inputPin2, rightNode);
|
FConnections.Add(TPinConnection.Create(leftResult.OutputPin, inputPin1));
|
||||||
|
if Assigned(rightResult.OutputPin) then
|
||||||
|
FConnections.Add(TPinConnection.Create(rightResult.OutputPin, inputPin2));
|
||||||
|
|
||||||
Result := binaryExprNode;
|
Result.LayoutNode := binaryExprNode;
|
||||||
|
Result.OutputPin := outPin;
|
||||||
end
|
end
|
||||||
);
|
);
|
||||||
Result := TAstValue.Void;
|
Result := TAstValue.Void;
|
||||||
@@ -407,15 +398,16 @@ end;
|
|||||||
function TAstToAuraNodeVisitor.VisitBlockExpression(const Node: IBlockExpressionNode): TAstValue;
|
function TAstToAuraNodeVisitor.VisitBlockExpression(const Node: IBlockExpressionNode): TAstValue;
|
||||||
var
|
var
|
||||||
blockNode: TAuraNode;
|
blockNode: TAuraNode;
|
||||||
|
childLastResult: TAuraNodeResult;
|
||||||
begin
|
begin
|
||||||
|
childLastResult.LayoutNode := nil;
|
||||||
|
childLastResult.OutputPin := nil;
|
||||||
|
|
||||||
// Use the helper to create and populate the container node.
|
// Use the helper to create and populate the container node.
|
||||||
// InPin and OutPin set: block acts as "virtual execution scope" with entry and exit-nodes
|
|
||||||
// InPin and OutPin empty: block acts as a simple container
|
|
||||||
blockNode :=
|
blockNode :=
|
||||||
VisitContainerNode(
|
VisitContainerNode(
|
||||||
'Block',
|
'', // No title for blocks
|
||||||
'',
|
'',
|
||||||
// 'enter', 'exit',
|
|
||||||
'',
|
'',
|
||||||
'',
|
'',
|
||||||
true,
|
true,
|
||||||
@@ -425,12 +417,19 @@ begin
|
|||||||
begin
|
begin
|
||||||
for expression in Node.Expressions do
|
for expression in Node.Expressions do
|
||||||
expression.Accept(Visitor);
|
expression.Accept(Visitor);
|
||||||
|
|
||||||
|
// Capture the full result of the last expression inside the block.
|
||||||
|
childLastResult := (Visitor as TAstToAuraNodeVisitor).FLastResult;
|
||||||
end
|
end
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// Blocks are drawn without title and border, with a transparent fill.
|
||||||
|
blockNode.Frameless := true;
|
||||||
|
|
||||||
// Update the state of the main visitor
|
// Update the state of the main visitor
|
||||||
FCurrentPos.Y := blockNode.Position.Y + blockNode.Height + FSpacing.Y;
|
FCurrentPos.Y := blockNode.Position.Y + blockNode.Height + FSpacing.Y;
|
||||||
FLastNode := blockNode;
|
FLastResult.LayoutNode := blockNode; // The layout node is the container itself.
|
||||||
|
FLastResult.OutputPin := childLastResult.OutputPin; // The connection pin is from the internal node.
|
||||||
|
|
||||||
Result := TAstValue.Void;
|
Result := TAstValue.Void;
|
||||||
end;
|
end;
|
||||||
@@ -439,10 +438,8 @@ function TAstToAuraNodeVisitor.VisitConstant(const Node: IConstantNode): TAstVal
|
|||||||
var
|
var
|
||||||
constantNode: TAuraNode;
|
constantNode: TAuraNode;
|
||||||
begin
|
begin
|
||||||
// A constant has a data output pin.
|
|
||||||
// Data outputs are round and on the right side of the box.
|
|
||||||
constantNode := CreateNodeControl('Constant', Node.Value.ToString);
|
constantNode := CreateNodeControl('Constant', Node.Value.ToString);
|
||||||
CreateOutput(constantNode, 0);
|
FLastResult.OutputPin := CreateOutput(constantNode, 0);
|
||||||
Result := TAstValue.Void;
|
Result := TAstValue.Void;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
@@ -546,13 +543,14 @@ begin
|
|||||||
|
|
||||||
VisitOperatorNode(
|
VisitOperatorNode(
|
||||||
inputExpressions,
|
inputExpressions,
|
||||||
function(const InputNodes: TAuraNodeList): TAuraNode
|
function(const InputResults: TAuraNodeResultList): TAuraNodeResult
|
||||||
var
|
var
|
||||||
funcCallNode: TAuraNode;
|
funcCallNode: TAuraNode;
|
||||||
calleePin: TControl;
|
calleePin: TControl;
|
||||||
argPin: array of TControl;
|
argPin: array of TControl;
|
||||||
currentInputOffsetY, currentOutputOffsetY: Single;
|
currentInputOffsetY, currentOutputOffsetY: Single;
|
||||||
i: Integer;
|
i: Integer;
|
||||||
|
outPin: TControl;
|
||||||
begin
|
begin
|
||||||
funcCallNode := BuildNodeControl('FunctionCall', '');
|
funcCallNode := BuildNodeControl('FunctionCall', '');
|
||||||
|
|
||||||
@@ -576,13 +574,16 @@ begin
|
|||||||
currentOutputOffsetY := -(numOutputPins - 1) / 2.0 * cPinOffsetY;
|
currentOutputOffsetY := -(numOutputPins - 1) / 2.0 * cPinOffsetY;
|
||||||
CreateExit(funcCallNode, '', currentOutputOffsetY);
|
CreateExit(funcCallNode, '', currentOutputOffsetY);
|
||||||
currentOutputOffsetY := currentOutputOffsetY + cPinOffsetY;
|
currentOutputOffsetY := currentOutputOffsetY + cPinOffsetY;
|
||||||
CreateOutput(funcCallNode, currentOutputOffsetY);
|
outPin := CreateOutput(funcCallNode, currentOutputOffsetY);
|
||||||
|
|
||||||
ConnectData(calleePin, InputNodes[0]);
|
if Assigned(InputResults[0].OutputPin) then
|
||||||
|
FConnections.Add(TPinConnection.Create(InputResults[0].OutputPin, calleePin));
|
||||||
for i := 0 to Node.Arguments.Count - 1 do
|
for i := 0 to Node.Arguments.Count - 1 do
|
||||||
ConnectData(argPin[i], InputNodes[i + 1]);
|
if Assigned(InputResults[i + 1].OutputPin) then
|
||||||
|
FConnections.Add(TPinConnection.Create(InputResults[i + 1].OutputPin, argPin[i]));
|
||||||
|
|
||||||
Result := funcCallNode;
|
Result.LayoutNode := funcCallNode;
|
||||||
|
Result.OutputPin := outPin;
|
||||||
end
|
end
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -592,8 +593,7 @@ end;
|
|||||||
function TAstToAuraNodeVisitor.VisitIdentifier(const Node: IIdentifierNode): TAstValue;
|
function TAstToAuraNodeVisitor.VisitIdentifier(const Node: IIdentifierNode): TAstValue;
|
||||||
begin
|
begin
|
||||||
var identifierNode := CreateNodeControl('Identifier', Node.Name);
|
var identifierNode := CreateNodeControl('Identifier', Node.Name);
|
||||||
// Add a data output pin on the right side.
|
FLastResult.OutputPin := CreateOutput(identifierNode, 0);
|
||||||
CreateOutput(identifierNode, 0);
|
|
||||||
Result := TAstValue.Void;
|
Result := TAstValue.Void;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
@@ -605,20 +605,24 @@ begin
|
|||||||
var ifNode :=
|
var ifNode :=
|
||||||
VisitOperatorNode(
|
VisitOperatorNode(
|
||||||
[Node.Condition],
|
[Node.Condition],
|
||||||
function(const InputNodes: TAuraNodeList): TAuraNode
|
function(const InputResults: TAuraNodeResultList): TAuraNodeResult
|
||||||
var
|
var
|
||||||
condNode: TAuraNode;
|
|
||||||
conditionInputPin: TControl;
|
conditionInputPin: TControl;
|
||||||
|
condResult: TAuraNodeResult;
|
||||||
|
ifNode: TAuraNode;
|
||||||
begin
|
begin
|
||||||
condNode := InputNodes[0];
|
condResult := InputResults[0];
|
||||||
|
ifNode := BuildNodeControl('If', '');
|
||||||
|
ifNode.Height := cIfNodeHeight;
|
||||||
|
CreateEntry(ifNode, -12);
|
||||||
|
|
||||||
Result := BuildNodeControl('If', '');
|
conditionInputPin := CreateInput(ifNode, 'Condition', 12);
|
||||||
Result.Height := cIfNodeHeight;
|
|
||||||
CreateEntry(Result, -12);
|
|
||||||
|
|
||||||
conditionInputPin := CreateInput(Result, 'Condition', 12);
|
if Assigned(condResult.OutputPin) then
|
||||||
|
FConnections.Add(TPinConnection.Create(condResult.OutputPin, conditionInputPin));
|
||||||
|
|
||||||
ConnectData(conditionInputPin, condNode);
|
Result.LayoutNode := ifNode;
|
||||||
|
Result.OutputPin := nil;
|
||||||
end
|
end
|
||||||
);
|
);
|
||||||
var conditionEndY := FCurrentPos.Y;
|
var conditionEndY := FCurrentPos.Y;
|
||||||
@@ -635,7 +639,7 @@ begin
|
|||||||
FCurrentPos.Y := startPosition.Y;
|
FCurrentPos.Y := startPosition.Y;
|
||||||
Node.ThenBranch.Accept(Self);
|
Node.ThenBranch.Accept(Self);
|
||||||
var thenEndY := FCurrentPos.Y;
|
var thenEndY := FCurrentPos.Y;
|
||||||
FLastNode := ifNode;
|
FLastResult.LayoutNode := ifNode;
|
||||||
execPathes.AddRange(FCurrentExec);
|
execPathes.AddRange(FCurrentExec);
|
||||||
|
|
||||||
// Else branch (if it exists)
|
// Else branch (if it exists)
|
||||||
@@ -654,10 +658,10 @@ begin
|
|||||||
// Finalize visitor state.
|
// Finalize visitor state.
|
||||||
FCurrentPos.X := startPosition.X;
|
FCurrentPos.X := startPosition.X;
|
||||||
FCurrentPos.Y := Max(conditionEndY, elseEndY);
|
FCurrentPos.Y := Max(conditionEndY, elseEndY);
|
||||||
FLastNode := ifNode;
|
FLastResult.LayoutNode := ifNode;
|
||||||
|
FLastResult.OutputPin := nil; // An if-expression has no data output itself
|
||||||
|
|
||||||
// After a branch, the execution flow has diverged. There is no single
|
// After a branch, the execution flow has diverged.
|
||||||
// execution pin to continue from, so we set it to nil.
|
|
||||||
FCurrentExec.Clear;
|
FCurrentExec.Clear;
|
||||||
FCurrentExec.AddRange(execPathes);
|
FCurrentExec.AddRange(execPathes);
|
||||||
|
|
||||||
@@ -691,11 +695,11 @@ begin
|
|||||||
procedure(const Visitor: IAstVisitor) begin Node.Body.Accept(Visitor); end
|
procedure(const Visitor: IAstVisitor) begin Node.Body.Accept(Visitor); end
|
||||||
);
|
);
|
||||||
|
|
||||||
CreateOutput(lambdaNode, 0);
|
|
||||||
|
|
||||||
// Update the state of the main visitor
|
// Update the state of the main visitor
|
||||||
FCurrentPos.Y := lambdaNode.Position.Y + lambdaNode.Height + FSpacing.Y;
|
FCurrentPos.Y := lambdaNode.Position.Y + lambdaNode.Height + FSpacing.Y;
|
||||||
FLastNode := lambdaNode;
|
|
||||||
|
FLastResult.LayoutNode := lambdaNode;
|
||||||
|
FLastResult.OutputPin := CreateOutput(lambdaNode, 0);
|
||||||
|
|
||||||
Result := TAstValue.Void;
|
Result := TAstValue.Void;
|
||||||
end;
|
end;
|
||||||
@@ -706,30 +710,33 @@ function TAstToAuraNodeVisitor.VisitOperatorNode(
|
|||||||
Alignment: TVerticalAlignment
|
Alignment: TVerticalAlignment
|
||||||
): TAuraNode;
|
): TAuraNode;
|
||||||
var
|
var
|
||||||
inputResultNodes: TAuraNodeList;
|
inputResults: TAuraNodeResultList;
|
||||||
inputNode: IExpressionNode;
|
inputNode: IExpressionNode;
|
||||||
startPosition: TPointF;
|
startPosition: TPointF;
|
||||||
endY, maxChildWidth: Single;
|
endY, maxChildWidth: Single;
|
||||||
parentNode: TAuraNode;
|
parentNode: TAuraNode;
|
||||||
|
createResult: TAuraNodeResult;
|
||||||
begin
|
begin
|
||||||
startPosition := FCurrentPos;
|
startPosition := FCurrentPos;
|
||||||
inputResultNodes := TAuraNodeList.Create;
|
inputResults := TAuraNodeResultList.Create;
|
||||||
try
|
try
|
||||||
// 1. Visit all input nodes and collect their visual representations.
|
// 1. Visit all input nodes and collect their visual representations.
|
||||||
for inputNode in InputExpressions do
|
for inputNode in InputExpressions do
|
||||||
begin
|
begin
|
||||||
inputNode.Accept(Self);
|
inputNode.Accept(Self);
|
||||||
inputResultNodes.Add(FLastNode);
|
inputResults.Add(FLastResult);
|
||||||
end;
|
end;
|
||||||
endY := FCurrentPos.Y;
|
endY := FCurrentPos.Y;
|
||||||
|
|
||||||
// 2. Determine the layout bounds of the input nodes.
|
// 2. Determine the layout bounds of the input nodes.
|
||||||
maxChildWidth := 0;
|
maxChildWidth := 0;
|
||||||
for var node in inputResultNodes do
|
for var res in inputResults do
|
||||||
maxChildWidth := Max(maxChildWidth, node.Position.X + node.Width);
|
if Assigned(res.LayoutNode) then
|
||||||
|
maxChildWidth := Max(maxChildWidth, res.LayoutNode.Position.X + res.LayoutNode.Width);
|
||||||
|
|
||||||
// 3. Let the closure create the parent node (without positioning).
|
// 3. Let the closure create the parent node (without positioning).
|
||||||
parentNode := CreateParentProc(inputResultNodes);
|
createResult := CreateParentProc(inputResults);
|
||||||
|
parentNode := createResult.LayoutNode;
|
||||||
Result := parentNode;
|
Result := parentNode;
|
||||||
|
|
||||||
// 4. Now position the parent node to the right of the inputs.
|
// 4. Now position the parent node to the right of the inputs.
|
||||||
@@ -747,23 +754,39 @@ begin
|
|||||||
parentNode.Position.Point := TPointF.Create(maxChildWidth + FSpacing.X, parentY);
|
parentNode.Position.Point := TPointF.Create(maxChildWidth + FSpacing.X, parentY);
|
||||||
|
|
||||||
// 5. Finalize visitor state for the next operation.
|
// 5. Finalize visitor state for the next operation.
|
||||||
FCurrentPos.X := startPosition.X;
|
|
||||||
FCurrentPos.Y := Max(endY, parentNode.Position.Y + parentNode.Height + FSpacing.Y);
|
FCurrentPos.Y := Max(endY, parentNode.Position.Y + parentNode.Height + FSpacing.Y);
|
||||||
FLastNode := parentNode;
|
FLastResult.LayoutNode := parentNode;
|
||||||
|
FLastResult.OutputPin := createResult.OutputPin;
|
||||||
finally
|
finally
|
||||||
inputResultNodes.Free;
|
inputResults.Free;
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function TAstToAuraNodeVisitor.VisitUnaryExpression(const Node: IUnaryExpressionNode): TAstValue;
|
function TAstToAuraNodeVisitor.VisitUnaryExpression(const Node: IUnaryExpressionNode): TAstValue;
|
||||||
begin
|
begin
|
||||||
CreateNodeControl('UnaryExpr', Node.Operator.ToString);
|
VisitOperatorNode(
|
||||||
FCurrentPos.X := FCurrentPos.X + FSpacing.X;
|
[Node.Right],
|
||||||
try
|
function(const InputResults: TAuraNodeResultList): TAuraNodeResult
|
||||||
Node.Right.Accept(Self);
|
var
|
||||||
finally
|
unaryExprNode: TAuraNode;
|
||||||
FCurrentPos.X := FCurrentPos.X - FSpacing.X;
|
inputPin: TControl;
|
||||||
end;
|
rightResult: TAuraNodeResult;
|
||||||
|
outPin: TControl;
|
||||||
|
begin
|
||||||
|
rightResult := InputResults[0];
|
||||||
|
unaryExprNode := BuildNodeControl(Node.Operator.ToString, '');
|
||||||
|
unaryExprNode.TitleFont.Size := 20;
|
||||||
|
|
||||||
|
inputPin := CreateInput(unaryExprNode, '', 0);
|
||||||
|
outPin := CreateOutput(unaryExprNode, 0);
|
||||||
|
|
||||||
|
if Assigned(rightResult.OutputPin) then
|
||||||
|
FConnections.Add(TPinConnection.Create(rightResult.OutputPin, inputPin));
|
||||||
|
|
||||||
|
Result.LayoutNode := unaryExprNode;
|
||||||
|
Result.OutputPin := outPin;
|
||||||
|
end
|
||||||
|
);
|
||||||
Result := TAstValue.Void;
|
Result := TAstValue.Void;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
@@ -773,20 +796,24 @@ begin
|
|||||||
begin
|
begin
|
||||||
VisitOperatorNode(
|
VisitOperatorNode(
|
||||||
[Node.Initializer],
|
[Node.Initializer],
|
||||||
function(const InputNodes: TAuraNodeList): TAuraNode
|
function(const InputResults: TAuraNodeResultList): TAuraNodeResult
|
||||||
var
|
var
|
||||||
varDeclNode, initializerNode: TAuraNode;
|
varDeclNode: TAuraNode;
|
||||||
inputPin: TControl;
|
inputPin: TControl;
|
||||||
|
initializerResult: TAuraNodeResult;
|
||||||
begin
|
begin
|
||||||
initializerNode := InputNodes[0];
|
initializerResult := InputResults[0];
|
||||||
varDeclNode := BuildNodeControl('VarDecl', Node.Identifier.Name);
|
varDeclNode := BuildNodeControl('VarDecl', Node.Identifier.Name);
|
||||||
|
|
||||||
CreateEntry(varDeclNode, -8);
|
CreateEntry(varDeclNode, -8);
|
||||||
CreateExit(varDeclNode, '', -8);
|
CreateExit(varDeclNode, '', -8);
|
||||||
inputPin := CreateInput(varDeclNode, 'Value', 8);
|
inputPin := CreateInput(varDeclNode, 'Value', 8);
|
||||||
ConnectData(inputPin, initializerNode);
|
|
||||||
|
|
||||||
Result := varDeclNode;
|
if Assigned(initializerResult.OutputPin) then
|
||||||
|
FConnections.Add(TPinConnection.Create(initializerResult.OutputPin, inputPin));
|
||||||
|
|
||||||
|
Result.LayoutNode := varDeclNode;
|
||||||
|
Result.OutputPin := nil;
|
||||||
end
|
end
|
||||||
);
|
);
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -48,6 +48,7 @@
|
|||||||
- Folgende Schlüsselwörter müssen klein geschrieben werden:
|
- Folgende Schlüsselwörter müssen klein geschrieben werden:
|
||||||
and, or, not, mod, div, in, as, is, array of, sizeof(), inc(), dec(), exit, inc, dec, shl, shr
|
and, or, not, mod, div, in, as, is, array of, sizeof(), inc(), dec(), exit, inc, dec, shl, shr
|
||||||
- Compiler-Direktiven (z.B. $region) sollen immer klein geschrieben werden.
|
- Compiler-Direktiven (z.B. $region) sollen immer klein geschrieben werden.
|
||||||
|
- Achte darauf keine Schlüsselwörter als Bezeichner (type, Result, if, etc) zu verwenden, da Delphi das nicht unterstützt.
|
||||||
|
|
||||||
* Ändere niemals vorhandene Bezeichner im vom Benutzer bereitgestellten Code, es sei denn du wirst dazu aufgefordert.
|
* Ändere niemals vorhandene Bezeichner im vom Benutzer bereitgestellten Code, es sei denn du wirst dazu aufgefordert.
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user