Commit Graph

1760 Commits

Author SHA1 Message Date
Daniel Jasper 0391e55650 clang-format: Fix access to uninitialized memory.
With incomplete code, we aren't guaranteed to generated changes for
every token. In that case, we need to assume that even the very first
change can continue a preprocessor directive and initialize values
accordingly.

llvm-svn: 231066
2015-03-03 13:59:49 +00:00
Filipe Cabecinhas 5c5c00b7da Add -frtti and -fexceptions to tests that assume these are on.
Summary:
We now have targets that don't enable rtti/exceptions by default, and the
ASTMatchers tests are assuming that these features are on (e.g: They use
dynamic_cast or try).

Reviewers: klimek, thakis, djasper

Subscribers: klimek, cfe-commits

Differential Revision: http://reviews.llvm.org/D7892

llvm-svn: 230984
2015-03-02 18:49:37 +00:00
Daniel Jasper e662316994 clang-format: Prefer wrapping a lambda's body over the lambda's return type.
Before:
  aaaaaaaaaaaaaaaaaaaaaa(
      [](aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa &aaa)
          -> aaaaaaaaaaaaaaaaaaaaa { return aaaaaaaaaaaaaaaaa; });

After:
  aaaaaaaaaaaaaaaaaaaaaa(
      [](aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa &aaa) -> aaaaaaaaaaaaaaaaaaaaa {
        return aaaaaaaaaaaaaaaaa;
      });

llvm-svn: 230942
2015-03-02 10:35:13 +00:00
Benjamin Kramer 33335df819 Add missing include.
llvm-svn: 230910
2015-03-01 21:36:40 +00:00
Daniel Jasper bea1ab46d9 clang-format: Always align */& in multi-var DeclStmts.
Seems like the most consistent thing to do and in multi-var DeclStmts,
it is especially important to point out that the */& bind to the
identifier.

llvm-svn: 230903
2015-03-01 18:55:26 +00:00
Daniel Jasper 308062bd0d clang-format: Make trailing commas in array inits force one per line.
Before:
  NSArray *array = @[ @"a", @"a", ];

After:
  NSArray *array = @[
    @"a",
    @"a",
  ];

llvm-svn: 230741
2015-02-27 08:41:05 +00:00
Daniel Jasper b812e323fa clang-format: Make braced list formatting more consistent.
Before:
  Aaaa aaaaaaaaaaa{
      {
       a, // +1 indent weird.
       b, // trailing comma signals one per line.
      },  // trailing comma signals one per line.
  };

After:
  Aaaa aaaaaaaaaaa{
      {
          a, // better!?
          b, // trailing comma signals one per line.
      },     // trailing comma signals one per line.
  };

