Search in sources :

Example 21 with SemanticConditionList

use of org.abs_models.frontend.analyser.SemanticConditionList in project abstools by abstools.

the class JavaBackendTest method getJavaCode.

protected JavaCode getJavaCode(String absCode, Config... config) throws Exception {
    Model model = null;
    String code = null;
    code = absCode;
    final int len = config.length;
    Config[] c2 = new Config[len + 2];
    for (int i = 0; i < len; i++) {
        c2[i] = config[i];
    }
    c2[len] = Config.TYPE_CHECK;
    // c2[len+1] = Config.WITH_LOC_INF; // XXX: Trips up CI.
    model = assertParse(code, c2);
    if (model.hasErrors()) {
        fail(model.getErrors().getFirstError().getHelpMessage());
    } else {
        SemanticConditionList el = model.typeCheck();
        if (el.containsErrors()) {
            fail(el.getFirstError().getMsg());
        }
    }
    if (model.hasErrors()) {
        fail(model.getErrors().getFirstError().getHelpMessage());
        return null;
    }
    return getJavaCode(model);
}
Also used : SemanticConditionList(org.abs_models.frontend.analyser.SemanticConditionList) Model(org.abs_models.frontend.ast.Model)

Example 22 with SemanticConditionList

use of org.abs_models.frontend.analyser.SemanticConditionList in project abstools by abstools.

the class LocationTypeInferenceExtension method finished.

@Override
public void finished() {
    ConstraintSolver solver = new ConstraintSolver(constraints, debug);
    results = solver.solve();
    if (debug) {
        for (Map.Entry<LocationTypeVar, LocationType> e : results.entrySet()) {
            System.out.println("" + e.getKey() + " := " + e.getValue());
        }
    }
    if (!errors.containsErrors()) {
        SemanticConditionList sel = new SemanticConditionList();
        List<TypeSystemExtension> exts = model.getTypeExt().getTypeSystemExtensionList();
        model.getTypeExt().clearTypeSystemExtensions();
        LocationTypeExtension lte = new LocationTypeExtension(model, results);
        lte.setDefaultType(defaultType);
        model.getTypeExt().register(lte);
        model.typeCheck(sel);
        errors.addAll(sel);
        model.getTypeExt().clearTypeSystemExtensions();
        model.getTypeExt().registerAll(exts);
    }
}
Also used : SemanticConditionList(org.abs_models.frontend.analyser.SemanticConditionList) Map(java.util.Map) DefaultTypeSystemExtension(org.abs_models.frontend.typechecker.ext.DefaultTypeSystemExtension) TypeSystemExtension(org.abs_models.frontend.typechecker.ext.TypeSystemExtension)

Example 23 with SemanticConditionList

use of org.abs_models.frontend.analyser.SemanticConditionList in project abstools by abstools.

the class Main method typeCheckModel.

private void typeCheckModel(Model m) {
    if (!arguments.notypecheck) {
        if (arguments.verbose)
            System.out.println("Typechecking Model...");
        registerNullableTypeChecking(m);
        registerLocationTypeChecking(m);
        SemanticConditionList typeerrors = m.typeCheck();
        for (SemanticCondition se : typeerrors) {
            System.err.println(se.getHelpMessage());
        }
    }
}
Also used : SemanticConditionList(org.abs_models.frontend.analyser.SemanticConditionList) SemanticCondition(org.abs_models.frontend.analyser.SemanticCondition)

Example 24 with SemanticConditionList

use of org.abs_models.frontend.analyser.SemanticConditionList in project abstools by abstools.

the class Main method analyzeFlattenAndRewriteModel.

/**
 * This horrible method does too many things and needs to be in every code
 * path that expects a working model, especially when products are
 * involved.  (ProductDecl.getProduct() returns null until
 * evaluateAllProductDeclarations() was called once.)
 *
 * @param m
 * @throws WrongProgramArgumentException
 * @throws DeltaModellingException
 * @throws FileNotFoundException
 */
