Exemple #1
0
/*
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;
  }
Exemple #2
0
int main(int argc, char* argv[]) {

	if(argc>1) {
		int i;
		for(i=1;i<argc;i++) {
			parse_and_print(argv[i]);
			printf("\n");
		}
	}
	else
	{
		printf("Syntax:\n");
		printf("\t%s [x-freq-uri] ...\n",argv[0]);
	}
	return 0;
}
Exemple #3
0
/*
bool
SuifPrinterModule::print_pointer(ostream& output, const PointerWrapper &obj,
				 const LString &name, 
				 int _indent,int deref = 0)
{
  return(print_pointer(output, obj.get_address(), obj.get_meta_class(),
		       name, _indent, deref));
}
*/
bool
SuifPrinterModule::print_pointer(ostream& output, 
				 const PointerWrapper &ptr_obj,
				 const LString &name, 
				 int _indent,int deref = 0)
{
  const Address what = ptr_obj.get_address();
  const PointerMetaClass* type = ptr_obj.get_meta_class();
  //output << "ptr:deref = " << deref << endl;
  int field_deref = deref ? deref-1 : 0;

  //   PointerMetaClass *p = (PointerMetaClass*) type;
  //   const Address curAddr = *(Address*) what;
  //PointerWrapper ptr_obj(what, type);
  ObjectWrapper pobj = ptr_obj.get_object();

  ObjectWrapper base_obj = ptr_obj.dereference();
  //   suif_assert(base_obj.get_meta_class() ==
  //	       ptr_obj.get_meta_class()->get_base_type()->get_meta_class(*(Address*) what));

   
  if (!print_all())
    if (base_obj.is_null())
      return false;



  String name_with_addr = String("*") + name;
  //   LString new_name = "*";
  //   LString new_name_str = new_name + name;
  char addr_str[256];
  sprintf(addr_str, " <%p>", base_obj.get_address());
  //   String name_with_addr = new_name_str + addr_str;
  name_with_addr += addr_str;

  if (base_obj.is_null())
    {
      output << type->get_instance_name();
      output << '(' << type->get_meta_class_id() << ")";
      if (name)
	output << ' ' << name << ' ';
      output << " = NULL;";
      return true;
    }

  /*
   * for the "print_all" style
   */
  if (print_all()) 
    {
      if (ptr_obj.get_meta_class()->is_owning_pointer()) 
	{
	  output << type->get_instance_name();
	  output << '(' << type->get_meta_class_id() << ")";
	  output << '<' << what << '>';
	  print2(output, base_obj, emptyLString, _indent, field_deref);
	} else {
	  if (deref) {
	    output << name_with_addr <<":";
	  } else {
	    output << type->get_instance_name();
	    output << ' ' << name_with_addr;
	    output << " (ref)";
	  }
	}
      return true;
    }

  /*
   * This is the short printing
   */
  if (ptr_obj.get_meta_class()->is_owning_pointer()) 
    {
      if (!base_obj.is_null()) 
	{
	  if (!print_all())
	    print2(output, base_obj,
		   name_with_addr, _indent, field_deref);
	  else {
	    output << base_obj.get_meta_class()->get_instance_name();
	    output << '(' << type->get_meta_class_id() << ")";
	    output << '<' << what << '>';
	    print2(output, base_obj, emptyLString, _indent, field_deref);
	  }
	}
    } else {
      //      MetaClassId id = baseType->get_meta_class_id();
      String ref_str = 
	get_print_ref_string(base_obj.get_meta_class()->get_instance_name());

      //ObjectWrapper obj(what, baseType);
      if (has_tag(pobj))
	{
	  size_t ref = get_tag(pobj);
	  output << "@t" << ref;
	  if (use_print_ref_string() && ref_str != emptyString) {
            output<<':';
            return parse_and_print(output, base_obj, emptyLString, ref_str,
                                   _indent, field_deref);
	  }
	}
      else 
	{
	  //ObjectWrapper obj(curAddr, baseType);
	  if (has_tag(base_obj))
	    {
	      size_t ref = get_tag(base_obj);
	      output << "@t" << ref;
	      if (use_print_ref_string() && ref_str != emptyString) 
		{
		  output<<':';
		  return parse_and_print(output, base_obj, emptyLString, 
					 ref_str,
					 _indent, field_deref);
		}
	    }
	  else 
	    {
	      // No tag on the Pointer or the Object.
	      // Here see if there should have been a tag but just hasn't been
	      // seen yet. If so, we can declare one now which will be used later.
	      if (use_print_ref_string() && ref_str != emptyString) 
		{
		  //ObjectWrapper obj(curAddr, baseType);
		  size_t ref = retrieve_tag(base_obj);
		  output << "@t" << ref;
		  output <<':';
		  return parse_and_print(output, base_obj,
					 emptyLString, ref_str,
					 _indent, field_deref);
		}
	      else
		{
		  output << type->get_instance_name();
		  output << ' ' << name_with_addr;
		  output << " (ref)";
		}
	    }
	}
    }
  return true;
}