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.
10 * Licensed under the Open Software License version 1.1
13 #include <sys/types.h>
17 * This describes the pure lexical elements (tokens), with
18 * no semantic meaning. In other words, an identifier doesn't
19 * have a type or meaning, it is only a specific string in
22 * Semantic meaning is handled elsewhere.
29 /* Use these to check for "already parsed" */
30 int constant
, nesting
;
31 struct ident
*protect
;
36 extern int input_stream_nr
;
37 extern struct stream
*input_streams
;
39 extern int ident_hit
, ident_miss
;
42 struct ident
*next
; /* Hash chain of identifiers */
43 struct symbol
*symbols
; /* Pointer to semantic meaning list */
44 unsigned char len
; /* Length of identifier name */
45 char name
[]; /* Actual identifier */
61 /* Combination tokens */
62 #define COMBINATION_STRINGS { \
80 SPECIAL_ADD_ASSIGN
= 256,
106 SPECIAL_ARG_SEPARATOR
115 * This is a very common data structure, it should be kept
116 * as small as humanly possible. Big (rare) types go as
122 struct token
*parent
;
127 unsigned int special
;
128 struct string
*string
;
133 #define token_type(x) ((x)->pos.type)
136 * Last token in the stream - points to itself.
137 * This allows us to not test for NULL pointers
138 * when following the token->next chain..
140 extern int preprocessing
, verbose
;
141 extern struct token eof_token_entry
;
142 #define eof_token(x) ((x) == &eof_token_entry)
144 extern int init_stream(const char *, int fd
);
145 extern struct ident
*hash_ident(struct ident
*);
146 extern struct ident
*built_in_ident(const char *);
147 extern struct token
*built_in_token(int, const char *);
148 extern const char *show_special(int);
149 extern const char *show_ident(const struct ident
*);
150 extern const char *show_string(const struct string
*string
);
151 extern const char *show_token(const struct token
*);
152 extern struct token
* tokenize(const char *, int, struct token
*);
153 extern struct token
* tokenize_buffer(unsigned char *, unsigned long, struct token
*);
155 extern void die(const char *, ...);
156 extern void show_identifier_stats(void);
157 extern struct token
*preprocess(struct token
*);
159 static inline int match_op(struct token
*token
, int op
)
161 return token
->pos
.type
== TOKEN_SPECIAL
&& token
->special
== op
;
164 static inline int match_ident(struct token
*token
, struct ident
*id
)
166 return token
->pos
.type
== TOKEN_IDENT
&& token
->ident
== id
;