summaryrefslogtreecommitdiffstats
path: root/clang/lib/Format
Commit message (Collapse)AuthorAgeFilesLines
* [clang-format] fix PR38557 - comments between "default" and ':' causes the ↵Jonas Toth2018-08-241-1/+4
| | | | | | | | | | | | | | | | | | | case label to be treated as an identifier Summary: The Bug was reported and fixed by Owen Pan. See the original bug report here: https://bugs.llvm.org/show_bug.cgi?id=38557 Patch by Owen Pan! Reviewers: krasimir, djasper, klimek Reviewed By: klimek Subscribers: JonasToth, cfe-commits Differential Revision: https://reviews.llvm.org/D50697 llvm-svn: 340624
* [clang-format] fix PR38525 - Extraneous continuation indent spaces with ↵Jonas Toth2018-08-241-1/+2
| | | | | | | | | | | | | | | | | | BreakBeforeBinaryOperators set to All Summary: See bug report https://bugs.llvm.org/show_bug.cgi?id=38525 for more details. Reviewers: djasper, klimek, krasimir, sammccall Reviewed By: sammccall Subscribers: hiraditya, JonasToth, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D50699 llvm-svn: 340623
* clang-format: Change Google style wrt. the formatting of empty messages.Daniel Jasper2018-08-151-1/+1
| | | | | | | | | | | Before: message Empty { } After: message Empty {} llvm-svn: 339803
* [clang-format] comment reflow: add last line's penalty when ending brokenKrasimir Georgiev2018-08-071-1/+8
| | | | | | | | | | | | | | | | | | Summary: This fixes a bug in clang-format where the last line's penalty is not taken into account when its ending is broken. Usually the last line's penalty is handled by addNextStateToQueue, but in cases where the trailing `*/` is put on a newline, the contents of the last line have to be considered for penalizing. Reviewers: mprobst Reviewed By: mprobst Subscribers: cfe-commits Differential Revision: https://reviews.llvm.org/D50378 llvm-svn: 339123
* clang-format: [JS] don't break comments before any '{'Martin Probst2018-08-031-12/+14
| | | | | | | | | | | | | | | | | | | | Summary: Previously, clang-format would avoid breaking before the first `{` found, but then happily break before subsequent '{'s on the line. This change fixes that by looking for the first location that has no opening curly, if any. This fixes the original commit by correcting the loop condition. This reverts commit 66dc646e09b795b943668179c33d09da71a3b6bc. Reviewers: krasimir Subscribers: cfe-commits Differential Revision: https://reviews.llvm.org/D50249 llvm-svn: 338890
* Revert "clang-format: [JS] don't break comments before any '{'"Tim Northover2018-08-031-12/+12
| | | | | | This reverts commit r338837, it introduced an infinite loop on all bots. llvm-svn: 338879
* clang-format: [JS] don't break comments before any '{'Martin Probst2018-08-031-12/+12
| | | | | | | | | | | | | | | | Summary: Previously, clang-format would avoid breaking before the first `{` found, but then happily break before subsequent '{'s on the line. This change fixes that by looking for the first location that has no opening curly, if any. Reviewers: krasimir Subscribers: cfe-commits Differential Revision: https://reviews.llvm.org/D50230 llvm-svn: 338837
* clang-format: fix a crash in comment wraps.Martin Probst2018-08-021-5/+21
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Summary: Previously, clang-format would crash if it tried to wrap an overlong single line comment, because two parts of the code inserted a break in the same location. /** heregoesalongcommentwithnospace */ This wasn't previously noticed as it could only trigger for an overlong single line comment that did have no breaking opportunities except for a whitespace at the very beginning. This also introduces a check for JavaScript to not ever wrap a comment before an opening curly brace: /** @mods {donotbreakbeforethecurly} */ This is because some machinery parsing these tags sometimes supports breaks before a possible `{`, but in some other cases does not. Previously clang-format was careful never to wrap a line with certain tags on it. The better solution is to specifically disable wrapping before the problematic token: this allows wrapping and aligning comments but still avoids the problem. Reviewers: krasimir Subscribers: cfe-commits Differential Revision: https://reviews.llvm.org/D50177 llvm-svn: 338706
* [Format] Fix for bug 35641Ilya Biryukov2018-08-011-1/+7
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Summary: Bug was caused due to comments at the start of scope. For a code like: ``` int func() { // int b; int c; } ``` the comment at the first line gets IndentAndNestingLevel (1,1) whereas the following declarations get only (0,1) which prevents them from insertion of a new scope. So, I changed the AlignTokenSequence to look at previous *non-comment* token when deciding whether to introduce a new scope into stack or not. Patch by Kadir Cetinkaya! Reviewers: rsmith, djasper Reviewed By: djasper Subscribers: lebedev.ri, cfe-commits, klimek Tags: #clang Differential Revision: https://reviews.llvm.org/D43303 llvm-svn: 338578
* [clang-format] Add some text proto functions to Google styleKrasimir Georgiev2018-08-011-0/+2
| | | | | | | | | | | | | | Summary: Adds 2 functions taking a text proto argument. Reviewers: djasper, klimek Reviewed By: djasper Subscribers: acoomans, cfe-commits Differential Revision: https://reviews.llvm.org/D50132 llvm-svn: 338524
* [clang-format] Add @private to the list of jsdoc annotationsKrasimir Georgiev2018-08-011-1/+1
| | | | | | | | | | | | Reviewers: mprobst Reviewed By: mprobst Subscribers: acoomans, cfe-commits Differential Revision: https://reviews.llvm.org/D50138 llvm-svn: 338519
* Remove trailing spaceFangrui Song2018-07-302-2/+2
| | | | | | sed -Ei 's/[[:space:]]+$//' include/**/*.{def,h,td} lib/**/*.{cpp,h} llvm-svn: 338291
* [clang-format] Silence -Wdocumentation warningsKrasimir Georgiev2018-07-301-6/+8
| | | | | | introduced in r338232 llvm-svn: 338245
* [clang-format] Indent after breaking Javadoc annotated lineKrasimir Georgiev2018-07-304-15/+96
| | | | | | | | | | | | | | | | Summary: This patch makes clang-format indent the subsequent lines created by breaking a long javadoc annotated line. Reviewers: mprobst Reviewed By: mprobst Subscribers: acoomans, cfe-commits Differential Revision: https://reviews.llvm.org/D49797 llvm-svn: 338232
* NFC: Add the emacs c++ mode hint "-*- C++ -*-" to the headers that don't have itErik Pilkington2018-07-242-2/+2
| | | | | | https://llvm.org/docs/CodingStandards.html#file-headers llvm-svn: 337780
* [clang-format/ObjC] Put ObjC method arguments into one line when they fitJacek Olesiak2018-07-091-0/+24
| | | | | | | | | | | | | | | | | | | | Reapply D47195: Currently BreakBeforeParameter is set to true everytime message receiver spans multiple lines, e.g.: ``` [[object block:^{ return 42; }] aa:42 bb:42]; ``` will be formatted: ``` [[object block:^{ return 42; }] aa:42 bb:42]; ``` even though arguments could fit into one line. This change fixes this behavior. llvm-svn: 336521
* [clang-format/ObjC] Improve split priorities for ObjC methodsJacek Olesiak2018-07-092-2/+21
| | | | | | | | | | 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] Prohibit breaking after a bracket opening ObjC method ↵Jacek Olesiak2018-07-091-0/+3
| | | | | | | | | | | | | | | | | | expression Summary: Don't break after a "[" opening an ObjC method expression. Tests are added in D48719 where formatting is improved (to avoid adding and changing tests immediately). Reviewers: benhamilton, klimek Reviewed By: benhamilton Subscribers: acoomans, cfe-commits Differential Revision: https://reviews.llvm.org/D48718 llvm-svn: 336519
* [clang-format/ObjC] Fix counting selector name parts for ObjCJacek Olesiak2018-07-092-13/+22
| | | | | | | | | | | | | | | | 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] Support additional common functions for text proto formattingKrasimir Georgiev2018-06-291-1/+4
| | | | | | | | | | | | | | Summary: This adds a few more common function names expecting a text proto argument. Reviewers: djasper Reviewed By: djasper Subscribers: cfe-commits Differential Revision: https://reviews.llvm.org/D48760 llvm-svn: 335978
* [clang-format] Do not format raw string literals inside a recognized ↵Krasimir Georgiev2018-06-281-1/+1
| | | | | | | | | | | | | | function with a non-recognized delimiter Summary: This stops clang-format from touching raw string contents with unrecognized delimiters inside recognized functions. Unrecognized delimiters signal that the string might be special. Subscribers: cfe-commits Differential Revision: https://reviews.llvm.org/D48728 llvm-svn: 335876
* [clang-format] Enable text proto formatting in common functionsKrasimir Georgiev2018-06-261-1/+4
| | | | | | | | Subscribers: cfe-commits Differential Revision: https://reviews.llvm.org/D48363 llvm-svn: 335595
* [clang-format] Add a default format style that can be used by users of ↵Eric Liu2018-06-251-0/+4
| | | | | | | | | | | | | | | | | | | | | | | | | `getStyle` Summary: Tools that reformat code often call `getStyle` to decide the format style to use on a certain source file. In practice, "file" style is widely used. As a result, many tools hardcode "file" when calling `getStyle`, which makes it hard to control the default style in tools across a codebase when needed. This change introduces a `DefaultFormatStyle` constant (default to "file" in upstream), which can be modified downstream if wanted, so that all users/tools built from the same source tree can have a consistent default format style. This also adds an DefaultFallbackStyle that is recommended to be used by tools and can be modified downstream. Reviewers: sammccall, djasper Reviewed By: sammccall Subscribers: cfe-commits Differential Revision: https://reviews.llvm.org/D48492 llvm-svn: 335492
* [clang-format] Keep @message together in text protosKrasimir Georgiev2018-06-252-3/+21
| | | | | | | | | | | | 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] Fix end-of-file comments text proto formattingKrasimir Georgiev2018-06-251-0/+12
| | | | | | | | | | | | | | | | | | | | Summary: The case of end-of-file comments was formatted badly: ``` key: value # end-of-file comment ``` This patch fixes that formatting: ``` key: value # end-of-file comment ``` Subscribers: cfe-commits Differential Revision: https://reviews.llvm.org/D48539 llvm-svn: 335449
* [Format] Do not use a global static value for EOF within ScopedMacroState.David L. Jones2018-06-151-12/+4
| | | | | | | | | | | | | | | | | ScopedMacroState injects its own EOF token under certain conditions, and the returned token may be modified in several different locations. If multiple reformat operations are started in different threads, then they will both see the same fake EOF token, and may both try to modify it. This is a data race. This bug was caught with tsan. Reviewers: klimek Subscribers: cfe-commits Differential Revision: https://reviews.llvm.org/D47759 llvm-svn: 334801
* [clang-format] Disable AlwaysBreakBeforeMultilineStrings in Google style for ↵Ben Hamilton2018-06-141-0/+1
| | | | | | | | | | | | | | | | Objective-C 📜 Contributed by @stephanemoore. Reviewers: benhamilton, jolesiak, djasper Reviewed By: benhamilton Subscribers: klimek, cfe-commits Differential Revision: https://reviews.llvm.org/D47393 llvm-svn: 334739
* [clang-format] Add SpaceBeforeCpp11BracedList option.Hans Wennborg2018-06-142-0/+7
| | | | | | | | | | | | | | | | | | | | 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] Fix crash while reflowing backslash in commentsKrasimir Georgiev2018-06-121-7/+38
| | | | | | | | | | | | | | | | | | | | | Summary: The added test case was currently crashing with an assertion: ``` krasimir@krasimir> cat test.cc ~ // How to run: // bbbbb run \ // rrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr \ // <log_file> -- --output_directory="<output_directory>" krasimir@krasimir> ~/work/llvm-build/bin/clang-format test.cc ~ clang-format: /usr/local/google/home/krasimir/work/llvm/tools/clang/lib/Format/WhitespaceManager.cpp:117: void clang::format::WhitespaceManager::calculateLineBreakInformation(): Assertion `PreviousOriginalWhitespaceEndOffset <= OriginalWhitespaceStartOffset' failed. ``` The root cause was that BreakableToken was not considering the case of a reflow between an unescaped newline in a line comment. Subscribers: cfe-commits Differential Revision: https://reviews.llvm.org/D48089 llvm-svn: 334527
* [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-113-10/+43
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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] Consider tok::hashhash in python-style commentsKrasimir Georgiev2018-06-072-2/+3
| | | | | | | | | | Summary: We were missing the case when python-style comments in text protos start with `##`. Subscribers: cfe-commits Differential Revision: https://reviews.llvm.org/D47870 llvm-svn: 334179
* Reland "Move #include manipulation code to new lib/Tooling/Inclusions."Eric Liu2018-06-042-1/+2
| | | | | | | | This reverts commit r333534 (i.e. reland r332720) after fixing module build. Differential Revision: https://reviews.llvm.org/D47068 llvm-svn: 333874
* [clang-format/ObjC] Correctly parse Objective-C methods with 'class' in nameBen Hamilton2018-05-302-0/+22
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Summary: Please take a close look at this CL. I haven't touched much of `UnwrappedLineParser` before, so I may have gotten things wrong. Previously, clang-format would incorrectly format the following: ``` @implementation Foo - (Class)class { } - (void)foo { } @end ``` as: ``` @implementation Foo - (Class)class { } - (void)foo { } @end ``` The problem is whenever `UnwrappedLineParser::parseStructuralElement()` sees any of the keywords `class`, `struct`, or `enum`, it calls `parseRecord()` to parse them as a C/C++ record. This causes subsequent lines to be parsed incorrectly, which causes them to be indented incorrectly. In Objective-C/Objective-C++, these keywords are valid selector components. This diff fixes the issue by explicitly handling `+` and `-` lines inside `@implementation` / `@interface` / `@protocol` blocks and parsing them as Objective-C methods. Test Plan: New tests added. Ran tests with: make -j16 FormatTests && ./tools/clang/unittests/Format/FormatTests Reviewers: jolesiak, klimek Reviewed By: jolesiak, klimek Subscribers: klimek, cfe-commits, Wizard Differential Revision: https://reviews.llvm.org/D47095 llvm-svn: 333553
* Revert "[clang-format] Fix putting ObjC message arguments in one line for ↵Jacek Olesiak2018-05-301-23/+0
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | multiline receiver" Summary: This reverts commit db9e5e9a616d7fdd4d1ba4c3b2cd89d8a0238533 (rC333171). Mentioned change introduced unintended formatting of ObjC code due to split priorities inherited from C/C++, e.g.: ``` fooooooo = [ [obj fooo] aaa:42 aaa:42]; ``` instead of ``` fooooooo = [[obj fooo] aaa:42 aaa:42]; ``` when formatted with ColumnLimit = 30. Reviewers: krasimir Reviewed By: krasimir Subscribers: benhamilton, klimek, cfe-commits Differential Revision: https://reviews.llvm.org/D47527 llvm-svn: 333539
* Revert "Reland "Move #include manipulation code to new lib/Tooling/Inclusions.""Eric Liu2018-05-302-2/+1
| | | | | | This reverts commit r333532. Revert for now to fix an internal bot issue. llvm-svn: 333534
* Reland "Move #include manipulation code to new lib/Tooling/Inclusions."Eric Liu2018-05-302-1/+2
| | | | | | | | | This reverts commit r332751 (i.e. reland r332720) after fixing module build. Differential Revision: https://reviews.llvm.org/D47068 llvm-svn: 333532
* [clang-format] Fix putting ObjC message arguments in one line for multiline ↵Jacek Olesiak2018-05-241-0/+23
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | receiver Summary: Reapply reverted changes from D46879. Currently BreakBeforeParameter is set to true everytime message receiver spans multiple lines, e.g.: ``` [[object block:^{ return 42; }] aa:42 bb:42]; ``` will be formatted: ``` [[object block:^{ return 42; }] aa:42 bb:42]; ``` even though arguments could fit into one line. This change fixes this behavior. Test Plan: make -j12 FormatTests && tools/clang/unittests/Format/FormatTests Reviewers: benhamilton, krasimir Reviewed By: benhamilton, krasimir Subscribers: djasper, klimek, cfe-commits Differential Revision: https://reviews.llvm.org/D47195 llvm-svn: 333171
* [clang-format] Break template declarations followed by commentsKrasimir Georgiev2018-05-231-2/+3
| | | | | | | | | | | | | | | | | Summary: This patch fixes two bugs in clang-format where the template wrapper doesn't skip over comments causing a long template declaration to not be split into multiple lines. These were latent and exposed by r332436. Reviewers: sammccall Reviewed By: sammccall Subscribers: klimek, cfe-commits Differential Revision: https://reviews.llvm.org/D47257 llvm-svn: 333085
* Revert "[clang-format] Fix putting ObjC message arguments in one line for ↵Jacek Olesiak2018-05-221-27/+1
| | | | | | | | | | | | | | | | multiline receiver" Summary: Reverts D46879 Reviewers: benhamilton Reviewed By: benhamilton Subscribers: krasimir, klimek, cfe-commits Differential Revision: https://reviews.llvm.org/D47205 llvm-svn: 332998
* 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] Fix crash in getLengthToMatchingParenKrasimir Georgiev2018-05-221-3/+3
| | | | | | | | | | | | | | Summary: Found by oss-fuzz: https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=8212 Reviewers: bkramer Subscribers: klimek, cfe-commits Differential Revision: https://reviews.llvm.org/D47191 llvm-svn: 332961
* Revert "Move #include manipulation code to new lib/Tooling/Inclusions."Eric Liu2018-05-182-2/+1
| | | | | | | This reverts commit r332720. This break build bot with modules. Need to investigate. Revert the change to unbreak bots. llvm-svn: 332751
* [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
* Move #include manipulation code to new lib/Tooling/Inclusions.Eric Liu2018-05-182-1/+2
| | | | | | | | | | | | | | | Summary: clangToolingCore is linked into almost everything (incl. clang), but not few tools need #include manipulation at this point. So pull this into a separate library in Tooling. Reviewers: ilya-biryukov Subscribers: klimek, mgorny, cfe-commits, thakis Differential Revision: https://reviews.llvm.org/D47068 llvm-svn: 332720
* [clang-format] Fix putting ObjC message arguments in one line for multiline ↵Jacek Olesiak2018-05-171-1/+27
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | receiver Summary: Currently BreakBeforeParameter is set to true everytime message receiver spans multiple lines, e.g.: ``` [[object block:^{ return 42; }] aa:42 bb:42]; ``` will be formatted: ``` [[object block:^{ return 42; }] aa:42 bb:42]; ``` even though arguments could fit into one line. This change fixes this behavior. Test Plan: make -j12 FormatTests && tools/clang/unittests/Format/FormatTests Reviewers: benhamilton, djasper Reviewed By: benhamilton Subscribers: klimek, cfe-commits Differential Revision: https://reviews.llvm.org/D46879 llvm-svn: 332582
* clang-format: Allow optimizer to break template declaration.Francois Ferrand2018-05-163-5/+29
| | | | | | | | | | | | | | | | | | | 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
OpenPOWER on IntegriCloud