libclang: introduce cxstring::createNull()
llvm-svn: 174173
This commit is contained in:
parent
191c093af1
commit
f98dfbae94
|
@ -2935,7 +2935,7 @@ CXCursor clang_getTranslationUnitCursor(CXTranslationUnit TU) {
|
||||||
extern "C" {
|
extern "C" {
|
||||||
CXString clang_getFileName(CXFile SFile) {
|
CXString clang_getFileName(CXFile SFile) {
|
||||||
if (!SFile)
|
if (!SFile)
|
||||||
return createCXString((const char*)NULL);
|
return cxstring::createNull();
|
||||||
|
|
||||||
FileEntry *FEnt = static_cast<FileEntry *>(SFile);
|
FileEntry *FEnt = static_cast<FileEntry *>(SFile);
|
||||||
return createCXString(FEnt->getName());
|
return createCXString(FEnt->getName());
|
||||||
|
@ -5875,7 +5875,7 @@ CXSourceRange clang_Cursor_getCommentRange(CXCursor C) {
|
||||||
|
|
||||||
CXString clang_Cursor_getRawCommentText(CXCursor C) {
|
CXString clang_Cursor_getRawCommentText(CXCursor C) {
|
||||||
if (!clang_isDeclaration(C.kind))
|
if (!clang_isDeclaration(C.kind))
|
||||||
return createCXString((const char *) NULL);
|
return cxstring::createNull();
|
||||||
|
|
||||||
const Decl *D = getCursorDecl(C);
|
const Decl *D = getCursorDecl(C);
|
||||||
ASTContext &Context = getCursorContext(C);
|
ASTContext &Context = getCursorContext(C);
|
||||||
|
@ -5890,7 +5890,7 @@ CXString clang_Cursor_getRawCommentText(CXCursor C) {
|
||||||
|
|
||||||
CXString clang_Cursor_getBriefCommentText(CXCursor C) {
|
CXString clang_Cursor_getBriefCommentText(CXCursor C) {
|
||||||
if (!clang_isDeclaration(C.kind))
|
if (!clang_isDeclaration(C.kind))
|
||||||
return createCXString((const char *) NULL);
|
return cxstring::createNull();
|
||||||
|
|
||||||
const Decl *D = getCursorDecl(C);
|
const Decl *D = getCursorDecl(C);
|
||||||
const ASTContext &Context = getCursorContext(C);
|
const ASTContext &Context = getCursorContext(C);
|
||||||
|
@ -5904,7 +5904,7 @@ CXString clang_Cursor_getBriefCommentText(CXCursor C) {
|
||||||
return createCXString(BriefText, false);
|
return createCXString(BriefText, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
return createCXString((const char *) NULL);
|
return cxstring::createNull();
|
||||||
}
|
}
|
||||||
|
|
||||||
CXComment clang_Cursor_getParsedComment(CXCursor C) {
|
CXComment clang_Cursor_getParsedComment(CXCursor C) {
|
||||||
|
|
|
@ -112,7 +112,7 @@ CXString clang_getCompletionChunkText(CXCompletionString completion_string,
|
||||||
unsigned chunk_number) {
|
unsigned chunk_number) {
|
||||||
CodeCompletionString *CCStr = (CodeCompletionString *)completion_string;
|
CodeCompletionString *CCStr = (CodeCompletionString *)completion_string;
|
||||||
if (!CCStr || chunk_number >= CCStr->size())
|
if (!CCStr || chunk_number >= CCStr->size())
|
||||||
return createCXString((const char*)0);
|
return cxstring::createNull();
|
||||||
|
|
||||||
switch ((*CCStr)[chunk_number].Kind) {
|
switch ((*CCStr)[chunk_number].Kind) {
|
||||||
case CodeCompletionString::CK_TypedText:
|
case CodeCompletionString::CK_TypedText:
|
||||||
|
@ -211,7 +211,7 @@ CXString clang_getCompletionAnnotation(CXCompletionString completion_string,
|
||||||
unsigned annotation_number) {
|
unsigned annotation_number) {
|
||||||
CodeCompletionString *CCStr = (CodeCompletionString *)completion_string;
|
CodeCompletionString *CCStr = (CodeCompletionString *)completion_string;
|
||||||
return CCStr ? createCXString(CCStr->getAnnotation(annotation_number))
|
return CCStr ? createCXString(CCStr->getAnnotation(annotation_number))
|
||||||
: createCXString((const char *) 0);
|
: cxstring::createNull();
|
||||||
}
|
}
|
||||||
|
|
||||||
CXString
|
CXString
|
||||||
|
@ -222,7 +222,7 @@ clang_getCompletionParent(CXCompletionString completion_string,
|
||||||
|
|
||||||
CodeCompletionString *CCStr = (CodeCompletionString *)completion_string;
|
CodeCompletionString *CCStr = (CodeCompletionString *)completion_string;
|
||||||
if (!CCStr)
|
if (!CCStr)
|
||||||
return createCXString((const char *)0);
|
return cxstring::createNull();
|
||||||
|
|
||||||
return createCXString(CCStr->getParentContextName(), /*DupString=*/false);
|
return createCXString(CCStr->getParentContextName(), /*DupString=*/false);
|
||||||
}
|
}
|
||||||
|
@ -232,7 +232,7 @@ clang_getCompletionBriefComment(CXCompletionString completion_string) {
|
||||||
CodeCompletionString *CCStr = (CodeCompletionString *)completion_string;
|
CodeCompletionString *CCStr = (CodeCompletionString *)completion_string;
|
||||||
|
|
||||||
if (!CCStr)
|
if (!CCStr)
|
||||||
return createCXString((const char *) NULL);
|
return cxstring::createNull();
|
||||||
|
|
||||||
return createCXString(CCStr->getBriefComment(), /*DupString=*/false);
|
return createCXString(CCStr->getBriefComment(), /*DupString=*/false);
|
||||||
}
|
}
|
||||||
|
|
|
@ -124,7 +124,7 @@ unsigned clang_InlineContentComment_hasTrailingNewline(CXComment CXC) {
|
||||||
CXString clang_TextComment_getText(CXComment CXC) {
|
CXString clang_TextComment_getText(CXComment CXC) {
|
||||||
const TextComment *TC = getASTNodeAs<TextComment>(CXC);
|
const TextComment *TC = getASTNodeAs<TextComment>(CXC);
|
||||||
if (!TC)
|
if (!TC)
|
||||||
return createCXString((const char *) 0);
|
return cxstring::createNull();
|
||||||
|
|
||||||
return createCXString(TC->getText(), /*DupString=*/ false);
|
return createCXString(TC->getText(), /*DupString=*/ false);
|
||||||
}
|
}
|
||||||
|
@ -132,7 +132,7 @@ CXString clang_TextComment_getText(CXComment CXC) {
|
||||||
CXString clang_InlineCommandComment_getCommandName(CXComment CXC) {
|
CXString clang_InlineCommandComment_getCommandName(CXComment CXC) {
|
||||||
const InlineCommandComment *ICC = getASTNodeAs<InlineCommandComment>(CXC);
|
const InlineCommandComment *ICC = getASTNodeAs<InlineCommandComment>(CXC);
|
||||||
if (!ICC)
|
if (!ICC)
|
||||||
return createCXString((const char *) 0);
|
return cxstring::createNull();
|
||||||
|
|
||||||
const CommandTraits &Traits = getCommandTraits(CXC);
|
const CommandTraits &Traits = getCommandTraits(CXC);
|
||||||
return createCXString(ICC->getCommandName(Traits), /*DupString=*/ false);
|
return createCXString(ICC->getCommandName(Traits), /*DupString=*/ false);
|
||||||
|
@ -172,7 +172,7 @@ CXString clang_InlineCommandComment_getArgText(CXComment CXC,
|
||||||
unsigned ArgIdx) {
|
unsigned ArgIdx) {
|
||||||
const InlineCommandComment *ICC = getASTNodeAs<InlineCommandComment>(CXC);
|
const InlineCommandComment *ICC = getASTNodeAs<InlineCommandComment>(CXC);
|
||||||
if (!ICC || ArgIdx >= ICC->getNumArgs())
|
if (!ICC || ArgIdx >= ICC->getNumArgs())
|
||||||
return createCXString((const char *) 0);
|
return cxstring::createNull();
|
||||||
|
|
||||||
return createCXString(ICC->getArgText(ArgIdx), /*DupString=*/ false);
|
return createCXString(ICC->getArgText(ArgIdx), /*DupString=*/ false);
|
||||||
}
|
}
|
||||||
|
@ -180,7 +180,7 @@ CXString clang_InlineCommandComment_getArgText(CXComment CXC,
|
||||||
CXString clang_HTMLTagComment_getTagName(CXComment CXC) {
|
CXString clang_HTMLTagComment_getTagName(CXComment CXC) {
|
||||||
const HTMLTagComment *HTC = getASTNodeAs<HTMLTagComment>(CXC);
|
const HTMLTagComment *HTC = getASTNodeAs<HTMLTagComment>(CXC);
|
||||||
if (!HTC)
|
if (!HTC)
|
||||||
return createCXString((const char *) 0);
|
return cxstring::createNull();
|
||||||
|
|
||||||
return createCXString(HTC->getTagName(), /*DupString=*/ false);
|
return createCXString(HTC->getTagName(), /*DupString=*/ false);
|
||||||
}
|
}
|
||||||
|
@ -204,7 +204,7 @@ unsigned clang_HTMLStartTag_getNumAttrs(CXComment CXC) {
|
||||||
CXString clang_HTMLStartTag_getAttrName(CXComment CXC, unsigned AttrIdx) {
|
CXString clang_HTMLStartTag_getAttrName(CXComment CXC, unsigned AttrIdx) {
|
||||||
const HTMLStartTagComment *HST = getASTNodeAs<HTMLStartTagComment>(CXC);
|
const HTMLStartTagComment *HST = getASTNodeAs<HTMLStartTagComment>(CXC);
|
||||||
if (!HST || AttrIdx >= HST->getNumAttrs())
|
if (!HST || AttrIdx >= HST->getNumAttrs())
|
||||||
return createCXString((const char *) 0);
|
return cxstring::createNull();
|
||||||
|
|
||||||
return createCXString(HST->getAttr(AttrIdx).Name, /*DupString=*/ false);
|
return createCXString(HST->getAttr(AttrIdx).Name, /*DupString=*/ false);
|
||||||
}
|
}
|
||||||
|
@ -212,7 +212,7 @@ CXString clang_HTMLStartTag_getAttrName(CXComment CXC, unsigned AttrIdx) {
|
||||||
CXString clang_HTMLStartTag_getAttrValue(CXComment CXC, unsigned AttrIdx) {
|
CXString clang_HTMLStartTag_getAttrValue(CXComment CXC, unsigned AttrIdx) {
|
||||||
const HTMLStartTagComment *HST = getASTNodeAs<HTMLStartTagComment>(CXC);
|
const HTMLStartTagComment *HST = getASTNodeAs<HTMLStartTagComment>(CXC);
|
||||||
if (!HST || AttrIdx >= HST->getNumAttrs())
|
if (!HST || AttrIdx >= HST->getNumAttrs())
|
||||||
return createCXString((const char *) 0);
|
return cxstring::createNull();
|
||||||
|
|
||||||
return createCXString(HST->getAttr(AttrIdx).Value, /*DupString=*/ false);
|
return createCXString(HST->getAttr(AttrIdx).Value, /*DupString=*/ false);
|
||||||
}
|
}
|
||||||
|
@ -220,7 +220,7 @@ CXString clang_HTMLStartTag_getAttrValue(CXComment CXC, unsigned AttrIdx) {
|
||||||
CXString clang_BlockCommandComment_getCommandName(CXComment CXC) {
|
CXString clang_BlockCommandComment_getCommandName(CXComment CXC) {
|
||||||
const BlockCommandComment *BCC = getASTNodeAs<BlockCommandComment>(CXC);
|
const BlockCommandComment *BCC = getASTNodeAs<BlockCommandComment>(CXC);
|
||||||
if (!BCC)
|
if (!BCC)
|
||||||
return createCXString((const char *) 0);
|
return cxstring::createNull();
|
||||||
|
|
||||||
const CommandTraits &Traits = getCommandTraits(CXC);
|
const CommandTraits &Traits = getCommandTraits(CXC);
|
||||||
return createCXString(BCC->getCommandName(Traits), /*DupString=*/ false);
|
return createCXString(BCC->getCommandName(Traits), /*DupString=*/ false);
|
||||||
|
@ -238,7 +238,7 @@ CXString clang_BlockCommandComment_getArgText(CXComment CXC,
|
||||||
unsigned ArgIdx) {
|
unsigned ArgIdx) {
|
||||||
const BlockCommandComment *BCC = getASTNodeAs<BlockCommandComment>(CXC);
|
const BlockCommandComment *BCC = getASTNodeAs<BlockCommandComment>(CXC);
|
||||||
if (!BCC || ArgIdx >= BCC->getNumArgs())
|
if (!BCC || ArgIdx >= BCC->getNumArgs())
|
||||||
return createCXString((const char *) 0);
|
return cxstring::createNull();
|
||||||
|
|
||||||
return createCXString(BCC->getArgText(ArgIdx), /*DupString=*/ false);
|
return createCXString(BCC->getArgText(ArgIdx), /*DupString=*/ false);
|
||||||
}
|
}
|
||||||
|
@ -254,7 +254,7 @@ CXComment clang_BlockCommandComment_getParagraph(CXComment CXC) {
|
||||||
CXString clang_ParamCommandComment_getParamName(CXComment CXC) {
|
CXString clang_ParamCommandComment_getParamName(CXComment CXC) {
|
||||||
const ParamCommandComment *PCC = getASTNodeAs<ParamCommandComment>(CXC);
|
const ParamCommandComment *PCC = getASTNodeAs<ParamCommandComment>(CXC);
|
||||||
if (!PCC || !PCC->hasParamName())
|
if (!PCC || !PCC->hasParamName())
|
||||||
return createCXString((const char *) 0);
|
return cxstring::createNull();
|
||||||
|
|
||||||
return createCXString(PCC->getParamNameAsWritten(), /*DupString=*/ false);
|
return createCXString(PCC->getParamNameAsWritten(), /*DupString=*/ false);
|
||||||
}
|
}
|
||||||
|
@ -305,7 +305,7 @@ enum CXCommentParamPassDirection clang_ParamCommandComment_getDirection(
|
||||||
CXString clang_TParamCommandComment_getParamName(CXComment CXC) {
|
CXString clang_TParamCommandComment_getParamName(CXComment CXC) {
|
||||||
const TParamCommandComment *TPCC = getASTNodeAs<TParamCommandComment>(CXC);
|
const TParamCommandComment *TPCC = getASTNodeAs<TParamCommandComment>(CXC);
|
||||||
if (!TPCC || !TPCC->hasParamName())
|
if (!TPCC || !TPCC->hasParamName())
|
||||||
return createCXString((const char *) 0);
|
return cxstring::createNull();
|
||||||
|
|
||||||
return createCXString(TPCC->getParamNameAsWritten(), /*DupString=*/ false);
|
return createCXString(TPCC->getParamNameAsWritten(), /*DupString=*/ false);
|
||||||
}
|
}
|
||||||
|
@ -338,7 +338,7 @@ CXString clang_VerbatimBlockLineComment_getText(CXComment CXC) {
|
||||||
const VerbatimBlockLineComment *VBL =
|
const VerbatimBlockLineComment *VBL =
|
||||||
getASTNodeAs<VerbatimBlockLineComment>(CXC);
|
getASTNodeAs<VerbatimBlockLineComment>(CXC);
|
||||||
if (!VBL)
|
if (!VBL)
|
||||||
return createCXString((const char *) 0);
|
return cxstring::createNull();
|
||||||
|
|
||||||
return createCXString(VBL->getText(), /*DupString=*/ false);
|
return createCXString(VBL->getText(), /*DupString=*/ false);
|
||||||
}
|
}
|
||||||
|
@ -346,7 +346,7 @@ CXString clang_VerbatimBlockLineComment_getText(CXComment CXC) {
|
||||||
CXString clang_VerbatimLineComment_getText(CXComment CXC) {
|
CXString clang_VerbatimLineComment_getText(CXComment CXC) {
|
||||||
const VerbatimLineComment *VLC = getASTNodeAs<VerbatimLineComment>(CXC);
|
const VerbatimLineComment *VLC = getASTNodeAs<VerbatimLineComment>(CXC);
|
||||||
if (!VLC)
|
if (!VLC)
|
||||||
return createCXString((const char *) 0);
|
return cxstring::createNull();
|
||||||
|
|
||||||
return createCXString(VLC->getText(), /*DupString=*/ false);
|
return createCXString(VLC->getText(), /*DupString=*/ false);
|
||||||
}
|
}
|
||||||
|
@ -838,7 +838,7 @@ extern "C" {
|
||||||
CXString clang_HTMLTagComment_getAsString(CXComment CXC) {
|
CXString clang_HTMLTagComment_getAsString(CXComment CXC) {
|
||||||
const HTMLTagComment *HTC = getASTNodeAs<HTMLTagComment>(CXC);
|
const HTMLTagComment *HTC = getASTNodeAs<HTMLTagComment>(CXC);
|
||||||
if (!HTC)
|
if (!HTC)
|
||||||
return createCXString((const char *) 0);
|
return cxstring::createNull();
|
||||||
|
|
||||||
SmallString<128> HTML;
|
SmallString<128> HTML;
|
||||||
CommentASTToHTMLConverter Converter(0, HTML, getCommandTraits(CXC));
|
CommentASTToHTMLConverter Converter(0, HTML, getCommandTraits(CXC));
|
||||||
|
@ -849,7 +849,7 @@ CXString clang_HTMLTagComment_getAsString(CXComment CXC) {
|
||||||
CXString clang_FullComment_getAsHTML(CXComment CXC) {
|
CXString clang_FullComment_getAsHTML(CXComment CXC) {
|
||||||
const FullComment *FC = getASTNodeAs<FullComment>(CXC);
|
const FullComment *FC = getASTNodeAs<FullComment>(CXC);
|
||||||
if (!FC)
|
if (!FC)
|
||||||
return createCXString((const char *) 0);
|
return cxstring::createNull();
|
||||||
|
|
||||||
SmallString<1024> HTML;
|
SmallString<1024> HTML;
|
||||||
CommentASTToHTMLConverter Converter(FC, HTML, getCommandTraits(CXC));
|
CommentASTToHTMLConverter Converter(FC, HTML, getCommandTraits(CXC));
|
||||||
|
@ -1377,7 +1377,7 @@ extern "C" {
|
||||||
CXString clang_FullComment_getAsXML(CXComment CXC) {
|
CXString clang_FullComment_getAsXML(CXComment CXC) {
|
||||||
const FullComment *FC = getASTNodeAs<FullComment>(CXC);
|
const FullComment *FC = getASTNodeAs<FullComment>(CXC);
|
||||||
if (!FC)
|
if (!FC)
|
||||||
return createCXString((const char *) 0);
|
return cxstring::createNull();
|
||||||
ASTContext &Context = FC->getDeclInfo()->CurrentDecl->getASTContext();
|
ASTContext &Context = FC->getDeclInfo()->CurrentDecl->getASTContext();
|
||||||
CXTranslationUnit TU = CXC.TranslationUnit;
|
CXTranslationUnit TU = CXC.TranslationUnit;
|
||||||
SourceManager &SM = cxtu::getASTUnit(TU)->getSourceManager();
|
SourceManager &SM = cxtu::getASTUnit(TU)->getSourceManager();
|
||||||
|
|
|
@ -107,7 +107,7 @@ CXString
|
||||||
clang_CompileCommand_getDirectory(CXCompileCommand CCmd)
|
clang_CompileCommand_getDirectory(CXCompileCommand CCmd)
|
||||||
{
|
{
|
||||||
if (!CCmd)
|
if (!CCmd)
|
||||||
return createCXString((const char*)NULL);
|
return cxstring::createNull();
|
||||||
|
|
||||||
CompileCommand *cmd = static_cast<CompileCommand *>(CCmd);
|
CompileCommand *cmd = static_cast<CompileCommand *>(CCmd);
|
||||||
return createCXString(cmd->Directory.c_str(), /*DupString=*/false);
|
return createCXString(cmd->Directory.c_str(), /*DupString=*/false);
|
||||||
|
@ -126,12 +126,12 @@ CXString
|
||||||
clang_CompileCommand_getArg(CXCompileCommand CCmd, unsigned Arg)
|
clang_CompileCommand_getArg(CXCompileCommand CCmd, unsigned Arg)
|
||||||
{
|
{
|
||||||
if (!CCmd)
|
if (!CCmd)
|
||||||
return createCXString((const char*)NULL);
|
return cxstring::createNull();
|
||||||
|
|
||||||
CompileCommand *Cmd = static_cast<CompileCommand *>(CCmd);
|
CompileCommand *Cmd = static_cast<CompileCommand *>(CCmd);
|
||||||
|
|
||||||
if (Arg >= Cmd->CommandLine.size())
|
if (Arg >= Cmd->CommandLine.size())
|
||||||
return createCXString((const char*)NULL);
|
return cxstring::createNull();
|
||||||
|
|
||||||
return createCXString(Cmd->CommandLine[Arg].c_str(), /*DupString=*/false);
|
return createCXString(Cmd->CommandLine[Arg].c_str(), /*DupString=*/false);
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,6 +29,13 @@ enum CXStringFlag { CXS_Unmanaged, CXS_Malloc, CXS_StringBuf };
|
||||||
// Basic generation of CXStrings.
|
// Basic generation of CXStrings.
|
||||||
//===----------------------------------------------------------------------===//
|
//===----------------------------------------------------------------------===//
|
||||||
|
|
||||||
|
CXString cxstring::createNull() {
|
||||||
|
CXString Str;
|
||||||
|
Str.data = 0;
|
||||||
|
Str.private_flags = CXS_Unmanaged;
|
||||||
|
return Str;
|
||||||
|
}
|
||||||
|
|
||||||
CXString cxstring::createCXString(const char *String, bool DupString){
|
CXString cxstring::createCXString(const char *String, bool DupString){
|
||||||
CXString Str;
|
CXString Str;
|
||||||
if (DupString) {
|
if (DupString) {
|
||||||
|
|
|
@ -25,6 +25,9 @@ namespace cxstring {
|
||||||
|
|
||||||
struct CXStringBuf;
|
struct CXStringBuf;
|
||||||
|
|
||||||
|
/// \brief Create a CXString object for an NULL string.
|
||||||
|
CXString createNull();
|
||||||
|
|
||||||
/// \brief Create a CXString object from a C string.
|
/// \brief Create a CXString object from a C string.
|
||||||
CXString createCXString(const char *String, bool DupString = false);
|
CXString createCXString(const char *String, bool DupString = false);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue