diff --git a/pom.xml b/pom.xml
index f356ce82..120f4204 100644
--- a/pom.xml
+++ b/pom.xml
@@ -29,14 +29,14 @@ http://maven.apache.org/maven-v4_0_0.xsd">
2.6
- com.google.guava
- guava
- 22.0
+ io.github.classgraph
+ classgraph
+ 4.8.172
- org.reflections
- reflections
- 0.9.11
+ com.google.guava
+ guava
+ 33.2.0-jre
diff --git a/resources/AllgemeinTest/Box.jav b/resources/AllgemeinTest/Box.jav
index bd5c39e5..b2716354 100644
--- a/resources/AllgemeinTest/Box.jav
+++ b/resources/AllgemeinTest/Box.jav
@@ -2,9 +2,7 @@ class Box {
A a;
- Box(A a) {
+ public Box(A a) {
this.a = a;
}
-}
-
-
+}
\ No newline at end of file
diff --git a/resources/bytecode/javFiles/Box.jav b/resources/bytecode/javFiles/Box.jav
index 4859d611..95b869ab 100644
--- a/resources/bytecode/javFiles/Box.jav
+++ b/resources/bytecode/javFiles/Box.jav
@@ -1,7 +1,9 @@
-class B { }
-class Box_Main extends B {
- m(b) {
- b.m(new Box_Main());
- b.m(new B());
- }
-}
+public class Box {
+
+ A a;
+
+ public Box() { }
+ public Box(A a) {
+ //this.a = a;
+ }
+}
\ No newline at end of file
diff --git a/resources/bytecode/javFiles/Bug333.jav b/resources/bytecode/javFiles/Bug333.jav
new file mode 100644
index 00000000..244e8a66
--- /dev/null
+++ b/resources/bytecode/javFiles/Bug333.jav
@@ -0,0 +1,11 @@
+import java.lang.String;
+
+public class Bug333 {
+ public static String Bar = "Bar";
+}
+
+class Bar {
+ public bar() {
+ String s = Bug333.Bar;
+ }
+}
\ No newline at end of file
diff --git a/resources/bytecode/javFiles/Bug338.jav b/resources/bytecode/javFiles/Bug338.jav
new file mode 100644
index 00000000..fa846e95
--- /dev/null
+++ b/resources/bytecode/javFiles/Bug338.jav
@@ -0,0 +1,11 @@
+import java.util.List;
+import java.lang.Integer;
+import java.lang.String;
+import java.lang.Object;
+import java.util.List;
+
+public class Bug338 {
+ public hashCode() {
+ return List.of(42);
+ }
+}
\ No newline at end of file
diff --git a/resources/bytecode/javFiles/ImportWildcard.jav b/resources/bytecode/javFiles/ImportWildcard.jav
new file mode 100644
index 00000000..a64e9ae2
--- /dev/null
+++ b/resources/bytecode/javFiles/ImportWildcard.jav
@@ -0,0 +1,5 @@
+import java.lang.*;
+
+public class ImportWildcard {
+ m(a, b) { return a * b; }
+}
\ No newline at end of file
diff --git a/resources/bytecode/javFiles/While.jav b/resources/bytecode/javFiles/While.jav
index df259cf5..cdd41f51 100644
--- a/resources/bytecode/javFiles/While.jav
+++ b/resources/bytecode/javFiles/While.jav
@@ -9,4 +9,13 @@ public class While {
}
return x;
}
+
+ public m2() {
+ int i = 0;
+ do {
+ ++i;
+ } while(i < 10);
+
+ return i;
+ }
}
\ No newline at end of file
diff --git a/src/main/java/de/dhbwstuttgart/bytecode/Codegen.java b/src/main/java/de/dhbwstuttgart/bytecode/Codegen.java
index b3c1fe20..8df566b9 100644
--- a/src/main/java/de/dhbwstuttgart/bytecode/Codegen.java
+++ b/src/main/java/de/dhbwstuttgart/bytecode/Codegen.java
@@ -978,6 +978,27 @@ public class Codegen {
mv.visitLabel(end);
break;
}
+ case TargetDo _do: {
+ Label start = new Label();
+ Label end = new Label();
+ Label check = new Label();
+
+ var env = new BreakEnv();
+ env.startLabel = check;
+ env.endLabel = end;
+
+ mv.visitLabel(start);
+ state.breakStack.push(env);
+ generate(state, _do.body());
+ state.breakStack.pop();
+
+ mv.visitLabel(check);
+ generate(state, _do.cond());
+ mv.visitJumpInsn(IFEQ, end);
+ mv.visitJumpInsn(GOTO, start);
+ mv.visitLabel(end);
+ break;
+ }
case TargetIf _if: {
generate(state, _if.cond());
Label _else = new Label();
diff --git a/src/main/java/de/dhbwstuttgart/core/JavaTXCompiler.java b/src/main/java/de/dhbwstuttgart/core/JavaTXCompiler.java
index d2f5ed5e..6b2f593a 100644
--- a/src/main/java/de/dhbwstuttgart/core/JavaTXCompiler.java
+++ b/src/main/java/de/dhbwstuttgart/core/JavaTXCompiler.java
@@ -98,7 +98,7 @@ public class JavaTXCompiler {
}
if (outputPath != null) path.add(outputPath);
classLoader = new DirectoryClassLoader(path, ClassLoader.getSystemClassLoader());
- environment = new CompilationEnvironment(sources);
+ environment = new CompilationEnvironment(sources, classLoader);
classPath = path;
this.outputPath = outputPath;
diff --git a/src/main/java/de/dhbwstuttgart/environment/CompilationEnvironment.java b/src/main/java/de/dhbwstuttgart/environment/CompilationEnvironment.java
index 4b802fe5..ad16e766 100644
--- a/src/main/java/de/dhbwstuttgart/environment/CompilationEnvironment.java
+++ b/src/main/java/de/dhbwstuttgart/environment/CompilationEnvironment.java
@@ -34,7 +34,7 @@ public class CompilationEnvironment {
*
* @param sourceFiles die zu kompilierenden Dateien
*/
- public CompilationEnvironment(List sourceFiles) {
+ public CompilationEnvironment(List sourceFiles, DirectoryClassLoader classLoader) {
/**
* Java 9 bringt einige Ă„nderungen am Classloader So funktioniert der BootClassLoader nicht mehr. hier gibts ein paar Quellen zum nachlesen: http://java9.wtf/class-loading/ https://stackoverflow.com/questions/46494112/classloaders-hierarchy-in-java-9
*
@@ -54,7 +54,7 @@ public class CompilationEnvironment {
// librarys = Arrays.asList(loader.getURLs());
this.sourceFiles = sourceFiles;
- this.packageCrawler = new PackageCrawler(librarys);
+ this.packageCrawler = new PackageCrawler(classLoader);
}
public void addClassesToRegistry(JavaClassRegistry registry, SourceFileContext tree, File sourceFile, JavaTXCompiler compiler) throws ClassNotFoundException, IOException {
@@ -104,12 +104,4 @@ public class CompilationEnvironment {
return packageName;
}
- public List getAllAvailableClasses() {
- List ret = new ArrayList<>();
- for (Class c : new PackageCrawler(librarys).getAllAvailableClasses()) {
- ret.add(ASTFactory.createClass(c));
- }
- return ret;
- }
-
}
diff --git a/src/main/java/de/dhbwstuttgart/environment/DirectoryClassLoader.java b/src/main/java/de/dhbwstuttgart/environment/DirectoryClassLoader.java
index f3d87641..8fba019a 100644
--- a/src/main/java/de/dhbwstuttgart/environment/DirectoryClassLoader.java
+++ b/src/main/java/de/dhbwstuttgart/environment/DirectoryClassLoader.java
@@ -5,31 +5,61 @@ import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLClassLoader;
-import java.nio.file.Files;
-import java.nio.file.Path;
+import java.nio.file.*;
+import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
public class DirectoryClassLoader extends URLClassLoader implements IByteArrayClassLoader {
- public DirectoryClassLoader(File directory, java.lang.ClassLoader parent) {
- super(generateURLArray(dirToURL(directory)), parent);
- }
+// public DirectoryClassLoader(File directory, java.lang.ClassLoader parent) {
+// super(generateURLArray(dirToURL(directory)), parent);
+// }
public DirectoryClassLoader(List directory, java.lang.ClassLoader parent) {
- super(directory.stream().map(DirectoryClassLoader::dirToURL).collect(Collectors.toList()).toArray(new URL[0]), parent);
+ super(directory.stream().map(DirectoryClassLoader::dirToURL).flatMap(List::stream).collect(Collectors.toList()).toArray(new URL[0]), parent.getParent());
}
private static URL[] generateURLArray(URL url) {
return new URL[]{url};
}
- private static URL dirToURL(File url){
- if(!url.isDirectory())throw new RuntimeException(url.toString() + " is not a directory");
- try {
- return url.toURI().toURL();
- } catch (MalformedURLException e) {
- throw new RuntimeException(e);
+ private static List dirToURL(File file) {
+ //if(!url.isDirectory())throw new RuntimeException(url.toString() + " is not a directory");
+
+ Path dir;
+ if (file.isDirectory()) {
+ try {
+ return List.of(file.toURI().toURL()); // if file is a directory, use it as is
+ } catch (MalformedURLException e) {
+ e.printStackTrace();
+ return List.of();
+ }
}
+
+ dir = file.toPath().getParent(); // if file is not a directory, get its parent directory
+ String pattern = file.toPath().getFileName().toString(); // use the file name as a glob pattern
+
+ List urls = new ArrayList<>();
+
+ try {
+ urls = Files.walk(dir)
+ .filter(Files::isRegularFile) // only consider files (not directories)
+ .filter(path -> {
+ PathMatcher matcher = FileSystems.getDefault().getPathMatcher("glob:" + pattern);
+ return matcher.matches(path.getFileName()); // match the file name against the pattern
+ })
+ .map(path -> {
+ try {
+ return path.toUri().toURL();
+ } catch (MalformedURLException e) {
+ throw new RuntimeException(e);
+ }
+ }) // convert the path to a URL
+ .toList(); // print the path of each matching file
+ } catch (IOException | RuntimeException e) {
+ e.printStackTrace();
+ }
+ return urls;
}
@Override
diff --git a/src/main/java/de/dhbwstuttgart/environment/PackageCrawler.java b/src/main/java/de/dhbwstuttgart/environment/PackageCrawler.java
index 646440b1..f645c3e9 100644
--- a/src/main/java/de/dhbwstuttgart/environment/PackageCrawler.java
+++ b/src/main/java/de/dhbwstuttgart/environment/PackageCrawler.java
@@ -1,17 +1,10 @@
package de.dhbwstuttgart.environment;
-import java.net.URL;
+import io.github.classgraph.ClassGraph;
+import io.github.classgraph.ScanResult;
+
import java.util.*;
-import org.reflections.Reflections;
-import org.reflections.scanners.ResourcesScanner;
-import org.reflections.scanners.SubTypesScanner;
-import org.reflections.util.ConfigurationBuilder;
-import org.reflections.util.FilterBuilder;
-
-import de.dhbwstuttgart.parser.scope.JavaClassName;
-import org.reflections.vfs.SystemDir;
-
/**
* Hilft beim Durchsuchen von Packages
* Benutzt die Reflections-Library (https://github.com/ronmamo/reflections)
@@ -19,48 +12,30 @@ import org.reflections.vfs.SystemDir;
*/
public class PackageCrawler {
- final URL[] urls;
- public PackageCrawler(List urlList) {
- urls = urlList.toArray(new URL[0]);
+ final DirectoryClassLoader classLoader;
+ public PackageCrawler(DirectoryClassLoader classLoader) {
+ this.classLoader = classLoader;
}
- public Set> getClassesInPackage(String packageName){
- /*
- List classLoadersList = new LinkedList();
- classLoadersList.add(Thread.currentThread().getContextClassLoader());
- classLoadersList.add(ClasspathHelper.staticClassLoader());
- classLoadersList.add(Thread.currentThread().getContextClassLoader().getParent());
- classLoadersList.add(DirectoryClassLoader.getSystemClassLoader());
- String bootClassPath = System.getProperty("sun.boot.class.path");
- ArrayList urlList = new ArrayList<>();
- for(String path : bootClassPath.split(";")) {
- try {
- urlList.add(new URL("file:"+path));
- } catch (MalformedURLException e) {
- new DebugException("Fehler im Classpath auf diesem System");
- }
- }
- URL[] urls = urlList.toArray(new URL[0]);
- classLoadersList.add(new URLClassLoader(urls, DirectoryClassLoader.getSystemClassLoader()));
- */
- Reflections reflections = new Reflections(new ConfigurationBuilder()
- .setScanners(new SubTypesScanner(false /* don't exclude Object.class */), new ResourcesScanner())
- .setUrls(urls)
- .filterInputsBy(new FilterBuilder().include(FilterBuilder.prefix(packageName))));
+ public Set> getClassesInPackage(String packageName) {
+ var res = new HashSet>();
- Set> classes = reflections.getSubTypesOf(Object.class);
+ try (ScanResult result = new ClassGraph()
+ .enableClassInfo()
+ .enableSystemJarsAndModules()
+ .addClassLoader(classLoader)
+ .acceptPackages(packageName)
+ .scan()) {
- return classes;
- }
+ for (var info : result.getAllClasses()) {
+ try {
+ var clazz = Class.forName(info.getName());
+ res.add(clazz);
+ } catch (ClassNotFoundException ignored) {}
+ }
+ };
- public Set> getAllAvailableClasses(){
- Reflections reflections = new Reflections(new ConfigurationBuilder()
- .setScanners(new SubTypesScanner(false /* don't exclude Object.class */), new ResourcesScanner())
- .setUrls(urls));
-
- Set> classes = reflections.getSubTypesOf(Object.class);
-
- return classes;
+ return res;
}
public Map getClassNames(String packageName){
diff --git a/src/main/java/de/dhbwstuttgart/parser/SyntaxTreeGenerator/StatementGenerator.java b/src/main/java/de/dhbwstuttgart/parser/SyntaxTreeGenerator/StatementGenerator.java
index 54f6b680..f4587b6b 100644
--- a/src/main/java/de/dhbwstuttgart/parser/SyntaxTreeGenerator/StatementGenerator.java
+++ b/src/main/java/de/dhbwstuttgart/parser/SyntaxTreeGenerator/StatementGenerator.java
@@ -597,8 +597,12 @@ public class StatementGenerator {
}
private Statement convert(Java17Parser.ContinuestmtContext stmt) {
- // TODO
- throw new NotImplementedException();
+ Token offset = stmt.getStart();
+ if (!Objects.isNull(stmt.identifier())) {
+ return new Continue(localVars.get(stmt.identifier().getText()), offset);
+ } else {
+ return new Continue(TypePlaceholder.fresh(offset), offset);
+ }
}
private Statement convert(Java17Parser.SemistmtContext stmt) {
@@ -804,6 +808,7 @@ public class StatementGenerator {
// Check for Classname:
if (reg.contains(whole)) {
receiver = generateStaticClassName(whole, offset);
+ break;
}
whole += ".";
}
diff --git a/src/main/java/de/dhbwstuttgart/parser/SyntaxTreeGenerator/SyntaxTreeGenerator.java b/src/main/java/de/dhbwstuttgart/parser/SyntaxTreeGenerator/SyntaxTreeGenerator.java
index 003f2580..de36c9f0 100644
--- a/src/main/java/de/dhbwstuttgart/parser/SyntaxTreeGenerator/SyntaxTreeGenerator.java
+++ b/src/main/java/de/dhbwstuttgart/parser/SyntaxTreeGenerator/SyntaxTreeGenerator.java
@@ -71,10 +71,6 @@ import de.dhbwstuttgart.syntaxtree.type.RefType;
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
import de.dhbwstuttgart.syntaxtree.type.Void;
-import de.dhbwstuttgart.typeinference.constraints.GenericsResolver;
-import javassist.compiler.SyntaxError;
-
-import javax.swing.text.html.Option;
public class SyntaxTreeGenerator {
private JavaClassRegistry reg;
diff --git a/src/main/java/de/dhbwstuttgart/syntaxtree/AbstractASTWalker.java b/src/main/java/de/dhbwstuttgart/syntaxtree/AbstractASTWalker.java
index bc963fb3..2b4fff9f 100644
--- a/src/main/java/de/dhbwstuttgart/syntaxtree/AbstractASTWalker.java
+++ b/src/main/java/de/dhbwstuttgart/syntaxtree/AbstractASTWalker.java
@@ -236,6 +236,11 @@ public abstract class AbstractASTWalker implements ASTVisitor {
aBreak.accept(this);
}
+ @Override
+ public void visit(Continue aContinue) {
+ aContinue.accept(this);
+ }
+
@Override
public void visit(StaticClassName staticClassName) {
diff --git a/src/main/java/de/dhbwstuttgart/syntaxtree/StatementVisitor.java b/src/main/java/de/dhbwstuttgart/syntaxtree/StatementVisitor.java
index 1f1dc61c..78148964 100644
--- a/src/main/java/de/dhbwstuttgart/syntaxtree/StatementVisitor.java
+++ b/src/main/java/de/dhbwstuttgart/syntaxtree/StatementVisitor.java
@@ -53,6 +53,8 @@ public interface StatementVisitor {
void visit(Break aBreak);
+ void visit(Continue aContinue);
+
void visit(Yield aYield);
void visit(StaticClassName staticClassName);
diff --git a/src/main/java/de/dhbwstuttgart/syntaxtree/statement/Continue.java b/src/main/java/de/dhbwstuttgart/syntaxtree/statement/Continue.java
new file mode 100644
index 00000000..7da44743
--- /dev/null
+++ b/src/main/java/de/dhbwstuttgart/syntaxtree/statement/Continue.java
@@ -0,0 +1,18 @@
+package de.dhbwstuttgart.syntaxtree.statement;
+
+import de.dhbwstuttgart.syntaxtree.StatementVisitor;
+import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
+import org.antlr.v4.runtime.Token;
+
+public class Continue extends Statement {
+
+ public Continue(RefTypeOrTPHOrWildcardOrGeneric type, Token offset) {
+ super(type, offset);
+ }
+
+ @Override
+ public void accept(StatementVisitor visitor) {
+ visitor.visit(this);
+ }
+
+}
diff --git a/src/main/java/de/dhbwstuttgart/syntaxtree/visual/OutputGenerator.java b/src/main/java/de/dhbwstuttgart/syntaxtree/visual/OutputGenerator.java
index bb24aae3..7297dd87 100644
--- a/src/main/java/de/dhbwstuttgart/syntaxtree/visual/OutputGenerator.java
+++ b/src/main/java/de/dhbwstuttgart/syntaxtree/visual/OutputGenerator.java
@@ -333,6 +333,11 @@ public class OutputGenerator implements ASTVisitor {
out.append("break");
}
+ @Override
+ public void visit(Continue aContinue) {
+ out.append("continue");
+ }
+
@Override
public void visit(StaticClassName staticClassName) {
diff --git a/src/main/java/de/dhbwstuttgart/target/generate/ASTToTargetAST.java b/src/main/java/de/dhbwstuttgart/target/generate/ASTToTargetAST.java
index 1c485d7e..bddeeca7 100644
--- a/src/main/java/de/dhbwstuttgart/target/generate/ASTToTargetAST.java
+++ b/src/main/java/de/dhbwstuttgart/target/generate/ASTToTargetAST.java
@@ -1,5 +1,6 @@
package de.dhbwstuttgart.target.generate;
+import de.dhbwstuttgart.bytecode.CodeGenException;
import de.dhbwstuttgart.bytecode.FunNGenerator;
import de.dhbwstuttgart.core.JavaTXCompiler;
import de.dhbwstuttgart.environment.ByteArrayClassLoader;
@@ -160,11 +161,11 @@ public class ASTToTargetAST {
var superInterfaces = input.getSuperInterfaces().stream().map(clazz -> convert(clazz, generics.javaGenerics)).toList();
var constructors = input.getConstructors().stream().map(constructor -> this.convert(input, constructor, finalFieldInitializer)).flatMap(List::stream).toList();
var fields = input.getFieldDecl().stream().map(this::convert).toList();
- var methods = groupOverloads(input.getMethods()).stream().map(m -> convert(input, m)).flatMap(List::stream).toList();
+ var methods = groupOverloads(input.getMethods()).stream().map(m -> convert(input, m)).flatMap(Set::stream).toList();
TargetMethod staticConstructor = null;
if (input.getStaticInitializer().isPresent())
- staticConstructor = this.convert(input, input.getStaticInitializer().get()).get(0);
+ staticConstructor = this.convert(input, input.getStaticInitializer().get()).stream().findFirst().orElseThrow();
if (input instanceof Record)
return new TargetRecord(input.getModifiers(), input.getClassName(), javaGenerics, txGenerics, superInterfaces, constructors, staticConstructor, fields, methods);
@@ -289,11 +290,11 @@ public class ASTToTargetAST {
return res.toString();
}
- private List convert(ClassOrInterface clazz, List overloadedMethods) {
+ private Set convert(ClassOrInterface clazz, List overloadedMethods) {
if (overloadedMethods.size() == 1) {
- return convert(clazz, overloadedMethods.get(0));
+ return convert(clazz, overloadedMethods.getFirst());
}
- var res = new ArrayList();
+ var methods = new ArrayList();
for (var method : overloadedMethods) {
var newMethod = new Method(
method.modifier,
@@ -305,7 +306,7 @@ public class ASTToTargetAST {
method.getGenerics(),
method.getOffset()
);
- res.add(newMethod);
+ methods.add(newMethod);
}
// TODO Record overloading
@@ -328,7 +329,15 @@ public class ASTToTargetAST {
var entryPoint = new Method(template.modifier, template.name, template.getReturnType(), params, block, template.getGenerics(), new NullToken());
res.add(entryPoint); // TODO*/
- return res.stream().map(m -> convert(clazz, m)).flatMap(List::stream).toList();
+ var res = new HashSet();
+ for (var method : methods) {
+ var overloads = convert(clazz, method);
+ for (var overload : overloads) {
+ if (res.contains(overload)) throw new CodeGenException("Duplicate method found: " + overload.name() + " with signature " + overload.signature().getSignature());
+ res.add(overload);
+ }
+ }
+ return res;
}
private Expression makeRecordSwitch(RefTypeOrTPHOrWildcardOrGeneric returnType, ParameterList params, List overloadedMethods) {
@@ -366,16 +375,15 @@ public class ASTToTargetAST {
for (var i = 0; i < params.size(); i++) {
var a = TargetType.toPrimitive(params.get(i).pattern().type());
var b = convert(sParams.getFormalparalist().get(i).getType());
- System.out.println(a + " " + b);
if (!Objects.equals(a, b)) return false;
}
return true;
}).findFirst();
}
- private List convert(ClassOrInterface currentClass, Method method) {
+ private Set convert(ClassOrInterface currentClass, Method method) {
generics = all.get(0);
- List result = new ArrayList<>();
+ Set result = new HashSet<>();
Set> parameterSet = new HashSet<>();
for (var s : all) {
@@ -387,8 +395,11 @@ public class ASTToTargetAST {
var superMethod = findSuperMethodToOverride(currentClass, method.getName(), params);
if (superMethod.isPresent()) {
// If we find a super method to override, use its parameters and return types
- returnType = convert(superMethod.get().getReturnType(), this.generics.javaGenerics);
- params = convert(superMethod.get().getParameterList(), method.getParameterList(), this.generics.javaGenerics);
+ var newReturnType = convert(superMethod.get().getReturnType(), this.generics.javaGenerics);
+ if (newReturnType instanceof TargetPrimitiveType && TargetType.toPrimitive(returnType).equals(newReturnType)) {
+ returnType = newReturnType;
+ params = convert(superMethod.get().getParameterList(), method.getParameterList(), this.generics.javaGenerics);
+ }
}
List finalParams = params;
@@ -400,10 +411,12 @@ public class ASTToTargetAST {
var javaSignature = new TargetMethod.Signature(javaMethodGenerics, params, returnType);
var txSignature = new TargetMethod.Signature(txMethodGenerics, txParams, convert(method.getReturnType(), this.generics.txGenerics));
- result.add(new TargetMethod(method.modifier, method.name, convert(method.block), javaSignature, txSignature));
+ var newMethod = new TargetMethod(method.modifier, method.name, convert(method.block), javaSignature, txSignature);
+ result.add(newMethod);
parameterSet.add(params);
}
}
+
return result;
}
diff --git a/src/main/java/de/dhbwstuttgart/target/generate/StatementToTargetExpression.java b/src/main/java/de/dhbwstuttgart/target/generate/StatementToTargetExpression.java
index 9851cd8e..7e50585a 100644
--- a/src/main/java/de/dhbwstuttgart/target/generate/StatementToTargetExpression.java
+++ b/src/main/java/de/dhbwstuttgart/target/generate/StatementToTargetExpression.java
@@ -228,6 +228,7 @@ public class StatementToTargetExpression implements ASTVisitor {
isInterface = receiverClass.isInterface();
}
+ System.out.println(argList);
result = new TargetMethodCall(converter.convert(methodCall.getType()), returnType, argList, converter.convert(methodCall.receiver), methodCall.getArgumentList().getArguments().stream().map(converter::convert).toList(), receiverType, methodCall.name, isStatic, isInterface, isPrivate);
}
@@ -260,6 +261,11 @@ public class StatementToTargetExpression implements ASTVisitor {
result = new TargetBreak();
}
+ @Override
+ public void visit(Continue aContinue) {
+ result = new TargetContinue();
+ }
+
@Override
public void visit(StaticClassName staticClassName) {
result = new TargetClassName(converter.convert(staticClassName.getType()));
@@ -282,7 +288,7 @@ public class StatementToTargetExpression implements ASTVisitor {
@Override
public void visit(DoStmt whileStmt) {
- throw new NotImplementedException();
+ result = new TargetDo(converter.convert(whileStmt.expr), converter.convert(whileStmt.loopBlock));
}
// TODO These two might not be necessary
diff --git a/src/main/java/de/dhbwstuttgart/target/generate/TracingStatementVisitor.java b/src/main/java/de/dhbwstuttgart/target/generate/TracingStatementVisitor.java
index 7b6f2a5f..d26cbbd9 100644
--- a/src/main/java/de/dhbwstuttgart/target/generate/TracingStatementVisitor.java
+++ b/src/main/java/de/dhbwstuttgart/target/generate/TracingStatementVisitor.java
@@ -124,6 +124,11 @@ public abstract class TracingStatementVisitor implements StatementVisitor {
}
+ @Override
+ public void visit(Continue aContinue) {
+
+ }
+
@Override
public void visit(StaticClassName staticClassName) {
diff --git a/src/main/java/de/dhbwstuttgart/target/tree/TargetMethod.java b/src/main/java/de/dhbwstuttgart/target/tree/TargetMethod.java
index 5a8b9368..bdabc81e 100644
--- a/src/main/java/de/dhbwstuttgart/target/tree/TargetMethod.java
+++ b/src/main/java/de/dhbwstuttgart/target/tree/TargetMethod.java
@@ -6,6 +6,7 @@ import de.dhbwstuttgart.target.tree.type.TargetType;
import org.objectweb.asm.Opcodes;
import java.util.List;
+import java.util.Objects;
import java.util.Set;
public record TargetMethod(int access, String name, TargetBlock block, Signature signature, Signature txSignature) {
@@ -64,5 +65,16 @@ public record TargetMethod(int access, String name, TargetBlock block, Signature
public boolean isStatic() {
return (access & Opcodes.ACC_STATIC) != 0;
}
+
+ @Override
+ public boolean equals(Object other) {
+ if (!(other instanceof TargetMethod otherMethod)) return false;
+ return otherMethod.signature.equals(this.signature) && otherMethod.name.equals(this.name);
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(name, signature);
+ }
}
diff --git a/src/main/java/de/dhbwstuttgart/target/tree/expression/TargetDo.java b/src/main/java/de/dhbwstuttgart/target/tree/expression/TargetDo.java
new file mode 100644
index 00000000..7329b2ea
--- /dev/null
+++ b/src/main/java/de/dhbwstuttgart/target/tree/expression/TargetDo.java
@@ -0,0 +1,4 @@
+package de.dhbwstuttgart.target.tree.expression;
+
+public record TargetDo(TargetExpression cond, TargetExpression body) implements TargetExpression {
+}
diff --git a/src/main/java/de/dhbwstuttgart/target/tree/expression/TargetExpression.java b/src/main/java/de/dhbwstuttgart/target/tree/expression/TargetExpression.java
index e0bbc523..b82cfd79 100644
--- a/src/main/java/de/dhbwstuttgart/target/tree/expression/TargetExpression.java
+++ b/src/main/java/de/dhbwstuttgart/target/tree/expression/TargetExpression.java
@@ -3,7 +3,7 @@ package de.dhbwstuttgart.target.tree.expression;
import de.dhbwstuttgart.target.tree.type.*;
public sealed interface TargetExpression
- permits TargetBinaryOp, TargetBlock, TargetBreak, TargetCast, TargetClassName, TargetContinue, TargetFieldVar, TargetFor, TargetForEach, TargetIf, TargetInstanceOf, TargetLambdaExpression, TargetLiteral, TargetLocalVar, TargetPattern, TargetReturn, TargetStatementExpression, TargetSuper, TargetSwitch, TargetTernary, TargetThis, TargetThrow, TargetUnaryOp, TargetVarDecl, TargetWhile, TargetYield {
+ permits TargetBinaryOp, TargetBlock, TargetBreak, TargetCast, TargetClassName, TargetContinue, TargetDo, TargetFieldVar, TargetFor, TargetForEach, TargetIf, TargetInstanceOf, TargetLambdaExpression, TargetLiteral, TargetLocalVar, TargetPattern, TargetReturn, TargetStatementExpression, TargetSuper, TargetSwitch, TargetTernary, TargetThis, TargetThrow, TargetUnaryOp, TargetVarDecl, TargetWhile, TargetYield {
default TargetType type() {
return null;
diff --git a/src/main/java/de/dhbwstuttgart/target/tree/expression/TargetWhile.java b/src/main/java/de/dhbwstuttgart/target/tree/expression/TargetWhile.java
index e1a3690c..463702bd 100644
--- a/src/main/java/de/dhbwstuttgart/target/tree/expression/TargetWhile.java
+++ b/src/main/java/de/dhbwstuttgart/target/tree/expression/TargetWhile.java
@@ -1,6 +1,4 @@
package de.dhbwstuttgart.target.tree.expression;
-import de.dhbwstuttgart.target.tree.type.TargetType;
-
public record TargetWhile(TargetExpression cond, TargetExpression body) implements TargetExpression {
}
diff --git a/src/main/java/de/dhbwstuttgart/typeinference/assumptions/TypeInferenceBlockInformation.java b/src/main/java/de/dhbwstuttgart/typeinference/assumptions/TypeInferenceBlockInformation.java
index 6b9f54a5..7fe843d1 100644
--- a/src/main/java/de/dhbwstuttgart/typeinference/assumptions/TypeInferenceBlockInformation.java
+++ b/src/main/java/de/dhbwstuttgart/typeinference/assumptions/TypeInferenceBlockInformation.java
@@ -35,7 +35,6 @@ public class TypeInferenceBlockInformation extends TypeInferenceInformation {
public ClassOrInterface getSuperClass() {
for (var clazz : getAvailableClasses()) {
- System.out.println(currentClass.getSuperClass().getName());
if (clazz.getClassName().equals(currentClass.getSuperClass().getName()))
return clazz;
}
diff --git a/src/main/java/de/dhbwstuttgart/typeinference/typeAlgo/TYPEStmt.java b/src/main/java/de/dhbwstuttgart/typeinference/typeAlgo/TYPEStmt.java
index be402d08..e068d9b2 100644
--- a/src/main/java/de/dhbwstuttgart/typeinference/typeAlgo/TYPEStmt.java
+++ b/src/main/java/de/dhbwstuttgart/typeinference/typeAlgo/TYPEStmt.java
@@ -514,6 +514,11 @@ public class TYPEStmt implements StatementVisitor {
}
+ @Override
+ public void visit(Continue aContinue) {
+
+ }
+
@Override
public void visit(StaticClassName staticClassName) {
// Hier entstehen keine Constraints
@@ -569,7 +574,10 @@ public class TYPEStmt implements StatementVisitor {
@Override
public void visit(DoStmt whileStmt) {
- throw new NotImplementedException();
+ RefType booleanType = new RefType(ASTFactory.createClass(java.lang.Boolean.class).getClassName(), new NullToken());
+ whileStmt.expr.accept(this);
+ constraintsSet.addUndConstraint(new Pair(whileStmt.expr.getType(), booleanType, PairOperator.EQUALSDOT, loc(whileStmt.expr.getOffset())));
+ whileStmt.loopBlock.accept(this);
}
@Override
diff --git a/src/test/java/AllgemeinTest.java b/src/test/java/AllgemeinTest.java
index 9c92dd0c..7b60af88 100644
--- a/src/test/java/AllgemeinTest.java
+++ b/src/test/java/AllgemeinTest.java
@@ -1,6 +1,7 @@
import static org.junit.Assert.*;
+import static targetast.TestCodegen.generateClassFiles;
import java.io.File;
import java.lang.reflect.Field;
@@ -14,6 +15,7 @@ import org.junit.Test;
import com.google.common.collect.Lists;
import de.dhbwstuttgart.core.JavaTXCompiler;
+import de.dhbwstuttgart.environment.ByteArrayClassLoader;
public class AllgemeinTest {
@@ -63,6 +65,8 @@ public class AllgemeinTest {
//String className = "TripleTest";
//String className = "WildcardList";
//String className = "List";
+ //String className = "Box";
+ //String className = "GenBox";
String className = "Foo";
//PL 2019-10-24: genutzt fuer unterschiedliche Tests
path = System.getProperty("user.dir")+"/resources/AllgemeinTest/" + className + ".jav";
@@ -75,7 +79,7 @@ public class AllgemeinTest {
Lists.newArrayList(new File(System.getProperty("user.dir")+"/resources/bytecode/classFiles/")),
new File(System.getProperty("user.dir")+"/resources/bytecode/classFiles/"));
//*/
- compiler.generateBytecode(new File(path));
+ compiler.generateBytecode();
pathToClassFile = System.getProperty("user.dir")+"/resources/bytecode/classFiles/";
loader = new URLClassLoader(new URL[] {new URL("file://"+pathToClassFile)});
classToTest = loader.loadClass(className);
diff --git a/src/test/java/TestComplete.java b/src/test/java/TestComplete.java
index ad2fd648..fd4b8b5e 100644
--- a/src/test/java/TestComplete.java
+++ b/src/test/java/TestComplete.java
@@ -606,10 +606,10 @@ public class TestComplete {
}
@Test
- @Ignore("This one isn't working")
+ //@Ignore("This one isn't working")
public void boxTest() throws Exception {
var classFiles = generateClassFiles(new ByteArrayClassLoader(), "Box.jav");
- var instance = classFiles.get("Box_Main").getDeclaredConstructor().newInstance();
+ var instance = classFiles.get("Box").getDeclaredConstructor().newInstance();
}
@Test
@@ -925,6 +925,22 @@ public class TestComplete {
assertEquals(clazz.getDeclaredMethod("main", Integer.class).invoke(instance, 5), "small");
}
+ @Test
+ public void testWhile() throws Exception {
+ var classFiles = generateClassFiles(new ByteArrayClassLoader(), "While.jav");
+ var clazz = classFiles.get("While");
+ var instance = clazz.getDeclaredConstructor().newInstance();
+ assertEquals(clazz.getDeclaredMethod("m", Integer.class).invoke(instance, 5), 5);
+ assertEquals(clazz.getDeclaredMethod("m2").invoke(instance), 10);
+ }
+
+ @Test
+ public void testImportWildcard() throws Exception {
+ var classFiles = generateClassFiles(new ByteArrayClassLoader(), "ImportWildcard.jav");
+ var clazz = classFiles.get("ImportWildcard");
+ var instance = clazz.getDeclaredConstructor().newInstance();
+ }
+
@Test
public void testBug122() throws Exception {
var classFiles = generateClassFiles(new ByteArrayClassLoader(), "Bug122.jav");
@@ -1085,6 +1101,7 @@ public class TestComplete {
var res = clazz.getDeclaredMethod("convert", List.class).invoke(instance, list);
assertEquals(res, List.of(6, 7, 8));
}
+
@Test
public void testBug325() throws Exception {
var classFiles = generateClassFiles(new ByteArrayClassLoader(), "Bug325.jav");
@@ -1108,4 +1125,18 @@ public class TestComplete {
var clazz = classFiles.get("Bug328");
var instance = clazz.getDeclaredConstructor().newInstance();
}
+
+ @Test
+ public void testBug333() throws Exception {
+ var classFiles = generateClassFiles(new ByteArrayClassLoader(), "Bug333.jav");
+ var clazz = classFiles.get("Bug333");
+ var instance = clazz.getDeclaredConstructor().newInstance();
+ }
+
+ @Test
+ public void testBug338() throws Exception {
+ var classFiles = generateClassFiles(new ByteArrayClassLoader(), "Bug338.jav");
+ var clazz = classFiles.get("Bug338");
+ var instance = clazz.getDeclaredConstructor().newInstance();
+ }
}
diff --git a/src/test/java/targetast/ASTToTypedTargetAST.java b/src/test/java/targetast/ASTToTypedTargetAST.java
index a4fa2ff0..3c4c7fed 100644
--- a/src/test/java/targetast/ASTToTypedTargetAST.java
+++ b/src/test/java/targetast/ASTToTypedTargetAST.java
@@ -57,7 +57,7 @@ public class ASTToTypedTargetAST {
var file = Path.of(System.getProperty("user.dir"), "/resources/bytecode/javFiles/Tph2.jav").toFile();
var compiler = new JavaTXCompiler(file);
var resultSet = compiler.typeInference(file);
- var converter = new ASTToTargetAST(resultSet);
+ var converter = new ASTToTargetAST(compiler, resultSet);
var classes = compiler.sourceFiles.get(file).getClasses();
var tphAndGenerics = TestCodegen.generateClass(converter.convert(classes.get(0)), new ByteArrayClassLoader());
@@ -68,7 +68,7 @@ public class ASTToTypedTargetAST {
var file = Path.of(System.getProperty("user.dir"), "/resources/bytecode/javFiles/Cycle.jav").toFile();
var compiler = new JavaTXCompiler(file);
var resultSet = compiler.typeInference(file);
- var converter = new ASTToTargetAST(resultSet);
+ var converter = new ASTToTargetAST(compiler, resultSet);
var classes = compiler.sourceFiles.get(file).getClasses();
var cycle = TestCodegen.generateClass(converter.convert(classes.get(0)), new ByteArrayClassLoader());
@@ -79,7 +79,7 @@ public class ASTToTypedTargetAST {
var file = Path.of(System.getProperty("user.dir"), "/resources/bytecode/javFiles/Infimum.jav").toFile();
var compiler = new JavaTXCompiler(file);
var resultSet = compiler.typeInference(file);
- var converter = new ASTToTargetAST(resultSet);
+ var converter = new ASTToTargetAST(compiler, resultSet);
var classes = compiler.sourceFiles.get(file).getClasses();
var infimum = TestCodegen.generateClass(converter.convert(classes.get(0)), new ByteArrayClassLoader());
@@ -90,7 +90,7 @@ public class ASTToTypedTargetAST {
var file = Path.of(System.getProperty("user.dir"), "/resources/bytecode/javFiles/Gen.jav").toFile();
var compiler = new JavaTXCompiler(file);
var resultSet = compiler.typeInference(file);
- var converter = new ASTToTargetAST(resultSet);
+ var converter = new ASTToTargetAST(compiler, resultSet);
var classes = compiler.sourceFiles.get(file).getClasses();
var generics = TestCodegen.generateClass(converter.convert(classes.get(0)), new ByteArrayClassLoader());
@@ -124,7 +124,7 @@ public class ASTToTypedTargetAST {
var file = Path.of(System.getProperty("user.dir"), "/resources/bytecode/javFiles/Generics2.jav").toFile();
var compiler = new JavaTXCompiler(file);
var resultSet = compiler.typeInference(file);
- var converter = new ASTToTargetAST(resultSet);
+ var converter = new ASTToTargetAST(compiler, resultSet);
var classes = compiler.sourceFiles.get(file).getClasses();
var generics2 = TestCodegen.generateClass(converter.convert(classes.get(0)), new ByteArrayClassLoader());
@@ -140,7 +140,7 @@ public class ASTToTypedTargetAST {
var file = Path.of(System.getProperty("user.dir"), "/resources/bytecode/javFiles/Generics3.jav").toFile();
var compiler = new JavaTXCompiler(file);
var resultSet = compiler.typeInference(file);
- var converter = new ASTToTargetAST(resultSet);
+ var converter = new ASTToTargetAST(compiler, resultSet);
var classes = compiler.sourceFiles.get(file).getClasses();
var generics3 = TestCodegen.generateClass(converter.convert(classes.get(0)), new ByteArrayClassLoader());