Search in sources :

Example 1 with PhaseOneResult

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

the class CFCFGBuilder method build.

/**
 * Build the control flow graph of some code.
 */
public static ControlFlowGraph build(CompilationUnitTree root, UnderlyingAST underlyingAST, BaseTypeChecker checker, AnnotatedTypeFactory factory, ProcessingEnvironment env) {
    boolean assumeAssertionsEnabled = checker.hasOption("assumeAssertionsAreEnabled");
    boolean assumeAssertionsDisabled = checker.hasOption("assumeAssertionsAreDisabled");
    if (assumeAssertionsEnabled && assumeAssertionsDisabled) {
        throw new UserError("Assertions cannot be assumed to be enabled and disabled at the same time.");
    }
    // allow a super-checker to query the stores of a subchecker.
    if (factory instanceof GenericAnnotatedTypeFactory) {
        GenericAnnotatedTypeFactory<?, ?, ?, ?> asGATF = (GenericAnnotatedTypeFactory<?, ?, ?, ?>) factory;
        if (asGATF.hasOrIsSubchecker) {
            ControlFlowGraph sharedCFG = asGATF.getSharedCFGForTree(underlyingAST.getCode());
            if (sharedCFG != null) {
                return sharedCFG;
            }
        }
    }
    CFTreeBuilder builder = new CFTreeBuilder(env);
    PhaseOneResult phase1result = new CFCFGTranslationPhaseOne(builder, checker, factory, assumeAssertionsEnabled, assumeAssertionsDisabled, env).process(root, underlyingAST);
    ControlFlowGraph phase2result = CFGTranslationPhaseTwo.process(phase1result);
    ControlFlowGraph phase3result = CFGTranslationPhaseThree.process(phase2result);
    if (factory instanceof GenericAnnotatedTypeFactory) {
        GenericAnnotatedTypeFactory<?, ?, ?, ?> asGATF = (GenericAnnotatedTypeFactory<?, ?, ?, ?>) factory;
        if (asGATF.hasOrIsSubchecker) {
            asGATF.addSharedCFGForTree(underlyingAST.getCode(), phase3result);
        }
    }
    return phase3result;
}
Also used : GenericAnnotatedTypeFactory(org.checkerframework.framework.type.GenericAnnotatedTypeFactory) UserError(org.checkerframework.javacutil.UserError) ControlFlowGraph(org.checkerframework.dataflow.cfg.ControlFlowGraph) PhaseOneResult(org.checkerframework.dataflow.cfg.builder.PhaseOneResult)

Aggregations

ControlFlowGraph (org.checkerframework.dataflow.cfg.ControlFlowGraph)1 PhaseOneResult (org.checkerframework.dataflow.cfg.builder.PhaseOneResult)1 GenericAnnotatedTypeFactory (org.checkerframework.framework.type.GenericAnnotatedTypeFactory)1 UserError (org.checkerframework.javacutil.UserError)1