summaryrefslogtreecommitdiff
path: root/glcpp-parse.y
diff options
context:
space:
mode:
authorCarl Worth <cworth@cworth.org>2010-05-25 20:35:01 -0700
committerCarl Worth <cworth@cworth.org>2010-05-25 20:39:33 -0700
commit10ae438399f14367dd9e03032594c1e16c428999 (patch)
treecf8b4ebb7e21d4f2cdfff8df4de65d3e5869a287 /glcpp-parse.y
parent5aa7ea08093f727761d424ad090f44b116c8f0bd (diff)
Avoid getting extra trailing whitespace from macros.
This trailing whitespace was coming from macro definitions and from macro arguments. We fix this with a little extra state in the token_list. It now remembers the last non-space token added, so that these can be trimmed off just before printing the list. With this fix test 23 now passes. Tests 24 and 25 are also passing, but they probbably would ahve before this fix---just that they weren't being run earlier.
Diffstat (limited to 'glcpp-parse.y')
-rw-r--r--glcpp-parse.y30
1 files changed, 28 insertions, 2 deletions
diff --git a/glcpp-parse.y b/glcpp-parse.y
index 02286cd..60eaf21 100644
--- a/glcpp-parse.y
+++ b/glcpp-parse.y
@@ -471,7 +471,7 @@ _token_create_ival (void *ctx, int type, int ival)
}
void
-_token_print (token_t *token)
+_glcpp_parser_print_token (glcpp_parser_t *parser, token_t *token)
{
if (token->type < 256) {
printf ("%c", token->type);
@@ -527,6 +527,7 @@ _token_list_create (void *ctx)
list = xtalloc (ctx, token_list_t);
list->head = NULL;
list->tail = NULL;
+ list->non_space_tail = NULL;
return list;
}
@@ -548,6 +549,8 @@ _token_list_append (token_list_t *list, token_t *token)
}
list->tail = node;
+ if (token->type != SPACE)
+ list->non_space_tail = node;
}
void
@@ -560,6 +563,25 @@ _token_list_append_list (token_list_t *list, token_list_t *tail)
}
list->tail = tail->tail;
+ list->non_space_tail = tail->non_space_tail;
+}
+
+void
+_token_list_trim_trailing_space (token_list_t *list)
+{
+ token_node_t *tail, *next;
+
+ if (list->non_space_tail) {
+ tail = list->non_space_tail->next;
+ list->non_space_tail->next = NULL;
+ list->tail = list->non_space_tail;
+
+ while (tail) {
+ next = tail->next;
+ talloc_free (tail);
+ tail = next;
+ }
+ }
}
void
@@ -618,7 +640,7 @@ _glcpp_parser_print_expanded_token (glcpp_parser_t *parser,
/* We only expand identifiers */
if (token->type != IDENTIFIER) {
- _token_print (token);
+ _glcpp_parser_print_token (parser, token);
return 0;
}
@@ -719,6 +741,8 @@ _arguments_parse (argument_list_t *arguments, token_node_t **node_ret)
if (node->token->type == ',' &&
paren_count == 1)
{
+ if (argument)
+ _token_list_trim_trailing_space (argument);
argument = NULL;
}
else {
@@ -834,6 +858,8 @@ _glcpp_parser_print_expanded_token_list (glcpp_parser_t *parser,
if (list == NULL)
return;
+ _token_list_trim_trailing_space (list);
+
for (node = list->head; node; node = node->next) {
if (_glcpp_parser_print_expanded_token (parser, node->token))
_glcpp_parser_print_expanded_function (parser, &node);