[cfe-commits] r41723 - in /cfe/trunk: Parse/ParseExpr.cpp Parse/ParseObjc.cpp include/clang/Parse/Parser.h test/Parser/method-prototype-1.m

Fariborz Jahanian fjahanian at apple.com
Wed Sep 5 12:52:07 PDT 2007


Author: fjahanian
Date: Wed Sep  5 14:52:07 2007
New Revision: 41723

URL: http://llvm.org/viewvc/llvm-project?rev=41723&view=rev
Log:
1. Fix parsing of method prototype involving c-style argument declarations.
2. Fixes all allowable key-words used as selectors.
3. Template to do the messaging parse.
4. A test case for all allowable selector names.

Added:
    cfe/trunk/test/Parser/method-prototype-1.m
Modified:
    cfe/trunk/Parse/ParseExpr.cpp
    cfe/trunk/Parse/ParseObjc.cpp
    cfe/trunk/include/clang/Parse/Parser.h

Modified: cfe/trunk/Parse/ParseExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Parse/ParseExpr.cpp?rev=41723&r1=41722&r2=41723&view=diff

==============================================================================
--- cfe/trunk/Parse/ParseExpr.cpp (original)
+++ cfe/trunk/Parse/ParseExpr.cpp Wed Sep  5 14:52:07 2007
@@ -427,11 +427,11 @@
 /// [GNU]   '__builtin_choose_expr' '(' assign-expr ',' assign-expr ','
 ///                                     assign-expr ')'
 /// [GNU]   '__builtin_types_compatible_p' '(' type-name ',' type-name ')'
-/// [OBC]   '[' objc-receiver objc-message-args ']'    [TODO]
-/// [OBC]   '@selector' '(' objc-selector-arg ')'      [TODO]
-/// [OBC]   '@protocol' '(' identifier ')'             [TODO]
-/// [OBC]   '@encode' '(' type-name ')'                [TODO]
-/// [OBC]   objc-string-literal
+/// [OBJC]  '[' objc-message-expr ']'    [TODO]
+/// [OBJC]  '@selector' '(' objc-selector-arg ')'      [TODO]
+/// [OBJC]  '@protocol' '(' identifier ')'             [TODO]
+/// [OBJC]  '@encode' '(' type-name ')'                [TODO]
+/// [OBJC]  objc-string-literal
 /// [C++]   'const_cast' '<' type-name '>' '(' expression ')'       [C++ 5.2p1]
 /// [C++]   'dynamic_cast' '<' type-name '>' '(' expression ')'     [C++ 5.2p1]
 /// [C++]   'reinterpret_cast' '<' type-name '>' '(' expression ')' [C++ 5.2p1]
@@ -590,6 +590,8 @@
     return ParseCXXCasts();
   case tok::at:
     return ParseObjCExpression();
+  case tok::l_square:
+    return ParseObjCMessageExpression ();
   default:
     Diag(Tok, diag::err_expected_expression);
     return ExprResult(true);

Modified: cfe/trunk/Parse/ParseObjc.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Parse/ParseObjc.cpp?rev=41723&r1=41722&r2=41723&view=diff

==============================================================================
--- cfe/trunk/Parse/ParseObjc.cpp (original)
+++ cfe/trunk/Parse/ParseObjc.cpp Wed Sep  5 14:52:07 2007
@@ -384,10 +384,9 @@
   tok::TokenKind tKind = Tok.getKind();
   IdentifierInfo *II = 0;
   
-  if (tKind == tok::identifier || 
+  if (tKind == tok::identifier   || tKind == tok::kw_typeof ||
+      tKind == tok::kw___alignof ||
       (tKind >= tok::kw_auto && tKind <= tok::kw__Complex)) {
-    // FIXME: make sure the list of keywords jives with gcc. For example,
-    // the above test does not include in/out/inout/bycopy/byref/oneway.
     II = Tok.getIdentifierInfo();
     ConsumeToken();
   } 
@@ -516,7 +515,12 @@
         ConsumeToken();
         break;
       }
-      ParseDeclaration(Declarator::PrototypeContext);
+      // Parse the c-style argument declaration-specifier.
+      DeclSpec DS;
+      ParseDeclarationSpecifiers(DS);
+      // Parse the declarator. 
+      Declarator ParmDecl(DS, Declarator::PrototypeContext);
+      ParseDeclarator(ParmDecl);
     }
   } else if (!selIdent) {
     Diag(Tok, diag::err_expected_ident); // missing selector name.
@@ -910,6 +914,37 @@
   return 0;
 }
 
