[cfe-commits] r44898 - in /cfe/trunk: Parse/ParseObjc.cpp Sema/Sema.h Sema/SemaExpr.cpp clang.xcodeproj/project.pbxproj include/clang/Basic/DiagnosticKinds.def include/clang/Parse/Action.h test/Sema/objc-string.m

Chris Lattner sabre at nondot.org
Tue Dec 11 17:04:12 PST 2007


Author: lattner
Date: Tue Dec 11 19:04:12 2007
New Revision: 44898

URL: http://llvm.org/viewvc/llvm-project?rev=44898&view=rev
Log:
Add ObjC parser support for concatenated ObjC strings.  Note that
this is passed to sema and ignored there, so the second part of the
string will not make it into the AST.  Passing to Fariborz to finish
Sema + AST construction.

Added:
    cfe/trunk/test/Sema/objc-string.m
Modified:
    cfe/trunk/Parse/ParseObjc.cpp
    cfe/trunk/Sema/Sema.h
    cfe/trunk/Sema/SemaExpr.cpp
    cfe/trunk/clang.xcodeproj/project.pbxproj
    cfe/trunk/include/clang/Basic/DiagnosticKinds.def
    cfe/trunk/include/clang/Parse/Action.h

Modified: cfe/trunk/Parse/ParseObjc.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Parse/ParseObjc.cpp?rev=44898&r1=44897&r2=44898&view=diff

