change the StringLiteral AST node to track all of the SourceLocations of 
the various PPTokens that are pasted together to make it.  In the course
of working on this, I discovered ParseObjCStringLiteral which needs some
work.  I'll tackle it next.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@64892 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/AST/Expr.cpp b/lib/AST/Expr.cpp
index 0cd68ce..81da444 100644
--- a/lib/AST/Expr.cpp
+++ b/lib/AST/Expr.cpp
@@ -39,20 +39,36 @@
 
 
 StringLiteral::StringLiteral(ASTContext& C, const char *strData,
-                             unsigned byteLength, bool Wide, QualType t,
-                             SourceLocation firstLoc,
-                             SourceLocation lastLoc) : 
-  Expr(StringLiteralClass, t) {
+                             unsigned byteLength, bool Wide, QualType Ty,
+                             SourceLocation Loc) : 
+    Expr(StringLiteralClass, Ty) {
   // OPTIMIZE: could allocate this appended to the StringLiteral.
   char *AStrData = new (C, 1) char[byteLength];
   memcpy(AStrData, strData, byteLength);
   StrData = AStrData;
   ByteLength = byteLength;
   IsWide = Wide;
-  firstTokLoc = firstLoc;
-  lastTokLoc = lastLoc;
+  TokLocs[0] = Loc;
+  NumConcatenated = 1;
 }
 
+StringLiteral::StringLiteral(ASTContext &C, const char *strData, 
+                             unsigned byteLength, bool Wide, QualType Ty,
+                             SourceLocation *Loc, unsigned NumStrs) : 
+    Expr(StringLiteralClass, Ty) {
+  // OPTIMIZE: could allocate this appended to the StringLiteral.
+  char *AStrData = new (C, 1) char[byteLength];
+  memcpy(AStrData, strData, byteLength);
+  StrData = AStrData;
+  ByteLength = byteLength;
+  IsWide = Wide;
+  TokLocs[0] = Loc[0];
+  NumConcatenated = NumStrs;
+  if (NumStrs != 1)
+    memcpy(&TokLocs[1], Loc+1, sizeof(SourceLocation)*(NumStrs-1));
+}
+
+
 void StringLiteral::Destroy(ASTContext &C) {
   C.Deallocate(const_cast<char*>(StrData));
   this->~StringLiteral();
diff --git a/lib/AST/StmtSerialization.cpp b/lib/AST/StmtSerialization.cpp
index 22ce818..074969e 100644
--- a/lib/AST/StmtSerialization.cpp
+++ b/lib/AST/StmtSerialization.cpp
@@ -955,8 +955,7 @@
 
 void StringLiteral::EmitImpl(Serializer& S) const {
   S.Emit(getType());
-  S.Emit(firstTokLoc);
-  S.Emit(lastTokLoc);
+  assert(0 && "Unimpl loc serialization");
   S.EmitBool(isWide());
   S.Emit(getByteLength());
 
@@ -966,13 +965,14 @@
 
 StringLiteral* StringLiteral::CreateImpl(Deserializer& D, ASTContext& C) {
   QualType t = QualType::ReadVal(D);
-  SourceLocation firstTokLoc = SourceLocation::ReadVal(D);
-  SourceLocation lastTokLoc = SourceLocation::ReadVal(D);
+  assert(0 && "Unimpl loc serialization");
+  //SourceLocation firstTokLoc = SourceLocation::ReadVal(D);
+  //SourceLocation lastTokLoc = SourceLocation::ReadVal(D);
   bool isWide = D.ReadBool();
   unsigned ByteLength = D.ReadInt();
   
   StringLiteral* sl = new (C, llvm::alignof<StringLiteral>())
-    StringLiteral(C, NULL, 0, isWide, t, firstTokLoc, lastTokLoc);
+    StringLiteral(C, NULL, 0, isWide, t, SourceLocation());
 
   char* StrData = new (C, llvm::alignof<char>()) char[ByteLength];
   for (unsigned i = 0; i < ByteLength; ++i)
diff --git a/lib/Sema/SemaExpr.cpp b/lib/Sema/SemaExpr.cpp
index 4eb29c4..c0b61bf 100644
--- a/lib/Sema/SemaExpr.cpp
+++ b/lib/Sema/SemaExpr.cpp
@@ -352,13 +352,17 @@
   StrTy = Context.getConstantArrayType(StrTy,
                                    llvm::APInt(32, Literal.GetStringLength()+1),
                                        ArrayType::Normal, 0);
-
+  // Allocate enough space for the StringLiteral plus an array of locations for
+  // any concatenated strings.
+  void *Mem = Context.Allocate(sizeof(StringLiteral)+
+                               sizeof(SourceLocation)*(NumStringToks-1));
+  
   // Pass &StringTokLocs[0], StringTokLocs.size() to factory!
-  return Owned(new (Context) StringLiteral(Context, Literal.GetString(), 
-                                 Literal.GetStringLength(),
-                                 Literal.AnyWide, StrTy,
-                                 StringToks[0].getLocation(),
-                                 StringToks[NumStringToks-1].getLocation()));
+  return Owned(new (Mem) StringLiteral(Context, Literal.GetString(), 
+                                       Literal.GetStringLength(),
+                                       Literal.AnyWide, StrTy,
+                                       &StringTokLocs[0],
+                                       StringTokLocs.size()));
 }
 
 /// ShouldSnapshotBlockValueReference - Return true if a reference inside of
diff --git a/lib/Sema/SemaExprObjC.cpp b/lib/Sema/SemaExprObjC.cpp
index 3e99482..b0b5367 100644
--- a/lib/Sema/SemaExprObjC.cpp
+++ b/lib/Sema/SemaExprObjC.cpp
@@ -29,10 +29,12 @@
     unsigned Length = 0;
     for (unsigned i = 0; i < NumStrings; i++)
       Length += static_cast<StringLiteral *>(Strings[i])->getByteLength();
-    char *strBuf = new char [Length];
+    
+    // FIXME: This should not be allocated by SEMA!
+    char *strBuf = new char[Length];
     char *p = strBuf;
     bool isWide = false;
-    for (unsigned i = 0; i < NumStrings; i++) {
+    for (unsigned i = 0; i != NumStrings; ++i) {
       S = static_cast<StringLiteral *>(Strings[i]);
       if (S->isWide())
         isWide = true;
@@ -40,9 +42,10 @@
       p += S->getByteLength();
       S->Destroy(Context);
     }
-    S = new (Context, 8) StringLiteral(Context, strBuf, Length, isWide,
-                                       Context.getPointerType(Context.CharTy),
-                                       AtLoc, EndLoc);
+    // FIXME: PASS LOCATIONS PROPERLY.
+    S = new (Context) StringLiteral(Context, strBuf, Length, isWide,
+                                    Context.getPointerType(Context.CharTy),
+                                    AtLoc);
   }
   
   if (CheckBuiltinCFStringArgument(S))