summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorBrian Paul <brianp@vmware.com>2009-06-10 12:25:35 -0600
committerBrian Paul <brianp@vmware.com>2009-06-17 11:30:04 -0600
commit2d6008bea51f5a57b12fe3d15ec5e60e32f75b93 (patch)
treefe413b0c744f38b39c2ffb9ec7483755fa058572 /src
parent7323704262761a0346d99d8eee442ff4a5290c5f (diff)
glsl: Handle continuation characters in preprocessor.
(cherry picked from master, commit cc22620e4b11425997f3bc1fc70f4c88cec22d2e)
Diffstat (limited to 'src')
-rw-r--r--src/mesa/shader/slang/slang_preprocess.c65
1 files changed, 63 insertions, 2 deletions
diff --git a/src/mesa/shader/slang/slang_preprocess.c b/src/mesa/shader/slang/slang_preprocess.c
index 5455ba68626..69536165e07 100644
--- a/src/mesa/shader/slang/slang_preprocess.c
+++ b/src/mesa/shader/slang/slang_preprocess.c
@@ -1306,6 +1306,44 @@ error:
}
+/*
+ * Remove the continuation characters from the input string.
+ * This is the very first step in preprocessing and is effective
+ * even inside comment blocks.
+ * If there is a whitespace between a backslash and a newline,
+ * this is not considered as a line continuation.
+ */
+GLboolean
+_slang_preprocess_backslashes(slang_string *output,
+ const char *input)
+{
+ while (*input) {
+ if (input[0] == '\\') {
+ /* If a newline follows, eat the backslash and the newline. */
+ if (input[1] == '\r') {
+ if (input[2] == '\n') {
+ input += 3;
+ } else {
+ input += 2;
+ }
+ } else if (input[1] == '\n') {
+ if (input[2] == '\r') {
+ input += 3;
+ } else {
+ input += 2;
+ }
+ } else {
+ /* Leave the backslash alone. */
+ slang_string_pushc(output, *input++);
+ }
+ } else {
+ slang_string_pushc(output, *input++);
+ }
+ }
+ return TRUE;
+}
+
+
/**
* Run preprocessor on source code.
* \param extensions indicates which GL extensions are enabled
@@ -1323,6 +1361,7 @@ _slang_preprocess_directives(slang_string *output,
{
grammar pid, eid;
GLboolean success;
+ slang_string without_backslashes;
pid = grammar_load_from_text ((const byte *) (slang_pp_directives_syn));
if (pid == 0) {
@@ -1335,14 +1374,36 @@ _slang_preprocess_directives(slang_string *output,
grammar_destroy (pid);
return GL_FALSE;
}
- success = preprocess_source (output, input, pid, eid, elog, extensions, pragmas);
+
+ slang_string_init(&without_backslashes);
+ success = _slang_preprocess_backslashes(&without_backslashes, input);
+
+ if (0) {
+ _mesa_printf("Pre-processed shader:\n");
+ _mesa_printf("%s", slang_string_cstr(&without_backslashes));
+ _mesa_printf("----------------------\n");
+ }
+
+ if (success) {
+ success = preprocess_source(output,
+ slang_string_cstr(&without_backslashes),
+ pid,
+ eid,
+ elog,
+ extensions,
+ pragmas);
+ }
+
+ slang_string_free(&without_backslashes);
grammar_destroy (eid);
grammar_destroy (pid);
+
if (0) {
_mesa_printf("Post-processed shader:\n");
- _mesa_printf("%s", output->data);
+ _mesa_printf("%s", slang_string_cstr(output));
_mesa_printf("----------------------\n");
}
+
return success;
}