mirror of
https://github.com/JonathanFleischmann/CompilerULTIMATE.git
synced 2024-12-27 09:28:03 +00:00
Add the list of TypedLocalVariable to TypedMethod and implemented the typeCheck
This commit is contained in:
parent
092cbb5af9
commit
ede0b38987
@ -20,8 +20,8 @@ public class TypedMethod implements TypedNode {
|
||||
private String name;
|
||||
private Type returnType;
|
||||
private List<TypedParameter> typedParameters = new ArrayList<>();
|
||||
private TypedBlock typedBlock;
|
||||
private List<TypedLocalVariable> localVariables = new ArrayList<>();
|
||||
private TypedBlock typedBlock;
|
||||
|
||||
public TypedMethod(TypedClass clas, Method unTypedMethod) {
|
||||
convertToTypedMethod(clas, unTypedMethod);
|
||||
@ -40,12 +40,11 @@ public class TypedMethod implements TypedNode {
|
||||
throw new RuntimeException("Method " + name + " already exists");
|
||||
}, () -> {
|
||||
});
|
||||
|
||||
//localVar.put(name, returnType);
|
||||
}
|
||||
|
||||
public void convertToTypedBlock(TypedClass clas, Method unTypedMethod) {
|
||||
typedBlock = new TypedBlock(clas, unTypedMethod.block());
|
||||
typeCheck(clas);
|
||||
}
|
||||
|
||||
public boolean isLocalVariablePresent(String localVarName) {
|
||||
@ -67,13 +66,11 @@ public class TypedMethod implements TypedNode {
|
||||
|
||||
@Override
|
||||
public Type typeCheck(TypedClass clas) {
|
||||
/* if (localVar.containsKey(name)) {
|
||||
throw new RuntimeException("Method " + name + " already exists");
|
||||
if(returnType != Type.VOID){
|
||||
if(typedBlock.typeCheck(clas) != returnType){
|
||||
throw new RuntimeException("Method " + name + " must return " + returnType);
|
||||
}
|
||||
}
|
||||
localVar.put(name, returnType);
|
||||
for (TypedParameter typedParameter : typedParameters) {
|
||||
typedParameter.typeCheck( clas);
|
||||
}*/
|
||||
return returnType;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user