Static specialization WIP

This commit is contained in:
Michael Schimmel
2025-11-19 14:38:40 +01:00
parent c129c1a3ae
commit 138e7ac454
26 changed files with 2349 additions and 1110 deletions
-69
View File
@@ -30,8 +30,6 @@ type
function JsonToConstantNode(const AObj: TJSONObject): IConstantNode;
function JsonToIdentifierNode(const AObj: TJSONObject): IIdentifierNode;
function JsonToKeywordNode(const AObj: TJSONObject): IKeywordNode;
function JsonToBinaryExprNode(const AObj: TJSONObject): IBinaryExpressionNode;
function JsonToUnaryExprNode(const AObj: TJSONObject): IUnaryExpressionNode;
function JsonToIfExprNode(const AObj: TJSONObject): IIfExpressionNode;
function JsonToTernaryExprNode(const AObj: TJSONObject): ITernaryExpressionNode;
function JsonToLambdaExprNode(const AObj: TJSONObject): ILambdaExpressionNode;
@@ -58,8 +56,6 @@ type
function VisitConstant(const Node: IConstantNode): TJSONObject; override;
function VisitIdentifier(const Node: IIdentifierNode): TJSONObject; override;
function VisitKeyword(const Node: IKeywordNode): TJSONObject; override;
function VisitBinaryExpression(const Node: IBinaryExpressionNode): TJSONObject; override;
function VisitUnaryExpression(const Node: IUnaryExpressionNode): TJSONObject; override;
function VisitIfExpression(const Node: IIfExpressionNode): TJSONObject; override;
function VisitTernaryExpression(const Node: ITernaryExpressionNode): TJSONObject; override;
function VisitLambdaExpression(const Node: ILambdaExpressionNode): TJSONObject; override;
@@ -162,32 +158,6 @@ begin
Result.AddPair('Name', TJSONString.Create(Node.Value.Name));
end;
function TJsonAstConverter.VisitBinaryExpression(const Node: IBinaryExpressionNode): TJSONObject;
var
leftObj, rightObj: TJSONObject;
begin
leftObj := Accept(Node.Left);
rightObj := Accept(Node.Right);
Result := TJSONObject.Create;
Result.AddPair('NodeType', TJSONString.Create('BinaryExpr'));
Result.AddPair('Operator', TJSONString.Create(Node.Operator.ToString));
Result.AddPair('Left', leftObj);
Result.AddPair('Right', rightObj);
end;
function TJsonAstConverter.VisitUnaryExpression(const Node: IUnaryExpressionNode): TJSONObject;
var
rightObj: TJSONObject;
begin
rightObj := Accept(Node.Right);
Result := TJSONObject.Create;
Result.AddPair('NodeType', TJSONString.Create('UnaryExpr'));
Result.AddPair('Operator', TJSONString.Create(Node.Operator.ToString));
Result.AddPair('Right', rightObj);
end;
function TJsonAstConverter.VisitIfExpression(const Node: IIfExpressionNode): TJSONObject;
var
condObj, thenObj, elseObj: TJSONObject;
@@ -517,41 +487,6 @@ begin
Result := TAst.Keyword(AObj.GetValue<string>('Name'));
end;
function TJsonAstConverter.JsonToBinaryExprNode(const AObj: TJSONObject): IBinaryExpressionNode;
var
opStr: string;
op: TScalar.TBinaryOp;
leftNode, rightNode: IAstNode;
begin
opStr := AObj.GetValue<string>('Operator');
for op := Low(TScalar.TBinaryOp) to High(TScalar.TBinaryOp) do
if SameText(op.ToString, opStr) then
begin
leftNode := JsonToNode(AObj.GetValue('Left'));
rightNode := JsonToNode(AObj.GetValue('Right'));
Result := TAst.BinaryExpr(leftNode, op, rightNode);
exit;
end;
raise EInvalidOpException.CreateFmt('Unknown binary operator "%s"', [opStr]);
end;
function TJsonAstConverter.JsonToUnaryExprNode(const AObj: TJSONObject): IUnaryExpressionNode;
var
opStr: string;
op: TScalar.TUnaryOp;
rightNode: IAstNode;
begin
opStr := AObj.GetValue<string>('Operator');
for op := Low(TScalar.TUnaryOp) to High(TScalar.TUnaryOp) do
if SameText(op.ToString, opStr) then
begin
rightNode := JsonToNode(AObj.GetValue('Right'));
Result := TAst.UnaryExpr(op, rightNode);
exit;
end;
raise EInvalidOpException.CreateFmt('Unknown unary operator "%s"', [opStr]);
end;
function TJsonAstConverter.JsonToIfExprNode(const AObj: TJSONObject): IIfExpressionNode;
var
condNode, thenNode, elseNode: IAstNode;
@@ -792,10 +727,6 @@ begin
Result := JsonToIdentifierNode(obj)
else if nodeType = 'Keyword' then
Result := JsonToKeywordNode(obj)
else if nodeType = 'BinaryExpr' then
Result := JsonToBinaryExprNode(obj)
else if nodeType = 'UnaryExpr' then
Result := JsonToUnaryExprNode(obj)
else if nodeType = 'IfExpr' then
Result := JsonToIfExprNode(obj)
else if nodeType = 'TernaryExpr' then