[cfe-commits] r96162 - in /cfe/trunk: bindings/python/tests/cindex/test_diagnostics.py include/clang-c/Index.h tools/CIndex/CIndex.cpp tools/c-index-test/c-index-test.c
Douglas Gregor
dgregor at apple.com
Mon Feb 15 08:50:24 PST 2010
On Feb 14, 2010, at 2:02 AM, Daniel Dunbar wrote:
> Author: ddunbar
> Date: Sun Feb 14 04:02:57 2010
> New Revision: 96162
>
> URL: http://llvm.org/viewvc/llvm-project?rev=96162&view=rev
> Log:
> CIndex: Switch CXSourceRange to proper half-open intervals.
> - Doug, please review.
Looks great, thanks!
- Doug
> Modified:
> cfe/trunk/bindings/python/tests/cindex/test_diagnostics.py
> cfe/trunk/include/clang-c/Index.h
> cfe/trunk/tools/CIndex/CIndex.cpp
> cfe/trunk/tools/c-index-test/c-index-test.c
>
> Modified: cfe/trunk/bindings/python/tests/cindex/test_diagnostics.py
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/bindings/python/tests/cindex/test_diagnostics.py?rev=96162&r1=96161&r2=96162&view=diff
>
> ==============================================================================
> --- cfe/trunk/bindings/python/tests/cindex/test_diagnostics.py (original)
> +++ cfe/trunk/bindings/python/tests/cindex/test_diagnostics.py Sun Feb 14 04:02:57 2010
> @@ -44,5 +44,5 @@
> assert tu.diagnostics[0].fixits[0].range.start.line == 1
> assert tu.diagnostics[0].fixits[0].range.start.column == 26
> assert tu.diagnostics[0].fixits[0].range.end.line == 1
> - assert tu.diagnostics[0].fixits[0].range.end.column == 29
> + assert tu.diagnostics[0].fixits[0].range.end.column == 30
> assert tu.diagnostics[0].fixits[0].value == '.f0 = '
>
> Modified: cfe/trunk/include/clang-c/Index.h
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang-c/Index.h?rev=96162&r1=96161&r2=96162&view=diff
>
> ==============================================================================
> --- cfe/trunk/include/clang-c/Index.h (original)
> +++ cfe/trunk/include/clang-c/Index.h Sun Feb 14 04:02:57 2010
> @@ -257,7 +257,7 @@
> } CXSourceLocation;
>
> /**
> - * \brief Identifies a range of source locations in the source code.
> + * \brief Identifies a half-open character range in the source code.
> *
> * Use clang_getRangeStart() and clang_getRangeEnd() to retrieve the
> * starting and end locations from a source range, respectively.
>
> Modified: cfe/trunk/tools/CIndex/CIndex.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/CIndex/CIndex.cpp?rev=96162&r1=96161&r2=96162&view=diff
>
> ==============================================================================
> --- cfe/trunk/tools/CIndex/CIndex.cpp (original)
> +++ cfe/trunk/tools/CIndex/CIndex.cpp Sun Feb 14 04:02:57 2010
> @@ -139,9 +139,11 @@
> SourceRange R2) {
> assert(R1.isValid() && "First range is invalid?");
> assert(R2.isValid() && "Second range is invalid?");
> - if (SM.isBeforeInTranslationUnit(R1.getEnd(), R2.getBegin()))
> + if (R1.getEnd() == R2.getBegin() ||
> + SM.isBeforeInTranslationUnit(R1.getEnd(), R2.getBegin()))
> return RangeBefore;
> - if (SM.isBeforeInTranslationUnit(R2.getEnd(), R1.getBegin()))
> + if (R2.getEnd() == R1.getBegin() ||
> + SM.isBeforeInTranslationUnit(R2.getEnd(), R1.getBegin()))
> return RangeAfter;
> return RangeOverlap;
> }
> @@ -180,9 +182,6 @@
> // Preprocessor::getLocForEndOfToken().
> if (InstLoc.isValid()) {
> unsigned Length = Lexer::MeasureTokenLength(InstLoc, SM, LangOpts);
> - // FIXME: Temporarily represent as closed range to preserve API
> - // compatibility.
> - if (Length) --Length;
> EndLoc = EndLoc.getFileLocWithOffset(Length);
> }
>
> @@ -235,7 +234,7 @@
> /// \brief Determine whether this particular source range comes before, comes
> /// after, or overlaps the region of interest.
> ///
> - /// \param R a source range retrieved from the abstract syntax tree.
> + /// \param R a half-open source range retrieved from the abstract syntax tree.
> RangeComparisonResult CompareRegionOfInterest(SourceRange R);
>
> public:
> @@ -319,12 +318,6 @@
> } // end anonymous namespace
>
> RangeComparisonResult CursorVisitor::CompareRegionOfInterest(SourceRange R) {
> - // Move the end of the input range to the end of the last token in that
> - // range.
> - SourceLocation NewEnd
> - = TU->getPreprocessor().getLocForEndOfToken(R.getEnd(), 1);
> - if (NewEnd.isValid())
> - R.setEnd(NewEnd);
> return RangeCompare(TU->getSourceManager(), R, RegionOfInterest);
> }
>
> @@ -444,12 +437,15 @@
> bool CursorVisitor::VisitDeclContext(DeclContext *DC) {
> for (DeclContext::decl_iterator
> I = DC->decls_begin(), E = DC->decls_end(); I != E; ++I) {
> + CXCursor Cursor = MakeCXCursor(*I, TU);
> +
> if (RegionOfInterest.isValid()) {
> - SourceRange R = (*I)->getSourceRange();
> - if (R.isInvalid())
> + SourceRange Range =
> + cxloc::translateCXSourceRange(clang_getCursorExtent(Cursor));
> + if (Range.isInvalid())
> continue;
> -
> - switch (CompareRegionOfInterest(R)) {
> +
> + switch (CompareRegionOfInterest(Range)) {
> case RangeBefore:
> // This declaration comes before the region of interest; skip it.
> continue;
> @@ -464,7 +460,7 @@
> }
> }
>
> - if (Visit(MakeCXCursor(*I, TU), true))
> + if (Visit(Cursor, true))
> return true;
> }
>
> @@ -1194,7 +1190,7 @@
> CXSourceRange Result = { { 0, 0 }, 0, 0 };
> return Result;
> }
> -
> +
> CXSourceRange clang_getRange(CXSourceLocation begin, CXSourceLocation end) {
> if (begin.ptr_data[0] != end.ptr_data[0] ||
> begin.ptr_data[1] != end.ptr_data[1])
> @@ -1468,7 +1464,7 @@
> SourceLocation SLoc = cxloc::translateSourceLocation(Loc);
> CXCursor Result = MakeCXCursorInvalid(CXCursor_NoDeclFound);
> if (SLoc.isValid()) {
> - SourceRange RegionOfInterest(SLoc, SLoc);
> + SourceRange RegionOfInterest(SLoc, SLoc.getFileLocWithOffset(1));
>
> // FIXME: Would be great to have a "hint" cursor, then walk from that
> // hint cursor upward until we find a cursor whose source range encloses
> @@ -2118,8 +2114,7 @@
> SourceLocation End
> = cxloc::translateSourceLocation(clang_getTokenLocation(TU,
> Tokens[NumTokens - 1]));
> - RegionOfInterest.setEnd(CXXUnit->getPreprocessor().getLocForEndOfToken(End,
> - 1));
> + RegionOfInterest.setEnd(CXXUnit->getPreprocessor().getLocForEndOfToken(End));
> // FIXME: Would be great to have a "hint" cursor, then walk from that
> // hint cursor upward until we find a cursor whose source range encloses
> // the region of interest, rather than starting from the translation unit.
>
> Modified: cfe/trunk/tools/c-index-test/c-index-test.c
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/c-index-test/c-index-test.c?rev=96162&r1=96161&r2=96162&view=diff
>
> ==============================================================================
> --- cfe/trunk/tools/c-index-test/c-index-test.c (original)
> +++ cfe/trunk/tools/c-index-test/c-index-test.c Sun Feb 14 04:02:57 2010
> @@ -34,9 +34,8 @@
>
> static void PrintExtent(FILE *out, unsigned begin_line, unsigned begin_column,
> unsigned end_line, unsigned end_column) {
> - /* FIXME: Remove this + 1. */
> fprintf(out, "[%d:%d - %d:%d]", begin_line, begin_column,
> - end_line, end_column + 1);
> + end_line, end_column);
> }
>
> static unsigned CreateTranslationUnit(CXIndex Idx, const char *file,
> @@ -616,7 +615,7 @@
> if ((c == EOF || !clang_equalCursors(cursor, prevCursor)) &&
> prevCursor.kind != CXCursor_InvalidFile) {
> print_cursor_file_scan(prevCursor, start_line, start_col,
> - line, col - 1, prefix);
> + line, col, prefix);
> start_line = line;
> start_col = col;
> }
>
>
> _______________________________________________
> cfe-commits mailing list
> cfe-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
More information about the cfe-commits
mailing list