Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Pull Request Description
This pull request introduces a new
ast
package that provides an Abstract Syntax Tree (AST) representation for Solidity contracts. The package offers a set of data structures, functions, and an AST builder to parse Solidity source code, construct an AST, and facilitate the analysis, manipulation, and generation of Solidity code.New Features and Enhancements
ASTBuilder: Added an
ASTBuilder
struct and associated functions to enable the construction of the AST from Solidity source code. TheASTBuilder
provides methods for traversing the Solidity parse tree, handling different context types, and creating AST nodes for contracts, functions, modifiers, variables, statements, expressions, events, errors, enums, structs, and more.Contract Node Implementation: Included support for representing contract definitions in the AST. The new
ContractNode
struct and associated functions allow the creation and manipulation of contract nodes, capturing their name, base contracts, state variables, functions, modifiers, events, and more.Function Node Implementation: Added support for representing function definitions in the AST. The new
FunctionNode
struct and related functions enable the representation of function nodes, capturing their name, parameters, return values, visibility, modifiers, and statements.Modifier Node Implementation: Introduced support for representing modifier definitions in the AST. The new
ModifierNode
struct and associated functions facilitate the representation of modifier nodes, capturing their name, parameters, visibility, and statements.Variable Node Implementation: Added support for representing variable declarations in the AST. The new
VariableNode
struct and accompanying functions enable the representation of variables, capturing their name, type, visibility, constantness, and initial values.Statement Node Implementation: Included support for representing statements in the AST. The new
StatementNode
struct and related functions allow the representation of various types of statements, such as assignments, function calls, control flow statements, and more.Expression Node Implementation: Introduced support for representing expressions in the AST. The new
ExpressionNode
struct and associated functions enable the representation of expressions, capturing their type, operators, operands, function calls, literals, and more.Event Node Implementation: Added support for representing event definitions in the AST. The new
EventNode
struct and accompanying functions facilitate the representation of events, capturing their name, parameters, and other event-related details.Error Node Implementation: Included support for representing error definitions in the AST. The new
ErrorNode
struct and related functions enable the representation of custom error types within Solidity contracts, facilitating better error handling and reporting.Enum Node Implementation: Introduced support for representing enum definitions in the AST. The new
EnumNode
struct and accompanying functions enable the representation of enumeration types within Solidity contracts, providing a concise and type-safe way to define a set of constant values.Struct Node Implementation: Added support for representing struct definitions in the AST. The new
StructNode
struct and related functions allow the creation and manipulation of struct nodes, capturing the structure and fields of Solidity structs.Fallback and Receive Functions: Extended the AST to handle fallback and receive functions in contracts. The
EnterFallbackFunctionDefinition
andEnterReceiveFunctionDefinition
functions now correctly create the corresponding function nodes, capturing their modifiers, visibility, and statements.Enhanced Traversal and Inspection: Provided utilities and functions to traverse and inspect the AST, allowing developers to analyze the structure, relationships, and properties of the Solidity code.
Code Generation Support: Included utilities for generating Solidity code from the AST, enabling the automated generation of Solidity contracts, functions, modifiers, and more.
Compatibility and Documentation
These changes introduce the
ast
package as a completely new component and do not impact any existing code or functionality. The package is designed to be compatible with ANTLR4 Solidity parser, to generate the initial AST from Solidity source code. The package documentation has been updated to reflect the new features and enhancements, providing clear explanations, usage examples, and guidelines for working with theASTBuilder
.