- All Superinterfaces:
ObjectType,Type,UnqualifiedObjectType
Represents an array type. See C11 Sec. 6.7.6.2.
Note that in certain contexts type qualifiers may also occur between the
square brackets in the array type designation. These will be determined by
calling the appropriate qualifier methods in TypeNode.
An array type is an object type specified by an element type and the extent. The element type must be a complete object type. For the extent, there are 4 possibilities:
NOTE: the keyword static can only appear in the outermost part
of the declaration of a function parameter, and since the types are converted
to pointer, static does not ultimately occur in an array type.
On the other hand * can occur in any number of internal array
types in a function parameter, so it can ultimately be part of an array type.
- the extent is not specified (i.e., is null): then the array type is an "incomplete type"
- the extent is
*: this is a "VLA type of unspecified size". It is nevertheless a complete type. This can only be used in declarations or type names in function prototype scope (i.e., in a function declaration that is not part of a function definition). - the extent is an integer constant expression AND the element type has known constant size: then the array type is "not a VLA" type. It is complete. (Note: an object type has "known constant size" iff it is not incomplete AND not a VLA (Variable Length Array) type.)
- otherwise, the extent is an expression which is not a constant
expression. This is a VLA type. It is complete. If it occurs in function
prototype scope, it is treated as if it were
*(i.e., the expression is not used).
-
Nested Class Summary
Nested classes/interfaces inherited from interface dev.civl.abc.ast.type.IF.Type
Type.TypeKind -
Method Summary
Modifier and TypeMethodDescriptionIf this array has a known constant extent, it is returned by this method.intGets the dimension of this array type.The type of the elements.The expression appearing in square brackets that specifies the length of the array, when that length is not a known constant.booleanIn C11, a star (*) may appear between the square brackets instead of an integer expression.booleanIs this a Variable Length Array (VLA) type?Methods inherited from interface dev.civl.abc.ast.type.IF.ObjectType
hasKnownConstantSize, isComplete, isConstantQualifiedMethods inherited from interface dev.civl.abc.ast.type.IF.Type
compatibleWith, equivalentTo, getId, ignoreQualifiersAtomic, isScalar, isVariablyModified, kind, print
-
Method Details
-
getElementType
ObjectType getElementType()The type of the elements. This is required and must be non-null.- Returns:
- the element type
-
getVariableSize
ExpressionNode getVariableSize()The expression appearing in square brackets that specifies the length of the array, when that length is not a known constant. If the length in brackets is a known constant, or is "*", or is absent, this will returnnull.- Returns:
- the variable array extent expression or
null
-
getConstantSize
IntegerValue getConstantSize()If this array has a known constant extent, it is returned by this method. Otherwise, this method returnsnull.- Returns:
- the known constant extent or
null
-
isVariableLengthArrayType
boolean isVariableLengthArrayType()Is this a Variable Length Array (VLA) type?- Returns:
- true iff this is a VLA type
-
hasUnspecifiedVariableLength
boolean hasUnspecifiedVariableLength()In C11, a star (*) may appear between the square brackets instead of an integer expression. The star represents "a variable length array type of unspecified size, which can only be used in declarations or type names with function prototype scope." See C11 Sec. 6.7.6.2(4).- Returns:
- true if a
*occurs between the brackets
-
getDimension
int getDimension()Gets the dimension of this array type.- Returns:
- the dimension of this array type, which is greater than or equal to 1.
-