Commit Graph

272 Commits

Author SHA1 Message Date
Daniel Jasper 92aeba790d clang-format: [JS/TypeScript] Support "enum" as an optional property name, too.
Before:
  enum?: string
  [];

After:
  enum?: string[];

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@259628 91177308-0d34-0410-b5e6-96231b3b80d8
2016-02-03 05:33:44 +00:00
Daniel Jasper 318abdbd28 clang-format: [JS] Support exporting abstract classes.
Before:
  export abstract class X {y: number;}
(and all sorts of other havoc in more complicated cases).

After:
  export abstract class X { y: number; }

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@257451 91177308-0d34-0410-b5e6-96231b3b80d8
2016-01-12 06:24:38 +00:00
Daniel Jasper 8e1a7611bc clang-format: [JS] Teach clang-format about "export interface".
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@257406 91177308-0d34-0410-b5e6-96231b3b80d8
2016-01-11 22:57:40 +00:00
Daniel Jasper 7d075491f3 clang-format: [JS] Support semicolons in TypeScript's TypeMemberLists.
Before:
  var x: {
    a: string;
    b: number;
  }
  = {};

After:
  var x: {a: string; b: number;} = {};

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@257255 91177308-0d34-0410-b5e6-96231b3b80d8
2016-01-09 15:56:28 +00:00
Daniel Jasper 34ce5c0ddb clang-format: [JS] Support more ES6 classes.
Before:
  foo = class {
      constructor() {}
  }
  ;

After:
  foo = class {
      constructor() {}
  };

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@257154 91177308-0d34-0410-b5e6-96231b3b80d8
2016-01-08 07:06:07 +00:00
Daniel Jasper 41575498a0 clang-format: [JS] Support more ES6 imports.
Before:
  import a, {X, Y}
  from 'some/module.js';

After:
  import a, {X, Y} from 'some/module.js';

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@257038 91177308-0d34-0410-b5e6-96231b3b80d8
2016-01-07 08:53:35 +00:00
Daniel Jasper bd20864678 clang-format: [JS/TypeScript] Support "enum" as property name.
Before:
  enum: string
  [];

After:
  enum: string[];

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@256546 91177308-0d34-0410-b5e6-96231b3b80d8
2015-12-29 08:54:23 +00:00
Daniel Jasper 794a77e319 clang-format: [TableGen] Support ;-less include lines.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@256412 91177308-0d34-0410-b5e6-96231b3b80d8
2015-12-25 08:53:31 +00:00
Daniel Jasper 43581a0db4 clang-format: [JS] Support arrays of object-type literals.
Before:
  interface I {
    o: {}
    [];
  }

After:
  interface I {
    o: {}[];
  }

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@256247 91177308-0d34-0410-b5e6-96231b3b80d8
2015-12-22 15:48:35 +00:00
Daniel Jasper b8cc716acd clang-format: Properly set the BlockKind for more blocks.
Before:
  void f() { struct Dummy { };
    f();
  }

After:
  void f() {
    struct Dummy {};
    f();
  }

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@256175 91177308-0d34-0410-b5e6-96231b3b80d8
2015-12-21 18:31:15 +00:00
Daniel Jasper b65b352ab0 clang-format: treat Q_SIGNALS as an access modifier
Patch by Alexander Richardson, thank you!

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@254407 91177308-0d34-0410-b5e6-96231b3b80d8
2015-12-01 12:05:04 +00:00
Saleem Abdulrasool bec01a5ecd Format: support inline namespaces
Correct handling for C++17 inline namespaces.  We would previously fail to
identify the inline namespaces as a namespace name since multiple ones may be
concatenated now with C++17.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@251690 91177308-0d34-0410-b5e6-96231b3b80d8
2015-10-30 05:07:56 +00:00
Angel Garcia Gomez d162035b9b Roll-back r250822.
Summary: It breaks the build for the ASTMatchers

Subscribers: klimek, cfe-commits

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

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@250827 91177308-0d34-0410-b5e6-96231b3b80d8
2015-10-20 13:23:58 +00:00
Angel Garcia Gomez e83bf34da9 Apply modernize-use-default to clang.
Summary: Replace empty bodies of default constructors and destructors with '= default'.

Reviewers: bkramer, klimek

