Commit Graph

1680 Commits

Author SHA1 Message Date
Martin Probst ec3dc98802 clang-format: [JS] Fix build breakage.
Checking Line.MustBeDeclaration does actually break the field and param initializer use case.

llvm-svn: 273694
2016-06-24 17:45:13 +00:00
Martin Probst 31d6da7c0c clang-format: [JS] handle conditionals in fields, default params.
Summary:

Reviewers: djasper

Subscribers: klimek, cfe-commits

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

llvm-svn: 273619
2016-06-23 21:51:49 +00:00
Martin Probst 1b7f98042d clang-format: [JS] recognize more type locations.
Summary: Includes parenthesized type expressions and type aliases.

Reviewers: djasper

Subscribers: klimek, cfe-commits

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

llvm-svn: 273603
2016-06-23 19:52:32 +00:00
Daniel Jasper 7f3b99fca7 clang-format: [Proto] Use more compact format for text-formatted options
Before:
  enum Type {
    UNKNOWN = 0 [(some_options) = {
      a: aa,
      b: bb
    }];
  };

After:
  enum Type {
    UNKNOWN = 0 [(some_options) = {a: aa, b: bb}];
  };

llvm-svn: 273553
2016-06-23 09:40:19 +00:00
Martin Probst dce8e4173b clang-format: [JS] Do not break before 'as'.
Summary:
'as' is a pseudo operator, so automatic semicolon insertion kicks in and the
code fails to part.

Reviewers: djasper

Subscribers: klimek

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

llvm-svn: 273422
2016-06-22 14:35:14 +00:00
Daniel Jasper f8bcc2445d clang-format: [JS] Add a Closure Compiler JSDoc tags to the default
Google configuration so that it isn't line-wrapped.

llvm-svn: 273285
2016-06-21 17:00:20 +00:00
Daniel Jasper 8b61d14d7e clang-format: [Proto] Fix "import public" after r273179.
llvm-svn: 273196
2016-06-20 20:39:53 +00:00
Daniel Jasper 3d5a7d6b65 clang-format: [Proto] Don't do bad things if imports are missing ;.
llvm-svn: 273179
2016-06-20 18:20:38 +00:00
Eric Liu 3753f912bf [clang-format] do not add existing includes.
Summary: do not add existing includes.

Reviewers: djasper

Subscribers: klimek, cfe-commits

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

llvm-svn: 272669
2016-06-14 14:09:21 +00:00
Daniel Jasper 887a399418 clang-format: [JS] Fix failing format with TypeScript casts.
Before, this could be formatted at all (with BracketAlignmentStyle
AlwaysBreak):

  foo = <Bar[]>[
    1, /* */
    2
  ];

llvm-svn: 272668
2016-06-14 13:54:38 +00:00
Daniel Jasper 6465008e0e clang-format: [JS] Support annotated classes.
llvm-svn: 272654
2016-06-14 11:28:02 +00:00
Martin Probst fb2342d274 clang-format: [JS] Initialize new configuration value.
llvm-svn: 272569
2016-06-13 17:50:10 +00:00
Martin Probst ece8c0c65f clang-format: [JS] Indent namespaces in JavaScript/TS by default.
Summary: There's no convention of avoiding the nested indentation.

Reviewers: djasper

Subscribers: klimek, alexeagle, cfe-commits

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

llvm-svn: 272559
2016-06-13 16:41:28 +00:00
Martin Probst 0cd74ee875 clang-format: [JS] Introduce JavaScriptWrapImports option.
Summary:
When turned on, clang-format wraps JavaScript imports (and importing exports),
instead of forcing the entire import statement onto one line.

Reviewers: djasper

Subscribers: klimek, cfe-commits

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

llvm-svn: 272558
2016-06-13 16:39:50 +00:00
Daniel Jasper 1f5d6371fd clang-format: Restrict r272537 to function ref qualifiers.
Seems this isn't generally desirable.

