Class LanguageFrontend

java.lang.Object
de.fraunhofer.aisec.cpg.frontends.LanguageFrontend

public abstract class LanguageFrontend
extends java.lang.Object
  • Field Details

    • log

      public static final org.slf4j.Logger log
    • config

      protected final TranslationConfiguration config
    • scopeManager

      protected de.fraunhofer.aisec.cpg.passes.scopes.ScopeManager scopeManager
    • objectListeners

      protected java.util.Map<java.lang.Object,​java.util.function.BiConsumer<java.lang.Object,​java.lang.Object>> objectListeners
      Two data structures used to associate Objects input to a pass to results of a pass, e.g. Javaparser AST-Nodes to CPG-Nodes. The "Listeners" in processedListener are called after the node they are saved under get an entry in processedMapping. THis combination allows to keep the information on which AST-Node build which CPG-Node and operate with these associations once they exist, important to resolve connections between labels and label usages.
    • predicateListeners

      protected java.util.Map<java.util.function.BiPredicate<java.lang.Object,​java.lang.Object>,​java.util.function.BiConsumer<java.lang.Object,​java.lang.Object>> predicateListeners
    • processedMapping

      protected java.util.Map<java.lang.Object,​java.lang.Object> processedMapping
    • currentTU

      protected TranslationUnitDeclaration currentTU
  • Constructor Details

    • LanguageFrontend

      public LanguageFrontend​(@NonNull TranslationConfiguration config, de.fraunhofer.aisec.cpg.passes.scopes.ScopeManager scopeManager, java.lang.String namespaceDelimiter)
  • Method Details

    • process

      public void process​(java.lang.Object from, java.lang.Object to)
    • registerObjectListener

      public void registerObjectListener​(java.lang.Object from, java.util.function.BiConsumer<java.lang.Object,​java.lang.Object> biConsumer)
    • registerPredicateListener

      public void registerPredicateListener​(java.util.function.BiPredicate<java.lang.Object,​java.lang.Object> predicate, java.util.function.BiConsumer<java.lang.Object,​java.lang.Object> biConsumer)
    • clearProcessed

      public void clearProcessed()
    • parseAll

      public java.util.List<TranslationUnitDeclaration> parseAll() throws TranslationException
      Throws:
      TranslationException
    • getScopeManager

      public @NonNull de.fraunhofer.aisec.cpg.passes.scopes.ScopeManager getScopeManager()
    • setScopeManager

      public void setScopeManager​(@NonNull de.fraunhofer.aisec.cpg.passes.scopes.ScopeManager scopeManager)
    • getCurrentTU

      public TranslationUnitDeclaration getCurrentTU()
    • setCurrentTU

      public void setCurrentTU​(TranslationUnitDeclaration currentTU)
    • parse

      public abstract TranslationUnitDeclaration parse​(java.io.File file) throws TranslationException
      Throws:
      TranslationException
    • getCodeFromRawNode

      public abstract <T> @Nullable java.lang.String getCodeFromRawNode​(T astNode)
      Returns the raw code of the ast node, generic for java or c++ ast nodes.
      Type Parameters:
      T - the raw ast type
      Parameters:
      astNode - the ast node
      Returns:
      the source code
    • getLocationFromRawNode

      public abstract <T> @Nullable PhysicalLocation getLocationFromRawNode​(T astNode)
      Returns the Region of the code with line and column, index starting at 1, generic for java or c++ ast nodes.
      Type Parameters:
      T - the raw ast type
      Parameters:
      astNode - the ast node
      Returns:
      the location
    • setCodeAndRegion

      public <N,​ S> void setCodeAndRegion​(@NonNull N cpgNode, @Nullable S astNode)
    • getNewLineType

      public java.lang.String getNewLineType​(de.fraunhofer.aisec.cpg.graph.Node node)
      To prevent issues with different newline types and formatting.
      Parameters:
      node - - The newline type is extracted from the nodes code.
      Returns:
      the String of the newline
    • getCodeOfSubregion

      public java.lang.String getCodeOfSubregion​(de.fraunhofer.aisec.cpg.graph.Node node, Region nodeRegion, Region subRegion)
      Returns the code represented by the subregion extracted from the parent node and its region.
      Parameters:
      node - - The parent node of the subregion
      nodeRegion - - region needs to be precomputed.
      subRegion - - precomputed subregion
      Returns:
      the code of the subregion.
    • mergeRegions

      public Region mergeRegions​(Region regionOne, Region regionTwo)
      Merges two regions. The new region contains both and is the minimal region to do so.
      Parameters:
      regionOne - the first region
      regionTwo - the second region
      Returns:
      the merged region
    • cleanup

      public void cleanup()
    • getNamespaceDelimiter

      public java.lang.String getNamespaceDelimiter()
    • setComment

      public abstract <S,​ T> void setComment​(S s, T ctx)
    • getConfig

      public TranslationConfiguration getConfig()