Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Abstract Syntax Tree (AST) package #13

Merged
merged 8 commits into from
Jul 3, 2023
Merged

Abstract Syntax Tree (AST) package #13

merged 8 commits into from
Jul 3, 2023

Conversation

0x19
Copy link
Contributor

@0x19 0x19 commented Jul 2, 2023

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

  1. ASTBuilder: Added an ASTBuilder struct and associated functions to enable the construction of the AST from Solidity source code. The ASTBuilder 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.

  2. 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.

  3. 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.

  4. 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.

  5. 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.

  6. 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.

  7. 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.

  8. 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.

  9. 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.

  10. 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.

  11. 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.

  12. Fallback and Receive Functions: Extended the AST to handle fallback and receive functions in contracts. The EnterFallbackFunctionDefinition and EnterReceiveFunctionDefinition functions now correctly create the corresponding function nodes, capturing their modifiers, visibility, and statements.

  13. 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.

  14. 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 the ASTBuilder.

@0x19 0x19 added documentation Improvements or additions to documentation enhancement New feature or request future work Something we should do in the future unit test ast Abstract Syntax Tree labels Jul 2, 2023
@0x19 0x19 self-assigned this Jul 2, 2023
@coveralls
Copy link

coveralls commented Jul 2, 2023

Pull Request Test Coverage Report for Build 5447908722

  • 417 of 494 (84.41%) changed or added relevant lines in 12 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+6.2%) to 76.661%

Changes Missing Coverage Covered Lines Changed/Added Lines %
ast/statement.go 16 19 84.21%
ast/function.go 87 105 82.86%
ast/builder.go 225 281 80.07%
Totals Coverage Status
Change from base Build 5437047281: 6.2%
Covered Lines: 854
Relevant Lines: 1114

💛 - Coveralls

@0x19 0x19 changed the title WIP: Abstract Syntax Tree (AST) package Abstract Syntax Tree (AST) package Jul 3, 2023
@0x19 0x19 merged commit 3c9310d into main Jul 3, 2023
@0x19 0x19 deleted the basic-ast branch July 3, 2023 19:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ast Abstract Syntax Tree documentation Improvements or additions to documentation enhancement New feature or request future work Something we should do in the future unit test
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants