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 8555901..3c37962 100644
--- a/Parse/ParseObjc.cpp
+++ b/Parse/ParseObjc.cpp
@@ -1129,6 +1129,8 @@
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 @@
// 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 b88c381..75d9388 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 cd48862..a5e6875 100644
--- a/include/clang/Parse/Action.h
+++ b/include/clang/Parse/Action.h
@@ -594,6 +594,13 @@
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 66ca274..02cbaa5 100644
--- a/include/clang/Parse/Parser.h
+++ b/include/clang/Parse/Parser.h
@@ -363,6 +363,7 @@
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 0000000..a06d2e6
--- /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:);
+}