@@ -52,7 +52,7 @@ public class ExpressionTreeElement {
52
52
*/
53
53
private static final ExpressionTreeElement [] EMPTY = new ExpressionTreeElement [0 ];
54
54
public static final int ANY_ARITY = -1 ;
55
- private static final int MAX_FUNCTION_ARGUMENTS = 256 ;
55
+ public static final int MAX_FUNCTION_ARGUMENTS = 256 ;
56
56
/**
57
57
* Contains the source string for the expression.
58
58
*/
@@ -88,10 +88,16 @@ public class ExpressionTreeElement {
88
88
*/
89
89
private Set <Integer > expectedArities = Set .of ();
90
90
91
+ @ Override
92
+ public String toString () {
93
+ return "ExpressionTreeElement(item=" + this .savedItem + ",slots=" + childrenSlots .length + ")" ;
94
+ }
95
+
91
96
private ExpressionTreeElement () {
92
97
this .sourceString = "" ;
93
98
this .includeStack = new FilePositionInfo [0 ];
94
99
}
100
+
95
101
/**
96
102
* The constructor
97
103
*
@@ -108,7 +114,6 @@ private ExpressionTreeElement() {
108
114
throw new PreprocessorException ("[Expression]The item is null" , this .sourceString ,
109
115
this .includeStack , null );
110
116
}
111
-
112
117
if (item .getExpressionItemType () == ExpressionItemType .OPERATOR ) {
113
118
final int arity = ((AbstractOperator ) item ).getArity ();
114
119
this .expectedArities = Set .of (arity );
@@ -159,7 +164,7 @@ public boolean isEmptySlot() {
159
164
}
160
165
161
166
private void assertNotEmptySlot () {
162
- if (isEmptySlot ()) {
167
+ if (this . isEmptySlot ()) {
163
168
throw new UnsupportedOperationException ("Unsupported operation for empty slot" );
164
169
}
165
170
}
@@ -168,7 +173,7 @@ private void assertNotEmptySlot() {
168
173
* Internal auxiliary function to set the maximum priority the element
169
174
*/
170
175
void makeMaxPriority () {
171
- priority = ExpressionItemPriority .VALUE .getPriority ();
176
+ this . priority = ExpressionItemPriority .VALUE .getPriority ();
172
177
}
173
178
174
179
/**
@@ -188,7 +193,7 @@ public ExpressionItem getItem() {
188
193
*/
189
194
190
195
public ExpressionTreeElement getParent () {
191
- return parentTreeElement ;
196
+ return this . parentTreeElement ;
192
197
}
193
198
194
199
/**
@@ -239,20 +244,16 @@ public boolean replaceElement(final ExpressionTreeElement oldOne,
239
244
this .includeStack , null );
240
245
}
241
246
242
- boolean result = false ;
243
-
244
- final ExpressionTreeElement [] children = childrenSlots ;
245
- final int len = children .length ;
246
-
247
- for (int i = 0 ; i < len ; i ++) {
248
- if (children [i ] == oldOne ) {
249
- children [i ] = newOne ;
247
+ boolean replaced = false ;
248
+ for (int i = 0 ; i < this .childrenSlots .length ; i ++) {
249
+ if (this .childrenSlots [i ] == oldOne ) {
250
+ this .childrenSlots [i ] = newOne ;
250
251
newOne .parentTreeElement = this ;
251
- result = true ;
252
+ replaced = true ;
252
253
break ;
253
254
}
254
255
}
255
- return result ;
256
+ return replaced ;
256
257
}
257
258
258
259
/**
@@ -298,11 +299,12 @@ public ExpressionTreeElement addTreeElement(final ExpressionTreeElement element)
298
299
}
299
300
if (element .nextChildSlotIndex >= element .childrenSlots .length ) {
300
301
throw new PreprocessorException (
301
- "[Expression]Can't process expression item, may be wrong number of arguments" ,
302
+ "[Expression] Can't add slot data, may be wrong number of arguments, slot index is " +
303
+ element .nextChildSlotIndex +
304
+ " but maximum slots is " + element .childrenSlots .length ,
302
305
this .sourceString , this .includeStack , null );
303
306
}
304
- element .childrenSlots [element .nextChildSlotIndex ] = this ;
305
- element .nextChildSlotIndex ++;
307
+ element .childrenSlots [element .nextChildSlotIndex ++] = this ;
306
308
this .parentTreeElement = element ;
307
309
result = element ;
308
310
} else if (this .isFull ()) {
@@ -387,7 +389,7 @@ private void addElementToNextFreeSlot(final ExpressionTreeElement element) {
387
389
this .includeStack , null );
388
390
}
389
391
390
- if (childrenSlots .length == 0 ) {
392
+ if (this . childrenSlots .length == 0 ) {
391
393
throw new PreprocessorException (
392
394
"[Expression]Unexpected element, may be unknown function [" + savedItem .toString () + ']' ,
393
395
this .sourceString , this .includeStack , null );
@@ -410,21 +412,21 @@ public void postProcess() {
410
412
switch (savedItem .getExpressionItemType ()) {
411
413
case OPERATOR : {
412
414
if (savedItem == OPERATOR_SUB ) {
413
- if (!childrenSlots [0 ].isEmptySlot () && childrenSlots [1 ].isEmptySlot ()) {
414
- final ExpressionTreeElement left = childrenSlots [0 ];
415
+ if (!this . childrenSlots [0 ].isEmptySlot () && this . childrenSlots [1 ].isEmptySlot ()) {
416
+ final ExpressionTreeElement left = this . childrenSlots [0 ];
415
417
final ExpressionItem item = left .getItem ();
416
418
if (item .getExpressionItemType () == ExpressionItemType .VALUE ) {
417
419
final Value val = (Value ) item ;
418
420
switch (val .getType ()) {
419
421
case INT : {
420
- childrenSlots = EMPTY ;
421
- savedItem = Value .valueOf (-val .asLong ());
422
+ this . childrenSlots = EMPTY ;
423
+ this . savedItem = Value .valueOf (-val .asLong ());
422
424
makeMaxPriority ();
423
425
}
424
426
break ;
425
427
case FLOAT : {
426
- childrenSlots = EMPTY ;
427
- savedItem = Value .valueOf (0.0f - val .asFloat ());
428
+ this . childrenSlots = EMPTY ;
429
+ this . savedItem = Value .valueOf (0.0f - val .asFloat ());
428
430
makeMaxPriority ();
429
431
}
430
432
break ;
@@ -437,14 +439,14 @@ public void postProcess() {
437
439
}
438
440
}
439
441
} else {
440
- for (final ExpressionTreeElement element : childrenSlots ) {
442
+ for (final ExpressionTreeElement element : this . childrenSlots ) {
441
443
if (!element .isEmptySlot ()) {
442
444
element .postProcess ();
443
445
}
444
446
}
445
447
}
446
448
} else {
447
- for (final ExpressionTreeElement element : childrenSlots ) {
449
+ for (final ExpressionTreeElement element : this . childrenSlots ) {
448
450
if (!element .isEmptySlot ()) {
449
451
element .postProcess ();
450
452
}
@@ -453,7 +455,7 @@ public void postProcess() {
453
455
}
454
456
break ;
455
457
case FUNCTION : {
456
- for (final ExpressionTreeElement element : childrenSlots ) {
458
+ for (final ExpressionTreeElement element : this . childrenSlots ) {
457
459
if (!element .isEmptySlot ()) {
458
460
element .postProcess ();
459
461
}
0 commit comments