Class LanguageFrontend
java.lang.Object
de.fraunhofer.aisec.cpg.frontends.LanguageFrontend
public abstract class LanguageFrontend
extends java.lang.Object
-
Field Summary
Fields Modifier and Type Field Description protected TranslationConfigurationconfigprotected TranslationUnitDeclarationcurrentTUstatic org.slf4j.Loggerlogprotected java.util.Map<java.lang.Object,java.util.function.BiConsumer<java.lang.Object,java.lang.Object>>objectListenersTwo data structures used to associate Objects input to a pass to results of a pass, e.g.protected java.util.Map<java.util.function.BiPredicate<java.lang.Object,java.lang.Object>,java.util.function.BiConsumer<java.lang.Object,java.lang.Object>>predicateListenersprotected java.util.Map<java.lang.Object,java.lang.Object>processedMappingprotected de.fraunhofer.aisec.cpg.passes.scopes.ScopeManagerscopeManager -
Constructor Summary
Constructors Constructor Description LanguageFrontend(@NonNull TranslationConfiguration config, de.fraunhofer.aisec.cpg.passes.scopes.ScopeManager scopeManager, java.lang.String namespaceDelimiter) -
Method Summary
Modifier and Type Method Description voidcleanup()voidclearProcessed()abstract <T> @Nullable java.lang.StringgetCodeFromRawNode(T astNode)Returns the raw code of the ast node, generic for java or c++ ast nodes.java.lang.StringgetCodeOfSubregion(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.TranslationConfigurationgetConfig()TranslationUnitDeclarationgetCurrentTU()abstract <T> @Nullable PhysicalLocationgetLocationFromRawNode(T astNode)Returns theRegionof the code with line and column, index starting at 1, generic for java or c++ ast nodes.java.lang.StringgetNamespaceDelimiter()java.lang.StringgetNewLineType(de.fraunhofer.aisec.cpg.graph.Node node)To prevent issues with different newline types and formatting.@NonNull de.fraunhofer.aisec.cpg.passes.scopes.ScopeManagergetScopeManager()RegionmergeRegions(Region regionOne, Region regionTwo)Merges two regions.abstract TranslationUnitDeclarationparse(java.io.File file)java.util.List<TranslationUnitDeclaration>parseAll()voidprocess(java.lang.Object from, java.lang.Object to)voidregisterObjectListener(java.lang.Object from, java.util.function.BiConsumer<java.lang.Object,java.lang.Object> biConsumer)voidregisterPredicateListener(java.util.function.BiPredicate<java.lang.Object,java.lang.Object> predicate, java.util.function.BiConsumer<java.lang.Object,java.lang.Object> biConsumer)<N, S> voidsetCodeAndRegion(@NonNull N cpgNode, @Nullable S astNode)abstract <S, T> voidsetComment(S s, T ctx)voidsetCurrentTU(TranslationUnitDeclaration currentTU)voidsetScopeManager(@NonNull de.fraunhofer.aisec.cpg.passes.scopes.ScopeManager scopeManager)Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Field Details
-
log
public static final org.slf4j.Logger log -
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>> objectListenersTwo 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
-
-
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
- 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
-
setCurrentTU
-
parse
- 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
Returns theRegionof 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 subregionnodeRegion- - region needs to be precomputed.subRegion- - precomputed subregion- Returns:
- the code of the subregion.
-
mergeRegions
Merges two regions. The new region contains both and is the minimal region to do so.- Parameters:
regionOne- the first regionregionTwo- 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
-