diff options
Diffstat (limited to 'clang/lib/Format/WhitespaceManager.h')
-rw-r--r-- | clang/lib/Format/WhitespaceManager.h | 30 |
1 files changed, 23 insertions, 7 deletions
diff --git a/clang/lib/Format/WhitespaceManager.h b/clang/lib/Format/WhitespaceManager.h index f47bf40204b33..1398a3aee2b89 100644 --- a/clang/lib/Format/WhitespaceManager.h +++ b/clang/lib/Format/WhitespaceManager.h @@ -19,6 +19,7 @@ #include "clang/Basic/SourceManager.h" #include "clang/Format/Format.h" #include <string> +#include <tuple> namespace clang { namespace format { @@ -49,7 +50,7 @@ public: /// this replacement. It is needed for determining how \p Spaces is turned /// into tabs and spaces for some format styles. void replaceWhitespace(FormatToken &Tok, unsigned Newlines, unsigned Spaces, - unsigned StartOfTokenColumn, + unsigned StartOfTokenColumn, bool isAligned = false, bool InPPDirective = false); /// Adds information about an unchangeable token's whitespace. @@ -109,7 +110,7 @@ public: SourceRange OriginalWhitespaceRange, int Spaces, unsigned StartOfTokenColumn, unsigned NewlinesBefore, StringRef PreviousLinePostfix, StringRef CurrentLinePrefix, - bool ContinuesPPDirective, bool IsInsideToken); + bool IsAligned, bool ContinuesPPDirective, bool IsInsideToken); // The kind of the token whose whitespace this change replaces, or in which // this change inserts whitespace. @@ -125,6 +126,7 @@ public: unsigned NewlinesBefore; std::string PreviousLinePostfix; std::string CurrentLinePrefix; + bool IsAligned; bool ContinuesPPDirective; // The number of spaces in front of the token or broken part of the token. @@ -157,11 +159,16 @@ public: const Change *StartOfBlockComment; int IndentationOffset; - // A combination of indent level and nesting level, which are used in - // tandem to compute lexical scope, for the purposes of deciding + // Depth of conditionals. Computed from tracking fake parenthesis, except + // it does not increase the indent for "chained" conditionals. + int ConditionalsLevel; + + // A combination of indent, nesting and conditionals levels, which are used + // in tandem to compute lexical scope, for the purposes of deciding // when to stop consecutive alignment runs. - std::pair<unsigned, unsigned> indentAndNestingLevel() const { - return std::make_pair(Tok->IndentLevel, Tok->NestingLevel); + std::tuple<unsigned, unsigned, unsigned> indentAndNestingLevel() const { + return std::make_tuple(Tok->IndentLevel, Tok->NestingLevel, + ConditionalsLevel); } }; @@ -177,9 +184,15 @@ private: /// Align consecutive assignments over all \c Changes. void alignConsecutiveAssignments(); + /// Align consecutive bitfields over all \c Changes. + void alignConsecutiveBitFields(); + /// Align consecutive declarations over all \c Changes. void alignConsecutiveDeclarations(); + /// Align consecutive declarations over all \c Changes. + void alignChainedConditionals(); + /// Align trailing comments over all \c Changes. void alignTrailingComments(); @@ -204,7 +217,10 @@ private: unsigned PreviousEndOfTokenColumn, unsigned EscapedNewlineColumn); void appendIndentText(std::string &Text, unsigned IndentLevel, - unsigned Spaces, unsigned WhitespaceStartColumn); + unsigned Spaces, unsigned WhitespaceStartColumn, + bool IsAligned); + unsigned appendTabIndent(std::string &Text, unsigned Spaces, + unsigned Indentation); SmallVector<Change, 16> Changes; const SourceManager &SourceMgr; |