forked from JavaTX/JavaCompilerCore
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 {
|
public ConstraintSet<Pair> getConstraints() throws ClassNotFoundException, IOException {
|
||||||
List<ClassOrInterface> allClasses = new ArrayList<>();//environment.getAllAvailableClasses();
|
List<ClassOrInterface> allClasses = new ArrayList<>();//environment.getAllAvailableClasses();
|
||||||
List<ClassOrInterface> importedClasses = new ArrayList<>();
|
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
|
//Alle Importierten Klassen in allen geparsten Sourcefiles kommen ins FC
|
||||||
for (File forSourceFile : sourceFiles.keySet()){
|
for (File forSourceFile : sourceFiles.keySet()){
|
||||||
for (JavaClassName name : sourceFiles.get(forSourceFile).getImports()) {
|
for (JavaClassName name : sourceFiles.get(forSourceFile).getImports()) {
|
||||||
@ -125,8 +127,20 @@ public class JavaTXCompiler {
|
|||||||
}
|
}
|
||||||
for (File f : this.sourceFiles.keySet()) {
|
for (File f : this.sourceFiles.keySet()) {
|
||||||
SourceFile sf = sourceFiles.get(f);
|
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 -> {
|
sf.KlassenVektor.forEach(cl -> {
|
||||||
ClassOrInterface superclass = null;
|
ClassOrInterface superclass = null;
|
||||||
|
if (cl.getSuperClass().getName().equals(new JavaClassName("java.lang.Object"))) {
|
||||||
|
superclass = objectClass;
|
||||||
|
}
|
||||||
|
else {
|
||||||
Optional<ClassOrInterface> optSuperclass =
|
Optional<ClassOrInterface> optSuperclass =
|
||||||
importedClasses.stream().filter(x -> x.getClassName().equals(
|
importedClasses.stream().filter(x -> x.getClassName().equals(
|
||||||
cl.getSuperClass().getName())).findFirst();
|
cl.getSuperClass().getName())).findFirst();
|
||||||
@ -136,6 +150,7 @@ public class JavaTXCompiler {
|
|||||||
else {
|
else {
|
||||||
//throw new ClassNotFoundException("");
|
//throw new ClassNotFoundException("");
|
||||||
}
|
}
|
||||||
|
}
|
||||||
Iterator<RefTypeOrTPHOrWildcardOrGeneric> paraIt= cl.getSuperClass().getParaList().iterator();
|
Iterator<RefTypeOrTPHOrWildcardOrGeneric> paraIt= cl.getSuperClass().getParaList().iterator();
|
||||||
Iterator<GenericTypeVar> tvarVarIt = superclass.getGenerics().iterator();
|
Iterator<GenericTypeVar> tvarVarIt = superclass.getGenerics().iterator();
|
||||||
|
|
||||||
@ -152,22 +167,12 @@ public class JavaTXCompiler {
|
|||||||
.stream()
|
.stream()
|
||||||
.map(fp -> new FormalParameter(fp.getName(), fp.getType().acceptTV(new TypeExchanger(gtvs)), fp.getOffset()))
|
.map(fp -> new FormalParameter(fp.getName(), fp.getType().acceptTV(new TypeExchanger(gtvs)), fp.getOffset()))
|
||||||
.collect(Collectors.toCollection(ArrayList::new)), m.getParameterList().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,
|
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()),
|
//new GenericDeclarationList(newGenericsList, ((GenericDeclarationList)m.getGenerics()).getOffset()),
|
||||||
(GenericDeclarationList)m.getGenerics(),
|
(GenericDeclarationList)m.getGenerics(),
|
||||||
m.getOffset()));
|
m.getOffset()));
|
||||||
}
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
allClasses.addAll(sf.getClasses());
|
allClasses.addAll(sf.getClasses());
|
||||||
}
|
}
|
||||||
|
@ -34,6 +34,7 @@ public class ClassOrInterface extends SyntaxTreeNode implements TypeScope{
|
|||||||
private List<RefType> implementedInterfaces;
|
private List<RefType> implementedInterfaces;
|
||||||
private List<Constructor> constructors;
|
private List<Constructor> constructors;
|
||||||
|
|
||||||
|
|
||||||
public ClassOrInterface(int modifiers, JavaClassName name, List<Field> fielddecl, Optional<Constructor> fieldInitializations, List<Method> methods, List<Constructor> constructors, GenericDeclarationList genericClassParameters,
|
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){
|
RefType superClass, Boolean isInterface, List<RefType> implementedInterfaces, Token offset){
|
||||||
super(offset);
|
super(offset);
|
||||||
@ -50,6 +51,23 @@ public class ClassOrInterface extends SyntaxTreeNode implements TypeScope{
|
|||||||
this.constructors = constructors;
|
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
|
// Gets class name
|
||||||
public JavaClassName getClassName(){
|
public JavaClassName getClassName(){
|
||||||
return this.name;
|
return this.name;
|
||||||
|
@ -26,6 +26,13 @@ public class SourceFile extends SyntaxTreeNode{
|
|||||||
this.imports = imports;
|
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(){
|
public String getPkgName(){
|
||||||
return this.pkgName;
|
return this.pkgName;
|
||||||
}
|
}
|
||||||
|
@ -574,11 +574,12 @@ public class TYPEStmt implements StatementVisitor{
|
|||||||
|
|
||||||
RefTypeOrTPHOrWildcardOrGeneric retType = assumption.getReceiverType(resolver);
|
RefTypeOrTPHOrWildcardOrGeneric retType = assumption.getReceiverType(resolver);
|
||||||
methodConstraint.add(new Pair(forMethod.receiver.getType(), retType,
|
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
|
//Fuer Bytecodegenerierung PL 2020-03-09 wird derzeit nicht benutzt ANFANG
|
||||||
methodConstraint.add(new Pair(forMethod.receiverType, retType,
|
//methodConstraint.add(new Pair(forMethod.receiverType, retType,
|
||||||
PairOperator.EQUALSDOT));
|
// PairOperator.EQUALSDOT));
|
||||||
|
//Fuer Bytecodegenerierung PL 2020-03-09 wird derzeit nicht benutzt ENDE
|
||||||
|
|
||||||
methodConstraint.add(new Pair(assumption.getReturnType(resolver), forMethod.getType(),
|
methodConstraint.add(new Pair(assumption.getReturnType(resolver), forMethod.getType(),
|
||||||
PairOperator.EQUALSDOT));
|
PairOperator.EQUALSDOT));
|
||||||
@ -595,8 +596,9 @@ public class TYPEStmt implements StatementVisitor{
|
|||||||
RefTypeOrTPHOrWildcardOrGeneric assType = assumption.getArgTypes(resolver).get(i);
|
RefTypeOrTPHOrWildcardOrGeneric assType = assumption.getArgTypes(resolver).get(i);
|
||||||
ret.add(new Pair(argType, assType, PairOperator.SMALLERDOT));
|
ret.add(new Pair(argType, assType, PairOperator.SMALLERDOT));
|
||||||
|
|
||||||
//Fuer Bytecodegenerierung PL 2020-03-09 wird derzeit nicht benutzt
|
//Fuer Bytecodegenerierung PL 2020-03-09 wird derzeit nicht benutzt ANFANG
|
||||||
ret.add(new Pair(foMethod.argTypes.get(i), assType, PairOperator.EQUALSDOT));
|
// ret.add(new Pair(foMethod.argTypes.get(i), assType, PairOperator.EQUALSDOT));
|
||||||
|
//Fuer Bytecodegenerierung PL 2020-03-09 wird derzeit nicht benutzt ENDE
|
||||||
}
|
}
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
@ -1813,7 +1813,10 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
|||||||
oderConstraintsOutput.remove(ret);
|
oderConstraintsOutput.remove(ret);
|
||||||
//Set<UnifyPair> retFlat = new HashSet<>();
|
//Set<UnifyPair> retFlat = new HashSet<>();
|
||||||
//ret.stream().forEach(x -> retFlat.addAll(x));
|
//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);
|
result.get(8).add(ret);
|
||||||
first = false;
|
first = false;
|
||||||
}
|
}
|
||||||
@ -1836,7 +1839,10 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
|||||||
// System.out.println("M");
|
// System.out.println("M");
|
||||||
//Set<UnifyPair> retFlat = new HashSet<>();
|
//Set<UnifyPair> retFlat = new HashSet<>();
|
||||||
//ret.stream().forEach(x -> retFlat.addAll(x));
|
//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);
|
result.get(8).add(ret);
|
||||||
first = false;
|
first = false;
|
||||||
}
|
}
|
||||||
|
@ -195,12 +195,14 @@ public class UnifyPair {
|
|||||||
if (other.getBasePair() != basePair || (other.getBasePair() == null && basePair == null)) {
|
if (other.getBasePair() != basePair || (other.getBasePair() == null && basePair == null)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!other.getBasePair().equals(basePair) ||
|
if (!other.getBasePair().equals(basePair) ||
|
||||||
!other.getAllSubstitutions().equals(getAllSubstitutions())) {
|
!other.getAllSubstitutions().equals(getAllSubstitutions())) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
return other.getPairOp() == pairOp
|
return other.getPairOp() == pairOp
|
||||||
&& other.getLhsType().equals(lhs)
|
&& other.getLhsType().equals(lhs)
|
||||||
&& other.getRhsType().equals(rhs);
|
&& other.getRhsType().equals(rhs);
|
||||||
|
Loading…
Reference in New Issue
Block a user