summaryrefslogtreecommitdiff
AgeCommit message (Collapse)Author
2010-05-26stashCarl Worth
2010-05-26Implement token pasting.Carl Worth
Which makes test 40 now pass.
2010-05-26Rename identifier from 'i' to 'node'.Carl Worth
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 Worth
All the code referencing these was removed some time ago.
2010-05-26Prevent unexpanded macros from being expanded again in the future.Carl Worth
With this fix, tests 37 - 39 now pass.
2010-05-26README: Document some known limitations.Carl Worth
None of these are fundamental---just a few things that haven't been implemented yet.
2010-05-26Fix a typo in a comment.Carl Worth
Always better to use proper grammar in our grammar.
2010-05-26Expand macro arguments before performing argument substitution.Carl Worth
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 Worth
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 Worth
With this fix, test 32 no longer recurses infinitely, but now passes.
2010-05-26Defer test 26 until much later (to test 55).Carl Worth
Supporting embedded newlines in a macro invocation is going to be tricky with our current approach to lexing and parsing. Since this isn't really an important feature for us, we can defer this until more important things are resolved. With this test out of the way, tests 27 through 31 are passing.
2010-05-25Avoid getting extra trailing whitespace from macros.Carl Worth
This trailing whitespace was coming from macro definitions and from macro arguments. We fix this with a little extra state in the token_list. It now remembers the last non-space token added, so that these can be trimmed off just before printing the list. With this fix test 23 now passes. Tests 24 and 25 are also passing, but they probbably would ahve before this fix---just that they weren't being run earlier.
2010-05-25Remove a bunch of old code and give the static treatment to what's left.Carl Worth
We're no longer using the expansion stack, so its functions can go along with most of the body of glcpp_parser_lex that was using it.
2010-05-25Avoid swallowing initial left parenthesis from nested macro invocation.Carl Worth
We weren't including this left parenthesis in the argument's token list so the nested function invocation wasn not being recognized. With this fix, tests 21 and 22 now pass.
2010-05-25Ignore separating whitespace at the beginning of a macro argument.Carl Worth
This causes test 16 to pass. Tests 17-20 are also passing now, (though they would probably have passed before this change and simply weren't being run yet).
2010-05-25Implement substitution of function parameters in macro calls.Carl Worth
This makes tests 16 - 19 pass.
2010-05-25Collapse multiple spaces in input down to a single space.Carl Worth
This is what gcc does, and it's actually less work to do this. Previously we were having to save the contents of space tokens as a string, but we don't need to do that now. We extend test #0 to exercise this feature here.
2010-05-25Add a test #0 to ensure that we don't do any inadvertent token pasting.Carl Worth
This simply ensures that spaces in input line are preserved.
2010-05-25Pass through literal space values from replacement lists.Carl Worth
This makes test 15 pass and also dramatically simplifies the lexer. We were previously using a CONTROL state in the lexer to only emit SPACE tokens when on text lines. But that's not actually what we want. We need SPACE tokens in the replacement lists as well. Instead of a lexer state for this, we now simply set a "space_tokens" flag whenever we start constructing a pp_tokens list and clear the flag whenever we see a '#' introducing a directive. Much cleaner this way.
2010-05-25Implement simplified substitution for function-like macro invocation.Carl Worth
This supports function-like macro invocation but without any argument substitution. This now makes test 11 through 14 pass.
2010-05-25Implement #undef.Carl Worth
Which is as simple as copying the former action back from the git history. Now all tests through test 11 pass.
2010-05-25Implement expansion of object-like macros.Carl Worth
For this we add an "active" string_list_t to the parser. This makes the current expansion_list_t in the parser obsolete, but we don't remove that yet. With this change we can now start passing some actual tests, so we turn on real testing in the test suite again. I expect to implement things more or less in the same order as before, so the test suite now halts on first error. With this change the first 8 tests in the suite pass, (object-like macros with chaining and recursion).
2010-05-25Make the lexer pass whitespace through (as OTHER tokens) for text lines.Carl Worth
With this change, we can recreate the original text-line input exactly. Previously we were inserting a space between every pair of tokens so our output had a lot more whitespace than our input. With this change, we can drop the "-b" option to diff and match the input exactly.
2010-05-25Store parsed tokens as token list and print all text lines.Carl Worth
Still not doing any macro expansion just yet. But it should be fairly easy from here.
2010-05-25Delete some trailing whitespace.Carl Worth
This pernicious stuff managed to sneak in on us.
2010-05-25Add xtalloc_reference.Carl Worth
Yet another talloc wrapper that should come in handy.
2010-05-25Starting over with the C99 grammar for the preprocessor.Carl Worth
This is a fresh start with a much simpler approach for the flex/bison portions of the preprocessor. This isn't functional yet, (produces no output), but can at least read all of our test cases without any parse errors. The grammar here is based on the grammar provided for the preprocessor in the C99 specification.
2010-05-24Add test for '/', '<<', and '>>' in #if expressions.Carl Worth
These operators have been supported already, but were not covered in existing tests yet. So this test passes already.
2010-05-24Add test of bitwise operators and octal/hexadecimal literals.Carl Worth
This new test covers several features from the last few commits. This test passes already.
2010-05-24Add support for octal and hexadecimal integer literals.Carl Worth
In addition to the decimal literals which we already support. Note that we use strtoll here to get the large-width integers demanded by the specification.
2010-05-24Switch to intmax_t (rather than int) for #if expressionsCarl Worth
This is what the C99 specification demands. And the GLSL specification says that we should follow the "standard C++" rules for #if condition expressions rather than the GLSL rules, (which only support a 32-bit integer).
2010-05-24Add the '~' operator to the lexer.Carl Worth
This was simply missing before, (and unnoticed since we had no test of the '~' operator).
2010-05-24Implement all operators specified for GLSL #if expressions (with tests).Carl Worth
The operator coverage here is quite complete. The one big thing missing is that we are not yet doing macro expansion in #if lines. This makes the whole support fairly useless, so we plan to fix that shortcoming right away.
2010-05-20Implement #if, #else, #elif, and #endif with tests.Carl Worth
So far the only expression implemented is a single integer literal, but obviously that's easy to extend. Various things including nesting are tested here.
2010-05-20Implement (and add test) for token pasting.Carl Worth
This is *very* easy to implement now that macro arguments are pre-expanded.
2010-05-20Pre-expand macro arguments at time of invocation.Carl Worth
Previously, we were using the same lexing stack as we use for macro expansion to also expand macro arguments. Instead, we now do this earlier by simply recursing over the macro-invocations replacement list and constructing a new expanded list, (and pushing only *that* onto the stack). This is simpler, and also allows us to more easily implement token pasting in the future.
2010-05-20Add xtalloc_asprintfCarl Worth
I expect this to be useful in the upcoming implementation of token pasting.
2010-05-20Finish cleaning up whitespace differences.Carl Worth
The last remaining thing here was that when a line ended with a macro, and the parser looked ahead to the newline token, the lexer was printing that newline before the parser printed the expansion of the macro. The fix is simple, just make the lexer tell the parser that a newline is needed, and the parser can wait until reducing a production to print that newline. With this, we now pass the entire test suite with simply "diff -u", so we no longer have any diff options hiding whitespace bugs from us. Hurrah!
2010-05-20Avoid printing a space at the beginning of lines in the output.Carl Worth
This fixes more differences compared to "gcc -E" so removes several cases of erroneously failing test cases. The implementation isn't very elegant, but it is functional.
2010-05-20Fix bug of consuming excess whitespace.Carl Worth
We fix this by moving printing up to the top-level "input" action and tracking whether a space is needed between one token and the next. This fixes all actual bugs in test-suite output, but does leave some tests failing due to differences in the amount of whitespace produced, (which aren't actual bugs per se).
2010-05-20Remove unused function _print_string_listCarl Worth
The only good dead code is non-existing dead code.
2010-05-20Remove "unnecessary" whitespace from some tests.Carl Worth
This whitespace was not part of anything being tested, and it introduces differences (that we don't actually care about) between the output of "gcc -E" and glcpp. Just eliminate this extra whitespace to reduce spurious test-case failures.
2010-05-20Stop ignoring whitespace while testing.Carl Worth
Sometime back the output of glcpp started differing from the output of "gcc -E" in the amount of whitespace in emitted. At the time, I switched the test suite to use "diff -w" to ignore this. This was a mistake since it ignores whitespace entirely. (I meant to use "diff -b" which ignores only changes in the amount of whitespace.) So bugs have since been introduced that the test suite doesn't notice. For example, glcpp is producing "twotokens" where it should be producing "two tokens". Let's stop ignoring whitespace in the test suite, which currently introduces lots of failures---some real and some spurious.
2010-05-20Add test (and fix) for a function argument of a macro that expands with a comma.Carl Worth
The fix here is quite simple (and actually only deletes code). When expanding a macro, we don't return a ',' as a unique token type, but simply let it fall through to the generic case.
2010-05-20Add support for commas within parenthesized groups in function arguments.Carl Worth
The specification says that commas within a parenthesized group, (that's not a function-like macro invocation), are passed through literally and not considered argument separators in any outer macro invocation. Add support and a test for this case. This support makes a third occurrence of the same "FUNC_MACRO (" shift/reduce conflict appear, so expect that. This change does introduce a fairly large copy/paste block in the grammar which is unfortunate. Perhaps if I were more clever I'd find a way to share the common pieces between argument and argument_or_comma.
2010-05-20Avoid re-expanding a macro name that has once been rejected from expansion.Carl Worth
The specification of the preprocessor in C99 says that when we see a macro name that we are already expanding that we refuse to expand it now, (which we've done for a while), but also that we refuse to ever expand it later if seen in other contexts at which it would be legitimate to expand. We add a test case for that here, and fix it to work. The fix takes advantage of a new token_t value for tokens and argument words along with the recently added IDENTIFIER_FINALIZED token type which instructs the parser to not even look for another expansion.
2010-05-19Use new token_list_t rather than string_list_t for macro values.Carl Worth
There's not yet any change in functionality here, (at least according to the test suite). But we now have the option of specifying a type for each string in the token list. This will allow us to finalize an unexpanded macro name so that it won't be subjected to excess expansion later.
2010-05-19Perform "re lexing" on string list values rathern than on text.Carl Worth
Previously, we would pass original strings back to the original lexer whenever we needed to re-lex something, (such as an expanded macro or a macro argument). Now, we instead parse the macro or argument originally to a string list, and then re-lex by simply returning each string from this list in turn. We do this in the recently added glcpp_parser_lex function that sits on top of the lower-level glcpp_lex that only deals with text. This doesn't change any behavior (at least according to the existing test suite which all still passes) but it brings us much closer to being able to "finalize" an unexpanded macro as required by the specification.
2010-05-19Remove unused NEWLINE token.Carl Worth
We fixed the lexer a while back to never return a NEWLINE token, but negelcted to clean up this declaration.
2010-05-19Remove unneeded YYLEX_PARAM define.Carl Worth
I'm not sure where this came from, but it's clearly not needed.