Commit Graph

36 Commits

Author SHA1 Message Date
Krasimir Georgiev 47f21ef2af [clang-format] Add space between a message field key and the opening bracket in proto messages
Summary:
This patch updates the formatting of message fields of type `a{...}` to `a {...}`
for proto messages.

Reviewers: djasper

Reviewed By: djasper

Subscribers: klimek, cfe-commits

Differential Revision: https://reviews.llvm.org/D35015

llvm-svn: 307261
2017-07-06 13:58:29 +00:00
Krasimir Georgiev feeba61006 [clang-format] Fix parsing of msg{field}-style proto options
Summary:
This patch makes the `{` in `msg_field{field: OK}` in a proto option scope be
treated as an assignment operator. Previosly the added test case was formatted
as:
```
option (MyProto.options) = {
  field_a: OK
  field_b{field_c: OK} field_d: OKOKOK field_e: OK
}
```

Reviewers: djasper

Reviewed By: djasper

Subscribers: klimek, cfe-commits

Differential Revision: https://reviews.llvm.org/D34749

llvm-svn: 306672
2017-06-29 13:30:41 +00:00
Krasimir Georgiev ff747be4d5 [clang-format] Support <>-style proto message fields
Summary:
This patch adds support for <>-style proto message fields inside proto options.
Previously these were wrongly treated as binary operators and as such were
working only by chance for a limited number of cases.

Reviewers: djasper

Reviewed By: djasper

Subscribers: cfe-commits, klimek

Differential Revision: https://reviews.llvm.org/D34621

llvm-svn: 306406
2017-06-27 13:43:07 +00:00
Krasimir Georgiev 9451e67158 [clang-format] Add a test for associative map proto buffer fields
Summary:
The test suite was missing a test about associative maps:
https://developers.google.com/protocol-buffers/docs/proto3#maps

Reviewers: djasper

Reviewed By: djasper

Subscribers: cfe-commits, klimek

Differential Revision: https://reviews.llvm.org/D34623

llvm-svn: 306386
2017-06-27 10:06:40 +00:00
Daniel Jasper c79e4d2d25 clang-format: Make it very slighly more expensive to wrap between "= {".
This prevents unwanted fallout from r296664. Specifically in proto formatting,
this changed:
  optional Aaaaaaaa aaaaaaaa = 12 [
    (aaa) = aaaa,
    (bbbbbbbbbbbbbbbbbbbbbbbbbb) = {
      aaaaaaaaaaaaaaaaa: true,
      aaaaaaaaaaaaaaaa: true
    }
  ];

Into:
  optional Aaaaaaaa aaaaaaaa = 12 [
    (aaa) = aaaa,
    (bbbbbbbbbbbbbbbbbbbbbbbbbb) =
        {aaaaaaaaaaaaaaaaa: true, aaaaaaaaaaaaaaaa: true}
  ];

Which is considered less readable. Generally, it seems preferable to
format such dict literals as blocks rather than contract them to one
line.

llvm-svn: 297696
2017-03-14 00:40:32 +00:00
Daniel Jasper da910e0a8b clang-format: [Proto] Also supports implicit string literal concatenation
llvm-svn: 293995
2017-02-03 08:29:02 +00:00
Eric Liu 4f8d99433d Make tooling::applyAllReplacements return llvm::Expected<string> instead of empty string to indicate potential error.
Summary:
return llvm::Expected<> to carry error status and error information.
This is the first step towards introducing "Error" into tooling::Replacements.

Reviewers: djasper, klimek

Subscribers: ioeric, klimek, cfe-commits

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

llvm-svn: 275062
2016-07-11 13:53:12 +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
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
Daniel Jasper ffbad0e8aa clang-format: [Proto] Basic support for options with <> for repeated fields.
llvm-svn: 256737
2016-01-04 07:28:12 +00:00
Daniel Jasper ccff4d1e60 clang-format: [Proto] Improve wrapping of message field attributes.
Before:
  optional AAA aaa = 1 [foo =
			    {
			      key: "a"  //
			    },
			bar = {
			  key: "a"  //
			}];

