Shrink "struct token" by moving "noexpand" into the position flags.
[smatch.git] / token.h
blob597c9f521199e80bc36d46ee7a5dcd82f09ce55d
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 struct stream {
27 int fd;
28 const char *name;
30 /* Use these to check for "already parsed" */
31 int constant, nesting;
32 struct ident *protect;
33 dev_t dev;
34 ino_t ino;
37 extern int input_stream_nr;
38 extern struct stream *input_streams;
40 extern int ident_hit, ident_miss;
42 struct ident {
43 struct ident *next; /* Hash chain of identifiers */
44 struct symbol *symbols; /* Pointer to semantic meaning list */
45 unsigned char len; /* Length of identifier name */
46 unsigned char tainted;
47 char name[]; /* Actual identifier */
50 enum token_type {
51 TOKEN_EOF,
52 TOKEN_ERROR,
53 TOKEN_IDENT,
54 TOKEN_NUMBER,
55 TOKEN_CHAR,
56 TOKEN_STRING,
57 TOKEN_SPECIAL,
58 TOKEN_STREAMBEGIN,
59 TOKEN_STREAMEND,
60 TOKEN_MACRO_ARGUMENT,
61 TOKEN_UNTAINT,
64 /* Combination tokens */
65 #define COMBINATION_STRINGS { \
66 "+=", "++", \
67 "-=", "--", "->", \
68 "*=", \
69 "/=", "/*", "//", \
70 "%=", \
71 "..", "...", \
72 "<=", "<<", "<<=", \
73 ">=", ">>", ">>=", \
74 "==", "!=", \
75 "&&", "&=", \
76 "||", "|=", \
77 "^=", "##", \
78 " @ ", \
81 enum special_token {
82 SPECIAL_BASE = 256,
83 SPECIAL_ADD_ASSIGN = 256,
84 SPECIAL_INCREMENT,
85 SPECIAL_SUB_ASSIGN,
86 SPECIAL_DECREMENT,
87 SPECIAL_DEREFERENCE,
88 SPECIAL_MUL_ASSIGN,
89 SPECIAL_DIV_ASSIGN,
90 SPECIAL_COMMENT,
91 SPECIAL_CPPCOMMENT,
92 SPECIAL_MOD_ASSIGN,
93 SPECIAL_DOTDOT,
94 SPECIAL_ELLIPSIS,
95 SPECIAL_LTE,
96 SPECIAL_LEFTSHIFT,
97 SPECIAL_SHL_ASSIGN,
98 SPECIAL_GTE,
99 SPECIAL_RIGHTSHIFT,
100 SPECIAL_SHR_ASSIGN,
101 SPECIAL_EQUAL,
102 SPECIAL_NOTEQUAL,
103 SPECIAL_LOGICAL_AND,
104 SPECIAL_AND_ASSIGN,
105 SPECIAL_LOGICAL_OR,
106 SPECIAL_OR_ASSIGN,
107 SPECIAL_XOR_ASSIGN,
108 SPECIAL_HASHHASH,
109 SPECIAL_ARG_SEPARATOR
112 struct string {
113 unsigned int length;
114 char data[];
118 * This is a very common data structure, it should be kept
119 * as small as humanly possible. Big (rare) types go as
120 * pointers.
122 struct token {
123 struct position pos;
124 struct token *next;
125 union {
126 char *number;
127 struct ident *ident;
128 unsigned int special;
129 struct string *string;
130 int character;
131 int argnum;
135 #define token_type(x) ((x)->pos.type)
138 * Last token in the stream - points to itself.
139 * This allows us to not test for NULL pointers
140 * when following the token->next chain..
142 extern int preprocessing, verbose;
143 extern struct token eof_token_entry;
144 #define eof_token(x) ((x) == &eof_token_entry)
146 extern int init_stream(const char *, int fd);
147 extern struct ident *hash_ident(struct ident *);
148 extern struct ident *built_in_ident(const char *);
149 extern struct token *built_in_token(int, const char *);
150 extern const char *show_special(int);
151 extern const char *show_ident(const struct ident *);
152 extern const char *show_string(const struct string *string);
153 extern const char *show_token(const struct token *);
154 extern struct token * tokenize(const char *, int, struct token *);
155 extern struct token * tokenize_buffer(unsigned char *, unsigned long, struct token *);
157 extern void die(const char *, ...);
158 extern void show_identifier_stats(void);
159 extern struct token *preprocess(struct token *);
161 static inline int match_op(struct token *token, int op)
163 return token->pos.type == TOKEN_SPECIAL && token->special == op;
166 static inline int match_ident(struct token *token, struct ident *id)
168 return token->pos.type == TOKEN_IDENT && token->ident == id;
171 #endif