Before:
  int const * a;

After:
  int const* a;

llvm-svn: 272548
2016-06-13 14:45:12 +00:00
Daniel Jasper 215616691a clang-format: Fix incorrect function type detection.
Before:
  returnsFunction (&param1, &param2)(param);

After:
  returnsFunction(&param1, &param2)(param);

llvm-svn: 272538
2016-06-13 07:49:35 +00:00
Daniel Jasper 43e4d3a05b clang-format: Don't merge const and &, e.g. in function ref qualifiers.
Before (when aligning & to the right):
  SomeType MemberFunction(const Deleted &) const&;

After:
  SomeType MemberFunction(const Deleted &) const &;

This also applies to variable declarations, e.g.:
  int const * a;

However, this form is very uncommon (most people would write
"const int* a" instead) and contracting to "const*" might actually send
the wrong signal of what the const binds to.

llvm-svn: 272537
2016-06-13 07:49:28 +00:00
Daniel Jasper 594be2f037 clang-format: Fix incorrect cast detection.
Before:
  auto s = sizeof...(Ts)-1;

After:
  auto s = sizeof...(Ts) - 1;

llvm-svn: 272536
2016-06-13 07:49:09 +00:00
Daniel Jasper 87448c5548 clang-format: Don't indent lambda body relative to its return type.
Before:
  []()  //
      -> int {
        return 1;  //
      };

After:
  []()  //
      -> int {
    return 1;  //
  };

llvm-svn: 272535
2016-06-13 07:48:45 +00:00
Martin Probst 0eb40cfa6f clang-format: [JS] post-fix non-null assertion operator.
Summary:
Do not insert whitespace preceding the "!" postfix operator. This is an
incomplete fix, but should cover common usage.

Reviewers: djasper

Subscribers: cfe-commits, klimek

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

llvm-svn: 272524
2016-06-13 00:49:54 +00:00
Eric Liu 43d67b6883 [clang-format] pass Style by reference instead of value.
llvm-svn: 272465
2016-06-11 11:45:08 +00:00
Martin Probst 2ec2324f3c clang-format: [JS] recognized named functions in AnnotatingParser.
Summary: This also fixes union type formatting in function parameter types.

Before: function x(path: number| string) {}
After: function x(path: number|string) {}

Reviewers: djasper

Subscribers: klimek, cfe-commits

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

llvm-svn: 272330
2016-06-09 22:49:04 +00:00
Martin Probst 4838588343 clang-format: [JS] fix a FIXME.
llvm-svn: 272143
2016-06-08 14:05:26 +00:00
Martin Probst 6f43efbdde clang-format: [JS] fix an assertion failure caused by shrinking sources.
Summary:
The JavaScript import sorter has a corner condition that can cause the overall
source text length to shrink. This change circumvents the issue by appending
trailing space in the line after the import blocks to match at least the
previous source code length.

This needs a better long term fix, but this fixes the immediate issue.

Reviewers: alexeagle, djasper

Subscribers: klimek

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

llvm-svn: 272142
2016-06-08 14:04:04 +00:00
Daniel Jasper acadc8e0d6 clang-format: Fix incorrect calculation of "length" of /**/ comments.
This could lead to column limit violations.

llvm-svn: 272125
2016-06-08 09:45:08 +00:00
Daniel Jasper 2b4d6eae39 clang-format: Fix bug in function ref qualifier identification.
.. and simplify it.

Before:
  void A::f()&& {}
  void f() && {}

After:
  void A::f() && {}
  void f() && {}

llvm-svn: 272124
2016-06-08 08:23:46 +00:00
Eric Liu 3528832930 [clang-format] make header guard identification stricter (with Lexer).
Summary: make header guard identification stricter with Lexer.

Reviewers: djasper

Subscribers: klimek, cfe-commits

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

