Module dev.civl.abc

Interface StructureOrUnionType

All Superinterfaces:
Entity, ObjectType, ProgramEntity, TaggedEntity, Type, UnqualifiedObjectType

public interface StructureOrUnionType extends UnqualifiedObjectType, TaggedEntity

A structure or union type. Such a type is specified by (0) a key, (1) a bit which says whether this is a structure or a union, (2) a tag (which is a string which names the type), and (3) a sequence of Fields, which are the members of the type. The type may be incomplete (the fields have not yet been specified) or complete (the fields have been specified).

Two instances are considered equal if they have equal keys, isStruct bits, and tags.

TODO: Idea for dealing better with anonymous members. Introduce new methods getMember(String), getNumMembers(), getMember(int). Check that no two members have the same name --- even if they are deep.
  • Method Details

    • getKey

      Object getKey()
      Returns the key associated to this instance. The key is used in the determination of equality of two instances of StructureOrUnionType.
      Returns:
      the key
    • getTag

      String getTag()
      Returns the tag of this type. The tag is the string that occurs in the declaration. For example, in a declaration "struct foo {...}", the tag is "foo".
      Returns:
      the tag of this type
    • isStruct

      boolean isStruct()
      Is this a struct, not a union?
      Returns:
      true if struct, false if union
    • isUnion

      boolean isUnion()
      Is this a union, not a struct?
      Returns:
      true if union, false if struct
    • findFieldCycle

      Iterable<Field> findFieldCycle()
      Attempts to find a cyclic type dependence in the fields of this struct/union type. This method tries to find a sequence of fields f_1, ..., f_n such that f_1 is a field of this type, f_(i+1) is a field of the type of field f_i, and the type of f_n is equal to this.
      Returns:
      null if this type does not contain a field cycle, otherwise returns the sequence of fields f_1, ..., f_n as described above.
    • getNumFields

      int getNumFields()
      Returns the number of fields (members) of this structure or union type.
      Returns:
      the number of fields in this type
      Throws:
      RuntimeException - if this type is not yet complete
    • getField

      Field getField(int index)
      Returns the index-th field in this structure or union type.
      Parameters:
      index - an integer between 0 and the number of fields minus 1, inclusive
      Returns:
      the index-th field
      Throws:
      RuntimeException - if this type is not yet complete
    • getField

      Field getField(String fieldName)
    • getFields

      Iterable<Field> getFields()
      Returns an iterator over the fields in this type, or null if this type is not yet complete.
      Returns:
      an iterable over the fields, in order, or null
    • complete

      void complete(Iterable<Field> fields)
      Completes this structure of union type by specifying its contents, i.e., the list of fields.
      Parameters:
      fields - an ordered list of fields
      Throws:
      RuntimeException - if this type is already complete
    • clear

      void clear()
      Make incomplete.
    • getType

      Description copied from interface: ProgramEntity

      Other than Label, and PragmaHandler, every kind of Entity has a type, returned by this method. For a Label or PragmaHandler, this returns null.

      The type is initially null. It can be set using method ProgramEntity.setType(Type).

      Specified by:
      getType in interface ProgramEntity
      Returns:
      the type of this entity or null
    • findDeepField

      Field[] findDeepField(String fieldName)
      Finds the field with the given name by looking not only in the immediate scope but also recursively through anonymous structure and union members. According to C11, these deep fields are also members of this structure or union.
      Parameters:
      fieldName - the name of the field to search for
      Returns:
      the sequence of fields that navigate to the deep field named fieldName, or null if no such such field exists. The first elements of this sequence will be an immediate field. The last element will be the Field named fieldName.