]> granicus.if.org Git - clang/commitdiff
Patch to parse @selector expressions.
authorFariborz Jahanian <fjahanian@apple.com>
Mon, 15 Oct 2007 23:39:13 +0000 (23:39 +0000)
committerFariborz Jahanian <fjahanian@apple.com>
Mon, 15 Oct 2007 23:39:13 +0000 (23:39 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@43022 91177308-0d34-0410-b5e6-96231b3b80d8

Parse/ParseObjc.cpp
clang.xcodeproj/project.pbxproj
include/clang/Parse/Action.h
include/clang/Parse/Parser.h
test/Parser/selector-1.m [new file with mode: 0644]

index 85559019e00d24c271f410daf0e1974e2f1fdc69..3c379621bf2f8b3c1de86099d0696ba336a0c7a6 100644 (file)
@@ -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
index b88c381faa0b21298a15082c3f3667bb0e3dacc7..75d938806b0068e9faf478a9935977559b88f772 100644 (file)
                08FB7793FE84155DC02AAC07 /* Project object */ = {
                        isa = PBXProject;
                        buildConfigurationList = 1DEB923508733DC60010E9CD /* Build configuration list for PBXProject "clang" */;
+                       compatibilityVersion = "Xcode 2.4";
                        hasScannedForEncodings = 1;
                        mainGroup = 08FB7794FE84155DC02AAC07 /* clang */;
                        projectDirPath = "";
index cd48862b089e59d08175da38aa5d55bbdac836f7..a5e6875c3dc5dedc19c0e63b8cc07986409d915b 100644 (file)
@@ -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
index 66ca274915e638a8d6bc96ce355eba247ab1a927..02cbaa55900569b6410d9dff558f9370c4c2a848 100644 (file)
@@ -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 (file)
index 0000000..a06d2e6
--- /dev/null
@@ -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:);
+}