From 21adeb7f26a4b16aa83dd57b3a57e33f35429883 Mon Sep 17 00:00:00 2001 From: Etienne Zink Date: Mon, 21 Mar 2022 17:15:03 +0100 Subject: [PATCH] Implementierung der von convert(..) in ASTToIntermediate. --- .../convert/ASTToIntermediate.java | 47 ++++++++++++++++++- 1 file changed, 46 insertions(+), 1 deletion(-) diff --git a/src/main/java/de/dhbwstuttgart/intermediate/convert/ASTToIntermediate.java b/src/main/java/de/dhbwstuttgart/intermediate/convert/ASTToIntermediate.java index 0673cbe2..f918c777 100644 --- a/src/main/java/de/dhbwstuttgart/intermediate/convert/ASTToIntermediate.java +++ b/src/main/java/de/dhbwstuttgart/intermediate/convert/ASTToIntermediate.java @@ -1,5 +1,50 @@ package de.dhbwstuttgart.intermediate.convert; +import de.dhbwstuttgart.exceptions.NotImplementedException; +import de.dhbwstuttgart.intermediate.types.*; +import de.dhbwstuttgart.syntaxtree.type.*; + +import java.util.stream.Collectors; + public class ASTToIntermediate { - //ToDo + + public IntermediateRefType convert(RefType originalType){ + return new IntermediateRefType(originalType.getName(), + originalType + .getParaList() + .stream() + .map(this::convert) + .collect(Collectors.toList())); + } + + + //ToDo abklären: darf hier kein stehen? da hier kein Typparameter existiert + public IntermediateGenericType convert(GenericRefType originalType){ + //no typ argument for e.g. is present in the definition of GenericRefType + return new IntermediateGenericType(originalType.getParsedName()); + } + + public IntermediateSuperWildcard convert(SuperWildcardType originalType){ + IntermediateType innerType = convert(originalType.getInnerType()); + //throws RuntimeException, because only IntermediateInnerType (no wildcards) are allowed as inner types of wildcards + if (!(innerType instanceof IntermediateInnerType)) throw new RuntimeException("False inner type!"); + return new IntermediateSuperWildcard((IntermediateInnerType) innerType); + } + + public IntermediateExtendsWildcard convert(ExtendsWildcardType originalType){ + IntermediateType innerType = convert(originalType.getInnerType()); + //throws RuntimeException because only IntermediateInnerType (no wildcards) are allowed as inner types of wildcards + if (!(innerType instanceof IntermediateInnerType)) throw new RuntimeException("False inner type!"); + return new IntermediateExtendsWildcard((IntermediateInnerType) innerType); + } + + public IntermediateWildcard convert(){ + //thows RuntimeException because in the AST is no typ defined which represents a normal wildcard + throw new NotImplementedException("There is no conversion defined for this type."); + } + + public IntermediateRefType convert(RefTypeOrTPHOrWildcardOrGeneric originalType){ + //default implementation which shouldn't be called because of polymorphism + throw new NotImplementedException("There is no conversion defined for this type."); + } }