Bug 169745 - [DOM] infix operators are not always flattened
Summary: [DOM] infix operators are not always flattened
Status: NEW
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.2.1   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: JDT-Core-Inbox CLA
QA Contact:
URL:
Whiteboard: stalebug
Keywords:
Depends on:
Blocks:
 
Reported: 2007-01-05 20:52 EST by xcok CLA
Modified: 2022-10-25 13:22 EDT (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description xcok CLA 2007-01-05 20:52:30 EST
In the Java AST, the InfixExpression AST node is allowed to have more than 2
operands, where the one operator is applied to all.  However, this flattening
is not always performed.  See the trees below.  A - operation followed by many
+ operations is not flattened, whereas many + followed by a - is flattened.
(I actually found it a pain to coerce my parser to reproduce this - it would
have been easier just to compare the current operator with the operator from
the previous (LH) operand - if the same, combine; if not, make a new Infix node)

TREES FOR class A { int i = 1 - 2 + 3 + 4 + 5; int j = 1 + 2 + 3 + 4 - 5; }
ECLIPSE AST
0) class org.eclipse.jdt.core.dom.CompilationUnit 0 65
 1) class org.eclipse.jdt.core.dom.TypeDeclaration 0 65
      interface = false
  2) class org.eclipse.jdt.core.dom.SimpleName 6 1
       identifier = A
  3) class org.eclipse.jdt.core.dom.FieldDeclaration 10 26
   4) class org.eclipse.jdt.core.dom.PrimitiveType 10 3
        primitiveTypeCode = int
   5) class org.eclipse.jdt.core.dom.VariableDeclarationFragment 14 21
        extraDimensions = 0
    6) class org.eclipse.jdt.core.dom.SimpleName 14 1
         identifier = i
    7) class org.eclipse.jdt.core.dom.InfixExpression 18 17
         operator = +
     8) class org.eclipse.jdt.core.dom.InfixExpression 18 13
          operator = +
      9) class org.eclipse.jdt.core.dom.InfixExpression 18 9
           operator = +
       10) class org.eclipse.jdt.core.dom.InfixExpression 18 5
            operator = -
        11) class org.eclipse.jdt.core.dom.NumberLiteral 18 1
             token = 1
        12) class org.eclipse.jdt.core.dom.NumberLiteral 22 1
             token = 2
       13) class org.eclipse.jdt.core.dom.NumberLiteral 26 1
            token = 3
      14) class org.eclipse.jdt.core.dom.NumberLiteral 30 1
           token = 4
     15) class org.eclipse.jdt.core.dom.NumberLiteral 34 1
          token = 5
  16) class org.eclipse.jdt.core.dom.FieldDeclaration 37 26
   17) class org.eclipse.jdt.core.dom.PrimitiveType 37 3
        primitiveTypeCode = int
   18) class org.eclipse.jdt.core.dom.VariableDeclarationFragment 41 21
        extraDimensions = 0
    19) class org.eclipse.jdt.core.dom.SimpleName 41 1
         identifier = j
    20) class org.eclipse.jdt.core.dom.InfixExpression 45 17
         operator = -
     21) class org.eclipse.jdt.core.dom.InfixExpression 45 13
          operator = +
      22) class org.eclipse.jdt.core.dom.NumberLiteral 45 1
           token = 1
      23) class org.eclipse.jdt.core.dom.NumberLiteral 49 1
           token = 2
      24) class org.eclipse.jdt.core.dom.NumberLiteral 53 1
           token = 3
      25) class org.eclipse.jdt.core.dom.NumberLiteral 57 1
           token = 4
     26) class org.eclipse.jdt.core.dom.NumberLiteral 61 1
          token = 5
Comment 1 Olivier Thomann CLA 2007-06-22 14:55:58 EDT
For 1 - 2 + 3 + 4 + 5, are you expecting to get an infix expression with:
-left: an infix expression that contains (1 - 2)
- rigth: 3
- extended operands: 4, 5
?
Comment 2 xcok CLA 2007-09-27 14:15:51 EDT
(In reply to comment #1)
> For 1 - 2 + 3 + 4 + 5, are you expecting to get an infix expression with:
> -left: an infix expression that contains (1 - 2)
> - rigth: 3
> - extended operands: 4, 5
> ?

Yes (and sorry I missed this comment when it was originally made).
Comment 3 Eclipse Genie CLA 2020-07-20 14:20:03 EDT
This bug hasn't had any activity in quite some time. Maybe the problem got resolved, was a duplicate of something else, or became less pressing for some reason - or maybe it's still relevant but just hasn't been looked at yet.

If you have further information on the current state of the bug, please add it. The information can be, for example, that the problem still occurs, that you still want the feature, that more information is needed, or that the bug is (for whatever reason) no longer relevant.

--
The automated Eclipse Genie.
Comment 4 Eclipse Genie CLA 2022-10-25 13:22:09 EDT
This bug hasn't had any activity in quite some time. Maybe the problem got resolved, was a duplicate of something else, or became less pressing for some reason - or maybe it's still relevant but just hasn't been looked at yet.

If you have further information on the current state of the bug, please add it. The information can be, for example, that the problem still occurs, that you still want the feature, that more information is needed, or that the bug is (for whatever reason) no longer relevant.

--
The automated Eclipse Genie.