Subscribers: klimek, alexfh, cfe-commits

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

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@250822 91177308-0d34-0410-b5e6-96231b3b80d8
2015-10-20 12:52:55 +00:00
Daniel Jasper 0e6b5702af clang-format: Fix false ObjC block detection.
Before:
  inline A operator^(const A &lhs, const A &rhs) {} int i;

After:
  inline A operator^(const A &lhs, const A &rhs) {}
  int i;

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@249517 91177308-0d34-0410-b5e6-96231b3b80d8
2015-10-07 03:43:10 +00:00
Daniel Jasper 6cc91d4e13 clang-format: Add a new brace style "custom" as well as flags to
control the individual braces. The existing choices for brace wrapping
are now merely presets for the different flags that get expanded upon
calling the reformat function.

All presets have been chose to keep the existing formatting, so there
shouldn't be any difference in formatting behavior.

Also change the dump_format_style.py to properly document the nested
structs that are used to keep these flags discoverable among all the
configuration flags.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@248802 91177308-0d34-0410-b5e6-96231b3b80d8
2015-09-29 14:57:55 +00:00
Daniel Jasper 52ed5ec631 clang-format: [JS] Support pseudo-keywords
JavaScript allows keywords to appear in IdenfierName positions, e.g.
fields, or object literal members, but not as plain identifiers.

Patch by Martin Probst. Thank you!

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@248714 91177308-0d34-0410-b5e6-96231b3b80d8
2015-09-28 14:29:45 +00:00
Daniel Jasper 048a64a775 clang-format: [JS] handle let (ES6)
Patch by Martin Probst. Thank you!

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@248713 91177308-0d34-0410-b5e6-96231b3b80d8
2015-09-28 14:28:08 +00:00
Daniel Jasper a3933711ef clang-format: Properly handle braced lists in macros.
Before:
  #define A    \
      { a, a } \
      ,

After:
  #define A {a, a},

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@245837 91177308-0d34-0410-b5e6-96231b3b80d8
2015-08-24 13:23:37 +00:00
Daniel Jasper 3306f568e9 clang-format: Fix incorrect lambda-detection.
Before:
  [ a, a ]() -> a<1>{};

After:
  [a, a]() -> a<1> {};

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@244890 91177308-0d34-0410-b5e6-96231b3b80d8
2015-08-13 13:37:08 +00:00
Daniel Jasper d04e4b6afa clang-format: [Proto] Handle enum bodies differently.
In proto, enum constants can contain complex options and should be
handled more like individual declarations.

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

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

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@242404 91177308-0d34-0410-b5e6-96231b3b80d8
2015-07-16 14:25:43 +00:00
Birunthan Mohanathas fac72109a1 clang-format: Add Mozilla brace breaking style
Differential Revision: http://reviews.llvm.org/D10883


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@241986 91177308-0d34-0410-b5e6-96231b3b80d8
2015-07-12 03:13:54 +00:00
Daniel Jasper 904365edb1 clang-format: [JS] Properly reset parse state after parsing interface.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@241446 91177308-0d34-0410-b5e6-96231b3b80d8
2015-07-06 14:26:04 +00:00
Birunthan Mohanathas 0af047c817 clang-format: Add MacroBlock{Begin,End} options
The MacroBlockBegin and MacroBlockEnd options make matching macro identifiers
behave like '{' and '}', respectively, in terms of indentation.

Mozilla code, for example, uses several macros that begin and end a scope.
Previously, Clang-Format removed the indentation resulting in:

    MACRO_BEGIN(...)
    MACRO_ENTRY(...)
    MACRO_ENTRY(...)
    MACRO_END

Now, using the options

    MacroBlockBegin: "^[A-Z_]+_BEGIN$"
    MacroBlockEnd: "^[A-Z_]+_END$"

will yield the expected result:

    MACRO_BEGIN(...)
      MACRO_ENTRY(...)
      MACRO_ENTRY(...)
    MACRO_END

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


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@241363 91177308-0d34-0410-b5e6-96231b3b80d8
2015-07-03 17:25:16 +00:00
Daniel Jasper 8378e8520c clang-format: Properly parse parenthesis in braced lists.
Among other things, this makes clang-format understand arbitrary blocks
embedded in them, such as:

  SomeFunction({MACRO({ return output; }), b});

