summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.gitignore3
-rw-r--r--Makefile2
-rw-r--r--glcpp-lex.l4
-rw-r--r--glcpp-parse.y174
-rw-r--r--glcpp.h8
-rw-r--r--tests/000-content-with-spaces.c.expected1
-rw-r--r--tests/001-define.c.expected2
-rw-r--r--tests/002-define-chain.c.expected3
-rw-r--r--tests/003-define-chain-reverse.c.expected3
-rw-r--r--tests/004-define-recursive.c.expected6
-rw-r--r--tests/005-define-composite-chain.c.expected3
-rw-r--r--tests/006-define-composite-chain-reverse.c.expected3
-rw-r--r--tests/007-define-composite-recursive.c.expected6
-rw-r--r--tests/008-define-empty.c.expected2
-rw-r--r--tests/009-undef.c.expected4
-rw-r--r--tests/010-undef-re-define.c.expected6
-rw-r--r--tests/011-define-func-empty.c.expected2
-rw-r--r--tests/012-define-func-no-args.c.expected2
-rw-r--r--tests/013-define-func-1-arg-unused.c.expected2
-rw-r--r--tests/014-define-func-2-arg-unused.c.expected2
-rw-r--r--tests/015-define-object-with-parens.c.expected4
-rw-r--r--tests/016-define-func-1-arg.c.expected2
-rw-r--r--tests/017-define-func-2-args.c.expected2
-rw-r--r--tests/018-define-func-macro-as-parameter.c.expected3
-rw-r--r--tests/019-define-func-1-arg-multi.c.expected2
-rw-r--r--tests/020-define-func-2-arg-multi.c.expected2
-rw-r--r--tests/021-define-func-compose.c.expected3
-rw-r--r--tests/022-define-func-arg-with-parens.c.expected2
-rw-r--r--tests/023-define-extra-whitespace.c.expected8
-rw-r--r--tests/024-define-chain-to-self-recursion.c.expected3
-rw-r--r--tests/025-func-macro-as-non-macro.c.expected2
-rw-r--r--tests/026-define-func-extra-newlines.c.expected3
-rw-r--r--tests/027-define-chain-obj-to-func.c.expected3
-rw-r--r--tests/028-define-chain-obj-to-non-func.c.expected3
-rw-r--r--tests/029-define-chain-obj-to-func-with-args.c.expected3
-rw-r--r--tests/030-define-chain-obj-to-func-compose.c.expected4
-rw-r--r--tests/031-define-chain-func-to-func-compose.c.expected4
-rw-r--r--tests/032-define-func-self-recurse.c.expected2
-rw-r--r--tests/033-define-func-self-compose.c.expected2
-rw-r--r--tests/034-define-func-self-compose-non-func.c.expected2
-rw-r--r--tests/035-define-func-self-compose-non-func-multi-token-argument.c.expected2
-rw-r--r--tests/036-define-func-non-macro-multi-token-argument.c.expected3
-rw-r--r--tests/037-finalize-unexpanded-macro.c.expected3
-rw-r--r--tests/038-func-arg-with-commas.c.expected2
-rw-r--r--tests/039-func-arg-obj-macro-with-comma.c.expected3
-rw-r--r--tests/040-token-pasting.c.expected2
-rw-r--r--tests/041-if-0.c.expected5
-rw-r--r--tests/042-if-1.c.expected5
-rw-r--r--tests/043-if-0-else.c.expected7
-rw-r--r--tests/044-if-1-else.c.expected7
-rw-r--r--tests/045-if-0-elif.c.expected11
-rw-r--r--tests/046-if-1-elsif.c.expected11
-rw-r--r--tests/047-if-elif-else.c.expected11
-rw-r--r--tests/048-if-nested.c.expected11
-rw-r--r--tests/049-if-expression-precedence.c.expected5
-rw-r--r--tests/050-if-defined.c.expected17
-rw-r--r--tests/051-if-relational.c.expected35
-rw-r--r--tests/052-if-bitwise.c.expected20
-rw-r--r--tests/053-if-divide-and-shift.c.expected15
-rw-r--r--tests/054-if-with-macros.c.expected34
-rw-r--r--tests/055-define-chain-obj-to-func-parens-in-text.c.expected3
-rw-r--r--tests/056-macro-argument-with-comma.c.expected4
-rw-r--r--tests/057-empty-arguments.c.expected6
-rw-r--r--tests/058-token-pasting-empty-arguments.c.expected5
-rw-r--r--tests/059-token-pasting-integer.c.expected4
-rw-r--r--tests/060-left-paren-in-macro-right-paren-in-text.c.expected3
-rw-r--r--tests/061-define-chain-obj-to-func-multi.c.expected5
-rw-r--r--tests/062-if-0-skips-garbage.c.expected5
-rw-r--r--tests/063-comments.c.expected13
-rw-r--r--tests/071-punctuator.c.expected1
-rw-r--r--tests/072-token-pasting-same-line.c.expected2
-rw-r--r--tests/099-c99-example.c.expected16
-rwxr-xr-xtests/glcpp-test5
73 files changed, 501 insertions, 77 deletions
diff --git a/.gitignore b/.gitignore
index b88f0cc75c..077db8d8e1 100644
--- a/.gitignore
+++ b/.gitignore
@@ -4,7 +4,4 @@ glcpp-parse.c
glcpp-parse.h
*.o
*~
-tests/*.expected
-tests/*.gcc
-tests/*.glcpp
tests/*.out
diff --git a/Makefile b/Makefile
index 0c06aa880f..3fb44ac3b2 100644
--- a/Makefile
+++ b/Makefile
@@ -22,4 +22,4 @@ test: glcpp
clean:
rm -f glcpp glcpp-lex.c glcpp-parse.c *.o *~
- rm -f tests/*.out tests/*.gcc tests/*.expected tests/*~
+ rm -f tests/*.out tests/*~
diff --git a/glcpp-lex.l b/glcpp-lex.l
index 2aec46a2ed..0d9a75415a 100644
--- a/glcpp-lex.l
+++ b/glcpp-lex.l
@@ -45,6 +45,8 @@ DECIMAL_INTEGER [1-9][0-9]*[uU]?
OCTAL_INTEGER 0[0-7]*[uU]?
HEXADECIMAL_INTEGER 0[xX][0-9a-fA-F]+[uU]?
+NON_STARS_THEN_STARS [^*]*[*]+
+
%%
/* Single-line comments */
@@ -53,7 +55,7 @@ HEXADECIMAL_INTEGER 0[xX][0-9a-fA-F]+[uU]?
}
/* Multi-line comments */
-"/*"([^*]*[*]+[^*/])*[^*]*[*]+"/" {
+"/*"({NON_STARS_THEN_STARS}[^*/])*{NON_STARS_THEN_STARS}"/" {
if (yyextra->space_tokens)
return SPACE;
}
diff --git a/glcpp-parse.y b/glcpp-parse.y
index 5072c48ee8..807cf59509 100644
--- a/glcpp-parse.y
+++ b/glcpp-parse.y
@@ -52,12 +52,6 @@ _string_list_append_item (string_list_t *list, const char *str);
static void
_string_list_append_list (string_list_t *list, string_list_t *tail);
-static void
-_string_list_push (string_list_t *list, const char *str);
-
-static void
-_string_list_pop (string_list_t *list);
-
static int
_string_list_contains (string_list_t *list, const char *member, int *index);
@@ -96,6 +90,20 @@ _token_list_append (token_list_t *list, token_t *token);
static void
_token_list_append_list (token_list_t *list, token_list_t *tail);
+static int
+_token_list_length (token_list_t *list);
+
+static active_list_t *
+_active_list_push (active_list_t *list,
+ const char *identifier,
+ token_node_t *marker);
+
+static active_list_t *
+_active_list_pop (active_list_t *list);
+
+int
+_active_list_contains (active_list_t *list, const char *identifier);
+
static void
_glcpp_parser_evaluate_defined (glcpp_parser_t *parser,
token_list_t *list);
@@ -468,42 +476,6 @@ _string_list_append_item (string_list_t *list, const char *str)
list->tail = node;
}
-void
-_string_list_push (string_list_t *list, const char *str)
-{
- string_node_t *node;
-
- node = xtalloc (list, string_node_t);
- node->str = xtalloc_strdup (node, str);
- node->next = list->head;
-
- if (list->tail == NULL) {
- list->tail = node;
- }
- list->head = node;
-}
-
-void
-_string_list_pop (string_list_t *list)
-{
- string_node_t *node;
-
- node = list->head;
-
- if (node == NULL) {
- fprintf (stderr, "Internal error: _string_list_pop called on an empty list.\n");
- exit (1);
- }
-
- list->head = node->next;
- if (list->tail == node) {
- assert (node->next == NULL);
- list->tail = NULL;
- }
-
- talloc_free (node);
-}
-
int
_string_list_contains (string_list_t *list, const char *member, int *index)
{
@@ -716,6 +688,21 @@ _token_list_trim_trailing_space (token_list_t *list)
}
}
+static int
+_token_list_length (token_list_t *list)
+{
+ int length = 0;
+ token_node_t *node;
+
+ if (list == NULL)
+ return 0;
+
+ for (node = list->head; node; node = node->next)
+ length++;
+
+ return length;
+}
+
static void
_token_print (token_t *token)
{
@@ -880,7 +867,7 @@ glcpp_parser_create (void)
glcpp_lex_init_extra (parser, &parser->scanner);
parser->defines = hash_table_ctor (32, hash_table_string_hash,
hash_table_string_compare);
- parser->active = _string_list_create (parser);
+ parser->active = NULL;
parser->lexing_if = 0;
parser->space_tokens = 1;
parser->newline_as_space = 0;
@@ -969,7 +956,7 @@ typedef enum function_status
* Macro name not followed by a '('. This is not an error, but
* simply that the macro name should be treated as a non-macro.
*
- * FUNCTION_UNBLANCED_PARENTHESES
+ * FUNCTION_UNBALANCED_PARENTHESES
*
* Macro name is not followed by a balanced set of parentheses.
*/
@@ -1078,6 +1065,9 @@ _glcpp_parser_expand_function (glcpp_parser_t *parser,
case FUNCTION_NOT_A_FUNCTION:
return NULL;
case FUNCTION_UNBALANCED_PARENTHESES:
+ fprintf (stderr, "Error: Macro %s call has unbalanced parentheses\n",
+ identifier);
+ exit (1);
return NULL;
}
@@ -1176,10 +1166,6 @@ _glcpp_parser_expand_function (glcpp_parser_t *parser,
substituted->non_space_tail = substituted->tail;
- _string_list_push (parser->active, identifier);
- _glcpp_parser_expand_token_list (parser, substituted);
- _string_list_pop (parser->active);
-
return substituted;
}
@@ -1206,7 +1192,6 @@ _glcpp_parser_expand_node (glcpp_parser_t *parser,
token_t *token = node->token;
const char *identifier;
macro_t *macro;
- token_list_t *expansion;
/* We only expand identifiers */
if (token->type != IDENTIFIER) {
@@ -1231,7 +1216,7 @@ _glcpp_parser_expand_node (glcpp_parser_t *parser,
/* Finally, don't expand this macro if we're already actively
* expanding it, (to avoid infinite recursion). */
- if (_string_list_contains (parser->active, identifier, NULL)) {
+ if (_active_list_contains (parser->active, identifier)) {
/* We change the token type here from IDENTIFIER to
* OTHER to prevent any future expansion of this
* unexpanded token. */
@@ -1254,18 +1239,63 @@ _glcpp_parser_expand_node (glcpp_parser_t *parser,
if (macro->replacements == NULL)
return _token_list_create (parser);
- expansion = _token_list_copy (parser, macro->replacements);
-
- _string_list_push (parser->active, identifier);
- _glcpp_parser_expand_token_list (parser, expansion);
- _string_list_pop (parser->active);
-
- return expansion;
+ return _token_list_copy (parser, macro->replacements);
}
return _glcpp_parser_expand_function (parser, node, last);
}
+/* Push a new identifier onto the active list, returning the new list.
+ *
+ * Here, 'marker' is the token node that appears in the list after the
+ * expansion of 'identifier'. That is, when the list iterator begins
+ * examinging 'marker', then it is time to pop this node from the
+ * active stack.
+ */
+active_list_t *
+_active_list_push (active_list_t *list,
+ const char *identifier,
+ token_node_t *marker)
+{
+ active_list_t *node;
+
+ node = xtalloc (list, active_list_t);
+ node->identifier = xtalloc_strdup (node, identifier);
+ node->marker = marker;
+ node->next = list;
+
+ return node;
+}
+
+active_list_t *
+_active_list_pop (active_list_t *list)
+{
+ active_list_t *node = list;
+
+ if (node == NULL)
+ return NULL;
+
+ node = list->next;
+ talloc_free (list);
+
+ return node;
+}
+
+int
+_active_list_contains (active_list_t *list, const char *identifier)
+{
+ active_list_t *node;
+
+ if (list == NULL)
+ return 0;
+
+ for (node = list; node; node = node->next)
+ if (strcmp (node->identifier, identifier) == 0)
+ return 1;
+
+ return 0;
+}
+
/* Walk over the token list replacing nodes with their expansion.
* Whenever nodes are expanded the walking will walk over the new
* nodes, continuing to expand as necessary. The results are placed in
@@ -1288,10 +1318,27 @@ _glcpp_parser_expand_token_list (glcpp_parser_t *parser,
node = list->head;
while (node) {
+
+ while (parser->active && parser->active->marker == node)
+ parser->active = _active_list_pop (parser->active);
+
/* Find the expansion for node, which will replace all
* nodes from node to last, inclusive. */
expansion = _glcpp_parser_expand_node (parser, node, &last);
if (expansion) {
+ token_node_t *n;
+
+ for (n = node; n != last->next; n = n->next)
+ while (parser->active &&
+ parser->active->marker == n)
+ {
+ parser->active = _active_list_pop (parser->active);
+ }
+
+ parser->active = _active_list_push (parser->active,
+ node->token->value.str,
+ last->next);
+
/* Splice expansion into list, supporting a
* simple deletion if the expansion is
* empty. */
@@ -1317,17 +1364,10 @@ _glcpp_parser_expand_token_list (glcpp_parser_t *parser,
node = node_prev ? node_prev->next : list->head;
}
- list->non_space_tail = list->tail;
-}
+ while (parser->active)
+ parser->active = _active_list_pop (parser->active);
-static void
-_glcpp_parser_expand_token_list_onto (glcpp_parser_t *parser,
- token_list_t *list,
- token_list_t *result)
-{
- _glcpp_parser_expand_token_list (parser, list);
-
- _token_list_append_list (result, list);
+ list->non_space_tail = list->tail;
}
void
diff --git a/glcpp.h b/glcpp.h
index 41fc2043d1..4459daa4f3 100644
--- a/glcpp.h
+++ b/glcpp.h
@@ -123,10 +123,16 @@ typedef struct skip_node {
struct skip_node *next;
} skip_node_t;
+typedef struct active_list {
+ const char *identifier;
+ token_node_t *marker;
+ struct active_list *next;
+} active_list_t;
+
struct glcpp_parser {
yyscan_t scanner;
struct hash_table *defines;
- string_list_t *active;
+ active_list_t *active;
int lexing_if;
int space_tokens;
int newline_as_space;
diff --git a/tests/000-content-with-spaces.c.expected b/tests/000-content-with-spaces.c.expected
new file mode 100644
index 0000000000..a7fc918c90
--- /dev/null
+++ b/tests/000-content-with-spaces.c.expected
@@ -0,0 +1 @@
+this is four tokens
diff --git a/tests/001-define.c.expected b/tests/001-define.c.expected
new file mode 100644
index 0000000000..a464d9da74
--- /dev/null
+++ b/tests/001-define.c.expected
@@ -0,0 +1,2 @@
+
+1
diff --git a/tests/002-define-chain.c.expected b/tests/002-define-chain.c.expected
new file mode 100644
index 0000000000..c6c9ee38a9
--- /dev/null
+++ b/tests/002-define-chain.c.expected
@@ -0,0 +1,3 @@
+
+
+1
diff --git a/tests/003-define-chain-reverse.c.expected b/tests/003-define-chain-reverse.c.expected
new file mode 100644
index 0000000000..c6c9ee38a9
--- /dev/null
+++ b/tests/003-define-chain-reverse.c.expected
@@ -0,0 +1,3 @@
+
+
+1
diff --git a/tests/004-define-recursive.c.expected b/tests/004-define-recursive.c.expected
new file mode 100644
index 0000000000..2d07687f8c
--- /dev/null
+++ b/tests/004-define-recursive.c.expected
@@ -0,0 +1,6 @@
+
+
+
+foo
+bar
+baz
diff --git a/tests/005-define-composite-chain.c.expected b/tests/005-define-composite-chain.c.expected
new file mode 100644
index 0000000000..892975c268
--- /dev/null
+++ b/tests/005-define-composite-chain.c.expected
@@ -0,0 +1,3 @@
+
+
+a 1
diff --git a/tests/006-define-composite-chain-reverse.c.expected b/tests/006-define-composite-chain-reverse.c.expected
new file mode 100644
index 0000000000..892975c268
--- /dev/null
+++ b/tests/006-define-composite-chain-reverse.c.expected
@@ -0,0 +1,3 @@
+
+
+a 1
diff --git a/tests/007-define-composite-recursive.c.expected b/tests/007-define-composite-recursive.c.expected
new file mode 100644
index 0000000000..0b0b477d9d
--- /dev/null
+++ b/tests/007-define-composite-recursive.c.expected
@@ -0,0 +1,6 @@
+
+
+
+a b c foo
+b c a bar
+c a b baz
diff --git a/tests/008-define-empty.c.expected b/tests/008-define-empty.c.expected
new file mode 100644
index 0000000000..139597f9cb
--- /dev/null
+++ b/tests/008-define-empty.c.expected
@@ -0,0 +1,2 @@
+
+
diff --git a/tests/009-undef.c.expected b/tests/009-undef.c.expected
new file mode 100644
index 0000000000..9c0b35a451
--- /dev/null
+++ b/tests/009-undef.c.expected
@@ -0,0 +1,4 @@
+
+1
+
+foo
diff --git a/tests/010-undef-re-define.c.expected b/tests/010-undef-re-define.c.expected
new file mode 100644
index 0000000000..5970f49028
--- /dev/null
+++ b/tests/010-undef-re-define.c.expected
@@ -0,0 +1,6 @@
+
+1
+
+foo
+
+2
diff --git a/tests/011-define-func-empty.c.expected b/tests/011-define-func-empty.c.expected
new file mode 100644
index 0000000000..139597f9cb
--- /dev/null
+++ b/tests/011-define-func-empty.c.expected
@@ -0,0 +1,2 @@
+
+
diff --git a/tests/012-define-func-no-args.c.expected b/tests/012-define-func-no-args.c.expected
new file mode 100644
index 0000000000..9f075f2600
--- /dev/null
+++ b/tests/012-define-func-no-args.c.expected
@@ -0,0 +1,2 @@
+
+bar
diff --git a/tests/013-define-func-1-arg-unused.c.expected b/tests/013-define-func-1-arg-unused.c.expected
new file mode 100644
index 0000000000..a464d9da74
--- /dev/null
+++ b/tests/013-define-func-1-arg-unused.c.expected
@@ -0,0 +1,2 @@
+
+1
diff --git a/tests/014-define-func-2-arg-unused.c.expected b/tests/014-define-func-2-arg-unused.c.expected
new file mode 100644
index 0000000000..a464d9da74
--- /dev/null
+++ b/tests/014-define-func-2-arg-unused.c.expected
@@ -0,0 +1,2 @@
+
+1
diff --git a/tests/015-define-object-with-parens.c.expected b/tests/015-define-object-with-parens.c.expected
new file mode 100644
index 0000000000..a70321a4c5
--- /dev/null
+++ b/tests/015-define-object-with-parens.c.expected
@@ -0,0 +1,4 @@
+
+()1()
+
+()2()
diff --git a/tests/016-define-func-1-arg.c.expected b/tests/016-define-func-1-arg.c.expected
new file mode 100644
index 0000000000..6bfe04f738
--- /dev/null
+++ b/tests/016-define-func-1-arg.c.expected
@@ -0,0 +1,2 @@
+
+((bar)+1)
diff --git a/tests/017-define-func-2-args.c.expected b/tests/017-define-func-2-args.c.expected
new file mode 100644
index 0000000000..f7a2b8c26c
--- /dev/null
+++ b/tests/017-define-func-2-args.c.expected
@@ -0,0 +1,2 @@
+
+((bar)*(baz))
diff --git a/tests/018-define-func-macro-as-parameter.c.expected b/tests/018-define-func-macro-as-parameter.c.expected
new file mode 100644
index 0000000000..c6c9ee38a9
--- /dev/null
+++ b/tests/018-define-func-macro-as-parameter.c.expected
@@ -0,0 +1,3 @@
+
+
+1
diff --git a/tests/019-define-func-1-arg-multi.c.expected b/tests/019-define-func-1-arg-multi.c.expected
new file mode 100644
index 0000000000..1e89b8cfd0
--- /dev/null
+++ b/tests/019-define-func-1-arg-multi.c.expected
@@ -0,0 +1,2 @@
+
+(this is more than one word)
diff --git a/tests/020-define-func-2-arg-multi.c.expected b/tests/020-define-func-2-arg-multi.c.expected
new file mode 100644
index 0000000000..19f59f5ecb
--- /dev/null
+++ b/tests/020-define-func-2-arg-multi.c.expected
@@ -0,0 +1,2 @@
+
+one fish,two fish,red fish,blue fish
diff --git a/tests/021-define-func-compose.c.expected b/tests/021-define-func-compose.c.expected
new file mode 100644
index 0000000000..87f51f0bac
--- /dev/null
+++ b/tests/021-define-func-compose.c.expected
@@ -0,0 +1,3 @@
+
+
+(2*((1+(3))))
diff --git a/tests/022-define-func-arg-with-parens.c.expected b/tests/022-define-func-arg-with-parens.c.expected
new file mode 100644
index 0000000000..1dfc6698bb
--- /dev/null
+++ b/tests/022-define-func-arg-with-parens.c.expected
@@ -0,0 +1,2 @@
+
+(argument(including parens)for the win)
diff --git a/tests/023-define-extra-whitespace.c.expected b/tests/023-define-extra-whitespace.c.expected
new file mode 100644
index 0000000000..9c58275d0f
--- /dev/null
+++ b/tests/023-define-extra-whitespace.c.expected
@@ -0,0 +1,8 @@
+
+
+
+
+1
+2
+3 4
+5 6 7
diff --git a/tests/024-define-chain-to-self-recursion.c.expected b/tests/024-define-chain-to-self-recursion.c.expected
new file mode 100644
index 0000000000..15600af546
--- /dev/null
+++ b/tests/024-define-chain-to-self-recursion.c.expected
@@ -0,0 +1,3 @@
+
+
+foo
diff --git a/tests/025-func-macro-as-non-macro.c.expected b/tests/025-func-macro-as-non-macro.c.expected
new file mode 100644
index 0000000000..4a59f0520e
--- /dev/null
+++ b/tests/025-func-macro-as-non-macro.c.expected
@@ -0,0 +1,2 @@
+
+foo bar
diff --git a/tests/026-define-func-extra-newlines.c.expected b/tests/026-define-func-extra-newlines.c.expected
new file mode 100644
index 0000000000..5e3c70f2cc
--- /dev/null
+++ b/tests/026-define-func-extra-newlines.c.expected
@@ -0,0 +1,3 @@
+
+
+bar
diff --git a/tests/027-define-chain-obj-to-func.c.expected b/tests/027-define-chain-obj-to-func.c.expected
new file mode 100644
index 0000000000..94c15f9505
--- /dev/null
+++ b/tests/027-define-chain-obj-to-func.c.expected
@@ -0,0 +1,3 @@
+
+
+success
diff --git a/tests/028-define-chain-obj-to-non-func.c.expected b/tests/028-define-chain-obj-to-non-func.c.expected
new file mode 100644
index 0000000000..94c15f9505
--- /dev/null
+++ b/tests/028-define-chain-obj-to-non-func.c.expected
@@ -0,0 +1,3 @@
+
+
+success
diff --git a/tests/029-define-chain-obj-to-func-with-args.c.expected b/tests/029-define-chain-obj-to-func-with-args.c.expected
new file mode 100644
index 0000000000..94c15f9505
--- /dev/null
+++ b/tests/029-define-chain-obj-to-func-with-args.c.expected
@@ -0,0 +1,3 @@
+
+
+success
diff --git a/tests/030-define-chain-obj-to-func-compose.c.expected b/tests/030-define-chain-obj-to-func-compose.c.expected
new file mode 100644
index 0000000000..bed826e783
--- /dev/null
+++ b/tests/030-define-chain-obj-to-func-compose.c.expected
@@ -0,0 +1,4 @@
+
+
+
+success
diff --git a/tests/031-define-chain-func-to-func-compose.c.expected b/tests/031-define-chain-func-to-func-compose.c.expected
new file mode 100644
index 0000000000..bed826e783
--- /dev/null
+++ b/tests/031-define-chain-func-to-func-compose.c.expected
@@ -0,0 +1,4 @@
+
+
+
+success
diff --git a/tests/032-define-func-self-recurse.c.expected b/tests/032-define-func-self-recurse.c.expected
new file mode 100644
index 0000000000..983f941740
--- /dev/null
+++ b/tests/032-define-func-self-recurse.c.expected
@@ -0,0 +1,2 @@
+
+foo(2*(3))
diff --git a/tests/033-define-func-self-compose.c.expected b/tests/033-define-func-self-compose.c.expected
new file mode 100644
index 0000000000..0818362364
--- /dev/null
+++ b/tests/033-define-func-self-compose.c.expected
@@ -0,0 +1,2 @@
+
+foo(2*(foo(2*(3))))
diff --git a/tests/034-define-func-self-compose-non-func.c.expected b/tests/034-define-func-self-compose-non-func.c.expected
new file mode 100644
index 0000000000..3f808fe665
--- /dev/null
+++ b/tests/034-define-func-self-compose-non-func.c.expected
@@ -0,0 +1,2 @@
+
+foo
diff --git a/tests/035-define-func-self-compose-non-func-multi-token-argument.c.expected b/tests/035-define-func-self-compose-non-func-multi-token-argument.c.expected
new file mode 100644
index 0000000000..09dfdd64e9
--- /dev/null
+++ b/tests/035-define-func-self-compose-non-func-multi-token-argument.c.expected
@@ -0,0 +1,2 @@
+
+1+foo
diff --git a/tests/036-define-func-non-macro-multi-token-argument.c.expected b/tests/036-define-func-non-macro-multi-token-argument.c.expected
new file mode 100644
index 0000000000..580ed9599c
--- /dev/null
+++ b/tests/036-define-func-non-macro-multi-token-argument.c.expected
@@ -0,0 +1,3 @@
+
+
+more success
diff --git a/tests/037-finalize-unexpanded-macro.c.expected b/tests/037-finalize-unexpanded-macro.c.expected
new file mode 100644
index 0000000000..e804d7e4f9
--- /dev/null
+++ b/tests/037-finalize-unexpanded-macro.c.expected
@@ -0,0 +1,3 @@
+
+
+expand(just once)
diff --git a/tests/038-func-arg-with-commas.c.expected b/tests/038-func-arg-with-commas.c.expected
new file mode 100644
index 0000000000..6544adb3a2
--- /dev/null
+++ b/tests/038-func-arg-with-commas.c.expected
@@ -0,0 +1,2 @@
+
+success
diff --git a/tests/039-func-arg-obj-macro-with-comma.c.expected b/tests/039-func-arg-obj-macro-with-comma.c.expected
new file mode 100644
index 0000000000..8a15397a03
--- /dev/null
+++ b/tests/039-func-arg-obj-macro-with-comma.c.expected
@@ -0,0 +1,3 @@
+
+
+(two,words)
diff --git a/tests/040-token-pasting.c.expected b/tests/040-token-pasting.c.expected
new file mode 100644
index 0000000000..48e836ec3f
--- /dev/null
+++ b/tests/040-token-pasting.c.expected
@@ -0,0 +1,2 @@
+
+onetoken
diff --git a/tests/041-if-0.c.expected b/tests/041-if-0.c.expected
new file mode 100644
index 0000000000..8b506b32d5
--- /dev/null
+++ b/tests/041-if-0.c.expected
@@ -0,0 +1,5 @@
+success_1
+
+
+
+success_2
diff --git a/tests/042-if-1.c.expected b/tests/042-if-1.c.expected
new file mode 100644
index 0000000000..a6ae9465a9
--- /dev/null
+++ b/tests/042-if-1.c.expected
@@ -0,0 +1,5 @@
+success_1
+
+success_2
+
+success_3
diff --git a/tests/043-if-0-else.c.expected b/tests/043-if-0-else.c.expected
new file mode 100644
index 0000000000..3d7e6be96c
--- /dev/null
+++ b/tests/043-if-0-else.c.expected
@@ -0,0 +1,7 @@
+success_1
+
+
+
+success_2
+
+success_3
diff --git a/tests/044-if-1-else.c.expected b/tests/044-if-1-else.c.expected
new file mode 100644
index 0000000000..4a31e1cfa9
--- /dev/null
+++ b/tests/044-if-1-else.c.expected
@@ -0,0 +1,7 @@
+success_1
+
+success_2
+
+
+
+success_3
diff --git a/tests/045-if-0-elif.c.expected b/tests/045-if-0-elif.c.expected
new file mode 100644
index 0000000000..a9bb1588e4
--- /dev/null
+++ b/tests/045-if-0-elif.c.expected
@@ -0,0 +1,11 @@
+success_1
+
+
+
+
+
+success_3
+
+
+
+success_4
diff --git a/tests/046-if-1-elsif.c.expected b/tests/046-if-1-elsif.c.expected
new file mode 100644
index 0000000000..a4995713ca
--- /dev/null
+++ b/tests/046-if-1-elsif.c.expected
@@ -0,0 +1,11 @@
+success_1
+
+success_2
+
+
+
+
+
+
+
+success_3
diff --git a/tests/047-if-elif-else.c.expected b/tests/047-if-elif-else.c.expected
new file mode 100644
index 0000000000..54d3086119
--- /dev/null
+++ b/tests/047-if-elif-else.c.expected
@@ -0,0 +1,11 @@
+success_1
+
+
+
+
+
+
+
+success_2
+
+success_3
diff --git a/tests/048-if-nested.c.expected b/tests/048-if-nested.c.expected
new file mode 100644
index 0000000000..8beb9c32c3
--- /dev/null
+++ b/tests/048-if-nested.c.expected
@@ -0,0 +1,11 @@
+success_1
+
+
+
+
+
+
+
+
+
+success_2
diff --git a/tests/049-if-expression-precedence.c.expected b/tests/049-if-expression-precedence.c.expected
new file mode 100644
index 0000000000..729bdd15f8
--- /dev/null
+++ b/tests/049-if-expression-precedence.c.expected
@@ -0,0 +1,5 @@
+
+
+
+success
+
diff --git a/tests/050-if-defined.c.expected b/tests/050-if-defined.c.expected
new file mode 100644
index 0000000000..737eb8d940
--- /dev/null
+++ b/tests/050-if-defined.c.expected
@@ -0,0 +1,17 @@
+
+
+
+success_1
+
+
+
+success_2
+
+
+
+
+
+
+
+success_3
+
diff --git a/tests/051-if-relational.c.expected b/tests/051-if-relational.c.expected
new file mode 100644
index 0000000000..652fefdd43
--- /dev/null
+++ b/tests/051-if-relational.c.expected
@@ -0,0 +1,35 @@
+
+
+
+success_1
+
+
+
+success_2
+
+
+
+
+
+success_3
+
+
+
+
+
+success_3
+
+
+
+
+
+
+
+success_4
+
+
+
+success_5
+
+
+
diff --git a/tests/052-if-bitwise.c.expected b/tests/052-if-bitwise.c.expected
new file mode 100644
index 0000000000..44e52b206e
--- /dev/null
+++ b/tests/052-if-bitwise.c.expected
@@ -0,0 +1,20 @@
+
+
+
+success_1
+
+
+success_2
+
+
+
+
+
+
+success_3
+
+
+success_4
+
+
+
diff --git a/tests/053-if-divide-and-shift.c.expected b/tests/053-if-divide-and-shift.c.expected
new file mode 100644
index 0000000000..7e78e0454e
--- /dev/null
+++ b/tests/053-if-divide-and-shift.c.expected
@@ -0,0 +1,15 @@
+
+
+
+success_1
+
+
+success_2
+
+
+
+
+
+
+success_3
+
diff --git a/tests/054-if-with-macros.c.expected b/tests/054-if-with-macros.c.expected
new file mode 100644
index 0000000000..70f737c90a
--- /dev/null
+++ b/tests/054-if-with-macros.c.expected
@@ -0,0 +1,34 @@
+
+
+
+
+
+
+
+success_1
+
+
+success_2
+
+
+
+
+success_3
+
+
+
+
+success_4
+
+
+
+
+
+
+success_5
+
+
+success_6
+
+
+
diff --git a/tests/055-define-chain-obj-to-func-parens-in-text.c.expected b/tests/055-define-chain-obj-to-func-parens-in-text.c.expected
new file mode 100644
index 0000000000..94c15f9505
--- /dev/null
+++ b/tests/055-define-chain-obj-to-func-parens-in-text.c.expected
@@ -0,0 +1,3 @@
+
+
+success
diff --git a/tests/056-macro-argument-with-comma.c.expected b/tests/056-macro-argument-with-comma.c.expected
new file mode 100644
index 0000000000..bed826e783
--- /dev/null
+++ b/tests/056-macro-argument-with-comma.c.expected
@@ -0,0 +1,4 @@
+
+
+
+success
diff --git a/tests/057-empty-arguments.c.expected b/tests/057-empty-arguments.c.expected
new file mode 100644
index 0000000000..7d97e15e29
--- /dev/null
+++ b/tests/057-empty-arguments.c.expected
@@ -0,0 +1,6 @@
+
+success
+
+success
+
+success
diff --git a/tests/058-token-pasting-empty-arguments.c.expected b/tests/058-token-pasting-empty-arguments.c.expected
new file mode 100644
index 0000000000..e0967a1b95
--- /dev/null
+++ b/tests/058-token-pasting-empty-arguments.c.expected
@@ -0,0 +1,5 @@
+
+ab
+a
+b
+
diff --git a/tests/059-token-pasting-integer.c.expected b/tests/059-token-pasting-integer.c.expected
new file mode 100644
index 0000000000..f1288aa7cb
--- /dev/null
+++ b/tests/059-token-pasting-integer.c.expected
@@ -0,0 +1,4 @@
+
+12
+1000
+identifier2
diff --git a/tests/060-left-paren-in-macro-right-paren-in-text.c.expected b/tests/060-left-paren-in-macro-right-paren-in-text.c.expected
new file mode 100644
index 0000000000..3e5501aa6e
--- /dev/null
+++ b/tests/060-left-paren-in-macro-right-paren-in-text.c.expected
@@ -0,0 +1,3 @@
+
+
+5*2
diff --git a/tests/061-define-chain-obj-to-func-multi.c.expected b/tests/061-define-chain-obj-to-func-multi.c.expected
new file mode 100644
index 0000000000..15eb64b97f
--- /dev/null
+++ b/tests/061-define-chain-obj-to-func-multi.c.expected
@@ -0,0 +1,5 @@
+
+
+
+
+success
diff --git a/tests/062-if-0-skips-garbage.c.expected b/tests/062-if-0-skips-garbage.c.expected
new file mode 100644
index 0000000000..3f2ff2d6cc
--- /dev/null
+++ b/tests/062-if-0-skips-garbage.c.expected
@@ -0,0 +1,5 @@
+
+
+
+
+
diff --git a/tests/063-comments.c.expected b/tests/063-comments.c.expected
new file mode 100644
index 0000000000..4998d76cc2
--- /dev/null
+++ b/tests/063-comments.c.expected
@@ -0,0 +1,13 @@
+
+
+
+f = g /h;
+ l();
+m = n
++ p;
+
+more code here
+
+are not treated like comments.
+
+
diff --git a/tests/071-punctuator.c.expected b/tests/071-punctuator.c.expected
new file mode 100644
index 0000000000..959d682598
--- /dev/null
+++ b/tests/071-punctuator.c.expected
@@ -0,0 +1 @@
+a = b
diff --git a/tests/072-token-pasting-same-line.c.expected b/tests/072-token-pasting-same-line.c.expected
new file mode 100644
index 0000000000..7b80af7e46
--- /dev/null
+++ b/tests/072-token-pasting-same-line.c.expected
@@ -0,0 +1,2 @@
+
+success_1 success_2 success_3
diff --git a/tests/099-c99-example.c.expected b/tests/099-c99-example.c.expected
new file mode 100644
index 0000000000..352bbff48f
--- /dev/null
+++ b/tests/099-c99-example.c.expected
@@ -0,0 +1,16 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+f(2 * (y+1)) + f(2 * (f(2 * (z[0])))) % f(2 * (0)) + t(1);
+f(2 * (2 +(3,4)-0,1)) | f(2 * (~ 5)) & f(2 * (0,1))^m(0,1);
+int i[] = { 1, 23, 4, 5, };
diff --git a/tests/glcpp-test b/tests/glcpp-test
index 24110333a5..396f6e175e 100755
--- a/tests/glcpp-test
+++ b/tests/glcpp-test
@@ -2,9 +2,6 @@
for test in *.c; do
echo "Testing $test"
- ../glcpp < $test > $test.glcpp
- grep -v '^ *$' < $test.glcpp > $test.out || true
- gcc -E $test -o $test.gcc
- grep -v '^#' < $test.gcc | grep -v '^$' | sed -r -e 's/^ +/ /' > $test.expected || true
+ ../glcpp < $test > $test.out
diff -u $test.expected $test.out
done