예제 #1
0
파일: suifprinter.cpp 프로젝트: jrk/suif2
/*
bool
SuifPrinterModule::print2(ostream& output, const ObjectWrapper &obj,
			  const LString &name, int _indent, int deref)
{
  return(print2(output, obj.get_address(), obj.get_meta_class(),
		name, _indent, deref));
}
*/
bool
//SuifPrinterModule::print2(ostream& output, const Address what, const MetaClass* type,
//       //const LString &name = emptyLString, int _indent = 2, int deref = 0)
//       const LString &name, int _indent, int deref)
SuifPrinterModule::print2(ostream& output, const ObjectWrapper &obj,
			  const LString &name, int _indent, int deref)
{
  if (!start_of_object(output,obj,deref)) {
      return false;
      }
  //  MetaClassId id = type->get_meta_class_id();
  String str = get_print_string(obj.get_meta_class()->get_instance_name());

  // This is NOT always a suifobject.  It is only
  // a suifobject if the metaclass is a child of the SuifObject metaclass.
  SuifObject *o = NULL;
  if (is_kind_of_suif_object_meta_class(obj.get_meta_class())) {
    o = (SuifObject *) obj.get_address(); 
    }

  // length is at least 1 (for the \0 at the end)
  //output << "p2:deref = " << deref << endl;
  if (use_print_string() && str != emptyString) {
     bool b = parse_and_print(output, obj, name, str, _indent, deref);
     end_of_object(output,obj);
     return b;
     }

  // No print string registered.
  const MetaClass *type = obj.get_meta_class();
  bool b = false;
  if (type->is_elementary()) {
     b =  print_elementary(output, obj, name, _indent, deref);
     }
  else if (type->isKindOf(AggregateMetaClass::get_class_name())) {
     b = print_aggregate(output, 
			      AggregateWrapper(obj),
			      name, _indent, deref);
     }  
  else if (type->isKindOf(PointerMetaClass::get_class_name())) {
     b = print_pointer(output, 
			    PointerWrapper(obj),
			    name, _indent, deref);
     }  
  else if (type->isKindOf(ListMetaClass::get_class_name())) {
     b = print_list(output, obj, name, _indent, deref);
     }  
  else if (type->isKindOf(STLMetaClass::get_class_name())) {
     b = print_stl(output, obj, name, _indent, deref);
     }  
  else {
     b = print_catchall(output, obj, name, _indent, deref);
     }
  end_of_object(output,obj);
  return b;
  }
