772 {&bad_ctype, "bad"},
773 {&null_ctype, "null"},
774 };
775
776 static const char *base_type_str(struct symbol *sym)
777 {
778 int i;
779
780 for (i = 0; i < ARRAY_SIZE(base_types); i++) {
781 if (sym == base_types[i].sym)
782 return base_types[i].name;
783 }
784 return "<unknown>";
785 }
786
787 static int type_str_helper(char *buf, int size, struct symbol *type)
788 {
789 int n;
790
791 if (!type)
792 return snprintf(buf, size, "<unknown>");
793
794 if (type->type == SYM_BASETYPE) {
795 return snprintf(buf, size, "%s", base_type_str(type));
796 } else if (type->type == SYM_PTR) {
797 type = get_real_base_type(type);
798 n = type_str_helper(buf, size, type);
799 if (n > size)
800 return n;
801 return n + snprintf(buf + n, size - n, "*");
802 } else if (type->type == SYM_ARRAY) {
803 type = get_real_base_type(type);
804 n = type_str_helper(buf, size, type);
805 if (n > size)
806 return n;
807 return n + snprintf(buf + n, size - n, "[]");
808 } else if (type->type == SYM_STRUCT) {
809 return snprintf(buf, size, "struct %s", type->ident ? type->ident->name : "");
810 } else if (type->type == SYM_UNION) {
811 if (type->ident)
812 return snprintf(buf, size, "union %s", type->ident->name);
|
772 {&bad_ctype, "bad"},
773 {&null_ctype, "null"},
774 };
775
776 static const char *base_type_str(struct symbol *sym)
777 {
778 int i;
779
780 for (i = 0; i < ARRAY_SIZE(base_types); i++) {
781 if (sym == base_types[i].sym)
782 return base_types[i].name;
783 }
784 return "<unknown>";
785 }
786
787 static int type_str_helper(char *buf, int size, struct symbol *type)
788 {
789 int n;
790
791 if (!type)
792 return snprintf(buf, size, "<null type>");
793
794 if (type->type == SYM_BASETYPE) {
795 return snprintf(buf, size, "%s", base_type_str(type));
796 } else if (type->type == SYM_PTR) {
797 type = get_real_base_type(type);
798 n = type_str_helper(buf, size, type);
799 if (n > size)
800 return n;
801 return n + snprintf(buf + n, size - n, "*");
802 } else if (type->type == SYM_ARRAY) {
803 type = get_real_base_type(type);
804 n = type_str_helper(buf, size, type);
805 if (n > size)
806 return n;
807 return n + snprintf(buf + n, size - n, "[]");
808 } else if (type->type == SYM_STRUCT) {
809 return snprintf(buf, size, "struct %s", type->ident ? type->ident->name : "");
810 } else if (type->type == SYM_UNION) {
811 if (type->ident)
812 return snprintf(buf, size, "union %s", type->ident->name);
|