Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,8 @@ component grammar SysMLOccurrences extends SysMLBasis {
SysMLElement*
"}" | ";")? ;

symbolrule ItemUsage = types:de.monticore.types.check.SymTypeExpression*
in:boolean
out:boolean;

}
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,7 @@ public void completeSymbolTable(ASTSysMLModel node) {
traverser.add4SysMLBasis(new SpecializationCompleter());
traverser.add4SysMLBasis(new DirectionCompleter());
traverser.add4SysMLParts(new DirectionCompleter());
traverser.add4SysMLOccurrences(new DirectionCompleter());
traverser.add4SysMLParts(new ConvertEnumUsagesToFields());
traverser.add4SysMLParts(new SysMLPartsCompleter());
traverser.add4SysMLParts(new IdentifierCompleter());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,27 @@
import de.monticore.lang.sysmlbasis._ast.ASTAnonymousUsage;
import de.monticore.lang.sysmlbasis._ast.ASTModifier;
import de.monticore.lang.sysmlbasis._visitor.SysMLBasisVisitor2;
import de.monticore.lang.sysmloccurrences._ast.ASTItemUsage;
import de.monticore.lang.sysmloccurrences._visitor.SysMLOccurrencesVisitor2;
import de.monticore.lang.sysmlparts._ast.ASTAttributeUsage;
import de.monticore.lang.sysmlparts._visitor.SysMLPartsVisitor2;

/**
* Sets the isIn / isOut properties of symbols based on Modifiers parsed to the AST.
*/
public class DirectionCompleter implements SysMLBasisVisitor2, SysMLPartsVisitor2 {
public class DirectionCompleter implements SysMLBasisVisitor2, SysMLPartsVisitor2,
SysMLOccurrencesVisitor2 {

/**
* Returns whether this is an input. Defaults to {@code true} if no direction was explicitly set. The keyword "inout"
* Returns whether this is an input. Defaults to {@code false} if no direction was explicitly set. The keyword "inout"
* yields true.
*/
protected boolean isIn(ASTModifier modifier) {
return modifier.isIn() || !modifier.isOut() && !modifier.isReturn();
return modifier.isIn() || modifier.isInout();
}

/**
* Returns whether this is an input. Defaults to {@code false} if no direction was explicitly set. The keyword "inout"
* Returns whether this is an output. Defaults to {@code false} if no direction was explicitly set. The keyword "inout"
* yields true. The keyword "return" is treated as output.
*/
protected boolean isOut(ASTModifier modifier) {
Expand Down Expand Up @@ -52,4 +55,11 @@ public void visit(ASTAttributeUsage node) {
}
}

@Override
public void visit(ASTItemUsage node) {
if(node.isPresentSymbol()) {
node.getSymbol().setIn(isIn(node.getModifier()));
node.getSymbol().setOut(isOut(node.getModifier()));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ public void testUserEnum() throws IOException {

@Test
public void testPortFullName() throws IOException {
var as = process("port def A { attribute b: boolean; } part def B { port a: A; }");
var as = process("port def A { in attribute b: boolean; } part def B { port a: A; }");
var port = as.resolveMildComponent("B").get().getPorts().get(0);

// Name muss widerspiegeln, dass der Port in B liegt und "a.b" heisst
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,23 +57,23 @@ public void reset() {
static Stream<Arguments> createInputs() {
return Stream.of(
Arguments.of(
"port def F { attribute a: boolean; }" +
"port def F { in attribute a: boolean; }" +
"part def X { port f: F; state s { transition first S if f.a then S; } }",
false),
Arguments.of(
"port def F { attribute a: boolean[3]; }" +
"port def F { in attribute a: boolean[3]; }" +
"part def X { port f: F; state s { transition first S if f.a[1] then S; } }",
false),
Arguments.of(
"port def F { attribute a: boolean; } " +
"port def F { in attribute a: boolean; } " +
"part def X { port f: F[3]; exhibit state s { transition first S if f[1].a then S; } }",
false),
Arguments.of(
"port def F { attribute a: boolean[3]; } " +
"port def F { in attribute a: boolean[3]; } " +
"part def X { port f: F[3]; exhibit state s { transition first S if f[1].a[1] then S; } }",
false),
Arguments.of(
"port def F { attribute a: boolean; } part def X { port f: F; constraint e { f.a } }",
"port def F { in attribute a: boolean; } part def X { port f: F; constraint e { f.a } }",
true)
);
}
Expand Down Expand Up @@ -106,7 +106,7 @@ public void test(String model, boolean isStream) throws IOException {

@Test
public void testProblem() throws IOException {
var ast = parser.parse_String("attribute a: boolean;");
var ast = parser.parse_String("in attribute a: boolean;");
assertThat(ast).isPresent();
var astSysmlmodel = ast.get();
SysMLv2Mill.scopesGenitorDelegator().createFromAST(astSysmlmodel);
Expand All @@ -117,7 +117,7 @@ public void testProblem() throws IOException {

@Test
public void testProblem2() throws IOException {
var ast = parser.parse_String("port def P { attribute a: boolean; }");
var ast = parser.parse_String("port def P { in attribute a: boolean; }");
assertThat(ast).isPresent();
var astSysmlmodel = ast.get();
SysMLv2Mill.scopesGenitorDelegator().createFromAST(astSysmlmodel);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,11 +106,11 @@ public void reset() {

@ParameterizedTest
@ValueSource(strings = {
"port def F { attribute a: boolean[2]; } part s { port f: F; constraint e { f.a[1] } }",
"port def F { attribute a: boolean; } part s { port f: F[1]; constraint e { f[1].a } }",
"port def F { in attribute a: boolean[2]; } part s { port f: F; constraint e { f.a[1] } }",
"port def F { in attribute a: boolean; } part s { port f: F[1]; constraint e { f[1].a } }",

"port def F { attribute a: boolean[2]; } part s { port f: F; constraint e { f[1] } }",
"port def F { attribute a: boolean; } part s { port f: F[1]; constraint e { f[1] } }"
"port def F { in attribute a: boolean[2]; } part s { port f: F; constraint e { f[1] } }",
"port def F { in attribute a: boolean; } part s { port f: F[1]; constraint e { f[1] } }"
}) public void test4ValidExpr1(String model) throws IOException {
var ast = parser.parse_String(model);
assertThat(ast).isPresent();
Expand All @@ -131,8 +131,8 @@ public void reset() {

@ParameterizedTest
@ValueSource(strings = {
"port def F { attribute a: boolean; } part s { port f: F[2]; constraint e { f.a } }",
"port def F { attribute a: boolean; } part s { port f: F[2]; constraint e { f } }"
"port def F { in attribute a: boolean; } part s { port f: F[2]; constraint e { f.a } }",
"port def F { in attribute a: boolean; } part s { port f: F[2]; constraint e { f } }"
})
public void test4InvalidExpr(String model) throws IOException {
var ast = parser.parse_String(model);;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,74 +121,74 @@ public void reset() {
static Stream<Arguments> createInputs() {
return Stream.of(
Arguments.of(
"port def F { attribute a: boolean; }" +
"port def F { in attribute a: boolean; }" +
"part def X { port f: F; state s { transition first S if f then S; } }")
,Arguments.of(
"port def F { attribute a: boolean[3]; }" +
"port def F { in attribute a: boolean[3]; }" +
"part def X { port f: F; state s { transition first S if f[1] then S; } }")
,Arguments.of(
"port def F { attribute a: boolean; } " +
"port def F { in attribute a: boolean; } " +
"part def X { port f: F[3]; exhibit state s { transition first S if f[1] then S; } }")
,Arguments.of(
"port def F { attribute a: boolean[3]; } " +
"port def F { in attribute a: boolean[3]; } " +
"part def X { port f: F[3]; exhibit state s { transition first S if f[1][1] then S; } }")
,Arguments.of(
"port def F { attribute a: boolean; } part def X { port f: F; constraint e { f } }")
"port def F { in attribute a: boolean; } part def X { port f: F; constraint e { f } }")


,Arguments.of(
"port def F { attribute a: boolean; }" +
"port def F { in attribute a: boolean; }" +
"part def X { port f: F; state s { transition first S if f.a then S; } }")
,Arguments.of(
"port def F { attribute a: boolean[3]; }" +
"port def F { in attribute a: boolean[3]; }" +
"part def X { port f: F; state s { transition first S if f.a[1] then S; } }")
,Arguments.of(
"port def F { attribute a: boolean; } " +
"port def F { in attribute a: boolean; } " +
"part def X { port f: F[3]; exhibit state s { transition first S if f[1].a then S; } }")
,Arguments.of(
"port def F { attribute a: boolean[3]; } " +
"port def F { in attribute a: boolean[3]; } " +
"part def X { port f: F[3]; exhibit state s { transition first S if f[1].a[1] then S; } }")
,Arguments.of(
"port def F { attribute a: boolean; } part def X { port f: F; constraint e { f.a } }")
"port def F { in attribute a: boolean; } part def X { port f: F; constraint e { f.a } }")
,Arguments.of(
"port def F { attribute a: boolean; } part def X { port f: F[3]; constraint e { f[1].a } }")
"port def F { in attribute a: boolean; } part def X { port f: F[3]; constraint e { f[1].a } }")


,Arguments.of(
"port def F { attribute a: boolean; attribute b: nat; }" +
"port def F { in attribute a: boolean; in attribute b: nat; }" +
"part def X { port f: F; state s { transition first S if f.a then S; } }")
,Arguments.of(
"port def F { attribute a: boolean[3]; attribute b: nat[3]; }" +
"port def F { in attribute a: boolean[3]; in attribute b: nat[3]; }" +
"part def X { port f: F; state s { transition first S if f.a[1] then S; } }")
,Arguments.of(
"port def F { attribute a: boolean; attribute b: nat; } " +
"port def F { in attribute a: boolean; in attribute b: nat; } " +
"part def X { port f: F[3]; exhibit state s { transition first S if f[1].a then S; } }")
,Arguments.of(
"port def F { attribute a: boolean[3]; attribute b: nat[3]; } " +
"port def F { in attribute a: boolean[3]; in attribute b: nat[3]; } " +
"part def X { port f: F[3]; exhibit state s { transition first S if f[1].a[1] then S; } }")
,Arguments.of(
"port def F { attribute a: boolean; attribute b: nat; } part def X { port f: F; constraint e { f.a } }")
"port def F { in attribute a: boolean; in attribute b: nat; } part def X { port f: F; constraint e { f.a } }")
,Arguments.of(
"port def F { attribute a: boolean; attribute b: nat; } part def X { port f: F[3]; constraint e { f[1].a } }")
"port def F { in attribute a: boolean; in attribute b: nat; } part def X { port f: F[3]; constraint e { f[1].a } }")
);
}

static Stream<Arguments> createInvalidInputs() {
return Stream.of(
Arguments.of(
"port def F { attribute a: boolean; attribute b: nat; }" +
"port def F { in attribute a: boolean; in attribute b: nat; }" +
"part def X { port f: F; state s { transition first S if f then S; } }")
,Arguments.of(
"port def F { attribute a: boolean[3]; attribute b: nat[3]; }" +
"port def F { in attribute a: boolean[3]; in attribute b: nat[3]; }" +
"part def X { port f: F; state s { transition first S if f[1] then S; } }")
,Arguments.of(
"port def F { attribute a: boolean; attribute b: nat; } " +
"port def F { in attribute a: boolean; in attribute b: nat; } " +
"part def X { port f: F[3]; exhibit state s { transition first S if f[1] then S; } }")
,Arguments.of(
"port def F { attribute a: boolean[3]; attribute b: nat[3]; } " +
"port def F { in attribute a: boolean[3]; in attribute b: nat[3]; } " +
"part def X { port f: F[3]; exhibit state s { transition first S if f[1][1] then S; } }")
,Arguments.of(
"port def F { attribute a: boolean; attribute b: nat; } part def X { port f: F; constraint e { f } }")
"port def F { in attribute a: boolean; in attribute b: nat; } part def X { port f: F; constraint e { f } }")
// TODO one field access with a stream method
);
}
Expand Down
Loading