예제 #2
0
void PointerMetaClass::initialize( const ObjectWrapper &obj,
				   InputStream* inputStream ) const {
  Address address = obj.get_address(); 
  kernel_assert(obj.get_meta_class() == this);

   // debugit("initializing pointer ",address);
  if ( _pre_init ) {
    _pre_init( obj, true, inputStream );
  }
  Address objectAddress =  *(Address*)address;


  // test for whether it's already there
  if ( _is_static ||
       (  _pointer_owns_object && inputStream->exists_in_input_stream( objectAddress ) &&
          (!inputStream->was_already_visited( objectAddress ) ) ) ) {
    if ( !_is_static ) {
      inputStream->set_already_visited( objectAddress );
    }
    const MetaClass *mc = 
      get_base_type()->get_meta_class( (Byte*)objectAddress );
    mc->initialize( ObjectWrapper(*(Address*)address, mc), inputStream );
  }
  if ( _post_init ) {
    _post_init( obj, true, inputStream );
  }
}
예제 #3
0
PointerWrapper::PointerWrapper(const ObjectWrapper &obj) :
  _meta_class(NULL), _address(0)
{
  kernel_assert_message(is_pointer(obj), 
			("Attempt to pointer object with non-pointer"));
  _meta_class = to<PointerMetaClass>(obj.get_meta_class());
  _address = obj.get_address();
}
예제 #4
0
void STLMetaClass::destruct( const ObjectWrapper &obj,
			     bool called_from_destructor ) const {
  kernel_assert(obj.get_meta_class() == this);
  // an stl object is never destroyed from the destructor
  kernel_assert( !called_from_destructor );

  _stl_descriptor->get_destructor_function()( obj );
}
예제 #5
0
파일: cprint_style.cpp 프로젝트: jrk/suif2
void CPrintStyleModule::print_dispatch(Module *module,
				       ostream &str,
				       const ObjectWrapper &obj)
{
  CPrintStyleModule *pm = (CPrintStyleModule*)module;
  String result;
  if (is_kind_of_suif_object_meta_class(obj.get_meta_class())) {
    result = pm->print_to_string((const SuifObject*)obj.get_address());
  }
  str << result.c_str();
}
예제 #6
0
void PointerMetaClass::destruct( const ObjectWrapper &obj,
				 bool called_from_destructor ) const {
  Address address = obj.get_address();
  kernel_assert(obj.get_meta_class() == this);

  // is never called from a destructor
  kernel_assert( !called_from_destructor );

  if ( _pointer_owns_object ) {
    Address object_address = *(Address*)address;
    if ( object_address ) {
      const MetaClass *mc = _base_type -> get_meta_class( object_address );
      mc-> destruct( ObjectWrapper(object_address, mc), false );
      delete (char*)object_address;
      *(Address*)address = 0; // just to be nice
    }
  }
}
예제 #7
0
파일: suifprinter.cpp 프로젝트: jrk/suif2
//----------------------------------------------------------------------------
//----------------------------------------------------------------------------
bool
SuifPrinterModule::print_catchall(ostream& output, 
				  const ObjectWrapper &obj,
				  const LString &name, 
				  int _indent,int deref = 0)
{
  const Address what = obj.get_address();
  const MetaClass* type = obj.get_meta_class(); 
   int field_deref = deref?deref-1:0;
   output << type->get_instance_name()
              << '(' << type->get_meta_class_id() << ") ";
   if (name)
         output << ' ' << name << ' ';
   output << " (un-implemented) ";
   Iterator* it = type->get_iterator(what);
   if (it) {
     if (it->current()) {
       //output << "{\n";
       output << endl;
       //while (it->is_valid()) {
       for (; it->is_valid(); it->next())
	 {
	   ObjectWrapper obj(it->current(), it->current_meta_class());
	   //		const MetaClass* currentMetaClass = it->current_meta_class();
	   //                 const Address curAddr = it->current();
	   if(!obj.is_null()) {
	     //                 if (curAddr) {
	     indent(output, _indent+istep);
	     print2(output, obj, it->current_name(), 
		    _indent+istep, field_deref);
	   }
	   //		it->next();
	   //}
	 }// while (it->is_valid());
       indent(output, _indent);
       //output << "}\n";
     }
         else
            output <<" {0x0}\n";
   }
   if (it) delete it;
   return true;
}
예제 #8
0
void UnionMetaClass::initialize( const ObjectWrapper &obj,
				 InputStream* inputStream ) const {
  Address address = obj.get_address();
  kernel_assert(obj.get_meta_class() == this);
 
  // debugit("initializing union ",address);
  AggregateWrapper agg_obj(address, this);
  AggregateMetaClass::initialize( obj, inputStream );
  int index = get_tag_num( address );
  if (index < 0)
    zero_field(address);
  else {
    FieldDescription* field_description = (*_union_fields)[ index ];
    ObjectWrapper field = field_description->build_object(agg_obj);

    //Address instance_address = (Address)( ( (Byte*)address ) + field_description->offset );
    field.initialize(inputStream);
    //    field_description->get_meta_class()->initialize( field.get_address() ,inputStream );
    }
}
예제 #9
0
void UnionMetaClass::write( const ObjectWrapper &obj,
			    OutputStream* outputStream ) const {
  Address instance = obj.get_address();
  kernel_assert(obj.get_meta_class() == this);

  AggregateWrapper agg_obj(instance, this);
  AggregateMetaClass::write( obj, outputStream );

  int index = get_tag_num( instance );
  // if the tag number is not stored in a field that was already
  // written out => write out the tag number
  if ( _tag_offset == -1 ) {
    outputStream->write_unsigned_int( index );
  }

  if ( index >= 0 ) {
    FieldDescription* field_description = (*_union_fields)[ index ];
    ObjectWrapper field = field_description->build_object(agg_obj);
    outputStream->write( field, false );
  }
}
예제 #10
0
void PointerMetaClass::read( const ObjectWrapper &obj,
			     InputStream* inputStream ) const {
    Address instance = obj.get_address();
    kernel_assert(obj.get_meta_class() == this);
    PointerWrapper ptr_obj(instance, this);

    if (_needs_cloning) {
	inputStream->read_defining_pointer( ptr_obj );
        }
    else if ( _pointer_owns_object ) {
    	if ( _is_static ) {
	    inputStream->read_static_pointer( ptr_obj );
    	    } 
	else {
      	    inputStream->read_owning_pointer( ptr_obj );
    	    }
  	} 
    else {
    	inputStream->read_reference( ptr_obj );
  	}
    }
