Merge both node and array information at array degrade time.
[smatch.git] / token.h
blob21db2aae8682e12d561aa79dfee73a276d444932
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, all rights reserved.
9 */
11 #include <sys/types.h>
12 #include "lib.h"
15 * This describes the pure lexical elements (tokens), with
16 * no semantic meaning. In other words, an identifier doesn't
17 * have a type or meaning, it is only a specific string in
18 * the input stream.
20 * Semantic meaning is handled elsewhere.
23 struct stream {
24 int fd;
25 const char *name;
27 /* Use these to check for "already parsed" */
28 int constant, nesting;
29 struct ident *protect;
30 dev_t dev;
31 ino_t ino;
34 extern int input_stream_nr;
35 extern struct stream *input_streams;
37 extern int ident_hit, ident_miss;
39 struct ident {
40 struct ident *next; /* Hash chain of identifiers */
41 struct symbol *symbols; /* Pointer to semantic meaning list */
42 unsigned char len; /* Length of identifier name */
43 char name[]; /* Actual identifier */
46 enum token_type {
47 TOKEN_EOF,
48 TOKEN_ERROR,
49 TOKEN_IDENT,
50 TOKEN_INTEGER,
51 TOKEN_FP,
52 TOKEN_CHAR,
53 TOKEN_STRING,
54 TOKEN_SPECIAL,
55 TOKEN_STREAMBEGIN,
56 TOKEN_STREAMEND,
59 /* Combination tokens */
60 #define COMBINATION_STRINGS { \
61 "+=", "++", \
62 "-=", "--", "->", \
63 "*=", \
64 "/=", "/*", "//", \
65 "%=", \
66 "..", "...", \
67 "<=", "<<", "<<=", \
68 ">=", ">>", ">>=", \
69 "==", "!=", \
70 "&&", "&=", \
71 "||", "|=", \
72 "^=", "##", \
73 " @ ", \
76 enum special_token {
77 SPECIAL_BASE = 256,
78 SPECIAL_ADD_ASSIGN = 256,
79 SPECIAL_INCREMENT,
80 SPECIAL_SUB_ASSIGN,
81 SPECIAL_DECREMENT,
82 SPECIAL_DEREFERENCE,
83 SPECIAL_MUL_ASSIGN,
84 SPECIAL_DIV_ASSIGN,
85 SPECIAL_COMMENT,
86 SPECIAL_CPPCOMMENT,
87 SPECIAL_MOD_ASSIGN,
88 SPECIAL_DOTDOT,
89 SPECIAL_ELLIPSIS,
90 SPECIAL_LTE,
91 SPECIAL_LEFTSHIFT,
92 SPECIAL_SHL_ASSIGN,
93 SPECIAL_GTE,
94 SPECIAL_RIGHTSHIFT,
95 SPECIAL_SHR_ASSIGN,
96 SPECIAL_EQUAL,
97 SPECIAL_NOTEQUAL,
98 SPECIAL_LOGICAL_AND,
99 SPECIAL_AND_ASSIGN,
100 SPECIAL_LOGICAL_OR,
101 SPECIAL_OR_ASSIGN,
102 SPECIAL_XOR_ASSIGN,
103 SPECIAL_HASHHASH,
104 SPECIAL_ARG_SEPARATOR
107 struct string {
108 unsigned int length;
109 char data[];
113 * This is a very common data structure, it should be kept
114 * as small as humanly possible. Big (rare) types go as
115 * pointers.
117 struct token {
118 struct position pos;
119 struct token *next;
120 union {
121 char *integer;
122 char *fp;
123 struct ident *ident;
124 unsigned int special;
125 struct string *string;
126 int character;
130 #define token_type(x) ((x)->pos.type)
133 * Last token in the stream - points to itself.
134 * This allows us to not test for NULL pointers
135 * when following the token->next chain..
137 extern int preprocessing;
138 extern struct token eof_token_entry;
139 #define eof_token(x) ((x) == &eof_token_entry)
141 extern int init_stream(const char *, int fd);
142 extern struct ident *hash_ident(struct ident *);
143 extern struct ident *built_in_ident(const char *);
144 extern struct token *built_in_token(int, const char *);
145 extern const char *show_special(int);
146 extern const char *show_ident(const struct ident *);
147 extern const char *show_string(const struct string *string);
148 extern const char *show_token(const struct token *);
149 extern struct token * tokenize(const char *, int, struct token *);
150 extern struct token * tokenize_buffer(unsigned char *, unsigned long, struct token *);
152 extern void die(const char *, ...);
153 extern void show_identifier_stats(void);
154 extern struct token *preprocess(struct token *);
156 static inline int match_op(struct token *token, int op)
158 return token->pos.type == TOKEN_SPECIAL && token->special == op;
161 static inline int match_ident(struct token *token, struct ident *id)
163 return token->pos.type == TOKEN_IDENT && token->ident == id;
166 #endif