GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — [java] Merge prefix/postfix expressions into one node by oowekyala · Pull Request #2155 · pmd/pmd

Conversation

@oowekyala

@oowekyala oowekyala commented Dec 9, 2019 •
edited by adangel
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member

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
CodeOld ASTNew AST
++a;
--b;
c++;
d--;
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"
~a
+a
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.

All reactions
oowekyala added 7 commits September 26, 2019 05:57
@oowekyala
Split UnaryExpr into Prefix and Postfix
b769629
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`
@oowekyala
Test precedence of cast
555c98d
@oowekyala
Checkstyle
8744fa9
@oowekyala
Merge branch 'java-grammar' into grammar-prefix-postfix
c7da6e9
@oowekyala
Fix style
928be5d
@oowekyala
Use a single node for unary exprs
76439a4
@oowekyala
Remove whitespace changes
03e9b64
@oowekyala oowekyala added the in:ast About the AST structure or API, the parsing step label Dec 9, 2019
@oowekyala oowekyala added this to the 7.0.0 milestone Dec 9, 2019
adangel
adangel approved these changes Dec 9, 2019
View reviewed changes

@adangel adangel left a comment

Copy link
Copy Markdown
Member

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.

looks good 👍

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@oowekyala
Fix tests
07c53cd
@ghost

ghost commented Dec 10, 2019

Copy link
Copy Markdown
1 Message
📖 No java rules are changed!

Generated by 🚫 Danger

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@oowekyala
Merge branch 'java-grammar' into grammar-prefix-postfix
218fdc7
@oowekyala
oowekyala merged commit 218fdc7 into pmd:java-grammar Dec 15, 2019
@oowekyala
oowekyala deleted the grammar-prefix-postfix branch December 15, 2019 00:35
@adangel adangel mentioned this pull request Jan 23, 2023
PMD 7 Tracking Issue #3898
Closed
55 tasks done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@adangel 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

Projects

None yet

Milestone

7.0.0

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

2 participants

@oowekyala @adangel
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.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.