Search in sources :

Example 1 with SemanticCondition

use of org.abs_models.frontend.analyser.SemanticCondition 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 2 with SemanticCondition

use of org.abs_models.frontend.analyser.SemanticCondition 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 3 with SemanticCondition

use of org.abs_models.frontend.analyser.SemanticCondition 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)

Example 4 with SemanticCondition

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

the class FrontendTest method assertTypeErrors.

protected void assertTypeErrors(String absCode, ErrorMessage expected) {
    SemanticCondition e = assertTypeErrors(absCode, EXPECT_TYPE_ERROR);
    assertEquals(expected, e.msg);
}
Also used : SemanticCondition(org.abs_models.frontend.analyser.SemanticCondition)

Example 5 with SemanticCondition

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

the class ABSTest method assertParseModelOk.

public static Model assertParseModelOk(Model m, Config... config) throws IOException {
    if (m != null) {
        final StringBuffer errs;
        String fileNames = m.getCompilationUnit(0).getFileName();
        for (int i = 1; i < m.getCompilationUnits().getNumChild(); i++) fileNames += " & " + m.getCompilationUnit(i).getFileName();
        int parseErrs = m.getParserErrors().size();
        if (parseErrs > 0) {
            errs = new StringBuffer("Parse errors: " + parseErrs + ". First error:\n");
            errs.append(m.getParserErrors().get(0));
            fail("Failed to parse: " + fileNames + "\n" + errs.toString());
            return m;
        }
        int numSemErrs = m.getErrors().getErrorCount();
        errs = new StringBuffer("Semantic errors: " + numSemErrs + "\n");
        if (numSemErrs > 0) {
            for (SemanticCondition error : m.getErrors()) errs.append(error.getHelpMessage() + "\n");
            fail("Failed to parse: " + fileNames + "\n" + errs.toString());
        } else if (isSet(TYPE_CHECK, config)) {
            SemanticConditionList l = m.typeCheck();
            if (l.containsErrors()) {
                for (SemanticCondition error : l) errs.append(error.getHelpMessage() + "\n");
                fail("Failed to typecheck: " + fileNames + "\n" + errs.toString());
            }
        }
    }
    return m;
}
Also used : SemanticConditionList(org.abs_models.frontend.analyser.SemanticConditionList) SemanticCondition(org.abs_models.frontend.analyser.SemanticCondition)

Aggregations

SemanticCondition (org.abs_models.frontend.analyser.SemanticCondition)7 SemanticConditionList (org.abs_models.frontend.analyser.SemanticConditionList)6 Model (org.abs_models.frontend.ast.Model)2 Constraint (choco.kernel.model.constraints.Constraint)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 File (java.io.File)1 PrintStream (java.io.PrintStream)1 ABSTest (org.abs_models.ABSTest)1 Main (org.abs_models.frontend.parser.Main)1 ParserError (org.abs_models.frontend.parser.ParserError)1 Test (org.junit.Test)1