mirror of
https://github.com/JonathanFleischmann/CompilerULTIMATE.git
synced 2024-12-28 16:28:04 +00:00
Refactored typed classes
This commit is contained in:
parent
0215d38aa1
commit
5fe0098062
@ -10,10 +10,6 @@ import lombok.Data;
|
|||||||
public class TypedBreak implements TypedStatement {
|
public class TypedBreak implements TypedStatement {
|
||||||
private Type type = Type.VOID;
|
private Type type = Type.VOID;
|
||||||
|
|
||||||
public TypedBreak convertToTypedBreak(TypedClass clas, Break unTypedBreak) {
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Type typeCheck(TypedProgram typedProgram) {
|
public Type typeCheck(TypedProgram typedProgram) {
|
||||||
return type;
|
return type;
|
||||||
|
@ -125,6 +125,7 @@ public class TypedClass implements TypedNode {
|
|||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Type getMethodType(String methodName) {
|
public Type getMethodType(String methodName) {
|
||||||
for (TypedMethod m : typedMethods) {
|
for (TypedMethod m : typedMethods) {
|
||||||
if (m.getName().equals(methodName)) {
|
if (m.getName().equals(methodName)) {
|
||||||
|
@ -66,6 +66,7 @@ public class TypedConstructor implements TypedNode {
|
|||||||
throw new RuntimeException("Parameter " + paraName + " already exists");
|
throw new RuntimeException("Parameter " + paraName + " already exists");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void convertToBlock(TypedProgram typedProgram, Constructor unTypedConstructor) {
|
public void convertToBlock(TypedProgram typedProgram, Constructor unTypedConstructor) {
|
||||||
this.typedBlock = new TypedBlock(typedProgram, unTypedConstructor.block());
|
this.typedBlock = new TypedBlock(typedProgram, unTypedConstructor.block());
|
||||||
typeCheck(typedProgram);
|
typeCheck(typedProgram);
|
||||||
|
@ -39,6 +39,7 @@ public class TypedFieldVarAccess implements TypedExpression {
|
|||||||
return type;
|
return type;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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);
|
type = typedProgram.getCurrentClass().getFieldType(name);
|
||||||
@ -53,6 +54,7 @@ public class TypedFieldVarAccess implements TypedExpression {
|
|||||||
throw new RuntimeException("Field " + name + " not declared");
|
throw new RuntimeException("Field " + name + " not declared");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private Type checkVariableType(TypedProgram typedProgram) {
|
private Type checkVariableType(TypedProgram typedProgram) {
|
||||||
if (typedProgram.getCurrentClass().isCurrentConstructorPresent()) {
|
if (typedProgram.getCurrentClass().isCurrentConstructorPresent()) {
|
||||||
return checkConstructorVariableType(typedProgram);
|
return checkConstructorVariableType(typedProgram);
|
||||||
@ -90,8 +92,7 @@ public class TypedFieldVarAccess implements TypedExpression {
|
|||||||
type = typedProgram.getCurrentClass().getFieldType(name);
|
type = typedProgram.getCurrentClass().getFieldType(name);
|
||||||
} else if (typedProgram.getCurrentClass().isMethodOfCurrentClass(name)) {
|
} else if (typedProgram.getCurrentClass().isMethodOfCurrentClass(name)) {
|
||||||
type = typedProgram.getCurrentClass().getMethodType(name);
|
type = typedProgram.getCurrentClass().getMethodType(name);
|
||||||
}
|
} else if (recursiveOwnerChain instanceof TypedFieldVarAccess typedFieldVarAccess) {
|
||||||
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");
|
||||||
|
@ -40,6 +40,7 @@ public class TypedMethod implements TypedNode {
|
|||||||
}, () -> {
|
}, () -> {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public void checkIfParameterExists(String parameterName) {
|
public void checkIfParameterExists(String parameterName) {
|
||||||
if (typedParameters.stream().anyMatch(parameter -> parameter.getParaName().equals(parameterName))) {
|
if (typedParameters.stream().anyMatch(parameter -> parameter.getParaName().equals(parameterName))) {
|
||||||
throw new RuntimeException("Parameter " + parameterName + " already exists");
|
throw new RuntimeException("Parameter " + parameterName + " already exists");
|
||||||
|
@ -43,6 +43,7 @@ public class TypedProgram {
|
|||||||
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();
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isTypedClassPresent(String className) {
|
public boolean isTypedClassPresent(String className) {
|
||||||
return typedClasses.stream().anyMatch(clas -> clas.getClassName().equals(className));
|
return typedClasses.stream().anyMatch(clas -> clas.getClassName().equals(className));
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user