Compare commits

..

No commits in common. "gradle" and "targetBytecode" have entirely different histories.

1961 changed files with 349049 additions and 27359 deletions

9
.gitattributes vendored
View File

@ -1,9 +0,0 @@
#
# https://help.github.com/articles/dealing-with-line-endings/
#
# Linux start script should use lf
/gradlew text eol=lf
# These are Windows script files and should use crlf
*.bat text eol=crlf

View File

@ -0,0 +1,25 @@
name: Build and Test with Maven
on: [push]
jobs:
Build-and-test-with-Maven:
runs-on: ubuntu-latest
steps:
- name: Check out repository code
uses: actions/checkout@v3
- name: Install maven
run: |
apt update
apt install -y maven
- name: Install java
uses: actions/setup-java@v4
with:
distribution: 'temurin'
java-version: '21'
cache: 'maven'
- name: Compile project
run: |
mvn compile
- name: Run tests
run: |
mvn test

11
.gitignore vendored
View File

@ -19,7 +19,9 @@ bin
.DS_Store .DS_Store
.project .project
.settings/ .settings/
.vscode/
/target/ /target/
settings.json
# #
manually/ manually/
@ -29,12 +31,3 @@ logFiles/**
src/main/java/de/dhbwstuttgart/parser/antlr/ src/main/java/de/dhbwstuttgart/parser/antlr/
src/main/java/de/dhbwstuttgart/sat/asp/parser/antlr/ src/main/java/de/dhbwstuttgart/sat/asp/parser/antlr/
#GRADLE
# Ignore Gradle project-specific cache directory
.gradle
# Ignore Gradle build output directory
build

14
README_aktuelle_Branches Normal file
View File

@ -0,0 +1,14 @@
Stand: 24.5.21
bigRefactoring: Master-Brach
targetBytecode: Neuer Codegenerator mit generated generics Daniel
bigRefactoringUnifyComment: Dokumentation Unify, Martin
bytecodeGenericsSecond: Generated Generics, Ali, Martin
inferWildcards, Wildcards, Till
master, derzeit nicht genutzt
plugin, eigemntlicher Branch fuer Plugin-Basis, derzeit nicht aktuelle (aktuelle Version in simplifyRes
simplifyRes, Basis fuer Plugin, sollte auf Plugin gemerged werden, noch keine Packages, Michael
strucTypesNew, Struturelle Typen, alte Basis, arbeite derzeit niemand
Stand 21.2.23
unif23: Testbranch fuer Tagungseinrecihung Unif23

Binary file not shown.

View File

@ -1,53 +0,0 @@
/*
* This file was generated by the Gradle 'init' task.
*
* This generated file contains a sample Java application project to get you started.
* For more details take a look at the 'Building Java & JVM projects' chapter in the Gradle
* User Manual available at https://docs.gradle.org/7.6/userguide/building_java_projects.html
*/
plugins {
// Apply the application plugin to add support for building a CLI application in Java.
antlr
application
}
java {
toolchain {
languageVersion.set(JavaLanguageVersion.of(19))
}
}
repositories {
// Use Maven Central for resolving dependencies.
mavenCentral()
}
dependencies {
// Use JUnit test framework.
testImplementation("junit:junit:4.13.2")
// This dependency is used by the application.
implementation("com.google.guava:guava:31.1-jre")
implementation("commons-io:commons-io:2.6")
implementation("org.reflections:reflections:0.9.11")
implementation("org.ow2.asm:asm:7.0")
//implementation("org.antlr:antlr4:4.11.1")
antlr("org.antlr:antlr4:4.8-1")
}
tasks.withType<JavaCompile> {
options.compilerArgs.add("--enable-preview")
}
tasks.withType<Test> {
jvmArgs("--enable-preview")
}
tasks.withType<JavaExec> {
jvmArgs("--enable-preview")
}
application {
// Define the main class for the application.
mainClass.set("de.dhbwstuttgart.App")
}

View File

@ -1,13 +0,0 @@
class Box<A>{
void m(A a){}
}
class B { }
class Box_Main extends B {
m(b) {
b.m(new Box_Main());
b.m(new B());
}
}

View File

@ -1,13 +0,0 @@
class Box<A>{
A f;
}
class B { }
class Box_Main extends B {//Fehler Bugzilla Bug 230
m(b) {
b.f = new Box_Main();
b.f = new B();
}
}

View File

@ -1,12 +0,0 @@
import java.util.Vector;
import java.util.List;
import java.lang.Integer;
class FCTest1 extends Vector<Vector<Integer>> {
fc1() {
var y;
var z;
y.add(z);
return y;
}
}

View File

@ -1,11 +0,0 @@
import java.util.Vector;
import java.util.List;
import java.lang.Integer;
class FCTest2 extends Vector<Vector<Integer>> {
fc2(y) {
var z;
y.add(z);
return y;
}
}

View File

@ -1,19 +0,0 @@
import java.util.Vector;
import java.lang.Integer;
class FCTest3 extends Pair<Vector<Integer>, Vector<Integer>> {
fc2(x) {
x.snd().addElement(2);
}
fc2a() {
var y;
y.snd().addElement(2);
return y;
}
}

View File

@ -1,10 +0,0 @@
import java.lang.Integer;
import java.util.Vector;
public class GenTest {
main(x) {
var v = new Vector();
return 1 + v.elementAt(0);
}
}

View File

@ -1,9 +0,0 @@
class Generics {
a;
id(b) { return b; }
setA(x) {
a = x;
return a;
}
m(x,y) { x = id(y); }
}

View File

@ -1,7 +0,0 @@
import java.util.List;
class M {
void m(p, p2){
new addList().addLists(p, p2);
}
}

View File

@ -1,9 +0,0 @@
import java.util.Stack;
import java.util.Vector;
class OverloadingMain {
mmMain(x) { var y; return new O1().mm(y); }
}

View File

@ -1,20 +0,0 @@
import java.lang.Integer;
public class Overloading_Generics {
id1 (x) { return x; }
//Integer id (Integer x) { return x; }
}
class Overloading_Generics1 {
main(x) {
var olg = new Overloading_Generics();
return olg.id1(1);
}
}

View File

@ -1,25 +0,0 @@
import java.util.Vector;
import java.util.Stack;
class OverrideMain {
ovrMain(x) {
var overide;
overide.ovr(x);
}
}
/*
[
[(TPH L = java.util.Stack<TPH FTM>), (TPH N = java.lang.String), (TPH M = ? extends Override2), (TPH FTN, TPH FTM), (TPH K = void)],
[(TPH FTO, TPH FTP), (TPH M = ? extends Override2), (TPH N = java.lang.String), (TPH L = java.util.Stack<TPH FTP>), (TPH K = void)],
[(TPH M = ? extends Override2), (TPH N = java.lang.String), (TPH K = void), (TPH FTR, TPH FTQ), (TPH L = java.util.Vector<TPH FTQ>)],
[(TPH FTT, TPH FTS), (TPH M = ? extends Override2), (TPH L = java.util.Vector<TPH FTS>), (TPH K = void), (TPH N = java.lang.String)],
[(TPH L = java.util.Vector<TPH FTV>), (TPH M = ? extends Override2), (TPH N = java.lang.String), (TPH FTU, TPH FTV), (TPH K = void)],
[(TPH FTX, TPH FTW), (TPH M = ? extends Override2), (TPH L = java.util.Vector<TPH FTW>), (TPH K = void), (TPH N = java.lang.String)],
[(TPH M = ? extends Override2), (TPH L = java.util.Stack<TPH FTZ>), (TPH K = void), (TPH FTY, TPH FTZ), (TPH N = java.lang.String)],
[(TPH FUB, TPH FUA), (TPH K = void), (TPH M = ? extends Override2), (TPH N = java.lang.String), (TPH L = java.util.Vector<TPH FUA>)],
[(TPH N = java.lang.String), (TPH L = java.util.Vector<TPH FUC>), (TPH FUD, TPH FUC), (TPH M = ? extends Override2), (TPH K = void)],
[(TPH N = java.lang.String), (TPH FUF, TPH FUE), (TPH M = ? extends Override2), (TPH K = void), (TPH L = java.util.Vector<TPH FUE>)]]
[[(TPH M = ? extends Override2), (TPH MNX, TPH MNY), (TPH N = java.lang.String), (TPH K = void), (TPH L = java.util.Stack<TPH MNY>)], [(TPH L = java.util.Stack<TPH MOC>), (TPH N = java.lang.String), (TPH M = ? extends Override2), (TPH K = void), (TPH MOB, TPH MOC)], [(TPH M = ? extends Override2), (TPH N = java.lang.String), (TPH MNZ, TPH MOA), (TPH L = java.util.Vector<TPH MOA>), (TPH K = void)], [(TPH L = java.util.Vector<TPH MOE>), (TPH K = void), (TPH M = ? extends Override2), (TPH MOD, TPH MOE), (TPH N = java.lang.String)], [(TPH M = ? extends Override2), (TPH K = void), (TPH N = java.lang.String), (TPH MOF, TPH MOG), (TPH L = java.util.Stack<TPH MOG>)], [(TPH L = java.util.Vector<TPH MOI>), (TPH K = void), (TPH MOH, TPH MOI), (TPH M = ? extends Override2), (TPH N = java.lang.String)], [(TPH L = java.util.Vector<TPH MOK>), (TPH MOJ, TPH MOK), (TPH K = void), (TPH M = ? extends Override2), (TPH N = java.lang.String)], [(TPH MOL, TPH MOM), (TPH L = java.util.Stack<TPH MOM>), (TPH M = ? extends Override2), (TPH K = void), (TPH N = java.lang.String)], [(TPH L = java.util.Vector<TPH MOO>), (TPH MON, TPH MOO), (TPH N = java.lang.String), (TPH K = void), (TPH M = ? extends Override2)], [(TPH L = java.util.Stack<TPH MOP>), (TPH N = java.lang.String), (TPH M = ? extends Override2), (TPH MOQ, TPH MOP), (TPH K = void)]]
*/

View File

@ -1,11 +0,0 @@
import java.util.Vector;
import java.util.Stack;
class OverrideMainRet {
ovrMain() {
var overide;
var x;
overide.ovr(x);
return x;
}
}

View File

@ -1,18 +0,0 @@
class Pair<T, U> {
T x;
U y;
public Pair() { }
public Pair(T x, U y) {
this.x = x;
this.y = y;
}
public T fst () {
return x;
}
public U snd () {
return y;
}
}

View File

@ -1,19 +0,0 @@
import java.util.Vector;
import java.util.Stack;
class Put {
putElement(ele, v) {
v.addElement(ele);
}
putElement(ele, s) {
s.push(ele);
}
main(ele, x) {
putElement(ele, x);
}
}

