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
);
301 if (p
->vararg
&& wanted
== 1 && eof_token(start
->next
))
303 arglist
= arglist
->next
->next
;
304 args
[count
].arg
= start
->next
;
305 args
[count
].n_normal
= p
->normal
;
306 args
[count
].n_quoted
= p
->quoted
;
307 args
[count
].n_str
= p
->str
;
308 if (match_op(next
, ')')) {
314 if (count
== wanted
&& !match_op(next
, ')'))
316 if (count
== wanted
- 1) {
317 struct argcount
*p
= &arglist
->next
->count
;
320 args
[count
].arg
= NULL
;
321 args
[count
].n_normal
= p
->normal
;
322 args
[count
].n_quoted
= p
->quoted
;
323 args
[count
].n_str
= p
->str
;
325 if (count
< wanted
- 1)
328 what
->next
= next
->next
;
332 sparse_error(what
->pos
, "macro \"%s\" requires %d arguments, but only %d given",
333 show_token(what
), wanted
, count
);
336 while (match_op(next
, ',')) {
337 next
= collect_arg(next
, 0, &what
->pos
, 0);
342 sparse_error(what
->pos
, "macro \"%s\" passed %d arguments, but takes just %d",
343 show_token(what
), count
, wanted
);
346 sparse_error(what
->pos
, "unterminated argument list invoking macro \"%s\"",
349 what
->next
= next
->next
;
353 static struct token
*dup_list(struct token
*list
)
355 struct token
*res
= NULL
;
356 struct token
**p
= &res
;
358 while (!eof_token(list
)) {
359 struct token
*newtok
= __alloc_token(0);
368 static const char *show_token_sequence(struct token
*token
, int quote
)
370 static char buffer
[MAX_STRING
];
374 if (!token
&& !quote
)
376 while (!eof_token(token
)) {
377 const char *val
= quote
? quote_token(token
) : show_token(token
);
378 int len
= strlen(val
);
380 if (ptr
+ whitespace
+ len
>= buffer
+ sizeof(buffer
)) {
381 sparse_error(token
->pos
, "too long token expansion");
387 memcpy(ptr
, val
, len
);
390 whitespace
= token
->pos
.whitespace
;
396 static struct token
*stringify(struct token
*arg
)
398 const char *s
= show_token_sequence(arg
, 1);
399 int size
= strlen(s
)+1;
400 struct token
*token
= __alloc_token(0);
401 struct string
*string
= __alloc_string(size
);
403 memcpy(string
->data
, s
, size
);
404 string
->length
= size
;
405 token
->pos
= arg
->pos
;
406 token_type(token
) = TOKEN_STRING
;
407 token
->string
= string
;
408 token
->next
= &eof_token_entry
;
412 static void expand_arguments(int count
, struct arg
*args
)
415 for (i
= 0; i
< count
; i
++) {
416 struct token
*arg
= args
[i
].arg
;
418 arg
= &eof_token_entry
;
420 args
[i
].str
= stringify(arg
);
421 if (args
[i
].n_normal
) {
422 if (!args
[i
].n_quoted
) {
423 args
[i
].expanded
= arg
;
425 } else if (eof_token(arg
)) {
426 args
[i
].expanded
= arg
;
428 args
[i
].expanded
= dup_list(arg
);
430 expand_list(&args
[i
].expanded
);
436 * Possibly valid combinations:
437 * - ident + ident -> ident
438 * - ident + number -> ident unless number contains '.', '+' or '-'.
439 * - 'L' + char constant -> wide char constant
440 * - 'L' + string literal -> wide string literal
441 * - number + number -> number
442 * - number + ident -> number
443 * - number + '.' -> number
444 * - number + '+' or '-' -> number, if number used to end on [eEpP].
445 * - '.' + number -> number, if number used to start with a digit.
446 * - special + special -> either special or an error.
448 static enum token_type
combine(struct token
*left
, struct token
*right
, char *p
)
451 enum token_type t1
= token_type(left
), t2
= token_type(right
);
453 if (t1
!= TOKEN_IDENT
&& t1
!= TOKEN_NUMBER
&& t1
!= TOKEN_SPECIAL
)
456 if (t1
== TOKEN_IDENT
&& left
->ident
== &L_ident
) {
457 if (t2
>= TOKEN_CHAR
&& t2
< TOKEN_WIDE_CHAR
)
458 return t2
+ TOKEN_WIDE_CHAR
- TOKEN_CHAR
;
459 if (t2
== TOKEN_STRING
)
460 return TOKEN_WIDE_STRING
;
463 if (t2
!= TOKEN_IDENT
&& t2
!= TOKEN_NUMBER
&& t2
!= TOKEN_SPECIAL
)
466 strcpy(p
, show_token(left
));
467 strcat(p
, show_token(right
));
473 if (t1
== TOKEN_IDENT
) {
474 if (t2
== TOKEN_SPECIAL
)
476 if (t2
== TOKEN_NUMBER
&& strpbrk(p
, "+-."))
481 if (t1
== TOKEN_NUMBER
) {
482 if (t2
== TOKEN_SPECIAL
) {
483 switch (right
->special
) {
487 if (strchr("eEpP", p
[len
- 2]))
496 if (p
[0] == '.' && isdigit((unsigned char)p
[1]))
499 return TOKEN_SPECIAL
;
502 static int merge(struct token
*left
, struct token
*right
)
504 static char buffer
[512];
505 enum token_type res
= combine(left
, right
, buffer
);
510 left
->ident
= built_in_ident(buffer
);
511 left
->pos
.noexpand
= 0;
515 char *number
= __alloc_bytes(strlen(buffer
) + 1);
516 memcpy(number
, buffer
, strlen(buffer
) + 1);
517 token_type(left
) = TOKEN_NUMBER
; /* could be . + num */
518 left
->number
= number
;
523 if (buffer
[2] && buffer
[3])
525 for (n
= SPECIAL_BASE
; n
< SPECIAL_ARG_SEPARATOR
; n
++) {
526 if (!memcmp(buffer
, combinations
[n
-SPECIAL_BASE
], 3)) {
533 case TOKEN_WIDE_CHAR
:
534 case TOKEN_WIDE_STRING
:
535 token_type(left
) = res
;
536 left
->pos
.noexpand
= 0;
537 left
->string
= right
->string
;
540 case TOKEN_WIDE_CHAR_EMBEDDED_0
... TOKEN_WIDE_CHAR_EMBEDDED_3
:
541 token_type(left
) = res
;
542 left
->pos
.noexpand
= 0;
543 memcpy(left
->embedded
, right
->embedded
, 4);
549 sparse_error(left
->pos
, "'##' failed: concatenation is not a valid token");
553 static struct token
*dup_token(struct token
*token
, struct position
*streampos
)
555 struct token
*alloc
= alloc_token(streampos
);
556 token_type(alloc
) = token_type(token
);
557 alloc
->pos
.newline
= token
->pos
.newline
;
558 alloc
->pos
.whitespace
= token
->pos
.whitespace
;
559 alloc
->number
= token
->number
;
560 alloc
->pos
.noexpand
= token
->pos
.noexpand
;
564 static struct token
**copy(struct token
**where
, struct token
*list
, int *count
)
566 int need_copy
= --*count
;
567 while (!eof_token(list
)) {
570 token
= dup_token(list
, &list
->pos
);
573 if (token_type(token
) == TOKEN_IDENT
&& token
->ident
->tainted
)
574 token
->pos
.noexpand
= 1;
576 where
= &token
->next
;
579 *where
= &eof_token_entry
;
583 static int handle_kludge(struct token
**p
, struct arg
*args
)
585 struct token
*t
= (*p
)->next
->next
;
587 struct arg
*v
= &args
[t
->argnum
];
588 if (token_type(t
->next
) != TOKEN_CONCAT
) {
590 /* ignore the first ## */
594 /* skip the entire thing */
598 if (v
->arg
&& !eof_token(v
->arg
))
599 return 0; /* no magic */
604 static struct token
**substitute(struct token
**list
, struct token
*body
, struct arg
*args
)
606 struct position
*base_pos
= &(*list
)->pos
;
608 enum {Normal
, Placeholder
, Concat
} state
= Normal
;
610 for (; !eof_token(body
); body
= body
->next
) {
611 struct token
*added
, *arg
;
615 switch (token_type(body
)) {
616 case TOKEN_GNU_KLUDGE
:
618 * GNU kludge: if we had <comma>##<vararg>, behaviour
619 * depends on whether we had enough arguments to have
620 * a vararg. If we did, ## is just ignored. Otherwise
621 * both , and ## are ignored. Worse, there can be
622 * an arbitrary number of ##<arg> in between; if all of
623 * those are empty, we act as if they hadn't been there,
624 * otherwise we act as if the kludge didn't exist.
627 if (handle_kludge(&body
, args
)) {
634 added
= dup_token(t
, base_pos
);
635 token_type(added
) = TOKEN_SPECIAL
;
639 case TOKEN_STR_ARGUMENT
:
640 arg
= args
[body
->argnum
].str
;
641 count
= &args
[body
->argnum
].n_str
;
644 case TOKEN_QUOTED_ARGUMENT
:
645 arg
= args
[body
->argnum
].arg
;
646 count
= &args
[body
->argnum
].n_quoted
;
647 if (!arg
|| eof_token(arg
)) {
656 case TOKEN_MACRO_ARGUMENT
:
657 arg
= args
[body
->argnum
].expanded
;
658 count
= &args
[body
->argnum
].n_normal
;
659 if (eof_token(arg
)) {
664 tail
= copy(&added
, arg
, count
);
665 added
->pos
.newline
= body
->pos
.newline
;
666 added
->pos
.whitespace
= body
->pos
.whitespace
;
670 if (state
== Placeholder
)
677 added
= dup_token(body
, base_pos
);
678 if (added
->ident
->tainted
)
679 added
->pos
.noexpand
= 1;
684 added
= dup_token(body
, base_pos
);
690 * if we got to doing real concatenation, we already have
691 * added something into the list, so containing_token() is OK.
693 if (state
== Concat
&& merge(containing_token(list
), added
)) {
695 if (tail
!= &added
->next
)
703 *list
= &eof_token_entry
;
707 static int expand(struct token
**list
, struct symbol
*sym
)
710 struct token
*token
= *list
;
711 struct ident
*expanding
= token
->ident
;
713 int nargs
= sym
->arglist
? sym
->arglist
->count
.normal
: 0;
714 struct arg args
[nargs
];
716 if (expanding
->tainted
) {
717 token
->pos
.noexpand
= 1;
722 if (!match_op(scan_next(&token
->next
), '('))
724 if (!collect_arguments(token
->next
, sym
->arglist
, args
, token
))
726 expand_arguments(nargs
, args
);
729 expanding
->tainted
= 1;
732 tail
= substitute(list
, sym
->expansion
, args
);
734 * Note that it won't be eof - at least TOKEN_UNTAINT will be there.
735 * We still can lose the newline flag if the sucker expands to nothing,
736 * but the price of dealing with that is probably too high (we'd need
737 * to collect the flags during scan_next())
739 (*list
)->pos
.newline
= token
->pos
.newline
;
740 (*list
)->pos
.whitespace
= token
->pos
.whitespace
;
746 static const char *token_name_sequence(struct token
*token
, int endop
, struct token
*start
)
748 static char buffer
[256];
751 while (!eof_token(token
) && !match_op(token
, endop
)) {
753 const char *val
= token
->string
->data
;
754 if (token_type(token
) != TOKEN_STRING
)
755 val
= show_token(token
);
757 memcpy(ptr
, val
, len
);
762 if (endop
&& !match_op(token
, endop
))
763 sparse_error(start
->pos
, "expected '>' at end of filename");
767 static int already_tokenized(const char *path
)
771 for (stream
= *hash_stream(path
); stream
>= 0 ; stream
= next
) {
772 struct stream
*s
= input_streams
+ stream
;
774 next
= s
->next_stream
;
776 if (strcmp(path
, s
->name
))
780 if (s
->constant
!= CONSTANT_FILE_YES
)
782 if (strcmp(path
, s
->name
))
784 if (s
->protect
&& !lookup_macro(s
->protect
))
791 /* Handle include of header files.
792 * The relevant options are made compatible with gcc. The only options that
793 * are not supported is -withprefix and friends.
795 * Three set of include paths are known:
796 * quote_includepath: Path to search when using #include "file.h"
797 * angle_includepath: Paths to search when using #include <file.h>
798 * isys_includepath: Paths specified with -isystem, come before the
799 * built-in system include paths. Gcc would suppress
800 * warnings from system headers. Here we separate
801 * them from the angle_ ones to keep search ordering.
803 * sys_includepath: Built-in include paths.
804 * dirafter_includepath Paths added with -dirafter.
806 * The above is implemented as one array with pointers
808 * quote_includepath ---> | |
812 * angle_includepath ---> | |
814 * isys_includepath ---> | |
816 * sys_includepath ---> | |
818 * dirafter_includepath -> | |
821 * -I dir insert dir just before isys_includepath and move the rest
822 * -I- makes all dirs specified with -I before to quote dirs only and
823 * angle_includepath is set equal to isys_includepath.
824 * -nostdinc removes all sys dirs by storing NULL in entry pointed
825 * to by * sys_includepath. Note that this will reset all dirs built-in
826 * and added before -nostdinc by -isystem and -idirafter.
827 * -isystem dir adds dir where isys_includepath points adding this dir as
829 * -idirafter dir adds dir to the end of the list
832 static void set_stream_include_path(struct stream
*stream
)
834 const char *path
= stream
->path
;
836 const char *p
= strrchr(stream
->name
, '/');
839 int len
= p
- stream
->name
+ 1;
840 char *m
= malloc(len
+1);
841 /* This includes the final "/" */
842 memcpy(m
, stream
->name
, len
);
848 includepath
[0] = path
;
851 static int try_include(const char *path
, const char *filename
, int flen
, struct token
**where
, const char **next_path
)
854 int plen
= strlen(path
);
855 static char fullname
[PATH_MAX
];
857 memcpy(fullname
, path
, plen
);
858 if (plen
&& path
[plen
-1] != '/') {
859 fullname
[plen
] = '/';
862 memcpy(fullname
+plen
, filename
, flen
);
863 if (already_tokenized(fullname
))
865 fd
= open(fullname
, O_RDONLY
);
867 char * streamname
= __alloc_bytes(plen
+ flen
);
868 memcpy(streamname
, fullname
, plen
+ flen
);
869 *where
= tokenize(streamname
, fd
, *where
, next_path
);
876 static int do_include_path(const char **pptr
, struct token
**list
, struct token
*token
, const char *filename
, int flen
)
880 while ((path
= *pptr
++) != NULL
) {
881 if (!try_include(path
, filename
, flen
, list
, pptr
))
888 static int free_preprocessor_line(struct token
*token
)
890 while (token_type(token
) != TOKEN_EOF
) {
891 struct token
*free
= token
;
898 static int handle_include_path(struct stream
*stream
, struct token
**list
, struct token
*token
, int how
)
900 const char *filename
;
908 if (!match_op(next
, '<')) {
909 expand_list(&token
->next
);
912 if (match_op(token
->next
, '<')) {
919 filename
= token_name_sequence(token
, expect
, token
);
920 flen
= strlen(filename
) + 1;
923 if (filename
[0] == '/') {
924 if (try_include("", filename
, flen
, list
, includepath
))
931 path
= stream
->next_path
;
938 /* Dir of input file is first dir to search for quoted includes */
939 set_stream_include_path(stream
);
940 path
= expect
? angle_includepath
: quote_includepath
;
943 /* Check the standard include paths.. */
944 if (do_include_path(path
, list
, token
, filename
, flen
))
947 error_die(token
->pos
, "unable to open '%s'", filename
);
950 static int handle_include(struct stream
*stream
, struct token
**list
, struct token
*token
)
952 return handle_include_path(stream
, list
, token
, 0);
955 static int handle_include_next(struct stream
*stream
, struct token
**list
, struct token
*token
)
957 return handle_include_path(stream
, list
, token
, 1);
960 static int handle_argv_include(struct stream
*stream
, struct token
**list
, struct token
*token
)
962 return handle_include_path(stream
, list
, token
, 2);
965 static int token_different(struct token
*t1
, struct token
*t2
)
969 if (token_type(t1
) != token_type(t2
))
972 switch (token_type(t1
)) {
974 different
= t1
->ident
!= t2
->ident
;
976 case TOKEN_ARG_COUNT
:
979 case TOKEN_GNU_KLUDGE
:
983 different
= strcmp(t1
->number
, t2
->number
);
986 different
= t1
->special
!= t2
->special
;
988 case TOKEN_MACRO_ARGUMENT
:
989 case TOKEN_QUOTED_ARGUMENT
:
990 case TOKEN_STR_ARGUMENT
:
991 different
= t1
->argnum
!= t2
->argnum
;
993 case TOKEN_CHAR_EMBEDDED_0
... TOKEN_CHAR_EMBEDDED_3
:
994 case TOKEN_WIDE_CHAR_EMBEDDED_0
... TOKEN_WIDE_CHAR_EMBEDDED_3
:
995 different
= memcmp(t1
->embedded
, t2
->embedded
, 4);
998 case TOKEN_WIDE_CHAR
:
1000 case TOKEN_WIDE_STRING
: {
1001 struct string
*s1
, *s2
;
1006 if (s1
->length
!= s2
->length
)
1008 different
= memcmp(s1
->data
, s2
->data
, s1
->length
);
1018 static int token_list_different(struct token
*list1
, struct token
*list2
)
1023 if (!list1
|| !list2
)
1025 if (token_different(list1
, list2
))
1027 list1
= list1
->next
;
1028 list2
= list2
->next
;
1032 static inline void set_arg_count(struct token
*token
)
1034 token_type(token
) = TOKEN_ARG_COUNT
;
1035 token
->count
.normal
= token
->count
.quoted
=
1036 token
->count
.str
= token
->count
.vararg
= 0;
1039 static struct token
*parse_arguments(struct token
*list
)
1041 struct token
*arg
= list
->next
, *next
= list
;
1042 struct argcount
*count
= &list
->count
;
1044 set_arg_count(list
);
1046 if (match_op(arg
, ')')) {
1048 list
->next
= &eof_token_entry
;
1052 while (token_type(arg
) == TOKEN_IDENT
) {
1053 if (arg
->ident
== &__VA_ARGS___ident
)
1055 if (!++count
->normal
)
1059 if (match_op(next
, ',')) {
1060 set_arg_count(next
);
1065 if (match_op(next
, ')')) {
1066 set_arg_count(next
);
1068 arg
->next
->next
= &eof_token_entry
;
1072 /* normal cases are finished here */
1074 if (match_op(next
, SPECIAL_ELLIPSIS
)) {
1075 if (match_op(next
->next
, ')')) {
1076 set_arg_count(next
);
1077 next
->count
.vararg
= 1;
1079 arg
->next
->next
= &eof_token_entry
;
1087 if (eof_token(next
)) {
1095 if (match_op(arg
, SPECIAL_ELLIPSIS
)) {
1097 token_type(arg
) = TOKEN_IDENT
;
1098 arg
->ident
= &__VA_ARGS___ident
;
1099 if (!match_op(next
, ')'))
1101 if (!++count
->normal
)
1103 set_arg_count(next
);
1104 next
->count
.vararg
= 1;
1106 arg
->next
->next
= &eof_token_entry
;
1110 if (eof_token(arg
)) {
1114 if (match_op(arg
, ','))
1121 sparse_error(arg
->pos
, "parameter name missing");
1124 sparse_error(arg
->pos
, "\"%s\" may not appear in macro parameter list",
1128 sparse_error(arg
->pos
, "missing ')' in macro parameter list");
1131 sparse_error(arg
->pos
, "__VA_ARGS__ can only appear in the expansion of a C99 variadic macro");
1134 sparse_error(arg
->pos
, "too many arguments in macro definition");
1138 static int try_arg(struct token
*token
, enum token_type type
, struct token
*arglist
)
1140 struct ident
*ident
= token
->ident
;
1143 if (!arglist
|| token_type(token
) != TOKEN_IDENT
)
1146 arglist
= arglist
->next
;
1148 for (nr
= 0; !eof_token(arglist
); nr
++, arglist
= arglist
->next
->next
) {
1149 if (arglist
->ident
== ident
) {
1150 struct argcount
*count
= &arglist
->next
->count
;
1154 token_type(token
) = type
;
1156 case TOKEN_MACRO_ARGUMENT
:
1157 n
= ++count
->normal
;
1159 case TOKEN_QUOTED_ARGUMENT
:
1160 n
= ++count
->quoted
;
1166 return count
->vararg
? 2 : 1;
1168 * XXX - need saner handling of that
1169 * (>= 1024 instances of argument)
1171 token_type(token
) = TOKEN_ERROR
;
1178 static struct token
*handle_hash(struct token
**p
, struct token
*arglist
)
1180 struct token
*token
= *p
;
1182 struct token
*next
= token
->next
;
1183 if (!try_arg(next
, TOKEN_STR_ARGUMENT
, arglist
))
1185 next
->pos
.whitespace
= token
->pos
.whitespace
;
1186 __free_token(token
);
1189 token
->pos
.noexpand
= 1;
1194 sparse_error(token
->pos
, "'#' is not followed by a macro parameter");
1198 /* token->next is ## */
1199 static struct token
*handle_hashhash(struct token
*token
, struct token
*arglist
)
1201 struct token
*last
= token
;
1202 struct token
*concat
;
1203 int state
= match_op(token
, ',');
1205 try_arg(token
, TOKEN_QUOTED_ARGUMENT
, arglist
);
1211 /* eat duplicate ## */
1212 concat
= token
->next
;
1213 while (match_op(t
= concat
->next
, SPECIAL_HASHHASH
)) {
1215 __free_token(concat
);
1218 token_type(concat
) = TOKEN_CONCAT
;
1223 if (match_op(t
, '#')) {
1224 t
= handle_hash(&concat
->next
, arglist
);
1229 is_arg
= try_arg(t
, TOKEN_QUOTED_ARGUMENT
, arglist
);
1231 if (state
== 1 && is_arg
) {
1235 state
= match_op(t
, ',');
1239 if (!match_op(token
->next
, SPECIAL_HASHHASH
))
1242 /* handle GNU ,##__VA_ARGS__ kludge, in all its weirdness */
1244 token_type(last
) = TOKEN_GNU_KLUDGE
;
1248 sparse_error(concat
->pos
, "'##' cannot appear at the ends of macro expansion");
1252 static struct token
*parse_expansion(struct token
*expansion
, struct token
*arglist
, struct ident
*name
)
1254 struct token
*token
= expansion
;
1257 if (match_op(token
, SPECIAL_HASHHASH
))
1260 for (p
= &expansion
; !eof_token(token
); p
= &token
->next
, token
= *p
) {
1261 if (match_op(token
, '#')) {
1262 token
= handle_hash(p
, arglist
);
1266 if (match_op(token
->next
, SPECIAL_HASHHASH
)) {
1267 token
= handle_hashhash(token
, arglist
);
1271 try_arg(token
, TOKEN_MACRO_ARGUMENT
, arglist
);
1273 switch (token_type(token
)) {
1278 case TOKEN_WIDE_STRING
:
1279 token
->string
->immutable
= 1;
1283 token
= alloc_token(&expansion
->pos
);
1284 token_type(token
) = TOKEN_UNTAINT
;
1285 token
->ident
= name
;
1291 sparse_error(token
->pos
, "'##' cannot appear at the ends of macro expansion");
1294 sparse_error(token
->pos
, "too many instances of argument in body");
1298 static int do_handle_define(struct stream
*stream
, struct token
**line
, struct token
*token
, int attr
)
1300 struct token
*arglist
, *expansion
;
1301 struct token
*left
= token
->next
;
1306 if (token_type(left
) != TOKEN_IDENT
) {
1307 sparse_error(token
->pos
, "expected identifier to 'define'");
1314 expansion
= left
->next
;
1315 if (!expansion
->pos
.whitespace
) {
1316 if (match_op(expansion
, '(')) {
1317 arglist
= expansion
;
1318 expansion
= parse_arguments(expansion
);
1321 } else if (!eof_token(expansion
)) {
1322 warning(expansion
->pos
,
1323 "no whitespace before object-like macro body");
1327 expansion
= parse_expansion(expansion
, arglist
, name
);
1332 sym
= lookup_symbol(name
, NS_MACRO
| NS_UNDEF
);
1336 if (attr
< sym
->attr
)
1339 clean
= (attr
== sym
->attr
&& sym
->namespace == NS_MACRO
);
1341 if (token_list_different(sym
->expansion
, expansion
) ||
1342 token_list_different(sym
->arglist
, arglist
)) {
1344 if ((clean
&& attr
== SYM_ATTR_NORMAL
)
1345 || sym
->used_in
== file_scope
) {
1346 warning(left
->pos
, "preprocessor token %.*s redefined",
1347 name
->len
, name
->name
);
1348 info(sym
->pos
, "this was the original definition");
1354 if (!sym
|| sym
->scope
!= file_scope
) {
1355 sym
= alloc_symbol(left
->pos
, SYM_NODE
);
1356 bind_symbol(sym
, name
, NS_MACRO
);
1357 add_ident(¯os
, name
);
1362 sym
->expansion
= expansion
;
1363 sym
->arglist
= arglist
;
1364 __free_token(token
); /* Free the "define" token, but not the rest of the line */
1367 sym
->namespace = NS_MACRO
;
1368 sym
->used_in
= NULL
;
1374 static int handle_define(struct stream
*stream
, struct token
**line
, struct token
*token
)
1376 return do_handle_define(stream
, line
, token
, SYM_ATTR_NORMAL
);
1379 static int handle_weak_define(struct stream
*stream
, struct token
**line
, struct token
*token
)
1381 return do_handle_define(stream
, line
, token
, SYM_ATTR_WEAK
);
1384 static int handle_strong_define(struct stream
*stream
, struct token
**line
, struct token
*token
)
1386 return do_handle_define(stream
, line
, token
, SYM_ATTR_STRONG
);
1389 static int do_handle_undef(struct stream
*stream
, struct token
**line
, struct token
*token
, int attr
)
1391 struct token
*left
= token
->next
;
1394 if (token_type(left
) != TOKEN_IDENT
) {
1395 sparse_error(token
->pos
, "expected identifier to 'undef'");
1399 sym
= lookup_symbol(left
->ident
, NS_MACRO
| NS_UNDEF
);
1401 if (attr
< sym
->attr
)
1403 if (attr
== sym
->attr
&& sym
->namespace == NS_UNDEF
)
1405 } else if (attr
<= SYM_ATTR_NORMAL
)
1408 if (!sym
|| sym
->scope
!= file_scope
) {
1409 sym
= alloc_symbol(left
->pos
, SYM_NODE
);
1410 bind_symbol(sym
, left
->ident
, NS_MACRO
);
1413 sym
->namespace = NS_UNDEF
;
1414 sym
->used_in
= NULL
;
1420 static int handle_undef(struct stream
*stream
, struct token
**line
, struct token
*token
)
1422 return do_handle_undef(stream
, line
, token
, SYM_ATTR_NORMAL
);
1425 static int handle_strong_undef(struct stream
*stream
, struct token
**line
, struct token
*token
)
1427 return do_handle_undef(stream
, line
, token
, SYM_ATTR_STRONG
);
1430 static int preprocessor_if(struct stream
*stream
, struct token
*token
, int true)
1432 token_type(token
) = false_nesting
? TOKEN_SKIP_GROUPS
: TOKEN_IF
;
1433 free_preprocessor_line(token
->next
);
1434 token
->next
= stream
->top_if
;
1435 stream
->top_if
= token
;
1436 if (false_nesting
|| true != 1)
1441 static int handle_ifdef(struct stream
*stream
, struct token
**line
, struct token
*token
)
1443 struct token
*next
= token
->next
;
1445 if (token_type(next
) == TOKEN_IDENT
) {
1446 arg
= token_defined(next
);
1448 dirty_stream(stream
);
1450 sparse_error(token
->pos
, "expected preprocessor identifier");
1453 return preprocessor_if(stream
, token
, arg
);
1456 static int handle_ifndef(struct stream
*stream
, struct token
**line
, struct token
*token
)
1458 struct token
*next
= token
->next
;
1460 if (token_type(next
) == TOKEN_IDENT
) {
1461 if (!stream
->dirty
&& !stream
->ifndef
) {
1462 if (!stream
->protect
) {
1463 stream
->ifndef
= token
;
1464 stream
->protect
= next
->ident
;
1465 } else if (stream
->protect
== next
->ident
) {
1466 stream
->ifndef
= token
;
1470 arg
= !token_defined(next
);
1472 dirty_stream(stream
);
1474 sparse_error(token
->pos
, "expected preprocessor identifier");
1478 return preprocessor_if(stream
, token
, arg
);
1481 static const char *show_token_sequence(struct token
*token
, int quote
);
1484 * Expression handling for #if and #elif; it differs from normal expansion
1485 * due to special treatment of "defined".
1487 static int expression_value(struct token
**where
)
1489 struct expression
*expr
;
1491 struct token
**list
= where
, **beginning
= NULL
;
1495 while (!eof_token(p
= scan_next(list
))) {
1498 if (token_type(p
) != TOKEN_IDENT
)
1500 if (p
->ident
== &defined_ident
) {
1505 if (!expand_one_symbol(list
))
1507 if (token_type(p
) != TOKEN_IDENT
)
1509 token_type(p
) = TOKEN_ZERO_IDENT
;
1512 if (match_op(p
, '(')) {
1516 replace_with_defined(p
);
1521 if (token_type(p
) == TOKEN_IDENT
)
1525 replace_with_defined(p
);
1530 if (!match_op(p
, ')'))
1531 sparse_error(p
->pos
, "missing ')' after \"defined\"");
1538 p
= constant_expression(*where
, &expr
);
1540 sparse_error(p
->pos
, "garbage at end: %s", show_token_sequence(p
, 0));
1541 value
= get_expression_value(expr
);
1545 static int handle_if(struct stream
*stream
, struct token
**line
, struct token
*token
)
1549 value
= expression_value(&token
->next
);
1551 dirty_stream(stream
);
1552 return preprocessor_if(stream
, token
, value
);
1555 static int handle_elif(struct stream
* stream
, struct token
**line
, struct token
*token
)
1557 struct token
*top_if
= stream
->top_if
;
1561 nesting_error(stream
);
1562 sparse_error(token
->pos
, "unmatched #elif within stream");
1566 if (token_type(top_if
) == TOKEN_ELSE
) {
1567 nesting_error(stream
);
1568 sparse_error(token
->pos
, "#elif after #else");
1574 dirty_stream(stream
);
1575 if (token_type(top_if
) != TOKEN_IF
)
1577 if (false_nesting
) {
1579 if (!expression_value(&token
->next
))
1583 token_type(top_if
) = TOKEN_SKIP_GROUPS
;
1588 static int handle_else(struct stream
*stream
, struct token
**line
, struct token
*token
)
1590 struct token
*top_if
= stream
->top_if
;
1594 nesting_error(stream
);
1595 sparse_error(token
->pos
, "unmatched #else within stream");
1599 if (token_type(top_if
) == TOKEN_ELSE
) {
1600 nesting_error(stream
);
1601 sparse_error(token
->pos
, "#else after #else");
1603 if (false_nesting
) {
1604 if (token_type(top_if
) == TOKEN_IF
)
1609 token_type(top_if
) = TOKEN_ELSE
;
1613 static int handle_endif(struct stream
*stream
, struct token
**line
, struct token
*token
)
1615 struct token
*top_if
= stream
->top_if
;
1618 nesting_error(stream
);
1619 sparse_error(token
->pos
, "unmatched #endif in stream");
1624 stream
->top_if
= top_if
->next
;
1625 __free_token(top_if
);
1629 static int handle_warning(struct stream
*stream
, struct token
**line
, struct token
*token
)
1631 warning(token
->pos
, "%s", show_token_sequence(token
->next
, 0));
1635 static int handle_error(struct stream
*stream
, struct token
**line
, struct token
*token
)
1637 sparse_error(token
->pos
, "%s", show_token_sequence(token
->next
, 0));
1641 static int handle_nostdinc(struct stream
*stream
, struct token
**line
, struct token
*token
)
1644 * Do we have any non-system includes?
1645 * Clear them out if so..
1647 *sys_includepath
= NULL
;
1651 static inline void update_inc_ptrs(const char ***where
)
1654 if (*where
<= dirafter_includepath
) {
1655 dirafter_includepath
++;
1656 /* If this was the entry that we prepend, don't
1657 * rise the lower entries, even if they are at
1658 * the same level. */
1659 if (where
== &dirafter_includepath
)
1662 if (*where
<= sys_includepath
) {
1664 if (where
== &sys_includepath
)
1667 if (*where
<= isys_includepath
) {
1669 if (where
== &isys_includepath
)
1673 /* angle_includepath is actually never updated, since we
1674 * don't suppport -iquote rught now. May change some day. */
1675 if (*where
<= angle_includepath
) {
1676 angle_includepath
++;
1677 if (where
== &angle_includepath
)
1682 /* Add a path before 'where' and update the pointers associated with the
1683 * includepath array */
1684 static void add_path_entry(struct token
*token
, const char *path
,
1685 const char ***where
)
1690 /* Need one free entry.. */
1691 if (includepath
[INCLUDEPATHS
-2])
1692 error_die(token
->pos
, "too many include path entries");
1694 /* check that this is not a duplicate */
1697 if (strcmp(*dst
, path
) == 0)
1704 update_inc_ptrs(where
);
1707 * Move them all up starting at dst,
1708 * insert the new entry..
1711 const char *tmp
= *dst
;
1718 static int handle_add_include(struct stream
*stream
, struct token
**line
, struct token
*token
)
1721 token
= token
->next
;
1722 if (eof_token(token
))
1724 if (token_type(token
) != TOKEN_STRING
) {
1725 warning(token
->pos
, "expected path string");
1728 add_path_entry(token
, token
->string
->data
, &isys_includepath
);
1732 static int handle_add_isystem(struct stream
*stream
, struct token
**line
, struct token
*token
)
1735 token
= token
->next
;
1736 if (eof_token(token
))
1738 if (token_type(token
) != TOKEN_STRING
) {
1739 sparse_error(token
->pos
, "expected path string");
1742 add_path_entry(token
, token
->string
->data
, &sys_includepath
);
1746 static int handle_add_system(struct stream
*stream
, struct token
**line
, struct token
*token
)
1749 token
= token
->next
;
1750 if (eof_token(token
))
1752 if (token_type(token
) != TOKEN_STRING
) {
1753 sparse_error(token
->pos
, "expected path string");
1756 add_path_entry(token
, token
->string
->data
, &dirafter_includepath
);
1760 /* Add to end on includepath list - no pointer updates */
1761 static void add_dirafter_entry(struct token
*token
, const char *path
)
1763 const char **dst
= includepath
;
1765 /* Need one free entry.. */
1766 if (includepath
[INCLUDEPATHS
-2])
1767 error_die(token
->pos
, "too many include path entries");
1769 /* Add to the end */
1777 static int handle_add_dirafter(struct stream
*stream
, struct token
**line
, struct token
*token
)
1780 token
= token
->next
;
1781 if (eof_token(token
))
1783 if (token_type(token
) != TOKEN_STRING
) {
1784 sparse_error(token
->pos
, "expected path string");
1787 add_dirafter_entry(token
, token
->string
->data
);
1791 static int handle_split_include(struct stream
*stream
, struct token
**line
, struct token
*token
)
1796 * Split the include path. Any directories specified with `-I'
1797 * options before `-I-' are searched only for headers requested with
1798 * `#include "FILE"'; they are not searched for `#include <FILE>'.
1799 * If additional directories are specified with `-I' options after
1800 * the `-I-', those directories are searched for all `#include'
1802 * In addition, `-I-' inhibits the use of the directory of the current
1803 * file directory as the first search directory for `#include "FILE"'.
1805 quote_includepath
= includepath
+1;
1806 angle_includepath
= sys_includepath
;
1811 * We replace "#pragma xxx" with "__pragma__" in the token
1812 * stream. Just as an example.
1814 * We'll just #define that away for now, but the theory here
1815 * is that we can use this to insert arbitrary token sequences
1816 * to turn the pragmas into internal front-end sequences for
1817 * when we actually start caring about them.
1819 * So eventually this will turn into some kind of extended
1820 * __attribute__() like thing, except called __pragma__(xxx).
1822 static int handle_pragma(struct stream
*stream
, struct token
**line
, struct token
*token
)
1824 struct token
*next
= *line
;
1826 if (match_ident(token
->next
, &once_ident
) && eof_token(token
->next
->next
)) {
1830 token
->ident
= &pragma_ident
;
1831 token
->pos
.newline
= 1;
1832 token
->pos
.whitespace
= 1;
1840 * We ignore #line for now.
1842 static int handle_line(struct stream
*stream
, struct token
**line
, struct token
*token
)
1847 static int handle_nondirective(struct stream
*stream
, struct token
**line
, struct token
*token
)
1849 sparse_error(token
->pos
, "unrecognized preprocessor line '%s'", show_token_sequence(token
, 0));
1854 static void init_preprocessor(void)
1857 int stream
= init_stream("preprocessor", -1, includepath
);
1860 int (*handler
)(struct stream
*, struct token
**, struct token
*);
1862 { "define", handle_define
},
1863 { "weak_define", handle_weak_define
},
1864 { "strong_define", handle_strong_define
},
1865 { "undef", handle_undef
},
1866 { "strong_undef", handle_strong_undef
},
1867 { "warning", handle_warning
},
1868 { "error", handle_error
},
1869 { "include", handle_include
},
1870 { "include_next", handle_include_next
},
1871 { "pragma", handle_pragma
},
1872 { "line", handle_line
},
1874 // our internal preprocessor tokens
1875 { "nostdinc", handle_nostdinc
},
1876 { "add_include", handle_add_include
},
1877 { "add_isystem", handle_add_isystem
},
1878 { "add_system", handle_add_system
},
1879 { "add_dirafter", handle_add_dirafter
},
1880 { "split_include", handle_split_include
},
1881 { "argv_include", handle_argv_include
},
1883 { "ifdef", handle_ifdef
},
1884 { "ifndef", handle_ifndef
},
1885 { "else", handle_else
},
1886 { "endif", handle_endif
},
1887 { "if", handle_if
},
1888 { "elif", handle_elif
},
1891 for (i
= 0; i
< ARRAY_SIZE(normal
); i
++) {
1893 sym
= create_symbol(stream
, normal
[i
].name
, SYM_PREPROCESSOR
, NS_PREPROCESSOR
);
1894 sym
->handler
= normal
[i
].handler
;
1897 for (i
= 0; i
< ARRAY_SIZE(special
); i
++) {
1899 sym
= create_symbol(stream
, special
[i
].name
, SYM_PREPROCESSOR
, NS_PREPROCESSOR
);
1900 sym
->handler
= special
[i
].handler
;
1907 static void handle_preprocessor_line(struct stream
*stream
, struct token
**line
, struct token
*start
)
1909 int (*handler
)(struct stream
*, struct token
**, struct token
*);
1910 struct token
*token
= start
->next
;
1913 if (eof_token(token
))
1916 if (token_type(token
) == TOKEN_IDENT
) {
1917 struct symbol
*sym
= lookup_symbol(token
->ident
, NS_PREPROCESSOR
);
1919 handler
= sym
->handler
;
1920 is_normal
= sym
->normal
;
1922 handler
= handle_nondirective
;
1924 } else if (token_type(token
) == TOKEN_NUMBER
) {
1925 handler
= handle_line
;
1927 handler
= handle_nondirective
;
1931 dirty_stream(stream
);
1935 if (!handler(stream
, line
, token
)) /* all set */
1939 free_preprocessor_line(token
);
1942 static void preprocessor_line(struct stream
*stream
, struct token
**line
)
1944 struct token
*start
= *line
, *next
;
1945 struct token
**tp
= &start
->next
;
1949 if (next
->pos
.newline
)
1954 *tp
= &eof_token_entry
;
1955 handle_preprocessor_line(stream
, line
, start
);
1958 static void do_preprocess(struct token
**list
)
1962 while (!eof_token(next
= scan_next(list
))) {
1963 struct stream
*stream
= input_streams
+ next
->pos
.stream
;
1965 if (next
->pos
.newline
&& match_op(next
, '#')) {
1966 if (!next
->pos
.noexpand
) {
1967 preprocessor_line(stream
, list
);
1968 __free_token(next
); /* Free the '#' token */
1973 switch (token_type(next
)) {
1974 case TOKEN_STREAMEND
:
1975 if (stream
->top_if
) {
1976 nesting_error(stream
);
1977 sparse_error(stream
->top_if
->pos
, "unterminated preprocessor conditional");
1978 stream
->top_if
= NULL
;
1982 stream
->constant
= CONSTANT_FILE_YES
;
1985 case TOKEN_STREAMBEGIN
:
1990 dirty_stream(stream
);
1991 if (false_nesting
) {
1997 if (token_type(next
) != TOKEN_IDENT
||
1998 expand_one_symbol(list
))
2004 struct token
* preprocess(struct token
*token
)
2007 init_preprocessor();
2008 do_preprocess(&token
);
2010 // Drop all expressions from preprocessing, they're not used any more.
2011 // This is not true when we have multiple files, though ;/
2012 // clear_expression_alloc();
2018 static void dump_macro(struct symbol
*sym
)
2020 int nargs
= sym
->arglist
? sym
->arglist
->count
.normal
: 0;
2021 struct token
*args
[nargs
];
2022 struct token
*token
;
2024 printf("#define %s", show_ident(sym
->ident
));
2025 token
= sym
->arglist
;
2027 const char *sep
= "";
2030 for (; !eof_token(token
); token
= token
->next
) {
2031 if (token_type(token
) == TOKEN_ARG_COUNT
)
2033 printf("%s%s", sep
, show_token(token
));
2034 args
[narg
++] = token
;
2041 token
= sym
->expansion
;
2042 while (!eof_token(token
)) {
2043 struct token
*next
= token
->next
;
2044 switch (token_type(token
)) {
2047 case TOKEN_MACRO_ARGUMENT
:
2048 token
= args
[token
->argnum
];
2051 printf("%s", show_token(token
));
2052 if (next
->pos
.whitespace
)
2060 void dump_macro_definitions(void)
2064 FOR_EACH_PTR(macros
, name
) {
2065 struct symbol
*sym
= lookup_macro(name
);
2068 } END_FOR_EACH_PTR(name
);