mirror of
https://github.com/JonathanFleischmann/CompilerULTIMATE.git
synced 2024-12-27 09:08:04 +00:00
Updated the TypedFieldVarAccess
This commit is contained in:
parent
bac72bdc81
commit
0215d38aa1
@ -117,6 +117,23 @@ public class TypedClass implements TypedNode {
|
||||
return null;
|
||||
}
|
||||
|
||||
public boolean isMethodOfCurrentClass(String methodName) {
|
||||
for (TypedMethod m : typedMethods) {
|
||||
if (m.getName().equals(methodName)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
public Type getMethodType(String methodName) {
|
||||
for (TypedMethod m : typedMethods) {
|
||||
if (m.getName().equals(methodName)) {
|
||||
return m.getReturnType();
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public Type getParameterTypeInCurrentConstructor(String parameterName) {
|
||||
for (TypedParameter p : currentConstructor.getTypedParameters()) {
|
||||
if (p.getParaName().equals(parameterName)) {
|
||||
|
@ -32,17 +32,20 @@ public class TypedFieldVarAccess implements TypedExpression {
|
||||
@Override
|
||||
public Type typeCheck(TypedProgram typedProgram) {
|
||||
if (field) {
|
||||
type = checkFieldType(typedProgram);
|
||||
type = checkFieldOrMethodType(typedProgram);
|
||||
return type;
|
||||
} else {
|
||||
type = checkVariableType(typedProgram);
|
||||
return type;
|
||||
}
|
||||
}
|
||||
private Type checkFieldType(TypedProgram typedProgram) {
|
||||
private Type checkFieldOrMethodType(TypedProgram typedProgram) {
|
||||
if (typedProgram.getCurrentClass().isThereField(name)) {
|
||||
type = typedProgram.getCurrentClass().getFieldType(name);
|
||||
return type;
|
||||
} else if(typedProgram.getCurrentClass().isMethodOfCurrentClass(name)) {
|
||||
type = typedProgram.getCurrentClass().getMethodType(name);
|
||||
return type;
|
||||
} else if (recursiveOwnerChain instanceof TypedFieldVarAccess typedFieldVarAccess) {
|
||||
type = typedProgram.getCurrentClass().getFieldType(typedFieldVarAccess.getName());
|
||||
return type;
|
||||
@ -66,7 +69,7 @@ public class TypedFieldVarAccess implements TypedExpression {
|
||||
} else if (typedProgram.getCurrentClass().getCurrentConstructor().isLocalVariablePresent(name)) {
|
||||
type = typedProgram.getCurrentClass().getCurrentConstructor().getLocalVariableType(name);
|
||||
} else {
|
||||
return checkFieldOrRecursiveType(typedProgram);
|
||||
return checkFieldOrMethodOrRecursiveType(typedProgram);
|
||||
}
|
||||
return type;
|
||||
}
|
||||
@ -77,15 +80,18 @@ public class TypedFieldVarAccess implements TypedExpression {
|
||||
} else if (typedProgram.getCurrentClass().getCurrentMethod().isLocalVariablePresent(name)) {
|
||||
type = typedProgram.getCurrentClass().getCurrentMethod().getLocalVariableType(name);
|
||||
} else {
|
||||
return checkFieldOrRecursiveType(typedProgram);
|
||||
return checkFieldOrMethodOrRecursiveType(typedProgram);
|
||||
}
|
||||
return type;
|
||||
}
|
||||
|
||||
private Type checkFieldOrRecursiveType(TypedProgram typedProgram) {
|
||||
private Type checkFieldOrMethodOrRecursiveType(TypedProgram typedProgram) {
|
||||
if (typedProgram.getCurrentClass().isThereField(name)) {
|
||||
type = typedProgram.getCurrentClass().getFieldType(name);
|
||||
} else if (recursiveOwnerChain instanceof TypedFieldVarAccess typedFieldVarAccess) {
|
||||
}else if(typedProgram.getCurrentClass().isMethodOfCurrentClass(name)) {
|
||||
type = typedProgram.getCurrentClass().getMethodType(name);
|
||||
}
|
||||
else if (recursiveOwnerChain instanceof TypedFieldVarAccess typedFieldVarAccess) {
|
||||
type = typedProgram.getCurrentClass().getFieldType(typedFieldVarAccess.getName());
|
||||
} else {
|
||||
throw new RuntimeException("Variable " + name + " not declared");
|
||||
|
Loading…
Reference in New Issue
Block a user