View File

@ -1,4 +0,0 @@
class Test {
a;
Test b;
}

View File

@ -1,12 +0,0 @@
import java.util.ArrayList;
class TestSubTypless {
m(a){
var l = new ArrayList<>();
l.add(a);
return m2(l).get(0);
}
m2(a){
return m(a);
}
}

View File

@ -1,3 +0,0 @@
class Twice {
twice = f -> x -> f.apply(f.apply(x));
}

View File

@ -1,5 +0,0 @@
class Var {
var(x) { var y; }
}

View File

@ -1,15 +0,0 @@
import java.util.Vector;
import java.lang.Integer;
public class VectorConstAdd {
vectorAdd(v1) {
var i = 0;
var erg = new Vector<>();
while (i < v1.size()) {
erg.addElement(v1.elementAt(i) + 1);
i++;
}
return erg;
}
}

View File

@ -1,8 +0,0 @@
class Wildcard_Andi {
Test<? extends A> ex = new Test<>();
Test<? super A> sup = new Test<>();
}

View File

@ -1,8 +0,0 @@
import java.util.List;
class addList {
addLists(a, b){
a.add(b.get(0));
b.add(a.get(0));
}
}

View File

@ -1,22 +0,0 @@
import java.util.List;
import java.lang.Integer;
import java.lang.Object;
import java.lang.Boolean;
class wildcardPair {
make(l) {
var p = new Pair(l.get(0), l.get(1));
return p;
}
//<X>Boolean compare(Pair<X, X> x) { return true; }
void m(l) {
Object o = l.get(0);
//Pair<? extends Object, ? extends Object> p;
//List<?> b;
//this.compare(p); //1, type incorrect
make(l);
//this.compare(this.make(b)); //2, OK
}
}

View File

@ -1,8 +0,0 @@
import java.lang.Integer;
import java.lang.String;
public class AA {
m(Integer i) { return "AA"; }
m2(AA x) { return "AA"; }
}

View File

@ -1,3 +0,0 @@
import java.lang.Integer;
public class BB extends AA { }

View File

@ -1,6 +0,0 @@
class Cycle {
m(x, y) {
y = x;
x = y;
}
}

View File

@ -1,3 +0,0 @@
public class Exceptions {
// m(Integer i) throws
}

View File

@ -1,12 +0,0 @@
public class FieldTph2 {
a;
m(b){
b = a;
return b;
}
m2(c){
a = c;
}
}

View File

@ -1,30 +0,0 @@
import java.lang.Integer;
import java.lang.Boolean;
class For{
Integer m(Integer x){
var c = x + 2;
// Boolean b = true;
// c = 5;
// c++;
// ++c;
// c--;
// --c;
// while(x<2){
// x = x +1;
// b = false;
// }
return c;
// for(int i = 0;i<10;i++) {
// x = x + 5;
// }
}
// m2(Integer x){
// if(x<2) {
// return 1;
// }else {
// return 2;
// }
// }
}

View File

@ -1,6 +0,0 @@
class Generics2<B extends String>{
<B extends Integer> B m1(B b){
return b;
}
}

View File

@ -1,9 +0,0 @@
public class LamRunnable{
public LamRunnable(){
Runnable lam = () -> {System.out.println("lambda");};
lam.run();
}
}

View File

@ -1,32 +0,0 @@
import java.lang.String;
import java.lang.Integer;
import java.lang.Double;
import java.lang.Boolean;
//import java.util.Vector;
public class OL {
java.lang.Double m(java.lang.Double x) { return x + x; }
java.lang.Integer m(java.lang.Integer x) { return x + x; }
java.lang.String m(java.lang.String x) { return x + x; }
java.lang.Boolean m(Boolean x) { return x; }
// if the class contains just this method, then correct BC will be generated.
// But if another methods are contained then the generated BC is not correct
// m(x) {
// //x.add(1);
// x.addAll(x);
// return x;
// }
}
public class OLMain {
main(x) {
var ol;
ol = new OL();
return ol.m(x);
}
}

View File

@ -1,18 +0,0 @@
public class Tph2 {
id = x->x;
id3 (x) {
return id.apply(x);
}
/*
m(a,b){
var c = m2(a,b);
//m2(a,b);
return a;
}
m2(a,b){
return b;
}
*/
}

View File

@ -1,42 +0,0 @@
import java.lang.Integer;
class Y {
y;
//factorial;
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); });
}
}
ergibt Parse-Error
class fac1 {
factorial;
fac1() {
var y;
y = new Y<>().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));
}
}
*/

View File

@ -1,12 +0,0 @@
public class TestContraVariant {
m(x) {
var y;
x = y;
return y;
}
main(x) {
return m(x);
}
}

View File

@ -1,37 +0,0 @@
public class EmptyMethod{
static String s1 ="";
String s2;
public void m1(){
//String s = "";
System.out.println("test");
//Integer ab = Math.abs(1);
//Math.abs(1);
//String lV = "local";
//s1 = "1";
//s1.concat("2");
s2 = s1;
//m2();
Clazz i = new Clazz();
Integer i = new Integer(1);
}
public void m2(){}
}
class Clazz{}
/*
public class EmptyMethod2{
public static test = "5";
public void m1(Integer i, String j, Boolean b){
//String s = "";
EmptyMethod em = new EmptyMethod();
em.m1();
em.s1 = "";
//Integer ab = Math.abs(1);
//Math.abs(1);
//String lV = "local";
//s1 = "1";
//s1.concat("2");
//s2 = s1;
}
}*/

View File

@ -1,16 +0,0 @@
import java.lang.Integer;
class Faculty {
//fact;
Integer mul(Integer x, Integer y) {
return x;
}
m () {
var fact = (Integer x) -> {
return mul(x, fact.apply(x));
};
return fact;
}
}

View File

@ -1,22 +0,0 @@
import java.lang.String;
class Generics<B> {
//<A extends B> A mt1(A a, B b){
B mt1(B a, B b){
return mt1(a, a);
}
}
class Test {
methode(String s){
return new Generics<String>().mt1(s,s);
}
}
/*
Problem:
auto test = new List<String>();
auto test2 = new List<Integer>();
... //code, welcher möglicherweise test und test2 vertauscht
test.add("hallo");
*/

View File

@ -1,14 +0,0 @@
import java.lang.Integer;
import java.lang.Boolean;
import java.lang.Object;
public class IfTest {
Object m1(b) {
Integer i;
if(b) {
return i;
}else{
return b;
}
}
}

View File

@ -1,8 +0,0 @@
import java.util.Vector;
class Import {
void methode(){
var v;
v.add(v);
}
}

View File

@ -1,13 +0,0 @@
class Apply { }
public class Lambda {
m () {
var lam1 = (x) -> {
return x;
};
return lam1.apply(new Apply());
}
}

View File

@ -1,33 +0,0 @@
import java.lang.String;
public class Lambda2
{
public static void main(List<String> args){
var listOfStrings = new List<String>();
var listOfObjects;
listOfObjects = map(listOfStrings, (a) -> a);
}
public map(a , b){
b.apply(a);
return a;
}
/*
public static <I,O> List<O> map(List<I> input, Function<I,O> func) {
List<O> output;
output = new List<O>();
output.add(func.apply(input.get()));
return output;
}
*/
}
class List<A>{
A get();
void add(A);
}
class Function<A,B>{
B apply(A a);
}

View File

@ -1,24 +0,0 @@
import java.lang.String;
public class Lambda2
{
/*
public static <A> List<A> map(List<? extends A> input,
Function<? super A, ? extends A> func){
input.add(func.apply(input.get()));
}
*/
public map(input,func){
input.add(func.apply(input.get()));
return map(new List<String>(), func);
}
}
class List<A>{
A get();
void add(A);
}
class Function<A,B>{
B apply(A a);
}

View File

@ -1,14 +0,0 @@
import java.lang.Runnable;
import java.lang.String;
import java.lang.System;
public class LamRunnable{
public LamRunnable(){
Runnable lam = () -> {System.out.println("lambda");};
lam.run();
}
}

View File

@ -1,28 +0,0 @@
import java.util.Vector;
import java.lang.Integer;
class Matrix extends Vector<Vector<Integer>> {
Integer mul1(Integer x, Integer y) { return x;}
Integer add1(Integer x, Integer y) { return x;}
mul(m) {
var ret = new Matrix();
var i = 0;
while(i < size()) {
var v1 = this.elementAt(i);
var v2 = new Vector<Integer>();
var j = 0;
while(j < v1.size()) {
var erg = 0;
var k = 0;
while(k < v1.size()) {
erg = erg + v1.elementAt(k) * m.elementAt(k).elementAt(j);
//erg = add1(erg, mul1(v1.elementAt(k),
// m.elementAt(k).elementAt(j)));
k++; }
v2.addElement(new Integer(erg));
j++; }
ret.addElement(v2);
i++; }
return ret;
}
}

View File

@ -1,17 +0,0 @@
class Methods {
mt4(a,b,c) { return a.add(b).sub(c) ; }
mt1(a) {return a;}
mt2(a) {return a.f; }
mt3(a) {return a.add(); }
}
class Test {
java.lang.Object f;
add(){}
add(b){return b;}
sub(b){}
}

View File

@ -1,11 +0,0 @@
public class Op1{
public Op1() {
Runnable lam = () -> {
String test = "";
String b = "b";
test = b;
System.out.println(test);};
//lam.run();
}
}

View File

@ -1,15 +0,0 @@
import java.util.List;
import java.util.Collection;
class Sorting{
void merge(a, b){
a.addAll(b);
return a;
}
sort(in){
var firstHalf = in;
var secondHalf = in;
return merge(sort(firstHalf), sort(secondHalf));
}
}

View File

@ -1,8 +0,0 @@
class MathStruc <A> {
A model;
innerOp = o -> ms -> new MathStruc<A>(o.apply(this.model, ms.model));
MathStruc(A m) { model=m; }
}

View File

@ -1,8 +0,0 @@
import java.lang.Integer;
import java.util.Vector;
public class Gen{
Vector<Integer> m(Vector<Integer> v){
return v;
}
}

View File

@ -1,12 +0,0 @@
import java.lang.String;
import java.lang.Integer;
import java.lang.Double;
public class OLMain {
main(x) {
var ol;
ol = new OLextends();
return ol.m(x);
}
}

View File

@ -1,22 +0,0 @@
import java.lang.String;
import java.lang.Integer;
import java.lang.Double;
import java.lang.Boolean;
public class OLOneFile {
m2(x) { return x + x; }
}
public class OLextendsOneFile extends OLOneFile { }
public class OLMainOneFile {
main(x) {
var ol;
ol = new OLextendsOneFile();
return ol.m2(x);
}
}

