Commit Graph

942 Commits

Author SHA1 Message Date
Manuel Klimek ffdeb595ba First step towards correctly formatting lambdas.
Implements parsing of lambdas in the UnwrappedLineParser.
This introduces the correct line breaks; the formatting of
lambda captures are still incorrect, and the braces are also
still formatted as if they were braced init lists instead of
blocks.

llvm-svn: 189818
2013-09-03 15:10:01 +00:00
Daniel Jasper 42401c8d13 clang-format: Fix segfault in overloaded operator parsing.
Before, constructs like:
  using A::operator+;

caused a segfault. This fixes llvm.org/PR17050.

llvm-svn: 189749
2013-09-02 09:20:39 +00:00
Daniel Jasper 7240762504 clang-format: Fix case-indentation in macros.
Before:
  #define OPERATION_CASE(name)           \
    case OP_name:                        \
    return operations::Operation##name

After:
  #define OPERATION_CASE(name)           \
    case OP_name:                        \
      return operations::Operation##name

llvm-svn: 189743
2013-09-02 08:26:29 +00:00
Samuel Benzaquen 998cda23b9 Reduce the number of symbols by changing how templates are instantiated per function bound in the registry.
Summary:
Reduce the number of symbols by changing how templates are instantiated per function bound in the registry.
This change reduces the number of sections in Registry.cpp.o by a little over 10%.

Reviewers: klimek

CC: cfe-commits, revane

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

