From ecb9abdf6b3205aae9f2e1d0e43f5a06a8468f77 Mon Sep 17 00:00:00 2001 From: ahmad Date: Sat, 11 May 2024 15:16:19 +0200 Subject: [PATCH] Add Type to TypedConstructor --- .../typedast/typedclass/TypedConstructor.java | 22 ++++++++----------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/src/main/java/de/maishai/typedast/typedclass/TypedConstructor.java b/src/main/java/de/maishai/typedast/typedclass/TypedConstructor.java index 9e8f964..0634ec5 100644 --- a/src/main/java/de/maishai/typedast/typedclass/TypedConstructor.java +++ b/src/main/java/de/maishai/typedast/typedclass/TypedConstructor.java @@ -25,8 +25,12 @@ public class TypedConstructor implements TypedNode { private String name; private List typedParameters = new ArrayList<>(); private TypedBlock typedBlock; - //TODO: add Type - + private Type type; + public TypedConstructor(String name, List typedParameters, TypedBlock typedBlock) { + this.name = name; + this.typedParameters = typedParameters; + this.typedBlock = typedBlock; + } public TypedConstructor(Map 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 localVar, TypedClass clas, Constructor unTypedConstructor) { @@ -45,17 +51,7 @@ public class TypedConstructor implements TypedNode { @Override public Type typeCheck(Map 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; }