Modified InstanceOf to use Pattern

This commit is contained in:
luca9913 2023-07-17 17:49:28 +02:00
parent 6119bc92ed
commit 1df354d5f1
3 changed files with 17 additions and 11 deletions

View File

@ -1,12 +1,12 @@
package de.dhbwstuttgart.syntaxtree.statement; package de.dhbwstuttgart.syntaxtree.statement;
import java.util.*; import java.util.ArrayList;
import java.util.List;
import org.antlr.v4.runtime.Token;
import de.dhbwstuttgart.syntaxtree.StatementVisitor; import de.dhbwstuttgart.syntaxtree.StatementVisitor;
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder; import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
import de.dhbwstuttgart.typeinference.assumptions.TypeInferenceBlockInformation;
import de.dhbwstuttgart.typeinference.constraints.ConstraintSet;
import org.antlr.v4.runtime.Token;
public class Block extends Statement { public class Block extends Statement {
public Block(List<Statement> statements, Token offset) { public Block(List<Statement> statements, Token offset) {

View File

@ -7,26 +7,28 @@ import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder; import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
public class InstanceOf extends BinaryExpr { public class InstanceOf extends BinaryExpr {
private RefTypeOrTPHOrWildcardOrGeneric reftype; private Pattern pattern;
private String name = null;
public InstanceOf(Expression expr, RefTypeOrTPHOrWildcardOrGeneric reftype, Token offset) { public InstanceOf(Expression expr, RefTypeOrTPHOrWildcardOrGeneric reftype, Token offset) {
super(BinaryExpr.Operator.INSTOF, TypePlaceholder.fresh(offset), expr, new LocalVar("", reftype, reftype.getOffset()), offset); super(BinaryExpr.Operator.INSTOF, TypePlaceholder.fresh(offset), expr, new LocalVar("", reftype, reftype.getOffset()), offset);
this.reftype = reftype; this.pattern = new Pattern(null, reftype, offset);
} }
public InstanceOf(Expression expr, Pattern pattern, Token offset) { public InstanceOf(Expression expr, Pattern pattern, Token offset) {
super(BinaryExpr.Operator.INSTOF, TypePlaceholder.fresh(offset), expr, new LocalVar(pattern.getName(), pattern.getType(), pattern.getOffset()), offset); super(BinaryExpr.Operator.INSTOF, TypePlaceholder.fresh(offset), expr, new LocalVar(pattern.getName(), pattern.getType(), pattern.getOffset()), offset);
this.reftype = pattern.getType(); this.pattern = pattern;
this.name = pattern.getName();
} }
public RefTypeOrTPHOrWildcardOrGeneric getReftype() { public RefTypeOrTPHOrWildcardOrGeneric getReftype() {
return reftype; return pattern.getType();
} }
public String getName() { public String getName() {
return name; return pattern.getName();
}
public Pattern gPattern() {
return pattern;
} }
@Override @Override

View File

@ -7,6 +7,9 @@ import static org.junit.Assert.fail;
import java.io.File; import java.io.File;
import java.io.FileFilter; import java.io.FileFilter;
import java.io.FileInputStream; import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.ObjectOutputStream;
import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import org.junit.BeforeClass; import org.junit.BeforeClass;
@ -14,6 +17,7 @@ import org.junit.Test;
import de.dhbwstuttgart.core.JavaTXCompiler; import de.dhbwstuttgart.core.JavaTXCompiler;
import de.dhbwstuttgart.exceptions.NotImplementedException; import de.dhbwstuttgart.exceptions.NotImplementedException;
import de.dhbwstuttgart.syntaxtree.SourceFile;
import de.dhbwstuttgart.syntaxtree.visual.ASTPrinter; import de.dhbwstuttgart.syntaxtree.visual.ASTPrinter;
/** /**