Skip to content

Commit

Permalink
Streamexpressions TypeCheck3 initial version
Browse files Browse the repository at this point in the history
  • Loading branch information
SE-FDr committed Dec 6, 2024
1 parent c680833 commit f10b35b
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,9 @@ component grammar StreamExpressions extends CommonExpressions {
* a:b^^c is equal to a:(b^^c)
* a+b:c is equal to (a+b):c, and
* (even so they are semantically associative)
* a <= b:c is equal to a <= (b:c), hence the priority 154, 156
* a <= b:c is equal to a <= (b:c), hence the priority 360, 370
*/
AppendStreamExpression implements Expression <154>, InfixExpression =
AppendStreamExpression implements Expression <360>, InfixExpression =
<rightassoc>
left:Expression operator:":" right:Expression;

Expand All @@ -122,7 +122,7 @@ component grammar StreamExpressions extends CommonExpressions {
* a^^b^^c is equal to a^^(b^^c), hence <rightassoc>
* (even so it is semantically associative)
*/
ConcatStreamExpression implements Expression <156>, InfixExpression =
ConcatStreamExpression implements Expression <370>, InfixExpression =
<rightassoc>
left:Expression operator:"^^" right:Expression;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ public void handle(ASTSimpleStreamConstructorExpression expr) {
// replace any Stream with EventStream after inference is done,
// as default types are not a feature the inference algorithm can handle,
// or needs to handle -> just override the result.
// todo FDr test
if (getType4Ast().hasTypeOfExpression(expr)) {
SymTypeOfGenerics streamType = getType4Ast()
.getTypeOfExpression(expr).asGenericType();
Expand Down Expand Up @@ -253,6 +252,24 @@ else if (expr.isUntimed()) {
return streamConstructorFunc;
}

/**
* {@code <T, S extends Stream<T>> (T, S) -> S}
*/
protected SymTypeOfFunction getAppendStreamFunc() {
SymTypeVariable typeVarT = createTypeVariable(
createBottomType(),
createTopType()
);
SymTypeVariable typeVarS = createTypeVariable(
createBottomType(),
StreamSymTypeFactory.createStream(typeVarT)
);
SymTypeOfFunction appendStreamFunc = createFunction(
typeVarS, List.of(typeVarT, typeVarS)
);
return appendStreamFunc;
}

/**
* {@code <T> ToptStream<T> -> ToptStream<T>}
*/
Expand Down Expand Up @@ -283,24 +300,6 @@ protected SymTypeOfFunction getAppendTickStreamFunc() {
return appendTickStreamFunc;
}

/**
* {@code <T, S extends Stream<T>> (T, S) -> S}
*/
protected SymTypeOfFunction getAppendStreamFunc() {
SymTypeVariable typeVarT = createTypeVariable(
createBottomType(),
createTopType()
);
SymTypeVariable typeVarS = createTypeVariable(
createBottomType(),
StreamSymTypeFactory.createStream(typeVarT)
);
SymTypeOfFunction appendStreamFunc = createFunction(
typeVarS, List.of(typeVarT, typeVarS)
);
return appendStreamFunc;
}

/**
* {@code <T, S extends Stream<T>> (S, S) -> S}
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -551,6 +551,7 @@ protected List<TypeEqualityBound> findInstantiationsSimple(
LOG_NAME
);
lubSubtyping = Optional.empty();
break;
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import de.monticore.expressions.commonexpressions._ast.ASTGreaterThanExpression;
import de.monticore.expressions.commonexpressions._ast.ASTLessEqualExpression;
import de.monticore.expressions.commonexpressions._ast.ASTLessThanExpression;
import de.monticore.expressions.commonexpressions._ast.ASTPlusExpression;
import de.monticore.expressions.expressionsbasis._ast.ASTExpression;
import de.monticore.expressions.expressionsbasis._ast.ASTNameExpression;
import de.monticore.expressions.javaclassexpressions._ast.ASTPrimaryGenericInvocationExpression;
Expand Down Expand Up @@ -72,7 +73,7 @@ public static Stream<Arguments> testStreamExprParsing() {
Arguments.of("<A, B, C> foo()", ASTPrimaryGenericInvocationExpression.class),
Arguments.of("Event < A > 1", ASTGreaterThanExpression.class),
Arguments.of("Event< A > 1", ASTGreaterThanExpression.class),
Arguments.of("1: c + 3", ASTAppendStreamExpression.class),
Arguments.of("1: c + 3", ASTPlusExpression.class),
Arguments.of("Tick", ASTNameExpression.class),
Arguments.of("Abs", ASTNameExpression.class),
Arguments.of("Tick : a", ASTAppendTickStreamExpression.class),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,9 @@ public static Stream<Arguments> streamConstructorTest() {
arguments("Event<1, 1.2f>", "EventStream<float>"),
arguments("Sync<1, 1.2f>", "SyncStream<float>"),
arguments("Topt<1, 1.2f>", "ToptStream<float>"),
arguments("Untimed<1, 1.2f>", "UntimedStream<float>")
arguments("Untimed<1, 1.2f>", "UntimedStream<float>"),
arguments("<1;;1.2f>", "EventStream<float>"),
arguments("<1,~,~,1.2f>", "ToptStream<float>")
);
}

Expand Down Expand Up @@ -71,6 +73,7 @@ public static Stream<Arguments> streamConstructorCTTITest() {
arguments("<1>", "UntimedStream<int>", "UntimedStream<int>")
);
}

@ParameterizedTest
@MethodSource
public void streamConstructorInvalidCTTITest(
Expand Down Expand Up @@ -108,7 +111,13 @@ public static Stream<Arguments> appendStreamTest() {
arguments("1.2f:Untimed<1>", "UntimedStream<float>"),
// longer chains
arguments("1:2:3:4:5:Event<6>", "EventStream<int>"),
arguments("1:2:3.5f:4:5:Event<6>", "EventStream<float>")
arguments("1:2:3.5f:4:5:Event<6>", "EventStream<float>"),
// Tick
arguments("Tick:<6>", "EventStream<int>"),
arguments("Tick:Tick:2:<6>", "EventStream<int>"),
// Abs
arguments("Abs:<6>", "ToptStream<int>"),
arguments("Abs:Abs:2:<6>", "ToptStream<int>")
);
}

Expand All @@ -129,7 +138,29 @@ public static Stream<Arguments> appendStreamCTTITest() {
arguments("1:2:<>", "EventStream<float>", "EventStream<float>"),
arguments("1:2:<>", "SyncStream<float>", "SyncStream<float>"),
arguments("1:2:<>", "ToptStream<float>", "ToptStream<float>"),
arguments("1:2:<>", "UntimedStream<float>", "UntimedStream<float>")
arguments("1:2:<>", "UntimedStream<float>", "UntimedStream<float>"),
// Tick
arguments("Tick:Tick:3.5f:Tick:5:<6>", "Stream<float>", "EventStream<float>"),
// Abs
arguments("Abs:Abs:3.5f:Abs:5:<6>", "Stream<float>", "ToptStream<float>")
);
}

@ParameterizedTest
@MethodSource
public void appendStreamInvalidTest(
String exprStr,
String expectedErrorStr
) throws IOException {
checkErrorExpr(exprStr, expectedErrorStr);
}

public static Stream<Arguments> appendStreamInvalidTest() {
return Stream.of(
arguments("Abs:1:Tick:1:<1>", "0xFD447"),
arguments("Tick:1:Abs:1:<1>", "0xFD447"),
arguments("Tick:<~,1>", "0xFD451"),
arguments("Abs:<;1>", "0xFD451")
);
}

Expand Down Expand Up @@ -188,9 +219,9 @@ public void concatStreamCTTITest(
public static Stream<Arguments> concatStreamCTTITest() {
return Stream.of(
arguments("<1>^^<1>", "EventStream<int>", "EventStream<int>"),
arguments("<>^^<1>", "EventStream<int>","EventStream<int>"),
arguments("Event<1>^^<>", "EventStream<int>","EventStream<int>"),
arguments("<1>^^<1.2f>", "EventStream<float>","EventStream<float>")
arguments("<>^^<1>", "EventStream<int>", "EventStream<int>"),
arguments("Event<1>^^<>", "EventStream<int>", "EventStream<int>"),
arguments("<1>^^<1.2f>", "EventStream<float>", "EventStream<float>")
);
}

Expand Down

0 comments on commit f10b35b

Please sign in to comment.