Compare commits

...

16 Commits

Author SHA1 Message Date
9801f8a5ae Merge branch 'targetBytecode' of ssh://gitea.hb.dhbw-stuttgart.de:2221/JavaTX/JavaCompilerCore into targetBytecode
All checks were successful
Build and Test with Maven / Build-and-test-with-Maven (push) Successful in 5m39s
2024-08-07 13:34:03 +02:00
f0b9bea23e Fix #343 (le null check) 2024-08-07 13:33:40 +02:00
ce4347dd96 Fix Y Test #341
All checks were successful
Build and Test with Maven / Build-and-test-with-Maven (push) Successful in 5m20s
2024-08-06 12:42:09 +02:00
7785c2d0aa Fix equals method of ClassOrInterface
Some checks failed
Build and Test with Maven / Build-and-test-with-Maven (push) Failing after 6m48s
2024-08-05 11:54:13 +02:00
a654f55deb Fix yTest
All checks were successful
Build and Test with Maven / Build-and-test-with-Maven (push) Successful in 4m45s
2024-07-25 17:05:27 +02:00
pl@gohorb.ba-horb.de
7037bdf9ef modified: src/main/java/de/dhbwstuttgart/parser/SyntaxTreeGenerator/FCGenerator.java
All checks were successful
Build and Test with Maven / Build-and-test-with-Maven (push) Successful in 5m16s
2024-07-24 23:31:13 +02:00
pl@gohorb.ba-horb.de
d9860497df Merge branch 'targetBytecode' of ssh://gitea.hb.dhbw-stuttgart.de:2222/JavaTX/JavaCompilerCore into targetBytecode
Some checks failed
Build and Test with Maven / Build-and-test-with-Maven (push) Failing after 5m38s
src/test/java/AllgemeinTest.java
2024-07-24 23:25:07 +02:00
pl@gohorb.ba-horb.de
fdffc11580 modified: resources/AllgemeinTest/Box.jav
deleted:    resources/bytecode/javFiles/Box.java
	modified:   src/test/java/AllgemeinTest.java
2024-07-24 23:23:39 +02:00
pl@gohorb.ba-horb.de
c10de35ca2 new file: resources/AllgemeinTest/Bar.java
Some checks failed
Build and Test with Maven / Build-and-test-with-Maven (push) Failing after 5m25s
2024-07-24 18:28:07 +02:00
pl@gohorb.ba-horb.de
56b73332c0 modified: pom.xml
new file:   resources/AllgemeinTest/Foo.jav
	modified:   src/main/java/de/dhbwstuttgart/parser/SyntaxTreeGenerator/FCGenerator.java
2024-07-24 18:27:32 +02:00
pl@gohorb.ba-horb.de
bdcd5ea3cf Merge branch 'targetBytecode' of https://gitea.hb.dhbw-stuttgart.de/JavaTX/JavaCompilerCore into targetBytecode 2024-07-24 12:35:43 +02:00
pl@gohorb.ba-horb.de
4dba867f9e Merge branch 'targetBytecode' of ssh://gitea.hb.dhbw-stuttgart.de:2222/JavaTX/JavaCompilerCore into targetBytecode 2024-06-14 11:28:05 +02:00
pl@gohorb.ba-horb.de
06caf0ff66 Merge branch 'targetBytecode' of ssh://gohorb.ba-horb.de/bahome/projekt/git/JavaCompilerCore into targetBytecode 2024-06-14 11:27:14 +02:00
pl@gohorb.ba-horb.de
5d03995f10 Merge branch 'targetBytecode' of https://gitea.hb.dhbw-stuttgart.de/JavaTX/JavaCompilerCore into targetBytecode 2024-05-27 17:44:29 +02:00
pl@gohorb.ba-horb.de
1bc58573c7 modified: src/main/java/de/dhbwstuttgart/core/JavaTXCompiler.java
modified:   src/test/java/AllgemeinTest.java
2024-05-27 17:35:59 +02:00
Pluemicke Martin
3d2b935c60 Merge branch 'targetBytecode' of https://gitea.hb.dhbw-stuttgart.de/JavaTX/JavaCompilerCore into targetBytecode 2024-05-14 22:53:08 +02:00
17 changed files with 134 additions and 57 deletions

View File

