static const char *NAME("operand"); //===========================// //== This software is ==// //== (c)opyrighted in 1993 ==// //== by Chris Koeritz ==// //== cak0l@Virginia.EDU ==// //===========================// #include "operand.h" #include "guards.h" #include "basics.h" #include operand::~operand() { am_i_modified = UNSET; } operand::operand() { am_i_modified = UNSET; } string operand::type_name() const { return my_type_name; } void operand::type_name(const string &type_name) { my_type_name = type_name; } string operand::name() const { return my_name; } void operand::name(const string &name) { my_name = name; } operand::modification_types operand::modifies() const { return am_i_modified; } void operand::modifies(modification_types new_modifies) { am_i_modified = new_modifies; } int operand::well_formed() const { if (!(char *)my_type_name) return FALSE; // guarantee 1. // guarantee 2 is vacuously true. if ( (am_i_modified != DOES_MODIFY) && (am_i_modified != DOES_NOT_MODIFY) ) return FALSE; // guarantee 3. } /* byte *operand::pack(int &size) const { if (!well_formed()) deadly_error(NAME, "pack", "operand is not well formed."); int packed_name_size = operand_name.length() + 1; int packed_type_size = my_type_name.length() + 1; size = packed_name_size + packed_type_size + 2 * sizeof(int); byte *to_return = new byte[size]; typed_copy(&packed_name_size, to_return, int); int temp = am_i_modified; typed_copy(&temp, to_return + sizeof(int), int); byte *stuff_place = to_return + 2 * sizeof(int); mcopy((char *)operand_name, stuff_place, packed_name_size); stuff_place += packed_name_size; mcopy((char *)my_type_name, stuff_place, packed_type_size); return to_return; } operand *unpack_operand(byte *packed_operand) { operand *to_return = new operand; int packed_name_size; typed_copy(packed_operand, &packed_name_size, int); typed_copy(packed_operand, &to_return->am_i_modified, int); byte *stuffed_place = packed_operand + 2 * sizeof(int); string opname((char *)stuffed_place); to_return->operand_name = opname; stuffed_place += packed_name_size; string optyp((char *)stuffed_place); to_return->my_type_name = optyp; if (!to_return->well_formed()) deadly_error(NAME, "unpack_opnd", "constructed operand is not well formed."); return to_return; } */ void operand::print() const { cout << "[ operand has type=" << type_name() << " and name=" << name() << endl << flush; cout << " operand is " << ( (am_i_modified==UNSET) ? "not set yet..." : ( (am_i_modified==DOES_NOT_MODIFY)? "not modifiable." : "modifiable.")) << "]\n" << flush; }