Ast list nodes
This commit is contained in:
@@ -29,6 +29,13 @@ type
|
||||
function VisitVariableDeclaration(const Node: IVariableDeclarationNode): Boolean; override;
|
||||
function VisitSeriesLength(const Node: ISeriesLengthNode): Boolean; override;
|
||||
|
||||
// --- List Visitors (New) ---
|
||||
function VisitParameterList(const Node: IParameterList): Boolean; override;
|
||||
function VisitArgumentList(const Node: IArgumentList): Boolean; override;
|
||||
function VisitExpressionList(const Node: IExpressionList): Boolean; override;
|
||||
function VisitRecordFieldList(const Node: IRecordFieldList): Boolean; override;
|
||||
function VisitRecordField(const Node: IRecordFieldNode): Boolean; override;
|
||||
|
||||
// --- Critical Checks ---
|
||||
function VisitIdentifier(const Node: IIdentifierNode): Boolean; override;
|
||||
function VisitFunctionCall(const Node: IFunctionCallNode): Boolean; override;
|
||||
@@ -81,6 +88,44 @@ begin
|
||||
Result := Node.Accept(Self).AsGeneric<Boolean>;
|
||||
end;
|
||||
|
||||
// --- List Visitors ---
|
||||
|
||||
function TPurityAnalyzer.VisitParameterList(const Node: IParameterList): Boolean;
|
||||
begin
|
||||
// Declarations are pure
|
||||
Result := True;
|
||||
end;
|
||||
|
||||
function TPurityAnalyzer.VisitArgumentList(const Node: IArgumentList): Boolean;
|
||||
begin
|
||||
for var item in Node do
|
||||
if not Accept(item) then
|
||||
exit(False);
|
||||
Result := True;
|
||||
end;
|
||||
|
||||
function TPurityAnalyzer.VisitExpressionList(const Node: IExpressionList): Boolean;
|
||||
begin
|
||||
for var item in Node do
|
||||
if not Accept(item) then
|
||||
exit(False);
|
||||
Result := True;
|
||||
end;
|
||||
|
||||
function TPurityAnalyzer.VisitRecordFieldList(const Node: IRecordFieldList): Boolean;
|
||||
begin
|
||||
for var item in Node do
|
||||
if not Accept(item) then
|
||||
exit(False);
|
||||
Result := True;
|
||||
end;
|
||||
|
||||
function TPurityAnalyzer.VisitRecordField(const Node: IRecordFieldNode): Boolean;
|
||||
begin
|
||||
// Key is usually pure (Keyword), check Value
|
||||
Result := Accept(Node.Key) and Accept(Node.Value);
|
||||
end;
|
||||
|
||||
// --- Safe Leaves ---
|
||||
|
||||
function TPurityAnalyzer.VisitConstant(const Node: IConstantNode): Boolean;
|
||||
@@ -120,11 +165,8 @@ begin
|
||||
exit(False);
|
||||
|
||||
// 2. All arguments must be pure expressions.
|
||||
for var arg in Node.Arguments do
|
||||
if not Accept(arg) then
|
||||
exit(False);
|
||||
|
||||
Result := True;
|
||||
// Delegate to ArgumentList visitor
|
||||
Result := Accept(Node.Arguments);
|
||||
end;
|
||||
|
||||
// --- Recursion ---
|
||||
@@ -132,10 +174,7 @@ end;
|
||||
function TPurityAnalyzer.VisitRecurNode(const Node: IRecurNode): Boolean;
|
||||
begin
|
||||
// 'recur' is just control flow. It is pure if its arguments are pure.
|
||||
for var arg in Node.Arguments do
|
||||
if not Accept(arg) then
|
||||
exit(False);
|
||||
Result := True;
|
||||
Result := Accept(Node.Arguments);
|
||||
end;
|
||||
|
||||
// --- Structures: Recursive Checks ---
|
||||
@@ -152,10 +191,8 @@ end;
|
||||
|
||||
function TPurityAnalyzer.VisitBlockExpression(const Node: IBlockExpressionNode): Boolean;
|
||||
begin
|
||||
for var expr in Node.Expressions do
|
||||
if not Accept(expr) then
|
||||
exit(False);
|
||||
Result := True;
|
||||
// Delegate to ExpressionList
|
||||
Result := Accept(Node.Expressions);
|
||||
end;
|
||||
|
||||
function TPurityAnalyzer.VisitVariableDeclaration(const Node: IVariableDeclarationNode): Boolean;
|
||||
@@ -167,10 +204,8 @@ end;
|
||||
|
||||
function TPurityAnalyzer.VisitRecordLiteral(const Node: IRecordLiteralNode): Boolean;
|
||||
begin
|
||||
for var field in Node.Fields do
|
||||
if not Accept(field.Value) then
|
||||
exit(False);
|
||||
Result := True;
|
||||
// Delegate to RecordFieldList
|
||||
Result := Accept(Node.Fields);
|
||||
end;
|
||||
|
||||
function TPurityAnalyzer.VisitIndexer(const Node: IIndexerNode): Boolean;
|
||||
|
||||
Reference in New Issue
Block a user