From 898b77ed1e615dd1b6dc911ac0294e2cd7e36af1 Mon Sep 17 00:00:00 2001 From: Mario Welzig Date: Sun, 5 Nov 2023 16:04:22 +0100 Subject: [PATCH 1/4] tests: break and continue --- .../tests/analysis/CoreDslStatementTest.xtend | 26 ++++++++++++++++--- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/com.minres.coredsl.tests/src/com/minres/coredsl/tests/analysis/CoreDslStatementTest.xtend b/com.minres.coredsl.tests/src/com/minres/coredsl/tests/analysis/CoreDslStatementTest.xtend index 3b40d6a..5a27245 100644 --- a/com.minres.coredsl.tests/src/com/minres/coredsl/tests/analysis/CoreDslStatementTest.xtend +++ b/com.minres.coredsl.tests/src/com/minres/coredsl/tests/analysis/CoreDslStatementTest.xtend @@ -423,6 +423,24 @@ class CoreDslStatementTest { ''' .testStatements() .run(); + + ''' + do { + break; + continue; + } while(0); + ''' + .testStatements() + .run(); + + ''' + for(;;) { + break; + continue; + } + ''' + .testStatements() + .run(); } @Test @@ -453,19 +471,19 @@ class CoreDslStatementTest { .run(); ''' - void test() { + void test1() { return; } - int test() { + int test2() { return; } - void test() { + void test3() { return 0; } - char test() { + char test4() { return 128; } ''' From e01527111a1ed4347b4a99ad7618bcf14ce9a6b7 Mon Sep 17 00:00:00 2001 From: Mario Welzig Date: Sun, 5 Nov 2023 16:30:59 +0100 Subject: [PATCH 2/4] add token field for spawn keyword --- com.minres.coredsl/src/com/minres/coredsl/CoreDsl.xtext | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/com.minres.coredsl/src/com/minres/coredsl/CoreDsl.xtext b/com.minres.coredsl/src/com/minres/coredsl/CoreDsl.xtext index db372d3..0e4a9d1 100644 --- a/com.minres.coredsl/src/com/minres/coredsl/CoreDsl.xtext +++ b/com.minres.coredsl/src/com/minres/coredsl/CoreDsl.xtext @@ -63,7 +63,7 @@ Statement: | LoopStatement; EmptyStatement: {EmptyStatement} ';'; -SpawnStatement: 'spawn' body=Statement; +SpawnStatement: t_spawn='spawn' body=Statement; CompoundStatement: {CompoundStatement} t_openingBrace='{' statements+=Statement* t_closingBrace='}'; ExpressionStatement: expression=AssignmentExpression ';'; DeclarationStatement: declaration=MultiInitDeclaration ';'; From cff1e577def86cded8b3c847034993cbb1b5e951 Mon Sep 17 00:00:00 2001 From: Mario Welzig Date: Sun, 5 Nov 2023 16:32:30 +0100 Subject: [PATCH 3/4] validate placement of spawn statements --- .../coredsl/analysis/CoreDslAnalyzer.xtend | 23 ++++++++++++++++++- .../coredsl/validation/IssueCodes.xtend | 1 + 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/com.minres.coredsl/src/com/minres/coredsl/analysis/CoreDslAnalyzer.xtend b/com.minres.coredsl/src/com/minres/coredsl/analysis/CoreDslAnalyzer.xtend index 90d14ee..17b686c 100644 --- a/com.minres.coredsl/src/com/minres/coredsl/analysis/CoreDslAnalyzer.xtend +++ b/com.minres.coredsl/src/com/minres/coredsl/analysis/CoreDslAnalyzer.xtend @@ -616,7 +616,28 @@ class CoreDslAnalyzer { analyzeStatement(ctx, statement.body); } + /** + * 1. The statement must be the last child of an instruction's behavior block. (InvalidSpawnStatementPlacement) + */ def static dispatch void analyzeStatement(AnalysisContext ctx, SpawnStatement statement) { + var isDirectInstrChild = statement.eContainingFeature == CoreDslPackage.Literals.INSTRUCTION__BEHAVIOR; + var isInstrBlockChild = statement.eContainer instanceof CompoundStatement && + statement.eContainer.eContainingFeature == CoreDslPackage.Literals.INSTRUCTION__BEHAVIOR; + + // There are two valid placements for a spawn statement: + // 1. As the direct child of an instruction + // 2. As the last child of a compound statement, which in turn is the direct child of an instruction + if(isInstrBlockChild) { + var block = statement.eContainer as CompoundStatement; + if(block.statements.indexOf(statement) != block.statements.size - 1) { + ctx.acceptError("A spawn statement must be the last statement of an instruction's behavior block", statement, + CoreDslPackage.Literals.SPAWN_STATEMENT__TSPAWN, -1, IssueCodes.InvalidSpawnStatementPlacement) + } + } else if(!isDirectInstrChild) { + ctx.acceptError("A spawn statement must be the last statement of an instruction's behavior block", statement, + CoreDslPackage.Literals.SPAWN_STATEMENT__TSPAWN, -1, IssueCodes.InvalidSpawnStatementPlacement) + } + analyzeStatement(ctx, statement.body); } @@ -868,7 +889,7 @@ class CoreDslAnalyzer { reportTarget.object, reportTarget.feature, reportTarget.index, IssueCodes.ValidConstantAssignment); } else { ctx.acceptError("Cannot implicitly convert " + valueType + " to " + targetType, reportTarget.object, - reportTarget.feature, reportTarget.index, issueCode); + reportTarget.feature, reportTarget.index, issueCode); } } } diff --git a/com.minres.coredsl/src/com/minres/coredsl/validation/IssueCodes.xtend b/com.minres.coredsl/src/com/minres/coredsl/validation/IssueCodes.xtend index 8e0acc8..533ba28 100644 --- a/com.minres.coredsl/src/com/minres/coredsl/validation/IssueCodes.xtend +++ b/com.minres.coredsl/src/com/minres/coredsl/validation/IssueCodes.xtend @@ -79,6 +79,7 @@ class IssueCodes { public static val SwitchDuplicateCaseSection = _prefix + 'SwitchDuplicateCaseSection'; public static val SwitchCaseConditionOutOfRange = _prefix + 'SwitchCaseConditionOutOfRange'; public static val StrayControlFlowStatement = _prefix + 'StrayControlFlowStatement'; + public static val InvalidSpawnStatementPlacement = _prefix + 'InvalidSpawnStatementPlacement'; // expression issues public static val ValidConstantAssignment = _prefix + 'ValidConstantAssignment'; From c9fb2d35983b2867a46a8b954eb4162028d6f318 Mon Sep 17 00:00:00 2001 From: Mario Welzig Date: Sun, 5 Nov 2023 16:41:08 +0100 Subject: [PATCH 4/4] tests: spawn statement --- .../tests/analysis/CoreDslStatementTest.xtend | 115 ++++++++++++++++++ 1 file changed, 115 insertions(+) diff --git a/com.minres.coredsl.tests/src/com/minres/coredsl/tests/analysis/CoreDslStatementTest.xtend b/com.minres.coredsl.tests/src/com/minres/coredsl/tests/analysis/CoreDslStatementTest.xtend index 5a27245..20af76d 100644 --- a/com.minres.coredsl.tests/src/com/minres/coredsl/tests/analysis/CoreDslStatementTest.xtend +++ b/com.minres.coredsl.tests/src/com/minres/coredsl/tests/analysis/CoreDslStatementTest.xtend @@ -493,4 +493,119 @@ class CoreDslStatementTest { .expectError(IssueCodes.ReturnTypeNotConvertible, 14) .run(); } + + @Test + def void spawnStatement() { + ''' + TEST { + encoding: 0; + behavior: spawn; + } + ''' + .testInstruction() + .run(); + + ''' + TEST { + encoding: 0; + behavior: { + spawn {} + } + } + ''' + .testInstruction() + .run(); + + ''' + TEST { + encoding: 0; + behavior: { + {}; + spawn; + } + } + ''' + .testInstruction() + .run(); + + ''' + TEST { + encoding: 0; + behavior: spawn { + unsigned<1> x = 2; + } + } + ''' + .testInstruction() + .expectError(IssueCodes.InvalidAssignmentType, 4) + .run(); + + ''' + TEST { + encoding: 0; + behavior: { + spawn; + spawn; + } + } + ''' + .testInstruction() + .expectError(IssueCodes.InvalidSpawnStatementPlacement, 4) + .run(); + + ''' + TEST { + encoding: 0; + behavior: { + { + spawn; + } + } + } + ''' + .testInstruction() + .expectError(IssueCodes.InvalidSpawnStatementPlacement, 5) + .run(); + + ''' + TEST { + encoding: 0; + behavior: spawn spawn; + } + ''' + .testInstruction() + .expectError(IssueCodes.InvalidSpawnStatementPlacement, 3) + .run(); + + ''' + Core X { + always { + TEST { + spawn; + } + } + } + ''' + .testProgram() + .expectError(IssueCodes.InvalidSpawnStatementPlacement, 4) + .run(); + + ''' + void test() { + spawn; + } + ''' + .testFunction() + .expectError(IssueCodes.InvalidSpawnStatementPlacement, 2) + .run(); + + ''' + void test() { + spawn; + } + ''' + .testFunction() + .expectError(IssueCodes.InvalidSpawnStatementPlacement, 2) + .run(); + } }