Skip to content

Commit

Permalink
Hotfix stereo value type check
Browse files Browse the repository at this point in the history
  • Loading branch information
schmalzing committed Dec 5, 2024
1 parent a2c7b80 commit 88070d7
Show file tree
Hide file tree
Showing 5 changed files with 79 additions and 8 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package montiarc.timed.automata;

component And {

port in boolean a;
port in boolean b;
port out boolean q;

boolean as = false;
boolean bs = false;

<<timed>> automaton {
initial state S;
S -> S a / { as = a; };
S -> S b / { bs = b; };
S -> S / { q = as && bs; };
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package montiarc.timed.automata;

import java.util.List;
import montiarc.maunit.api.AssertEqualsTimed;
import montiarc.maunit.api.EmitTimed;

<<test,
ticks=3,
a=[
[[false, false], [true], [true]],
[[false, false], [false], [false, true]]
],
b=[
[[false, true], [false], [true]],
[[false, true], [false], [true, true]]
],
expected=[
[[false], [false], [true]],
[[false], [false], [true]]
]>>
component AndTest(List<List<Boolean>> a,
List<List<Boolean>> b,
List<List<Boolean>> expected) {

And sut;

emitterA.out -> sut.a;
emitterB.out -> sut.b;
sut.q -> assertEquals.actual;

AssertEqualsTimed<Boolean> assertEquals(expected);
EmitTimed<Boolean> emitterA(a);
EmitTimed<Boolean> emitterB(b);
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,22 @@
import arcbasis.ArcBasisMill;
import arcbasis._ast.ASTArcParameter;
import arcbasis._ast.ASTComponentType;
import arcbasis._ast.ASTStereoValueExpr;
import arcbasis._cocos.ArcBasisASTComponentTypeCoCo;
import com.google.common.base.Preconditions;
import de.monticore.ast.ASTNode;
import de.monticore.expressions.expressionsbasis._ast.ASTExpression;
import de.monticore.ocl.setexpressions._ast.ASTSetCollectionItem;
import de.monticore.ocl.setexpressions._ast.ASTSetEnumeration;
import de.monticore.types.check.SymTypeExpression;
import de.monticore.types.check.SymTypeExpressionFactory;
import de.monticore.types.check.SymTypeOfGenerics;
import de.monticore.types.mccollectiontypes.types3.util.MCCollectionSymTypeFactory;
import de.monticore.types3.SymTypeRelations;
import de.monticore.types3.TypeCheck3;
import de.se_rwth.commons.logging.Log;
import montiarc.MontiArcMill;
import montiarc.util.MontiArcError;
import org.codehaus.commons.nullanalysis.NotNull;
import arcbasis._ast.ASTStereoValueExpr;
import variablearc._ast.ASTArcFeature;
import variablearc._ast.ASTArcFeatureDeclaration;

Expand Down Expand Up @@ -230,9 +231,14 @@ protected void checkTypeFits(@NotNull ASTStereoValueExpr stereo, @NotNull SymTyp

if (MontiArcMill.typeDispatcher().isSetExpressionsASTSetEnumeration(stereo.getExpression())
&& MontiArcMill.typeDispatcher().asSetExpressionsASTSetEnumeration(stereo.getExpression()).isList()) {
for (ASTSetCollectionItem node : MontiArcMill.typeDispatcher().asSetExpressionsASTSetEnumeration(stereo.getExpression()).getSetCollectionItemList()) {
checkTypeFits(stereo.getName(), node, type, TypeCheck3.typeOf(MontiArcMill.typeDispatcher().asSetExpressionsASTSetValueItem(node).getExpression(), type));
}

// The stereo value should be of type List<X> where X is the type of the
// corresponding parameter. We create the target type for the stereo
// value here to check against it.
SymTypeOfGenerics targetType = MCCollectionSymTypeFactory.createList(type);

checkTypeFits(stereo.getName(), stereo.getExpression(), targetType, TypeCheck3.typeOf(stereo.getExpression(), targetType) );

} else {
checkTypeFits(stereo.getName(), stereo, type, TypeCheck3.typeOf(ArcBasisMill.typeDispatcher().asArcBasisASTStereoValueExpr(stereo).getExpression(), type));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,23 @@
import arcbasis._ast.ASTComponentType;
import arcbasis._symboltable.ComponentTypeSymbol;
import com.google.common.base.Preconditions;
import de.monticore.class2mc.OOClass2MCResolver;
import de.monticore.expressions.expressionsbasis._ast.ASTExpression;
import de.monticore.literals.mccommonliterals._ast.ASTNatLiteral;
import de.monticore.symbols.basicsymbols.BasicSymbolsMill;
import de.monticore.types.check.SymTypeExpressionFactory;
import de.monticore.types.mcbasictypes._ast.ASTMCType;
import de.monticore.types.mccollectiontypes.MCCollectionTypesMill;
import de.monticore.types.mccollectiontypes.types3.util.MCCollectionSymTypeFactory;
import de.se_rwth.commons.logging.Log;
import montiarc.MontiArcMill;
import montiarc.MontiArcTestBase;
import montiarc._ast.ASTMACompilationUnit;
import montiarc.util.Error;
import montiarc.util.MCError;
import montiarc.util.MontiArcError;
import org.codehaus.commons.nullanalysis.NotNull;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
Expand All @@ -35,6 +41,12 @@
*/
class MaUnitTestConfiguredCorrectlyTest extends MontiArcTestBase {

@BeforeEach
public void initSymbols() {
MontiArcMill.globalScope().addAdaptedTypeSymbolResolver(new OOClass2MCResolver());
MontiArcMill.globalScope().addAdaptedOOTypeSymbolResolver(new OOClass2MCResolver());
}

@ParameterizedTest
@ValueSource(strings = {
// no test
Expand Down Expand Up @@ -143,10 +155,10 @@ protected static Stream<Arguments> invalidModels() {
MontiArcError.UNIT_TYPE_MISMATCH),
// 2 tests, ticks type mismatch in list
arg("<<test, ticks=[1,true]>> component Comp12() { }",
MontiArcError.UNIT_TYPE_MISMATCH),
MCError.TARGET_TYPE_MISMATCH),
// 2 tests, parameter type mismatch in list
arg("<<test, ticks=[1,2], i=[1,true]>> component Comp13(int i) { }",
MontiArcError.UNIT_TYPE_MISMATCH),
MCError.TARGET_TYPE_MISMATCH),
// test, but not deployable
arg("<<test>> component Comp14 { port out int p; }",
MontiArcError.UNIT_CANNOT_HAVE_PORTS),
Expand Down
3 changes: 2 additions & 1 deletion languages/montiarc/test/java/montiarc/util/MCError.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ public enum MCError implements Error {
CANT_FIND_SYMBOL("0xA0324"),
CANT_FIND_SYMBOL_IN_EXPRESSION("0xFD118"),
TYPE_STRING_NOT_RESOLVABLE("0xD02A6"),
FOUND_MULTIPLE_SYMBOLS("0xA4095");
FOUND_MULTIPLE_SYMBOLS("0xA4095"),
TARGET_TYPE_MISMATCH("0xFD451");

public static final Pattern ERROR_CODE_PATTERN = Pattern.compile("0xA\\d{4}");

Expand Down

0 comments on commit 88070d7

Please sign in to comment.