*Log << TU << ' ' << FileName;
}
- if (!TU)
+ if (isNotUseableTU(TU)) {
+ LOG_BAD_TU(TU);
return CXSaveError_InvalidTU;
+ }
ASTUnit *CXXUnit = cxtu::getASTUnit(TU);
ASTUnit::ConcurrencyCheck Check(*CXXUnit);
static void clang_reparseTranslationUnit_Impl(void *UserData) {
ReparseTranslationUnitInfo *RTUI =
static_cast<ReparseTranslationUnitInfo*>(UserData);
+ RTUI->result = 1; // Error.
+
CXTranslationUnit TU = RTUI->TU;
- if (!TU)
+ if (isNotUseableTU(TU)) {
+ LOG_BAD_TU(TU);
return;
+ }
// Reset the associated diagnostics.
delete static_cast<CXDiagnosticSetImpl*>(TU->Diagnostics);
struct CXUnsavedFile *unsaved_files = RTUI->unsaved_files;
unsigned options = RTUI->options;
(void) options;
- RTUI->result = 1;
CIndexer *CXXIdx = TU->CIdx;
if (CXXIdx->isOptEnabled(CXGlobalOpt_ThreadBackgroundPriorityForEditing))
CXString clang_getTranslationUnitSpelling(CXTranslationUnit CTUnit) {
- if (!CTUnit)
+ if (isNotUseableTU(CTUnit)) {
+ LOG_BAD_TU(CTUnit);
return cxstring::createEmpty();
+ }
ASTUnit *CXXUnit = cxtu::getASTUnit(CTUnit);
return cxstring::createDup(CXXUnit->getOriginalSourceFileName());
}
CXCursor clang_getTranslationUnitCursor(CXTranslationUnit TU) {
- if (!TU)
+ if (isNotUseableTU(TU)) {
+ LOG_BAD_TU(TU);
return clang_getNullCursor();
+ }
ASTUnit *CXXUnit = cxtu::getASTUnit(TU);
return MakeCXCursor(CXXUnit->getASTContext().getTranslationUnitDecl(), TU);
}
CXFile clang_getFile(CXTranslationUnit TU, const char *file_name) {
- if (!TU)
+ if (isNotUseableTU(TU)) {
+ LOG_BAD_TU(TU);
return 0;
+ }
ASTUnit *CXXUnit = cxtu::getASTUnit(TU);
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 (isNotUseableTU(TU)) {
+ LOG_BAD_TU(TU);
+ return 0;
+ }
+
+ if (!file)
return 0;
ASTUnit *CXXUnit = cxtu::getASTUnit(TU);
}
CXCursor clang_getCursor(CXTranslationUnit TU, CXSourceLocation Loc) {
- if (!TU)
+ if (isNotUseableTU(TU)) {
+ LOG_BAD_TU(TU);
return clang_getNullCursor();
+ }
ASTUnit *CXXUnit = cxtu::getASTUnit(TU);
ASTUnit::ConcurrencyCheck Check(*CXXUnit);
break;
}
+ if (isNotUseableTU(TU)) {
+ LOG_BAD_TU(TU);
+ return cxstring::createEmpty();
+ }
+
// We have to find the starting buffer pointer the hard way, by
// deconstructing the source location.
ASTUnit *CXXUnit = cxtu::getASTUnit(TU);
}
CXSourceLocation clang_getTokenLocation(CXTranslationUnit TU, CXToken CXTok) {
+ if (isNotUseableTU(TU)) {
+ LOG_BAD_TU(TU);
+ return clang_getNullLocation();
+ }
+
ASTUnit *CXXUnit = cxtu::getASTUnit(TU);
if (!CXXUnit)
return clang_getNullLocation();
}
CXSourceRange clang_getTokenExtent(CXTranslationUnit TU, CXToken CXTok) {
+ if (isNotUseableTU(TU)) {
+ LOG_BAD_TU(TU);
+ return clang_getNullRange();
+ }
+
ASTUnit *CXXUnit = cxtu::getASTUnit(TU);
if (!CXXUnit)
return clang_getNullRange();
if (NumTokens)
*NumTokens = 0;
- if (!TU)
+ if (isNotUseableTU(TU)) {
+ LOG_BAD_TU(TU);
return;
+ }
ASTUnit *CXXUnit = cxtu::getASTUnit(TU);
if (!CXXUnit || !Tokens || !NumTokens)
void clang_annotateTokens(CXTranslationUnit TU,
CXToken *Tokens, unsigned NumTokens,
CXCursor *Cursors) {
- if (!TU || NumTokens == 0 || !Tokens || !Cursors) {
+ if (isNotUseableTU(TU)) {
+ LOG_BAD_TU(TU);
+ return;
+ }
+ if (NumTokens == 0 || !Tokens || !Cursors) {
LOG_FUNC_SECTION { *Log << "<null input>"; }
return;
}
unsigned clang_Module_getNumTopLevelHeaders(CXTranslationUnit TU,
CXModule CXMod) {
- if (!TU || !CXMod)
+ if (isNotUseableTU(TU)) {
+ LOG_BAD_TU(TU);
+ return 0;
+ }
+ if (!CXMod)
return 0;
Module *Mod = static_cast<Module*>(CXMod);
FileManager &FileMgr = cxtu::getASTUnit(TU)->getFileManager();
CXFile clang_Module_getTopLevelHeader(CXTranslationUnit TU,
CXModule CXMod, unsigned Index) {
- if (!TU || !CXMod)
+ if (isNotUseableTU(TU)) {
+ LOG_BAD_TU(TU);
+ return 0;
+ }
+ if (!CXMod)
return 0;
Module *Mod = static_cast<Module*>(CXMod);
FileManager &FileMgr = cxtu::getASTUnit(TU)->getFileManager();
}
CXTUResourceUsage clang_getCXTUResourceUsage(CXTranslationUnit TU) {
- if (!TU) {
+ if (isNotUseableTU(TU)) {
+ LOG_BAD_TU(TU);
CXTUResourceUsage usage = { (void*) 0, 0, 0 };
return usage;
}
skipped->count = 0;
skipped->ranges = 0;
+ if (isNotUseableTU(TU)) {
+ LOG_BAD_TU(TU);
+ return skipped;
+ }
+
if (!file)
return skipped;