Search in sources :

Example 16 with DeltaDecl

use of org.abs_models.frontend.ast.DeltaDecl in project abstools by abstools.

the class DeltaAddFunctionalTest method addTypeSyn.

@Test
public void addTypeSyn() throws DeltaModellingException {
    Model model = assertParse("module M;" + "type X = Int;" + "delta I; uses M;" + "adds type Y = X;");
    Decl typeX = findDecl(model, "M", "X");
    assertNotNull(typeX);
    assertThat(typeX, instanceOf(TypeSynDecl.class));
    DeltaDecl delta = findDelta(model, "I");
    assertNotNull(delta);
    assertThat(delta, instanceOf(DeltaDecl.class));
    Decl typeY = findDecl(model, "M", "Y");
    assertNull(typeY);
    model.applyDelta(delta);
    typeY = findDecl(model, "M", "Y");
    assertNotNull(typeY);
    assertThat(typeY, instanceOf(TypeSynDecl.class));
}
Also used : Model(org.abs_models.frontend.ast.Model) DeltaDecl(org.abs_models.frontend.ast.DeltaDecl) FunctionDecl(org.abs_models.frontend.ast.FunctionDecl) TypeSynDecl(org.abs_models.frontend.ast.TypeSynDecl) Decl(org.abs_models.frontend.ast.Decl) DataTypeDecl(org.abs_models.frontend.ast.DataTypeDecl) ParametricDataTypeDecl(org.abs_models.frontend.ast.ParametricDataTypeDecl) DeltaDecl(org.abs_models.frontend.ast.DeltaDecl) TypeSynDecl(org.abs_models.frontend.ast.TypeSynDecl) Test(org.junit.Test)

Example 17 with DeltaDecl

use of org.abs_models.frontend.ast.DeltaDecl in project abstools by abstools.

the class DeltaAddFunctionalTest method addDataType.

@Test
public void addDataType() throws DeltaModellingException {
    Model model = assertParse("module M;" + "data O = O;" + "delta I; uses M;" + "adds data X<A> = X(A a) | N;" + "adds data Y = K | Y(Int i);");
    Decl dataO = findDecl(model, "M", "O");
    assertNotNull(dataO);
    assertThat(dataO, instanceOf(DataTypeDecl.class));
    DeltaDecl delta = findDelta(model, "I");
    assertNotNull(delta);
    assertThat(delta, instanceOf(DeltaDecl.class));
    Decl dataX = findDecl(model, "M", "X");
    assertNull(dataX);
    Decl dataY = findDecl(model, "M", "Y");
    assertNull(dataY);
    model.applyDelta(delta);
    dataX = findDecl(model, "M", "X");
    assertNotNull(dataX);
    assertThat(dataX, instanceOf(ParametricDataTypeDecl.class));
    dataY = findDecl(model, "M", "Y");
    assertNotNull(dataY);
    assertThat(dataY, instanceOf(DataTypeDecl.class));
}
Also used : Model(org.abs_models.frontend.ast.Model) DeltaDecl(org.abs_models.frontend.ast.DeltaDecl) FunctionDecl(org.abs_models.frontend.ast.FunctionDecl) TypeSynDecl(org.abs_models.frontend.ast.TypeSynDecl) Decl(org.abs_models.frontend.ast.Decl) DataTypeDecl(org.abs_models.frontend.ast.DataTypeDecl) ParametricDataTypeDecl(org.abs_models.frontend.ast.ParametricDataTypeDecl) DeltaDecl(org.abs_models.frontend.ast.DeltaDecl) ParametricDataTypeDecl(org.abs_models.frontend.ast.ParametricDataTypeDecl) DataTypeDecl(org.abs_models.frontend.ast.DataTypeDecl) ParametricDataTypeDecl(org.abs_models.frontend.ast.ParametricDataTypeDecl) Test(org.junit.Test)

Example 18 with DeltaDecl

use of org.abs_models.frontend.ast.DeltaDecl in project abstools by abstools.

the class ProductLineAnalysisHelper method isStronglyUnambiguous.

/*
     * A product line is strongly unambiguous if each set in the partition of
     * the delta modules specified in the product-line declaration is
     * consistent, that is, if one delta module in a set adds or removes a
     * class, no other delta module in the same set may add, remove or modify
     * the same class, and the modifications of the same class in different
     * delta modules in the same set have to be disjoint.
     */
