Skip to content

Commit

Permalink
Performance improvements for CXX frontend
Browse files Browse the repository at this point in the history
  • Loading branch information
oxisto committed Nov 24, 2023
1 parent 62d1691 commit 9695742
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 4 deletions.
19 changes: 19 additions & 0 deletions cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/ScopeManager.kt
Original file line number Diff line number Diff line change
Expand Up @@ -878,6 +878,25 @@ class ScopeManager : ScopeProvider {
list += Alias(from, to)
}

fun typeDefFor(finalToCheck: Type): Type? {
var current = currentScope

// We need to build a path from the current scope to the top most one. This ensures us that
// a local definition overwrites / shadows one that was there on a higher scope.
while (current != null) {
if (current is ValueDeclarationScope) {
val decl = current.typedefs[finalToCheck]
if (decl != null) {
return decl.type
}
}

current = current.parent
}

return null
}

/** Returns the current scope for the [ScopeProvider] interface. */
override val scope: Scope?
get() = currentScope
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -252,10 +252,7 @@ class TypeManager {

fun resolvePossibleTypedef(alias: Type, scopeManager: ScopeManager): Type {
val finalToCheck = alias.root
val applicable =
scopeManager.currentTypedefs
.firstOrNull { t: TypedefDeclaration -> t.alias.root == finalToCheck }
?.type
val applicable = scopeManager.typeDefFor(finalToCheck)
return applicable ?: alias
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -716,6 +716,7 @@ class DeclarationHandler(lang: CXXLanguageFrontend) :
frontend.scopeManager.resetToGlobal(node)
frontend.currentTU = node
val problematicIncludes = HashMap<String?, HashSet<ProblemDeclaration>>()

for (declaration in translationUnit.declarations) {
if (declaration is CPPASTLinkageSpecification) {
continue // do not care about these for now
Expand Down

0 comments on commit 9695742

Please sign in to comment.