Module dev.civl.abc

Class CommonEntity

java.lang.Object
dev.civl.abc.ast.entity.IF.CommonEntity
All Implemented Interfaces:
Entity, ProgramEntity

public class CommonEntity extends Object implements ProgramEntity
A simple, generic implementation of Entity. This class may be extended by specific entities, or it may used as a field (as in the Delegation Pattern) to help implement other entities that cannot extend this class for some reason (for example, because they extend some other class.)
  • Constructor Details

  • Method Details

    • setIsSystem

      public void setIsSystem(boolean value)
      Description copied from interface: ProgramEntity
      Declares that this entity is or is not a system-defined entity.
      Specified by:
      setIsSystem in interface ProgramEntity
      Parameters:
      value - if true, declares this to be a system-defined entity; if false, declares this to be a user-defined entity. The default is false.
    • isSystem

      public boolean isSystem()
      Description copied from interface: ProgramEntity
      Is this a system-defined entity (as opposed to a user-defined one)? Examples include standard types, like size_t. The default is false; it can be changed using method ProgramEntity.setIsSystem(boolean).
      Specified by:
      isSystem in interface ProgramEntity
    • getEntityKind

      public Entity.EntityKind getEntityKind()
      Description copied from interface: Entity

      The kind of entity this is.

      If the kind is Entity.EntityKind.VARIABLE, this entity may be safely cast to Variable

      If the kind is Entity.EntityKind.FUNCTION, this entity may be safely cast to Function.

      If the kind is Entity.EntityKind.TYPEDEF, this entity may be safely cast to Typedef.

      If the kind is Entity.EntityKind.STRUCTURE_OR_UNION, this entity may be safely cast to

      invalid reference
      StructureOrUnion
      .

      If the kind is Entity.EntityKind.ENUMERATION, this entity may be safely cast to Enumeration.

      If the kind is Entity.EntityKind.ENUMERATOR, this entity may be safely cast to Enumerator. An enumerator is an element of an enumeration.

      If the kind is Entity.EntityKind.FIELD, this entity may be safely cast to Field. A "field" is a member of a structure or union.

      If the kind is Entity.EntityKind.LABEL, this entity may be safely cast to Label.

      If the kind is Entity.EntityKind.PRAGMA_HANDLER, this entity may be safely cast to PragmaHandler.

      Specified by:
      getEntityKind in interface Entity
      Returns:
      the entity kind
    • getDeclarations

      public Iterable<DeclarationNode> getDeclarations()
      Description copied from interface: ProgramEntity
      Returns an iterator over all the known declarations of this entity. An entity may be declared multiple times. This includes the definition. The declarations will be returned in program order.
      Specified by:
      getDeclarations in interface ProgramEntity
      Returns:
      iterator over declarations of this entity, in program order
    • getFirstDeclaration

      public DeclarationNode getFirstDeclaration()
      Description copied from interface: ProgramEntity
      Gets one of the declarations of this entity.
      Specified by:
      getFirstDeclaration in interface ProgramEntity
      Returns:
      a declaration of this entity or null if there aren't any
    • getNumDeclarations

      public int getNumDeclarations()
      Description copied from interface: ProgramEntity
      Returns the number of declarations of this entity.
      Specified by:
      getNumDeclarations in interface ProgramEntity
      Returns:
      the number of declarations of this entity
    • getDeclaration

      public DeclarationNode getDeclaration(int index)
      Description copied from interface: ProgramEntity
      Returns the index-th declaration of this entity.
      Specified by:
      getDeclaration in interface ProgramEntity
      Parameters:
      index - an integer in the range [0,n), where n is the number of declarations of this entity
      Returns:
      the index-th declaration of this entity
    • addDeclaration

      public void addDeclaration(DeclarationNode declaration)
      Description copied from interface: ProgramEntity
      Adds a declaration to this entity.
      Specified by:
      addDeclaration in interface ProgramEntity
      Parameters:
      declaration - a declaration of this entity
    • getDefinition

      public DeclarationNode getDefinition()
      Description copied from interface: ProgramEntity

      Gets the definition, i.e., the defining declaration of this entity. Every entity has at most one definition. The definition is a declaration of a special kind. For example, for an object (variable), a definition is the declaration that allocates storage for that object. For a function, a definition is the declaration the contains the function body.

      The definition is initially null, but can be set using method ProgramEntity.setDefinition(DeclarationNode).

      Specified by:
      getDefinition in interface ProgramEntity
      Returns:
      the definition of this entity or null
    • setDefinition

      public void setDefinition(DeclarationNode declaration)
      Description copied from interface: ProgramEntity

      Sets the definition for this entity. Every entity has at most one definition. The definition is a declaration of a special kind. For example, for an object (variable), a definition is the declaration that allocates storage for that object. For a function, a definition is the declaration the contains the function body.

      The definition is initially null, and can be set using this method. Note that this does not affect the list of declarations of this entity. It is the client's responsibility to add the definition to the list of declarations as well as to invoke this method, to ensure that the definition occurs in the list of declarations.

      Specified by:
      setDefinition in interface ProgramEntity
      Parameters:
      declaration - the declaration node for the definition
    • getLinkage

      public ProgramEntity.LinkageKind getLinkage()
      Description copied from interface: ProgramEntity
      Returns the kind of linkage this entity has.
      Specified by:
      getLinkage in interface ProgramEntity
      Returns:
      the kind of linkage this entity has
    • setLinkage

      public void setLinkage(ProgramEntity.LinkageKind linkage)
      Description copied from interface: ProgramEntity
      Sets the linkage of this entity. It is initially ProgramEntity.LinkageKind.NONE .
      Specified by:
      setLinkage in interface ProgramEntity
      Parameters:
      linkage - the linkage kind of this entity
    • getName

      public String getName()
      Description copied from interface: Entity
      Gets the name of this entity. This is the identifier used in the declaration of the entity. It can be null in certain situations (e.g., an unnamed field).
      Specified by:
      getName in interface Entity
      Returns:
      the name of this entity
    • getType

      public Type 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
    • setType

      public void setType(Type type)
      Description copied from interface: ProgramEntity
      Sets the type of this entity.
      Specified by:
      setType in interface ProgramEntity
      Parameters:
      type - the type of this entity
    • toString

      public String toString()
      Overrides:
      toString in class Object