Klasse CombinedBinaryExpression

Alle implementierten Schnittstellen:
OperatorIds, TypeConstants, TypeIds

public class CombinedBinaryExpression extends BinaryExpression
CombinedBinaryExpression is an implementation of BinaryExpression that specifically attempts to mitigate the issues raised by expressions which have a very deep leftmost branch. It does so by maintaining a table of direct references to its subexpressions, and implementing non-recursive variants of the most significant recursive algorithms of its ancestors. The subexpressions table only holds intermediate binary expressions. Its role is to provide the reversed navigation through the left relationship of BinaryExpression to Expression. To cope with potentially very deep left branches, an instance of CombinedBinaryExpression is created once in a while, using variable thresholds held by arityMax. As a specific case, the topmost node of all binary expressions that are deeper than one is a CombinedBinaryExpression, but it has no references table.
Notes:
  • CombinedBinaryExpression is not meant to behave in other ways than BinaryExpression in any observable respect;
  • visitors that implement their own traversal upon binary expressions should consider taking advantage of combined binary expressions, or else face a risk of StackOverflowError upon deep instances;
  • callers that need to change the operator should rebuild the expression from scratch, or else amend the references table as needed to cope with the resulting, separated expressions.
  • Felddetails

    • arity

      public int arity
      The number of consecutive binary expressions of this' left branch that bear the same operator as this.
      Notes:
      • the presence of a CombinedBinaryExpression instance resets arity, even when its operator is compatible;
      • this property is maintained by the parser.
    • arityMax

      public int arityMax
      The threshold that will trigger the creation of the next full-fledged CombinedBinaryExpression. This field is only maintained for the topmost binary expression (it is 0 otherwise). It enables a variable policy, which scales better with very large expressions.
    • ARITY_MAX_MAX

      public static final int ARITY_MAX_MAX
      Upper limit for arityMax.
      Siehe auch:
    • ARITY_MAX_MIN

      public static final int ARITY_MAX_MIN
      Default lower limit for arityMax.
      Siehe auch:
    • defaultArityMaxStartingValue

      public static int defaultArityMaxStartingValue
      Default value for the first term of the series of arityMax values. Changing this allows for experimentation. Not meant to be changed during a parse operation.
    • referencesTable

      public BinaryExpression[] referencesTable
      A table of references to the binary expressions of this' left branch. Instances of CombinedBinaryExpression are not repeated here. Instead, the left subexpression of referencesTable[0] may be a combined binary expression, if appropriate. Null when this only cares about tracking the expression's arity.
  • Konstruktordetails

    • CombinedBinaryExpression

      public CombinedBinaryExpression(Expression left, Expression right, int operator, int arity)
      Make a new CombinedBinaryExpression. If arity is strictly greater than one, a references table is built and initialized with the reverse relationship of the one defined by BinaryExpression.left. arity and left must be compatible with each other (that is, there must be at least arity - 1 consecutive compatible binary expressions into the leftmost branch of left, the topmost of which being left's immediate left expression).
      Parameter:
      left - the left branch expression
      right - the right branch expression
      operator - the operator for this binary expression - only PLUS for now
      arity - the number of binary expressions of a compatible operator that already exist into the leftmost branch of left (including left); must be strictly greater than 0
    • CombinedBinaryExpression

      public CombinedBinaryExpression(CombinedBinaryExpression expression)
  • Methodendetails