Class LanguageFrontend
- java.lang.Object
-
- de.fraunhofer.aisec.cpg.frontends.LanguageFrontend
-
- Direct Known Subclasses:
CXXLanguageFrontend,JavaLanguageFrontend
public abstract class LanguageFrontend extends java.lang.Object
-
-
Field Summary
Fields Modifier and Type Field Description protected TranslationConfigurationconfigprotected static 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 ScopeManagerscopeManager
-
Constructor Summary
Constructors Constructor Description LanguageFrontend(@NonNull TranslationConfiguration config, ScopeManager scopeManager, java.lang.String namespaceDelimiter)
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description voidaddRecord(RecordDeclaration record)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(Node node, Region nodeRegion, Region subRegion)Returns the code represented by the subregion extracted from the parent node and its region.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(Node node)To prevent issues with different newline types and formatting.java.util.Optional<RecordDeclaration>getRecordForName(java.lang.String name)Returns a record declaration, if it exists for the given namejava.util.Map<java.lang.String,RecordDeclaration>getRecords()@NonNull 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, @NonNull S astNode)abstract <S,T>
voidsetComment(S s, T ctx)voidsetScopeManager(@NonNull ScopeManager scopeManager)
-
-
-
Field Detail
-
log
protected static final org.slf4j.Logger log
-
config
protected final TranslationConfiguration config
-
scopeManager
protected 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
-
-
Constructor Detail
-
LanguageFrontend
public LanguageFrontend(@NonNull TranslationConfiguration config, ScopeManager scopeManager, java.lang.String namespaceDelimiter)
-
-
Method Detail
-
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 ScopeManager getScopeManager()
-
setScopeManager
public void setScopeManager(@NonNull ScopeManager scopeManager)
-
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 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, @NonNull S astNode)
-
getNewLineType
public java.lang.String getNewLineType(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(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
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 regionregionTwo- the second region- Returns:
- the merged region
-
addRecord
public void addRecord(RecordDeclaration record)
-
getRecords
public java.util.Map<java.lang.String,RecordDeclaration> getRecords()
-
cleanup
public void cleanup()
-
getNamespaceDelimiter
public java.lang.String getNamespaceDelimiter()
-
setComment
public abstract <S,T> void setComment(S s, T ctx)
-
getRecordForName
public java.util.Optional<RecordDeclaration> getRecordForName(java.lang.String name)
Returns a record declaration, if it exists for the given name- Parameters:
name- the record name- Returns:
- an optional containing the
RecordDeclaration, if it exists.
-
-