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:
parent
0dcd739507
commit
d58c46e46f
@ -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();
|
||||
}
|
||||
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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 {
|
||||
|
6
src/test/kc/struct-err-0.kc
Normal file
6
src/test/kc/struct-err-0.kc
Normal file
@ -0,0 +1,6 @@
|
||||
// Undeclared struct
|
||||
|
||||
void main() {
|
||||
struct Point p1;
|
||||
}
|
||||
|
23
src/test/kc/struct-err-1.kc
Normal file
23
src/test/kc/struct-err-1.kc
Normal 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;
|
||||
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user