Search in sources :

Example 1 with ScopedWalker

use of de.fraunhofer.aisec.cpg.helpers.SubgraphWalker.ScopedWalker in project cpg by Fraunhofer-AISEC.

the class VariableUsageResolver method accept.

@Override
public void accept(TranslationResult result) {
    walker = new ScopedWalker(lang);
    for (TranslationUnitDeclaration tu : result.getTranslationUnits()) {
        currTu = tu;
        walker.clearCallbacks();
        walker.registerHandler((currClass, parent, currNode) -> walker.collectDeclarations(currNode));
        walker.registerHandler(this::findRecordsAndEnums);
        walker.iterate(currTu);
    }
    Map<Type, List<Type>> currSuperTypes = recordMap.values().stream().collect(Collectors.toMap(r -> TypeParser.createFrom(r.getName(), true), RecordDeclaration::getSuperTypes));
    superTypesMap.putAll(currSuperTypes);
    for (TranslationUnitDeclaration tu : result.getTranslationUnits()) {
        walker.clearCallbacks();
        walker.registerHandler(this::resolveFieldUsages);
        walker.iterate(tu);
    }
    for (TranslationUnitDeclaration tu : result.getTranslationUnits()) {
        walker.clearCallbacks();
        walker.registerHandler(this::resolveLocalVarUsage);
        walker.iterate(tu);
    }
}
Also used : Util.warnWithFileLocation(de.fraunhofer.aisec.cpg.helpers.Util.warnWithFileLocation) java.util(java.util) DeclaredReferenceExpression(de.fraunhofer.aisec.cpg.graph.statements.expressions.DeclaredReferenceExpression) Logger(org.slf4j.Logger) LoggerFactory(org.slf4j.LoggerFactory) de.fraunhofer.aisec.cpg.graph(de.fraunhofer.aisec.cpg.graph) ScopedWalker(de.fraunhofer.aisec.cpg.helpers.SubgraphWalker.ScopedWalker) NodeBuilder.newRecordDeclaration(de.fraunhofer.aisec.cpg.graph.NodeBuilder.newRecordDeclaration) Collectors(java.util.stream.Collectors) TranslationResult(de.fraunhofer.aisec.cpg.TranslationResult) MemberCallExpression(de.fraunhofer.aisec.cpg.graph.statements.expressions.MemberCallExpression) Matcher(java.util.regex.Matcher) de.fraunhofer.aisec.cpg.graph.declarations(de.fraunhofer.aisec.cpg.graph.declarations) MemberExpression(de.fraunhofer.aisec.cpg.graph.statements.expressions.MemberExpression) Util(de.fraunhofer.aisec.cpg.helpers.Util) de.fraunhofer.aisec.cpg.graph.types(de.fraunhofer.aisec.cpg.graph.types) Pattern(java.util.regex.Pattern) JavaLanguageFrontend(de.fraunhofer.aisec.cpg.frontends.java.JavaLanguageFrontend) Nullable(org.checkerframework.checker.nullness.qual.Nullable) ScopedWalker(de.fraunhofer.aisec.cpg.helpers.SubgraphWalker.ScopedWalker)

Example 2 with ScopedWalker

use of de.fraunhofer.aisec.cpg.helpers.SubgraphWalker.ScopedWalker in project cpg by Fraunhofer-AISEC.

the class CallResolver method accept.

@Override
public void accept(@NonNull TranslationResult translationResult) {
    walker = new ScopedWalker(lang);
    walker.registerHandler((currClass, parent, currNode) -> walker.collectDeclarations(currNode));
    walker.registerHandler(this::findRecords);
    walker.registerHandler(this::findTemplates);
    walker.registerHandler(this::registerMethods);
    for (TranslationUnitDeclaration tu : translationResult.getTranslationUnits()) {
        walker.iterate(tu);
    }
    walker.clearCallbacks();
    walker.registerHandler(this::fixInitializers);
    for (TranslationUnitDeclaration tu : translationResult.getTranslationUnits()) {
        walker.iterate(tu);
    }
    walker.clearCallbacks();
    walker.registerHandler(this::resolve);
    for (TranslationUnitDeclaration tu : translationResult.getTranslationUnits()) {
        walker.iterate(tu);
    }
}
Also used : ScopedWalker(de.fraunhofer.aisec.cpg.helpers.SubgraphWalker.ScopedWalker)

Aggregations

ScopedWalker (de.fraunhofer.aisec.cpg.helpers.SubgraphWalker.ScopedWalker)2 TranslationResult (de.fraunhofer.aisec.cpg.TranslationResult)1 JavaLanguageFrontend (de.fraunhofer.aisec.cpg.frontends.java.JavaLanguageFrontend)1 de.fraunhofer.aisec.cpg.graph (de.fraunhofer.aisec.cpg.graph)1 NodeBuilder.newRecordDeclaration (de.fraunhofer.aisec.cpg.graph.NodeBuilder.newRecordDeclaration)1 de.fraunhofer.aisec.cpg.graph.declarations (de.fraunhofer.aisec.cpg.graph.declarations)1 DeclaredReferenceExpression (de.fraunhofer.aisec.cpg.graph.statements.expressions.DeclaredReferenceExpression)1 MemberCallExpression (de.fraunhofer.aisec.cpg.graph.statements.expressions.MemberCallExpression)1 MemberExpression (de.fraunhofer.aisec.cpg.graph.statements.expressions.MemberExpression)1 de.fraunhofer.aisec.cpg.graph.types (de.fraunhofer.aisec.cpg.graph.types)1 Util (de.fraunhofer.aisec.cpg.helpers.Util)1 Util.warnWithFileLocation (de.fraunhofer.aisec.cpg.helpers.Util.warnWithFileLocation)1 java.util (java.util)1 Matcher (java.util.regex.Matcher)1 Pattern (java.util.regex.Pattern)1 Collectors (java.util.stream.Collectors)1 Nullable (org.checkerframework.checker.nullness.qual.Nullable)1 Logger (org.slf4j.Logger)1 LoggerFactory (org.slf4j.LoggerFactory)1