Make arrays properly degenerate into pointer expressions when
[smatch.git] / symbol.h
blob9d5432ec881584c6d724db095284869968dfe928
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_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_MEMBER,
44 SYM_BITFIELD,
47 struct ctype {
48 unsigned long modifiers;
49 struct symbol *base_type;
52 struct symbol {
53 enum namespace namespace:8;
54 enum type type:8;
55 struct token *token; /* Where this symbol was declared */
56 struct token *ident; /* What identifier this symbol is associated with */
57 struct symbol *next_id; /* Next semantic symbol that shares this identifier */
58 struct symbol **id_list; /* Backpointer to symbol list head */
59 union {
60 struct preprocessor_sym {
61 int busy;
62 struct token *expansion;
63 struct token *arglist;
65 struct ctype_symbol {
66 struct symbol *next; /* Next symbol at this level */
67 unsigned long offset;
68 unsigned int bit_size;
69 unsigned int alignment:24,
70 bit_offset:8;
71 int array_size;
72 struct ctype ctype;
73 struct symbol_list *arguments;
74 struct statement *stmt;
75 struct symbol_list *symbol_list;
76 long long value; /* Initial value */
77 int fieldwidth;
78 int arg_count:10, variadic:1;
83 /* Modifiers */
84 #define MOD_AUTO 0x0001
85 #define MOD_REGISTER 0x0002
86 #define MOD_STATIC 0x0004
87 #define MOD_EXTERN 0x0008
89 #define MOD_STORAGE (MOD_AUTO | MOD_REGISTER | MOD_STATIC | MOD_EXTERN)
91 #define MOD_CONST 0x0010
92 #define MOD_VOLATILE 0x0020
93 #define MOD_SIGNED 0x0040
94 #define MOD_UNSIGNED 0x0080
96 #define MOD_CHAR 0x0100
97 #define MOD_SHORT 0x0200
98 #define MOD_LONG 0x0400
99 #define MOD_LONGLONG 0x0800
101 #define MOD_TYPEDEF 0x1000
102 #define MOD_STRUCTOF 0x2000
103 #define MOD_UNIONOF 0x4000
104 #define MOD_ENUMOF 0x8000
106 #define MOD_TYPEOF 0x10000
107 #define MOD_ATTRIBUTE 0x20000
109 /* Basic types */
110 extern struct symbol void_type,
111 int_type,
112 fp_type,
113 vector_type,
114 bad_type;
116 /* C types */
117 extern struct symbol bool_ctype, void_ctype,
118 char_ctype, uchar_ctype,
119 short_ctype, ushort_ctype,
120 int_ctype, uint_ctype,
121 long_ctype, ulong_ctype,
122 llong_ctype, ullong_ctype,
123 float_ctype, double_ctype, ldouble_ctype,
124 string_ctype, ptr_ctype;
127 /* Basic identifiers */
128 extern struct ident sizeof_ident,
129 alignof_ident,
130 __alignof_ident,
131 __alignof___ident,
132 if_ident,
133 else_ident,
134 switch_ident,
135 case_ident,
136 default_ident,
137 break_ident,
138 continue_ident,
139 for_ident,
140 while_ident,
141 do_ident,
142 goto_ident,
143 return_ident;
145 extern struct ident __asm___ident,
146 __asm_ident,
147 asm_ident,
148 __volatile___ident,
149 __volatile_ident,
150 volatile_ident,
151 __attribute___ident,
152 __attribute_ident;
154 #define symbol_is_typename(sym) ((sym)->type == SYM_TYPE)
156 extern struct symbol *lookup_symbol(struct ident *, enum namespace);
157 extern void init_symbols(void);
158 extern struct symbol *alloc_symbol(struct token *, int type);
159 extern void show_type(struct symbol *);
160 extern const char *modifier_string(unsigned long mod);
161 extern void show_symbol(struct symbol *);
162 extern void show_type_list(struct symbol *);
163 extern void show_symbol_list(struct symbol_list *, const char *);
164 extern void add_symbol(struct symbol_list **, struct symbol *);
165 extern void bind_symbol(struct symbol *, struct ident *, enum namespace);
167 extern void examine_symbol_type(struct symbol *);
168 extern void examine_simple_symbol_type(struct symbol *);
170 #endif /* SEMANTIC_H */