libclang: type safety for CXTranslationUnitImpl::FormatContext

llvm-svn: 173589
This commit is contained in:
Dmitri Gribenko 2013-01-26 21:39:50 +00:00
parent d36209e308
commit ba82fea336
3 changed files with 10 additions and 15 deletions

View File

@ -2823,7 +2823,7 @@ void clang_disposeTranslationUnit(CXTranslationUnit CTUnit) {
disposeCXStringPool(CTUnit->StringPool);
delete static_cast<CXDiagnosticSetImpl *>(CTUnit->Diagnostics);
disposeOverridenCXCursorsPool(CTUnit->OverridenCursorsPool);
delete static_cast<SimpleFormatContext*>(CTUnit->FormatContext);
delete CTUnit->FormatContext;
delete CTUnit;
}
}

View File

@ -1368,23 +1368,20 @@ CXString clang_FullComment_getAsXML(CXComment CXC) {
ASTContext &Context = FC->getDeclInfo()->CurrentDecl->getASTContext();
CXTranslationUnit TU = CXC.TranslationUnit;
SourceManager &SM = cxtu::getASTUnit(TU)->getSourceManager();
SimpleFormatContext *SFC =
static_cast<SimpleFormatContext*>(TU->FormatContext);
if (!SFC) {
SFC = new SimpleFormatContext(Context.getLangOpts());
TU->FormatContext = SFC;
if (!TU->FormatContext) {
TU->FormatContext = new SimpleFormatContext(Context.getLangOpts());
} else if ((TU->FormatInMemoryUniqueId % 1000) == 0) {
// Delete after some number of iterators, so the buffers don't grow
// too large.
delete SFC;
SFC = new SimpleFormatContext(Context.getLangOpts());
TU->FormatContext = SFC;
delete TU->FormatContext;
TU->FormatContext = new SimpleFormatContext(Context.getLangOpts());
}
SmallString<1024> XML;
CommentASTToXMLConverter Converter(FC, XML, getCommandTraits(CXC), SM,
*SFC, TU->FormatInMemoryUniqueId++);
*TU->FormatContext,
TU->FormatInMemoryUniqueId++);
Converter.visit(FC);
return createCXString(XML.str(), /* DupString = */ true);
}

View File

@ -19,6 +19,7 @@
namespace clang {
class ASTUnit;
class CIndexer;
class SimpleFormatContext;
} // namespace clang
struct CXTranslationUnitImpl {
@ -27,14 +28,11 @@ struct CXTranslationUnitImpl {
void *StringPool;
void *Diagnostics;
void *OverridenCursorsPool;
void *FormatContext;
clang::SimpleFormatContext *FormatContext;
unsigned FormatInMemoryUniqueId;
};
namespace clang {
class ASTUnit;
class CIndexer;
namespace cxtu {
CXTranslationUnitImpl *MakeCXTranslationUnit(CIndexer *CIdx, ASTUnit *AU);