mirror of
https://github.com/JonathanFleischmann/CompilerULTIMATE.git
synced 2024-12-27 09:28:03 +00:00
Fixed using same parameter in different methods or constructors
This commit is contained in:
parent
3b0649f5cd
commit
878794ffa7
@ -98,37 +98,20 @@ public class TypedClass implements TypedNode {
|
||||
return type;
|
||||
}
|
||||
|
||||
public boolean isParameterWitNameInMethod(String parameterName) {
|
||||
for (TypedMethod m : typedMethods) {
|
||||
for (TypedParameter p : m.getTypedParameters()) {
|
||||
if (p.getParaName().equals(parameterName)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
public boolean isParameterWitNameInCurrentMethod(String parameterName) {
|
||||
return this.getCurrentMethod().getTypedParameters().stream().anyMatch(parameter -> parameter.getParaName().equals(parameterName));
|
||||
}
|
||||
|
||||
public boolean isParameterWitNameInConstructor(String parameterName) {
|
||||
for (TypedConstructor c : typedConstructors) {
|
||||
for (TypedParameter p : c.getTypedParameters()) {
|
||||
if (p.getParaName().equals(parameterName)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
public boolean isParameterWitNameInCurrentConstructor(String parameterName) {
|
||||
return this.getCurrentConstructor().getTypedParameters().stream().anyMatch(parameter -> parameter.getParaName().equals(parameterName));
|
||||
}
|
||||
|
||||
public Type getParameterTypeInCurrentMethod(String parameterName) {
|
||||
for (TypedMethod m : typedMethods) {
|
||||
for (TypedParameter p : m.getTypedParameters()) {
|
||||
if (p.getParaName().equals(parameterName)) {
|
||||
return p.getType();
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
return getCurrentMethod().getTypedParameters().stream().filter(parameter -> parameter.getParaName().equals(parameterName)).findFirst().get().getType();
|
||||
}
|
||||
|
||||
public Type getParameterTypeInCurrentConstructor(String parameterName) {
|
||||
return getCurrentConstructor().getTypedParameters().stream().filter(parameter -> parameter.getParaName().equals(parameterName)).findFirst().get().getType();
|
||||
}
|
||||
|
||||
public boolean isMethodOfCurrentClass(String methodName) {
|
||||
@ -149,15 +132,6 @@ public class TypedClass implements TypedNode {
|
||||
return null;
|
||||
}
|
||||
|
||||
public Type getParameterTypeInCurrentConstructor(String parameterName) {
|
||||
for (TypedParameter p : currentConstructor.getTypedParameters()) {
|
||||
if (p.getParaName().equals(parameterName)) {
|
||||
return p.getType();
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public boolean isThereField(String fieldName) {
|
||||
for (TypedDeclaration f : typedDeclarations) {
|
||||
if (f.getName().equals(fieldName)) {
|
||||
|
@ -84,7 +84,7 @@ public class TypedFieldVarAccess implements TypedExpression {
|
||||
}
|
||||
|
||||
private Type checkMethodVariableType(TypedProgram typedProgram) {
|
||||
if (typedProgram.getCurrentClass().isParameterWitNameInMethod(name)) {
|
||||
if (typedProgram.getCurrentClass().isParameterWitNameInCurrentMethod(name)) {
|
||||
type = typedProgram.getCurrentClass().getParameterTypeInCurrentMethod(name);
|
||||
} else if (typedProgram.getCurrentClass().getCurrentMethod().isLocalVariablePresent(name)) {
|
||||
type = typedProgram.getCurrentClass().getCurrentMethod().getLocalVariableType(name);
|
||||
|
@ -52,6 +52,7 @@ public class TypedMethod implements TypedNode {
|
||||
public void convertToTypedBlock(TypedProgram typedProgram, Method unTypedMethod) {
|
||||
typedBlock = new TypedBlock(typedProgram, unTypedMethod.block());
|
||||
typeCheck(typedProgram);
|
||||
localVariables.clear();
|
||||
}
|
||||
|
||||
public boolean isLocalVariablePresent(String localVarName) {
|
||||
|
@ -35,11 +35,11 @@ public class TypedParameter implements TypedNode {
|
||||
public Type typeCheck(TypedProgram typedProgram) {
|
||||
|
||||
if (typedProgram.getCurrentClass().isCurrentMethodPresent()) {
|
||||
if (typedProgram.getCurrentClass().isParameterWitNameInMethod(paraName)) {
|
||||
if (typedProgram.getCurrentClass().isParameterWitNameInCurrentMethod(paraName)) {
|
||||
throw new RuntimeException("Parameter " + paraName + " already exists");
|
||||
}
|
||||
} else if (typedProgram.getCurrentClass().isCurrentConstructorPresent()) {
|
||||
if (typedProgram.getCurrentClass().isParameterWitNameInConstructor(paraName)) {
|
||||
if (typedProgram.getCurrentClass().isParameterWitNameInCurrentConstructor(paraName)) {
|
||||
throw new RuntimeException("Parameter " + paraName + " already exists");
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user