diff --git a/src/main/java/de/dhbwstuttgart/parser/SyntaxTreeGenerator/StatementGenerator.java b/src/main/java/de/dhbwstuttgart/parser/SyntaxTreeGenerator/StatementGenerator.java index e15cc721..8cc1d586 100644 --- a/src/main/java/de/dhbwstuttgart/parser/SyntaxTreeGenerator/StatementGenerator.java +++ b/src/main/java/de/dhbwstuttgart/parser/SyntaxTreeGenerator/StatementGenerator.java @@ -469,14 +469,14 @@ public class StatementGenerator { }; } - private TypePattern convert(PrimaryPatternContext pPattern) { + private FormalParameter convert(PrimaryPatternContext pPattern) { switch (pPattern) { case TPatternContext tPattern: TypePatternContext typePattern = tPattern.typePattern(); var text = typePattern.identifier().getText(); var type = TypeGenerator.convert(typePattern.typeType(), reg, generics); localVars.put(text, type); - return new TypePattern(text, type, typePattern.getStart()); + return new FormalParameter(text, type, typePattern.getStart()); case RPatternContext rPattern: RecordPatternContext recordPattern = rPattern.recordPattern(); return convert(recordPattern); @@ -488,9 +488,7 @@ public class StatementGenerator { private RecordPattern convert(RecordPatternContext recordPatternCtx) { List subPatternCtx = recordPatternCtx.recordStructurePattern().recordComponentPatternList().pattern(); - List subPattern = subPatternCtx.stream().map((patternCtx) -> { - return (TypePattern) convert(patternCtx); - }).collect(Collectors.toList()); + List subPattern = subPatternCtx.stream().map(this::convert).collect(Collectors.toList()); IdentifierContext identifierCtx = recordPatternCtx.identifier(); var text = (identifierCtx != null) ? identifierCtx.getText() : null; var type = TypeGenerator.convert(recordPatternCtx.typeType(), reg, generics); @@ -888,7 +886,7 @@ public class StatementGenerator { String localVarName = typePatternCtx.identifier().getText(); RefTypeOrTPHOrWildcardOrGeneric localVarType = TypeGenerator.convert(typePatternCtx.typeType(), reg, generics); localVars.put(localVarName, localVarType); - return new InstanceOf(left, new TypePattern(localVarName, localVarType, typePatternCtx.getStart()), offset); + return new InstanceOf(left, new FormalParameter(localVarName, localVarType, typePatternCtx.getStart()), offset); default: throw new NotImplementedException(); } diff --git a/src/main/java/de/dhbwstuttgart/syntaxtree/ASTVisitor.java b/src/main/java/de/dhbwstuttgart/syntaxtree/ASTVisitor.java index 508d08e0..41d821f8 100644 --- a/src/main/java/de/dhbwstuttgart/syntaxtree/ASTVisitor.java +++ b/src/main/java/de/dhbwstuttgart/syntaxtree/ASTVisitor.java @@ -31,8 +31,6 @@ public interface ASTVisitor extends StatementVisitor{ void visit(ExtendsWildcardType extendsWildcardType); void visit(GenericRefType genericRefType); - - void visit(TypePattern aPattern); void visit(ExpressionPattern aPattern); diff --git a/src/main/java/de/dhbwstuttgart/syntaxtree/AbstractASTWalker.java b/src/main/java/de/dhbwstuttgart/syntaxtree/AbstractASTWalker.java index 58c5ab04..08e9bdf0 100644 --- a/src/main/java/de/dhbwstuttgart/syntaxtree/AbstractASTWalker.java +++ b/src/main/java/de/dhbwstuttgart/syntaxtree/AbstractASTWalker.java @@ -304,11 +304,6 @@ public abstract class AbstractASTWalker implements ASTVisitor { aYield.accept(this); } - @Override - public void visit(TypePattern aPattern) { - - } - @Override public void visit(ExpressionPattern aPattern) { diff --git a/src/main/java/de/dhbwstuttgart/syntaxtree/GuardedPattern.java b/src/main/java/de/dhbwstuttgart/syntaxtree/GuardedPattern.java index c26def76..55a95e9c 100644 --- a/src/main/java/de/dhbwstuttgart/syntaxtree/GuardedPattern.java +++ b/src/main/java/de/dhbwstuttgart/syntaxtree/GuardedPattern.java @@ -6,9 +6,9 @@ import org.antlr.v4.runtime.Token; public class GuardedPattern extends Pattern { private final Expression condition; - private final TypePattern nested; + private final Pattern nested; - public GuardedPattern(Expression condition, TypePattern nested, Token offset) { + public GuardedPattern(Expression condition, Pattern nested, Token offset) { super(nested.getType(), offset); this.condition = condition; this.nested = nested; @@ -18,7 +18,7 @@ public class GuardedPattern extends Pattern { return condition; } - public TypePattern getNestedPattern() { + public Pattern getNestedPattern() { return nested; } diff --git a/src/main/java/de/dhbwstuttgart/syntaxtree/RecordPattern.java b/src/main/java/de/dhbwstuttgart/syntaxtree/RecordPattern.java index ca912f73..cfe9c2dc 100644 --- a/src/main/java/de/dhbwstuttgart/syntaxtree/RecordPattern.java +++ b/src/main/java/de/dhbwstuttgart/syntaxtree/RecordPattern.java @@ -7,24 +7,24 @@ import org.antlr.v4.runtime.Token; import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric; -public class RecordPattern extends TypePattern { +public class RecordPattern extends FormalParameter { - private List subPattern = new ArrayList<>(); + private List subPattern = new ArrayList<>(); public RecordPattern(String name, RefTypeOrTPHOrWildcardOrGeneric type, Token offset) { super(name, type, offset); } - public RecordPattern(List subPattern, String name, RefTypeOrTPHOrWildcardOrGeneric type, Token offset) { + public RecordPattern(List subPattern, String name, RefTypeOrTPHOrWildcardOrGeneric type, Token offset) { super(name, type, offset); this.subPattern = subPattern; } - public List getSubPattern() { + public List getSubPattern() { return this.subPattern; } - public void addSubPattern(TypePattern newPattern) { + public void addSubPattern(Pattern newPattern) { this.subPattern.add(newPattern); } diff --git a/src/main/java/de/dhbwstuttgart/syntaxtree/TypePattern.java b/src/main/java/de/dhbwstuttgart/syntaxtree/TypePattern.java deleted file mode 100644 index 8de43b06..00000000 --- a/src/main/java/de/dhbwstuttgart/syntaxtree/TypePattern.java +++ /dev/null @@ -1,26 +0,0 @@ -package de.dhbwstuttgart.syntaxtree; - -import de.dhbwstuttgart.syntaxtree.statement.Expression; -import org.antlr.v4.runtime.Token; - -import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric; - -public class TypePattern extends Pattern { - - private final String name; - - public TypePattern(String name, RefTypeOrTPHOrWildcardOrGeneric type, Token offset) { - super(type, offset); - this.name = name; - } - - public String getName() { - return name; - } - - @Override - public void accept(ASTVisitor visitor) { - visitor.visit(this); - } - -} diff --git a/src/main/java/de/dhbwstuttgart/syntaxtree/statement/InstanceOf.java b/src/main/java/de/dhbwstuttgart/syntaxtree/statement/InstanceOf.java index db5ce52e..0c8b0eab 100644 --- a/src/main/java/de/dhbwstuttgart/syntaxtree/statement/InstanceOf.java +++ b/src/main/java/de/dhbwstuttgart/syntaxtree/statement/InstanceOf.java @@ -1,6 +1,7 @@ package de.dhbwstuttgart.syntaxtree.statement; -import de.dhbwstuttgart.syntaxtree.TypePattern; +import de.dhbwstuttgart.syntaxtree.FormalParameter; +import de.dhbwstuttgart.syntaxtree.Pattern; import org.antlr.v4.runtime.Token; import de.dhbwstuttgart.syntaxtree.StatementVisitor; @@ -8,14 +9,14 @@ import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric; import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder; public class InstanceOf extends BinaryExpr { - private TypePattern pattern; + private FormalParameter pattern; public InstanceOf(Expression expr, RefTypeOrTPHOrWildcardOrGeneric reftype, Token offset) { super(BinaryExpr.Operator.INSTOF, TypePlaceholder.fresh(offset), expr, new LocalVar("", reftype, reftype.getOffset()), offset); - this.pattern = new TypePattern(null, reftype, offset); + this.pattern = new FormalParameter(null, reftype, offset); } - public InstanceOf(Expression expr, TypePattern pattern, Token offset) { + public InstanceOf(Expression expr, FormalParameter pattern, Token offset) { super(BinaryExpr.Operator.INSTOF, TypePlaceholder.fresh(offset), expr, new LocalVar(pattern.getName(), pattern.getType(), pattern.getOffset()), offset); this.pattern = pattern; } @@ -28,7 +29,7 @@ public class InstanceOf extends BinaryExpr { return pattern.getName(); } - public TypePattern gPattern() { + public FormalParameter gPattern() { return pattern; } diff --git a/src/main/java/de/dhbwstuttgart/syntaxtree/visual/OutputGenerator.java b/src/main/java/de/dhbwstuttgart/syntaxtree/visual/OutputGenerator.java index d9f0cc54..b32c325d 100644 --- a/src/main/java/de/dhbwstuttgart/syntaxtree/visual/OutputGenerator.java +++ b/src/main/java/de/dhbwstuttgart/syntaxtree/visual/OutputGenerator.java @@ -452,12 +452,6 @@ public class OutputGenerator implements ASTVisitor { aYield.getType().accept(this); } - @Override - public void visit(TypePattern aPattern) { - aPattern.getType().accept(this); - out.append(" " + aPattern.getName()); - } - @Override public void visit(ExpressionPattern aPattern) { aPattern.getType().accept(this); @@ -469,7 +463,7 @@ public class OutputGenerator implements ASTVisitor { public void visit(RecordPattern aRecordPattern) { aRecordPattern.getType().accept(this); out.append("("); - List subPatterns = aRecordPattern.getSubPattern(); + List subPatterns = aRecordPattern.getSubPattern(); int i; for (i = 0; i < subPatterns.size() - 1; i++) { subPatterns.get(i).accept(this); diff --git a/src/main/java/de/dhbwstuttgart/target/generate/StatementToTargetExpression.java b/src/main/java/de/dhbwstuttgart/target/generate/StatementToTargetExpression.java index 300f1f6e..b27672b6 100644 --- a/src/main/java/de/dhbwstuttgart/target/generate/StatementToTargetExpression.java +++ b/src/main/java/de/dhbwstuttgart/target/generate/StatementToTargetExpression.java @@ -376,11 +376,6 @@ public class StatementToTargetExpression implements ASTVisitor { } - @Override - public void visit(FormalParameter formalParameter) { - - } - @Override public void visit(GenericDeclarationList genericTypeVars) { @@ -437,7 +432,7 @@ public class StatementToTargetExpression implements ASTVisitor { } @Override - public void visit(TypePattern aPattern) { + public void visit(FormalParameter aPattern) { result = new SimplePattern(converter.convert(aPattern.getType()), aPattern.getName()); } diff --git a/src/main/java/de/dhbwstuttgart/target/generate/TracingStatementVisitor.java b/src/main/java/de/dhbwstuttgart/target/generate/TracingStatementVisitor.java index e1a9dd43..6301145b 100644 --- a/src/main/java/de/dhbwstuttgart/target/generate/TracingStatementVisitor.java +++ b/src/main/java/de/dhbwstuttgart/target/generate/TracingStatementVisitor.java @@ -1,9 +1,6 @@ package de.dhbwstuttgart.target.generate; import de.dhbwstuttgart.parser.SyntaxTreeGenerator.AssignToLocal; -import de.dhbwstuttgart.syntaxtree.GuardedPattern; -import de.dhbwstuttgart.syntaxtree.TypePattern; -import de.dhbwstuttgart.syntaxtree.RecordPattern; import de.dhbwstuttgart.syntaxtree.StatementVisitor; import de.dhbwstuttgart.syntaxtree.statement.*; diff --git a/src/main/java/de/dhbwstuttgart/typeinference/typeAlgo/TYPEStmt.java b/src/main/java/de/dhbwstuttgart/typeinference/typeAlgo/TYPEStmt.java index 954e629f..082b5f7a 100644 --- a/src/main/java/de/dhbwstuttgart/typeinference/typeAlgo/TYPEStmt.java +++ b/src/main/java/de/dhbwstuttgart/typeinference/typeAlgo/TYPEStmt.java @@ -31,7 +31,6 @@ import de.dhbwstuttgart.syntaxtree.statement.EmptyStmt; import de.dhbwstuttgart.syntaxtree.statement.ExpressionReceiver; import de.dhbwstuttgart.syntaxtree.statement.FieldVar; import de.dhbwstuttgart.syntaxtree.statement.ForStmt; -import de.dhbwstuttgart.syntaxtree.GuardedPattern; import de.dhbwstuttgart.syntaxtree.statement.IfStmt; import de.dhbwstuttgart.syntaxtree.statement.InstanceOf; import de.dhbwstuttgart.syntaxtree.statement.LambdaExpression; @@ -41,8 +40,6 @@ import de.dhbwstuttgart.syntaxtree.statement.LocalVarDecl; import de.dhbwstuttgart.syntaxtree.statement.MethodCall; import de.dhbwstuttgart.syntaxtree.statement.NewArray; import de.dhbwstuttgart.syntaxtree.statement.NewClass; -import de.dhbwstuttgart.syntaxtree.TypePattern; -import de.dhbwstuttgart.syntaxtree.RecordPattern; import de.dhbwstuttgart.syntaxtree.statement.Return; import de.dhbwstuttgart.syntaxtree.statement.ReturnVoid; import de.dhbwstuttgart.syntaxtree.statement.Statement; @@ -739,7 +736,7 @@ public class TYPEStmt implements StatementVisitor { RefTypeOrTPHOrWildcardOrGeneric caseExpressionType = null; for (var child : switchStmt.getBlocks()) { for (var label : child.getLabels()) { - if (!(label.getPattern() instanceof TypePattern) && !(label.getType() instanceof Void)) { + if (!(label.getPattern() instanceof FormalParameter) && !(label.getType() instanceof Void)) { if (caseExpressionType != null && !caseExpressionType.equals(label.getType())) throw new TypeinferenceException("Case labels must all have the same Type if they are expressions", label); caseExpressionType = label.getType(); @@ -749,7 +746,7 @@ public class TYPEStmt implements StatementVisitor { if (caseExpressionType == null) { for (var child : switchStmt.getBlocks()) { for (var label : child.getLabels()) { - if (label.getPattern() instanceof TypePattern) { + if (label.getPattern() instanceof FormalParameter) { constraintsSet.addUndConstraint(new Pair(label.getPattern().getType(), switchStmt.getSwitch().getType(), PairOperator.SMALLERDOT)); } }