Merge branch 'bytecodeGenericsSecond' of ssh://gohorb.ba-horb.de/bahome/projekt/git/JavaCompilerCore into bytecodeGenericsSecond

This commit is contained in:
pl@gohorb.ba-horb.de 2021-01-29 22:49:07 +01:00
commit b942e508fc
6 changed files with 65 additions and 65 deletions

View File

@ -3,16 +3,14 @@
*/
package de.dhbwstuttgart.bytecode.genericsGenerator;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Optional;
import java.util.*;
import de.dhbwstuttgart.bytecode.TPHExtractor;
import de.dhbwstuttgart.bytecode.constraint.ExtendsConstraint;
import de.dhbwstuttgart.bytecode.constraint.TPHConstraint;
import de.dhbwstuttgart.bytecode.genericsGeneratorTypes.*;
import de.dhbwstuttgart.bytecode.insertGenerics.ClassConstraint;
import de.dhbwstuttgart.bytecode.insertGenerics.FamilyOfGeneratedGenerics;
import de.dhbwstuttgart.bytecode.genericsGeneratorTypes.GenericGenratorResultForSourceFile;
import de.dhbwstuttgart.bytecode.genericsGeneratorTypes.GenericsGeneratorResultForClass;
import de.dhbwstuttgart.bytecode.genericsGeneratorTypes.MethodAndConstraints;
import de.dhbwstuttgart.bytecode.utilities.MethodAndTPH;
import de.dhbwstuttgart.bytecode.utilities.MethodUtility;
import de.dhbwstuttgart.bytecode.utilities.Resolver;
@ -127,6 +125,7 @@ public class GeneratedGenericsFinder implements ASTVisitor {
ConstraintsSimplierResult simplifiedConstraints = null;
GenericsGeneratorResultForClass ggResult = null;
GenericsGeneratorResultForClass ggResultAlternative = null;
for (int i = 0; i < listOfResultSetsList.size(); i++) {
resultSet = listOfResultSetsList.get(i);
@ -160,7 +159,35 @@ public class GeneratedGenericsFinder implements ASTVisitor {
if(ggResult != null)
generatedGenericsForSF.addGenericGeneratorResultClass(ggResult);
System.out.println("ddd");
List<GenericsGeneratorResult> listOfClassCons = new ArrayList<>();
for(TPHConstraint clCons: fogg.classConstraints) {
// ExtendsConstraint ec = new ExtendsConstraint(clCons.getLeft(), clCons.getRight());
GenericsGeneratorResult ggR = new GenericsGeneratorResult(clCons, new HashSet<>());
listOfClassCons.add(ggR);
}
GenericGeneratorResultsForAllMethods ggRfaM = null;
List<MethodAndConstraints> listOfMethAndCons = new ArrayList<>();
for(String methID: fogg.methodConstraintsWithPosition.keySet()) {
List<GenericsGeneratorResult> listOfGGR = new ArrayList<>();
for(TPHConstraint methCons: fogg.methodConstraintsWithPosition.get(methID)) {
// ExtendsConstraint ec = new ExtendsConstraint(methCons.getLeft(),methCons.getRight());
GenericsGeneratorResult ggR = new GenericsGeneratorResult(methCons, new HashSet<>());
listOfGGR.add(ggR);
}
MethodAndConstraints mac = new MethodAndConstraints(methID, listOfGGR);
listOfMethAndCons.add(mac);
}
ggRfaM = new GenericGeneratorResultsForAllMethods(listOfMethAndCons);
ggResultAlternative = new GenericsGeneratorResultForClass(className, listOfClassCons, ggRfaM);
if(ggResultAlternative != null) {
generatedGenericsForSF.addGenericGeneratorResultClass(ggResultAlternative);
System.out.println(generatedGenericsForSF);
}
System.out.println(ggResultAlternative);
}

View File

@ -128,8 +128,8 @@ public class FamilyOfGeneratedGenerics {
for(String curMeth: tempMethodConstraintsWithPosition.keySet()){
for(int i=0; i<tempMethodConstraintsWithPosition.get(curMeth).size(); i++) {
MethodConstraint currentMC = tempMethodConstraintsWithPosition.get(curMeth).get(i);
if(currentMC.getRight()!= "Object" && !compareTphsOfConstraints(currentMC.getRight(), cs_cl) && !compareTphsOfConstraints(currentMC.getRight(), tempMethodConstraintsWithPosition.get(curMeth))) {
MethodConstraint mc = new MethodConstraint(currentMC.getRight(), "Object", Relation.EXTENDS);
if(currentMC.getRight()!= Object.class.getTypeName() && !compareTphsOfConstraints(currentMC.getRight(), cs_cl) && !compareTphsOfConstraints(currentMC.getRight(), tempMethodConstraintsWithPosition.get(curMeth))) {
MethodConstraint mc = new MethodConstraint(currentMC.getRight(), Object.class.getTypeName(), Relation.EXTENDS);
tempMethodConstraintsWithPosition.get(curMeth).add(mc);
}
}
@ -212,7 +212,7 @@ public class FamilyOfGeneratedGenerics {
boolean hasSmallerTVInClCons = (posOfTphs.containsKey(cCons.getRight()) && cCons.getRight() == tph && cCons.getLeft() != null);
if( ((tvInField || hasSmallerTVInClCons) && cCons.getRel()==Relation.EXTENDS) &&
!checkUpperBound(allConstraints, tph) && allCons.getRel()==Relation.EXTENDS) {
ClassConstraint consToAdd = new ClassConstraint(tph, "Object", Relation.EXTENDS);
ClassConstraint consToAdd = new ClassConstraint(tph, Object.class.getTypeName(), Relation.EXTENDS);
if (!checkForDuplicates(consToAdd, tempCC)){
tempCC.add(consToAdd);
}
@ -312,7 +312,7 @@ public class FamilyOfGeneratedGenerics {
for(PairTphMethod pair: posOfTphs.get(tph)) {
for(TPHConstraint allCons: allConstraints) {
if((pair.fst.equals(PositionFinder.Position.METHOD) || pair.fst.equals(PositionFinder.Position.CONSTRUCTOR)) && !checkUpperBound(allConstraints,tph)) {
MethodConstraint consToAdd = new MethodConstraint(tph, "Object", Relation.EXTENDS);
MethodConstraint consToAdd = new MethodConstraint(tph, Object.class.getTypeName(), Relation.EXTENDS);
if (!checkForDuplicates(consToAdd, tempMC)) {
tempMC.add(consToAdd);
}
@ -326,7 +326,7 @@ public class FamilyOfGeneratedGenerics {
}
for(TPHConstraint mc1: tempMCObject1) {
if(tph==mc1.getRight() && !checkUpperBound(tempMCObject1,tph)) {
MethodConstraint consToAdd = new MethodConstraint(tph, "Object", Relation.EXTENDS);
MethodConstraint consToAdd = new MethodConstraint(tph, Object.class.getTypeName(), Relation.EXTENDS);
if (!checkForDuplicates(consToAdd, tempMC)) {
tempMC.add(consToAdd);
}

View File

@ -215,6 +215,7 @@ public abstract class AbstractASTWalker implements ASTVisitor{
@Override
public void visit(Return aReturn) {
aReturn.retexpr.accept(this);
aReturn.retexpr.getType().accept(this);
}
@Override

View File

@ -1,30 +0,0 @@
package insertGenerics;
import de.dhbwstuttgart.bytecode.genericsGenerator.GeneratedGenericsFinder;
import de.dhbwstuttgart.core.JavaTXCompiler;
import de.dhbwstuttgart.syntaxtree.ClassOrInterface;
import de.dhbwstuttgart.syntaxtree.SourceFile;
import de.dhbwstuttgart.typeinference.result.ResultSet;
import junit.framework.TestResult;
import org.junit.Test;
import java.io.File;
import java.io.IOException;
import java.util.List;
public class MethodsTest {
public static final String rootDirectory = System.getProperty("user.dir")+"/src/test/resources/insertGenericsJav/";
public static final String fileDirectory = rootDirectory + "TestGGFinder.jav";
@Test
public void testVisit(ClassOrInterface coi) throws IOException, ClassNotFoundException {
JavaTXCompiler compiler = new JavaTXCompiler(new File(fileDirectory));
SourceFile sf = compiler.sourceFiles.get(compiler.sourceFiles.keySet());
List<ResultSet> results = compiler.typeInference();
GeneratedGenericsFinder ggf = new GeneratedGenericsFinder(sf, results);
ClassOrInterface coiHere = coi;
ggf.visit(coiHere);
//assert results.size()>0;
}
}

View File

@ -20,13 +20,13 @@ import java.util.HashSet;
import java.util.List;
import java.util.Set;
public class TryTest {
public class TestTwoArgs2 {
public static final String rootDirectory = System.getProperty("user.dir")+"/src/test/resources/insertGenericsJav/";
@Test
public void ggFinder() throws IOException, ClassNotFoundException {
execute(new File(rootDirectory+"TestGGFinder.jav"));
execute(new File(rootDirectory+"TestTwoArgs2.jav"));
}
private static class TestResultSet{
@ -34,25 +34,9 @@ public class TryTest {
}
public TestResultSet execute(File fileToTest) throws IOException, ClassNotFoundException {
//filesToTest.add(new File(rootDirectory+"fc.jav"));
//filesToTest.add(new File(rootDirectory+"Lambda.jav"));
//filesToTest.add(new File(rootDirectory+"Lambda2.jav"));
//filesToTest.add(new File(rootDirectory+"Lambda3.jav"));
//filesToTest.add(new File(rootDirectory+"Vector.jav"));
//filesToTest.add(new File(rootDirectory+"Generics.jav"));
//filesToTest.add(new File(rootDirectory+"MethodsEasy.jav"));
//filesToTest.add(new File(rootDirectory+"Matrix.jav"));
//filesToTest.add(new File(rootDirectory+"Import.jav"));
// //filesToTest.add(new File(rootDirectory+"Faculty.jav"));
// //filesToTest.add(new File(rootDirectory+"mathStruc.jav"));
// //filesToTest.add(new File(rootDirectory+"test.jav"));
JavaTXCompiler compiler = new JavaTXCompiler(fileToTest);
for(File f : compiler.sourceFiles.keySet()){
SourceFile sf = compiler.sourceFiles.get(f);
// System.out.println(ASTTypePrinter.print(sf));
// System.out.println("---------------------------1");
// System.out.println(ASTPrinter.print(sf));
// System.out.println("---------------------------2");
}
List<ResultSet> results = compiler.typeInference();
List<GenericGenratorResultForSourceFile> simplifyResultsForAllSourceFiles = compiler.getGeneratedGenericResultsForAllSourceFiles(results);
@ -60,9 +44,7 @@ public class TryTest {
for(File f : compiler.sourceFiles.keySet()){
SourceFile sf = compiler.sourceFiles.get(f);
System.out.println(ASTTypePrinter.print(sf));
// System.out.println("---------------------------3");
System.out.println(ASTPrinter.print(sf));
// System.out.println("---------------------------4");
//List<ResultSet> results = compiler.typeInference(); PL 2017-10-03 vor die For-Schleife gezogen
assert results.size()>0;
Set<String> insertedTypes = new HashSet<>();
@ -75,9 +57,7 @@ public class TryTest {
}
}
for(String s : insertedTypes){
System.out.println("---------------------------51");
System.out.println(s);
System.out.println("---------------------------52");
}
}
return new TestResultSet();

View File

@ -0,0 +1,22 @@
class TestTwoArgs {
a;
id(b) {
var c = b;
return c;
}
setA(x) {
a = x;
return a;
}
m(x,y) {
x = id(y);
return x;
}
main(x,y) {
return m(id(x),setA(y));
}
}