1
0
mirror of https://gitlab.com/camelot/kickc.git synced 2025-02-16 18:30:37 +00:00

Added two struct value error tests.

This commit is contained in:
Jesper Gravgaard 2019-06-07 13:46:36 +02:00
parent 0dcd739507
commit d58c46e46f
5 changed files with 44 additions and 5 deletions

View File

@ -463,7 +463,8 @@ public class Pass0GenerateStatementSequence extends KickCBaseVisitor<Object> {
@Override
public Object visitDeclTypes(KickCParser.DeclTypesContext ctx) {
List<KickCParser.DirectiveContext> directive = ctx.directive();
this.declVarType = (SymbolType) visit(ctx.typeDecl());
SymbolType varType = (SymbolType) visit(ctx.typeDecl());
this.declVarType = varType;
this.declVarDirectives = getDirectives(directive);
this.declVarComments = getCommentsSymbol(ctx.getParent());
return null;
@ -1195,6 +1196,9 @@ public class Pass0GenerateStatementSequence extends KickCBaseVisitor<Object> {
public Object visitStructRef(KickCParser.StructRefContext ctx) {
String structDefName = ctx.NAME().getText();
StructDefinition structDefinition = getCurrentScope().getStructDefinition(structDefName);
if(structDefinition==null) {
throw new CompileError("Unknown struct type "+structDefName, new StatementSource(ctx));
}
return structDefinition.getType();
}

View File

@ -1,9 +1,7 @@
package dk.camelot64.kickc.passes;
import dk.camelot64.kickc.model.Comment;
import dk.camelot64.kickc.model.ControlFlowBlock;
import dk.camelot64.kickc.model.*;
import dk.camelot64.kickc.model.InternalError;
import dk.camelot64.kickc.model.Program;
import dk.camelot64.kickc.model.iterator.ProgramValueIterator;
import dk.camelot64.kickc.model.statements.Statement;
import dk.camelot64.kickc.model.statements.StatementAssignment;
@ -120,7 +118,7 @@ public class Pass1UnwindStructValues extends Pass1Base {
stmtIt.remove();
}
} else {
throw new RuntimeException("Struct assignment not implemented yet " + statement.toString(getProgram(), false));
throw new CompileError("Incompatible struct assignment " + statement.toString(getProgram(), false), statement);
}
}
}

View File

@ -50,7 +50,15 @@ public class TestPrograms {
compileAndCompare("struct-ptr-0", log());
}
@Test
public void testError1() throws IOException, URISyntaxException {
assertError("struct-err-1", "Incompatible struct assignment");
}
@Test
public void testError0() throws IOException, URISyntaxException {
assertError("struct-err-0", "Unknown struct type");
}
@Test
public void testStruct5() throws IOException, URISyntaxException {

View File

@ -0,0 +1,6 @@
// Undeclared struct
void main() {
struct Point p1;
}

View File

@ -0,0 +1,23 @@
// Incompatible struct assignment
struct Point1 {
byte x;
byte y;
};
struct Point2 {
byte x;
byte y;
};
void main() {
struct Point1 p1;
struct Point2 p2;
p1.x = 4;
p2 = p1;
const byte* SCREEN = 0x0400;
SCREEN[0] = p2.x;
SCREEN[0] = p2.y;
}