Package it.unive.lisa.program
Class Unit
- java.lang.Object
-
- it.unive.lisa.program.Unit
-
- Direct Known Subclasses:
CompilationUnit,Program
public abstract class Unit extends java.lang.ObjectA unit of the program to analyze. A unit is a logical entity that groups a set ofGlobals, a set ofCFGs and a set ofNativeCFGs. The signature of each of these elements is unique within the unit.
Note that this class does not implementObject.equals(Object)norObject.hashCode()since all units are unique.
-
-
Constructor Summary
Constructors Modifier Constructor Description protectedUnit(java.lang.String name)Builds a unit, defined at the given location.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanaddCFG(CFG cfg)Adds a newCFG, identified by its signature (CFGDescriptor.getSignature()), to this unit.booleanaddConstruct(NativeCFG construct)Adds a newNativeCFG, identified by its signature (CFGDescriptor.getSignature()), to this unit.booleanaddGlobal(Global global)Adds a newGlobal, identified by its name (Global.getName()), to this unit.java.util.Collection<CFG>getAllCFGs()Yields the collection of all theCFGs defined in this unit.java.util.Collection<CodeMember>getAllCodeMembers()Yields the collection of all theCodeMembers 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.CFGgetCFG(java.lang.String signature)Yields theCFGdefined in this unit having the given signature (CFGDescriptor.getSignature()), if any.java.util.Collection<CFG>getCFGs()Yields the collection ofCFGs defined in this unit.java.util.Collection<CFG>getCFGsByName(java.lang.String name)Yields the collection of allCFGs defined in this unit that have the given name.CodeMembergetCodeMember(java.lang.String signature)Yields theCodeMemberdefined in this unit having the given signature (CFGDescriptor.getSignature()), if any.java.util.Collection<CodeMember>getCodeMembers()Yields the collection ofCodeMembers defined in this unit.java.util.Collection<CodeMember>getCodeMembersByName(java.lang.String name)Yields the collection of allCodeMembers defined in this unit that have the given name.NativeCFGgetConstruct(java.lang.String signature)Yields theNativeCFGdefined in this unit having the given signature (CFGDescriptor.getSignature()), if any.java.util.Collection<NativeCFG>getConstructs()Yields the collection of constructs (NativeCFGs) defined in this unit.java.util.Collection<NativeCFG>getConstructsByName(java.lang.String name)Yields the collection of allNativeCFGs defined in this unit that have the given name.GlobalgetGlobal(java.lang.String name)Yields theGlobaldefined in this unit having the given name (Global.getName()), if any.java.util.Collection<Global>getGlobals()Yields the collection ofGlobals defined in this unit.java.util.Collection<CodeMember>getMatchingCodeMember(CFGDescriptor signature)Finds all the code members whose signature matches the one of the givenCFGDescriptor, according toCFGDescriptor.matchesSignature(CFGDescriptor).java.lang.StringgetName()Yields the name of the unit.java.lang.StringtoString()voidvalidateAndFinalize()Validates this unit, ensuring its consistency.
-
-
-
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 ofGlobals 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 ofCFGs 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 ofCodeMembers defined in this unit. This method returns the union ofgetCFGs()andgetConstructs().- Returns:
- the collection of code members
-
getGlobal
public final Global getGlobal(java.lang.String name)
Yields theGlobaldefined 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 theCFGdefined 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 theNativeCFGdefined 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 theCodeMemberdefined 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, throughgetCFG(String), and then within the constructs throughgetConstruct(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 allCFGs 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 allNativeCFGs 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 allCodeMembers defined in this unit that have the given name. This method returns the union ofgetCFGsByName(String)andgetConstructsByName(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 theGlobals defined in this unit.- Returns:
- the collection of the globals
-
getAllCFGs
public java.util.Collection<CFG> getAllCFGs()
Yields the collection of all theCFGs defined in this unit.- Returns:
- the collection of the cfgs
-
getAllConstructs
public java.util.Collection<NativeCFG> getAllConstructs()
Yields the collection of all theNativeCFGs defined in this unit.- Returns:
- the collection of the cfgs
-
getAllCodeMembers
public final java.util.Collection<CodeMember> getAllCodeMembers()
Yields the collection of all theCodeMembers defined in this unit. This method returns the union betweengetAllCFGs()andgetAllConstructs().- Returns:
- the collection of the code members
-
addGlobal
public final boolean addGlobal(Global global)
Adds a newGlobal, identified by its name (Global.getName()), to this unit.- Parameters:
global- the global to add- Returns:
trueif there was no global previously associated with the same name,falseotherwise. If this method returnsfalse, the given global is discarded.
-
addCFG
public final boolean addCFG(CFG cfg)
Adds a newCFG, identified by its signature (CFGDescriptor.getSignature()), to this unit.- Parameters:
cfg- the cfg to add- Returns:
trueif there was no cfg previously associated with the same signature,falseotherwise. If this method returnsfalse, the given cfg is discarded.
-
addConstruct
public final boolean addConstruct(NativeCFG construct)
Adds a newNativeCFG, identified by its signature (CFGDescriptor.getSignature()), to this unit.- Parameters:
construct- the construct to add- Returns:
trueif there was no construct previously associated with the same signature,falseotherwise. If this method returnsfalse, the given construct is discarded.
-
toString
public final java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
getMatchingCodeMember
public final java.util.Collection<CodeMember> getMatchingCodeMember(CFGDescriptor signature)
Finds all the code members whose signature matches the one of the givenCFGDescriptor, according toCFGDescriptor.matchesSignature(CFGDescriptor).- Parameters:
signature- the descriptor providing the signature to match- Returns:
- the collection of code members that match the given signature
-
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().- Throws:
ProgramValidationException- if the program has an invalid structure
-
-