Merge branch 'bigRefactoring'
This commit is contained in:
commit
c442e2ac17
22
.classpath
22
.classpath
@ -1,22 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<classpath>
|
|
||||||
<classpathentry kind="src" path="src"/>
|
|
||||||
<classpathentry kind="src" path="test"/>
|
|
||||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/>
|
|
||||||
<classpathentry kind="lib" path="lib/bcel-6.1-SNAPSHOT.jar" sourcepath="lib/bcel-6.1-SNAPSHOT-sources.jar"/>
|
|
||||||
<classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/4"/>
|
|
||||||
<classpathentry kind="lib" path="lib/antlr-complete.jar"/>
|
|
||||||
<classpathentry kind="lib" path="lib/annotations-2.0.1.jar"/>
|
|
||||||
<classpathentry kind="lib" path="lib/bcel-6.1-SNAPSHOT-sources.jar"/>
|
|
||||||
<classpathentry kind="lib" path="lib/cloning.jar"/>
|
|
||||||
<classpathentry kind="lib" path="lib/commons-bcel6-6.0-SNAPSHOT.jar"/>
|
|
||||||
<classpathentry kind="lib" path="lib/javassist-3.19.0-GA.jar"/>
|
|
||||||
<classpathentry kind="lib" path="lib/junit-4.0.jar"/>
|
|
||||||
<classpathentry kind="lib" path="lib/log4j-1.2.12.jar"/>
|
|
||||||
<classpathentry kind="lib" path="lib/reflections-0.9.10-javadoc.jar"/>
|
|
||||||
<classpathentry kind="lib" path="lib/reflections-0.9.10-sources.jar"/>
|
|
||||||
<classpathentry kind="lib" path="lib/reflections-0.9.10.jar" sourcepath="/reflections/src"/>
|
|
||||||
<classpathentry kind="lib" path="lib/guava-22.0.jar" sourcepath="lib/guava-22.0-sources.jar"/>
|
|
||||||
<classpathentry kind="lib" path="lib/guava-15.0.jar"/>
|
|
||||||
<classpathentry kind="output" path="bin"/>
|
|
||||||
</classpath>
|
|
10
.gitignore
vendored
10
.gitignore
vendored
@ -10,3 +10,13 @@ bin
|
|||||||
*.jar
|
*.jar
|
||||||
*.war
|
*.war
|
||||||
*.ear
|
*.ear
|
||||||
|
|
||||||
|
# IDEs
|
||||||
|
.classpath
|
||||||
|
*.iml
|
||||||
|
.idea/
|
||||||
|
/target/
|
||||||
|
.DS_Store
|
||||||
|
.project
|
||||||
|
.settings/
|
||||||
|
|
||||||
|
22
.idea/libraries/lib.xml
generated
22
.idea/libraries/lib.xml
generated
@ -1,22 +0,0 @@
|
|||||||
<component name="libraryTable">
|
|
||||||
<library name="lib">
|
|
||||||
<CLASSES>
|
|
||||||
<root url="jar://$PROJECT_DIR$/lib/log4j-1.2.12.jar!/" />
|
|
||||||
<root url="jar://$PROJECT_DIR$/lib/guava-10.0.1.jar!/" />
|
|
||||||
<root url="jar://$PROJECT_DIR$/lib/bcel-6.1-SNAPSHOT.jar!/" />
|
|
||||||
<root url="jar://$PROJECT_DIR$/lib/bcel-6.1-SNAPSHOT-sources.jar!/" />
|
|
||||||
<root url="jar://$PROJECT_DIR$/lib/annotations-2.0.1.jar!/" />
|
|
||||||
<root url="jar://$PROJECT_DIR$/lib/guava-15.0.jar!/" />
|
|
||||||
<root url="jar://$PROJECT_DIR$/lib/junit-4.0.jar!/" />
|
|
||||||
<root url="jar://$PROJECT_DIR$/lib/commons-bcel6-6.0-SNAPSHOT.jar!/" />
|
|
||||||
<root url="jar://$PROJECT_DIR$/lib/reflections-0.9.10-javadoc.jar!/" />
|
|
||||||
<root url="jar://$PROJECT_DIR$/lib/reflections-0.9.10.jar!/" />
|
|
||||||
<root url="jar://$PROJECT_DIR$/lib/cloning.jar!/" />
|
|
||||||
<root url="jar://$PROJECT_DIR$/lib/javassist-3.19.0-GA.jar!/" />
|
|
||||||
<root url="jar://$PROJECT_DIR$/lib/reflections-0.9.10-sources.jar!/" />
|
|
||||||
<root url="jar://$PROJECT_DIR$/lib/antlr-complete.jar!/" />
|
|
||||||
</CLASSES>
|
|
||||||
<JAVADOC />
|
|
||||||
<SOURCES />
|
|
||||||
</library>
|
|
||||||
</component>
|
|
17
.project
17
.project
@ -1,17 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<projectDescription>
|
|
||||||
<name>JavaCompilerCore</name>
|
|
||||||
<comment></comment>
|
|
||||||
<projects>
|
|
||||||
</projects>
|
|
||||||
<buildSpec>
|
|
||||||
<buildCommand>
|
|
||||||
<name>org.eclipse.jdt.core.javabuilder</name>
|
|
||||||
<arguments>
|
|
||||||
</arguments>
|
|
||||||
</buildCommand>
|
|
||||||
</buildSpec>
|
|
||||||
<natures>
|
|
||||||
<nature>org.eclipse.jdt.core.javanature</nature>
|
|
||||||
</natures>
|
|
||||||
</projectDescription>
|
|
@ -1,12 +0,0 @@
|
|||||||
eclipse.preferences.version=1
|
|
||||||
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
|
|
||||||
org.eclipse.jdt.core.compiler.codegen.methodParameters=do not generate
|
|
||||||
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
|
|
||||||
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
|
|
||||||
org.eclipse.jdt.core.compiler.compliance=1.8
|
|
||||||
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
|
|
||||||
org.eclipse.jdt.core.compiler.debug.localVariable=generate
|
|
||||||
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
|
|
||||||
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
|
|
||||||
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
|
|
||||||
org.eclipse.jdt.core.compiler.source=1.8
|
|
@ -1,9 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<module type="WEB_MODULE" version="4">
|
|
||||||
<component name="NewModuleRootManager" inherit-compiler-output="true">
|
|
||||||
<exclude-output />
|
|
||||||
<content url="file://$MODULE_DIR$" />
|
|
||||||
<orderEntry type="inheritedJdk" />
|
|
||||||
<orderEntry type="sourceFolder" forTests="false" />
|
|
||||||
</component>
|
|
||||||
</module>
|
|
@ -1,9 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<module type="WEB_MODULE" version="4">
|
|
||||||
<component name="NewModuleRootManager" inherit-compiler-output="true">
|
|
||||||
<exclude-output />
|
|
||||||
<content url="file://$MODULE_DIR$" />
|
|
||||||
<orderEntry type="inheritedJdk" />
|
|
||||||
<orderEntry type="sourceFolder" forTests="false" />
|
|
||||||
</component>
|
|
||||||
</module>
|
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
BIN
lib/cloning.jar
BIN
lib/cloning.jar
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
30
pom.xml
30
pom.xml
@ -31,6 +31,11 @@
|
|||||||
<groupId>org.reflections</groupId>
|
<groupId>org.reflections</groupId>
|
||||||
<artifactId>reflections</artifactId>
|
<artifactId>reflections</artifactId>
|
||||||
<version>0.9.11</version>
|
<version>0.9.11</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.ow2.asm</groupId>
|
||||||
|
<artifactId>asm-all</artifactId>
|
||||||
|
<version>[4.0.0,)</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
@ -41,7 +46,30 @@
|
|||||||
<testOutputDirectory>target/test-classes</testOutputDirectory>
|
<testOutputDirectory>target/test-classes</testOutputDirectory>
|
||||||
<sourceDirectory>src/</sourceDirectory>
|
<sourceDirectory>src/</sourceDirectory>
|
||||||
<testSourceDirectory>test/</testSourceDirectory>
|
<testSourceDirectory>test/</testSourceDirectory>
|
||||||
</build>
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.antlr</groupId>
|
||||||
|
<artifactId>antlr4-maven-plugin</artifactId>
|
||||||
|
<version>4.7</version>
|
||||||
|
<executions>
|
||||||
|
<execution>
|
||||||
|
<id>antlr</id>
|
||||||
|
<goals>
|
||||||
|
<goal>antlr4</goal>
|
||||||
|
</goals>
|
||||||
|
<configuration>
|
||||||
|
<sourceDirectory>src/de/dhbwstuttgart/parser/antlr/</sourceDirectory>
|
||||||
|
<outputDirectory>src/de/dhbwstuttgart/parser/antlr/</outputDirectory>
|
||||||
|
<arguments>
|
||||||
|
<argument>-package</argument>
|
||||||
|
<argument>de.dhbwstuttgart.parser.antlr</argument>
|
||||||
|
</arguments>
|
||||||
|
</configuration>
|
||||||
|
</execution>
|
||||||
|
</executions>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
</build>
|
||||||
<properties>
|
<properties>
|
||||||
<maven.compiler.source>1.8</maven.compiler.source>
|
<maven.compiler.source>1.8</maven.compiler.source>
|
||||||
<maven.compiler.target>1.8</maven.compiler.target>
|
<maven.compiler.target>1.8</maven.compiler.target>
|
||||||
|
@ -1,11 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<module type="JAVA_MODULE" version="4">
|
|
||||||
<component name="NewModuleRootManager" inherit-compiler-output="true">
|
|
||||||
<exclude-output />
|
|
||||||
<content url="file://$MODULE_DIR$">
|
|
||||||
<sourceFolder url="file://$MODULE_DIR$" isTestSource="false" />
|
|
||||||
</content>
|
|
||||||
<orderEntry type="inheritedJdk" />
|
|
||||||
<orderEntry type="sourceFolder" forTests="false" />
|
|
||||||
</component>
|
|
||||||
</module>
|
|
BIN
src/de/dhbwstuttgart/.DS_Store
vendored
Normal file
BIN
src/de/dhbwstuttgart/.DS_Store
vendored
Normal file
Binary file not shown.
386
src/de/dhbwstuttgart/bytecode/BytecodeGen.java
Normal file
386
src/de/dhbwstuttgart/bytecode/BytecodeGen.java
Normal file
@ -0,0 +1,386 @@
|
|||||||
|
package de.dhbwstuttgart.bytecode;
|
||||||
|
|
||||||
|
import java.awt.List;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Iterator;
|
||||||
|
|
||||||
|
import org.objectweb.asm.ClassWriter;
|
||||||
|
import org.objectweb.asm.FieldVisitor;
|
||||||
|
import org.objectweb.asm.MethodVisitor;
|
||||||
|
import org.objectweb.asm.Opcodes;
|
||||||
|
|
||||||
|
import de.dhbwstuttgart.parser.SyntaxTreeGenerator.AssignToLocal;
|
||||||
|
import de.dhbwstuttgart.syntaxtree.*;
|
||||||
|
import de.dhbwstuttgart.syntaxtree.statement.ArgumentList;
|
||||||
|
import de.dhbwstuttgart.syntaxtree.statement.Assign;
|
||||||
|
import de.dhbwstuttgart.syntaxtree.statement.AssignToField;
|
||||||
|
import de.dhbwstuttgart.syntaxtree.statement.Binary;
|
||||||
|
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.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.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.Receiver;
|
||||||
|
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.UnaryPlus;
|
||||||
|
import de.dhbwstuttgart.syntaxtree.statement.WhileStmt;
|
||||||
|
import de.dhbwstuttgart.syntaxtree.statement.literal.Literal;
|
||||||
|
import de.dhbwstuttgart.syntaxtree.statement.literal.Null;
|
||||||
|
import de.dhbwstuttgart.syntaxtree.type.ExtendsWildcardType;
|
||||||
|
import de.dhbwstuttgart.syntaxtree.type.GenericRefType;
|
||||||
|
import de.dhbwstuttgart.syntaxtree.type.RefType;
|
||||||
|
import de.dhbwstuttgart.syntaxtree.type.SuperWildcardType;
|
||||||
|
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
|
||||||
|
|
||||||
|
public class BytecodeGen implements ASTVisitor {
|
||||||
|
|
||||||
|
ClassWriter cw =new ClassWriter(ClassWriter.COMPUTE_FRAMES|ClassWriter.COMPUTE_MAXS);
|
||||||
|
// String methDesc;
|
||||||
|
|
||||||
|
String type;
|
||||||
|
|
||||||
|
String className;
|
||||||
|
|
||||||
|
// 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<>();
|
||||||
|
byte[] bytecode;
|
||||||
|
HashMap<String,byte[]> classFiles;
|
||||||
|
|
||||||
|
public BytecodeGen(HashMap<String,byte[]> classFiles) {
|
||||||
|
this.classFiles = classFiles;
|
||||||
|
paramsAndLocals = new HashMap<>();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void visit(SourceFile sourceFile) {
|
||||||
|
for(ClassOrInterface cl : sourceFile.getClasses()) {
|
||||||
|
BytecodeGen classGen = new BytecodeGen(classFiles);
|
||||||
|
cl.accept(classGen);
|
||||||
|
classGen.writeClass(cl.getClassName().toString());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void writeClass(String name) {
|
||||||
|
bytecode = cw.toByteArray();
|
||||||
|
classFiles.put(name, bytecode);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public HashMap<String,byte[]> getClassFiles() {
|
||||||
|
return classFiles;
|
||||||
|
}
|
||||||
|
@Override
|
||||||
|
public void visit(ClassOrInterface classOrInterface) {
|
||||||
|
className = classOrInterface.getClassName().toString();
|
||||||
|
// access flages??
|
||||||
|
cw.visit(Opcodes.V1_8, classOrInterface.getModifiers()+Opcodes.ACC_SUPER, classOrInterface.getClassName().toString()
|
||||||
|
, null, classOrInterface.getSuperClass().toString(), null);
|
||||||
|
|
||||||
|
// for each field in the class
|
||||||
|
for(Field f : classOrInterface.getFieldDecl()) {
|
||||||
|
System.out.println("get Fields");
|
||||||
|
System.out.println(f.getName());
|
||||||
|
f.accept(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
for(Constructor c : classOrInterface.getConstructors()) {
|
||||||
|
c.accept(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
for(Method m : classOrInterface.getMethods()) {
|
||||||
|
m.accept(this);
|
||||||
|
}
|
||||||
|
cw.visitSource(classOrInterface.getClassName().toString()+".jav", null);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void visit(Constructor field) {
|
||||||
|
Descriptor desc = new Descriptor(field);
|
||||||
|
MethodVisitor mv = cw.visitMethod(Opcodes.ACC_PUBLIC, "<init>", desc.getDesc(), null, null);
|
||||||
|
mv.visitCode();
|
||||||
|
System.out.println("-----Constructor-----");
|
||||||
|
BytecodeGenMethod gen = new BytecodeGenMethod(className,field, mv,paramsAndLocals,desc.getDesc(),cw);
|
||||||
|
|
||||||
|
mv.visitInsn(Opcodes.RETURN);
|
||||||
|
mv.visitMaxs(0, 0);
|
||||||
|
mv.visitEnd();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void visit(Method method) {
|
||||||
|
method.getParameterList().accept(this);
|
||||||
|
Descriptor methDesc = new Descriptor(method);
|
||||||
|
System.out.println("-----Method-----");
|
||||||
|
MethodVisitor mv = cw.visitMethod(Opcodes.ACC_PUBLIC, method.getName(), methDesc.getDesc(), null, null);
|
||||||
|
mv.visitCode();
|
||||||
|
|
||||||
|
BytecodeGenMethod gen = new BytecodeGenMethod(className,method, mv,paramsAndLocals,methDesc.getDesc(),cw);
|
||||||
|
mv.visitMaxs(0, 0);
|
||||||
|
mv.visitEnd();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void visit(ParameterList formalParameters) {
|
||||||
|
Iterator<FormalParameter> itr = formalParameters.iterator();
|
||||||
|
int i = 1;
|
||||||
|
while(itr.hasNext()) {
|
||||||
|
FormalParameter fp = itr.next();
|
||||||
|
paramsAndLocals.put(fp.getName(), i);
|
||||||
|
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();
|
||||||
|
}
|
||||||
|
|
||||||
|
// access flages?? modifiers
|
||||||
|
@Override
|
||||||
|
public void visit(Field field) {
|
||||||
|
System.out.println("in field");
|
||||||
|
FieldVisitor fv = cw.visitField(Opcodes.ACC_PRIVATE, field.getName(), "L"+field.getType().toString().replace(".", "/")+";", null, null);
|
||||||
|
fv.visitEnd();
|
||||||
|
}
|
||||||
|
|
||||||
|
@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(Binary binary) {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@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(Receiver receiver) {
|
||||||
|
// 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(UnaryPlus unaryPlus) {
|
||||||
|
// 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(Null aNull) {
|
||||||
|
// 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) {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
227
src/de/dhbwstuttgart/bytecode/BytecodeGenLambda.java
Normal file
227
src/de/dhbwstuttgart/bytecode/BytecodeGenLambda.java
Normal file
@ -0,0 +1,227 @@
|
|||||||
|
package de.dhbwstuttgart.bytecode;
|
||||||
|
|
||||||
|
import org.objectweb.asm.MethodVisitor;
|
||||||
|
|
||||||
|
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.Binary;
|
||||||
|
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.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.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.Receiver;
|
||||||
|
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.UnaryPlus;
|
||||||
|
import de.dhbwstuttgart.syntaxtree.statement.WhileStmt;
|
||||||
|
import de.dhbwstuttgart.syntaxtree.statement.literal.Literal;
|
||||||
|
import de.dhbwstuttgart.syntaxtree.statement.literal.Null;
|
||||||
|
|
||||||
|
public class BytecodeGenLambda implements StatementVisitor{
|
||||||
|
private LambdaExpression lambdaExpression;
|
||||||
|
private MethodVisitor mv;
|
||||||
|
|
||||||
|
public BytecodeGenLambda(LambdaExpression lambdaExpression, MethodVisitor mv) {
|
||||||
|
this.lambdaExpression = lambdaExpression;
|
||||||
|
this.mv = mv;
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void visit(ArgumentList argumentList) {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@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(Binary binary) {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@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(FieldVar fieldVar) {
|
||||||
|
// 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(Receiver receiver) {
|
||||||
|
// 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(UnaryPlus unaryPlus) {
|
||||||
|
// 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(Null aNull) {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void visit(Literal literal) {
|
||||||
|
// 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
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
360
src/de/dhbwstuttgart/bytecode/BytecodeGenMethod.java
Normal file
360
src/de/dhbwstuttgart/bytecode/BytecodeGenMethod.java
Normal file
@ -0,0 +1,360 @@
|
|||||||
|
package de.dhbwstuttgart.bytecode;
|
||||||
|
|
||||||
|
import java.io.PrintStream;
|
||||||
|
import java.lang.invoke.CallSite;
|
||||||
|
import java.lang.invoke.MethodHandle;
|
||||||
|
import java.lang.invoke.MethodHandles;
|
||||||
|
import java.lang.invoke.MethodType;
|
||||||
|
import java.security.GeneralSecurityException;
|
||||||
|
import java.util.HashMap;
|
||||||
|
|
||||||
|
import org.objectweb.asm.ClassWriter;
|
||||||
|
import org.objectweb.asm.Handle;
|
||||||
|
import org.objectweb.asm.MethodVisitor;
|
||||||
|
import org.objectweb.asm.Opcodes;
|
||||||
|
import org.objectweb.asm.Type;
|
||||||
|
|
||||||
|
import de.dhbwstuttgart.parser.SyntaxTreeGenerator.AssignToLocal;
|
||||||
|
import de.dhbwstuttgart.syntaxtree.Method;
|
||||||
|
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.Binary;
|
||||||
|
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.Expression;
|
||||||
|
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.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.Receiver;
|
||||||
|
import de.dhbwstuttgart.syntaxtree.statement.Return;
|
||||||
|
import de.dhbwstuttgart.syntaxtree.statement.ReturnVoid;
|
||||||
|
import de.dhbwstuttgart.syntaxtree.statement.Statement;
|
||||||
|
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.UnaryPlus;
|
||||||
|
import de.dhbwstuttgart.syntaxtree.statement.WhileStmt;
|
||||||
|
import de.dhbwstuttgart.syntaxtree.statement.literal.Literal;
|
||||||
|
import de.dhbwstuttgart.syntaxtree.statement.literal.Null;
|
||||||
|
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
|
||||||
|
|
||||||
|
public class BytecodeGenMethod implements StatementVisitor{
|
||||||
|
|
||||||
|
private Method m;
|
||||||
|
private MethodVisitor mv;
|
||||||
|
private HashMap<String, Integer> paramsAndLocals = new HashMap<>();
|
||||||
|
private String desc;
|
||||||
|
private String className;
|
||||||
|
private int lamCounter;
|
||||||
|
private ClassWriter cw;
|
||||||
|
|
||||||
|
//for tests **
|
||||||
|
private String fieldName;
|
||||||
|
private String fieldDesc;
|
||||||
|
private Expression rightSideTemp;
|
||||||
|
private String where;
|
||||||
|
|
||||||
|
public BytecodeGenMethod(String className, Method m, MethodVisitor mv, HashMap<String, Integer> paramsAndLocals,
|
||||||
|
String desc, ClassWriter cw) {
|
||||||
|
|
||||||
|
this.where = "NORMAL METHOD";
|
||||||
|
|
||||||
|
this.className = className;
|
||||||
|
this.m = m;
|
||||||
|
this.mv = mv;
|
||||||
|
this.paramsAndLocals = paramsAndLocals;
|
||||||
|
this.desc = desc;
|
||||||
|
this.cw = cw;
|
||||||
|
this.lamCounter = -1;
|
||||||
|
|
||||||
|
this.m.block.accept(this);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public BytecodeGenMethod(LambdaExpression lambdaExpression, MethodVisitor mv,
|
||||||
|
HashMap<String, Integer> paramsAndLocals, String desc) {
|
||||||
|
System.out.println("++++++IN LAMBDA -------");
|
||||||
|
|
||||||
|
this.where = "&&&&&&&& LAMBDA METHOD";
|
||||||
|
|
||||||
|
this.mv = mv;
|
||||||
|
this.paramsAndLocals = paramsAndLocals;
|
||||||
|
this.desc = desc;
|
||||||
|
|
||||||
|
this.lamCounter = -1;
|
||||||
|
|
||||||
|
lambdaExpression.methodBody.accept(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void visit(Block block) {
|
||||||
|
for(Statement stmt : block.getStatements()) {
|
||||||
|
System.out.println(where);
|
||||||
|
System.out.println("Stmt : " + stmt.toString());
|
||||||
|
stmt.accept(this);
|
||||||
|
System.out.println("--------------------------\n");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void visit(SuperCall superCall) {
|
||||||
|
superCall.receiver.accept(this);
|
||||||
|
superCall.arglist.accept(this);
|
||||||
|
// mv.visitMethodInsn(Opcodes.INVOKESPECIAL, "java/lang/Object", superCall.name, desc,false);
|
||||||
|
mv.visitMethodInsn(Opcodes.INVOKESPECIAL, Type.getInternalName(Object.class), superCall.name, desc,false);
|
||||||
|
}
|
||||||
|
|
||||||
|
// ??
|
||||||
|
@Override
|
||||||
|
public void visit(LocalVar localVar) {
|
||||||
|
System.out.println("in Local Var");
|
||||||
|
}
|
||||||
|
// ??
|
||||||
|
@Override
|
||||||
|
public void visit(LocalVarDecl localVarDecl) {
|
||||||
|
// Integer i;
|
||||||
|
paramsAndLocals.put(localVarDecl.getName(), paramsAndLocals.size()+1);
|
||||||
|
System.out.println("In localVarDecl");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void visit(Assign assign) {
|
||||||
|
System.out.println("Assign : \nright = "+assign.rightSide + "\nLeft = " + assign.lefSide);
|
||||||
|
|
||||||
|
if(assign.lefSide.getClass().equals(AssignToField.class)) {
|
||||||
|
// load_0, ldc or .. then putfield
|
||||||
|
this.rightSideTemp = assign.rightSide;
|
||||||
|
assign.lefSide.accept(this);
|
||||||
|
}else {
|
||||||
|
assign.rightSide.accept(this);
|
||||||
|
assign.lefSide.accept(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void visit(Binary binary) {
|
||||||
|
System.out.println("++ In Binary: ");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void visit(LambdaExpression lambdaExpression) {
|
||||||
|
System.out.println("\n++ In Lambda: ");
|
||||||
|
this.lamCounter++;
|
||||||
|
//Call site, which, when invoked, returns an instance of the functional interface to which
|
||||||
|
//the lambda is being converted
|
||||||
|
MethodType mt = MethodType.methodType(CallSite.class, MethodHandles.Lookup.class, String.class,
|
||||||
|
MethodType.class, MethodType.class, MethodHandle.class, MethodType.class);
|
||||||
|
|
||||||
|
Handle bootstrap = new Handle(Opcodes.H_INVOKESTATIC, "java/lang/invoke/LambdaMetafactory",
|
||||||
|
"metafactory", mt.toMethodDescriptorString(), false);
|
||||||
|
String methodName = "lambda$new$" + this.lamCounter;
|
||||||
|
// Type erasure
|
||||||
|
Type arg1 = Type.getMethodType("()V");
|
||||||
|
// real Type
|
||||||
|
Type arg3 = Type.getMethodType("()V");
|
||||||
|
Handle arg2 = new Handle(Opcodes.H_INVOKESTATIC, this.className, methodName,
|
||||||
|
arg3.toString(),false);
|
||||||
|
mv.visitInvokeDynamicInsn("run", "()Ljava/lang/Runnable;", bootstrap,
|
||||||
|
arg1, arg2,arg3);
|
||||||
|
|
||||||
|
MethodVisitor mvLambdaBody = cw.visitMethod(Opcodes.ACC_PRIVATE+ Opcodes.ACC_STATIC + Opcodes.ACC_SYNTHETIC,
|
||||||
|
methodName, arg3.toString(), null, null);
|
||||||
|
// new BytecodeGenLambda(lambdaExpression, mvLambdaBody);
|
||||||
|
|
||||||
|
new BytecodeGenMethod(lambdaExpression, mvLambdaBody, new HashMap<>(), arg3.toString());
|
||||||
|
mvLambdaBody.visitMaxs(0, 0);
|
||||||
|
mvLambdaBody.visitEnd();
|
||||||
|
}
|
||||||
|
|
||||||
|
@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(FieldVar fieldVar) {
|
||||||
|
System.out.println("in fieldVar " + fieldVar.fieldVarName + " ** receiver: "+fieldVar.receiver);
|
||||||
|
|
||||||
|
fieldName = fieldVar.fieldVarName;
|
||||||
|
fieldDesc = fieldVar.getType().toString();
|
||||||
|
|
||||||
|
fieldVar.receiver.accept(this);
|
||||||
|
// test (if)
|
||||||
|
if(!fieldVar.receiver.getClass().equals(StaticClassName.class)) {
|
||||||
|
mv.visitFieldInsn(Opcodes.GETFIELD,fieldVar.getType().toString(),fieldName ,fieldDesc);
|
||||||
|
}
|
||||||
|
|
||||||
|
// mv.visitFieldInsn(Opcodes.GETSTATIC, fieldVar.receiver.getType().toString().replace(".", "/"),
|
||||||
|
// fieldVar.fieldVarName, fieldVar.getType().toString());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void visit(ForStmt forStmt) {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void visit(IfStmt ifStmt) {
|
||||||
|
System.out.println("++ IF-Statment: ");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void visit(InstanceOf instanceOf) {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void visit(MethodCall methodCall) {
|
||||||
|
System.out.println(" In Methodcall: (" +methodCall.name+")" );
|
||||||
|
System.out.println(" Method-Receiver: "+methodCall.receiver.expr);
|
||||||
|
|
||||||
|
methodCall.receiver.accept(this);
|
||||||
|
methodCall.arglist.accept(this);
|
||||||
|
|
||||||
|
Descriptor mDesc = new Descriptor(methodCall.arglist, methodCall.getType());
|
||||||
|
|
||||||
|
mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, methodCall.receiver.expr.getType().toString(),
|
||||||
|
methodCall.name, mDesc.getDesc(), false);
|
||||||
|
// test
|
||||||
|
if(!methodCall.getType().toString().equals("V")) {
|
||||||
|
mv.visitInsn(Opcodes.POP);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void visit(NewClass methodCall) {
|
||||||
|
System.out.println("In NewClass: ");
|
||||||
|
System.out.println("name: " + methodCall.name + " *** " + "Receiver: " + methodCall.receiver);
|
||||||
|
|
||||||
|
mv.visitTypeInsn(Opcodes.NEW, methodCall.name.replace(".", "/"));
|
||||||
|
mv.visitInsn(Opcodes.DUP);
|
||||||
|
// creates Descriptor
|
||||||
|
methodCall.arglist.accept(this);
|
||||||
|
String d = "(";
|
||||||
|
for(Expression e : methodCall.arglist.getArguments()) {
|
||||||
|
d = d + "L"+e.getType().toString().replace(".", "/") + ";";
|
||||||
|
}
|
||||||
|
d += ")V";
|
||||||
|
|
||||||
|
mv.visitMethodInsn(Opcodes.INVOKESPECIAL, methodCall.name.replace(".", "/"), "<init>", d, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void visit(NewArray newArray) {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void visit(Receiver receiver) {
|
||||||
|
System.out.println(" in Receiver");
|
||||||
|
System.out.println(" expr : " + receiver.expr);
|
||||||
|
receiver.expr.accept(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void visit(Return aReturn) {
|
||||||
|
mv.visitInsn(Opcodes.ARETURN);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void visit(ReturnVoid aReturn) {
|
||||||
|
mv.visitInsn(Opcodes.RETURN);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void visit(StaticClassName staticClassName) {
|
||||||
|
System.out.println("In StaticClassName: ");
|
||||||
|
// mv.visitMethodInsn(Opcodes.INVOKESTATIC, staticClassName.getType().toString().replace(".", "/"),
|
||||||
|
// staticClassName.toString(), staticClassName.getType().toString(), false);
|
||||||
|
mv.visitFieldInsn(Opcodes.GETSTATIC, staticClassName.getType().toString().replace(".", "/"),
|
||||||
|
fieldName, fieldDesc);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void visit(Super aSuper) {
|
||||||
|
System.out.println(">> In Super: ");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void visit(This aThis) {
|
||||||
|
System.out.println("-> IN This");
|
||||||
|
mv.visitVarInsn(Opcodes.ALOAD, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void visit(UnaryPlus unaryPlus) {
|
||||||
|
System.out.println("++ In UnaryPlus: ");
|
||||||
|
}
|
||||||
|
|
||||||
|
@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(Null aNull) {
|
||||||
|
mv.visitInsn(Opcodes.ACONST_NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void visit(Literal literal) {
|
||||||
|
// value?
|
||||||
|
mv.visitLdcInsn(literal.getType().toString());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void visit(ArgumentList argumentList) {
|
||||||
|
for(Expression al : argumentList.getArguments()) {
|
||||||
|
al.accept(this);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void visit(AssignToField assignLeftSide) {
|
||||||
|
// Loads the an object reference from the local variable
|
||||||
|
// array slot onto the top of the operand stack.
|
||||||
|
assignLeftSide.field.receiver.accept(this);
|
||||||
|
this.rightSideTemp.accept(this);
|
||||||
|
mv.visitFieldInsn(Opcodes.PUTFIELD, assignLeftSide.field.receiver.getType().toString(),
|
||||||
|
assignLeftSide.field.fieldVarName, assignLeftSide.field.getType().toString());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void visit(AssignToLocal assignLeftSide) {
|
||||||
|
paramsAndLocals.put(assignLeftSide.localVar.name, paramsAndLocals.size()+1);
|
||||||
|
mv.visitVarInsn(Opcodes.ASTORE, paramsAndLocals.size());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
14
src/de/dhbwstuttgart/bytecode/ClassFile.java
Normal file
14
src/de/dhbwstuttgart/bytecode/ClassFile.java
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
package de.dhbwstuttgart.bytecode;
|
||||||
|
|
||||||
|
public class ClassFile {
|
||||||
|
|
||||||
|
String name;
|
||||||
|
byte[] bytecode;
|
||||||
|
|
||||||
|
public ClassFile(String name, byte[] bytecode) {
|
||||||
|
this.name = name;
|
||||||
|
this.bytecode = bytecode;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
54
src/de/dhbwstuttgart/bytecode/Descriptor.java
Normal file
54
src/de/dhbwstuttgart/bytecode/Descriptor.java
Normal file
@ -0,0 +1,54 @@
|
|||||||
|
package de.dhbwstuttgart.bytecode;
|
||||||
|
|
||||||
|
import java.awt.List;
|
||||||
|
import java.util.Iterator;
|
||||||
|
|
||||||
|
import de.dhbwstuttgart.syntaxtree.Constructor;
|
||||||
|
import de.dhbwstuttgart.syntaxtree.FormalParameter;
|
||||||
|
import de.dhbwstuttgart.syntaxtree.Method;
|
||||||
|
import de.dhbwstuttgart.syntaxtree.statement.ArgumentList;
|
||||||
|
import de.dhbwstuttgart.syntaxtree.statement.Expression;
|
||||||
|
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
|
||||||
|
|
||||||
|
public class Descriptor {
|
||||||
|
String desc;
|
||||||
|
|
||||||
|
public Descriptor(Method method) {
|
||||||
|
desc = "(";
|
||||||
|
Iterator<FormalParameter> itr = method.getParameterList().iterator();
|
||||||
|
while(itr.hasNext()) {
|
||||||
|
FormalParameter fp = itr.next();
|
||||||
|
desc = desc + "L"+fp.getType().toString().replace(".", "/") + ";";
|
||||||
|
}
|
||||||
|
if(method.getReturnType().toString().equals("void")){
|
||||||
|
desc = desc + ")V";
|
||||||
|
}else {
|
||||||
|
desc = desc + ")" + "L"+method.getReturnType().toString().replace(".", "/")+";";
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public Descriptor(Constructor constructor) {
|
||||||
|
desc = "(";
|
||||||
|
Iterator<FormalParameter> itr = constructor.getParameterList().iterator();
|
||||||
|
while(itr.hasNext()) {
|
||||||
|
FormalParameter fp = itr.next();
|
||||||
|
desc = desc + "L"+fp.getType().toString().replace(".", "/") + ";";
|
||||||
|
}
|
||||||
|
desc = desc + ")V";
|
||||||
|
}
|
||||||
|
|
||||||
|
public Descriptor(ArgumentList argList, RefTypeOrTPHOrWildcardOrGeneric returnType) {
|
||||||
|
desc = "(";
|
||||||
|
for(Expression e : argList.getArguments()) {
|
||||||
|
desc = desc + "L"+e.getType().toString().replace(".", "/") + ";";
|
||||||
|
}
|
||||||
|
desc = desc + ")"+returnType.toString();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getDesc() {
|
||||||
|
return this.desc;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
150
src/de/dhbwstuttgart/bytecode/Test.java
Normal file
150
src/de/dhbwstuttgart/bytecode/Test.java
Normal file
@ -0,0 +1,150 @@
|
|||||||
|
package de.dhbwstuttgart.bytecode;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FileNotFoundException;
|
||||||
|
import java.io.FileOutputStream;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.lang.invoke.CallSite;
|
||||||
|
import java.lang.invoke.MethodHandle;
|
||||||
|
import java.lang.invoke.MethodHandles;
|
||||||
|
import java.lang.invoke.MethodType;
|
||||||
|
import java.lang.reflect.Method;
|
||||||
|
import java.net.URL;
|
||||||
|
import java.net.URLClassLoader;
|
||||||
|
|
||||||
|
import org.objectweb.asm.ClassReader;
|
||||||
|
import org.objectweb.asm.ClassWriter;
|
||||||
|
import org.objectweb.asm.Handle;
|
||||||
|
import org.objectweb.asm.Label;
|
||||||
|
import org.objectweb.asm.MethodVisitor;
|
||||||
|
import org.objectweb.asm.Opcodes;
|
||||||
|
import org.objectweb.asm.Type;
|
||||||
|
|
||||||
|
|
||||||
|
public class Test {
|
||||||
|
private static final String rootDirectory = System.getProperty("user.dir") + "/bin/de/dhbwstuttgart/bytecode/";
|
||||||
|
|
||||||
|
protected static ClassLoader getClassLoader() throws Exception {
|
||||||
|
File file = new File(rootDirectory);
|
||||||
|
URL url = file.toURI().toURL();
|
||||||
|
URL[] urls = new URL[] { url };
|
||||||
|
System.out.println(urls[0]);
|
||||||
|
return new URLClassLoader(urls);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
// Test Lambda
|
||||||
|
ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_MAXS);
|
||||||
|
cw.visit(Opcodes.V1_8, Opcodes.ACC_PUBLIC + Opcodes.ACC_SUPER, "TestClass", null, "java/lang/Object", null);
|
||||||
|
|
||||||
|
cw.visitSource("TestClass.java", null);
|
||||||
|
|
||||||
|
// Create Constructor
|
||||||
|
MethodVisitor mv = cw.visitMethod(Opcodes.ACC_PUBLIC, "<init>", "()V", null, null);
|
||||||
|
mv.visitVarInsn(Opcodes.ALOAD, 0);
|
||||||
|
|
||||||
|
mv.visitMethodInsn(Opcodes.INVOKESPECIAL, "java/lang/Object", "<init>", "()V");
|
||||||
|
|
||||||
|
// mv.visitMethodInsn(INVOKEDYNAMIC, "#0", "run", "()Ljava/lang/Runnable");
|
||||||
|
//Call site, which, when invoked, returns an instance of the functional interface to which
|
||||||
|
//the lambda is being converted
|
||||||
|
MethodType mt = MethodType.methodType(CallSite.class, MethodHandles.Lookup.class, String.class,
|
||||||
|
MethodType.class, MethodType.class, MethodHandle.class, MethodType.class);
|
||||||
|
|
||||||
|
Handle bootstrap = new Handle(Opcodes.H_INVOKESTATIC, "java/lang/invoke/LambdaMetafactory", "metafactory",
|
||||||
|
mt.toMethodDescriptorString());
|
||||||
|
Handle arg2 = new Handle(Opcodes.H_INVOKESTATIC, "TestClass", "lambda$0", "()V");
|
||||||
|
|
||||||
|
mv.visitInvokeDynamicInsn("run", "()Ljava/lang/Runnable;", bootstrap,
|
||||||
|
Type.getMethodType("()V"), arg2,
|
||||||
|
Type.getMethodType("()V"));
|
||||||
|
|
||||||
|
mv.visitVarInsn(Opcodes.ASTORE, 1);
|
||||||
|
mv.visitVarInsn(Opcodes.ALOAD, 1);
|
||||||
|
mv.visitMethodInsn(Opcodes.INVOKEINTERFACE, "java/lang/Runnable", "run", "()V");
|
||||||
|
mv.visitInsn(Opcodes.RETURN);
|
||||||
|
|
||||||
|
// creates bridge method, contains lambdas body
|
||||||
|
MethodVisitor mvl = cw.visitMethod(Opcodes.ACC_PRIVATE + Opcodes.ACC_STATIC + Opcodes.ACC_SYNTHETIC, "lambda$0",
|
||||||
|
"()V", null, null);
|
||||||
|
mvl.visitCode();
|
||||||
|
mvl.visitFieldInsn(Opcodes.GETSTATIC, "java/lang/System", "out", "Ljava/io/PrintStream;");
|
||||||
|
mvl.visitLdcInsn("lambda");
|
||||||
|
mvl.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/io/PrintStream", "println", "(Ljava/lang/String;)V");
|
||||||
|
mvl.visitInsn(Opcodes.RETURN);
|
||||||
|
mvl.visitMaxs(2, 0);
|
||||||
|
mvl.visitEnd();
|
||||||
|
|
||||||
|
mv.visitMaxs(1, 2);
|
||||||
|
mv.visitEnd();
|
||||||
|
|
||||||
|
|
||||||
|
cw.visitInnerClass("java/lang/invoke/MethodHandles$Lookup", "java/lang/invoke/MethodHandles", "Lookup",
|
||||||
|
Opcodes.ACC_PUBLIC + Opcodes.ACC_STATIC + Opcodes.ACC_FINAL);
|
||||||
|
cw.visitEnd();
|
||||||
|
|
||||||
|
byte[] b = cw.toByteArray();
|
||||||
|
|
||||||
|
// Test if statement
|
||||||
|
/*
|
||||||
|
* ClassWriter cw = new
|
||||||
|
* ClassWriter(ClassWriter.COMPUTE_FRAMES|ClassWriter.COMPUTE_MAXS);
|
||||||
|
*
|
||||||
|
* cw.visit(Opcodes.V1_8, Opcodes.ACC_PUBLIC+Opcodes.ACC_SUPER, "TestIf", null,
|
||||||
|
* "java/lang/Object", null); MethodVisitor mv =
|
||||||
|
* cw.visitMethod(Opcodes.ACC_PUBLIC, "<init>", "(Ljava/lang/Boolean;)V", null,
|
||||||
|
* null); mv.visitCode();
|
||||||
|
*
|
||||||
|
* // Label l0 = new Label(); // mv.visitLabel(l0);
|
||||||
|
*
|
||||||
|
* mv.visitVarInsn(Opcodes.ALOAD, 0);
|
||||||
|
*
|
||||||
|
* mv.visitMethodInsn(Opcodes.INVOKESPECIAL, "java/lang/Object", "<init>",
|
||||||
|
* "()V");
|
||||||
|
*
|
||||||
|
* // Label l1 = new Label(); // mv.visitLabel(l1);
|
||||||
|
* mv.visitVarInsn(Opcodes.ALOAD, 1); mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL,
|
||||||
|
* "java/lang/Boolean", "booleanValue", "()Z");
|
||||||
|
*
|
||||||
|
* Label label = new Label(); mv.visitJumpInsn(Opcodes.IFEQ, label);
|
||||||
|
*
|
||||||
|
* mv.visitFieldInsn(Opcodes.GETSTATIC, "java/lang/System", "out",
|
||||||
|
* "Ljava/io/PrintStream;"); mv.visitLdcInsn("1");
|
||||||
|
* mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/io/PrintStream", "println",
|
||||||
|
* "(Ljava/lang/String;)V");
|
||||||
|
*
|
||||||
|
* Label endLabel = new Label(); mv.visitJumpInsn(Opcodes.GOTO, endLabel);
|
||||||
|
*
|
||||||
|
* mv.visitLabel(label); mv.visitFieldInsn(Opcodes.GETSTATIC,
|
||||||
|
* "java/lang/System", "out", "Ljava/io/PrintStream;"); mv.visitLdcInsn("0");
|
||||||
|
* mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/io/PrintStream", "println",
|
||||||
|
* "(Ljava/lang/String;)V");
|
||||||
|
*
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* mv.visitLabel(endLabel); mv.visitInsn(Opcodes.RETURN);
|
||||||
|
*
|
||||||
|
* // Label l2 = new Label(); // mv.visitLabel(l2);
|
||||||
|
*
|
||||||
|
* // mv.visitLocalVariable("this", "LTestIf;", null, l0, l2, 0); //
|
||||||
|
* mv.visitLocalVariable("b", "Ljava/lang/Boolean;", null, l0, l2, 1);
|
||||||
|
* mv.visitMaxs(2, 2); mv.visitEnd();
|
||||||
|
*
|
||||||
|
* cw.visitEnd(); byte[] b = cw.toByteArray();
|
||||||
|
*/
|
||||||
|
FileOutputStream output;
|
||||||
|
|
||||||
|
try {
|
||||||
|
output = new FileOutputStream(new File(System.getProperty("user.dir") + "/testBytecode/TestClass.class"));
|
||||||
|
output.write(b);
|
||||||
|
output.close();
|
||||||
|
} catch (FileNotFoundException e) {
|
||||||
|
// TODO Auto-generated catch block
|
||||||
|
e.printStackTrace();
|
||||||
|
} catch (IOException e) {
|
||||||
|
// TODO Auto-generated catch block
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
8
src/de/dhbwstuttgart/bytecode/TestClass.java
Normal file
8
src/de/dhbwstuttgart/bytecode/TestClass.java
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
package de.dhbwstuttgart.bytecode;
|
||||||
|
|
||||||
|
public class TestClass {
|
||||||
|
public TestClass() {
|
||||||
|
Runnable lam = () -> System.out.println("lambda");
|
||||||
|
lam.run();
|
||||||
|
}
|
||||||
|
}
|
59
src/de/dhbwstuttgart/bytecode/TestFields.java
Normal file
59
src/de/dhbwstuttgart/bytecode/TestFields.java
Normal file
@ -0,0 +1,59 @@
|
|||||||
|
package de.dhbwstuttgart.bytecode;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FileNotFoundException;
|
||||||
|
import java.io.FileOutputStream;
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
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;
|
||||||
|
|
||||||
|
public class TestFields {
|
||||||
|
private static final String rootDirectory = System.getProperty("user.dir") + "/bin/de/dhbwstuttgart/bytecode/";
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_FRAMES|ClassWriter.COMPUTE_MAXS);
|
||||||
|
cw.visit(Opcodes.V1_8, Opcodes.ACC_PUBLIC + Opcodes.ACC_SUPER, "TetsF", null, "java/lang/Object", null);
|
||||||
|
|
||||||
|
cw.visitSource("TetsF.java", null);
|
||||||
|
|
||||||
|
FieldVisitor fv = cw.visitField(Opcodes.ACC_PRIVATE, "z", Type.INT_TYPE.getDescriptor(), null, null);
|
||||||
|
fv.visitEnd();
|
||||||
|
|
||||||
|
FieldVisitor fvS = cw.visitField(Opcodes.ACC_PUBLIC, "s", "Ljava/lang/String;", null, null);
|
||||||
|
fvS.visitEnd();
|
||||||
|
// Create Constructor
|
||||||
|
MethodVisitor mv = cw.visitMethod(Opcodes.ACC_PUBLIC, "<init>", "()V", null, null);
|
||||||
|
mv.visitCode();
|
||||||
|
|
||||||
|
mv.visitVarInsn(Opcodes.ALOAD, 0);
|
||||||
|
mv.visitMethodInsn(Opcodes.INVOKESPECIAL, "java/lang/Object", "<init>", "()V");
|
||||||
|
mv.visitVarInsn(Opcodes.ALOAD, 0);
|
||||||
|
mv.visitLdcInsn("");
|
||||||
|
mv.visitFieldInsn(Opcodes.PUTFIELD, "TetsF", "s", "Ljava/lang/String;");
|
||||||
|
mv.visitInsn(Opcodes.RETURN);
|
||||||
|
mv.visitMaxs(2, 1);
|
||||||
|
mv.visitEnd();
|
||||||
|
|
||||||
|
byte[] b = cw.toByteArray();
|
||||||
|
|
||||||
|
FileOutputStream output;
|
||||||
|
|
||||||
|
try {
|
||||||
|
output = new FileOutputStream(new File(System.getProperty("user.dir") + "/testBytecode/TetsF.class"));
|
||||||
|
output.write(b);
|
||||||
|
output.close();
|
||||||
|
} catch (FileNotFoundException e) {
|
||||||
|
// TODO Auto-generated catch block
|
||||||
|
e.printStackTrace();
|
||||||
|
} catch (IOException e) {
|
||||||
|
// TODO Auto-generated catch block
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
11
src/de/dhbwstuttgart/bytecode/TestIf.java
Normal file
11
src/de/dhbwstuttgart/bytecode/TestIf.java
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
package de.dhbwstuttgart.bytecode;
|
||||||
|
|
||||||
|
public class TestIf {
|
||||||
|
public TestIf(Boolean b) {
|
||||||
|
if(b) {
|
||||||
|
System.out.println("1");
|
||||||
|
}else {
|
||||||
|
System.out.println("0");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
18
src/de/dhbwstuttgart/bytecode/TestMeth.java
Normal file
18
src/de/dhbwstuttgart/bytecode/TestMeth.java
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
package de.dhbwstuttgart.bytecode;
|
||||||
|
|
||||||
|
public class TestMeth {
|
||||||
|
private int z;
|
||||||
|
public String s;
|
||||||
|
public TestMeth(int temp) {
|
||||||
|
this.z = temp;
|
||||||
|
}
|
||||||
|
public void m1(int a, int b) {
|
||||||
|
int y = m2(1,2,3,4);
|
||||||
|
}
|
||||||
|
|
||||||
|
public int m2(int a, int b, int x, int y) {
|
||||||
|
Integer c = 55;
|
||||||
|
Integer g;
|
||||||
|
return a+b+y+c;
|
||||||
|
}
|
||||||
|
}
|
6
src/de/dhbwstuttgart/bytecode/TetsF.java
Normal file
6
src/de/dhbwstuttgart/bytecode/TetsF.java
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
package de.dhbwstuttgart.bytecode;
|
||||||
|
|
||||||
|
public class TetsF {
|
||||||
|
private int z;
|
||||||
|
public String s = "";
|
||||||
|
}
|
@ -1,12 +1,16 @@
|
|||||||
package de.dhbwstuttgart.core;
|
package de.dhbwstuttgart.core;
|
||||||
|
|
||||||
|
|
||||||
import de.dhbwstuttgart.environment.CompilationEnvironment;
|
import de.dhbwstuttgart.environment.CompilationEnvironment;
|
||||||
import de.dhbwstuttgart.parser.JavaTXParser;
|
import de.dhbwstuttgart.parser.JavaTXParser;
|
||||||
import de.dhbwstuttgart.parser.SyntaxTreeGenerator.GenericsRegistry;
|
import de.dhbwstuttgart.parser.scope.GenericsRegistry;
|
||||||
import de.dhbwstuttgart.parser.SyntaxTreeGenerator.SyntaxTreeGenerator;
|
import de.dhbwstuttgart.parser.SyntaxTreeGenerator.SyntaxTreeGenerator;
|
||||||
import de.dhbwstuttgart.parser.antlr.Java8Parser.CompilationUnitContext;
|
import de.dhbwstuttgart.parser.antlr.Java8Parser.CompilationUnitContext;
|
||||||
|
import de.dhbwstuttgart.parser.scope.JavaClassName;
|
||||||
|
import de.dhbwstuttgart.parser.scope.JavaClassRegistry;
|
||||||
import de.dhbwstuttgart.syntaxtree.ClassOrInterface;
|
import de.dhbwstuttgart.syntaxtree.ClassOrInterface;
|
||||||
import de.dhbwstuttgart.syntaxtree.SourceFile;
|
import de.dhbwstuttgart.syntaxtree.SourceFile;
|
||||||
|
import de.dhbwstuttgart.syntaxtree.factory.ASTFactory;
|
||||||
import de.dhbwstuttgart.syntaxtree.factory.UnifyTypeFactory;
|
import de.dhbwstuttgart.syntaxtree.factory.UnifyTypeFactory;
|
||||||
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
|
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
|
||||||
import de.dhbwstuttgart.typeinference.constraints.Constraint;
|
import de.dhbwstuttgart.typeinference.constraints.Constraint;
|
||||||
@ -39,13 +43,23 @@ public class JavaTXCompiler {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<ResultSet> typeInference(){
|
public List<ResultSet> typeInference() throws ClassNotFoundException {
|
||||||
List<ClassOrInterface> allClasses = new ArrayList<>();
|
List<ClassOrInterface> allClasses = new ArrayList<>();//environment.getAllAvailableClasses();
|
||||||
for(SourceFile sf : sourceFiles.values()){
|
for(SourceFile sf : sourceFiles.values()){
|
||||||
allClasses.addAll(sf.getClasses());
|
allClasses.addAll(sf.getClasses());
|
||||||
}
|
}
|
||||||
FiniteClosure finiteClosure = UnifyTypeFactory.generateFC(allClasses);
|
List<ClassOrInterface> importedClasses = new ArrayList<>();
|
||||||
final ConstraintSet<Pair> cons = new TYPE(sourceFiles.values()).getConstraints();
|
//Alle Importierten Klassen in allen geparsten Sourcefiles kommen ins FC
|
||||||
|
for(File forSourceFile : sourceFiles.keySet())
|
||||||
|
for(JavaClassName name : sourceFiles.get(forSourceFile).getImports()){
|
||||||
|
ClassOrInterface importedClass = ASTFactory.createClass(
|
||||||
|
ClassLoader.getSystemClassLoader().loadClass(name.toString()));
|
||||||
|
importedClasses.add(importedClass);
|
||||||
|
}
|
||||||
|
allClasses.addAll(importedClasses);
|
||||||
|
FiniteClosure finiteClosure = UnifyTypeFactory.generateFC(allClasses);
|
||||||
|
|
||||||
|
final ConstraintSet<Pair> cons = new TYPE(sourceFiles.values(), allClasses).getConstraints();
|
||||||
ConstraintSet<UnifyPair> unifyCons = UnifyTypeFactory.convert(cons);
|
ConstraintSet<UnifyPair> unifyCons = UnifyTypeFactory.convert(cons);
|
||||||
|
|
||||||
TypeUnify unify = new TypeUnify();
|
TypeUnify unify = new TypeUnify();
|
||||||
@ -56,9 +70,9 @@ public class JavaTXCompiler {
|
|||||||
xConsSet.addAll(constraint);
|
xConsSet.addAll(constraint);
|
||||||
}
|
}
|
||||||
|
|
||||||
System.out.println(xConsSet);
|
//System.out.println(xConsSet);
|
||||||
Set<Set<UnifyPair>> result = unify.unify(xConsSet, finiteClosure);
|
Set<Set<UnifyPair>> result = unify.unify(xConsSet, finiteClosure);
|
||||||
System.out.println("RESULT: " + result);
|
//System.out.println("RESULT: " + result);
|
||||||
results.addAll(result);
|
results.addAll(result);
|
||||||
}
|
}
|
||||||
return results.stream().map((unifyPairs ->
|
return results.stream().map((unifyPairs ->
|
||||||
@ -85,5 +99,5 @@ public class JavaTXCompiler {
|
|||||||
SourceFile ret = generator.convert(tree);
|
SourceFile ret = generator.convert(tree);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -10,6 +10,9 @@ import java.util.LinkedList;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
|
import de.dhbwstuttgart.syntaxtree.ClassOrInterface;
|
||||||
|
import de.dhbwstuttgart.syntaxtree.SourceFile;
|
||||||
|
import de.dhbwstuttgart.syntaxtree.factory.ASTFactory;
|
||||||
import org.reflections.Reflections;
|
import org.reflections.Reflections;
|
||||||
import org.reflections.scanners.ResourcesScanner;
|
import org.reflections.scanners.ResourcesScanner;
|
||||||
import org.reflections.scanners.SubTypesScanner;
|
import org.reflections.scanners.SubTypesScanner;
|
||||||
@ -31,7 +34,8 @@ import de.dhbwstuttgart.parser.scope.JavaClassRegistry;
|
|||||||
*/
|
*/
|
||||||
public class CompilationEnvironment {
|
public class CompilationEnvironment {
|
||||||
private final List<URL> librarys;
|
private final List<URL> librarys;
|
||||||
|
private final List<File> sourceFiles;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Imitiert die Environment beim Aufruf des JavaCompilers auf einer Menge von java-Dateien
|
* Imitiert die Environment beim Aufruf des JavaCompilers auf einer Menge von java-Dateien
|
||||||
* Die Environment enth<EFBFBD>lt automatisch die Java Standard Library
|
* Die Environment enth<EFBFBD>lt automatisch die Java Standard Library
|
||||||
@ -47,10 +51,11 @@ public class CompilationEnvironment {
|
|||||||
new DebugException("Fehler im Classpath auf diesem System");
|
new DebugException("Fehler im Classpath auf diesem System");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
this.sourceFiles = sourceFiles;
|
||||||
}
|
}
|
||||||
|
|
||||||
public JavaClassRegistry getRegistry(File forSourceFile) throws ClassNotFoundException, IOException {
|
public JavaClassRegistry getRegistry(File forSourceFile) throws ClassNotFoundException, IOException {
|
||||||
List<String> allNames = new ArrayList<>();
|
List<String> allNames;
|
||||||
CompilationUnitContext tree = JavaTXParser.parse(forSourceFile);
|
CompilationUnitContext tree = JavaTXParser.parse(forSourceFile);
|
||||||
allNames = GatherNames.getNames(tree, new PackageCrawler(librarys));
|
allNames = GatherNames.getNames(tree, new PackageCrawler(librarys));
|
||||||
return new JavaClassRegistry(allNames);
|
return new JavaClassRegistry(allNames);
|
||||||
|
@ -53,7 +53,7 @@ public class PackageCrawler {
|
|||||||
|
|
||||||
return classes;
|
return classes;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<String> getClassNames(String packageName){
|
public List<String> getClassNames(String packageName){
|
||||||
List<String> nameList = new ArrayList();
|
List<String> nameList = new ArrayList();
|
||||||
Set<Class<?>> classes = getClassesInPackage(packageName);
|
Set<Class<?>> classes = getClassesInPackage(packageName);
|
||||||
|
@ -3,6 +3,7 @@ package de.dhbwstuttgart.parser.SyntaxTreeGenerator;
|
|||||||
import de.dhbwstuttgart.exceptions.NotImplementedException;
|
import de.dhbwstuttgart.exceptions.NotImplementedException;
|
||||||
import de.dhbwstuttgart.parser.NullToken;
|
import de.dhbwstuttgart.parser.NullToken;
|
||||||
import de.dhbwstuttgart.parser.antlr.Java8Parser;
|
import de.dhbwstuttgart.parser.antlr.Java8Parser;
|
||||||
|
import de.dhbwstuttgart.parser.scope.GenericsRegistry;
|
||||||
import de.dhbwstuttgart.parser.scope.JavaClassRegistry;
|
import de.dhbwstuttgart.parser.scope.JavaClassRegistry;
|
||||||
import de.dhbwstuttgart.syntaxtree.*;
|
import de.dhbwstuttgart.syntaxtree.*;
|
||||||
import de.dhbwstuttgart.syntaxtree.statement.*;
|
import de.dhbwstuttgart.syntaxtree.statement.*;
|
||||||
|
@ -2,8 +2,9 @@ package de.dhbwstuttgart.parser.SyntaxTreeGenerator;
|
|||||||
|
|
||||||
import de.dhbwstuttgart.exceptions.NotImplementedException;
|
import de.dhbwstuttgart.exceptions.NotImplementedException;
|
||||||
import java.lang.ClassNotFoundException;
|
import java.lang.ClassNotFoundException;
|
||||||
import de.dhbwstuttgart.parser.NullToken;
|
|
||||||
import de.dhbwstuttgart.parser.antlr.Java8Parser;
|
import de.dhbwstuttgart.parser.antlr.Java8Parser;
|
||||||
|
import de.dhbwstuttgart.parser.scope.GenericsRegistry;
|
||||||
import de.dhbwstuttgart.parser.scope.JavaClassName;
|
import de.dhbwstuttgart.parser.scope.JavaClassName;
|
||||||
import de.dhbwstuttgart.parser.scope.JavaClassRegistry;
|
import de.dhbwstuttgart.parser.scope.JavaClassRegistry;
|
||||||
import de.dhbwstuttgart.syntaxtree.*;
|
import de.dhbwstuttgart.syntaxtree.*;
|
||||||
@ -13,9 +14,7 @@ import de.dhbwstuttgart.syntaxtree.type.RefType;
|
|||||||
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
|
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
|
||||||
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
|
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
import java.lang.reflect.Modifier;
|
import java.lang.reflect.Modifier;
|
||||||
import java.sql.Ref;
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@ -77,13 +76,13 @@ public class SyntaxTreeGenerator{
|
|||||||
newImports.add(convertSingleTypeImportDeclaration(importDeclCtx.singleTypeImportDeclaration()));
|
newImports.add(convertSingleTypeImportDeclaration(importDeclCtx.singleTypeImportDeclaration()));
|
||||||
}
|
}
|
||||||
else if(importDeclCtx.typeImportOnDemandDeclaration() != null){
|
else if(importDeclCtx.typeImportOnDemandDeclaration() != null){
|
||||||
newImports.add(convertTypeImportOnDemandDeclaration(importDeclCtx.typeImportOnDemandDeclaration()));
|
newImports.addAll(convertTypeImportOnDemandDeclaration(importDeclCtx.typeImportOnDemandDeclaration()));
|
||||||
}
|
}
|
||||||
else if(importDeclCtx.singleStaticImportDeclaration() != null){
|
else if(importDeclCtx.singleStaticImportDeclaration() != null){
|
||||||
newImports.add(convertSingleStaticImportDeclaration(importDeclCtx.singleStaticImportDeclaration()));
|
newImports.add(convertSingleStaticImportDeclaration(importDeclCtx.singleStaticImportDeclaration()));
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
newImports.add(convertStaticImportOnDemandDeclaration(importDeclCtx.staticImportOnDemandDeclaration()));
|
newImports.addAll(convertStaticImportOnDemandDeclaration(importDeclCtx.staticImportOnDemandDeclaration()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
this.imports.addAll(newImports);
|
this.imports.addAll(newImports);
|
||||||
@ -95,16 +94,16 @@ public class SyntaxTreeGenerator{
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
private JavaClassName convertTypeImportOnDemandDeclaration(Java8Parser.TypeImportOnDemandDeclarationContext ctx){
|
private List<JavaClassName> convertTypeImportOnDemandDeclaration(Java8Parser.TypeImportOnDemandDeclarationContext ctx){
|
||||||
return null;
|
return reg.getAllFromPackage(ctx.packageOrTypeName().getText());
|
||||||
}
|
}
|
||||||
|
|
||||||
private JavaClassName convertSingleStaticImportDeclaration(Java8Parser.SingleStaticImportDeclarationContext ctx){
|
private JavaClassName convertSingleStaticImportDeclaration(Java8Parser.SingleStaticImportDeclarationContext ctx){
|
||||||
return null;
|
throw new NotImplementedException();
|
||||||
}
|
}
|
||||||
|
|
||||||
private JavaClassName convertStaticImportOnDemandDeclaration(Java8Parser.StaticImportOnDemandDeclarationContext ctx){
|
private List<JavaClassName> convertStaticImportOnDemandDeclaration(Java8Parser.StaticImportOnDemandDeclarationContext ctx){
|
||||||
return null;
|
return reg.getAllFromPackage(ctx.typeName().getText());
|
||||||
}
|
}
|
||||||
|
|
||||||
private String getPackageFromClass(String cls){
|
private String getPackageFromClass(String cls){
|
||||||
|
@ -2,25 +2,21 @@ package de.dhbwstuttgart.parser.SyntaxTreeGenerator;
|
|||||||
|
|
||||||
import de.dhbwstuttgart.exceptions.NotImplementedException;
|
import de.dhbwstuttgart.exceptions.NotImplementedException;
|
||||||
import de.dhbwstuttgart.exceptions.TypeinferenceException;
|
import de.dhbwstuttgart.exceptions.TypeinferenceException;
|
||||||
import de.dhbwstuttgart.parser.NullToken;
|
|
||||||
import de.dhbwstuttgart.parser.antlr.Java8Parser;
|
import de.dhbwstuttgart.parser.antlr.Java8Parser;
|
||||||
import de.dhbwstuttgart.parser.scope.GenericTypeName;
|
import de.dhbwstuttgart.parser.scope.GenericTypeName;
|
||||||
|
import de.dhbwstuttgart.parser.scope.GenericsRegistry;
|
||||||
import de.dhbwstuttgart.parser.scope.JavaClassName;
|
import de.dhbwstuttgart.parser.scope.JavaClassName;
|
||||||
import de.dhbwstuttgart.parser.scope.JavaClassRegistry;
|
import de.dhbwstuttgart.parser.scope.JavaClassRegistry;
|
||||||
import de.dhbwstuttgart.syntaxtree.GenericDeclarationList;
|
import de.dhbwstuttgart.syntaxtree.GenericDeclarationList;
|
||||||
import de.dhbwstuttgart.syntaxtree.GenericTypeVar;
|
import de.dhbwstuttgart.syntaxtree.GenericTypeVar;
|
||||||
import de.dhbwstuttgart.syntaxtree.factory.ASTFactory;
|
import de.dhbwstuttgart.syntaxtree.factory.ASTFactory;
|
||||||
import de.dhbwstuttgart.syntaxtree.statement.ArgumentList;
|
|
||||||
import de.dhbwstuttgart.syntaxtree.type.GenericRefType;
|
import de.dhbwstuttgart.syntaxtree.type.GenericRefType;
|
||||||
import de.dhbwstuttgart.syntaxtree.type.RefType;
|
import de.dhbwstuttgart.syntaxtree.type.RefType;
|
||||||
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
|
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
|
||||||
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
|
|
||||||
|
|
||||||
import javassist.bytecode.stackmap.TypeData;
|
|
||||||
import org.antlr.v4.runtime.Token;
|
import org.antlr.v4.runtime.Token;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class TypeGenerator {
|
public class TypeGenerator {
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
// Generated from Java8.g4 by ANTLR 4.5.3
|
// Generated from Java8.g4 by ANTLR 4.7
|
||||||
package de.dhbwstuttgart.parser.antlr;
|
package de.dhbwstuttgart.parser.antlr;
|
||||||
|
|
||||||
import org.antlr.v4.runtime.ParserRuleContext;
|
import org.antlr.v4.runtime.ParserRuleContext;
|
||||||
@ -1571,6 +1571,18 @@ public class Java8BaseListener implements Java8Listener {
|
|||||||
* <p>The default implementation does nothing.</p>
|
* <p>The default implementation does nothing.</p>
|
||||||
*/
|
*/
|
||||||
@Override public void exitLocalVariableDeclarationStatement(Java8Parser.LocalVariableDeclarationStatementContext ctx) { }
|
@Override public void exitLocalVariableDeclarationStatement(Java8Parser.LocalVariableDeclarationStatementContext ctx) { }
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*
|
||||||
|
* <p>The default implementation does nothing.</p>
|
||||||
|
*/
|
||||||
|
@Override public void enterUnannTypeOrAuto(Java8Parser.UnannTypeOrAutoContext ctx) { }
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*
|
||||||
|
* <p>The default implementation does nothing.</p>
|
||||||
|
*/
|
||||||
|
@Override public void exitUnannTypeOrAuto(Java8Parser.UnannTypeOrAutoContext ctx) { }
|
||||||
/**
|
/**
|
||||||
* {@inheritDoc}
|
* {@inheritDoc}
|
||||||
*
|
*
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
// Generated from /home/janulrich/Development/intellijworkspace/JavaCompilerCore/src/de/dhbwstuttgart/parser/antlr/Java8.g4 by ANTLR 4.5.1
|
// Generated from Java8.g4 by ANTLR 4.7
|
||||||
package de.dhbwstuttgart.parser.antlr;
|
package de.dhbwstuttgart.parser.antlr;
|
||||||
import org.antlr.v4.runtime.Lexer;
|
import org.antlr.v4.runtime.Lexer;
|
||||||
import org.antlr.v4.runtime.CharStream;
|
import org.antlr.v4.runtime.CharStream;
|
||||||
@ -11,7 +11,7 @@ import org.antlr.v4.runtime.misc.*;
|
|||||||
|
|
||||||
@SuppressWarnings({"all", "warnings", "unchecked", "unused", "cast"})
|
@SuppressWarnings({"all", "warnings", "unchecked", "unused", "cast"})
|
||||||
public class Java8Lexer extends Lexer {
|
public class Java8Lexer extends Lexer {
|
||||||
static { RuntimeMetaData.checkVersion("4.5.1", RuntimeMetaData.VERSION); }
|
static { RuntimeMetaData.checkVersion("4.7", RuntimeMetaData.VERSION); }
|
||||||
|
|
||||||
protected static final DFA[] _decisionToDFA;
|
protected static final DFA[] _decisionToDFA;
|
||||||
protected static final PredictionContextCache _sharedContextCache =
|
protected static final PredictionContextCache _sharedContextCache =
|
||||||
@ -34,6 +34,10 @@ public class Java8Lexer extends Lexer {
|
|||||||
OR_ASSIGN=97, XOR_ASSIGN=98, MOD_ASSIGN=99, LSHIFT_ASSIGN=100, RSHIFT_ASSIGN=101,
|
OR_ASSIGN=97, XOR_ASSIGN=98, MOD_ASSIGN=99, LSHIFT_ASSIGN=100, RSHIFT_ASSIGN=101,
|
||||||
URSHIFT_ASSIGN=102, Identifier=103, AT=104, ELLIPSIS=105, WS=106, COMMENT=107,
|
URSHIFT_ASSIGN=102, Identifier=103, AT=104, ELLIPSIS=105, WS=106, COMMENT=107,
|
||||||
LINE_COMMENT=108;
|
LINE_COMMENT=108;
|
||||||
|
public static String[] channelNames = {
|
||||||
|
"DEFAULT_TOKEN_CHANNEL", "HIDDEN"
|
||||||
|
};
|
||||||
|
|
||||||
public static String[] modeNames = {
|
public static String[] modeNames = {
|
||||||
"DEFAULT_MODE"
|
"DEFAULT_MODE"
|
||||||
};
|
};
|
||||||
@ -148,6 +152,9 @@ public class Java8Lexer extends Lexer {
|
|||||||
@Override
|
@Override
|
||||||
public String getSerializedATN() { return _serializedATN; }
|
public String getSerializedATN() { return _serializedATN; }
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String[] getChannelNames() { return channelNames; }
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String[] getModeNames() { return modeNames; }
|
public String[] getModeNames() { return modeNames; }
|
||||||
|
|
||||||
@ -184,7 +191,7 @@ public class Java8Lexer extends Lexer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static final String _serializedATN =
|
public static final String _serializedATN =
|
||||||
"\3\u0430\ud6d1\u8206\uad2d\u4417\uaef1\u8d80\uaadd\2n\u044e\b\1\4\2\t"+
|
"\3\u608b\ua72a\u8133\ub9ed\u417c\u3be7\u7786\u5964\2n\u044e\b\1\4\2\t"+
|
||||||
"\2\4\3\t\3\4\4\t\4\4\5\t\5\4\6\t\6\4\7\t\7\4\b\t\b\4\t\t\t\4\n\t\n\4\13"+
|
"\2\4\3\t\3\4\4\t\4\4\5\t\5\4\6\t\6\4\7\t\7\4\b\t\b\4\t\t\t\4\n\t\n\4\13"+
|
||||||
"\t\13\4\f\t\f\4\r\t\r\4\16\t\16\4\17\t\17\4\20\t\20\4\21\t\21\4\22\t\22"+
|
"\t\13\4\f\t\f\4\r\t\r\4\16\t\16\4\17\t\17\4\20\t\20\4\21\t\21\4\22\t\22"+
|
||||||
"\4\23\t\23\4\24\t\24\4\25\t\25\4\26\t\26\4\27\t\27\4\30\t\30\4\31\t\31"+
|
"\4\23\t\23\4\24\t\24\4\25\t\25\4\26\t\26\4\27\t\27\4\30\t\30\4\31\t\31"+
|
||||||
@ -275,8 +282,8 @@ public class Java8Lexer extends Lexer {
|
|||||||
"DDdd\3\2\62\63\4\2GGgg\4\2--//\6\2FFHHffhh\4\2RRrr\4\2))^^\4\2$$^^\n\2"+
|
"DDdd\3\2\62\63\4\2GGgg\4\2--//\6\2FFHHffhh\4\2RRrr\4\2))^^\4\2$$^^\n\2"+
|
||||||
"$$))^^ddhhppttvv\3\2\62\65\6\2&&C\\aac|\4\2\2\u0081\ud802\udc01\3\2\ud802"+
|
"$$))^^ddhhppttvv\3\2\62\65\6\2&&C\\aac|\4\2\2\u0081\ud802\udc01\3\2\ud802"+
|
||||||
"\udc01\3\2\udc02\ue001\7\2&&\62;C\\aac|\5\2\13\f\16\17\"\"\4\2\f\f\17"+
|
"\udc01\3\2\udc02\ue001\7\2&&\62;C\\aac|\5\2\13\f\16\17\"\"\4\2\f\f\17"+
|
||||||
"\17\u045c\2\3\3\2\2\2\2\5\3\2\2\2\2\7\3\2\2\2\2\t\3\2\2\2\2\13\3\2\2\2"+
|
"\17\2\u045c\2\3\3\2\2\2\2\5\3\2\2\2\2\7\3\2\2\2\2\t\3\2\2\2\2\13\3\2\2"+
|
||||||
"\2\r\3\2\2\2\2\17\3\2\2\2\2\21\3\2\2\2\2\23\3\2\2\2\2\25\3\2\2\2\2\27"+
|
"\2\2\r\3\2\2\2\2\17\3\2\2\2\2\21\3\2\2\2\2\23\3\2\2\2\2\25\3\2\2\2\2\27"+
|
||||||
"\3\2\2\2\2\31\3\2\2\2\2\33\3\2\2\2\2\35\3\2\2\2\2\37\3\2\2\2\2!\3\2\2"+
|
"\3\2\2\2\2\31\3\2\2\2\2\33\3\2\2\2\2\35\3\2\2\2\2\37\3\2\2\2\2!\3\2\2"+
|
||||||
"\2\2#\3\2\2\2\2%\3\2\2\2\2\'\3\2\2\2\2)\3\2\2\2\2+\3\2\2\2\2-\3\2\2\2"+
|
"\2\2#\3\2\2\2\2%\3\2\2\2\2\'\3\2\2\2\2)\3\2\2\2\2+\3\2\2\2\2-\3\2\2\2"+
|
||||||
"\2/\3\2\2\2\2\61\3\2\2\2\2\63\3\2\2\2\2\65\3\2\2\2\2\67\3\2\2\2\29\3\2"+
|
"\2/\3\2\2\2\2\61\3\2\2\2\2\63\3\2\2\2\2\65\3\2\2\2\2\67\3\2\2\2\29\3\2"+
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
// Generated from Java8.g4 by ANTLR 4.5.3
|
// Generated from Java8.g4 by ANTLR 4.7
|
||||||
package de.dhbwstuttgart.parser.antlr;
|
package de.dhbwstuttgart.parser.antlr;
|
||||||
import org.antlr.v4.runtime.tree.ParseTreeListener;
|
import org.antlr.v4.runtime.tree.ParseTreeListener;
|
||||||
|
|
||||||
@ -1307,6 +1307,16 @@ public interface Java8Listener extends ParseTreeListener {
|
|||||||
* @param ctx the parse tree
|
* @param ctx the parse tree
|
||||||
*/
|
*/
|
||||||
void exitLocalVariableDeclarationStatement(Java8Parser.LocalVariableDeclarationStatementContext ctx);
|
void exitLocalVariableDeclarationStatement(Java8Parser.LocalVariableDeclarationStatementContext ctx);
|
||||||
|
/**
|
||||||
|
* Enter a parse tree produced by {@link Java8Parser#unannTypeOrAuto}.
|
||||||
|
* @param ctx the parse tree
|
||||||
|
*/
|
||||||
|
void enterUnannTypeOrAuto(Java8Parser.UnannTypeOrAutoContext ctx);
|
||||||
|
/**
|
||||||
|
* Exit a parse tree produced by {@link Java8Parser#unannTypeOrAuto}.
|
||||||
|
* @param ctx the parse tree
|
||||||
|
*/
|
||||||
|
void exitUnannTypeOrAuto(Java8Parser.UnannTypeOrAutoContext ctx);
|
||||||
/**
|
/**
|
||||||
* Enter a parse tree produced by {@link Java8Parser#localVariableDeclaration}.
|
* Enter a parse tree produced by {@link Java8Parser#localVariableDeclaration}.
|
||||||
* @param ctx the parse tree
|
* @param ctx the parse tree
|
||||||
|
File diff suppressed because it is too large
Load Diff
@ -1,7 +1,8 @@
|
|||||||
package de.dhbwstuttgart.parser.SyntaxTreeGenerator;
|
package de.dhbwstuttgart.parser.scope;
|
||||||
|
|
||||||
|
import de.dhbwstuttgart.parser.SyntaxTreeGenerator.GenericContext;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
|
@ -1,5 +1,7 @@
|
|||||||
package de.dhbwstuttgart.parser.scope;
|
package de.dhbwstuttgart.parser.scope;
|
||||||
|
|
||||||
|
import com.sun.xml.internal.bind.v2.runtime.reflect.Lister;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@ -35,7 +37,7 @@ public class JavaClassName {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gibt von einem Klassennamen nur den Namen der Klasse zurück
|
* Gibt von einem Klassennamen nur den Namen der Klasse zur<EFBFBD>ck
|
||||||
* Beispiel:
|
* Beispiel:
|
||||||
* java.lang.Object wird zu: Object
|
* java.lang.Object wird zu: Object
|
||||||
*/
|
*/
|
||||||
|
@ -1,13 +1,14 @@
|
|||||||
package de.dhbwstuttgart.parser.scope;
|
package de.dhbwstuttgart.parser.scope;
|
||||||
|
|
||||||
|
import de.dhbwstuttgart.exceptions.NotImplementedException;
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Speichert die Klassen für einen bestimmten Projektscope
|
* Speichert die Klassen f<EFBFBD>r einen bestimmten Projektscope
|
||||||
*/
|
*/
|
||||||
public class JavaClassRegistry {
|
public class JavaClassRegistry {
|
||||||
final List<JavaClassName> existingClasses = new ArrayList<>();
|
final List<JavaClassName> existingClasses = new ArrayList<>();
|
||||||
final List<String> importedPackages = new ArrayList<>();
|
|
||||||
|
|
||||||
public JavaClassRegistry(List<String> initialNames){
|
public JavaClassRegistry(List<String> initialNames){
|
||||||
for(String name : initialNames){
|
for(String name : initialNames){
|
||||||
@ -23,13 +24,7 @@ public class JavaClassRegistry {
|
|||||||
for(JavaClassName name : existingClasses){
|
for(JavaClassName name : existingClasses){
|
||||||
if(name.equals(new JavaClassName(className)))return name;
|
if(name.equals(new JavaClassName(className)))return name;
|
||||||
}
|
}
|
||||||
//Jetzt noch alle importierten Packages durchsuchen:
|
throw new NotImplementedException();
|
||||||
JavaClassName ret = getClassFromImportedPackages(className);
|
|
||||||
if(ret == null){
|
|
||||||
throw new TypeNotPresentException(className, new Throwable());
|
|
||||||
}else{
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -37,35 +32,18 @@ public class JavaClassRegistry {
|
|||||||
return existingClasses.toString();
|
return existingClasses.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public List<JavaClassName> getAllFromPackage(String packageName) {
|
||||||
|
List<JavaClassName> ret = new ArrayList<>();
|
||||||
|
for(JavaClassName className : this.existingClasses){
|
||||||
|
JavaClassName toCompare = new JavaClassName(packageName + "." + JavaClassName.stripClassName(className.toString()));
|
||||||
|
if(toCompare.toString().equals(className.toString())){
|
||||||
|
ret.add(className);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
public boolean contains(String whole) {
|
public boolean contains(String whole) {
|
||||||
boolean ret = existingClasses.contains(new JavaClassName(whole));
|
return existingClasses.contains(new JavaClassName(whole));
|
||||||
if(ret == false){
|
|
||||||
JavaClassName imported = getClassFromImportedPackages(whole);
|
|
||||||
if(imported != null){
|
|
||||||
existingClasses.add(imported);
|
|
||||||
return true;
|
|
||||||
}else {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}else {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private JavaClassName getClassFromImportedPackages(String className){
|
|
||||||
ClassLoader loader = Thread.currentThread().getContextClassLoader();
|
|
||||||
String shortName = JavaClassName.stripClassName(className);
|
|
||||||
for(String packageName : importedPackages) {
|
|
||||||
try {
|
|
||||||
loader.loadClass(packageName+"."+shortName);
|
|
||||||
//Keine Exception! Die Klasse existiert:
|
|
||||||
JavaClassName ret = new JavaClassName(packageName+"."+shortName);
|
|
||||||
if(ret.equals(new JavaClassName(className)))return ret;
|
|
||||||
} catch (ClassNotFoundException e) {
|
|
||||||
//Die Klasse wurde nicht gefunden!
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -24,13 +24,13 @@ public class ClassOrInterface extends SyntaxTreeNode implements TypeScope{
|
|||||||
private List<Field> fields = new ArrayList<>();
|
private List<Field> fields = new ArrayList<>();
|
||||||
private List<Method> methods = new ArrayList<>();
|
private List<Method> methods = new ArrayList<>();
|
||||||
private GenericDeclarationList genericClassParameters;
|
private GenericDeclarationList genericClassParameters;
|
||||||
private RefTypeOrTPHOrWildcardOrGeneric superClass;
|
private RefType superClass;
|
||||||
protected boolean isInterface;
|
protected boolean isInterface;
|
||||||
private List<? extends RefTypeOrTPHOrWildcardOrGeneric> implementedInterfaces;
|
private List<? extends RefTypeOrTPHOrWildcardOrGeneric> implementedInterfaces;
|
||||||
private List<Constructor> constructors;
|
private List<Constructor> constructors;
|
||||||
|
|
||||||
public ClassOrInterface(int modifiers, JavaClassName name, List<Field> fielddecl, List<Method> methods, List<Constructor> constructors, GenericDeclarationList genericClassParameters,
|
public ClassOrInterface(int modifiers, JavaClassName name, List<Field> fielddecl, List<Method> methods, List<Constructor> constructors, GenericDeclarationList genericClassParameters,
|
||||||
RefTypeOrTPHOrWildcardOrGeneric superClass, Boolean isInterface, List<? extends RefTypeOrTPHOrWildcardOrGeneric> implementedInterfaces, Token offset){
|
RefType superClass, Boolean isInterface, List<? extends RefTypeOrTPHOrWildcardOrGeneric> implementedInterfaces, Token offset){
|
||||||
super(offset);
|
super(offset);
|
||||||
this.modifiers = modifiers;
|
this.modifiers = modifiers;
|
||||||
this.name = name;
|
this.name = name;
|
||||||
@ -74,7 +74,7 @@ public class ClassOrInterface extends SyntaxTreeNode implements TypeScope{
|
|||||||
return new RefType(name, params, offset);
|
return new RefType(name, params, offset);
|
||||||
}
|
}
|
||||||
|
|
||||||
public RefTypeOrTPHOrWildcardOrGeneric getSuperClass() {
|
public RefType getSuperClass() {
|
||||||
return superClass;
|
return superClass;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2,6 +2,7 @@ package de.dhbwstuttgart.syntaxtree.statement;
|
|||||||
|
|
||||||
|
|
||||||
import de.dhbwstuttgart.syntaxtree.ASTVisitor;
|
import de.dhbwstuttgart.syntaxtree.ASTVisitor;
|
||||||
|
import de.dhbwstuttgart.syntaxtree.StatementVisitor;
|
||||||
import de.dhbwstuttgart.syntaxtree.SyntaxTreeNode;
|
import de.dhbwstuttgart.syntaxtree.SyntaxTreeNode;
|
||||||
import org.antlr.v4.runtime.Token;
|
import org.antlr.v4.runtime.Token;
|
||||||
|
|
||||||
@ -20,8 +21,13 @@ public class ArgumentList extends SyntaxTreeNode
|
|||||||
return expr;
|
return expr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void accept(ASTVisitor visitor) {
|
public void accept(ASTVisitor visitor) {
|
||||||
visitor.visit(this);
|
visitor.visit(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void accept(StatementVisitor visitor) {
|
||||||
|
visitor.visit(this);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -11,13 +11,6 @@ import java.util.List;
|
|||||||
|
|
||||||
public class RefType extends RefTypeOrTPHOrWildcardOrGeneric
|
public class RefType extends RefTypeOrTPHOrWildcardOrGeneric
|
||||||
{
|
{
|
||||||
/**
|
|
||||||
* Ist IsArray auf true, muss beim Codegen ein Zeichen [ gesetzt werden
|
|
||||||
* Bsp.: 15| tag = CONSTANT_Utf8, length = 22, ([Ljava/lang/String;)V
|
|
||||||
* Ist IsArray auf false, muss beim Codegen ein Zeichen [ gesetzt werden
|
|
||||||
* Bsp.: 9| tag = CONSTANT_Utf8, length = 21, (Ljava/lang/String;)V
|
|
||||||
*/
|
|
||||||
private boolean IsArray = false;
|
|
||||||
protected final JavaClassName name;
|
protected final JavaClassName name;
|
||||||
protected final List<RefTypeOrTPHOrWildcardOrGeneric> parameter;
|
protected final List<RefTypeOrTPHOrWildcardOrGeneric> parameter;
|
||||||
/**
|
/**
|
||||||
|
@ -9,6 +9,7 @@ import de.dhbwstuttgart.syntaxtree.TypeScope;
|
|||||||
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
|
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collection;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.Stack;
|
import java.util.Stack;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
@ -17,7 +18,7 @@ public class TypeInferenceBlockInformation extends TypeInferenceInformation {
|
|||||||
private TypeScope methodContext;
|
private TypeScope methodContext;
|
||||||
private ClassOrInterface currentClass;
|
private ClassOrInterface currentClass;
|
||||||
|
|
||||||
public TypeInferenceBlockInformation(Set<ClassOrInterface> availableClasses,
|
public TypeInferenceBlockInformation(Collection<ClassOrInterface> availableClasses,
|
||||||
ClassOrInterface currentClass, TypeScope methodContext) {
|
ClassOrInterface currentClass, TypeScope methodContext) {
|
||||||
super(availableClasses);
|
super(availableClasses);
|
||||||
this.methodContext = new TypeScopeContainer(currentClass, methodContext);
|
this.methodContext = new TypeScopeContainer(currentClass, methodContext);
|
||||||
|
@ -12,6 +12,7 @@ import de.dhbwstuttgart.typeinference.constraints.Constraint;
|
|||||||
import de.dhbwstuttgart.typeinference.constraints.Pair;
|
import de.dhbwstuttgart.typeinference.constraints.Pair;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collection;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
@ -26,9 +27,9 @@ Zweiteres hat den Vorteil, dass bei der Entwicklung leichter Dinge hinzugefügt
|
|||||||
Die ganze Logik steckt in dieser Klasse.
|
Die ganze Logik steckt in dieser Klasse.
|
||||||
*/
|
*/
|
||||||
public class TypeInferenceInformation {
|
public class TypeInferenceInformation {
|
||||||
private Set<ClassOrInterface> classes;
|
private Collection<ClassOrInterface> classes;
|
||||||
|
|
||||||
public TypeInferenceInformation(Set<ClassOrInterface> availableClasses){
|
public TypeInferenceInformation(Collection<ClassOrInterface> availableClasses){
|
||||||
classes = availableClasses;
|
classes = availableClasses;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -52,7 +53,7 @@ public class TypeInferenceInformation {
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Set<ClassOrInterface> getAvailableClasses() {
|
public Collection<ClassOrInterface> getAvailableClasses() {
|
||||||
return classes;
|
return classes;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -13,18 +13,19 @@ import java.util.*;
|
|||||||
public class TYPE {
|
public class TYPE {
|
||||||
|
|
||||||
private final Collection<SourceFile> sfs;
|
private final Collection<SourceFile> sfs;
|
||||||
|
private final TypeInferenceInformation typeInferenceInformation;
|
||||||
|
|
||||||
public TYPE(Collection<SourceFile> sourceFiles){
|
public TYPE(Collection<SourceFile> sourceFiles, Collection<ClassOrInterface> allAvailableClasses){
|
||||||
sfs = sourceFiles;
|
sfs = sourceFiles;
|
||||||
|
this.typeInferenceInformation = new TypeInferenceInformation(allAvailableClasses);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public ConstraintSet getConstraints() {
|
public ConstraintSet getConstraints() {
|
||||||
ConstraintSet ret = new ConstraintSet();
|
ConstraintSet ret = new ConstraintSet();
|
||||||
TypeInferenceInformation info = getTypeInferenceInformation();
|
|
||||||
for(SourceFile sf : sfs)
|
for(SourceFile sf : sfs)
|
||||||
for (ClassOrInterface cl : sf.KlassenVektor) {
|
for (ClassOrInterface cl : sf.KlassenVektor) {
|
||||||
ret.addAll(getConstraintsClass(cl ,info));
|
ret.addAll(getConstraintsClass(cl ,typeInferenceInformation));
|
||||||
}
|
}
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
@ -39,25 +40,28 @@ public class TYPE {
|
|||||||
}
|
}
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
/*
|
||||||
|
TODO: Hier eine Information erstellen nur mit den importierte Klassen einer einzigen SourceFile
|
||||||
|
private TypeInferenceInformation getTypeInferenceInformation(sourceFile) {
|
||||||
|
ClassLoader classLoader = ClassLoader.getSystemClassLoader();
|
||||||
|
Set<ClassOrInterface> classes = new HashSet<>();
|
||||||
|
|
||||||
private TypeInferenceInformation getTypeInferenceInformation() {
|
for(SourceFile sourceFile : sfs){
|
||||||
ClassLoader classLoader = ClassLoader.getSystemClassLoader();
|
for(JavaClassName importName : sourceFile.imports){
|
||||||
Set<ClassOrInterface> classes = new HashSet<>();
|
System.out.println(importName);
|
||||||
for(SourceFile sourceFile : sfs){
|
try {
|
||||||
for(JavaClassName importName : sourceFile.imports){
|
classes.add(ASTFactory.createClass(classLoader.loadClass(importName.toString())));
|
||||||
System.out.println(importName);
|
} catch (ClassNotFoundException e) {
|
||||||
try {
|
throw new DebugException("Klasse " + importName + " konnte nicht geladen werden");
|
||||||
classes.add(ASTFactory.createClass(classLoader.loadClass(importName.toString())));
|
}
|
||||||
} catch (ClassNotFoundException e) {
|
|
||||||
throw new DebugException("Klasse " + importName + " konnte nicht geladen werden");
|
|
||||||
}
|
}
|
||||||
|
classes.addAll(sourceFile.KlassenVektor);
|
||||||
}
|
}
|
||||||
classes.addAll(sourceFile.KlassenVektor);
|
|
||||||
|
return new TypeInferenceInformation(classes);
|
||||||
}
|
}
|
||||||
|
|
||||||
return new TypeInferenceInformation(classes);
|
*/
|
||||||
}
|
|
||||||
|
|
||||||
private ConstraintSet getConstraintsMethod(Method m, TypeInferenceInformation info, ClassOrInterface currentClass) {
|
private ConstraintSet getConstraintsMethod(Method m, TypeInferenceInformation info, ClassOrInterface currentClass) {
|
||||||
if(m.block == null)return new ConstraintSet(); //Abstrakte Methoden generieren keine Constraints
|
if(m.block == null)return new ConstraintSet(); //Abstrakte Methoden generieren keine Constraints
|
||||||
TypeInferenceBlockInformation blockInfo = new TypeInferenceBlockInformation(info.getAvailableClasses(), currentClass, m);
|
TypeInferenceBlockInformation blockInfo = new TypeInferenceBlockInformation(info.getAvailableClasses(), currentClass, m);
|
||||||
|
@ -6,7 +6,6 @@ import de.dhbwstuttgart.exceptions.NotImplementedException;
|
|||||||
import de.dhbwstuttgart.exceptions.TypeinferenceException;
|
import de.dhbwstuttgart.exceptions.TypeinferenceException;
|
||||||
import de.dhbwstuttgart.parser.NullToken;
|
import de.dhbwstuttgart.parser.NullToken;
|
||||||
import de.dhbwstuttgart.parser.SyntaxTreeGenerator.AssignToLocal;
|
import de.dhbwstuttgart.parser.SyntaxTreeGenerator.AssignToLocal;
|
||||||
import de.dhbwstuttgart.parser.SyntaxTreeGenerator.GenericsRegistry;
|
|
||||||
import de.dhbwstuttgart.syntaxtree.*;
|
import de.dhbwstuttgart.syntaxtree.*;
|
||||||
import de.dhbwstuttgart.syntaxtree.statement.*;
|
import de.dhbwstuttgart.syntaxtree.statement.*;
|
||||||
import de.dhbwstuttgart.syntaxtree.statement.literal.Literal;
|
import de.dhbwstuttgart.syntaxtree.statement.literal.Literal;
|
||||||
|
@ -575,8 +575,9 @@ public class RuleSet implements IRuleSet{
|
|||||||
if(pair.getPairOp() == PairOperator.EQUALSDOT
|
if(pair.getPairOp() == PairOperator.EQUALSDOT
|
||||||
&& pair.getLhsType() instanceof PlaceholderType)
|
&& pair.getLhsType() instanceof PlaceholderType)
|
||||||
lhsType = (PlaceholderType) pair.getLhsType();
|
lhsType = (PlaceholderType) pair.getLhsType();
|
||||||
|
rhsType = pair.getRhsType(); //PL eingefuegt 2017-09-29 statt !((rhsType = pair.getRhsType()) instanceof PlaceholderType)
|
||||||
if(lhsType != null
|
if(lhsType != null
|
||||||
&& !((rhsType = pair.getRhsType()) instanceof PlaceholderType)
|
//&& !((rhsType = pair.getRhsType()) instanceof PlaceholderType) //PL geloescht am 2017-09-29 Begründung: auch Typvariablen muessen ersetzt werden.
|
||||||
&& typeMap.get(lhsType) > 1 // The type occurs in more pairs in the set than just the recent pair.
|
&& typeMap.get(lhsType) > 1 // The type occurs in more pairs in the set than just the recent pair.
|
||||||
&& !rhsType.getTypeParams().occurs(lhsType)) {
|
&& !rhsType.getTypeParams().occurs(lhsType)) {
|
||||||
Unifier uni = new Unifier(lhsType, rhsType);
|
Unifier uni = new Unifier(lhsType, rhsType);
|
||||||
@ -688,7 +689,10 @@ public class RuleSet implements IRuleSet{
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Optional<Set<UnifyPair>> reduceFunN(UnifyPair pair) {
|
public Optional<Set<UnifyPair>> reduceFunN(UnifyPair pair) {
|
||||||
if(pair.getPairOp() != PairOperator.SMALLERDOT)
|
if((pair.getPairOp() != PairOperator.SMALLERDOT)
|
||||||
|
&& (pair.getPairOp() != PairOperator.EQUALSDOT)) //PL 2017-10-03 hinzugefuegt
|
||||||
|
//da Regel auch fuer EQUALSDOT anwendbar
|
||||||
|
//TODO: fuer allen anderen Relationen noch pruefen
|
||||||
return Optional.empty();
|
return Optional.empty();
|
||||||
|
|
||||||
UnifyType lhsType = pair.getLhsType();
|
UnifyType lhsType = pair.getLhsType();
|
||||||
|
@ -73,7 +73,7 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
|||||||
* @param fc The finite closure
|
* @param fc The finite closure
|
||||||
* @return The set of all principal type unifiers
|
* @return The set of all principal type unifiers
|
||||||
*/
|
*/
|
||||||
protected Set<Set<UnifyPair>> unify(Set<UnifyPair> eq, IFiniteClosure fc, boolean parallel) {
|
protected Set<Set<UnifyPair>> unify(Set<UnifyPair> eq, IFiniteClosure fc, boolean parallel) {
|
||||||
/*
|
/*
|
||||||
* Step 1: Repeated application of reduce, adapt, erase, swap
|
* Step 1: Repeated application of reduce, adapt, erase, swap
|
||||||
*/
|
*/
|
||||||
@ -119,7 +119,10 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
|||||||
// Sets of the "second level"
|
// Sets of the "second level"
|
||||||
Set<UnifyPair> undefinedPairs = new HashSet<>();
|
Set<UnifyPair> undefinedPairs = new HashSet<>();
|
||||||
Set<Set<Set<Set<UnifyPair>>>> secondLevelSets = calculatePairSets(eq2s, fc, undefinedPairs);
|
Set<Set<Set<Set<UnifyPair>>>> secondLevelSets = calculatePairSets(eq2s, fc, undefinedPairs);
|
||||||
|
//PL 2017-09-20: Im calculatePairSets wird möglicherweise O .< java.lang.Integer
|
||||||
|
//nicht ausgewertet Faculty Beispiel im 1. Schritt
|
||||||
|
//PL 2017-10-03 geloest, muesste noch mit FCs mit kleineren
|
||||||
|
//Typen getestet werden.
|
||||||
// If pairs occured that did not match one of the cartesian product cases,
|
// If pairs occured that did not match one of the cartesian product cases,
|
||||||
// those pairs are contradictory and the unification is impossible.
|
// those pairs are contradictory and the unification is impossible.
|
||||||
if(!undefinedPairs.isEmpty())
|
if(!undefinedPairs.isEmpty())
|
||||||
@ -149,7 +152,6 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
|||||||
Set<Set<Set<UnifyPair>>> eqPrimeSet = setOps.cartesianProduct(topLevelSets)
|
Set<Set<Set<UnifyPair>>> eqPrimeSet = setOps.cartesianProduct(topLevelSets)
|
||||||
.stream().map(x -> new HashSet<>(x))
|
.stream().map(x -> new HashSet<>(x))
|
||||||
.collect(Collectors.toCollection(HashSet::new));
|
.collect(Collectors.toCollection(HashSet::new));
|
||||||
//System.out.println(result);
|
|
||||||
|
|
||||||
Set<Set<UnifyPair>> eqPrimePrimeSet = new HashSet<>();
|
Set<Set<UnifyPair>> eqPrimePrimeSet = new HashSet<>();
|
||||||
|
|
||||||
@ -164,12 +166,14 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
|||||||
*/
|
*/
|
||||||
Optional<Set<UnifyPair>> eqPrimePrime = rules.subst(eqPrime);
|
Optional<Set<UnifyPair>> eqPrimePrime = rules.subst(eqPrime);
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Step 6 a) Restart (fork) for pairs where subst was applied
|
* Step 6 a) Restart (fork) for pairs where subst was applied
|
||||||
*/
|
*/
|
||||||
if(parallel) {
|
if(parallel) {
|
||||||
if (eqPrime.equals(eq))
|
if //(eqPrime.equals(eq)) //PL 2017-09-29 auskommentiert und durch
|
||||||
|
(!eqPrimePrime.isPresent()) //PL 2071-09-29 dies ersetzt
|
||||||
|
//Begruendung: Wenn in der Substitution keine Veraenderung
|
||||||
|
//(!eqPrimePrime.isPresent()) erfolgt ist, ist das Ergebnis erzielt.
|
||||||
eqPrimePrimeSet.add(eqPrime);
|
eqPrimePrimeSet.add(eqPrime);
|
||||||
else if(eqPrimePrime.isPresent()) {
|
else if(eqPrimePrime.isPresent()) {
|
||||||
TypeUnifyTask fork = new TypeUnifyTask(eqPrimePrime.get(), fc, true);
|
TypeUnifyTask fork = new TypeUnifyTask(eqPrimePrime.get(), fc, true);
|
||||||
@ -183,7 +187,10 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
else { // sequentiell (Step 6b is included)
|
else { // sequentiell (Step 6b is included)
|
||||||
if (eqPrime.equals(eq))
|
if //(eqPrime.equals(eq)) //PL 2017-09-29 auskommentiert und durch
|
||||||
|
(!eqPrimePrime.isPresent()) //PL 2071-09-29 dies ersetzt
|
||||||
|
//Begruendung: Wenn in der Substitution keine Veraenderung
|
||||||
|
//(!eqPrimePrime.isPresent()) erfolgt ist, ist das Ergebnis erzielt.
|
||||||
eqPrimePrimeSet.add(eqPrime);
|
eqPrimePrimeSet.add(eqPrime);
|
||||||
else if(eqPrimePrime.isPresent())
|
else if(eqPrimePrime.isPresent())
|
||||||
eqPrimePrimeSet.addAll(unify(eqPrimePrime.get(), fc, false));
|
eqPrimePrimeSet.addAll(unify(eqPrimePrime.get(), fc, false));
|
||||||
@ -438,9 +445,10 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
|||||||
Set<UnifyType> cs = fc.getAllTypesByName(thetaPrime.getName());
|
Set<UnifyType> cs = fc.getAllTypesByName(thetaPrime.getName());
|
||||||
cs.add(thetaPrime);
|
cs.add(thetaPrime);
|
||||||
|
|
||||||
for(UnifyType c : cs) {
|
for(UnifyType c : cs) {
|
||||||
Set<UnifyType> thetaQs = fc.getChildren(c).stream().collect(Collectors.toCollection(HashSet::new));
|
Set<UnifyType> thetaQs = fc.getChildren(c).stream().collect(Collectors.toCollection(HashSet::new));
|
||||||
//thetaQs.add(thetaPrime);
|
thetaQs.add(thetaPrime); //PL 2017-10-03: War auskommentiert habe ich wieder einkommentiert,
|
||||||
|
//da children offensichtlich ein echtes kleiner und kein kleinergleich ist
|
||||||
Set<UnifyType> thetaQPrimes = new HashSet<>();
|
Set<UnifyType> thetaQPrimes = new HashSet<>();
|
||||||
TypeParams cParams = c.getTypeParams();
|
TypeParams cParams = c.getTypeParams();
|
||||||
if(cParams.size() == 0)
|
if(cParams.size() == 0)
|
||||||
|
72
test/bytecode/JavaTXCompilerTest.java
Normal file
72
test/bytecode/JavaTXCompilerTest.java
Normal file
@ -0,0 +1,72 @@
|
|||||||
|
package bytecode;
|
||||||
|
|
||||||
|
import de.dhbwstuttgart.bytecode.BytecodeGen;
|
||||||
|
import de.dhbwstuttgart.core.JavaTXCompiler;
|
||||||
|
import de.dhbwstuttgart.syntaxtree.SourceFile;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FileNotFoundException;
|
||||||
|
import java.io.FileOutputStream;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.nio.charset.Charset;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
|
import java.nio.file.Files;
|
||||||
|
import java.nio.file.Paths;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
|
public class JavaTXCompilerTest {
|
||||||
|
|
||||||
|
private static final String rootDirectory = System.getProperty("user.dir")+"/test/javFiles/";
|
||||||
|
private static final List<File> filesToTest = new ArrayList<>();
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void test() throws IOException, java.lang.ClassNotFoundException {
|
||||||
|
System.out.println(rootDirectory);
|
||||||
|
filesToTest.add(new File(rootDirectory+"EmptyClass.jav"));
|
||||||
|
JavaTXCompiler compiler = new JavaTXCompiler(filesToTest);
|
||||||
|
System.out.println("test");
|
||||||
|
for(File f : filesToTest){
|
||||||
|
String content = readFile(f.getPath(), StandardCharsets.UTF_8);
|
||||||
|
HashMap<String,byte[]> bytecode = this.getBytecode(compiler.sourceFiles.get(f));
|
||||||
|
this.writeClassFile(bytecode, "EmptyClass");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public HashMap<String,byte[]> getBytecode(SourceFile sf) {
|
||||||
|
HashMap<String,byte[]> classFiles = new HashMap<>();
|
||||||
|
BytecodeGen bytecodeGen = new BytecodeGen(classFiles);
|
||||||
|
bytecodeGen.visit(sf);
|
||||||
|
return bytecodeGen.getClassFiles();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void writeClassFile(HashMap<String,byte[]> classFiles, String name) {
|
||||||
|
FileOutputStream output;
|
||||||
|
byte[] bytecode = classFiles.get(name);
|
||||||
|
try {
|
||||||
|
System.out.println("generating .class file");
|
||||||
|
output = new FileOutputStream(new File(System.getProperty("user.dir") + "/testBytecode/" +name+".class"));
|
||||||
|
output.write(bytecode);
|
||||||
|
output.close();
|
||||||
|
System.out.println(".class file generated");
|
||||||
|
} catch (FileNotFoundException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static String readFile(String path, Charset encoding)
|
||||||
|
throws IOException
|
||||||
|
{
|
||||||
|
byte[] encoded = Files.readAllBytes(Paths.get(path));
|
||||||
|
return new String(encoded, encoding);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
3
test/javFiles/EmptyClass.jav
Normal file
3
test/javFiles/EmptyClass.jav
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
public class EmptyClass{
|
||||||
|
|
||||||
|
}
|
37
test/javFiles/EmptyMethod.jav
Normal file
37
test/javFiles/EmptyMethod.jav
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
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;
|
||||||
|
}
|
||||||
|
}*/
|
11
test/javFiles/Op1.jav
Normal file
11
test/javFiles/Op1.jav
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
public class Op1{
|
||||||
|
public Op1() {
|
||||||
|
|
||||||
|
Runnable lam = () -> {
|
||||||
|
String test = "";
|
||||||
|
String b = "b";
|
||||||
|
test = b;
|
||||||
|
System.out.println(test);};
|
||||||
|
//lam.run();
|
||||||
|
}
|
||||||
|
}
|
6
test/javFiles/Subclass.jav
Normal file
6
test/javFiles/Subclass.jav
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
public class Subclass extends Superclass {
|
||||||
|
|
||||||
|
public void printMethod() {
|
||||||
|
super.printMethod();
|
||||||
|
}
|
||||||
|
}
|
6
test/javFiles/Superclass.jav
Normal file
6
test/javFiles/Superclass.jav
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
public class Superclass {
|
||||||
|
|
||||||
|
public void printMethod() {
|
||||||
|
System.out.println("Printed in Superclass.");
|
||||||
|
}
|
||||||
|
}
|
17
test/javFiles/fc.jav
Normal file
17
test/javFiles/fc.jav
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
import java.util.*;
|
||||||
|
|
||||||
|
class Test{
|
||||||
|
methode(param1, param2, param3) {
|
||||||
|
return param1.meth(param2.add(param3));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
interface Klasse1{
|
||||||
|
Klasse1 meth(Klasse1 p);
|
||||||
|
Klasse1 meth(Klasse2 p);
|
||||||
|
}
|
||||||
|
|
||||||
|
interface Klasse2{
|
||||||
|
Klasse1 meth(Klasse1 p);
|
||||||
|
Klasse2 meth(Klasse2 p);
|
||||||
|
}
|
@ -10,6 +10,6 @@ interface Klasse1{
|
|||||||
}
|
}
|
||||||
|
|
||||||
interface Klasse2{
|
interface Klasse2{
|
||||||
Klasse1 meth(Klasse1 p):
|
Klasse1 meth(Klasse1 p);
|
||||||
Klasse2 meth(Klasse2 p):
|
Klasse2 meth(Klasse2 p);
|
||||||
}
|
}
|
7
test/javFiles/test1.jav
Normal file
7
test/javFiles/test1.jav
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
class Faculty {
|
||||||
|
|
||||||
|
int a;
|
||||||
|
m (int x) {
|
||||||
|
return a+x;
|
||||||
|
}
|
||||||
|
}
|
@ -1,11 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<module type="JAVA_MODULE" version="4">
|
|
||||||
<component name="NewModuleRootManager" inherit-compiler-output="true">
|
|
||||||
<exclude-output />
|
|
||||||
<content url="file://$MODULE_DIR$">
|
|
||||||
<sourceFolder url="file://$MODULE_DIR$" isTestSource="true" />
|
|
||||||
</content>
|
|
||||||
<orderEntry type="inheritedJdk" />
|
|
||||||
<orderEntry type="sourceFolder" forTests="false" />
|
|
||||||
</component>
|
|
||||||
</module>
|
|
9
test/typeinference/FiniteClosureTest.java
Normal file
9
test/typeinference/FiniteClosureTest.java
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
package typeinference;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
|
||||||
|
public class FiniteClosureTest extends JavaTXCompilerTest{
|
||||||
|
public FiniteClosureTest() {
|
||||||
|
this.fileToTest = new File(rootDirectory+"fc.jav");
|
||||||
|
}
|
||||||
|
}
|
@ -36,6 +36,7 @@ public class JavaTXCompilerTest {
|
|||||||
//filesToTest.add(new File(rootDirectory+"Faculty.jav"));
|
//filesToTest.add(new File(rootDirectory+"Faculty.jav"));
|
||||||
//filesToTest.add(new File(rootDirectory+"mathStruc.jav"));
|
//filesToTest.add(new File(rootDirectory+"mathStruc.jav"));
|
||||||
//filesToTest.add(new File(rootDirectory+"test.jav"));
|
//filesToTest.add(new File(rootDirectory+"test.jav"));
|
||||||
|
filesToTest.add(new File(rootDirectory+"EmptyMethod.jav"));
|
||||||
//filesToTest.add(new File(rootDirectory+"Lambda.jav"));
|
//filesToTest.add(new File(rootDirectory+"Lambda.jav"));
|
||||||
//filesToTest.add(new File(rootDirectory+"Lambda2.jav"));
|
//filesToTest.add(new File(rootDirectory+"Lambda2.jav"));
|
||||||
//filesToTest.add(new File(rootDirectory+"Lambda3.jav"));
|
//filesToTest.add(new File(rootDirectory+"Lambda3.jav"));
|
||||||
@ -45,12 +46,12 @@ public class JavaTXCompilerTest {
|
|||||||
//filesToTest.add(new File(rootDirectory+"Matrix.jav"));
|
//filesToTest.add(new File(rootDirectory+"Matrix.jav"));
|
||||||
//filesToTest.add(new File(rootDirectory+"Import.jav"));
|
//filesToTest.add(new File(rootDirectory+"Import.jav"));
|
||||||
JavaTXCompiler compiler = new JavaTXCompiler(fileToTest);
|
JavaTXCompiler compiler = new JavaTXCompiler(fileToTest);
|
||||||
compiler.typeInference();
|
List<ResultSet> results = compiler.typeInference();
|
||||||
|
|
||||||
for(File f : compiler.sourceFiles.keySet()){
|
for(File f : compiler.sourceFiles.keySet()){
|
||||||
SourceFile sf = compiler.sourceFiles.get(f);
|
SourceFile sf = compiler.sourceFiles.get(f);
|
||||||
System.out.println(ASTTypePrinter.print(sf));
|
System.out.println(ASTTypePrinter.print(sf));
|
||||||
List<ResultSet> results = compiler.typeInference();
|
//List<ResultSet> results = compiler.typeInference(); PL 2017-10-03 vor die For-Schleife gezogen
|
||||||
assert results.size()>0;
|
assert results.size()>0;
|
||||||
for(ResultSet resultSet : results){
|
for(ResultSet resultSet : results){
|
||||||
Set<TypeInsert> result = TypeInsertFactory.createTypeInsertPoints(sf, resultSet);
|
Set<TypeInsert> result = TypeInsertFactory.createTypeInsertPoints(sf, resultSet);
|
||||||
|
6
testBytecode/Field.java
Normal file
6
testBytecode/Field.java
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
public class Field{
|
||||||
|
public void m(){
|
||||||
|
MethFieldVar mF = new MethFieldVar();
|
||||||
|
mF.s1 = "Field S1";
|
||||||
|
}
|
||||||
|
}
|
8
testBytecode/Import.java
Normal file
8
testBytecode/Import.java
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
import java.util.Vector;
|
||||||
|
|
||||||
|
class Import {
|
||||||
|
void methode(){
|
||||||
|
Vector v = new Vector();
|
||||||
|
v.add(v);
|
||||||
|
}
|
||||||
|
}
|
10
testBytecode/Lam1.java
Normal file
10
testBytecode/Lam1.java
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
import java.util.function.Function;
|
||||||
|
public class Lam1{
|
||||||
|
public Lam1() {
|
||||||
|
Function<String,String> fun = (x) -> x+"1";
|
||||||
|
fun.apply("2");
|
||||||
|
|
||||||
|
Runnable lam = () -> System.out.println("lambda");
|
||||||
|
lam.run();
|
||||||
|
}
|
||||||
|
}
|
8
testBytecode/LamRun.java
Normal file
8
testBytecode/LamRun.java
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
public class LamRun{
|
||||||
|
|
||||||
|
public LamRun(){
|
||||||
|
|
||||||
|
Runnable lam = () -> System.out.println("lambda");
|
||||||
|
lam.run();
|
||||||
|
}
|
||||||
|
}
|
38
testBytecode/MethFieldVar.java
Normal file
38
testBytecode/MethFieldVar.java
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
public class MethFieldVar{
|
||||||
|
String s1;// = "";
|
||||||
|
String s2;
|
||||||
|
|
||||||
|
/* public void meth(Integer i, String j, Boolean b){
|
||||||
|
//String local = "a";
|
||||||
|
//int localL = local.length();
|
||||||
|
//int l = s.length();
|
||||||
|
String s = null;
|
||||||
|
//s = "";
|
||||||
|
//return s.length();//l+localL;
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
public void mm(){
|
||||||
|
// return "mm";
|
||||||
|
}
|
||||||
|
public void m2(){
|
||||||
|
System.out.println("");
|
||||||
|
// Math.abs(1);
|
||||||
|
// String lV = "local";
|
||||||
|
// s1 = "1";
|
||||||
|
// s1.concat("2");
|
||||||
|
s2 = s1;
|
||||||
|
|
||||||
|
mm();
|
||||||
|
|
||||||
|
Clazz i = new Clazz();
|
||||||
|
|
||||||
|
Runnable lam = ()->{
|
||||||
|
String test = "";
|
||||||
|
String b = "b";
|
||||||
|
test = b;
|
||||||
|
System.out.println(test);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class Clazz{}
|
6
testBytecode/Subclass.java
Normal file
6
testBytecode/Subclass.java
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
public class Subclass extends Superclass {
|
||||||
|
|
||||||
|
public void printMethod() {
|
||||||
|
super.printMethod();
|
||||||
|
}
|
||||||
|
}
|
14
testBytecode/SuperTest.java
Normal file
14
testBytecode/SuperTest.java
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
public class Superclass {
|
||||||
|
|
||||||
|
public void printMethod() {
|
||||||
|
System.out.println("Printed in Superclass.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public class Subclass extends Superclass {
|
||||||
|
|
||||||
|
public void printMethod() {
|
||||||
|
super.printMethod();
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
6
testBytecode/Superclass.java
Normal file
6
testBytecode/Superclass.java
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
public class Superclass {
|
||||||
|
|
||||||
|
public void printMethod() {
|
||||||
|
System.out.println("Printed in Superclass.");
|
||||||
|
}
|
||||||
|
}
|
10
testBytecode/TestMyTest.java
Normal file
10
testBytecode/TestMyTest.java
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
class TestMyTest{
|
||||||
|
public static void main(String[] a){
|
||||||
|
//test1
|
||||||
|
//new TestClass();
|
||||||
|
//test if statement
|
||||||
|
//new TestIf(new Boolean(true));
|
||||||
|
// test lambda
|
||||||
|
new TestClass();
|
||||||
|
}
|
||||||
|
}
|
1
testBytecode/public
Normal file
1
testBytecode/public
Normal file
@ -0,0 +1 @@
|
|||||||
|
|
5
testBytecode/testF.java
Normal file
5
testBytecode/testF.java
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
public class testTets(){
|
||||||
|
public static void main(String[] args){
|
||||||
|
new tetsF();
|
||||||
|
}
|
||||||
|
}
|
5
testBytecode/testTets.java
Normal file
5
testBytecode/testTets.java
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
public class testTets{
|
||||||
|
public static void main(String[] args){
|
||||||
|
new TetsF();
|
||||||
|
}
|
||||||
|
}
|
5
testBytecode/testTetsF.java
Normal file
5
testBytecode/testTetsF.java
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
public class testTets(){
|
||||||
|
public static void main(String[] args){
|
||||||
|
new tetsF();
|
||||||
|
}
|
||||||
|
}
|
@ -1,3 +0,0 @@
|
|||||||
y.output
|
|
||||||
*.java
|
|
||||||
*.class
|
|
@ -1,46 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<project name="JavaCompiler.buildParser" default="JavaParser" basedir=".">
|
|
||||||
|
|
||||||
<property name="ParserSrcDir" value="./../src/mycompiler/myparser/"/>
|
|
||||||
|
|
||||||
<target name ="JavaParser" depends="JavaLexer" description="Create the file JavaParser.java">
|
|
||||||
|
|
||||||
<exec executable="${basedir}/RunJay.sh" os="linux" failonerror="true"/>
|
|
||||||
<exec executable="${basedir}/RunJayDarwin.sh" os="mac" failonerror="true"/>
|
|
||||||
<exec executable="${basedir}/RunJay.bat" os="windows" failonerror="true"/>
|
|
||||||
|
|
||||||
<!--
|
|
||||||
<echo message="Hallo Welt: ${ParserSrcDir}JavaParser.jay"/>
|
|
||||||
<exec executable="ipconfig" failonerror="true">
|
|
||||||
<arg value="/all"/>
|
|
||||||
</exec>
|
|
||||||
-->
|
|
||||||
|
|
||||||
<!--
|
|
||||||
<exec executable="${basedir}/jay.cygwin32" dir="${ParserSrcDir}" failonerror="true">
|
|
||||||
<arg value="-v ${ParserSrcDir}JavaParser.jay <skeleton> ${ParserSrcDir}JavaParser.java"/>
|
|
||||||
|
|
||||||
<arg value="-v"/>
|
|
||||||
<arg value="${ParserSrcDir}JavaParser.jay"/>
|
|
||||||
<arg value="<"/>
|
|
||||||
<arg value="skeleton"/>
|
|
||||||
<arg value=">"/>
|
|
||||||
<arg value="${ParserSrcDir}JavaParser.java"/>
|
|
||||||
</exec>
|
|
||||||
-->
|
|
||||||
</target>
|
|
||||||
|
|
||||||
<target name ="JavaLexer" depends="Lexer" description="Move the file JavaParser.lex.java to JavaParser.java">
|
|
||||||
<copy file="${ParserSrcDir}JavaLexer.lex.java" tofile="${ParserSrcDir}JavaLexer.java" failonerror="true"/>
|
|
||||||
</target>
|
|
||||||
|
|
||||||
<target name ="Lexer" description="Create the file JavaLexer.lex.java">
|
|
||||||
<java classname="JLex.Main"
|
|
||||||
classpath="${basedir}/JLex_neu.jar"
|
|
||||||
fork="true"
|
|
||||||
failonerror="true">
|
|
||||||
<arg value="${ParserSrcDir}JavaLexer.lex"/>
|
|
||||||
</java>
|
|
||||||
</target>
|
|
||||||
|
|
||||||
</project>
|
|
@ -1,43 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<project name="JavaCompiler.buildParser" default="JavaParser" basedir=".">
|
|
||||||
|
|
||||||
<property name="ParserSrcDir" value="./../src/de/dhbwstuttgart/parser/"/>
|
|
||||||
|
|
||||||
<target name ="JavaParser" depends="JavaLexer" description="Create the file JavaParser.java">
|
|
||||||
|
|
||||||
<exec executable="${basedir}/RunJayDarwin.sh" failonerror="true"/>
|
|
||||||
<!--
|
|
||||||
<echo message="Hallo Welt: ${ParserSrcDir}JavaParser.jay"/>
|
|
||||||
<exec executable="ipconfig" failonerror="true">
|
|
||||||
<arg value="/all"/>
|
|
||||||
</exec>
|
|
||||||
-->
|
|
||||||
|
|
||||||
<!--
|
|
||||||
<exec executable="${basedir}/jay.cygwin32" dir="${ParserSrcDir}" failonerror="true">
|
|
||||||
<arg value="-v ${ParserSrcDir}JavaParser.jay <skeleton> ${ParserSrcDir}JavaParser.java"/>
|
|
||||||
|
|
||||||
<arg value="-v"/>
|
|
||||||
<arg value="${ParserSrcDir}JavaParser.jay"/>
|
|
||||||
<arg value="<"/>
|
|
||||||
<arg value="skeleton"/>
|
|
||||||
<arg value=">"/>
|
|
||||||
<arg value="${ParserSrcDir}JavaParser.java"/>
|
|
||||||
</exec>
|
|
||||||
-->
|
|
||||||
</target>
|
|
||||||
|
|
||||||
<target name ="JavaLexer" depends="Lexer" description="Move the file JavaParser.lex.java to JavaParser.java">
|
|
||||||
<move file="${ParserSrcDir}JavaLexer.lex.java" tofile="${ParserSrcDir}JavaLexer.java" failonerror="true"/>
|
|
||||||
</target>
|
|
||||||
|
|
||||||
<target name ="Lexer" description="Create the file JavaLexer.lex.java">
|
|
||||||
<java classname="JLex.Main"
|
|
||||||
classpath="${basedir}/JLex_neu.jar"
|
|
||||||
fork="true"
|
|
||||||
failonerror="true">
|
|
||||||
<arg value="${ParserSrcDir}JavaLexer.lex"/>
|
|
||||||
</java>
|
|
||||||
</target>
|
|
||||||
|
|
||||||
</project>
|
|
@ -1,42 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<project name="JavaCompiler.buildParser" default="JavaParser" basedir=".">
|
|
||||||
|
|
||||||
<property name="ParserSrcDir" value="./../src/mycompiler/myparser/"/>
|
|
||||||
|
|
||||||
<target name ="JavaParser" depends="JavaLexer" description="Create the file JavaParser.java">
|
|
||||||
<exec executable="${basedir}/RunJay.sh" failonerror="true"/>
|
|
||||||
<!--
|
|
||||||
<echo message="Hallo Welt: ${ParserSrcDir}JavaParser.jay"/>
|
|
||||||
<exec executable="ipconfig" failonerror="true">
|
|
||||||
<arg value="/all"/>
|
|
||||||
</exec>
|
|
||||||
-->
|
|
||||||
|
|
||||||
<!--
|
|
||||||
<exec executable="${basedir}/jay.cygwin32" dir="${ParserSrcDir}" failonerror="true">
|
|
||||||
<arg value="-v ${ParserSrcDir}JavaParser.jay <skeleton> ${ParserSrcDir}JavaParser.java"/>
|
|
||||||
|
|
||||||
<arg value="-v"/>
|
|
||||||
<arg value="${ParserSrcDir}JavaParser.jay"/>
|
|
||||||
<arg value="<"/>
|
|
||||||
<arg value="skeleton"/>
|
|
||||||
<arg value=">"/>
|
|
||||||
<arg value="${ParserSrcDir}JavaParser.java"/>
|
|
||||||
</exec>
|
|
||||||
-->
|
|
||||||
</target>
|
|
||||||
|
|
||||||
<target name ="JavaLexer" depends="Lexer" description="Move the file JavaParser.lex.java to JavaParser.java">
|
|
||||||
<move file="${ParserSrcDir}JavaLexer.lex.java" tofile="${ParserSrcDir}JavaLexer.java" failonerror="true"/>
|
|
||||||
</target>
|
|
||||||
|
|
||||||
<target name ="Lexer" description="Create the file JavaLexer.lex.java">
|
|
||||||
<java classname="JLex.Main"
|
|
||||||
classpath="${basedir}/JLex_neu.jar"
|
|
||||||
fork="true"
|
|
||||||
failonerror="true">
|
|
||||||
<arg value="${ParserSrcDir}JavaLexer.lex"/>
|
|
||||||
</java>
|
|
||||||
</target>
|
|
||||||
|
|
||||||
</project>
|
|
@ -1,45 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<project name="JavaCompiler.buildParser" default="JavaParser" basedir=".">
|
|
||||||
|
|
||||||
<property name="ParserSrcDir" value="./../src/de/dhbwstuttgart/parser/"/>
|
|
||||||
|
|
||||||
<target name ="JavaParser" depends="JavaLexer" description="Create the file JavaParser.java">
|
|
||||||
|
|
||||||
<!-- Diese Buildfile wird ausgeführt, auch unter linux... -->
|
|
||||||
|
|
||||||
<exec executable="${basedir}/RunJay.sh" failonerror="true"/>
|
|
||||||
<!--
|
|
||||||
<echo message="Hallo Welt: ${ParserSrcDir}JavaParser.jay"/>
|
|
||||||
<exec executable="ipconfig" failonerror="true">
|
|
||||||
<arg value="/all"/>
|
|
||||||
</exec>
|
|
||||||
-->
|
|
||||||
|
|
||||||
<!--
|
|
||||||
<exec executable="${basedir}/jay.cygwin32" dir="${ParserSrcDir}" failonerror="true">
|
|
||||||
<arg value="-v ${ParserSrcDir}JavaParser.jay <skeleton> ${ParserSrcDir}JavaParser.java"/>
|
|
||||||
|
|
||||||
<arg value="-v"/>
|
|
||||||
<arg value="${ParserSrcDir}JavaParser.jay"/>
|
|
||||||
<arg value="<"/>
|
|
||||||
<arg value="skeleton"/>
|
|
||||||
<arg value=">"/>
|
|
||||||
<arg value="${ParserSrcDir}JavaParser.java"/>
|
|
||||||
</exec>
|
|
||||||
-->
|
|
||||||
</target>
|
|
||||||
|
|
||||||
<target name ="JavaLexer" depends="Lexer" description="Move the file JavaParser.lex.java to JavaParser.java">
|
|
||||||
<move file="${ParserSrcDir}JavaLexer.lex.java" tofile="${ParserSrcDir}JavaLexer.java" failonerror="true"/>
|
|
||||||
</target>
|
|
||||||
|
|
||||||
<target name ="Lexer" description="Create the file JavaLexer.lex.java">
|
|
||||||
<java classname="JLex.Main"
|
|
||||||
classpath="${basedir}/JLex_neu.jar"
|
|
||||||
fork="true"
|
|
||||||
failonerror="true">
|
|
||||||
<arg value="${ParserSrcDir}JavaLexer.lex"/>
|
|
||||||
</java>
|
|
||||||
</target>
|
|
||||||
|
|
||||||
</project>
|
|
BIN
tools/JLex.jar
BIN
tools/JLex.jar
Binary file not shown.
Binary file not shown.
1509
tools/JavaParser.jay
1509
tools/JavaParser.jay
File diff suppressed because it is too large
Load Diff
@ -1,12 +0,0 @@
|
|||||||
#!/bin/bash
|
|
||||||
|
|
||||||
if [ $1 ] ;
|
|
||||||
then
|
|
||||||
/usr/lib/jvm/jdk1.8.0/bin/javac -d './' $1
|
|
||||||
echo $classfile
|
|
||||||
classfile=`echo $1 | sed 's/^.*\/\([^/]*\)\.java/\1/'`
|
|
||||||
#classfile=`pwd`"/$classfile"
|
|
||||||
echo "Klasse erfolgreich generiert: $classfile"
|
|
||||||
/usr/lib/jvm/jdk1.8.0/bin/java $classfile
|
|
||||||
else echo "Fehler: Bitte den Pfad zu einer .java Datei als Parameter übergeben!"
|
|
||||||
fi
|
|
@ -1 +0,0 @@
|
|||||||
jay.cygwin32 -v .\..\src\mycompiler\myparser\JavaParser.jay < skeleton > .\..\src\mycompiler\myparser\JavaParser.java
|
|
@ -1 +0,0 @@
|
|||||||
./../tools/jay -v ./../src/de/dhbwstuttgart/parser/JavaParser.jay < skeleton > ./../src/de/dhbwstuttgart/parser/JavaParser.java
|
|
@ -1 +0,0 @@
|
|||||||
./../tools/jay.darwin -v ./../src/de/dhbwstuttgart/parser/JavaParser.jay < skeleton > ./../src/de/dhbwstuttgart/parser/JavaParser.java
|
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user