[cfe-commits] r150790 - in /cfe/trunk: include/clang/Parse/Parser.h lib/Parse/ParseInit.cpp test/Parser/cxx0x-lambda-expressions.cpp

Douglas Gregor dgregor at apple.com
Fri Feb 17 08:46:33 PST 2012


On Feb 17, 2012, at 12:05 AM, Sebastian Redl wrote:

> 
> On 17.02.2012, at 04:49, Douglas Gregor wrote:
> 
>> Author: dgregor
>> Date: Thu Feb 16 21:49:44 2012
>> New Revision: 150790
>> 
>> URL: http://llvm.org/viewvc/llvm-project?rev=150790&view=rev
>> Log:
>> Disambiguate between C++11 lambda expressions and C99 array
>> designators in the parser. In the worst case, this disambiguation
>> requires tentative parsing just past the closing ']', but for most
>> cases we'll be able to tell by looking ahead just one token (without
>> going into the heavyweight tentative parsing machinery).
>> 
>> Modified:
>>   cfe/trunk/include/clang/Parse/Parser.h
>>   cfe/trunk/lib/Parse/ParseInit.cpp
>>   cfe/trunk/test/Parser/cxx0x-lambda-expressions.cpp
>> 
>> Modified: cfe/trunk/lib/Parse/ParseInit.cpp
>> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseInit.cpp?rev=150790&r1=150789&r2=150790&view=diff
>> ==============================================================================
>> --- cfe/trunk/lib/Parse/ParseInit.cpp (original)
>> +++ cfe/trunk/lib/Parse/ParseInit.cpp Thu Feb 16 21:49:44 2012
>> @@ -21,15 +21,86 @@
>> using namespace clang;
>> 
>> 
>> -/// MayBeDesignationStart - Return true if this token might be the start of a
>> -/// designator.  If we can tell it is impossible that it is a designator, return
>> -/// false.
>> -static bool MayBeDesignationStart(tok::TokenKind K, Preprocessor &PP) {
>> -  switch (K) {
>> -  default: return false;
>> +/// MayBeDesignationStart - Return true if the current token might be the start 
>> +/// of a designator.  If we can tell it is impossible that it is a designator, 
>> +/// return false.
>> +bool Parser::MayBeDesignationStart() {
>> +  switch (Tok.getKind()) {
>> +  default: 
>> +    return false;
>> +      
>>  case tok::period:      // designator: '.' identifier
>> -  case tok::l_square:    // designator: array-designator
>> +    return true;
>> +      
>> +  case tok::l_square: {  // designator: array-designator
>> +    if (!PP.getLangOptions().CPlusPlus0x)
>>      return true;
>> +    
> 
> Maybe reduce nesting by breaking out of the switch here?

Sure. r150817 keeps the easy cases in the switch, but moves the tentative parsing below.

	- Doug

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20120217/fd81ddc7/attachment.html>


More information about the cfe-commits mailing list