Skip to content

Commit

Permalink
Synchronize adding TUs (#1423)
Browse files Browse the repository at this point in the history
  • Loading branch information
KuechA authored Jan 30, 2024
1 parent dab9a64 commit 3dd242a
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,7 @@ private constructor(
}
return null
}
component.translationUnits.add(frontend.parse(sourceLocation))
component.addTranslationUnit(frontend.parse(sourceLocation))
} catch (ex: TranslationException) {
log.error("An error occurred during parsing of ${sourceLocation.name}: ${ex.message}")
if (config.failOnError) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ class TranslationResult(
components.add(swc)
}
}
tu?.let { swc.translationUnits.add(it) }
tu?.let { swc.addTranslationUnit(it) }
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@ open class Component : Node() {
/** All translation units belonging to this application. */
@AST val translationUnits: MutableList<TranslationUnitDeclaration> = mutableListOf()

@Synchronized
fun addTranslationUnit(tu: TranslationUnitDeclaration) {
translationUnits.add(tu)
}

/**
* All points where unknown data may enter this application, e.g., the main method, or other
* targets such as listeners to external events such as HTTP requests. This also includes the
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,7 @@ class CXXCompilationDatabaseTest {
assertEquals(2, tus.size)
val ref = mapOf("main_tu_1.c" to 1, "main_tu_2.c" to 2)

for (i in tus.indices) {
val tu = tus[i]
for (tu in tus) {
val value = ref[File(tu.name.toString()).name]
val mainFunc = tu.byNameOrNull<FunctionDeclaration>("main")
assertNotNull(mainFunc)
Expand Down

0 comments on commit 3dd242a

Please sign in to comment.