Commit Graph

45 Commits

Author SHA1 Message Date
Carl Worth
c42e64099b preprocessor: Initialize a potentially uninitialized variable.
My current reading of the relevant static functions suggests that last
is never used without being uninitialized, (we only use it if the
expansion function returned non-NULL and the expansion functions
always set it before returning non-NULL).

Apparently gcc isn't coming to the same conclusion. Initializing this
to NULL nicely quites gcc and will guarantee a nice, early segfault if
my anaylsis turns out to be wrong.
2010-06-23 16:13:31 -07:00
Carl Worth
726faddda2 preprocessor: Remove dead code _token_list_length
As gcc noticed, this function is not currently being used. Good-bye.
2010-06-23 16:13:31 -07:00
Carl Worth
45cbc08438 preprocessor: Remove dead code _string_list_append_list
As gcc noticed, this function is not currently being used. Good-bye.
2010-06-23 16:13:31 -07:00
Kenneth Graunke
bc1097d151 glcpp: Support line continuations within preprocessor directives.
Fixes CorrectPreprocess5.frag.
2010-06-23 14:14:57 -07:00
Kenneth Graunke
186e2634bf glcpp: Make standalone binary use preprocess().
This prevents the two code paths from getting out of sync.  Also, future
work will need the shader source as a string anyway.

Unfortunately, this copies and pastes load_text_file from main.cpp, with
small changes (support for reading from stdin, talloc).
2010-06-23 14:14:57 -07:00
Kenneth Graunke
12a820c9d8 glcpp: Fix "dangerous trailing context" warning.
Flex couldn't be sure whether "def" and "ndef" were part of the #ifdef
and #ifndef patterns or the trailing context of the #if pattern.
2010-06-23 14:14:57 -07:00
Kenneth Graunke
e6ae7afc0c glcpp: Recognize plain "//" as a comment.
Found in glsl-orangebook-ch06-bump.(frag|vert).  This was resulting in
the comments getting passed through to the main compiler's lexer.
2010-06-23 14:14:57 -07:00
Ian Romanick
b302359394 Add missing build products to gitignore 2010-06-22 12:24:42 -07:00
Kenneth Graunke
1b85c46bcf glcpp: Initialize error state. 2010-06-21 13:55:12 -07:00
Kenneth Graunke
332fc47dc0 glcpp: Accept #elif without an expression if the expression doesn't matter.
Issue a warning.  nVidia's compiler seems to accept this; apparently
GCC < 4.4 did as well: http://gcc.gnu.org/gcc-4.4/porting_to.html
2010-06-21 12:41:05 -07:00
Kenneth Graunke
74704e80c6 glcpp: Print to the main compiler's infolog, not stdout. 2010-06-21 12:41:05 -07:00
Kenneth Graunke
4a2bbdacfc Use yy_scan_string and stop caring about shader->SourceLen.
We had to call strlen on the preprocessed source, which seemed a bit
pointless; also, we updated shader->SourceLen but not shader->Source,
which was even more confusing.  Just leave both untouched.
2010-06-21 12:41:05 -07:00
Kenneth Graunke
26e761edb2 glcpp: Rework handling of "defined" operator.
It's now done in the grammar, and as a result, can easily handle
parenthesis.  defined ( identifier ) is now supported.

Fixes glcpp/tests/065-if-defined-parens.c.
2010-06-21 12:41:05 -07:00
Kenneth Graunke
bac0e371e3 glcpp/tests: Add a test for #if defined (identifier)
Previously we only tested #if defined identifier (without parenthesis).
2010-06-21 12:41:05 -07:00
Kenneth Graunke
6587574354 glcpp: Ignore junk tokens at end of #ifdef/#ifndef (with warning)
Both nVidia's compiler and GCC accept this.
Fixes CorrectPreprocess11.frag.
2010-06-21 12:41:05 -07:00
Kenneth Graunke
c9529c4d77 glcpp: Add glcpp_warning for printing warnings to the info log. 2010-06-21 12:41:05 -07:00
Kenneth Graunke
62b4b7785a glcpp: Add boolean 'error' flag.
We used to check if the info log is non-empty, but when we print
warnings, this will no longer be valid.
2010-06-21 12:39:49 -07:00
Kenneth Graunke
33eaa3e0b3 glcpp: Rename "errors" to "info_log."
Eventually, we'll want to be be able to print out warnings as well.
2010-06-21 12:38:39 -07:00
Kenneth Graunke
03ee33809f glcpp: Don't include newlines as part of #version-passthrough.
Fixes glcpp/tests/064-version.c.
2010-06-21 12:31:04 -07:00
Kenneth Graunke
214632f527 glcpp/tests: Add a test for #version followed by #define.
This isn't really a C file, but...that's probably okay.
2010-06-21 12:31:04 -07:00
Kenneth Graunke
8f32221638 glcpp: Fix line and column numbering.
Lines were off by one, and column numbering was completely daft.
2010-06-21 12:31:03 -07:00
Kenneth Graunke
e8e93a4543 glcpp: Remove calls to exit().
Calling exit() would be really bad once integrated into mesa.  Even in
the standalone binary, we want to print the error log first.