View File

@ -1,6 +0,0 @@
java -jar ~/eclipse-workspace/JavaCompilerCore/target/JavaTXcompiler-0.2-jar-with-dependencies.jar de/test/OL.jav -d de/test/output
java -jar ~/eclipse-workspace/JavaCompilerCore/target/JavaTXcompiler-0.2-jar-with-dependencies.jar OLextends.jav -cp de/test/output
java -jar ~/eclipse-workspace/JavaCompilerCore/target/JavaTXcompiler-0.2-jar-with-dependencies.jar OLMain.jav -cp .:de/test/output
javac UseOLMain.java
java -cp .:de/test/output UseOLMain
rm -f UseOLMain.class

View File

@ -1,7 +0,0 @@
import de.test.OL;
public class OLextends extends OL {
}

View File

@ -1,14 +0,0 @@
import de.test.Pair;
class Pairs {
setfst(fst) {
return new Pair<>(snd, fst);
}
swap () {
return new Pair<> (snd, fst); }
polyrec(p) {
return polyrec (p.swap());
}
}

View File

@ -1,3 +0,0 @@
public class Test{
}

View File

@ -1,5 +0,0 @@
class UseOLMain {
public static void main(String[] arg) {
System.out.println(new OLMain().main(1+1));
}
}

View File

@ -1,9 +0,0 @@
package de.test;
import de.test.ToImport;
class ImportTest{
void methode(){
new ToImport();
}
}

View File

@ -1,11 +0,0 @@
package de.test;
import de.test.subpackage1.ToImport2;
import de.test.subpackage2.ToImport3;
class ImportTest2{
void methode(){
new ToImport2().m1();
new ToImport3().m2();
}
}

View File

@ -1,7 +0,0 @@
package de.test;
class ImportTestDefault{
void methode(){
new ToImport();
}
}

View File

@ -1,13 +0,0 @@
package de.test;
import java.lang.String;
import java.lang.Integer;
import java.lang.Double;
import java.lang.Boolean;
//import java.util.Vector;
public class OL {
public m(x) { return x + x; }
}

View File

@ -1,12 +0,0 @@
package de.test;
class Pair {
fst;
snd;
Pair(fst, snd) {
this.fst = fst;
this.snd = snd;
}
}

View File

@ -1,3 +0,0 @@
package de.test;
public class TestClass{}

View File

@ -1,4 +0,0 @@
package de.test;
class ToImport{
}

View File

@ -1,18 +0,0 @@
package de.test;
import java.util.Vector;
import java.lang.Integer;
public class mathStruc {
model;
//Fun1*<Fun2*<A,A,A>, Fun1*<MathStruc <A>,MathStruc <A>>>
innerOp = (o) -> (ms) -> new mathStruc<>(o.apply(model,ms.model));
public mathStruc(m) {
model =m;
//innerOp = (o) -> (ms) -> new mathStruc<>(o.apply(this.model,ms.model));
}
}

View File

@ -1,33 +0,0 @@
package de.test;
import java.util.Vector;
import java.lang.Integer;
import java.lang.Boolean;
import de.test.mathStruc;
import de.test.vectorAdd;
public class mathStrucVector {
public main() {
Vector<Integer> v1 = new Vector<Integer>();
v1.addElement(2);
v1.addElement(2);
Vector<Integer> v2 = new Vector<Integer>();
v2.addElement(3);
v2.addElement(3);
vectorAdd va = new vectorAdd();
var ms;
ms = new mathStruc<>(v1);
var ms2;
ms2 = new mathStruc<>(v2);
var ms3;
ms3 = ms.innerOp.apply(va.add).apply(ms2);
return ms3;
}
}

View File

@ -1,10 +0,0 @@
package de.test;
import de.test.mathStrucVector;
class mathStrucVectorUse {
public static void main(String[] args) {
new mathStrucVector().main();
}
}

View File

@ -1,8 +0,0 @@
class mathStrucVectorUse {
public static void main(String[] args) {
new mathStrucVector().main();
}
}

View File

@ -1,3 +0,0 @@
package de.tesst;
class TestClass{}

View File

@ -1,4 +0,0 @@
package de.test.subpackage1;
class Test1{
}

View File

@ -1,5 +0,0 @@
package de.test.subpackage1;
class ToImport2{
void m1(){}
}

View File

@ -1,4 +0,0 @@
package de.test.subpackage2;
class Test2{
}

View File

@ -1,5 +0,0 @@
package de.test.subpackage2;
class ToImport3{
void m2(){}
}

View File

@ -1,20 +0,0 @@
package de.test;
import java.util.Vector;
import java.lang.Integer;
import java.lang.Boolean;
public class vectorAdd {
public add = (v1, v2) -> {
var ret = new Vector<Integer>();
var i = 0;
while(i < v1.size()) {
//if (i < v2.size()) {
ret.addElement(v1.elementAt(i) + v2.elementAt(i));
//}
}
return ret;
};
}

View File

@ -1,4 +0,0 @@
# Ignore everything in this directory
*
# Except this file
!.gitignore

File diff suppressed because it is too large Load Diff

View File

@ -1,30 +0,0 @@
package de.dhbwstuttgart.bytecode;
import org.objectweb.asm.Label;
import org.objectweb.asm.MethodVisitor;
import org.objectweb.asm.Opcodes;
import de.dhbwstuttgart.syntaxtree.statement.BinaryExpr;
import de.dhbwstuttgart.syntaxtree.statement.Expression;
public abstract class AStatement implements IStatement {
protected Expression expr;
public AStatement(Expression expr) {
this.expr = expr;
}
@Override
public boolean isExprBinary() {
return (expr instanceof BinaryExpr);
}
@Override
public void genBCForRelOp(MethodVisitor mv,Label branchLabel, Label endLabel, BytecodeGenMethod bytecodeGenMethod) {
mv.visitInsn(Opcodes.ICONST_1);
mv.visitJumpInsn(Opcodes.GOTO, endLabel);
mv.visitLabel(branchLabel);
mv.visitInsn(Opcodes.ICONST_0);
mv.visitLabel(endLabel);
}
}

View File

@ -1,11 +0,0 @@
package de.dhbwstuttgart.bytecode;
import de.dhbwstuttgart.syntaxtree.statement.Expression;
public class ArgumentExpr extends AStatement {
public ArgumentExpr(Expression expr) {
super(expr);
}
}

View File

@ -1,258 +0,0 @@
package de.dhbwstuttgart.bytecode;
import java.util.List;
import de.dhbwstuttgart.parser.SyntaxTreeGenerator.AssignToLocal;
import de.dhbwstuttgart.syntaxtree.StatementVisitor;
import de.dhbwstuttgart.syntaxtree.statement.ArgumentList;
import de.dhbwstuttgart.syntaxtree.statement.Assign;
import de.dhbwstuttgart.syntaxtree.statement.AssignToField;
import de.dhbwstuttgart.syntaxtree.statement.BinaryExpr;
import de.dhbwstuttgart.syntaxtree.statement.Block;
import de.dhbwstuttgart.syntaxtree.statement.CastExpr;
import de.dhbwstuttgart.syntaxtree.statement.DoStmt;
import de.dhbwstuttgart.syntaxtree.statement.EmptyStmt;
import de.dhbwstuttgart.syntaxtree.statement.ExpressionReceiver;
import de.dhbwstuttgart.syntaxtree.statement.FieldVar;
import de.dhbwstuttgart.syntaxtree.statement.ForStmt;
import de.dhbwstuttgart.syntaxtree.statement.IfStmt;
import de.dhbwstuttgart.syntaxtree.statement.InstanceOf;
import de.dhbwstuttgart.syntaxtree.statement.LambdaExpression;
import de.dhbwstuttgart.syntaxtree.statement.Literal;
import de.dhbwstuttgart.syntaxtree.statement.LocalVar;
import de.dhbwstuttgart.syntaxtree.statement.LocalVarDecl;
import de.dhbwstuttgart.syntaxtree.statement.MethodCall;
import de.dhbwstuttgart.syntaxtree.statement.NewArray;
import de.dhbwstuttgart.syntaxtree.statement.NewClass;
import de.dhbwstuttgart.syntaxtree.statement.Return;
import de.dhbwstuttgart.syntaxtree.statement.ReturnVoid;
import de.dhbwstuttgart.syntaxtree.statement.StaticClassName;
import de.dhbwstuttgart.syntaxtree.statement.Super;
import de.dhbwstuttgart.syntaxtree.statement.SuperCall;
import de.dhbwstuttgart.syntaxtree.statement.This;
import de.dhbwstuttgart.syntaxtree.statement.UnaryExpr;
import de.dhbwstuttgart.syntaxtree.statement.WhileStmt;
public class ArgumentVisitor implements StatementVisitor {
private List<Boolean> argListMethCall;
private BytecodeGenMethod bytecodeGenMethod;
public ArgumentVisitor(List<Boolean> argListMethCall, BytecodeGenMethod bytecodeGenMethod) {
this.argListMethCall = argListMethCall;
this.bytecodeGenMethod = bytecodeGenMethod;
}
@Override
public void visit(ArgumentList argumentList) {
// TODO Auto-generated method stub
}
@Override
public void visit(LambdaExpression lambdaExpression) {
lambdaExpression.accept(bytecodeGenMethod);
// Zieltype des Lambas ist Funktionale Interface
// kann nie primitiv sein => un-/boxing wird hier nicht gebraucht
argListMethCall.remove(0);
}
@Override
public void visit(Assign assign) {
assign.accept(bytecodeGenMethod);
if(argListMethCall.get(0))
bytecodeGenMethod.doUnboxing(bytecodeGenMethod.getResolver().getResolvedType(assign.getType()));
argListMethCall.remove(0);
}
@Override
public void visit(BinaryExpr binary) {
binary.accept(bytecodeGenMethod);
if(argListMethCall.get(0)) {
bytecodeGenMethod.doUnboxing(bytecodeGenMethod.getResolver().getResolvedType(binary.getType()));
} else {
bytecodeGenMethod.doBoxing(bytecodeGenMethod.getResolver().getResolvedType(binary.getType()));
}
argListMethCall.remove(0);
}
@Override
public void visit(Block block) {
// TODO Auto-generated method stub
}
@Override
public void visit(CastExpr castExpr) {
castExpr.accept(bytecodeGenMethod);
if(argListMethCall.get(0))
bytecodeGenMethod.doUnboxing(bytecodeGenMethod.getResolver().getResolvedType(castExpr.getType()));
argListMethCall.remove(0);
}
@Override
public void visit(EmptyStmt emptyStmt) {
// TODO Auto-generated method stub
}
@Override
public void visit(FieldVar fieldVar) {
fieldVar.accept(bytecodeGenMethod);
if(argListMethCall.get(0))
bytecodeGenMethod.doUnboxing(bytecodeGenMethod.getResolver().getResolvedType(fieldVar.getType()));
argListMethCall.remove(0);
}
@Override
public void visit(ForStmt forStmt) {
// TODO Auto-generated method stub
}
@Override
public void visit(IfStmt ifStmt) {
// TODO Auto-generated method stub
}
@Override
public void visit(InstanceOf instanceOf) {
instanceOf.accept(bytecodeGenMethod);
if(argListMethCall.get(0))
bytecodeGenMethod.doUnboxing(bytecodeGenMethod.getResolver().getResolvedType(instanceOf.getType()));
argListMethCall.remove(0);
}
@Override
public void visit(LocalVar localVar) {
localVar.accept(bytecodeGenMethod);
if(!bytecodeGenMethod.isBinaryExp) {
if(argListMethCall.get(0))
bytecodeGenMethod.doUnboxing(bytecodeGenMethod.getResolver().getResolvedType(localVar.getType()));
}
argListMethCall.remove(0);
}
@Override
public void visit(LocalVarDecl localVarDecl) {
// TODO Auto-generated method stub
}
@Override
public void visit(MethodCall methodCall) {
methodCall.accept(bytecodeGenMethod);
if(argListMethCall.get(0))
bytecodeGenMethod.doUnboxing(bytecodeGenMethod.getResolver().getResolvedType(methodCall.getType()));
argListMethCall.remove(0);
}
@Override
public void visit(NewClass methodCall) {
methodCall.accept(bytecodeGenMethod);
if(argListMethCall.get(0))
bytecodeGenMethod.doUnboxing(bytecodeGenMethod.getResolver().getResolvedType(methodCall.getType()));
argListMethCall.remove(0);
}
@Override
public void visit(NewArray newArray) {
// TODO Auto-generated method stub
}
@Override
public void visit(Return aReturn) {
// TODO Auto-generated method stub
}
@Override
public void visit(ReturnVoid aReturn) {
// TODO Auto-generated method stub
}
@Override
public void visit(StaticClassName staticClassName) {
// TODO Auto-generated method stub
}
@Override
public void visit(Super aSuper) {
// TODO Auto-generated method stub
}
@Override
public void visit(This aThis) {
aThis.accept(bytecodeGenMethod);
if(argListMethCall.get(0))
bytecodeGenMethod.doUnboxing(bytecodeGenMethod.getResolver().getResolvedType(aThis.getType()));
argListMethCall.remove(0);
}
@Override
public void visit(WhileStmt whileStmt) {
// TODO Auto-generated method stub
}
@Override
public void visit(DoStmt whileStmt) {
// TODO Auto-generated method stub
}
@Override
public void visit(AssignToField assignLeftSide) {
// TODO Auto-generated method stub
}
@Override
public void visit(AssignToLocal assignLeftSide) {
// TODO Auto-generated method stub
}
@Override
public void visit(SuperCall superCall) {
// TODO Auto-generated method stub
}
@Override
public void visit(ExpressionReceiver expressionReceiver) {
// TODO Auto-generated method stub
}
@Override
public void visit(UnaryExpr unaryExpr) {
unaryExpr.accept(bytecodeGenMethod);
if(argListMethCall.get(0))
bytecodeGenMethod.doUnboxing(bytecodeGenMethod.getResolver().getResolvedType(unaryExpr.getType()));
argListMethCall.remove(0);
}
@Override
public void visit(Literal literal) {
literal.accept(bytecodeGenMethod);
if(argListMethCall.get(0))
bytecodeGenMethod.doUnboxing(bytecodeGenMethod.getResolver().getResolvedType(literal.getType()));
argListMethCall.remove(0);
}
}

