[cfe-commits] r61911 - in /cfe/trunk: include/clang/Lex/PTHLexer.h lib/Lex/PTHLexer.cpp lib/Lex/Preprocessor.cpp

Chris Lattner clattner at apple.com
Thu Jan 8 11:19:14 PST 2009


On Jan 7, 2009, at 6:47 PM, Ted Kremenek wrote:

> Author: kremenek
> Date: Wed Jan  7 20:47:16 2009
> New Revision: 61911
>
> URL: http://llvm.org/viewvc/llvm-project?rev=61911&view=rev
> Log:
> PTH:
> - Added stub PTHLexer::getSpelling() that will be used for fetching  
> cached
>  spellings from the PTH file.  This doesn't do anything yet.
> - Added a hook in Preprocessor::getSpelling() to call  
> PTHLexer::getSpelling()
>  when using a PTHLexer.
> - Updated PTHLexer to read the offsets of spelling tables in the PTH  
> file.

Ok.

> +  // If using PTH, try and get the spelling from the PTH file.
> +  if (CurPTHLexer) {
> +    // We perform the const_cast<> here because we will only have a  
> PTHLexer
> +    // when grabbing a stream of tokens from the PTH file (and thus  
> the
> +    // Preprocessor state is allowed to change).  The PTHLexer can  
> assume we are
> +    // getting token spellings in the order of tokens, and thus can  
> update
> +    // its internal state so that it can quickly fetch spellings  
> from the PTH
> +    // file.
> +    unsigned len =
> +      const_cast<PTHLexer*>(CurPTHLexer.get())- 
> >getSpelling(Tok.getLocation(),
> +                                                            Buffer);

Are you sure this const_cast is needed?  If it really is, maybe the  
state poked at by getSpelling should be made mutable?

-Chris



More information about the cfe-commits mailing list