Interface ValueFactory


public interface ValueFactory
Constant expressions are discussed in C11 Sec. 6.6:
A constant expression can be evaluated during translation rather than runtime, and accordingly may be used in any place that a constant may be.

Constraints

  • 3. Constant expressions shall not contain assignment, increment, decrement, function-call, or comma operators, except when they are contained within a subexpression that is not evaluated.(115)
  • 4. Each constant expression shall evaluate to a constant that is in the range of representable values for its type.

Semantics

  • 5. An expression that evaluates to a constant is required in several contexts. If a floating expression is evaluated in the translation environment, the arithmetic range and precision shall be at least as great as if the expression were being evaluated in the execution environment.(116)
  • 6. An integer constant expression(117) shall have integer type and shall only have operands that are integer constants, enumeration constants, character constants, sizeof expressions whose results are integer constants, _Alignof expressions, and floating constants that are the immediate operands of casts. Cast operators in an integer constant expression shall only convert arithmetic types to integer types, except as part of an operand to the sizeof or _Alignof operator.
  • 7. More latitude is permitted for constant expressions in initializers. Such a constant expression shall be, or evaluate to, one of the following:
    • an arithmetic constant expression,
    • a null pointer constant,
    • an address constant, or
    • an address constant for a complete object type plus or minus an integer constant expression.
  • 8. An arithmetic constant expression shall have arithmetic type and shall only have operands that are integer constants, floating constants, enumeration constants, character constants, sizeof expressions whose results are integer constants, and _Alignof expressions. Cast operators in an arithmetic constant expression shall only convert arithmetic types to arithmetic types, except as part of an operand to a sizeof or _Alignof operator.
  • 9. An address constant is a null pointer, a pointer to an lvalue designating an object of static storage duration, or a pointer to a function designator; it shall be created explicitly using the unary & operator or an integer constant cast to pointer type, or implicitly by the use of an expression of array or function type. The array-subscript [] and member-access . and -> operators, the address & and indirection * unary operators, and pointer casts may be used in the creation of an address constant, but the value of an object shall not be accessed by use of these operators.
  • 10. An implementation may accept other forms of constant expressions.
  • 11. The semantic rules for the evaluation of a constant expression are the same as for nonconstant expressions.
Footnotes:
  • 115) The operand of a sizeof or _Alignof operator is usually not evaluated (6.5.3.4).
  • 116) The use of evaluation formats as characterized by FLT_EVAL_METHOD also applies to evaluation in the translation environment.
  • 117) An integer constant expression is required in a number of contexts such as the size of a bit-field member of a structure, the value of an enumeration constant, and the size of a non-variable length array. Further constraints that apply to the integer constant expressions used in conditional-inclusion preprocessing directives are discussed in 6.10.1.
In addition, string literals and compound literals.
  • Method Details

    • evaluate

      Value evaluate(ExpressionNode constantExpression) throws SyntaxException
      Evaluates a constant expression.
      Parameters:
      constantExpression - a constant expression
      Returns:
      value of that expression
      Throws:
      SyntaxException - if expression is not a constant expression
    • isZero

      ValueFactory.Answer isZero(Value value)
      Is the value a zero value? Maybe, maybe not: how to deal? Thm prover time.
      Parameters:
      value - a value
      Returns:
      yes, no, or maybe, depending on whether the value is determined to be zero
    • plusOne

      IntegerValue plusOne(IntegerValue value)
    • characterValue

      CharacterValue characterValue(ExecutionCharacter character)
    • stringValue

      StringValue stringValue(StringLiteral literal)
    • integerValue

      IntegerValue integerValue(IntegerType type, BigInteger integerValue)
    • integerValue

      IntegerValue integerValue(IntegerType type, int intValue)
      An integer value of the given type and with the given Java int value. Provided for convenience.
      Parameters:
      type - an integer type
      intValue - a Java int
      Returns:
      the integer value with given type and int value
    • realFloatingValue

      RealFloatingValue realFloatingValue(FloatingType type, int radix, BigInteger wholePartValue, BigInteger fractionPartValue, int fractionLength, BigInteger exponentValue)
    • complexValue

      ComplexValue complexValue(FloatingType type, RealFloatingValue realPart, RealFloatingValue imaginaryPart)
    • sizeofValue

      Value sizeofValue(Type type)
    • alignofValue

      TypeValue alignofValue(Type type)
    • castValue

      CastValue castValue(Type castType, Value argument)
    • addressValue

      AddressValue addressValue(ExpressionNode lhs) throws SyntaxException
      Throws:
      SyntaxException
    • operatorValue

      OperatorValue operatorValue(Type type, OperatorNode.Operator operator, Value[] arguments)
      The legal operators are:
      • ADDRESSOF: & pointer to object
      • BITAND: & bit-wise and
      • BITCOMPLEMENT: ~ bit-wise complement
      • BITOR: | bit-wise inclusive or
      • BITXOR: ^ bit-wise exclusive or
      • CONDITIONAL: ?: the conditional operator
      • DEREFERENCE: * pointer dereference
      • DIV: / numerical division
      • EQUALS: == equality
      • GT: > greater than
      • GTE: >= greater than or equals
      • LAND: && logical and
      • LOR: || logical or
      • LT: < less than
      • LTE: <= less than or equals
      • MINUS: - binary subtraction (numbers and pointers)
      • MOD: % integer modulus
      • NEQ: != not equals
      • NOT: ! logical not
      • PLUS: + binary addition, numeric or pointer
      • SHIFTLEFT: << shift left
      • SHIFTRIGHT: >> shift right
      • SUBSCRIPT: [] array subscript
      • TIMES: * numeric multiplication
      • UNARYMINUS: - numeric negative
      • UNARYPLUS // + numeric no-op
      Parameters:
      operator - one of the legal value operators
      arguments - list of arguments to that operator
      Returns:
      an OperatorValue as specified
    • newArrayValue

      ArrayValue newArrayValue(ArrayType type)
      Creates a new empty array value. The value can be completed using the methods provided in ArrayValue.
    • newStructureValue

      StructureValue newStructureValue(StructureOrUnionType type)
    • newUnionValue

      UnionValue newUnionValue(StructureOrUnionType unionType, Field field, Value memberValue)