@ -54,8 +54,8 @@ http://maven.apache.org/maven-v4_0_0.xsd">
<version>3.11.0</version>
<configuration>
<compilerArgs>--enable-preview</compilerArgs>
<source>22</source>
<target>22</target>
<source>21</source>
<target>21</target>
</configuration>
</plugin>
<plugin>

View File

@ -0,0 +1,10 @@
public class Bar{
void visit(Object o){
System.out.println("Object");
}
void visit(Bla f){
System.out.println("Foo");
}
}

View File

@ -1,8 +1,9 @@
class Box<A> {
public class Box<A> {
A a;
public Box() { }
public Box(A a) {
this.a = a;
//this.a = a;
}
}

View File

@ -0,0 +1,6 @@
public class Foo{
public accept(Bar b){
b.visit(this);
}
}

View File

@ -1,3 +0,0 @@
class Box<A> {
void m(A a) { }
}

View File

@ -0,0 +1,2 @@
public record Bug343() {
}

View File

@ -2,41 +2,21 @@ import java.lang.Integer;
public class Y {
y;
//factorial;
public Y() {
y = f -> t -> f.apply(y.apply(f)).apply(t);
//factorial = y.apply(f -> n -> { if (n == 0) return 1; else return n * f.apply(n - 1); });
}
/*
getY() {
return y;
}
*/
}
/*
class fac1 {
factorial;
fac1() {
var y;
y = new Y<Integer,Integer,Integer,Integer,Integer>().getY();
factorial = y.apply(f -> n -> { if (n == 0) return 1; else return n * f.apply(n - 1); });
y = f -> t -> f.apply(y.apply(f)).apply(t);
}
}
ergibt Parse-Error
class fac1 {
factorial;
fac1() {
public class Fac1 {
public factorial;
public Fac1() {
var y;
y = new Y<>().y;
var tmp = new Y<>(); // TODO Having new Y<>().y on one line doesn't work, see FIXME in StatementGenerator
y = tmp.y;
factorial = y.apply(f -> n -> { if (n == 0) return 1; else return n * f.apply(n - 1); });
}
public static void main(String args[]) {
System.out.println(new fac1().factorial.apply(3));
public fac(v) {
return factorial.apply(v);
}
}
*/
}

View File

