From: Fariborz Jahanian Date: Wed, 5 Sep 2007 19:52:07 +0000 (+0000) Subject: 1. Fix parsing of method prototype involving c-style argument declarations. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=0ccb27ded12fd03eb6818a880f50901bb70254fe;p=clang 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. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@41723 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/Parse/ParseExpr.cpp b/Parse/ParseExpr.cpp index c2b5482855..f030e5d91d 100644 --- a/Parse/ParseExpr.cpp +++ b/Parse/ParseExpr.cpp @@ -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); diff --git a/Parse/ParseObjc.cpp b/Parse/ParseObjc.cpp index f82555a9b6..cb65c1c27a 100644 --- a/Parse/ParseObjc.cpp +++ b/Parse/ParseObjc.cpp @@ -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(); diff --git a/include/clang/Parse/Parser.h b/include/clang/Parse/Parser.h index 9d8021a24c..f05a2ec5b5 100644 --- a/include/clang/Parse/Parser.h +++ b/include/clang/Parse/Parser.h @@ -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 index 0000000000..6399f040a9 --- /dev/null +++ b/test/Parser/method-prototype-1.m @@ -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