4 * Basic tokenization structures. NOTE! Those tokens had better
5 * be pretty small, since we're going to keep them all in memory
8 * Copyright (C) 2003 Transmeta Corp.
11 * Licensed under the Open Software License version 1.1
14 #include <sys/types.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
23 * Semantic meaning is handled elsewhere.
27 CONSTANT_FILE_MAYBE
, // To be determined, not inside any #ifs in this file
28 CONSTANT_FILE_IFNDEF
, // To be determined, currently inside #ifndef
29 CONSTANT_FILE_NOPE
, // No
30 CONSTANT_FILE_YES
// Yes
33 extern const char *includepath
[];
38 const char *path
; // inputfile path - see set_stream_include_path()
39 const char **next_path
;
41 /* Use these to check for "already parsed" */
42 enum constantfile constant
;
44 struct ident
*protect
;
47 extern int input_stream_nr
;
48 extern struct stream
*input_streams
;
50 extern int ident_hit
, ident_miss
;
53 struct ident
*next
; /* Hash chain of identifiers */
54 struct symbol
*symbols
; /* Pointer to semantic meaning list */
55 unsigned char len
; /* Length of identifier name */
56 unsigned char tainted
:1,
58 char name
[]; /* Actual identifier */
73 TOKEN_QUOTED_ARGUMENT
,
80 /* Combination tokens */
81 #define COMBINATION_STRINGS { \
95 "<", ">", "<=", ">=" \
100 SPECIAL_ADD_ASSIGN
= SPECIAL_BASE
,
124 SPECIAL_ARG_SEPARATOR
,
127 SPECIAL_UNSIGNED_LTE
,
128 SPECIAL_UNSIGNED_GTE
,
136 /* will fit into 32 bits */
145 * This is a very common data structure, it should be kept
146 * as small as humanly possible. Big (rare) types go as
155 unsigned int special
;
156 struct string
*string
;
159 struct argcount count
;
163 #define MAX_STRING 4095
165 static inline struct token
*containing_token(struct token
**p
)
167 void *addr
= (char*)p
- ((char*)&((struct token
*)0)->next
- (char*)0);
171 #define token_type(x) ((x)->pos.type)
174 * Last token in the stream - points to itself.
175 * This allows us to not test for NULL pointers
176 * when following the token->next chain..
178 extern struct token eof_token_entry
;
179 #define eof_token(x) ((x) == &eof_token_entry)
181 extern int init_stream(const char *, int fd
, const char **next_path
);
182 extern const char *stream_name(int stream
);
183 extern struct ident
*hash_ident(struct ident
*);
184 extern struct ident
*built_in_ident(const char *);
185 extern struct token
*built_in_token(int, const char *);
186 extern const char *show_special(int);
187 extern const char *show_ident(const struct ident
*);
188 extern const char *show_string(const struct string
*string
);
189 extern const char *show_token(const struct token
*);
190 extern struct token
* tokenize(const char *, int, struct token
*, const char **next_path
);
191 extern struct token
* tokenize_buffer(unsigned char *, unsigned long, struct token
*);
193 extern void show_identifier_stats(void);
194 extern struct token
*preprocess(struct token
*);
196 static inline int match_op(struct token
*token
, int op
)
198 return token
->pos
.type
== TOKEN_SPECIAL
&& token
->special
== op
;
201 static inline int match_ident(struct token
*token
, struct ident
*id
)
203 return token
->pos
.type
== TOKEN_IDENT
&& token
->ident
== id
;