diff options
author | marha <marha@users.sourceforge.net> | 2013-01-14 15:13:52 +0100 |
---|---|---|
committer | marha <marha@users.sourceforge.net> | 2013-01-14 15:13:52 +0100 |
commit | 2a1abdc8fe640583dac90dc316caf2d40b9ee4e2 (patch) | |
tree | 721982dda954c217323cf726bf1ff527b0477ebe /mesalib/src/glsl/glcpp/pp.c | |
parent | ddc05759f098f06bd93253a7bffe38640963dfb3 (diff) | |
download | vcxsrv-2a1abdc8fe640583dac90dc316caf2d40b9ee4e2.tar.gz vcxsrv-2a1abdc8fe640583dac90dc316caf2d40b9ee4e2.tar.bz2 vcxsrv-2a1abdc8fe640583dac90dc316caf2d40b9ee4e2.zip |
libxtrans xwininfo libX11 libXau libXmu libXdmcp mesa mkfontscale
xkeyboard-config git update 14 jan 2013
libxtrans: ec3136232f7ce930f9ca812b6ab42a71b60af4af
xwininfo: 3e60a26559221e561770710a8c4ed0b8ebc31afb
libX11: 3cd974b1d4d1fa6389d3695fa9fcc0c22a51d50c
libXau: 8570d287396934f26224c76d48d7f17d87380e72
libXmu: 9b253d99d5b4f3fbb681c2cb1b84f8f9acfee528
libXdmcp: ca65a92405500393f09d34388edbbf6350e6c146
mesa: e3e1ffb2520498584ef402213d0c8aa4303a46a3
mkfontscale: 1157b3039551b552b483f05f6a411e57941a87c0
Diffstat (limited to 'mesalib/src/glsl/glcpp/pp.c')
-rw-r--r-- | mesalib/src/glsl/glcpp/pp.c | 123 |
1 files changed, 54 insertions, 69 deletions
diff --git a/mesalib/src/glsl/glcpp/pp.c b/mesalib/src/glsl/glcpp/pp.c index 11b29417b..789f7f941 100644 --- a/mesalib/src/glsl/glcpp/pp.c +++ b/mesalib/src/glsl/glcpp/pp.c @@ -70,92 +70,77 @@ glcpp_warning (YYLTYPE *locp, glcpp_parser_t *parser, const char *fmt, ...) &parser->info_log_length, "\n"); } -/* Searches backwards for '^ *#' from a given starting point. */ -static int -in_directive(const char *shader, const char *ptr) -{ - assert(ptr >= shader); - - /* Search backwards for '#'. If we find a \n first, it doesn't count */ - for (; ptr >= shader && *ptr != '#'; ptr--) { - if (*ptr == '\n') - return 0; - } - if (ptr >= shader) { - /* Found '#'...look for spaces preceded by a newline */ - for (ptr--; ptr >= shader && isblank(*ptr); ptr--); - // FIXME: I don't think the '\n' case can happen - if (ptr < shader || *ptr == '\n') - return 1; - } - return 0; -} - -/* Remove any line continuation characters in preprocessing directives. - * However, ignore any in GLSL code, as "There is no line continuation - * character" (1.30 page 9) in GLSL. +/* Remove any line continuation characters in the shader, (whether in + * preprocessing directives or in GLSL code). */ static char * remove_line_continuations(glcpp_parser_t *ctx, const char *shader) { - int in_continued_line = 0; - int extra_newlines = 0; char *clean = ralloc_strdup(ctx, ""); - const char *search_start = shader; - const char *newline; - while ((newline = strchr(search_start, '\n')) != NULL) { - const char *backslash = NULL; - - /* # of characters preceding the newline. */ - int n = newline - shader; - - /* Find the preceding '\', if it exists */ - if (n >= 1 && newline[-1] == '\\') - backslash = newline - 1; - else if (n >= 2 && newline[-1] == '\r' && newline[-2] == '\\') - backslash = newline - 2; - - /* Double backslashes don't count (the backslash is escaped) */ - if (backslash != NULL && backslash[-1] == '\\') { - backslash = NULL; - } - - if (backslash != NULL) { - /* We found a line continuation, but do we care? */ - if (!in_continued_line) { - if (in_directive(shader, backslash)) { - in_continued_line = 1; - extra_newlines = 0; - } - } - if (in_continued_line) { - /* Copy everything before the \ */ - ralloc_strncat(&clean, shader, backslash - shader); + const char *backslash, *newline, *search_start; + int collapsed_newlines = 0; + + search_start = shader; + + while (true) { + backslash = strchr(search_start, '\\'); + + /* If we have previously collapsed any line-continuations, + * then we want to insert additional newlines at the next + * occurrence of a newline character to avoid changing any + * line numbers. + */ + if (collapsed_newlines) { + newline = strchr(search_start, '\n'); + if (newline && + (backslash == NULL || newline < backslash)) + { + ralloc_strncat(&clean, shader, + newline - shader + 1); + while (collapsed_newlines--) + ralloc_strcat(&clean, "\n"); shader = newline + 1; - extra_newlines++; + search_start = shader; } - } else if (in_continued_line) { - /* Copy everything up to and including the \n */ - ralloc_strncat(&clean, shader, newline - shader + 1); - shader = newline + 1; - /* Output extra newlines to make line numbers match */ - for (; extra_newlines > 0; extra_newlines--) - ralloc_strcat(&clean, "\n"); - in_continued_line = 0; } - search_start = newline + 1; + + search_start = backslash + 1; + + if (backslash == NULL) + break; + + /* At each line continuation, (backslash followed by a + * newline), copy all preceding text to the output, then + * advance the shader pointer to the character after the + * newline. + */ + if (backslash[1] == '\n' || + (backslash[1] == '\r' && backslash[2] == '\n')) + { + collapsed_newlines++; + ralloc_strncat(&clean, shader, backslash - shader); + if (backslash[1] == '\n') + shader = backslash + 2; + else + shader = backslash + 3; + search_start = shader; + } } + ralloc_strcat(&clean, shader); + return clean; } int glcpp_preprocess(void *ralloc_ctx, const char **shader, char **info_log, - const struct gl_extensions *extensions, int api) + const struct gl_extensions *extensions, struct gl_context *gl_ctx) { int errors; - glcpp_parser_t *parser = glcpp_parser_create (extensions, api); - *shader = remove_line_continuations(parser, *shader); + glcpp_parser_t *parser = glcpp_parser_create (extensions, gl_ctx->API); + + if (! gl_ctx->Const.DisableGLSLLineContinuations) + *shader = remove_line_continuations(parser, *shader); glcpp_lex_set_source_string (parser, *shader); |