@@ -52,7 +52,7 @@ public class ExpressionTreeElement {
5252 */
5353 private static final ExpressionTreeElement [] EMPTY = new ExpressionTreeElement [0 ];
5454 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 ;
5656 /**
5757 * Contains the source string for the expression.
5858 */
@@ -88,10 +88,16 @@ public class ExpressionTreeElement {
8888 */
8989 private Set <Integer > expectedArities = Set .of ();
9090
91+ @ Override
92+ public String toString () {
93+ return "ExpressionTreeElement(item=" + this .savedItem + ",slots=" + childrenSlots .length + ")" ;
94+ }
95+
9196 private ExpressionTreeElement () {
9297 this .sourceString = "" ;
9398 this .includeStack = new FilePositionInfo [0 ];
9499 }
100+
95101 /**
96102 * The constructor
97103 *
@@ -108,7 +114,6 @@ private ExpressionTreeElement() {
108114 throw new PreprocessorException ("[Expression]The item is null" , this .sourceString ,
109115 this .includeStack , null );
110116 }
111-
112117 if (item .getExpressionItemType () == ExpressionItemType .OPERATOR ) {
113118 final int arity = ((AbstractOperator ) item ).getArity ();
114119 this .expectedArities = Set .of (arity );
@@ -159,7 +164,7 @@ public boolean isEmptySlot() {
159164 }
160165
161166 private void assertNotEmptySlot () {
162- if (isEmptySlot ()) {
167+ if (this . isEmptySlot ()) {
163168 throw new UnsupportedOperationException ("Unsupported operation for empty slot" );
164169 }
165170 }
@@ -168,7 +173,7 @@ private void assertNotEmptySlot() {
168173 * Internal auxiliary function to set the maximum priority the element
169174 */
170175 void makeMaxPriority () {
171- priority = ExpressionItemPriority .VALUE .getPriority ();
176+ this . priority = ExpressionItemPriority .VALUE .getPriority ();
172177 }
173178
174179 /**
@@ -188,7 +193,7 @@ public ExpressionItem getItem() {
188193 */
189194
190195 public ExpressionTreeElement getParent () {
191- return parentTreeElement ;
196+ return this . parentTreeElement ;
192197 }
193198
194199 /**
@@ -239,20 +244,16 @@ public boolean replaceElement(final ExpressionTreeElement oldOne,
239244 this .includeStack , null );
240245 }
241246
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 ;
250251 newOne .parentTreeElement = this ;
251- result = true ;
252+ replaced = true ;
252253 break ;
253254 }
254255 }
255- return result ;
256+ return replaced ;
256257 }
257258
258259 /**
@@ -298,11 +299,12 @@ public ExpressionTreeElement addTreeElement(final ExpressionTreeElement element)
298299 }
299300 if (element .nextChildSlotIndex >= element .childrenSlots .length ) {
300301 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 ,
302305 this .sourceString , this .includeStack , null );
303306 }
304- element .childrenSlots [element .nextChildSlotIndex ] = this ;
305- element .nextChildSlotIndex ++;
307+ element .childrenSlots [element .nextChildSlotIndex ++] = this ;
306308 this .parentTreeElement = element ;
307309 result = element ;
308310 } else if (this .isFull ()) {
@@ -387,7 +389,7 @@ private void addElementToNextFreeSlot(final ExpressionTreeElement element) {
387389 this .includeStack , null );
388390 }
389391
390- if (childrenSlots .length == 0 ) {
392+ if (this . childrenSlots .length == 0 ) {
391393 throw new PreprocessorException (
392394 "[Expression]Unexpected element, may be unknown function [" + savedItem .toString () + ']' ,
393395 this .sourceString , this .includeStack , null );
@@ -410,21 +412,21 @@ public void postProcess() {
410412 switch (savedItem .getExpressionItemType ()) {
411413 case OPERATOR : {
412414 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 ];
415417 final ExpressionItem item = left .getItem ();
416418 if (item .getExpressionItemType () == ExpressionItemType .VALUE ) {
417419 final Value val = (Value ) item ;
418420 switch (val .getType ()) {
419421 case INT : {
420- childrenSlots = EMPTY ;
421- savedItem = Value .valueOf (-val .asLong ());
422+ this . childrenSlots = EMPTY ;
423+ this . savedItem = Value .valueOf (-val .asLong ());
422424 makeMaxPriority ();
423425 }
424426 break ;
425427 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 ());
428430 makeMaxPriority ();
429431 }
430432 break ;
@@ -437,14 +439,14 @@ public void postProcess() {
437439 }
438440 }
439441 } else {
440- for (final ExpressionTreeElement element : childrenSlots ) {
442+ for (final ExpressionTreeElement element : this . childrenSlots ) {
441443 if (!element .isEmptySlot ()) {
442444 element .postProcess ();
443445 }
444446 }
445447 }
446448 } else {
447- for (final ExpressionTreeElement element : childrenSlots ) {
449+ for (final ExpressionTreeElement element : this . childrenSlots ) {
448450 if (!element .isEmptySlot ()) {
449451 element .postProcess ();
450452 }
@@ -453,7 +455,7 @@ public void postProcess() {
453455 }
454456 break ;
455457 case FUNCTION : {
456- for (final ExpressionTreeElement element : childrenSlots ) {
458+ for (final ExpressionTreeElement element : this . childrenSlots ) {
457459 if (!element .isEmptySlot ()) {
458460 element .postProcess ();
459461 }
0 commit comments