From: Fariborz Jahanian Date: Mon, 15 Oct 2007 23:39:13 +0000 (+0000) Subject: Patch to parse @selector expressions. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=a0818e3cd7d59d05e6da41015033b5574c3d7893;p=clang Patch to parse @selector expressions. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@43022 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/Parse/ParseObjc.cpp b/Parse/ParseObjc.cpp index 85559019e0..3c379621bf 100644 --- a/Parse/ParseObjc.cpp +++ b/Parse/ParseObjc.cpp @@ -1129,6 +1129,8 @@ Parser::ExprResult Parser::ParseObjCAtExpression(SourceLocation AtLoc) { return ParsePostfixExpressionSuffix(ParseObjCEncodeExpression()); case tok::objc_protocol: return ParsePostfixExpressionSuffix(ParseObjCProtocolExpression()); + case tok::objc_selector: + return ParsePostfixExpressionSuffix(ParseObjCSelectorExpression()); default: Diag(AtLoc, diag::err_unexpected_at); SkipUntil(tok::semi); @@ -1304,3 +1306,43 @@ Parser::ExprResult Parser::ParseObjCProtocolExpression() // FIXME return 0; } + +/// objc-selector-expression +/// @selector '(' objc-keyword-selector ')' +Parser::ExprResult Parser::ParseObjCSelectorExpression() +{ + SourceLocation SelectorLoc = ConsumeToken(); + + if (Tok.isNot(tok::l_paren)) { + Diag(Tok, diag::err_expected_lparen_after, "@selector"); + return 0; + } + + SourceLocation LParenLoc = ConsumeParen(); + SourceLocation sLoc; + IdentifierInfo *SelIdent = ParseObjCSelector(sLoc); + if (!SelIdent && Tok.isNot(tok::colon)) { + + Diag(Tok, diag::err_expected_ident); // missing selector name. + return 0; + } + if (Tok.isNot(tok::r_paren)) + while (1) { + if (Tok.isNot(tok::colon)) { + Diag(Tok, diag::err_expected_colon); + break; + } + ConsumeToken(); // Eat the ':'. + if (Tok.is(tok::r_paren)) + break; + // Check for another keyword selector. + SourceLocation Loc; + SelIdent = ParseObjCSelector(Loc); + if (!SelIdent && Tok.isNot(tok::colon)) + break; + } + SourceLocation RParenLoc = MatchRHSPunctuation(tok::r_paren, LParenLoc); + + // FIXME + return 0; +} \ No newline at end of file diff --git a/clang.xcodeproj/project.pbxproj b/clang.xcodeproj/project.pbxproj index b88c381faa..75d938806b 100644 --- a/clang.xcodeproj/project.pbxproj +++ b/clang.xcodeproj/project.pbxproj @@ -742,6 +742,7 @@ 08FB7793FE84155DC02AAC07 /* Project object */ = { isa = PBXProject; buildConfigurationList = 1DEB923508733DC60010E9CD /* Build configuration list for PBXProject "clang" */; + compatibilityVersion = "Xcode 2.4"; hasScannedForEncodings = 1; mainGroup = 08FB7794FE84155DC02AAC07 /* clang */; projectDirPath = ""; diff --git a/include/clang/Parse/Action.h b/include/clang/Parse/Action.h index cd48862b08..a5e6875c3d 100644 --- a/include/clang/Parse/Action.h +++ b/include/clang/Parse/Action.h @@ -594,6 +594,13 @@ public: return 0; } + virtual ExprResult ParseObjCSelectorExpression(SourceLocation EncLoc, + SourceLocation LParenLoc, + TypeTy *Ty, + SourceLocation RParenLoc) { + return 0; + } + }; /// MinimalAction - Minimal actions are used by light-weight clients of the diff --git a/include/clang/Parse/Parser.h b/include/clang/Parse/Parser.h index 66ca274915..02cbaa5590 100644 --- a/include/clang/Parse/Parser.h +++ b/include/clang/Parse/Parser.h @@ -363,6 +363,7 @@ private: ExprResult ParseObjCAtExpression(SourceLocation AtLocation); ExprResult ParseObjCStringLiteral(); ExprResult ParseObjCEncodeExpression(); + ExprResult ParseObjCSelectorExpression(); ExprResult ParseObjCProtocolExpression(); ExprResult ParseObjCMessageExpression(); diff --git a/test/Parser/selector-1.m b/test/Parser/selector-1.m new file mode 100644 index 0000000000..a06d2e6e61 --- /dev/null +++ b/test/Parser/selector-1.m @@ -0,0 +1,16 @@ +// RUN: clang -parse-noop %s + +typedef struct objc_selector *SEL; + +int main() { + SEL s = @selector(retain); + SEL s1 = @selector(meth1:); + SEL s2 = @selector(retainArgument::); + SEL s3 = @selector(retainArgument:::::); + SEL s4 = @selector(retainArgument:with:); + SEL s5 = @selector(meth1:with:with:); + SEL s6 = @selector(getEnum:enum:bool:); + SEL s7 = @selector(char:float:double:unsigned:short:long:); + + SEL s9 = @selector(:enum:bool:); +}