public static boolean isStronglyUnambiguous(ProductLine pl, SemanticConditionList errors) {
    boolean result = true;
    Model model = pl.getModel();
    /*
        System.out.print("Delta partition: ");
        for (Set<String> set : pl.getDeltaPartition()) {
            System.out.print("{");
            for (String el : set)
                System.out.print(" " + el + " ");
            System.out.print("}   ");
        }
        System.out.println();
         */
    assert pl.getDeltaPartition() != null;
    for (Set<String> set : pl.getDeltaPartition()) {
        // Remember the names of classes and methods modified by deltas in
        // current set
        // { Module.Class -> { Method -> Delta } }
        // { Module.Class -> { "CLASS" -> Delta } }
        Map<String, Map<String, String>> cache = new HashMap<>();
        for (String deltaID : set) {
            // assumes the DeltaDecl corresponding to deltaID exists (wellFormedProductLine)
            DeltaDecl delta = model.getDeltaDeclsMap().get(deltaID);
            assert delta.getModuleModifiers() != null;
            for (ModuleModifier moduleModifier : delta.getModuleModifiers()) {
                if (moduleModifier instanceof ModifyClassModifier) {
                    // String methodID;
                    String prefix = ((ClassModifier) moduleModifier).getQualifiedName();
                    for (Modifier mod : ((ModifyClassModifier) moduleModifier).getModifiers()) {
                        if (mod instanceof DeltaTraitModifier) {
                            HashSet<String> methodIDSet = new HashSet<>();
                            ((DeltaTraitModifier) mod).collectMethodIDs(methodIDSet, model);
                            for (String methodID : methodIDSet) {
                                if (cache.containsKey(prefix)) {
                                    if (cache.get(prefix).containsKey(methodID)) {
                                        result = false;
                                        String otherDeltaID = cache.get(prefix).get(methodID);
                                        if (!deltaID.equals(otherDeltaID))
                                            errors.add(new TypeError(pl, ErrorMessage.AMBIGUOUS_PRODUCTLINE, pl.getName(), deltaID, otherDeltaID, prefix + ", method " + methodID));
                                        else
                                            // FIXME also a kind of ambiguity but needs a different error message
                                            ;
                                    } else if (cache.get(prefix).containsKey("CLASS")) {
                                        result = false;
                                        String otherDeltaID = cache.get(prefix).get("CLASS");
                                        if (!deltaID.equals(otherDeltaID))
                                            errors.add(new TypeError(pl, ErrorMessage.AMBIGUOUS_PRODUCTLINE, pl.getName(), deltaID, otherDeltaID, prefix));
                                        else
                                            // FIXME also a kind of ambiguity but needs a different error message
                                            ;
                                    } else {
                                        cache.get(prefix).put(methodID, deltaID);
                                    }
                                } else {
                                    cache.put(prefix, new HashMap<>());
                                    cache.get(prefix).put(methodID, deltaID);
                                }
                            }
                        }
                    }
                } else if (moduleModifier instanceof AddClassModifier || moduleModifier instanceof RemoveClassModifier) {
                    String prefix = ((ClassModifier) moduleModifier).getQualifiedName();
                    if (cache.containsKey(prefix)) {
                        result = false;
                        assert !cache.get(prefix).isEmpty();
                        String otherDeltaID = cache.get(prefix).values().iterator().next();
                        errors.add(new TypeError(pl, ErrorMessage.AMBIGUOUS_PRODUCTLINE, pl.getName(), deltaID, otherDeltaID, prefix));
                        System.out.println("3 ambiguity due to " + deltaID + "<>" + otherDeltaID);
                    } else {
                        cache.put(prefix, new HashMap<>());
                        cache.get(prefix).put("CLASS", deltaID);
                    }
                }
            }
        // TODO apply same reasoning to other elements: fields,
        // functions, ADTs, etc
        }
    }
    // TODO remove boolean result unless needed
    return result;
}
Also used : HashMap(java.util.HashMap) RemoveClassModifier(org.abs_models.frontend.ast.RemoveClassModifier) AddClassModifier(org.abs_models.frontend.ast.AddClassModifier) ModifyClassModifier(org.abs_models.frontend.ast.ModifyClassModifier) ClassModifier(org.abs_models.frontend.ast.ClassModifier) AddClassModifier(org.abs_models.frontend.ast.AddClassModifier) RemoveClassModifier(org.abs_models.frontend.ast.RemoveClassModifier) DeltaDecl(org.abs_models.frontend.ast.DeltaDecl) ModifyClassModifier(org.abs_models.frontend.ast.ModifyClassModifier) ModuleModifier(org.abs_models.frontend.ast.ModuleModifier) Model(org.abs_models.frontend.ast.Model) TypeError(org.abs_models.frontend.analyser.TypeError) DeltaTraitModifier(org.abs_models.frontend.ast.DeltaTraitModifier) HashMap(java.util.HashMap) Map(java.util.Map) Modifier(org.abs_models.frontend.ast.Modifier) RemoveClassModifier(org.abs_models.frontend.ast.RemoveClassModifier) AddClassModifier(org.abs_models.frontend.ast.AddClassModifier) ModifyClassModifier(org.abs_models.frontend.ast.ModifyClassModifier) DeltaTraitModifier(org.abs_models.frontend.ast.DeltaTraitModifier) ClassModifier(org.abs_models.frontend.ast.ClassModifier) ModuleModifier(org.abs_models.frontend.ast.ModuleModifier) HashSet(java.util.HashSet)

