[cfe-commits] r173585 - libclang: factor out the frequent pattern static_cast<ASTUnit *>(TU->TUData)
Dmitri Gribenko
gribozavr at gmail.com
Sat Jan 26 10:53:39 PST 2013
Author: gribozavr
Date: Sat Jan 26 12:53:38 2013
New Revision: 173585
URL: http://llvm.org/viewvc/llvm-project?rev=173585&view=rev
Log:
libclang: factor out the frequent pattern static_cast<ASTUnit *>(TU->TUData)
into a getter cxtu::getASTUnit(TU)
Modified:
cfe/trunk/tools/libclang/CIndex.cpp
cfe/trunk/tools/libclang/CIndexCodeCompletion.cpp
cfe/trunk/tools/libclang/CIndexDiagnostic.cpp
cfe/trunk/tools/libclang/CIndexHigh.cpp
cfe/trunk/tools/libclang/CIndexInclusionStack.cpp
cfe/trunk/tools/libclang/CXComment.cpp
cfe/trunk/tools/libclang/CXComment.h
cfe/trunk/tools/libclang/CXCursor.cpp
cfe/trunk/tools/libclang/CXSourceLocation.cpp
cfe/trunk/tools/libclang/CXTranslationUnit.h
cfe/trunk/tools/libclang/CXType.cpp
cfe/trunk/tools/libclang/CursorVisitor.h
cfe/trunk/tools/libclang/Indexing.cpp
cfe/trunk/tools/libclang/IndexingContext.cpp
Modified: cfe/trunk/tools/libclang/CIndex.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/libclang/CIndex.cpp?rev=173585&r1=173584&r2=173585&view=diff
==============================================================================
--- cfe/trunk/tools/libclang/CIndex.cpp (original)
+++ cfe/trunk/tools/libclang/CIndex.cpp Sat Jan 26 12:53:38 2013
@@ -228,7 +228,7 @@ void CursorVisitor::visitFileRegion() {
if (RegionOfInterest.isInvalid())
return;
- ASTUnit *Unit = static_cast<ASTUnit *>(TU->TUData);
+ ASTUnit *Unit = cxtu::getASTUnit(TU);
SourceManager &SM = Unit->getSourceManager();
std::pair<FileID, unsigned>
@@ -274,7 +274,7 @@ static bool isInLexicalContext(Decl *D,
void CursorVisitor::visitDeclsFromFileRegion(FileID File,
unsigned Offset, unsigned Length) {
- ASTUnit *Unit = static_cast<ASTUnit *>(TU->TUData);
+ ASTUnit *Unit = cxtu::getASTUnit(TU);
SourceManager &SM = Unit->getSourceManager();
SourceRange Range = RegionOfInterest;
@@ -485,8 +485,8 @@ bool CursorVisitor::VisitChildren(CXCurs
}
if (clang_isTranslationUnit(Cursor.kind)) {
- CXTranslationUnit tu = getCursorTU(Cursor);
- ASTUnit *CXXUnit = static_cast<ASTUnit*>(tu->TUData);
+ CXTranslationUnit TU = getCursorTU(Cursor);
+ ASTUnit *CXXUnit = cxtu::getASTUnit(TU);
int VisitOrder[2] = { VisitPreprocessorLast, !VisitPreprocessorLast };
for (unsigned I = 0; I != 2; ++I) {
@@ -496,7 +496,7 @@ bool CursorVisitor::VisitChildren(CXCurs
for (ASTUnit::top_level_iterator TL = CXXUnit->top_level_begin(),
TLEnd = CXXUnit->top_level_end();
TL != TLEnd; ++TL) {
- if (Visit(MakeCXCursor(*TL, tu, RegionOfInterest), true))
+ if (Visit(MakeCXCursor(*TL, TU, RegionOfInterest), true))
return true;
}
} else if (VisitDeclContext(
@@ -2762,7 +2762,7 @@ static void clang_saveTranslationUnit_Im
if (CXXIdx->isOptEnabled(CXGlobalOpt_ThreadBackgroundPriorityForIndexing))
setThreadBackgroundPriority();
- bool hadError = static_cast<ASTUnit *>(STUI->TU->TUData)->Save(STUI->FileName);
+ bool hadError = cxtu::getASTUnit(STUI->TU)->Save(STUI->FileName);
STUI->result = hadError ? CXSaveError_Unknown : CXSaveError_None;
}
@@ -2775,7 +2775,7 @@ int clang_saveTranslationUnit(CXTranslat
if (!TU)
return CXSaveError_InvalidTU;
- ASTUnit *CXXUnit = static_cast<ASTUnit *>(TU->TUData);
+ ASTUnit *CXXUnit = cxtu::getASTUnit(TU);
ASTUnit::ConcurrencyCheck Check(*CXXUnit);
if (!CXXUnit->hasSema())
return CXSaveError_InvalidTU;
@@ -2816,10 +2816,10 @@ void clang_disposeTranslationUnit(CXTran
if (CTUnit) {
// If the translation unit has been marked as unsafe to free, just discard
// it.
- if (static_cast<ASTUnit *>(CTUnit->TUData)->isUnsafeToFree())
+ if (cxtu::getASTUnit(CTUnit)->isUnsafeToFree())
return;
- delete static_cast<ASTUnit *>(CTUnit->TUData);
+ delete cxtu::getASTUnit(CTUnit);
disposeCXStringPool(CTUnit->StringPool);
delete static_cast<CXDiagnosticSetImpl *>(CTUnit->Diagnostics);
disposeOverridenCXCursorsPool(CTUnit->OverridenCursorsPool);
@@ -2861,7 +2861,7 @@ static void clang_reparseTranslationUnit
if (CXXIdx->isOptEnabled(CXGlobalOpt_ThreadBackgroundPriorityForEditing))
setThreadBackgroundPriority();
- ASTUnit *CXXUnit = static_cast<ASTUnit *>(TU->TUData);
+ ASTUnit *CXXUnit = cxtu::getASTUnit(TU);
ASTUnit::ConcurrencyCheck Check(*CXXUnit);
OwningPtr<std::vector<ASTUnit::RemappedFile> >
@@ -2904,7 +2904,7 @@ int clang_reparseTranslationUnit(CXTrans
if (!RunSafely(CRC, clang_reparseTranslationUnit_Impl, &RTUI)) {
fprintf(stderr, "libclang: crash detected during reparsing\n");
- static_cast<ASTUnit *>(TU->TUData)->setUnsafeToFree(true);
+ cxtu::getASTUnit(TU)->setUnsafeToFree(true);
return 1;
} else if (getenv("LIBCLANG_RESOURCE_USAGE"))
PrintLibclangResourceUsage(TU);
@@ -2917,12 +2917,12 @@ CXString clang_getTranslationUnitSpellin
if (!CTUnit)
return createCXString("");
- ASTUnit *CXXUnit = static_cast<ASTUnit *>(CTUnit->TUData);
+ ASTUnit *CXXUnit = cxtu::getASTUnit(CTUnit);
return createCXString(CXXUnit->getOriginalSourceFileName(), true);
}
CXCursor clang_getTranslationUnitCursor(CXTranslationUnit TU) {
- ASTUnit *CXXUnit = static_cast<ASTUnit*>(TU->TUData);
+ ASTUnit *CXXUnit = cxtu::getASTUnit(TU);
return MakeCXCursor(CXXUnit->getASTContext().getTranslationUnitDecl(), TU);
}
@@ -2949,21 +2949,21 @@ time_t clang_getFileTime(CXFile SFile) {
return FEnt->getModificationTime();
}
-CXFile clang_getFile(CXTranslationUnit tu, const char *file_name) {
- if (!tu)
+CXFile clang_getFile(CXTranslationUnit TU, const char *file_name) {
+ if (!TU)
return 0;
- ASTUnit *CXXUnit = static_cast<ASTUnit *>(tu->TUData);
+ ASTUnit *CXXUnit = cxtu::getASTUnit(TU);
FileManager &FMgr = CXXUnit->getFileManager();
return const_cast<FileEntry *>(FMgr.getFile(file_name));
}
-unsigned clang_isFileMultipleIncludeGuarded(CXTranslationUnit tu, CXFile file) {
- if (!tu || !file)
+unsigned clang_isFileMultipleIncludeGuarded(CXTranslationUnit TU, CXFile file) {
+ if (!TU || !file)
return 0;
- ASTUnit *CXXUnit = static_cast<ASTUnit *>(tu->TUData);
+ ASTUnit *CXXUnit = cxtu::getASTUnit(TU);
FileEntry *FEnt = static_cast<FileEntry *>(file);
return CXXUnit->getPreprocessor().getHeaderSearchInfo()
.isFileMultipleIncludeGuarded(FEnt);
@@ -3849,7 +3849,7 @@ CXCursor clang_getCursor(CXTranslationUn
if (!TU)
return clang_getNullCursor();
- ASTUnit *CXXUnit = static_cast<ASTUnit *>(TU->TUData);
+ ASTUnit *CXXUnit = cxtu::getASTUnit(TU);
ASTUnit::ConcurrencyCheck Check(*CXXUnit);
SourceLocation SLoc = cxloc::translateSourceLocation(Loc);
@@ -4122,7 +4122,7 @@ CXCursor cxcursor::getCursor(CXTranslati
if (SLoc.isInvalid())
return clang_getNullCursor();
- ASTUnit *CXXUnit = static_cast<ASTUnit *>(TU->TUData);
+ ASTUnit *CXXUnit = cxtu::getASTUnit(TU);
// Translate the given source location to make it point at the beginning of
// the token under the cursor.
@@ -4387,9 +4387,9 @@ CXCursor clang_getCursorReferenced(CXCur
case CXCursor_LabelRef:
// FIXME: We end up faking the "parent" declaration here because we
// don't want to make CXCursor larger.
- return MakeCXCursor(getCursorLabelRef(C).first,
- static_cast<ASTUnit*>(tu->TUData)->getASTContext()
- .getTranslationUnitDecl(),
+ return MakeCXCursor(getCursorLabelRef(C).first,
+ cxtu::getASTUnit(tu)->getASTContext()
+ .getTranslationUnitDecl(),
tu);
case CXCursor_OverloadedDeclRef:
@@ -4790,7 +4790,7 @@ CXString clang_getTokenSpelling(CXTransl
// We have to find the starting buffer pointer the hard way, by
// deconstructing the source location.
- ASTUnit *CXXUnit = static_cast<ASTUnit *>(TU->TUData);
+ ASTUnit *CXXUnit = cxtu::getASTUnit(TU);
if (!CXXUnit)
return createCXString("");
@@ -4807,7 +4807,7 @@ CXString clang_getTokenSpelling(CXTransl
}
CXSourceLocation clang_getTokenLocation(CXTranslationUnit TU, CXToken CXTok) {
- ASTUnit *CXXUnit = static_cast<ASTUnit *>(TU->TUData);
+ ASTUnit *CXXUnit = cxtu::getASTUnit(TU);
if (!CXXUnit)
return clang_getNullLocation();
@@ -4816,7 +4816,7 @@ CXSourceLocation clang_getTokenLocation(
}
CXSourceRange clang_getTokenExtent(CXTranslationUnit TU, CXToken CXTok) {
- ASTUnit *CXXUnit = static_cast<ASTUnit *>(TU->TUData);
+ ASTUnit *CXXUnit = cxtu::getASTUnit(TU);
if (!CXXUnit)
return clang_getNullRange();
@@ -4907,7 +4907,7 @@ void clang_tokenize(CXTranslationUnit TU
if (NumTokens)
*NumTokens = 0;
- ASTUnit *CXXUnit = static_cast<ASTUnit *>(TU->TUData);
+ ASTUnit *CXXUnit = cxtu::getASTUnit(TU);
if (!CXXUnit || !Tokens || !NumTokens)
return;
@@ -4982,17 +4982,17 @@ class AnnotateTokensWorker {
public:
AnnotateTokensWorker(CXToken *tokens, CXCursor *cursors, unsigned numTokens,
- CXTranslationUnit tu, SourceRange RegionOfInterest)
+ CXTranslationUnit TU, SourceRange RegionOfInterest)
: Tokens(tokens), Cursors(cursors),
NumTokens(numTokens), TokIdx(0), PreprocessingTokIdx(0),
- AnnotateVis(tu,
+ AnnotateVis(TU,
AnnotateTokensVisitor, this,
/*VisitPreprocessorLast=*/true,
/*VisitIncludedEntities=*/false,
RegionOfInterest,
/*VisitDeclsOnly=*/false,
AnnotateTokensPostChildrenVisitor),
- SrcMgr(static_cast<ASTUnit*>(tu->TUData)->getSourceManager()),
+ SrcMgr(cxtu::getASTUnit(TU)->getSourceManager()),
HasContextSensitiveKeywords(false) { }
void VisitChildren(CXCursor C) { AnnotateVis.VisitChildren(C); }
@@ -5369,7 +5369,7 @@ static void annotatePreprocessorTokens(C
CXCursor *Cursors,
CXToken *Tokens,
unsigned NumTokens) {
- ASTUnit *CXXUnit = static_cast<ASTUnit *>(TU->TUData);
+ ASTUnit *CXXUnit = cxtu::getASTUnit(TU);
Preprocessor &PP = CXXUnit->getPreprocessor();
SourceManager &SourceMgr = CXXUnit->getSourceManager();
@@ -5591,7 +5591,7 @@ void clang_annotateTokens(CXTranslationU
for (unsigned I = 0; I != NumTokens; ++I)
Cursors[I] = C;
- ASTUnit *CXXUnit = static_cast<ASTUnit *>(TU->TUData);
+ ASTUnit *CXXUnit = cxtu::getASTUnit(TU);
if (!CXXUnit)
return;
@@ -6089,7 +6089,7 @@ CXTUResourceUsage clang_getCXTUResourceU
return usage;
}
- ASTUnit *astUnit = static_cast<ASTUnit*>(TU->TUData);
+ ASTUnit *astUnit = cxtu::getASTUnit(TU);
OwningPtr<MemUsageEntries> entries(new MemUsageEntries());
ASTContext &astContext = astUnit->getASTContext();
@@ -6260,7 +6260,7 @@ MacroInfo *cxindex::getMacroInfo(const I
if (!II.hadMacroDefinition())
return 0;
- ASTUnit *Unit = static_cast<ASTUnit *>(TU->TUData);
+ ASTUnit *Unit = cxtu::getASTUnit(TU);
Preprocessor &PP = Unit->getPreprocessor();
MacroInfo *MI = PP.getMacroInfoHistory(&II);
while (MI) {
@@ -6295,7 +6295,7 @@ MacroDefinition *cxindex::checkForMacroI
return 0;
SourceRange DefRange(MI->getReplacementToken(0).getLocation(),
MI->getDefinitionEndLoc());
- ASTUnit *Unit = static_cast<ASTUnit *>(TU->TUData);
+ ASTUnit *Unit = cxtu::getASTUnit(TU);
// Check that the token is inside the definition and not its argument list.
SourceManager &SM = Unit->getSourceManager();
@@ -6333,7 +6333,7 @@ MacroDefinition *cxindex::checkForMacroI
if (MI->getNumTokens() == 0)
return 0;
- ASTUnit *Unit = static_cast<ASTUnit *>(TU->TUData);
+ ASTUnit *Unit = cxtu::getASTUnit(TU);
Preprocessor &PP = Unit->getPreprocessor();
if (!PP.getPreprocessingRecord())
return 0;
@@ -6355,7 +6355,7 @@ CXString clang_getClangVersion() {
Logger &cxindex::Logger::operator<<(CXTranslationUnit TU) {
if (TU) {
- if (ASTUnit *Unit = static_cast<ASTUnit *>(TU->TUData)) {
+ if (ASTUnit *Unit = cxtu::getASTUnit(TU)) {
LogOS << '<' << Unit->getMainFileName() << '>';
return *this;
}
Modified: cfe/trunk/tools/libclang/CIndexCodeCompletion.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/libclang/CIndexCodeCompletion.cpp?rev=173585&r1=173584&r2=173585&view=diff
==============================================================================
--- cfe/trunk/tools/libclang/CIndexCodeCompletion.cpp (original)
+++ cfe/trunk/tools/libclang/CIndexCodeCompletion.cpp Sat Jan 26 12:53:38 2013
@@ -688,7 +688,7 @@ void clang_codeCompleteAt_Impl(void *Use
bool EnableLogging = getenv("LIBCLANG_CODE_COMPLETION_LOGGING") != 0;
- ASTUnit *AST = static_cast<ASTUnit *>(TU->TUData);
+ ASTUnit *AST = cxtu::getASTUnit(TU);
if (!AST)
return;
@@ -841,7 +841,7 @@ CXCodeCompleteResults *clang_codeComplet
if (!RunSafely(CRC, clang_codeCompleteAt_Impl, &CCAI)) {
fprintf(stderr, "libclang: crash detected in code completion\n");
- static_cast<ASTUnit *>(TU->TUData)->setUnsafeToFree(true);
+ cxtu::getASTUnit(TU)->setUnsafeToFree(true);
return 0;
} else if (getenv("LIBCLANG_RESOURCE_USAGE"))
PrintLibclangResourceUsage(TU);
Modified: cfe/trunk/tools/libclang/CIndexDiagnostic.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/libclang/CIndexDiagnostic.cpp?rev=173585&r1=173584&r2=173585&view=diff
==============================================================================
--- cfe/trunk/tools/libclang/CIndexDiagnostic.cpp (original)
+++ cfe/trunk/tools/libclang/CIndexDiagnostic.cpp Sat Jan 26 12:53:38 2013
@@ -158,7 +158,7 @@ public:
CXDiagnosticSetImpl *cxdiag::lazyCreateDiags(CXTranslationUnit TU,
bool checkIfChanged) {
- ASTUnit *AU = static_cast<ASTUnit *>(TU->TUData);
+ ASTUnit *AU = cxtu::getASTUnit(TU);
if (TU->Diagnostics && checkIfChanged) {
// In normal use, ASTUnit's diagnostics should not change unless we reparse.
Modified: cfe/trunk/tools/libclang/CIndexHigh.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/libclang/CIndexHigh.cpp?rev=173585&r1=173584&r2=173585&view=diff
==============================================================================
--- cfe/trunk/tools/libclang/CIndexHigh.cpp (original)
+++ cfe/trunk/tools/libclang/CIndexHigh.cpp Sat Jan 26 12:53:38 2013
@@ -62,7 +62,7 @@ struct FindFileIdRefVisitData {
}
ASTContext &getASTContext() const {
- return static_cast<ASTUnit *>(TU->TUData)->getASTContext();
+ return cxtu::getASTUnit(TU)->getASTContext();
}
/// \brief We are looking to find all semantically relevant identifiers,
@@ -215,8 +215,7 @@ static void findIdRefsInFile(CXTranslati
const FileEntry *File,
CXCursorAndRangeVisitor Visitor) {
assert(clang_isDeclaration(declCursor.kind));
- ASTUnit *Unit = static_cast<ASTUnit*>(TU->TUData);
- SourceManager &SM = Unit->getSourceManager();
+ SourceManager &SM = cxtu::getASTUnit(TU)->getSourceManager();
FileID FID = SM.translateFile(File);
const Decl *Dcl = cxcursor::getCursorDecl(declCursor);
@@ -313,7 +312,7 @@ static void findMacroRefsInFile(CXTransl
Cursor.kind != CXCursor_MacroExpansion)
return;
- ASTUnit *Unit = static_cast<ASTUnit*>(TU->TUData);
+ ASTUnit *Unit = cxtu::getASTUnit(TU);
SourceManager &SM = Unit->getSourceManager();
FileID FID = SM.translateFile(File);
Modified: cfe/trunk/tools/libclang/CIndexInclusionStack.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/libclang/CIndexInclusionStack.cpp?rev=173585&r1=173584&r2=173585&view=diff
==============================================================================
--- cfe/trunk/tools/libclang/CIndexInclusionStack.cpp (original)
+++ cfe/trunk/tools/libclang/CIndexInclusionStack.cpp Sat Jan 26 12:53:38 2013
@@ -25,7 +25,7 @@ extern "C" {
void clang_getInclusions(CXTranslationUnit TU, CXInclusionVisitor CB,
CXClientData clientData) {
- ASTUnit *CXXUnit = static_cast<ASTUnit *>(TU->TUData);
+ ASTUnit *CXXUnit = cxtu::getASTUnit(TU);
SourceManager &SM = CXXUnit->getSourceManager();
ASTContext &Ctx = CXXUnit->getASTContext();
Modified: cfe/trunk/tools/libclang/CXComment.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/libclang/CXComment.cpp?rev=173585&r1=173584&r2=173585&view=diff
==============================================================================
--- cfe/trunk/tools/libclang/CXComment.cpp (original)
+++ cfe/trunk/tools/libclang/CXComment.cpp Sat Jan 26 12:53:38 2013
@@ -1367,7 +1367,7 @@ CXString clang_FullComment_getAsXML(CXCo
return createCXString((const char *) 0);
ASTContext &Context = FC->getDeclInfo()->CurrentDecl->getASTContext();
CXTranslationUnit TU = CXC.TranslationUnit;
- SourceManager &SM = static_cast<ASTUnit *>(TU->TUData)->getSourceManager();
+ SourceManager &SM = cxtu::getASTUnit(TU)->getSourceManager();
SimpleFormatContext *SFC =
static_cast<SimpleFormatContext*>(TU->FormatContext);
Modified: cfe/trunk/tools/libclang/CXComment.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/libclang/CXComment.h?rev=173585&r1=173584&r2=173585&view=diff
==============================================================================
--- cfe/trunk/tools/libclang/CXComment.h (original)
+++ cfe/trunk/tools/libclang/CXComment.h Sat Jan 26 12:53:38 2013
@@ -49,7 +49,7 @@ inline const T *getASTNodeAs(CXComment C
}
inline ASTContext &getASTContext(CXComment CXC) {
- return static_cast<ASTUnit *>(CXC.TranslationUnit->TUData)->getASTContext();
+ return cxtu::getASTUnit(CXC.TranslationUnit)->getASTContext();
}
inline comments::CommandTraits &getCommandTraits(CXComment CXC) {
Modified: cfe/trunk/tools/libclang/CXCursor.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/libclang/CXCursor.cpp?rev=173585&r1=173584&r2=173585&view=diff
==============================================================================
--- cfe/trunk/tools/libclang/CXCursor.cpp (original)
+++ cfe/trunk/tools/libclang/CXCursor.cpp Sat Jan 26 12:53:38 2013
@@ -810,7 +810,7 @@ ASTUnit *cxcursor::getCursorASTUnit(CXCu
CXTranslationUnit TU = getCursorTU(Cursor);
if (!TU)
return 0;
- return static_cast<ASTUnit *>(TU->TUData);
+ return cxtu::getASTUnit(TU);
}
CXTranslationUnit cxcursor::getCursorTU(CXCursor Cursor) {
Modified: cfe/trunk/tools/libclang/CXSourceLocation.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/libclang/CXSourceLocation.cpp?rev=173585&r1=173584&r2=173585&view=diff
==============================================================================
--- cfe/trunk/tools/libclang/CXSourceLocation.cpp (original)
+++ cfe/trunk/tools/libclang/CXSourceLocation.cpp Sat Jan 26 12:53:38 2013
@@ -119,15 +119,15 @@ CXSourceLocation clang_getRangeEnd(CXSou
extern "C" {
-CXSourceLocation clang_getLocation(CXTranslationUnit tu,
+CXSourceLocation clang_getLocation(CXTranslationUnit TU,
CXFile file,
unsigned line,
unsigned column) {
- if (!tu || !file)
+ if (!TU || !file)
return clang_getNullLocation();
LogRef Log = Logger::make(LLVM_FUNCTION_NAME);
- ASTUnit *CXXUnit = static_cast<ASTUnit *>(tu->TUData);
+ ASTUnit *CXXUnit = cxtu::getASTUnit(TU);
ASTUnit::ConcurrencyCheck Check(*CXXUnit);
const FileEntry *File = static_cast<const FileEntry *>(file);
SourceLocation SLoc = CXXUnit->getLocation(File, line, column);
@@ -147,13 +147,13 @@ CXSourceLocation clang_getLocation(CXTra
return CXLoc;
}
-CXSourceLocation clang_getLocationForOffset(CXTranslationUnit tu,
+CXSourceLocation clang_getLocationForOffset(CXTranslationUnit TU,
CXFile file,
unsigned offset) {
- if (!tu || !file)
+ if (!TU || !file)
return clang_getNullLocation();
- ASTUnit *CXXUnit = static_cast<ASTUnit *>(tu->TUData);
+ ASTUnit *CXXUnit = cxtu::getASTUnit(TU);
SourceLocation SLoc
= CXXUnit->getLocation(static_cast<const FileEntry *>(file), offset);
Modified: cfe/trunk/tools/libclang/CXTranslationUnit.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/libclang/CXTranslationUnit.h?rev=173585&r1=173584&r2=173585&view=diff
==============================================================================
--- cfe/trunk/tools/libclang/CXTranslationUnit.h (original)
+++ cfe/trunk/tools/libclang/CXTranslationUnit.h Sat Jan 26 12:53:38 2013
@@ -14,6 +14,8 @@
#ifndef LLVM_CLANG_CXTRANSLATIONUNIT_H
#define LLVM_CLANG_CXTRANSLATIONUNIT_H
+#include "clang-c/Index.h"
+
extern "C" {
struct CXTranslationUnitImpl {
void *CIdx;
@@ -33,7 +35,11 @@ namespace clang {
namespace cxtu {
CXTranslationUnitImpl *MakeCXTranslationUnit(CIndexer *CIdx, ASTUnit *TU);
-
+
+static inline ASTUnit *getASTUnit(CXTranslationUnit TU) {
+ return static_cast<ASTUnit *>(TU->TUData);
+}
+
class CXTUOwner {
CXTranslationUnitImpl *TU;
Modified: cfe/trunk/tools/libclang/CXType.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/libclang/CXType.cpp?rev=173585&r1=173584&r2=173585&view=diff
==============================================================================
--- cfe/trunk/tools/libclang/CXType.cpp (original)
+++ cfe/trunk/tools/libclang/CXType.cpp Sat Jan 26 12:53:38 2013
@@ -97,7 +97,7 @@ CXType cxtype::MakeCXType(QualType T, CX
CXTypeKind TK = CXType_Invalid;
if (TU && !T.isNull()) {
- ASTContext &Ctx = static_cast<ASTUnit *>(TU->TUData)->getASTContext();
+ ASTContext &Ctx = cxtu::getASTUnit(TU)->getASTContext();
if (Ctx.getLangOpts().ObjC1) {
QualType UnqualT = T.getUnqualifiedType();
if (Ctx.isObjCIdType(UnqualT))
@@ -134,7 +134,7 @@ CXType clang_getCursorType(CXCursor C) {
if (!TU)
return MakeCXType(QualType(), TU);
- ASTContext &Context = static_cast<ASTUnit *>(TU->TUData)->getASTContext();
+ ASTContext &Context = cxtu::getASTUnit(TU)->getASTContext();
if (clang_isExpression(C.kind)) {
QualType T = cxcursor::getCursorExpr(C)->getType();
return MakeCXType(T, TU);
@@ -293,8 +293,9 @@ CXType clang_getCanonicalType(CXType CT)
if (T.isNull())
return MakeCXType(QualType(), GetTU(CT));
- ASTUnit *AU = static_cast<ASTUnit*>(TU->TUData);
- return MakeCXType(AU->getASTContext().getCanonicalType(T), TU);
+ return MakeCXType(cxtu::getASTUnit(TU)->getASTContext()
+ .getCanonicalType(T),
+ TU);
}
unsigned clang_isConstQualifiedType(CXType CT) {
@@ -552,9 +553,8 @@ unsigned clang_isPODType(CXType X) {
return 0;
CXTranslationUnit TU = GetTU(X);
- ASTUnit *AU = static_cast<ASTUnit*>(TU->TUData);
- return T.isPODType(AU->getASTContext()) ? 1 : 0;
+ return T.isPODType(cxtu::getASTUnit(TU)->getASTContext()) ? 1 : 0;
}
CXType clang_getElementType(CXType CT) {
Modified: cfe/trunk/tools/libclang/CursorVisitor.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/libclang/CursorVisitor.h?rev=173585&r1=173584&r2=173585&view=diff
==============================================================================
--- cfe/trunk/tools/libclang/CursorVisitor.h (original)
+++ cfe/trunk/tools/libclang/CursorVisitor.h Sat Jan 26 12:53:38 2013
@@ -148,7 +148,7 @@ public:
SourceRange RegionOfInterest = SourceRange(),
bool VisitDeclsOnly = false,
PostChildrenVisitorTy PostChildrenVisitor = 0)
- : TU(TU), AU(static_cast<ASTUnit*>(TU->TUData)),
+ : TU(TU), AU(cxtu::getASTUnit(TU)),
Visitor(Visitor), PostChildrenVisitor(PostChildrenVisitor),
ClientData(ClientData),
VisitPreprocessorLast(VisitPreprocessorLast),
@@ -172,7 +172,7 @@ public:
}
}
- ASTUnit *getASTUnit() const { return static_cast<ASTUnit*>(TU->TUData); }
+ ASTUnit *getASTUnit() const { return AU; }
CXTranslationUnit getTU() const { return TU; }
bool Visit(CXCursor Cursor, bool CheckedRegionOfInterest = false);
Modified: cfe/trunk/tools/libclang/Indexing.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/libclang/Indexing.cpp?rev=173585&r1=173584&r2=173585&view=diff
==============================================================================
--- cfe/trunk/tools/libclang/Indexing.cpp (original)
+++ cfe/trunk/tools/libclang/Indexing.cpp Sat Jan 26 12:53:38 2013
@@ -783,7 +783,7 @@ static void clang_indexTranslationUnit_I
llvm::CrashRecoveryContextCleanupRegistrar<IndexingConsumer>
IndexConsumerCleanup(IndexConsumer.get());
- ASTUnit *Unit = static_cast<ASTUnit *>(TU->TUData);
+ ASTUnit *Unit = cxtu::getASTUnit(TU);
if (!Unit)
return;
Modified: cfe/trunk/tools/libclang/IndexingContext.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/libclang/IndexingContext.cpp?rev=173585&r1=173584&r2=173585&view=diff
==============================================================================
--- cfe/trunk/tools/libclang/IndexingContext.cpp (original)
+++ cfe/trunk/tools/libclang/IndexingContext.cpp Sat Jan 26 12:53:38 2013
@@ -196,11 +196,11 @@ const char *ScratchAlloc::copyCStr(Strin
void IndexingContext::setASTContext(ASTContext &ctx) {
Ctx = &ctx;
- static_cast<ASTUnit*>(CXTU->TUData)->setASTContext(&ctx);
+ cxtu::getASTUnit(CXTU)->setASTContext(&ctx);
}
void IndexingContext::setPreprocessor(Preprocessor &PP) {
- static_cast<ASTUnit*>(CXTU->TUData)->setPreprocessor(&PP);
+ cxtu::getASTUnit(CXTU)->setPreprocessor(&PP);
}
bool IndexingContext::isFunctionLocalDecl(const Decl *D) {
More information about the cfe-commits
mailing list