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