Class Unit

  • Direct Known Subclasses:
    Program, ProgramUnit

    public abstract class Unit
    extends java.lang.Object
    A unit of the program to analyze. A unit is a logical entity that groups a set of Globals, a set of CFGs and a set of NativeCFGs. The signature of each of these elements is unique within the unit.

    Note that this class does not implement Object.equals(Object) nor Object.hashCode() since all units are unique.
    • Constructor Detail

      • Unit

        protected Unit​(java.lang.String name)
        Builds a unit, defined at the given location.
        Parameters:
        name - the name of the unit
    • Method Detail

      • getName

        public final java.lang.String getName()
        Yields the name of the unit.
        Returns:
        the name
      • getGlobals

        public final java.util.Collection<Global> getGlobals()
        Yields the collection of Globals defined in this unit. Each global is uniquely identified by its name, meaning that there are no two globals having the same name in each unit.
        Returns:
        the collection of globals
      • getCodeMembers

        public final java.util.Collection<CodeMember> getCodeMembers()
        Yields the collection of CodeMembers defined in this unit. Each code member is uniquely identified by its signature (CodeMemberDescriptor.getSignature()), meaning that there are no two cfgs having the same signature in each unit.
        Returns:
        the collection of code members
      • getGlobal

        public final Global getGlobal​(java.lang.String name)
        Yields the Global defined in this unit having the given name (Global.getName()), if any.
        Parameters:
        name - the name of the global to find
        Returns:
        the global with the given name, or null
      • getCodeMember

        public final CodeMember getCodeMember​(java.lang.String signature)
        Yields the CodeMember defined in this unit having the given signature (CodeMemberDescriptor.getSignature()), if any.
        Parameters:
        signature - the signature of the code member to find
        Returns:
        the code member with the given signature, or null
      • getCodeMembersByName

        public final java.util.Collection<CodeMember> getCodeMembersByName​(java.lang.String name)
        Yields the collection of all CodeMembers defined in this unit that have the given name.
        Parameters:
        name - the name of the code members to include
        Returns:
        the collection of code members with the given name
      • getGlobalsRecursively

        public java.util.Collection<Global> getGlobalsRecursively()
        Yields the collection of all the Globals defined in this unit.
        Returns:
        the collection of the globals
      • getCodeMembersRecursively

        public java.util.Collection<CodeMember> getCodeMembersRecursively()
        Yields the collection of all the CodeMembers defined in this unit. This method returns the same result as getCodeMembers(), but subclasses are likely to re-implement it to add additional ones (e.g., instance members).
        Returns:
        the collection of the code members
      • addGlobal

        public final boolean addGlobal​(Global global)
        Adds a new Global, identified by its name (Global.getName()), to this unit.
        Parameters:
        global - the global to add
        Returns:
        true if there was no global previously associated with the same name, false otherwise. If this method returns false, the given global is discarded.
      • addCodeMember

        public final boolean addCodeMember​(CodeMember member)
        Adds a new CodeMember, identified by its signature (CodeMemberDescriptor.getSignature()), to this unit.
        Parameters:
        member - the member to add
        Returns:
        true if there was no member previously associated with the same signature, false otherwise. If this method returns false, the given member is discarded.
      • toString

        public final java.lang.String toString()
        Overrides:
        toString in class java.lang.Object
      • canBeInstantiated

        public abstract boolean canBeInstantiated()
        Yields true if this unit can be instantiated, false otherwise (e.g., interfaces, abstract classes).
        Returns:
        true if this unit can be instantiated, false otherwise
      • getProgram

        public abstract Program getProgram()
        Yields the Program where this unit is defined.
        Returns:
        the program