Fix stringify that got broken by other changes
[smatch.git] / symbol.h
blobd1e2b154a793f21e77ac2c41607a1884e2cbb682
1 #ifndef SEMANTIC_H
2 #define SEMANTIC_H
3 /*
4 * Basic symbol and namespace definitions.
6 * Copyright (C) 2003 Linus Torvalds, all rights reserved.
7 */
9 #include "token.h"
12 * An identifier with semantic meaning is a "symbol".
14 * There's a 1:n relationship: each symbol is always
15 * associated with one identifier, while each identifier
16 * can have one or more semantic meanings due to C scope
17 * rules.
19 * The progression is symbol -> token -> identifier. The
20 * token contains the information on where the symbol was
21 * declared.
23 enum namespace {
24 NS_NONE,
25 NS_PREPROCESSOR,
26 NS_TYPEDEF,
27 NS_STRUCT,
28 NS_ENUM,
29 NS_LABEL,
30 NS_SYMBOL,
33 enum type {
34 SYM_NONE,
35 SYM_TYPE,
36 SYM_PTR,
37 SYM_FN,
38 SYM_ARRAY,
39 SYM_STRUCT,
40 SYM_UNION,
41 SYM_ENUM,
42 SYM_TYPEDEF,
43 SYM_MEMBER,
44 SYM_BITFIELD,
45 SYM_ELLIPSIS,
48 struct ctype {
49 unsigned long modifiers;
50 struct symbol *base_type;
53 struct symbol {
54 enum namespace namespace:8;
55 enum type type:8;
56 struct token *token; /* Where this symbol was declared */
57 struct token *ident; /* What identifier this symbol is associated with */
58 struct symbol *next_id; /* Next semantic symbol that shares this identifier */
59 struct symbol **id_list; /* Backpointer to symbol list head */
60 union {
61 struct preprocessor_sym {
62 int busy;
63 struct token *expansion;
64 struct token *arglist;
66 struct ctype_symbol {
67 struct symbol *next; /* Next symbol at this level */
68 unsigned long size;
69 struct ctype ctype;
70 struct symbol_list *arguments;
71 struct statement *stmt;
72 struct symbol_list *symbol_list;
73 long long value; /* Initial value */
78 /* Modifiers */
79 #define MOD_AUTO 0x0001
80 #define MOD_REGISTER 0x0002
81 #define MOD_STATIC 0x0004
82 #define MOD_EXTERN 0x0008
84 #define MOD_STORAGE (MOD_AUTO | MOD_REGISTER | MOD_STATIC | MOD_EXTERN)
86 #define MOD_CONST 0x0010
87 #define MOD_VOLATILE 0x0020
88 #define MOD_SIGNED 0x0040
89 #define MOD_UNSIGNED 0x0080
91 #define MOD_CHAR 0x0100
92 #define MOD_SHORT 0x0200
93 #define MOD_LONG 0x0400
94 #define MOD_LONGLONG 0x0800
96 #define MOD_TYPEDEF 0x1000
97 #define MOD_STRUCTOF 0x2000
98 #define MOD_UNIONOF 0x4000
99 #define MOD_ENUMOF 0x8000
101 #define MOD_TYPEOF 0x10000
102 #define MOD_ATTRIBUTE 0x20000
104 /* Basic types */
105 extern struct symbol void_type,
106 int_type,
107 fp_type,
108 vector_type,
109 bad_type;
111 /* Basic identifiers */
112 extern struct ident sizeof_ident,
113 alignof_ident,
114 __alignof_ident,
115 __alignof___ident,
116 if_ident,
117 else_ident,
118 switch_ident,
119 case_ident,
120 default_ident,
121 break_ident,
122 continue_ident,
123 for_ident,
124 while_ident,
125 do_ident,
126 goto_ident,
127 return_ident;
129 extern struct ident __asm___ident,
130 __asm_ident,
131 asm_ident,
132 __volatile___ident,
133 __volatile_ident,
134 volatile_ident,
135 __attribute___ident,
136 __attribute_ident;
138 #define symbol_is_typename(sym) ((sym)->type == SYM_TYPE)
140 extern struct symbol *lookup_symbol(struct ident *, enum namespace);
141 extern void init_symbols(void);
142 extern struct symbol *alloc_symbol(struct token *, int type);
143 extern void show_type(struct symbol *);
144 extern const char *modifier_string(unsigned long mod);
145 extern void show_symbol(struct symbol *);
146 extern void show_type_list(struct symbol *);
147 extern void show_symbol_list(struct symbol_list *, const char *);
148 extern void add_symbol(struct symbol_list **, struct symbol *);
149 extern void bind_symbol(struct symbol *, struct ident *, enum namespace);
151 #endif /* SEMANTIC_H */