Search in sources :

Example 1 with CFGBuilder

use of org.checkerframework.dataflow.cfg.CFGBuilder in project checker-framework by typetools.

the class GenericAnnotatedTypeFactory method analyze.

protected void analyze(Queue<ClassTree> queue, Queue<Pair<LambdaExpressionTree, Store>> lambdaQueue, UnderlyingAST ast, List<Pair<VariableElement, Value>> fieldValues, ClassTree currentClass, boolean isInitializationCode, boolean updateInitializationStore, boolean isStatic, Store lambdaStore) {
    CFGBuilder builder = new CFCFGBuilder(checker, this);
    ControlFlowGraph cfg = builder.run(root, processingEnv, ast);
    FlowAnalysis newAnalysis = createFlowAnalysis(fieldValues);
    TransferFunction transfer = newAnalysis.getTransferFunction();
    if (emptyStore == null) {
        emptyStore = newAnalysis.createEmptyStore(transfer.usesSequentialSemantics());
    }
    analyses.addFirst(newAnalysis);
    if (lambdaStore != null) {
        transfer.setFixedInitialStore(lambdaStore);
    } else {
        Store initStore = !isStatic ? initializationStore : initializationStaticStore;
        if (isInitializationCode) {
            if (initStore != null) {
                // we have already seen initialization code and analyzed it, and
                // the analysis ended with the store initStore.
                // use it to start the next analysis.
                transfer.setFixedInitialStore(initStore);
            }
        }
    }
    analyses.getFirst().performAnalysis(cfg);
    AnalysisResult<Value, Store> result = analyses.getFirst().getResult();
    // store result
    flowResult.combine(result);
    if (ast.getKind() == UnderlyingAST.Kind.METHOD) {
        // store exit store (for checking postconditions)
        CFGMethod mast = (CFGMethod) ast;
        MethodTree method = mast.getMethod();
        Store regularExitStore = analyses.getFirst().getRegularExitStore();
        if (regularExitStore != null) {
            regularExitStores.put(method, regularExitStore);
        }
        returnStatementStores.put(method, analyses.getFirst().getReturnStatementStores());
    } else if (ast.getKind() == UnderlyingAST.Kind.ARBITRARY_CODE) {
        CFGStatement block = (CFGStatement) ast;
        Store regularExitStore = analyses.getFirst().getRegularExitStore();
        if (regularExitStore != null) {
            regularExitStores.put(block.getCode(), regularExitStore);
        }
    } else if (ast.getKind() == UnderlyingAST.Kind.LAMBDA) {
        // TODO: Postconditions?
        CFGLambda block = (CFGLambda) ast;
        Store regularExitStore = analyses.getFirst().getRegularExitStore();
        if (regularExitStore != null) {
            regularExitStores.put(block.getCode(), regularExitStore);
        }
    }
    if (isInitializationCode && updateInitializationStore) {
        Store newInitStore = analyses.getFirst().getRegularExitStore();
        if (!isStatic) {
            initializationStore = newInitStore;
        } else {
            initializationStaticStore = newInitStore;
        }
    }
    if (checker.hasOption("flowdotdir") || checker.hasOption("cfgviz")) {
        handleCFGViz();
    }
    analyses.removeFirst();
    // add classes declared in method
    queue.addAll(builder.getDeclaredClasses());
    for (LambdaExpressionTree lambda : builder.getDeclaredLambdas()) {
        lambdaQueue.add(Pair.of(lambda, getStoreBefore(lambda)));
    }
}
Also used : CFGMethod(org.checkerframework.dataflow.cfg.UnderlyingAST.CFGMethod) MethodTree(com.sun.source.tree.MethodTree) CFGStatement(org.checkerframework.dataflow.cfg.UnderlyingAST.CFGStatement) CFCFGBuilder(org.checkerframework.framework.flow.CFCFGBuilder) CFGBuilder(org.checkerframework.dataflow.cfg.CFGBuilder) CFStore(org.checkerframework.framework.flow.CFStore) CFAbstractStore(org.checkerframework.framework.flow.CFAbstractStore) LambdaExpressionTree(com.sun.source.tree.LambdaExpressionTree) ControlFlowGraph(org.checkerframework.dataflow.cfg.ControlFlowGraph) CFAbstractValue(org.checkerframework.framework.flow.CFAbstractValue) CFValue(org.checkerframework.framework.flow.CFValue) CFGLambda(org.checkerframework.dataflow.cfg.UnderlyingAST.CFGLambda) CFCFGBuilder(org.checkerframework.framework.flow.CFCFGBuilder)

Aggregations

LambdaExpressionTree (com.sun.source.tree.LambdaExpressionTree)1 MethodTree (com.sun.source.tree.MethodTree)1 CFGBuilder (org.checkerframework.dataflow.cfg.CFGBuilder)1 ControlFlowGraph (org.checkerframework.dataflow.cfg.ControlFlowGraph)1 CFGLambda (org.checkerframework.dataflow.cfg.UnderlyingAST.CFGLambda)1 CFGMethod (org.checkerframework.dataflow.cfg.UnderlyingAST.CFGMethod)1 CFGStatement (org.checkerframework.dataflow.cfg.UnderlyingAST.CFGStatement)1 CFAbstractStore (org.checkerframework.framework.flow.CFAbstractStore)1 CFAbstractValue (org.checkerframework.framework.flow.CFAbstractValue)1 CFCFGBuilder (org.checkerframework.framework.flow.CFCFGBuilder)1 CFStore (org.checkerframework.framework.flow.CFStore)1 CFValue (org.checkerframework.framework.flow.CFValue)1