Add "__volatile" and "__volatile__" for gcc compatibility.
[smatch.git] / token.h
blob73fe9ec3eae6fa9026975ee042b2d53d23bb4763
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.
10 * Licensed under the Open Software License version 1.1
13 #include <sys/types.h>
14 #include "lib.h"
17 * This describes the pure lexical elements (tokens), with
18 * no semantic meaning. In other words, an identifier doesn't
19 * have a type or meaning, it is only a specific string in
20 * the input stream.
22 * Semantic meaning is handled elsewhere.
25 struct stream {
26 int fd;
27 const char *name;
29 /* Use these to check for "already parsed" */
30 int constant, nesting;
31 struct ident *protect;
32 dev_t dev;
33 ino_t ino;
36 extern int input_stream_nr;
37 extern struct stream *input_streams;
39 extern int ident_hit, ident_miss;
41 struct ident {
42 struct ident *next; /* Hash chain of identifiers */
43 struct symbol *symbols; /* Pointer to semantic meaning list */
44 unsigned char len; /* Length of identifier name */
45 char name[]; /* Actual identifier */
48 enum token_type {
49 TOKEN_EOF,
50 TOKEN_ERROR,
51 TOKEN_IDENT,
52 TOKEN_INTEGER,
53 TOKEN_FP,
54 TOKEN_CHAR,
55 TOKEN_STRING,
56 TOKEN_SPECIAL,
57 TOKEN_STREAMBEGIN,
58 TOKEN_STREAMEND,
61 /* Combination tokens */
62 #define COMBINATION_STRINGS { \
63 "+=", "++", \
64 "-=", "--", "->", \
65 "*=", \
66 "/=", "/*", "//", \
67 "%=", \
68 "..", "...", \
69 "<=", "<<", "<<=", \
70 ">=", ">>", ">>=", \
71 "==", "!=", \
72 "&&", "&=", \
73 "||", "|=", \
74 "^=", "##", \
75 " @ ", \
78 enum special_token {
79 SPECIAL_BASE = 256,
80 SPECIAL_ADD_ASSIGN = 256,
81 SPECIAL_INCREMENT,
82 SPECIAL_SUB_ASSIGN,
83 SPECIAL_DECREMENT,
84 SPECIAL_DEREFERENCE,
85 SPECIAL_MUL_ASSIGN,
86 SPECIAL_DIV_ASSIGN,
87 SPECIAL_COMMENT,
88 SPECIAL_CPPCOMMENT,
89 SPECIAL_MOD_ASSIGN,
90 SPECIAL_DOTDOT,
91 SPECIAL_ELLIPSIS,
92 SPECIAL_LTE,
93 SPECIAL_LEFTSHIFT,
94 SPECIAL_SHL_ASSIGN,
95 SPECIAL_GTE,
96 SPECIAL_RIGHTSHIFT,
97 SPECIAL_SHR_ASSIGN,
98 SPECIAL_EQUAL,
99 SPECIAL_NOTEQUAL,
100 SPECIAL_LOGICAL_AND,
101 SPECIAL_AND_ASSIGN,
102 SPECIAL_LOGICAL_OR,
103 SPECIAL_OR_ASSIGN,
104 SPECIAL_XOR_ASSIGN,
105 SPECIAL_HASHHASH,
106 SPECIAL_ARG_SEPARATOR
109 struct string {
110 unsigned int length;
111 char data[];
115 * This is a very common data structure, it should be kept
116 * as small as humanly possible. Big (rare) types go as
117 * pointers.
119 struct token {
120 struct position pos;
121 struct token *next;
122 union {
123 char *integer;
124 char *fp;
125 struct ident *ident;
126 unsigned int special;
127 struct string *string;
128 int character;
132 #define token_type(x) ((x)->pos.type)
135 * Last token in the stream - points to itself.
136 * This allows us to not test for NULL pointers
137 * when following the token->next chain..
139 extern int preprocessing;
140 extern struct token eof_token_entry;
141 #define eof_token(x) ((x) == &eof_token_entry)
143 extern int init_stream(const char *, int fd);
144 extern struct ident *hash_ident(struct ident *);
145 extern struct ident *built_in_ident(const char *);
146 extern struct token *built_in_token(int, const char *);
147 extern const char *show_special(int);
148 extern const char *show_ident(const struct ident *);
149 extern const char *show_string(const struct string *string);
150 extern const char *show_token(const struct token *);
151 extern struct token * tokenize(const char *, int, struct token *);
152 extern struct token * tokenize_buffer(unsigned char *, unsigned long, struct token *);
154 extern void die(const char *, ...);
155 extern void show_identifier_stats(void);
156 extern struct token *preprocess(struct token *);
158 static inline int match_op(struct token *token, int op)
160 return token->pos.type == TOKEN_SPECIAL && token->special == op;
163 static inline int match_ident(struct token *token, struct ident *id)
165 return token->pos.type == TOKEN_IDENT && token->ident == id;
168 #endif