summaryrefslogtreecommitdiffstats
path: root/clang/lib/Format/TokenAnnotator.cpp
Commit message (Collapse)AuthorAgeFilesLines
...
* [clang-format] Add basic support for formatting C# filesPaul Hoad2019-03-211-1/+56
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Summary: This revision adds basic support for formatting C# files with clang-format, I know the barrier to entry is high here so I'm sending this revision in to test the water as to whether this might be something we'd consider landing. Tracking in Bugzilla as: https://bugs.llvm.org/show_bug.cgi?id=40850 Justification: C# code just looks ugly in comparison to the C++ code in our source tree which is clang-formatted. I've struggled with Visual Studio reformatting to get a clean and consistent style, I want to format our C# code on saving like I do now for C++ and i want it to have the same style as defined in our .clang-format file, so it consistent as it can be with C++. (Braces/Breaking/Spaces/Indent etc..) Using clang format without this patch leaves the code in a bad state, sometimes when the BreakStringLiterals is set, it fails to compile. Mostly the C# is similar to Java, except instead of JavaAnnotations I try to reuse the TT_AttributeSquare. Almost the most valuable portion is to have a new Language in order to partition the configuration for C# within a common .clang-format file, with the auto detection on the .cs extension. But there are other C# specific styles that could be added later if this is accepted. in particular how `{ set;get }` is formatted. Reviewers: djasper, klimek, krasimir, benhamilton, JonasToth Reviewed By: klimek Subscribers: llvm-commits, mgorny, jdoerfert, cfe-commits Tags: #clang, #clang-tools-extra Differential Revision: https://reviews.llvm.org/D58404 llvm-svn: 356662
* [clang-format] BeforeHash added to IndentPPDirectivesPaul Hoad2019-03-201-6/+9
| | | | | | | | | | | | | | | | | | Summary: The option BeforeHash added to IndentPPDirectives. Fixes Bug 36019. https://bugs.llvm.org/show_bug.cgi?id=36019 Reviewers: djasper, klimek, krasimir, sammccall, mprobst, Nicola, MyDeveloperDay Reviewed By: klimek, MyDeveloperDay Subscribers: kadircet, MyDeveloperDay, mnussbaum, geleji, ufna, cfe-commits Patch by to-mix. Differential Revision: https://reviews.llvm.org/D52150 llvm-svn: 356613
* [clang-format] structured binding in range for detected as Objective CPaul Hoad2019-03-201-1/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Summary: Sometime after 6.0.0 and the current trunk 9.0.0 the following code would be considered as objective C and not C++ Reported by: https://twitter.com/mattgodbolt/status/1096188576503644160 $ clang-format.exe test.h Configuration file(s) do(es) not support Objective-C: C:\clang\build\.clang-format --- test.h -- ``` std::vector<std::pair<std::string,std::string>> C; void foo() { for (auto && [A,B] : C) { std::string D = A + B; } } ``` The following code fixes this issue of incorrect detection Reviewers: djasper, klimek, JonasToth, reuk Reviewed By: klimek Subscribers: cfe-commits Tags: #clang-tools-extra Differential Revision: https://reviews.llvm.org/D59546 llvm-svn: 356575
* [clang-format] [JS] Don't break between template string and tagMartin Probst2019-03-191-0/+5
| | | | | | | | | | | | | | | | | | | Before: const x = veryLongIdentifier `hello`; After: const x = veryLongIdentifier`hello`; While it's allowed to have the template string and tag identifier separated by a line break, currently the clang-format output is not stable when a break is forced. Additionally, disallowing a line break makes it clear that the identifier is actually a tag for a template string. Patch originally by mitchellwills (thanks!). llvm-svn: 356447
* [clang-format] [NFC] clang-format the Format libraryPaul Hoad2019-03-011-13/+15
| | | | | | | | | | | Previously revisions commited non-clang-formatted changes to the Format library, this means submitting any revision e.g. {D55170} can cause additional whitespace changes to potentially be included in a revision. Commit a non functional change using latest build Windows clang-format r351376 with no other changes, to remove these differences All FormatTests pass [==========] 652 tests from 20 test cases ran. llvm-svn: 355182
* [clang-format] SpaceBeforeParens for lambda expressionsAndrew Ng2019-02-261-1/+3
| | | | | | | | | Add support for lambda expressions to the SpaceBeforeParens formatting option. Differential Revision: https://reviews.llvm.org/D58241 llvm-svn: 354880
* [Format/ObjC] Fix [foo bar]->baz formatting as lambda arrowBen Hamilton2019-02-081-0/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Summary: Currently, `UnwrappedLineParser` thinks an arrow token after an ObjC method expression is a C++ lambda arrow, so it formats: ``` [foo bar]->baz ``` as: ``` [foo bar] -> baz ``` Because `UnwrappedLineParser` runs before `TokenAnnotator`, it can't know if the arrow token is after an ObjC method expression or not. This diff makes `TokenAnnotator` remove the TT_LambdaArrow on the arrow token if it follows an ObjC method expression. Test Plan: New test added. Ran test with: % ninja FormatTests && ./tools/clang/unittests/Format/FormatTests Confirmed test failed before diff and passed after diff. Reviewers: krasimir, djasper, sammccall Reviewed By: sammccall Subscribers: cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D57923 llvm-svn: 353531
* [clang-format] Fix breaking of qualified operatorKrasimir Georgiev2019-02-041-3/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Summary: From https://bugs.llvm.org/show_bug.cgi?id=40516 ``` $ cat a.cpp const NamespaceName::VeryLongClassName &NamespaceName::VeryLongClassName::myFunction() { // do stuff } const NamespaceName::VeryLongClassName &NamespaceName::VeryLongClassName::operator++() { // do stuff } $ ~/ll/build/opt/bin/clang-format -style=LLVM a.cpp const NamespaceName::VeryLongClassName & NamespaceName::VeryLongClassName::myFunction() { // do stuff } const NamespaceName::VeryLongClassName &NamespaceName::VeryLongClassName:: operator++() { // do stuff } ``` What was happening is that the split penalty before `operator` was being set to a smaller value by a prior if block. Moved checks around to fix this and added a regression test. Reviewers: djasper Reviewed By: djasper Tags: #clang Differential Revision: https://reviews.llvm.org/D57604 llvm-svn: 353033
* [clang-format] square parens with one token are not Objective-C message sendsAlex Lorenz2019-01-241-2/+7
| | | | | | | | | | | | | | The commit r322690 introduced support for ObjC detection in header files. Unfortunately some C headers that use designated initializers are now incorrectly detected as Objective-C. This commit fixes it by ensuring that `[ token ]` is not annotated as an Objective-C message send. rdar://45504376 Differential Revision: https://reviews.llvm.org/D56226 llvm-svn: 352125
* Update the file headers across all of the LLVM projects in the monorepoChandler Carruth2019-01-191-4/+3
| | | | | | | | | | | | | | | | | to reflect the new license. We understand that people may be surprised that we're moving the header entirely to discuss the new license. We checked this carefully with the Foundation's lawyer and we believe this is the correct approach. Essentially, all code in the project is now made available by the LLVM project under our new license, so you will see that the license headers include that license only. Some of our contributors have contributed code under our old license, and accordingly, we have retained a copy of our old license notice in the top-level files in each project and repository. llvm-svn: 351636
* clang-format: [JS] support goog.requireType.Martin Probst2019-01-071-0/+1
| | | | | | | | | | | | | | Summary: It's a new primitive for importing symbols, and should be treated like the (previously handled) `goog.require` and `goog.forwardDeclare`. Reviewers: krasimir Subscribers: cfe-commits Differential Revision: https://reviews.llvm.org/D56385 llvm-svn: 350516
* [clang-format] Do not treat asm clobber [ as ObjCExpr, refinedKrasimir Georgiev2018-11-221-5/+6
| | | | | | | | | | | | | | | | | | | Summary: r346756 refined clang-format to not treat the `[` in `asm (...: [] ..)` as an ObjCExpr. However that's not enough, as we might have a comma-separated list of such clobbers as in the newly added test. This updates the detection to instead look at the Line's first token being `asm` and not mark `[`-s as ObjCExprs in this case. Reviewers: djasper, benhamilton Reviewed By: djasper, benhamilton Subscribers: benhamilton, cfe-commits Differential Revision: https://reviews.llvm.org/D54795 llvm-svn: 347465
* [clang-format] JS: don't treat is: as a type matcherKrasimir Georgiev2018-11-201-2/+15
| | | | | | | | | | | | | | | | Summary: Clang-format is treating all occurences of `is` in js as type matchers. In some cases this is wrong, as it might be a dict key. Reviewers: mprobst Reviewed By: mprobst Subscribers: cfe-commits Differential Revision: https://reviews.llvm.org/D54753 llvm-svn: 347307
* [clang-format] Do not treat the asm clobber [ as ObjCExprKrasimir Georgiev2018-11-131-2/+3
| | | | | | | | | | | | | | | | | Summary: The opening square of an inline asm clobber was being annotated as an ObjCExpr. This caused, amongst other things, the ObjCGuesser to guess header files containing that pattern as ObjC files. Reviewers: benhamilton Reviewed By: benhamilton Subscribers: cfe-commits Differential Revision: https://reviews.llvm.org/D54111 llvm-svn: 346756
* [clang-format] Support breaking consecutive string literals for TableGenJordan Rupprecht2018-11-121-0/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Summary: clang-format can get confused by string literals in TableGen: it knows that strings can be broken up, but doesn't seem to understand how that can be indented across line breaks, and arranges them in a weird triangular pattern. Take this output example from `clang-format tools/llvm-objcopy/ObjcopyOpts.td` (which has now been formatted in rL345896 with this patch applied): ``` defm keep_global_symbols : Eq< "keep-global-symbols", "Reads a list of symbols from <filename> and " "runs as if " "--keep-global-symbol=<symbol> " "is set for each one. " "<filename> " "contains one " "symbol per line " "and may contain " "comments " "beginning " "with" " '#'" ". " "Lead" "ing " ``` Reviewers: alexshap, MaskRay, djasper Reviewed By: MaskRay Subscribers: krasimir, mgorny, cfe-commits Differential Revision: https://reviews.llvm.org/D53952 llvm-svn: 346687
* Fix ClangFormat issue of recognizing ObjC subscript as C++ attributes when ↵Yan Zhang2018-11-091-1/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | message target is a result of a C-style method. Summary: The issue is that for array subscript like: ``` arr[[Foo() bar]]; ``` ClangFormat will recognize it as C++11 attribute syntax and put a space between 'arr' and first '[', like: ``` arr [[Foo() bar]]; ``` Now it is fixed. Tested with: ``` ninja FormatTests ``` Reviewers: benhamilton Reviewed By: benhamilton Subscribers: cfe-commits Differential Revision: https://reviews.llvm.org/D54288 llvm-svn: 346566
* [clang-format] tweaked another case of lambda formattingKrasimir Georgiev2018-10-311-0/+24
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Summary: This is done in order to improve cases where the lambda's body is moved too far to the right. Consider the following snippet with column limit set to 79: ``` void f() { leader::MakeThisCallHere(&leader_service_, cq_.get(), [this, liveness](const leader::ReadRecordReq& req, std::function<void()> done) { logger_->HandleReadRecord( req, resp, std::move(done)); }); leader::MakeAnother(&leader_service_, cq_.get(), [this, liveness](const leader::ReadRecordReq& req, std::function<void()> done) { logger_->HandleReadRecord( req, resp, std::move(done), a); }); } ``` The tool favors extra indentation for the lambda body and so the code incurs extra wrapping and adjacent calls are indented to a different level. I find this behavior annoying and I'd like the tool to favor new lines and, thus, use the extra width. The fix, reduced, brings the following formatting. Before: function(1, [] { DoStuff(); // }, 1); After: function( 1, [] { DoStuff(); // }, 1); Refer to the new tests in FormatTest.cpp Contributed by oleg.smolsky! Reviewers: djasper, klimek, krasimir Subscribers: cfe-commits, owenpan Tags: #clang Differential Revision: https://reviews.llvm.org/D52676 llvm-svn: 345753
* clang-format: Don't insert spaces in front of :: for Java 8 Method References.Nico Weber2018-10-051-1/+7
| | | | | | | | | | | | | The existing code kept the space if it was there for identifiers, and it didn't handle `this`. After this patch, for Java `this` is handled in addition to identifiers, and existing space is always stripped between identifier and `::`. Also accept `::` in addition to `.` in front of `<` in `foo::<T>bar` generic calls. Differential Revision: https://reviews.llvm.org/D52842 llvm-svn: 343872
* clang-format: [JS] conditional types.Martin Probst2018-09-271-0/+6
| | | | | | | | | | | | | | | | | | | | | Summary: This change adds some rudimentary support for conditional types. Specifically it avoids breaking before `extends` and `infer` keywords, which are subject to Automatic Semicolon Insertion, so breaking before them creates incorrect syntax. The actual formatting of the type expression is odd, but there is as of yet no clear idea on how to format these. See https://www.typescriptlang.org/docs/handbook/release-notes/typescript-2-8.html#conditional-types. Reviewers: krasimir Subscribers: cfe-commits Differential Revision: https://reviews.llvm.org/D52536 llvm-svn: 343179
* clang-format: [JS] space after parameter naming.Martin Probst2018-09-261-1/+3
| | | | | | | | | | | | | | | | | | | Summary: Previously: foo(/*bar=*/baz); Now: foo(/*bar=*/ baz); The run-in parameter naming comment is not intended in JS. Reviewers: mboehme Subscribers: cfe-commits Differential Revision: https://reviews.llvm.org/D52535 llvm-svn: 343080
* [clang-format/ObjC] Improve split priorities for ObjC methodsJacek Olesiak2018-07-091-2/+16
| | | | | | | | | | Reduce penalty for aligning ObjC method arguments using the colon alignment as this is the canonical way. Trying to fit a whole expression into one line should not force other line breaks (e.g. when ObjC method expression is a part of other expression). llvm-svn: 336520
* [clang-format/ObjC] Fix counting selector name parts for ObjCJacek Olesiak2018-07-091-11/+19
| | | | | | | | | | | | | | | | Summary: Counts selector parts also for method declarations and counts correctly for methods without arguments. This is an internal change and doesn't influence formatting on its own (at the current state). Its lack would be visible after applying D48719. Reviewers: benhamilton, klimek Reviewed By: benhamilton Subscribers: acoomans, cfe-commits Differential Revision: https://reviews.llvm.org/D48716 llvm-svn: 336518
* [clang-format/ObjC] Fix NS_SWIFT_NAME(foo(bar:baz:)) after ObjC method declBen Hamilton2018-06-291-1/+7
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Summary: In D44638, I partially fixed `NS_SWIFT_NAME(foo(bar:baz:))`-style annotations on C functions, but didn't add a test for Objective-C method declarations. For ObjC method declarations which are annotated with `NS_SWIFT_NAME(...)`, we currently fail to annotate the final component of the selector name as `TT_SelectorName`. Because the token type is left unknown, clang-format will happily cause a compilation error when it changes the following: ``` @interface Foo - (void)doStuffWithFoo:(id)name bar:(id)bar baz:(id)baz NS_SWIFT_NAME(doStuff(withFoo:bar:baz:)); @end ``` to: ``` @interface Foo - (void)doStuffWithFoo:(id)name bar:(id)bar baz:(id)baz NS_SWIFT_NAME(doStuff(withFoo:bar:baz :)); @end ``` (note the linebreak before the final `:`). The logic which decides whether or not to annotate the token before a `:` with `TT_SelectorName` is pretty fragile, and has to handle some pretty odd cases like pair-parameters: ``` [I drawRectOn:surface ofSize:aa:bbb atOrigin:cc:dd]; ``` So, to minimize the effect of this change, I decided to only annotate unknown identifiers before a `:` as `TT_SelectorName` for Objective-C declaration lines. Test Plan: New tests included. Confirmed tests failed before change and passed after change. Ran tests with: % make -j16 FormatTests && ./tools/clang/unittests/Format/FormatTests Reviewers: djasper, krasimir, jolesiak Reviewed By: krasimir Subscribers: cfe-commits Differential Revision: https://reviews.llvm.org/D48679 llvm-svn: 335983
* [clang-format] Keep @message together in text protosKrasimir Georgiev2018-06-251-2/+19
| | | | | | | | | | | | Summary: In C++ code snippets of the form `@field` are common. This makes clang-format keep them together in text protos, whereas before it would break them. Subscribers: cfe-commits Differential Revision: https://reviews.llvm.org/D48543 llvm-svn: 335459
* [clang-format] Add SpaceBeforeCpp11BracedList option.Hans Wennborg2018-06-141-0/+3
| | | | | | | | | | | | | | | | | | | | WebKit C++ style for object initialization is as follows: Foo foo { bar }; Yet using clang-format -style=webkit changes this to: Foo foo{ bar }; As there is no existing combination of rules that will ensure a space before a braced list in this fashion, this patch adds a new SpaceBeforeCpp11BracedList rule. Patch by Ross Kirsling! Differential Revision: https://reviews.llvm.org/D46024 llvm-svn: 334692
* [clang-format] Discourage breaks in submessage entries, hard ruleKrasimir Georgiev2018-06-121-4/+33
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Summary: Currently clang-format allows this for text protos: ``` submessage: { key: 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa' } ``` when it is under the column limit and when putting it all on one line exceeds the column limit. This is not a very intuitive formatting, so I'd prefer having ``` submessage: { key: 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa' } ``` instead, even if it takes one line more. This patch prevents clang-format from inserting a break between `: {` and similar cases. Reviewers: djasper, sammccall Reviewed By: sammccall Subscribers: cfe-commits Differential Revision: https://reviews.llvm.org/D48063 llvm-svn: 334517
* clang-format: [JS] strict prop init annotation.Martin Probst2018-06-111-1/+4
| | | | | | | | | | | | | | | | | | | | | | Summary: TypeScript uses the `!` token for strict property initialization assertions, as in: class X { strictPropAsserted!: string; } Previously, clang-format would wrap between the `!` and the `:` for overly long lines. This patch fixes that by generally preventing the wrap in that location. Reviewers: krasimir Subscribers: cfe-commits Differential Revision: https://reviews.llvm.org/D48030 llvm-svn: 334415
* clang-format: Introduce BreakInheritanceList optionFrancois Ferrand2018-06-111-4/+9
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Summary: This option replaces the BreakBeforeInheritanceComma option with an enum, thus introducing a mode where the colon stays on the same line as constructor declaration: // When it fits on line: class A : public B, public C { ... }; // When it does not fit: class A : public B, public C { ... }; This matches the behavior of the `BreakConstructorInitializers` option, introduced in https://reviews.llvm.org/D32479. Reviewers: djasper, klimek Reviewed By: djasper Subscribers: mzeren-vmw, cfe-commits Differential Revision: https://reviews.llvm.org/D43015 llvm-svn: 334408
* [clang-format] text protos: put entries on separate lines if there is a ↵Krasimir Georgiev2018-06-111-0/+68
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | submessage Summary: This patch updates clang-format text protos to put entries of a submessage into separate lines if the submessage contains at least two entries and contains at least one submessage entry. For example, the entries here are kept on separate lines even if putting them on a single line would be under the column limit: ``` message: { entry: 1 submessage: { key: value } } ``` Messages containing a single submessage or several scalar entries can still be put on one line if they fit: ``` message { submessage { key: value } } message { x: 1 y: 2 z: 3 } ``` Reviewers: sammccall Reviewed By: sammccall Subscribers: klimek, cfe-commits Differential Revision: https://reviews.llvm.org/D46757 llvm-svn: 334401
* clang-format: [JS] do not wrap before any `is`.Martin Probst2018-05-221-1/+1
| | | | | | | | | | | | | | | | | | | | Summary: `is` type annotations can occur at any nesting level. For example: function x() { return function y(): a is B { ... }; } Breaking before the `is` above breaks TypeScript parsing the code. This change prevents the wrap. Reviewers: krasimir Subscribers: klimek, cfe-commits Differential Revision: https://reviews.llvm.org/D47193 llvm-svn: 332968
* [clang-format/ObjC] Correctly annotate single-component ObjC method invocationsBen Hamilton2018-05-181-0/+6
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Summary: Previously, clang-format's parser would fail to annotate the selector in a single-component Objective-C method invocation with `TT_SelectorName`. For example, the following: [foo bar]; would parse `bar` as `TT_Unknown`: M=0 C=1 T=Unknown S=0 B=0 BK=0 P=140 Name=identifier L=34 PPK=2 FakeLParens= FakeRParens=0 II=0x559d5db51770 Text='bar' This caused us to fail to insert a space after a closing cast rparen, so the following: [((Foo *)foo) bar]; would format as: [((Foo *)foo)bar]; This diff fixes the issue by ensuring we annotate the selector in a single-component Objective-C method invocation as `TT_SelectorName`. Test Plan: New tests added. Ran tests with: % make -j16 FormatTests && ./tools/clang/unittests/Format/FormatTests Reviewers: djasper, jolesiak Reviewed By: jolesiak Subscribers: Wizard, klimek, hokein, cfe-commits Differential Revision: https://reviews.llvm.org/D47028 llvm-svn: 332727
* clang-format: Allow optimizer to break template declaration.Francois Ferrand2018-05-161-1/+3
| | | | | | | | | | | | | | | | | | | Summary: Introduce `PenaltyBreakTemplateDeclaration` to control the penalty, and change `AlwaysBreakTemplateDeclarations` to an enum with 3 modes: * `No` for regular, penalty based, wrapping of template declaration * `MultiLine` for always wrapping before multi-line declarations (e.g. same as legacy behavior when `AlwaysBreakTemplateDeclarations=false`) * `Yes` for always wrapping (e.g. same as legacy behavior when `AlwaysBreakTemplateDeclarations=true`) Reviewers: krasimir, djasper, klimek Subscribers: cfe-commits Differential Revision: https://reviews.llvm.org/D42684 llvm-svn: 332436
* clang-format: tweak formatting of variable initialization blocksFrancois Ferrand2018-05-161-0/+5
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Summary: This patch changes the behavior of PenaltyBreakBeforeFirstCallParameter so that is does not apply after a brace, when Cpp11BracedListStyle is false. This way, variable initialization is wrapped more like an initializer than like a function call, which is more consistent with user expectations for this braced list style. With PenaltyBreakBeforeFirstCallParameter=200, this gives the following code: (with Cpp11BracedListStyle=false) Before : const std::unordered_map<std::string, int> Something::MyHashTable = { { "aaaaaaaaaaaaaaaaaaaaa", 0 }, { "bbbbbbbbbbbbbbbbbbbbb", 1 }, { "ccccccccccccccccccccc", 2 } }; After : const std::unordered_set<std::string> Something::MyUnorderedSet = { { "aaaaaaaaaaaaaaaaaaaaa", 0 }, { "bbbbbbbbbbbbbbbbbbbbb", 1 }, { "ccccccccccccccccccccc", 2 } }; Reviewers: krasimir, djasper, klimek Subscribers: cfe-commits Differential Revision: https://reviews.llvm.org/D43290 llvm-svn: 332434
* [clang] Update uses of DEBUG macro to LLVM_DEBUG.Nicola Zaghen2018-05-151-1/+1
| | | | | | | | | | | | | The DEBUG() macro is very generic so it might clash with other projects. The renaming was done as follows: - git grep -l 'DEBUG' | xargs sed -i 's/\bDEBUG\s\?(/LLVM_DEBUG(/g' - git diff -U0 master | ../clang/tools/clang-format/clang-format-diff.py -i -p1 -style LLVM Explicitly avoided changing the strings in the clang-format tests. Differential Revision: https://reviews.llvm.org/D44975 llvm-svn: 332350
* Remove \brief commands from doxygen comments.Adrian Prantl2018-05-091-13/+13
| | | | | | | | | | | | | | | | | | | This is similar to the LLVM change https://reviews.llvm.org/D46290. We've been running doxygen with the autobrief option for a couple of years now. This makes the \brief markers into our comments redundant. Since they are a visual distraction and we don't want to encourage more \brief markers in new code either, this patch removes them all. Patch produced by for i in $(git grep -l '\@brief'); do perl -pi -e 's/\@brief //g' $i & done for i in $(git grep -l '\\brief'); do perl -pi -e 's/\\brief //g' $i & done Differential Revision: https://reviews.llvm.org/D46320 llvm-svn: 331834
* [clang-format/ObjC] Use getIdentifierInfo() instead of tok::identifierBen Hamilton2018-04-271-4/+21
| | | | | | | | | | | | | | | | | | | | | | | | Summary: Previously, we checked tokens for `tok::identifier` to see if they were identifiers inside an Objective-C selector. However, this missed C++ keywords like `new` and `delete`. To fix this, this diff uses `getIdentifierInfo()` to find identifiers or keywords inside Objective-C selectors. Test Plan: New tests added. Ran tests with: % make -j16 FormatTests && ./tools/clang/unittests/Format/FormatTests Reviewers: djasper, jolesiak Reviewed By: djasper Subscribers: klimek, cfe-commits Differential Revision: https://reviews.llvm.org/D46143 llvm-svn: 331067
* Revert "[clang-format] Improve Incomplete detection for (text) protos"Krasimir Georgiev2018-04-231-18/+5
| | | | | | | | This reverts commit r330016. The incomplete detection has too many false positives, picking up typos for hard failures and refusing to format anything in that case. llvm-svn: 330569
* [clang-format] Improve Incomplete detection for (text) protosKrasimir Georgiev2018-04-131-5/+18
| | | | | | | | | | | | | | | | | | Summary: This patch improves detection of incomplete code for protos and text protos. This is especially important for text protos in raw string literals, since they might be partial strings concatenated, and we'd like to disable formatting in these cases. Reviewers: sammccall Reviewed By: sammccall Subscribers: klimek, cfe-commits Differential Revision: https://reviews.llvm.org/D44203 llvm-svn: 330016
* [clang-format] Do not break after ObjC category open parenBen Hamilton2018-04-121-0/+7
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Summary: Previously, `clang-format` would break Objective-C category extensions after the opening parenthesis to avoid breaking the protocol list: ``` % echo "@interface ccccccccccccc (ccccccccccc) <ccccccccccccc> { }" | \ clang-format -assume-filename=foo.h -style="{BasedOnStyle: llvm, \ ColumnLimit: 40}" @interface ccccccccccccc ( ccccccccccc) <ccccccccccccc> { } ``` This looks fairly odd, as we could have kept the category extension on the previous line. Category extensions are a single item, so they are generally very short compared to protocol lists. We should prefer breaking after the opening `<` of the protocol list over breaking after the opening `(` of the category extension. With this diff, we now avoid breaking after the category extension's open paren, which causes us to break after the protocol list's open angle bracket: ``` % echo "@interface ccccccccccccc (ccccccccccc) <ccccccccccccc> { }" | \ ./bin/clang-format -assume-filename=foo.h -style="{BasedOnStyle: llvm, \ ColumnLimit: 40}" @interface ccccccccccccc (ccccccccccc) < ccccccccccccc> { } ``` Test Plan: New test added. Confirmed test failed before diff and passed after diff by running: % make -j16 FormatTests && ./tools/clang/unittests/Format/FormatTests Reviewers: djasper, jolesiak Reviewed By: djasper Subscribers: klimek, cfe-commits Differential Revision: https://reviews.llvm.org/D45526 llvm-svn: 329919
* [clang-format] Don't insert space between ObjC class and lightweight genericBen Hamilton2018-04-121-3/+6
| | | | | | | | | | | | | | | | | | | | | | | | | Summary: In D45185, I added clang-format parser support for Objective-C generics. However, I didn't touch the whitespace logic, so they got the same space logic as Objective-C protocol lists. In every example in the Apple SDK and in the documentation, there is no space between the class name and the opening `<` for the lightweight generic specification, so this diff removes the space and updates the tests. Test Plan: Tests updated. Ran tests with: % make -j16 FormatTests && ./tools/clang/unittests/Format/FormatTests Reviewers: djasper, jolesiak Reviewed By: djasper Subscribers: klimek, cfe-commits Differential Revision: https://reviews.llvm.org/D45498 llvm-svn: 329917
* [clang-format] Ensure ObjC selectors with 0 args are annotated correctlyBen Hamilton2018-04-051-0/+14
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Summary: Previously, clang-format would incorrectly annotate 0-argument Objective-C selector names as TT_TrailingAnnotation: ``` % echo "-(void)foo;" > /tmp/test.m % ./bin/clang-format -debug /tmp/test.m Language: Objective-C ---- Line(0, FSC=0): minus[T=68, OC=0] l_paren[T=68, OC=1] void[T=68, OC=2] r_paren[T=68, OC=6] identifier[T=68, OC=7] semi[T=68, OC=10] Line(0, FSC=0): eof[T=68, OC=0] Run 0... AnnotatedTokens(L=0): M=0 C=0 T=ObjCMethodSpecifier S=1 B=0 BK=0 P=0 Name=minus L=1 PPK=2 FakeLParens= FakeRParens=0 Text='-' M=0 C=1 T=Unknown S=1 B=0 BK=0 P=33 Name=l_paren L=3 PPK=2 FakeLParens= FakeRParens=0 Text='(' M=0 C=1 T=Unknown S=0 B=0 BK=0 P=140 Name=void L=7 PPK=2 FakeLParens= FakeRParens=0 Text='void' M=0 C=0 T=CastRParen S=0 B=0 BK=0 P=43 Name=r_paren L=8 PPK=2 FakeLParens= FakeRParens=0 Text=')' M=0 C=1 T=TrailingAnnotation S=0 B=0 BK=0 P=120 Name=identifier L=11 PPK=2 FakeLParens= FakeRParens=0 Text='foo' M=0 C=0 T=Unknown S=0 B=0 BK=0 P=23 Name=semi L=12 PPK=2 FakeLParens= FakeRParens=0 Text=';' ``` This caused us to incorrectly indent 0-argument wrapped selectors when Style.IndentWrappedFunctionNames was false, as we thought the 0-argument ObjC selector name was actually a trailing annotation (which is always indented). This diff fixes the issue and adds tests. Test Plan: New tests added. Confirmed tests failed before diff. After diff, tests passed. Ran tests with: % make -j12 FormatTests && ./tools/clang/unittests/Format/FormatTests Reviewers: djasper, jolesiak Reviewed By: djasper, jolesiak Subscribers: klimek, cfe-commits Differential Revision: https://reviews.llvm.org/D44996 llvm-svn: 329297
* [clang-format] Preserve spaces before a percent in (text) protosKrasimir Georgiev2018-04-051-0/+4
| | | | | | | This makes sure that we do not change the meaning of pieces of text with format specifiers. llvm-svn: 329263
* [clang-format/ObjC] Do not detect "[]" as ObjC method expressionBen Hamilton2018-04-031-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Summary: The following C++ code was being detected by `guessLanguage()` as Objective-C: #define FOO(...) auto bar = [] __VA_ARGS__; This was because `[] __VA_ARGS__` is not currently detected as a C++ lambda expression (it has no parens or braces), so `TokenAnnotator::parseSquare()` incorrectly treats the opening square as an ObjC method expression. We have two options to fix this: 1. Parse `[] __VA_ARGS__` explicitly as a C++ lambda 2. Make it so `[]` is never parsed as an Objective-C method expression This diff implements option 2, which causes the `[` to be parsed as `TT_ArraySubscriptLSquare` instead of `TT_ObjCMethodExpr`. Note that when I fixed this, it caused one change in formatting behavior, where the following was implicitly relying on the `[` being parsed as `TT_ObjCMethodExpr`: A<int * []> a; becomes: A<int *[]> a; with `Style.PointerAlignment = Middle`. I don't really know what the desired format is for this syntax; the test was added by Janusz Sobczak and integrated by @djasper in https://github.com/llvm-mirror/clang/commit/b511fe9818829d7ece0cc0b2ce1fbe04a1f0739a . I went ahead and changed the test for now. Test Plan: New tests added. Ran tests with: % make -j12 FormatTests && ./tools/clang/unittests/Format/FormatTests Fixes: https://bugs.llvm.org/show_bug.cgi?id=36248 Reviewers: djasper, jolesiak Reviewed By: djasper Subscribers: klimek, cfe-commits, djasper Differential Revision: https://reviews.llvm.org/D45169 llvm-svn: 329070
* [clang-format/ObjC] Do not insert space after opening brace of ObjC dict literalBen Hamilton2018-04-031-0/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | Summary: D44816 attempted to fix a few cases where `clang-format` incorrectly inserted a space before the closing brace of an Objective-C dictionary literal. This revealed there were still a few cases where we inserted a space after the opening brace of an Objective-C dictionary literal. This fixes the formatting to be consistent and adds more tests. Test Plan: New tests added. Confirmed tests failed before diff and passed after diff. Ran tests with: % make -j12 FormatTests && ./tools/clang/unittests/Format/FormatTests Reviewers: djasper, jolesiak, krasimir Reviewed By: djasper Subscribers: klimek, cfe-commits Differential Revision: https://reviews.llvm.org/D45168 llvm-svn: 329069
* [clang-format] Do not insert space before closing brace in ObjC dict literalBen Hamilton2018-03-271-0/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Summary: Previously, `clang-format` would sometimes insert a space before the closing brace in an Objective-C dictionary literal. Unlike array literals (which obey `Style.SpacesInContainerLiterals` to add a space after `[` and before `]`), Objective-C dictionary literals currently are not meant to insert a space after `{` and before `}`, regardless of `Style.SpacesInContainerLiterals`. However, some constructs like `@{foo : @(bar)}` caused `clang-format` to insert a space between `)` and `}`. This fixes the issue and adds tests. (I understand the behavior is not consistent between array literals and dictionary literals, but that's existing behavior that's a much larger change.) Test Plan: New tests added. Ran tests with: % make -j12 FormatTests && ./tools/clang/unittests/Format/FormatTests Reviewers: djasper, jolesiak, Wizard Reviewed By: djasper Subscribers: klimek, cfe-commits Differential Revision: https://reviews.llvm.org/D44816 llvm-svn: 328627
* clang-format: Narrow down raw string literal line break exception.Daniel Jasper2018-03-221-4/+4
| | | | | | | | | | | | For multiline raw string literals, we generally want to respect the author's choice of linebreak before the 'R"(' as the rest of the raw string might be aligned to it and we cannot (commonly) modify the content. For single-line raw string literals, this doesn't make any sense and so we should just treat them as regular string literals in this regard. llvm-svn: 328201
* clang-format: Fix SpacesInParentheses with fully qualified names.Daniel Jasper2018-03-221-1/+2
| | | | | | | | | | | When SpacesInParentheses is set to true clang-format does not add a space before fully qualified names. For example: do_something(::globalVar ); Fix by Darby Payne. Thank you! llvm-svn: 328200
* [clang-format] Don't insert space between r_paren and 'new' in ObjC declBen Hamilton2018-03-221-2/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | | | Summary: Previously, clang-format would insert a space between the closing parenthesis and 'new' in the following valid Objective-C declaration: + (instancetype)new; This was because 'new' is treated as a keyword, not an identifier. TokenAnnotator::spaceRequiredBefore() already handled the case where r_paren came before an identifier, so this diff extends it to handle r_paren before 'new'. Test Plan: New tests added. Ran tests with: % make -j12 FormatTests && ./tools/clang/unittests/Format/FormatTests Reviewers: djasper, jolesiak, stephanemoore Reviewed By: djasper, jolesiak, stephanemoore Subscribers: stephanemoore, klimek, cfe-commits Differential Revision: https://reviews.llvm.org/D44692 llvm-svn: 328174
* [clang-format] Fix ObjC selectors with multiple params passed to macroBen Hamilton2018-03-201-1/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Summary: Objective-C selectors with arguments take the form of: foo: foo:bar: foo:bar:baz: These can be passed to a macro, like NS_SWIFT_NAME(): https://developer.apple.com/library/content/documentation/Swift/Conceptual/BuildingCocoaApps/MixandMatch.html and must never have spaces inserted around the colons. Previously, there was logic in TokenAnnotator's tok::colon parser to handle the single-argument case, but it failed for the multiple-argument cases. This diff fixes the bug and adds more tests. Test Plan: New tests added. Ran tests with: % make -j12 FormatTests && ./tools/clang/unittests/Format/FormatTests Reviewers: jolesiak, djasper, Wizard Reviewed By: jolesiak, Wizard Subscribers: klimek, cfe-commits Differential Revision: https://reviews.llvm.org/D44638 llvm-svn: 327986
* [clang-format] Disallow breaks before ']' in text proto extensionsKrasimir Georgiev2018-03-161-0/+3
| | | | | | | | | | Summary: This disallows patterns like `[ext.name\n]` in text protos. Subscribers: klimek, cfe-commits Differential Revision: https://reviews.llvm.org/D44569 llvm-svn: 327716
OpenPOWER on IntegriCloud