View File

@ -1,11 +0,0 @@
package de.dhbwstuttgart.bytecode;
import de.dhbwstuttgart.syntaxtree.statement.Expression;
public class AssignStmt extends AStatement {
public AssignStmt(Expression rightSide) {
super(rightSide);
}
}

View File

@ -1,630 +0,0 @@
package de.dhbwstuttgart.bytecode;
import java.io.File;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Optional;
import de.dhbwstuttgart.parser.scope.JavaClassName;
import org.objectweb.asm.ClassWriter;
import org.objectweb.asm.FieldVisitor;
import org.objectweb.asm.MethodVisitor;
import org.objectweb.asm.Opcodes;
import org.objectweb.asm.Type;
import de.dhbwstuttgart.bytecode.Exception.BytecodeGeneratorError;
import de.dhbwstuttgart.bytecode.descriptor.DescriptorToString;
import de.dhbwstuttgart.bytecode.descriptor.TypeToDescriptor;
import de.dhbwstuttgart.bytecode.signature.Signature;
import de.dhbwstuttgart.bytecode.signature.TypeToSignature;
import de.dhbwstuttgart.bytecode.signature.TypeToString;
import de.dhbwstuttgart.bytecode.genericsGeneratorTypes.GenericGenratorResultForSourceFile;
import de.dhbwstuttgart.bytecode.genericsGeneratorTypes.GenericsGeneratorResult;
import de.dhbwstuttgart.bytecode.genericsGeneratorTypes.GenericsGeneratorResultForClass;
import de.dhbwstuttgart.bytecode.utilities.MethodUtility;
import de.dhbwstuttgart.bytecode.utilities.NormalConstructor;
import de.dhbwstuttgart.bytecode.utilities.NormalMethod;
import de.dhbwstuttgart.bytecode.utilities.Resolver;
import de.dhbwstuttgart.exceptions.NotImplementedException;
import de.dhbwstuttgart.parser.SyntaxTreeGenerator.AssignToLocal;
import de.dhbwstuttgart.syntaxtree.ASTVisitor;
import de.dhbwstuttgart.syntaxtree.ClassOrInterface;
import de.dhbwstuttgart.syntaxtree.Constructor;
import de.dhbwstuttgart.syntaxtree.Field;
import de.dhbwstuttgart.syntaxtree.FormalParameter;
import de.dhbwstuttgart.syntaxtree.GenericDeclarationList;
import de.dhbwstuttgart.syntaxtree.GenericTypeVar;
import de.dhbwstuttgart.syntaxtree.Method;
import de.dhbwstuttgart.syntaxtree.ParameterList;
import de.dhbwstuttgart.syntaxtree.SourceFile;
import de.dhbwstuttgart.syntaxtree.statement.ArgumentList;
import de.dhbwstuttgart.syntaxtree.statement.Assign;
import de.dhbwstuttgart.syntaxtree.statement.AssignToField;
import de.dhbwstuttgart.syntaxtree.statement.BinaryExpr;
import de.dhbwstuttgart.syntaxtree.statement.Block;
import de.dhbwstuttgart.syntaxtree.statement.CastExpr;
import de.dhbwstuttgart.syntaxtree.statement.DoStmt;
import de.dhbwstuttgart.syntaxtree.statement.EmptyStmt;
import de.dhbwstuttgart.syntaxtree.statement.ExpressionReceiver;
import de.dhbwstuttgart.syntaxtree.statement.FieldVar;
import de.dhbwstuttgart.syntaxtree.statement.ForStmt;
import de.dhbwstuttgart.syntaxtree.statement.IfStmt;
import de.dhbwstuttgart.syntaxtree.statement.InstanceOf;
import de.dhbwstuttgart.syntaxtree.statement.LambdaExpression;
import de.dhbwstuttgart.syntaxtree.statement.Literal;
import de.dhbwstuttgart.syntaxtree.statement.LocalVar;
import de.dhbwstuttgart.syntaxtree.statement.LocalVarDecl;
import de.dhbwstuttgart.syntaxtree.statement.MethodCall;
import de.dhbwstuttgart.syntaxtree.statement.NewArray;
import de.dhbwstuttgart.syntaxtree.statement.NewClass;
import de.dhbwstuttgart.syntaxtree.statement.Return;
import de.dhbwstuttgart.syntaxtree.statement.ReturnVoid;
import de.dhbwstuttgart.syntaxtree.statement.StaticClassName;
import de.dhbwstuttgart.syntaxtree.statement.Super;
import de.dhbwstuttgart.syntaxtree.statement.SuperCall;
import de.dhbwstuttgart.syntaxtree.statement.This;
import de.dhbwstuttgart.syntaxtree.statement.UnaryExpr;
import de.dhbwstuttgart.syntaxtree.statement.WhileStmt;
import de.dhbwstuttgart.syntaxtree.type.ExtendsWildcardType;
import de.dhbwstuttgart.syntaxtree.type.GenericRefType;
import de.dhbwstuttgart.syntaxtree.type.RefType;
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
import de.dhbwstuttgart.syntaxtree.type.SuperWildcardType;
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
import de.dhbwstuttgart.typeinference.result.ResultSet;
public class BytecodeGen implements ASTVisitor {
ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_FRAMES | ClassWriter.COMPUTE_MAXS);
String type;
public static RefTypeOrTPHOrWildcardOrGeneric THISTYPE = null;
private JavaClassName className;
private String pkgName;
private boolean isInterface;
private Collection<ResultSet> listOfResultSets;
private ResultSet resultSet;
private SourceFile sf;
private File path;
private Optional<Constructor> fieldInitializations;
private int indexOfFirstParam = 0;
private String superClass;
private List<String> tphsClass;
// stores parameter, local vars and the next index on the local variable table,
// which use for aload_i, astore_i,...
HashMap<String, Integer> paramsAndLocals = new HashMap<>();
// stores generics and their bounds of class
HashMap<String, String> genericsAndBounds = new HashMap<>();
private int constructorPos = 0;
HashMap<String, RefTypeOrTPHOrWildcardOrGeneric> methodParamsAndTypes = new HashMap<>();
byte[] bytecode;
HashMap<JavaClassName, byte[]> classFiles;
private final ArrayList<String> methodNameAndParamsT = new ArrayList<>();
private final ArrayList<String> fieldNameAndParamsT = new ArrayList<>();
private final ArrayList<String> fieldNameSignature = new ArrayList<>();
private List<GenericGenratorResultForSourceFile> simplifyResultsForAllSourceFiles;
private GenericsGeneratorResultForClass generatedGenerics;
private Resolver resolver;
private final ClassLoader classLoader;
public BytecodeGen(HashMap<JavaClassName, byte[]> classFiles, Collection<ResultSet> listOfResultSets, List<GenericGenratorResultForSourceFile> simplifyResultsForAllSourceFiles, SourceFile sf,
File path, ClassLoader classLoader) {
this.classFiles = classFiles;
this.listOfResultSets = listOfResultSets;
this.simplifyResultsForAllSourceFiles = simplifyResultsForAllSourceFiles;
this.sf = sf;
this.path = path;
this.pkgName = sf.getPkgName();
this.classLoader = classLoader;
}
@Override
public void visit(SourceFile sourceFile) {
for (ClassOrInterface cl : sourceFile.getClasses()) {
System.out.println("in Class: " + cl.getClassName().toString());
BytecodeGen classGen = new BytecodeGen(classFiles, listOfResultSets, simplifyResultsForAllSourceFiles, sf, path, classLoader);
cl.accept(classGen);
classGen.writeClass(cl.getClassName());
}
}
/**
* Associates the bytecode of the class that was build with the classWriter
* {@link #cw} with the class name in the map {@link #classFiles}
*
* @param name name of the class with which the bytecode is to be associated
*/
private void writeClass(JavaClassName name) {
bytecode = cw.toByteArray();
classFiles.put(name, bytecode);
}
public HashMap<JavaClassName, byte[]> getClassFiles() {
return classFiles;
}
@Override
public void visit(ClassOrInterface classOrInterface) {
className = classOrInterface.getClassName();
cw.visitSource(className.getClassName() + ".jav", null);
isInterface = (classOrInterface.getModifiers() & 512) == 512;
int acc = isInterface ? classOrInterface.getModifiers() + Opcodes.ACC_ABSTRACT
: classOrInterface.getModifiers() + Opcodes.ACC_SUPER;
fieldInitializations = classOrInterface.getfieldInitializations();
// resultSet = listOfResultSets.get(0);
boolean isVisited = false;
List<ResultSet> listOfResultSetsList = new ArrayList<>(listOfResultSets);
generatedGenerics = simplifyResultsForAllSourceFiles.stream().map(sr->sr.getSimplifyResultsByName(className)).findFirst().get();
for (int i = 0; i < listOfResultSetsList.size(); i++) {
//for (ResultSet rs : listOfResultSets) {
superClass = classOrInterface.getSuperClass().acceptTV(new TypeToDescriptor());
resultSet = listOfResultSetsList.get(i);
resolver = new Resolver(resultSet);
// tphExtractor.setResultSet(resultSet);
// Nur einmal ausführen!!
if (!isVisited) {
String sig = null;
/*
* if class has generics then creates signature Signature looks like:
* <E:Ljava/...>Superclass
*/
if (classOrInterface.getGenerics().iterator().hasNext() || classOrInterface.getSuperClass().acceptTV(new TypeToSignature()).contains("<")
|| !generatedGenerics.getClassConstraints().isEmpty()) {
List<GenericsGeneratorResult> consClass = generatedGenerics.getClassConstraints();
//
Signature signature = new Signature(classOrInterface, genericsAndBounds, consClass);
sig = signature.createSignatureForClassOrInterface();
System.out.println("Signature: => " + sig);
}
cw.visit(Opcodes.V1_8, acc, classOrInterface.getClassName().toString().replace(".", "/"), sig,
classOrInterface.getSuperClass().acceptTV(new TypeToDescriptor()), null);
isVisited = true;
}
for (Field f : classOrInterface.getFieldDecl()) {
f.accept(this);
}
for (Constructor c : classOrInterface.getConstructors()) {
c.accept(this);
}
for (Method m : classOrInterface.getMethods()) {
m.accept(this);
}
}
}
@Override
public void visit(Constructor field) {
// stores generics and their bounds of method
HashMap<String, String> genericsAndBoundsMethod = new HashMap<>();
field.getParameterList().accept(this);
String id = MethodUtility.createID(resolver, field);
if (methodNameAndParamsT.contains(id)) {
return;
}
methodNameAndParamsT.add(id);
System.out.println("Constructor: " + field.name + " , paramsType: " + id);
String desc = null;
boolean hasGen = false;
for (String paramName : methodParamsAndTypes.keySet()) {
String typeOfParam = methodParamsAndTypes.get(paramName).acceptTV(new TypeToSignature());
System.out.println(typeOfParam);
if (genericsAndBounds.containsKey(typeOfParam) || typeOfParam.contains("$") || typeOfParam.contains("<")) {
hasGen = true;
break;
}
}
String sig = null;
if (hasGen) {
List<GenericsGeneratorResult> constraints = generatedGenerics.getClassConstraints();
Signature signature = new Signature(genericsAndBounds,
methodParamsAndTypes, resultSet, constraints);
sig = signature.createSignatureForConstructor(field);
}
if (field.getParameterList().iterator().hasNext())
System.out.println(field.getParameterList().iterator().next().getType().acceptTV(new TypeToDescriptor()));
NormalConstructor constructor = new NormalConstructor(field, genericsAndBounds, hasGen);
desc = constructor.accept(new DescriptorToString(resultSet));
System.out.println("Constructor: " + field.getName() + " Sig: " + sig + " Desc: " + desc);
MethodVisitor mv = cw.visitMethod(Opcodes.ACC_PUBLIC, "<init>", desc, sig, null);
mv.visitCode();
Block block = fieldInitializations.get().block;
constructorPos += 1;
BytecodeGenMethod gen = new BytecodeGenMethod(className, superClass, resultSet, field, mv, paramsAndLocals, cw,
genericsAndBoundsMethod, genericsAndBounds, isInterface, classFiles, sf, path, block, constructorPos, classLoader);
if (!field.getParameterList().iterator().hasNext()
&& !(field.block.statements.get(field.block.statements.size() - 1) instanceof ReturnVoid)) {
mv.visitInsn(Opcodes.RETURN);
}
mv.visitMaxs(0, 0);
mv.visitEnd();
}
@Override
public void visit(Method method) {
// TODO: check if the method is static => if static then the first param will be
// stored in pos 0
// else it will be stored in pos 1 and this will be stored in pos 0
String retType = resultSet.resolveType(method.getReturnType()).resolvedType.acceptTV(new TypeToDescriptor());
String id = MethodUtility.createID(resolver, method);
if (methodNameAndParamsT.contains(id)) {
return;
}
methodNameAndParamsT.add(id);
System.out.println("Method: " + method.name + " , paramsType: " + id);
// stores generics and their bounds of method
HashMap<String, String> genericsAndBoundsMethod = new HashMap<>();
method.getParameterList().accept(this);
String methDesc = null;
// Method getModifiers() ?
int acc = isInterface ? Opcodes.ACC_ABSTRACT : method.modifier;
System.out.println(acc);
/* Prüfe, ob die Rückgabe-Type der Methode eine Type-Variable ist */
boolean hasGenInParameterList = genericsAndBounds.containsKey(retType) || retType.contains("TPH ")
|| resultSet.resolveType(method.getReturnType()).resolvedType.acceptTV(new TypeToSignature())
.contains("<");
/*
* Wenn die Rückgabe-Type eine Typ-variable ist, erzeuge direkt die Signature,
* wenn nicht, prüfe, ob einer der Parameter Typ-Variable als Typ hat
*/
if (!hasGenInParameterList) {
for (String paramName : methodParamsAndTypes.keySet()) {
String typeOfParam = methodParamsAndTypes.get(paramName).acceptTV(new TypeToDescriptor());
String sigOfParam = methodParamsAndTypes.get(paramName).acceptTV(new TypeToSignature());
if (genericsAndBounds.containsKey(typeOfParam) || typeOfParam.contains("TPH ")
|| sigOfParam.contains("<")) {
hasGenInParameterList = true;
break;
}
}
}
// TODO: Test if the return-type or any of the parameter is a parameterized
// type. (VP)
// then create the descriptor with the new syntax.
String sig = null;
/*
* method.getGenerics: <....> RT method(..)
*/
boolean hasGen = method.getGenerics().iterator().hasNext() || hasGenInParameterList;
/* if method has generics or return type is TPH, create signature */
// zwite operand muss weggelassen werden
if (hasGen || resultSet.resolveType(method.getReturnType()).resolvedType.acceptTV(new TypeToString())
.equals("TPH")) {
List<GenericsGeneratorResult> constraints = generatedGenerics.getMethodConstraintsByID(id);
List<GenericsGeneratorResult> classConstraints = generatedGenerics.getClassConstraints();
Signature signature = new Signature(genericsAndBoundsMethod, genericsAndBounds,
methodParamsAndTypes, resultSet, constraints,classConstraints);
sig = signature.createSignatureForMethod(method);
}
System.out.println(method.getName() + " ==> " + sig);
NormalMethod meth = new NormalMethod(method, genericsAndBounds, genericsAndBoundsMethod, hasGen);
methDesc = meth.accept(new DescriptorToString(resultSet));
MethodVisitor mv = cw.visitMethod(Opcodes.ACC_PUBLIC + acc, method.getName(), methDesc, sig, null);
mv.visitCode();
BytecodeGenMethod gen = new BytecodeGenMethod(className, superClass, resultSet, method, mv, paramsAndLocals, cw,
genericsAndBoundsMethod, genericsAndBounds, isInterface, classFiles, sf, path, classLoader);
mv.visitMaxs(0, 0);
mv.visitEnd();
}
@Override
public void visit(ParameterList formalParameters) {
paramsAndLocals = new HashMap<>();
methodParamsAndTypes = new HashMap<>();
Iterator<FormalParameter> itr = formalParameters.iterator();
int i = 1;
while (itr.hasNext()) {
FormalParameter fp = itr.next();
paramsAndLocals.put(fp.getName(), i);
methodParamsAndTypes.put(fp.getName(), resultSet.resolveType(fp.getType()).resolvedType);
fp.accept(this);
i++;
}
}
@Override
public void visit(FormalParameter formalParameter) {
formalParameter.getType().accept(this);
}
@Override
public void visit(RefType refType) {
type = "L" + refType.toString() + ";";
}
@Override
public void visit(SuperWildcardType superWildcardType) {
// TODO Auto-generated method stub
}
@Override
public void visit(TypePlaceholder typePlaceholder) {
// TODO Auto-generated method stub
}
@Override
public void visit(ExtendsWildcardType extendsWildcardType) {
// TODO Auto-generated method stub
}
@Override
public void visit(GenericRefType genericRefType) {
// TODO Auto-generated method stub
}
// ??
@Override
public void visit(FieldVar fieldVar) {
System.out.println("In FieldVar ---");
// cw.newField(fieldVar.receiver.toString(), fieldVar.fieldVarName.toString(), fieldVar.getType().toString());
FieldVisitor fv = cw.visitField(Opcodes.ACC_PRIVATE, fieldVar.fieldVarName, "L" + fieldVar.getType() + ";",
null, null);
fv.visitEnd();
}
@Override
public void visit(Field field) {
System.out.println("In Field ---");
String des = "L";
if (resultSet.resolveType(field.getType()).resolvedType instanceof TypePlaceholder) {
des += Type.getInternalName(Object.class);
} else {
des += resultSet.resolveType(field.getType()).resolvedType.acceptTV(new TypeToDescriptor());
}
des += ";";
System.out.println(des);
String sig = resultSet.resolveType(field.getType()).resolvedType.acceptTV(new TypeToSignature(generatedGenerics.getClassConstraints()));
System.out.println(sig);
if (sig.charAt(sig.length() - 1) != (";").charAt(0)) {
sig += ";";
}
String nameAndDesc = field.getName() + "%%" + des;
String nameAndSig = field.getName() + "%%" + sig;
if (fieldNameAndParamsT.contains(nameAndDesc)) {
if (fieldNameSignature.contains(nameAndSig)) {
return;
}
throw new BytecodeGeneratorError("Bytecode generation aborted due to duplicate field name&signature");
}
fieldNameAndParamsT.add(nameAndDesc);
fieldNameSignature.add(nameAndSig);
cw.visitField(field.modifier, field.getName(), des, sig, null);
}
@Override
public void visit(LambdaExpression lambdaExpression) {
// TODO Auto-generated method stub
}
@Override
public void visit(Assign assign) {
// TODO Auto-generated method stub
}
@Override
public void visit(BinaryExpr binary) {
}
@Override
public void visit(Block block) {
// TODO Auto-generated method stub
}
@Override
public void visit(CastExpr castExpr) {
// TODO Auto-generated method stub
}
@Override
public void visit(EmptyStmt emptyStmt) {
// TODO Auto-generated method stub
}
@Override
public void visit(ForStmt forStmt) {
// TODO Auto-generated method stub
}
@Override
public void visit(IfStmt ifStmt) {
// TODO Auto-generated method stub
}
@Override
public void visit(InstanceOf instanceOf) {
// TODO Auto-generated method stub
}
@Override
public void visit(LocalVar localVar) {
// TODO Auto-generated method stub
}
@Override
public void visit(LocalVarDecl localVarDecl) {
// TODO Auto-generated method stub
}
@Override
public void visit(MethodCall methodCall) {
// TODO Auto-generated method stub
}
@Override
public void visit(NewClass methodCall) {
// TODO Auto-generated method stub
}
@Override
public void visit(NewArray newArray) {
// TODO Auto-generated method stub
}
@Override
public void visit(Return aReturn) {
// TODO Auto-generated method stub
}
@Override
public void visit(ReturnVoid aReturn) {
// TODO Auto-generated method stub
}
@Override
public void visit(StaticClassName staticClassName) {
// TODO Auto-generated method stub
}
@Override
public void visit(Super aSuper) {
// TODO Auto-generated method stub
}
@Override
public void visit(This aThis) {
// TODO Auto-generated method stub
}
@Override
public void visit(WhileStmt whileStmt) {
// TODO Auto-generated method stub
}
@Override
public void visit(DoStmt whileStmt) {
// TODO Auto-generated method stub
}
// ???
@Override
public void visit(Literal literal) {
// TODO Auto-generated method stub
}
@Override
public void visit(ArgumentList argumentList) {
// TODO Auto-generated method stub
}
@Override
public void visit(GenericTypeVar genericTypeVar) {
// TODO Auto-generated method stub
}
@Override
public void visit(GenericDeclarationList genericTypeVars) {
// TODO Auto-generated method stub
}
@Override
public void visit(AssignToField assignLeftSide) {
// TODO Auto-generated method stub
}
@Override
public void visit(AssignToLocal assignLeftSide) {
// TODO Auto-generated method stub
}
@Override
public void visit(SuperCall superCall) {
}
@Override
public void visit(ExpressionReceiver expressionReceiver) {
// TODO Auto-generated method stub
}
@Override
public void visit(UnaryExpr unaryExpr) {
throw new NotImplementedException();
}
}

