forked from JavaTX/JavaCompilerCore
Aenderugen siehe http://bugzilla.ba-horb.de/show_bug.cgi?id=124
modified: ../../src/de/dhbwstuttgart/parser/SyntaxTreeGenerator/SyntaxTreeGenerator.java Zusäztlich Ein Fehler in der Trennung von Konstruktoren und Methoden gefixt. modified: ../../src/de/dhbwstuttgart/syntaxtree/ClassOrInterface.java modified: ../../src/de/dhbwstuttgart/syntaxtree/Constructor.java modified: ../../src/de/dhbwstuttgart/syntaxtree/factory/ASTFactory.java modified: ../../src/de/dhbwstuttgart/typeinference/assumptions/FunNClass.java modified: ../../src/de/dhbwstuttgart/typeinference/typeAlgo/TYPE.java modified: ../../test/bytecode/MatrixOpTest.java
This commit is contained in:
parent
7bfc222037
commit
416d68bcb0
@ -151,7 +151,7 @@ public class SyntaxTreeGenerator{
|
||||
block = stmtGen.convert(body.block(),true);
|
||||
}
|
||||
if(parentClass.equals(new JavaClassName(name))){
|
||||
return new Constructor(modifiers, name, retType, parameterList, block, gtvDeclarations, header.getStart(), fieldInitializations);
|
||||
return new Constructor(modifiers, name, retType, parameterList, block, gtvDeclarations, header.getStart() /*, fieldInitializations geloescht PL 2018-11-24 */);
|
||||
}else{
|
||||
return new Method(modifiers, name, retType, parameterList,block, gtvDeclarations, header.getStart());
|
||||
}
|
||||
@ -198,14 +198,18 @@ public class SyntaxTreeGenerator{
|
||||
}
|
||||
List<Field> fielddecl = convertFields(ctx.classBody(), generics);
|
||||
//fieldInitializations = generateFieldInitializations(ctx.classBody(), generics);
|
||||
List<Method> methods = convertMethods(ctx.classBody(), name, superClass, generics);
|
||||
List<Method> methodsAndConstructors = convertMethods(ctx.classBody(), name, superClass, generics);
|
||||
List<Method> methods = new ArrayList<>();
|
||||
List<Constructor> konstruktoren = new ArrayList<>();
|
||||
for(int i = 0; i<methods.size();i++){
|
||||
Method m = methods.get(i);
|
||||
//int noOfMethods = methods.size();
|
||||
for(int i = 0; i < methodsAndConstructors.size(); i++){
|
||||
Method m = methodsAndConstructors.get(i);
|
||||
if(m instanceof Constructor){
|
||||
methods.remove(i);
|
||||
konstruktoren.add((Constructor) m);
|
||||
}
|
||||
else {
|
||||
methods.add(m);
|
||||
}
|
||||
}
|
||||
if(konstruktoren.size()<1){//Standardkonstruktor anfügen:
|
||||
konstruktoren.add(
|
||||
@ -217,7 +221,10 @@ public class SyntaxTreeGenerator{
|
||||
|
||||
Boolean isInterface = false;
|
||||
List<RefType> implementedInterfaces = convert(ctx.superinterfaces(), generics);
|
||||
return new ClassOrInterface(modifiers, name, fielddecl, methods, konstruktoren, genericClassParameters, superClass,
|
||||
|
||||
return new ClassOrInterface(modifiers, name, fielddecl,
|
||||
Optional.of(this.generatePseudoConstructor(ctx.Identifier().getText(), name, superClass, genericClassParameters, offset)),
|
||||
methods, konstruktoren, genericClassParameters, superClass,
|
||||
isInterface, implementedInterfaces, offset);
|
||||
}
|
||||
|
||||
@ -267,7 +274,15 @@ public class SyntaxTreeGenerator{
|
||||
RefType classType = ClassOrInterface.generateTypeOfClass(reg.getName(className), classGenerics, offset);
|
||||
ParameterList params = new ParameterList(new ArrayList<>(), offset);
|
||||
Block block = new Block(new ArrayList<>(), offset);
|
||||
return new Constructor(Modifier.PUBLIC, className, classType, params, block, classGenerics, offset, fieldInitializations);
|
||||
return new Constructor(Modifier.PUBLIC, className, classType, params, block, classGenerics, offset /*, fieldInitializations geloescht PL 2018-11-24 */);
|
||||
}
|
||||
|
||||
/* fieldInitializations werden in einem Psedokonstruktor in der abstrakten Syntax gespeichert */
|
||||
private Constructor generatePseudoConstructor(String className, JavaClassName parentClass, RefType superClass, GenericDeclarationList classGenerics, Token offset){
|
||||
RefType classType = ClassOrInterface.generateTypeOfClass(reg.getName(className), classGenerics, offset);
|
||||
ParameterList params = new ParameterList(new ArrayList<>(), offset);
|
||||
Block block = new Block(fieldInitializations, offset);
|
||||
return new Constructor(Modifier.PUBLIC, className, classType, params, block, classGenerics, offset /*, fieldInitializations geloescht PL 2018-11-24 */);
|
||||
}
|
||||
|
||||
private RefType convert(Java8Parser.SuperclassContext superclass) {
|
||||
@ -441,7 +456,7 @@ public class SyntaxTreeGenerator{
|
||||
|
||||
List<RefType> extendedInterfaces = convert(ctx.extendsInterfaces(), generics);
|
||||
|
||||
return new ClassOrInterface(modifiers, name, fields, methods, new ArrayList<>(),
|
||||
return new ClassOrInterface(modifiers, name, fields, Optional.empty(), methods, new ArrayList<>(),
|
||||
genericParams, superClass, true, extendedInterfaces, ctx.getStart());
|
||||
}
|
||||
|
||||
|
@ -3,6 +3,7 @@ package de.dhbwstuttgart.syntaxtree;
|
||||
import de.dhbwstuttgart.core.IItemWithOffset;
|
||||
import de.dhbwstuttgart.exceptions.DebugException;
|
||||
import de.dhbwstuttgart.parser.scope.JavaClassName;
|
||||
import de.dhbwstuttgart.syntaxtree.statement.Statement;
|
||||
import de.dhbwstuttgart.syntaxtree.type.RefType;
|
||||
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
|
||||
import de.dhbwstuttgart.syntaxtree.visual.ASTPrinter;
|
||||
@ -16,6 +17,7 @@ import java.lang.reflect.Modifier;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
/**
|
||||
* Stellt jede Art von Klasse dar. Auch abstrakte Klassen und Interfaces
|
||||
@ -24,6 +26,7 @@ public class ClassOrInterface extends SyntaxTreeNode implements TypeScope{
|
||||
protected int modifiers;
|
||||
protected JavaClassName name;
|
||||
private List<Field> fields = new ArrayList<>();
|
||||
private Optional<Constructor> fieldInitializations; //PL 2018-11-24: Noetig, um Bytecode fuer initializators nur einmal zu erzeugen
|
||||
private List<Method> methods = new ArrayList<>();
|
||||
private GenericDeclarationList genericClassParameters;
|
||||
private RefType superClass;
|
||||
@ -31,13 +34,14 @@ public class ClassOrInterface extends SyntaxTreeNode implements TypeScope{
|
||||
private List<RefType> implementedInterfaces;
|
||||
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, Optional<Constructor> fieldInitializations, List<Method> methods, List<Constructor> constructors, GenericDeclarationList genericClassParameters,
|
||||
RefType superClass, Boolean isInterface, List<RefType> implementedInterfaces, Token offset){
|
||||
super(offset);
|
||||
if(isInterface && !Modifier.isInterface(modifiers))modifiers += Modifier.INTERFACE;
|
||||
this.modifiers = modifiers;
|
||||
this.name = name;
|
||||
this.fields = fielddecl;
|
||||
this.fieldInitializations= fieldInitializations;
|
||||
this.genericClassParameters = genericClassParameters;
|
||||
this.superClass = superClass;
|
||||
this.isInterface = isInterface;
|
||||
@ -59,6 +63,11 @@ public class ClassOrInterface extends SyntaxTreeNode implements TypeScope{
|
||||
public List<Field> getFieldDecl(){
|
||||
return this.fields;
|
||||
}
|
||||
|
||||
public Optional<Constructor> getfieldInitializations(){
|
||||
return this.fieldInitializations;
|
||||
}
|
||||
|
||||
public List<Method> getMethods(){
|
||||
return this.methods;
|
||||
}
|
||||
|
@ -15,8 +15,8 @@ public class Constructor extends Method {
|
||||
|
||||
//TODO: Constructor braucht ein super-Statement
|
||||
public Constructor(int modifier, String name, RefTypeOrTPHOrWildcardOrGeneric returnType, ParameterList parameterList, Block codeInsideConstructor,
|
||||
GenericDeclarationList gtvDeclarations, Token offset, List<Statement> fieldInitializations) {
|
||||
super(modifier, name, returnType, parameterList, prepareBlock(codeInsideConstructor,fieldInitializations), gtvDeclarations, offset);
|
||||
GenericDeclarationList gtvDeclarations, Token offset /*, List<Statement> fieldInitializations geloescht PL 2018-11-24 */) {
|
||||
super(modifier, name, returnType, parameterList, prepareBlock(codeInsideConstructor /* ,fieldInitializations geloescht PL 2018-11-24 */), gtvDeclarations, offset);
|
||||
|
||||
}
|
||||
|
||||
@ -25,10 +25,10 @@ public class Constructor extends Method {
|
||||
* welche die Felder der zugehörigen Klasse dieses
|
||||
* Konstruktor initialisieren
|
||||
*/
|
||||
protected static Block prepareBlock(Block constructorBlock, List<Statement> fieldInitializations){
|
||||
protected static Block prepareBlock(Block constructorBlock /*, List<Statement> fieldInitializations new ArrayList<>() geloescht PL 2018-11-24 */){
|
||||
List<Statement> statements = constructorBlock.getStatements();
|
||||
statements.add(0, new SuperCall(constructorBlock.getOffset()));
|
||||
statements.addAll(fieldInitializations);
|
||||
/* statements.addAll(fieldInitializations); geloescht PL 2018-11-24 */
|
||||
return new Block(statements, constructorBlock.getOffset());
|
||||
}
|
||||
|
||||
|
@ -4,6 +4,7 @@ import java.lang.reflect.*;
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
import de.dhbwstuttgart.exceptions.NotImplementedException;
|
||||
import de.dhbwstuttgart.parser.NullToken;
|
||||
@ -65,7 +66,7 @@ public class ASTFactory {
|
||||
|
||||
Token offset = new NullToken(); //Braucht keinen Offset, da diese Klasse nicht aus einem Quellcode geparst wurde
|
||||
|
||||
return new ClassOrInterface(modifier, name, felder, methoden, konstruktoren, genericDeclarationList, superClass,isInterface, implementedInterfaces, offset);
|
||||
return new ClassOrInterface(modifier, name, felder, Optional.empty() /* eingefuegt PL 2018-11-24 */,methoden, konstruktoren, genericDeclarationList, superClass,isInterface, implementedInterfaces, offset);
|
||||
}
|
||||
|
||||
private static Field createField(java.lang.reflect.Field field, JavaClassName jreClass) {
|
||||
@ -98,7 +99,7 @@ public class ASTFactory {
|
||||
return null;
|
||||
}
|
||||
|
||||
return new de.dhbwstuttgart.syntaxtree.Constructor(modifier, name,returnType, parameterList, block, gtvDeclarations, offset, new ArrayList<>());
|
||||
return new de.dhbwstuttgart.syntaxtree.Constructor(modifier, name,returnType, parameterList, block, gtvDeclarations, offset /*, new ArrayList<>() geloescht PL 2018-11-24 */);
|
||||
}
|
||||
|
||||
public static Method createMethod(java.lang.reflect.Method jreMethod, java.lang.Class inClass){
|
||||
|
@ -17,10 +17,11 @@ import org.antlr.v4.runtime.Token;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
public class FunNClass extends ClassOrInterface {
|
||||
public FunNClass(List<GenericRefType> funNParams) {
|
||||
super(0, new JavaClassName("Fun"+(funNParams.size())), new ArrayList<>(),
|
||||
super(0, new JavaClassName("Fun"+(funNParams.size())), new ArrayList<>(), Optional.empty() /* eingefuegt PL 2018-11-24 */,
|
||||
createMethods(funNParams), new ArrayList<>(), createGenerics(funNParams),
|
||||
ASTFactory.createObjectType(), true, new ArrayList<>(), new NullToken());
|
||||
|
||||
|
@ -38,6 +38,9 @@ public class TYPE {
|
||||
for(Constructor m : cl.getConstructors()){
|
||||
ret.addAll(getConstraintsConstructor(m,info, cl));
|
||||
}
|
||||
if (cl.getfieldInitializations().isPresent()) {
|
||||
ret.addAll(getConstraintsConstructor(cl.getfieldInitializations().get(), info, cl));
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
/*
|
||||
@ -61,6 +64,7 @@ public class TYPE {
|
||||
return new TypeInferenceInformation(classes);
|
||||
}
|
||||
*/
|
||||
|
||||
private ConstraintSet getConstraintsMethod(Method m, TypeInferenceInformation info, ClassOrInterface currentClass) {
|
||||
if(m.block == null)return new ConstraintSet(); //Abstrakte Methoden generieren keine Constraints
|
||||
TypeInferenceBlockInformation blockInfo = new TypeInferenceBlockInformation(info.getAvailableClasses(), currentClass, m);
|
||||
|
@ -32,7 +32,7 @@ public class MatrixOpTest {
|
||||
fileToTest = new File(path);
|
||||
compiler = new JavaTXCompiler(fileToTest);
|
||||
pathToClassFile = System.getProperty("user.dir")+"/testBytecode/generatedBC/";
|
||||
// compiler.generateBytecode(pathToClassFile);
|
||||
compiler.generateBytecode(pathToClassFile);
|
||||
// loader = new URLClassLoader(new URL[] {new URL("file://"+pathToClassFile)});
|
||||
// classToTest = loader.loadClass("MatrixOP");
|
||||
/*
|
||||
|
Loading…
Reference in New Issue
Block a user