From 043dda660b000dc673a2c098e68e1cfc94d0864b Mon Sep 17 00:00:00 2001 From: luca9913 Date: Fri, 10 Mar 2023 07:48:38 +0100 Subject: [PATCH] =?UTF-8?q?Fehler=20im=20neuen=20SyntaxTreeGenerator=20bes?= =?UTF-8?q?eitigt=20und=20TODOs=20eingef=C3=BCgt?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../parser/SyntaxTreeGenerator/ASTGen.java | 40 ++++++++++++++++--- 1 file changed, 35 insertions(+), 5 deletions(-) diff --git a/src/main/java/de/dhbwstuttgart/parser/SyntaxTreeGenerator/ASTGen.java b/src/main/java/de/dhbwstuttgart/parser/SyntaxTreeGenerator/ASTGen.java index 5ba6bc72..fe00ea79 100644 --- a/src/main/java/de/dhbwstuttgart/parser/SyntaxTreeGenerator/ASTGen.java +++ b/src/main/java/de/dhbwstuttgart/parser/SyntaxTreeGenerator/ASTGen.java @@ -3,6 +3,7 @@ package de.dhbwstuttgart.parser.SyntaxTreeGenerator; import java.util.HashMap; import java.util.HashSet; import java.util.Map; +import java.util.Objects; import java.util.Optional; import java.util.Set; import java.util.stream.Collectors; @@ -21,6 +22,7 @@ import de.dhbwstuttgart.parser.antlr.Java17Parser; import de.dhbwstuttgart.parser.antlr.Java17Parser.ClassBodyDeclarationContext; import de.dhbwstuttgart.parser.antlr.Java17Parser.ClassOrInterfaceModifierContext; import de.dhbwstuttgart.parser.antlr.Java17Parser.ClassorinterfacedeclContext; +import de.dhbwstuttgart.parser.antlr.Java17Parser.EmptymethodContext; import de.dhbwstuttgart.parser.antlr.Java17Parser.GenericDeclarationListContext; import de.dhbwstuttgart.parser.antlr.Java17Parser.GenericmethodContext; import de.dhbwstuttgart.parser.antlr.Java17Parser.MemberclassorinterfaceContext; @@ -28,11 +30,14 @@ import de.dhbwstuttgart.parser.antlr.Java17Parser.MemberconstructorContext; import de.dhbwstuttgart.parser.antlr.Java17Parser.MemberdeclContext; import de.dhbwstuttgart.parser.antlr.Java17Parser.MemberfieldContext; import de.dhbwstuttgart.parser.antlr.Java17Parser.MembermethodContext; +import de.dhbwstuttgart.parser.antlr.Java17Parser.MethodBodyContext; import de.dhbwstuttgart.parser.antlr.Java17Parser.MethodDeclarationContext; import de.dhbwstuttgart.parser.antlr.Java17Parser.MethodHeaderContext; +import de.dhbwstuttgart.parser.antlr.Java17Parser.MethodblockContext; import de.dhbwstuttgart.parser.antlr.Java17Parser.MethoddeclContext; import de.dhbwstuttgart.parser.antlr.Java17Parser.ModifierContext; import de.dhbwstuttgart.parser.antlr.Java17Parser.NoclassorinterfaceContext; +import de.dhbwstuttgart.parser.antlr.Java17Parser.ReftypeContext; import de.dhbwstuttgart.parser.antlr.Java17Parser.SrcfileContext; import de.dhbwstuttgart.parser.scope.GatherNames; import de.dhbwstuttgart.parser.scope.GenericsRegistry; @@ -49,6 +54,7 @@ import de.dhbwstuttgart.syntaxtree.factory.ASTFactory; import de.dhbwstuttgart.syntaxtree.type.RefType; import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric; import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder; +import de.dhbwstuttgart.syntaxtree.type.Void; import de.dhbwstuttgart.syntaxtree.statement.Block; import de.dhbwstuttgart.syntaxtree.statement.Statement; @@ -133,7 +139,8 @@ public class ASTGen { if (clsoif.classDeclaration() != null) { newClass = convertClass(clsoif.classDeclaration(), modifiers); } else { - newClass = convertInterface(clsoif.interfaceDeclaration(), modifiers); + // TODO: newClass = convertInterface(clsoif.interfaceDeclaration(), modifiers); + throw new NotImplementedException(); } classes.add(newClass); } @@ -315,14 +322,37 @@ public class ASTGen { methoddeclaration = mdc.methodDeclaration(); header = methoddeclaration.methodHeader(); gtvDeclarations = new GenericDeclarationList(new ArrayList<>(), header.getStart()); + name = header.identifier().getText(); } RefTypeOrTPHOrWildcardOrGeneric retType; - if (header.refType() != null) { - retType = TypeGenerator.convert(header.refType()); + if (Objects.isNull(header.refType())) { + retType = TypePlaceholder.fresh(header.getStart()); + } else { + if (header.refType() instanceof ReftypeContext reftype) { + retType = TypeGenerator.convert(reftype.typeType(), reg, generics); + } else { + retType = new Void(header.refType().getStart()); + } + } + StatementGenerator stmtgen = new StatementGenerator(reg, localgenerics, fields, new HashMap<>()); + ParameterList paramlist = stmtgen.convert(header.formalParameters().formalParameterList()); + MethodBodyContext body = methoddeclaration.methodBody(); + Block block = null; + if (body instanceof EmptymethodContext emptymethod) { + if (!Modifier.isAbstract(modifiers)) { + // TODO: Error! Abstrakte Methode ohne abstrakt Keyword + } + } else { + block = stmtgen.convert(new MethodblockContext(body).block(), true); + } + if (parentClass.equals(new JavaClassName(name))) { + // TODO: Konstruktoren in eigener Methode behandeln + /* fieldInitializations geloescht PL 2018-11-24 */ + return new Constructor(modifiers, name, retType, paramlist, block, gtvDeclarations, header.getStart()); + } else { + return new Method(modifiers, name, retType, paramlist, block, gtvDeclarations, header.getStart()); } - - return null; } private List convert(Java17Parser.FieldDeclarationContext fieldDeclContext, int modifiers,