View File

@ -1,19 +0,0 @@
/**
*
*/
package de.dhbwstuttgart.bytecode.Exception;
/**
* @author fayez
*
*/
public class BytecodeGeneratorError extends RuntimeException {
/**
* @param message
*/
public BytecodeGeneratorError(String message) {
super(message);
}
}

View File

@ -1,25 +0,0 @@
/**
*
*/
package de.dhbwstuttgart.bytecode.Exception;
/**
* @author fayez
*
*/
public class NotFoundException extends Exception {
/**
*
*/
private static final long serialVersionUID = 1L;
/**
* @param message
*/
public NotFoundException(String message) {
super(message);
}
}

View File

@ -1,26 +0,0 @@
/**
*
*/
package de.dhbwstuttgart.bytecode.Exception;
/**
* @author fayez
*
*/
public class NotInCurrentPackageException extends Exception {
/**
*
*/
private static final long serialVersionUID = 1L;
/**
* @param message
*/
public NotInCurrentPackageException(String message) {
super(message);
}
}

View File

@ -1,9 +0,0 @@
package de.dhbwstuttgart.bytecode;
import org.objectweb.asm.Label;
import org.objectweb.asm.MethodVisitor;
public interface IStatement {
public boolean isExprBinary();
public void genBCForRelOp(MethodVisitor mv, Label branchLabel, Label endLabel, BytecodeGenMethod bytecodeGenMethod);
}

