Class CompilationUnit

  • All Implemented Interfaces:
    CodeElement

    public class CompilationUnit
    extends Unit
    A compilation unit of the program to analyze. A compilation unit is a Unit that also defines instance members, that can be inherited by subunits.
    • Constructor Detail

      • CompilationUnit

        public CompilationUnit​(CodeLocation location,
                               java.lang.String name,
                               boolean sealed)
        Builds a compilation unit, defined at the given program point.
        Parameters:
        location - the location where the unit is define within the source file
        name - the name of the unit
        sealed - whether or not this unit is sealed, meaning that it cannot be used as super unit of other compilation units
    • Method Detail

      • isSealed

        public final boolean isSealed()
        Yields whether or not this unit is sealed, meaning that it cannot be used as super unit of other compilation units.
        Returns:
        true if this unit is sealed
      • getSuperUnits

        public final java.util.Collection<CompilationUnit> getSuperUnits()
        Yields the collection of CompilationUnits that this unit directly inherits from. The returned collection does not include units that are transitively inherited.
        Returns:
        the collection of direct super units
      • getInstances

        public final java.util.Collection<CompilationUnit> getInstances()
        Yields the collection of CompilationUnits that are instances of this one, including itself. In other words, this method returns the collection of compilation units that directly or indirectly, inherit from this one.

        Note that this method returns an empty collection, until validateAndFinalize() has been called.
        Returns:
        the collection of units that are instances of this one, including this unit itself
      • getInstanceGlobals

        public final java.util.Collection<Global> getInstanceGlobals​(boolean traverseHierarchy)
        Yields the collection of instance Globals defined in this unit. Each global is uniquely identified by its name, meaning that there are no two instance globals having the same name in each unit.
        Parameters:
        traverseHierarchy - if true, also returns instance globals from superunits, transitively
        Returns:
        the collection of instance globals
      • getInstanceCFGs

        public final java.util.Collection<CFG> getInstanceCFGs​(boolean traverseHierarchy)
        Yields the collection of instance CFGs defined in this unit. Each cfg is uniquely identified by its signature (CFGDescriptor.getSignature()), meaning that there are no two instance cfgs having the same signature in each unit. Instance cfgs can be overridden inside subunits, according to CFGDescriptor.isOverridable().
        Parameters:
        traverseHierarchy - if true, also returns instance cfgs from superunits, transitively
        Returns:
        the collection of instance cfgs
      • getInstanceConstructs

        public final java.util.Collection<NativeCFG> getInstanceConstructs​(boolean traverseHierarchy)
        Yields the collection of instance constructs (NativeCFGs) defined in this unit. Each construct is uniquely identified by its signature (CFGDescriptor.getSignature()), meaning that there are no two instance constructs having the same signature in each unit. Instance constructs can be overridden inside subunits, according to CFGDescriptor.isOverridable().
        Parameters:
        traverseHierarchy - if true, also returns instance constructs from superunits, transitively
        Returns:
        the collection of instance constructs
      • addSuperUnit

        public final boolean addSuperUnit​(CompilationUnit unit)
        Adds a new CompilationUnit as superunit of this unit.
        Parameters:
        unit - the unit to add
        Returns:
        true if the collection of superunits changed as a result of the call
      • addInstanceGlobal

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

        public final boolean addInstanceCFG​(CFG cfg)
        Adds a new instance CFG, identified by its signature (CFGDescriptor.getSignature()), to this unit. Instance cfgs can be overridden inside subunits, according to CFGDescriptor.isOverridable().
        Parameters:
        cfg - the cfg to add
        Returns:
        true if there was no instance cfg previously associated with the same signature, false otherwise. If this method returns false, the given cfg is discarded.
      • addInstanceConstruct

        public final boolean addInstanceConstruct​(NativeCFG construct)
        Adds a new instance NativeCFG, identified by its signature (CFGDescriptor.getSignature()), to this unit. Instance constructs can be overridden inside subunits, according to CFGDescriptor.isOverridable().
        Parameters:
        construct - the construct to add
        Returns:
        true if there was no instance construct previously associated with the same signature, false otherwise. If this method returns false, the given construct is discarded.
      • getInstanceCFG

        public final CFG getInstanceCFG​(java.lang.String signature,
                                        boolean traverseHierarchy)
        Yields the instance CFG defined in this unit having the given signature (CFGDescriptor.getSignature()), if any.
        Parameters:
        signature - the signature of the cfg to find
        traverseHierarchy - if true, also returns instance cfgs from superunits, transitively
        Returns:
        the instance cfg with the given signature, or null
      • getInstanceConstruct

        public final NativeCFG getInstanceConstruct​(java.lang.String signature,
                                                    boolean traverseHierarchy)
        Yields the instance NativeCFG defined in this unit having the given signature (CFGDescriptor.getSignature()), if any.
        Parameters:
        signature - the signature of the construct to find
        traverseHierarchy - if true, also returns instance constructs from superunits, transitively
        Returns:
        the instance construct with the given signature, or null
      • getInstanceGlobal

        public final Global getInstanceGlobal​(java.lang.String name,
                                              boolean traverseHierarchy)
        Yields the instance Global defined in this unit having the given name (Global.getName()), if any.
        Parameters:
        name - the name of the global to find
        traverseHierarchy - if true, also returns instance globals from superunits, transitively
        Returns:
        the instance global with the given name, or null
      • getInstanceCodeMember

        public final CodeMember getInstanceCodeMember​(java.lang.String signature,
                                                      boolean traverseHierarchy)
        Yields the instance CodeMember defined in this unit having the given signature (CFGDescriptor.getSignature()), if any. This method searches the code member both among the instance cfgs and instance constructs defined in this unit.
        Parameters:
        signature - the signature of the code member to find
        traverseHierarchy - if true, also returns instance code members from superunits, transitively
        Returns:
        the instance code member with the given signature, or null
      • getInstanceCFGsByName

        public final java.util.Collection<CFG> getInstanceCFGsByName​(java.lang.String name,
                                                                     boolean traverseHierarchy)
        Yields the collection of all instance CFGs defined in this unit that have the given name.
        Parameters:
        name - the name of the constructs to include
        traverseHierarchy - if true, also returns instance cfgs from superunits, transitively
        Returns:
        the collection of instance cfgs with the given name
      • getInstanceConstructsByName

        public final java.util.Collection<NativeCFG> getInstanceConstructsByName​(java.lang.String name,
                                                                                 boolean traverseHierarchy)
        Yields the collection of all instance NativeCFGs defined in this unit that have the given name.
        Parameters:
        name - the name of the constructs to include
        traverseHierarchy - if true, also returns instance constructs from superunits, transitively
        Returns:
        the collection of instance constructs with the given name
      • getInstanceCodeMembersByName

        public final java.util.Collection<CodeMember> getInstanceCodeMembersByName​(java.lang.String name,
                                                                                   boolean traverseHierarchy)
        Yields the collection of all instance CodeMembers defined in this unit that have the given name. This method searches the code member both among the instance cfgs and instance constructs defined in this unit.
        Parameters:
        name - the name of the code members to include
        traverseHierarchy - if true, also returns instance code members from superunits, transitively
        Returns:
        the collection of code members with the given name
      • getMatchingInstanceCodeMembers

        public final java.util.Collection<CodeMember> getMatchingInstanceCodeMembers​(CFGDescriptor signature,
                                                                                     boolean traverseHierarchy)
        Finds all the instance 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
        traverseHierarchy - if true, also returns instance code members from superunits, transitively
        Returns:
        the collection of instance code members that match the given signature
      • getAllCFGs

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

        This method also returns all the instance cfgs defined in this unit.
        Overrides:
        getAllCFGs in class Unit
        Returns:
        the collection of the cfgs
      • getAllGlobals

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

        This method also returns all the instance globals defined in this unit.
        Overrides:
        getAllGlobals in class Unit
        Returns:
        the collection of the globals
      • getAllConstructs

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

        This method also returns all the instance constructs defined in this unit.
        Overrides:
        getAllConstructs in class Unit
        Returns:
        the collection of the cfgs
      • getInstanceCodeMembers

        public final java.util.Collection<CodeMember> getInstanceCodeMembers​(boolean traverseHierarchy)
        Yields the collection of instance CodeMembers defined in this unit. This method returns the union of getInstanceCFGs(boolean) and getInstanceConstructs(boolean).
        Parameters:
        traverseHierarchy - if true, also returns instance code members from superunits, transitively
        Returns:
        the collection of instance code members
      • isInstanceOf

        public final boolean isInstanceOf​(CompilationUnit unit)
        Yields true if and only if this unit is an instance of the given one. This method works correctly even if validateAndFinalize() has not been called yet, and thus the if collection of instances of the given unit is not yet available.
        Parameters:
        unit - the other unit
        Returns:
        true only if that condition holds