]> git.ipfire.org Git - thirdparty/gcc.git/commit - libcpp/include/cpplib.h
Generate virtual locations for tokens
authorTom Tromey <tromey@redhat.com>
Mon, 17 Oct 2011 09:59:12 +0000 (09:59 +0000)
committerDodji Seketeli <dodji@gcc.gnu.org>
Mon, 17 Oct 2011 09:59:12 +0000 (11:59 +0200)
commit92582b753e34fd574b6a5672b2f82979c966187a
tree372dab78d59e4e58eead8df4f751726cec9b98b4
parent46427374e1ffdcb2781d99abc63ebd3ab7af6110
Generate virtual locations for tokens

This second instalment uses the infrastructure of the previous patch
to allocate a macro map for each macro expansion and assign a virtual
location to each token resulting from the expansion.

To date when cpp_get_token comes across a token that happens to be a
macro, the macro expander kicks in, expands the macro, pushes the
resulting tokens onto a "token context" and returns a dummy padding
token. The next call to cpp_get_token goes look into the token context
for the next token [which is going to result from the previous macro
expansion] and returns it.  If the token is a macro, the macro expander
kicks in and you know the story.

This patch piggy-backs on that macro expansion process, so to speak.
First it modifies the macro expander to make it create a macro map for
each macro expansion. It then allocates a virtual location for each
resulting token.  Virtual locations of tokens resulting from macro
expansions are then stored on a special kind of context called an
"expanded tokens context".  In other words, in an expanded tokens
context, there are tokens resulting from macro expansion and their
associated virtual locations.  cpp_get_token_with_location is modified
to return the virtual location of tokens resulting from macro
expansion.  Note that once all tokens from an expanded token context have
been consumed and the context and is freed, the memory used to store the
virtual locations of the tokens held in that context is freed as well.
This helps reducing the overall peak memory consumption.

The client code that was getting macro expansion point location from
cpp_get_token_with_location now gets virtual location from it. Those
virtual locations can in turn be resolved into the different
interesting physical locations thanks to the linemap API exposed by
the previous patch.

Expensive progress. Possibly. So this whole virtual location
allocation business is switched off by default. So by default no
extended token is created. No extended token context is created
either. One has to use -ftrack-macro-expansion to switch this on. This
complicates the code but I believe it can be useful as some of our
friends found out at http://llvm.org/bugs/show_bug.cgi?id=5610

The patch tries to reduce the memory consumption by freeing some token
context memory that was being reused before. I didn't notice any
compilation slow down due to this immediate freeing on my GNU/Linux
system.

As no client code tries to resolve virtual locations to anything but
what was being done before, no new test case has been added.

Co-Authored-By: Dodji Seketeli <dodji@redhat.com>
From-SVN: r180082
17 files changed:
gcc/ChangeLog
gcc/c-family/ChangeLog
gcc/c-family/c-opts.c
gcc/c-family/c.opt
gcc/doc/cppopts.texi
gcc/doc/invoke.texi
gcc/input.c
libcpp/ChangeLog
libcpp/directives.c
libcpp/include/cpplib.h
libcpp/include/line-map.h
libcpp/init.c
libcpp/internal.h
libcpp/lex.c
libcpp/line-map.c
libcpp/macro.c
libcpp/traditional.c