Example 19 with DeltaDecl

use of org.abs_models.frontend.ast.DeltaDecl in project abstools by abstools.

the class PrettyPrinterTests method prettyPrinterAddDataTypeModifierTest.

@Test
public void prettyPrinterAddDataTypeModifierTest() throws Exception {
    String deltaDecl = "delta Foo;adds data States=F|B|I|M;";
    DeltaDecl d = (DeltaDecl) parseString(deltaDecl).getCompilationUnit(1).getDeltaDecl(0);
    assertEqualsAndParses(deltaDecl, d);
}
Also used : DeltaDecl(org.abs_models.frontend.ast.DeltaDecl) ABSTest(org.abs_models.ABSTest) Test(org.junit.Test)

Example 20 with DeltaDecl

use of org.abs_models.frontend.ast.DeltaDecl in project abstools by abstools.

the class OtherAnalysisTests method awaitRewriteDecl2.

@Test
public void awaitRewriteDecl2() throws Exception {
    String deltaDecl = "delta D; modifies class C { adds Unit m() { return await this!m();}}";
    Model m = assertParse(deltaDecl);
    DeltaDecl d = m.findDelta("D");
    // pity, would like this to work so that size == 0
    assertEquals(d.findChildren(AwaitAsyncCall.class).size(), 1);
}
Also used : Model(org.abs_models.frontend.ast.Model) DeltaDecl(org.abs_models.frontend.ast.DeltaDecl) FrontendTest(org.abs_models.frontend.FrontendTest) Test(org.junit.Test)

Aggregations

DeltaDecl (org.abs_models.frontend.ast.DeltaDecl)36 Test (org.junit.Test)35 Model (org.abs_models.frontend.ast.Model)34 ClassDecl (org.abs_models.frontend.ast.ClassDecl)24 ModifyClassModifier (org.abs_models.frontend.ast.ModifyClassModifier)13 DeltaTraitModifier (org.abs_models.frontend.ast.DeltaTraitModifier)8 ModifyMethodModifier (org.abs_models.frontend.ast.ModifyMethodModifier)7 TraitExpr (org.abs_models.frontend.ast.TraitExpr)7 AddMethodModifier (org.abs_models.frontend.ast.AddMethodModifier)5 TraitSetExpr (org.abs_models.frontend.ast.TraitSetExpr)5 CompilationUnit (org.abs_models.frontend.ast.CompilationUnit)4 FrontendTest (org.abs_models.frontend.FrontendTest)3 DataTypeDecl (org.abs_models.frontend.ast.DataTypeDecl)3 Decl (org.abs_models.frontend.ast.Decl)3 DeltaAccess (org.abs_models.frontend.ast.DeltaAccess)3 FunctionDecl (org.abs_models.frontend.ast.FunctionDecl)3 List (org.abs_models.frontend.ast.List)3 MethodSig (org.abs_models.frontend.ast.MethodSig)3 ParametricDataTypeDecl (org.abs_models.frontend.ast.ParametricDataTypeDecl)3 TypeSynDecl (org.abs_models.frontend.ast.TypeSynDecl)3