addDeclaration

fun addDeclaration(declaration: Declaration?, addToAST: Boolean = true)

This function MUST be called when a language frontend first handles a Declaration. It adds a declaration to the scope manager, taking into account the currently active scope. Furthermore, it adds the declaration to the de.fraunhofer.aisec.cpg.graph.DeclarationHolder that is associated with the current scope through ValueDeclarationScope.addValueDeclaration and StructureDeclarationScope.addStructureDeclaration.

Setting Scope.astNode to false is useful, if you want to make sure a certain declaration is visible within a scope, but is not directly part of the scope's AST. An example is the way C/C++ handles unscoped enum constants. They are visible in the enclosing scope, e.g., a translation unit, but they are added to the AST of their enum declaration, not the translation unit. The enum declaration is then added to the translation unit.

Parameters

declaration

the declaration to add

addToAST

specifies, whether the declaration also gets added to the Scope.astNode of the current scope (if it implements DeclarationHolder). Defaults to true.