Since each case already flags an error, compilation will still fail,
but it may go on (with something fudged) and generate more errors.
2010-06-21 12:31:03 -07:00
Kenneth Graunke
0774523d18 glcpp: Add line locations to "Unterminated #if" error message. 2010-06-21 12:31:03 -07:00
Kenneth Graunke
8a132aa08b glcpp: Add line locations to various mismatched #if error messages. 2010-06-21 12:31:03 -07:00
Kenneth Graunke
dcdf62f1c6 glcpp: Add line locations to "reserved name" error messages. 2010-06-21 12:31:03 -07:00
Kenneth Graunke
ca9e5fce25 glcpp: Print locations in error messages where possible. 2010-06-21 12:31:03 -07:00
Kenneth Graunke
f1e6c069fa glcpp: Introduce new glcpp_error function. 2010-06-21 12:31:02 -07:00
Kenneth Graunke
b78c9ddfbf glcpp: Set locations on tokens. 2010-06-21 11:31:56 -07:00
Kenneth Graunke
db938103c7 glcpp: Set line locations in the lexer. 2010-06-21 11:31:56 -07:00
Kenneth Graunke
465e03ee07 glcpp: Add plumbing to support line locations. 2010-06-21 11:31:55 -07:00
Kenneth Graunke
f70f60739a glcpp: Add %error-verbose. 2010-06-21 11:31:55 -07:00
Kenneth Graunke
77260fc0a0 glcpp: Actually support #ifdef and #ifndef.
Strangely, the lexer never created these tokens, even though the parser
already had code to handle them.
2010-06-21 11:31:55 -07:00
Kenneth Graunke
e0e429fca3 glcpp: Build a reentrant parser. 2010-06-21 11:31:55 -07:00
Kenneth Graunke
b673ff91ab glcpp: Print errors on stdout instead of stderr (non-standalone version).
Otherwise, piglit marks tests as "warn" when the shader was (correctly)
failing.
2010-06-21 11:31:55 -07:00
Kenneth Graunke
3370c5f90b glcpp/tests: Add extra newline at the end of expected output.
This newline at EOF is harmless and generated by the previous commit.
2010-06-21 11:31:55 -07:00
Kenneth Graunke
f82d673648 glcpp: Handle missing newline at EOF.
Fixes CorrectFuncOverload.vert.
2010-06-21 11:31:55 -07:00
Kenneth Graunke
739ba06680 glcpp: Complain about unrecognized directives. 2010-06-21 11:31:55 -07:00
Kenneth Graunke
3b73ea36c4 glcpp: Pass #version, #extension, and #pragma directives through unchanged.
Let the main compiler's lexer/parser handle them.
2010-06-21 11:31:55 -07:00
Kenneth Graunke
04ba86a536 Make the main compiler call the preprocessor.
By using a single function, the main compiler doesn't need to include
glcpp.h, which currently has a lot of details about the preprocessor
internals.  In particular, this prevents the two yacc grammars from
seeing each other, which would be rather messy to sort out.
2010-06-21 11:31:54 -07:00
Kenneth Graunke
1b1f43e608 glcpp: Add support for lexing from a string.
The standalone binary still reads from stdin, however.
2010-06-21 11:25:50 -07:00
Kenneth Graunke
4c8a1af811 glcpp: Output to a buffer and error log rather than directly printing.
In the standalone case, simply print the buffers when done.
2010-06-21 11:25:50 -07:00
Kenneth Graunke
0656f6b875 glcpp: Fix a case of == where = probably ought to be.
Caught by a GCC warning.
2010-06-21 11:25:50 -07:00
Kenneth Graunke
cbaab7093c Add glcpp to the build. 2010-06-21 11:25:48 -07:00
Kenneth Graunke
254a485c33 Specify %option prefix="glcpp_" in the source code, not the Makefile. 2010-06-21 11:25:30 -07:00
Kenneth Graunke
6f510a49d2 Merge Carl's preprocessor into the glcpp subdirectory. 2010-06-21 11:22:11 -07:00