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

Support multiple declarations in a single statement #159

Merged
merged 4 commits into from
Jun 13, 2024

Conversation

Lai-YT
Copy link
Collaborator

@Lai-YT Lai-YT commented Jun 8, 2024

A new statement node called DeclStmtNode has been introduced to hold multiple declarations. The AST nodes backed by non-terminals that take decl now accept a DeclStmtNode instead of a DeclNode. These nodes include LoopInitNode and CompoundStmtNode; other nodes remain unaffected.
Since DeclStmtNode is simply a sequence of DeclNodes, the Visit functions will visit each DeclNode it holds.

How to review?

  1. Test Cases: Examine the test cases to see how the AST looks after the changes. Since this PR introduces a new node to wrap the DeclNode, nearly all *.exp files are affected. However, reviewing decl.c, for_stmt.c, pointer.c, array.c, struct.c, and union.c along with their corresponding *.exp files should suffice.
  2. Code Changes: Review the changes in parser.y and include/ast.hpp to understand how the grammars have been modified and how the AST nodes have been adjusted to accommodate these changes.

A new statement node called `DeclStmtNode` has been introduced to hold
multiple declarations. The AST nodes backed by non-terminals that take
`decl` now accept a `DeclStmtNode` instead of a `DeclNode`. These nodes
include `LoopInitNode` and `CompoundStmtNode`; other nodes remain
unaffected.
Since `DeclStmtNode` is simply a sequence of `DeclNode`s, the `Visit`
functions will visit each `DeclNode` it holds.
Objects are placed in a valid but unspecified state after being
moved-from.
Since an item of a compound statement is no longer an `std::variant`, we
no longer use a type alias to simplify the type. Additionally, the data
member has been renamed to remove the word `item`, which is a technical
term used during parsing.
@Lai-YT Lai-YT added the enhancement New feature or request label Jun 8, 2024
@Lai-YT Lai-YT requested a review from leewei05 June 8, 2024 10:32
@Lai-YT Lai-YT self-assigned this Jun 8, 2024
Copy link
Contributor

@leewei05 leewei05 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@leewei05 leewei05 merged commit 6ef6a7b into fruits-lab:main Jun 13, 2024
4 checks passed
@Lai-YT Lai-YT deleted the feat-init-declarator-list branch June 13, 2024 12:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants