JavaPatternMatching/src/mycompiler/mybytecode/ClassFile.java

855 lines
30 KiB
Java
Raw Normal View History

2014-03-24 14:32:13 +00:00
//key_vector funktioniert nicht PL 14-03-21
//muss angeschaut werden
2013-10-18 11:33:46 +00:00
// ino.module.ClassFile.8531.package
package mycompiler.mybytecode;
// ino.end
// ino.module.ClassFile.8531.import
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
2013-10-18 11:33:46 +00:00
import java.lang.reflect.Array;
import java.util.Vector;
2013-10-18 11:33:46 +00:00
import mycompiler.myclass.ParameterList;
import mycompiler.myclass.UsedId;
import mycompiler.MyCompiler;
import mycompiler.myexception.JVMCodeException;
import mycompiler.myinterface.Interface;
import mycompiler.mystatement.Assign;
import mycompiler.mystatement.Block;
import mycompiler.mytype.Type;
import mycompiler.SourceFile;
2013-10-18 11:33:46 +00:00
import org.apache.log4j.Logger;
// ino.end
// ino.class.ClassFile.21492.description type=javadoc
/**
* Darstellung einer Klassendatei aus Sicht fuer die JVM.
* Generiert bei der Bytegenerierung Header, Constantenpool, usw.
*
* @author hama, scju
*
*/
// ino.end
// ino.class.ClassFile.21492.declaration
public class ClassFile
// ino.end
// ino.class.ClassFile.21492.body
{
public boolean hamaAload0 = false; //hama: f<>gt in Konstruktor und set Methode ein aload_0 ein wird f<>r StoreSomethingParmCon ben<65>tigt
// ino.attribute.codegenlog.21495.decldescription type=line
// Logger fuer Code-Gen
// ino.end
// ino.attribute.codegenlog.21495.declaration
protected static Logger codegenlog = Logger.getLogger("codegen");
// ino.end
// ino.attribute.magic.21498.decldescription type=line
// Header fuer Java Version 1.5.0_05
// ino.end
// ino.attribute.magic.21498.declaration
private static int magic = 0xcafebabe;
// ino.end
// ino.attribute.minor_version.21501.declaration
2014-03-24 14:32:13 +00:00
public static short minor_version = 0;
2013-10-18 11:33:46 +00:00
// ino.end
// ino.attribute.major_version.21504.declaration
2014-03-24 14:32:13 +00:00
public static short major_version = 0x31;
2013-10-18 11:33:46 +00:00
// ino.end
// ino.attribute.constant_pool.21507.declaration
private Vector<CPInfo> constant_pool = new Vector<CPInfo>();
// ino.end
// ino.attribute.access_flags.21510.declaration
private short access_flags;
// ino.end
// ino.attribute.this_class.21513.declaration
private short this_class;
// ino.end
// ino.attribute.super_class.21516.declaration
private short super_class;
// ino.end
// ino.attribute.fields.21519.declaration
private Vector<FieldInfo> fields = new Vector<FieldInfo>();
// ino.end
// ino.attribute.methods.21522.declaration
private Vector<MethodInfo> methods = new Vector<MethodInfo>();
// ino.end
// ino.attribute.attributes.21525.declaration
private Vector<Attribute> attributes = new Vector<Attribute>();
// ino.end
// ino.attribute.interfaces.21528.declaration
private Vector<Short> interfaces = new Vector<Short>();
// ino.end
// ino.attribute.key_vector.21531.declaration
private Vector<Key> key_vector = new Vector<Key>();
// ino.end
// ino.attribute.class_block.21534.declaration
private Vector<Assign> class_block = new Vector<Assign>();
// ino.end
// ino.attribute.class_name.21537.declaration
2014-03-24 14:32:13 +00:00
private String class_name = new String("OUTPUT");//DEFAULTWERT PL 14-03-21 eingefuegt
2013-10-18 11:33:46 +00:00
// ino.end
// ino.attribute.super_class_name.21540.declaration
private String super_class_name = new String();
// ino.end
// ino.attribute.constructor_founded.21543.declaration
private boolean constructor_founded = false;
// ino.end
// ino.attribute.ConstantValueID.21546.decldescription type=line
// Wird fuer Konstante benoetigt (UTF-8 Eintrag mit
// "ConstantValue"), lediglich ein Mal pro Klasse
// ino.end
// ino.attribute.ConstantValueID.21546.declaration
private short ConstantValueID = 0;
// ino.end
// ino.attribute.SignatureID.21549.decldescription type=line
// Wird fuer Signaturen (Generics) benoetigt
// Wiederrum nur ein UTF-8 Eintrag in der
// Konstantentabelle ("Signature")
// ino.end
// ino.attribute.SignatureID.21549.declaration
private short SignatureID = 0;
// ino.end
// ino.method.ClassFile.21552.defdescription type=javadoc
/**
* Default Konstruktor
*/
// ino.end
// ino.method.ClassFile.21552.definition
public ClassFile()
// ino.end
// ino.method.ClassFile.21552.body
{
}
// ino.end
// ino.method.ClassFile.21555.defdescription type=javadoc
/**
* Konstruktor, um Klasseninfos direkt aus dem Interface zu laden
*/
// ino.end
// ino.method.ClassFile.21555.definition
public ClassFile(Interface ic, SourceFile sf)
// ino.end
// ino.method.ClassFile.21555.body
{
// Modifier wird auf den Wert 0x601 festgelegt (INTERFACE+ABSTRACT+PUBLIC)
// Andere Werte machen hier keinen Sinn!
String pkgName = "";
if (sf.getPackageName() != null) {
pkgName = sf.getPackageName().get_codegen_UsedId() + "/";
}
this.add_interface(ic.getName(), pkgName, "java/lang/Object", (short) 0x601);
}
// ino.end
// ino.method.add_CONSTANT_Utf8_info.21558.definition
public int add_CONSTANT_Utf8_info(String name)
// ino.end
// ino.method.add_CONSTANT_Utf8_info.21558.body
{
Key utf8_key = new Key(JVMCode.CONSTANT_Utf8, name);
if(!this.key_vector.contains(utf8_key)) {
CONSTANT_Utf8_info utf8_info = new CONSTANT_Utf8_info();
utf8_info.set_tag(JVMCode.CONSTANT_Utf8);
utf8_info.set_bytes(name.getBytes());
this.key_vector.addElement(utf8_key);
this.constant_pool.addElement(utf8_info);
}
return (this.key_vector.indexOf(utf8_key)+1);
}
// ino.end
// ino.method.add_CONSTANT_Class_info.21561.definition
public int add_CONSTANT_Class_info(String name)
// ino.end
// ino.method.add_CONSTANT_Class_info.21561.body
{
Key class_key = new Key(JVMCode.CONSTANT_Class, name);
if(!this.key_vector.contains(class_key)) {
CONSTANT_Class_info class_info = new CONSTANT_Class_info();
class_info.set_tag(JVMCode.CONSTANT_Class);
class_info.set_name_index((short)this.add_CONSTANT_Utf8_info(name));
this.key_vector.addElement(class_key);
this.constant_pool.addElement(class_info);
}
return (this.key_vector.indexOf(class_key)+1);
}
// ino.end
// ino.method.add_CONSTANT_NameAndType_info.21564.definition
public int add_CONSTANT_NameAndType_info(String name, String param_type)
// ino.end
// ino.method.add_CONSTANT_NameAndType_info.21564.body
{
Key name_type_key = new Key(JVMCode.CONSTANT_NameAndType, name + param_type);
if(!this.key_vector.contains(name_type_key))
{
CONSTANT_NameAndType_info name_type = new CONSTANT_NameAndType_info();
name_type.set_tag(JVMCode.CONSTANT_NameAndType);
name_type.set_name_index((short)this.add_CONSTANT_Utf8_info(name));
name_type.set_descriptor_index((short)this.add_CONSTANT_Utf8_info(param_type));
this.key_vector.addElement(name_type_key);
this.constant_pool.addElement(name_type);
}
return this.key_vector.indexOf(name_type_key) + 1;
}
// ino.end
// ino.method.add_CONSTANT_Integer_info.21567.definition
public int add_CONSTANT_Integer_info(int i)
// ino.end
// ino.method.add_CONSTANT_Integer_info.21567.body
{
Key key = new Key(JVMCode.CONSTANT_Integer, "" + i);
if(!this.key_vector.contains(key)) {
CONSTANT_Integer_info info = new CONSTANT_Integer_info();
info.set_tag(JVMCode.CONSTANT_Integer);
info.set_bytes(i);
this.key_vector.addElement(key);
this.constant_pool.addElement(info);
}
return (this.key_vector.indexOf(key)+1);
}
// ino.end
// ino.method.add_CONSTANT_String_info.21570.definition
public int add_CONSTANT_String_info(String s)
// ino.end
// ino.method.add_CONSTANT_String_info.21570.body
{
Key key = new Key(JVMCode.CONSTANT_String, s);
if(!this.key_vector.contains(key)) {
CONSTANT_String_info info = new CONSTANT_String_info();
info.set_tag(JVMCode.CONSTANT_String);
info.set_string_index((short)this.add_CONSTANT_Utf8_info(s));
this.key_vector.addElement(key);
this.constant_pool.addElement(info);
}
return (this.key_vector.indexOf(key)+1);
}
// ino.end
// ino.method.add_class.21573.defdescription type=javadoc
/**
* Fuegt Informationen ueber eine neue Klasse ein. Gleichzeitig
* wird ein Default-Konstruktor angelegt.
*/
// ino.end
// ino.method.add_class.21573.definition
public void add_class(String name, String pkgName, String super_name, short acc_flag)
// ino.end
// ino.method.add_class.21573.body
{
codegenlog.debug("Klasse hinzugefuegt: " + name + ", Package: " + pkgName
+ ", Superklasse: " + super_name + ", Accessflags: " + acc_flag);
addClassInfo(name, pkgName, super_name, acc_flag);
this.add_method_ref(super_name, "<init>", "()V");
}
// ino.end
// ino.method.add_interface.21576.defdescription type=javadoc
/**
* Fuegt Informationen ueber ein neues Interface ein.
*/
// ino.end
// ino.method.add_interface.21576.definition
public void add_interface(String name, String pkgName, String super_name, short acc_flag)
// ino.end
// ino.method.add_interface.21576.body
{
codegenlog.debug("Interface hinzugefuegt: " + name + ", Package: " + pkgName
+ ", Superklasse: " + super_name + ", Accessflags: " + acc_flag);
addClassInfo(name, pkgName, super_name, acc_flag);
}
// ino.end
// ino.method.addClassInfo.21579.defdescription type=javadoc
/**
* Fuegt Informationen ueber Access-Flags, Superklasse usw. ein
*/
// ino.end
// ino.method.addClassInfo.21579.definition
private void addClassInfo(String name, String pkgName, String super_name, short acc_flag)
// ino.end
// ino.method.addClassInfo.21579.body
{
//feda 15.05.2007
//Eine Klasse hat immer den Access Modifier Super 0x0020
short tempAcc_super = 32;
acc_flag +=tempAcc_super;
access_flags = acc_flag;
class_name = name;
super_class_name = super_name;
this.this_class = (short)add_CONSTANT_Class_info(pkgName+name);
this.super_class = (short)add_CONSTANT_Class_info(super_name);
}
// ino.end
// ino.method.addSuperInterfaces.21582.defdescription type=javadoc
/**
* Fuegt die erweiterten (bei Interfaces) implementierten (bei Klassen)
* Interfaces ein.
*/
// ino.end
// ino.method.addSuperInterfaces.21582.definition
public void addSuperInterfaces(Vector<UsedId> superif)
// ino.end
// ino.method.addSuperInterfaces.21582.body
{
if (superif == null) return;
for (int i=0; i< superif.size(); i++) {
UsedId uid = superif.elementAt(i);
interfaces.addElement((short) add_CONSTANT_Class_info(uid.get_codegen_UsedId()));
}
}
// ino.end
// ino.method.addGenerics.21585.defdescription type=javadoc
/**
* Fuegt ggf. Generics in den Klassendefintion selbst
* hinzu.
*/
// ino.end
// ino.method.addGenerics.21585.definition
public void addGenerics(Vector<Type> para, UsedId superClass, Vector<UsedId> superIf)
// ino.end
// ino.method.addGenerics.21585.body
{
if (para == null || para.size() == 0) return;
SignatureInfo si = new SignatureInfo(para, superClass, superIf, this);
attributes.addElement(si);
}
// ino.end
// ino.method.add_method.21588.definition
public void add_method(String name, String param_type, ParameterList param,
Type type, Block block, short acc_flag, Vector paralist, boolean isAbstract)
throws JVMCodeException
// ino.end
// ino.method.add_method.21588.body
{
Vector<Attribute> method_attributes = new Vector<Attribute>();
// Sofern eine Signatur (Generic) in der Beschreibung der Methode vorkommt,
// Signatur generieren.
if(SignatureInfo.needsSignature( param, type))
method_attributes.addElement(new SignatureInfo(param, type, this));
codegenlog.debug("Methode hinzugefuegt: " + name + ", Parameter-Typ: " + param_type
+ ", Accessflags: " + acc_flag);
CodeAttribute code = new CodeAttribute(class_name, acc_flag);
code.set_attribute_name_index((short)this.add_CONSTANT_Utf8_info("Code"));
if(name.equals("<init>"))
{
code.add_code(JVMCode.aload_0);
code.add_code(JVMCode.invokespecial);
//hama: habe die obere original Zeile auskommentiert.
//Ich bekomme mit der obigen Zeile ein Fehler in der Verlinkung des
//ConstantPool (mit der unteren Zeile nicht)
//code.add_code_short(this.add_method_ref(super_class_name, name, param_type));
code.add_code_short(this.add_method_ref(super_class_name, name, "()V"));
for(int i = 0; i < class_block.size(); i++)
{
class_block.elementAt(i).codegen(this, code, paralist);
}
if(param != null) param.codegen(this, code);
//hama: in dem Use Case StoreSomething wird vom Compiler ein
//aload_0 zuwening im Konstruktor erzeugt. Deshalb schreibe ich
//es hier hard rein.
//Test Workaround: Das eigentliche Problem: "Warum fehlt das aload_0" ist
//noch nicht behoben. Au<41>erdem stimmt das hier nur f<>r den einen Use Case
//in allen anderen F<>llen wird f<>lschlicher Weise das aload_0 einef<65>gt.
if(this.hamaAload0 == true)
{
byte b2 = 42;
Byte b1 = new Byte(b2);
code.add_code(b1);
codegenlog.warn("hama: Class ClassFile: !!!!!!!!!!!!!!!!!!!!ACHTUNG experimentell aload_0 in Konstrukor eingef<65>gt!!!");
}
//hama: bis hier experimentell
if(block != null)
{
block.codegen(this, code, paralist);
}
code.add_code(JVMCode.return_);
}
else
{
if(param != null)
{
param.codegen(this, code);
}
//hama: in dem Use Case StoreSomething wird vom Compiler ein
//aload_0 zuwening in der set Methode erzeugt. Deshalb schreibe ich
//es hier hard rein.
//Test Workaround: Das eigentliche Problem: "Warum fehlt das aload_0" ist
//noch nicht behoben. Au<41>erdem stimmt das hier nur f<>r den einen Use Case
//in allen anderen F<>llen einer Set Methode wird f<>lschlicher Weise das
//aload_0 einef<65>gt.
if(this.hamaAload0 == true)
{
if(name.equals("set"))
{
byte b2 = 42;
Byte b1 = new Byte(b2);
code.add_code(b1);
codegenlog.warn("hama: Class ClassFile: !!!!!!!!!!!!!!!!!!!!ACHTUNG experimentell aload_0 in die set Methode eingef<65>gt!!!");
}
}
//hama: bis hier experimentell.
if(block != null)
{
block.codegen(this, code, paralist);
}
if(type != null && type.getName().equals("void"))
{
code.add_code(JVMCode.return_);
}
}
// Code nur hinzufuegen, wenn nicht abstract (Interface!)
if (!isAbstract) method_attributes.addElement(code);
// Methodeninformationen zusammenstellen
MethodInfo method = new MethodInfo();
//feda Accessflag muss beim <init> 1 = Public sein.
if(name.equals("<init>"))
{
acc_flag = 1;
}
method.set_access_flags(acc_flag);
method.set_name_index((short)add_CONSTANT_Utf8_info(name));
method.set_descriptor_index((short)add_CONSTANT_Utf8_info(param_type));
method.set_attributes(method_attributes);
if(!this.methods.contains(method))
{
methods.addElement(method);
}
}
// ino.end
// ino.method.add_method_ref.21591.definition
public int add_method_ref(String cl_name, String name, String param_type)
// ino.end
// ino.method.add_method_ref.21591.body
{
// Bei fully qualified names wichtig!
if (cl_name.contains(".")) cl_name = cl_name.replace(".", "/");
codegenlog.debug("Methodenreferenz hinzugefuegt: " + name + ", Klasse: " + cl_name
+ ", Paramter-Typ: " + param_type);
Key methodref_key = new Key(JVMCode.CONSTANT_Methodref, cl_name + name + param_type);
if(!this.key_vector.contains(methodref_key))
{
CONSTANT_Methodref_info methodref = new CONSTANT_Methodref_info();
methodref.set_tag(JVMCode.CONSTANT_Methodref);
methodref.set_class_index((short)this.add_CONSTANT_Class_info(cl_name));
methodref.set_name_and_type_index((short)this.add_CONSTANT_NameAndType_info(name, param_type));
this.key_vector.addElement(methodref_key);
this.constant_pool.addElement(methodref);
}
return this.key_vector.indexOf(methodref_key)+1;
}
// ino.end
// ino.method.getConstantValueID.21594.defdescription type=javadoc
/**
* Gibt den NameIndex auf die UTF-8 Konstante "ConstantValue" zurueck,
* der fuer die Definition von Konstanten benoetigt wird.
*/
// ino.end
// ino.method.getConstantValueID.21594.definition
public short getConstantValueID()
// ino.end
// ino.method.getConstantValueID.21594.body
{
if (ConstantValueID == 0) {
ConstantValueID = (short) add_CONSTANT_Utf8_info("ConstantValue");
}
return ConstantValueID;
}
// ino.end
// ino.method.getSignatureID.21597.defdescription type=javadoc
/**
* Gibt den NameIndex auf die UTF-8 Konstante "Signature" zurueck,
* der fuer die Definition von Konstanten benoetigt wird.
*/
// ino.end
// ino.method.getSignatureID.21597.definition
public short getSignatureID()
// ino.end
// ino.method.getSignatureID.21597.body
{
if (SignatureID == 0) {
SignatureID = (short) add_CONSTANT_Utf8_info("Signature");
}
return SignatureID;
}
// ino.end
// ino.method.add_field.21600.definition
public void add_field(String name, String type, short acc_flag, Attribute attr)
// ino.end
// ino.method.add_field.21600.body
{
codegenlog.debug("Field hinzugefuegt: " + name + ", Typ: " + type + " ," +
"Accessflags: " + acc_flag);
FieldInfo field = new FieldInfo();
field.set_Name(name);
field.set_Type(type);
field.set_Class_Name(class_name);
field.set_access_flags(acc_flag);
field.set_name_index((short)this.add_CONSTANT_Utf8_info(name));
field.set_descriptor_index((short)this.add_CONSTANT_Utf8_info(type));
if (attr != null) {
Vector<Attribute> vec = new Vector<Attribute>();
vec.addElement(attr);
field.set_attributes(vec);
}
fields.addElement(field);
}
// ino.end
// ino.method.add_field_ref.21603.definition
public int add_field_ref(String name, String cl_name, String type)
throws JVMCodeException
// ino.end
// ino.method.add_field_ref.21603.body
{
if(cl_name==null) cl_name = class_name;
if(type==null) {
int index = -1;
for(int i=0; i < fields.size();i++)
if(name.equals(fields.elementAt(i).get_Name())) { index = i; break; }
if(index == -1) throw new JVMCodeException("JVMCodeException: ClassFile: int add_field_ref(String name, String cla_name, String atype)");
FieldInfo field = fields.elementAt(index);
type = field.get_Type();
cl_name = field.get_Class_Name();
codegenlog.debug("Fieldref hinzugefuegt: " + name + ", Klassenname: " + cl_name
+ ", Accessflags: " + field.get_access_flags());
Key fieldref_key = new Key(JVMCode.CONSTANT_Fieldref, cl_name + name + type);
if(!this.key_vector.contains(fieldref_key)) {
CONSTANT_Fieldref_info fieldref = new CONSTANT_Fieldref_info();
fieldref.set_tag(JVMCode.CONSTANT_Fieldref);
fieldref.set_class_index((short)this.add_CONSTANT_Class_info(cl_name));
fieldref.set_name_and_type_index((short)this.add_CONSTANT_NameAndType_info(name, type));
this.key_vector.addElement(fieldref_key);
this.constant_pool.addElement(fieldref);
}
return (this.key_vector.indexOf(fieldref_key)+1);
}
else {
codegenlog.debug("Fieldref hinzugefuegt: " + name + ", Klassenname: " + cl_name
+ ", Typ: " + type);
Key fieldref_key = new Key(JVMCode.CONSTANT_Fieldref, cl_name + name + type);
if(!this.key_vector.contains(fieldref_key)) {
CONSTANT_Fieldref_info fieldref = new CONSTANT_Fieldref_info();
fieldref.set_tag(JVMCode.CONSTANT_Fieldref);
fieldref.set_class_index((short)this.add_CONSTANT_Class_info(cl_name));
fieldref.set_name_and_type_index((short)this.add_CONSTANT_NameAndType_info(name, type));
this.key_vector.addElement(fieldref_key);
this.constant_pool.addElement(fieldref);
}
return (this.key_vector.indexOf(fieldref_key)+1);
}
}
// ino.end
// ino.method.set_constant_pool.21606.definition
public void set_constant_pool(Vector<CPInfo> t)
// ino.end
// ino.method.set_constant_pool.21606.body
{ this.constant_pool = t; }
// ino.end
// ino.method.set_access_flags.21609.definition
public void set_access_flags(short t)
// ino.end
// ino.method.set_access_flags.21609.body
{ this.access_flags = t; }
// ino.end
// ino.method.set_this_class.21612.definition
public void set_this_class(short t)
// ino.end
// ino.method.set_this_class.21612.body
{ this.this_class = t; }
// ino.end
// ino.method.set_super_class.21615.definition
public void set_super_class(short t)
// ino.end
// ino.method.set_super_class.21615.body
{ this.super_class = t; }
// ino.end
// ino.method.set_fields.21618.definition
public void set_fields(Vector<FieldInfo> t)
// ino.end
// ino.method.set_fields.21618.body
{ this.fields = t; }
// ino.end
// ino.method.set_methods.21621.definition
public void set_methods(Vector<MethodInfo> t)
// ino.end
// ino.method.set_methods.21621.body
{ this.methods = t; }
// ino.end
// ino.method.set_attributes.21624.definition
public void set_attributes(Vector<Attribute> t)
// ino.end
// ino.method.set_attributes.21624.body
{ this.attributes = t; }
// ino.end
2014-03-24 14:32:13 +00:00
public void set_class_name(String cn) {
this.class_name = cn;
}
2013-10-18 11:33:46 +00:00
// ino.method.set_constructor_founded.21627.definition
public void set_constructor_founded(boolean t)
// ino.end
// ino.method.set_constructor_founded.21627.body
{ this.constructor_founded = t; }
// ino.end
// ino.method.add_classblock_Element.21630.definition
public void add_classblock_Element(Assign a)
// ino.end
// ino.method.add_classblock_Element.21630.body
{ class_block.addElement(a); }
// ino.end
// ino.method.get_constant_pool.21633.definition
public Vector<CPInfo> get_constant_pool()
// ino.end
// ino.method.get_constant_pool.21633.body
{ return this.constant_pool; }
// ino.end
// ino.method.get_access_flags.21636.definition
public short get_access_flags()
// ino.end
// ino.method.get_access_flags.21636.body
{ return this.access_flags; }
// ino.end
// ino.method.get_this_class.21639.definition
public short get_this_class()
// ino.end
// ino.method.get_this_class.21639.body
{ return this.this_class; }
// ino.end
// ino.method.get_super_class.21642.definition
public short get_super_class()
// ino.end
// ino.method.get_super_class.21642.body
{ return this.super_class; }
// ino.end
// ino.method.get_fields.21645.definition
public Vector<FieldInfo> get_fields()
// ino.end
// ino.method.get_fields.21645.body
{ return this.fields; }
// ino.end
// ino.method.get_methods.21648.definition
public Vector<MethodInfo> get_methods()
// ino.end
// ino.method.get_methods.21648.body
{ return this.methods; }
// ino.end
// ino.method.get_attributes.21651.definition
public Vector<Attribute> get_attributes()
// ino.end
// ino.method.get_attributes.21651.body
{ return this.attributes; }
// ino.end
// ino.method.get_key_vector.21654.definition
public Vector<Key> get_key_vector()
// ino.end
// ino.method.get_key_vector.21654.body
{ return this.key_vector; }
// ino.end
// ino.method.get_constructor_founded.21657.definition
public boolean get_constructor_founded()
// ino.end
// ino.method.get_constructor_founded.21657.body
{ return this.constructor_founded; }
// ino.end
// ino.method.get_constant_pool_element.21660.definition
public short get_constant_pool_element(byte b, String id)
// ino.end
// ino.method.get_constant_pool_element.21660.body
{ return (short)this.key_vector.indexOf(new Key(b, id)); }
// ino.end
// ino.method.get_class_block.21663.definition
public Vector<Assign> get_class_block()
// ino.end
// ino.method.get_class_block.21663.body
{ return this.class_block; }
// ino.end
// ino.method.codegen.21666.definition
public void codegen()
throws JVMCodeException
// ino.end
// ino.method.codegen.21666.body
{
try
{
codegenlog.info("Generieren der Klasse: " + class_name);
// Datei vorbereiten
2014-03-24 14:32:13 +00:00
//File file = new File(MyCompiler.getAPI().getOutputDir()
File file = new File ("/Users/pl/forschung/PIZZA+/JVM_Generics/Testfiles/"
2013-10-18 11:33:46 +00:00
+ class_name + ".class");
FileOutputStream f = new FileOutputStream(file);
// Schreiben der Header-Infos
writeInt(f, magic);
writeShort(f, minor_version);
writeShort(f, major_version);
codegenlog.debug("Header: magic=" + Integer.toHexString(magic));
codegenlog.debug("Header: minor_version=" + minor_version);
codegenlog.debug("Header: major_version=" + major_version);
codegenlog.info("Verarbeite Konstanten-Pool: " + (constant_pool.size()+1));
// Constant-Pool verarbeiten
writeShort(f, (short)(constant_pool.size() + 1));
for(int i = 0; i < constant_pool.size(); i++)
{
codegenlog.debug((i+1) +". " +
constant_pool.elementAt(i).toString());
constant_pool.elementAt(i).codegen(this, f);
}
// Informationen ueber die Klasse selbst verarbeiten
writeShort(f, access_flags);
writeShort(f, this_class);
writeShort(f, super_class);
codegenlog.debug("Klasseninfos: access_flags=" + access_flags);
codegenlog.debug("Klasseninfos: this_class=" + this_class);
codegenlog.debug("Klasseninfos: super_class=" + super_class);
// Interfaces verarbeiten
codegenlog.info("Verarbeite Interfaces: " + interfaces.size());
writeShort(f, (short)interfaces.size());
for (int i=0; i<interfaces.size(); i++) {
writeShort(f, interfaces.elementAt(i));
}
// Felder verarbeiten
codegenlog.info("Verarbeite Fields: " + fields.size());
writeShort(f, (short)fields.size());
for(int i = 0; i < fields.size(); i++)
{
fields.elementAt(i).codegen(this, f);
}
// Methodenvektor
codegenlog.info("Verarbeite Methodenliste: " + methods.size());
writeShort(f, (short)methods.size());
for(int i = 0; i < methods.size(); i++)
{
codegenlog.debug("Verarbeite Methode " + (i+1));
methods.elementAt(i).codegen(this, f);
}
// Attribut-Vektor
codegenlog.info("Verarbeite Attribute: " + attributes.size());
writeShort(f, (short)attributes.size());
for(int i = 0; i < attributes.size(); i++)
{
attributes.elementAt(i).codegen(this, f);
}
}
catch (java.io.IOException e)
{
codegenlog.fatal("Fehler beim Schreiben der ClassFile", e);
}
}
// ino.end
// ino.method.writeInt.21669.definition
public void writeInt(OutputStream f, int i)
2013-10-18 11:33:46 +00:00
throws IOException
// ino.end
// ino.method.writeInt.21669.body
{
f.write(((i >>> 24) & 255));
f.write(((i >>> 16) & 255));
f.write(((i >>> 8) & 255));
f.write((i & 255));
}
// ino.end
// ino.method.writeShort.21672.definition
public void writeShort(OutputStream f, short i)
2013-10-18 11:33:46 +00:00
throws IOException
// ino.end
// ino.method.writeShort.21672.body
{
f.write((i >>> 8) & 255);
f.write(i & 255);
}
// ino.end
// ino.method.writeByte.21675.definition
public void writeByte(OutputStream f, byte i)
2013-10-18 11:33:46 +00:00
throws IOException
// ino.end
// ino.method.writeByte.21675.body
{
f.write(i);
}
// ino.end
// ino.method.writeByteArray.21678.definition
public void writeByteArray(OutputStream f, byte[] b)
2013-10-18 11:33:46 +00:00
throws IOException
// ino.end
// ino.method.writeByteArray.21678.body
{
for(int i = 0; i < Array.getLength(b); i++) f.write(b[i]);
}
// ino.end
}
// ino.end