diff options
author | Daniel Jasper <djasper@google.com> | 2013-08-22 15:00:41 +0000 |
---|---|---|
committer | Daniel Jasper <djasper@google.com> | 2013-08-22 15:00:41 +0000 |
commit | 8de9ed05b7748ecd69b0a2f08611f456ad559c8a (patch) | |
tree | 1851727476ae8adfcdbce5cd495b7271bb3fc910 /clang/lib/Format/TokenAnnotator.cpp | |
parent | effabf96916b766b9aa2324daf006b4da281fa57 (diff) | |
download | bcm5719-llvm-8de9ed05b7748ecd69b0a2f08611f456ad559c8a.tar.gz bcm5719-llvm-8de9ed05b7748ecd69b0a2f08611f456ad559c8a.zip |
clang-format: Add column layout formatting for braced lists
With this patch, braced lists (with more than 3 elements are formatted in a
column layout if possible). E.g.:
static const uint16_t CallerSavedRegs64Bit[] = {
X86::RAX, X86::RDX, X86::RCX, X86::RSI, X86::RDI,
X86::R8, X86::R9, X86::R10, X86::R11, 0
};
Required other changes:
- FormatTokens can now have a special role that contains extra data and can do
special formattings. A comma separated list is currently the only
implementation.
- Move penalty calculation entirely into ContinuationIndenter (there was a last
piece still in UnwrappedLineFormatter).
Review: http://llvm-reviews.chandlerc.com/D1457
llvm-svn: 189018
Diffstat (limited to 'clang/lib/Format/TokenAnnotator.cpp')
-rw-r--r-- | clang/lib/Format/TokenAnnotator.cpp | 19 |
1 files changed, 15 insertions, 4 deletions
diff --git a/clang/lib/Format/TokenAnnotator.cpp b/clang/lib/Format/TokenAnnotator.cpp index e3d6d5e1bb0..ffbe240fa75 100644 --- a/clang/lib/Format/TokenAnnotator.cpp +++ b/clang/lib/Format/TokenAnnotator.cpp @@ -29,9 +29,11 @@ namespace { /// into template parameter lists. class AnnotatingParser { public: - AnnotatingParser(AnnotatedLine &Line, IdentifierInfo &Ident_in) - : Line(Line), CurrentToken(Line.First), KeywordVirtualFound(false), - NameFound(false), AutoFound(false), Ident_in(Ident_in) { + AnnotatingParser(const FormatStyle &Style, AnnotatedLine &Line, + IdentifierInfo &Ident_in) + : Style(Style), Line(Line), CurrentToken(Line.First), + KeywordVirtualFound(false), NameFound(false), AutoFound(false), + Ident_in(Ident_in) { Contexts.push_back(Context(tok::unknown, 1, /*IsExpression=*/false)); } @@ -268,6 +270,9 @@ private: void updateParameterCount(FormatToken *Left, FormatToken *Current) { if (Current->is(tok::comma)) { ++Left->ParameterCount; + if (!Left->Role) + Left->Role.reset(new CommaSeparatedList(Style)); + Left->Role->CommaFound(Current); } else if (Left->ParameterCount == 0 && Current->isNot(tok::comment)) { Left->ParameterCount = 1; } @@ -827,6 +832,7 @@ private: SmallVector<Context, 8> Contexts; + const FormatStyle &Style; AnnotatedLine &Line; FormatToken *CurrentToken; bool KeywordVirtualFound; @@ -937,7 +943,7 @@ private: } // end anonymous namespace void TokenAnnotator::annotate(AnnotatedLine &Line) { - AnnotatingParser Parser(Line, Ident_in); + AnnotatingParser Parser(Style, Line, Ident_in); Line.Type = Parser.parseLine(); if (Line.Type == LT_Invalid) return; @@ -1007,6 +1013,11 @@ void TokenAnnotator::calculateFormattingInformation(AnnotatedLine &Line) { } calculateUnbreakableTailLengths(Line); + for (Current = Line.First; Current != NULL; Current = Current->Next) { + if (Current->Role) + Current->Role->precomputeFormattingInfos(Current); + } + DEBUG({ printDebugInfo(Line); }); |