mirror of
https://gitlab.com/camelot/kickc.git
synced 2025-02-17 10:30:43 +00:00
Added a few enum error tests
This commit is contained in:
parent
291c87621e
commit
2acc1010ec
@ -1207,6 +1207,7 @@ public class Pass0GenerateStatementSequence extends KickCBaseVisitor<Object> {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Object visitEnumDef(KickCParser.EnumDefContext ctx) {
|
public Object visitEnumDef(KickCParser.EnumDefContext ctx) {
|
||||||
|
try {
|
||||||
String enumDefName;
|
String enumDefName;
|
||||||
if(ctx.NAME() != null) {
|
if(ctx.NAME() != null) {
|
||||||
enumDefName = ctx.NAME().getText();
|
enumDefName = ctx.NAME().getText();
|
||||||
@ -1227,6 +1228,9 @@ public class Pass0GenerateStatementSequence extends KickCBaseVisitor<Object> {
|
|||||||
parentScope.add(new ConstantVar(member.getLocalName(), parentScope, SymbolType.BYTE, member.getValue()));
|
parentScope.add(new ConstantVar(member.getLocalName(), parentScope, SymbolType.BYTE, member.getValue()));
|
||||||
}
|
}
|
||||||
return SymbolType.BYTE;
|
return SymbolType.BYTE;
|
||||||
|
} catch (CompileError e) {
|
||||||
|
throw new CompileError(e.getMessage(), new StatementSource(ctx));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -35,6 +35,21 @@ public class TestPrograms {
|
|||||||
public TestPrograms() {
|
public TestPrograms() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testEnumErr2() throws IOException, URISyntaxException {
|
||||||
|
assertError("enum-err-2", "Enum value not constant");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testEnumErr1() throws IOException, URISyntaxException {
|
||||||
|
assertError("enum-err-1", "Symbol already declared");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testEnumErr0() throws IOException, URISyntaxException {
|
||||||
|
assertError("enum-err-0", "Symbol already declared");
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testEnum8() throws IOException, URISyntaxException {
|
public void testEnum8() throws IOException, URISyntaxException {
|
||||||
compileAndCompare("enum-8");
|
compileAndCompare("enum-8");
|
||||||
|
15
src/test/kc/enum-err-0.kc
Normal file
15
src/test/kc/enum-err-0.kc
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
// Test of simple enum error - name already used
|
||||||
|
|
||||||
|
byte ON = 17;
|
||||||
|
|
||||||
|
enum State {
|
||||||
|
OFF,
|
||||||
|
ON
|
||||||
|
};
|
||||||
|
|
||||||
|
void main() {
|
||||||
|
enum State state = ON;
|
||||||
|
const byte* SCREEN = 0x0400;
|
||||||
|
*SCREEN = state;
|
||||||
|
}
|
||||||
|
|
14
src/test/kc/enum-err-1.kc
Normal file
14
src/test/kc/enum-err-1.kc
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
// Test of simple enum error - name already used
|
||||||
|
|
||||||
|
enum State {
|
||||||
|
OFF,
|
||||||
|
ON,
|
||||||
|
OFF
|
||||||
|
};
|
||||||
|
|
||||||
|
void main() {
|
||||||
|
enum State state = ON;
|
||||||
|
const byte* SCREEN = 0x0400;
|
||||||
|
*SCREEN = state;
|
||||||
|
}
|
||||||
|
|
15
src/test/kc/enum-err-2.kc
Normal file
15
src/test/kc/enum-err-2.kc
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
// Test of simple enum error - name already used
|
||||||
|
|
||||||
|
byte val;
|
||||||
|
|
||||||
|
enum State {
|
||||||
|
OFF,
|
||||||
|
ON = val
|
||||||
|
};
|
||||||
|
|
||||||
|
void main() {
|
||||||
|
enum State state = ON;
|
||||||
|
const byte* SCREEN = 0x0400;
|
||||||
|
*SCREEN = state;
|
||||||
|
}
|
||||||
|
|
Loading…
x
Reference in New Issue
Block a user