libclang: type safety for CXTranslationUnitImpl::FormatContext
authorDmitri Gribenko <gribozavr@gmail.com>
Sat, 26 Jan 2013 21:39:50 +0000 (21:39 +0000)
committerDmitri Gribenko <gribozavr@gmail.com>
Sat, 26 Jan 2013 21:39:50 +0000 (21:39 +0000)
llvm-svn: 173589

clang/tools/libclang/CIndex.cpp
clang/tools/libclang/CXComment.cpp
clang/tools/libclang/CXTranslationUnit.h

index c4d4a5a..a78b607 100644 (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;
   }
 }
index b14e174..0fcd7c2 100644 (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);
 }
index 15e89ea..428f562 100644 (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);