* compatible, thus CINDEX_VERSION_MAJOR is expected to remain stable.
*/
#define CINDEX_VERSION_MAJOR 0
-#define CINDEX_VERSION_MINOR 13
+#define CINDEX_VERSION_MINOR 14
#define CINDEX_VERSION_ENCODE(major, minor) ( \
((major) * 10000) \
* each reference found.
* The CXSourceRange will point inside the file; if the reference is inside
* a macro (and not a macro argument) the CXSourceRange will be invalid.
+ *
+ * \returns
+ * 1 : if a parameter was invalid
+ * -1 : if the callback returned CXVisit_Break,
+ * otherwise returns 0.
*/
-CINDEX_LINKAGE void clang_findReferencesInFile(CXCursor cursor, CXFile file,
- CXCursorAndRangeVisitor visitor);
+CINDEX_LINKAGE int clang_findReferencesInFile(CXCursor cursor, CXFile file,
+ CXCursorAndRangeVisitor visitor);
/**
* \brief Find #import/#include directives in a specific file.
*
* \param visitor callback that will receive pairs of CXCursor/CXSourceRange for
* each directive found.
+ *
+ * \returns
+ * 1 : if a parameter was invalid
+ * -1 : if the callback returned CXVisit_Break,
+ * otherwise returns 0.
*/
-CINDEX_LINKAGE void clang_findIncludesInFile(CXTranslationUnit TU, CXFile file,
- CXCursorAndRangeVisitor visitor);
+CINDEX_LINKAGE int clang_findIncludesInFile(CXTranslationUnit TU, CXFile file,
+ CXCursorAndRangeVisitor visitor);
#ifdef __has_feature
# if __has_feature(blocks)
(^CXCursorAndRangeVisitorBlock)(CXCursor, CXSourceRange);
CINDEX_LINKAGE
-void clang_findReferencesInFileWithBlock(CXCursor, CXFile,
- CXCursorAndRangeVisitorBlock);
+int clang_findReferencesInFileWithBlock(CXCursor, CXFile,
+ CXCursorAndRangeVisitorBlock);
CINDEX_LINKAGE
-void clang_findIncludesInFileWithBlock(CXTranslationUnit, CXFile,
- CXCursorAndRangeVisitorBlock);
+int clang_findIncludesInFileWithBlock(CXTranslationUnit, CXFile,
+ CXCursorAndRangeVisitorBlock);
# endif
#endif
PPRec, FID);
}
-void CursorVisitor::visitFileRegion() {
+bool CursorVisitor::visitFileRegion() {
if (RegionOfInterest.isInvalid())
- return;
+ return false;
ASTUnit *Unit = cxtu::getASTUnit(TU);
SourceManager &SM = Unit->getSourceManager();
assert(Begin.first == End.first);
if (Begin.second > End.second)
- return;
+ return false;
FileID File = Begin.first;
unsigned Offset = Begin.second;
if (!VisitDeclsOnly && !VisitPreprocessorLast)
if (visitPreprocessedEntitiesInRegion())
- return; // visitation break.
+ return true; // visitation break.
- visitDeclsFromFileRegion(File, Offset, Length);
+ if (visitDeclsFromFileRegion(File, Offset, Length))
+ return true; // visitation break.
if (!VisitDeclsOnly && VisitPreprocessorLast)
- visitPreprocessedEntitiesInRegion();
+ return visitPreprocessedEntitiesInRegion();
+
+ return false;
}
static bool isInLexicalContext(Decl *D, DeclContext *DC) {
return false;
}
-void CursorVisitor::visitDeclsFromFileRegion(FileID File,
+bool CursorVisitor::visitDeclsFromFileRegion(FileID File,
unsigned Offset, unsigned Length) {
ASTUnit *Unit = cxtu::getASTUnit(TU);
SourceManager &SM = Unit->getSourceManager();
bool Invalid = false;
const SrcMgr::SLocEntry &SLEntry = SM.getSLocEntry(File, &Invalid);
if (Invalid)
- return;
+ return false;
SourceLocation Outer;
if (SLEntry.isFile())
else
Outer = SLEntry.getExpansion().getExpansionLocStart();
if (Outer.isInvalid())
- return;
+ return false;
llvm::tie(File, Offset) = SM.getDecomposedExpansionLoc(Outer);
Length = 0;
}
if (Visit(MakeCXCursor(D, TU, Range), /*CheckedRegionOfInterest=*/true))
- break;
+ return true; // visitation break.
}
if (VisitedAtLeastOnce)
- return;
+ return false;
// No Decls overlapped with the range. Move up the lexical context until there
// is a context that contains the range or we reach the translation unit
break;
if (RangeCompare(SM, CurDeclRange, Range) == RangeOverlap) {
- Visit(MakeCXCursor(D, TU, Range), /*CheckedRegionOfInterest=*/true);
- break;
+ if (Visit(MakeCXCursor(D, TU, Range), /*CheckedRegionOfInterest=*/true))
+ return true; // visitation break.
}
DC = D->getLexicalDeclContext();
}
+
+ return false;
}
bool CursorVisitor::visitPreprocessedEntitiesInRegion() {
return CXChildVisit_Recurse;
}
-static void findIdRefsInFile(CXTranslationUnit TU, CXCursor declCursor,
- const FileEntry *File,
- CXCursorAndRangeVisitor Visitor) {
+static bool findIdRefsInFile(CXTranslationUnit TU, CXCursor declCursor,
+ const FileEntry *File,
+ CXCursorAndRangeVisitor Visitor) {
assert(clang_isDeclaration(declCursor.kind));
SourceManager &SM = cxtu::getASTUnit(TU)->getSourceManager();
FileID FID = SM.translateFile(File);
const Decl *Dcl = cxcursor::getCursorDecl(declCursor);
if (!Dcl)
- return;
+ return false;
FindFileIdRefVisitData data(TU, FID, Dcl,
cxcursor::getSelectorIdentifierIndex(declCursor),
Visitor);
if (const DeclContext *DC = Dcl->getParentFunctionOrMethod()) {
- clang_visitChildren(cxcursor::MakeCXCursor(cast<Decl>(DC), TU),
- findFileIdRefVisit, &data);
- return;
+ return clang_visitChildren(cxcursor::MakeCXCursor(cast<Decl>(DC), TU),
+ findFileIdRefVisit, &data);
}
SourceRange Range(SM.getLocForStartOfFile(FID), SM.getLocForEndOfFile(FID));
/*VisitIncludedEntities=*/false,
Range,
/*VisitDeclsOnly=*/true);
- FindIdRefsVisitor.visitFileRegion();
+ return FindIdRefsVisitor.visitFileRegion();
}
namespace {
return CXChildVisit_Continue;
}
-static void findMacroRefsInFile(CXTranslationUnit TU, CXCursor Cursor,
+static bool findMacroRefsInFile(CXTranslationUnit TU, CXCursor Cursor,
const FileEntry *File,
CXCursorAndRangeVisitor Visitor) {
if (Cursor.kind != CXCursor_MacroDefinition &&
Cursor.kind != CXCursor_MacroExpansion)
- return;
+ return false;
ASTUnit *Unit = cxtu::getASTUnit(TU);
SourceManager &SM = Unit->getSourceManager();
else
Macro = getCursorMacroExpansion(Cursor).getName();
if (!Macro)
- return;
+ return false;
FindFileMacroRefVisitData data(*Unit, File, Macro, Visitor);
/*VisitPreprocessorLast=*/false,
/*VisitIncludedEntities=*/false,
Range);
- FindMacroRefsVisitor.visitPreprocessedEntitiesInRegion();
+ return FindMacroRefsVisitor.visitPreprocessedEntitiesInRegion();
}
namespace {
} // anonymous namespace
-static void findIncludesInFile(CXTranslationUnit TU, const FileEntry *File,
+static bool findIncludesInFile(CXTranslationUnit TU, const FileEntry *File,
CXCursorAndRangeVisitor Visitor) {
assert(TU && File && Visitor.visit);
/*VisitPreprocessorLast=*/false,
/*VisitIncludedEntities=*/false,
Range);
- InclusionCursorsVisitor.visitPreprocessedEntitiesInRegion();
+ return InclusionCursorsVisitor.visitPreprocessedEntitiesInRegion();
}
extern "C" {
-void clang_findReferencesInFile(CXCursor cursor, CXFile file,
- CXCursorAndRangeVisitor visitor) {
+int clang_findReferencesInFile(CXCursor cursor, CXFile file,
+ CXCursorAndRangeVisitor visitor) {
LogRef Log = Logger::make(LLVM_FUNCTION_NAME);
if (clang_Cursor_isNull(cursor)) {
if (Log)
*Log << "Null cursor";
- return;
+ return 1;
}
if (cursor.kind == CXCursor_NoDeclFound) {
if (Log)
*Log << "Got CXCursor_NoDeclFound";
- return;
+ return 1;
}
if (!file) {
if (Log)
*Log << "Null file";
- return;
+ return 1;
}
if (!visitor.visit) {
if (Log)
*Log << "Null visitor";
- return;
+ return 1;
}
if (Log)
ASTUnit *CXXUnit = cxcursor::getCursorASTUnit(cursor);
if (!CXXUnit)
- return;
+ return 1;
ASTUnit::ConcurrencyCheck Check(*CXXUnit);
if (cursor.kind == CXCursor_MacroDefinition ||
cursor.kind == CXCursor_MacroExpansion) {
- findMacroRefsInFile(cxcursor::getCursorTU(cursor),
- cursor,
- static_cast<const FileEntry *>(file),
- visitor);
- return;
+ if (findMacroRefsInFile(cxcursor::getCursorTU(cursor),
+ cursor,
+ static_cast<const FileEntry *>(file),
+ visitor))
+ return -1; // visitation break;
+ return 0;
}
// We are interested in semantics of identifiers so for C++ constructor exprs
if (!clang_isDeclaration(refCursor.kind)) {
if (Log)
*Log << "cursor is not referencing a declaration";
- return;
+ return 1;
}
- findIdRefsInFile(cxcursor::getCursorTU(cursor),
- refCursor,
- static_cast<const FileEntry *>(file),
- visitor);
+ if (findIdRefsInFile(cxcursor::getCursorTU(cursor),
+ refCursor,
+ static_cast<const FileEntry *>(file),
+ visitor))
+ return -1; //visitation break;
+ return 0;
}
-void clang_findIncludesInFile(CXTranslationUnit TU, CXFile file,
- CXCursorAndRangeVisitor visitor) {
+int clang_findIncludesInFile(CXTranslationUnit TU, CXFile file,
+ CXCursorAndRangeVisitor visitor) {
LogRef Log = Logger::make(LLVM_FUNCTION_NAME);
if (!TU) {
if (Log)
*Log << "Null CXTranslationUnit";
- return;
+ return 1;
}
if (!file) {
if (Log)
*Log << "Null file";
- return;
+ return 1;
}
if (!visitor.visit) {
if (Log)
*Log << "Null visitor";
- return;
+ return 1;
}
if (Log)
ASTUnit *CXXUnit = cxtu::getASTUnit(TU);
if (!CXXUnit)
- return;
+ return 1;
ASTUnit::ConcurrencyCheck Check(*CXXUnit);
- findIncludesInFile(TU, static_cast<const FileEntry *>(file), visitor);
+ if (findIncludesInFile(TU, static_cast<const FileEntry *>(file), visitor))
+ return -1; //visitation break;
+ return 0;
}
static enum CXVisitorResult _visitCursorAndRange(void *context,
return INVOKE_BLOCK2(block, cursor, range);
}
-void clang_findReferencesInFileWithBlock(CXCursor cursor,
- CXFile file,
- CXCursorAndRangeVisitorBlock block) {
+int clang_findReferencesInFileWithBlock(CXCursor cursor,
+ CXFile file,
+ CXCursorAndRangeVisitorBlock block) {
CXCursorAndRangeVisitor visitor = { block,
block ? _visitCursorAndRange : 0 };
return clang_findReferencesInFile(cursor, file, visitor);
}
-void clang_findIncludesInFileWithBlock(CXTranslationUnit TU,
- CXFile file,
- CXCursorAndRangeVisitorBlock block) {
+int clang_findIncludesInFileWithBlock(CXTranslationUnit TU,
+ CXFile file,
+ CXCursorAndRangeVisitorBlock block) {
CXCursorAndRangeVisitor visitor = { block,
block ? _visitCursorAndRange : 0 };
return clang_findIncludesInFile(TU, file, visitor);