llvm-svn: 271883
2016-06-06 11:00:13 +00:00
Eric Liu 303baf53b1 [clang-format] skip empty lines and comments in the top of the code when inserting new headers.
Summary:
[clang-format] skip empty lines and comments in the top of the code when inserting new headers.

Pair-programmed with @hokein

Reviewers: djasper

Subscribers: ioeric, cfe-commits, hokein, klimek

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

llvm-svn: 271664
2016-06-03 12:52:59 +00:00
Martin Probst 48622090c7 clang-format: [JS] no ASI on `import {x as\n y}`.
Summary: ASI did not handle the ES6 `as` operator correctly.

Reviewers: djasper

Subscribers: klimek, cfe-commits

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

llvm-svn: 271401
2016-06-01 15:22:47 +00:00
Martin Probst 081f176a62 clang-format: [JS] Sort imported symbols.
Summary: E.g. sort `import {b, a} from 'x';` into `import {a, b} from 'x';`.

Reviewers: djasper

Subscribers: cfe-commits, klimek

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

llvm-svn: 271400
2016-06-01 15:19:53 +00:00
Benjamin Kramer 1cb7ee1300 Avoid unused variable warning in release builds.
llvm-svn: 271280
2016-05-31 14:14:42 +00:00
Eric Liu 659afd55fa [clang-format] insert new #includes into correct blocks when cleaning up Replacement with cleanupAroundReplacements().
Summary:
When a replacement's offset is set to UINT_MAX or -1U, it is treated as
a header insertion replacement by cleanupAroundReplacements(). The new #include
directive is then inserted into the correct block.

Reviewers: klimek, djasper

Subscribers: klimek, cfe-commits, bkramer

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

llvm-svn: 271276
2016-05-31 13:34:20 +00:00
Daniel Jasper e77f19c0af clang-format: Fix segfault introduced by allowing wraps after comments.
llvm-svn: 271191
2016-05-29 22:07:22 +00:00
Martin Probst 7ea9b6d783 clang-format: [JS] Support shebang lines on the very first line.
Summary:
Shebang lines (`#!/bin/blah`) can be used in JavaScript scripts to indicate
they should be run using e.g. node. This change treats # lines on the first line
as line comments.

Reviewers: djasper

Subscribers: klimek, cfe-commits

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

llvm-svn: 271185
2016-05-29 14:41:36 +00:00
Martin Probst 409697ecb9 clang-format: [JS] fix async parsing.
Summary:
Only treat the sequence `async function` as the start of a function expression,
as opposed to every occurrence of the token `async` (whoops).

Reviewers: djasper

Subscribers: klimek, cfe-commits

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

llvm-svn: 271184
2016-05-29 14:41:07 +00:00
Martin Probst 1244ecbbd2 clang-format: [JS] FormatToken.startsSequence/endsSequence.
Refactors AnnotatedLine.startsWith/endsWith by extracting the core functionality
into FormatToken.startsSequence/endsSequence. This allows checking tokens within
the pointered linked list structure with a lookahead, automatically ignoring
comments, which is useful in many places (e.g. see subsequent commit).

llvm-svn: 271183
2016-05-29 14:41:02 +00:00
Daniel Jasper 99302edd1c clang-format: Allow splitting the line after /**/-comments.
While it might change the meaning of the comment in rare circumstances,
it is better than violating the column limit.

llvm-svn: 270975
2016-05-27 08:59:34 +00:00
Martin Probst c4a0dd49a3 clang-format: [JS] sort ES6 imports.
Summary:
This change automatically sorts ES6 imports and exports into four groups:
absolute imports, parent imports, relative imports, and then exports. Exports
are sorted in the same order, but not grouped further.

To keep JS import sorting out of Format.cpp, this required extracting the
TokenAnalyzer infrastructure to separate header and implementation files.

Reviewers: djasper

Subscribers: cfe-commits, klimek

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

llvm-svn: 270203
2016-05-20 11:24:24 +00:00
Daniel Jasper 997cf2fea8 clang-format: [JS] Treat "for" as a reserved word after a ".".
Otherwise, clang-format can get confused with statements like:

  x.for = 1;

