diff options
author | Alexander Kornienko <alexfh@google.com> | 2014-04-17 16:12:46 +0000 |
---|---|---|
committer | Alexander Kornienko <alexfh@google.com> | 2014-04-17 16:12:46 +0000 |
commit | 67d9c8c87ef4451214211ae8bb44f84ec7713a4b (patch) | |
tree | 67b2dde644078e6bb48465303e6b7f79e97afef3 /clang/lib/Format/WhitespaceManager.h | |
parent | ed5aced64ef601411e400d8bb89e4dde4b7820a7 (diff) | |
download | bcm5719-llvm-67d9c8c87ef4451214211ae8bb44f84ec7713a4b.tar.gz bcm5719-llvm-67d9c8c87ef4451214211ae8bb44f84ec7713a4b.zip |
Fix alignment of trailing block comments.
Summary:
This patch ensures that the lines of the block comments retain relative
column offsets. In order to do this WhitespaceManager::Changes representing
continuation of block comments keep a pointer on the change representing the
whitespace change before the block comment, and a relative column offset to this
change, so that the correct column can be reconstructed at the end of alignment
process.
Fixes http://llvm.org/PR19325
Reviewers: djasper
Reviewed By: djasper
CC: cfe-commits, klimek
Differential Revision: http://reviews.llvm.org/D3408
llvm-svn: 206472
Diffstat (limited to 'clang/lib/Format/WhitespaceManager.h')
-rw-r--r-- | clang/lib/Format/WhitespaceManager.h | 26 |
1 files changed, 23 insertions, 3 deletions
diff --git a/clang/lib/Format/WhitespaceManager.h b/clang/lib/Format/WhitespaceManager.h index f94464ff38a..189b1aefa03 100644 --- a/clang/lib/Format/WhitespaceManager.h +++ b/clang/lib/Format/WhitespaceManager.h @@ -63,6 +63,12 @@ public: /// (in this order) at \p Offset inside \p Tok, replacing \p ReplaceChars /// characters. /// + /// Note: \p Spaces can be negative to retain information about initial + /// relative column offset between a line of a block comment and the start of + /// the comment. This negative offset may be compensated by trailing comment + /// alignment here. In all other cases negative \p Spaces will be truncated to + /// 0. + /// /// When \p InPPDirective is true, escaped newlines are inserted. \p Spaces is /// used to align backslashes correctly. void replaceWhitespaceInToken(const FormatToken &Tok, unsigned Offset, @@ -70,7 +76,7 @@ public: StringRef PreviousPostfix, StringRef CurrentPrefix, bool InPPDirective, unsigned Newlines, unsigned IndentLevel, - unsigned Spaces); + int Spaces); /// \brief Returns all the \c Replacements created during formatting. const tooling::Replacements &generateReplacements(); @@ -101,7 +107,7 @@ private: /// \p StartOfTokenColumn and \p InPPDirective will be used to lay out /// trailing comments and escaped newlines. Change(bool CreateReplacement, const SourceRange &OriginalWhitespaceRange, - unsigned IndentLevel, unsigned Spaces, unsigned StartOfTokenColumn, + unsigned IndentLevel, int Spaces, unsigned StartOfTokenColumn, unsigned NewlinesBefore, StringRef PreviousLinePostfix, StringRef CurrentLinePrefix, tok::TokenKind Kind, bool ContinuesPPDirective); @@ -128,7 +134,10 @@ private: // The number of spaces in front of the token or broken part of the token. // This will be adapted when aligning tokens. - unsigned Spaces; + // Can be negative to retain information about the initial relative offset + // of the lines in a block comment. This is used when aligning trailing + // comments. Uncompensated negative offset is truncated to 0. + int Spaces; // \c IsTrailingComment, \c TokenLength, \c PreviousEndOfTokenColumn and // \c EscapedNewlineColumn will be calculated in @@ -137,6 +146,17 @@ private: unsigned TokenLength; unsigned PreviousEndOfTokenColumn; unsigned EscapedNewlineColumn; + + // These fields are used to retain correct relative line indentation in a + // block comment when aligning trailing comments. + // + // If this Change represents a continuation of a block comment, + // \c StartOfBlockComment is pointer to the first Change in the block + // comment. \c IndentationOffset is a relative column offset to this + // change, so that the correct column can be reconstructed at the end of + // the alignment process. + const Change *StartOfBlockComment; + int IndentationOffset; }; /// \brief Calculate \c IsTrailingComment, \c TokenLength for the last tokens |