Class Unit

  • Direct Known Subclasses:
    CompilationUnit, Program

    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
      • getCFGs

        public final java.util.Collection<CFG> getCFGs()
        Yields the collection of CFGs defined in this unit. Each cfg is uniquely identified by its signature (CFGDescriptor.getSignature()), meaning that there are no two cfgs having the same signature in each unit.
        Returns:
        the collection of cfgs
      • getConstructs

        public final java.util.Collection<NativeCFG> getConstructs()
        Yields the collection of constructs (NativeCFGs) defined in this unit. Each construct is uniquely identified by its signature (CFGDescriptor.getSignature()), meaning that there are no two constructs having the same signature in each unit.
        Returns:
        the collection of constructs
      • getCodeMembers

        public final java.util.Collection<CodeMember> getCodeMembers()
        Yields the collection of CodeMembers defined in this unit. This method returns the union of getCFGs() and getConstructs().
        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
      • getCFG

        public final CFG getCFG​(java.lang.String signature)
        Yields the CFG defined in this unit having the given signature (CFGDescriptor.getSignature()), if any.
        Parameters:
        signature - the signature of the cfg to find
        Returns:
        the cfg with the given signature, or null
      • getConstruct

        public final NativeCFG getConstruct​(java.lang.String signature)
        Yields the NativeCFG defined in this unit having the given signature (CFGDescriptor.getSignature()), if any.
        Parameters:
        signature - the signature of the construct to find
        Returns:
        the construct with the given signature, or null
      • getCodeMember

        public final CodeMember getCodeMember​(java.lang.String signature)
        Yields the CodeMember defined in this unit having the given signature (CFGDescriptor.getSignature()), if any. This method first searches the code member within the cfgs defined in this unit, through getCFG(String), and then within the constructs through getConstruct(String), returning the first non-null result.
        Parameters:
        signature - the signature of the code member to find
        Returns:
        the code member with the given signature, or null
      • getCFGsByName

        public final java.util.Collection<CFG> getCFGsByName​(java.lang.String name)
        Yields the collection of all CFGs defined in this unit that have the given name.
        Parameters:
        name - the name of the cfgs to include
        Returns:
        the collection of cfgs with the given name
      • getConstructsByName

        public final java.util.Collection<NativeCFG> getConstructsByName​(java.lang.String name)
        Yields the collection of all NativeCFGs defined in this unit that have the given name.
        Parameters:
        name - the name of the constructs to include
        Returns:
        the collection of constructs with the given name
      • 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. This method returns the union of getCFGsByName(String) and getConstructsByName(String).
        Parameters:
        name - the name of the code members to include
        Returns:
        the collection of code members with the given name
      • getAllGlobals

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

        public java.util.Collection<CFG> getAllCFGs()
        Yields the collection of all the CFGs defined in this unit.
        Returns:
        the collection of the cfgs
      • getAllConstructs

        public java.util.Collection<NativeCFG> getAllConstructs()
        Yields the collection of all the NativeCFGs defined in this unit.
        Returns:
        the collection of the cfgs
      • getAllCodeMembers

        public final java.util.Collection<CodeMember> getAllCodeMembers()
        Yields the collection of all the CodeMembers defined in this unit. This method returns the union between getAllCFGs() and getAllConstructs().
        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.
      • addCFG

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

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

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

        public final java.util.Collection<CodeMember> getMatchingCodeMember​(CFGDescriptor signature)
        Finds all the code members whose signature matches the one of the given CFGDescriptor, according to CFGDescriptor.matchesSignature(CFGDescriptor).
        Parameters:
        signature - the descriptor providing the signature to match
        Returns:
        the collection of code members that match the given signature