aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
authorLuc Van Oostenryck <luc.vanoostenryck@gmail.com>2017-12-08 23:43:05 +0100
committerLuc Van Oostenryck <luc.vanoostenryck@gmail.com>2018-12-14 00:40:52 +0100
commit7f6221f9b4a6d0f392bebc0a2b7e311b7cacf17b (patch)
tree1f48e66969aa92e3e1ebd4a3802205e72f10f43d
parent1376b07cf3395716bd566afa31631d4753b0d54a (diff)
downloadsparse-dev-7f6221f9b4a6d0f392bebc0a2b7e311b7cacf17b.tar.gz
add builtin_type_suffix()
With this helper, we can easily output constants with the correct type, like '0x123' for ints, '0x123UL' for unsigned longs, .... Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
-rw-r--r--show-parse.c73
-rw-r--r--symbol.h1
2 files changed, 43 insertions, 31 deletions
diff --git a/show-parse.c b/show-parse.c
index 6328439c..7f9332fc 100644
--- a/show-parse.c
+++ b/show-parse.c
@@ -218,38 +218,39 @@ static void FORMAT_ATTR(2) append(struct type_name *name, const char *fmt, ...)
static struct ctype_name {
struct symbol *sym;
const char *name;
+ const char *suffix;
} typenames[] = {
- { & char_ctype, "char" },
- { &schar_ctype, "signed char" },
- { &uchar_ctype, "unsigned char" },
- { & short_ctype, "short" },
- { &sshort_ctype, "signed short" },
- { &ushort_ctype, "unsigned short" },
- { & int_ctype, "int" },
- { &sint_ctype, "signed int" },
- { &uint_ctype, "unsigned int" },
- { &slong_ctype, "signed long" },
- { & long_ctype, "long" },
- { &ulong_ctype, "unsigned long" },
- { & llong_ctype, "long long" },
- { &sllong_ctype, "signed long long" },
- { &ullong_ctype, "unsigned long long" },
- { & lllong_ctype, "long long long" },
- { &slllong_ctype, "signed long long long" },
- { &ulllong_ctype, "unsigned long long long" },
-
- { &void_ctype, "void" },
- { &bool_ctype, "bool" },
- { &string_ctype, "string" },
-
- { &float_ctype, "float" },
- { &double_ctype, "double" },
- { &ldouble_ctype,"long double" },
- { &incomplete_ctype, "incomplete type" },
- { &int_type, "abstract int" },
- { &fp_type, "abstract fp" },
- { &label_ctype, "label type" },
- { &bad_ctype, "bad type" },
+ { & char_ctype, "char", "" },
+ { &schar_ctype, "signed char", "" },
+ { &uchar_ctype, "unsigned char", "" },
+ { & short_ctype, "short", "" },
+ { &sshort_ctype, "signed short", "" },
+ { &ushort_ctype, "unsigned short", "" },
+ { & int_ctype, "int", "" },
+ { &sint_ctype, "signed int", "" },
+ { &uint_ctype, "unsigned int", "U" },
+ { & long_ctype, "long", "L" },
+ { &slong_ctype, "signed long", "L" },
+ { &ulong_ctype, "unsigned long", "UL" },
+ { & llong_ctype, "long long", "LL" },
+ { &sllong_ctype, "signed long long", "LL" },
+ { &ullong_ctype, "unsigned long long", "ULL" },
+ { & lllong_ctype, "long long long", "LLL" },
+ { &slllong_ctype, "signed long long long", "LLL" },
+ { &ulllong_ctype, "unsigned long long long", "ULLL" },
+
+ { &void_ctype, "void", "" },
+ { &bool_ctype, "bool", "" },
+ { &string_ctype, "string", "" },
+
+ { &float_ctype, "float", "F" },
+ { &double_ctype, "double", "" },
+ { &ldouble_ctype,"long double", "L" },
+ { &incomplete_ctype, "incomplete type", "" },
+ { &int_type, "abstract int", "" },
+ { &fp_type, "abstract fp", "" },
+ { &label_ctype, "label type", "" },
+ { &bad_ctype, "bad type", "" },
};
const char *builtin_typename(struct symbol *sym)
@@ -262,6 +263,16 @@ const char *builtin_typename(struct symbol *sym)
return NULL;
}
+const char *builtin_type_suffix(struct symbol *sym)
+{
+ int i;
+
+ for (i = 0; i < ARRAY_SIZE(typenames); i++)
+ if (typenames[i].sym == sym)
+ return typenames[i].suffix;
+ return NULL;
+}
+
const char *builtin_ctypename(struct ctype *ctype)
{
int i;
diff --git a/symbol.h b/symbol.h
index 5a3d7cef..f9fb4bc5 100644
--- a/symbol.h
+++ b/symbol.h
@@ -317,6 +317,7 @@ extern struct symbol *examine_symbol_type(struct symbol *);
extern struct symbol *examine_pointer_target(struct symbol *);
extern const char *show_typename(struct symbol *sym);
extern const char *builtin_typename(struct symbol *sym);
+extern const char *builtin_type_suffix(struct symbol *sym);
extern const char *builtin_ctypename(struct ctype *ctype);
extern const char* get_type_name(enum type type);