Silence the mutually exclusive output again.
[smatch.git] / token.h
blobba7866d74ec06721c4515034bb05157fd7cfa654
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 * Licensed under the Open Software License version 1.1
14 #include <sys/types.h>
15 #include "lib.h"
18 * This describes the pure lexical elements (tokens), with
19 * no semantic meaning. In other words, an identifier doesn't
20 * have a type or meaning, it is only a specific string in
21 * the input stream.
23 * Semantic meaning is handled elsewhere.
26 enum constantfile {
27 CONSTANT_FILE_MAYBE, // To be determined, not inside any #ifs in this file
28 CONSTANT_FILE_IFNDEF, // To be determined, currently inside #ifndef
29 CONSTANT_FILE_NOPE, // No
30 CONSTANT_FILE_YES // Yes
33 extern const char *includepath[];
35 struct stream {
36 int fd;
37 const char *name;
38 const char *path; // input-file path - see set_stream_include_path()
39 const char **next_path;
41 /* Use these to check for "already parsed" */
42 enum constantfile constant;
43 int dirty;
44 struct ident *protect;
45 struct token *ifndef;
46 struct token *top_if;
49 extern int input_stream_nr;
50 extern struct stream *input_streams;
52 struct ident {
53 struct ident *next; /* Hash chain of identifiers */
54 struct symbol *symbols; /* Pointer to semantic meaning list */
55 unsigned char len; /* Length of identifier name */
56 unsigned char tainted:1,
57 reserved:1,
58 keyword:1;
59 char name[]; /* Actual identifier */
62 enum token_type {
63 TOKEN_EOF,
64 TOKEN_ERROR,
65 TOKEN_IDENT,
66 TOKEN_ZERO_IDENT,
67 TOKEN_NUMBER,
68 TOKEN_CHAR,
69 TOKEN_STRING,
70 TOKEN_SPECIAL,
71 TOKEN_STREAMBEGIN,
72 TOKEN_STREAMEND,
73 TOKEN_MACRO_ARGUMENT,
74 TOKEN_STR_ARGUMENT,
75 TOKEN_QUOTED_ARGUMENT,
76 TOKEN_CONCAT,
77 TOKEN_GNU_KLUDGE,
78 TOKEN_UNTAINT,
79 TOKEN_ARG_COUNT,
80 TOKEN_IF,
81 TOKEN_SKIP_GROUPS,
82 TOKEN_ELSE,
85 /* Combination tokens */
86 #define COMBINATION_STRINGS { \
87 "+=", "++", \
88 "-=", "--", "->", \
89 "*=", \
90 "/=", \
91 "%=", \
92 "<=", ">=", \
93 "==", "!=", \
94 "&&", "&=", \
95 "||", "|=", \
96 "^=", "##", \
97 "<<", ">>", "..", \
98 "<<=", ">>=", "...", \
99 "", \
100 "<", ">", "<=", ">=" \
103 extern unsigned char combinations[][4];
105 enum special_token {
106 SPECIAL_BASE = 256,
107 SPECIAL_ADD_ASSIGN = SPECIAL_BASE,
108 SPECIAL_INCREMENT,
109 SPECIAL_SUB_ASSIGN,
110 SPECIAL_DECREMENT,
111 SPECIAL_DEREFERENCE,
112 SPECIAL_MUL_ASSIGN,
113 SPECIAL_DIV_ASSIGN,
114 SPECIAL_MOD_ASSIGN,
115 SPECIAL_LTE,
116 SPECIAL_GTE,
117 SPECIAL_EQUAL,
118 SPECIAL_NOTEQUAL,
119 SPECIAL_LOGICAL_AND,
120 SPECIAL_AND_ASSIGN,
121 SPECIAL_LOGICAL_OR,
122 SPECIAL_OR_ASSIGN,
123 SPECIAL_XOR_ASSIGN,
124 SPECIAL_HASHHASH,
125 SPECIAL_LEFTSHIFT,
126 SPECIAL_RIGHTSHIFT,
127 SPECIAL_DOTDOT,
128 SPECIAL_SHL_ASSIGN,
129 SPECIAL_SHR_ASSIGN,
130 SPECIAL_ELLIPSIS,
131 SPECIAL_ARG_SEPARATOR,
132 SPECIAL_UNSIGNED_LT,
133 SPECIAL_UNSIGNED_GT,
134 SPECIAL_UNSIGNED_LTE,
135 SPECIAL_UNSIGNED_GTE,
138 struct string {
139 unsigned int length;
140 char data[];
143 /* will fit into 32 bits */
144 struct argcount {
145 unsigned normal:10;
146 unsigned quoted:10;
147 unsigned str:10;
148 unsigned vararg:1;
152 * This is a very common data structure, it should be kept
153 * as small as humanly possible. Big (rare) types go as
154 * pointers.
156 struct token {
157 struct position pos;
158 struct token *next;
159 union {
160 const char *number;
161 struct ident *ident;
162 unsigned int special;
163 struct string *string;
164 int character;
165 int argnum;
166 struct argcount count;
170 #define MAX_STRING 4095
172 static inline struct token *containing_token(struct token **p)
174 void *addr = (char *)p - ((char *)&((struct token *)0)->next - (char *)0);
175 return addr;
178 #define token_type(x) ((x)->pos.type)
181 * Last token in the stream - points to itself.
182 * This allows us to not test for NULL pointers
183 * when following the token->next chain..
185 extern struct token eof_token_entry;
186 #define eof_token(x) ((x) == &eof_token_entry)
188 extern int init_stream(const char *, int fd, const char **next_path);
189 extern const char *stream_name(int stream);
190 extern struct ident *hash_ident(struct ident *);
191 extern struct ident *built_in_ident(const char *);
192 extern struct token *built_in_token(int, const char *);
193 extern const char *show_special(int);
194 extern const char *show_ident(const struct ident *);
195 extern const char *show_string(const struct string *string);
196 extern const char *show_token(const struct token *);
197 extern struct token * tokenize(const char *, int, struct token *, const char **next_path);
198 extern struct token * tokenize_buffer(void *, unsigned long, struct token *);
200 extern void show_identifier_stats(void);
201 extern struct token *preprocess(struct token *);
203 static inline int match_op(struct token *token, int op)
205 return token->pos.type == TOKEN_SPECIAL && token->special == op;
208 static inline int match_ident(struct token *token, struct ident *id)
210 return token->pos.type == TOKEN_IDENT && token->ident == id;
213 #endif