Only add symbol definitions, not declarations, to the result list
[smatch.git] / symbol.h
bloba56972ad56a32a6549a5254dea89e9bceb954742
1 #ifndef SEMANTIC_H
2 #define SEMANTIC_H
3 /*
4 * Basic symbol and namespace definitions.
6 * Copyright (C) 2003 Transmeta Corp, 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_BASETYPE,
35 SYM_NODE,
36 SYM_PTR,
37 SYM_FN,
38 SYM_ARRAY,
39 SYM_STRUCT,
40 SYM_UNION,
41 SYM_ENUM,
42 SYM_TYPEDEF,
43 SYM_TYPEOF,
44 SYM_MEMBER,
45 SYM_BITFIELD,
46 SYM_LABEL,
49 struct ctype {
50 unsigned long modifiers;
51 unsigned long alignment;
52 unsigned int contextmask, context, as;
53 struct symbol *base_type;
56 struct symbol {
57 enum namespace namespace:8;
58 enum type type:8;
59 struct position pos; /* Where this symbol was declared */
60 struct ident *ident; /* What identifier this symbol is associated with */
61 struct symbol *next_id; /* Next semantic symbol that shares this identifier */
62 struct symbol **id_list; /* Backpointer to symbol list head */
63 union {
64 struct preprocessor_sym {
65 int busy;
66 struct token *expansion;
67 struct token *arglist;
69 struct ctype_symbol {
70 struct symbol *next; /* Next symbol at this level */
71 unsigned long offset;
72 unsigned int bit_size;
73 unsigned int bit_offset:8,
74 fieldwidth:8,
75 arg_count:10,
76 variadic:1;
77 int array_size;
78 struct ctype ctype;
79 struct symbol_list *arguments;
80 struct statement *stmt;
81 struct symbol_list *symbol_list;
82 struct expression *initializer;
83 long long value; /* Initial value */
88 /* Modifiers */
89 #define MOD_AUTO 0x0001
90 #define MOD_REGISTER 0x0002
91 #define MOD_STATIC 0x0004
92 #define MOD_EXTERN 0x0008
94 #define MOD_STORAGE (MOD_AUTO | MOD_REGISTER | MOD_STATIC | MOD_EXTERN | MOD_INLINE)
96 #define MOD_CONST 0x0010
97 #define MOD_VOLATILE 0x0020
98 #define MOD_SIGNED 0x0040
99 #define MOD_UNSIGNED 0x0080
101 #define MOD_CHAR 0x0100
102 #define MOD_SHORT 0x0200
103 #define MOD_LONG 0x0400
104 #define MOD_LONGLONG 0x0800
106 #define MOD_TYPEDEF 0x1000
107 #define MOD_STRUCTOF 0x2000
108 #define MOD_UNIONOF 0x4000
109 #define MOD_ENUMOF 0x8000
111 #define MOD_TYPEOF 0x10000
112 #define MOD_ATTRIBUTE 0x20000
113 #define MOD_INLINE 0x40000
115 #define MOD_NOCAST 0x100000
116 #define MOD_NODEREF 0x200000
118 /* Basic types */
119 extern struct symbol void_type,
120 int_type,
121 fp_type,
122 vector_type,
123 bad_type;
125 /* C types */
126 extern struct symbol bool_ctype, void_ctype,
127 char_ctype, uchar_ctype,
128 short_ctype, ushort_ctype,
129 int_ctype, uint_ctype,
130 long_ctype, ulong_ctype,
131 llong_ctype, ullong_ctype,
132 float_ctype, double_ctype, ldouble_ctype,
133 string_ctype, ptr_ctype;
136 /* Basic identifiers */
137 extern struct ident sizeof_ident,
138 alignof_ident,
139 __alignof_ident,
140 __alignof___ident,
141 if_ident,
142 else_ident,
143 switch_ident,
144 case_ident,
145 default_ident,
146 break_ident,
147 continue_ident,
148 for_ident,
149 while_ident,
150 do_ident,
151 goto_ident,
152 return_ident;
154 extern struct ident __asm___ident,
155 __asm_ident,
156 asm_ident,
157 __volatile___ident,
158 __volatile_ident,
159 volatile_ident,
160 __attribute___ident,
161 __attribute_ident;
163 #define symbol_is_typename(sym) ((sym)->type == SYM_TYPE)
165 extern struct symbol *lookup_symbol(struct ident *, enum namespace);
166 extern void init_symbols(void);
167 extern struct symbol *alloc_symbol(struct position, int type);
168 extern void show_type(struct symbol *);
169 extern const char *modifier_string(unsigned long mod);
170 extern void show_symbol(struct symbol *);
171 extern void show_type_list(struct symbol *);
172 extern void show_symbol_list(struct symbol_list *, const char *);
173 extern void add_symbol(struct symbol_list **, struct symbol *);
174 extern void bind_symbol(struct symbol *, struct ident *, enum namespace);
176 extern struct symbol *examine_symbol_type(struct symbol *);
177 extern void examine_simple_symbol_type(struct symbol *);
179 #endif /* SEMANTIC_H */