Enables layouting unwrapped lines around preprocessor directives.
Previously, we'd always start at indent level 0 after a preprocessor
directive, now we layout the following snippet (column limit 69) as
follows:
functionCallTo(someOtherFunction(
withSomeParameters, whichInSequence,
areLongerThanALine(andAnotherCall,
B
withMoreParamters,
whichStronglyInfluenceTheLayout),
andMoreParameters),
trailing);
Note that the different jumping indent is a different issue that will be
addressed separately.
This is the first step towards handling #ifdef->#else->#endif chains
correctly.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@171974 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Format/UnwrappedLineParser.h b/lib/Format/UnwrappedLineParser.h
index 010bad8..500054f 100644
--- a/lib/Format/UnwrappedLineParser.h
+++ b/lib/Format/UnwrappedLineParser.h
@@ -34,7 +34,7 @@
struct FormatToken {
FormatToken()
: NewlinesBefore(0), HasUnescapedNewline(false), WhiteSpaceLength(0),
- TokenLength(0), IsFirst(false) {
+ TokenLength(0), IsFirst(false), MustBreakBefore(false) {
}
/// \brief The \c Token.
@@ -68,6 +68,12 @@
/// \brief Indicates that this is the first token.
bool IsFirst;
+ /// \brief Whether there must be a line break before this token.
+ ///
+ /// This happens for example when a preprocessor directive ended directly
+ /// before the token.
+ bool MustBreakBefore;
+
// FIXME: We currently assume that there is exactly one token in this vector
// except for the very last token that does not have any children.
/// \brief All tokens that logically follow this token.
@@ -144,10 +150,11 @@
// FIXME: We are constantly running into bugs where Line.Level is incorrectly
// subtracted from beyond 0. Introduce a method to subtract from Line.Level
// and use that everywhere in the Parser.
- UnwrappedLine Line;
+ llvm::OwningPtr<UnwrappedLine> Line;
bool RootTokenInitialized;
FormatToken *LastInCurrentLine;
FormatToken FormatTok;
+ bool MustBreakBeforeNextToken;
const FormatStyle &Style;
FormatTokenSource *Tokens;