mirror of
https://github.com/JonathanFleischmann/CompilerULTIMATE.git
synced 2024-12-28 01:38:03 +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;
|
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) {
|
public Type getParameterTypeInCurrentConstructor(String parameterName) {
|
||||||
for (TypedParameter p : currentConstructor.getTypedParameters()) {
|
for (TypedParameter p : currentConstructor.getTypedParameters()) {
|
||||||
if (p.getParaName().equals(parameterName)) {
|
if (p.getParaName().equals(parameterName)) {
|
||||||
|
@ -32,17 +32,20 @@ public class TypedFieldVarAccess implements TypedExpression {
|
|||||||
@Override
|
@Override
|
||||||
public Type typeCheck(TypedProgram typedProgram) {
|
public Type typeCheck(TypedProgram typedProgram) {
|
||||||
if (field) {
|
if (field) {
|
||||||
type = checkFieldType(typedProgram);
|
type = checkFieldOrMethodType(typedProgram);
|
||||||
return type;
|
return type;
|
||||||
} else {
|
} else {
|
||||||
type = checkVariableType(typedProgram);
|
type = checkVariableType(typedProgram);
|
||||||
return type;
|
return type;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
private Type checkFieldType(TypedProgram typedProgram) {
|
private Type checkFieldOrMethodType(TypedProgram typedProgram) {
|
||||||
if (typedProgram.getCurrentClass().isThereField(name)) {
|
if (typedProgram.getCurrentClass().isThereField(name)) {
|
||||||
type = typedProgram.getCurrentClass().getFieldType(name);
|
type = typedProgram.getCurrentClass().getFieldType(name);
|
||||||
return type;
|
return type;
|
||||||
|
} else if(typedProgram.getCurrentClass().isMethodOfCurrentClass(name)) {
|
||||||
|
type = typedProgram.getCurrentClass().getMethodType(name);
|
||||||
|
return type;
|
||||||
} else if (recursiveOwnerChain instanceof TypedFieldVarAccess typedFieldVarAccess) {
|
} else if (recursiveOwnerChain instanceof TypedFieldVarAccess typedFieldVarAccess) {
|
||||||
type = typedProgram.getCurrentClass().getFieldType(typedFieldVarAccess.getName());
|
type = typedProgram.getCurrentClass().getFieldType(typedFieldVarAccess.getName());
|
||||||
return type;
|
return type;
|
||||||
@ -66,7 +69,7 @@ public class TypedFieldVarAccess implements TypedExpression {
|
|||||||
} else if (typedProgram.getCurrentClass().getCurrentConstructor().isLocalVariablePresent(name)) {
|
} else if (typedProgram.getCurrentClass().getCurrentConstructor().isLocalVariablePresent(name)) {
|
||||||
type = typedProgram.getCurrentClass().getCurrentConstructor().getLocalVariableType(name);
|
type = typedProgram.getCurrentClass().getCurrentConstructor().getLocalVariableType(name);
|
||||||
} else {
|
} else {
|
||||||
return checkFieldOrRecursiveType(typedProgram);
|
return checkFieldOrMethodOrRecursiveType(typedProgram);
|
||||||
}
|
}
|
||||||
return type;
|
return type;
|
||||||
}
|
}
|
||||||
@ -77,15 +80,18 @@ public class TypedFieldVarAccess implements TypedExpression {
|
|||||||
} else if (typedProgram.getCurrentClass().getCurrentMethod().isLocalVariablePresent(name)) {
|
} else if (typedProgram.getCurrentClass().getCurrentMethod().isLocalVariablePresent(name)) {
|
||||||
type = typedProgram.getCurrentClass().getCurrentMethod().getLocalVariableType(name);
|
type = typedProgram.getCurrentClass().getCurrentMethod().getLocalVariableType(name);
|
||||||
} else {
|
} else {
|
||||||
return checkFieldOrRecursiveType(typedProgram);
|
return checkFieldOrMethodOrRecursiveType(typedProgram);
|
||||||
}
|
}
|
||||||
return type;
|
return type;
|
||||||
}
|
}
|
||||||
|
|
||||||
private Type checkFieldOrRecursiveType(TypedProgram typedProgram) {
|
private Type checkFieldOrMethodOrRecursiveType(TypedProgram typedProgram) {
|
||||||
if (typedProgram.getCurrentClass().isThereField(name)) {
|
if (typedProgram.getCurrentClass().isThereField(name)) {
|
||||||
type = typedProgram.getCurrentClass().getFieldType(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());
|
type = typedProgram.getCurrentClass().getFieldType(typedFieldVarAccess.getName());
|
||||||
} else {
|
} else {
|
||||||
throw new RuntimeException("Variable " + name + " not declared");
|
throw new RuntimeException("Variable " + name + " not declared");
|
||||||
|
Loading…
Reference in New Issue
Block a user