Class Program


  • public class Program
    extends Unit
    A program that LiSA can analyze. A program is a Unit that is defined at an unknown program location, and that has a set of CompilationUnits defined in it.
    • Field Detail

      • PROGRAM_NAME

        public static final java.lang.String PROGRAM_NAME
        The name of the program.
        See Also:
        Constant Field Values
    • Constructor Detail

      • Program

        public Program()
        Builds an empty program.
    • Method Detail

      • registerType

        public final boolean registerType​(Type type)
        Registers a new Type that appears in the program.
        Parameters:
        type - the type to add
        Returns:
        true if the collection of types changed as a result of the call
      • getRegisteredTypes

        public final java.util.Collection<Type> getRegisteredTypes()
        Yields the collection of Types that have been registered in this program.
        Returns:
        the collection of types
      • addCompilationUnit

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

        public final boolean addEntryPoint​(CFG method)
        Adds a new CFG to the entry points of this program.
        Parameters:
        method - the code member to add
        Returns:
        true if the entry point was successfully added. If this method returns false, the given code member is discarded.
      • getEntryPoints

        public final java.util.Collection<CFG> getEntryPoints()
        Yields the collection of CFGs that are entry points in this program.
        Returns:
        the collection of entry points
      • getUnits

        public final java.util.Collection<CompilationUnit> getUnits()
        Yields the collection of CompilationUnits defined in this program. Each compilation unit is uniquely identified by its name, meaning that there are no two compilation units having the same name in a program.
        Returns:
        the collection of compilation units
      • getUnit

        public final CompilationUnit getUnit​(java.lang.String name)
        Yields the CompilationUnit defined in this unit having the given name (Unit.getName()), if any.
        Parameters:
        name - the name of the compilation unit to find
        Returns:
        the compilation unit with the given name, or null
      • getAllCFGs

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

        This method also returns all the cfgs defined in all the CompilationUnits in this program, through CompilationUnit.getAllCFGs().
        Overrides:
        getAllCFGs in class Unit
        Returns:
        the collection of the cfgs
      • validateAndFinalize

        public void validateAndFinalize()
                                 throws ProgramValidationException
        Validates this unit, ensuring its consistency. This ensures that no two code members exist in this unit whose signatures matches one another, according to CFGDescriptor.matchesSignature(CFGDescriptor). This avoids ambiguous call resolution. Moreover, this ensures that all CFGs are valid, according to CFG.validate().

        Validating a program simply causes the validation of all the CompilationUnits defined inside it. Validation also clears (by setting it to null) the set of registered types, in order to shrink the memory fingerprint of the program.
        Overrides:
        validateAndFinalize in class Unit
        Throws:
        ProgramValidationException - if the program has an invalid structure