mirror of
https://gitlab.com/camelot/kickc.git
synced 2024-12-28 16:31:36 +00:00
Merge branch 'master' into stripping_to_string_outputs_for_statetments
This commit is contained in:
commit
cee9bbb3f7
@ -6,6 +6,8 @@ import dk.camelot64.kickc.model.Program;
|
||||
import dk.camelot64.kickc.model.statements.Statement;
|
||||
import dk.camelot64.kickc.model.statements.StatementCall;
|
||||
import dk.camelot64.kickc.model.symbols.Procedure;
|
||||
import dk.camelot64.kickc.model.symbols.Scope;
|
||||
import dk.camelot64.kickc.model.symbols.Symbol;
|
||||
|
||||
/**
|
||||
* Updates procedure calls to point to the actual procedure called.
|
||||
@ -23,10 +25,13 @@ public class Pass1Procedures extends Pass2SsaOptimization {
|
||||
if(statement instanceof StatementCall) {
|
||||
StatementCall call = (StatementCall) statement;
|
||||
String procedureName = call.getProcedureName();
|
||||
Procedure procedure = getScope().getLocalProcedure(procedureName);
|
||||
if(procedure == null) {
|
||||
throw new CompileError("Called procedure not found. " + call.toString(getProgram(), false), statement.getSource());
|
||||
}
|
||||
Scope localScope = (Scope) getScope().getSymbol(block.getScope());
|
||||
final Symbol procedureSymbol = localScope.findSymbol(procedureName);
|
||||
if(procedureSymbol == null)
|
||||
throw new CompileError("Called procedure not found. " + procedureName, statement.getSource());
|
||||
if(!(procedureSymbol instanceof Procedure))
|
||||
throw new CompileError("Called symbol is not a procedure. " + procedureSymbol.toString(), statement.getSource());
|
||||
Procedure procedure = (Procedure) procedureSymbol;
|
||||
call.setProcedure(procedure.getRef());
|
||||
if(procedure.isVariableLengthParameterList() && procedure.getParameters().size() > call.getParameters().size()) {
|
||||
throw new CompileError("Wrong number of parameters in call. Expected " + procedure.getParameters().size() + " or more. " + statement.toString(), statement.getSource());
|
||||
|
@ -42,6 +42,11 @@ public class TestPrograms {
|
||||
public TestPrograms() {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLocalVarShadowingProcedure() throws IOException, URISyntaxException {
|
||||
assertError("local-var-shadowing-procedure.c", "Called symbol is not a procedure. main::doit");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAdventOfCode04() throws IOException, URISyntaxException {
|
||||
compileAndCompare("adventofcode/2020-04.c");
|
||||
|
12
src/test/kc/local-var-shadowing-procedure.c
Normal file
12
src/test/kc/local-var-shadowing-procedure.c
Normal file
@ -0,0 +1,12 @@
|
||||
// Demonstrate that local variable shadowing a global procedure causes an error
|
||||
|
||||
void main() {
|
||||
char doit = 7;
|
||||
doit();
|
||||
}
|
||||
|
||||
char * const SCREEN = 0x0400;
|
||||
|
||||
void doit() {
|
||||
SCREEN[0] = '*';
|
||||
}
|
Loading…
Reference in New Issue
Block a user