diff options
author | Manuel Klimek <klimek@google.com> | 2013-01-02 16:30:12 +0000 |
---|---|---|
committer | Manuel Klimek <klimek@google.com> | 2013-01-02 16:30:12 +0000 |
commit | a080a187fa7e538da3212c7d5e678e4b7ae03253 (patch) | |
tree | 5a2c54db0a6a2ec4e1764cea7c7080d6898b8d84 /lib/Format/UnwrappedLineParser.h | |
parent | ef5b9c3d38a1f6d0921591cb2749e529a8cc4a2e (diff) |
Fixes use of unescaped newlines when formatting preprocessor directives.
This is the first step towards handling preprocessor directives. This
patch only fixes the most pressing issue, namely correctly escaping
newlines for tokens within a sequence of a preprocessor directive.
The next step will be to fix incorrect format decisions on #define
directives.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@171393 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Format/UnwrappedLineParser.h')
-rw-r--r-- | lib/Format/UnwrappedLineParser.h | 12 |
1 files changed, 10 insertions, 2 deletions
diff --git a/lib/Format/UnwrappedLineParser.h b/lib/Format/UnwrappedLineParser.h index ccf437f507..9ed796d45b 100644 --- a/lib/Format/UnwrappedLineParser.h +++ b/lib/Format/UnwrappedLineParser.h @@ -30,7 +30,8 @@ namespace format { /// \brief A wrapper around a \c Token storing information about the /// whitespace characters preceeding it. struct FormatToken { - FormatToken() : NewlinesBefore(0), WhiteSpaceLength(0) { + FormatToken() + : NewlinesBefore(0), HasUnescapedNewline(false), WhiteSpaceLength(0) { } /// \brief The \c Token. @@ -42,6 +43,10 @@ struct FormatToken { /// and thereby e.g. leave an empty line between two function definitions. unsigned NewlinesBefore; + /// \brief Whether there is at least one unescaped newline before the \c + /// Token. + bool HasUnescapedNewline; + /// \brief The location of the start of the whitespace immediately preceeding /// the \c Token. /// @@ -60,7 +65,7 @@ struct FormatToken { /// \c UnwrappedLineFormatter. The key property is that changing the formatting /// within an unwrapped line does not affect any other unwrapped lines. struct UnwrappedLine { - UnwrappedLine() : Level(0) { + UnwrappedLine() : Level(0), InPPDirective(false) { } /// \brief The \c Token comprising this \c UnwrappedLine. @@ -68,6 +73,9 @@ struct UnwrappedLine { /// \brief The indent level of the \c UnwrappedLine. unsigned Level; + + /// \brief Whether this \c UnwrappedLine is part of a preprocessor directive. + bool InPPDirective; }; class UnwrappedLineConsumer { |