View File

@ -1,29 +0,0 @@
package de.dhbwstuttgart.bytecode;
import org.objectweb.asm.Label;
import org.objectweb.asm.MethodVisitor;
import org.objectweb.asm.Opcodes;
import de.dhbwstuttgart.syntaxtree.statement.Expression;
import de.dhbwstuttgart.syntaxtree.statement.Statement;
public class IfStatement extends AStatement{
private Statement then_block;
private Statement else_block;
public IfStatement(Expression expr, Statement then_block, Statement else_block) {
super(expr);
this.then_block = then_block;
this.else_block = else_block;
}
@Override
public void genBCForRelOp(MethodVisitor mv,Label branchLabel, Label endLabel, BytecodeGenMethod bytecodeGenMethod) {
bytecodeGenMethod.isBinary(false);
this.then_block.accept(bytecodeGenMethod);
mv.visitLabel(branchLabel);
this.else_block.accept(bytecodeGenMethod);
}
}

View File

@ -1,26 +0,0 @@
package de.dhbwstuttgart.bytecode;
import org.objectweb.asm.Label;
import org.objectweb.asm.MethodVisitor;
import org.objectweb.asm.Opcodes;
import de.dhbwstuttgart.syntaxtree.statement.Expression;
import de.dhbwstuttgart.syntaxtree.statement.Statement;
public class LoopStmt extends AStatement {
private Statement loopBlock;
public LoopStmt(Expression expr, Statement loopBlock) {
super(expr);
this.loopBlock = loopBlock;
}
@Override
public void genBCForRelOp(MethodVisitor mv,Label branchLabel, Label endLabel, BytecodeGenMethod bytecodeGenMethod) {
bytecodeGenMethod.isBinary(false);
this.loopBlock.accept(bytecodeGenMethod);
mv.visitJumpInsn(Opcodes.GOTO, endLabel);
mv.visitLabel(branchLabel);
}
}

View File

@ -1,14 +0,0 @@
package de.dhbwstuttgart.bytecode;
import org.objectweb.asm.MethodVisitor;
import de.dhbwstuttgart.syntaxtree.statement.BinaryExpr;
import de.dhbwstuttgart.syntaxtree.statement.Expression;
public class ReturnStmt extends AStatement {
public ReturnStmt(Expression retexpr) {
super(retexpr);
}
}

View File

