67
67
import org .elasticsearch .painless .ir .UnaryMathNode ;
68
68
import org .elasticsearch .painless .ir .WhileLoopNode ;
69
69
import org .elasticsearch .painless .lookup .PainlessLookupUtility ;
70
+ import org .elasticsearch .painless .symbol .IRDecorations .IRDExpressionType ;
70
71
71
72
import java .util .function .Consumer ;
72
73
@@ -180,7 +181,7 @@ public void visitUnaryMath(UnaryMathNode irUnaryMathNode, Consumer<ExpressionNod
180
181
if (irUnaryMathNode .getChildNode () instanceof ConstantNode ) {
181
182
ConstantNode irConstantNode = (ConstantNode )irUnaryMathNode .getChildNode ();
182
183
Operation operation = irUnaryMathNode .getOperation ();
183
- Class <?> type = irUnaryMathNode .getExpressionType ();
184
+ Class <?> type = irUnaryMathNode .getDecoration ( IRDExpressionType . class ). getType ();
184
185
185
186
if (operation == Operation .SUB ) {
186
187
if (type == int .class ) {
@@ -238,7 +239,7 @@ public void visitBinaryMath(BinaryMathNode irBinaryMathNode, Consumer<Expression
238
239
ConstantNode irLeftConstantNode = (ConstantNode )irBinaryMathNode .getLeftNode ();
239
240
ConstantNode irRightConstantNode = (ConstantNode )irBinaryMathNode .getRightNode ();
240
241
Operation operation = irBinaryMathNode .getOperation ();
241
- Class <?> type = irBinaryMathNode .getExpressionType ();
242
+ Class <?> type = irBinaryMathNode .getDecoration ( IRDExpressionType . class ). getType ();
242
243
243
244
if (operation == Operation .MUL ) {
244
245
if (type == int .class ) {
@@ -435,22 +436,22 @@ public void visitStringConcatenation(StringConcatenationNode irStringConcatenati
435
436
if (irLeftNode instanceof ConstantNode && irRightNode instanceof ConstantNode ) {
436
437
ConstantNode irConstantNode = (ConstantNode )irLeftNode ;
437
438
irConstantNode .setConstant ("" + irConstantNode .getConstant () + ((ConstantNode )irRightNode ).getConstant ());
438
- irConstantNode .setExpressionType ( String .class );
439
+ irConstantNode .attachDecoration ( new IRDExpressionType ( String .class ) );
439
440
irStringConcatenationNode .getArgumentNodes ().remove (i + 1 );
440
441
} else if (irLeftNode instanceof NullNode && irRightNode instanceof ConstantNode ) {
441
442
ConstantNode irConstantNode = (ConstantNode )irRightNode ;
442
443
irConstantNode .setConstant ("" + null + ((ConstantNode )irRightNode ).getConstant ());
443
- irConstantNode .setExpressionType ( String .class );
444
+ irConstantNode .attachDecoration ( new IRDExpressionType ( String .class ) );
444
445
irStringConcatenationNode .getArgumentNodes ().remove (i );
445
446
} else if (irLeftNode instanceof ConstantNode && irRightNode instanceof NullNode ) {
446
447
ConstantNode irConstantNode = (ConstantNode )irLeftNode ;
447
448
irConstantNode .setConstant ("" + ((ConstantNode )irLeftNode ).getConstant () + null );
448
- irConstantNode .setExpressionType ( String .class );
449
+ irConstantNode .attachDecoration ( new IRDExpressionType ( String .class ) );
449
450
irStringConcatenationNode .getArgumentNodes ().remove (i + 1 );
450
451
} else if (irLeftNode instanceof NullNode && irRightNode instanceof NullNode ) {
451
452
ConstantNode irConstantNode = new ConstantNode (irLeftNode .getLocation ());
452
453
irConstantNode .setConstant ("" + null + null );
453
- irConstantNode .setExpressionType ( String .class );
454
+ irConstantNode .attachDecoration ( new IRDExpressionType ( String .class ) );
454
455
irStringConcatenationNode .getArgumentNodes ().set (i , irConstantNode );
455
456
irStringConcatenationNode .getArgumentNodes ().remove (i + 1 );
456
457
} else {
@@ -476,7 +477,7 @@ public void visitBoolean(BooleanNode irBooleanNode, Consumer<ExpressionNode> sco
476
477
ConstantNode irLeftConstantNode = (ConstantNode )irBooleanNode .getLeftNode ();
477
478
ConstantNode irRightConstantNode = (ConstantNode )irBooleanNode .getRightNode ();
478
479
Operation operation = irBooleanNode .getOperation ();
479
- Class <?> type = irBooleanNode .getExpressionType ();
480
+ Class <?> type = irBooleanNode .getDecoration ( IRDExpressionType . class ). getType ();
480
481
481
482
if (operation == Operation .AND ) {
482
483
if (type == boolean .class ) {
@@ -544,7 +545,7 @@ public void visitComparison(ComparisonNode irComparisonNode, Consumer<Expression
544
545
}
545
546
}
546
547
547
- irLeftConstantNode .setExpressionType ( boolean .class );
548
+ irLeftConstantNode .attachDecoration ( new IRDExpressionType ( boolean .class ) );
548
549
scope .accept (irLeftConstantNode );
549
550
} else if (operation == Operation .NE || operation == Operation .NER ) {
550
551
if (type == boolean .class ) {
@@ -571,7 +572,7 @@ public void visitComparison(ComparisonNode irComparisonNode, Consumer<Expression
571
572
}
572
573
}
573
574
574
- irLeftConstantNode .setExpressionType ( boolean .class );
575
+ irLeftConstantNode .attachDecoration ( new IRDExpressionType ( boolean .class ) );
575
576
scope .accept (irLeftConstantNode );
576
577
} else if (irLeftConstantNode != null && irRightConstantNode != null ) {
577
578
if (operation == Operation .GT ) {
@@ -591,7 +592,7 @@ public void visitComparison(ComparisonNode irComparisonNode, Consumer<Expression
591
592
"constants [" + irLeftConstantNode .getConstant () + "] and [" + irRightConstantNode .getConstant () + "]" ));
592
593
}
593
594
594
- irLeftConstantNode .setExpressionType ( boolean .class );
595
+ irLeftConstantNode .attachDecoration ( new IRDExpressionType ( boolean .class ) );
595
596
scope .accept (irLeftConstantNode );
596
597
} else if (operation == Operation .GTE ) {
597
598
if (type == int .class ) {
@@ -610,7 +611,7 @@ public void visitComparison(ComparisonNode irComparisonNode, Consumer<Expression
610
611
"constants [" + irLeftConstantNode .getConstant () + "] and [" + irRightConstantNode .getConstant () + "]" ));
611
612
}
612
613
613
- irLeftConstantNode .setExpressionType ( boolean .class );
614
+ irLeftConstantNode .attachDecoration ( new IRDExpressionType ( boolean .class ) );
614
615
scope .accept (irLeftConstantNode );
615
616
} else if (operation == Operation .LT ) {
616
617
if (type == int .class ) {
@@ -629,7 +630,7 @@ public void visitComparison(ComparisonNode irComparisonNode, Consumer<Expression
629
630
"constants [" + irLeftConstantNode .getConstant () + "] and [" + irRightConstantNode .getConstant () + "]" ));
630
631
}
631
632
632
- irLeftConstantNode .setExpressionType ( boolean .class );
633
+ irLeftConstantNode .attachDecoration ( new IRDExpressionType ( boolean .class ) );
633
634
scope .accept (irLeftConstantNode );
634
635
} else if (operation == Operation .LTE ) {
635
636
if (type == int .class ) {
@@ -648,7 +649,7 @@ public void visitComparison(ComparisonNode irComparisonNode, Consumer<Expression
648
649
"constants [" + irLeftConstantNode .getConstant () + "] and [" + irRightConstantNode .getConstant () + "]" ));
649
650
}
650
651
651
- irLeftConstantNode .setExpressionType ( boolean .class );
652
+ irLeftConstantNode .attachDecoration ( new IRDExpressionType ( boolean .class ) );
652
653
scope .accept (irLeftConstantNode );
653
654
}
654
655
}
@@ -659,11 +660,12 @@ public void visitComparison(ComparisonNode irComparisonNode, Consumer<Expression
659
660
public void visitCast (CastNode irCastNode , Consumer <ExpressionNode > scope ) {
660
661
irCastNode .getChildNode ().visit (this , irCastNode ::setChildNode );
661
662
662
- if (irCastNode .getChildNode () instanceof ConstantNode && PainlessLookupUtility .isConstantType (irCastNode .getExpressionType ())) {
663
+ if (irCastNode .getChildNode () instanceof ConstantNode &&
664
+ PainlessLookupUtility .isConstantType (irCastNode .getDecoration (IRDExpressionType .class ).getType ())) {
663
665
ConstantNode irConstantNode = (ConstantNode )irCastNode .getChildNode ();
664
666
irConstantNode .setConstant (
665
667
AnalyzerCaster .constCast (irCastNode .getLocation (), irConstantNode .getConstant (), irCastNode .getCast ()));
666
- irConstantNode .setExpressionType (irCastNode . getExpressionType () );
668
+ irConstantNode .copyDecorationFrom (irCastNode , IRDExpressionType . class );
667
669
scope .accept (irConstantNode );
668
670
}
669
671
}
0 commit comments