[cfe-commits] r112935 - in /cfe/trunk: include/clang/Lex/Token.h lib/Lex/Preprocessor.cpp lib/Parse/ParseObjc.cpp test/SemaObjCXX/cxxoperator-selector.mm

Fariborz Jahanian fjahanian at apple.com
Fri Sep 3 08:10:26 PDT 2010


On Sep 2, 2010, at 9:36 PM, Chris Lattner wrote:

>
> On Sep 2, 2010, at 6:26 PM, Fariborz Jahanian wrote:
>
>> Author: fjahanian
>> Date: Thu Sep  2 20:26:16 2010
>> New Revision: 112935
>>
>> URL: http://llvm.org/viewvc/llvm-project?rev=112935&view=rev
>> Log:
>> Patch to allow alternative representation of c++
>> operators (and, or, etc.) to be used as selectors
>> to match g++'s behavior.
>
> Hi Fariborz,
>
> Instead of adding this to Token, can you just use  
> SomeToken.getIdentifier()->isCPlusPlusOperatorKeyword() wherever  
> you'd check Tok.isCPlusPlusOpKeyword()?

I tried this first. When we set the Identifier field to 0 when we  
detect such tokens. I tried to remove code which does that. But there  
are
assumptions of Token.getIdentifier() to be 0 and several tests broke.  
So, I use a 1-bit flag instead.