@ -1,269 +0,0 @@
/**
*
*/
package de.dhbwstuttgart.bytecode;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.function.Function;
import java.util.function.Predicate;
import java.util.stream.Collectors;
import de.dhbwstuttgart.bytecode.constraint.ExtendsConstraint;
import de.dhbwstuttgart.bytecode.constraint.TPHConstraint;
import de.dhbwstuttgart.bytecode.constraint.TPHConstraint.Relation;
import de.dhbwstuttgart.bytecode.utilities.MethodAndTPH;
import de.dhbwstuttgart.bytecode.utilities.MethodUtility;
import de.dhbwstuttgart.bytecode.utilities.Resolver;
import de.dhbwstuttgart.syntaxtree.AbstractASTWalker;
import de.dhbwstuttgart.syntaxtree.ClassOrInterface;
import de.dhbwstuttgart.syntaxtree.Constructor;
import de.dhbwstuttgart.syntaxtree.Field;
import de.dhbwstuttgart.syntaxtree.FormalParameter;
import de.dhbwstuttgart.syntaxtree.Method;
import de.dhbwstuttgart.syntaxtree.ParameterList;
import de.dhbwstuttgart.syntaxtree.statement.LocalVar;
import de.dhbwstuttgart.syntaxtree.statement.LocalVarDecl;
import de.dhbwstuttgart.syntaxtree.type.GenericRefType;
import de.dhbwstuttgart.syntaxtree.type.RefType;
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
import de.dhbwstuttgart.typeinference.constraints.Constraint;
import de.dhbwstuttgart.typeinference.constraints.ConstraintSet;
import de.dhbwstuttgart.typeinference.constraints.Pair;
import de.dhbwstuttgart.typeinference.result.GenericInsertPair;
import de.dhbwstuttgart.typeinference.result.ResultPair;
import de.dhbwstuttgart.typeinference.result.ResultSet;
/**
* @author Fayez Abu Alia
*
*/
public class TPHExtractor extends AbstractASTWalker {
// Alle TPHs der Felder werden iKopf der Klasse definiert
// alle TPHs der Klasse: (TPH, is in Method?)
public final HashMap<String, Boolean> allTPHS = new HashMap<>();
public final List<String> tphsClass = new ArrayList<>();
MethodAndTPH methodAndTph;
Boolean inMethod = false;
boolean inLocalOrParamOrReturn = false;
public final ArrayList<MethodAndTPH> ListOfMethodsAndTph = new ArrayList<>();
// Alle Constraints in einer Menge (Und- & Oder-Constraints)
public Set<Pair> oldConstraints = new HashSet<>();
final ArrayList<ResultPair<TypePlaceholder, TypePlaceholder>> allPairs = new ArrayList<>();
public final ArrayList<TPHConstraint> allCons = new ArrayList<>();
private ResultSet resultSet;
private Resolver resolver;
public TPHExtractor() {
}
public void setResultSet(ResultSet resultSet) {
this.resultSet = resultSet;
this.resolver = new Resolver(resultSet);
}
public Resolver getResolver() {
return resolver;
}
// @Override
// public void visit(ClassOrInterface classOrInterface) {
// inMethod = false;
// classOrInterface.getfieldInitializations().ifPresent(c->c.block.accept(this));
// super.visit(classOrInterface);
// inMethod = true;
// }
@Override
public void visit(TypePlaceholder tph) {
if (resultSet.resolveType(tph).resolvedType instanceof TypePlaceholder) {
TypePlaceholder resolvedTPH = (TypePlaceholder) resultSet.resolveType(tph).resolvedType;
String tphName = resolvedTPH.getName();
if (inMethod && !tphsClass.contains(tphName)) {
ArrayList<String> tphs = null;
if (!(tphs = methodAndTph.getTphs()).contains(tphName)) {
methodAndTph.addTph(tphName);
}
if (inLocalOrParamOrReturn) {
if (!(tphs = methodAndTph.getLocalTphs()).contains(tphName)) {
tphs.add(tphName);
}
}
} else {
if (!tphsClass.contains(tphName)) {
tphsClass.add(tphName);
}
}
if (!allTPHS.containsKey(tphName)) {
allTPHS.put(tphName, inMethod);
}
// final List<TPHConstraint> cons = new ArrayList<>();
// resultSet.resolveType(tph).additionalGenerics.forEach(ag -> {
// TPHConstraint con = new ExtendsConstraint(ag.TA1.getName(), ag.TA2.getName(), Relation.EXTENDS);
// cons.add(con);
// });
//
// Map<TPHConstraint, Boolean> visitMap = new HashMap<>();
// for(TPHConstraint cc : cons) {
// visitMap.put(cc, false);
// }
//
// String left = resolvedTPH.getName();
// for (TPHConstraint cc : visitMap.keySet()) {
//
// if(visitMap.get(cc))
// continue;
//
// if (cc.getLeft().equals(left)) {
// allCons.add(cc);
// List<TPHConstraint> toVisit = getToVisitCons(cons,cc.getRight(), visitMap);
// }
// }
//resultSet.resolveType(tph).getAdditionalGenerics().forEach(ag -> {
resultSet.genIns.forEach(ag -> {
// if (ag.contains(resolvedTPH) /* && ag.TA1.equals(resolvedTPH) */ && !contains(allPairs, ag)) {
if (inMethod)
methodAndTph.getPairs().add(ag);
allPairs.add(ag);
TPHConstraint con = new ExtendsConstraint(ag.getLeft().getName(), ag.getRight().getName());
if(!containsConstraint(allCons,con))
allCons.add(con);
// }
});
} else if (resultSet.resolveType(tph).resolvedType instanceof RefType) {
RefType rt = (RefType) resultSet.resolveType(tph).resolvedType;
rt.accept(this);
}
}
private static boolean containsConstraint(ArrayList<TPHConstraint> allCons, TPHConstraint c) {
for(TPHConstraint con:allCons) {
if(c.getLeft().equals(con.getLeft()) && c.getRight().equals(con.getRight())) {
return true;
}
}
return false;
}
private List<TPHConstraint> getToVisitCons(List<TPHConstraint> cons, String right, Map<TPHConstraint, Boolean> visitMap) {
List<TPHConstraint> res = new ArrayList<>();
for(TPHConstraint cc : cons) {
if(cc.getLeft().equals(right)) {
res.add(cc);
if(visitMap.get(cc))
visitMap.replace(cc, false);
}
}
return res;
}
@Override
public void visit(GenericRefType genericRefType) {
String name = genericRefType.getParsedName();
if (inMethod) {
methodAndTph.addTph(name);
if (inLocalOrParamOrReturn)
methodAndTph.getLocalTphs().add(name);
}else {
tphsClass.add(name);
}
allTPHS.put(name, inMethod);
}
private boolean contains(ArrayList<GenericInsertPair> pairs, GenericInsertPair genPair) {
for (int i = 0; i < pairs.size(); ++i) {
GenericInsertPair p = pairs.get(i);
if (p.TA1.equals(genPair.TA1) && p.TA2.equals(genPair.TA2))
return true;
}
return false;
}
@Override
public void visit(Method method) {
inMethod = true;
String id = MethodUtility.createID(resolver,method);
Predicate<Pair> filterUndConstraints = cs -> ((cs.TA1 instanceof TypePlaceholder) && (cs.TA2 instanceof TypePlaceholder) &&
(resultSet.resolveType((TypePlaceholder)(cs.TA1)).resolvedType instanceof TypePlaceholder) &&
(resultSet.resolveType((TypePlaceholder)(cs.TA2)).resolvedType instanceof TypePlaceholder));
Function<ConstraintSet<Pair>, ConstraintSet<Pair>> filterConstrRemainingTVar =
csS -> {
ConstraintSet<Pair> ret = new ConstraintSet<>();
ret.addAllUndConstraint(
csS.getUndConstraints()
.stream().filter(filterUndConstraints)
.collect(Collectors.toCollection(Constraint<Pair>::new)));
csS.getOderConstraints()
.forEach(oConSSet -> { Set<Constraint<Pair>> setCons = new HashSet<>();
oConSSet.forEach(OConS -> { Constraint<Pair> newConsPair = new Constraint<Pair>();
newConsPair.isStatement = OConS.isStatement;
setCons.add(
OConS.stream()
.filter(filterUndConstraints)
.collect(Collectors.toCollection(() -> newConsPair)) );
} );
ret.addOderConstraint(setCons);} );
return ret;
};
ConstraintSet<Pair> filteredConstraints = filterConstrRemainingTVar.apply(method.getConstraints());
methodAndTph = new MethodAndTPH(id, filteredConstraints);
oldConstraints.addAll(filteredConstraints.getAll());
inLocalOrParamOrReturn = true;
method.getReturnType().accept(this);
method.getParameterList().accept(this);
inLocalOrParamOrReturn = false;
if(method.block != null)
method.block.accept(this);
inMethod = false;
ListOfMethodsAndTph.add(methodAndTph);
}
@Override
public void visit(Constructor cons) {
inMethod = false;
//super.visit(cons);
cons.getParameterList().accept(this);
if(cons.block != null)
cons.block.accept(this);
inMethod = true;
}
@Override
public void visit(LocalVarDecl localVarDecl) {
// inLocalOrParamOrReturn = inMethod;
super.visit(localVarDecl);
// inLocalOrParamOrReturn = false;
}
@Override
public void visit(LocalVar localVar) {
// inLocalOrParamOrReturn = inMethod;
super.visit(localVar);
// inLocalOrParamOrReturn = false;
}
@Override
public void visit(ParameterList formalParameters) {
inLocalOrParamOrReturn = inMethod;
super.visit(formalParameters);
inLocalOrParamOrReturn = false;
}
}

View File

@ -1,9 +0,0 @@
package de.dhbwstuttgart.bytecode.constraint;
public class EqualConstraint extends TPHConstraint {
public EqualConstraint(String left, String right) {
super(left, right, Relation.EQUAL);
}
}

View File

@ -1,9 +0,0 @@
package de.dhbwstuttgart.bytecode.constraint;
public class ExtendsConstraint extends TPHConstraint {
public ExtendsConstraint(String left, String right) {
super(left, right, Relation.EXTENDS);
}
}

View File

@ -1,90 +0,0 @@
package de.dhbwstuttgart.bytecode.constraint;
import de.dhbwstuttgart.typeinference.constraints.Pair;
import de.dhbwstuttgart.typeinference.unify.model.PairOperator;
import de.dhbwstuttgart.bytecode.constraint.TPHConstraint.Relation;
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
public class TPHConstraint {
protected String left;
protected String right;
protected Relation rel;
protected int variance; //noch nicht benutzt
public enum Relation{
EXTENDS, EQUAL
}
public TPHConstraint(Pair p) {
this.left = ((TypePlaceholder)p.TA1).getName();
this.right = ((TypePlaceholder)p.TA2).getName();
this.rel = p.GetOperator().equals(PairOperator.SMALLERDOT) ? Relation.EXTENDS : Relation.EQUAL;
}
public TPHConstraint(String left, String right, Relation rel) {
this.left = left;
this.right = right;
this.rel = rel;
}
public String getLeft() {
return left;
}
public String getRight() {
return right;
}
public Relation getRel() {
return rel;
}
public void setLeft(String left) {
this.left = left;
}
public void setRight(String right) {
this.right = right;
}
public void setRel(Relation rel) {
this.rel = rel;
}
public boolean containTPH(String tph) {
return left.equals(tph)||right.equals(tph);
}
public boolean equalConstraint(TPHConstraint constraint) {
return rel == constraint.getRel() && left.equals(constraint.getLeft()) && right.equals(constraint.getRight());
}
@Override
public int hashCode() {
return (left+right).hashCode();
}
@Override
public boolean equals (Object o) {
if (o instanceof TPHConstraint) {
TPHConstraint o_tphcons = (TPHConstraint)o;
return (this.left.equals(o_tphcons.getLeft())
&& this.right.equals(o_tphcons.getRight())
&& this.rel.equals(o_tphcons.rel));
}
else {
return false;
}
}
@Override
public String toString() {
if(rel == Relation.EXTENDS) {
return left + " < " + right;
}else {
return left + " = " + right;
}
}
}

View File

