Adds function get_type_name to symbol.h to get a string representation of a given type. Signed-off-by: Rob Taylor <rob.taylor@xxxxxxxxxxxxxxx> --- symbol.c | 29 +++++++++++++++++++++++++++++ symbol.h | 1 + 2 files changed, 30 insertions(+), 0 deletions(-) diff --git a/symbol.c b/symbol.c index 7585978..516c50f 100644 --- a/symbol.c +++ b/symbol.c @@ -444,6 +444,35 @@ struct symbol *examine_symbol_type(struct symbol * sym) return sym; } +const char* get_type_name(enum type type) +{ + const char *type_lookup[] = { + [SYM_UNINITIALIZED] = "uninitialized", + [SYM_PREPROCESSOR] = "preprocessor", + [SYM_BASETYPE] = "basetype", + [SYM_NODE] = "node", + [SYM_PTR] = "pointer", + [SYM_FN] = "function", + [SYM_ARRAY] = "array", + [SYM_STRUCT] = "struct", + [SYM_UNION] = "union", + [SYM_ENUM] = "enum", + [SYM_TYPEDEF] = "typedef", + [SYM_TYPEOF] = "typeof", + [SYM_MEMBER] = "member", + [SYM_BITFIELD] = "bitfield", + [SYM_LABEL] = "label", + [SYM_RESTRICT] = "restrict", + [SYM_FOULED] = "fouled", + [SYM_KEYWORD] = "keyword", + [SYM_BAD] = "bad"}; + + if (type <= SYM_BAD) + return type_lookup[type]; + else + return NULL; +} + static struct symbol_list *restr, *fouled; void create_fouled(struct symbol *type) diff --git a/symbol.h b/symbol.h index be5e6b1..c651a84 100644 --- a/symbol.h +++ b/symbol.h @@ -267,6 +267,7 @@ extern void examine_simple_symbol_type(struct symbol *); extern const char *show_typename(struct symbol *sym); extern const char *builtin_typename(struct symbol *sym); extern const char *builtin_ctypename(struct ctype *ctype); +extern const char* get_type_name(enum type type); extern void debug_symbol(struct symbol *); extern void merge_type(struct symbol *sym, struct symbol *base_type); -- 1.5.2-rc3.GIT --------------040700010305000000020101 Content-Type: text/x-patch; name="0004-add-c2xml-program.patch" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="0004-add-c2xml-program.patch"