+///   objc-message-expr: 
+///     '[' objc-receiver objc-message-args ']'
+///
+///   objc-receiver:
+///     expression
+///     class-name
+///     type-name
+///  
+///   objc-message-args:
+///     objc-selector
+///     objc-keywordarg-list
+///
+///   objc-keywordarg-list:
+///     objc-keywordarg
+///     objc-keywordarg-list objc-keywordarg
+///
+///   objc-keywordarg: 
+///     selector-name[opt] ':' objc-keywordexpr
+///
+///   objc-keywordexpr:
+///     nonempty-expr-list
+///
+///   nonempty-expr-list:
+///     assignment-expression
+///     nonempty-expr-list , assignment-expression
+///   
+Parser::ExprResult Parser::ParseObjCMessageExpression() {
+  assert(false && "Unimp");
+  return 0;
+}
+
 Parser::ExprResult Parser::ParseObjCStringLiteral() {
   ExprResult Res = ParseStringLiteralExpression();
 

Modified: cfe/trunk/include/clang/Parse/Parser.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Parse/Parser.h?rev=41723&r1=41722&r2=41723&view=diff

==============================================================================
--- cfe/trunk/include/clang/Parse/Parser.h (original)
+++ cfe/trunk/include/clang/Parse/Parser.h Wed Sep  5 14:52:07 2007
@@ -354,6 +354,7 @@
   ExprResult ParseObjCStringLiteral();
   ExprResult ParseObjCEncodeExpression();
   ExprResult ParseObjCProtocolExpression();
+  ExprResult ParseObjCMessageExpression();
 
   //===--------------------------------------------------------------------===//
   // C99 6.8: Statements and Blocks.

Added: cfe/trunk/test/Parser/method-prototype-1.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Parser/method-prototype-1.m?rev=41723&view=auto

==============================================================================
--- cfe/trunk/test/Parser/method-prototype-1.m (added)
+++ cfe/trunk/test/Parser/method-prototype-1.m Wed Sep  5 14:52:07 2007
@@ -0,0 +1,43 @@
+// RUN: clang %s -parse-noop
+ at interface MyObject 
+- (void) bycopy  : (int) woodo, ... ;
+- (void) break  : (int) woodo, ... ;
+- (void) enum  : (int) woodo, ... ;
+- (void) struct  : (int) woodo, ... ;
+- (void) union  : (int) woodo, ... ;
+- (void) if  : (int) woodo, int i, char chh, ... ;
+- (void) else  : (int) woodo, ... ;
+- (void) while  : (int) woodo, ... ;
+- (void) do  : (int) woodo, ... ;
+- (void) for  : (int) woodo, ... ;
+- (void) switch  : (int) woodo, ... ;
+- (void) case  : (int) woodo, ... ;
+- (void) default  : (int) woodo, ... ;
+- (void) break  : (int) woodo, ... ;
+- (void) continue  : (int) woodo, ... ;
+- (void) return  : (int) woodo, ... ;
+- (void) goto  : (int) woodo, ... ;
+- (void) sizeof  : (int) woodo, ... ;
+- (void) typeof  : (int) woodo, ... ;
+- (void) __alignof  : (int) woodo, ... ;
+- (void) unsigned  : (int) woodo, ... ;
+- (void) long  : (int) woodo, ... ;
+- (void) const  : (int) woodo, ... ;
+- (void) short  : (int) woodo, ... ;
+- (void) volatile  : (int) woodo, ... ;
+- (void) signed  : (int) woodo, ... ;
+- (void) restrict  : (int) woodo, ... ;
+- (void) _Complex  : (int) woodo, ... ;
+- (void) in  : (int) woodo, ... ;
+- (void) out  : (int) woodo, ... ;
+- (void) inout  : (int) woodo, ... ;
+- (void) bycopy  : (int) woodo, ... ;
+- (void) byref  : (int) woodo, ... ;
+- (void) oneway  : (int) woodo, ... ;
+- (void) int  : (int) woodo, ... ;
+- (void) char  : (int) woodo, ... ;
+- (void) float  : (int) woodo, ... ;
+- (void) double  : (int) woodo, ... ;
+- (void) void  : (int) woodo, ... ;
+- (void) _Bool  : (int) woodo, ... ;
+ at end





More information about the cfe-commits mailing list