After:
  optional AAA aaa = 1 [
    foo = {
      key: "a"  //
    },
    bar = {
      key: "a"  //
    }
  ];

llvm-svn: 256736
2016-01-04 07:27:33 +00:00
Daniel Jasper d8d9839ae6 clang-format: [Proto] Support extending message.
Before:
  extend.foo.Bar {
  }

After:
  extend .foo.Bar {
  }

llvm-svn: 253667
2015-11-20 14:32:54 +00:00
Daniel Jasper c6dd273a98 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
    }];
  };

llvm-svn: 242404
2015-07-16 14:25:43 +00:00
Daniel Jasper 23d3bcfe5b clang-format: [Proto] Don't treat "operator" as keyword.
Before:
  optional string operator= 1;

After:
  optional string operator = 1;

llvm-svn: 240624
2015-06-25 08:38:46 +00:00
Alexander Kornienko ab9db51042 Revert r240270 ("Fixed/added namespace ending comments using clang-tidy").
llvm-svn: 240353
2015-06-22 23:07:51 +00:00
Alexander Kornienko 3d9d929e42 Fixed/added namespace ending comments using clang-tidy. NFC
The patch is generated using this command:

  $ tools/extra/clang-tidy/tool/run-clang-tidy.py -fix \
      -checks=-*,llvm-namespace-comment -header-filter='llvm/.*|clang/.*' \
      work/llvm/tools/clang

To reduce churn, not touching namespaces spanning less than 10 lines.

llvm-svn: 240270
2015-06-22 09:47:44 +00:00
Daniel Jasper 1b998815a0 clang-format: [Proto] Don't linewrap top-level options.
They are very similar to import statements.

llvm-svn: 235582
2015-04-23 09:54:10 +00:00
Daniel Jasper 1662bfe077 clang-format: [Proto] No alternate operator names.
llvm-svn: 234055
2015-04-03 21:15:46 +00:00
Daniel Jasper ce2fdb0a0a clang-format: [Proto] Change formatting text-formatted options.
Before:
  optional Type type = 1 [(mutate_options) = {vital : true
                                              abc : false}];

After:
  optional Type type = 1 [(mutate_options) = {
    vital : true
    abc : false
  }];

llvm-svn: 220679
2014-10-27 13:25:59 +00:00
Daniel Jasper 497d9fdcf8 clang-format: [proto] Understand text-format nesting without :
Before:
  option (MyProto.options) = {
    field_c : "OK" msg_field{field_d : 123}
  };

After:
  option (MyProto.options) = {
    field_c : "OK"
    msg_field{field_d : 123}
  };

(Note that the colon after "msg_field" is optional).

llvm-svn: 215692
2014-08-15 05:00:35 +00:00
Daniel Jasper a382cbe4eb clang-format: [proto] Improve formatting of text-proto options.
Initial patch and tests by Kaushik Sridharan, thank you!

llvm-svn: 214084
2014-07-28 14:08:09 +00:00
Daniel Jasper 9c2820c4e3 clang-format: [proto] Add required space before absolute references.
llvm-svn: 211488
2014-06-23 07:36:25 +00:00
Nikola Smiljanic e08a91ecd2 Enable alternative tokens by default for clang-format.
Patch by Bobby Moretti.

llvm-svn: 208269
2014-05-08 00:05:13 +00:00
Daniel Jasper 883ae9d9a3 clang-format: Don't bin-pack text-proto-formatted options.
Before:
  repeated double value = 1
      [(aaaaaaa.aaaaaaaaa) = {aaaaaaaaaaaaaaaa: AAAAAAAAAA,
                              bbbbbbb: BBBB, bbbb: BBB}];

After:
  repeated double value = 1
      [(aaaaaaa.aaaaaaaaa) = {aaaaaaaaaaaaaaaa: AAAAAAAAAA,
                              bbbbbbb: BBBB,
                              bbbb: BBB}];

