From b51079280e503dfdb86bdd57aa42cf383840caba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Enrico=20Schr=C3=B6dter?= Date: Wed, 30 Mar 2016 10:09:17 +0200 Subject: [PATCH] - New Statement, Problem Syntax des Klassennamens --- src/de/dhbwstuttgart/syntaxtree/Class.java | 2 +- src/de/dhbwstuttgart/syntaxtree/Field.java | 3 +- .../syntaxtree/FieldDeclaration.java | 6 ++-- .../syntaxtree/FormalParameter.java | 5 +-- .../syntaxtree/SyntaxTreeNode.java | 6 ++-- .../syntaxtree/statement/Block.java | 2 +- .../syntaxtree/statement/LocalVarDecl.java | 2 +- .../syntaxtree/statement/NewClass.java | 4 +-- .../syntaxtree/statement/Statement.java | 2 +- .../syntaxtree/type/RefType.java | 7 ++++ test/bytecode/Parameter.jav | 3 ++ test/bytecode/ParameterTest.java | 34 +++++++++++++++++++ test/bytecode/types/AutoOverloadingVector.jav | 2 +- 13 files changed, 63 insertions(+), 15 deletions(-) create mode 100644 test/bytecode/Parameter.jav create mode 100644 test/bytecode/ParameterTest.java diff --git a/src/de/dhbwstuttgart/syntaxtree/Class.java b/src/de/dhbwstuttgart/syntaxtree/Class.java index 09c33f80..e2d97772 100755 --- a/src/de/dhbwstuttgart/syntaxtree/Class.java +++ b/src/de/dhbwstuttgart/syntaxtree/Class.java @@ -993,7 +993,7 @@ public class Class extends GTVDeclarationContext implements AClassOrInterface, I } @Override - public String getDescription(){ + public String getDescription(ClassGenerator cg, TypeinferenceResultSet rs){ return "class "+this.getName(); } @Override diff --git a/src/de/dhbwstuttgart/syntaxtree/Field.java b/src/de/dhbwstuttgart/syntaxtree/Field.java index fabc1328..25e97f78 100644 --- a/src/de/dhbwstuttgart/syntaxtree/Field.java +++ b/src/de/dhbwstuttgart/syntaxtree/Field.java @@ -16,6 +16,7 @@ import de.dhbwstuttgart.typeinference.JavaCodeResult; import de.dhbwstuttgart.typeinference.ResultSet; import de.dhbwstuttgart.typeinference.TypeInsertable; import de.dhbwstuttgart.typeinference.Typeable; +import de.dhbwstuttgart.typeinference.TypeinferenceResultSet; import de.dhbwstuttgart.typeinference.assumptions.TypeAssumptions; import de.dhbwstuttgart.typeinference.typedeployment.TypeInsertPoint; @@ -107,7 +108,7 @@ public abstract class Field extends GTVDeclarationContext implements TypeInserta } @Override - public String getDescription(){ + public String getDescription(ClassGenerator cg, TypeinferenceResultSet rs){ return this.getIdentifier(); } diff --git a/src/de/dhbwstuttgart/syntaxtree/FieldDeclaration.java b/src/de/dhbwstuttgart/syntaxtree/FieldDeclaration.java index 7aba86b2..08f0df8d 100644 --- a/src/de/dhbwstuttgart/syntaxtree/FieldDeclaration.java +++ b/src/de/dhbwstuttgart/syntaxtree/FieldDeclaration.java @@ -173,7 +173,7 @@ public class FieldDeclaration extends Field{ */ public InstructionList genByteCode(ClassGenerator cg, TypeinferenceResultSet rs) { //Das Feld an die Klasse anfügen: - FieldGen field = new FieldGen(0, this.getType().getBytecodeType(cg, rs), this.getDescription(), cg.getConstantPool()); + FieldGen field = new FieldGen(0, this.getType().getBytecodeType(cg, rs), this.getDescription(cg, rs), cg.getConstantPool()); field.addAttribute(cg.getInstructionFactory().createSignatureAttribute(this.getType().getBytecodeSignature(cg, rs))); cg.addField(field.getField()); @@ -183,11 +183,11 @@ public class FieldDeclaration extends Field{ il.append(this.wert.genByteCode(cg, rs)); FieldInstruction putFieldInstruction = cg.getInstructionFactory().createFieldAccess(this.getParentClass().getName().toString(), - this.getDescription(), this.getType().getBytecodeType(cg, rs), Constants.PUTFIELD); + this.getDescription(cg, rs), this.getType().getBytecodeType(cg, rs), Constants.PUTFIELD); il.append(putFieldInstruction ); return il; } - + /*@Override public void genByteCode(ClassGen cg) { // TODO Auto-generated method stub diff --git a/src/de/dhbwstuttgart/syntaxtree/FormalParameter.java b/src/de/dhbwstuttgart/syntaxtree/FormalParameter.java index d3df4039..f897ac05 100755 --- a/src/de/dhbwstuttgart/syntaxtree/FormalParameter.java +++ b/src/de/dhbwstuttgart/syntaxtree/FormalParameter.java @@ -4,7 +4,7 @@ package de.dhbwstuttgart.syntaxtree; // ino.module.FormalParameter.8561.import import de.dhbwstuttgart.typeinference.Menge; - +import de.dhbwstuttgart.bytecode.ClassGenerator; import de.dhbwstuttgart.logger.Logger; import de.dhbwstuttgart.syntaxtree.misc.DeclId; @@ -14,6 +14,7 @@ import de.dhbwstuttgart.typeinference.JavaCodeResult; import de.dhbwstuttgart.typeinference.ResultSet; import de.dhbwstuttgart.typeinference.TypeInsertable; import de.dhbwstuttgart.typeinference.Typeable; +import de.dhbwstuttgart.typeinference.TypeinferenceResultSet; import de.dhbwstuttgart.typeinference.exceptions.NotImplementedException; import de.dhbwstuttgart.typeinference.exceptions.TypeinferenceException; import de.dhbwstuttgart.typeinference.typedeployment.TypeInsertPoint; @@ -233,7 +234,7 @@ public class FormalParameter extends SyntaxTreeNode implements Typeable, TypeIns } @Override - public String getDescription() { + public String getDescription(ClassGenerator cg, TypeinferenceResultSet rs){ String ret = ""; if(this.getType() != null && !(this.getType() instanceof TypePlaceholder)){ ret += this.getType().getBytecodeSignature(null, null); diff --git a/src/de/dhbwstuttgart/syntaxtree/SyntaxTreeNode.java b/src/de/dhbwstuttgart/syntaxtree/SyntaxTreeNode.java index f76249ba..b557ed74 100644 --- a/src/de/dhbwstuttgart/syntaxtree/SyntaxTreeNode.java +++ b/src/de/dhbwstuttgart/syntaxtree/SyntaxTreeNode.java @@ -3,6 +3,7 @@ package de.dhbwstuttgart.syntaxtree; import org.apache.commons.bcel6.generic.ClassGen; import de.dhbwstuttgart.typeinference.Menge; +import de.dhbwstuttgart.bytecode.ClassGenerator; import de.dhbwstuttgart.core.IItemWithOffset; import de.dhbwstuttgart.syntaxtree.type.GenericTypeVar; import de.dhbwstuttgart.syntaxtree.type.Type; @@ -10,6 +11,7 @@ import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder; import de.dhbwstuttgart.typeinference.Pair; import de.dhbwstuttgart.typeinference.ResultSet; import de.dhbwstuttgart.typeinference.TypeInsertable; +import de.dhbwstuttgart.typeinference.TypeinferenceResultSet; import de.dhbwstuttgart.typeinference.exceptions.DebugException; import de.dhbwstuttgart.typeinference.exceptions.TypeinferenceException; import de.dhbwstuttgart.typeinference.typedeployment.GenericTypeInsertPoint; @@ -55,7 +57,7 @@ public abstract class SyntaxTreeNode implements IItemWithOffset{ * Eine Beschreibung/Name des SyntaxTree-Nodes * @return */ - public String getDescription(){ + public String getDescription(ClassGenerator cg, TypeinferenceResultSet rs){ return this.toString(); } @@ -64,7 +66,7 @@ public abstract class SyntaxTreeNode implements IItemWithOffset{ public boolean equals(Object object){ if(!(object instanceof SyntaxTreeNode))return false; SyntaxTreeNode equal = (SyntaxTreeNode)object; - if(!equal.getDescription().equals(this.getDescription()))return false; + if(!equal.getDescription(null, null).equals(this.getDescription(null, null)))return false; if(this.getParent()!=null) if(!this.getParent().equals(equal.getParent()))return false; //auch das Elternelement überprüfen. return true; diff --git a/src/de/dhbwstuttgart/syntaxtree/statement/Block.java b/src/de/dhbwstuttgart/syntaxtree/statement/Block.java index a149a0cf..2625da53 100755 --- a/src/de/dhbwstuttgart/syntaxtree/statement/Block.java +++ b/src/de/dhbwstuttgart/syntaxtree/statement/Block.java @@ -252,7 +252,7 @@ public class Block extends Statement } @Override - public String getDescription(){ + public String getDescription(ClassGenerator cg, TypeinferenceResultSet rs){ return "Block"; } diff --git a/src/de/dhbwstuttgart/syntaxtree/statement/LocalVarDecl.java b/src/de/dhbwstuttgart/syntaxtree/statement/LocalVarDecl.java index e03c1f81..423e143f 100755 --- a/src/de/dhbwstuttgart/syntaxtree/statement/LocalVarDecl.java +++ b/src/de/dhbwstuttgart/syntaxtree/statement/LocalVarDecl.java @@ -379,7 +379,7 @@ public class LocalVarDecl extends Statement implements TypeInsertable } @Override - public String getDescription() { + public String getDescription(ClassGenerator cg, TypeinferenceResultSet rs){ if(this.getType() == null)return "no type " + declid.toString(); if(this.getType() instanceof TypePlaceholder)return declid.toString(); return this.getType().toString() + " " + declid.toString(); diff --git a/src/de/dhbwstuttgart/syntaxtree/statement/NewClass.java b/src/de/dhbwstuttgart/syntaxtree/statement/NewClass.java index eefc048b..079f652c 100755 --- a/src/de/dhbwstuttgart/syntaxtree/statement/NewClass.java +++ b/src/de/dhbwstuttgart/syntaxtree/statement/NewClass.java @@ -202,11 +202,11 @@ public class NewClass extends Expr if(arglist!=null){ il.append(arglist.generateBytecode(_cg, rs)); - il.append(_cg.getInstructionFactory().createInvoke(this.getType().getDescription(), "", + il.append(_cg.getInstructionFactory().createInvoke(this.getType().getDescription(_cg, rs), "", org.apache.commons.bcel6.generic.Type.VOID, this.arglist.getBytecodeTypeList(_cg, rs), Constants.INVOKESPECIAL)); }else{ - il.append(_cg.getInstructionFactory().createInvoke(this.getType().getDescription(), "", + il.append(_cg.getInstructionFactory().createInvoke(this.getType().getDescription(_cg, rs), "", org.apache.commons.bcel6.generic.Type.VOID, new org.apache.commons.bcel6.generic.Type[]{}, Constants.INVOKESPECIAL)); } diff --git a/src/de/dhbwstuttgart/syntaxtree/statement/Statement.java b/src/de/dhbwstuttgart/syntaxtree/statement/Statement.java index d6e2e9f8..4e1ce702 100755 --- a/src/de/dhbwstuttgart/syntaxtree/statement/Statement.java +++ b/src/de/dhbwstuttgart/syntaxtree/statement/Statement.java @@ -119,7 +119,7 @@ public abstract class Statement extends SyntaxTreeNode implements IItemWithOffse public abstract JavaCodeResult printJavaCode(ResultSet resultSet); @Override - public String getDescription(){ + public String getDescription(ClassGenerator cg, TypeinferenceResultSet rs){ return this.printJavaCode(new ResultSet(new Menge())).toString(); } diff --git a/src/de/dhbwstuttgart/syntaxtree/type/RefType.java b/src/de/dhbwstuttgart/syntaxtree/type/RefType.java index ba03d583..0e8199e7 100755 --- a/src/de/dhbwstuttgart/syntaxtree/type/RefType.java +++ b/src/de/dhbwstuttgart/syntaxtree/type/RefType.java @@ -874,6 +874,13 @@ public class RefType extends ObjectType implements IMatchable public GenericClassType getGenericClassType(){ return new GenericClassType(getName().toString(), getParaList(), parent, getOffset()); } + + @Override + public String getDescription(ClassGenerator cg, TypeinferenceResultSet rs) { + return getBytecodeSignature(cg, rs); + } + + } // ino.end diff --git a/test/bytecode/Parameter.jav b/test/bytecode/Parameter.jav new file mode 100644 index 00000000..18517679 --- /dev/null +++ b/test/bytecode/Parameter.jav @@ -0,0 +1,3 @@ +class Parameter{ + public String param; +} \ No newline at end of file diff --git a/test/bytecode/ParameterTest.java b/test/bytecode/ParameterTest.java new file mode 100644 index 00000000..cd06eeef --- /dev/null +++ b/test/bytecode/ParameterTest.java @@ -0,0 +1,34 @@ +package bytecode; + +import static org.junit.Assert.*; + +import java.io.File; +import java.io.IOException; + +import junit.framework.TestCase; + +import org.junit.Test; + +import plugindevelopment.TypeInsertTester; +import de.dhbwstuttgart.core.MyCompiler; +import de.dhbwstuttgart.core.MyCompilerAPI; +import de.dhbwstuttgart.logger.LoggerConfiguration; +import de.dhbwstuttgart.logger.Section; +import de.dhbwstuttgart.parser.JavaParser.yyException; +import de.dhbwstuttgart.typeinference.ByteCodeResult; +import de.dhbwstuttgart.typeinference.Menge; +import de.dhbwstuttgart.typeinference.TypeinferenceResultSet; +import de.dhbwstuttgart.typeinference.typedeployment.TypeInsertSet; + +public class ParameterTest { + + public final static String rootDirectory = System.getProperty("user.dir")+"/test/bytecode/"; + public final static String testFile = "Parameter.jav"; + public final static String outputFile = "Parameter.class"; + + @Test + public void test() { + SingleClassTester.compileToBytecode(rootDirectory+testFile, rootDirectory+outputFile); + } + +} diff --git a/test/bytecode/types/AutoOverloadingVector.jav b/test/bytecode/types/AutoOverloadingVector.jav index 4a3b1197..eb65ae4c 100644 --- a/test/bytecode/types/AutoOverloadingVector.jav +++ b/test/bytecode/types/AutoOverloadingVector.jav @@ -1,6 +1,6 @@ import java.util.Vector; -class AutoOverloadingVector{ +class AutoOverloadingVector{ method2(p){ method(p); }