89 using namespace r_code;
 
   93 const char *Class::Expression = 
"xpr";
 
   94 const char *Class::Type = 
"type";
 
   96 bool Class::has_offset()
 const {
 
   98   switch (atom_.getDescriptor()) {
 
  101   case Atom::INSTANTIATED_PROGRAM:
 
  102   case Atom::INSTANTIATED_CPP_PROGRAM:
 
  104   case Atom::MARKER: 
return true;
 
  105   default: 
return false;
 
  109 Class::Class(ReturnType t) : type(t), str_opcode(
"undefined") {
 
  112 Class::Class(
Atom atom,
 
  113   std::string str_opcode,
 
  114   vector<StructureMember> r,
 
  115   ReturnType t) : atom_(atom),
 
  116   str_opcode(str_opcode),
 
  119   use_as(StructureMember::I_CLASS) {
 
  122 bool Class::is_pattern(Metadata *metadata)
 const {
 
  124   return (metadata->classes_.find(
"ptn")->second.atom_ == atom_) || (metadata->classes_.find(
"|ptn")->second.atom_ == atom_);
 
  127 bool Class::is_fact(Metadata *metadata)
 const {
 
  129   return (metadata->classes_.find(
"fact")->second.atom_ == atom_) || (metadata->classes_.find(
"|fact")->second.atom_ == atom_);
 
  132 bool Class::get_member_index(Metadata *metadata, std::string &name, uint16 &index, Class *&p)
 const {
 
  134   for (uint16 i = 0; i < things_to_read.size(); ++i)
 
  135     if (things_to_read[i].name_ == name) {
 
  137       index = (has_offset() ? i + 1 : i); 
 
  138       if (things_to_read[i].used_as_expression()) 
 
  141         p = things_to_read[i].get_class(metadata);
 
  147 std::string Class::get_member_name(uint32 index) {
 
  149   return things_to_read[has_offset() ? index - 1 : index].name_;
 
  152 ReturnType Class::get_member_type(
const uint16 index) {
 
  154   return things_to_read[has_offset() ? index - 1 : index].get_return_type();
 
  157 Class *Class::get_member_class(Metadata *metadata, 
const std::string &name) {
 
  159   for (uint16 i = 0; i < things_to_read.size(); ++i)
 
  160     if (things_to_read[i].name_ == name)
 
  161       return things_to_read[i].get_class(metadata);
 
  165 void Class::write(word32 *storage) {
 
  167   storage[0] = atom_.atom_;
 
  168   r_code::Write(storage + 1, str_opcode);
 
  169   uint32 offset = 1 + r_code::GetSize(str_opcode);
 
  170   storage[offset++] = type;
 
  171   storage[offset++] = use_as;
 
  172   storage[offset++] = things_to_read.size();
 
  173   for (uint32 i = 0; i < things_to_read.size(); ++i) {
 
  175     things_to_read[i].write(storage + offset);
 
  176     offset += things_to_read[i].get_size();
 
  180 void Class::read(word32 *storage) {
 
  183   r_code::Read(storage + 1, str_opcode);
 
  184   uint32 offset = 1 + r_code::GetSize(str_opcode);
 
  185   type = (ReturnType)storage[offset++];
 
  186   use_as = (StructureMember::Iteration)storage[offset++];
 
  187   uint32 member_count = storage[offset++];
 
  188   for (uint32 i = 0; i < member_count; ++i) {
 
  191     m.read(storage + offset);
 
  192     things_to_read.push_back(m);
 
  193     offset += m.get_size();
 
  197 uint32 Class::get_size() { 
 
  200   size += r_code::GetSize(str_opcode);
 
  201   for (uint32 i = 0; i < things_to_read.size(); ++i)
 
  202     size += things_to_read[i].get_size();