2 * Do C preprocessing, based on a token list gathered by
5 * This may not be the smartest preprocessor on the planet.
7 * Copyright (C) 2003 Transmeta Corp.
8 * 2003-2004 Linus Torvalds
10 * Permission is hereby granted, free of charge, to any person obtaining a copy
11 * of this software and associated documentation files (the "Software"), to deal
12 * in the Software without restriction, including without limitation the rights
13 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
14 * copies of the Software, and to permit persons to whom the Software is
15 * furnished to do so, subject to the following conditions:
17 * The above copyright notice and this permission notice shall be included in
18 * all copies or substantial portions of the Software.
20 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
23 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
25 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
44 #include "expression.h"
47 static struct ident_list
*macros
; // only needed for -dD
48 static int false_nesting
= 0;
49 static int counter_macro
= 0; // __COUNTER__ expansion
51 #define INCLUDEPATHS 300
52 const char *includepath
[INCLUDEPATHS
+1] = {
59 static const char **quote_includepath
= includepath
;
60 static const char **angle_includepath
= includepath
+ 1;
61 static const char **isys_includepath
= includepath
+ 1;
62 static const char **sys_includepath
= includepath
+ 1;
63 static const char **dirafter_includepath
= includepath
+ 3;
65 #define dirty_stream(stream) \
67 if (!stream->dirty) { \
69 if (!stream->ifndef) \
70 stream->protect = NULL; \
74 #define end_group(stream) \
76 if (stream->ifndef == stream->top_if) { \
77 stream->ifndef = NULL; \
79 stream->protect = NULL; \
80 else if (stream->protect) \
85 #define nesting_error(stream) \
88 stream->ifndef = NULL; \
89 stream->protect = NULL; \
92 static struct token
*alloc_token(struct position
*pos
)
94 struct token
*token
= __alloc_token(0);
96 token
->pos
.stream
= pos
->stream
;
97 token
->pos
.line
= pos
->line
;
98 token
->pos
.pos
= pos
->pos
;
99 token
->pos
.whitespace
= 1;
103 /* Expand symbol 'sym' at '*list' */
104 static int expand(struct token
**, struct symbol
*);
106 static void replace_with_string(struct token
*token
, const char *str
)
108 int size
= strlen(str
) + 1;
109 struct string
*s
= __alloc_string(size
);
112 memcpy(s
->data
, str
, size
);
113 token_type(token
) = TOKEN_STRING
;
117 static void replace_with_integer(struct token
*token
, unsigned int val
)
119 char *buf
= __alloc_bytes(11);
120 sprintf(buf
, "%u", val
);
121 token_type(token
) = TOKEN_NUMBER
;
125 static struct symbol
*lookup_macro(struct ident
*ident
)
127 struct symbol
*sym
= lookup_symbol(ident
, NS_MACRO
| NS_UNDEF
);
128 if (sym
&& sym
->namespace != NS_MACRO
)
133 static int token_defined(struct token
*token
)
135 if (token_type(token
) == TOKEN_IDENT
) {
136 struct symbol
*sym
= lookup_macro(token
->ident
);
138 sym
->used_in
= file_scope
;
144 sparse_error(token
->pos
, "expected preprocessor identifier");
148 static void replace_with_defined(struct token
*token
)
150 static const char *string
[] = { "0", "1" };
151 int defined
= token_defined(token
);
153 token_type(token
) = TOKEN_NUMBER
;
154 token
->number
= string
[defined
];
157 static int expand_one_symbol(struct token
**list
)
159 struct token
*token
= *list
;
161 static char buffer
[12]; /* __DATE__: 3 + ' ' + 2 + ' ' + 4 + '\0' */
164 if (token
->pos
.noexpand
)
167 sym
= lookup_macro(token
->ident
);
169 sym
->used_in
= file_scope
;
170 return expand(list
, sym
);
172 if (token
->ident
== &__LINE___ident
) {
173 replace_with_integer(token
, token
->pos
.line
);
174 } else if (token
->ident
== &__FILE___ident
) {
175 replace_with_string(token
, stream_name(token
->pos
.stream
));
176 } else if (token
->ident
== &__DATE___ident
) {
179 strftime(buffer
, 12, "%b %e %Y", localtime(&t
));
180 replace_with_string(token
, buffer
);
181 } else if (token
->ident
== &__TIME___ident
) {
184 strftime(buffer
, 9, "%T", localtime(&t
));
185 replace_with_string(token
, buffer
);
186 } else if (token
->ident
== &__COUNTER___ident
) {
187 replace_with_integer(token
, counter_macro
++);
192 static inline struct token
*scan_next(struct token
**where
)
194 struct token
*token
= *where
;
195 if (token_type(token
) != TOKEN_UNTAINT
)
198 token
->ident
->tainted
= 0;
200 } while (token_type(token
) == TOKEN_UNTAINT
);
205 static void expand_list(struct token
**list
)
208 while (!eof_token(next
= scan_next(list
))) {
209 if (token_type(next
) != TOKEN_IDENT
|| expand_one_symbol(list
))
214 static void preprocessor_line(struct stream
*stream
, struct token
**line
);
216 static struct token
*collect_arg(struct token
*prev
, int vararg
, struct position
*pos
, int count
)
218 struct stream
*stream
= input_streams
+ prev
->pos
.stream
;
219 struct token
**p
= &prev
->next
;
223 while (!eof_token(next
= scan_next(p
))) {
224 if (next
->pos
.newline
&& match_op(next
, '#')) {
225 if (!next
->pos
.noexpand
) {
226 sparse_error(next
->pos
,
227 "directive in argument list");
228 preprocessor_line(stream
, p
);
229 __free_token(next
); /* Free the '#' token */
233 switch (token_type(next
)) {
234 case TOKEN_STREAMEND
:
235 case TOKEN_STREAMBEGIN
:
236 *p
= &eof_token_entry
;
239 case TOKEN_WIDE_STRING
:
241 next
->string
->immutable
= 1;
249 if (match_op(next
, '(')) {
251 } else if (match_op(next
, ')')) {
254 } else if (match_op(next
, ',') && !nesting
&& !vararg
) {
257 next
->pos
.stream
= pos
->stream
;
258 next
->pos
.line
= pos
->line
;
259 next
->pos
.pos
= pos
->pos
;
262 *p
= &eof_token_entry
;
267 * We store arglist as <counter> [arg1] <number of uses for arg1> ... eof
272 struct token
*expanded
;
279 static int collect_arguments(struct token
*start
, struct token
*arglist
, struct arg
*args
, struct token
*what
)
281 int wanted
= arglist
->count
.normal
;
282 struct token
*next
= NULL
;
285 arglist
= arglist
->next
; /* skip counter */
288 next
= collect_arg(start
, 0, &what
->pos
, 0);
291 if (!eof_token(start
->next
) || !match_op(next
, ')')) {
296 for (count
= 0; count
< wanted
; count
++) {
297 struct argcount
*p
= &arglist
->next
->count
;
298 next
= collect_arg(start
, p
->vararg
, &what
->pos
, p
->normal
);
299 arglist
= arglist
->next
->next
;
302 args
[count
].arg
= start
->next
;
303 args
[count
].n_normal
= p
->normal
;
304 args
[count
].n_quoted
= p
->quoted
;
305 args
[count
].n_str
= p
->str
;
306 if (match_op(next
, ')')) {
312 if (count
== wanted
&& !match_op(next
, ')'))
314 if (count
== wanted
- 1) {
315 struct argcount
*p
= &arglist
->next
->count
;
318 args
[count
].arg
= NULL
;
319 args
[count
].n_normal
= p
->normal
;
320 args
[count
].n_quoted
= p
->quoted
;
321 args
[count
].n_str
= p
->str
;
323 if (count
< wanted
- 1)
326 what
->next
= next
->next
;
330 sparse_error(what
->pos
, "macro \"%s\" requires %d arguments, but only %d given",
331 show_token(what
), wanted
, count
);
334 while (match_op(next
, ',')) {
335 next
= collect_arg(next
, 0, &what
->pos
, 0);
340 sparse_error(what
->pos
, "macro \"%s\" passed %d arguments, but takes just %d",
341 show_token(what
), count
, wanted
);
344 sparse_error(what
->pos
, "unterminated argument list invoking macro \"%s\"",
347 what
->next
= next
->next
;
351 static struct token
*dup_list(struct token
*list
)
353 struct token
*res
= NULL
;
354 struct token
**p
= &res
;
356 while (!eof_token(list
)) {
357 struct token
*newtok
= __alloc_token(0);
366 static const char *show_token_sequence(struct token
*token
, int quote
)
368 static char buffer
[MAX_STRING
];
372 if (!token
&& !quote
)
374 while (!eof_token(token
)) {
375 const char *val
= quote
? quote_token(token
) : show_token(token
);
376 int len
= strlen(val
);
378 if (ptr
+ whitespace
+ len
>= buffer
+ sizeof(buffer
)) {
379 sparse_error(token
->pos
, "too long token expansion");
385 memcpy(ptr
, val
, len
);
388 whitespace
= token
->pos
.whitespace
;
394 static struct token
*stringify(struct token
*arg
)
396 const char *s
= show_token_sequence(arg
, 1);
397 int size
= strlen(s
)+1;
398 struct token
*token
= __alloc_token(0);
399 struct string
*string
= __alloc_string(size
);
401 memcpy(string
->data
, s
, size
);
402 string
->length
= size
;
403 token
->pos
= arg
->pos
;
404 token_type(token
) = TOKEN_STRING
;
405 token
->string
= string
;
406 token
->next
= &eof_token_entry
;
410 static void expand_arguments(int count
, struct arg
*args
)
413 for (i
= 0; i
< count
; i
++) {
414 struct token
*arg
= args
[i
].arg
;
416 arg
= &eof_token_entry
;
418 args
[i
].str
= stringify(arg
);
419 if (args
[i
].n_normal
) {
420 if (!args
[i
].n_quoted
) {
421 args
[i
].expanded
= arg
;
423 } else if (eof_token(arg
)) {
424 args
[i
].expanded
= arg
;
426 args
[i
].expanded
= dup_list(arg
);
428 expand_list(&args
[i
].expanded
);
434 * Possibly valid combinations:
435 * - ident + ident -> ident
436 * - ident + number -> ident unless number contains '.', '+' or '-'.
437 * - 'L' + char constant -> wide char constant
438 * - 'L' + string literal -> wide string literal
439 * - number + number -> number
440 * - number + ident -> number
441 * - number + '.' -> number
442 * - number + '+' or '-' -> number, if number used to end on [eEpP].
443 * - '.' + number -> number, if number used to start with a digit.
444 * - special + special -> either special or an error.
446 static enum token_type
combine(struct token
*left
, struct token
*right
, char *p
)
449 enum token_type t1
= token_type(left
), t2
= token_type(right
);
451 if (t1
!= TOKEN_IDENT
&& t1
!= TOKEN_NUMBER
&& t1
!= TOKEN_SPECIAL
)
454 if (t1
== TOKEN_IDENT
&& left
->ident
== &L_ident
) {
455 if (t2
>= TOKEN_CHAR
&& t2
< TOKEN_WIDE_CHAR
)
456 return t2
+ TOKEN_WIDE_CHAR
- TOKEN_CHAR
;
457 if (t2
== TOKEN_STRING
)
458 return TOKEN_WIDE_STRING
;
461 if (t2
!= TOKEN_IDENT
&& t2
!= TOKEN_NUMBER
&& t2
!= TOKEN_SPECIAL
)
464 strcpy(p
, show_token(left
));
465 strcat(p
, show_token(right
));
471 if (t1
== TOKEN_IDENT
) {
472 if (t2
== TOKEN_SPECIAL
)
474 if (t2
== TOKEN_NUMBER
&& strpbrk(p
, "+-."))
479 if (t1
== TOKEN_NUMBER
) {
480 if (t2
== TOKEN_SPECIAL
) {
481 switch (right
->special
) {
485 if (strchr("eEpP", p
[len
- 2]))
494 if (p
[0] == '.' && isdigit((unsigned char)p
[1]))
497 return TOKEN_SPECIAL
;
500 static int merge(struct token
*left
, struct token
*right
)
502 static char buffer
[512];
503 enum token_type res
= combine(left
, right
, buffer
);
508 left
->ident
= built_in_ident(buffer
);
509 left
->pos
.noexpand
= 0;
513 char *number
= __alloc_bytes(strlen(buffer
) + 1);
514 memcpy(number
, buffer
, strlen(buffer
) + 1);
515 token_type(left
) = TOKEN_NUMBER
; /* could be . + num */
516 left
->number
= number
;
521 if (buffer
[2] && buffer
[3])
523 for (n
= SPECIAL_BASE
; n
< SPECIAL_ARG_SEPARATOR
; n
++) {
524 if (!memcmp(buffer
, combinations
[n
-SPECIAL_BASE
], 3)) {
531 case TOKEN_WIDE_CHAR
:
532 case TOKEN_WIDE_STRING
:
533 token_type(left
) = res
;
534 left
->pos
.noexpand
= 0;
535 left
->string
= right
->string
;
538 case TOKEN_WIDE_CHAR_EMBEDDED_0
... TOKEN_WIDE_CHAR_EMBEDDED_3
:
539 token_type(left
) = res
;
540 left
->pos
.noexpand
= 0;
541 memcpy(left
->embedded
, right
->embedded
, 4);
547 sparse_error(left
->pos
, "'##' failed: concatenation is not a valid token");
551 static struct token
*dup_token(struct token
*token
, struct position
*streampos
)
553 struct token
*alloc
= alloc_token(streampos
);
554 token_type(alloc
) = token_type(token
);
555 alloc
->pos
.newline
= token
->pos
.newline
;
556 alloc
->pos
.whitespace
= token
->pos
.whitespace
;
557 alloc
->number
= token
->number
;
558 alloc
->pos
.noexpand
= token
->pos
.noexpand
;
562 static struct token
**copy(struct token
**where
, struct token
*list
, int *count
)
564 int need_copy
= --*count
;
565 while (!eof_token(list
)) {
568 token
= dup_token(list
, &list
->pos
);
571 if (token_type(token
) == TOKEN_IDENT
&& token
->ident
->tainted
)
572 token
->pos
.noexpand
= 1;
574 where
= &token
->next
;
577 *where
= &eof_token_entry
;
581 static int handle_kludge(struct token
**p
, struct arg
*args
)
583 struct token
*t
= (*p
)->next
->next
;
585 struct arg
*v
= &args
[t
->argnum
];
586 if (token_type(t
->next
) != TOKEN_CONCAT
) {
588 /* ignore the first ## */
592 /* skip the entire thing */
596 if (v
->arg
&& !eof_token(v
->arg
))
597 return 0; /* no magic */
602 static struct token
**substitute(struct token
**list
, struct token
*body
, struct arg
*args
)
604 struct position
*base_pos
= &(*list
)->pos
;
606 enum {Normal
, Placeholder
, Concat
} state
= Normal
;
608 for (; !eof_token(body
); body
= body
->next
) {
609 struct token
*added
, *arg
;
613 switch (token_type(body
)) {
614 case TOKEN_GNU_KLUDGE
:
616 * GNU kludge: if we had <comma>##<vararg>, behaviour
617 * depends on whether we had enough arguments to have
618 * a vararg. If we did, ## is just ignored. Otherwise
619 * both , and ## are ignored. Worse, there can be
620 * an arbitrary number of ##<arg> in between; if all of
621 * those are empty, we act as if they hadn't been there,
622 * otherwise we act as if the kludge didn't exist.
625 if (handle_kludge(&body
, args
)) {
632 added
= dup_token(t
, base_pos
);
633 token_type(added
) = TOKEN_SPECIAL
;
637 case TOKEN_STR_ARGUMENT
:
638 arg
= args
[body
->argnum
].str
;
639 count
= &args
[body
->argnum
].n_str
;
642 case TOKEN_QUOTED_ARGUMENT
:
643 arg
= args
[body
->argnum
].arg
;
644 count
= &args
[body
->argnum
].n_quoted
;
645 if (!arg
|| eof_token(arg
)) {
654 case TOKEN_MACRO_ARGUMENT
:
655 arg
= args
[body
->argnum
].expanded
;
656 count
= &args
[body
->argnum
].n_normal
;
657 if (eof_token(arg
)) {
662 tail
= copy(&added
, arg
, count
);
663 added
->pos
.newline
= body
->pos
.newline
;
664 added
->pos
.whitespace
= body
->pos
.whitespace
;
668 if (state
== Placeholder
)
675 added
= dup_token(body
, base_pos
);
676 if (added
->ident
->tainted
)
677 added
->pos
.noexpand
= 1;
682 added
= dup_token(body
, base_pos
);
688 * if we got to doing real concatenation, we already have
689 * added something into the list, so containing_token() is OK.
691 if (state
== Concat
&& merge(containing_token(list
), added
)) {
693 if (tail
!= &added
->next
)
701 *list
= &eof_token_entry
;
705 static int expand(struct token
**list
, struct symbol
*sym
)
708 struct token
*token
= *list
;
709 struct ident
*expanding
= token
->ident
;
711 int nargs
= sym
->arglist
? sym
->arglist
->count
.normal
: 0;
712 struct arg args
[nargs
];
714 if (expanding
->tainted
) {
715 token
->pos
.noexpand
= 1;
720 if (!match_op(scan_next(&token
->next
), '('))
722 if (!collect_arguments(token
->next
, sym
->arglist
, args
, token
))
724 expand_arguments(nargs
, args
);
727 expanding
->tainted
= 1;
730 tail
= substitute(list
, sym
->expansion
, args
);
732 * Note that it won't be eof - at least TOKEN_UNTAINT will be there.
733 * We still can lose the newline flag if the sucker expands to nothing,
734 * but the price of dealing with that is probably too high (we'd need
735 * to collect the flags during scan_next())
737 (*list
)->pos
.newline
= token
->pos
.newline
;
738 (*list
)->pos
.whitespace
= token
->pos
.whitespace
;
744 static const char *token_name_sequence(struct token
*token
, int endop
, struct token
*start
)
746 static char buffer
[256];
749 while (!eof_token(token
) && !match_op(token
, endop
)) {
751 const char *val
= token
->string
->data
;
752 if (token_type(token
) != TOKEN_STRING
)
753 val
= show_token(token
);
755 memcpy(ptr
, val
, len
);
760 if (endop
&& !match_op(token
, endop
))
761 sparse_error(start
->pos
, "expected '>' at end of filename");
765 static int already_tokenized(const char *path
)
769 for (stream
= *hash_stream(path
); stream
>= 0 ; stream
= next
) {
770 struct stream
*s
= input_streams
+ stream
;
772 next
= s
->next_stream
;
774 if (strcmp(path
, s
->name
))
778 if (s
->constant
!= CONSTANT_FILE_YES
)
780 if (strcmp(path
, s
->name
))
782 if (s
->protect
&& !lookup_macro(s
->protect
))
789 /* Handle include of header files.
790 * The relevant options are made compatible with gcc. The only options that
791 * are not supported is -withprefix and friends.
793 * Three set of include paths are known:
794 * quote_includepath: Path to search when using #include "file.h"
795 * angle_includepath: Paths to search when using #include <file.h>
796 * isys_includepath: Paths specified with -isystem, come before the
797 * built-in system include paths. Gcc would suppress
798 * warnings from system headers. Here we separate
799 * them from the angle_ ones to keep search ordering.
801 * sys_includepath: Built-in include paths.
802 * dirafter_includepath Paths added with -dirafter.
804 * The above is implemented as one array with pointers
806 * quote_includepath ---> | |
810 * angle_includepath ---> | |
812 * isys_includepath ---> | |
814 * sys_includepath ---> | |
816 * dirafter_includepath -> | |
819 * -I dir insert dir just before isys_includepath and move the rest
820 * -I- makes all dirs specified with -I before to quote dirs only and
821 * angle_includepath is set equal to isys_includepath.
822 * -nostdinc removes all sys dirs by storing NULL in entry pointed
823 * to by * sys_includepath. Note that this will reset all dirs built-in
824 * and added before -nostdinc by -isystem and -idirafter.
825 * -isystem dir adds dir where isys_includepath points adding this dir as
827 * -idirafter dir adds dir to the end of the list
830 static void set_stream_include_path(struct stream
*stream
)
832 const char *path
= stream
->path
;
834 const char *p
= strrchr(stream
->name
, '/');
837 int len
= p
- stream
->name
+ 1;
838 char *m
= malloc(len
+1);
839 /* This includes the final "/" */
840 memcpy(m
, stream
->name
, len
);
846 includepath
[0] = path
;
849 static int try_include(const char *path
, const char *filename
, int flen
, struct token
**where
, const char **next_path
)
852 int plen
= strlen(path
);
853 static char fullname
[PATH_MAX
];
855 memcpy(fullname
, path
, plen
);
856 if (plen
&& path
[plen
-1] != '/') {
857 fullname
[plen
] = '/';
860 memcpy(fullname
+plen
, filename
, flen
);
861 if (already_tokenized(fullname
))
863 fd
= open(fullname
, O_RDONLY
);
865 char * streamname
= __alloc_bytes(plen
+ flen
);
866 memcpy(streamname
, fullname
, plen
+ flen
);
867 *where
= tokenize(streamname
, fd
, *where
, next_path
);
874 static int do_include_path(const char **pptr
, struct token
**list
, struct token
*token
, const char *filename
, int flen
)
878 while ((path
= *pptr
++) != NULL
) {
879 if (!try_include(path
, filename
, flen
, list
, pptr
))
886 static int free_preprocessor_line(struct token
*token
)
888 while (token_type(token
) != TOKEN_EOF
) {
889 struct token
*free
= token
;
896 static int handle_include_path(struct stream
*stream
, struct token
**list
, struct token
*token
, int how
)
898 const char *filename
;
906 if (!match_op(next
, '<')) {
907 expand_list(&token
->next
);
910 if (match_op(token
->next
, '<')) {
917 filename
= token_name_sequence(token
, expect
, token
);
918 flen
= strlen(filename
) + 1;
921 if (filename
[0] == '/') {
922 if (try_include("", filename
, flen
, list
, includepath
))
929 path
= stream
->next_path
;
936 /* Dir of input file is first dir to search for quoted includes */
937 set_stream_include_path(stream
);
938 path
= expect
? angle_includepath
: quote_includepath
;
941 /* Check the standard include paths.. */
942 if (do_include_path(path
, list
, token
, filename
, flen
))
945 error_die(token
->pos
, "unable to open '%s'", filename
);
948 static int handle_include(struct stream
*stream
, struct token
**list
, struct token
*token
)
950 return handle_include_path(stream
, list
, token
, 0);
953 static int handle_include_next(struct stream
*stream
, struct token
**list
, struct token
*token
)
955 return handle_include_path(stream
, list
, token
, 1);
958 static int handle_argv_include(struct stream
*stream
, struct token
**list
, struct token
*token
)
960 return handle_include_path(stream
, list
, token
, 2);
963 static int token_different(struct token
*t1
, struct token
*t2
)
967 if (token_type(t1
) != token_type(t2
))
970 switch (token_type(t1
)) {
972 different
= t1
->ident
!= t2
->ident
;
974 case TOKEN_ARG_COUNT
:
977 case TOKEN_GNU_KLUDGE
:
981 different
= strcmp(t1
->number
, t2
->number
);
984 different
= t1
->special
!= t2
->special
;
986 case TOKEN_MACRO_ARGUMENT
:
987 case TOKEN_QUOTED_ARGUMENT
:
988 case TOKEN_STR_ARGUMENT
:
989 different
= t1
->argnum
!= t2
->argnum
;
991 case TOKEN_CHAR_EMBEDDED_0
... TOKEN_CHAR_EMBEDDED_3
:
992 case TOKEN_WIDE_CHAR_EMBEDDED_0
... TOKEN_WIDE_CHAR_EMBEDDED_3
:
993 different
= memcmp(t1
->embedded
, t2
->embedded
, 4);
996 case TOKEN_WIDE_CHAR
:
998 case TOKEN_WIDE_STRING
: {
999 struct string
*s1
, *s2
;
1004 if (s1
->length
!= s2
->length
)
1006 different
= memcmp(s1
->data
, s2
->data
, s1
->length
);
1016 static int token_list_different(struct token
*list1
, struct token
*list2
)
1021 if (!list1
|| !list2
)
1023 if (token_different(list1
, list2
))
1025 list1
= list1
->next
;
1026 list2
= list2
->next
;
1030 static inline void set_arg_count(struct token
*token
)
1032 token_type(token
) = TOKEN_ARG_COUNT
;
1033 token
->count
.normal
= token
->count
.quoted
=
1034 token
->count
.str
= token
->count
.vararg
= 0;
1037 static struct token
*parse_arguments(struct token
*list
)
1039 struct token
*arg
= list
->next
, *next
= list
;
1040 struct argcount
*count
= &list
->count
;
1042 set_arg_count(list
);
1044 if (match_op(arg
, ')')) {
1046 list
->next
= &eof_token_entry
;
1050 while (token_type(arg
) == TOKEN_IDENT
) {
1051 if (arg
->ident
== &__VA_ARGS___ident
)
1053 if (!++count
->normal
)
1057 if (match_op(next
, ',')) {
1058 set_arg_count(next
);
1063 if (match_op(next
, ')')) {
1064 set_arg_count(next
);
1066 arg
->next
->next
= &eof_token_entry
;
1070 /* normal cases are finished here */
1072 if (match_op(next
, SPECIAL_ELLIPSIS
)) {
1073 if (match_op(next
->next
, ')')) {
1074 set_arg_count(next
);
1075 next
->count
.vararg
= 1;
1077 arg
->next
->next
= &eof_token_entry
;
1085 if (eof_token(next
)) {
1093 if (match_op(arg
, SPECIAL_ELLIPSIS
)) {
1095 token_type(arg
) = TOKEN_IDENT
;
1096 arg
->ident
= &__VA_ARGS___ident
;
1097 if (!match_op(next
, ')'))
1099 if (!++count
->normal
)
1101 set_arg_count(next
);
1102 next
->count
.vararg
= 1;
1104 arg
->next
->next
= &eof_token_entry
;
1108 if (eof_token(arg
)) {
1112 if (match_op(arg
, ','))
1119 sparse_error(arg
->pos
, "parameter name missing");
1122 sparse_error(arg
->pos
, "\"%s\" may not appear in macro parameter list",
1126 sparse_error(arg
->pos
, "missing ')' in macro parameter list");
1129 sparse_error(arg
->pos
, "__VA_ARGS__ can only appear in the expansion of a C99 variadic macro");
1132 sparse_error(arg
->pos
, "too many arguments in macro definition");
1136 static int try_arg(struct token
*token
, enum token_type type
, struct token
*arglist
)
1138 struct ident
*ident
= token
->ident
;
1141 if (!arglist
|| token_type(token
) != TOKEN_IDENT
)
1144 arglist
= arglist
->next
;
1146 for (nr
= 0; !eof_token(arglist
); nr
++, arglist
= arglist
->next
->next
) {
1147 if (arglist
->ident
== ident
) {
1148 struct argcount
*count
= &arglist
->next
->count
;
1152 token_type(token
) = type
;
1154 case TOKEN_MACRO_ARGUMENT
:
1155 n
= ++count
->normal
;
1157 case TOKEN_QUOTED_ARGUMENT
:
1158 n
= ++count
->quoted
;
1164 return count
->vararg
? 2 : 1;
1166 * XXX - need saner handling of that
1167 * (>= 1024 instances of argument)
1169 token_type(token
) = TOKEN_ERROR
;
1176 static struct token
*handle_hash(struct token
**p
, struct token
*arglist
)
1178 struct token
*token
= *p
;
1180 struct token
*next
= token
->next
;
1181 if (!try_arg(next
, TOKEN_STR_ARGUMENT
, arglist
))
1183 next
->pos
.whitespace
= token
->pos
.whitespace
;
1184 __free_token(token
);
1187 token
->pos
.noexpand
= 1;
1192 sparse_error(token
->pos
, "'#' is not followed by a macro parameter");
1196 /* token->next is ## */
1197 static struct token
*handle_hashhash(struct token
*token
, struct token
*arglist
)
1199 struct token
*last
= token
;
1200 struct token
*concat
;
1201 int state
= match_op(token
, ',');
1203 try_arg(token
, TOKEN_QUOTED_ARGUMENT
, arglist
);
1209 /* eat duplicate ## */
1210 concat
= token
->next
;
1211 while (match_op(t
= concat
->next
, SPECIAL_HASHHASH
)) {
1213 __free_token(concat
);
1216 token_type(concat
) = TOKEN_CONCAT
;
1221 if (match_op(t
, '#')) {
1222 t
= handle_hash(&concat
->next
, arglist
);
1227 is_arg
= try_arg(t
, TOKEN_QUOTED_ARGUMENT
, arglist
);
1229 if (state
== 1 && is_arg
) {
1233 state
= match_op(t
, ',');
1237 if (!match_op(token
->next
, SPECIAL_HASHHASH
))
1240 /* handle GNU ,##__VA_ARGS__ kludge, in all its weirdness */
1242 token_type(last
) = TOKEN_GNU_KLUDGE
;
1246 sparse_error(concat
->pos
, "'##' cannot appear at the ends of macro expansion");
1250 static struct token
*parse_expansion(struct token
*expansion
, struct token
*arglist
, struct ident
*name
)
1252 struct token
*token
= expansion
;
1255 if (match_op(token
, SPECIAL_HASHHASH
))
1258 for (p
= &expansion
; !eof_token(token
); p
= &token
->next
, token
= *p
) {
1259 if (match_op(token
, '#')) {
1260 token
= handle_hash(p
, arglist
);
1264 if (match_op(token
->next
, SPECIAL_HASHHASH
)) {
1265 token
= handle_hashhash(token
, arglist
);
1269 try_arg(token
, TOKEN_MACRO_ARGUMENT
, arglist
);
1271 switch (token_type(token
)) {
1276 case TOKEN_WIDE_STRING
:
1277 token
->string
->immutable
= 1;
1281 token
= alloc_token(&expansion
->pos
);
1282 token_type(token
) = TOKEN_UNTAINT
;
1283 token
->ident
= name
;
1289 sparse_error(token
->pos
, "'##' cannot appear at the ends of macro expansion");
1292 sparse_error(token
->pos
, "too many instances of argument in body");
1296 static int do_handle_define(struct stream
*stream
, struct token
**line
, struct token
*token
, int attr
)
1298 struct token
*arglist
, *expansion
;
1299 struct token
*left
= token
->next
;
1304 if (token_type(left
) != TOKEN_IDENT
) {
1305 sparse_error(token
->pos
, "expected identifier to 'define'");
1312 expansion
= left
->next
;
1313 if (!expansion
->pos
.whitespace
) {
1314 if (match_op(expansion
, '(')) {
1315 arglist
= expansion
;
1316 expansion
= parse_arguments(expansion
);
1319 } else if (!eof_token(expansion
)) {
1320 warning(expansion
->pos
,
1321 "no whitespace before object-like macro body");
1325 expansion
= parse_expansion(expansion
, arglist
, name
);
1330 sym
= lookup_symbol(name
, NS_MACRO
| NS_UNDEF
);
1334 if (attr
< sym
->attr
)
1337 clean
= (attr
== sym
->attr
&& sym
->namespace == NS_MACRO
);
1339 if (token_list_different(sym
->expansion
, expansion
) ||
1340 token_list_different(sym
->arglist
, arglist
)) {
1342 if ((clean
&& attr
== SYM_ATTR_NORMAL
)
1343 || sym
->used_in
== file_scope
) {
1344 warning(left
->pos
, "preprocessor token %.*s redefined",
1345 name
->len
, name
->name
);
1346 info(sym
->pos
, "this was the original definition");
1352 if (!sym
|| sym
->scope
!= file_scope
) {
1353 sym
= alloc_symbol(left
->pos
, SYM_NODE
);
1354 bind_symbol(sym
, name
, NS_MACRO
);
1355 add_ident(¯os
, name
);
1360 sym
->expansion
= expansion
;
1361 sym
->arglist
= arglist
;
1362 __free_token(token
); /* Free the "define" token, but not the rest of the line */
1365 sym
->namespace = NS_MACRO
;
1366 sym
->used_in
= NULL
;
1372 static int handle_define(struct stream
*stream
, struct token
**line
, struct token
*token
)
1374 return do_handle_define(stream
, line
, token
, SYM_ATTR_NORMAL
);
1377 static int handle_weak_define(struct stream
*stream
, struct token
**line
, struct token
*token
)
1379 return do_handle_define(stream
, line
, token
, SYM_ATTR_WEAK
);
1382 static int handle_strong_define(struct stream
*stream
, struct token
**line
, struct token
*token
)
1384 return do_handle_define(stream
, line
, token
, SYM_ATTR_STRONG
);
1387 static int do_handle_undef(struct stream
*stream
, struct token
**line
, struct token
*token
, int attr
)
1389 struct token
*left
= token
->next
;
1392 if (token_type(left
) != TOKEN_IDENT
) {
1393 sparse_error(token
->pos
, "expected identifier to 'undef'");
1397 sym
= lookup_symbol(left
->ident
, NS_MACRO
| NS_UNDEF
);
1399 if (attr
< sym
->attr
)
1401 if (attr
== sym
->attr
&& sym
->namespace == NS_UNDEF
)
1403 } else if (attr
<= SYM_ATTR_NORMAL
)
1406 if (!sym
|| sym
->scope
!= file_scope
) {
1407 sym
= alloc_symbol(left
->pos
, SYM_NODE
);
1408 bind_symbol(sym
, left
->ident
, NS_MACRO
);
1411 sym
->namespace = NS_UNDEF
;
1412 sym
->used_in
= NULL
;
1418 static int handle_undef(struct stream
*stream
, struct token
**line
, struct token
*token
)
1420 return do_handle_undef(stream
, line
, token
, SYM_ATTR_NORMAL
);
1423 static int handle_strong_undef(struct stream
*stream
, struct token
**line
, struct token
*token
)
1425 return do_handle_undef(stream
, line
, token
, SYM_ATTR_STRONG
);
1428 static int preprocessor_if(struct stream
*stream
, struct token
*token
, int true)
1430 token_type(token
) = false_nesting
? TOKEN_SKIP_GROUPS
: TOKEN_IF
;
1431 free_preprocessor_line(token
->next
);
1432 token
->next
= stream
->top_if
;
1433 stream
->top_if
= token
;
1434 if (false_nesting
|| true != 1)
1439 static int handle_ifdef(struct stream
*stream
, struct token
**line
, struct token
*token
)
1441 struct token
*next
= token
->next
;
1443 if (token_type(next
) == TOKEN_IDENT
) {
1444 arg
= token_defined(next
);
1446 dirty_stream(stream
);
1448 sparse_error(token
->pos
, "expected preprocessor identifier");
1451 return preprocessor_if(stream
, token
, arg
);
1454 static int handle_ifndef(struct stream
*stream
, struct token
**line
, struct token
*token
)
1456 struct token
*next
= token
->next
;
1458 if (token_type(next
) == TOKEN_IDENT
) {
1459 if (!stream
->dirty
&& !stream
->ifndef
) {
1460 if (!stream
->protect
) {
1461 stream
->ifndef
= token
;
1462 stream
->protect
= next
->ident
;
1463 } else if (stream
->protect
== next
->ident
) {
1464 stream
->ifndef
= token
;
1468 arg
= !token_defined(next
);
1470 dirty_stream(stream
);
1472 sparse_error(token
->pos
, "expected preprocessor identifier");
1476 return preprocessor_if(stream
, token
, arg
);
1479 static const char *show_token_sequence(struct token
*token
, int quote
);
1482 * Expression handling for #if and #elif; it differs from normal expansion
1483 * due to special treatment of "defined".
1485 static int expression_value(struct token
**where
)
1487 struct expression
*expr
;
1489 struct token
**list
= where
, **beginning
= NULL
;
1493 while (!eof_token(p
= scan_next(list
))) {
1496 if (token_type(p
) != TOKEN_IDENT
)
1498 if (p
->ident
== &defined_ident
) {
1503 if (!expand_one_symbol(list
))
1505 if (token_type(p
) != TOKEN_IDENT
)
1507 token_type(p
) = TOKEN_ZERO_IDENT
;
1510 if (match_op(p
, '(')) {
1514 replace_with_defined(p
);
1519 if (token_type(p
) == TOKEN_IDENT
)
1523 replace_with_defined(p
);
1528 if (!match_op(p
, ')'))
1529 sparse_error(p
->pos
, "missing ')' after \"defined\"");
1536 p
= constant_expression(*where
, &expr
);
1538 sparse_error(p
->pos
, "garbage at end: %s", show_token_sequence(p
, 0));
1539 value
= get_expression_value(expr
);
1543 static int handle_if(struct stream
*stream
, struct token
**line
, struct token
*token
)
1547 value
= expression_value(&token
->next
);
1549 dirty_stream(stream
);
1550 return preprocessor_if(stream
, token
, value
);
1553 static int handle_elif(struct stream
* stream
, struct token
**line
, struct token
*token
)
1555 struct token
*top_if
= stream
->top_if
;
1559 nesting_error(stream
);
1560 sparse_error(token
->pos
, "unmatched #elif within stream");
1564 if (token_type(top_if
) == TOKEN_ELSE
) {
1565 nesting_error(stream
);
1566 sparse_error(token
->pos
, "#elif after #else");
1572 dirty_stream(stream
);
1573 if (token_type(top_if
) != TOKEN_IF
)
1575 if (false_nesting
) {
1577 if (!expression_value(&token
->next
))
1581 token_type(top_if
) = TOKEN_SKIP_GROUPS
;
1586 static int handle_else(struct stream
*stream
, struct token
**line
, struct token
*token
)
1588 struct token
*top_if
= stream
->top_if
;
1592 nesting_error(stream
);
1593 sparse_error(token
->pos
, "unmatched #else within stream");
1597 if (token_type(top_if
) == TOKEN_ELSE
) {
1598 nesting_error(stream
);
1599 sparse_error(token
->pos
, "#else after #else");
1601 if (false_nesting
) {
1602 if (token_type(top_if
) == TOKEN_IF
)
1607 token_type(top_if
) = TOKEN_ELSE
;
1611 static int handle_endif(struct stream
*stream
, struct token
**line
, struct token
*token
)
1613 struct token
*top_if
= stream
->top_if
;
1616 nesting_error(stream
);
1617 sparse_error(token
->pos
, "unmatched #endif in stream");
1622 stream
->top_if
= top_if
->next
;
1623 __free_token(top_if
);
1627 static int handle_warning(struct stream
*stream
, struct token
**line
, struct token
*token
)
1629 warning(token
->pos
, "%s", show_token_sequence(token
->next
, 0));
1633 static int handle_error(struct stream
*stream
, struct token
**line
, struct token
*token
)
1635 sparse_error(token
->pos
, "%s", show_token_sequence(token
->next
, 0));
1639 static int handle_nostdinc(struct stream
*stream
, struct token
**line
, struct token
*token
)
1642 * Do we have any non-system includes?
1643 * Clear them out if so..
1645 *sys_includepath
= NULL
;
1649 static inline void update_inc_ptrs(const char ***where
)
1652 if (*where
<= dirafter_includepath
) {
1653 dirafter_includepath
++;
1654 /* If this was the entry that we prepend, don't
1655 * rise the lower entries, even if they are at
1656 * the same level. */
1657 if (where
== &dirafter_includepath
)
1660 if (*where
<= sys_includepath
) {
1662 if (where
== &sys_includepath
)
1665 if (*where
<= isys_includepath
) {
1667 if (where
== &isys_includepath
)
1671 /* angle_includepath is actually never updated, since we
1672 * don't suppport -iquote rught now. May change some day. */
1673 if (*where
<= angle_includepath
) {
1674 angle_includepath
++;
1675 if (where
== &angle_includepath
)
1680 /* Add a path before 'where' and update the pointers associated with the
1681 * includepath array */
1682 static void add_path_entry(struct token
*token
, const char *path
,
1683 const char ***where
)
1688 /* Need one free entry.. */
1689 if (includepath
[INCLUDEPATHS
-2])
1690 error_die(token
->pos
, "too many include path entries");
1692 /* check that this is not a duplicate */
1695 if (strcmp(*dst
, path
) == 0)
1702 update_inc_ptrs(where
);
1705 * Move them all up starting at dst,
1706 * insert the new entry..
1709 const char *tmp
= *dst
;
1716 static int handle_add_include(struct stream
*stream
, struct token
**line
, struct token
*token
)
1719 token
= token
->next
;
1720 if (eof_token(token
))
1722 if (token_type(token
) != TOKEN_STRING
) {
1723 warning(token
->pos
, "expected path string");
1726 add_path_entry(token
, token
->string
->data
, &isys_includepath
);
1730 static int handle_add_isystem(struct stream
*stream
, struct token
**line
, struct token
*token
)
1733 token
= token
->next
;
1734 if (eof_token(token
))
1736 if (token_type(token
) != TOKEN_STRING
) {
1737 sparse_error(token
->pos
, "expected path string");
1740 add_path_entry(token
, token
->string
->data
, &sys_includepath
);
1744 static int handle_add_system(struct stream
*stream
, struct token
**line
, struct token
*token
)
1747 token
= token
->next
;
1748 if (eof_token(token
))
1750 if (token_type(token
) != TOKEN_STRING
) {
1751 sparse_error(token
->pos
, "expected path string");
1754 add_path_entry(token
, token
->string
->data
, &dirafter_includepath
);
1758 /* Add to end on includepath list - no pointer updates */
1759 static void add_dirafter_entry(struct token
*token
, const char *path
)
1761 const char **dst
= includepath
;
1763 /* Need one free entry.. */
1764 if (includepath
[INCLUDEPATHS
-2])
1765 error_die(token
->pos
, "too many include path entries");
1767 /* Add to the end */
1775 static int handle_add_dirafter(struct stream
*stream
, struct token
**line
, struct token
*token
)
1778 token
= token
->next
;
1779 if (eof_token(token
))
1781 if (token_type(token
) != TOKEN_STRING
) {
1782 sparse_error(token
->pos
, "expected path string");
1785 add_dirafter_entry(token
, token
->string
->data
);
1789 static int handle_split_include(struct stream
*stream
, struct token
**line
, struct token
*token
)
1794 * Split the include path. Any directories specified with `-I'
1795 * options before `-I-' are searched only for headers requested with
1796 * `#include "FILE"'; they are not searched for `#include <FILE>'.
1797 * If additional directories are specified with `-I' options after
1798 * the `-I-', those directories are searched for all `#include'
1800 * In addition, `-I-' inhibits the use of the directory of the current
1801 * file directory as the first search directory for `#include "FILE"'.
1803 quote_includepath
= includepath
+1;
1804 angle_includepath
= sys_includepath
;
1809 * We replace "#pragma xxx" with "__pragma__" in the token
1810 * stream. Just as an example.
1812 * We'll just #define that away for now, but the theory here
1813 * is that we can use this to insert arbitrary token sequences
1814 * to turn the pragmas into internal front-end sequences for
1815 * when we actually start caring about them.
1817 * So eventually this will turn into some kind of extended
1818 * __attribute__() like thing, except called __pragma__(xxx).
1820 static int handle_pragma(struct stream
*stream
, struct token
**line
, struct token
*token
)
1822 struct token
*next
= *line
;
1824 if (match_ident(token
->next
, &once_ident
) && eof_token(token
->next
->next
)) {
1828 token
->ident
= &pragma_ident
;
1829 token
->pos
.newline
= 1;
1830 token
->pos
.whitespace
= 1;
1838 * We ignore #line for now.
1840 static int handle_line(struct stream
*stream
, struct token
**line
, struct token
*token
)
1845 static int handle_nondirective(struct stream
*stream
, struct token
**line
, struct token
*token
)
1847 sparse_error(token
->pos
, "unrecognized preprocessor line '%s'", show_token_sequence(token
, 0));
1852 static void init_preprocessor(void)
1855 int stream
= init_stream("preprocessor", -1, includepath
);
1858 int (*handler
)(struct stream
*, struct token
**, struct token
*);
1860 { "define", handle_define
},
1861 { "weak_define", handle_weak_define
},
1862 { "strong_define", handle_strong_define
},
1863 { "undef", handle_undef
},
1864 { "strong_undef", handle_strong_undef
},
1865 { "warning", handle_warning
},
1866 { "error", handle_error
},
1867 { "include", handle_include
},
1868 { "include_next", handle_include_next
},
1869 { "pragma", handle_pragma
},
1870 { "line", handle_line
},
1872 // our internal preprocessor tokens
1873 { "nostdinc", handle_nostdinc
},
1874 { "add_include", handle_add_include
},
1875 { "add_isystem", handle_add_isystem
},
1876 { "add_system", handle_add_system
},
1877 { "add_dirafter", handle_add_dirafter
},
1878 { "split_include", handle_split_include
},
1879 { "argv_include", handle_argv_include
},
1881 { "ifdef", handle_ifdef
},
1882 { "ifndef", handle_ifndef
},
1883 { "else", handle_else
},
1884 { "endif", handle_endif
},
1885 { "if", handle_if
},
1886 { "elif", handle_elif
},
1889 for (i
= 0; i
< ARRAY_SIZE(normal
); i
++) {
1891 sym
= create_symbol(stream
, normal
[i
].name
, SYM_PREPROCESSOR
, NS_PREPROCESSOR
);
1892 sym
->handler
= normal
[i
].handler
;
1895 for (i
= 0; i
< ARRAY_SIZE(special
); i
++) {
1897 sym
= create_symbol(stream
, special
[i
].name
, SYM_PREPROCESSOR
, NS_PREPROCESSOR
);
1898 sym
->handler
= special
[i
].handler
;
1905 static void handle_preprocessor_line(struct stream
*stream
, struct token
**line
, struct token
*start
)
1907 int (*handler
)(struct stream
*, struct token
**, struct token
*);
1908 struct token
*token
= start
->next
;
1911 if (eof_token(token
))
1914 if (token_type(token
) == TOKEN_IDENT
) {
1915 struct symbol
*sym
= lookup_symbol(token
->ident
, NS_PREPROCESSOR
);
1917 handler
= sym
->handler
;
1918 is_normal
= sym
->normal
;
1920 handler
= handle_nondirective
;
1922 } else if (token_type(token
) == TOKEN_NUMBER
) {
1923 handler
= handle_line
;
1925 handler
= handle_nondirective
;
1929 dirty_stream(stream
);
1933 if (!handler(stream
, line
, token
)) /* all set */
1937 free_preprocessor_line(token
);
1940 static void preprocessor_line(struct stream
*stream
, struct token
**line
)
1942 struct token
*start
= *line
, *next
;
1943 struct token
**tp
= &start
->next
;
1947 if (next
->pos
.newline
)
1952 *tp
= &eof_token_entry
;
1953 handle_preprocessor_line(stream
, line
, start
);
1956 static void do_preprocess(struct token
**list
)
1960 while (!eof_token(next
= scan_next(list
))) {
1961 struct stream
*stream
= input_streams
+ next
->pos
.stream
;
1963 if (next
->pos
.newline
&& match_op(next
, '#')) {
1964 if (!next
->pos
.noexpand
) {
1965 preprocessor_line(stream
, list
);
1966 __free_token(next
); /* Free the '#' token */
1971 switch (token_type(next
)) {
1972 case TOKEN_STREAMEND
:
1973 if (stream
->top_if
) {
1974 nesting_error(stream
);
1975 sparse_error(stream
->top_if
->pos
, "unterminated preprocessor conditional");
1976 stream
->top_if
= NULL
;
1980 stream
->constant
= CONSTANT_FILE_YES
;
1983 case TOKEN_STREAMBEGIN
:
1988 dirty_stream(stream
);
1989 if (false_nesting
) {
1995 if (token_type(next
) != TOKEN_IDENT
||
1996 expand_one_symbol(list
))
2002 struct token
* preprocess(struct token
*token
)
2005 init_preprocessor();
2006 do_preprocess(&token
);
2008 // Drop all expressions from preprocessing, they're not used any more.
2009 // This is not true when we have multiple files, though ;/
2010 // clear_expression_alloc();
2016 static void dump_macro(struct symbol
*sym
)
2018 int nargs
= sym
->arglist
? sym
->arglist
->count
.normal
: 0;
2019 struct token
*args
[nargs
];
2020 struct token
*token
;
2022 printf("#define %s", show_ident(sym
->ident
));
2023 token
= sym
->arglist
;
2025 const char *sep
= "";
2028 for (; !eof_token(token
); token
= token
->next
) {
2029 if (token_type(token
) == TOKEN_ARG_COUNT
)
2031 printf("%s%s", sep
, show_token(token
));
2032 args
[narg
++] = token
;
2039 token
= sym
->expansion
;
2040 while (!eof_token(token
)) {
2041 struct token
*next
= token
->next
;
2042 switch (token_type(token
)) {
2045 case TOKEN_MACRO_ARGUMENT
:
2046 token
= args
[token
->argnum
];
2049 printf("%s", show_token(token
));
2050 if (next
->pos
.whitespace
)
2058 void dump_macro_definitions(void)
2062 FOR_EACH_PTR(macros
, name
) {
2063 struct symbol
*sym
= lookup_macro(name
);
2066 } END_FOR_EACH_PTR(name
);