forked from JavaTX/JavaCompilerCore
Compare commits
6 Commits
9ec4d59f24
...
targetByte
Author | SHA1 | Date | |
---|---|---|---|
|
6247416e6c | ||
|
514a504f0f | ||
|
e9722e595c | ||
|
cb7c81c41b | ||
|
51b676a98a | ||
|
18728712d3 |
BIN
JavaTXcompiler-2.0-jar-with-dependencies.jar
Normal file
BIN
JavaTXcompiler-2.0-jar-with-dependencies.jar
Normal file
Binary file not shown.
BIN
JavaTXcompiler-2.1-jar-with-dependencies.jar
Normal file
BIN
JavaTXcompiler-2.1-jar-with-dependencies.jar
Normal file
Binary file not shown.
BIN
JavaTXcompiler-2.2-jar-with-dependencies.jar
Normal file
BIN
JavaTXcompiler-2.2-jar-with-dependencies.jar
Normal file
Binary file not shown.
BIN
JavaTXcompiler-2.3-jar-with-dependencies.jar
Normal file
BIN
JavaTXcompiler-2.3-jar-with-dependencies.jar
Normal file
Binary file not shown.
BIN
JavaTXcompiler-2.4-jar-with-dependencies.jar
Normal file
BIN
JavaTXcompiler-2.4-jar-with-dependencies.jar
Normal file
Binary file not shown.
BIN
JavaTXcompiler-2.5-jar-with-dependencies.jar
Normal file
BIN
JavaTXcompiler-2.5-jar-with-dependencies.jar
Normal file
Binary file not shown.
25
compile.sh
25
compile.sh
@@ -3,7 +3,7 @@
|
|||||||
SRCDIR="javatx-src/main/java"
|
SRCDIR="javatx-src/main/java"
|
||||||
DESTDIR="out"
|
DESTDIR="out"
|
||||||
JAVAC_FLAGS="-g:none -nowarn"
|
JAVAC_FLAGS="-g:none -nowarn"
|
||||||
JAVATX_COMPILER_PATH="JavaTXcompiler-1.9-jar-with-dependencies.jar"
|
JAVATX_COMPILER_PATH="JavaTXcompiler-2.5-jar-with-dependencies.jar"
|
||||||
|
|
||||||
#remove all files, if the script is called with parameter "clear"
|
#remove all files, if the script is called with parameter "clear"
|
||||||
if [ "$1" = "clean" ]; then
|
if [ "$1" = "clean" ]; then
|
||||||
@@ -11,10 +11,19 @@ if [ "$1" = "clean" ]; then
|
|||||||
exit 0
|
exit 0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
#find all .java/.jav files recursively and store them in an array
|
if [ "$1" != "" ]; then
|
||||||
|
echo "invalid argument: $1"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
#find all .java/.jav files and store paths in an array
|
||||||
|
#note: somehow absolute paths don't work correctly with find -newer
|
||||||
|
#JAVA_FILES=($(find "$SRCDIR" -name "*.java" -exec realpath {} \;))
|
||||||
|
#JAV_FILES=($(find "$SRCDIR" -name "*.jav" -exec realpath {} \;))
|
||||||
JAVA_FILES=($(find "$SRCDIR" -name "*.java"))
|
JAVA_FILES=($(find "$SRCDIR" -name "*.java"))
|
||||||
JAV_FILES=($(find "$SRCDIR" -name "*.jav"))
|
JAV_FILES=($(find "$SRCDIR" -name "*.jav"))
|
||||||
|
|
||||||
|
|
||||||
#create empty arrays for .class file paths
|
#create empty arrays for .class file paths
|
||||||
JAVA_CLASSES=()
|
JAVA_CLASSES=()
|
||||||
JAV_CLASSES=()
|
JAV_CLASSES=()
|
||||||
@@ -51,10 +60,15 @@ for file in "${JAV_FILES[@]}"; do
|
|||||||
done
|
done
|
||||||
|
|
||||||
|
|
||||||
|
#if [ "${#JAV_CHANGED[@]}" -ne 0 ]; then
|
||||||
|
# echo "java -jar $JAVATX_COMPILER_PATH -d $DESTDIR -cp "$SRCDIR:$DESTDIR:target/dependencies/" ${JAV_CHANGED[@]}"
|
||||||
|
# java -jar $JAVATX_COMPILER_PATH -d $DESTDIR -cp "$SRCDIR:$DESTDIR:target/dependencies/" "${JAV_CHANGED[@]}"
|
||||||
|
#fi
|
||||||
|
|
||||||
if [ "${#JAV_CHANGED[@]}" -ne 0 ]; then
|
if [ "${#JAV_CHANGED[@]}" -ne 0 ]; then
|
||||||
for ((i = 0; i < "${#JAV_CHANGED[@]}"; i++)); do
|
for ((i = 0; i < "${#JAV_CHANGED[@]}"; i++)); do
|
||||||
echo "java -jar $JAVATX_COMPILER_PATH -d "${JAV_CLASSES[i]%/*}" -cp "$SRCDIR:$DESTDIR:target/dependencies/" ${JAV_CHANGED[i]}"
|
echo "java -jar $(realpath $JAVATX_COMPILER_PATH) -d $(realpath "$DESTDIR") -cp "$(realpath $SRCDIR):$(realpath $DESTDIR):$(realpath "target/dependencies/")" ${JAV_CHANGED[i]}"
|
||||||
java -jar $JAVATX_COMPILER_PATH -d "${JAV_CLASSES[i]%/*}" -cp "$SRCDIR:$DESTDIR:target/dependencies/" "${JAV_CHANGED[i]}"
|
java -jar $JAVATX_COMPILER_PATH -d "$DESTDIR" -cp "$SRCDIR:$DESTDIR:target/dependencies/" "${JAV_CHANGED[i]}"
|
||||||
if [ $? -eq 1 ]; then
|
if [ $? -eq 1 ]; then
|
||||||
exit 1;
|
exit 1;
|
||||||
fi
|
fi
|
||||||
@@ -65,6 +79,3 @@ if [ "${#JAVA_CHANGED[@]}" -ne 0 ]; then
|
|||||||
echo "javac -d $DESTDIR -cp "$SRCDIR:$DESTDIR:target/dependencies/*" $JAVAC_FLAGS ${JAVA_CHANGED[@]}"
|
echo "javac -d $DESTDIR -cp "$SRCDIR:$DESTDIR:target/dependencies/*" $JAVAC_FLAGS ${JAVA_CHANGED[@]}"
|
||||||
javac -d $DESTDIR -cp "$SRCDIR:$DESTDIR:target/dependencies/*" $JAVAC_FLAGS "${JAVA_CHANGED[@]}"
|
javac -d $DESTDIR -cp "$SRCDIR:$DESTDIR:target/dependencies/*" $JAVAC_FLAGS "${JAVA_CHANGED[@]}"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@@ -0,0 +1,209 @@
|
|||||||
|
package de.dhbwstuttgart.syntaxtree;
|
||||||
|
|
||||||
|
import de.dhbwstuttgart.parser.NullToken;
|
||||||
|
import de.dhbwstuttgart.parser.scope.JavaClassName;
|
||||||
|
import de.dhbwstuttgart.syntaxtree.type.GenericRefType;
|
||||||
|
import de.dhbwstuttgart.syntaxtree.type.RefType;
|
||||||
|
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
|
||||||
|
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
|
||||||
|
import org.antlr.v4.runtime.Token;
|
||||||
|
|
||||||
|
import java.lang.reflect.Modifier;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
|
import java.util.function.Predicate;
|
||||||
|
import java.util.stream.Stream;
|
||||||
|
//import de.dhbwstuttgart.syntaxtree.*;
|
||||||
|
import de.dhbwstuttgart.syntaxtree.SyntaxTreeNode;
|
||||||
|
import de.dhbwstuttgart.syntaxtree.Field;
|
||||||
|
import de.dhbwstuttgart.syntaxtree.Constructor;
|
||||||
|
import de.dhbwstuttgart.syntaxtree.Method;
|
||||||
|
import de.dhbwstuttgart.syntaxtree.GenericDeclarationList;
|
||||||
|
import de.dhbwstuttgart.syntaxtree.GenericTypeVar;
|
||||||
|
import de.dhbwstuttgart.syntaxtree.TypeScope;
|
||||||
|
import de.dhbwstuttgart.syntaxtree.ASTVisitor;
|
||||||
|
|
||||||
|
import java.lang.Boolean;
|
||||||
|
import java.lang.String;
|
||||||
|
import java.lang.Integer;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Stellt jede Art von Klasse dar. Auch abstrakte Klassen und Interfaces
|
||||||
|
*/
|
||||||
|
public class ClassOrInterface extends SyntaxTreeNode implements TypeScope {
|
||||||
|
private Boolean methodAdded = false; // wird benoetigt bei in JavaTXCompiler.getConstraints()
|
||||||
|
protected int modifiers;
|
||||||
|
protected JavaClassName name;
|
||||||
|
private final String fileName;
|
||||||
|
|
||||||
|
private List<Field> fields = new ArrayList<>();
|
||||||
|
private Optional<Constructor> fieldInitializations; // PL 2018-11-24: Noetig, um Bytecode fuer initializators nur einmal zu erzeugen
|
||||||
|
private Optional<Method> staticInitializer;
|
||||||
|
private List<Method> methods = new ArrayList<>();
|
||||||
|
private GenericDeclarationList genericClassParameters;
|
||||||
|
private RefType superClass;
|
||||||
|
protected boolean isInterface;
|
||||||
|
protected boolean isFunctionalInterface;
|
||||||
|
private List<RefType> implementedInterfaces;
|
||||||
|
private List<RefType> permittedSubtypes;
|
||||||
|
private List<Constructor> constructors;
|
||||||
|
|
||||||
|
public ClassOrInterface(modifiers, name, fielddecl, fieldInitializations, staticInitializer, methods, constructors, genericClassParameters, superClass, isInterface, isFunctionalInterface, implementedInterfaces, permittedSubtypes, offset, fileName) {
|
||||||
|
super(offset);
|
||||||
|
if (isInterface) {
|
||||||
|
modifiers = modifiers | Modifier.INTERFACE | Modifier.ABSTRACT;
|
||||||
|
}
|
||||||
|
this.modifiers = modifiers;
|
||||||
|
this.name = name;
|
||||||
|
this.fields = fielddecl;
|
||||||
|
this.fieldInitializations = fieldInitializations;
|
||||||
|
this.staticInitializer = staticInitializer;
|
||||||
|
this.genericClassParameters = genericClassParameters;
|
||||||
|
this.superClass = superClass;
|
||||||
|
this.isInterface = isInterface;
|
||||||
|
this.isFunctionalInterface= isFunctionalInterface;
|
||||||
|
this.implementedInterfaces = implementedInterfaces;
|
||||||
|
this.permittedSubtypes = permittedSubtypes;
|
||||||
|
this.methods = methods;
|
||||||
|
this.constructors = constructors;
|
||||||
|
this.fileName = fileName;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* erzeugt fuer Fields, Konstruktoren und Methoden neue ArrayList-Objekte alle anderen Datenobjekte werden nur kopiert.
|
||||||
|
*/
|
||||||
|
public ClassOrInterface(cl) {
|
||||||
|
super(cl.getOffset());
|
||||||
|
this.modifiers = cl.modifiers;
|
||||||
|
this.name = cl.name;
|
||||||
|
this.fields = new ArrayList<>(cl.fields);
|
||||||
|
this.fieldInitializations = cl.fieldInitializations;
|
||||||
|
this.staticInitializer = cl.staticInitializer;
|
||||||
|
this.genericClassParameters = cl.genericClassParameters;
|
||||||
|
this.superClass = cl.superClass;
|
||||||
|
this.isInterface = cl.isInterface;
|
||||||
|
this.isFunctionalInterface= cl.isFunctionalInterface;
|
||||||
|
this.implementedInterfaces = cl.implementedInterfaces;
|
||||||
|
this.methods = new ArrayList<>(cl.methods);
|
||||||
|
this.constructors = new ArrayList<>(cl.constructors);
|
||||||
|
this.fileName = cl.fileName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public getFileName() {
|
||||||
|
return fileName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public getField(name) {
|
||||||
|
// TODO This should be a map
|
||||||
|
return fields.stream().filter(field -> field.getName().equals(name)).findFirst();
|
||||||
|
}
|
||||||
|
|
||||||
|
public getStaticInitializer() {
|
||||||
|
return staticInitializer;
|
||||||
|
}
|
||||||
|
|
||||||
|
public isInterface() {
|
||||||
|
return (Modifier.INTERFACE & this.getModifiers()) != 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
public isFunctionalInterface() {
|
||||||
|
return this.isFunctionalInterface;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Gets if it is added
|
||||||
|
public areMethodsAdded() {
|
||||||
|
return methodAdded;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Sets that it is added
|
||||||
|
public setMethodsAdded() {
|
||||||
|
methodAdded = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Gets class name
|
||||||
|
public getClassName() {
|
||||||
|
return this.name;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get modifiers
|
||||||
|
public getModifiers() {
|
||||||
|
return this.modifiers;
|
||||||
|
}
|
||||||
|
|
||||||
|
public getFieldDecl() {
|
||||||
|
return this.fields;
|
||||||
|
}
|
||||||
|
|
||||||
|
public getfieldInitializations() {
|
||||||
|
return this.fieldInitializations;
|
||||||
|
}
|
||||||
|
|
||||||
|
public getMethods() {
|
||||||
|
return this.methods;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* public RefType getType() { return generateTypeOfClass(this.getClassName(), this.getGenerics(), this.getOffset()); }
|
||||||
|
*/
|
||||||
|
// TODO: Das hier ist ein Problem. Je nach Kontext wird hier ein anderer Typ benötigt
|
||||||
|
public static generateTypeOfClass(name, genericsOfClass, offset) {
|
||||||
|
// Hier wird immer ein generischer Typ generiert, also mit Type placeholdern
|
||||||
|
List<RefTypeOrTPHOrWildcardOrGeneric> params = new ArrayList<>();
|
||||||
|
for (GenericTypeVar genericTypeVar : genericsOfClass) {
|
||||||
|
// params.add(genericTypeVar.getTypePlaceholder());
|
||||||
|
params.add(TypePlaceholder.fresh(offset));
|
||||||
|
}
|
||||||
|
return new RefType(name, params, offset);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @return die aktuelle Klasse als RefType
|
||||||
|
*/
|
||||||
|
public generateTypeOfThisClass() {
|
||||||
|
List<RefTypeOrTPHOrWildcardOrGeneric> params = new ArrayList<>();
|
||||||
|
for (GenericTypeVar genericTypeVar : this.getGenerics()) {
|
||||||
|
// params.add(genericTypeVar.getTypePlaceholder());
|
||||||
|
params.add(new GenericRefType(genericTypeVar.getName(), new NullToken()));
|
||||||
|
}
|
||||||
|
return new RefType(name, params, new NullToken());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Die Superklasse im Kontext dieser ClassOrInterface Das bedeutet, dass generische Variablen als GenericRefTypes dargestellt sind
|
||||||
|
*/
|
||||||
|
public getSuperClass() {
|
||||||
|
return superClass;
|
||||||
|
}
|
||||||
|
|
||||||
|
public getGenerics() {
|
||||||
|
return this.genericClassParameters;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public getReturnType() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public getConstructors() {
|
||||||
|
return constructors;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public accept(visitor) {
|
||||||
|
visitor.visit(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
public getSuperInterfaces() {
|
||||||
|
return implementedInterfaces;
|
||||||
|
}
|
||||||
|
|
||||||
|
public toString() {
|
||||||
|
return this.name.toString() + this.genericClassParameters.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@@ -14,14 +14,6 @@ import java.util.Collection;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
|
||||||
import java.util.function.Predicate;
|
|
||||||
import java.util.stream.Stream;
|
|
||||||
import de.dhbwstuttgart.syntaxtree.*;
|
|
||||||
|
|
||||||
import java.lang.Boolean;
|
|
||||||
import java.lang.String;
|
|
||||||
import java.lang.Integer;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Stellt jede Art von Klasse dar. Auch abstrakte Klassen und Interfaces
|
* Stellt jede Art von Klasse dar. Auch abstrakte Klassen und Interfaces
|
||||||
*/
|
*/
|
||||||
@@ -46,7 +38,7 @@ public class ClassOrInterface extends SyntaxTreeNode implements TypeScope {
|
|||||||
public ClassOrInterface(int modifiers, JavaClassName name, List<Field> fielddecl, Optional<Constructor> fieldInitializations, Optional<Method> staticInitializer, List<Method> methods, List<Constructor> constructors, GenericDeclarationList genericClassParameters, RefType superClass, Boolean isInterface, Boolean isFunctionalInterface, List<RefType> implementedInterfaces, List<RefType> permittedSubtypes, Token offset, String fileName) {
|
public ClassOrInterface(int modifiers, JavaClassName name, List<Field> fielddecl, Optional<Constructor> fieldInitializations, Optional<Method> staticInitializer, List<Method> methods, List<Constructor> constructors, GenericDeclarationList genericClassParameters, RefType superClass, Boolean isInterface, Boolean isFunctionalInterface, List<RefType> implementedInterfaces, List<RefType> permittedSubtypes, Token offset, String fileName) {
|
||||||
super(offset);
|
super(offset);
|
||||||
if (isInterface) {
|
if (isInterface) {
|
||||||
modifiers = modifiers | Modifier.INTERFACE | Modifier.ABSTRACT;
|
modifiers |= Modifier.INTERFACE | Modifier.ABSTRACT;
|
||||||
}
|
}
|
||||||
this.modifiers = modifiers;
|
this.modifiers = modifiers;
|
||||||
this.name = name;
|
this.name = name;
|
||||||
@@ -90,8 +82,7 @@ public class ClassOrInterface extends SyntaxTreeNode implements TypeScope {
|
|||||||
|
|
||||||
public Optional<Field> getField(String name) {
|
public Optional<Field> getField(String name) {
|
||||||
// TODO This should be a map
|
// TODO This should be a map
|
||||||
Predicate<Field> func = field -> field.getName().equals(name);
|
return fields.stream().filter(field -> field.getName().equals(name)).findFirst();
|
||||||
return fields.stream().filter(func).findFirst();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Optional<Method> getStaticInitializer() {
|
public Optional<Method> getStaticInitializer() {
|
||||||
@@ -137,7 +128,6 @@ public class ClassOrInterface extends SyntaxTreeNode implements TypeScope {
|
|||||||
public List<Method> getMethods() {
|
public List<Method> getMethods() {
|
||||||
return this.methods;
|
return this.methods;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* public RefType getType() { return generateTypeOfClass(this.getClassName(), this.getGenerics(), this.getOffset()); }
|
* public RefType getType() { return generateTypeOfClass(this.getClassName(), this.getGenerics(), this.getOffset()); }
|
||||||
*/
|
*/
|
||||||
|
@@ -3,8 +3,18 @@ package de.dhbwstuttgart.syntaxtree;
|
|||||||
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
|
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
|
||||||
import org.antlr.v4.runtime.Token;
|
import org.antlr.v4.runtime.Token;
|
||||||
|
|
||||||
|
import de.dhbwstuttgart.syntaxtree.SyntaxTreeNode;
|
||||||
|
import java.lang.String;
|
||||||
|
import java.lang.Integer;
|
||||||
|
import de.dhbwstuttgart.syntaxtree.ASTVisitor;
|
||||||
|
import de.dhbwstuttgart.syntaxtree.GenericTypeVar;
|
||||||
|
import java.lang.Iterable;
|
||||||
|
import de.dhbwstuttgart.syntaxtree.TypeScope;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
||||||
|
//TODO: curretly types are needed, or else wrong bytecode type in visitor.accept -> runtime crash, figure out why
|
||||||
|
|
||||||
public class Field extends SyntaxTreeNode implements TypeScope {
|
public class Field extends SyntaxTreeNode implements TypeScope {
|
||||||
|
|
||||||
public final int modifier;
|
public final int modifier;
|
@@ -1,8 +1,9 @@
|
|||||||
package de.dhbwstuttgart.syntaxtree;
|
package de.dhbwstuttgart.syntaxtree;
|
||||||
|
|
||||||
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
|
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
|
||||||
|
import de.dhbwstuttgart.syntaxtree.GenericTypeVar;
|
||||||
|
|
||||||
import java.util.Collection;
|
import java.lang.Iterable;
|
||||||
|
|
||||||
|
|
||||||
public interface TypeScope {
|
public interface TypeScope {
|
||||||
|
@@ -17,6 +17,37 @@ import java.util.List;
|
|||||||
import java.lang.Boolean;
|
import java.lang.Boolean;
|
||||||
import java.lang.String;
|
import java.lang.String;
|
||||||
|
|
||||||
|
//imports of jav imports
|
||||||
|
import de.dhbwstuttgart.syntaxtree.TypeScope;
|
||||||
|
|
||||||
|
import de.dhbwstuttgart.parser.NullToken;
|
||||||
|
import de.dhbwstuttgart.parser.scope.JavaClassName;
|
||||||
|
import de.dhbwstuttgart.syntaxtree.ClassOrInterface;
|
||||||
|
import de.dhbwstuttgart.syntaxtree.GenericDeclarationList;
|
||||||
|
import de.dhbwstuttgart.syntaxtree.GenericTypeVar;
|
||||||
|
import de.dhbwstuttgart.syntaxtree.Method;
|
||||||
|
import de.dhbwstuttgart.syntaxtree.factory.ASTFactory;
|
||||||
|
import de.dhbwstuttgart.syntaxtree.factory.NameGenerator;
|
||||||
|
import de.dhbwstuttgart.syntaxtree.type.GenericRefType;
|
||||||
|
import de.dhbwstuttgart.syntaxtree.type.RefType;
|
||||||
|
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
|
||||||
|
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
|
||||||
|
import de.dhbwstuttgart.syntaxtree.Constructor;
|
||||||
|
import de.dhbwstuttgart.syntaxtree.Method;
|
||||||
|
import de.dhbwstuttgart.syntaxtree.ASTVisitor;
|
||||||
|
|
||||||
|
import org.antlr.v4.runtime.Token;
|
||||||
|
|
||||||
|
import javax.swing.text.html.Option;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
|
import java.util.Objects;
|
||||||
|
import java.lang.Integer;
|
||||||
|
import java.lang.String;
|
||||||
|
import java.lang.Boolean;
|
||||||
|
|
||||||
public class FieldAssumption extends Assumption{
|
public class FieldAssumption extends Assumption{
|
||||||
private ClassOrInterface receiverClass;
|
private ClassOrInterface receiverClass;
|
||||||
private RefTypeOrTPHOrWildcardOrGeneric type;
|
private RefTypeOrTPHOrWildcardOrGeneric type;
|
||||||
@@ -37,7 +68,8 @@ public class FieldAssumption extends Assumption{
|
|||||||
return resolver.resolve(type);
|
return resolver.resolve(type);
|
||||||
}
|
}
|
||||||
|
|
||||||
public getReceiverType(resolver) {
|
//Hier inferiert Java-TX RefType, obwohl RefTypeOrTPHOrWildcardOrGeneric genereller sein sollte
|
||||||
|
public RefTypeOrTPHOrWildcardOrGeneric getReceiverType(resolver) {
|
||||||
List<RefTypeOrTPHOrWildcardOrGeneric> params = new ArrayList<>();
|
List<RefTypeOrTPHOrWildcardOrGeneric> params = new ArrayList<>();
|
||||||
for(gtv : receiverClass.getGenerics()){
|
for(gtv : receiverClass.getGenerics()){
|
||||||
//Hier wird ein GenericRefType gebildet, welcher einen für dieses Feld eindeutigen Namen hat
|
//Hier wird ein GenericRefType gebildet, welcher einen für dieses Feld eindeutigen Namen hat
|
||||||
|
@@ -27,11 +27,13 @@ import java.util.Objects;
|
|||||||
import java.lang.Integer;
|
import java.lang.Integer;
|
||||||
import java.lang.String;
|
import java.lang.String;
|
||||||
import java.lang.Boolean;
|
import java.lang.Boolean;
|
||||||
|
import java.lang.Iterable;
|
||||||
|
import java.util.Collection;
|
||||||
|
|
||||||
|
|
||||||
public class FunNClass extends ClassOrInterface {
|
public class FunNClass extends ClassOrInterface {
|
||||||
public FunNClass(funNParams) {
|
public FunNClass(funNParams) {
|
||||||
super(0, new JavaClassName("Fun" + (funNParams.size() - 1).toString()), new ArrayList<>(), Optional.empty(), Optional.empty() /* eingefuegt PL 2018-11-24 */, createMethods(funNParams), new ArrayList<>(), createGenerics(funNParams), ASTFactory.createObjectType(), true, false, new ArrayList<>(), new ArrayList<>(), new NullToken(), null);
|
super(0, new JavaClassName("Fun" + (funNParams.size() - 1).toString()), new ArrayList<>(), Optional.empty(), Optional.empty() /* eingefuegt PL 2018-11-24 */, createMethods(funNParams), new ArrayList<>(), createGenerics(funNParams), ASTFactory.createObjectType(), true, false, new ArrayList<>(), new ArrayList<>(), new NullToken(), null);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static createGenerics(funNParams) {
|
private static createGenerics(funNParams) {
|
||||||
|
@@ -18,6 +18,37 @@ import java.util.List;
|
|||||||
import java.lang.Boolean;
|
import java.lang.Boolean;
|
||||||
import java.lang.String;
|
import java.lang.String;
|
||||||
|
|
||||||
|
//imports of jav imports
|
||||||
|
import de.dhbwstuttgart.syntaxtree.TypeScope;
|
||||||
|
|
||||||
|
import de.dhbwstuttgart.parser.NullToken;
|
||||||
|
import de.dhbwstuttgart.parser.scope.JavaClassName;
|
||||||
|
import de.dhbwstuttgart.syntaxtree.ClassOrInterface;
|
||||||
|
import de.dhbwstuttgart.syntaxtree.GenericDeclarationList;
|
||||||
|
import de.dhbwstuttgart.syntaxtree.GenericTypeVar;
|
||||||
|
import de.dhbwstuttgart.syntaxtree.Method;
|
||||||
|
import de.dhbwstuttgart.syntaxtree.factory.ASTFactory;
|
||||||
|
import de.dhbwstuttgart.syntaxtree.factory.NameGenerator;
|
||||||
|
import de.dhbwstuttgart.syntaxtree.type.GenericRefType;
|
||||||
|
import de.dhbwstuttgart.syntaxtree.type.RefType;
|
||||||
|
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
|
||||||
|
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
|
||||||
|
import de.dhbwstuttgart.syntaxtree.Constructor;
|
||||||
|
import de.dhbwstuttgart.syntaxtree.Method;
|
||||||
|
import de.dhbwstuttgart.syntaxtree.ASTVisitor;
|
||||||
|
|
||||||
|
import org.antlr.v4.runtime.Token;
|
||||||
|
|
||||||
|
import javax.swing.text.html.Option;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
|
import java.util.Objects;
|
||||||
|
import java.lang.Integer;
|
||||||
|
import java.lang.String;
|
||||||
|
import java.lang.Boolean;
|
||||||
|
|
||||||
public class MethodAssumption extends Assumption{
|
public class MethodAssumption extends Assumption{
|
||||||
private ClassOrInterface receiver;
|
private ClassOrInterface receiver;
|
||||||
private RefTypeOrTPHOrWildcardOrGeneric retType;
|
private RefTypeOrTPHOrWildcardOrGeneric retType;
|
||||||
@@ -39,25 +70,25 @@ public class MethodAssumption extends Assumption{
|
|||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public ClassOrInterface getReceiver(){
|
public getReceiver(){
|
||||||
return receiver;
|
return receiver;
|
||||||
}
|
}
|
||||||
|
|
||||||
public RefTypeOrTPHOrWildcardOrGeneric getReturnType() {
|
public getReturnType() {
|
||||||
return retType;
|
return retType;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<? extends RefTypeOrTPHOrWildcardOrGeneric> getArgTypes(){
|
public getArgTypes(){
|
||||||
return params;
|
return params;
|
||||||
}
|
}
|
||||||
|
|
||||||
public RefTypeOrTPHOrWildcardOrGeneric getReturnType(GenericsResolver resolver) {
|
public getReturnType(resolver) {
|
||||||
return resolver.resolve(retType);
|
return resolver.resolve(retType);
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<RefTypeOrTPHOrWildcardOrGeneric> getArgTypes(GenericsResolver resolver) {
|
public getArgTypes(resolver) {
|
||||||
List<RefTypeOrTPHOrWildcardOrGeneric> ret = new ArrayList<>();
|
List<RefTypeOrTPHOrWildcardOrGeneric> ret = new ArrayList<>();
|
||||||
for(RefTypeOrTPHOrWildcardOrGeneric param : params){
|
for(param : params){
|
||||||
param = resolver.resolve(param);
|
param = resolver.resolve(param);
|
||||||
ret.add(param);
|
ret.add(param);
|
||||||
}
|
}
|
||||||
@@ -69,14 +100,15 @@ public class MethodAssumption extends Assumption{
|
|||||||
* @param resolver
|
* @param resolver
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public RefTypeOrTPHOrWildcardOrGeneric getReceiverType(GenericsResolver resolver) {
|
public getReceiverType(resolver) {
|
||||||
if (receiver == null) return null;
|
if (receiver == null) return null;
|
||||||
List<RefTypeOrTPHOrWildcardOrGeneric> params = new ArrayList<>();
|
List<RefTypeOrTPHOrWildcardOrGeneric> params = new ArrayList<>();
|
||||||
for(GenericTypeVar gtv : receiver.getGenerics()){
|
for(gtv : receiver.getGenerics()){
|
||||||
//Die Generics werden alle zu TPHs umgewandelt.
|
//Die Generics werden alle zu TPHs umgewandelt.
|
||||||
params.add(resolver.resolve(new GenericRefType(gtv.getName(), new NullToken())));
|
params.add(resolver.resolve(new GenericRefType(gtv.getName(), new NullToken())));
|
||||||
}
|
}
|
||||||
RefTypeOrTPHOrWildcardOrGeneric receiverType;
|
RefTypeOrTPHOrWildcardOrGeneric receiverType;
|
||||||
|
|
||||||
if(receiver instanceof FunNClass){
|
if(receiver instanceof FunNClass){
|
||||||
receiverType = new RefType(new JavaClassName(receiver.getClassName().toString()+"$$"), params, new NullToken()); // new FunN(params);
|
receiverType = new RefType(new JavaClassName(receiver.getClassName().toString()+"$$"), params, new NullToken()); // new FunN(params);
|
||||||
}else{
|
}else{
|
||||||
@@ -86,7 +118,7 @@ public class MethodAssumption extends Assumption{
|
|||||||
return receiverType;
|
return receiverType;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Boolean isInherited() {
|
public isInherited() {
|
||||||
return isInherited;
|
return isInherited;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -24,8 +24,7 @@ public class TypeInferenceBlockInformation extends TypeInferenceInformation {
|
|||||||
private TypeScope methodContext;
|
private TypeScope methodContext;
|
||||||
private ClassOrInterface currentClass;
|
private ClassOrInterface currentClass;
|
||||||
|
|
||||||
public TypeInferenceBlockInformation(Collection<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);
|
||||||
this.currentClass = currentClass;
|
this.currentClass = currentClass;
|
||||||
@@ -34,10 +33,10 @@ public class TypeInferenceBlockInformation extends TypeInferenceInformation {
|
|||||||
public TypeInferenceBlockInformation(TypeInferenceBlockInformation oldScope, TypeScope newScope) {
|
public TypeInferenceBlockInformation(TypeInferenceBlockInformation oldScope, TypeScope newScope) {
|
||||||
this(oldScope.getAvailableClasses(), oldScope.currentClass, new TypeScopeContainer(oldScope.methodContext, newScope));
|
this(oldScope.getAvailableClasses(), oldScope.currentClass, new TypeScopeContainer(oldScope.methodContext, newScope));
|
||||||
}
|
}
|
||||||
public ClassOrInterface getCurrentClass() {
|
public getCurrentClass() {
|
||||||
return currentClass;
|
return currentClass;
|
||||||
}
|
}
|
||||||
public TypeScope getCurrentTypeScope() {
|
public getCurrentTypeScope() {
|
||||||
return methodContext;
|
return methodContext;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -1,3 +1,5 @@
|
|||||||
|
//TODO: Somehow this file is not compiling with javatx
|
||||||
|
|
||||||
package de.dhbwstuttgart.typeinference.assumptions;
|
package de.dhbwstuttgart.typeinference.assumptions;
|
||||||
|
|
||||||
import de.dhbwstuttgart.exceptions.NotImplementedException;
|
import de.dhbwstuttgart.exceptions.NotImplementedException;
|
||||||
@@ -18,7 +20,7 @@ import java.util.ArrayList;
|
|||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Anmerkung:
|
Anmerkung:
|
||||||
@@ -49,9 +51,8 @@ public class TypeInferenceInformation {
|
|||||||
public List<FieldAssumption> getFields(String name){
|
public List<FieldAssumption> getFields(String name){
|
||||||
List<FieldAssumption> ret = new ArrayList<>();
|
List<FieldAssumption> ret = new ArrayList<>();
|
||||||
for(ClassOrInterface cl : classes){
|
for(ClassOrInterface cl : classes){
|
||||||
for(Field m : cl.getFieldDecl()){
|
for(var m : cl.getFieldDecl()){
|
||||||
if(m.getName().equals(name)){
|
if(m.getName().equals(name)){
|
||||||
|
|
||||||
ret.add(new FieldAssumption(name, cl, m.getType(), new TypeScopeContainer(cl, m)));
|
ret.add(new FieldAssumption(name, cl, m.getType(), new TypeScopeContainer(cl, m)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -27,47 +27,47 @@ public class Constraint<A> extends HashSet<A> {
|
|||||||
super();
|
super();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Constraint(Boolean isInherited) {
|
public Constraint(isInherited) {
|
||||||
this.isInherited = isInherited;
|
this.isInherited = isInherited;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Constraint(Boolean isInherited, Constraint<A> extendConstraint, Set<A> methodSignatureConstraint) {
|
public Constraint(isInherited, Constraint<A> extendConstraint, Set<A> methodSignatureConstraint) {
|
||||||
this.isInherited = isInherited;
|
this.isInherited = isInherited;
|
||||||
this.extendConstraint = extendConstraint;
|
this.extendConstraint = extendConstraint;
|
||||||
this.methodSignatureConstraint = methodSignatureConstraint;
|
this.methodSignatureConstraint = methodSignatureConstraint;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setIsInherited(Boolean isInherited) {
|
public setIsInherited(isInherited) {
|
||||||
this.isInherited = isInherited;
|
this.isInherited = isInherited;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Boolean isInherited() {
|
public isInherited() {
|
||||||
return isInherited;
|
return isInherited;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Constraint<A> getExtendConstraint() {
|
public getExtendConstraint() {
|
||||||
return extendConstraint;
|
return extendConstraint;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setExtendConstraint(Constraint<A> c) {
|
public setExtendConstraint(c) {
|
||||||
extendConstraint = c;
|
extendConstraint = c;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Set<A> getmethodSignatureConstraint() {
|
public getmethodSignatureConstraint() {
|
||||||
return methodSignatureConstraint;
|
return methodSignatureConstraint;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setmethodSignatureConstraint(Set<A> c) {
|
public setmethodSignatureConstraint(c) {
|
||||||
methodSignatureConstraint = c;
|
methodSignatureConstraint = c;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String toString() {
|
public toString() {
|
||||||
return super.toString() + "\nisInherited = " + isInherited.toString()
|
return super.toString() + "\nisInherited = " + isInherited.toString()
|
||||||
//" + extendsContraint: " + (extendConstraint != null ? extendConstraint.toStringBase() : "null" )
|
//" + extendsContraint: " + (extendConstraint != null ? extendConstraint.toStringBase() : "null" )
|
||||||
+ "\n" ;
|
+ "\n" ;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String toStringBase() {
|
public toStringBase() {
|
||||||
return super.toString();
|
return super.toString();
|
||||||
}
|
}
|
||||||
|
|
2
makefile
2
makefile
@@ -6,7 +6,7 @@ JTX = JavaTXcompiler-1.0-jar-with-dependencies.jar
|
|||||||
SRCDIR = javatx-src/main/java
|
SRCDIR = javatx-src/main/java
|
||||||
DESTDIR = out
|
DESTDIR = out
|
||||||
|
|
||||||
# Use find to locate all .java files recursively
|
# Use find to locate all .java and .jav files recursively
|
||||||
JAVASOURCES := $(shell find $(SRCDIR) -name '*.java')
|
JAVASOURCES := $(shell find $(SRCDIR) -name '*.java')
|
||||||
JAVSOURCES := $(shell find $(SRCDIR) -name '*.jav')
|
JAVSOURCES := $(shell find $(SRCDIR) -name '*.jav')
|
||||||
|
|
||||||
|
1
pom.xml
1
pom.xml
@@ -70,7 +70,6 @@ http://maven.apache.org/maven-v4_0_0.xsd">
|
|||||||
<artifactId>maven-compiler-plugin</artifactId>
|
<artifactId>maven-compiler-plugin</artifactId>
|
||||||
<version>3.11.0</version>
|
<version>3.11.0</version>
|
||||||
<configuration>
|
<configuration>
|
||||||
<compilerArgs>--enable-preview</compilerArgs>
|
|
||||||
<source>21</source>
|
<source>21</source>
|
||||||
<target>21</target>
|
<target>21</target>
|
||||||
</configuration>
|
</configuration>
|
||||||
|
Reference in New Issue
Block a user