Search in sources :

Example 1 with ProductDecl

use of abs.frontend.ast.ProductDecl in project abstools by abstools.

the class SearchSolutionsTest method CheckEmptyProduct.

@Test
public void CheckEmptyProduct() throws WrongProgramArgumentException {
    Model model = assertParseOk(withoutProducLine);
    ChocoSolver s = model.instantiateCSModel();
    model.evaluateAllProductDeclarations();
    ProductDecl product = model.findProduct("P");
    Map<String, Integer> guess = product.getProduct().getSolution();
    assertEquals(true, s.checkSolution(guess, model));
}
Also used : ProductDecl(abs.frontend.ast.ProductDecl) Model(abs.frontend.ast.Model) Test(org.junit.Test) FrontendTest(abs.frontend.FrontendTest)

Example 2 with ProductDecl

use of abs.frontend.ast.ProductDecl in project abstools by abstools.

the class AbstractTab method fillProductDropDownMenue.

/**
 * Lists all products in the current project's module, incl. a "<base>" product if
 * no particular product is selected.
 * @param preSelected The product that should be preselected, or null for <base>.
 */
protected void fillProductDropDownMenue(String preSelected) {
    productDropDown.removeAll();
    productDropDown.add("<base>");
    IProject proj = getSelectedProject();
    if (proj == null) {
        return;
    }
    AbsNature n = UtilityFunctions.getAbsNature(proj);
    Model m = n.getCompleteModel();
    if (m == null)
        return;
    Collection<ProductDecl> prods = m.getProductDecls();
    if (prods == null)
        return;
    int i = 1;
    /* base comes first */
    int selected = 0;
    for (ProductDecl p : prods) {
        final String name = p.getName();
        productDropDown.add(name);
        if (name.equals(preSelected)) {
            selected = i;
        }
        i++;
    }
    productDropDown.select(selected);
}
Also used : ProductDecl(abs.frontend.ast.ProductDecl) Model(abs.frontend.ast.Model) IProject(org.eclipse.core.resources.IProject) AbsNature(org.absmodels.abs.plugin.builder.AbsNature)

Example 3 with ProductDecl

use of abs.frontend.ast.ProductDecl in project abstools by abstools.

the class IncrementalModelBuilder method typeCheckModel.

public synchronized SemanticConditionList typeCheckModel(IProgressMonitor monitor, boolean locationTypeChecking, String defaultloctype, String locationTypePrecision, boolean checkProducts) throws NoModelException, TypecheckInternalException {
    if (model == null)
        throw new NoModelException();
    if (model.hasParserErrors())
        // don't typecheck if the model has parsererrors
        return new SemanticConditionList();
    // throw new TypecheckInternalException(new Exception("Model has parser errors!"));
    // model.flushCache();
    flushAll(model);
    model.getTypeExt().clearTypeSystemExtensions();
    if (locationTypeChecking) {
        LocationType defaultLocType = LocationType.createFromName(defaultloctype);
        LocationTypeInferrerExtension ltie = new LocationTypeInferrerExtension(model);
        this.ltie = ltie;
        ltie.setDefaultType(defaultLocType);
        ltie.setLocationTypingPrecision(LocationTypingPrecision.valueOf(locationTypePrecision));
        model.registerTypeSystemExtension(ltie);
    }
    try {
        SemanticConditionList semerrors = model.getErrors();
        /* Don't typecheck with semerrors, it might trip up. */
        if (!semerrors.containsErrors())
            semerrors = model.typeCheck();
        /* Check products for errors.
			 * Only the first error is reported (if any), on the product AST-node.
			 * TODO: May be time-consuming for large projects, hence the checkProducts-switch.
			 *       Also could use a timer to switch off if it becomes excessive.
			 * TODO: Use Eclipse's nested markers to show ALL contained errors?
			 * TODO: The outline could indicate the broken product as well.
			 */
        if (!semerrors.containsErrors() && checkProducts) {
            // arbitrary value
            monitor = new SubProgressMonitor(monitor, 10);
            monitor.beginTask("Checking products", model.getProductDecls().size());
            for (ProductDecl p : model.getProductDecls()) {
                monitor.subTask("Checking " + p.getName());
                Model m2 = model.treeCopyNoTransform();
                m2.flushTreeCache();
                try {
                    m2.flattenForProduct(p);
                    SemanticConditionList p_errs = m2.typeCheck();
                    if (p_errs.containsErrors()) {
                        // Only show first error, on product
                        semerrors.add(new SemanticError(p, ErrorMessage.ERROR_IN_PRODUCT, p.getName(), p_errs.getFirstError().getMessage()));
                    }
                } catch (WrongProgramArgumentException e) {
                    semerrors.add(new SemanticError(p, ErrorMessage.ERROR_IN_PRODUCT, p.getName(), e.getMessage()));
                } catch (DeltaModellingException e) {
                    /* We we have a better location for error reporting? */
                    final ASTNode<?> loc;
                    if (e instanceof DeltaModellingWithNodeException)
                        loc = ((DeltaModellingWithNodeException) e).getNode();
                    else
                        loc = p;
                    if (e.getDelta() == null)
                        semerrors.add(new SemanticError(loc, ErrorMessage.ERROR_IN_PRODUCT, p.getName(), e.getMessage()));
                    else
                        semerrors.add(new SemanticError(loc, ErrorMessage.ERROR_IN_PRODUCT_WITH_DELTA, p.getName(), e.getDelta().getName(), e.getMessage()));
                }
            }
            monitor.done();
        }
        return semerrors;
    } catch (TypeCheckerException e) {
        return new SemanticConditionList(e);
    } catch (RuntimeException e) {
        throw new TypecheckInternalException(e);
    }
}
Also used : ProductDecl(abs.frontend.ast.ProductDecl) WrongProgramArgumentException(abs.common.WrongProgramArgumentException) DeltaModellingWithNodeException(abs.frontend.delta.DeltaModellingWithNodeException) SubProgressMonitor(org.eclipse.core.runtime.SubProgressMonitor) LocationTypeInferrerExtension(abs.frontend.typechecker.locationtypes.infer.LocationTypeInferrerExtension) TypeCheckerException(abs.frontend.typechecker.TypeCheckerException) SemanticConditionList(abs.frontend.analyser.SemanticConditionList) SemanticError(abs.frontend.analyser.SemanticError) Model(abs.frontend.ast.Model) ASTNode(abs.frontend.ast.ASTNode) LocationType(abs.frontend.typechecker.locationtypes.LocationType) DeltaModellingException(abs.frontend.delta.DeltaModellingException)

