[cfe-dev] [PATCH] C++ nested-name-specifier (Parser)

Argiris Kirtzidis akyrtzi at gmail.com
Fri Aug 1 12:39:20 PDT 2008


Hi,

For the next chapter of the C++ support saga, I've implemented 
nested-name-specifier support ("foo::bar::").

The attached 'pp-caching' patch, modifies Preprocessor::LookAhead 
(making it efficient enough to replace LookNext) and adds 'rewinding' 
functionality.
That is, one can call Preprocessor::EnableRewindAtThisPos, lex and 
consume any number of tokens, and later call Preprocessor::Rewind to 
make the preprocessor re-lex the tokens that were previsouly lexed since 
EnableRewindAtThisPos was called.

This is used by the parser to determine whether a "foo::bar::x" 
construct represents a typename without consuming any tokens. It goes 
something like this:

-EnableRewindAtThisPos()
-Parse 'foo::bar::' tokens
-Check whether 'x' is a typename in the 'foo::bar::' scope
-Rewind()

The Preprocessor modifications should have no impact on its efficiency 
for normal lexing.


The C++ standard does not have a syntactic category for both the global 
scope specifier ('::') and nested-name-specifier ('foo::'), but I found 
that it's simpler to regard them both as a 'C++ scope specifier' and 
have them both treated the same way. For example, "::x", "foo::x", and 
"::foo::x" will all be treated as "[cxx-scope-spec] x" by the parser.


Comments are welcomed!

-Argiris


-------------- next part --------------
A non-text attachment was scrubbed...
Name: pp-caching.patch
Type: text/x-diff
Size: 13314 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20080801/1aa41a0e/attachment.patch>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: nns-parser.patch
Type: text/x-diff
Size: 34992 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20080801/1aa41a0e/attachment-0001.patch>


More information about the cfe-dev mailing list