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
; // input-file 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
;
49 extern int input_stream_nr
;
50 extern struct stream
*input_streams
;
51 extern unsigned int tabstop
;
55 struct ident
*next
; /* Hash chain of identifiers */
56 struct symbol
*symbols
; /* Pointer to semantic meaning list */
57 unsigned char len
; /* Length of identifier name */
58 unsigned char tainted
:1,
61 char name
[]; /* Actual identifier */
77 TOKEN_QUOTED_ARGUMENT
,
87 /* Combination tokens */
88 #define COMBINATION_STRINGS { \
100 "<<=", ">>=", "...", \
102 "<", ">", "<=", ">=" \
105 extern unsigned char combinations
[][4];
109 SPECIAL_ADD_ASSIGN
= SPECIAL_BASE
,
133 SPECIAL_ARG_SEPARATOR
,
136 SPECIAL_UNSIGNED_LTE
,
137 SPECIAL_UNSIGNED_GTE
,
145 /* will fit into 32 bits */
154 * This is a very common data structure, it should be kept
155 * as small as humanly possible. Big (rare) types go as
164 unsigned int special
;
165 struct string
*string
;
168 struct argcount count
;
172 #define MAX_STRING 4095
174 static inline struct token
*containing_token(struct token
**p
)
176 void *addr
= (char *)p
- ((char *)&((struct token
*)0)->next
- (char *)0);
180 #define token_type(x) ((x)->pos.type)
183 * Last token in the stream - points to itself.
184 * This allows us to not test for NULL pointers
185 * when following the token->next chain..
187 extern struct token eof_token_entry
;
188 #define eof_token(x) ((x) == &eof_token_entry)
190 extern int init_stream(const char *, int fd
, const char **next_path
);
191 extern const char *stream_name(int stream
);
192 extern struct ident
*hash_ident(struct ident
*);
193 extern struct ident
*built_in_ident(const char *);
194 extern struct token
*built_in_token(int, const char *);
195 extern const char *show_special(int);
196 extern const char *show_ident(const struct ident
*);
197 extern const char *show_string(const struct string
*string
);
198 extern const char *show_token(const struct token
*);
199 extern struct token
* tokenize(const char *, int, struct token
*, const char **next_path
);
200 extern struct token
* tokenize_buffer(void *, unsigned long, struct token
**);
202 extern void show_identifier_stats(void);
203 extern struct token
*preprocess(struct token
*);
205 extern void store_macro_pos(struct token
*);
206 extern char *get_macro_name(struct position
*);
208 static inline int match_op(struct token
*token
, int op
)
210 return token
->pos
.type
== TOKEN_SPECIAL
&& token
->special
== op
;
213 static inline int match_ident(struct token
*token
, struct ident
*id
)
215 return token
->pos
.type
== TOKEN_IDENT
&& token
->ident
== id
;