Compare commits
No commits in common. "949c2de28e5483a444008c29a19723265a11f72d" and "d665c0393c17bd01d0725f3cfc03a65fe6bfc1fa" have entirely different histories.
949c2de28e
...
d665c0393c
@ -104,7 +104,6 @@ public class Compiler {
|
||||
// }
|
||||
|
||||
|
||||
abstractSyntaxTree.classes.get(2).methodDecls.get(0).codeBlock.returnType = "int";
|
||||
abstractSyntaxTree.typeCheck();
|
||||
|
||||
abstractSyntaxTree.codeGen();
|
||||
|
@ -6,13 +6,16 @@ class Example {
|
||||
int i;
|
||||
boolean b;
|
||||
char c;
|
||||
void callM(){
|
||||
Example2 example2 = new Example2();
|
||||
example2.m(1);
|
||||
}
|
||||
|
||||
}
|
||||
class Example2 {
|
||||
boolean instVarBool;
|
||||
int m(int n){
|
||||
int localA;
|
||||
int localB;
|
||||
boolean a = this.instVarBool;
|
||||
return n;
|
||||
}
|
||||
}
|
||||
|
@ -36,10 +36,6 @@ public class MethodDecl implements Node {
|
||||
|
||||
public TypeCheckResult typeCheck(HashMap<String, HashMap<String, HashMap<String, ParameterList>>> methodContext, HashMap<String, HashMap<String, String>> typeContext) throws Exception {
|
||||
// jede methode als block statement aufrufen und jede neue locale varibale in localvars schreiben
|
||||
List<Parameter> parametersList = parameters.parameterList;
|
||||
for(Parameter parameter : parametersList){
|
||||
localVars.put(parameter.identifier, parameter.type);
|
||||
}
|
||||
|
||||
TypeCheckResult result = new TypeCheckResult();
|
||||
codeBlock.typeCheck(methodContext, typeContext, localVars);
|
||||
|
@ -9,7 +9,6 @@ import org.objectweb.asm.Opcodes;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Objects;
|
||||
|
||||
public class InstVarExpression implements IExpression{
|
||||
|
||||
|
@ -29,7 +29,7 @@ public class LocalVarIdentifier implements IExpression{
|
||||
if (localVars.containsKey(identifier)) {
|
||||
result.type = localVars.get(identifier);
|
||||
} else {
|
||||
throw new Exception("TypeCheck Exception: Local var " + identifier + " does not exist.");
|
||||
throw new Exception("TypeCheck Exception: local var does not exist");
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
@ -36,16 +36,10 @@ public class BlockStatement extends AbstractType implements IStatement {
|
||||
}
|
||||
|
||||
for (IStatement statement : statements) {
|
||||
|
||||
// todo remove later if there are no null statement any more
|
||||
if (statement != null) {
|
||||
TypeCheckResult typeOfCurrentStatement = statement.typeCheck(methodContext, typeContext, localVars);
|
||||
|
||||
if(statement instanceof LocalVarDecl){
|
||||
LocalVarDecl localVarDecl = (LocalVarDecl) statement;
|
||||
localVars.put(localVarDecl.identifier, localVarDecl.type);
|
||||
}
|
||||
|
||||
if (typeOfCurrentStatement.type.contains(",")) {
|
||||
// else if has 2 returns, all code paths must retrun a value.
|
||||
String[] substrings = typeOfCurrentStatement.type.split(",");
|
||||
@ -55,10 +49,10 @@ public class BlockStatement extends AbstractType implements IStatement {
|
||||
|
||||
if (!firstType.equals(this.returnType) || !firstType.equals(this.returnType)) {
|
||||
if (!firstType.equals("void")) {
|
||||
throw new Exception("TypeCheck Exception: if paths return wrong type");
|
||||
throw new Exception("TypeCeck Exception: if paths return wrong type");
|
||||
}
|
||||
if (!secondType.equals("void")) {
|
||||
throw new Exception("TypeCheck Exception: else paths return wrong type");
|
||||
throw new Exception("TypeCeck Exception: else paths return wrong type");
|
||||
}
|
||||
boolean firstIsVoid = firstType.equals("void");
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user