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