Main Page | Class Hierarchy | Compound List | File List | Compound Members | File Members | Related Pages

code_attribute.cpp

00001 /*
00002  * Copyright (c) 2003, Raymond Bosman
00003  * Copyright (c) 2003, Frederik Holljen
00004  * All Rights Reserved.
00005  *
00006  * See COPYING for licensing.
00007  */
00008 
00009 
00010 #include "code_attribute.hpp"
00011 #include "class.hpp"
00012 
00013 namespace ClassEncoder
00014 {
00015 using namespace std;
00016 
00018 
00023 code_attribute::code_attribute( ConstantPool *pool )
00024 {
00025     Code = new ByteCode( pool );
00026     max_locals = 0;
00027     ConstantPoolEntries = pool;
00028     // add self description
00029     setNameIndex( pool->add( new Utf8_info( "Code" ) ) );
00030 }
00031 
00033 
00036 code_attribute::~code_attribute()
00037 {
00038     if( Code ) delete Code;
00039 }
00040 
00042 
00046 void code_attribute::write( ofstream &stream )
00047 {
00048     attribute_info::write( stream );
00049 // u2 max_stack;
00050     writeu2( stream, Code->maxStackSize() );
00051 // u2 max_locals;
00052     writeu2( stream, max_locals );
00053 // u4 code_length;
00054     writeu4( stream, Code->nextInstrAddr() );
00055 // u1 code[code_length];
00056     Code->write( stream );
00057 
00058 // u2 exception_table_length;
00059 //   exception_table[exception_table_length];
00060     writeu2( stream, 0 );
00061 // u2 attributes_count;
00062 // attribute_info attributes[attribute_count];
00063     writeu2( stream, 0 );
00064 }
00065 
00067 
00071 unsigned int code_attribute::size()
00072 {
00073     return 2 + 2 + 4 + Code->nextInstrAddr() + 2 + 2;
00074 }
00075 
00076 } // end namespace

Generated on Mon Dec 1 14:26:27 2003 for Ck by doxygen 1.3.3