Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Combine Elsif node with IfNode #299

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

Merged
merged 4 commits into from
Mar 8, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Update yarv compiler and decompiler to stop using Elsif node
  • Loading branch information
egiurleo committed Mar 3, 2023
commit 17539d0d78a0e13ddb5a53bb2590cf8633e6af6f
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) a

- Fixed the AST output by adding blocks to `Command` and `CommandCall` nodes in the `FieldVisitor`.
- Fixed the location of lambda local variables (e.g., `->(; a) {}`).
- The `Elsif` node has been folded into `IfNode`. A `keyword` field has been added to `IfNode` specifying if the node represents an `if` or `elsif`.

## [6.0.1] - 2023-02-26

Expand Down
12 changes: 1 addition & 11 deletions lib/syntax_tree/yarv/compiler.rb
Original file line number Diff line number Diff line change
Expand Up @@ -916,17 +916,6 @@ def visit_else(node)
iseq.pop unless last_statement?
end

def visit_elsif(node)
visit_if(
IfNode.new(
predicate: node.predicate,
statements: node.statements,
consequent: node.consequent,
location: node.location
)
)
end

def visit_ensure(node)
end

Expand Down Expand Up @@ -1054,6 +1043,7 @@ def visit_if(node)
def visit_if_op(node)
visit_if(
IfNode.new(
keyword: Kw.new(value: "if", location: Location.default),
predicate: node.predicate,
statements:
Statements.new(body: [node.truthy], location: Location.default),
Expand Down
2 changes: 1 addition & 1 deletion lib/syntax_tree/yarv/decompiler.rb
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ def decompile(iseq)
Next(Args([]))
]

clause << IfNode(clause.pop, Statements(body), nil)
clause << IfNode(Kw("if"), clause.pop, Statements(body), nil)
when Dup
clause << clause.last
when DupHash
Expand Down