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

ClassEncoder::code_attribute Class Reference

A code attribute. More...

#include <code_attribute.hpp>

Inheritance diagram for ClassEncoder::code_attribute:

Inheritance graph
[legend]
Collaboration diagram for ClassEncoder::code_attribute:

Collaboration graph
[legend]
List of all members.

Public Member Functions

 code_attribute (ConstantPool *pool)
 Standard constructor.

virtual ~code_attribute ()
 Default destructor.

virtual void write (std::ofstream &stream)
 Write contents to class stream.

virtual unsigned int size ()
 Compute size.

ByteCodecode ()
 Get the bytecode object.

unsigned int addLocal ()
 Add a local variable.


Private Member Functions

 code_attribute ()
 Default constructor.


Private Attributes

ConstantPoolConstantPoolEntries
ByteCodeCode
u2 max_locals

Detailed Description

A code attribute.

This class represents a code attribute used by the method_info class as defined by the SUN documentation: http://java.sun.com/docs/books/vmspec/2nd-edition/html/ClassFile.doc.html#1546 It is responsible for holding the code for one method and information about this code such as the maximum number of locals and the maximum stack size.

Definition at line 27 of file code_attribute.hpp.


Constructor & Destructor Documentation

ClassEncoder::code_attribute::code_attribute ConstantPool pool  ) 
 

Standard constructor.

Creates the ByteCode entry initialises the other variables and sets our name to Code via attribute_info::setNameIndex.

Parameters:
pool Pointer to the constant pool of the class this code_attribute belongs to.
See also:
attribute_info::setNameIndex

Definition at line 23 of file code_attribute.cpp.

References ClassEncoder::attribute_info::setNameIndex().

ClassEncoder::code_attribute::~code_attribute  )  [virtual]
 

Default destructor.

Delete the ByteCode entry located in the constructor.

Definition at line 36 of file code_attribute.cpp.

ClassEncoder::code_attribute::code_attribute  )  [inline, private]
 

Default constructor.

Should never be used and is therefore private.

Definition at line 60 of file code_attribute.hpp.


Member Function Documentation

unsigned int ClassEncoder::code_attribute::addLocal  )  [inline]
 

Add a local variable.

A single local variable can hold a value of type boolean, byte, char, short, int, float, reference, or returnAddress. A pair of local variables can hold a value of type long or double.

Local variables are addressed by indexing. The index of the first local variable is zero. An integer is be considered to be an index into the local variable array if and only if that integer is between zero and one less than the size of the local variable array.

Returns:
The variable index. Note: The JVM variable index is one less than the number of locals since indexing starts at 0.

Definition at line 53 of file code_attribute.hpp.

Referenced by ClassEncoder::method_info::addLocal(), and ClassEncoder::method_info::addParameter().

ByteCode* ClassEncoder::code_attribute::code  )  [inline]
 

Get the bytecode object.

This function returns a pointer to the bytecode object. This object is used to manipulate the code for this code_attribute.

Returns:
Pointer to the ByteCode object.

Definition at line 40 of file code_attribute.hpp.

Referenced by ClassEncoder::method_info::code().

unsigned int ClassEncoder::code_attribute::size  )  [virtual]
 

Compute size.

Computes the total number of bytes the elements of the code_attribute use. This corresponds to 2 + 2 + 4 + the size of the code + 2 + 2.

Implements ClassEncoder::attribute_info.

Definition at line 71 of file code_attribute.cpp.

References ClassEncoder::ByteCode::nextInstrAddr().

void ClassEncoder::code_attribute::write std::ofstream &  stream  )  [virtual]
 

Write contents to class stream.

Writes the contents of this attribute to the class stream.

Parameters:
stream The class stream to write to.

Reimplemented from ClassEncoder::attribute_info.

Definition at line 46 of file code_attribute.cpp.

References ClassEncoder::ByteCode::maxStackSize(), ClassEncoder::ByteCode::nextInstrAddr(), ClassEncoder::ByteCode::write(), ClassEncoder::ClassWriterBase::writeu2(), and ClassEncoder::ClassWriterBase::writeu4().

Referenced by ClassEncoder::method_info::write().


The documentation for this class was generated from the following files:
Generated on Mon Dec 1 14:26:30 2003 for Ck by doxygen 1.3.3