Fixing bugs

This commit is contained in:
ahmad 2024-07-05 00:41:10 +02:00
parent b0ee9781ab
commit 8a2b54d3f4
3 changed files with 16 additions and 2 deletions

View File

@ -53,7 +53,8 @@ public class TypedBinary implements TypedExpression {
throw new RuntimeException("Type mismatch in " + op);
}
} else if (op == Operator.EQ || op == Operator.NE ) {
if (leftType == Type.INT && rightType == Type.INT || leftType == Type.BOOL && rightType == Type.BOOL) {
if (leftType == Type.INT && rightType == Type.INT || leftType == Type.BOOL && rightType == Type.BOOL
|| leftType == Type.CHAR && rightType == Type.CHAR) {
type = Type.BOOL;
return Type.BOOL;
} else {

View File

@ -58,7 +58,7 @@ public class TypedFieldVarAccess implements TypedExpression {
} else if (recursiveOwnerChain instanceof TypedFieldVarAccess typedFieldVarAccess) {
boolean isClassWithNamePresent = typedProgram.isClassWithNamePresent(recursiveOwnerChain.getType().getReference());
if (isClassWithNamePresent) {
Type typeofFieldNameInClass = typedProgram.getTypeOfFieldNameInClass(recursiveOwnerChain.getType().getReference(), name);
Type typeofFieldNameInClass = typedProgram.getTypeOfFieldOrMethodNameInClass(recursiveOwnerChain.getType().getReference(), name);
if (typeofFieldNameInClass != null) {
return typeofFieldNameInClass;
} else {

View File

@ -51,6 +51,19 @@ public class TypedProgram {
public Type getTypeOfFieldNameInClass(String className, String fieldName) {
return typedClasses.stream().filter(clas -> clas.getClassName().equals(className)).findFirst().get().getFieldType(fieldName);
}
public Type getTypeOfFieldOrMethodNameInClass(String className, String fieldName) {
if(className == null || fieldName == null){
return null;
}
TypedClass c = typedClasses.stream().filter(clas -> clas.getClassName().equals(className)).findFirst().get();
if(c.isThereField(fieldName)){
return c.getFieldType(fieldName);
}else if(c.isMethodOfCurrentClass(fieldName)){
return c.getMethodType(fieldName);
}
return null;
}
public TypedClass getTypedClass(String className) {
return typedClasses.stream().filter(clas -> clas.getClassName().equals(className)).findFirst().get();