summaryrefslogtreecommitdiffstats
path: root/clang/lib/Format/Format.cpp
diff options
context:
space:
mode:
authorDaniel Jasper <djasper@google.com>2013-02-18 13:08:03 +0000
committerDaniel Jasper <djasper@google.com>2013-02-18 13:08:03 +0000
commit55d7ba6b661974ae69b8a3012e5bb02d03b6735c (patch)
tree4aa26053cde2289ce3a3dea18e0db694d876ff95 /clang/lib/Format/Format.cpp
parent5065bc4b2c3e13be9b1186dcdde7471ffb9e326f (diff)
downloadbcm5719-llvm-55d7ba6b661974ae69b8a3012e5bb02d03b6735c.tar.gz
bcm5719-llvm-55d7ba6b661974ae69b8a3012e5bb02d03b6735c.zip
Reformat lines if they were "moved around".
An unwrapped line can get moved around if there is no newline before it and the previous line was formatted. Example: template<typename T> // Cursor is on this line when hitting "format" T *getFETokenInfo() const { return static_cast<T*>(FETokenInfo); } "return .." is the second unwrapped line in this scenario. I does not touch any reformatted region. Thus, the result of formatting is: template <typename T> T *getFETokenInfo() const { return static_cast<T *>(FETokenInfo); } After second format (and arguably desired end-result): template <typename T> T *getFETokenInfo() const { return static_cast<T *>(FETokenInfo); } This fixes: llvm.org/PR15060. llvm-svn: 175440
Diffstat (limited to 'clang/lib/Format/Format.cpp')
-rw-r--r--clang/lib/Format/Format.cpp4
1 files changed, 3 insertions, 1 deletions
diff --git a/clang/lib/Format/Format.cpp b/clang/lib/Format/Format.cpp
index fa62752fe63..e950fe60302 100644
--- a/clang/lib/Format/Format.cpp
+++ b/clang/lib/Format/Format.cpp
@@ -999,7 +999,9 @@ public:
while (IndentForLevel.size() <= TheLine.Level)
IndentForLevel.push_back(-1);
IndentForLevel.resize(TheLine.Level + 1);
- if (touchesRanges(TheLine) && TheLine.Type != LT_Invalid) {
+ bool WasMoved =
+ PreviousLineWasTouched && TheLine.First.FormatTok.NewlinesBefore == 0;
+ if (TheLine.Type != LT_Invalid && (WasMoved || touchesRanges(TheLine))) {
unsigned LevelIndent = getIndent(IndentForLevel, TheLine.Level);
unsigned Indent = LevelIndent;
if (static_cast<int>(Indent) + Offset >= 0)
OpenPOWER on IntegriCloud