forked from OSchip/llvm-project
Some code refactoring per Dimitri's comment.
llvm-svn: 170478
This commit is contained in:
parent
85cf531593
commit
b67908a07b
|
@ -861,10 +861,10 @@ public:
|
||||||
SmallVectorImpl<char> &Str,
|
SmallVectorImpl<char> &Str,
|
||||||
const CommandTraits &Traits,
|
const CommandTraits &Traits,
|
||||||
const SourceManager &SM,
|
const SourceManager &SM,
|
||||||
SimpleFormatContext &RTC,
|
SimpleFormatContext &SFC,
|
||||||
unsigned FUID) :
|
unsigned FUID) :
|
||||||
FC(FC), Result(Str), Traits(Traits), SM(SM),
|
FC(FC), Result(Str), Traits(Traits), SM(SM),
|
||||||
FormatRewriterContext(RTC),
|
FormatRewriterContext(SFC),
|
||||||
FormatInMemoryUniqueId(FUID) { }
|
FormatInMemoryUniqueId(FUID) { }
|
||||||
|
|
||||||
// Inline content.
|
// Inline content.
|
||||||
|
@ -887,9 +887,8 @@ public:
|
||||||
// Helpers.
|
// Helpers.
|
||||||
void appendToResultWithXMLEscaping(StringRef S);
|
void appendToResultWithXMLEscaping(StringRef S);
|
||||||
|
|
||||||
unsigned getFormatInMemoryUniqueId() { return FormatInMemoryUniqueId; }
|
void formatTextOfDeclaration(const DeclInfo *DI,
|
||||||
SimpleFormatContext &getFormatRewriterContext()
|
SmallString<128> &Declaration);
|
||||||
{ return FormatRewriterContext; }
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
const FullComment *FC;
|
const FullComment *FC;
|
||||||
|
@ -915,15 +914,15 @@ void getSourceTextOfDeclaration(const DeclInfo *ThisDecl,
|
||||||
/*Indentation*/0, /*PrintInstantiation*/true);
|
/*Indentation*/0, /*PrintInstantiation*/true);
|
||||||
}
|
}
|
||||||
|
|
||||||
void formatTextOfDeclaration(CommentASTToXMLConverter *C,
|
void CommentASTToXMLConverter::formatTextOfDeclaration(
|
||||||
const DeclInfo *DI,
|
const DeclInfo *DI,
|
||||||
SmallString<128> &Declaration) {
|
SmallString<128> &Declaration) {
|
||||||
// FIXME. This conditional is TEMPORARY. We don't want to break multiple
|
// FIXME. This conditional is TEMPORARY. We don't want to break multiple
|
||||||
// large tests each time Format.cpp changes. This condition will
|
// large tests each time Format.cpp changes. This condition will
|
||||||
// go away and formatting will happen for all declarations.
|
// go away and formatting will happen for all declarations.
|
||||||
if (getenv("LIBCLANG_ACTIVATE_FORMAT")) {
|
if (!getenv("LIBCLANG_ACTIVATE_FORMAT"))
|
||||||
SimpleFormatContext &FormatRewriterContext =
|
return;
|
||||||
C->getFormatRewriterContext();
|
|
||||||
// FIXME. formatting API expects null terminated input string.
|
// FIXME. formatting API expects null terminated input string.
|
||||||
// There might be more efficient way of doing this.
|
// There might be more efficient way of doing this.
|
||||||
std::string StringDecl = Declaration.str();
|
std::string StringDecl = Declaration.str();
|
||||||
|
@ -932,7 +931,7 @@ void formatTextOfDeclaration(CommentASTToXMLConverter *C,
|
||||||
// Form a unique in memory buffer name.
|
// Form a unique in memory buffer name.
|
||||||
llvm::SmallString<128> filename;
|
llvm::SmallString<128> filename;
|
||||||
filename += "xmldecl";
|
filename += "xmldecl";
|
||||||
filename += llvm::utostr(C->getFormatInMemoryUniqueId());
|
filename += llvm::utostr(FormatInMemoryUniqueId);
|
||||||
filename += ".xd";
|
filename += ".xd";
|
||||||
FileID ID = FormatRewriterContext.createInMemoryFile(filename, StringDecl);
|
FileID ID = FormatRewriterContext.createInMemoryFile(filename, StringDecl);
|
||||||
SourceLocation Start =
|
SourceLocation Start =
|
||||||
|
@ -950,7 +949,6 @@ void formatTextOfDeclaration(CommentASTToXMLConverter *C,
|
||||||
applyAllReplacements(Replace, FormatRewriterContext.Rewrite);
|
applyAllReplacements(Replace, FormatRewriterContext.Rewrite);
|
||||||
Declaration = FormatRewriterContext.getRewrittenText(ID);
|
Declaration = FormatRewriterContext.getRewrittenText(ID);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
} // end unnamed namespace
|
} // end unnamed namespace
|
||||||
|
|
||||||
|
@ -1216,7 +1214,7 @@ void CommentASTToXMLConverter::visitFullComment(const FullComment *C) {
|
||||||
Result << "<Declaration>";
|
Result << "<Declaration>";
|
||||||
SmallString<128> Declaration;
|
SmallString<128> Declaration;
|
||||||
getSourceTextOfDeclaration(DI, Declaration);
|
getSourceTextOfDeclaration(DI, Declaration);
|
||||||
formatTextOfDeclaration(this, DI, Declaration);
|
formatTextOfDeclaration(DI, Declaration);
|
||||||
appendToResultWithXMLEscaping(Declaration);
|
appendToResultWithXMLEscaping(Declaration);
|
||||||
|
|
||||||
Result << "</Declaration>";
|
Result << "</Declaration>";
|
||||||
|
@ -1382,8 +1380,9 @@ CXString clang_FullComment_getAsXML(CXComment CXC) {
|
||||||
if (!SFC) {
|
if (!SFC) {
|
||||||
SFC = new SimpleFormatContext(Context.getLangOpts());
|
SFC = new SimpleFormatContext(Context.getLangOpts());
|
||||||
TU->FormatContext = SFC;
|
TU->FormatContext = SFC;
|
||||||
}
|
} else if ((TU->FormatInMemoryUniqueId % 10) == 0) {
|
||||||
else if ((TU->FormatInMemoryUniqueId % 10) == 0) {
|
// Delete after some number of iterators, so the buffers don't grow
|
||||||
|
// too large.
|
||||||
delete SFC;
|
delete SFC;
|
||||||
SFC = new SimpleFormatContext(Context.getLangOpts());
|
SFC = new SimpleFormatContext(Context.getLangOpts());
|
||||||
TU->FormatContext = SFC;
|
TU->FormatContext = SFC;
|
||||||
|
|
|
@ -7,7 +7,7 @@
|
||||||
//
|
//
|
||||||
//===----------------------------------------------------------------------===//
|
//===----------------------------------------------------------------------===//
|
||||||
//
|
//
|
||||||
// This file defines a utility class for Rewriter related tests.
|
/// \file This file defines a utility class for use of clang-format in libclang
|
||||||
//
|
//
|
||||||
//===----------------------------------------------------------------------===//
|
//===----------------------------------------------------------------------===//
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue