Compare commits
3 Commits
d5b526b8fc
...
94b3830561
Author | SHA1 | Date | |
---|---|---|---|
|
94b3830561 | ||
|
3dcaad62f9 | ||
|
62060462a9 |
@ -100,6 +100,6 @@ public class Compiler {
|
|||||||
System.out.println("No TypeCheck errors found.");
|
System.out.println("No TypeCheck errors found.");
|
||||||
|
|
||||||
abstractSyntaxTree.codeGen();
|
abstractSyntaxTree.codeGen();
|
||||||
System.out.println("Your input was compiler. You can find the output at ???");// todo wo output? überhaupt hinschreiben?
|
System.out.println("Your input was compiled. You can find the output at ???");// todo wo output? überhaupt hinschreiben?
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -5,6 +5,7 @@ class TestClass {
|
|||||||
public TestClass(){i = 3456;}
|
public TestClass(){i = 3456;}
|
||||||
int meth(int n){
|
int meth(int n){
|
||||||
Example e = new Example();
|
Example e = new Example();
|
||||||
|
e.example1 = new TestClass();
|
||||||
int abc = e.example1.m1(2).m2().m3();
|
int abc = e.example1.m1(2).m2().m3();
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -8,17 +8,18 @@ public class TypeCheckHelper {
|
|||||||
boolean type1Primitiv = Objects.equals(type1, "boolean") || Objects.equals(type1, "int") || Objects.equals(type1, "char");
|
boolean type1Primitiv = Objects.equals(type1, "boolean") || Objects.equals(type1, "int") || Objects.equals(type1, "char");
|
||||||
boolean type2Primitiv = Objects.equals(type2, "boolean") || Objects.equals(type2, "int") || Objects.equals(type2, "char");
|
boolean type2Primitiv = Objects.equals(type2, "boolean") || Objects.equals(type2, "int") || Objects.equals(type2, "char");
|
||||||
|
|
||||||
String result;
|
String result = "class";
|
||||||
if(type1Primitiv && type2Primitiv){
|
if(type1Primitiv && type2Primitiv){
|
||||||
if(Objects.equals(type1, type2)){
|
if(Objects.equals(type1, type2)){
|
||||||
result = type1;
|
result = type1;
|
||||||
}else{
|
}else{
|
||||||
throw new TypeCheckException("There is no upper bound between " + type1 + " and " + type2 + ".");
|
throw new TypeCheckException("There is no upper bound between " + type1 + " and " + type2 + ".");
|
||||||
}
|
}
|
||||||
}else if(type1Primitiv || type2Primitiv){
|
}else if(type1Primitiv ^ type2Primitiv){
|
||||||
throw new TypeCheckException("There is no upper bound between " + type1 + " and " + type2 + ".");
|
throw new TypeCheckException("There is no upper bound between " + type1 + " and " + type2 + ".");
|
||||||
}else{
|
}else{
|
||||||
result = "class";
|
if(Objects.equals(type1, type2))
|
||||||
|
result = type1;
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
@ -31,6 +31,10 @@ public class InstVarExpression extends AbstractType implements IExpression{
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public TypeCheckResult typeCheck(HashMap<String, HashMap<String, HashMap<String, ParameterList>>> methodContext, HashMap<String, HashMap<String, String>> typeContext, HashMap<String, String> localVars) throws TypeCheckException {
|
public TypeCheckResult typeCheck(HashMap<String, HashMap<String, HashMap<String, ParameterList>>> methodContext, HashMap<String, HashMap<String, String>> typeContext, HashMap<String, String> localVars) throws TypeCheckException {
|
||||||
|
if(this.receivers.get(0).identifier != null){
|
||||||
|
thisClass = localVars.get(this.receivers.get(0).identifier);
|
||||||
|
}
|
||||||
|
|
||||||
String varType = typeContext.get(thisClass).get(fieldName);
|
String varType = typeContext.get(thisClass).get(fieldName);
|
||||||
if (varType == null) {
|
if (varType == null) {
|
||||||
throw new TypeCheckException("Field " + fieldName + " was not found in class " + thisClass + ".");
|
throw new TypeCheckException("Field " + fieldName + " was not found in class " + thisClass + ".");
|
||||||
|
@ -45,6 +45,8 @@ public class AssignStatementExpression extends AbstractType implements IExpressi
|
|||||||
leftType.type = typeContext.get(thisClass).get(identifier);
|
leftType.type = typeContext.get(thisClass).get(identifier);
|
||||||
}
|
}
|
||||||
}else{
|
}else{
|
||||||
|
if(left instanceof InstVarExpression instVarExpression)
|
||||||
|
instVarExpression.thisClass = this.thisClass;
|
||||||
leftType = left.typeCheck(methodContext, typeContext, localVars);
|
leftType = left.typeCheck(methodContext, typeContext, localVars);
|
||||||
}
|
}
|
||||||
TypeCheckResult rightType = right.typeCheck(methodContext, typeContext, localVars);
|
TypeCheckResult rightType = right.typeCheck(methodContext, typeContext, localVars);
|
||||||
|
Loading…
Reference in New Issue
Block a user