llvm-svn: 270188
2016-05-20 06:16:01 +00:00
Daniel Jasper 5dbcd3bd07 clang-format: [JS] Fix spacing in destructuring assignments.
Before:
  const[a, b, c] = [1, 2, 3];

After:
  const [a, b, c] = [1, 2, 3];

llvm-svn: 270029
2016-05-19 07:18:07 +00:00
Daniel Jasper 451544ab57 clang-format: Fix incorrect indentation in last line of macro definition
Before:
  #define MACRO(a) \
    if (a) {       \
      f();         \
    } else         \
    g()

After:
  #define MACRO(a) \
    if (a) {       \
      f();         \
    } else         \
      g()

llvm-svn: 270028
2016-05-19 06:30:48 +00:00
Daniel Jasper e2fab13313 clang-format: Fix enumerator case ranges.
Before:
  case a... b: break;

After:
  case a ... b: break;

llvm-svn: 270027
2016-05-19 06:19:17 +00:00
Eric Liu baf58c2309 [clang-format] Make formatReplacements() also sort #includes.
Summary: [clang-format] Make formatReplacements() also sort #includes.

Reviewers: bkramer, djasper

Subscribers: klimek, cfe-commits

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

llvm-svn: 269924
2016-05-18 13:43:48 +00:00
Eric Liu 2874ac3e28 [clang-format] Make FormatTokenLess::operator() const.
llvm-svn: 269889
2016-05-18 08:14:49 +00:00
Eric Liu ce5e4bc7ac Make clang-format cleaner remove redundant commas in list and redundant colon in constructor initializer.
Summary: Make clang-format cleaner remove redundant commas/colons in constructor initializer list.

Reviewers: klimek, djasper

Subscribers: cfe-commits, klimek

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

llvm-svn: 269888
2016-05-18 08:02:56 +00:00
Martin Probst cb6e042040 clang-format: [JS] simplify logic by parsing forward.
This also reduces complexity to O(n) from O(n^2) by avoiding backtracking
re-parses, and fixes length calculation.

llvm-svn: 269748
2016-05-17 06:29:33 +00:00
Martin Probst e71b4cbdd1 clang-format: [JS] fix template string width counting.
Summary:
Simply looking at the final text greatly simplifies the algorithm and also
fixes a reported issue. This requires duplicating the "actual encoding width"
logic, but that seems cleaner than the column acrobatics before.

Reviewers: djasper, bkramer

Subscribers: cfe-commits, klimek

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

llvm-svn: 269747
2016-05-17 06:29:29 +00:00
Martin Probst a166979e45 clang-format: [JS] respect clang-format off when requoting strings.
Reviewers: djasper

Subscribers: klimek, cfe-commits

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

llvm-svn: 269282
2016-05-12 11:20:32 +00:00
Nemanja Ivanovic bb1ea2d613 Enable support for __float128 in Clang and enable it on pertinent platforms
This patch corresponds to reviews:
http://reviews.llvm.org/D15120
http://reviews.llvm.org/D19125

It adds support for the __float128 keyword, literals and target feature to
enable it. Based on the latter of the two aforementioned reviews, this feature
is enabled on Linux on i386/X86 as well as SystemZ.
This is also the second attempt in commiting this feature. The first attempt
did not enable it on required platforms which caused failures when compiling
type_traits with -std=gnu++11.

If you see failures with compiling this header on your platform after this
commit, it is likely that your platform needs to have this feature enabled.

llvm-svn: 268898
2016-05-09 08:52:33 +00:00
Daniel Jasper 2b2c967c1a clang-format: Fix space after argument comments.
Before:
  f(/*a=*/a, /*b=*/ ::b);

After:
  f(/*a=*/a, /*b=*/::b);

llvm-svn: 268879
2016-05-08 18:14:01 +00:00