r174174 - libclang: itroduce cxstring::createEmpty()
Dmitri Gribenko
gribozavr at gmail.com
Fri Feb 1 06:21:23 PST 2013
Author: gribozavr
Date: Fri Feb 1 08:21:22 2013
New Revision: 174174
URL: http://llvm.org/viewvc/llvm-project?rev=174174&view=rev
Log:
libclang: itroduce cxstring::createEmpty()
Modified:
cfe/trunk/tools/libclang/CIndex.cpp
cfe/trunk/tools/libclang/CIndexCodeCompletion.cpp
cfe/trunk/tools/libclang/CIndexDiagnostic.cpp
cfe/trunk/tools/libclang/CIndexUSRs.cpp
cfe/trunk/tools/libclang/CXLoadedDiagnostic.cpp
cfe/trunk/tools/libclang/CXSourceLocation.cpp
cfe/trunk/tools/libclang/CXStoredDiagnostic.cpp
cfe/trunk/tools/libclang/CXString.cpp
cfe/trunk/tools/libclang/CXString.h
cfe/trunk/tools/libclang/CXType.cpp
Modified: cfe/trunk/tools/libclang/CIndex.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/libclang/CIndex.cpp?rev=174174&r1=174173&r2=174174&view=diff
==============================================================================
--- cfe/trunk/tools/libclang/CIndex.cpp (original)
+++ cfe/trunk/tools/libclang/CIndex.cpp Fri Feb 1 08:21:22 2013
@@ -2915,7 +2915,7 @@ int clang_reparseTranslationUnit(CXTrans
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 @@ unsigned clang_visitChildrenWithBlock(CX
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 @@ static CXString getDeclSpelling(const De
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 @@ static CXString getDeclSpelling(const De
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 @@ CXString clang_getCursorSpelling(CXCurso
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 @@ CXString clang_getCursorSpelling(CXCurso
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 @@ CXString clang_getCursorSpelling(CXCurso
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 @@ CXString clang_getCursorSpelling(CXCurso
return createCXString(AA->getLabel());
}
- return createCXString("");
+ return cxstring::createEmpty();
}
CXSourceRange clang_Cursor_getSpellingNameRange(CXCursor C,
@@ -3358,7 +3358,7 @@ CXString clang_getCursorDisplayName(CXCu
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 @@ CXString clang_getTokenSpelling(CXTransl
// 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 @@ CXString clang_getTokenSpelling(CXTransl
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 @@ int clang_getCursorPlatformAvailability(
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 @@ CXModule clang_Module_getParent(CXModule
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());
}
Modified: cfe/trunk/tools/libclang/CIndexCodeCompletion.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/libclang/CIndexCodeCompletion.cpp?rev=174174&r1=174173&r2=174174&view=diff
==============================================================================
--- cfe/trunk/tools/libclang/CIndexCodeCompletion.cpp (original)
+++ cfe/trunk/tools/libclang/CIndexCodeCompletion.cpp Fri Feb 1 08:21:22 2013
@@ -139,7 +139,7 @@ CXString clang_getCompletionChunkText(CX
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 @@ AllocatedCXCodeCompleteResults::Allocate
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 @@ namespace {
}
else {
AllocatedResults.ContainerKind = CXCursor_InvalidCode;
- AllocatedResults.ContainerUSR = createCXString("");
+ AllocatedResults.ContainerUSR = cxstring::createEmpty();
AllocatedResults.ContainerIsIncomplete = 1;
}
}
@@ -912,7 +912,7 @@ CXString clang_codeCompleteGetContainerU
AllocatedCXCodeCompleteResults *Results =
static_cast<AllocatedCXCodeCompleteResults *>(ResultsIn);
if (!Results)
- return createCXString("");
+ return cxstring::createEmpty();
return createCXString(clang_getCString(Results->ContainerUSR));
}
@@ -922,7 +922,7 @@ CXString clang_codeCompleteGetObjCSelect
AllocatedCXCodeCompleteResults *Results =
static_cast<AllocatedCXCodeCompleteResults *>(ResultsIn);
if (!Results)
- return createCXString("");
+ return cxstring::createEmpty();
return createCXString(Results->Selector);
}
Modified: cfe/trunk/tools/libclang/CIndexDiagnostic.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/libclang/CIndexDiagnostic.cpp?rev=174174&r1=174173&r2=174174&view=diff
==============================================================================
--- cfe/trunk/tools/libclang/CIndexDiagnostic.cpp (original)
+++ cfe/trunk/tools/libclang/CIndexDiagnostic.cpp Fri Feb 1 08:21:22 2013
@@ -67,12 +67,12 @@ public:
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 @@ public:
CXString getFixIt(unsigned FixIt, CXSourceRange *ReplacementRange) const {
if (ReplacementRange)
*ReplacementRange = clang_getNullRange();
- return createCXString("", false);
+ return cxstring::createEmpty();
}
};
@@ -239,7 +239,7 @@ void clang_disposeDiagnostic(CXDiagnosti
CXString clang_formatDiagnostic(CXDiagnostic Diagnostic, unsigned Options) {
if (!Diagnostic)
- return createCXString("");
+ return cxstring::createEmpty();
CXDiagnosticSeverity Severity = clang_getDiagnosticSeverity(Diagnostic);
@@ -377,17 +377,17 @@ CXSourceLocation clang_getDiagnosticLoca
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_getDiagnosticCategoryName
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 @@ CXString clang_getDiagnosticFixIt(CXDiag
if (!D || FixIt >= D->getNumFixIts()) {
if (ReplacementRange)
*ReplacementRange = clang_getNullRange();
- return createCXString("");
+ return cxstring::createEmpty();
}
return D->getFixIt(FixIt, ReplacementRange);
}
Modified: cfe/trunk/tools/libclang/CIndexUSRs.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/libclang/CIndexUSRs.cpp?rev=174174&r1=174173&r2=174174&view=diff
==============================================================================
--- cfe/trunk/tools/libclang/CIndexUSRs.cpp (original)
+++ cfe/trunk/tools/libclang/CIndexUSRs.cpp Fri Feb 1 08:21:22 2013
@@ -823,20 +823,20 @@ CXString clang_getCursorUSR(CXCursor C)
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 @@ CXString clang_getCursorUSR(CXCursor C)
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 @@ CXString clang_getCursorUSR(CXCursor C)
return createCXString(buf);
}
- return createCXString("");
+ return cxstring::createEmpty();
}
CXString clang_constructUSR_ObjCIvar(const char *name, CXString classUSR) {
Modified: cfe/trunk/tools/libclang/CXLoadedDiagnostic.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/libclang/CXLoadedDiagnostic.cpp?rev=174174&r1=174173&r2=174174&view=diff
==============================================================================
--- cfe/trunk/tools/libclang/CXLoadedDiagnostic.cpp (original)
+++ cfe/trunk/tools/libclang/CXLoadedDiagnostic.cpp Fri Feb 1 08:21:22 2013
@@ -102,7 +102,7 @@ CXString CXLoadedDiagnostic::getSpelling
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 @@ public:
if (error)
*error = CXLoadDiag_None;
if (errorString)
- *errorString = createCXString("");
+ *errorString = cxstring::createEmpty();
}
CXDiagnosticSet load(const char *file);
Modified: cfe/trunk/tools/libclang/CXSourceLocation.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/libclang/CXSourceLocation.cpp?rev=174174&r1=174173&r2=174174&view=diff
==============================================================================
--- cfe/trunk/tools/libclang/CXSourceLocation.cpp (original)
+++ cfe/trunk/tools/libclang/CXSourceLocation.cpp Fri Feb 1 08:21:22 2013
@@ -187,7 +187,7 @@ static void createNullLocation(CXFile *f
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)
Modified: cfe/trunk/tools/libclang/CXStoredDiagnostic.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/libclang/CXStoredDiagnostic.cpp?rev=174174&r1=174173&r2=174174&view=diff
==============================================================================
--- cfe/trunk/tools/libclang/CXStoredDiagnostic.cpp (original)
+++ cfe/trunk/tools/libclang/CXStoredDiagnostic.cpp Fri Feb 1 08:21:22 2013
@@ -67,7 +67,7 @@ CXString CXStoredDiagnostic::getDiagnost
return createCXString("-ferror-limit=");
}
- return createCXString("");
+ return cxstring::createEmpty();
}
unsigned CXStoredDiagnostic::getCategory() const {
Modified: cfe/trunk/tools/libclang/CXString.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/libclang/CXString.cpp?rev=174174&r1=174173&r2=174174&view=diff
==============================================================================
--- cfe/trunk/tools/libclang/CXString.cpp (original)
+++ cfe/trunk/tools/libclang/CXString.cpp Fri Feb 1 08:21:22 2013
@@ -29,6 +29,13 @@ enum CXStringFlag { CXS_Unmanaged, CXS_M
// 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;
Modified: cfe/trunk/tools/libclang/CXString.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/libclang/CXString.h?rev=174174&r1=174173&r2=174174&view=diff
==============================================================================
--- cfe/trunk/tools/libclang/CXString.h (original)
+++ cfe/trunk/tools/libclang/CXString.h Fri Feb 1 08:21:22 2013
@@ -25,6 +25,9 @@ namespace cxstring {
struct CXStringBuf;
+/// \brief Create a CXString object for an empty "" string.
+CXString createEmpty();
+
/// \brief Create a CXString object for an NULL string.
CXString createNull();
Modified: cfe/trunk/tools/libclang/CXType.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/libclang/CXType.cpp?rev=174174&r1=174173&r2=174174&view=diff
==============================================================================
--- cfe/trunk/tools/libclang/CXType.cpp (original)
+++ cfe/trunk/tools/libclang/CXType.cpp Fri Feb 1 08:21:22 2013
@@ -636,7 +636,7 @@ long long clang_getArraySize(CXType CT)
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);
More information about the cfe-commits
mailing list