[PATCH] casts are not lvalues
[smatch.git] / token.h
blob5fba158ff896141ff79b14991bbc2b9aa4ff174d
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_STR_ARGUMENT,
62 TOKEN_QUOTED_ARGUMENT,
63 TOKEN_CONCAT,
64 TOKEN_GNU_KLUDGE,
65 TOKEN_UNTAINT,
66 TOKEN_ARG_COUNT,
69 /* Combination tokens */
70 #define COMBINATION_STRINGS { \
71 "+=", "++", \
72 "-=", "--", "->", \
73 "*=", \
74 "/=", \
75 "%=", \
76 "..", "...", \
77 "<=", "<<", "<<=", \
78 ">=", ">>", ">>=", \
79 "==", "!=", \
80 "&&", "&=", \
81 "||", "|=", \
82 "^=", "##", \
83 "", \
84 "<", ">", "<=", ">=" \
87 enum special_token {
88 SPECIAL_BASE = 256,
89 SPECIAL_ADD_ASSIGN = SPECIAL_BASE,
90 SPECIAL_INCREMENT,
91 SPECIAL_SUB_ASSIGN,
92 SPECIAL_DECREMENT,
93 SPECIAL_DEREFERENCE,
94 SPECIAL_MUL_ASSIGN,
95 SPECIAL_DIV_ASSIGN,
96 SPECIAL_MOD_ASSIGN,
97 SPECIAL_DOTDOT,
98 SPECIAL_ELLIPSIS,
99 SPECIAL_LTE,
100 SPECIAL_LEFTSHIFT,
101 SPECIAL_SHL_ASSIGN,
102 SPECIAL_GTE,
103 SPECIAL_RIGHTSHIFT,
104 SPECIAL_SHR_ASSIGN,
105 SPECIAL_EQUAL,
106 SPECIAL_NOTEQUAL,
107 SPECIAL_LOGICAL_AND,
108 SPECIAL_AND_ASSIGN,
109 SPECIAL_LOGICAL_OR,
110 SPECIAL_OR_ASSIGN,
111 SPECIAL_XOR_ASSIGN,
112 SPECIAL_HASHHASH,
113 SPECIAL_ARG_SEPARATOR,
114 SPECIAL_UNSIGNED_LT,
115 SPECIAL_UNSIGNED_GT,
116 SPECIAL_UNSIGNED_LTE,
117 SPECIAL_UNSIGNED_GTE,
120 struct string {
121 unsigned int length;
122 char data[];
125 /* will fit into 32 bits */
126 struct argcount {
127 unsigned normal:10;
128 unsigned quoted:10;
129 unsigned str:10;
130 unsigned vararg:1;
134 * This is a very common data structure, it should be kept
135 * as small as humanly possible. Big (rare) types go as
136 * pointers.
138 struct token {
139 struct position pos;
140 struct token *next;
141 union {
142 char *number;
143 struct ident *ident;
144 unsigned int special;
145 struct string *string;
146 int character;
147 int argnum;
148 struct argcount count;
152 #define MAX_STRING 4095
154 static inline struct token *containing_token(struct token **p)
156 void *addr = (char*)p - ((char*)&((struct token *)0)->next - (char*)0);
157 return addr;
160 #define token_type(x) ((x)->pos.type)
163 * Last token in the stream - points to itself.
164 * This allows us to not test for NULL pointers
165 * when following the token->next chain..
167 extern int preprocessing, verbose;
168 extern struct token eof_token_entry;
169 #define eof_token(x) ((x) == &eof_token_entry)
171 extern int init_stream(const char *, int fd);
172 extern struct ident *hash_ident(struct ident *);
173 extern struct ident *built_in_ident(const char *);
174 extern struct token *built_in_token(int, const char *);
175 extern const char *show_special(int);
176 extern const char *show_ident(const struct ident *);
177 extern const char *show_string(const struct string *string);
178 extern const char *show_token(const struct token *);
179 extern struct token * tokenize(const char *, int, struct token *);
180 extern struct token * tokenize_buffer(unsigned char *, unsigned long, struct token *);
182 extern void die(const char *, ...);
183 extern void show_identifier_stats(void);
184 extern struct token *preprocess(struct token *);
186 static inline int match_op(struct token *token, int op)
188 return token->pos.type == TOKEN_SPECIAL && token->special == op;
191 static inline int match_ident(struct token *token, struct ident *id)
193 return token->pos.type == TOKEN_IDENT && token->ident == id;
196 #endif