==============================================================================
--- cfe/trunk/Parse/ParseObjc.cpp (original)
+++ cfe/trunk/Parse/ParseObjc.cpp Tue Dec 11 19:04:12 2007
@@ -1190,11 +1190,11 @@
 Parser::ExprResult Parser::ParseObjCAtExpression(SourceLocation AtLoc) {
 
   switch (Tok.getKind()) {
-    case tok::string_literal:    // primary-expression: string-literal
-    case tok::wide_string_literal:
-      return ParsePostfixExpressionSuffix(ParseObjCStringLiteral(AtLoc));
-    default:
-      break;
+  case tok::string_literal:    // primary-expression: string-literal
+  case tok::wide_string_literal:
+    return ParsePostfixExpressionSuffix(ParseObjCStringLiteral(AtLoc));
+  default:
+    break;
   }
   
   switch (Tok.getIdentifierInfo()->getObjCKeywordID()) {
@@ -1333,10 +1333,38 @@
 
 Parser::ExprResult Parser::ParseObjCStringLiteral(SourceLocation AtLoc) {
   ExprResult Res = ParseStringLiteralExpression();
-
   if (Res.isInvalid) return Res;
+  
+  // @"foo" @"bar" is a valid concatenated string.  Eat any subsequent string
+  // expressions.  At this point, we know that the only valid thing that starts
+  // with '@' is an @"".
+  llvm::SmallVector<SourceLocation, 4> AtLocs;
+  llvm::SmallVector<ExprTy*, 4> AtStrings;
+  AtLocs.push_back(AtLoc);
+  AtStrings.push_back(Res.Val);
+  
+  while (Tok.is(tok::at)) {
+    AtLocs.push_back(ConsumeToken()); // eat the @.
+
+    ExprResult Res(true);  // Invalid unless there is a string literal.
+    if (isTokenStringLiteral())
+      Res = ParseStringLiteralExpression();
+    else
+      Diag(Tok, diag::err_objc_concat_string);
+    
+    if (Res.isInvalid) {
+      while (!AtStrings.empty()) {
+        Actions.DeleteExpr(AtStrings.back());
+        AtStrings.pop_back();
+      }
+      return Res;
+    }
+
+    AtStrings.push_back(Res.Val);
+  }
 
-  return Actions.ParseObjCStringLiteral(AtLoc, Res.Val);
+  return Actions.ParseObjCStringLiteral(&AtLocs[0], &AtStrings[0],
+                                        AtStrings.size());
 }
 
 ///    objc-encode-expression:

Modified: cfe/trunk/Sema/Sema.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Sema/Sema.h?rev=44898&r1=44897&r2=44898&view=diff

==============================================================================
--- cfe/trunk/Sema/Sema.h (original)
+++ cfe/trunk/Sema/Sema.h Tue Dec 11 19:04:12 2007
@@ -465,8 +465,9 @@
                                          tok::TokenKind Kind);
   
   // ParseObjCStringLiteral - Parse Objective-C string literals.
-  virtual ExprResult ParseObjCStringLiteral(SourceLocation AtLoc,
-                                            ExprTy *string);
+  virtual ExprResult ParseObjCStringLiteral(SourceLocation *AtLocs, 
+                                            ExprTy **Strings,
+                                            unsigned NumStrings);
   virtual ExprResult ParseObjCEncodeExpression(SourceLocation AtLoc,
                                                SourceLocation EncodeLoc,
                                                SourceLocation LParenLoc,

Modified: cfe/trunk/Sema/SemaExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Sema/SemaExpr.cpp?rev=44898&r1=44897&r2=44898&view=diff

==============================================================================
--- cfe/trunk/Sema/SemaExpr.cpp (original)
+++ cfe/trunk/Sema/SemaExpr.cpp Tue Dec 11 19:04:12 2007
@@ -2046,9 +2046,14 @@
 }
 
 // TODO: Move this to SemaObjC.cpp
-Sema::ExprResult Sema::ParseObjCStringLiteral(SourceLocation AtLoc, 
-                                              ExprTy *string) {
-  StringLiteral* S = static_cast<StringLiteral *>(string);
+Sema::ExprResult Sema::ParseObjCStringLiteral(SourceLocation *AtLocs, 
+                                              ExprTy **Strings,
+                                              unsigned NumStrings) {
+  
+  // FIXME: This is passed in an ARRAY of strings which need to be concatenated.
+  // Handle this case here.  For now we just ignore all but the first one.
+  SourceLocation AtLoc = AtLocs[0];
+  StringLiteral* S = static_cast<StringLiteral *>(Strings[0]);
   
   if (CheckBuiltinCFStringArgument(S))
     return true;

Modified: cfe/trunk/clang.xcodeproj/project.pbxproj
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/clang.xcodeproj/project.pbxproj?rev=44898&r1=44897&r2=44898&view=diff

==============================================================================
--- cfe/trunk/clang.xcodeproj/project.pbxproj (original)
+++ cfe/trunk/clang.xcodeproj/project.pbxproj Tue Dec 11 19:04:12 2007
@@ -772,7 +772,6 @@
 		08FB7793FE84155DC02AAC07 /* Project object */ = {
 			isa = PBXProject;
 			buildConfigurationList = 1DEB923508733DC60010E9CD /* Build configuration list for PBXProject "clang" */;
-			compatibilityVersion = "Xcode 2.4";
 			hasScannedForEncodings = 1;
 			mainGroup = 08FB7794FE84155DC02AAC07 /* clang */;
 			projectDirPath = "";

Modified: cfe/trunk/include/clang/Basic/DiagnosticKinds.def
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticKinds.def?rev=44898&r1=44897&r2=44898&view=diff

==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticKinds.def (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticKinds.def Tue Dec 11 19:04:12 2007
@@ -414,6 +414,8 @@
      "@optional may be specified in protocols only")
 DIAG(err_missing_catch_finally, ERROR,
      "@try statment without a @catch and @finally clause")
+DIAG(err_objc_concat_string, ERROR,
+     "unexpected token after Objective-C string")
 DIAG(err_undef_superclass, ERROR,
      "cannot find interface declaration for '%0', superclass of '%1'")
 DIAG(err_duplicate_class_def, ERROR,
@@ -465,7 +467,7 @@
 DIAG(err_conflicting_aliasing_type, ERROR,
      "conflicting types for alias %0'")
 DIAG(err_statically_allocated_object, ERROR,
-     "statically allocated Objective-c object '%0'")
+     "statically allocated Objective-C object '%0'")
 DIAG(warn_method_not_found, WARNING,
      "method '%0%1' not found (return type defaults to 'id')")
 

Modified: cfe/trunk/include/clang/Parse/Action.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Parse/Action.h?rev=44898&r1=44897&r2=44898&view=diff

==============================================================================
--- cfe/trunk/include/clang/Parse/Action.h (original)
+++ cfe/trunk/include/clang/Parse/Action.h Tue Dec 11 19:04:12 2007
@@ -643,8 +643,10 @@
                                                
                                                
   //===----------------------- Obj-C Expressions --------------------------===//
-  virtual ExprResult ParseObjCStringLiteral(SourceLocation AtLoc, 
-                                            ExprTy *string) {
+
+  virtual ExprResult ParseObjCStringLiteral(SourceLocation *AtLocs, 
+                                            ExprTy **Strings,
+                                            unsigned NumStrings) {
     return 0;
   }
 

Added: cfe/trunk/test/Sema/objc-string.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/objc-string.m?rev=44898&view=auto

==============================================================================
--- cfe/trunk/test/Sema/objc-string.m (added)
+++ cfe/trunk/test/Sema/objc-string.m Tue Dec 11 19:04:12 2007
@@ -0,0 +1,12 @@
+// RUN: clang %s -verify -fsyntax-only
+
+ at class NSString;
+ at interface NSConstantString;
+ at end
+
+
+
+NSString *s = @"123"; // simple
+NSString *t = @"123" @"456"; // concat
+NSString *u = @"123" @ blah; // expected-error: {{unexpected token}}
+





More information about the cfe-commits mailing list