Commit graph

21 commits

Author SHA1 Message Date
Carl Worth
2be8be0f74 Make macro-expansion productions create string-list values rather than printing
Then we print the final string list up at the top-level content
production along with all other printing.

Additionally, having macro-expansion productions that create values
will make it easier to solve problems like composed function-like
macro invocations in the future.
2010-05-14 11:50:27 -07:00
Carl Worth
04af13539a Move most printing to the action in the content production.
Previously, printing was occurring all over the place. Here we
document that it should all be happening at the top-level content
production, and we move the printing of directive newlines.

The printing of expanded macros is still happening in lower-level
productions, but we plan to fix that soon.
2010-05-14 11:50:27 -07:00
Carl Worth
c5e9855f13 Remove _list suffix from several identifiers.
Instead of "parameter_list" and "replacement_list" just use
"parameters" and "replacements". This is consistent with the existing
"arguments" and keeps the line length down in the face of the
now-longer "string_list_t" rather than "list_t".
2010-05-14 11:50:27 -07:00
Carl Worth
610053b2c6 Rename list_t and node_t to string_list_t and string_node_t.
We'll soon be adding other types of lists, so it will be helpful to
have a qualified name here.
2010-05-14 11:50:27 -07:00
Carl Worth
7f9aa36bbc Fix case of a macro formal parameter matching a defined macro.
Simply need to allow for a macro name to appear in the parameter list.

This makes the recently-added test pass.
2010-05-14 09:53:50 -07:00
Carl Worth
dcc2ecd30d Implement substitution of macro arguments.
Making the two recently-added tests for this functionality now pass.
2010-05-14 09:53:50 -07:00
Carl Worth
48b94da099 Make the lexer return SPACE tokens unconditionally.
It seems strange to always be returning SPACE tokens, but since we
were already needing to return a SPACE token in some cases, this
actually simplifies our lexer.

This also allows us to fix two whitespace-handling differences
compared to "gcc -E" so that now the recent modification to the test
suite passes once again.
2010-05-14 09:48:14 -07:00
Carl Worth
0a93cbbe4f Fix parsing of object-like macro with a definition that begins with '('.
Previously our parser was incorrectly treating this case as a
function-like macro. We fix this by conditionally passing a SPACE
token from the lexer, (but only immediately after the identifier
immediately after #define).
2010-05-14 09:20:13 -07:00
Carl Worth
db35d557a4 Eliminate a reduce/reduce conflict in the function-like macro production.
Previously, an empty argument could be parsed as either an "argument_list"
directly or first as an "argument" and then an "argument_list".

We fix this by removing the possibility of an empty "argument_list"
directly.
2010-05-14 08:47:32 -07:00
Carl Worth
fcbbb46886 Add support for the structure of function-like macros.
We accept the structure of arguments in both macro definition and
macro invocation, but we don't yet expand those arguments. This is
just enough code to pass the recently-added tests, but does not yet
provide any sort of useful function-like macro.
2010-05-13 09:36:23 -07:00
Carl Worth
9f62a7e9e2 Make the lexer distinguish between identifiers and defined macros.
This is just a minor style improvement for now. But the same
mechanism, (having the lexer peek into the table of defined macros),
will be essential when we add function-like macros in addition to the
current object-like macros.
2010-05-13 07:38:29 -07:00
Carl Worth
8bcb6f1777 Remove some redundancy in the top-level production.
Previously we had two copies of all top-level actions, (once in a list
context and once in a non-list context). Much simpler to instead have
a single list-context production with no action and then only have the
actions in their own non-list contexts.
2010-05-12 13:21:20 -07:00
Carl Worth
012295f94c Simplify lexer significantly (remove all stateful lexing).
We are able to remove all state by simply passing NEWLINE through
as a token unconditionally (as opposed to only passing newline when
on a driective line as we did previously).
2010-05-12 13:20:31 -07:00
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
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
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
0b27b5f051 Implment #define
By using the recently-imported hash_table implementation.
2010-05-10 16:16:06 -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