@ -1,11 +1,13 @@
package de.dhbwstuttgart.bytecode;
import de.dhbwstuttgart.syntaxtree.statement.Break;
import de.dhbwstuttgart.target.tree.TargetGeneric;
import de.dhbwstuttgart.target.tree.type.*;
import org.objectweb.asm.ClassWriter;
import org.objectweb.asm.MethodVisitor;
import org.objectweb.asm.Type;
import java.sql.Array;
import java.util.*;
import java.util.stream.Collectors;
import java.util.stream.Stream;
@ -35,19 +37,33 @@ public class FunNGenerator {
public List<TargetType> parameters = new ArrayList<>();
final String descriptor;
public final List<TargetType> inParams;
public final List<TargetType> realParams;
public GenericParameters(List<TargetType> params, int numReturns) {
this.inParams = params;
this.realParams = params;
this.inParams = flattenTypeParams(params);
var type = new TargetRefType(FunNGenerator.getSuperClassName(params.size() - 1, numReturns), params);
descriptor = applyDescriptor(type, this);
}
private static List<TargetType> flattenTypeParams(List<TargetType> params) {
var res = new ArrayList<TargetType>();
for (var param : params) {
if (param instanceof TargetSpecializedType tspec) {
res.addAll(flattenTypeParams(tspec.params()));
} else {
res.add(param);
}
}
return res;
}
public TargetType getReturnType() {
return FunNGenerator.getReturnType(inParams);
return FunNGenerator.getReturnType(realParams);
}
public List<TargetType> getArguments() {
return FunNGenerator.getArguments(inParams);
return FunNGenerator.getArguments(realParams);
}
}
@ -162,7 +178,7 @@ public class FunNGenerator {
}
public static String getSpecializedClassName(GenericParameters gep) {
return getSpecializedClassName(getArguments(gep.inParams), getReturnType(gep.inParams));
return getSpecializedClassName(gep.getArguments(), gep.getReturnType());
}
public static String getSpecializedClassName(List<TargetType> argumentTypes, TargetType returnType) {

View File

@ -66,7 +66,7 @@ public class JavaTXCompiler {
Boolean resultmodel = true;
public final Map<File, SourceFile> sourceFiles = new HashMap<>();
Boolean log = true; //gibt an ob ein Log-File nach System.getProperty("user.dir")+""/logFiles/"" geschrieben werden soll?
Boolean log = false; //gibt an ob ein Log-File nach System.getProperty("user.dir")+""/logFiles/"" geschrieben werden soll?
public volatile UnifyTaskModel usedTasks = new UnifyTaskModel();
public final DirectoryClassLoader classLoader;

View File

@ -158,7 +158,8 @@ public class FCGenerator {
}
/**
* Tauscht die GTVs in einem Typ gegen die entsprechenden Typen in der übergebenen Map aus.
* Tauscht die GTVs in einem Typ gegen die entsprechenden Typen in der übergebenen Map aus auf der direkten Argumentebene.
* Hier sind keine Wildcards zulässig
*/
private static class TypeExchanger implements TypeVisitor<RefTypeOrTPHOrWildcardOrGeneric>{
@ -172,7 +173,7 @@ public class FCGenerator {
public RefTypeOrTPHOrWildcardOrGeneric visit(RefType refType) {
List<RefTypeOrTPHOrWildcardOrGeneric> params = new ArrayList<>();
for(RefTypeOrTPHOrWildcardOrGeneric param : refType.getParaList()){
params.add(param.acceptTV(this));
params.add(param.acceptTV(new TypeExchangerInner(gtvs)));
}
RefTypeOrTPHOrWildcardOrGeneric ret = new RefType(refType.getName(), params, new NullToken());
return ret;
@ -201,4 +202,51 @@ public class FCGenerator {
}
}
/**
* Tauscht die GTVs in einem Typ gegen die entsprechenden Typen in der übergebenen Map aus auf den Argumenten der Argumente.
* Hier sind Wildcards zulässig
*/
private static class TypeExchangerInner implements TypeVisitor<RefTypeOrTPHOrWildcardOrGeneric>{
private final HashMap<String, RefTypeOrTPHOrWildcardOrGeneric> gtvs;
TypeExchangerInner(HashMap<String, RefTypeOrTPHOrWildcardOrGeneric> gtvs){
this.gtvs = gtvs;
}
@Override
public RefTypeOrTPHOrWildcardOrGeneric visit(RefType refType) {
List<RefTypeOrTPHOrWildcardOrGeneric> params = new ArrayList<>();
for(RefTypeOrTPHOrWildcardOrGeneric param : refType.getParaList()){
params.add(param.acceptTV(this));
}
RefTypeOrTPHOrWildcardOrGeneric ret = new RefType(refType.getName(), params, new NullToken());
return ret;
}
@Override
public RefTypeOrTPHOrWildcardOrGeneric visit(SuperWildcardType superWildcardType) {
return superWildcardType;
}
@Override
public RefTypeOrTPHOrWildcardOrGeneric visit(TypePlaceholder typePlaceholder) {
throw new DebugException("Dieser Fall darf nicht auftreten");
}
@Override
public RefTypeOrTPHOrWildcardOrGeneric visit(ExtendsWildcardType extendsWildcardType) {
return extendsWildcardType;
}
@Override
public RefTypeOrTPHOrWildcardOrGeneric visit(GenericRefType genericRefType) {
if(! gtvs.containsKey(genericRefType.getParsedName()))
throw new DebugException("Dieser Fall darf nicht auftreten");
return gtvs.get(genericRefType.getParsedName());
}
}
}

View File

@ -697,6 +697,7 @@ public class StatementGenerator {
if (!Objects.isNull(expr.methodCall())) {
return convert(expr.methodCall(), expr.expression(), offset);
} else if (!Objects.isNull(expr.identifier())) {
// FIXME This is not the right way of handling any of this
return generateLocalOrFieldVarOrClassName(expr.getText(), offset);
} else {
// Für alle anderen Optionen, wie Feldzugriff, Aufrufe von super oder explizite
@ -779,6 +780,7 @@ public class StatementGenerator {
* @return
*/
private Expression generateLocalOrFieldVarOrClassName(String expression, Token offset) {
// FIXME Why does this take a String argument???
String[] parts = expression.split("\\.");
if (parts.length < 2) {
// Check for localVar:

View File

@ -254,7 +254,10 @@ public class SyntaxTreeGenerator {
List<RefType> implementedInterfaces = new ArrayList<>();
List<Pattern> constructorParameters = new ArrayList<>();
List<Statement> constructorStatements = new ArrayList<>();
for (RecordComponentContext component : recordDeclaration.recordHeader().recordComponentList().recordComponent()) {
List<Java17Parser.RecordComponentContext> components = recordDeclaration.recordHeader().recordComponentList() != null ?
recordDeclaration.recordHeader().recordComponentList().recordComponent(): List.of();
for (RecordComponentContext component : components) {
int fieldmodifiers = allmodifiers.get("private") + allmodifiers.get("final");
String fieldname = component.identifier().getText();
Token fieldoffset = component.getStart();

View File

@ -188,9 +188,8 @@ public class ClassOrInterface extends SyntaxTreeNode implements TypeScope {
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
ClassOrInterface that = (ClassOrInterface) o;
return Objects.equals(name, that.name);
if (!(o instanceof ClassOrInterface other)) return false;
return Objects.equals(name, other.name);
}
@Override

View File

@ -34,6 +34,7 @@ public class ASTFactory {
private static final HashMap<java.lang.Class, ClassOrInterface> cache = new HashMap<>();
public static ClassOrInterface createClass(java.lang.Class jreClass) {
System.out.println(jreClass);
if (cache.containsKey(jreClass))
return cache.get(jreClass);
@ -173,6 +174,7 @@ public class ASTFactory {
superClass = (RefType) createType(java.lang.Object.class);
}
List<RefType> implementedInterfaces = new ArrayList<>();
System.out.println(jreClass);
for (Type jreInterface : jreClass.getGenericInterfaces()) {
implementedInterfaces.add((RefType) createType(jreInterface));
}

View File

@ -652,14 +652,12 @@ public abstract class GenerateGenerics {
}
void normalize(Set<Pair> result, Set<Pair> classGenerics, Set<TPH> usedTphs) {
outer:
for (var tph : usedTphs) {
for (var p1 : new HashSet<>(result)) {
if (p1 instanceof PairLT ptph && ptph.left.equals(ptph.right))
result.remove(p1); // TODO This is a bit strange
if (p1.left.equals(tph)) continue outer;
}
for (var p1 : new HashSet<>(result)) {
if (p1 instanceof PairLT ptph && ptph.left.resolve().equals(ptph.right.resolve()))
result.remove(p1); // TODO This is a bit strange
}
for (var tph : usedTphs) {
if (classGenerics == null || classGenerics.stream().noneMatch((pair) -> pair.left.equals(tph)))
addToPairs(result, new PairEQ(tph, ASTToTargetAST.OBJECT));
}

View File

@ -66,7 +66,9 @@ public class AllgemeinTest {
//String className = "WildcardList";
//String className = "List";
//String className = "Box";
String className = "GenBox";
//String className = "GenBox";
//String className = "InnerInf";
String className = "Foo";
//PL 2019-10-24: genutzt fuer unterschiedliche Tests
path = System.getProperty("user.dir")+"/resources/AllgemeinTest/" + className + ".jav";
//path = System.getProperty("user.dir")+"/src/test/resources/AllgemeinTest/Overloading_Generics.jav";

View File

@ -602,7 +602,11 @@ public class TestComplete {
@Test
public void yTest() throws Exception {
var classFiles = generateClassFiles(new ByteArrayClassLoader(), "Y.jav");
var instance = classFiles.get("Y").getDeclaredConstructor().newInstance();
var fac1 = classFiles.get("Fac1");
var instance = fac1.getDeclaredConstructor().newInstance();
var fac = fac1.getDeclaredMethod("fac", Integer.class);
assertEquals(fac.invoke(instance, 10), 3628800);
}
@Test
@ -1147,4 +1151,11 @@ public class TestComplete {
var clazz = classFiles.get("Bug338");
var instance = clazz.getDeclaredConstructor().newInstance();
}
@Test
public void testBug343() throws Exception {
var classFiles = generateClassFiles(new ByteArrayClassLoader(), "Bug343.jav");
var clazz = classFiles.get("Bug343");
var instance = clazz.getDeclaredConstructor().newInstance();
}
}