[PATCH] Clang-format: added -fromline and -toline options to specify ranges in line numbers instead of byte offsets.
Alexander Kornienko
alexfh at google.com
Thu Jul 18 14:40:22 PDT 2013
================
Comment at: tools/clang-format/ClangFormat.cpp:190
@@ +189,3 @@
+ SourceLocation Start = Sources.translateLineCol(ID, FromLine, 1);
+ SourceLocation End = Sources.translateLineCol(ID, ToLine, (unsigned)-1);
+ if (Start.isInvalid() || End.isInvalid())
----------------
Daniel Jasper wrote:
> (unsigned)-1?????
>
> I think just using Sources.translateLineCol(ID, ToLine, 1) should almost always lead to the same result (but I am not 100% sure).
>
> How about:
> Sources.translateLineCol(ID, ToLine + 1, 1).getLocWithOffset(-1)?
I was also not sure about (unsigned)-1, but we should use a large number to ensure the whole line is included in the range to avoid problems when multiple statements are in one line. ToLine + 1 may fail to work for the last line. I've changed this to UINT_MAX for now.
================
Comment at: tools/clang-format/ClangFormat.cpp:175
@@ +174,3 @@
+ if (!Offsets.empty() || !Lengths.empty()) {
+ llvm::errs() << "error: can not use -lines with -offset/-length\n";
+ return true;
----------------
Daniel Jasper wrote:
> nit: cannot
Done.
http://llvm-reviews.chandlerc.com/D1160
BRANCH
svn
ARCANIST PROJECT
clang
More information about the cfe-commits
mailing list