Class Var


public final class Var extends ExprInfo
Variable expression.
Author:
BaseX Team 2005-21, BSD License, Christian Gruen, Leo Woerteler
  • Field Details

    • name

      public final QNm name
      Variable name.
    • id

      public final int id
      Variable ID.
    • info

      public final InputInfo info
      Input info.
    • declType

      public SeqType declType
      Declared type, null if not specified.
    • promote

      public boolean promote
      Flag for function conversion.
  • Constructor Details

    • Var

      public Var(QNm name, SeqType declType, boolean param, int slot, QueryContext qc, StaticContext sc, InputInfo info)
      Constructor for a variable with an already known stack slot.
      Parameters:
      name - variable name
      declType - declared type, null for no check
      param - function parameter flag
      slot - stack slot
      qc - query context, used for generating a variable ID
      sc - static context
      info - input info
    • Var

      public Var(QNm name, SeqType declType, boolean param, QueryContext qc, StaticContext sc, InputInfo info)
      Constructor.
      Parameters:
      name - variable name
      declType - declared sequence type, null for no check
      param - function parameter flag
      qc - query context, used for generating a variable ID
      sc - static context
      info - input info
    • Var

      public Var(Var var, QueryContext qc, StaticContext sc)
      Copy constructor.
      Parameters:
      var - variable to copy
      qc - query context
      sc - static context
  • Method Details

    • seqType

      public SeqType seqType()
      Sequence type of values bound to this variable.
      Returns:
      sequence type
    • expr

      public void expr(Expr expr)
      Attaches an input expression.
      Parameters:
      expr - input expression
    • size

      public long size()
      Returns the result size.
      Returns:
      result size
    • ddo

      public boolean ddo()
      Returns the distinct document order flag. See Expr.ddo() for details.
      Returns:
      result of check
    • data

      public Data data()
      Returns the data reference bound to this variable. See Expr.data() for details.
      Returns:
      data reference (can be null)
    • declaredType

      public SeqType declaredType()
      Declared type of this variable.
      Returns:
      declared type
    • refineType

      public void refineType(SeqType st, CompileContext cc) throws QueryException
      Tries to refine the type of this variable through the type of the bound expression.
      Parameters:
      st - sequence type of the bound expression
      cc - compilation context (can be null)
      Throws:
      QueryException - query exception
    • refineType

      public void refineType(SeqType st, long size, CompileContext cc) throws QueryException
      Tries to refine the type of this variable through the type of the bound expression.
      Parameters:
      st - sequence type of the bound expression
      size - size (can be -1)
      cc - compilation context (can be null)
      Throws:
      QueryException - query exception
    • checksType

      public boolean checksType()
      Determines if this variable checks the type of the expression bound to it.
      Returns:
      true if the type is checked or promoted, false otherwise
    • checked

      public Expr checked(Expr expr, CompileContext cc) throws QueryException
      Returns an equivalent to the given expression that checks this variable's type.
      Parameters:
      expr - expression
      cc - compilation context
      Returns:
      checked expression
      Throws:
      QueryException - query exception
    • checkType

      public Value checkType(Value value, QueryContext qc, boolean opt) throws QueryException
      Checks the type of this value and casts/promotes it when necessary.
      Parameters:
      value - value to be checked
      qc - query context
      opt - if the result should be optimized
      Returns:
      checked and possibly cast value
      Throws:
      QueryException - if the check failed
    • checkType

      public void checkType(Expr expr) throws QueryException
      Checks if the type of the specified expression could be converted to the sequence type of this variable. Due to insufficient typing, the check will only be performed if:
      • The variable type is an instance of the specified type. This way, expressions with super types like item() will not be rejected.
      • The expression is to be promoted, and it is not of type node (eg: function-declaration-016)
      Parameters:
      expr - expression
      Throws:
      QueryException - query exception
    • is

      public boolean is(Var var)
      Checks whether the given variable is identical to this one, i.e. has the same id.
      Parameters:
      var - variable to check
      Returns:
      true if the IDs are equal, false otherwise
    • promotes

      public boolean promotes()
      Checks if this variable performs function conversion on its bound values.
      Returns:
      result of check
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • adoptCheck

      public boolean adoptCheck(SeqType st, boolean prom)
      Tries to adopt the given type check.
      Parameters:
      st - type to check
      prom - if function conversion should be applied
      Returns:
      true if the check could be adopted, false otherwise
    • equals

      public boolean equals(Object obj)
      Overrides:
      equals in class Object
    • plan

      public void plan(QueryPlan plan)
      Description copied from class: ExprInfo
      Creates a query plan.
      Specified by:
      plan in class ExprInfo
      Parameters:
      plan - expression plan
    • id

      public byte[] id()
      Returns a unique representation of the variable.
      Returns:
      variable id
    • plan

      public void plan(QueryString qs)
      Description copied from class: ExprInfo
      Creates a query string.
      Specified by:
      plan in class ExprInfo
      Parameters:
      qs - query string builder
    • toErrorString

      public String toErrorString()
      Description copied from class: ExprInfo
      Returns a string representation of the expression that can be embedded in error messages. Defaults to ExprInfo.toString().
      Overrides:
      toErrorString in class ExprInfo
      Returns:
      class name