summaryrefslogtreecommitdiff
path: root/tests
AgeCommit message (Collapse)Author
2010-05-19Like previous fix, but for object-like macros (and add a test).Carl Worth
The support for an object-like amcro within a macro-invocation argument was also implemented at one level too high in the grammar. Fortunately, this is a very simple fix.
2010-05-19Fix bug as in previous fix, but with multi-token argument.Carl Worth
The previous fix added FUNC_MACRO to a production one higher in teh grammar than it should have. So it prevented a FUNC_MACRO from appearing as part of a mutli-token argument rather than just alone as an argument. Fix this (and add a test).
2010-05-19Fix bug (and test) for an invocation using macro name as a non-macro argumentCarl Worth
This adds a second shift/reduce conflict to our grammar. It's basically the same conflict we had previously, (deciding to shift a '(' after a FUNC_MACRO) but this time in the "argument" context rather than the "content" context. It would be nice to not have these, but I think they are unavoidable (withotu a lot of pain at least) given the preprocessor specification.
2010-05-19Fix bug (and add tests) for a function-like macro defined as itself.Carl Worth
This case worked previously, but broke in the recent rewrite of function- like macro expansion. The recursion was still terminated correctly, but any parenthesized expression after the macro name was still being swallowed even though the identifier was not being expanded as a macro. The fix is to notice earlier that the identifier is an already-expanding macro. We let the lexer know this through the classify_token function so that an already-expanding macro is lexed as an identifier, not a FUNC_MACRO.
2010-05-18Add several tests where the defined value of a macro is (or looks like) a macroCarl Worth
Many of these look quite similar to existing tests that are handled correctly, yet none of these work. For example, in test 30 we have a simple non-function macro "foo" that is defined as "bar(baz(success))" and obviously non-function macro expansion has been working for a long time. Similarly, if we had text of "bar(baz(success))" it would be expanded correctly as well. But when this otherwise functioning text appears as the body of a macro, things don't work at all. This is pointing out a fundamental problem with the current approach. The current code does a recursive expansion of a macro definition, but this doesn't involve the parsing machinery, so it can't actually handle things like an arbitrary nesting of parentheses. The fix will require the parser to stuff macro values back into the lexer to get at all of the existing machinery when expanding macros.
2010-05-17Fix (and add test for) function-like macro invocation with newlines.Carl Worth
The test has a newline before the left parenthesis, and newlines to separate the parentheses from the argument. The fix involves more state in the lexer to only return a NEWLINE token when termniating a directive. This is very similar to our previous fix with extra lexer state to only return the SPACE token when it would be significant for the parser. With this change, the exact number and positioning of newlines in the output is now different compared to "gcc -E" so we add a -B option to diff when testing to ignore that.
2010-05-17Fix bug (and add test) for a function-like-macro appearing as a non-macro.Carl Worth
That is, when a function-like macro appears in the content without parentheses it should be accepted and passed on through, (previously the parser was regarding this as a syntax error).
2010-05-17Add test and fix bug leading to infinite recursion.Carl Worth
The test case here is simply "#define foo foo" and "#define bar foo" and then attempting to expand "bar". Previously, our termination condition for the recursion was overly simple---just looking for the single identifier that began the expansion. We now fix this to maintain a stack of identifiers and terminate when any one of them occurs in the replacement list.
2010-05-14Don't return SPACE tokens unless strictly needed.Carl Worth
This reverts the unconditional return of SPACE tokens from the lexer from commit 48b94da0994b44e41324a2419117dcd81facce8b . That commit seemed useful because it kept the lexer simpler, but the presence of SPACE tokens is causing lots of extra complication for the parser itself, (redundant productions other than whitespace differences, several productions buggy in the case of extra whitespace, etc.) Of course, we'd prefer to never have any whitespace token, but that's not possible with the need to distinguish between "#define foo()" and "#define foo ()". So we'll accept a little bit of pain in the lexer, (enough state to support this special-case token), in exchange for keeping most of the parser blissffully ignorant of whether tokens are separated by whitespace or not. This change does mean that our output now differs from that of "gcc -E", but only in whitespace. So we test with "diff -w now to ignore those differences.
2010-05-14Add test with extra whitespace in macro defintions and invocations.Carl Worth
This whitespace is not dealt with in an elegant way yet so this test does not pass currently.
2010-05-14Add test invoking a macro with an argument containing (non-macro) parentheses.Carl Worth
The macro invocation is defined to consume all text between a set of matched parentheses. We previously tested for inner parentheses from a nested function-like macro invocation. Here we test for inner parentheses occuring on their own, (not part of another macro invocation).
2010-05-14Add test for composed invocation of function-like macros.Carl Worth
This is a case like "foo(bar(x))" where both foo and bar are defined function-like macros. This is not yet parsed correctly so this test fails.
2010-05-14Add test for function-like macro invocations with multiple-token arguments.Carl Worth
These are not yet parsed correctly, so these tests fail.
2010-05-14Add test where a macro formal parameter is the same as an existing macro.Carl Worth
This is a well-defined condition, but something that currently trips up the implementation. Should be easy to fix.
2010-05-14Add tests exercising substitution of arguments in function-like macros.Carl Worth
This capability is the only thing that makes function-like macros interesting. This isn't supported yet so these tests fail for now.
2010-05-14Add some whitespace variations to test 15.Carl Worth
This shows two minor failures in our current parsing (resulting in whitespace-only changes, oso not that significant): 1. We are inserting extra whitespace between tokens not originally separated by whitespace in the replacement list of a macro definition. 2. We are swallowing whitespace separating tokens in the general content.
2010-05-14Add test for an object-like macro with a definition beginning with '('Carl Worth
Our current parser sees "#define foo (" as an identifier token followed by a '(' token and parses this as a function-like macro. That would be correct for "#define foo(" but the preprocessor specification treats this whitespace as significant here so this test currently fails.
2010-05-13Add tests for the structure of function-like macros.Carl Worth
These test only the most basic aspect of parsing of function-like macros. Specifically, none of the definitions of these function like macros use the arguments of the function. No function-like macros are implemented yet, so all of these fail for now.
2010-05-12Add test case to define, undef, and then again define a macro.Carl Worth
Happily, this is another test case that works just fine without any additional code.
2010-05-12Add test for #undef.Carl Worth
Which hasn't been implemented yet, so this test fails.
2010-05-12Add test for an empty definition.Carl Worth
Happily this one passes without needing any additional code.
2010-05-11Add tests defining a macro to be a literal and another macro.Carl Worth
These 3 new tests are modeled after 3 existing tests but made slightly more complex since now instead of definining a new macro to be an existing macro, we define it to be replaced with two tokens, (one a literal, and one an existing macro). These tests all fail currently because the replacement lookup is currently happening on the basis of the entire replacement string rather than on a list of tokens.
2010-05-11Add a couple more tests for chained #define directives.Carl Worth
One with the chained defines in the opposite order, and one with the potential to trigger an infinite-loop bug through mutual recursion. Each of these tests pass already.
2010-05-11Add test for chained #define directives.Carl Worth
Where one macro is defined in terms of another macro. The current implementation does not yet deal with this correctly.
2010-05-10Add a very simple test for the pre-processor.Carl Worth
Validate desired test cases by ensuring the output of glcpp matches the output of the gcc preprocessor, (ignoring any lines of the gcc output beginning with '#'). Only one test case so far with a trivial #define.