Search in sources :

Example 1 with IVisitor

use of de.fraunhofer.aisec.cpg.processing.IVisitor in project cpg by Fraunhofer-AISEC.

the class SubgraphWalker method activateTypes.

public static void activateTypes(Node node) {
    AtomicInteger num = new AtomicInteger();
    Map<HasType, Set<Type>> typeCache = TypeManager.getInstance().getTypeCache();
    node.accept(Strategy::AST_FORWARD, new IVisitor<>() {

        @Override
        public void visit(Node n) {
            if (n instanceof HasType) {
                HasType typeNode = (HasType) n;
                typeCache.getOrDefault(typeNode, Collections.emptySet()).forEach(t -> {
                    t = TypeManager.getInstance().resolvePossibleTypedef(t);
                    ((HasType) n).setType(t);
                });
                typeCache.remove((HasType) n);
                num.getAndIncrement();
            }
        }
    });
    LOGGER.debug("Activated {} nodes for {}", num, node.getName());
    // For some nodes it may happen that they are not reachable via AST, but we still need to set
    // their type to the requested value
    typeCache.forEach((n, types) -> types.forEach(t -> {
        t = TypeManager.getInstance().resolvePossibleTypedef(t);
        n.setType(t);
    }));
}
Also used : LanguageFrontend(de.fraunhofer.aisec.cpg.frontends.LanguageFrontend) java.util(java.util) NonNull(org.checkerframework.checker.nullness.qual.NonNull) Logger(org.slf4j.Logger) Strategy(de.fraunhofer.aisec.cpg.processing.strategy.Strategy) AnnotationFormatError(java.lang.annotation.AnnotationFormatError) Type(de.fraunhofer.aisec.cpg.graph.types.Type) Predicate(java.util.function.Predicate) LoggerFactory(org.slf4j.LoggerFactory) de.fraunhofer.aisec.cpg.graph(de.fraunhofer.aisec.cpg.graph) Relationship(org.neo4j.ogm.annotation.Relationship) Field(java.lang.reflect.Field) Collectors(java.util.stream.Collectors) Consumer(java.util.function.Consumer) CompoundStatement(de.fraunhofer.aisec.cpg.graph.statements.CompoundStatement) IVisitor(de.fraunhofer.aisec.cpg.processing.IVisitor) de.fraunhofer.aisec.cpg.graph.declarations(de.fraunhofer.aisec.cpg.graph.declarations) MutablePair(org.apache.commons.lang3.tuple.MutablePair) Pair(org.apache.commons.lang3.tuple.Pair) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) BiConsumer(java.util.function.BiConsumer) NotNull(org.jetbrains.annotations.NotNull) PropertyEdge(de.fraunhofer.aisec.cpg.graph.edge.PropertyEdge) Nullable(org.checkerframework.checker.nullness.qual.Nullable) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Strategy(de.fraunhofer.aisec.cpg.processing.strategy.Strategy)

Aggregations

LanguageFrontend (de.fraunhofer.aisec.cpg.frontends.LanguageFrontend)1 de.fraunhofer.aisec.cpg.graph (de.fraunhofer.aisec.cpg.graph)1 de.fraunhofer.aisec.cpg.graph.declarations (de.fraunhofer.aisec.cpg.graph.declarations)1 PropertyEdge (de.fraunhofer.aisec.cpg.graph.edge.PropertyEdge)1 CompoundStatement (de.fraunhofer.aisec.cpg.graph.statements.CompoundStatement)1 Type (de.fraunhofer.aisec.cpg.graph.types.Type)1 IVisitor (de.fraunhofer.aisec.cpg.processing.IVisitor)1 Strategy (de.fraunhofer.aisec.cpg.processing.strategy.Strategy)1 AnnotationFormatError (java.lang.annotation.AnnotationFormatError)1 Field (java.lang.reflect.Field)1 java.util (java.util)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 BiConsumer (java.util.function.BiConsumer)1 Consumer (java.util.function.Consumer)1 Predicate (java.util.function.Predicate)1 Collectors (java.util.stream.Collectors)1 MutablePair (org.apache.commons.lang3.tuple.MutablePair)1 Pair (org.apache.commons.lang3.tuple.Pair)1 NonNull (org.checkerframework.checker.nullness.qual.NonNull)1 Nullable (org.checkerframework.checker.nullness.qual.Nullable)1