libclang: itroduce cxstring::createEmpty()


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@174174 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/tools/libclang/CIndex.cpp b/tools/libclang/CIndex.cpp
index 6b90cef..d6a9378 100644
--- a/tools/libclang/CIndex.cpp
+++ b/tools/libclang/CIndex.cpp
@@ -2915,7 +2915,7 @@
 
 CXString clang_getTranslationUnitSpelling(CXTranslationUnit CTUnit) {
   if (!CTUnit)
-    return createCXString("");
+    return cxstring::createEmpty();
 
   ASTUnit *CXXUnit = cxtu::getASTUnit(CTUnit);
   return createCXString(CXXUnit->getOriginalSourceFileName(), true);
@@ -3107,7 +3107,7 @@
 
 static CXString getDeclSpelling(const Decl *D) {
   if (!D)
-    return createCXString("");
+    return cxstring::createEmpty();
 
   const NamedDecl *ND = dyn_cast<NamedDecl>(D);
   if (!ND) {
@@ -3120,7 +3120,7 @@
       if (Module *Mod = ImportD->getImportedModule())
         return createCXString(Mod->getFullModuleName());
 
-    return createCXString("");
+    return cxstring::createEmpty();
   }
   
   if (const ObjCMethodDecl *OMD = dyn_cast<ObjCMethodDecl>(ND))
@@ -3133,7 +3133,7 @@
     return createCXString(CIMP->getIdentifier()->getNameStart());
 
   if (isa<UsingDirectiveDecl>(D))
-    return createCXString("");
+    return cxstring::createEmpty();
   
   SmallString<1024> S;
   llvm::raw_svector_ostream os(S);
@@ -3205,14 +3205,14 @@
       if (const Decl *D = Storage.dyn_cast<const Decl *>()) {
         if (const NamedDecl *ND = dyn_cast<NamedDecl>(D))
           return createCXString(ND->getNameAsString());
-        return createCXString("");
+        return cxstring::createEmpty();
       }
       if (const OverloadExpr *E = Storage.dyn_cast<const OverloadExpr *>())
         return createCXString(E->getName().getAsString());
       OverloadedTemplateStorage *Ovl
         = Storage.get<OverloadedTemplateStorage*>();
       if (Ovl->size() == 0)
-        return createCXString("");
+        return cxstring::createEmpty();
       return createCXString((*Ovl->begin())->getNameAsString());
     }
         
@@ -3232,7 +3232,7 @@
     const Decl *D = getDeclFromExpr(getCursorExpr(C));
     if (D)
       return getDeclSpelling(D);
-    return createCXString("");
+    return cxstring::createEmpty();
   }
 
   if (clang_isStatement(C.kind)) {
@@ -3240,7 +3240,7 @@
     if (const LabelStmt *Label = dyn_cast_or_null<LabelStmt>(S))
       return createCXString(Label->getName());
 
-    return createCXString("");
+    return cxstring::createEmpty();
   }
   
   if (C.kind == CXCursor_MacroExpansion)
@@ -3267,7 +3267,7 @@
     return createCXString(AA->getLabel());
   }
 
-  return createCXString("");
+  return cxstring::createEmpty();
 }
 
 CXSourceRange clang_Cursor_getSpellingNameRange(CXCursor C,
@@ -3358,7 +3358,7 @@
   
   const Decl *D = getCursorDecl(C);
   if (!D)
-    return createCXString("");
+    return cxstring::createEmpty();
 
   PrintingPolicy Policy = getCursorContext(C).getPrintingPolicy();
   if (const FunctionTemplateDecl *FunTmpl = dyn_cast<FunctionTemplateDecl>(D))
@@ -4792,7 +4792,7 @@
   // deconstructing the source location.
   ASTUnit *CXXUnit = cxtu::getASTUnit(TU);
   if (!CXXUnit)
-    return createCXString("");
+    return cxstring::createEmpty();
 
   SourceLocation Loc = SourceLocation::getFromRawEncoding(CXTok.int_data[1]);
   std::pair<FileID, unsigned> LocInfo
@@ -4801,7 +4801,7 @@
   StringRef Buffer
     = CXXUnit->getSourceManager().getBufferData(LocInfo.first, &Invalid);
   if (Invalid)
-    return createCXString("");
+    return cxstring::createEmpty();
 
   return createCXString(Buffer.substr(LocInfo.second, CXTok.int_data[2]));
 }