>> if (II.isCPlusPlusOperatorKeyword()) {
>>    Identifier.setIdentifierInfo(0);
...

- Fariborz

>
> -Chris
>
>>
>>
>> Added:
>>   cfe/trunk/test/SemaObjCXX/cxxoperator-selector.mm
>> Modified:
>>   cfe/trunk/include/clang/Lex/Token.h
>>   cfe/trunk/lib/Lex/Preprocessor.cpp
>>   cfe/trunk/lib/Parse/ParseObjc.cpp
>>
>> Modified: cfe/trunk/include/clang/Lex/Token.h
>> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Lex/Token.h?rev=112935&r1=112934&r2=112935&view=diff
>> = 
>> = 
>> = 
>> = 
>> = 
>> = 
>> = 
>> = 
>> = 
>> =====================================================================
>> --- cfe/trunk/include/clang/Lex/Token.h (original)
>> +++ cfe/trunk/include/clang/Lex/Token.h Thu Sep  2 20:26:16 2010
>> @@ -76,7 +76,9 @@
>>    StartOfLine   = 0x01,  // At start of line or only after  
>> whitespace.
>>    LeadingSpace  = 0x02,  // Whitespace exists before this token.
>>    DisableExpand = 0x04,  // This identifier may never be macro  
>> expanded.
>> -    NeedsCleaning = 0x08   // Contained an escaped newline or  
>> trigraph.
>> +    NeedsCleaning = 0x08,  // Contained an escaped newline or  
>> trigraph.
>> +    CPlusPlusOpKeyword = 0x10 // alternative representation of
>> +                              // a C++ operator in objc selectors.
>>  };
>>
>>  tok::TokenKind getKind() const { return (tok::TokenKind)Kind; }
>> @@ -231,6 +233,12 @@
>>  /// newlines in it.
>>  ///
>>  bool needsCleaning() const { return (Flags & NeedsCleaning) ?  
>> true : false; }
>> +
>> +  /// isCPlusPlusOpKeyword - Return true if this token is an  
>> operator
>> +  /// for C++ operator keywords.
>> +  bool isCPlusPlusOpKeyword() const
>> +  { return (Flags & CPlusPlusOpKeyword) ? true : false; }
>> +
>> };
>>
>> /// PPConditionalInfo - Information about the conditional stack  
>> (#if directives)
>>
>> Modified: cfe/trunk/lib/Lex/Preprocessor.cpp
>> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/Preprocessor.cpp?rev=112935&r1=112934&r2=112935&view=diff
>> = 
>> = 
>> = 
>> = 
>> = 
>> = 
>> = 
>> = 
>> = 
>> =====================================================================
>> --- cfe/trunk/lib/Lex/Preprocessor.cpp (original)
>> +++ cfe/trunk/lib/Lex/Preprocessor.cpp Thu Sep  2 20:26:16 2010
>> @@ -613,8 +613,10 @@
>>  // C++ 2.11p2: If this is an alternative representation of a C++  
>> operator,
>>  // then we act as if it is the actual operator and not the textual
>>  // representation of it.
>> -  if (II.isCPlusPlusOperatorKeyword())
>> +  if (II.isCPlusPlusOperatorKeyword()) {
>>    Identifier.setIdentifierInfo(0);
>> +    Identifier.setFlag(Token::CPlusPlusOpKeyword);
>> +  }
>>
>>  // If this is an extension token, diagnose its use.
>>  // We avoid diagnosing tokens that originate from macro definitions.
>>
>> Modified: cfe/trunk/lib/Parse/ParseObjc.cpp
>> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseObjc.cpp?rev=112935&r1=112934&r2=112935&view=diff
>> = 
>> = 
>> = 
>> = 
>> = 
>> = 
>> = 
>> = 
>> = 
>> =====================================================================
>> --- cfe/trunk/lib/Parse/ParseObjc.cpp (original)
>> +++ cfe/trunk/lib/Parse/ParseObjc.cpp Thu Sep  2 20:26:16 2010
>> @@ -553,6 +553,60 @@
>>  MatchRHSPunctuation(tok::r_paren, LHSLoc);
>> }
>>
>> +static void ConvertCPlusPlusOperatorToken(Preprocessor &PP, Token  
>> &Tok) {
>> +  if (!Tok.isCPlusPlusOpKeyword())
>> +    return;
>> +
>> +  switch (Tok.getKind()) {
>> +    case tok::ampamp:
>> +      Tok.setIdentifierInfo(&PP.getIdentifierTable().get("and"));
>> +      Tok.setKind(tok::identifier);
>> +      return;
>> +    case tok::ampequal:
>> +      Tok.setIdentifierInfo(&PP.getIdentifierTable().get("and_eq"));
>> +      Tok.setKind(tok::identifier);
>> +      return;
>> +    case tok::amp:
>> +      Tok.setIdentifierInfo(&PP.getIdentifierTable().get("bitand"));
>> +      Tok.setKind(tok::identifier);
>> +      return;
>> +    case tok::pipe:
>> +      Tok.setIdentifierInfo(&PP.getIdentifierTable().get("pipe"));
>> +      Tok.setKind(tok::identifier);
>> +      return;
>> +    case tok::tilde:
>> +      Tok.setIdentifierInfo(&PP.getIdentifierTable().get("compl"));
>> +      Tok.setKind(tok::identifier);
>> +      return;
>> +    case tok::exclaim:
>> +      Tok.setIdentifierInfo(&PP.getIdentifierTable().get("not"));
>> +      Tok.setKind(tok::identifier);
>> +      return;
>> +    case tok::exclaimequal:
>> +      Tok.setIdentifierInfo(&PP.getIdentifierTable().get("not_eq"));
>> +      Tok.setKind(tok::identifier);
>> +      return;
>> +    case tok::pipepipe:
>> +      Tok.setIdentifierInfo(&PP.getIdentifierTable().get("or"));
>> +      Tok.setKind(tok::identifier);
>> +      return;
>> +    case tok::pipeequal:
>> +      Tok.setIdentifierInfo(&PP.getIdentifierTable().get("or_eq"));
>> +      Tok.setKind(tok::identifier);
>> +      return;
>> +    case tok::caret:
>> +      Tok.setIdentifierInfo(&PP.getIdentifierTable().get("xor"));
>> +      Tok.setKind(tok::identifier);
>> +      return;
>> +    case tok::caretequal:
>> +      Tok.setIdentifierInfo(&PP.getIdentifierTable().get("xor_eq"));
>> +      Tok.setKind(tok::identifier);
>> +      return;
>> +    default:
>> +      return;
>> +  }
>> +}
>> +
>> ///   objc-method-proto:
>> ///     objc-instance-method objc-method-decl objc-method-attributes 
>> [opt]
>> ///     objc-class-method objc-method-decl objc-method-attributes 
>> [opt]
>> @@ -569,7 +623,6 @@
>>
>>  tok::TokenKind methodType = Tok.getKind();
>>  SourceLocation mLoc = ConsumeToken();
>> -
>>  Decl *MDecl = ParseObjCMethodDecl(mLoc, methodType,  
>> IDecl,MethodImplKind);
>>  // Since this rule is used for both method declarations and  
>> definitions,
>>  // the caller is (optionally) responsible for consuming the ';'.
>> @@ -585,6 +638,8 @@
>> ///       in out inout bycopy byref oneway int char float double  
>> void _Bool
>> ///
>> IdentifierInfo *Parser::ParseObjCSelectorPiece(SourceLocation  
>> &SelectorLoc) {
>> +  ConvertCPlusPlusOperatorToken(PP, Tok);
>> +
>>  switch (Tok.getKind()) {
>>  default:
>>    return 0;
>>
>> Added: cfe/trunk/test/SemaObjCXX/cxxoperator-selector.mm
>> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjCXX/cxxoperator-selector.mm?rev=112935&view=auto
>> = 
>> = 
>> = 
>> = 
>> = 
>> = 
>> = 
>> = 
>> = 
>> =====================================================================
>> --- cfe/trunk/test/SemaObjCXX/cxxoperator-selector.mm (added)
>> +++ cfe/trunk/test/SemaObjCXX/cxxoperator-selector.mm Thu Sep  2  
>> 20:26:16 2010
>> @@ -0,0 +1,24 @@
>> +// RUN: %clang_cc1 -fsyntax-only -verify %s
>> +// rdar:// 8328250
>> +
>> + at class NSDate;
>> +
>> + at interface XSGraphDataSet
>> +- and;
>> +- xor;
>> +- or;
>> +
>> +- ||; // expected-error {{expected selector for Objective-C method}}
>> +
>> +- &&; // expected-error {{expected selector for Objective-C method}}
>> +
>> +- (void)dataSetForValuesBetween:(NSDate *)startDate and:(NSDate *) 
>> endDate;
>> + at end
>> +
>> + at implementation XSGraphDataSet
>> +- (id) and{return 0; };
>> +- (id) xor{return 0; };
>> +- (id) or{return 0; };
>> +
>> +- (void)dataSetForValuesBetween:(NSDate *)startDate and:(NSDate *) 
>> endDate { return; }
>> + at end
>>
>>
>> _______________________________________________
>> cfe-commits mailing list
>> cfe-commits at cs.uiuc.edu
>> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
>




More information about the cfe-commits mailing list