<html><head><meta http-equiv="Content-Type" content="text/html charset=us-ascii"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;">On Mar 8, 2013, at 1:44 PM, Jordan Rose <<a href="mailto:jordan_rose@apple.com">jordan_rose@apple.com</a>> wrote:<br><div><br class="Apple-interchange-newline"><blockquote type="cite"><div style="letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px;">Why is this not returning an enum?<br></div></blockquote><div><br></div><div>Why indeed; changed it in r176732, thanks for reviewing!</div><br><blockquote type="cite"><div style="letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px;"><br><br>On Mar 8, 2013, at 12:42 , Argyrios Kyrtzidis <<a href="mailto:akyrtzi@gmail.com">akyrtzi@gmail.com</a>> wrote:<br><br><blockquote type="cite">Author: akirtzidis<br>Date: Fri Mar 8 14:42:33 2013<br>New Revision: 176716<br><br>URL: <a href="http://llvm.org/viewvc/llvm-project?rev=176716&view=rev">http://llvm.org/viewvc/llvm-project?rev=176716&view=rev</a><br>Log:<br>[libclang] Modify clang_findReferencesInFile and clang_findIncludesInFile to return a value.<br><br>Possible values are:<br>1 : if a parameter was invalid<br>-1 : if the callback returned CXVisit_Break,<br>otherwise returns 0.<br><br>Modified:<br> cfe/trunk/include/clang-c/Index.h<br> cfe/trunk/tools/libclang/CIndex.cpp<br> cfe/trunk/tools/libclang/CIndexHigh.cpp<br> cfe/trunk/tools/libclang/CursorVisitor.h<br><br>Modified: cfe/trunk/include/clang-c/Index.h<br>URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang-c/Index.h?rev=176716&r1=176715&r2=176716&view=diff">http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang-c/Index.h?rev=176716&r1=176715&r2=176716&view=diff</a><br>==============================================================================<br>--- cfe/trunk/include/clang-c/Index.h (original)<br>+++ cfe/trunk/include/clang-c/Index.h Fri Mar 8 14:42:33 2013<br>@@ -32,7 +32,7 @@<br>* compatible, thus CINDEX_VERSION_MAJOR is expected to remain stable.<br>*/<br>#define CINDEX_VERSION_MAJOR 0<br>-#define CINDEX_VERSION_MINOR 13<br>+#define CINDEX_VERSION_MINOR 14<br><br>#define CINDEX_VERSION_ENCODE(major, minor) ( \<br> ((major) * 10000) \<br>@@ -5017,9 +5017,14 @@ typedef struct {<br>* each reference found.<br>* The CXSourceRange will point inside the file; if the reference is inside<br>* a macro (and not a macro argument) the CXSourceRange will be invalid.<br>+ *<br>+ * \returns<br>+ * 1 : if a parameter was invalid<br>+ * -1 : if the callback returned CXVisit_Break,<br>+ * otherwise returns 0.<br>*/<br>-CINDEX_LINKAGE void clang_findReferencesInFile(CXCursor cursor, CXFile file,<br>- CXCursorAndRangeVisitor visitor);<br>+CINDEX_LINKAGE int clang_findReferencesInFile(CXCursor cursor, CXFile file,<br>+ CXCursorAndRangeVisitor visitor);<br><br>/**<br>* \brief Find #import/#include directives in a specific file.<br>@@ -5030,9 +5035,14 @@ CINDEX_LINKAGE void clang_findReferences<br>*<br>* \param visitor callback that will receive pairs of CXCursor/CXSourceRange for<br>* each directive found.<br>+ *<br>+ * \returns<br>+ * 1 : if a parameter was invalid<br>+ * -1 : if the callback returned CXVisit_Break,<br>+ * otherwise returns 0.<br>*/<br>-CINDEX_LINKAGE void clang_findIncludesInFile(CXTranslationUnit TU, CXFile file,<br>- CXCursorAndRangeVisitor visitor);<br>+CINDEX_LINKAGE int clang_findIncludesInFile(CXTranslationUnit TU, CXFile file,<br>+ CXCursorAndRangeVisitor visitor);<br><br>#ifdef __has_feature<br># if __has_feature(blocks)<br>@@ -5041,12 +5051,12 @@ typedef enum CXVisitorResult<br> (^CXCursorAndRangeVisitorBlock)(CXCursor, CXSourceRange);<br><br>CINDEX_LINKAGE<br>-void clang_findReferencesInFileWithBlock(CXCursor, CXFile,<br>- CXCursorAndRangeVisitorBlock);<br>+int clang_findReferencesInFileWithBlock(CXCursor, CXFile,<br>+ CXCursorAndRangeVisitorBlock);<br><br>CINDEX_LINKAGE<br>-void clang_findIncludesInFileWithBlock(CXTranslationUnit, CXFile,<br>- CXCursorAndRangeVisitorBlock);<br>+int clang_findIncludesInFileWithBlock(CXTranslationUnit, CXFile,<br>+ CXCursorAndRangeVisitorBlock);<br><br># endif<br>#endif<br><br>Modified: cfe/trunk/tools/libclang/CIndex.cpp<br>URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/libclang/CIndex.cpp?rev=176716&r1=176715&r2=176716&view=diff">http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/libclang/CIndex.cpp?rev=176716&r1=176715&r2=176716&view=diff</a><br>==============================================================================<br>--- cfe/trunk/tools/libclang/CIndex.cpp (original)<br>+++ cfe/trunk/tools/libclang/CIndex.cpp Fri Mar 8 14:42:33 2013<br>@@ -223,9 +223,9 @@ static bool visitPreprocessedEntitiesInR<br> PPRec, FID);<br>}<br><br>-void CursorVisitor::visitFileRegion() {<br>+bool CursorVisitor::visitFileRegion() {<br> if (RegionOfInterest.isInvalid())<br>- return;<br>+ return false;<br><br> ASTUnit *Unit = cxtu::getASTUnit(TU);<br> SourceManager &SM = Unit->getSourceManager();<br>@@ -243,7 +243,7 @@ void CursorVisitor::visitFileRegion() {<br><br> assert(Begin.first == End.first);<br> if (Begin.second > End.second)<br>- return;<br>+ return false;<br><br> FileID File = Begin.first;<br> unsigned Offset = Begin.second;<br>@@ -251,12 +251,15 @@ void CursorVisitor::visitFileRegion() {<br><br> if (!VisitDeclsOnly && !VisitPreprocessorLast)<br> if (visitPreprocessedEntitiesInRegion())<br>- return; // visitation break.<br>+ return true; // visitation break.<br><br>- visitDeclsFromFileRegion(File, Offset, Length);<br>+ if (visitDeclsFromFileRegion(File, Offset, Length))<br>+ return true; // visitation break.<br><br> if (!VisitDeclsOnly && VisitPreprocessorLast)<br>- visitPreprocessedEntitiesInRegion();<br>+ return visitPreprocessedEntitiesInRegion();<br>+<br>+ return false;<br>}<br><br>static bool isInLexicalContext(Decl *D, DeclContext *DC) {<br>@@ -271,7 +274,7 @@ static bool isInLexicalContext(Decl *D,<br> return false;<br>}<br><br>-void CursorVisitor::visitDeclsFromFileRegion(FileID File,<br>+bool CursorVisitor::visitDeclsFromFileRegion(FileID File,<br> unsigned Offset, unsigned Length) {<br> ASTUnit *Unit = cxtu::getASTUnit(TU);<br> SourceManager &SM = Unit->getSourceManager();<br>@@ -286,7 +289,7 @@ void CursorVisitor::visitDeclsFromFileRe<br> bool Invalid = false;<br> const SrcMgr::SLocEntry &SLEntry = SM.getSLocEntry(File, &Invalid);<br> if (Invalid)<br>- return;<br>+ return false;<br><br> SourceLocation Outer;<br> if (SLEntry.isFile())<br>@@ -294,7 +297,7 @@ void CursorVisitor::visitDeclsFromFileRe<br> else<br> Outer = SLEntry.getExpansion().getExpansionLocStart();<br> if (Outer.isInvalid())<br>- return;<br>+ return false;<br><br> llvm::tie(File, Offset) = SM.getDecomposedExpansionLoc(Outer);<br> Length = 0;<br>@@ -337,11 +340,11 @@ void CursorVisitor::visitDeclsFromFileRe<br> }<br><br> if (Visit(MakeCXCursor(D, TU, Range), /*CheckedRegionOfInterest=*/true))<br>- break;<br>+ return true; // visitation break.<br> }<br><br> if (VisitedAtLeastOnce)<br>- return;<br>+ return false;<br><br> // No Decls overlapped with the range. Move up the lexical context until there<br> // is a context that contains the range or we reach the translation unit<br>@@ -356,12 +359,14 @@ void CursorVisitor::visitDeclsFromFileRe<br> break;<br><br> if (RangeCompare(SM, CurDeclRange, Range) == RangeOverlap) {<br>- Visit(MakeCXCursor(D, TU, Range), /*CheckedRegionOfInterest=*/true);<br>- break;<br>+ if (Visit(MakeCXCursor(D, TU, Range), /*CheckedRegionOfInterest=*/true))<br>+ return true; // visitation break.<br> }<br><br> DC = D->getLexicalDeclContext();<br> }<br>+<br>+ return false;<br>}<br><br>bool CursorVisitor::visitPreprocessedEntitiesInRegion() {<br><br>Modified: cfe/trunk/tools/libclang/CIndexHigh.cpp<br>URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/libclang/CIndexHigh.cpp?rev=176716&r1=176715&r2=176716&view=diff">http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/libclang/CIndexHigh.cpp?rev=176716&r1=176715&r2=176716&view=diff</a><br>==============================================================================<br>--- cfe/trunk/tools/libclang/CIndexHigh.cpp (original)<br>+++ cfe/trunk/tools/libclang/CIndexHigh.cpp Fri Mar 8 14:42:33 2013<br>@@ -212,25 +212,24 @@ static enum CXChildVisitResult findFileI<br> return CXChildVisit_Recurse;<br>}<br><br>-static void findIdRefsInFile(CXTranslationUnit TU, CXCursor declCursor,<br>- const FileEntry *File,<br>- CXCursorAndRangeVisitor Visitor) {<br>+static bool findIdRefsInFile(CXTranslationUnit TU, CXCursor declCursor,<br>+ const FileEntry *File,<br>+ CXCursorAndRangeVisitor Visitor) {<br> assert(clang_isDeclaration(declCursor.kind));<br> SourceManager &SM = cxtu::getASTUnit(TU)->getSourceManager();<br><br> FileID FID = SM.translateFile(File);<br> const Decl *Dcl = cxcursor::getCursorDecl(declCursor);<br> if (!Dcl)<br>- return;<br>+ return false;<br><br> FindFileIdRefVisitData data(TU, FID, Dcl,<br> cxcursor::getSelectorIdentifierIndex(declCursor),<br> Visitor);<br><br> if (const DeclContext *DC = Dcl->getParentFunctionOrMethod()) {<br>- clang_visitChildren(cxcursor::MakeCXCursor(cast<Decl>(DC), TU),<br>- findFileIdRefVisit, &data);<br>- return;<br>+ return clang_visitChildren(cxcursor::MakeCXCursor(cast<Decl>(DC), TU),<br>+ findFileIdRefVisit, &data);<br> }<br><br> SourceRange Range(SM.getLocForStartOfFile(FID), SM.getLocForEndOfFile(FID));<br>@@ -240,7 +239,7 @@ static void findIdRefsInFile(CXTranslati<br> /*VisitIncludedEntities=*/false,<br> Range,<br> /*VisitDeclsOnly=*/true);<br>- FindIdRefsVisitor.visitFileRegion();<br>+ return FindIdRefsVisitor.visitFileRegion();<br>}<br><br>namespace {<br>@@ -307,12 +306,12 @@ static enum CXChildVisitResult findFileM<br> return CXChildVisit_Continue;<br>}<br><br>-static void findMacroRefsInFile(CXTranslationUnit TU, CXCursor Cursor,<br>+static bool findMacroRefsInFile(CXTranslationUnit TU, CXCursor Cursor,<br> const FileEntry *File,<br> CXCursorAndRangeVisitor Visitor) {<br> if (Cursor.kind != CXCursor_MacroDefinition &&<br> Cursor.kind != CXCursor_MacroExpansion)<br>- return;<br>+ return false;<br><br> ASTUnit *Unit = cxtu::getASTUnit(TU);<br> SourceManager &SM = Unit->getSourceManager();<br>@@ -324,7 +323,7 @@ static void findMacroRefsInFile(CXTransl<br> else<br> Macro = getCursorMacroExpansion(Cursor).getName();<br> if (!Macro)<br>- return;<br>+ return false;<br><br> FindFileMacroRefVisitData data(*Unit, File, Macro, Visitor);<br><br>@@ -334,7 +333,7 @@ static void findMacroRefsInFile(CXTransl<br> /*VisitPreprocessorLast=*/false,<br> /*VisitIncludedEntities=*/false,<br> Range);<br>- FindMacroRefsVisitor.visitPreprocessedEntitiesInRegion();<br>+ return FindMacroRefsVisitor.visitPreprocessedEntitiesInRegion();<br>}<br><br>namespace {<br>@@ -382,7 +381,7 @@ struct FindFileIncludesVisitor {<br><br>} // anonymous namespace<br><br>-static void findIncludesInFile(CXTranslationUnit TU, const FileEntry *File,<br>+static bool findIncludesInFile(CXTranslationUnit TU, const FileEntry *File,<br> CXCursorAndRangeVisitor Visitor) {<br> assert(TU && File && Visitor.visit);<br><br>@@ -400,7 +399,7 @@ static void findIncludesInFile(CXTransla<br> /*VisitPreprocessorLast=*/false,<br> /*VisitIncludedEntities=*/false,<br> Range);<br>- InclusionCursorsVisitor.visitPreprocessedEntitiesInRegion();<br>+ return InclusionCursorsVisitor.visitPreprocessedEntitiesInRegion();<br>}<br><br><br>@@ -410,29 +409,29 @@ static void findIncludesInFile(CXTransla<br><br>extern "C" {<br><br>-void clang_findReferencesInFile(CXCursor cursor, CXFile file,<br>- CXCursorAndRangeVisitor visitor) {<br>+int clang_findReferencesInFile(CXCursor cursor, CXFile file,<br>+ CXCursorAndRangeVisitor visitor) {<br> LogRef Log = Logger::make(LLVM_FUNCTION_NAME);<br><br> if (clang_Cursor_isNull(cursor)) {<br> if (Log)<br> *Log << "Null cursor";<br>- return;<br>+ return 1;<br> }<br> if (cursor.kind == CXCursor_NoDeclFound) {<br> if (Log)<br> *Log << "Got CXCursor_NoDeclFound";<br>- return;<br>+ return 1;<br> }<br> if (!file) {<br> if (Log)<br> *Log << "Null file";<br>- return;<br>+ return 1;<br> }<br> if (!visitor.visit) {<br> if (Log)<br> *Log << "Null visitor";<br>- return;<br>+ return 1;<br> }<br><br> if (Log)<br>@@ -440,17 +439,18 @@ void clang_findReferencesInFile(CXCursor<br><br> ASTUnit *CXXUnit = cxcursor::getCursorASTUnit(cursor);<br> if (!CXXUnit)<br>- return;<br>+ return 1;<br><br> ASTUnit::ConcurrencyCheck Check(*CXXUnit);<br><br> if (cursor.kind == CXCursor_MacroDefinition ||<br> cursor.kind == CXCursor_MacroExpansion) {<br>- findMacroRefsInFile(cxcursor::getCursorTU(cursor),<br>- cursor,<br>- static_cast<const FileEntry *>(file),<br>- visitor);<br>- return;<br>+ if (findMacroRefsInFile(cxcursor::getCursorTU(cursor),<br>+ cursor,<br>+ static_cast<const FileEntry *>(file),<br>+ visitor))<br>+ return -1; // visitation break;<br>+ return 0;<br> }<br><br> // We are interested in semantics of identifiers so for C++ constructor exprs<br>@@ -467,33 +467,35 @@ void clang_findReferencesInFile(CXCursor<br> if (!clang_isDeclaration(refCursor.kind)) {<br> if (Log)<br> *Log << "cursor is not referencing a declaration";<br>- return;<br>+ return 1;<br> }<br><br>- findIdRefsInFile(cxcursor::getCursorTU(cursor),<br>- refCursor,<br>- static_cast<const FileEntry *>(file),<br>- visitor);<br>+ if (findIdRefsInFile(cxcursor::getCursorTU(cursor),<br>+ refCursor,<br>+ static_cast<const FileEntry *>(file),<br>+ visitor))<br>+ return -1; //visitation break;<br>+ return 0;<br>}<br><br>-void clang_findIncludesInFile(CXTranslationUnit TU, CXFile file,<br>- CXCursorAndRangeVisitor visitor) {<br>+int clang_findIncludesInFile(CXTranslationUnit TU, CXFile file,<br>+ CXCursorAndRangeVisitor visitor) {<br> LogRef Log = Logger::make(LLVM_FUNCTION_NAME);<br><br> if (!TU) {<br> if (Log)<br> *Log << "Null CXTranslationUnit";<br>- return;<br>+ return 1;<br> }<br> if (!file) {<br> if (Log)<br> *Log << "Null file";<br>- return;<br>+ return 1;<br> }<br> if (!visitor.visit) {<br> if (Log)<br> *Log << "Null visitor";<br>- return;<br>+ return 1;<br> }<br><br> if (Log)<br>@@ -501,11 +503,13 @@ void clang_findIncludesInFile(CXTranslat<br><br> ASTUnit *CXXUnit = cxtu::getASTUnit(TU);<br> if (!CXXUnit)<br>- return;<br>+ return 1;<br><br> ASTUnit::ConcurrencyCheck Check(*CXXUnit);<br><br>- findIncludesInFile(TU, static_cast<const FileEntry *>(file), visitor);<br>+ if (findIncludesInFile(TU, static_cast<const FileEntry *>(file), visitor))<br>+ return -1; //visitation break;<br>+ return 0;<br>}<br><br>static enum CXVisitorResult _visitCursorAndRange(void *context,<br>@@ -515,17 +519,17 @@ static enum CXVisitorResult _visitCursor<br> return INVOKE_BLOCK2(block, cursor, range);<br>}<br><br>-void clang_findReferencesInFileWithBlock(CXCursor cursor,<br>- CXFile file,<br>- CXCursorAndRangeVisitorBlock block) {<br>+int clang_findReferencesInFileWithBlock(CXCursor cursor,<br>+ CXFile file,<br>+ CXCursorAndRangeVisitorBlock block) {<br> CXCursorAndRangeVisitor visitor = { block,<br> block ? _visitCursorAndRange : 0 };<br> return clang_findReferencesInFile(cursor, file, visitor);<br>}<br><br>-void clang_findIncludesInFileWithBlock(CXTranslationUnit TU,<br>- CXFile file,<br>- CXCursorAndRangeVisitorBlock block) {<br>+int clang_findIncludesInFileWithBlock(CXTranslationUnit TU,<br>+ CXFile file,<br>+ CXCursorAndRangeVisitorBlock block) {<br> CXCursorAndRangeVisitor visitor = { block,<br> block ? _visitCursorAndRange : 0 };<br> return clang_findIncludesInFile(TU, file, visitor);<br><br>Modified: cfe/trunk/tools/libclang/CursorVisitor.h<br>URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/libclang/CursorVisitor.h?rev=176716&r1=176715&r2=176716&view=diff">http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/libclang/CursorVisitor.h?rev=176716&r1=176715&r2=176716&view=diff</a><br>==============================================================================<br>--- cfe/trunk/tools/libclang/CursorVisitor.h (original)<br>+++ cfe/trunk/tools/libclang/CursorVisitor.h Fri Mar 8 14:42:33 2013<br>@@ -116,7 +116,7 @@ private:<br> /// \param R a half-open source range retrieved from the abstract syntax tree.<br> RangeComparisonResult CompareRegionOfInterest(SourceRange R);<br><br>- void visitDeclsFromFileRegion(FileID File, unsigned Offset, unsigned Length);<br>+ bool visitDeclsFromFileRegion(FileID File, unsigned Offset, unsigned Length);<br><br> class SetParentRAII {<br> CXCursor &Parent;<br>@@ -179,7 +179,7 @@ public:<br><br> /// \brief Visit declarations and preprocessed entities for the file region<br> /// designated by \see RegionOfInterest.<br>- void visitFileRegion();<br>+ bool visitFileRegion();<br><br> bool visitPreprocessedEntitiesInRegion();<br><br><br><br>_______________________________________________<br>cfe-commits mailing list<br><a href="mailto:cfe-commits@cs.uiuc.edu">cfe-commits@cs.uiuc.edu</a><br>http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits</blockquote></div></blockquote></div><br></body></html>