@@ -5734,11 +5734,11 @@
   if (always_deprecated)
     *always_deprecated = 0;
   if (deprecated_message)
-    *deprecated_message = cxstring::createCXString("", /*DupString=*/false);
+    *deprecated_message = cxstring::createEmpty();
   if (always_unavailable)
     *always_unavailable = 0;
   if (unavailable_message)
-    *unavailable_message = cxstring::createCXString("", /*DupString=*/false);
+    *unavailable_message = cxstring::createEmpty();
   
   if (!clang_isDeclaration(cursor.kind))
     return 0;
@@ -5937,14 +5937,14 @@
 
 CXString clang_Module_getName(CXModule CXMod) {
   if (!CXMod)
-    return createCXString("");
+    return cxstring::createEmpty();
   Module *Mod = static_cast<Module*>(CXMod);
   return createCXString(Mod->Name);
 }
 
 CXString clang_Module_getFullName(CXModule CXMod) {
   if (!CXMod)
-    return createCXString("");
+    return cxstring::createEmpty();
   Module *Mod = static_cast<Module*>(CXMod);
   return createCXString(Mod->getFullModuleName());
 }
diff --git a/tools/libclang/CIndexCodeCompletion.cpp b/tools/libclang/CIndexCodeCompletion.cpp
index 07c04ac..950513d 100644
--- a/tools/libclang/CIndexCodeCompletion.cpp
+++ b/tools/libclang/CIndexCodeCompletion.cpp
@@ -139,7 +139,7 @@
       
   case CodeCompletionString::CK_Optional:
     // Note: treated as an empty text block.
-    return createCXString("");
+    return cxstring::createEmpty();
   }
 
   llvm_unreachable("Invalid CodeCompletionString Kind!");
@@ -321,7 +321,7 @@
     CodeCompletionAllocator(new clang::GlobalCodeCompletionAllocator),
     Contexts(CXCompletionContext_Unknown),
     ContainerKind(CXCursor_InvalidCode),
-    ContainerUSR(createCXString("")),
+    ContainerUSR(cxstring::createEmpty()),
     ContainerIsIncomplete(1)
 { 
   if (getenv("LIBCLANG_OBJTRACKING")) {
@@ -619,7 +619,7 @@
       }
       else {
         AllocatedResults.ContainerKind = CXCursor_InvalidCode;
-        AllocatedResults.ContainerUSR = createCXString("");
+        AllocatedResults.ContainerUSR = cxstring::createEmpty();
         AllocatedResults.ContainerIsIncomplete = 1;
       }
     }
@@ -912,7 +912,7 @@
   AllocatedCXCodeCompleteResults *Results =
     static_cast<AllocatedCXCodeCompleteResults *>(ResultsIn);
   if (!Results)
-    return createCXString("");
+    return cxstring::createEmpty();
   
   return createCXString(clang_getCString(Results->ContainerUSR));
 }
@@ -922,7 +922,7 @@
   AllocatedCXCodeCompleteResults *Results =
     static_cast<AllocatedCXCodeCompleteResults *>(ResultsIn);
   if (!Results)
-    return createCXString("");
+    return cxstring::createEmpty();
   
   return createCXString(Results->Selector);
 }
diff --git a/tools/libclang/CIndexDiagnostic.cpp b/tools/libclang/CIndexDiagnostic.cpp
index f48034e..9c5aa93 100644
--- a/tools/libclang/CIndexDiagnostic.cpp
+++ b/tools/libclang/CIndexDiagnostic.cpp
@@ -67,12 +67,12 @@
   
   CXString getDiagnosticOption(CXString *Disable) const {
     if (Disable)
-      *Disable = createCXString("", false);    
-    return createCXString("", false);
+      *Disable = cxstring::createEmpty();
+    return cxstring::createEmpty();
   }
   
   unsigned getCategory() const { return 0; }
