예제 #1
0
static void
print_array(struct mlist *mlp, struct tdesc *tdp, char *format, int level)
{
	struct ardef *ap = tdp->data.ardef;
	int items, inc;

	if (level == 0) {
		items = ap->indices->range_end - ap->indices->range_start + 1;
		inc = (mlp->size / items) / 8;
#if 0 /* { FIXME: */
		printf("#define\t%s 0x%x\n", format, mlp->offset / 8);
		printf("#define\t%s_INCR 0x%x\n", format, inc);
#endif /* } */
		printf("!\tarray %s @ 0x%x size 0x%x : element size 0x%x\n",
		    format, mlp->offset / 8, mlp->size, inc);
		switch_on_type(mlp, ap->contents, format, level);
#if 0 /* { FIXME: */
		switch (ap->contents->type) {
		case INTRINSIC:
			print_intrinsic(mlp, ap->contents, format, level);
			break;

		case POINTER:
			print_pointer(mlp, ap->contents, format, level);
			break;

		default:
			break;
		}
#endif /* } */
	}
}
예제 #2
0
int main(int argc, char *argv[]) {
    char *str_array[] = {"beijing", "shanghai", "wuhan", "xian", NULL};
    print_pointer(str_array);
    print_array(str_array);
    //========================
    pointer_run();
    return 0;
}
예제 #3
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;
  }
예제 #4
0
static void
switch_on_type(struct mlist *mlp, struct tdesc *tdp, char *format, int level)
{
	boolean_t allocated = B_FALSE;

	if (format == NULL) {
		allocated = B_TRUE;
		format = uc(mlp->name);
	}

	switch (tdp->type) {
	case INTRINSIC:
		print_intrinsic(mlp, tdp, format, level);
		break;
	case POINTER:
		print_pointer(mlp, tdp, format, level);
		break;
	case ARRAY:
		print_array(mlp, tdp, format, level);
		break;
	case FUNCTION:
		print_function(mlp, tdp, format, level);
		break;
	case UNION:
		print_union(mlp, tdp, format, level);
		break;
	case ENUM:
		print_enum(mlp, tdp, format, level);
		break;
	case FORWARD:
		print_forward(mlp, tdp, format, level);
		break;
	case TYPEOF:
		print_typeof(mlp, tdp, format, level);
		break;
	case STRUCT:
		print_struct(mlp, tdp, format, level);
		break;
	case VOLATILE:
		print_volatile(mlp, tdp, format, level);
		break;
	default:
		fprintf(stderr, "Switch to Unknown type\n");
		error = B_TRUE;
		break;
	}
	if (allocated)
		free(format);
}
예제 #5
0
파일: codegen.c 프로젝트: Neodyblue/a2c
void print_type_decl(struct type_decl *type_decl)
{
  switch (type_decl->type_def->type_type)
  {
    case enum_type:
      print_enum(type_decl->ident, type_decl->type_def->def.enum_def);
      break;
    case array_type:
      print_array(type_decl->ident, type_decl->type_def->def.array_def);
      break;
    case struct_type:
      print_record(type_decl->ident, type_decl->type_def->def.record_def);
      break;
    case pointer_type:
      print_pointer(type_decl->ident, type_decl->type_def->def.pointer_def);
      break;
    default:
      printf("type not handled yet (in print_type_decl)\n");
  }
}
예제 #6
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;
}