Package it.unive.lisa.program
Class Unit
- java.lang.Object
-
- it.unive.lisa.program.Unit
-
- Direct Known Subclasses:
Program
,ProgramUnit
public abstract class Unit extends java.lang.Object
A unit of the program to analyze. A unit is a logical entity that groups a set ofGlobal
s, a set ofCFG
s and a set ofNativeCFG
s. 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 protected
Unit(java.lang.String name)
Builds a unit, defined at the given location.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description boolean
addCodeMember(CodeMember member)
Adds a newCodeMember
, identified by its signature (CodeMemberDescriptor.getSignature()
), to this unit.boolean
addGlobal(Global global)
Adds a newGlobal
, identified by its name (Global.getName()
), to this unit.abstract boolean
canBeInstantiated()
Yieldstrue
if this unit can be instantiated,false
otherwise (e.g., interfaces, abstract classes).CodeMember
getCodeMember(java.lang.String signature)
Yields theCodeMember
defined in this unit having the given signature (CodeMemberDescriptor.getSignature()
), if any.java.util.Collection<CodeMember>
getCodeMembers()
Yields the collection ofCodeMember
s defined in this unit.java.util.Collection<CodeMember>
getCodeMembersByName(java.lang.String name)
Yields the collection of allCodeMember
s defined in this unit that have the given name.java.util.Collection<CodeMember>
getCodeMembersRecursively()
Yields the collection of all theCodeMember
s defined in this unit.Global
getGlobal(java.lang.String name)
Yields theGlobal
defined in this unit having the given name (Global.getName()
), if any.java.util.Collection<Global>
getGlobals()
Yields the collection ofGlobal
s defined in this unit.java.util.Collection<Global>
getGlobalsRecursively()
Yields the collection of all theGlobal
s defined in this unit.java.util.Collection<CodeMember>
getMatchingCodeMember(CodeMemberDescriptor signature)
Finds all the code members whose signature matches the one of the givenCodeMemberDescriptor
, according toCodeMemberDescriptor.matchesSignature(CodeMemberDescriptor)
.java.lang.String
getName()
Yields the name of the unit.abstract Program
getProgram()
Yields theProgram
where this unit is defined.java.lang.String
toString()
-
-
-
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 ofGlobal
s 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
-
getCodeMembers
public final java.util.Collection<CodeMember> getCodeMembers()
Yields the collection ofCodeMember
s defined in this unit. Each code member is uniquely identified by its signature (CodeMemberDescriptor.getSignature()
), meaning that there are no two cfgs having the same signature in each unit.- Returns:
- the collection of code members
-
getGlobal
public final Global getGlobal(java.lang.String name)
Yields theGlobal
defined 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
-
getCodeMember
public final CodeMember getCodeMember(java.lang.String signature)
Yields theCodeMember
defined in this unit having the given signature (CodeMemberDescriptor.getSignature()
), if any.- Parameters:
signature
- the signature of the code member to find- Returns:
- the code member with the given signature, or
null
-
getCodeMembersByName
public final java.util.Collection<CodeMember> getCodeMembersByName(java.lang.String name)
Yields the collection of allCodeMember
s defined in this unit that have the given name.- Parameters:
name
- the name of the code members to include- Returns:
- the collection of code members with the given name
-
getGlobalsRecursively
public java.util.Collection<Global> getGlobalsRecursively()
Yields the collection of all theGlobal
s defined in this unit.- Returns:
- the collection of the globals
-
getCodeMembersRecursively
public java.util.Collection<CodeMember> getCodeMembersRecursively()
Yields the collection of all theCodeMember
s defined in this unit. This method returns the same result asgetCodeMembers()
, but subclasses are likely to re-implement it to add additional ones (e.g., instance members).- 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:
true
if there was no global previously associated with the same name,false
otherwise. If this method returnsfalse
, the given global is discarded.
-
addCodeMember
public final boolean addCodeMember(CodeMember member)
Adds a newCodeMember
, identified by its signature (CodeMemberDescriptor.getSignature()
), to this unit.- Parameters:
member
- the member to add- Returns:
true
if there was no member previously associated with the same signature,false
otherwise. If this method returnsfalse
, the given member is discarded.
-
toString
public final java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
getMatchingCodeMember
public final java.util.Collection<CodeMember> getMatchingCodeMember(CodeMemberDescriptor signature)
Finds all the code members whose signature matches the one of the givenCodeMemberDescriptor
, according toCodeMemberDescriptor.matchesSignature(CodeMemberDescriptor)
.- Parameters:
signature
- the descriptor providing the signature to match- Returns:
- the collection of code members that match the given signature
-
canBeInstantiated
public abstract boolean canBeInstantiated()
Yieldstrue
if this unit can be instantiated,false
otherwise (e.g., interfaces, abstract classes).- Returns:
true
if this unit can be instantiated,false
otherwise
-
-