summaryrefslogtreecommitdiffstats
path: root/src/glsl/glcpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/glsl/glcpp')
-rw-r--r--src/glsl/glcpp/glcpp-parse.y82
-rw-r--r--src/glsl/glcpp/tests/084-unbalanced-parentheses.c.expected2
-rw-r--r--src/glsl/glcpp/tests/093-divide-by-zero.c.expected4
-rw-r--r--src/glsl/glcpp/tests/094-divide-by-zero-short-circuit.c11
-rw-r--r--src/glsl/glcpp/tests/094-divide-by-zero-short-circuit.c.expected15
-rw-r--r--src/glsl/glcpp/tests/095-recursive-define.c.expected4
-rwxr-xr-xsrc/glsl/glcpp/tests/glcpp-test62
7 files changed, 125 insertions, 55 deletions
diff --git a/src/glsl/glcpp/glcpp-parse.y b/src/glsl/glcpp/glcpp-parse.y
index 1f6e67fa062..6f15e85a122 100644
--- a/src/glsl/glcpp/glcpp-parse.y
+++ b/src/glsl/glcpp/glcpp-parse.y
@@ -95,16 +95,16 @@ _token_list_append_list (token_list_t *list, token_list_t *tail);
static int
_token_list_equal_ignoring_space (token_list_t *a, token_list_t *b);
-static active_list_t *
-_active_list_push (active_list_t *list,
- const char *identifier,
- token_node_t *marker);
+static void
+_parser_active_list_push (glcpp_parser_t *parser,
+ const char *identifier,
+ token_node_t *marker);
-static active_list_t *
-_active_list_pop (active_list_t *list);
+static void
+_parser_active_list_pop (glcpp_parser_t *parser);
-int
-_active_list_contains (active_list_t *list, const char *identifier);
+static int
+_parser_active_list_contains (glcpp_parser_t *parser, const char *identifier);
static void
_glcpp_parser_expand_if (glcpp_parser_t *parser, int type, token_list_t *list);
@@ -1468,7 +1468,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 (_active_list_contains (parser->active, identifier)) {
+ if (_parser_active_list_contains (parser, identifier)) {
/* We change the token type here from IDENTIFIER to
* OTHER to prevent any future expansion of this
* unexpanded token. */
@@ -1498,51 +1498,53 @@ _glcpp_parser_expand_node (glcpp_parser_t *parser,
return _glcpp_parser_expand_function (parser, node, last);
}
-/* Push a new identifier onto the active list, returning the new list.
+/* Push a new identifier onto the parser's active 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
+ * examining '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)
+static void
+_parser_active_list_push (glcpp_parser_t *parser,
+ const char *identifier,
+ token_node_t *marker)
{
active_list_t *node;
- node = ralloc (list, active_list_t);
+ node = ralloc (parser->active, active_list_t);
node->identifier = ralloc_strdup (node, identifier);
node->marker = marker;
- node->next = list;
+ node->next = parser->active;
- return node;
+ parser->active = node;
}
-active_list_t *
-_active_list_pop (active_list_t *list)
+static void
+_parser_active_list_pop (glcpp_parser_t *parser)
{
- active_list_t *node = list;
+ active_list_t *node = parser->active;
- if (node == NULL)
- return NULL;
+ if (node == NULL) {
+ parser->active = NULL;
+ return;
+ }
- node = list->next;
- ralloc_free (list);
+ node = parser->active->next;
+ ralloc_free (parser->active);
- return node;
+ parser->active = node;
}
-int
-_active_list_contains (active_list_t *list, const char *identifier)
+static int
+_parser_active_list_contains (glcpp_parser_t *parser, const char *identifier)
{
active_list_t *node;
- if (list == NULL)
+ if (parser->active == NULL)
return 0;
- for (node = list; node; node = node->next)
+ for (node = parser->active; node; node = node->next)
if (strcmp (node->identifier, identifier) == 0)
return 1;
@@ -1561,6 +1563,7 @@ _glcpp_parser_expand_token_list (glcpp_parser_t *parser,
token_node_t *node_prev;
token_node_t *node, *last = NULL;
token_list_t *expansion;
+ active_list_t *active_initial = parser->active;
if (list == NULL)
return;
@@ -1573,10 +1576,8 @@ _glcpp_parser_expand_token_list (glcpp_parser_t *parser,
while (node) {
while (parser->active && parser->active->marker == node)
- parser->active = _active_list_pop (parser->active);
+ _parser_active_list_pop (parser);
- /* 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;
@@ -1585,12 +1586,12 @@ _glcpp_parser_expand_token_list (glcpp_parser_t *parser,
while (parser->active &&
parser->active->marker == n)
{
- parser->active = _active_list_pop (parser->active);
+ _parser_active_list_pop (parser);
}
- parser->active = _active_list_push (parser->active,
- node->token->value.str,
- last->next);
+ _parser_active_list_push (parser,
+ node->token->value.str,
+ last->next);
/* Splice expansion into list, supporting a
* simple deletion if the expansion is
@@ -1617,8 +1618,11 @@ _glcpp_parser_expand_token_list (glcpp_parser_t *parser,
node = node_prev ? node_prev->next : list->head;
}
- while (parser->active)
- parser->active = _active_list_pop (parser->active);
+ /* Remove any lingering effects of this invocation on the
+ * active list. That is, pop until the list looks like it did
+ * at the beginning of this function. */
+ while (parser->active && parser->active != active_initial)
+ _parser_active_list_pop (parser);
list->non_space_tail = list->tail;
}
diff --git a/src/glsl/glcpp/tests/084-unbalanced-parentheses.c.expected b/src/glsl/glcpp/tests/084-unbalanced-parentheses.c.expected
new file mode 100644
index 00000000000..af49a37369d
--- /dev/null
+++ b/src/glsl/glcpp/tests/084-unbalanced-parentheses.c.expected
@@ -0,0 +1,2 @@
+0:2(8): preprocessor error: syntax error, unexpected $end
+
diff --git a/src/glsl/glcpp/tests/093-divide-by-zero.c.expected b/src/glsl/glcpp/tests/093-divide-by-zero.c.expected
new file mode 100644
index 00000000000..08f183f24f5
--- /dev/null
+++ b/src/glsl/glcpp/tests/093-divide-by-zero.c.expected
@@ -0,0 +1,4 @@
+0:1(13): preprocessor error: division by 0 in preprocessor directive
+
+
+
diff --git a/src/glsl/glcpp/tests/094-divide-by-zero-short-circuit.c b/src/glsl/glcpp/tests/094-divide-by-zero-short-circuit.c
index a9c6f36def8..04497b17913 100644
--- a/src/glsl/glcpp/tests/094-divide-by-zero-short-circuit.c
+++ b/src/glsl/glcpp/tests/094-divide-by-zero-short-circuit.c
@@ -1,2 +1,13 @@
+/* glcpp is generating a division-by-zero error for this case. It's
+ * easy to argue that it should be short-circuiting the evaluation and
+ * not generating the diagnostic (which happens to be what gcc does).
+ * But it doesn't seem like we should force this behavior on our
+ * pre-processor, (and, as always, the GLSL specification of the
+ * pre-processor is too vague on this point).
+ *
+ * If a short-circuit evaluation optimization does get added to the
+ * pre-processor then it would legitimate to update the expected file
+ * for this test.
+*/
#if 1 || (1 / 0)
#endif
diff --git a/src/glsl/glcpp/tests/094-divide-by-zero-short-circuit.c.expected b/src/glsl/glcpp/tests/094-divide-by-zero-short-circuit.c.expected
new file mode 100644
index 00000000000..84fdc50c920
--- /dev/null
+++ b/src/glsl/glcpp/tests/094-divide-by-zero-short-circuit.c.expected
@@ -0,0 +1,15 @@
+0:12(17): preprocessor error: division by 0 in preprocessor directive
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/src/glsl/glcpp/tests/095-recursive-define.c.expected b/src/glsl/glcpp/tests/095-recursive-define.c.expected
new file mode 100644
index 00000000000..c7aa18ff6cb
--- /dev/null
+++ b/src/glsl/glcpp/tests/095-recursive-define.c.expected
@@ -0,0 +1,4 @@
+
+
+B(0, C)
+
diff --git a/src/glsl/glcpp/tests/glcpp-test b/src/glsl/glcpp/tests/glcpp-test
index 5dc08ea6acb..e8f3b546387 100755
--- a/src/glsl/glcpp/tests/glcpp-test
+++ b/src/glsl/glcpp/tests/glcpp-test
@@ -2,6 +2,34 @@
trap 'rm $test.valgrind-errors; exit 1' INT QUIT
+usage ()
+{
+ cat <<EOF
+Usage: glcpp [options...]
+
+Run the test suite for mesa's GLSL pre-processor.
+
+Valid options include:
+
+ --valgrind Run the test suite a second time under valgrind
+EOF
+}
+
+# Parse command-line options
+for option; do
+ if [ "${option}" = '--help' ] ; then
+ usage
+ exit 0
+ elif [ "${option}" = '--valgrind' ] ; then
+ do_valgrind=yes
+ else
+ echo "Unrecognized option: $option" >&2
+ echo >&2
+ usage
+ exit 1
+ fi
+done
+
total=0
pass=0
clean=0
@@ -24,23 +52,25 @@ echo ""
echo "$pass/$total tests returned correct results"
echo ""
-echo "====== Testing for valgrind cleanliness ======"
-for test in *.c; do
- echo -n "Testing $test with valgrind..."
- valgrind --error-exitcode=31 --log-file=$test.valgrind-errors ../glcpp < $test >/dev/null 2>&1
- if [ "$?" = "31" ]; then
- echo "ERRORS"
- cat $test.valgrind-errors
- else
- echo "CLEAN"
- clean=$((clean+1))
- rm $test.valgrind-errors
- fi
-done
+if [ "$do_valgrind" = "yes" ]; then
+ echo "====== Testing for valgrind cleanliness ======"
+ for test in *.c; do
+ echo -n "Testing $test with valgrind..."
+ valgrind --error-exitcode=31 --log-file=$test.valgrind-errors ../glcpp < $test >/dev/null 2>&1
+ if [ "$?" = "31" ]; then
+ echo "ERRORS"
+ cat $test.valgrind-errors
+ else
+ echo "CLEAN"
+ clean=$((clean+1))
+ rm $test.valgrind-errors
+ fi
+ done
-echo ""
-echo "$pass/$total tests returned correct results"
-echo "$clean/$total tests are valgrind-clean"
+ echo ""
+ echo "$pass/$total tests returned correct results"
+ echo "$clean/$total tests are valgrind-clean"
+fi
if [ "$pass" = "$total" ] && [ "$clean" = "$total" ]; then
exit 0