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.Footnotes: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 invalid input: '&' 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 invalid input: '&' 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.
In addition, string literals and compound literals.
- 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.
-
Nested Class Summary
Nested Classes -
Method Summary
Modifier and TypeMethodDescriptionalignofValue(Type type) characterValue(ExecutionCharacter character) complexFloatingValue(FloatingType type, RealFloatingValue realPart, RealFloatingValue imaginaryPart) evaluate(ExpressionNode constantExpression) Evaluates a constant expression.integerValue(IntegerType type, int intValue) An integer value of the given type and with the given Java int value.integerValue(IntegerType type, BigInteger integerValue) Is the value a zero value? Maybe, maybe not: how to deal? Thm prover time.newArrayValue(ArrayType type) Creates a new empty array value.newUnionValue(StructureOrUnionType unionType, Field field, Value memberValue) operatorValue(Type type, OperatorNode.Operator operator, Value[] arguments) The legal operators are: ADDRESSOF: invalid input: '&' pointer to object BITAND: invalid input: '&' 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: invalid input: '&'invalid input: '&' logical and LOR: || logical or LT: invalid input: '<' less than LTE: invalid input: '<'= 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: invalid input: '<'invalid input: '<' shift left SHIFTRIGHT: >> shift right SUBSCRIPT: [] array subscript TIMES: * numeric multiplication UNARYMINUS: - numeric negative UNARYPLUS // + numeric no-opplusOne(IntegerValue value) realFloatingValue(FloatingType type, int radix, BigInteger wholePartValue, BigInteger fractionPartValue, int fractionLength, BigInteger exponentValue) sizeofValue(Type type) stringValue(StringLiteral literal)
-
Method Details
-
evaluate
Evaluates a constant expression.- Parameters:
constantExpression- a constant expression- Returns:
- value of that expression
- Throws:
SyntaxException- if expression is not a constant expression
-
isZero
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
-
characterValue
-
stringValue
-
integerValue
-
integerValue
An integer value of the given type and with the given Java int value. Provided for convenience.- Parameters:
type- an integer typeintValue- 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) -
complexFloatingValue
ComplexFloatingValue complexFloatingValue(FloatingType type, RealFloatingValue realPart, RealFloatingValue imaginaryPart) -
sizeofValue
-
alignofValue
-
castValue
-
addressValue
- Throws:
SyntaxException
-
operatorValue
The legal operators are:- ADDRESSOF: invalid input: '&' pointer to object
- BITAND: invalid input: '&' 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: invalid input: '&'invalid input: '&' logical and
- LOR: || logical or
- LT: invalid input: '<' less than
- LTE: invalid input: '<'= 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: invalid input: '<'invalid input: '<' 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 operatorsarguments- list of arguments to that operator- Returns:
- an OperatorValue as specified
-
newArrayValue
Creates a new empty array value. The value can be completed using the methods provided in ArrayValue. -
newStructureValue
-
newUnionValue
-