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 **next_path
;
40 /* Use these to check for "already parsed" */
41 enum constantfile constant
;
43 struct ident
*protect
;
46 extern int input_stream_nr
;
47 extern struct stream
*input_streams
;
49 extern int ident_hit
, ident_miss
;
52 struct ident
*next
; /* Hash chain of identifiers */
53 struct symbol
*symbols
; /* Pointer to semantic meaning list */
54 unsigned char len
; /* Length of identifier name */
55 unsigned char tainted
:1,
57 char name
[]; /* Actual identifier */
72 TOKEN_QUOTED_ARGUMENT
,
79 /* Combination tokens */
80 #define COMBINATION_STRINGS { \
94 "<", ">", "<=", ">=" \
99 SPECIAL_ADD_ASSIGN
= SPECIAL_BASE
,
123 SPECIAL_ARG_SEPARATOR
,
126 SPECIAL_UNSIGNED_LTE
,
127 SPECIAL_UNSIGNED_GTE
,
135 /* will fit into 32 bits */
144 * This is a very common data structure, it should be kept
145 * as small as humanly possible. Big (rare) types go as
154 unsigned int special
;
155 struct string
*string
;
158 struct argcount count
;
162 #define MAX_STRING 4095
164 static inline struct token
*containing_token(struct token
**p
)
166 void *addr
= (char*)p
- ((char*)&((struct token
*)0)->next
- (char*)0);
170 #define token_type(x) ((x)->pos.type)
173 * Last token in the stream - points to itself.
174 * This allows us to not test for NULL pointers
175 * when following the token->next chain..
177 extern struct token eof_token_entry
;
178 #define eof_token(x) ((x) == &eof_token_entry)
180 extern int init_stream(const char *, int fd
, const char **next_path
);
181 extern const char *stream_name(int stream
);
182 extern struct ident
*hash_ident(struct ident
*);
183 extern struct ident
*built_in_ident(const char *);
184 extern struct token
*built_in_token(int, const char *);
185 extern const char *show_special(int);
186 extern const char *show_ident(const struct ident
*);
187 extern const char *show_string(const struct string
*string
);
188 extern const char *show_token(const struct token
*);
189 extern struct token
* tokenize(const char *, int, struct token
*, const char **next_path
);
190 extern struct token
* tokenize_buffer(unsigned char *, unsigned long, struct token
*);
192 extern void show_identifier_stats(void);
193 extern struct token
*preprocess(struct token
*);
195 static inline int match_op(struct token
*token
, int op
)
197 return token
->pos
.type
== TOKEN_SPECIAL
&& token
->special
== op
;
200 static inline int match_ident(struct token
*token
, struct ident
*id
)
202 return token
->pos
.type
== TOKEN_IDENT
&& token
->ident
== id
;