| '(' { printf ("("); }
| ')' { printf (")"); }
| ',' { printf (","); }
+| SPACE { printf (" "); }
;
macro:
| DEFINE IDENTIFIER SPACE replacement_list {
_define_object_macro (parser, $2, $4);
}
-| DEFINE IDENTIFIER '(' parameter_list ')' replacement_list {
- _define_function_macro (parser, $2, $4, $6);
+| DEFINE IDENTIFIER '(' parameter_list ')' {
+ list_t *list = _list_create (parser);
+ _define_function_macro (parser, $2, $4, list);
+ }
+| DEFINE IDENTIFIER '(' parameter_list ')' SPACE replacement_list {
+ _define_function_macro (parser, $2, $4, $7);
}
| UNDEF FUNC_MACRO {
list_t *replacement = hash_table_find (parser->defines, $2);
;
replacement_list:
- /* empty */ {
+ word_or_symbol {
$$ = _list_create (parser);
+ _list_append_item ($$, $1);
+ talloc_free ($1);
}
| replacement_list word_or_symbol {
_list_append_item ($1, $2);
| '(' { $$ = xtalloc_strdup (parser, "("); }
| ')' { $$ = xtalloc_strdup (parser, ")"); }
| ',' { $$ = xtalloc_strdup (parser, ","); }
+| SPACE { $$ = xtalloc_strdup (parser, " "); }
;
word:
static void
_print_expanded_macro_recursive (glcpp_parser_t *parser,
const char *token,
- const char *orig,
- int *first)
+ const char *orig)
{
macro_t *macro;
node_t *node;
macro = hash_table_find (parser->defines, token);
if (macro == NULL) {
- printf ("%s%s", *first ? "" : " ", token);
- *first = 0;
+ printf ("%s", token);
} else {
list_t *replacement_list = macro->replacement_list;
for (node = replacement_list->head ; node ; node = node->next) {
token = node->str;
- if (strcmp (token, orig) == 0) {
- printf ("%s%s", *first ? "" : " ", token);
- *first = 0;
- } else {
+ if (strcmp (token, orig) == 0)
+ printf ("%s", token);
+ else
_print_expanded_macro_recursive (parser,
- token, orig,
- first);
- }
+ token, orig);
}
}
}
void
_print_expanded_object_macro (glcpp_parser_t *parser, const char *identifier)
{
- int first = 1;
macro_t *macro;
macro = hash_table_find (parser->defines, identifier);
assert (! macro->is_function);
- _print_expanded_macro_recursive (parser, identifier, identifier, &first);
+ _print_expanded_macro_recursive (parser, identifier, identifier);
}
void
const char *identifier,
list_t *arguments)
{
- int first = 1;
macro_t *macro;
macro = hash_table_find (parser->defines, identifier);
/* XXX: Need to use argument list here in the expansion. */
- _print_expanded_macro_recursive (parser, identifier, identifier, &first);
+ _print_expanded_macro_recursive (parser, identifier, identifier);
}