GeezerVison is showing github.com — [java] Merge prefix/postfix expressions into one node by oowekyala · Pull Request #2155 · pmd/pmd
Conversation
oowekyala
commented
Dec 9, 2019
•
edited by adangel
Loading
Uh oh!
There was an error while loading. Please reload this page.
Merges IncrementExpression into UnaryExpression. Instead the operator has a method to check whether it has side effects. This doesn't hurt usability, and fixes the inconsistency with the naming of those nodes (increment expressions may also be decrementing, and they are unary, by definition).
This section of the wiki can be updated to read:
Merge unary expressions
- What: Merge AST nodes for postfix and prefix expressions into the single UnaryExpression node. The merged nodes are:
- PreIncrementExpression
- PreDecrementExpression
- UnaryExpression
- UnaryExpressionNotPlusMinus
- Why: Those nodes were asymmetric, and inconsistently nested within UnaryExpression. By definition they're all unary, so that using a single node is appropriate.
- #1890 [java] Merge different increment/decrement expressions
| Code | Old AST | New AST |
|
|
StatementExpression
+ PreIncrementExpression
+ PrimaryExpression
+ PrimaryPrefix
+ Name "a"
StatementExpression
+ PreDecrementExpression
+ PrimaryExpression
+ PrimaryPrefix
+ Name "b"
StatementExpression
+ PostfixExpression "++"
+ PrimaryExpression
+ PrimaryPrefix
+ Name "c"
StatementExpression
+ PostfixExpression "--"
+ PrimaryExpression
+ PrimaryPrefix
+ Name "d"
|
StatementExpression
+ UnaryExpression[@Prefix=true()][@Operator="++"]
+ VariableAccess "a"
StatementExpression
+ UnaryExpression[@Prefix=true()][@Operator="--"]
+ VariableAccess "b"
StatementExpression
+ UnaryExpression[@Prefix=false()][@Operator="++"]
+ VariableAccess "c"
StatementExpression
+ UnaryExpression[@Prefix=false()][@Operator="--"]
+ VariableAccess "d"
|
|
|
UnaryExpression[@Image=null]
+ UnaryExpressionNotPlusMinus[@Image="~"]
+ PrimaryExpression
+ PrimaryPrefix
+ Name "a"
UnaryExpression[@Image="+"]
+ PrimaryExpression
+ PrimaryPrefix
+ Name "a"
|
+ UnaryExpression[@Operator="~"]
+ VariableAccess "a"
+ UnaryExpression[@Operator="+"]
+ VariableAccess "a"
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Among the different possible categorisations
of unary expressions, this is probably the
most logical and easiest to document.
Here's a comparison of different possible
categorisations. Note: `_++` is the postfix
increment operator, while `++_` is the prefix
one - idem for decrement. The last one is the
one implemented by this commit.
\## 6.0.x
```
Unary = { -, + }
UnaryNotPlusMinus { !, ~ }
PreIncrement = { ++_ }
PreDecrement { --_ }
Postfix { _++, _++ }
```
* Very assymmetric, splits operators based on parsing
concerns
\## Before pmd#1890:
```
Unary = { -, + , !, ~ }
PreIncrement = { ++_ }
PreDecrement { --_ }
Postfix { _++, _++ }
```
* Minor simplification
\## pmd#1890:
```
Unary = Prefix \ { ++_, --_ })
Increment ( { ++ , -- } x (postfix, prefix) )
```
* Names are weird (IncrementExpr may be decrement, Unary != Increment
even though semantically, Increment \subset Unary)
* No possibility to introduce a supertype (what would it be?)
* But easy to match all increment/decrement expressions
\## JLS (also, Eclipse):
```
Prefix = { !, ~, -, +, ++_, --_ }
Postfix = { _++, _-- }
```
* Both can have super interface UnaryExpr
* This allows matching all increment/decrement expressions easily too
* Easiest to document, JLS like, AST like
* Fits well with `InfixExpr`
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
|
1 Message
|
| 📖 |
No java rules are changed! |
Generated by 🚫 Danger
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Reviewers
adangel
adangel approved these changes
Uh oh!
There was an error while loading. Please reload this page.
Assignees
No one assigned
Labels
in:ast
About the AST structure or API, the parsing step
Development
Successfully merging this pull request may close these issues.
Uh oh!
There was an error while loading. Please reload this page.
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.
|