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
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.String
PROGRAM_NAME
The name of the program.
-
Constructor Summary
Constructors Constructor Description Program(LanguageFeatures features, TypeSystem types)
Builds an empty program.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
addEntryPoint(CFG cm)
Adds a newCFG
to the entry points of this program.boolean
addUnit(Unit unit)
Adds a newClassUnit
, identified by its name (Unit.getName()
), to this program.boolean
canBeInstantiated()
Yieldstrue
if this unit can be instantiated,false
otherwise (e.g., interfaces, abstract classes).java.util.Collection<CFG>
getAllCFGs()
Yields all theCFG
s defined in this program, obtained by filtering the results ofgetCodeMembersRecursively()
.java.util.Collection<CodeMember>
getCodeMembersRecursively()
Yields the collection of all theCodeMember
s defined in this unit.java.util.Collection<CFG>
getEntryPoints()
Yields the collection ofCFG
s that are entry points in this program.LanguageFeatures
getFeatures()
Yields the language-specific features, algorithms and semantics of this program.java.util.Collection<Global>
getGlobalsRecursively()
Yields the collection of all theGlobal
s defined in this unit.Program
getProgram()
Yields theProgram
where this unit is defined.TypeSystem
getTypes()
Yields the type system knowing about the types that appear in the program.Unit
getUnit(java.lang.String name)
Yields theClassUnit
defined in this unit having the given name (Unit.getName()
), if any.java.util.Collection<Unit>
getUnits()
Yields the collection ofClassUnit
s defined in this program.-
Methods inherited from class it.unive.lisa.program.Unit
addCodeMember, addGlobal, getCodeMember, getCodeMembers, getCodeMembersByName, 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
-
-
Constructor Detail
-
Program
public Program(LanguageFeatures features, TypeSystem types)
Builds an empty program.- Parameters:
features
- the language-specific features, algorithms and semantics of this programtypes
- the type system knowing about the types that appear in the program
-
-
Method Detail
-
getFeatures
public LanguageFeatures getFeatures()
Yields the language-specific features, algorithms and semantics of this program.- Returns:
- the features
-
getTypes
public TypeSystem getTypes()
Yields the type system knowing about the types that appear in the program.- Returns:
- the type system
-
addUnit
public final boolean addUnit(Unit unit)
Adds a newClassUnit
, 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 returnsfalse
, the given unit is discarded.- Throws:
java.lang.IllegalArgumentException
- if the given unit is an instance of this class
-
addEntryPoint
public final boolean addEntryPoint(CFG cm)
Adds a newCFG
to the entry points of this program.- Parameters:
cm
- the cfg to add- Returns:
true
if the entry point was successfully added. If this method returnsfalse
, the given cfg is discarded.
-
getEntryPoints
public final java.util.Collection<CFG> getEntryPoints()
Yields the collection ofCFG
s that are entry points in this program.- Returns:
- the collection of entry points
-
getUnits
public final java.util.Collection<Unit> getUnits()
Yields the collection ofClassUnit
s 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 Unit getUnit(java.lang.String name)
Yields theClassUnit
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
-
getCodeMembersRecursively
public java.util.Collection<CodeMember> getCodeMembersRecursively()
Yields the collection of all theCodeMember
s defined in this unit. This method returns the same result asUnit.getCodeMembers()
, but subclasses are likely to re-implement it to add additional ones (e.g., instance members).
This method also returns all the cfgs defined in all theUnit
s in this program, throughUnit.getCodeMembersRecursively()
.- Overrides:
getCodeMembersRecursively
in classUnit
- Returns:
- the collection of the code members
-
getGlobalsRecursively
public java.util.Collection<Global> getGlobalsRecursively()
Yields the collection of all theGlobal
s defined in this unit.
This method also returns all the globals defined in all theClassUnit
s in this program, throughCompilationUnit.getGlobalsRecursively()
.- Overrides:
getGlobalsRecursively
in classUnit
- Returns:
- the collection of the globals
-
canBeInstantiated
public boolean canBeInstantiated()
Description copied from class:Unit
Yieldstrue
if this unit can be instantiated,false
otherwise (e.g., interfaces, abstract classes).- Specified by:
canBeInstantiated
in classUnit
- Returns:
true
if this unit can be instantiated,false
otherwise
-
getProgram
public Program getProgram()
Description copied from class:Unit
Yields theProgram
where this unit is defined.- Specified by:
getProgram
in classUnit
- Returns:
- the program
-
getAllCFGs
public java.util.Collection<CFG> getAllCFGs()
Yields all theCFG
s defined in this program, obtained by filtering the results ofgetCodeMembersRecursively()
.- Returns:
- the cfgs
-
-