Commit graph

18 commits

Author SHA1 Message Date
Carl Worth
cd27e6413a Add support for the #undef macro.
This isn't ideal for two reasons:

1. There's a bunch of stateful redundancy in the lexer that should be
   cleaned up.

2. The hash table does not provide a mechanism to delete an entry, so
   we waste memory to add a new NULL entry in front of the existing
   entry with the same key.

But this does at least work, (it passes the recently added undef test
case).
2010-05-12 13:11:50 -07:00
Carl Worth
7bdd1f36d9 Add test for #undef.
Which hasn't been implemented yet, so this test fails.
2010-05-12 13:11:23 -07:00
Carl Worth
39cd7c2f2e Add test for an empty definition.
Happily this one passes without needing any additional code.
2010-05-12 12:49:07 -07:00
Carl Worth
5070a20cd1 Convert lexer to talloc and add xtalloc wrappers.
The lexer was previously using strdup (expecting the parser to free),
but is now more consistent, easier to use, and slightly more efficent
by using talloc along with the parser.

Also, we add xtalloc and xtalloc_strdup wrappers around talloc and
talloc_strdup to put all of the out-of-memory-checking code in one
place.
2010-05-12 12:47:29 -07:00
Carl Worth
33cc400714 Fix defines involving both literals and other defined macros.
We now store a list of tokens in our hash-table rather than a single
string. This lets us replace each macro in the value as necessary.

This code adds a link dependency on talloc which does exactly what we
want in terms of memory management for a parser.

The 3 tests added in the previous commit now pass.
2010-05-12 12:25:34 -07:00
Carl Worth
df2ab5b992 Add tests defining a macro to be a literal and another macro.
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-11 12:39:29 -07:00
Carl Worth
34db0d332e Add a couple more tests for chained #define directives.
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-11 12:35:06 -07:00
Carl Worth
c6d5af3351 Fix to handle chained #define directives.
The fix is as simple as adding a loop to continue to lookup values
in the hash table until one of the following termination conditions:

	1. The token we look up has no definition

	2. We get back the original symbol we started with

This second termination condition prevents infinite iteration.
2010-05-11 12:30:09 -07:00
Carl Worth
49206ef4c8 Add test for chained #define directives.
Where one macro is defined in terms of another macro. The current
implementation does not yet deal with this correctly.
2010-05-11 12:29:22 -07:00
Carl Worth
beb26e8ac3 Add README file describing glcpp.
Mostly this is a place for me to write down the URLs of the GLSL and
C99 specifications that I need to write this code.
2010-05-11 12:20:15 -07:00
Carl Worth
e8c790b3ce Add a very simple test for the pre-processor.
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.
2010-05-10 16:21:10 -07:00
Carl Worth
0b27b5f051 Implment #define
By using the recently-imported hash_table implementation.
2010-05-10 16:16:06 -07:00
Carl Worth
725c17a926 Makefile: Enable debugging of parser.
This compiles the debugging code for teh parser. It's not active
unless the yydebug variable is set to a non-zero value.
2010-05-10 16:14:59 -07:00
Carl Worth
633a692225 Add hash table implementation from glsl2 project.
The preprocessor here is intended to become part of the glsl2 codebase
eventually anyway.
2010-05-10 13:36:26 -07:00
Carl Worth
a70e7bab2b Add .gitignore file.
To ignore generated source files (and glcpp binary).
2010-05-10 13:32:42 -07:00
Carl Worth
a1e32bcff0 Add some compiler warnings and corresponding fixes.
Most of the current problems were (mostly) harmless things like
missing declarations, but there was at least one real error, (reversed
argument order for yyerrror).
2010-05-10 13:32:29 -07:00
Carl Worth
38aa83560b Make the lexer reentrant (to avoid "still reachable" memory).
This allows the final program to be 100% "valgrind clean", (freeing
all memory that it allocates). This will make it much easier to ensure
that any allocation that parser actions perform are also cleaned up.
2010-05-10 11:52:29 -07:00
Carl Worth
3a37b8701c Add the tiniest shell of a flex/bison-based parser.
It doesn't really *do* anything yet---merlely parsing a stream of
whitespace-separated tokens, (and not interpreting them at all).
2010-05-10 11:46:34 -07:00