Interface Type

All Known Subinterfaces:
ArithmeticType, ArrayType, AtomicType, DomainType, EnumerationType, FloatingType, FunctionType, IntegerType, LambdaType, MemType, ObjectType, PointerType, QualifiedObjectType, SetType, SignedIntegerType, SignedOrUnsignedIntegerType, StandardBasicType, StandardSignedIntegerType, StandardUnsignedIntegerType, StructureOrUnionType, UnqualifiedObjectType, UnsignedIntegerType

public interface Type

An instance of Type represents a C type. A type is a conceptual entity, not a syntactic element. This class is the root of the type hierarchy for all types used to represent C types.

There may also be additional types that are not part of C, but are part of some extension to C (such as CIVL-C).

Summary of type hierarchy:

Type

Note: AtomicType and QualifiedObjectType constructors take an UnqualifiedObjectType.

Equivalence relations: there are 3 equivalence relations on the set of types. From strongest to weakest, they are: equality, equivalence, and compatibility. If T1 equals (according to the equals method) T2, then T1 is also equivalent to T2. If T1 is equivalent to T2 then T1 is compatible with T2.

The differences mainly involve tagged entities (structs, unions, enums). In C, it is possible for two structs (for example) to have the same tag, fields, and field types, but still represent two distinct types. This happens if they are declared in two different scopes. Hence it is necessary to specify some other "hidden" component of a struct type to determine when two are equal. We call this the "key": this is any Object, whose "equals" method is used to determine when two tagged types are equal. For any key, there can be at most one struct type using that key. Hence two structs are equal if and only if their keys are equal. Since there can be only one struct object with that key, it follows that they are ==. This invariant is enforced by the type factory.

Two structs which are not equal may still be "equivalent". This means they have equal tags (equal as strings), and, they are either both complete or both incomplete. If they are complete, they must have equivalent fields with the same names and in the same order.

Two structs which are not equal may nevertheless be "compatible". An incomplete struct with tag T is compatible with any struct with tag T. An incomplete array type is compatible with a complete array type which has a compatible element type.

  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Interface
    Description
    static enum 
    The different kinds of types.
  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
    Is this type "compatible" with the given type? See C11 Sec.
    boolean
    Is this type "equivalent to" the given type.
    int
    The types created by the type factories are given unique id numbers.
    boolean
    C11 6.2.4(21): "Arithmetic types and pointer types are collectively called scalar types."
    boolean
    Is this type a "VM" type (variable modified type)? This is defined in the C11 Standard Sec.
    The kind of type this is.
    void
    print(String prefix, PrintStream out, boolean abbrv)
    Prints the type in a tree-formatted style.
  • Method Details

    • compatibleWith

      boolean compatibleWith(Type type)

      Is this type "compatible" with the given type? See C11 Sec. 6.2.7 for the definition of "compatible".

      Special handling for tags that begin with "$anon"--all of these are treated as identical. These are the names given to anonymous entities by ABC for convenience.

      Parameters:
      type - the type to compare with this one for compatibility
      Returns:
      true iff the two types are compatible
    • equivalentTo

      boolean equivalentTo(Type type)

      Is this type "equivalent to" the given type. Two equivalent types should be interchangeable in any situation. Note that an incomplete struct type (for example) will never be equivalent to a complete struct type, though they may be compatible.

      Special handling for tags that begin with "$anon"--all of these are treated as identical. These are the names given to anonymous entities by ABC for convenience.

      Parameters:
      type - any type
      Returns:
      true iff the two types are equivalent.
    • getId

      int getId()
      The types created by the type factories are given unique id numbers. This method returns the id number of this type.
      Returns:
      the id number of this type
    • isScalar

      boolean isScalar()
      C11 6.2.4(21): "Arithmetic types and pointer types are collectively called scalar types."
      Returns:
      true iff type is scalar
    • isVariablyModified

      boolean isVariablyModified()
      Is this type a "VM" type (variable modified type)? This is defined in the C11 Standard Sec. 6.7.6:
      If, in the nested sequence of declarators in a full declarator, there is a declarator specifying a variable length array type, the type specified by the full declarator is said to be variably modified. Furthermore, any type derived by declarator type derivation from a variably modified type is itself variably modified.
      The definition of "variable length array type" is given in Sec. 6.7.6.2:
      If the size is not present, the array type is an incomplete type. If the size is * instead of being an expression, the array type is a variable length array type of unspecified size, which can only be used in declarations or type names with function prototype scope;143) such arrays are nonetheless complete types. If the size is an integer constant expression and the element type has a known constant size, the array type is not a variable length array type; otherwise, the array type is a variable length array type. (Variable length arrays are a conditional feature that implementations need not support; see 6.10.8.3.)
      Returns:
      true iff this type is a VM type
    • kind

      The kind of type this is. See definition of the enumerated type Type.TypeKind. These kinds partition the set of all types.
      Returns:
      the kind of this type
    • print

      void print(String prefix, PrintStream out, boolean abbrv)
      Prints the type in a tree-formatted style. The prefix string is prepended to each line of output other than the first. Output for structure or union types may leave out the fields by setting abbrv to true.
      Parameters:
      prefix - string to preprend to lines after first
      out - PrintStream to which output should be sent
      abbrv - if true, abbreviate representations of structure or union types by leaving out their fields