diff options
author | Dmitri Gribenko <gribozavr@gmail.com> | 2012-10-25 18:28:26 +0000 |
---|---|---|
committer | Dmitri Gribenko <gribozavr@gmail.com> | 2012-10-25 18:28:26 +0000 |
commit | 7c98499ba594116d75555f39a1cce28cd26d76a5 (patch) | |
tree | 52434b088e0f5a0ee529f2743a2aea8cce7092d0 /tools | |
parent | 3304c436130edcc0e4c500a48f951249e242d9d0 (diff) | |
download | clang-7c98499ba594116d75555f39a1cce28cd26d76a5.tar.gz |
Comment to XML conversion: avoid memory allocation while pretty-printing the
declaration.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@166707 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'tools')
-rw-r--r-- | tools/libclang/CXComment.cpp | 40 |
1 files changed, 22 insertions, 18 deletions
diff --git a/tools/libclang/CXComment.cpp b/tools/libclang/CXComment.cpp index 0c3b8c7388..fa149a0ff9 100644 --- a/tools/libclang/CXComment.cpp +++ b/tools/libclang/CXComment.cpp @@ -891,6 +891,19 @@ private: const CommandTraits &Traits; const SourceManager &SM; }; + +void getSourceTextOfDeclaration(const DeclInfo *ThisDecl, + SmallVectorImpl<char> &Str) { + ASTContext &Context = ThisDecl->CurrentDecl->getASTContext(); + const LangOptions &LangOpts = Context.getLangOpts(); + llvm::raw_svector_ostream OS(Str); + PrintingPolicy PPolicy(LangOpts); + PPolicy.SuppressAttributes = true; + PPolicy.TerseOutput = true; + ThisDecl->CurrentDecl->print(OS, PPolicy, + /*Indentation*/0, /*PrintInstantiation*/true); +} + } // end unnamed namespace void CommentASTToXMLConverter::visitTextComment(const TextComment *C) { @@ -1032,20 +1045,6 @@ void CommentASTToXMLConverter::visitVerbatimLineComment( Result << "</Verbatim>"; } -static std::string getSourceTextOfDeclaration(const DeclInfo *ThisDecl) { - - ASTContext &Context = ThisDecl->CurrentDecl->getASTContext(); - const LangOptions &LangOpts = Context.getLangOpts(); - std::string SStr; - llvm::raw_string_ostream S(SStr); - PrintingPolicy PPolicy(LangOpts); - PPolicy.SuppressAttributes = true; - PPolicy.TerseOutput = true; - ThisDecl->CurrentDecl->print(S, PPolicy, - /*Indentation*/0, /*PrintInstantiation*/true); - return S.str(); -} - void CommentASTToXMLConverter::visitFullComment(const FullComment *C) { FullCommentParts Parts(C, Traits); @@ -1164,11 +1163,16 @@ void CommentASTToXMLConverter::visitFullComment(const FullComment *C) { Result << "<Other><Name>unknown</Name>"; } + { + // Pretty-print the declaration. + Result << "<Declaration>"; + SmallString<128> Declaration; + getSourceTextOfDeclaration(DI, Declaration); + appendToResultWithXMLEscaping(Declaration); + Result << "</Declaration>"; + } + bool FirstParagraphIsBrief = false; - Result << "<Declaration>"; - appendToResultWithXMLEscaping(getSourceTextOfDeclaration(DI)); - Result << "</Declaration>"; - if (Parts.Brief) { Result << "<Abstract>"; visit(Parts.Brief); |