[cfe-commits] r41200 - in /cfe/trunk: Parse/ParseObjc.cpp Parse/Parser.cpp include/clang/Basic/DiagnosticKinds.def include/clang/Parse/Parser.h

Chris Lattner clattner at apple.com
Wed Aug 22 18:21:22 PDT 2007


On Aug 20, 2007, at 2:31 PM, Steve Naroff wrote:

> Author: snaroff
> Date: Mon Aug 20 16:31:48 2007
> New Revision: 41200
>
> URL: http://llvm.org/viewvc/llvm-project?rev=41200&view=rev
> Log:
>
> Start parsing ObjC classes/categories!

Nice!

> +Parser::DeclTy *Parser::ParseObjCAtInterfaceDeclaration(
> +  SourceLocation atLoc, AttributeList *attrList) {
..

> +  if (Tok.getKind() == tok::l_paren) { // we have a category

Comment is a sentence, needs a "." :)

> +    SourceLocation lparenLoc = ConsumeParen();
> +    SourceLocation categoryLoc, rparenLoc;
> +    IdentifierInfo *categoryId = 0;
> +
> +    // OBJC2: The cateogry name is optional (not an error).

typo: cateogry.

If this is an objc2 feature, should it check getLang().ObjC2?   
Likewise in other places that handle objc2 features in various ways.

> +    if (Tok.getKind() == tok::identifier) {
> +      categoryId = Tok.getIdentifierInfo();
> +      categoryLoc = ConsumeToken();
> +    }
> +    if (Tok.getKind() != tok::r_paren) {
> +      Diag(Tok, diag::err_expected_rparen);
> +      SkipUntil(tok::r_paren, false); // don't stop at ';'
> +      return 0;
> +    }

It might be possible to use Parser::MatchRHSPunctuation to handle this.

...

> +  // Parse a class interface.
> +  IdentifierInfo *superClassId = 0;
> +  SourceLocation superClassLoc;
> +
> +  if (Tok.getKind() == tok::colon) { // a super class is specified.
> +    ConsumeToken();

This is a common idiom.  Do you think it would be worthwhile to add a:

bool Parser::ConsumeIfToken(tokenkind), which could be used like:

   if (ConsumeIfToken(tok::colon)) {
     ...
?

However, one bad thing about this is that it loses the location of  
the token if consumed.

> ====================================================================== 
> ========
> --- cfe/trunk/Parse/Parser.cpp (original)
> +++ cfe/trunk/Parse/Parser.cpp Mon Aug 20 16:31:48 2007
> @@ -370,6 +370,13 @@
>      return Actions.ParsedFreeStandingDeclSpec(CurScope, DS);
>    }
>
> +  // OBJC: This grammar hack allows prefix attributes on class  
> interfaces.

How is this a hack?

> +  if (Tok.getKind() == tok::at) {
> +    SourceLocation AtLoc = ConsumeToken(); // the "@"
> +    if (Tok.getIdentifierInfo()->getObjCKeywordID() ==  
> tok::objc_interface)

This is another common idiom.  It seems like it would be nice to add a:

bool Token::isObjCAtKeyword(...)

method, allowing:

if (Tok.isObjCAtKeyword(tok::objc_interface))

-Chris





More information about the cfe-commits mailing list