Commit Graph

11 Commits

Author SHA1 Message Date
Alexander Kornienko e2e0387f3e Keep track of indentation levels in static initializers for correct indentation with tabs.
Summary:
Store IndentationLevel in ParentState and use it instead of the
Line::Level when indening.
Also fixed incorrect indentation level calculation in formatFirstToken.

Reviewers: djasper

Reviewed By: djasper

CC: cfe-commits, klimek

Differential Revision: http://llvm-reviews.chandlerc.com/D1797

llvm-svn: 192563
2013-10-14 00:46:35 +00:00
Manuel Klimek 71814b4465 Support formatting of preprocessor branches.
We now correctly format:
  void SomeFunction(int param1,
  #ifdef X
                    NoTemplate param2,
  #else
                    template <
  #ifdef A
                        MyType<Some> >
  #else
                        Type1, Type2>
  #endif
                    param2,
  #endif
                    param3) {
    f();
  }

llvm-svn: 192503
2013-10-11 21:25:45 +00:00
Alexander Kornienko 1f80396d03 Refactoring: split addTokenToState into two methods.
Summary: Pure refactoring, should be no semantic changes.

Reviewers: djasper

Reviewed By: djasper

CC: cfe-commits, klimek

Differential Revision: http://llvm-reviews.chandlerc.com/D1796

llvm-svn: 191772
2013-10-01 14:41:18 +00:00
Alexander Kornienko 917f9e04b5 Correctly calculate OriginalColumn after multi-line tokens.
Summary: This also unifies the handling of escaped newlines for all tokens.

Reviewers: djasper

Reviewed By: djasper

CC: cfe-commits, klimek

Differential Revision: http://llvm-reviews.chandlerc.com/D1638

llvm-svn: 190405
2013-09-10 12:29:48 +00:00
Daniel Jasper 1c5d9df8d1 clang-format: Fix comment formatting bugs in nested blocks.
This fixes two issues:
1) The indent of a line comment was not adapted to the subsequent
   statement as it would be outside of a nested block.
2) A missing DryRun flag caused actualy breaks to be inserted in
   overly long comments while trying to come up with the best line
   breaking decisions.

llvm-svn: 190123
2013-09-06 07:54:20 +00:00
Daniel Jasper 9fe0e8dacd clang-format: Enable formatting of nested blocks.
Among other things, this enables (better) formatting lambdas and
constructs like:
  MACRO({
          long_statement();
          long_statement_2();
        },
        {
          long_statement();
          long_statement_2();
        },
        { short_statement(); }, "");

This fixes llvm.org/PR15381.

llvm-svn: 190038
2013-09-05 09:29:45 +00:00
Alexander Kornienko d7b837e78d Better support for multiline string literals (including C++11 raw string literals).
Summary:
Calculate characters in the first and the last line correctly so that
we only break before the literal when needed.

Reviewers: djasper

Reviewed By: djasper

CC: cfe-commits, klimek

Differential Revision: http://llvm-reviews.chandlerc.com/D1544

llvm-svn: 189595
2013-08-29 17:32:57 +00:00
Daniel Jasper 4c6e00595b clang-format: Format segments of builder-type calls one per line.
This fixes llvm.org/PR14818.

Before:
  return llvm::StringSwitch<Reference::Kind>(name)
             .StartsWith(".eh_frame_hdr", ORDER_EH_FRAMEHDR)
             .StartsWith(".eh_frame", ORDER_EH_FRAME)
             .StartsWith(".init", ORDER_INIT).StartsWith(".fini", ORDER_FINI)
             .StartsWith(".hash", ORDER_HASH).Default(ORDER_TEXT);

After:
  return llvm::StringSwitch<Reference::Kind>(name)
             .StartsWith(".eh_frame_hdr", ORDER_EH_FRAMEHDR)
             .StartsWith(".eh_frame", ORDER_EH_FRAME)
             .StartsWith(".init", ORDER_INIT)
             .StartsWith(".fini", ORDER_FINI)
             .StartsWith(".hash", ORDER_HASH)
             .Default(ORDER_TEXT);

llvm-svn: 189353
2013-08-27 14:24:43 +00:00
Daniel Jasper f438cb7619 clang-format: Fix corner case for string splitting ..
.. in conjunction with Style.AlwaysBreakBeforeMultilineStrings. Also,
simplify the implementation by handling newly split strings and already
split strings by the same code.

llvm-svn: 189102
2013-08-23 11:57:34 +00:00
Daniel Jasper 8de9ed05b7 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
2013-08-22 15:00:41 +00:00
Daniel Jasper de0328aea8 Split UnwrappedLineFormatter into individual components.
Goals: Structure code better and make components easier to use for
future features (e.g. column layout for long braced initializers).

No functional changes intended.

llvm-svn: 188543
2013-08-16 11:20:30 +00:00