Package it.unive.lisa.program
Class Program
- java.lang.Object
-
- it.unive.lisa.program.Unit
-
- it.unive.lisa.program.Program
-
public class Program extends Unit
A program that LiSA can analyze. A program is aUnitthat is defined at an unknown program location, and that has a set ofCompilationUnits defined in it.
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.StringPROGRAM_NAMEThe name of the program.
-
Constructor Summary
Constructors Constructor Description Program()Builds an empty program.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanaddCompilationUnit(CompilationUnit unit)Adds a newCompilationUnit, identified by its name (Unit.getName()), to this program.booleanaddEntryPoint(CFG method)Adds a newCFGto the entry points of this program.java.util.Collection<CFG>getAllCFGs()Yields the collection of all theCFGs defined in this unit.java.util.Collection<NativeCFG>getAllConstructs()Yields the collection of all theNativeCFGs defined in this unit.java.util.Collection<Global>getAllGlobals()Yields the collection of all theGlobals defined in this unit.java.util.Collection<CFG>getEntryPoints()Yields the collection ofCFGs that are entry points in this program.java.util.Collection<Type>getRegisteredTypes()Yields the collection ofTypes that have been registered in this program.CompilationUnitgetUnit(java.lang.String name)Yields theCompilationUnitdefined in this unit having the given name (Unit.getName()), if any.java.util.Collection<CompilationUnit>getUnits()Yields the collection ofCompilationUnits defined in this program.booleanregisterType(Type type)Registers a newTypethat appears in the program.voidvalidateAndFinalize()Validates this unit, ensuring its consistency.-
Methods inherited from class it.unive.lisa.program.Unit
addCFG, addConstruct, addGlobal, getAllCodeMembers, getCFG, getCFGs, getCFGsByName, getCodeMember, getCodeMembers, getCodeMembersByName, getConstruct, getConstructs, getConstructsByName, getGlobal, getGlobals, getMatchingCodeMember, getName, toString
-
-
-
-
Field Detail
-
PROGRAM_NAME
public static final java.lang.String PROGRAM_NAME
The name of the program.- See Also:
- Constant Field Values
-
-
Method Detail
-
registerType
public final boolean registerType(Type type)
Registers a newTypethat appears in the program.- Parameters:
type- the type to add- Returns:
trueif the collection of types changed as a result of the call
-
getRegisteredTypes
public final java.util.Collection<Type> getRegisteredTypes()
Yields the collection ofTypes that have been registered in this program.- Returns:
- the collection of types
-
addCompilationUnit
public final boolean addCompilationUnit(CompilationUnit unit)
Adds a newCompilationUnit, identified by its name (Unit.getName()), to this program.- Parameters:
unit- the compilation unit to add- Returns:
trueif there was no unit previously associated with the same name,falseotherwise. If this method returnsfalse, the given unit is discarded.
-
addEntryPoint
public final boolean addEntryPoint(CFG method)
Adds a newCFGto the entry points of this program.- Parameters:
method- the code member to add- Returns:
trueif the entry point was successfully added. If this method returnsfalse, the given code member is discarded.
-
getEntryPoints
public final java.util.Collection<CFG> getEntryPoints()
Yields the collection ofCFGs that are entry points in this program.- Returns:
- the collection of entry points
-
getUnits
public final java.util.Collection<CompilationUnit> getUnits()
Yields the collection ofCompilationUnits 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 theCompilationUnitdefined 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 theCFGs defined in this unit.
This method also returns all the cfgs defined in all theCompilationUnits in this program, throughCompilationUnit.getAllCFGs().- Overrides:
getAllCFGsin classUnit- Returns:
- the collection of the cfgs
-
getAllConstructs
public java.util.Collection<NativeCFG> getAllConstructs()
Yields the collection of all theNativeCFGs defined in this unit.
This method also returns all the constructs defined in all theCompilationUnits in this program, throughCompilationUnit.getAllConstructs().- Overrides:
getAllConstructsin classUnit- Returns:
- the collection of the cfgs
-
getAllGlobals
public java.util.Collection<Global> getAllGlobals()
Yields the collection of all theGlobals defined in this unit.
This method also returns all the globals defined in all theCompilationUnits in this program, throughCompilationUnit.getAllGlobals().- Overrides:
getAllGlobalsin classUnit- Returns:
- the collection of the globals
-
validateAndFinalize
public void validateAndFinalize() throws ProgramValidationExceptionValidates this unit, ensuring its consistency. This ensures that no two code members exist in this unit whose signatures matches one another, according toCFGDescriptor.matchesSignature(CFGDescriptor). This avoids ambiguous call resolution. Moreover, this ensures that allCFGs are valid, according toCFG.validate().
Validating a program simply causes the validation of all theCompilationUnits defined inside it. Validation also clears (by setting it tonull) the set of registered types, in order to shrink the memory fingerprint of the program.- Overrides:
validateAndFinalizein classUnit- Throws:
ProgramValidationException- if the program has an invalid structure
-
-