where MACRO could e.g. expand to a lambda.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@241059 91177308-0d34-0410-b5e6-96231b3b80d8
2015-06-30 11:32:22 +00:00
Nico Weber 33b0503c15 clang-format: Support @autoreleasepool.
Format @autoreleasepool properly for the Attach brace style
by recognizing @autoreleasepool as a block introducer.

Patch from Strager Neds!
http://reviews.llvm.org/D10372


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@240896 91177308-0d34-0410-b5e6-96231b3b80d8
2015-06-28 01:06:16 +00:00
Daniel Jasper f68ad12985 clang-format: Better fix to detect elaborated enum return types.
The previous one (r240021) regressed:
  enum E Type::f() { .. }

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@240127 91177308-0d34-0410-b5e6-96231b3b80d8
2015-06-19 08:17:32 +00:00
Daniel Jasper da9b856426 clang-format: Better support functions with elaborated enum return types.
Before, this wasn't formatted properly:
  enum ::C f() {
    return a;
  }

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@240021 91177308-0d34-0410-b5e6-96231b3b80d8
2015-06-18 15:45:17 +00:00
Daniel Jasper f8d4459793 clang-format: clang-format (NFC)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@239903 91177308-0d34-0410-b5e6-96231b3b80d8
2015-06-17 13:08:06 +00:00
Daniel Jasper ee4c1b5fd6 clang-format: [JS] Fix typescript enum formatting.
Patch by Martin Probst.

Before:
  enum {
    A,
    B
  } var x = 1;

After:
  enum {
    A,
    B
  }
  var x = 1;

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@239893 91177308-0d34-0410-b5e6-96231b3b80d8
2015-06-17 09:44:02 +00:00
Daniel Jasper e7869a575c clang-format: [JS] Support "export enum" declarations.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@239595 91177308-0d34-0410-b5e6-96231b3b80d8
2015-06-12 05:08:18 +00:00
Daniel Jasper 7fd025f21c clang-format: [JS] Fix regression caused by r239592.
Without it, it would do:

  interface I {
    x: string;
  } var y;

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@239593 91177308-0d34-0410-b5e6-96231b3b80d8
2015-06-12 04:56:34 +00:00
Daniel Jasper 6281b76cbd clang-format: [JS] fix incorrectly collapsed lines after export
statement.

When an exported function would follow a class declaration, it would not
be recognized as a stand-alone function. That would then collapse the
following line with the current one, e.g.

  class C {}
  export function f() {} var x;

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@239592 91177308-0d34-0410-b5e6-96231b3b80d8
2015-06-12 04:52:02 +00:00
Daniel Jasper ecbdb36dba clang-format: More eagerly wrap trailing return types.
Before:
  template <typename T>
  auto aaaaaaaaaaaaaaaaaaaaaa(T t) -> decltype(eaaaaaaaaaaaaaaa<T>(t.a)
                                                   .aaaaaaaa());

After:
  template <typename T>
  auto aaaaaaaaaaaaaaaaaaaaaa(T t)
      -> decltype(eaaaaaaaaaaaaaaa<T>(t.a).aaaaaaaa());

Also add a test case for a difficult template parsing case I stumbled accross.
Needs fixing.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@239149 91177308-0d34-0410-b5e6-96231b3b80d8
2015-06-05 13:18:09 +00:00
Daniel Jasper 7a6350f291 clang-format: Don't try to detect C++ lambdas in other languages.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@238845 91177308-0d34-0410-b5e6-96231b3b80d8
2015-06-02 15:31:37 +00:00
Benjamin Kramer 3982210b8d [Format] Move UnwrappedLines instead of copying.
No functional change intended.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@238673 91177308-0d34-0410-b5e6-96231b3b80d8
2015-05-31 11:18:05 +00:00
Daniel Jasper 01b2e8ebea clang-format: NFC. Cleanup after r237895.
Specifically adhere to LLVM Coding Standards (no 'else' after
return/break/continue) and remove yet another implementation of
paren counting. We already have enough of those in the
UnwrappedLineParser.

No functional changes intended.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@238672 91177308-0d34-0410-b5e6-96231b3b80d8
2015-05-31 08:51:54 +00:00
Manuel Klimek 384ba28ba1 clang-format: [JS] Better support for fat arrows.
Assigns a token type (TT_JsFatArrow) to => tokens, and uses that to
more easily recognize and format fat arrow functions.
Improves function parsing to better recognize formal parameter
lists and return type declarations.
Recognizes arrow functions and parse function bodies as child blocks.