Example 4 with ProductDecl

use of abs.frontend.ast.ProductDecl in project abstools by abstools.

the class DeltaOrderingTest method properSorting1.

@Test
public void properSorting1() throws DeltaModellingException, WrongProgramArgumentException {
    Model model = assertParseOk("module Test;" + "delta D1;" + "delta D2;" + "productline PL;" + "features A,B;" + "delta D1 when A;" + "delta D2 after D1 when B;" + "product P1(A);" + "product P2(A, B);");
    model.evaluateAllProductDeclarations();
    ProductDecl prod = model.findProduct("P1");
    ProductLine pl = model.getProductLine();
    Set<String> deltaids = pl.findApplicableDeltas(prod.getProduct());
    List<String> sorted_deltaids = pl.sortDeltas(deltaids);
    assertArrayEquals(new String[] { "D1" }, sorted_deltaids.toArray());
    prod = model.findProduct("P2");
    deltaids = pl.findApplicableDeltas(prod.getProduct());
    sorted_deltaids = pl.sortDeltas(deltaids);
    assertArrayEquals(new String[] { "D1", "D2" }, sorted_deltaids.toArray());
    assertFalse(model.typeCheck().containsErrors());
}
Also used : ProductDecl(abs.frontend.ast.ProductDecl) Model(abs.frontend.ast.Model) ProductLine(abs.frontend.ast.ProductLine) Test(org.junit.Test)

Example 5 with ProductDecl

use of abs.frontend.ast.ProductDecl in project abstools by abstools.

the class DeltaOrderingTest method properSorting9.

@Test
public void properSorting9() throws DeltaModellingException, WrongProgramArgumentException {
    Model model = assertParseOk("module Test;" + "delta D1;" + "delta D2;" + "delta D3;" + "delta D4;" + "delta D5;" + "delta D6;" + "delta D7;" + "delta D8;" + "delta D9;" + "productline PL;" + "features A,B,C,D,E,F,G,H,I;" + "delta D1 after D2 when A;" + "delta D2 after D3 when B;" + "delta D3 after D4 when C;" + "delta D4 after D5 when D;" + "delta D5 after D6 when E;" + "delta D6 after D7 when F;" + "delta D7 after D8 when G;" + "delta D8 after D9 when H;" + "delta D9 when I;" + "product P1(A,B,C,D,E,F,G,H,I);" + "product P2(A,C,E,G,I);");
    model.evaluateAllProductDeclarations();
    ProductDecl prod = model.findProduct("P1");
    ProductLine pl = model.getProductLine();
    Set<String> deltaids = pl.findApplicableDeltas(prod.getProduct());
    List<String> sorted_deltaids = pl.sortDeltas(deltaids);
    assertArrayEquals(new String[] { "D9", "D8", "D7", "D6", "D5", "D4", "D3", "D2", "D1" }, sorted_deltaids.toArray());
    prod = model.findProduct("P2");
    deltaids = pl.findApplicableDeltas(prod.getProduct());
    sorted_deltaids = pl.sortDeltas(deltaids);
    assertArrayEquals(new String[] { "D9", "D7", "D5", "D3", "D1" }, sorted_deltaids.toArray());
    assertFalse(model.typeCheck().containsErrors());
}
Also used : ProductDecl(abs.frontend.ast.ProductDecl) Model(abs.frontend.ast.Model) ProductLine(abs.frontend.ast.ProductLine) Test(org.junit.Test)

Aggregations

ProductDecl (abs.frontend.ast.ProductDecl)7 Model (abs.frontend.ast.Model)6 ProductLine (abs.frontend.ast.ProductLine)3 Test (org.junit.Test)3 WrongProgramArgumentException (abs.common.WrongProgramArgumentException)1 FrontendTest (abs.frontend.FrontendTest)1 SemanticConditionList (abs.frontend.analyser.SemanticConditionList)1 SemanticError (abs.frontend.analyser.SemanticError)1 ASTNode (abs.frontend.ast.ASTNode)1 AppCond (abs.frontend.ast.AppCond)1 AppCondFeature (abs.frontend.ast.AppCondFeature)1 DeltaClause (abs.frontend.ast.DeltaClause)1 DeltaID (abs.frontend.ast.DeltaID)1 Deltaspec (abs.frontend.ast.Deltaspec)1 Feature (abs.frontend.ast.Feature)1 ProductFeatureSet (abs.frontend.ast.ProductFeatureSet)1 DeltaModellingException (abs.frontend.delta.DeltaModellingException)1 DeltaModellingWithNodeException (abs.frontend.delta.DeltaModellingWithNodeException)1 TypeCheckerException (abs.frontend.typechecker.TypeCheckerException)1 LocationType (abs.frontend.typechecker.locationtypes.LocationType)1