llvm-svn: 189676
2013-08-30 15:09:52 +00:00
Daniel Jasper 8ddfa8489b clang-format: Enable formatting of protocol buffer definitions.
Almost by accident, clang-format seems to be able to format protocol
buffer definitions (https://code.google.com/p/protobuf/).

The only change is that a space is required between numeric constants
and opening square brackets (for default values). While this might in
theory be used for array subscripts (int val = 4[MyArray]), I have not
seen this pattern in practice much. If this is wrong, we can make this
smarter in the future.

llvm-svn: 189663
2013-08-30 10:36:58 +00:00
Daniel Jasper b715087278 clang-format: Improve recovery from enums with errors.
Before:
  namespace n {
  enum Type {
    One,
    Two, // missing };
    int i;
  } void g() {
  }

After:
  namespace n {
  enum Type {
    One,
    Two, // missing };
    int i;
  }
  void g() {}

llvm-svn: 189662
2013-08-30 10:10:19 +00:00
Daniel Jasper f79b0b1562 clang-format: Fix incorrect indentation.
Before:
aaaaaaaaaa(bbbbbbbbbbbbbbbbbbbbbbbbb.ccccccccccccccccc(
               dddddddddddddddddddddddddddddd));
aaaaaaaaaaa(bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb(
    dddddddddddddddddddddddddddddd));

After:
aaaaaaaaaaa(bbbbbbbbbbbbbbbbbbbbbbbbb.ccccccccccccccccc(
    dddddddddddddddddddddddddddddd));
aaaaaaaaaaa(bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb(
    dddddddddddddddddddddddddddddd));

This was overlooked when interducing the new builder-type call
detection in r189337. Also, some minor reorganization of a test.

llvm-svn: 189658
2013-08-30 08:29:25 +00:00
Daniel Jasper 2cf664fb86 clang-format: Don't indent builders relative to "return".
While this looks kind of nice, it wastes horizontal space and does not
seem to be common in the LLVM codebase.

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: 189657
2013-08-30 07:27:13 +00:00
Daniel Jasper f8151e9bc1 clang-format: Fix corner case in builder-type calls.
Before:
  aaaaaaaaaaaaa->aaaaaaaaaaaaaaaaaaaaaaaa()->aaaaaaaaaaaaaae(
                                                 0)->aaaaaaaaaaaaaaa();

After:
  aaaaaaaaaaaaa->aaaaaaaaaaaaaaaaaaaaaaaa()
      ->aaaaaaaaaaaaaae(0)
      ->aaaaaaaaaaaaaaa();

llvm-svn: 189655
2013-08-30 07:12:40 +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
Samuel Benzaquen 68cd396f82 Fix tests to be more specific.
The environments can inject some declaration in every translation unit,
which can match very generic matchers, thus failing the tests.

Summary:
Fix tests to be more specific.
The environments can inject some declaration in every translation unit,
which can match very generic matchers, thus failing the tests.

Reviewers: aaron.ballman

CC: klimek, cfe-commits, revane

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

llvm-svn: 189587
2013-08-29 15:39:26 +00:00
Manuel Klimek 31c85921b2 Fixes various problems with accounting for tabs in the original code.
We now count the original token's column directly when lexing the
tokens, where we already have all knowledge about where lines start.

Before this patch, formatting:
 void f() {
 \tg();
 \th();
 }
would incorrectly count the \t's as 1 character if only the line
containing h() was reformatted, and thus indent h() at offset 1.

llvm-svn: 189585
2013-08-29 15:21:40 +00:00
Samuel Benzaquen 4adca6262e Add support for eachOf/allOf/anyOf variadic matchers in the dynamic layer.
Summary:
Add support for eachOf/allOf/anyOf variadic matchers in the dynamic layer.
These function require some late binding behavior for the type conversions, thus changes in VariadicValue's MatcherList.
Second try. This time with a fix for C++11 builds.

Reviewers: klimek

CC: cfe-commits, revane

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

llvm-svn: 189500
2013-08-28 18:42:04 +00:00
Daniel Jasper 2739af3b9c clang-format: Improve token breaking behavior.
Two changes:
* Don't add an extra penalty on breaking the same token multiple times.
  Generally, we should prefer not to break, but once we break, the
  normal line breaking penalties apply.
* Slightly increase the penalty for breaking comments. In general, the
  author has put some thought into how to break the comment and we
  should not overwrite this unnecessarily.

With a 40-column column limit, formatting
  aaaaaa("aaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaa");

Leads to:
Before:
  aaaaaa(
      "aaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaa "
      "aaaaaaaaaaaaaaaa");

After:
  aaaaaa("aaaaaaaaaaaaaaaa "
         "aaaaaaaaaaaaaaaa "
         "aaaaaaaaaaaaaaaa");

llvm-svn: 189466
2013-08-28 10:03:58 +00:00
Daniel Jasper 96df37a6a1 clang-format: Fix segfault in 'incomplete' macros.
The code leading to a segfault was:
  #pragma omp threadprivate(y)), // long comment leading to a line break

This fixes llvm.org/PR16513.

llvm-svn: 189460
2013-08-28 09:17:37 +00:00
Daniel Jasper a49393f54d clang-format: Fix infinite loop in macro special case.
If escaped newlines are aligned right
(FormatStyle.AlignEscapedNewlinesLeft == false), and a line contained
too many characters to fit into the column limit, this would result in
a (virtually) endless loop creating a negative number of spaces.

Instead, allow the escaped newlines to be pushed past the column limit
in this case.

This fixes llvm.org/PR16515.

llvm-svn: 189459
2013-08-28 09:07:32 +00:00
Daniel Jasper ed8f1c6dce clang-format: Don't insert space in __has_include
Before:
  #if __has_include( <strstream>)
  #include <strstream>
  #endif

After:
  #if __has_include(<strstream>)
  #include <strstream>
  #endif

This fixes llvm.org/PR16516.

llvm-svn: 189455
2013-08-28 08:24:04 +00:00
Daniel Jasper a15da3068d clang-format: Fix corner case in ObjC interface definitions.
In
  @implementation ObjcClass
  - (void)method;
  {
  }
  @end
the ObjC compiler seems to accept the superfluous comma after "method",
but clang-format used to assert on the subsequent "{".

This fixes llvm.org/PR16604.

llvm-svn: 189453
2013-08-28 08:04:23 +00:00
Daniel Jasper 65b79829c3 clang-format: Improve braced init list detection:
Before:
  std::this_thread::sleep_for(std::chrono::nanoseconds{
    std::chrono::seconds { 1 }
  } /
                              5);

After:
  std::this_thread::sleep_for(
      std::chrono::nanoseconds{ std::chrono::seconds{ 1 } } / 5);

This fixes llvm.org/PR16554.

llvm-svn: 189451
2013-08-28 07:50:37 +00:00
Daniel Jasper d215b8bde2 clang-format: Fix corner case in overloaded operator definitions.
Before:
  SomeLoooooooooooooooooooooooooogType operator>
      >(const SomeLooooooooooooooooooooooooogType &other);
  SomeLoooooooooooooooooooooooooogType // break
      operator>>(const SomeLooooooooooooooooooooooooogType &other);

After:
  SomeLoooooooooooooooooooooooooogType
  operator>>(const SomeLooooooooooooooooooooooooogType &other);
  SomeLoooooooooooooooooooooooooogType // break
  operator>>(const SomeLooooooooooooooooooooooooogType &other);

This fixes llvm.org/PR16328.

llvm-svn: 189450
2013-08-28 07:27:35 +00:00
Daniel Jasper 11be8ac590 clang-format: Fix space in decltype-constexprs.
Before:
  static constexpr bool Bar = decltype(bar()) ::value;

After:
  static constexpr bool Bar = decltype(bar())::value;

llvm-svn: 189449
2013-08-28 07:07:07 +00:00
Samuel Benzaquen 46e59b05eb Revert "Add support for eachOf/allOf/anyOf variadic matchers in the dynamic layer."
Summary:
This reverts commit 3b082a3c72324aa3363b5184731740534c6b9a2b.

It breaks the build in c++11 mode.

Reviewers: klimek

CC: cfe-commits, revane

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

llvm-svn: 189368
2013-08-27 16:55:22 +00:00
Samuel Benzaquen fe48aaf1a4 Add support for eachOf/allOf/anyOf variadic matchers in the dynamic layer.
Summary:
Add support for eachOf/allOf/anyOf variadic matchers in the dynamic layer.
These function require some late binding behavior for the type conversions, thus changes in VariadicValue's MatcherList.

Reviewers: klimek

CC: cfe-commits, revane

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

llvm-svn: 189362
2013-08-27 16:04:53 +00:00
Edwin Vane 18e503c995 Adding a vector version of clang::tooling::shiftedCodePosition().
During the transition of clang::tooling::Replacements from std::set to
std::vector, functions such as clang::tooling::applyAllReplacements() have been
duplicated to take a std::vector<Replacement>. Applying this same temporary
duplication to clang::tooling::shiftedCodePosition().

llvm-svn: 189358
2013-08-27 15:44:26 +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 b27c4b7cb5 clang-format: Revamp builder-type call formatting.
Previously builder-type calls were only correctly recognized in
top-level calls.

This fixes llvm.org/PR16981.
Before:
  someobj->Add((new util::filetools::Handler(dir))->OnEvent1(
      NewPermanentCallback(this, &HandlerHolderClass::EventHandlerCBA))
                   ->OnEvent2(NewPermanentCallback(
                                  this, &HandlerHolderClass::EventHandlerCBB))
                   ->OnEvent3(NewPermanentCallback(
                                  this, &HandlerHolderClass::EventHandlerCBC))
                   ->OnEvent5(NewPermanentCallback(
                                  this, &HandlerHolderClass::EventHandlerCBD))
                   ->OnEvent6(NewPermanentCallback(
                         this, &HandlerHolderClass::EventHandlerCBE)));

After:
  someobj->Add((new util::filetools::Handler(dir))
                   ->OnEvent1(NewPermanentCallback(
                         this, &HandlerHolderClass::EventHandlerCBA))
                   ->OnEvent2(NewPermanentCallback(
                         this, &HandlerHolderClass::EventHandlerCBB))
                   ->OnEvent3(NewPermanentCallback(
                         this, &HandlerHolderClass::EventHandlerCBC))
                   ->OnEvent5(NewPermanentCallback(
                         this, &HandlerHolderClass::EventHandlerCBD))
                   ->OnEvent6(NewPermanentCallback(
                         this, &HandlerHolderClass::EventHandlerCBE)));

llvm-svn: 189337
2013-08-27 11:09:05 +00:00
Daniel Jasper cb3f0ed817 clang-format: Fix bug in column layout.
Before (with 60 character limit in Google style):
  return {
      {aaaaaaaaaaaaaaaaaaaaaaaaa}, {aaaaaaaaaaaaaaaaa},
      {aaaaaaaaaaaaaaaaaaaaaaaaa}, {aaaaaaaaaaaaaaaaa}};
After:
  return {{aaaaaaaaaaaaaaaaaaaaaaaaa}, {aaaaaaaaaaaaaaaaa},
          {aaaaaaaaaaaaaaaaaaaaaaaaa}, {aaaaaaaaaaaaaaaaa}};

llvm-svn: 189327
2013-08-27 08:43:47 +00:00
Daniel Jasper 8863ada85b clang-format: Fix bug in column-layout formatting.
Specific arrangements of comments after trailing commas could confuse
the column width calculation, e.g. in:

vector<int> x = { a, b,
                  /* some */ /* comment */ };

llvm-svn: 189211
2013-08-26 08:10:17 +00:00
Dmitri Gribenko 1e50cbf366 Comment parsing: fix a bug where a line with whitespace between two paragraphs
would cause us to concatenate these paragraphs into a single one.

The no-op whitespace churn in test/Index test happened because these tests
don't use the correct approach for testing and are more strict than required
for they are testing.

llvm-svn: 189126
2013-08-23 18:03:40 +00:00
Daniel Jasper 0649d36172 clang-format: Fix indentation relative to unary expressions.
This should be done, only if we are still in the unary expression's
scope.

Before:
  bool aaaa = !aaaaaaaa(  // break
                   aaaaaaaaaaa);
  *aaaaaa = aaaaaaa( // break
       aaaaaaaaaaaaaaaa);

After:
  bool aaaa = !aaaaaaaa(  // break
                   aaaaaaaaaaa); // <- (unchanged)
  *aaaaaa = aaaaaaa( // break
      aaaaaaaaaaaaaaaa); // <- (no longer indented relative to "*")

llvm-svn: 189108
2013-08-23 15:14:03 +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 f93551c8b1 clang-format: Handle trailing commas in column layout of braced list.
Before, this was causing errors.

Also exit early in breakProtrudingToken() (before the expensive call to
SourceManager::getSpellingColumnNumber()). This makes formatting huge
(100k+-item) braced lists possible.

llvm-svn: 189094
2013-08-23 10:05:49 +00:00
Jordan Rose a1e4b12223 Fix dependencies now that the ARC migrator depends on the static analyzer.
Thanks for pointing this out, Stephen. I think this is right now -- I
attempted to try all four valid combinations with both the autoconf and
CMake builds.

See also LLVM changes to the configure script.

llvm-svn: 189027
2013-08-22 15:50:02 +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 f110e201e4 clang-format: Indent relative to unary operators.
Before:
  if (!aaaaaaaaaa(  // break
          aaaaa)) {
  }

After:
  if (!aaaaaaaaaa(  // break
           aaaaa)) {
  }

Also cleaned up formatting using clang-format.

llvm-svn: 188891
2013-08-21 08:39:01 +00:00
Edwin Vane d7e2278f6c Adding Replacement serialization support
Adding a new data structure for storing the Replacements generated for a single
translation unit. Structure contains a vector of Replacements as well a field
indicating the main source file of the translation unit. An optional 'Context'
field allows for tools to provide any information they want about the context
the Replacements were generated in. This context is printed, for example, when
detecting conflicts during Replacement deduplication.

YAML serialization for this data structure is implemented in this patch. Tests
are included.

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

llvm-svn: 188818
2013-08-20 19:07:21 +00:00
Daniel Jasper 2b41a82e61 clang-format: Format enum struct/class like enum.
Patch by Joe Hermaszewski. Thank you!

llvm-svn: 188794
2013-08-20 12:42:50 +00:00
Daniel Jasper b55acad91c clang-format: Additional options for spaces around parentheses.
This patch adds four new options to control:
- Spaces after control keyworks (if(..) vs if (..))
- Spaces in empty parentheses (f( ) vs f())
- Spaces in c-style casts (( int )1.0 vs (int)1.0)
- Spaces in other parentheses (f(a) vs f( a ))

Patch by Joe Hermaszewski. Thank you for working on this!

llvm-svn: 188793
2013-08-20 12:36:34 +00:00
Daniel Jasper 5364306e12 clang-format: Fix return type line break decision.
This accidentally introduced by r186077, as function names were not
correctly recognized in templated declarations.

Before:
  template <class TemplateIt>
  SomeReturnType
  SomeFunction(TemplateIt begin, TemplateIt end, TemplateIt* stop) {}

After:
  template <class TemplateIt>
  SomeReturnType SomeFunction(TemplateIt begin, TemplateIt end,
                              TemplateIt* stop) {}

llvm-svn: 188665
2013-08-19 10:16:18 +00:00
Edwin Vane c514848d1b Have Range::overlapsWith use positive logic
Improved test to catch missing case.

llvm-svn: 188304
2013-08-13 18:11:16 +00:00
Edwin Vane 349e1c18eb Adding a vector version of tooling::applyAllReplacements
One day soon, tooling::Replacements will be changed from being implemented as
an std::set to being implemented as an std::vector. Until then, some new code
using vectors of Replacements would enjoy having a version of
applyAllReplacements that takes a vector.

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

llvm-svn: 188295
2013-08-13 17:38:19 +00:00
Edwin Vane f59b1a9211 Fixing a conflict detection bug in tooling::deduplicate
If a Replacment is contained within the conflict range being built, the
conflict range would be erroneously shortened. Now fixed. Tests updated to
catch this case.

llvm-svn: 188287
2013-08-13 16:26:44 +00:00
Samuel Benzaquen 0239b69167 Refactor "MatcherList" into "VariantMatcher" and abstract the notion of a list of matchers for the polymorphic case.
Summary:
Refactor "MatcherList" into "VariantMatcher" and abstract the notion of a list of matchers for the polymorphic case.
This work is to support future changes needed for eachOf/allOf/anyOf matchers. We will add a new type on VariantMatcher.

Reviewers: klimek

CC: cfe-commits, revane

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

llvm-svn: 188272
2013-08-13 14:54:51 +00:00
Daniel Jasper cdaffa45d4 clang-format: Add option for the offset of constructor initializers.
Some coding styles use a different indent for constructor initializers.

Patch by Klemens Baum. Thank you.
Review: http://llvm-reviews.chandlerc.com/D1360

Post review changes: Changed data type to unsigned as a negative indent
width does not make sense and added test for configuration parsing.

llvm-svn: 188260
2013-08-13 10:58:30 +00:00
Daniel Jasper 29a98cfca0 clang-format: Improve boolean expression formatting in macros.
Before:
  #define IF(a, b, c) if (a&&(b == c))

After:
  #define IF(a, b, c) if (a && (b == c))

llvm-svn: 188256
2013-08-13 09:09:09 +00:00
Daniel Jasper 70dc91aaf1 clang-format: Activate WebKit-style tests for MS compilers.
They were accidentally placed in the #if.

llvm-svn: 188255
2013-08-13 08:29:26 +00:00
Daniel Jasper 301d017139 clang-format: Slightly adapt line break penalties.
Before:
  aaaaaaaaaaaaaaaaaaaaaaaa(aaaaaaaaaaaaa(aaaaaaaaaaaaaaaaaaaaaaaaa)
                               ->aaaaaaaaa());
After:
  aaaaaaaaaaaaaaaaaaaaaaaa(
      aaaaaaaaaaaaa(aaaaaaaaaaaaaaaaaaaaaaaaa)->aaaaaaaaa());

llvm-svn: 188253
2013-08-13 06:50:04 +00:00
Kaelyn Uhrain 2c351bbc25 Add hooks to ExternalSemaSource for after-the-fact diagnosis of
incomplete types, courtesy of Luke Zarko.

llvm-svn: 188212
2013-08-12 22:11:14 +00:00
Kaelyn Uhrain 4ebf57672d Forgot to add unittests/Sema/ before committing r188196 :(
llvm-svn: 188197
2013-08-12 19:57:06 +00:00
Kaelyn Uhrain f0aabdadc6 Add hooks for typo correction to ExternalSemaSource, courtesy of Luke Zarko.
llvm-svn: 188196
2013-08-12 19:54:38 +00:00