-  CXString getCategoryText() const { return createCXString(""); }
+  CXString getCategoryText() const { return cxstring::createEmpty(); }
 
   unsigned getNumRanges() const { return 0; }
   CXSourceRange getRange(unsigned Range) const { return clang_getNullRange(); }
@@ -80,7 +80,7 @@
   CXString getFixIt(unsigned FixIt, CXSourceRange *ReplacementRange) const {
     if (ReplacementRange)
       *ReplacementRange = clang_getNullRange();
-    return createCXString("", false);
+    return cxstring::createEmpty();
   }
 };    
     
@@ -239,7 +239,7 @@
 
 CXString clang_formatDiagnostic(CXDiagnostic Diagnostic, unsigned Options) {
   if (!Diagnostic)
-    return createCXString("");
+    return cxstring::createEmpty();
 
   CXDiagnosticSeverity Severity = clang_getDiagnosticSeverity(Diagnostic);
 
@@ -377,17 +377,17 @@
 CXString clang_getDiagnosticSpelling(CXDiagnostic Diag) {
   if (CXDiagnosticImpl *D = static_cast<CXDiagnosticImpl *>(Diag))
     return D->getSpelling();
-  return createCXString("");
+  return cxstring::createEmpty();
 }
 
 CXString clang_getDiagnosticOption(CXDiagnostic Diag, CXString *Disable) {
   if (Disable)
-    *Disable = createCXString("");
+    *Disable = cxstring::createEmpty();
 
   if (CXDiagnosticImpl *D = static_cast<CXDiagnosticImpl *>(Diag))
     return D->getDiagnosticOption(Disable);
 
-  return createCXString("");
+  return cxstring::createEmpty();
 }
 
 unsigned clang_getDiagnosticCategory(CXDiagnostic Diag) {
@@ -404,7 +404,7 @@
 CXString clang_getDiagnosticCategoryText(CXDiagnostic Diag) {
   if (CXDiagnosticImpl *D = static_cast<CXDiagnosticImpl *>(Diag))
     return D->getCategoryText();
-  return createCXString("");
+  return cxstring::createEmpty();
 }
   
 unsigned clang_getDiagnosticNumRanges(CXDiagnostic Diag) {
@@ -432,7 +432,7 @@
   if (!D || FixIt >= D->getNumFixIts()) {
     if (ReplacementRange)
       *ReplacementRange = clang_getNullRange();
-    return createCXString("");
+    return cxstring::createEmpty();
   }
   return D->getFixIt(FixIt, ReplacementRange);
 }
diff --git a/tools/libclang/CIndexUSRs.cpp b/tools/libclang/CIndexUSRs.cpp
index eac74fa..6dc85c8 100644
--- a/tools/libclang/CIndexUSRs.cpp
+++ b/tools/libclang/CIndexUSRs.cpp
@@ -823,20 +823,20 @@
   if (clang_isDeclaration(K)) {
     const Decl *D = cxcursor::getCursorDecl(C);
     if (!D)
-      return createCXString("");
+      return cxstring::createEmpty();
 
     CXTranslationUnit TU = cxcursor::getCursorTU(C);
     if (!TU)
-      return createCXString("");
+      return cxstring::createEmpty();
 
     CXStringBuf *buf = cxstring::getCXStringBuf(TU);
     if (!buf)
-      return createCXString("");
+      return cxstring::createEmpty();
 
     bool Ignore = cxcursor::getDeclCursorUSR(D, buf->Data);
     if (Ignore) {
       buf->dispose();
-      return createCXString("");
+      return cxstring::createEmpty();
     }
 
     // Return the C-string, but don't make a copy since it is already in
@@ -848,11 +848,11 @@
   if (K == CXCursor_MacroDefinition) {
     CXTranslationUnit TU = cxcursor::getCursorTU(C);
     if (!TU)
-      return createCXString("");
+      return cxstring::createEmpty();
 
     CXStringBuf *buf = cxstring::getCXStringBuf(TU);
     if (!buf)
-      return createCXString("");
+      return cxstring::createEmpty();
 
     {
       USRGenerator UG(&cxcursor::getCursorASTUnit(C)->getASTContext(),
@@ -864,7 +864,7 @@
     return createCXString(buf);
   }
 
-  return createCXString("");
+  return cxstring::createEmpty();
 }
 
 CXString clang_constructUSR_ObjCIvar(const char *name, CXString classUSR) {
diff --git a/tools/libclang/CXLoadedDiagnostic.cpp b/tools/libclang/CXLoadedDiagnostic.cpp
index 65b816c..b9c4135 100644
--- a/tools/libclang/CXLoadedDiagnostic.cpp
+++ b/tools/libclang/CXLoadedDiagnostic.cpp
@@ -102,7 +102,7 @@
 
 CXString CXLoadedDiagnostic::getDiagnosticOption(CXString *Disable) const {
   if (DiagOption.empty())
-    return createCXString("");
+    return cxstring::createEmpty();
 
   // FIXME: possibly refactor with logic in CXStoredDiagnostic.
   if (Disable)
@@ -241,7 +241,7 @@
       if (error)
         *error = CXLoadDiag_None;
       if (errorString)
-        *errorString = createCXString("");
+        *errorString = cxstring::createEmpty();
     }
 
   CXDiagnosticSet load(const char *file);
diff --git a/tools/libclang/CXSourceLocation.cpp b/tools/libclang/CXSourceLocation.cpp
index bddb47b..afbac6d 100644
--- a/tools/libclang/CXSourceLocation.cpp
+++ b/tools/libclang/CXSourceLocation.cpp
@@ -187,7 +187,7 @@
 static void createNullLocation(CXString *filename, unsigned *line,
                                unsigned *column, unsigned *offset = 0) {
   if (filename)
-    *filename = createCXString("");
+    *filename = cxstring::createEmpty();
   if (line)
     *line = 0;
   if (column)
diff --git a/tools/libclang/CXStoredDiagnostic.cpp b/tools/libclang/CXStoredDiagnostic.cpp
index fa331de..f3fa126 100644
--- a/tools/libclang/CXStoredDiagnostic.cpp
+++ b/tools/libclang/CXStoredDiagnostic.cpp
@@ -67,7 +67,7 @@
     return createCXString("-ferror-limit=");
   }
 
-  return createCXString("");
+  return cxstring::createEmpty();
 }
 
 unsigned CXStoredDiagnostic::getCategory() const {
diff --git a/tools/libclang/CXString.cpp b/tools/libclang/CXString.cpp
index 030e34c..f2f33a2 100644
--- a/tools/libclang/CXString.cpp
+++ b/tools/libclang/CXString.cpp
@@ -29,6 +29,13 @@
 // Basic generation of CXStrings.
 //===----------------------------------------------------------------------===//
 
+CXString cxstring::createEmpty() {
+  CXString Str;
+  Str.data = "";
+  Str.private_flags = CXS_Unmanaged;
+  return Str;
+}
+
 CXString cxstring::createNull() {
   CXString Str;
   Str.data = 0;
diff --git a/tools/libclang/CXString.h b/tools/libclang/CXString.h
index 5078a42..0495ee9 100644
--- a/tools/libclang/CXString.h
+++ b/tools/libclang/CXString.h
@@ -25,6 +25,9 @@
 
 struct CXStringBuf;
 
+/// \brief Create a CXString object for an empty "" string.
+CXString createEmpty();
+
 /// \brief Create a CXString object for an NULL string.
 CXString createNull();
 
diff --git a/tools/libclang/CXType.cpp b/tools/libclang/CXType.cpp
index 06ca328..7c06bda 100644
--- a/tools/libclang/CXType.cpp
+++ b/tools/libclang/CXType.cpp
@@ -636,7 +636,7 @@
 
 CXString clang_getDeclObjCTypeEncoding(CXCursor C) {
   if (!clang_isDeclaration(C.kind))
-    return cxstring::createCXString("");
+    return cxstring::createEmpty();
 
   const Decl *D = static_cast<const Decl*>(C.data[0]);
   ASTUnit *AU = cxcursor::getCursorASTUnit(C);