modified: ../src/main/java/de/dhbwstuttgart/core/JavaTXCompiler.java
modified: ../src/main/java/de/dhbwstuttgart/syntaxtree/ClassOrInterface.java modified: ../src/main/java/de/dhbwstuttgart/syntaxtree/SourceFile.java modified: ../src/main/java/de/dhbwstuttgart/typeinference/typeAlgo/TYPEStmt.java modified: ../src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java modified: ../src/main/java/de/dhbwstuttgart/typeinference/unify/model/UnifyPair.java
This commit is contained in:
parent
e4e3704c7b
commit
592de5310e
@ -110,6 +110,8 @@ public class JavaTXCompiler {
|
||||
public ConstraintSet<Pair> getConstraints() throws ClassNotFoundException, IOException {
|
||||
List<ClassOrInterface> allClasses = new ArrayList<>();//environment.getAllAvailableClasses();
|
||||
List<ClassOrInterface> importedClasses = new ArrayList<>();
|
||||
ClassOrInterface objectClass = ASTFactory.createClass(
|
||||
classLoader.loadClass(new JavaClassName("java.lang.Object").toString()));
|
||||
//Alle Importierten Klassen in allen geparsten Sourcefiles kommen ins FC
|
||||
for (File forSourceFile : sourceFiles.keySet()){
|
||||
for (JavaClassName name : sourceFiles.get(forSourceFile).getImports()) {
|
||||
@ -125,16 +127,29 @@ public class JavaTXCompiler {
|
||||
}
|
||||
for (File f : this.sourceFiles.keySet()) {
|
||||
SourceFile sf = sourceFiles.get(f);
|
||||
sf = new SourceFile(sf.getPkgName(),
|
||||
sf.KlassenVektor.stream()
|
||||
.map(cl -> new ClassOrInterface(cl))
|
||||
.collect(Collectors.toCollection(ArrayList::new)),
|
||||
sf.imports);
|
||||
//sf enthaelt neues Source-File, neue Klassen-Objekte und neue
|
||||
//ArrayListen-Objekte fuer Fields, Construktoren und Methoden
|
||||
//Alle anderen Objekte werden nur kopiert.
|
||||
sf.KlassenVektor.forEach(cl -> {
|
||||
ClassOrInterface superclass = null;
|
||||
Optional<ClassOrInterface> optSuperclass =
|
||||
importedClasses.stream().filter(x -> x.getClassName().equals(
|
||||
cl.getSuperClass().getName())).findFirst();
|
||||
if (optSuperclass.isPresent()) {
|
||||
superclass = optSuperclass.get();
|
||||
}
|
||||
if (cl.getSuperClass().getName().equals(new JavaClassName("java.lang.Object"))) {
|
||||
superclass = objectClass;
|
||||
}
|
||||
else {
|
||||
//throw new ClassNotFoundException("");
|
||||
Optional<ClassOrInterface> optSuperclass =
|
||||
importedClasses.stream().filter(x -> x.getClassName().equals(
|
||||
cl.getSuperClass().getName())).findFirst();
|
||||
if (optSuperclass.isPresent()) {
|
||||
superclass = optSuperclass.get();
|
||||
}
|
||||
else {
|
||||
//throw new ClassNotFoundException("");
|
||||
}
|
||||
}
|
||||
Iterator<RefTypeOrTPHOrWildcardOrGeneric> paraIt= cl.getSuperClass().getParaList().iterator();
|
||||
Iterator<GenericTypeVar> tvarVarIt = superclass.getGenerics().iterator();
|
||||
@ -152,22 +167,12 @@ public class JavaTXCompiler {
|
||||
.stream()
|
||||
.map(fp -> new FormalParameter(fp.getName(), fp.getType().acceptTV(new TypeExchanger(gtvs)), fp.getOffset()))
|
||||
.collect(Collectors.toCollection(ArrayList::new)), m.getParameterList().getOffset());
|
||||
/*
|
||||
Iterator<? extends GenericTypeVar> genericsIt = m.getGenerics().iterator();
|
||||
List<GenericTypeVar> newGenericsList = new ArrayList<>();
|
||||
Set<String> keys = gtvs.keySet();
|
||||
while (genericsIt.hasNext()) {
|
||||
GenericTypeVar gtv = genericsIt.next();
|
||||
if (!keys.contains(gtv.getName())) {
|
||||
newGenericsList.add(gtv);
|
||||
}
|
||||
}
|
||||
*/
|
||||
cl.getMethods().add(new Method(m.modifier, m.name, m.getReturnType().acceptTV(new TypeExchanger(gtvs)), newParaList, m.block,
|
||||
//new GenericDeclarationList(newGenericsList, ((GenericDeclarationList)m.getGenerics()).getOffset()),
|
||||
(GenericDeclarationList)m.getGenerics(),
|
||||
m.getOffset()));
|
||||
}
|
||||
|
||||
});
|
||||
allClasses.addAll(sf.getClasses());
|
||||
}
|
||||
|
@ -34,6 +34,7 @@ public class ClassOrInterface extends SyntaxTreeNode implements TypeScope{
|
||||
private List<RefType> implementedInterfaces;
|
||||
private List<Constructor> constructors;
|
||||
|
||||
|
||||
public ClassOrInterface(int modifiers, JavaClassName name, List<Field> fielddecl, Optional<Constructor> fieldInitializations, List<Method> methods, List<Constructor> constructors, GenericDeclarationList genericClassParameters,
|
||||
RefType superClass, Boolean isInterface, List<RefType> implementedInterfaces, Token offset){
|
||||
super(offset);
|
||||
@ -50,6 +51,23 @@ public class ClassOrInterface extends SyntaxTreeNode implements TypeScope{
|
||||
this.constructors = constructors;
|
||||
}
|
||||
|
||||
/* erzeugt fuer Fields, Konstruktoren und Methoden neue ArrayList-Objekte
|
||||
* alle anderen Datenobjekte werden nur kopiert.
|
||||
*/
|
||||
public ClassOrInterface(ClassOrInterface cl){
|
||||
super(cl.getOffset());
|
||||
this.modifiers = cl.modifiers;
|
||||
this.name = cl.name;
|
||||
this.fields = new ArrayList<>(cl.fields);
|
||||
this.fieldInitializations= cl.fieldInitializations;
|
||||
this.genericClassParameters = cl.genericClassParameters;
|
||||
this.superClass = cl.superClass;
|
||||
this.isInterface = cl.isInterface;
|
||||
this.implementedInterfaces = cl.implementedInterfaces;
|
||||
this.methods = new ArrayList<>(cl.methods);
|
||||
this.constructors = new ArrayList<>(cl.constructors);
|
||||
}
|
||||
|
||||
// Gets class name
|
||||
public JavaClassName getClassName(){
|
||||
return this.name;
|
||||
|
@ -26,6 +26,13 @@ public class SourceFile extends SyntaxTreeNode{
|
||||
this.imports = imports;
|
||||
}
|
||||
|
||||
public SourceFile(SourceFile sf) {
|
||||
super(new NullToken());
|
||||
this.KlassenVektor = new ArrayList<>(sf.KlassenVektor);
|
||||
this.imports = new HashSet<>(sf.imports);
|
||||
}
|
||||
|
||||
|
||||
public String getPkgName(){
|
||||
return this.pkgName;
|
||||
}
|
||||
|
@ -574,11 +574,12 @@ public class TYPEStmt implements StatementVisitor{
|
||||
|
||||
RefTypeOrTPHOrWildcardOrGeneric retType = assumption.getReceiverType(resolver);
|
||||
methodConstraint.add(new Pair(forMethod.receiver.getType(), retType,
|
||||
PairOperator.SMALLERDOT));
|
||||
PairOperator.EQUALSDOT));//PL 2020-03-17 SMALLERDOT in EQUALSDOT umgewandelt, weil alle geerbten Methoden in den jeweilen Klassen enthalten sind.
|
||||
|
||||
//Fuer Bytecodegenerierung PL 2020-03-09 wird derzeit nicht benutzt
|
||||
methodConstraint.add(new Pair(forMethod.receiverType, retType,
|
||||
PairOperator.EQUALSDOT));
|
||||
//Fuer Bytecodegenerierung PL 2020-03-09 wird derzeit nicht benutzt ANFANG
|
||||
//methodConstraint.add(new Pair(forMethod.receiverType, retType,
|
||||
// PairOperator.EQUALSDOT));
|
||||
//Fuer Bytecodegenerierung PL 2020-03-09 wird derzeit nicht benutzt ENDE
|
||||
|
||||
methodConstraint.add(new Pair(assumption.getReturnType(resolver), forMethod.getType(),
|
||||
PairOperator.EQUALSDOT));
|
||||
@ -595,8 +596,9 @@ public class TYPEStmt implements StatementVisitor{
|
||||
RefTypeOrTPHOrWildcardOrGeneric assType = assumption.getArgTypes(resolver).get(i);
|
||||
ret.add(new Pair(argType, assType, PairOperator.SMALLERDOT));
|
||||
|
||||
//Fuer Bytecodegenerierung PL 2020-03-09 wird derzeit nicht benutzt
|
||||
ret.add(new Pair(foMethod.argTypes.get(i), assType, PairOperator.EQUALSDOT));
|
||||
//Fuer Bytecodegenerierung PL 2020-03-09 wird derzeit nicht benutzt ANFANG
|
||||
// ret.add(new Pair(foMethod.argTypes.get(i), assType, PairOperator.EQUALSDOT));
|
||||
//Fuer Bytecodegenerierung PL 2020-03-09 wird derzeit nicht benutzt ENDE
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
@ -1813,7 +1813,10 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
||||
oderConstraintsOutput.remove(ret);
|
||||
//Set<UnifyPair> retFlat = new HashSet<>();
|
||||
//ret.stream().forEach(x -> retFlat.addAll(x));
|
||||
ret.stream().forEach(x -> x.stream().forEach(y -> y.addSubstitutions(x)));
|
||||
ret.stream().forEach(x -> x.stream().forEach(y -> { Set<UnifyPair> x_new = new HashSet<>(x); //PL 2020-03-18: y selbst darf nicht in die Substitutionen
|
||||
x_new.remove(y);
|
||||
y.addSubstitutions(x_new);
|
||||
}));
|
||||
result.get(8).add(ret);
|
||||
first = false;
|
||||
}
|
||||
@ -1836,7 +1839,10 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
||||
// System.out.println("M");
|
||||
//Set<UnifyPair> retFlat = new HashSet<>();
|
||||
//ret.stream().forEach(x -> retFlat.addAll(x));
|
||||
ret.stream().forEach(x -> x.stream().forEach(y -> y.addSubstitutions(x)));
|
||||
ret.stream().forEach(x -> x.stream().forEach(y -> { Set<UnifyPair> x_new = new HashSet<>(x); //PL 2020-03-18: y selbst darf nicht in die Substitutionen
|
||||
x_new.remove(y);
|
||||
y.addSubstitutions(x_new);
|
||||
}));
|
||||
result.get(8).add(ret);
|
||||
first = false;
|
||||
}
|
||||
|
@ -195,11 +195,13 @@ public class UnifyPair {
|
||||
if (other.getBasePair() != basePair || (other.getBasePair() == null && basePair == null)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!other.getBasePair().equals(basePair) ||
|
||||
!other.getAllSubstitutions().equals(getAllSubstitutions())) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return other.getPairOp() == pairOp
|
||||
&& other.getLhsType().equals(lhs)
|
||||
|
Loading…
Reference in New Issue
Block a user