summaryrefslogtreecommitdiff
AgeCommit message (Collapse)AuthorFilesLines
2010-06-09Merge remote branch 'kwg/fixes'HEADmasterCarl Worth1-0/+20
2010-06-04Disallow defining macros whose names start with "__" or "GL_".Kenneth Graunke1-0/+20
The GLSL specification reserves these for future use.
2010-06-02test suite: Add expected output for every test.Carl Worth70-8/+384
Rather than using the (munged) output of "gcc -E" we now capture precisely the output we expect from every test case. This allows us to stay immune from strange output from gcc (unpredictable whitespace output---aprticularly with different gcc versions). This will also allow us to write tests that capture expected error messages from the preprocessor as well.
2010-06-02Restore error message for a macro with unbalanced parentheses.Carl Worth1-1/+4
We had to remove this earlier because our recursive function calls caused the same nodes to be examined for expansion more than once. And in the test suite, one node would be examined before it had its closing parenthesis and then again later after the parenthesis was added. So we removed this error message to allow the test case to pass. Now that we've removed the unnecessary recursive function call we can catch this error case and report it as desired.
2010-06-02Eliminate some recursion from children of _expand_token_listCarl Worth2-57/+110
Previously, both _expand_node and _expand_function would always make mutually recursive calls into _expand_token_list. This was unnecessary since these functions can simply return unexpanded results, after which the outer iteration will next attempt expansion of the results. The only trick in doing this is to arrange so that the active list is popped at the appropriate time. To do this, we add a new token_node_t marker to the active stack. When pushing onto the active list, we set marker to last->next, and when the marker is seen by the token list iteration, we pop from the active stack.
2010-06-02Remove dead code: _glcpp_parser_expand_token_list_ontoCarl Worth1-10/+0
This function simply isn't being called anymore.
2010-06-02Factor out common sub-expression from multi-line-comment regular expression.Carl Worth1-1/+3
In two places we look for an (optional) sequence of characters other than "*" followed by a sequence of on or more "*". Using a name for this (NON_STARS_THEN_STARS) seems to make it a bit easier to understand.
2010-06-02Make the multi-line comment regular expression a bit easier to read.Carl Worth1-1/+1
Use quoted strings for literal portions rather than a sequence of single-character character classes.
2010-06-02Fix multi-line comment regular expression to handle (non) nested comments.Carl Worth2-1/+6
Ken reminded me of a couple cases that I should be testing. These are the non-nestedness of things that look like nested comments as well as potentially tricky things like "/*/" and "/*/*/". The (non) nested comment case was not working in the case of the comment terminator with multiple '*' characters. We fix this by not considering a '*' as the "non-slash" to terminate a sequence of '*' characters within the comment. We also fix the final match of the terminator to use '+' rather than '*' to require the presence of a final '*' character in the comment terminator.
2010-06-01Implement comment handling in the lexer (with test).Carl Worth3-2/+28
We support both single-line (//) and multi-line (/* ... */) comments and add a test for this, (trying to stress the rules just a bit by embedding one comment delimiter into a comment delimited with the other style, etc.). To keep the test suite passing we do now discard any output lines from glcpp that consist only of spacing, (in addition to blank lines as previously). We also discard any initial whitespace from gcc output. In neither case should the absence or presence of this whitespace affect correctness.
2010-06-01Fix #if-skipping to *really* skip the skipped group.Carl Worth4-25/+44
Previously we were avoiding printing within a skipped group, but we were still evluating directives such as #define and #undef and still emitting diagnostics for things such as macro calls with the wrong number of arguments. Add a test for this and fix it with a high-priority rule in the lexer that consumes the skipped content.
2010-05-29Merge branch 'take-2'Carl Worth8-616/+1106
The take-2 branch started over with a new grammar based directly on the grammar from the C99 specification. It doesn't try to capture things like balanced sets of parentheses for macro arguments in the grammar. Instead, it merely captures things as token lists and then performs operations like parsing arguments and expanding macros on those lists. We merge it here since it's currently behaving better, (passing the entire test suite). But the code base has proven quite fragile really. Several of the recently added test cases required additional special cases in the take-2 branch while working trivially on master. So this merge point may be useful in the future, since we might have a cleaner code base by coming back to the state before this merge and fixing it, rather than accepting all the fragile imperative/list-munging code from the take-2 branch.
2010-05-29Add three more tests cases recently added to the take-2 branch.Carl Worth3-0/+20
The 071-punctuator test is failing only trivially (whitespace change only). And the 072-token-pasting-same-line.c test passes just fine here, (more evidence perhaps that the approach in take-2 is more trouble than it's worth?). The 099-c99-example test case is the inspiration for much of the rest of the test suite. It amazingly passes on the take-2 branch, but doesn't pass here yet.
2010-05-29Add killer test case from the C99 specification.Carl Worth1-0/+17
Happily, this passes now, (since many of the previously added test cases were extracted from this one).
2010-05-29Add test and fix bugs with multiple token-pasting on the same line.Carl Worth2-51/+43
The list replacement when token pasting was broken, (failing to properly update the list's tail pointer). Also, memory management when pasting was broken, (modifying the original token's string which would cause problems with multiple calls to a macro which pasted a literal string). We didn't catch this with previous tests because they only pasted argument values.
2010-05-29Fix pass-through of '=' and add a test for it.Carl Worth3-1/+3
Previously '=' was not included in our PUNCTUATION regeular expression, but it *was* excldued from our OTHER regular expression, so we were getting the default (and hamful) lex action of just printing it. The test we add here is named "punctuator" with the idea that we can extend it as needed for other punctuator testing.
2010-05-28Add two more (failing) tests from the take-2 branch.Carl Worth2-0/+8
These tests were recently fixed on the take-2 branch, but will require additional work before they will pass here.
2010-05-28Add two (passing) tests from the take-2 branch.Carl Worth2-0/+6
These two tests were tricky to make work on take-2, but happen to already eb working here.
2010-05-28Tweak test 25 slightly, (so the non-macro doesn't end the file).Carl Worth1-1/+1
This isn't a problem here, but on the take-2 branch, it was trickier at one point to make a non-macro work when the last token of the file. So we use the simpler test case here and defer the other case until later.
2010-05-28Remove some blank lines from the end of some test cases.Carl Worth3-4/+0
To match what we have done on the take-2 branch to these test cases.
2010-05-28Perform macro by replacing tokens in original list.take-2Carl Worth3-99/+187
We take the results of macro expansion and splice them into the original token list over which we are iterating. This makes it easy for function-like macro invocations to find their arguments since they are simply subsequent tokens on the list. This fixes the recently-introduced regressions (tests 55 and 56) and also passes new tests 60 and 61 introduced to strees this feature, (with macro-argument parentheses split between a macro value and the textual input).
2010-05-28Simplify calling conventions of functions under expand_token_list_onto.Carl Worth1-85/+74
We previously had a confusing thing where _expand_token_onto would return a non-zero value to indicate that the caller should then call _expand_function_onto. It's much cleaner for _expand_token_onto to just do what's needed and call the necessary function.
2010-05-28Stop interrupting the test suite at the first failure.Carl Worth1-1/+0
This behavior was useful when starting the implementation over ("take-2") where the whole test suite was failing. This made it easy to focus on one test at a time and get each working. More recently, we got the whole suite working, so we don't need this feature anymore. And in the previous commit, we regressed a couple of tests, so it's nice to be able to see all the failures with a single run of the suite.
2010-05-28Revert "Add support for an object-to-function chain with the parens in the ↵Carl Worth1-49/+16
content." This reverts commit 7db2402a8009772a3f10d19cfc7f30be9ee79295 It doesn't revert the new test case from that commit, just the extremely ugly second-pass implementation.
2010-05-27Remove blank lines from output files before comparing.Carl Worth2-3/+5
Recently I'm seeing cases where "gcc -E" mysteriously omits blank lines, (even though it prints the blank lines in other very similar cases). Rather than trying to decipher and imitate this, just get rid of the blank lines. This approach with sed to kill the lines before the diff is better than "diff -B" since when there is an actual difference, the presence of blank lines won't make the diff harder to read.
2010-05-27Add test for token-pasting of integers.Carl Worth1-0/+4
This test was tricky to make pass in the take-2 branch. It ends up passing already here with no additional effort, (since we are lexing integers as string-valued token except when in the ST_IF state in the lexer anyway).
2010-05-27Implement token pasting of integers.Carl Worth4-17/+33
To do this correctly, we change the lexer to lex integers as string values, (new token type of INTEGER_STRING), and only convert to integer values when evaluating an expression value. Add a new test case for this, (which does pass now).
2010-05-27Add placeholder tokens to support pasting with empty arguments.Carl Worth2-6/+35
Along with a passing test to verify that this works.
2010-05-27Add test for macro invocations with empty arguments.Carl Worth1-0/+6
This case was recently solved on the take-2 branch.
2010-05-27Provide support for empty arguments in macro invocations.Carl Worth2-9/+17
For this we always add a new argument to the argument list as soon as possible, without waiting until we see some argument token. This does mean we need to take some extra care when comparing the number of arguments with the number of expected arguments. In addition to matching numbers, we also support one (empty) argument when zero arguments are expected. Add a test case here for this, which does pass.
2010-05-27Make two list-processing functions do nothing with an empty list.Carl Worth1-1/+4
This just makes these functions easier to understand all around. In the case of _token_list_append_list this is an actual bug fix, (where append an empty list onto a non-empty list would previously scramble the tail pointer of the original list).
2010-05-27Add test 56 for a comma within the expansion of an argument.Carl Worth1-0/+4
This case was tricky on the take-2 branch. It happens to be passing already here.
2010-05-27Avoid treating an expanded comma as an argument separator.Carl Worth2-2/+20
That is, a function-like invocation foo(x) is valid as a single-argument invocation even if 'x' is a macro that expands into a value with a comma. Add a new COMMA_FINAL token type to handle this, and add a test for this case, (which passes).
2010-05-26Add support (and test) for an object-to-function chain with the parens in ↵Carl Worth2-16/+52
the content. That is, the following case: #define foo(x) (x) #define bar bar(baz) which now works with this (ugly) commit. I definitely want to come up with something cleaner than this.
2010-05-26Add two tests developed on the take-2 branch.Carl Worth2-0/+37
The define-chain-obj-to-func-parens-in-text test passes here while the if-with-macros test fails.
2010-05-26Treat newlines as space when invoking a function-like macro invocation.Carl Worth5-3/+67
This adds three new pieces of state to the parser, (is_control_line, newline_as_space, and paren_count), and a large amount of messy code. I'd definitely like to see a cleaner solution for this. With this fix, the "define-func-extra-newlines" now passes so we put it back to test #26 where it was originally (lately it has been known as test #55). Also, we tweak test 25 slightly. Previously this test was ending a file function-like macro name that was not actually a macro (not followed by a left parenthesis). As is, this fix was making that test fail because the text_line production expects to see a terminating NEWLINE, but that NEWLINE is now getting turned into a SPACE here. This seems unlikely to be a problem in the wild, (function macros being used in a non-macro sense seems rare enough---but more than likely they won't happen at the end of a file). Still, we document this shortcoming in the README.
2010-05-26All macro lookups should be of type macro_t, not string_list_t.Carl Worth1-4/+4
This is what I get for using a non-type-safe hash-table implementation.
2010-05-26Implement (and test) support for macro expansion within conditional expressions.Carl Worth3-22/+169
To do this we have split the existing "HASH_IF expression" into two productions: First is HASH_IF pp_tokens which simply constructs a list of tokens. Then, with that resulting token list, we first evaluate all DEFINED operator tokens, then expand all macros, and finally start lexing from the resulting token list. This brings us to the second production, IF_EXPANDED expression This final production works just like our previous "HASH_IF expression", evaluating a constant integer expression. The new test (54) added for this case now passes.
2010-05-26Fix lexing of "defined" as an operator, not an identifier.Carl Worth2-7/+5
Simply need to move the rule for IDENTIFIER to be after "defined" and everything is happy. With this change, tests 50 through 53 all pass now.
2010-05-26Implement #if and friends.Carl Worth4-5/+2
With this change, tests 41 through 49 all pass. (The defined operator appears to be somehow broken so that test 50 doesn't pass yet.)
2010-05-26stashCarl Worth2-5/+176
2010-05-26Implement token pasting.Carl Worth1-0/+117
Which makes test 40 now pass.
2010-05-26Rename identifier from 'i' to 'node'.Carl Worth1-5/+5
Now that we no longer have nested for loops with 'i' and 'j' we can use the 'node' that we already have.
2010-05-26Remove some stale token types.Carl Worth1-3/+0
All the code referencing these was removed some time ago.
2010-05-26Prevent unexpanded macros from being expanded again in the future.Carl Worth1-2/+11
With this fix, tests 37 - 39 now pass.
2010-05-26README: Document some known limitations.Carl Worth1-0/+12
None of these are fundamental---just a few things that haven't been implemented yet.
2010-05-26Fix a typo in a comment.Carl Worth1-1/+1
Always better to use proper grammar in our grammar.
2010-05-26Expand macro arguments before performing argument substitution.Carl Worth1-4/+5
As required by the C99 specification of the preprocessor. With this fix, tests 33 through 36 now pass.
2010-05-26Change macro expansion to append onto token lists rather than printing directly.Carl Worth1-73/+120
This doesn't change any functionality here, but will allow us to make future changes that were not possible with direct printing. Specifically, we need to expand macros within macro arguments before performing argument substitution. And *that* expansion cannot result in immediate printing.
2010-05-26Check active expansions before expanding a function-like macro invocation.Carl Worth1-5/+5
With this fix, test 32 no longer recurses infinitely, but now passes.