mirror of
https://github.com/JonathanFleischmann/CompilerULTIMATE.git
synced 2024-12-28 00:58:04 +00:00
Added check for field of other classes
This commit is contained in:
parent
878794ffa7
commit
e6e5433a91
@ -49,12 +49,20 @@ public class TypedFieldVarAccess implements TypedExpression {
|
|||||||
|
|
||||||
private Type checkFieldOrMethodType(TypedProgram typedProgram) {
|
private Type checkFieldOrMethodType(TypedProgram typedProgram) {
|
||||||
if (typedProgram.getCurrentClass().isThereField(name)) {
|
if (typedProgram.getCurrentClass().isThereField(name)) {
|
||||||
type = typedProgram.getCurrentClass().getFieldType(name);
|
return checkTypeField(typedProgram);
|
||||||
return type;
|
|
||||||
} else if (typedProgram.getCurrentClass().isMethodOfCurrentClass(name)) {
|
} else if (typedProgram.getCurrentClass().isMethodOfCurrentClass(name)) {
|
||||||
type = typedProgram.getCurrentClass().getMethodType(name);
|
type = typedProgram.getCurrentClass().getMethodType(name);
|
||||||
return type;
|
return type;
|
||||||
} else if (recursiveOwnerChain instanceof TypedFieldVarAccess typedFieldVarAccess) {
|
} else if (recursiveOwnerChain instanceof TypedFieldVarAccess typedFieldVarAccess) {
|
||||||
|
|
||||||
|
if (typedProgram.isClassWithNamePresent(recursiveOwnerChain.getType().getReference())) {
|
||||||
|
Type typeofFieldNameInClass = typedProgram.getTypeOfFieldNameInClass(recursiveOwnerChain.getType().getReference(), name);
|
||||||
|
if(typeofFieldNameInClass != null){
|
||||||
|
return typeofFieldNameInClass;
|
||||||
|
}else{
|
||||||
|
throw new RuntimeException("Field " + name + " not declared in class " + recursiveOwnerChain.getType().getReference());
|
||||||
|
}
|
||||||
|
}
|
||||||
type = typedProgram.getCurrentClass().getFieldType(typedFieldVarAccess.getName());
|
type = typedProgram.getCurrentClass().getFieldType(typedFieldVarAccess.getName());
|
||||||
return type;
|
return type;
|
||||||
} else {
|
} else {
|
||||||
@ -106,7 +114,15 @@ public class TypedFieldVarAccess implements TypedExpression {
|
|||||||
}
|
}
|
||||||
return type;
|
return type;
|
||||||
}
|
}
|
||||||
|
private Type checkTypeField(TypedProgram typedProgram) {
|
||||||
|
if (recursiveOwnerChain != null) {
|
||||||
|
if (recursiveOwnerChain.getType() != null) {
|
||||||
|
return typedProgram.getTypeOfFieldNameInClass(recursiveOwnerChain.getType().getReference(), name);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
type = typedProgram.getCurrentClass().getFieldType(name);
|
||||||
|
return type;
|
||||||
|
}
|
||||||
@Override
|
@Override
|
||||||
public void codeGen(MethodContext ctx) {
|
public void codeGen(MethodContext ctx) {
|
||||||
if (recursiveOwnerChain != null) {
|
if (recursiveOwnerChain != null) {
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package de.maishai.typedast.typedclass;
|
package de.maishai.typedast.typedclass;
|
||||||
|
|
||||||
import de.maishai.ast.records.Program;
|
import de.maishai.ast.records.Program;
|
||||||
|
import de.maishai.typedast.Type;
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
|
|
||||||
@ -43,6 +44,12 @@ public class TypedProgram {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean isClassWithNamePresent(String className) {
|
||||||
|
return typedClasses.stream().anyMatch(clas -> clas.getClassName().equals(className));
|
||||||
|
}
|
||||||
|
public Type getTypeOfFieldNameInClass(String className, String fieldName) {
|
||||||
|
return typedClasses.stream().filter(clas -> clas.getClassName().equals(className)).findFirst().get().getFieldType(fieldName);
|
||||||
|
}
|
||||||
public TypedClass getTypedClass(String className) {
|
public TypedClass getTypedClass(String className) {
|
||||||
return typedClasses.stream().filter(clas -> clas.getClassName().equals(className)).findFirst().get();
|
return typedClasses.stream().filter(clas -> clas.getClassName().equals(className)).findFirst().get();
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user