예제 #11
0
void UnionMetaClass::read( const ObjectWrapper &obj,
			   InputStream* inputStream ) const {
  Address instance = obj.get_address();
  kernel_assert(obj.get_meta_class() == this);

  AggregateWrapper agg_obj(instance, this);
  AggregateMetaClass::read( obj, inputStream );
  int index;
  if ( _tag_offset != -1 ) {
    index = *(int *) ((Byte*)instance + _tag_offset);
  } else {
    index = inputStream->read_unsigned_int();
  }
  if ( index >= 0 ) {
    FieldDescription* field_description = (*_union_fields)[ index ];
    ObjectWrapper field = field_description->build_object(agg_obj);

    inputStream->read( field, false );
  } else { // works for now as only Union is a Union of pointers
    zero_field(instance);
  }
}
예제 #12
0
파일: object.cpp 프로젝트: jrk/suif2
Address Object::get_member( const LString& name,
                            Address& return_address,
                            const MetaClass*&  return_meta_class ) const {
  kernel_assert_message( _meta_class, ("Empty MetaClass") );

  FieldDescription* field_description = 
    _meta_class->get_field_description( (void*)address,  name );
  if ( field_description ) {
    //    return_address = ((const Object *)this) + field_description->offset;
    AggregateWrapper agg_obj((Address)this, _meta_class);
    ObjectWrapper obj = field_description->build_object(agg_obj);
    obj = obj.update_meta_class();
    return_address = obj.get_address();
    return_meta_class = obj.get_meta_class();
    //return_address = ((Byte*)this) + field_description->offset;
    //    return_meta_class = field_description->
    //                           metaClass->get_meta_class( return_address );
  } else {
    return_address = 0;
    return_meta_class = 0;
  }
  return return_address;
}
예제 #13
0
파일: suifprinter.cpp 프로젝트: jrk/suif2
//----------------------------------------------------------------------------
//----------------------------------------------------------------------------
bool
SuifPrinterModule::print_elementary(ostream& output, 
				    const ObjectWrapper &obj,
				    const LString &name, 
				    int _indent,int deref = 0)
{
  const Address what = obj.get_address();
  const MetaClass* type = obj.get_meta_class();
  //output << "elem:deref = " << deref << endl;
  if (!deref) {
    output << type->get_instance_name()
	   << '(' << type->get_meta_class_id() << ')';
    if (name)
      output << ' ' << name << ' ';
  }
  if (what) {
    if (type->isKindOf("String"))
      output <<'[' << *(String*)what <<"] ";
    else
      output <<'[' << *(int*)what <<"] ";
  }
  return true;
}
예제 #14
0
파일: suifprinter.cpp 프로젝트: jrk/suif2
bool
SuifPrinterModule::parse_and_print(ostream& output, const ObjectWrapper &obj,
				   const LString &name, const String &str, 
				   int _indent, int deref = 0)
{
  const Address what = obj.get_address();
  const MetaClass *type = obj.get_meta_class();
  //  ObjectWrapper obj(what, type);
  //output << "str:deref = " << deref << endl;
  int l_sep = list_separator;
  if (str.length() == 0) {
    return false;
  }
  if (deref)
    _indent -= istep;
  int str_length = str.length();
  bool need_indent = false;
  bool first_field = true;
  for (int i = 0; i < str_length; ++i) {
    if (str[i] != '%') {
      // If there are less than 2 extra stars don't print anything but the
      // fields.
      if (deref < 2) {
	// Need to check for \n and take care of indentation here
	switch(str[i]) {
	case '\n':
	  output << str[i];
	  if (str[i+1]) {
	    need_indent = true;
	    indent(output, _indent);
	  }
	  break;
	case '\t': indent(output, istep); break;
	case '\b': _indent -= istep; break;
	default: output << str[i];
	}
      }
    }
    else {
      ++i;
      if (str[i] == '%') {
	// Double % means print out a '%'
	output << '%';
      }
      else {
	// This has to be cleaned up a bit ...
	//int field_deref = deref?deref-1:0;
	int field_deref = 0;
	char buff[256];
	int j = 0;
	char c = str[i++];
	if (c == '*') {
	  ++field_deref;
	  while ((c = str[i++]) == '*')
	    ++ field_deref;
	}
	while (isalnum(c) || c == '_') {
	  buff[j++] = c;
	  c = str[i++];
	}
	i -= 2;
	buff[j] = 0;
	// Now retrieve the particular field and print it.
	if (!strcmp(buff, "Cl")) {
	  output << type->get_instance_name() << '('
		 << type->get_meta_class_id() << ") ";
	}
	else if (!strcmp(buff, "ii")) { // Deal with printing IInteger
	  IInteger *ii = (IInteger *)what;
	  output << ii->to_String().c_str();
	}
	else if (!strcmp(buff, "i")) { // Deal with printing int
	  output << *(int*)what;
	}
	else if (!strcmp(buff, "f")) { // float
	  output << *(float*)what;
	}
	else if (!strcmp(buff, "d")) { // double
	  output << *(double*)what;
	}
	else if (!strcmp(buff, "c")) { // char
	  output << *(char*)what;
	}
	else if (!strcmp(buff, "b")) { // byte
	  output << (int)*(char*)what;
	}
	else if (!strcmp(buff, "B")) { // bool
	  output << *(bool*)what;
	}
	else if (!strcmp(buff, "ls")) { // Deal with printing LStrings
	  LString str = *(LString*) what;
	  output << str;
	}
	else if (!strcmp(buff, "s")) { // Deal with printing Strings
	  String str = *(String*) what;
	  output << str;
	}
	else if (!strcmp(buff, "n")) { // Deal with name of field
	  if (!deref)
	    output << name;
	}
	else if (!strcmp(buff, "P")) {
	  if (obj.is_null())
	    output << "NULL";
	  else {
	    PointerWrapper ptr_obj(obj);
	    ObjectWrapper base_obj = ptr_obj.dereference();
	    if (ptr_obj.get_meta_class()->is_owning_pointer()) {
	      size_t ref = retrieve_tag(obj.get_object());
	      output << "t" << ref<< ": ";
	      print2(output, base_obj, emptyLString, 
		     _indent+istep, field_deref);
	    }
	    else {
	      print_pointer(output, ptr_obj, emptyLString, _indent, deref);
	    }
	  }
	}
	else if (!strcmp(buff, "R")) { // print the ref #
	  if (!what)
	    output << "NULL";
	  else {
	    //  PointerMetaClass *p = (PointerMetaClass*) type;
	    //  const Address baseAddr = *(Address*) type;
	    //ObjectWrapper obj(what, type);
	    size_t ref = retrieve_tag(obj);
	    output << "t" << ref<< ": ";
	  }
	}
	else if (!strcmp(buff, "LS")) {
	  list_separator = ' ';
	}
	else if (!strcmp(buff, "LN")) {
	  list_separator = '\n';
	}
	else if (!strcmp(buff, "LC")) {
	  list_separator = ',';
	}
	else if (!strcmp(buff, "ANNOTES")) {
	  // Special CASE for handling ANNOTATIONS
	  AggregateWrapper agg(obj);
	  LString field_name("_annotes");
	  FieldDescription *f = agg.get_field_description(field_name);
	  if (!f)
	    cerr << type->get_meta_class(what)->get_class_name()
		 << ":No field '" << field_name << "' found to print!!!\n";
	  else {
	    // Now we need to get the field offset and increment 'what'
	    if (field_deref != 0)
	      cerr << "Extra '*' for %ANNOTES\n";
	    FieldWrapper field = agg.get_field(field_name);
	    if (need_indent) {
	      indent(output, istep);
	      need_indent = false;
	    }
	    char old_sep = list_separator;
	    list_separator = '\n';
	    print2(output, 
		   field.get_object(),
		   field_name, _indent+istep,
		   1);
	    list_separator = old_sep;
	  }
	}
	else if (j) {
	  // Retrieve the field mentioned
	  // The following cast works as we should reach here only if it
	  // is not an elementary or pointer type.
	  AggregateWrapper agg(obj);
	  char *bf = buff;
	  LString field_name(bf);
	  FieldDescription *f = agg.get_field_description(field_name);
	  if (!f)
	    cerr << type->get_meta_class(what)->get_class_name()
		 << ":No field '" << field_name << "' found to print!!!\n";
	  else {
	    // Now we need to get the field offset and increment 'what'
	    if (deref)
	      if (!first_field) output << ' ';
	      else first_field = false;
	    FieldWrapper field = agg.get_field(field_name);
	    //char *f_add = (char*)what + f->get_offset();
	    //indent(output, _indent+istep);
	    if (need_indent) {
	      indent(output, istep);
	      need_indent = false;
	    }
	    if (deref && !field_deref)
	      field_deref = deref - 1;
	    //output << "\tstr:field_deref = " << field_deref << endl;
	    print2(output, 
		   field.get_object(),
		   field_name, _indent+istep,
		   field_deref);
	  }
	}
      }
    }
  }
  list_separator = l_sep;
  return true;
}
예제 #15
0
파일: suifprinter.cpp 프로젝트: jrk/suif2
//----------------------------------------------------------------------------
//----------------------------------------------------------------------------
bool
SuifPrinterModule::print_list(ostream& output, 
			      const ObjectWrapper &obj,
			      const LString &name, 
			      int _indent, int deref = 0)
{
  const Address what = obj.get_address();
  const MetaClass* type = obj.get_meta_class(); 
  //output << "list:deref = " << deref << endl;
  int l_sep = list_separator;
  int field_deref = deref?deref-1:0;
  ListMetaClass *p = (ListMetaClass*) type;
  ListIterator* it = (ListIterator*) p->get_iterator(what);
  //  bool verbose_list = false;
  if (!print_all() && !it->is_valid()) {
      if (list_separator != '\n')
	output << "<None>";
    return true;
  }
  size_t length = it->length();
  if (!deref) {
    if (print_all()) {
      output << type->get_instance_name()
	     << '(' << type->get_meta_class_id() << ") ";
      if (name)
	output << ' ' << name << ' ';
    }
    else // if (length != 1)
      {
	output <<"list ";
	if (name)
	  output << ' ' << name << ' ';
      }
  }
  else if (_indent > 0)
    _indent -= istep;
  {
    if (print_all())
      output << '[' << length << "]:";
    if (it->current()) {
      int num_elts = 0;
      bool last_printed = true;
      bool nl_needed = false;
      if (deref && length == 1)
	last_printed = false;
      else {
	//output << endl;
      }
      //output << '{';
      //indent(output, istep);
      //while (it->is_valid()) {
      for (; it->is_valid();  it->next())
	{
	  list_separator = l_sep;
	  ObjectWrapper element(it->current(),
				it->current_meta_class());
	  //	    const MetaClass* currentMetaClass = it->current_meta_class();
	  //	    const Address curAddr = it->current();
	  if (!element.is_null()) {
	    //	    if (curAddr) {
	    if (last_printed &&
		nl_needed) {
	      output << (char)list_separator;
	      if (list_separator != ' ') {
		if (list_separator == '\n')
		  indent(output, _indent+istep);
		else if (list_separator == ',')
		  output << ' ';
	      }
	    }
	    char buff[100] = { 0 };
	    if (print_all())
	      sprintf(buff,"[%d]", num_elts++);
	    last_printed = print2(output, element,
				  buff, _indent+istep, field_deref);
	    nl_needed = last_printed;
	  }
	}
      if (last_printed &&
	  nl_needed) {
	if (list_separator == '\n') {
	  output << (char)list_separator;
	  indent(output, _indent+istep);
	}
      }
    } else
      output <<" {0x0} ";
  }
  delete it;
  list_separator = l_sep;
  return true;
}
예제 #16
0
bool PointerWrapper::is_pointer(const ObjectWrapper &obj) {
  const MetaClass *mc = obj.get_meta_class();
  return(is_kind_of<PointerMetaClass>(mc));
}
예제 #17
0
파일: suifprinter.cpp 프로젝트: jrk/suif2
void
SuifPrinterModule::print(ostream& output, const ObjectWrapper &obj)
{
  print(output, obj.get_address(), obj.get_meta_class(), 0);
}