Compare commits
3 Commits
542389d35b
...
patternMat
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
007d55ea3f | ||
| 4318856fa8 | |||
| 1ace099d72 |
@@ -9,4 +9,12 @@ public class Box {
|
||||
set(x) {
|
||||
a = x;
|
||||
}
|
||||
|
||||
get() {
|
||||
return a;
|
||||
}
|
||||
|
||||
m(b) {
|
||||
//b.set(b.get());
|
||||
}
|
||||
}
|
||||
@@ -23,9 +23,7 @@ public class Matrix extends Vector<Vector<Integer>> {
|
||||
|
||||
public mul(m) {
|
||||
var ret = new Matrix();
|
||||
var i = 0;
|
||||
while(i < size()) {
|
||||
var v1 = this.elementAt(i);
|
||||
for(v1 : this) {
|
||||
var v2 = new Vector<Integer>();
|
||||
var j = 0;
|
||||
while(j < v1.size()) {
|
||||
@@ -39,7 +37,6 @@ public class Matrix extends Vector<Vector<Integer>> {
|
||||
v2.addElement(erg);
|
||||
j++; }
|
||||
ret.addElement(v2);
|
||||
i++;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -483,9 +483,9 @@ public class StatementGenerator {
|
||||
IdentifierContext identifierCtx = recordPatternCtx.identifier();
|
||||
var text = (identifierCtx != null) ? identifierCtx.getText() : null;
|
||||
//Hier evtl. Typ anpassen -> wenn kein Typ bekannt ist push neuen Typ auf Hashtable
|
||||
var recordType = recordPatternCtx.typeType() == null ? TypePlaceholder.fresh(recordPatternCtx.getStart()) : TypeGenerator.convert(recordPatternCtx.typeType(), reg, generics);
|
||||
if (text != null) localVars.put(text, recordType);
|
||||
var ret = new RecordPattern(subPattern, text, recordType, TypePlaceholder.fresh(recordPatternCtx.getStart()), recordPatternCtx.getStart());
|
||||
var type = recordPatternCtx.typeType() == null ? TypePlaceholder.fresh(recordPatternCtx.getStart()) : TypeGenerator.convert(recordPatternCtx.typeType(), reg, generics);
|
||||
if (text != null) localVars.put(text, type);
|
||||
var ret = new RecordPattern(subPattern, text, type, recordPatternCtx.getStart());
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
@@ -3,7 +3,6 @@ package de.dhbwstuttgart.syntaxtree;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import de.dhbwstuttgart.syntaxtree.type.RefType;
|
||||
import org.antlr.v4.runtime.Token;
|
||||
|
||||
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
|
||||
@@ -11,12 +10,15 @@ import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
|
||||
public class RecordPattern extends FormalParameter {
|
||||
|
||||
private final List<Pattern> subPattern;
|
||||
public final RefTypeOrTPHOrWildcardOrGeneric recordType;
|
||||
|
||||
public RecordPattern(List<Pattern> subPattern, String name, RefTypeOrTPHOrWildcardOrGeneric recordType, RefTypeOrTPHOrWildcardOrGeneric type, Token offset) {
|
||||
public RecordPattern(String name, RefTypeOrTPHOrWildcardOrGeneric type, Token offset) {
|
||||
super(name, type, offset);
|
||||
subPattern = new ArrayList<>();
|
||||
}
|
||||
|
||||
public RecordPattern(List<Pattern> subPattern, String name, RefTypeOrTPHOrWildcardOrGeneric type, Token offset) {
|
||||
super(name, type, offset);
|
||||
this.subPattern = subPattern;
|
||||
this.recordType = recordType;
|
||||
}
|
||||
|
||||
public List<Pattern> getSubPattern() {
|
||||
|
||||
@@ -179,17 +179,12 @@ public class ASTToTargetAST {
|
||||
// This finds a common sealed interface type to group together methods that use different records
|
||||
private List<ClassOrInterface> commonSuperInterfaceTypes(TargetType a, TargetType b) {
|
||||
if (a instanceof TargetGenericType && b instanceof TargetGenericType) return List.of(ASTFactory.createClass(Object.class));
|
||||
|
||||
if (a instanceof TargetRefType ta && b instanceof TargetRefType tb) {
|
||||
var res = new HashSet<ClassOrInterface>();
|
||||
|
||||
var cla = compiler.getClass(new JavaClassName(ta.name()));
|
||||
var clb = compiler.getClass(new JavaClassName(tb.name()));
|
||||
|
||||
if (cla.equals(clb) && cla.isInterface() && cla.isSealed()) {
|
||||
res.add(cla);
|
||||
}
|
||||
|
||||
while (!cla.equals(ASTFactory.createClass(Object.class))) {
|
||||
var clb2 = clb;
|
||||
while (!clb2.equals(ASTFactory.createClass(Object.class))) {
|
||||
@@ -243,13 +238,6 @@ public class ASTToTargetAST {
|
||||
}
|
||||
}
|
||||
|
||||
mapOfSignatures.values().forEach(e -> {
|
||||
e.forEach(e2 -> {
|
||||
System.out.println(e2.name() + " -> " + e2.signature().parameters().stream().map(m -> m.pattern().type()).toList());
|
||||
});
|
||||
System.out.println();
|
||||
});
|
||||
|
||||
return mapOfSignatures.values().stream().toList();
|
||||
}
|
||||
|
||||
@@ -450,7 +438,6 @@ public class ASTToTargetAST {
|
||||
}
|
||||
|
||||
private List<TargetMethod> generatePatternOverloads(ClassOrInterface clazz, List<TargetMethod> overloadedMethods) {
|
||||
if (true) return overloadedMethods;
|
||||
if (overloadedMethods.size() <= 1) return overloadedMethods;
|
||||
// Check if we have a pattern as a parameter
|
||||
var firstMethod = overloadedMethods.getFirst();
|
||||
|
||||
@@ -103,18 +103,12 @@ public class TYPE {
|
||||
|
||||
var subPatternList = recordPattern.getSubPattern();
|
||||
var resolver = new GenericsResolverSameName();
|
||||
|
||||
var refType = (RefType) resolver.visit((RefType) recordPattern.recordType);
|
||||
var refType = (RefType) recordPattern.getType();
|
||||
|
||||
var allClasses = blockInformation.getAvailableClasses();
|
||||
var typename = refType.getName().getClassName();
|
||||
|
||||
ClassOrInterface allClass = allClasses.stream().filter(c -> c.getClassName().getClassName().equals(typename)).findFirst().orElseThrow();
|
||||
// Constraints on the type of the pattern itself
|
||||
constraintSet.addUndConstraint(new Pair(refType, recordPattern.getType(), PairOperator.SMALLERDOT));
|
||||
for (var superInterface : allClass.getSuperInterfaces()) {
|
||||
constraintSet.addUndConstraint(new Pair(recordPattern.getType(), resolver.visit(superInterface), PairOperator.SMALLERDOT));
|
||||
}
|
||||
|
||||
int counter = 0;
|
||||
for (Pattern el : subPatternList){
|
||||
@@ -124,7 +118,7 @@ public class TYPE {
|
||||
FormalParameter param = (FormalParameter) allClass.getConstructors().getFirst().getParameterList().getParameterAt(counter);
|
||||
FieldAssumption assumption = new FieldAssumption(param.getName(), allClass, param.getType(), blockInformation.getCurrentTypeScope());
|
||||
|
||||
var fieldCons = new Pair(el.getType(), assumption.getType(resolver), PairOperator.EQUALSDOT);
|
||||
var fieldCons = new Pair(el.getType(), assumption.getType(resolver), PairOperator.SMALLERDOT);
|
||||
var recvCons = new Pair(refType, assumption.getReceiverType(resolver), PairOperator.EQUALSDOT);
|
||||
constraintSet.addUndConstraint(fieldCons);
|
||||
constraintSet.addUndConstraint(recvCons);
|
||||
@@ -134,7 +128,6 @@ public class TYPE {
|
||||
((RefType)assumption.getReceiverType(resolver)).getParaList().get(i),
|
||||
PairOperator.EQUALSDOT));
|
||||
}
|
||||
|
||||
}
|
||||
counter++;
|
||||
}
|
||||
|
||||
@@ -55,7 +55,7 @@ public class AllgemeinTest {
|
||||
//String className = "VectorNotObject";
|
||||
//String className = "WildcardCaptureConversionTest";
|
||||
//String className = "CaptureConversion";
|
||||
//String className = "Pair";
|
||||
String className = "Pair2";
|
||||
//String className = "UseWildcardPair";
|
||||
//String className = "Assign";
|
||||
//String className = "StreamTest";
|
||||
@@ -64,8 +64,8 @@ public class AllgemeinTest {
|
||||
//String className = "Cycle";
|
||||
//String className = "TripleTest";
|
||||
//String className = "WildcardList";
|
||||
String className = "List";
|
||||
//String className = "Box";
|
||||
//String className = "List";
|
||||
//String className = "BoxUse";
|
||||
//String className = "GenBox";
|
||||
//String className = "InnerInf";
|
||||
//String className = "Foo";
|
||||
|
||||
Reference in New Issue
Block a user