public interface ConversionFactory
A factory for producing instances of
Conversion.-
Method Summary
Modifier and TypeMethodDescriptionarithmeticConversion(ArithmeticType oldType, ArithmeticType newType) Returns an ArithmeticConversion object with given old type and new type.arrayConversion(ObjectType type) Returns the array conversion with old type the given type.assignmentConversion(Configuration config, ExpressionNode rhs, Type newType) Given (1) the processed right hand side of an assignment expression and (2) the type of the assignment expression (i.e., the adjusted type of the left hand side), returns the conversion from the right-hand type to the assignment type.assignmentConversion(Configuration config, ExpressionNode rhs, Type newType, boolean ignoreQualifier) Given (1) the processed right hand side of an assignment expression and (2) the type of the assignment expression (i.e., the adjusted type of the left hand side), returns the conversion from the right-hand type to the assignment type.compatiblePointerConversion(PointerType type1, PointerType type2) Creates a new compatible-pointer-conversion object from the first pointer type to the second.Creates a new compatible-structure-or-union-conversion object from the given structure-or-union types.Returns the function conversion object with old type equal to the given function type.integer2PointerConversion(IntegerType oldType, PointerType newType) creates a integer-to-pointer type conversionbooleanIs this expression a null pointer constant? Prerequisite: node has already been processed.booleanisPointerToObject(PointerType type) Is the given pointer type a pointer an object type?booleanisPointerToVoid(PointerType type) Is the given pointer type a pointer to a qualified or unqualified version of void?lvalueConversion(ObjectType type) Returns a non-trivialLvalueConversionwith old type the given type, or null if the conversion is trivial.Returns the type that would result from applying lvalue conversion to the given type.memConversion(ExpressionNode expr) Returns the mem conversion which converts the type of the givenexprto aMemType.nullPointerConversion(ObjectType type1, PointerType type2) Conversion from an integer constant with value 0 or such cast to a void*, to a pointer type.pointer2IntegerConversion(PointerType oldType, IntegerType newType) creates a pointer-to-integer type conversionpointerBoolConversion(PointerType oldType) Conversion from any pointer type to a boolean (_Bool).regularRangeToDomainConversion(ObjectType rangeType, DomainType domainType) When a range expression is used in $for or $parfor, it is converted automatically to $domain type.voidPointerConversion(PointerType type1, PointerType type2) Creates a new conversion object between some pointer type and the typevoid*(pointer-to-void).
-
Method Details
-
getTypeFactory
TypeFactory getTypeFactory() -
arithmeticConversion
Returns an ArithmeticConversion object with given old type and new type. Note that the newType is determined by applying an algorithm to two types, of which the old type is one. The usual way to use these methods when given two arithmetic types type1 and type2 is as follows: let newType = usualArithmeticConversion(type1, type2). If newType != type1, let c1 = arithmeticConversion(type1, newType) and add the nontrivial conversion c1 to the sequence of conversions for its expression. Repeat for type2: if newType != type2, let c2=arithmeticConversion(type2, newType) and add c2 to the sequence of conversions for its expression.- Parameters:
oldType- an arithmetic type: the original type of an expressionnewType- the arithmetic type that results after applying a usual arithmetic conversion- Returns:
- an object representing the conversion of the old type to the new
-
lvalueConversion
Returns a non-trivialLvalueConversionwith old type the given type, or null if the conversion is trivial. C11 Sec. 6.3.2.1:Except when it is the operand of the sizeof operator, the
_Alignofoperator, the unaryinvalid input: '&'operator, the++operator, the--operator, or the left operand of the.operator or an assignment operator, an lvalue that does not have array type is converted to the value stored in the designated object (and is no longer an lvalue); this is called lvalue conversion. If the lvalue has qualified type, the value has the unqualified version of the type of the lvalue; additionally, if the lvalue has atomic type, the value has the non-atomic version of the type of the lvalue; otherwise, the value has the type of the lvalue. If the lvalue has an incomplete type and does not have array type, the behavior is undefined. If the lvalue designates an object of automatic storage duration that could have been declared with the register storage class (never had its address taken), and that object is uninitialized (not declared with an initializer and no assignment to it has been performed prior to use), the behavior is undefined.- Parameters:
type- an object type- Returns:
- either (1) an LvalueConversion with old type the given ObjectType and new type determined as follows: if qualified, the unqualified version; if atomic, the non-atomic version; or (2) null if the conversion is trivial (new type same as old)
-
lvalueConversionType
Returns the type that would result from applying lvalue conversion to the given type.- Parameters:
type- any object type- Returns:
- result of lvalue conversion
-
arrayConversion
Returns the array conversion with old type the given type. C11 Sec. 6.3.2.1: "Except when it is the operand of thesizeofoperator, the_Alignofoperator, or the unaryinvalid input: '&'operator, or is a string literal used to initialize an array, an expression that has type "array of type" is converted to an expression with type "pointer to type" that points to the initial element of the array object and is not an lvalue. If the array object has register storage class, the behavior is undefined." The old type may be an ArrayType or a QualifiedObjectType (with $input or $output qualifier) with base type ArrayType. I think.- Parameters:
type- any array type or qualified array type- Returns:
- array conversion with old type the given array type and new type the pointer type to the element type of the array type
-
functionConversion
Returns the function conversion object with old type equal to the given function type. C11 Sec. 6.3.2.1:A function designator is an expression that has function type. Except when it is the operand of the
sizeofoperator, the_Alignofoperator, or the unaryinvalid input: '&'operator, a function designator with type "function returning type" is converted to an expression that has type "pointer to function returning type" .- Parameters:
type- a function type- Returns:
- a FunctionConversion with old type the given function type and new type the pointer type to the function type
-
compatibleStructureOrUnionConversion
CompatibleStructureOrUnionConversion compatibleStructureOrUnionConversion(StructureOrUnionType type1, StructureOrUnionType type2) Creates a new compatible-structure-or-union-conversion object from the given structure-or-union types.- Parameters:
type1- a structure or union typetype2- a compatible structure or union type- Returns:
- the conversion from type1 to type2
-
compatiblePointerConversion
Creates a new compatible-pointer-conversion object from the first pointer type to the second.- Parameters:
type1- a pointer typetype2- a pointer type which is either compatible with type1 or is obtained from type1 by adding qualifiers to the type of thing pointed to- Returns:
- the conversion
-
voidPointerConversion
Creates a new conversion object between some pointer type and the type
void*(pointer-to-void). From C11 Sec. 6.3.2.3:A pointer to void may be converted to or from a pointer to any object type. A pointer to any object type may be converted to a pointer to void and back again; the result shall compare equal to the original pointer.
One of the two arguments must be a pointer-to-void.
- Parameters:
type1- a pointer typetype2- a pointer type- Returns:
- the conversion object from type1 to type2
-
nullPointerConversion
Conversion from an integer constant with value 0 or such cast to a void*, to a pointer type.- Parameters:
type1- an integer type or pointer-to-voidtype2- any pointer type- Returns:
- conversion from type1 to type2
-
pointerBoolConversion
Conversion from any pointer type to a boolean (_Bool).- Parameters:
oldType-- Returns:
- PointerBoolConversion with given oldType and newType the boolean type
-
assignmentConversion
Conversion assignmentConversion(Configuration config, ExpressionNode rhs, Type newType) throws UnsourcedException Given (1) the processed right hand side of an assignment expression and (2) the type of the assignment expression (i.e., the adjusted type of the left hand side), returns the conversion from the right-hand type to the assignment type. If no conversion is necessary because the types are equal, returns null. If no such conversion exists, an exception is thrown. C11 Section 6.5.16(3) states:An assignment operator stores a value in the object designated by the left operand. An assignment expression has the value of the left operand after the assignment,111) but is not an lvalue. The type of an assignment expression is the type the left operand would have after lvalue conversion. The side effect of updating the stored value of the left operand is sequenced after the value computations of the left and right operands. The evaluations of the operands are unsequenced.
and C11 Section 6.5.16.1 continues:One of the following shall hold:
These suggest the following types of conversions be used, respectively, for the cases above:- the left operand has atomic, qualified, or unqualified arithmetic type, and the right has arithmetic type;
- the left operand has an atomic, qualified, or unqualified version of a structure or union type compatible with the type of the right;
- the left operand has atomic, qualified, or unqualified pointer type, and (considering the type the left operand would have after lvalue conversion) both operands are pointers to qualified or unqualified versions of compatible types, and the type pointed to by the left has all the qualifiers of the type pointed to by the right;
- the left operand has atomic, qualified, or unqualified pointer type, and (considering the type the left operand would have after lvalue conversion) one operand is a pointer to an object type, and the other is a pointer to a qualified or unqualified version of void, and the type pointed to by the left has all the qualifiers of the type pointed to by the right;
- the left operand is an atomic, qualified, or unqualified pointer, and the right is a null pointer constant; or
- the left operand has type atomic, qualified, or unqualified _Bool, and the right is a pointer.
ArithmeticConversion,CompatibleStructureOrUnionConversion,CompatiblePointerConversion,VoidPointerConversion,NullPointerConversion,PointerBoolConversion. The processing of a simple assignement expression then proceeds as follows:- let
newTypebe the result of applying lvalue conversion to the lhs expression and make this the initial type of the assignment expression - add standard conversions to rhs expression and call the resulting
type
oldType - consider cases above to generate a conversion from
oldTypetonewType; add that conversion to rhs expression
- Parameters:
rhs- the right-hand side of the assignment, after having been processed and the standard conversions appliednewType- the type of the assignment expression, i.e., the type to which the rhs expression must be converted; it is the result of applying lvalue conversion to the left hand side.- Throws:
UnsourcedException
-
assignmentConversion
Conversion assignmentConversion(Configuration config, ExpressionNode rhs, Type newType, boolean ignoreQualifier) throws UnsourcedException Given (1) the processed right hand side of an assignment expression and (2) the type of the assignment expression (i.e., the adjusted type of the left hand side), returns the conversion from the right-hand type to the assignment type. If no conversion is necessary because the types are equal, returns null. If no such conversion exists, an exception is thrown. C11 Section 6.5.16(3) states:An assignment operator stores a value in the object designated by the left operand. An assignment expression has the value of the left operand after the assignment,111) but is not an lvalue. The type of an assignment expression is the type the left operand would have after lvalue conversion. The side effect of updating the stored value of the left operand is sequenced after the value computations of the left and right operands. The evaluations of the operands are unsequenced.
and C11 Section 6.5.16.1 continues:One of the following shall hold:
These suggest the following types of conversions be used, respectively, for the cases above:- the left operand has atomic, qualified, or unqualified arithmetic type, and the right has arithmetic type;
- the left operand has an atomic, qualified, or unqualified version of a structure or union type compatible with the type of the right;
- the left operand has atomic, qualified, or unqualified pointer type, and (considering the type the left operand would have after lvalue conversion) both operands are pointers to qualified or unqualified versions of compatible types, and the type pointed to by the left has all the qualifiers of the type pointed to by the right;
- the left operand has atomic, qualified, or unqualified pointer type, and (considering the type the left operand would have after lvalue conversion) one operand is a pointer to an object type, and the other is a pointer to a qualified or unqualified version of void, and the type pointed to by the left has all the qualifiers of the type pointed to by the right;
- the left operand is an atomic, qualified, or unqualified pointer, and the right is a null pointer constant; or
- the left operand has type atomic, qualified, or unqualified _Bool, and the right is a pointer.
ArithmeticConversion,CompatibleStructureOrUnionConversion,CompatiblePointerConversion,VoidPointerConversion,NullPointerConversion,PointerBoolConversion. The processing of a simple assignment expression then proceeds as follows:- let
newTypebe the result of applying lvalue conversion to the lhs expression and make this the initial type of the assignment expression - add standard conversions to rhs expression and call the resulting
type
oldType - consider cases above to generate a conversion from
oldTypetonewType; add that conversion to rhs expression
- Parameters:
config-rhs- the right-hand side of the assignment, after having been processed and the standard conversions appliednewType- the type of the assignment expression, i.e., the type to which the rhs expression must be converted; it is the result of applying lvalue conversion to the left hand side.ignoreQualifier- whether involved qualifiers should be ignored.- Returns:
- Throws:
UnsourcedException
-
regularRangeToDomainConversion
RegularRangeToDomainConversion regularRangeToDomainConversion(ObjectType rangeType, DomainType domainType) When a range expression is used in $for or $parfor, it is converted automatically to $domain type.- Parameters:
rangeType-domainType-- Returns:
-
isNullPointerConstant
Is this expression a null pointer constant? Prerequisite: node has already been processed. A null pointer constant is either (1) an integer constant with value 0, or (2) such a constant cast to (void *).- Parameters:
node- an expression node- Returns:
- true iff expression is a null pointer constant, else false
-
isPointerToVoid
Is the given pointer type a pointer to a qualified or unqualified version of void?- Parameters:
type- any (unqualified) pointer type- Returns:
- true iff the referenced type is a qualified (including atomic) or unqualified version of void
-
isPointerToObject
Is the given pointer type a pointer an object type?- Parameters:
type-- Returns:
trueiff the pointer type's base type is an object type
-
memConversion
Returns the mem conversion which converts the type of the given
exprto aMemType. The type ofexprmay be pointer type or set-of-pointer type- Parameters:
expr- an expression that will be converted to a $mem type expression- Returns:
- a conversion with type of the expr and
MemType - Throws:
UnsourcedException- when the old type is not a pointer type or a set of pointer typeSyntaxException- if there is a semantically invalid sub-expression in the given expression.
-
pointer2IntegerConversion
creates a pointer-to-integer type conversion- Parameters:
oldType-newType-- Returns:
-
integer2PointerConversion
creates a integer-to-pointer type conversion- Parameters:
oldType-newType-- Returns:
-