Class TranslationConfiguration.Builder

java.lang.Object
de.fraunhofer.aisec.cpg.TranslationConfiguration.Builder
Enclosing class:
TranslationConfiguration

public static class TranslationConfiguration.Builder
extends java.lang.Object
Builds a TranslationConfiguration.

Example:


 TranslationManager.builder()
    .config( TranslationConfiguration.builder()
        .sourceLocations(new File("example.cpp"))
        .defaultPasses()
        .debugParser(true)
        .build())
 .build();
 
  • Constructor Details

    • Builder

      public Builder()
  • Method Details

    • symbols

      public TranslationConfiguration.Builder symbols​(java.util.Map<java.lang.String,​java.lang.String> symbols)
    • sourceLocations

      public TranslationConfiguration.Builder sourceLocations​(java.io.File... sourceLocations)
      Files or directories containing the source code to analyze. Generates a dummy software component called "SWC".
      Parameters:
      sourceLocations - The files with the source code
      Returns:
      this
    • sourceLocations

      public TranslationConfiguration.Builder sourceLocations​(java.util.List<java.io.File> sourceLocations)
      Files or directories containing the source code to analyze. Generates a dummy software component called "SWC".
      Parameters:
      sourceLocations - The files with the source code
      Returns:
      this
    • softwareComponents

      public TranslationConfiguration.Builder softwareComponents​(java.util.Map<java.lang.String,​java.util.List<java.io.File>> softwareComponents)
      Files or directories containing the source code to analyze organized by different components
      Parameters:
      softwareComponents - A map holding the different components with their files
      Returns:
      this
    • useCompilationDatabase

      public TranslationConfiguration.Builder useCompilationDatabase​(de.fraunhofer.aisec.cpg.frontends.CompilationDatabase compilationDatabase)
    • topLevel

      public TranslationConfiguration.Builder topLevel​(java.io.File topLevel)
    • debugParser

      public TranslationConfiguration.Builder debugParser​(boolean debugParser)
      Dump parser debug output to the logs (Caution: this will generate a lot of output).
      Parameters:
      debugParser -
      Returns:
    • failOnError

      public TranslationConfiguration.Builder failOnError​(boolean failOnError)
      Fail analysis on first error. Try to continue otherwise.
      Parameters:
      failOnError -
      Returns:
    • loadIncludes

      public TranslationConfiguration.Builder loadIncludes​(boolean loadIncludes)
      Load C/C++ include headers before the analysis.

      Required for macro expansion.

      Parameters:
      loadIncludes -
      Returns:
    • includePath

      public TranslationConfiguration.Builder includePath​(java.lang.String includePath)
      Directory containing include headers.
      Parameters:
      includePath -
      Returns:
    • includeWhitelist

      public TranslationConfiguration.Builder includeWhitelist​(java.lang.String includeFile)
      Adds the specified file to the include whitelist. Relative and absolute paths are supported.
      Parameters:
      includeFile -
      Returns:
    • disableCleanup

      public TranslationConfiguration.Builder disableCleanup()
    • includeBlacklist

      public TranslationConfiguration.Builder includeBlacklist​(java.lang.String includeFile)
      Adds the specified file to the include blacklist. Relative and absolute paths are supported.
      Parameters:
      includeFile -
      Returns:
    • registerPass

      public TranslationConfiguration.Builder registerPass​(@NonNull Pass pass)
      Register an additional Pass.
      Parameters:
      pass -
      Returns:
    • registerLanguage

      public TranslationConfiguration.Builder registerLanguage​(@NonNull java.lang.Class<? extends LanguageFrontend> frontend, java.util.List<java.lang.String> fileTypes)
      Registers an additional LanguageFrontend.
    • unregisterLanguage

      public TranslationConfiguration.Builder unregisterLanguage​(@NonNull java.lang.Class<? extends LanguageFrontend> frontend)
      Unregisters a registered LanguageFrontend.
    • defaultPasses

      public TranslationConfiguration.Builder defaultPasses()
      Register all default Passes.

      This will register

      1. FilenameMapper
      2. TypeHierarchyResolver
      3. ImportResolver
      4. VariableUsageResolver
      5. CallResolver
      6. EvaluationOrderGraphPass
      7. TypeResolver
      to be executed exactly in the specified order
      Returns:
    • defaultLanguages

      public TranslationConfiguration.Builder defaultLanguages()
      Register all default languages.
      Returns:
    • codeInNodes

      public TranslationConfiguration.Builder codeInNodes​(boolean b)
    • processAnnotations

      public TranslationConfiguration.Builder processAnnotations​(boolean b)
      Specifies, whether annotations should be process or not. By default, they are not processed, since they might populate the graph too much.
      Parameters:
      b - the new value
      Returns:
    • useUnityBuild

      public TranslationConfiguration.Builder useUnityBuild​(boolean b)
      Only relevant for C++. A unity build refers to a build that consolidates all translation units into a single one, which has the advantage that header files are only processed once, adding far less duplicate nodes to the graph
      Parameters:
      b - the new value
      Returns:
    • useParallelFrontends

      public TranslationConfiguration.Builder useParallelFrontends​(boolean b)
      If true, the ASTs for the source files are parsed in parallel, but the passes afterwards will still run in a single thread. This speeds up initial parsing but makes sure that further graph enrichment algorithms remain correct. Please make sure to also set typeSystemActiveInFrontend(boolean) to false to avoid probabilistic errors that appear depending on the parsing order.
      Parameters:
      b - the new value
      Returns:
    • typeSystemActiveInFrontend

      public TranslationConfiguration.Builder typeSystemActiveInFrontend​(boolean b)
      If false, the type system is only activated once the frontends are done building the initial AST structure. This avoids errors where the type of a node may depend on the order in which the source files have been parsed.
      Parameters:
      b - the new value
      Returns:
    • inferenceConfiguration

      public TranslationConfiguration.Builder inferenceConfiguration​(de.fraunhofer.aisec.cpg.InferenceConfiguration configuration)
    • build

      public TranslationConfiguration build()