NewArray implementiert, scheitert daran, dass der Parser keine Array

Initialisierung annimmt.
This commit is contained in:
Schubert, Julia (WWI2012D) 2015-06-25 23:05:51 +02:00
parent 03b0544131
commit d2f50069d2
3 changed files with 217 additions and 153 deletions

View File

@ -1,153 +1,162 @@
// ino.module.NewArray.8641.package // ino.module.NewArray.8641.package
package de.dhbwstuttgart.syntaxtree.statement; package de.dhbwstuttgart.syntaxtree.statement;
// ino.end // ino.end
// ino.module.NewArray.8641.import // ino.module.NewArray.8641.import
import java.util.Hashtable; import java.util.Hashtable;
import org.apache.bcel.generic.ClassGen; import org.apache.bcel.generic.ClassGen;
import org.apache.bcel.generic.InstructionFactory;
import de.dhbwstuttgart.typeinference.Menge; import org.apache.bcel.generic.InstructionList;
import de.dhbwstuttgart.logger.Logger;
import de.dhbwstuttgart.myexception.CTypeReconstructionException; import de.dhbwstuttgart.typeinference.Menge;
import de.dhbwstuttgart.myexception.JVMCodeException; import de.dhbwstuttgart.logger.Logger;
import de.dhbwstuttgart.syntaxtree.Class; import de.dhbwstuttgart.myexception.CTypeReconstructionException;
import de.dhbwstuttgart.syntaxtree.SyntaxTreeNode; import de.dhbwstuttgart.myexception.JVMCodeException;
import de.dhbwstuttgart.syntaxtree.type.GenericTypeVar; import de.dhbwstuttgart.syntaxtree.Class;
import de.dhbwstuttgart.syntaxtree.type.Type; import de.dhbwstuttgart.syntaxtree.SyntaxTreeNode;
import de.dhbwstuttgart.typeinference.ConstraintsSet; import de.dhbwstuttgart.syntaxtree.type.GenericTypeVar;
import de.dhbwstuttgart.typeinference.JavaCodeResult; import de.dhbwstuttgart.syntaxtree.type.Type;
import de.dhbwstuttgart.typeinference.ResultSet; import de.dhbwstuttgart.typeinference.ConstraintsSet;
import de.dhbwstuttgart.typeinference.assumptions.TypeAssumptions; import de.dhbwstuttgart.typeinference.JavaCodeResult;
import de.dhbwstuttgart.typeinference.unify.CSubstitutionSet; import de.dhbwstuttgart.typeinference.ResultSet;
import de.dhbwstuttgart.typeinference.assumptions.TypeAssumptions;
import de.dhbwstuttgart.typeinference.unify.CSubstitutionSet;
// ino.class.NewArray.25787.declaration
public class NewArray extends Expr
// ino.end // ino.class.NewArray.25787.declaration
// ino.class.NewArray.25787.body public class NewArray extends Expr
{ // ino.end
// ino.method.NewArray.25791.definition // ino.class.NewArray.25787.body
public NewArray(int offset,int variableLength) {
// ino.end // ino.method.NewArray.25791.definition
// ino.method.NewArray.25791.body public NewArray(int offset,int variableLength)
{ // ino.end
super(offset,variableLength); // ino.method.NewArray.25791.body
} {
// ino.end super(offset,variableLength);
// ino.attribute.type.25794.declaration }
private Type type; // ino.end
// ino.end // ino.attribute.type.25794.declaration
// ino.attribute.expr.25797.declaration private Type type;
public Menge<Expr> expr = new Menge<Expr>(); // ino.end
// ino.end // ino.attribute.expr.25797.declaration
// ino.attribute.parserlog.25800.declaration public Menge<Expr> expr = new Menge<Expr>();
protected static Logger parserlog = Logger.getLogger("parser"); // ino.end
// ino.end // ino.attribute.parserlog.25800.declaration
protected static Logger parserlog = Logger.getLogger("parser");
// ino.end
// ino.method.getType.25803.defdescription type=javadoc
/**
* Author: ¯Â¿Â½rg ¯Â¿Â½uerle<br/> // ino.method.getType.25803.defdescription type=javadoc
* @return Returns the type. /**
*/ * Author: ¯Â¿Â½rg ¯Â¿Â½uerle<br/>
// ino.end * @return Returns the type.
// ino.method.getType.25803.definition */
public Type getType() // ino.end
// ino.end // ino.method.getType.25803.definition
// ino.method.getType.25803.body public Type getType()
{ // ino.end
return type; // ino.method.getType.25803.body
} {
// ino.end return type;
}
// ino.method.setType.25806.defdescription type=javadoc // ino.end
/**
* Author: ¯Â¿Â½rg ¯Â¿Â½uerle<br/> // ino.method.setType.25806.defdescription type=javadoc
* @param type The type to set. /**
*/ * Author: ¯Â¿Â½rg ¯Â¿Â½uerle<br/>
// ino.end * @param type The type to set.
// ino.method.setType.25806.definition */
public void setType(Type type) // ino.end
// ino.end // ino.method.setType.25806.definition
// ino.method.setType.25806.body public void setType(Type type)
{ // ino.end
this.type = type; // ino.method.setType.25806.body
} {
// ino.end this.type = type;
}
// ino.method.get_Name.25809.definition // ino.end
public String get_Name()
// ino.end // ino.method.get_Name.25809.definition
// ino.method.get_Name.25809.body public String get_Name()
{ // ino.end
return null; // ino.method.get_Name.25809.body
} {
// ino.end return null;
}
/* // ino.end
// ino.method.sc_check.25812.definition
public void sc_check(Menge<Class> classname, Hashtable bh, Hashtable<String, String> ch,boolean ext, Hashtable parach, Hashtable<String, Hashtable> parabh) /*
// ino.end // ino.method.sc_check.25812.definition
// ino.method.sc_check.25812.body public void sc_check(Menge<Class> classname, Hashtable bh, Hashtable<String, String> ch,boolean ext, Hashtable parach, Hashtable<String, Hashtable> parabh)
{ // ino.end
if(ext) // ino.method.sc_check.25812.body
parserlog.debug(" ---NewArray---"); {
} if(ext)
// ino.end parserlog.debug(" ---NewArray---");
*/ }
// ino.end
// ino.method.get_codegen_Array_Type.25815.definition */
public int get_codegen_Array_Type()
throws JVMCodeException // ino.method.get_codegen_Array_Type.25815.definition
// ino.end public int get_codegen_Array_Type()
// ino.method.get_codegen_Array_Type.25815.body throws JVMCodeException
{ // ino.end
if(this.getType().equals("boolean")) return 4; // ino.method.get_codegen_Array_Type.25815.body
else if(this.getType().equals("char")) return 5; {
else if(this.getType().equals("float")) return 6; if(this.getType().equals("boolean")) return 4;
else if(this.getType().equals("double")) return 7; else if(this.getType().equals("char")) return 5;
else if(this.getType().equals("byte")) return 8; else if(this.getType().equals("float")) return 6;
else if(this.getType().equals("short")) return 9; else if(this.getType().equals("double")) return 7;
else if(this.getType().equals("int")) return 10; else if(this.getType().equals("byte")) return 8;
else if(this.getType().equals("long")) return 11; else if(this.getType().equals("short")) return 9;
else throw new JVMCodeException("JVMCodeException: NewArray: int get_codegen_Array_Type()"); else if(this.getType().equals("int")) return 10;
} else if(this.getType().equals("long")) return 11;
// ino.end else throw new JVMCodeException("JVMCodeException: NewArray: int get_codegen_Array_Type()");
}
// ino.method.wandleRefTypeAttributes2GenericAttributes.25827.definition // ino.end
public void wandleRefTypeAttributes2GenericAttributes(Menge<Type> paralist, Menge<GenericTypeVar> genericMethodParameters)
// ino.end // ino.method.wandleRefTypeAttributes2GenericAttributes.25827.definition
// ino.method.wandleRefTypeAttributes2GenericAttributes.25827.body public void wandleRefTypeAttributes2GenericAttributes(Menge<Type> paralist, Menge<GenericTypeVar> genericMethodParameters)
{ // ino.end
} // ino.method.wandleRefTypeAttributes2GenericAttributes.25827.body
// ino.end {
}
@Override // ino.end
public ConstraintsSet TYPEExpr(TypeAssumptions assumptions) {
// TODO Auto-generated method stub @Override
return null; public ConstraintsSet TYPEExpr(TypeAssumptions assumptions) {
} // TODO Auto-generated method stub
return null;
@Override }
public JavaCodeResult printJavaCode(ResultSet resultSet) {
// TODO Auto-generated method stub @Override
return null; public JavaCodeResult printJavaCode(ResultSet resultSet) {
} // TODO Auto-generated method stub
return null;
@Override }
public Menge<SyntaxTreeNode> getChildren() {
Menge<SyntaxTreeNode> ret = new Menge<SyntaxTreeNode>(); @Override
ret.addAll(this.expr); public Menge<SyntaxTreeNode> getChildren() {
return ret; Menge<SyntaxTreeNode> ret = new Menge<SyntaxTreeNode>();
} ret.addAll(this.expr);
return ret;
@Override }
public void genByteCode(ClassGen _cg) {
// TODO Auto-generated method stub @Override
public InstructionList genByteCode(ClassGen cg) {
}
InstructionFactory _factory = new InstructionFactory(cg, cg.getConstantPool());
} InstructionList il = new InstructionList();
// ino.end
il.append(expr.elementAt(0).genByteCode(cg));
il.append(_factory.createNewArray(org.apache.bcel.generic.Type.getType(getTypeName()), (short)1));
return il;
}
}
// ino.end

View File

@ -0,0 +1,10 @@
class NewArray{
void method() {
zahl;
zahl = new Integer[2];
}
}

View File

@ -0,0 +1,45 @@
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 NewArrayTest {
public final static String rootDirectory = System.getProperty("user.dir")+"/test/bytecode/";
public final static String testFile = "NewArray.jav";
public final static String outputFile = "NewArray.class";
@Test
public void test() {
LoggerConfiguration logConfig = new LoggerConfiguration().setOutput(Section.PARSER, System.out);
MyCompilerAPI compiler = MyCompiler.getAPI(logConfig);
try {
compiler.parse(new File(rootDirectory + testFile));
compiler.typeReconstruction();
ByteCodeResult bytecode = compiler.generateBytecode();
System.out.println(bytecode);
bytecode.getByteCode().getJavaClass().dump(new File(rootDirectory + outputFile));
} catch (IOException | yyException e) {
e.printStackTrace();
TestCase.fail();
}
}
}