Class ScopeManager
- java.lang.Object
-
- de.fraunhofer.aisec.cpg.passes.scopes.ScopeManager
-
public class ScopeManager extends java.lang.ObjectThe scope manager builds a multitree-structure of scopes associated to a scope. These Scopes capture the are of validity of certain (Variable-, Field-, Record-)declarations but are also used to identify outer scopes that should be target of a jump (continue, break, throw).enterScope(Node) and leaveScope(Node) can be used to enter the Tree of scopes and then sitting at a path, access the currently valid "stack" of scopes.
-
-
Constructor Summary
Constructors Constructor Description ScopeManager()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddBreakStatement(BreakStatement breakStatement)voidaddContinueStatement(ContinueStatement continueStatement)voidaddDeclaration(Declaration declaration)Adds a declaration to the CPG by taking into account the currently active scope, and add the Declaration to the appropriate node.voidaddGlobal(VariableDeclaration global)voidaddLabelStatement(LabelStatement labelStatement)voidaddTypedef(TypedefDeclaration typedef)voidconnectToLocal(DeclaredReferenceExpression referenceExpression)voidenterScope(Node nodeToScope)voidenterScopeIfExists(Node nodeToScope)@Nullable CompoundStatementgetCurrentBlock()@Nullable FunctionDeclarationgetCurrentFunction()java.lang.StringgetCurrentNamePrefix()java.lang.StringgetCurrentNamePrefixWithDelimiter()@Nullable RecordDeclarationgetCurrentRecord()ScopegetCurrentScope()java.util.List<TypedefDeclaration>getCurrentTypedefs()@Nullable ScopegetFirstScopeThat(Scope searchScope, java.util.function.Predicate<Scope> predicate)@Nullable ScopegetFirstScopeThat(java.util.function.Predicate<Scope> predicate)java.util.Map<java.lang.String,Scope>getFqnScopeMap()java.util.List<ValueDeclaration>getGlobals()@Nullable LabelStatementgetLabelStatement(java.lang.String labelString)LanguageFrontendgetLang()@Nullable RecordDeclarationgetRecordForName(Scope scope, java.lang.String name)Retrieves theRecordDeclarationfor the given name in the given scope.ScopegetScopeOfStatment(Node node)java.util.List<Scope>getScopesThat(java.util.function.Predicate<Scope> predicate)<T> java.util.List<Scope>getUniqueScopesThat(java.util.function.Predicate<Scope> predicate, java.util.function.Function<Scope,T> uniqueProperty)booleanisBreakable(Scope scope)booleanisContinuable(Scope scope)booleanisInBlock()booleanisInFunction()booleanisInRecord()@Nullable ScopeleaveScope(@NonNull Node nodeToLeave)Remove all scopes above the specified one including the specified one.@Nullable ScopeleaveScopeIfExists(Node nodeToLeave)voidremoveDeclaration(Declaration declaration)TO remove a valueDeclaration in the cases were the declaration gets replaced by something elsevoidresetToGlobal(TranslationUnitDeclaration declaration)@Nullable ValueDeclarationresolve(DeclaredReferenceExpression ref)java.util.List<FunctionDeclaration>resolveFunction(CallExpression call)@Nullable DeclarationresolveInInheritanceHierarchy(RecordDeclaration recordDeclaration, DeclaredReferenceExpression ref)@Nullable DeclarationresolveInRecord(RecordDeclaration recordDeclaration, DeclaredReferenceExpression ref)voidsetLang(LanguageFrontend lang)
-
-
-
Method Detail
-
getLang
public LanguageFrontend getLang()
-
setLang
public void setLang(LanguageFrontend lang)
-
isInBlock
public boolean isInBlock()
-
isInFunction
public boolean isInFunction()
-
isInRecord
public boolean isInRecord()
-
getFqnScopeMap
public java.util.Map<java.lang.String,Scope> getFqnScopeMap()
-
getCurrentBlock
public @Nullable CompoundStatement getCurrentBlock()
-
getCurrentFunction
public @Nullable FunctionDeclaration getCurrentFunction()
-
getCurrentRecord
public @Nullable RecordDeclaration getCurrentRecord()
-
getGlobals
public java.util.List<ValueDeclaration> getGlobals()
-
getCurrentScope
public Scope getCurrentScope()
-
addGlobal
public void addGlobal(VariableDeclaration global)
-
enterScopeIfExists
public void enterScopeIfExists(Node nodeToScope)
-
enterScope
public void enterScope(Node nodeToScope)
-
isBreakable
public boolean isBreakable(Scope scope)
-
isContinuable
public boolean isContinuable(Scope scope)
-
leaveScope
public @Nullable Scope leaveScope(@NonNull Node nodeToLeave)
Remove all scopes above the specified one including the specified one.- Parameters:
nodeToLeave- - The scope is defined by its astNode- Returns:
- the scope is returned for processing
-
getFirstScopeThat
public @Nullable Scope getFirstScopeThat(java.util.function.Predicate<Scope> predicate)
-
getFirstScopeThat
public @Nullable Scope getFirstScopeThat(Scope searchScope, java.util.function.Predicate<Scope> predicate)
-
getScopesThat
public java.util.List<Scope> getScopesThat(java.util.function.Predicate<Scope> predicate)
-
getUniqueScopesThat
public <T> java.util.List<Scope> getUniqueScopesThat(java.util.function.Predicate<Scope> predicate, java.util.function.Function<Scope,T> uniqueProperty)
-
addBreakStatement
public void addBreakStatement(BreakStatement breakStatement)
-
addContinueStatement
public void addContinueStatement(ContinueStatement continueStatement)
-
addLabelStatement
public void addLabelStatement(LabelStatement labelStatement)
-
getLabelStatement
public @Nullable LabelStatement getLabelStatement(java.lang.String labelString)
-
removeDeclaration
public void removeDeclaration(Declaration declaration)
TO remove a valueDeclaration in the cases were the declaration gets replaced by something else- Parameters:
declaration-
-
resetToGlobal
public void resetToGlobal(TranslationUnitDeclaration declaration)
-
addDeclaration
public void addDeclaration(Declaration declaration)
Adds a declaration to the CPG by taking into account the currently active scope, and add the Declaration to the appropriate node. This function will keep the declaration in the Scopes and allows the ScopeManager by himself to resolve ValueDeclarations throughresolve(DeclaredReferenceExpression).- Parameters:
declaration-
-
addTypedef
public void addTypedef(TypedefDeclaration typedef)
-
getCurrentTypedefs
public java.util.List<TypedefDeclaration> getCurrentTypedefs()
-
getCurrentNamePrefix
public java.lang.String getCurrentNamePrefix()
-
getCurrentNamePrefixWithDelimiter
public java.lang.String getCurrentNamePrefixWithDelimiter()
-
resolve
public @Nullable ValueDeclaration resolve(DeclaredReferenceExpression ref)
-
resolveFunction
public java.util.List<FunctionDeclaration> resolveFunction(CallExpression call)
-
resolveInRecord
public @Nullable Declaration resolveInRecord(RecordDeclaration recordDeclaration, DeclaredReferenceExpression ref)
-
resolveInInheritanceHierarchy
public @Nullable Declaration resolveInInheritanceHierarchy(RecordDeclaration recordDeclaration, DeclaredReferenceExpression ref)
-
connectToLocal
public void connectToLocal(DeclaredReferenceExpression referenceExpression)
-
getRecordForName
public @Nullable RecordDeclaration getRecordForName(Scope scope, java.lang.String name)
Retrieves theRecordDeclarationfor the given name in the given scope.- Parameters:
scope- the scopename- the name- Returns:
- the declaration, or null if it does not exist
-
-