Interesting that this apparently was entirely untested :-(.

llvm-svn: 230627
2015-02-26 11:46:29 +00:00
Daniel Jasper beaa322c36 clang-format: Fix space of arrays of pointers to templated types.
Before:
  vector<int>(*foo_)[6];

After:
  vector<int> (*foo_)[6];

llvm-svn: 230625
2015-02-26 11:30:50 +00:00
Daniel Jasper a42de763ac clang-format: Allow breaking after "else if(" as a last resort.
This isn't generally nice, but better than violating the column limit.

llvm-svn: 230620
2015-02-26 09:49:08 +00:00
Daniel Jasper 1c22048834 clang-format: Fix spacing for function with ref-qualification ..
.. when using SpacesInCStyleCastParentheses != SpacesInParentheses.

Before:
  FormatStyle Spaces = getLLVMStyle();
  Deleted &operator=(const Deleted &)& = default;

  Spaces.SpacesInParentheses = true;
  Deleted(const Deleted &)& = default;

  Spaces.SpacesInCStyleCastParentheses = true;
  Spaces.SpacesInParentheses= false;
  Deleted( const Deleted & )& = default;

After:
  FormatStyle Spaces = getLLVMStyle();
  Deleted &operator=(const Deleted &)& = default;;

  Spaces.SpacesInParentheses= true;
  Deleted( const Deleted & )& = default;

  Spaces.SpacesInCStyleCastParentheses = true;
  Spaces.SpacesInParentheses= false;
  Deleted(const Deleted &)& = default;

Patch by Jean-Philippe Dufraigne. Thank you!

llvm-svn: 230473
2015-02-25 10:30:06 +00:00
Adrian Prantl cbc368c5b5 Revert "Wrap clang module files in a Mach-O, ELF, or COFF container."
llvm-svn: 230454
2015-02-25 02:44:04 +00:00
Adrian Prantl 8bf7af3de8 Wrap clang module files in a Mach-O, ELF, or COFF container.
This is a necessary prerequisite for debugging with modules.
The .pcm files become containers that hold the serialized AST which allows
us to store debug information in the module file that can be shared by all
object files that were built importing the module.

This reapplies r230044 with a fixed configure+make build and updated
dependencies and testcase requirements. Over the last iteration this
version adds
- missing target requirements for testcases that specify an x86 triple,
- a missing clangCodeGen.a dependency to libClang.a in the make build.

rdar://problem/19104245

llvm-svn: 230423
2015-02-25 01:31:45 +00:00
Jacques Pienaar 411b251cea clang-format: Change location of stashed token
Commit of patch in http://reviews.llvm.org/D7871

llvm-svn: 230395
2015-02-24 23:23:24 +00:00
Adrian Prantl a39924a1f8 Revert "Wrap clang module files in a Mach-O, ELF, or COFF container."
This reverts commit r230305.
Off to fix another round of missing dependencies on various platforms.

llvm-svn: 230309
2015-02-24 05:14:17 +00:00
Adrian Prantl fc360dc30b Wrap clang module files in a Mach-O, ELF, or COFF container.
This is a necessary prerequisite for debugging with modules.
The .pcm files become containers that hold the serialized AST which allows
us to store debug information in the module file that can be shared by all
object files that were built importing the module.

rdar://problem/19104245

This reapplies r230044 with a fixed configure+make build and updated
dependencies. Take 3.

llvm-svn: 230305
2015-02-24 04:25:59 +00:00
Adrian Prantl 67fbfa3773 Revert "Wrap clang module files in a Mach-O, ELF, or COFF container."
This reverts commit 230099.

The Linux configure+make build variant still needs some work.

llvm-svn: 230103
2015-02-21 00:29:14 +00:00
Adrian Prantl f2b0cd91eb Wrap clang module files in a Mach-O, ELF, or COFF container.
This is a necessary prerequisite for debugging with modules.
The .pcm files become containers that hold the serialized AST which allows
us to store debug information in the module file that can be shared by all
object files that were built importing the module.

rdar://problem/19104245

This reapplies r230044 with a fixed configure+make build and updated
dependencies. Take 2.

llvm-svn: 230089
2015-02-20 23:34:26 +00:00
Adrian Prantl 690b2f7746 Revert "Wrap clang module files in a Mach-O, ELF, or COFF container."
This reverts commit r230067.

Investigating another batch of problems found by the bots.

llvm-svn: 230073
2015-02-20 22:12:19 +00:00
Adrian Prantl b59bc1a528 Wrap clang module files in a Mach-O, ELF, or COFF container.
This is a necessary prerequisite for debugging with modules.
The .pcm files become containers that hold the serialized AST which allows
us to store debug information in the module file that can be shared by all
object files that were built importing the module.

rdar://problem/19104245

This reapplies r230044 with a fixed configure+make build and updated
dependencies.

llvm-svn: 230067
2015-02-20 21:53:12 +00:00
Jacques Pienaar 68a7dbf86d Fix merging of << at end of input.
Commit of review http://reviews.llvm.org/D7766

llvm-svn: 230061
2015-02-20 21:09:01 +00:00
Daniel Jasper a0ef4f36c8 clang-format: [js] Support template strings.
Merge template strings (marked by backticks ``).
Do not format any contents of template strings.

Patch by Martin Probst. Thank you.

llvm-svn: 230011
2015-02-20 13:47:38 +00:00
Daniel Jasper fca735cd58 clang-format: [js] Support ES6 module exports.
Patch by Martin Probst, thank you!

llvm-svn: 229865
2015-02-19 16:14:18 +00:00
Daniel Jasper 354aa51587 clang-format: [js] Support ES6 module imports.
Patch by Martin Probst.

llvm-svn: 229863
2015-02-19 16:07:32 +00:00
Daniel Jasper 6fa9ec7885 clang-format: [js] Do not fall through for JS structural elements.
Patch by Martin Probst. Thank you.

llvm-svn: 229862
2015-02-19 16:03:16 +00:00
Jacques Pienaar fc27511223 clang-format: Space and triple angle braces.
Committing patch http://reviews.llvm.org/D6800.

llvm-svn: 229783
2015-02-18 23:48:37 +00:00
Daniel Jasper 3c42dba2dc clang-format: [JS] support AtScript style annotations for JS.
Based on Java annotation support and style.

Patch by Martin Probst.

llvm-svn: 229703
2015-02-18 17:17:15 +00:00
Daniel Jasper 8370908667 clang-format: [JS] Support classes.
This adds support for JavaScript class definitions (again following
TypeScript & AtScript style). This only required support for
visibility modifiers in JS, everything else was already working.

Patch by Martin Probst, thank you.

llvm-svn: 229701
2015-02-18 17:14:05 +00:00
Daniel Jasper b10bdff337 clang-format: [JS] Support type annotations.
This patch adds support for type annotations that follow TypeScript's,
Flow's, and AtScript's syntax style.

Patch by Martin Probst, thank you.
Review: http://reviews.llvm.org/D7721

llvm-svn: 229700
2015-02-18 17:09:53 +00:00
Daniel Jasper 699631298e clang-format: Don't force a break after "endl" if everything fits on one line.
llvm-svn: 229486
2015-02-17 10:05:15 +00:00
Daniel Jasper d97d5d5cf7 clang-format: Fix crasher.
llvm-svn: 229485
2015-02-17 09:58:03 +00:00
Aaron Ballman 61005bc5de Reverting a switch from LLVM_DELETED_FUNCTION to = delete; this test should not have changed.
llvm-svn: 229394
2015-02-16 14:14:01 +00:00
Aaron Ballman abc1892057 Removing LLVM_DELETED_FUNCTION, as MSVC 2012 was the last reason for requiring the macro. NFC; Clang edition.
llvm-svn: 229339
2015-02-15 22:54:08 +00:00
Samuel Benzaquen ef621f43ff Add translationUnitDecl matcher.
Summary: Add translationUnitDecl matcher.

Reviewers: alexfh

Subscribers: klimek, cfe-commits

Differential Revision: http://reviews.llvm.org/D7512

llvm-svn: 228694
2015-02-10 14:46:45 +00:00
Daniel Jasper 29d39d54e7 clang-format: Correctly mark preprocessor lines in child blocks.
This prevents contracting:
  auto lambda = []() {
    int a = 2
  #if A
            + 2
  #endif
        ;
  };

into:
  auto lambda = []() { int a = 2
  #if A + 2
  #endif ; };

Which is obviously BAD.

This fixes llvm.org/PR22496.

llvm-svn: 228522
2015-02-08 09:34:49 +00:00
Nico Weber 33381f5e0b clang-format: Format Objective-C try blocks like all the other try blocks.
Before:

  @try {
    // ...
  }
  @finally {
    // ...
  }

Now:

  @try {
    // ...
  } @finally {
    // ...
  }

This is consistent with how we format C++ try blocks and SEH try blocks.
clang-format not doing this before was an implementation oversight.

This is dependent on BraceBreakingStyle.  The snippet above is with the
Attach style.  Style Stroustrip for example still results in the "Before:"
snippet, which makes sense since other blocks (try, else) break after '}' too.

llvm-svn: 228483
2015-02-07 01:57:32 +00:00
Daniel Jasper 30029c6b58 clang-format: Fix assert triggering on carriage returns.
llvm-svn: 228288
2015-02-05 11:05:31 +00:00
Nico Weber fac2371be3 clang-format: Add support for SEH __try / __except / __finally blocks.
This lets clang-format format

    __try {
    } __except(0) {
    }

and

    __try {
    } __finally {
    }

correctly. __try and __finally are keywords if `LangOpts.MicrosoftExt` is set,
so this turns this on.  This also enables a few other keywords, but it
shouldn't overly perturb regular clang-format operation.  __except is a
context-sensitive keyword, so `AdditionalKeywords` needs to be passed around to
a few more places.

Fixes PR22321.

llvm-svn: 228148
2015-02-04 15:26:27 +00:00
Daniel Jasper 774e6b55b3 Rewrite r228138 to be somewhat saner.
While probably technically correct, the solution r228138 was quite hard
to read/understand. This should be simpler.

Also added a test to ensure that we are still visiting the syntactic form
as well.

llvm-svn: 228144
2015-02-04 14:29:47 +00:00
Daniel Jasper 1d8ecbdffc Let RecursiveASTVisitor walk both syntactic and semantic form of InitListExprs.
Otherwise, this can lead to unexpected results when AST matching as
some nodes are only present in the semantic form.

For example, only looking at the syntactic form does not find the
DeclRefExpr to f() in:

  struct S { S(void (*a)()); };
  void f();
  S s[1] = {&f};

llvm-svn: 228138
2015-02-04 13:11:42 +00:00
Daniel Jasper d142381cd8 Add some overloads so that floating point literals can be AST matched properly.
I am not entirely sure whether the implemented sematics are ideal. In
particular, should floatLiteral(equals(0.5)) match "0.5f" and should
floatLiteral(equals(0.5f)) match "0.5". With the overloads in this
patch, the answer to both questions is yes, but I am happy to change
that.

llvm-svn: 227956
2015-02-03 09:45:52 +00:00
Daniel Jasper 05ce1eed0a Revert "Add some overloads so that floating point literals can be AST matched properly."
Apparently the build bots get angry for some reason. Can't reproduce
that in a local cmake/ninja build. Will look closer. Rolling back for
now.

llvm-svn: 227895
2015-02-02 23:35:39 +00:00
Daniel Jasper 88de3d7284 Add some overloads so that floating point literals can be AST matched properly.
I am not entirely sure whether the implemented sematics are ideal. In
particular, should floatLiteral(equals(0.5)) match "0.5f" and should
floatLiteral(equals(0.5f)) match "0.5". With the overloads in this
patch, the answer to both questions is yes, but I am happy to change
that.

llvm-svn: 227892
2015-02-02 23:04:00 +00:00
Daniel Jasper 47b35aeaa1 clang-format: Fix crasher caused by not properly setting dry-run.
llvm-svn: 227427
2015-01-29 10:47:14 +00:00
Daniel Jasper d1c13736e0 clang-format: Fix another crasher caused by incomplete macro code.
We did't properly mark all of an AnnotatedLine's children as finalized
and thus would reformat the same tokens in different branches of #if/#else
sequences leading to invalid replacements.

llvm-svn: 226930
2015-01-23 19:37:25 +00:00
Daniel Jasper 7509216a41 clang-format: Fix incorrect classification of "*".
Before:
  *a = b *c;

After:
  *a = b * c;

llvm-svn: 226923
2015-01-23 19:04:49 +00:00
Daniel Jasper e4b48c635c clang-format: Fix crasher when splitting incomplete escape sequences.
llvm-svn: 226698
2015-01-21 19:50:35 +00:00
Daniel Jasper 04b979dd81 clang-format: Fix crasher caused by incorrect resetting of token info.
llvm-svn: 226685
2015-01-21 18:35:47 +00:00
Daniel Jasper d1debfc2bb clang-format: Fix bad memory access.
llvm-svn: 226680
2015-01-21 18:04:02 +00:00
Daniel Jasper fd725c060b clang-format: Fix use-heap-after-free bug.
Discovered by the awesome test case and ASAN.

llvm-svn: 226678
2015-01-21 17:35:29 +00:00
Daniel Jasper 6fd5d646cc clang-format: Fix AlwaysBreakBeforeMultilineStrings with ColumnLimit=0
Before:
  const char *x =
      "hello llvm";

After:
  const char *x = "hello llvm";

This fixes llvm.org/PR22245.
Patch by Bill Meltsner, thank you!

llvm-svn: 226564
2015-01-20 12:59:20 +00:00