llvm-svn: 207538
2014-04-29 15:54:14 +00:00
Chandler Carruth 1034666777 [Modules] Fix potential ODR violations by sinking the DEBUG_TYPE
definition below all of the header #include lines, clang edition.

If you want more details about this, you can see some of the commits to
Debug.h in LLVM recently. This is just the clang section of a cleanup
I've done for all uses of DEBUG_TYPE in LLVM.

llvm-svn: 206849
2014-04-22 03:17:02 +00:00
Daniel Jasper 783bac6bba clang-format: Understand proto text format without commas.
Also removed spaces before colons as they don't seem to be used
frequently.

Before:
optional int32 b = 2
    [(foo_options) = {aaaaaaaaaaaaaaaaaaa : 123 bbbbbbbbbbbbbbbbbbbbbbbb :
                          "baz"}];

After:
optional int32 b = 2 [(foo_options) = {aaaaaaaaaaaaaaaaaaa: 123,
                                       bbbbbbbbbbbbbbbbbbbbbbbb:"baz"}];

llvm-svn: 206269
2014-04-15 09:54:30 +00:00
Daniel Jasper 9d3adc06c6 x
llvm-svn: 206268
2014-04-15 09:54:24 +00:00
Daniel Jasper 220c0d1f5e clang-format: Fix false positive in braced list detection in protos.
llvm-svn: 205954
2014-04-10 07:27:12 +00:00
Nico Weber 514ecc8ce8 clang-format: Let chromium style inherit google style's javascript tweaks.
llvm-svn: 200652
2014-02-02 20:50:45 +00:00
Daniel Jasper f24301d79c clang-format: More custom option fixes for protocol buffer files.
Before:
  repeated double value = 1 [(aaaaaaa.aaaaaaaaa) = {
                               aaaaaaaaaaaaaaaa : AAAAAAAAAA,
                               bbbbbbbbbbbbbbbb : BBBBBBBBBB
                             }];

After:
  repeated double value = 1
      [(aaaaaaa.aaaaaaaaa) = {aaaaaaaaaaaaaaaa : AAAAAAAAAA,
                              bbbbbbbbbbbbbbbb : BBBBBBBBBB}];

llvm-svn: 200406
2014-01-29 18:52:43 +00:00
Daniel Jasper 6e58feef76 clang-format: Fix formatting of custom proto options.
Before:
  repeated double value = 1 [(aaaaaaa.aaaaaaaaa) = {
                              aaaaaaaaaaaaaaaaa : AAAAAAAA
                            }];

After:
  repeated double value = 1
      [(aaaaaaa.aaaaaaaaa) = {aaaaaaaaaaaaaaaaa : AAAAAAAA}];

llvm-svn: 200405
2014-01-29 18:43:40 +00:00
Daniel Jasper a0e9be2bb2 clang-format: Fix option formatting in protocol buffer files.
Before:
  optional int32 foo[ default = true, deprecated = true ];

After:
  optional int32 foo[default = true, deprecated = true];

llvm-svn: 200327
2014-01-28 18:51:11 +00:00
Daniel Jasper 215d6c8c50 clang-format: Treat "." in protos like namespace separators.
Before:
  optional really.really.long.and.qualified.type.aaaaaaa
      .aaaaaaaa another_fiiiiiiiiiiiiiiiiiiiiield = 2;

After:
  optional
     really.really.long.and.qualified.type.aaaaaaa.aaaaaaaa
          another_fiiiiiiiiiiiiiiiiiiiiield = 2;

llvm-svn: 199796
2014-01-22 08:04:52 +00:00
Daniel Jasper 929b1db276 clang-format: Properly format custom options in protocol buffer definitions.
Before:
  option(my_option) = "abc";

After:
  option (my_option) = "abc";

llvm-svn: 199672
2014-01-20 16:47:22 +00:00
Daniel Jasper 7052ce6d8b clang-format: Better support and testing for protocol buffers.
With this patch, there is dedicated testing for protocol buffers
(https://developers.google.com/protocol-buffers/).

Also some minor tweaks formatting tweaks.

llvm-svn: 199580
2014-01-19 09:04:08 +00:00