summaryrefslogtreecommitdiffstats
path: root/clang/lib
diff options
context:
space:
mode:
authorDaniel Jasper <djasper@google.com>2013-02-28 11:05:57 +0000
committerDaniel Jasper <djasper@google.com>2013-02-28 11:05:57 +0000
commitc22f5b4abb1f1100dd8083d04d4ab2c79080104f (patch)
treecfd7ff3a6961778154bd30083fe926c1dc545826 /clang/lib
parent57d4a5821d7099ab85475b535d80ee952d8f3f12 (diff)
downloadbcm5719-llvm-c22f5b4abb1f1100dd8083d04d4ab2c79080104f.tar.gz
bcm5719-llvm-c22f5b4abb1f1100dd8083d04d4ab2c79080104f.zip
Improve formatting of #defines.
Two improvements: 1) Always leave at least one space before "\". Otherwise is can look bad and there is a risk of unwillingly joining to characters to a different token. 2) Use the full column limit for single-line #defines. Fixes llvm.org/PR15148 llvm-svn: 176245
Diffstat (limited to 'clang/lib')
-rw-r--r--clang/lib/Format/Format.cpp15
1 files changed, 10 insertions, 5 deletions
diff --git a/clang/lib/Format/Format.cpp b/clang/lib/Format/Format.cpp
index 18a853f1e4b..4aaae844fca 100644
--- a/clang/lib/Format/Format.cpp
+++ b/clang/lib/Format/Format.cpp
@@ -273,7 +273,7 @@ public:
///
/// \returns The column after the last token in the last line of the
/// \c UnwrappedLine.
- unsigned format() {
+ unsigned format(const AnnotatedLine *NextLine) {
// Initialize state dependent on indent.
LineState State;
State.Column = FirstIndent;
@@ -295,7 +295,11 @@ public:
moveStateToNextToken(State, /*DryRun=*/ false);
// If everything fits on a single line, just put it there.
- if (Line.Last->TotalLength <= getColumnLimit() - FirstIndent) {
+ unsigned ColumnLimit = Style.ColumnLimit;
+ if (NextLine && NextLine->InPPDirective &&
+ !NextLine->First.FormatTok.HasUnescapedNewline)
+ ColumnLimit = getColumnLimit();
+ if (Line.Last->TotalLength <= ColumnLimit - FirstIndent) {
while (State.NextToken != NULL) {
addTokenToState(false, false, State);
}
@@ -749,7 +753,7 @@ private:
}
unsigned getColumnLimit() {
- return Style.ColumnLimit - (Line.InPPDirective ? 1 : 0);
+ return Style.ColumnLimit - (Line.InPPDirective ? 2 : 0);
}
/// \brief An edge in the solution space from \c Previous->State to \c State,
@@ -1112,7 +1116,8 @@ public:
UnwrappedLineFormatter Formatter(Style, SourceMgr, TheLine, Indent,
TheLine.First, Whitespaces,
StructuralError);
- PreviousEndOfLineColumn = Formatter.format();
+ PreviousEndOfLineColumn =
+ Formatter.format(I + 1 != E ? &*(I + 1) : NULL);
IndentForLevel[TheLine.Level] = LevelIndent;
PreviousLineWasTouched = true;
} else {
@@ -1192,7 +1197,7 @@ private:
if (I->Last->Type == TT_LineComment)
return;
- unsigned Limit = Style.ColumnLimit - (I->InPPDirective ? 1 : 0) - Indent;
+ unsigned Limit = Style.ColumnLimit - Indent;
// If we already exceed the column limit, we set 'Limit' to 0. The different
// tryMerge..() functions can then decide whether to still do merging.
Limit = I->Last->TotalLength > Limit ? 0 : Limit - I->Last->TotalLength;
OpenPOWER on IntegriCloud