mirror of
https://github.com/JonathanFleischmann/CompilerULTIMATE.git
synced 2024-12-27 09:28:03 +00:00
Add Type to TypedConstructor
This commit is contained in:
parent
17601da0a7
commit
ecb9abdf6b
@ -25,8 +25,12 @@ public class TypedConstructor implements TypedNode {
|
||||
private String name;
|
||||
private List<TypedParameter> typedParameters = new ArrayList<>();
|
||||
private TypedBlock typedBlock;
|
||||
//TODO: add Type
|
||||
|
||||
private Type type;
|
||||
public TypedConstructor(String name, List<TypedParameter> typedParameters, TypedBlock typedBlock) {
|
||||
this.name = name;
|
||||
this.typedParameters = typedParameters;
|
||||
this.typedBlock = typedBlock;
|
||||
}
|
||||
public TypedConstructor(Map<String, Type> localVar, TypedClass clas, Constructor unTypedConstructor) {
|
||||
convertToTypedConstructor(localVar, clas, unTypedConstructor);
|
||||
}
|
||||
@ -37,6 +41,8 @@ public class TypedConstructor implements TypedNode {
|
||||
for (Parameter param : unTypedConstructor.params()) {
|
||||
typedParameters.add(new TypedParameter(localVar, clas, param));
|
||||
}
|
||||
// Konstrukteur hat den Rückgabetyp wie der Klassenname, obwohl es keinen expliziten Rückgabetyp gibt
|
||||
type = clas.getType();
|
||||
|
||||
}
|
||||
public void convertToBlock(Map<String, Type> localVar, TypedClass clas, Constructor unTypedConstructor) {
|
||||
@ -45,17 +51,7 @@ public class TypedConstructor implements TypedNode {
|
||||
|
||||
@Override
|
||||
public Type typeCheck(Map<String, Type> localVar, TypedClass clas) {
|
||||
if (localVar.containsKey(name)) {
|
||||
throw new RuntimeException("constructor already declared");
|
||||
}
|
||||
localVar.put(name, Type.VOID);
|
||||
if (typedParameters != null) {
|
||||
for (TypedParameter param : typedParameters) {
|
||||
param.typeCheck(localVar, clas);
|
||||
}
|
||||
}
|
||||
typedBlock.typeCheck(localVar, clas);
|
||||
return Type.VOID;
|
||||
return type;
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user