summaryrefslogtreecommitdiffstats
path: root/clang/lib/Format/Format.cpp
diff options
context:
space:
mode:
authorManuel Klimek <klimek@google.com>2013-02-20 15:25:48 +0000
committerManuel Klimek <klimek@google.com>2013-02-20 15:25:48 +0000
commit02f640a3ab800df9912269dff25bf186785be1a4 (patch)
tree34183a5921572eb8857de0f6c1d0001470632ab5 /clang/lib/Format/Format.cpp
parent3389c55e10c29dad7c19bbe6241490c443f7174b (diff)
downloadbcm5719-llvm-02f640a3ab800df9912269dff25bf186785be1a4.tar.gz
bcm5719-llvm-02f640a3ab800df9912269dff25bf186785be1a4.zip
Fixes bug in string literal alignment.
We now indent the following correctly: 1. some + "literal" /* comment */ "literal"; 2. breaking string literals after which we have another string literal. llvm-svn: 175628
Diffstat (limited to 'clang/lib/Format/Format.cpp')
-rw-r--r--clang/lib/Format/Format.cpp17
1 files changed, 15 insertions, 2 deletions
diff --git a/clang/lib/Format/Format.cpp b/clang/lib/Format/Format.cpp
index 625f93151ff..aca5d36aefc 100644
--- a/clang/lib/Format/Format.cpp
+++ b/clang/lib/Format/Format.cpp
@@ -284,6 +284,7 @@ public:
State.VariablePos = 0;
State.LineContainsContinuedForLoopSection = false;
State.ParenLevel = 0;
+ State.StartOfStringLiteral = 0;
State.StartOfLineLevel = State.ParenLevel;
DEBUG({
@@ -421,6 +422,10 @@ private:
/// \brief The \c ParenLevel at the start of this line.
unsigned StartOfLineLevel;
+ /// \brief The start column of the string literal, if we're in a string
+ /// literal sequence, 0 otherwise.
+ unsigned StartOfStringLiteral;
+
/// \brief A stack keeping track of properties applying to parenthesis
/// levels.
std::vector<ParenState> Stack;
@@ -440,6 +445,8 @@ private:
return ParenLevel < Other.ParenLevel;
if (StartOfLineLevel != Other.StartOfLineLevel)
return StartOfLineLevel < Other.StartOfLineLevel;
+ if (StartOfStringLiteral != Other.StartOfStringLiteral)
+ return StartOfStringLiteral < Other.StartOfStringLiteral;
return Stack < Other.Stack;
}
};
@@ -472,8 +479,8 @@ private:
if (Current.is(tok::r_brace)) {
State.Column = Line.Level * 2;
} else if (Current.is(tok::string_literal) &&
- Previous.is(tok::string_literal)) {
- State.Column = State.Column - Previous.FormatTok.TokenLength;
+ State.StartOfStringLiteral != 0) {
+ State.Column = State.StartOfStringLiteral;
State.Stack.back().BreakBeforeParameter = true;
} else if (Current.is(tok::lessless) &&
State.Stack.back().FirstLessLess != 0) {
@@ -685,6 +692,12 @@ private:
State.Stack.pop_back();
}
+ if (Current.is(tok::string_literal) && State.StartOfStringLiteral == 0) {
+ State.StartOfStringLiteral = State.Column;
+ } else if (Current.isNot(tok::comment)) {
+ State.StartOfStringLiteral = 0;
+ }
+
State.Column += Current.FormatTok.TokenLength;
if (State.NextToken->Children.empty())
OpenPOWER on IntegriCloud