From b99f1bc3c99abbeaac911db04f3c82c26e87a8d1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Enrico=20Schr=C3=B6dter?= Date: Fri, 23 Oct 2015 16:23:20 +0200 Subject: [PATCH] =?UTF-8?q?JavaClassName:=20Hack=20damit=20Object=20zu=20j?= =?UTF-8?q?ava.lang.Object=20wird.=20Muss=20unbedingt=20anders=20gel=C3=B6?= =?UTF-8?q?st=20werden?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../bytecode/ClassGenerator.java | 2 +- .../dhbwstuttgart/parser/JavaClassName.java | 6 ++ src/de/dhbwstuttgart/syntaxtree/Class.java | 62 ------------------- .../syntaxtree/factory/ASTFactory.java | 6 ++ .../syntaxtree/type/RefType.java | 13 ++-- test/bytecode/types/Test.java | 12 ++++ 6 files changed, 32 insertions(+), 69 deletions(-) create mode 100644 test/bytecode/types/Test.java diff --git a/src/de/dhbwstuttgart/bytecode/ClassGenerator.java b/src/de/dhbwstuttgart/bytecode/ClassGenerator.java index be42c2ba..d657c89b 100644 --- a/src/de/dhbwstuttgart/bytecode/ClassGenerator.java +++ b/src/de/dhbwstuttgart/bytecode/ClassGenerator.java @@ -35,7 +35,7 @@ public class ClassGenerator extends ClassGen{ private Map extraClasses = new HashMap<>(); public ClassGenerator(String name, Type superClass, String string, short accPublic, String[] strings, TypeinferenceResultSet resultSet) { - super(name,superClass.get_Name(),string,accPublic,strings, new DHBWConstantPoolGen()); + super(name,superClass.getName().toString(),string,accPublic,strings, new DHBWConstantPoolGen()); this.tiResult = resultSet; this.superClass = superClass; diff --git a/src/de/dhbwstuttgart/parser/JavaClassName.java b/src/de/dhbwstuttgart/parser/JavaClassName.java index 14005560..4384fe5f 100644 --- a/src/de/dhbwstuttgart/parser/JavaClassName.java +++ b/src/de/dhbwstuttgart/parser/JavaClassName.java @@ -18,6 +18,12 @@ public class JavaClassName { public JavaClassName(String name){ if(name == null)throw new NullPointerException(); + + //TODO bytecode hack, muss unbedingt anders gelöst werden + if(name.equals("Object")){ + name = "java.lang.Object"; + } + String[] names = name.split("[.]"); boolean match = true; if(names.length == 1){ diff --git a/src/de/dhbwstuttgart/syntaxtree/Class.java b/src/de/dhbwstuttgart/syntaxtree/Class.java index bfa79b33..53f81428 100755 --- a/src/de/dhbwstuttgart/syntaxtree/Class.java +++ b/src/de/dhbwstuttgart/syntaxtree/Class.java @@ -1026,67 +1026,5 @@ public class Class extends GTVDeclarationContext implements AClassOrInterface, I public boolean isInterface(){ return false; } - - /* - private Collection getGenericClasses() { - Collection results = new Menge<>(); - - for(Field field : this.fielddecl){ - Type type = field.getType(); - //Der Type des Feldes - if(type instanceof RefType){ - RefType refType = (RefType) type; - - if(!refType.getCombinedType(null).equals(refType.get_Name().replace(".", "%"))){ - results.addAll(generateGenericClass(refType.getCombinedType(null), new Class("java/util/Vector",-1))); - } - } - - if(field instanceof Method){ - Method method = (Method) field; - ParameterList parameterList = method.getParameterList(); - - //Die Typen der Methodenparameter - for(FormalParameter parameter: parameterList){ - Type parameterType = parameter.getType(); - - if(parameterType instanceof RefType){ - RefType refType = (RefType) parameterType; - - if(!refType.getCombinedType(null).equals(refType.get_Name().replace(".", "%"))){ - results.addAll(generateGenericClass(refType.getCombinedType(null), new Class("java/util/Vector",-1))); - } - } - } - } - } - - return results; - } - */ - - /* - private Menge generateGenericClass(String name, Class superClass){ - //TODO: bytecode -- Generics hinzufügen - //Type superClassType = superClass.getType(); - - //TODO: bytecode - //ClassGenerator genericClassGenerator = new ClassGenerator(name, superClassType, name + ".java", Constants.ACC_PUBLIC , new String[] { }, new TypeinferenceResultSet(null, null, null)); - - //TODO: bytecode -- Namen der neuen Klasse - Class generatedClass = new Class(name, 0); - - //TODO: bytecode -- alle Konstruktoren generieren - Block konstruktorBlock = new Block(); - konstruktorBlock.setType(new de.dhbwstuttgart.syntaxtree.type.Void(konstruktorBlock, 0)); - konstruktorBlock.statements.add(new SuperCall(konstruktorBlock)); - Constructor standardKonstruktor = new Constructor(Method.createEmptyMethod(konstruktorBlock, name, superClass), superClass); - standardKonstruktor.parserPostProcessing(generatedClass); - - generatedClass.addField(standardKonstruktor); - - return generatedClass.genByteCode(new TypeinferenceResultSet(generatedClass, new Menge<>(), new ResultSet())); - } - */ } // ino.end diff --git a/src/de/dhbwstuttgart/syntaxtree/factory/ASTFactory.java b/src/de/dhbwstuttgart/syntaxtree/factory/ASTFactory.java index 557ff35b..060ea12c 100644 --- a/src/de/dhbwstuttgart/syntaxtree/factory/ASTFactory.java +++ b/src/de/dhbwstuttgart/syntaxtree/factory/ASTFactory.java @@ -53,4 +53,10 @@ public class ASTFactory { return generatedClass; } + + public static Class createObjectClass() { + Class generatedClass = new Class("java.lang.Object", 0); + + return generatedClass; + } } diff --git a/src/de/dhbwstuttgart/syntaxtree/type/RefType.java b/src/de/dhbwstuttgart/syntaxtree/type/RefType.java index ef49744d..d73260bd 100755 --- a/src/de/dhbwstuttgart/syntaxtree/type/RefType.java +++ b/src/de/dhbwstuttgart/syntaxtree/type/RefType.java @@ -843,14 +843,15 @@ public class RefType extends ObjectType implements IMatchable //TODO: bytecode woher bekommt ich die parent klasse String combinedType = getCombinedType(cg); - if(!combinedType.equals(get_Name())){ - // TODO bytecode createClass - Class generatedClass = ASTFactory.createClass(getCombinedType(cg), getParentClass()); + if(!combinedType.equals(getName().toString())){ + // TODO bytecode statt getParentClass die eigene Class?!?! + Class classObject = ASTFactory.createClass(getName().toString(), ASTFactory.createObjectClass()); + Class generatedClass = ASTFactory.createClass(getCombinedType(cg), classObject); cg.addExtraClass(generatedClass.genByteCode(new TypeinferenceResultSet(generatedClass, new Menge<>(), new ResultSet())).getByteCode()); } - return "L"+getCombinedType(cg)+";"; + return "L"+combinedType+";"; } public String getCombinedType(ClassGenerator cg){ @@ -858,14 +859,14 @@ public class RefType extends ObjectType implements IMatchable StringBuilder sb = new StringBuilder(); if(parameter != null && parameter.size() > 0){ - sb.append(this.get_Name().replace(".", "%")); + sb.append(getName().toString().replace(".", "%")); sb.append("%%"); for(Type type: parameter){ sb.append(((RefType) type).getCombinedType(cg).replace(".", "%")); sb.append("%"); } }else{ - sb.append(this.get_Name()); + sb.append(this.getName().toString()); } return sb.toString(); diff --git a/test/bytecode/types/Test.java b/test/bytecode/types/Test.java new file mode 100644 index 00000000..78235be2 --- /dev/null +++ b/test/bytecode/types/Test.java @@ -0,0 +1,12 @@ +import java.util.Vector; + +public class Test { + + public static void main(String[] args) { + Overloading o = new Overloading(); + Vector stringVector = new Vector(); + + o.method(stringVector); + } + +}