private void analyzeFlattenAndRewriteModel(Model m) throws WrongProgramArgumentException, DeltaModellingException, FileNotFoundException {
    m.verbose = arguments.verbose;
    m.debug = arguments.debug;
    m.doAACrewrite = !arguments.prettyprint_keepsugar;
    m.doForEachRewrite = !arguments.prettyprint_keepsugar;
    if (m.hasParserErrors()) {
        System.err.println("Syntactic errors: " + m.getParserErrors().size());
        for (ParserError e : m.getParserErrors()) {
            System.err.println(e.getHelpMessage());
            System.err.flush();
        }
        return;
    }
    // resolve ProductExpressions to simple sets of features
    m.evaluateAllProductDeclarations();
    rewriteModel(m, arguments.product);
    m.flattenTraitOnly();
    m.collapseTraitModifiers();
    m.expandPartialFunctions();
    m.expandForeachLoops();
    m.expandAwaitAsyncCalls();
    if (arguments.product != null) {
        // apply deltas that correspond to arguments.productproduct
        if (arguments.notypecheck) {
            m.flattenForProductUnsafe(arguments.product);
        } else {
            m.flattenForProduct(arguments.product);
        }
    }
    if (arguments.dump) {
        m.dumpMVars();
        m.dump(System.out);
    }
    final SemanticConditionList semErrs = m.getErrors();
    if (semErrs.containsErrors()) {
        System.err.println("Semantic errors: " + semErrs.getErrorCount());
    }
    for (SemanticCondition error : semErrs) {
        // Print both errors and warnings
        System.err.println(error.getHelpMessage());
        System.err.flush();
    }
    if (!semErrs.containsErrors()) {
        typeCheckModel(m);
    }
}
Also used : SemanticConditionList(org.abs_models.frontend.analyser.SemanticConditionList) SemanticCondition(org.abs_models.frontend.analyser.SemanticCondition)

Example 25 with SemanticConditionList

use of org.abs_models.frontend.analyser.SemanticConditionList in project abstools by abstools.

the class CheckSPLCommand method typeCheckProductLine.

private void typeCheckProductLine(Model m) {
    // int n = m.getFeatureModelConfigurations().size();
    int n = m.getProductList().getNumChild();
    if (n == 0)
        return;
    if (parent.verbose) {
        System.out.println("Typechecking Software Product Line (" + n + " products)...");
    }
    SemanticConditionList errors = m.typeCheckPL();
    for (SemanticCondition err : errors) {
        System.err.println(err.getHelpMessage());
    }
}
Also used : SemanticConditionList(org.abs_models.frontend.analyser.SemanticConditionList) SemanticCondition(org.abs_models.frontend.analyser.SemanticCondition) Constraint(choco.kernel.model.constraints.Constraint)

Aggregations

SemanticConditionList (org.abs_models.frontend.analyser.SemanticConditionList)42 Model (org.abs_models.frontend.ast.Model)27 Test (org.junit.Test)27 ProductLine (org.abs_models.frontend.ast.ProductLine)7 SemanticCondition (org.abs_models.frontend.analyser.SemanticCondition)6 FrontendTest (org.abs_models.frontend.FrontendTest)5 ProductDecl (org.abs_models.frontend.ast.ProductDecl)3 ABSTest (org.abs_models.ABSTest)2 TypeError (org.abs_models.frontend.analyser.TypeError)2 Constraint (choco.kernel.model.constraints.Constraint)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 File (java.io.File)1 IOException (java.io.IOException)1 PrintStream (java.io.PrintStream)1 PrintWriter (java.io.PrintWriter)1 List (java.util.List)1 Map (java.util.Map)1 Set (java.util.Set)1 InternalBackendException (org.abs_models.backend.common.InternalBackendException)1 DefaultABSFormatter (org.abs_models.backend.prettyprint.DefaultABSFormatter)1