Print this page
12724 update smatch to 0.6.1-rc1-il-5
Split |
Close |
Expand all |
Collapse all |
--- old/usr/src/tools/smatch/src/token.h
+++ new/usr/src/tools/smatch/src/token.h
1 1 #ifndef TOKEN_H
2 2 #define TOKEN_H
3 3 /*
4 4 * Basic tokenization structures. NOTE! Those tokens had better
5 5 * be pretty small, since we're going to keep them all in memory
6 6 * indefinitely.
7 7 *
8 8 * Copyright (C) 2003 Transmeta Corp.
9 9 * 2003 Linus Torvalds
10 10 *
11 11 * Permission is hereby granted, free of charge, to any person obtaining a copy
12 12 * of this software and associated documentation files (the "Software"), to deal
13 13 * in the Software without restriction, including without limitation the rights
14 14 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
15 15 * copies of the Software, and to permit persons to whom the Software is
16 16 * furnished to do so, subject to the following conditions:
17 17 *
18 18 * The above copyright notice and this permission notice shall be included in
19 19 * all copies or substantial portions of the Software.
20 20 *
21 21 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
22 22 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23 23 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
24 24 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
25 25 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
26 26 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
27 27 * THE SOFTWARE.
28 28 */
29 29
30 30 #include <sys/types.h>
31 31 #include "lib.h"
32 32
33 33 /*
34 34 * This describes the pure lexical elements (tokens), with
35 35 * no semantic meaning. In other words, an identifier doesn't
36 36 * have a type or meaning, it is only a specific string in
37 37 * the input stream.
38 38 *
39 39 * Semantic meaning is handled elsewhere.
40 40 */
41 41
42 42 enum constantfile {
43 43 CONSTANT_FILE_MAYBE, // To be determined, not inside any #ifs in this file
44 44 CONSTANT_FILE_IFNDEF, // To be determined, currently inside #ifndef
45 45 CONSTANT_FILE_NOPE, // No
46 46 CONSTANT_FILE_YES // Yes
47 47 };
48 48
49 49 extern const char *includepath[];
50 50
51 51 struct stream {
52 52 int fd;
53 53 const char *name;
54 54 const char *path; // input-file path - see set_stream_include_path()
55 55 const char **next_path;
56 56
57 57 /* Use these to check for "already parsed" */
58 58 enum constantfile constant;
59 59 int dirty, next_stream, once;
60 60 struct ident *protect;
61 61 struct token *ifndef;
62 62 struct token *top_if;
63 63 };
64 64
65 65 extern int input_stream_nr;
66 66 extern struct stream *input_streams;
67 67 extern unsigned int tabstop;
68 68 extern int no_lineno;
69 69 extern int *hash_stream(const char *name);
70 70
71 71 struct ident {
72 72 struct ident *next; /* Hash chain of identifiers */
73 73 struct symbol *symbols; /* Pointer to semantic meaning list */
74 74 unsigned char len; /* Length of identifier name */
75 75 unsigned char tainted:1,
76 76 reserved:1,
77 77 keyword:1;
78 78 char name[]; /* Actual identifier */
79 79 };
80 80
81 81 enum token_type {
82 82 TOKEN_EOF,
83 83 TOKEN_BAD,
84 84 TOKEN_ERROR,
85 85 TOKEN_IDENT,
86 86 TOKEN_ZERO_IDENT,
87 87 TOKEN_NUMBER,
88 88 TOKEN_CHAR,
89 89 TOKEN_CHAR_EMBEDDED_0,
90 90 TOKEN_CHAR_EMBEDDED_1,
91 91 TOKEN_CHAR_EMBEDDED_2,
92 92 TOKEN_CHAR_EMBEDDED_3,
93 93 TOKEN_WIDE_CHAR,
94 94 TOKEN_WIDE_CHAR_EMBEDDED_0,
95 95 TOKEN_WIDE_CHAR_EMBEDDED_1,
96 96 TOKEN_WIDE_CHAR_EMBEDDED_2,
97 97 TOKEN_WIDE_CHAR_EMBEDDED_3,
98 98 TOKEN_STRING,
99 99 TOKEN_WIDE_STRING,
100 100 TOKEN_SPECIAL,
101 101 TOKEN_STREAMBEGIN,
102 102 TOKEN_STREAMEND,
103 103 TOKEN_MACRO_ARGUMENT,
104 104 TOKEN_STR_ARGUMENT,
105 105 TOKEN_QUOTED_ARGUMENT,
106 106 TOKEN_CONCAT,
107 107 TOKEN_GNU_KLUDGE,
108 108 TOKEN_UNTAINT,
109 109 TOKEN_ARG_COUNT,
110 110 TOKEN_IF,
111 111 TOKEN_SKIP_GROUPS,
112 112 TOKEN_ELSE,
113 113 };
114 114
115 115 /* Combination tokens */
116 116 #define COMBINATION_STRINGS { \
117 117 "+=", "++", \
118 118 "-=", "--", "->", \
119 119 "*=", \
120 120 "/=", \
121 121 "%=", \
122 122 "<=", ">=", \
123 123 "==", "!=", \
124 124 "&&", "&=", \
125 125 "||", "|=", \
126 126 "^=", "##", \
127 127 "<<", ">>", "..", \
128 128 "<<=", ">>=", "...", \
129 129 "", \
130 130 "<", ">", "<=", ">=" \
131 131 }
132 132
133 133 extern unsigned char combinations[][4];
134 134
135 135 enum special_token {
136 136 SPECIAL_BASE = 256,
137 137 SPECIAL_ADD_ASSIGN = SPECIAL_BASE,
138 138 SPECIAL_INCREMENT,
139 139 SPECIAL_SUB_ASSIGN,
140 140 SPECIAL_DECREMENT,
141 141 SPECIAL_DEREFERENCE,
142 142 SPECIAL_MUL_ASSIGN,
143 143 SPECIAL_DIV_ASSIGN,
144 144 SPECIAL_MOD_ASSIGN,
145 145 SPECIAL_LTE,
146 146 SPECIAL_GTE,
147 147 SPECIAL_EQUAL,
148 148 SPECIAL_NOTEQUAL,
149 149 SPECIAL_LOGICAL_AND,
150 150 SPECIAL_AND_ASSIGN,
151 151 SPECIAL_LOGICAL_OR,
152 152 SPECIAL_OR_ASSIGN,
153 153 SPECIAL_XOR_ASSIGN,
154 154 SPECIAL_HASHHASH,
155 155 SPECIAL_LEFTSHIFT,
156 156 SPECIAL_RIGHTSHIFT,
157 157 SPECIAL_DOTDOT,
158 158 SPECIAL_SHL_ASSIGN,
159 159 SPECIAL_SHR_ASSIGN,
160 160 SPECIAL_ELLIPSIS,
161 161 SPECIAL_ARG_SEPARATOR,
162 162 SPECIAL_UNSIGNED_LT,
163 163 SPECIAL_UNSIGNED_GT,
164 164 SPECIAL_UNSIGNED_LTE,
165 165 SPECIAL_UNSIGNED_GTE,
166 166 };
167 167
168 168 struct string {
169 169 unsigned int length:31;
170 170 unsigned int immutable:1;
171 171 char data[];
172 172 };
173 173
174 174 /* will fit into 32 bits */
175 175 struct argcount {
176 176 unsigned normal:10;
177 177 unsigned quoted:10;
178 178 unsigned str:10;
179 179 unsigned vararg:1;
180 180 };
181 181
182 182 /*
183 183 * This is a very common data structure, it should be kept
184 184 * as small as humanly possible. Big (rare) types go as
185 185 * pointers.
186 186 */
187 187 struct token {
188 188 struct position pos;
189 189 struct token *next;
190 190 union {
191 191 const char *number;
192 192 struct ident *ident;
193 193 unsigned int special;
194 194 struct string *string;
195 195 int argnum;
196 196 struct argcount count;
197 197 char embedded[4];
198 198 };
199 199 };
200 200
201 201 #define MAX_STRING 8191
202 202
203 203 static inline struct token *containing_token(struct token **p)
204 204 {
205 205 void *addr = (char *)p - ((char *)&((struct token *)0)->next - (char *)0);
206 206 return addr;
207 207 }
208 208
209 209 #define token_type(x) ((x)->pos.type)
210 210
↓ open down ↓ |
210 lines elided |
↑ open up ↑ |
211 211 /*
212 212 * Last token in the stream - points to itself.
213 213 * This allows us to not test for NULL pointers
214 214 * when following the token->next chain..
215 215 */
216 216 extern struct token eof_token_entry;
217 217 #define eof_token(x) ((x) == &eof_token_entry)
218 218
219 219 extern int init_stream(const char *, int fd, const char **next_path);
220 220 extern const char *stream_name(int stream);
221 +struct ident *alloc_ident(const char *name, int len);
221 222 extern struct ident *hash_ident(struct ident *);
222 223 extern struct ident *built_in_ident(const char *);
223 224 extern struct token *built_in_token(int, struct ident *);
224 225 extern const char *show_special(int);
225 226 extern const char *show_ident(const struct ident *);
226 227 extern const char *show_string(const struct string *string);
227 228 extern const char *show_token(const struct token *);
228 229 extern const char *quote_token(const struct token *);
229 230 extern struct token * tokenize(const char *, int, struct token *, const char **next_path);
230 231 extern struct token * tokenize_buffer(void *, unsigned long, struct token **);
231 232
232 233 extern void show_identifier_stats(void);
233 234 extern void init_include_path(void);
234 235 extern struct token *preprocess(struct token *);
235 236
236 237 extern void store_all_tokens(struct token *token);
237 238 extern struct token *pos_get_token(struct position pos);
238 239 extern char *pos_ident(struct position pos);
239 240
240 241 extern void store_macro_pos(struct token *);
241 242 extern char *get_macro_name(struct position pos);
242 243 extern char *get_inner_macro(struct position pos);
243 244 extern struct string_list *get_all_macros(struct position pos);
244 245
245 246 static inline int match_op(struct token *token, unsigned int op)
246 247 {
247 248 return token->pos.type == TOKEN_SPECIAL && token->special == op;
248 249 }
249 250
250 251 static inline int match_ident(struct token *token, struct ident *id)
251 252 {
252 253 return token->pos.type == TOKEN_IDENT && token->ident == id;
253 254 }
254 255
255 256 #endif
↓ open down ↓ |
25 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX