]> granicus.if.org Git - clang/commitdiff
1. Fix parsing of method prototype involving c-style argument declarations.
authorFariborz Jahanian <fjahanian@apple.com>
Wed, 5 Sep 2007 19:52:07 +0000 (19:52 +0000)
committerFariborz Jahanian <fjahanian@apple.com>
Wed, 5 Sep 2007 19:52:07 +0000 (19:52 +0000)
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.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@41723 91177308-0d34-0410-b5e6-96231b3b80d8

Parse/ParseExpr.cpp
Parse/ParseObjc.cpp
include/clang/Parse/Parser.h
test/Parser/method-prototype-1.m [new file with mode: 0644]

index c2b54828556c1d481ecc9f83b4689fda55807f0c..f030e5d91d5beb7b95b3a909ca831441954bc0fc 100644 (file)
@@ -427,11 +427,11 @@ Parser::ParseRHSOfBinaryExpression(ExprResult LHS, unsigned MinPrec) {
 /// [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 @@ Parser::ExprResult Parser::ParseCastExpression(bool isUnaryExpression) {
     return ParseCXXCasts();
   case tok::at:
     return ParseObjCExpression();
+  case tok::l_square:
+    return ParseObjCMessageExpression ();
   default:
     Diag(Tok, diag::err_expected_expression);
     return ExprResult(true);
index f82555a9b6a4a886b8ea04ebd4cd2c70f40f3819..cb65c1c27aecc3fcd99b0ac02e7148928476774d 100644 (file)
@@ -384,10 +384,9 @@ IdentifierInfo *Parser::ParseObjCSelector() {
   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 @@ void Parser::ParseObjCMethodDecl(tok::TokenKind mType, SourceLocation mLoc) {
         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 @@ Parser::ExprResult Parser::ParseObjCExpression() {
   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();
 
index 9d8021a24c19f0cb45849f12553bacabd641eb30..f05a2ec5b56db0d87a877ed046df46be99b77f78 100644 (file)
@@ -354,6 +354,7 @@ private:
   ExprResult ParseObjCStringLiteral();
   ExprResult ParseObjCEncodeExpression();
   ExprResult ParseObjCProtocolExpression();
+  ExprResult ParseObjCMessageExpression();
 
   //===--------------------------------------------------------------------===//
   // C99 6.8: Statements and Blocks.
diff --git a/test/Parser/method-prototype-1.m b/test/Parser/method-prototype-1.m
new file mode 100644 (file)
index 0000000..6399f04
--- /dev/null
@@ -0,0 +1,43 @@
+// RUN: clang %s -parse-noop
+@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, ... ;
+@end