Patch by Martin Probst.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@237895 91177308-0d34-0410-b5e6-96231b3b80d8
2015-05-21 12:23:34 +00:00
Daniel Jasper 6219f10c6f clang-format: Fix another regression caused by r237565.
Before:
  class C : test {
    class D : test{void f(){int i{2};
  }
  }
  ;
  }
  ;

After:
  class C : test {
    class D : test {
      void f() { int i{2}; }
    };
  };

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@237569 91177308-0d34-0410-b5e6-96231b3b80d8
2015-05-18 14:49:19 +00:00
Daniel Jasper 513f0c09b4 clang-format: Fix regression introduced by r237565.
Before:
  class C : public D {
    SomeClass SC { 2 };
  };

After:
  class C : public D {
    SomeClass SC{2};
  };

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@237568 91177308-0d34-0410-b5e6-96231b3b80d8
2015-05-18 14:12:24 +00:00
Daniel Jasper b0cbc5dca1 clang-format: Allow braced initializers in template arguments of class
specializations.

Before:
  template <class T>
      struct S < std::is_arithmetic<T> {
  } > {};

After:
  template <class T> struct S<std::is_arithmetic<T>{}> {};

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@237565 91177308-0d34-0410-b5e6-96231b3b80d8
2015-05-18 12:52:00 +00:00
Daniel Jasper 9d1d803853 clang-format: Fix semicolon less macro-detection.
It was fooled by the comment.

Before:
  SOME_UNRELATED_MACRO
      /*static*/ int i;

After:
  SOME_UNRELATED_MACRO
  /*static*/ int i;

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@237246 91177308-0d34-0410-b5e6-96231b3b80d8
2015-05-13 11:35:53 +00:00
Daniel Jasper d775e36456 clang-format: Don't merge subsequent lines into _asm blocks.
Before:
  _asm {
  } int i;

After:
  _asm {
  }
  int i;

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@236985 91177308-0d34-0410-b5e6-96231b3b80d8
2015-05-11 11:59:46 +00:00
Daniel Jasper 1de7d7cdcd clang-format: [JS] Clean up export declaration parsing.
NFC intended.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@236982 91177308-0d34-0410-b5e6-96231b3b80d8
2015-05-11 09:14:50 +00:00
Daniel Jasper 32c2216dee clang-format: [JS] Parse exported functions as free-standing.
Before:
  export function foo() {} export function bar() {}

After:
  export function foo() {
  }
  export function bar() {
  }

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@236978 91177308-0d34-0410-b5e6-96231b3b80d8
2015-05-11 09:03:10 +00:00
Daniel Jasper 9b03bacc4a clang-format: Preserve line break before } in __asm { ... }.
Some compilers ignore everything after a semicolon in such inline asm
blocks and thus, the closing brace must not be moved to the previous
line.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@236946 91177308-0d34-0410-b5e6-96231b3b80d8
2015-05-10 08:42:04 +00:00
Daniel Jasper 4ec9a3892c clang-format: Merge labels and subsequent semicolons.
E.g.:

  default:;

This can be used to get around restrictions as to what can follow a
label. It fixes llvm.org/PR19648.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@236604 91177308-0d34-0410-b5e6-96231b3b80d8
2015-05-06 15:19:47 +00:00
Daniel Jasper 1fc06ca35a clang-format: Accept slightly more record declarations.
This fixes llvm.org/PR23397.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@236599 91177308-0d34-0410-b5e6-96231b3b80d8
2015-05-06 14:03:02 +00:00
Manuel Klimek 13e7452f30 Remove all computation of structural errors in clang-format's line parser.
We were already ignoring those already.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@236591 91177308-0d34-0410-b5e6-96231b3b80d8
2015-05-06 11:56:29 +00:00
Daniel Jasper 61201a7ae8 clang-format: [JS] support optional methods.
Optional methods use ? tokens like this:

  interface X { y?(): z; }

It seems easiest to detect and disambiguate these from ternary
expressions by checking if the code is in a declaration context. Turns
out that that didn't quite work properly for interfaces in Java and JS,
and for JS file root contexts.

Patch by Martin Probst, thank you.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@236488 91177308-0d34-0410-b5e6-96231b3b80d8
2015-05-05 08:40:32 +00:00