- All Superinterfaces:
Entity,ObjectType,ProgramEntity,TaggedEntity,Type,UnqualifiedObjectType
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.-
Nested Class Summary
Nested classes/interfaces inherited from interface dev.civl.abc.ast.entity.IF.Entity
Entity.EntityKindNested classes/interfaces inherited from interface dev.civl.abc.ast.entity.IF.ProgramEntity
ProgramEntity.LinkageKindNested classes/interfaces inherited from interface dev.civl.abc.ast.type.IF.Type
Type.TypeKind -
Method Summary
Modifier and TypeMethodDescriptionvoidclear()Make incomplete.voidCompletes this structure of union type by specifying its contents, i.e., the list of fields.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.Attempts to find a cyclic type dependence in the fields of this struct/union type.getField(int index) Returns the index-th field in this structure or union type.Returns an iterator over the fields in this type, or null if this type is not yet complete.getKey()Returns the key associated to this instance.intReturns the number of fields (members) of this structure or union type.getTag()Returns the tag of this type.getType()Other thanLabel, andPragmaHandler, every kind of Entity has a type, returned by this method.booleanisStruct()Is this a struct, not a union?booleanisUnion()Is this a union, not a struct?Methods inherited from interface dev.civl.abc.ast.entity.IF.Entity
getEntityKind, getNameMethods inherited from interface dev.civl.abc.ast.type.IF.ObjectType
hasKnownConstantSize, isComplete, isConstantQualifiedMethods inherited from interface dev.civl.abc.ast.entity.IF.ProgramEntity
addDeclaration, getDeclaration, getDeclarations, getDefinition, getFirstDeclaration, getLinkage, getNumDeclarations, isSystem, setDefinition, setIsSystem, setLinkage, setTypeMethods inherited from interface dev.civl.abc.ast.entity.IF.TaggedEntity
isCompleteMethods inherited from interface dev.civl.abc.ast.type.IF.Type
compatibleWith, equivalentTo, getId, ignoreQualifiersAtomic, isScalar, isVariablyModified, kind, print
-
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
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
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
-
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
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
StructureOrUnionType getType()Description copied from interface:ProgramEntityOther than
Label, andPragmaHandler, every kind of Entity has a type, returned by this method. For aLabelorPragmaHandler, this returnsnull.The type is initially
null. It can be set using methodProgramEntity.setType(Type).- Specified by:
getTypein interfaceProgramEntity- Returns:
- the type of this entity or
null
-
findDeepField
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, ornullif no such such field exists. The first elements of this sequence will be an immediate field. The last element will be the Field namedfieldName.
-