@ -1,260 +0,0 @@
package de.dhbwstuttgart.bytecode.descriptor;
import java.util.HashMap;
import java.util.Iterator;
import de.dhbwstuttgart.bytecode.utilities.*;
import de.dhbwstuttgart.syntaxtree.statement.ArgumentList;
import org.objectweb.asm.Type;
import de.dhbwstuttgart.syntaxtree.FormalParameter;
import de.dhbwstuttgart.syntaxtree.statement.Expression;
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
import de.dhbwstuttgart.typeinference.result.ResultSet;
public class DescriptorToString implements DescriptorVisitor, CONSTANTS {
ResultSet resultSet;
public DescriptorToString() {
}
public DescriptorToString(ResultSet resultSet) {
this.resultSet = resultSet;
}
private String addReturnType(String desc, RefTypeOrTPHOrWildcardOrGeneric returnType, ResultSet resultSet) {
if(resultSet.resolveType(returnType).resolvedType.toString().equals(CONSTANTS.VOID)){
desc = desc + ")V";
}else {
desc = desc + ")" + "L"+resultSet.resolveType(returnType).resolvedType.acceptTV(new TypeToDescriptor())+ ";";
}
return desc;
}
@Override
public String visit(NormalMethod method) {
String desc = "(";
Iterator<FormalParameter> itr = method.getParameterList().iterator();
while(itr.hasNext()) {
FormalParameter fp = itr.next();
// System.out.println(resultSet.resolveType(fp.getType()).resolvedType.acceptTV(new TypeToSignature()));
// System.out.println("Parmetrisierte typ ? "+ ((RefType) fp.getType()).getParaList().size());
if(method.hasGen()) {
String fpDesc = fp.getType().acceptTV(new TypeToDescriptor());
if(method.getGenericsAndBoundsMethod().containsKey(fpDesc)) {
String bound = getBound(fpDesc, method.getGenericsAndBoundsMethod());
desc += "L"+bound+ ";";
}else if(method.getGenericsAndBounds().containsKey(fpDesc)){
String bound = getBound(fpDesc, method.getGenericsAndBounds());
desc += "L"+bound+ ";";
}else {
// desc += "L"+resultSet.resolveType(fp.getType()).resolvedType.acceptTV(new TypeToDescriptor())+ ";";
String resType = resultSet.resolveType(fp.getType()).resolvedType.acceptTV(new TypeToDescriptor());
if(resType.contains(CONSTANTS.TPH)/*resType.subSequence(0, 4).equals("TPH ")*/) {
// Bound ist immer Object
desc += "L"+Type.getInternalName(Object.class)+ ";";
} else {
// TODO::
if(method.getGenericsAndBounds().containsKey(resType)) {
String bound = getBound(resType, method.getGenericsAndBounds());
desc += "L"+bound+ ";";
}else if(method.getGenericsAndBoundsMethod().containsKey(resType)) {
String bound = getBound(resType, method.getGenericsAndBoundsMethod());
desc += "L"+bound+ ";";
} else {
desc += "L"+resType+ ";";
}
}
}
}
//TODO: generate a class java%% ... %%
else if(resultSet.resolveType(fp.getType()).resolvedType.acceptTV(new TypeToDescriptor()).contains(CONSTANTS.ANGLEBRACKET)){
desc += "L"+resultSet.resolveType(fp.getType()).resolvedType.toString().replace(".", "$$").replace(CONSTANTS.ANGLEBRACKET, "$$$").replace(">", "$$$")+ ";";
}
else {
desc += "L"+resultSet.resolveType(fp.getType()).resolvedType.acceptTV(new TypeToDescriptor())+ ";";
}
}
if(resultSet.resolveType(method.getReturnType()).resolvedType.toString().equals(CONSTANTS.VOID)) {
desc += ")V";
}else {
if(method.hasGen()) {
String ret = method.getReturnType().acceptTV(new TypeToDescriptor());
if(method.getGenericsAndBoundsMethod().containsKey(ret)) {
desc += ")L"+method.getGenericsAndBoundsMethod().get(ret)+ ";";
}else if(method.getGenericsAndBounds().containsKey(ret)){
desc += ")L"+method.getGenericsAndBounds().get(ret)+ ";";
}else {
String resType = resultSet.resolveType(method.getReturnType()).resolvedType.acceptTV(new TypeToDescriptor());
if(resType.contains(CONSTANTS.TPH)/*resType.subSequence(0, 4).equals("TPH ")*/) {
// desc += ")" + "L"+method.getGenericsAndBoundsMethod().get(resType.substring(4)+"$")+ ";";
desc += ")" + "L"+Type.getInternalName(Object.class)+ ";";
} else {
// TODO::
if(method.getGenericsAndBounds().containsKey(resType)) {
String bound = getBound(resType, method.getGenericsAndBounds());
desc += ")L"+bound+ ";";
}else if(method.getGenericsAndBoundsMethod().containsKey(resType)) {
String bound = getBound(resType, method.getGenericsAndBoundsMethod());
desc += ")L"+bound+ ";";
} else {
desc += ")L"+resType+ ";";
}
// desc += ")" + "L"+resType+ ";";
}
}
}else {
desc += ")" + "L"+resultSet.resolveType(method.getReturnType()).resolvedType.acceptTV(new TypeToDescriptor())+ ";";
}
}
// desc = addReturnType(desc,method.getReturnType(), resultSet);
return desc;
}
private String getBound(String fpDesc, HashMap<String, String> genericsAndBounds) {
String start = genericsAndBounds.get(fpDesc);
while(genericsAndBounds.containsKey(start)) {
start = genericsAndBounds.get(start);
}
return start;
}
@Override
public String visit(NormalConstructor constructor) {
String desc = "(";
Iterator<FormalParameter> itr = constructor.getParameterList().iterator();
while(itr.hasNext()) {
FormalParameter fp = itr.next();
if(constructor.hasGen()) {
// System.out.println("Cons has Gens");
String fpDesc = fp.getType().acceptTV(new TypeToDescriptor());
// System.out.println(fpDesc);
if(constructor.getGenericsAndBounds().containsKey(fpDesc)){
desc += "L"+constructor.getGenericsAndBounds().get(fpDesc)+ ";";
}else {
// desc += "L"+resultSet.resolveType(fp.getType()).resolvedType.acceptTV(new TypeToDescriptor())+ ";";
String resType = resultSet.resolveType(fp.getType()).resolvedType.acceptTV(new TypeToDescriptor());
if(resType.subSequence(0, 4).equals(CONSTANTS.TPH)) {
// Bound ist immer Object
desc += "L"+Type.getInternalName(Object.class)+ ";";
} else {
desc += "L"+resType+ ";";
}
}
}else {
// System.out.println("Cons has NO Gens");
desc += "L"+resultSet.resolveType(fp.getType()).resolvedType.acceptTV(new TypeToDescriptor())+ ";";
}
}
desc = desc + ")V";
return desc;
}
//ToDo Etienne: ändern
@Override
public String visit(Lambda lambdaExpression) {
String desc = "(";
Iterator<FormalParameter> itr = lambdaExpression.getParams().iterator();
while(itr.hasNext()) {
FormalParameter fp = itr.next();
String d = resultSet.resolveType(fp.getType()).resolvedType.acceptTV(new TypeToDescriptor());
if(d.contains(CONSTANTS.TPH) ||d.contains(CONSTANTS.ANGLEBRACKET)) {
desc += "L"+Type.getInternalName(Object.class)+ ";";
}else {
desc = desc + "L"+ d + ";";
}
}
String retType = resultSet.resolveType(lambdaExpression.getReturnType()).resolvedType.acceptTV(new TypeToDescriptor());
if(retType.contains(CONSTANTS.TPH)|| retType.contains(CONSTANTS.ANGLEBRACKET)){
desc += ")L"+Type.getInternalName(Object.class)+ ";";
}else {
desc = desc + ")"+"L"+retType+";";
}
return desc;
}
@Override
public String visit(SamMethod samMethod) {
String desc = "(";
Iterator<RefTypeOrTPHOrWildcardOrGeneric> itr = samMethod.getArgumentList().iterator();
while(itr.hasNext()) {
RefTypeOrTPHOrWildcardOrGeneric rt = itr.next();
String d = resultSet.resolveType(rt).resolvedType.acceptTV(new TypeToDescriptor());
if(d.contains(CONSTANTS.TPH) ||d.contains(CONSTANTS.ANGLEBRACKET)) {
desc += "L"+Type.getInternalName(Object.class)+ ";";
}else {
desc += "L"+ d + ";";
}
}
String retType = resultSet.resolveType(samMethod.getReturnType()).resolvedType.acceptTV(new TypeToDescriptor());
if(retType.contains(CONSTANTS.TPH)|| retType.contains(CONSTANTS.ANGLEBRACKET)){
desc += ")L"+Type.getInternalName(Object.class)+ ";";
}else {
desc = desc + ")"+"L"+retType+";";
}
return desc;
}
@Override
public String visit(MethodFromMethodCall methodFromMethodCall) {
String desc = "(";
for(Expression e : methodFromMethodCall.getArgList().getArguments()) {
String d = resultSet.resolveType(e.getType()).resolvedType.acceptTV(new TypeToDescriptor());
if(d.contains(CONSTANTS.TPH) ||d.contains(CONSTANTS.ANGLEBRACKET) || methodFromMethodCall.getReceiverName().contains("$$")) {
desc += "L"+Type.getInternalName(Object.class)+ ";";
}else {
if(methodFromMethodCall.getGenericsAndBoundsMethod().containsKey(d)) {
desc += "L"+methodFromMethodCall.getGenericsAndBoundsMethod().get(d)+ ";";
}else if(methodFromMethodCall.getGenericsAndBounds().containsKey(d)) {
desc += "L"+methodFromMethodCall.getGenericsAndBounds().get(d)+ ";";
}else {
desc += "L"+resultSet.resolveType(e.getType()).resolvedType.acceptTV(new TypeToDescriptor())+ ";";
}
}
}
String retType = resultSet.resolveType(methodFromMethodCall.getReturnType()).resolvedType.acceptTV(new TypeToDescriptor());
System.out.println("DescriptorToString retType = " + retType);
if(retType.equals(CONSTANTS.VOID)) {
desc += ")V";
}else if(retType.contains(CONSTANTS.TPH)|| retType.contains(CONSTANTS.ANGLEBRACKET) || methodFromMethodCall.getReceiverName().contains("$$")){
desc += ")L"+Type.getInternalName(Object.class)+ ";";
}else {
if(methodFromMethodCall.getGenericsAndBoundsMethod().containsKey(retType)) {
desc += ")L"+methodFromMethodCall.getGenericsAndBoundsMethod().get(retType)+ ";";
}else if(methodFromMethodCall.getGenericsAndBounds().containsKey(retType)){
desc += ")L"+methodFromMethodCall.getGenericsAndBounds().get(retType)+ ";";
}else {
desc += ")" + "L"+retType+ ";";
}
}
// desc = addReturnType(desc, methodFromMethodCall.getReturnType(), resultSet);
return desc;
}
@Override
public String createDescForFunN(ArgumentList argumentList, String returnType) {
Iterator<Expression> itr1 = argumentList.getArguments().iterator();
String methDesc = "(";
while(itr1.hasNext()) {
methDesc += "L" + Type.getInternalName(Object.class) + ";";
itr1.next();
}
if (returnType.equals(CONSTANTS.VOID)){
methDesc += ")V";
} else {
methDesc += ")L" + Type.getInternalName(Object.class) + ";";
}
return methDesc;
}
}

View File

@ -1,17 +0,0 @@
package de.dhbwstuttgart.bytecode.descriptor;
import de.dhbwstuttgart.bytecode.utilities.Lambda;
import de.dhbwstuttgart.bytecode.utilities.MethodFromMethodCall;
import de.dhbwstuttgart.bytecode.utilities.NormalConstructor;
import de.dhbwstuttgart.bytecode.utilities.NormalMethod;
import de.dhbwstuttgart.bytecode.utilities.SamMethod;
import de.dhbwstuttgart.syntaxtree.statement.ArgumentList;
public interface DescriptorVisitor {
String visit(NormalMethod method);
String visit(NormalConstructor constructor);
String visit(Lambda lambdaExpression);
String visit(SamMethod samMethod);
String visit(MethodFromMethodCall methodFromMethodCall);
String createDescForFunN(ArgumentList argumentList, String returnType);
}

Some files were not shown because too many files have changed in this diff Show More