Revert ptr-to-array type demotion. It's wrong.
[smatch.git] / token.h
blobb9a699c8c14cda5810f96f98d9a7ab395e2f9ee7
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 char name[]; /* Actual identifier */
49 enum token_type {
50 TOKEN_EOF,
51 TOKEN_ERROR,
52 TOKEN_IDENT,
53 TOKEN_INTEGER,
54 TOKEN_FP,
55 TOKEN_CHAR,
56 TOKEN_STRING,
57 TOKEN_SPECIAL,
58 TOKEN_STREAMBEGIN,
59 TOKEN_STREAMEND,
62 /* Combination tokens */
63 #define COMBINATION_STRINGS { \
64 "+=", "++", \
65 "-=", "--", "->", \
66 "*=", \
67 "/=", "/*", "//", \
68 "%=", \
69 "..", "...", \
70 "<=", "<<", "<<=", \
71 ">=", ">>", ">>=", \
72 "==", "!=", \
73 "&&", "&=", \
74 "||", "|=", \
75 "^=", "##", \
76 " @ ", \
79 enum special_token {
80 SPECIAL_BASE = 256,
81 SPECIAL_ADD_ASSIGN = 256,
82 SPECIAL_INCREMENT,
83 SPECIAL_SUB_ASSIGN,
84 SPECIAL_DECREMENT,
85 SPECIAL_DEREFERENCE,
86 SPECIAL_MUL_ASSIGN,
87 SPECIAL_DIV_ASSIGN,
88 SPECIAL_COMMENT,
89 SPECIAL_CPPCOMMENT,
90 SPECIAL_MOD_ASSIGN,
91 SPECIAL_DOTDOT,
92 SPECIAL_ELLIPSIS,
93 SPECIAL_LTE,
94 SPECIAL_LEFTSHIFT,
95 SPECIAL_SHL_ASSIGN,
96 SPECIAL_GTE,
97 SPECIAL_RIGHTSHIFT,
98 SPECIAL_SHR_ASSIGN,
99 SPECIAL_EQUAL,
100 SPECIAL_NOTEQUAL,
101 SPECIAL_LOGICAL_AND,
102 SPECIAL_AND_ASSIGN,
103 SPECIAL_LOGICAL_OR,
104 SPECIAL_OR_ASSIGN,
105 SPECIAL_XOR_ASSIGN,
106 SPECIAL_HASHHASH,
107 SPECIAL_ARG_SEPARATOR
110 struct string {
111 unsigned int length;
112 char data[];
116 * This is a very common data structure, it should be kept
117 * as small as humanly possible. Big (rare) types go as
118 * pointers.
120 struct token {
121 struct position pos;
122 struct token *next;
123 struct token *parent;
124 union {
125 char *integer;
126 char *fp;
127 struct ident *ident;
128 unsigned int special;
129 struct string *string;
130 int character;
134 #define token_type(x) ((x)->pos.type)
137 * Last token in the stream - points to itself.
138 * This allows us to not test for NULL pointers
139 * when following the token->next chain..
141 extern int preprocessing, verbose;
142 extern struct token eof_token_entry;
143 #define eof_token(x) ((x) == &eof_token_entry)
145 extern int init_stream(const char *, int fd);
146 extern struct ident *hash_ident(struct ident *);
147 extern struct ident *built_in_ident(const char *);
148 extern struct token *built_in_token(int, const char *);
149 extern const char *show_special(int);
150 extern const char *show_ident(const struct ident *);
151 extern const char *show_string(const struct string *string);
152 extern const char *show_token(const struct token *);
153 extern struct token * tokenize(const char *, int, struct token *);
154 extern struct token * tokenize_buffer(unsigned char *, unsigned long, struct token *);
156 extern void die(const char *, ...);
157 extern void show_identifier_stats(void);
158 extern struct token *preprocess(struct token *);
160 static inline int match_op(struct token *token, int op)
162 return token->pos.type == TOKEN_SPECIAL && token->special == op;
165 static inline int match_ident(struct token *token, struct ident *id)
167 return token->pos.type == TOKEN_IDENT && token->ident == id;
170 #endif