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