#
9dc78163 |
| 03-Apr-2018 |
Ben Hamilton <benhamilton@google.com> |
[clang-format/ObjC] Do not detect "[]" as ObjC method expression
Summary: The following C++ code was being detected by `guessLanguage()` as Objective-C:
#define FOO(...) auto bar = [] __VA_ARGS__
[clang-format/ObjC] Do not detect "[]" as ObjC method expression
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
show more ...
|
#
ea7a27b8 |
| 27-Mar-2018 |
Ben Hamilton <benhamilton@google.com> |
[clang-format] Refine ObjC guesser to handle child lines of child lines
Summary: This fixes an issue brought up by djasper@ in his review of D44790. We handled top-level child lines, but if those ch
[clang-format] Refine ObjC guesser to handle child lines of child lines
Summary: This fixes an issue brought up by djasper@ in his review of D44790. We handled top-level child lines, but if those child lines themselves had child lines, we didn't handle them.
Rather than use recursion (which could blow out the stack), I use a DenseSet to hold the set of lines we haven't yet checked (since order doesn't matter), and update the set to add the children of each line as we check it.
Test Plan: New tests added. Confirmed tests failed before fix and passed after fix.
Reviewers: djasper
Reviewed By: djasper
Subscribers: klimek, cfe-commits
Differential Revision: https://reviews.llvm.org/D44831
llvm-svn: 328628
show more ...
|
#
03e69f5c |
| 27-Mar-2018 |
Krasimir Georgiev <krasimir@google.com> |
Revert "[clang-format] Remove empty lines before }[;] // comment"
This reverts commit r327861.
The empty line before namespaces is desired in some places. We need a better approach to handle this.
Revert "[clang-format] Remove empty lines before }[;] // comment"
This reverts commit r327861.
The empty line before namespaces is desired in some places. We need a better approach to handle this.
llvm-svn: 328621
show more ...
|
#
6432afe5 |
| 22-Mar-2018 |
Ben Hamilton <benhamilton@google.com> |
[clang-format] Fix ObjC style guesser to also iterate over child lines
Summary: When I wrote `ObjCHeaderStyleGuesser`, I incorrectly assumed the correct way to iterate over all tokens in `AnnotatedL
[clang-format] Fix ObjC style guesser to also iterate over child lines
Summary: When I wrote `ObjCHeaderStyleGuesser`, I incorrectly assumed the correct way to iterate over all tokens in `AnnotatedLine` was to iterate over the linked list tokens starting with `AnnotatedLine::First`.
However, `AnnotatedLine` also contains a vector `AnnotedLine::Children` with child `AnnotedLine`s which have their own tokens which we need to iterate over.
Because I didn't iterate over the tokens in the children lines, the ObjC style guesser would fail on syntax like:
#define FOO ({ NSString *s = ... })
as the statement(s) inside { ... } are child lines.
This fixes the bug and adds a test. I confirmed the test failed before the fix, and passed after the fix.
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/D44790
llvm-svn: 328220
show more ...
|
#
fd327674 |
| 22-Mar-2018 |
Daniel Jasper <djasper@google.com> |
clang-format: Narrow down raw string literal line break exception.
For multiline raw string literals, we generally want to respect the author's choice of linebreak before the 'R"(' as the rest of th
clang-format: Narrow down raw string literal line break exception.
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
show more ...
|
#
d5e9ff4f |
| 22-Mar-2018 |
Daniel Jasper <djasper@google.com> |
clang-format: Fix SpacesInParentheses with fully qualified names.
When SpacesInParentheses is set to true clang-format does not add a space before fully qualified names. For example:
do_something
clang-format: Fix SpacesInParentheses with fully qualified names.
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
show more ...
|
#
19c782d5 |
| 22-Mar-2018 |
Ben Hamilton <benhamilton@google.com> |
[clang-format] Add a few more Core Graphics identifiers to ObjC heuristic
Summary: We received reports of the Objective-C style guesser getting a false negative on header files like:
CGSize SizeOfT
[clang-format] Add a few more Core Graphics identifiers to ObjC heuristic
Summary: We received reports of the Objective-C style guesser getting a false negative on header files like:
CGSize SizeOfThing(MyThing thing);
This adds more Core Graphics identifiers to the Objective-C style guesser.
Test Plan: New tests added. Ran tests with: % make -j12 FormatTests && ./tools/clang/unittests/Format/FormatTests
Reviewers: jolesiak, djasper
Reviewed By: jolesiak, djasper
Subscribers: krasimir, klimek, cfe-commits
Differential Revision: https://reviews.llvm.org/D44632
llvm-svn: 328175
show more ...
|
#
5cca20f8 |
| 19-Mar-2018 |
Krasimir Georgiev <krasimir@google.com> |
[clang-format] Remove empty lines before }[;] // comment
Summary: This addresses bug 36766 and a FIXME in tests about empty lines before `}[;] // comment` lines.
Subscribers: klimek, cfe-commits
D
[clang-format] Remove empty lines before }[;] // comment
Summary: This addresses bug 36766 and a FIXME in tests about empty lines before `}[;] // comment` lines.
Subscribers: klimek, cfe-commits
Differential Revision: https://reviews.llvm.org/D44631
llvm-svn: 327861
show more ...
|
#
788a2227 |
| 12-Mar-2018 |
Ben Hamilton <benhamilton@google.com> |
[clang-format] Improve detection of Objective-C block types
Summary: Previously, clang-format would detect the following as an Objective-C block type:
FOO(^);
when it actually must be a C or C++
[clang-format] Improve detection of Objective-C block types
Summary: Previously, clang-format would detect the following as an Objective-C block type:
FOO(^);
when it actually must be a C or C++ macro dealing with an XOR statement or an XOR operator overload.
According to the Clang Block Language Spec:
https://clang.llvm.org/docs/BlockLanguageSpec.html
block types are of the form:
int (^)(char, float)
and block variables of block type are of the form:
void (^blockReturningVoidWithVoidArgument)(void); int (^blockReturningIntWithIntAndCharArguments)(int, char); void (^arrayOfTenBlocksReturningVoidWithIntArgument[10])(int);
This tightens up the detection so we don't unnecessarily detect C macros which pass in the XOR operator.
Depends On D43904
Test Plan: New tests added. Ran tests with: make -j12 FormatTests && ./tools/clang/unittests/Format/FormatTests
Reviewers: krasimir, jolesiak, djasper
Reviewed By: djasper
Subscribers: djasper, cfe-commits, klimek
Differential Revision: https://reviews.llvm.org/D43906
llvm-svn: 327285
show more ...
|
#
b060ad87 |
| 12-Mar-2018 |
Ben Hamilton <benhamilton@google.com> |
[clang-format] Don't detect C++11 attribute specifiers as ObjC
Summary: Previously, clang-format would detect C++11 and C++17 attribute specifiers like the following as Objective-C method invocation
[clang-format] Don't detect C++11 attribute specifiers as ObjC
Summary: Previously, clang-format would detect C++11 and C++17 attribute specifiers like the following as Objective-C method invocations:
[[noreturn]]; [[clang::fallthrough]]; [[noreturn, deprecated("so sorry")]]; [[using gsl: suppress("type")]];
To fix this, I ported part of the logic from tools/clang/lib/Parse/ParseTentative.cpp into TokenAnnotator.cpp so we can explicitly parse and identify C++11 attribute specifiers.
This allows the guessLanguage() and getStyle() APIs to correctly guess files containing the C++11 attribute specifiers as C++, not Objective-C.
Test Plan: New tests added. Ran tests with: make -j12 FormatTests && ./tools/clang/unittests/Format/FormatTests
Reviewers: krasimir, jolesiak, djasper
Reviewed By: djasper
Subscribers: aaron.ballman, cfe-commits, klimek
Differential Revision: https://reviews.llvm.org/D43902
llvm-svn: 327284
show more ...
|
#
1d6c6ee1 |
| 06-Mar-2018 |
Ben Hamilton <benhamilton@google.com> |
[clang-format] Improve detection of ObjC for-in statements
Summary: Previously, clang-format would detect the following as an Objective-C for-in statement:
for (int x = in.value(); ...) {}
becau
[clang-format] Improve detection of ObjC for-in statements
Summary: Previously, clang-format would detect the following as an Objective-C for-in statement:
for (int x = in.value(); ...) {}
because the logic only decided a for-loop was definitely *not* an Objective-C for-in loop after it saw a semicolon or a colon.
To fix this, I delayed the decision of whether this was a for-in statement until after we found the matching right-paren, at which point we know if we've seen a semicolon or not.
Test Plan: New tests added. Ran tests with: make -j12 FormatTests && ./tools/clang/unittests/Format/FormatTests
Reviewers: krasimir, jolesiak
Reviewed By: jolesiak
Subscribers: djasper, cfe-commits, klimek
Differential Revision: https://reviews.llvm.org/D43904
llvm-svn: 326815
show more ...
|
#
446d6ec9 |
| 06-Mar-2018 |
Krasimir Georgiev <krasimir@google.com> |
[clang-format] fix handling of consecutive unary operators
Summary: Code that used to be formatted as `if (! + object) {` is now formatted as `if (!+object) {` (we have a particular object in our co
[clang-format] fix handling of consecutive unary operators
Summary: Code that used to be formatted as `if (! + object) {` is now formatted as `if (!+object) {` (we have a particular object in our codebase where unary `operator+` is overloaded to return the underlying value, which in this case is a `bool`)
We still preserve the TypeScript behavior where `!` is a trailing non-null operator. (This is already tested by an existing unit test in `FormatTestJS.cpp`)
It doesn't appear like handling of consecutive unary operators are tested in general, so I added another test for completeness
Patch contributed by @kevinl!
Reviewers: krasimir
Reviewed By: krasimir
Subscribers: klimek, cfe-commits
Differential Revision: https://reviews.llvm.org/D43312
llvm-svn: 326792
show more ...
|
#
2a9ea781 |
| 01-Mar-2018 |
Francois Ferrand <thetypz@gmail.com> |
[clang-format] Add SpaceBeforeColon option
Summary: When disabled, this option allows removing the space before colon, making it act more like the semi-colon. When enabled (default), the current beh
[clang-format] Add SpaceBeforeColon option
Summary: When disabled, this option allows removing the space before colon, making it act more like the semi-colon. When enabled (default), the current behavior is not affected.
This mostly affects C++11 loop, initializer list, inheritance list and container literals:
class Foo: Bar {} Foo::Foo(): a(a) {} for (auto i: myList) {} f({a: 1, b: 2, c: 3});
Reviewers: krasimir, djasper
Reviewed By: djasper
Subscribers: xvallspl, teemperor, karies, cfe-commits, klimek
Differential Revision: https://reviews.llvm.org/D32525
llvm-svn: 326426
show more ...
|
#
6e066350 |
| 27-Feb-2018 |
Ben Hamilton <benhamilton@google.com> |
[clang-format] Tidy up new API guessLanguage()
Summary: This fixes a few issues djasper@ brought up in his review of D43522.
Test Plan: make -j12 FormatTests && ./tools/clang/unittests/Format/For
[clang-format] Tidy up new API guessLanguage()
Summary: This fixes a few issues djasper@ brought up in his review of D43522.
Test Plan: make -j12 FormatTests && ./tools/clang/unittests/Format/FormatTests
Reviewers: djasper
Reviewed By: djasper
Subscribers: klimek, cfe-commits
Differential Revision: https://reviews.llvm.org/D43598
llvm-svn: 326205
show more ...
|
#
0b2f774b |
| 26-Feb-2018 |
Bjorn Pettersson <bjorn.a.pettersson@ericsson.com> |
Resolve build bot problems in unittests/Format/FormatTest.cpp
Summary: Make the new GetStyleWithEmptyFileName test case independent of the file system used when running the test. Since the test is s
Resolve build bot problems in unittests/Format/FormatTest.cpp
Summary: Make the new GetStyleWithEmptyFileName test case independent of the file system used when running the test. Since the test is supposed to use the fallback "Google" style we now use a InMemoryFileSystem to make sure that we do not accidentaly find a .clang-format file in the real file system. That could for example happen when having the build directory inside the llvm och clang repo (as there is a .clang-format file inside the repos).
Reviewers: vsapsai, jolesiak, krasimir, benhamilton
Reviewed By: krasimir
Subscribers: uabelho, twoh, klimek, cfe-commits
Differential Revision: https://reviews.llvm.org/D43732
llvm-svn: 326086
show more ...
|
#
07e58365 |
| 21-Feb-2018 |
Ben Hamilton <benhamilton@google.com> |
[clang-format] Fix regression when getStyle() called with empty filename
Summary: D43522 caused an assertion failure when getStyle() was called with an empty filename:
P8065
This adds a test to re
[clang-format] Fix regression when getStyle() called with empty filename
Summary: D43522 caused an assertion failure when getStyle() was called with an empty filename:
P8065
This adds a test to reproduce the failure and fixes the issue by ensuring we never pass an empty filename to Environment::CreateVirtualEnvironment().
Test Plan: New test added. Ran test with: % make -j12 FormatTests && ./tools/clang/unittests/Format/FormatTests Before diff, test failed with P8065. Now, test passes.
Reviewers: vsapsai, jolesiak, krasimir
Reviewed By: vsapsai
Subscribers: klimek, cfe-commits
Differential Revision: https://reviews.llvm.org/D43590
llvm-svn: 325722
show more ...
|
#
3b345c36 |
| 21-Feb-2018 |
Ben Hamilton <benhamilton@google.com> |
[clang-format] New API guessLanguage()
Summary: For clients which don't have a filesystem, calling getStyle() doesn't make much sense (there's no .clang-format files to search for).
In this diff, I
[clang-format] New API guessLanguage()
Summary: For clients which don't have a filesystem, calling getStyle() doesn't make much sense (there's no .clang-format files to search for).
In this diff, I hoist out the language-guessing logic from getStyle() and move it into a new API guessLanguage().
I also added support for guessing the language of files which have no extension (they could be C++ or ObjC).
Test Plan: New tests added. Ran tests with: % make -j12 FormatTests && ./tools/clang/unittests/Format/FormatTests
Reviewers: jolesiak, krasimir
Reviewed By: jolesiak, krasimir
Subscribers: klimek, cfe-commits, sammccall
Differential Revision: https://reviews.llvm.org/D43522
llvm-svn: 325691
show more ...
|
#
1c3afaf5 |
| 05-Feb-2018 |
Mark Zeren <mzeren@vmware.com> |
[clang-format] Re-land: Fixup #include guard indents after parseFile()
Summary: When a preprocessor indent closes after the last line of normal code we do not correctly fixup include guard indents.
[clang-format] Re-land: Fixup #include guard indents after parseFile()
Summary: When a preprocessor indent closes after the last line of normal code we do not correctly fixup include guard indents. For example:
#ifndef HEADER_H #define HEADER_H #if 1 int i; # define A 0 #endif #endif
incorrectly reformats to:
#ifndef HEADER_H #define HEADER_H #if 1 int i; # define A 0 # endif #endif
To resolve this issue we must fixup levels after parseFile(). Delaying the fixup introduces a new state, so consolidate include guard search state into an enum.
Reviewers: krasimir, klimek
Subscribers: cfe-commits
Differential Revision: https://reviews.llvm.org/D42035
llvm-svn: 324246
show more ...
|
#
b0cc6ed2 |
| 05-Feb-2018 |
Mark Zeren <mzeren@vmware.com> |
Revert "[clang-format] Fixup #include guard indents after parseFile()"
This reverts r324238 | mzeren-vmw | 2018-02-05 06:35:54 -0800 (Mon, 05 Feb 2018) | 35 lines
Incorrect version pushed upstream.
Revert "[clang-format] Fixup #include guard indents after parseFile()"
This reverts r324238 | mzeren-vmw | 2018-02-05 06:35:54 -0800 (Mon, 05 Feb 2018) | 35 lines
Incorrect version pushed upstream.
llvm-svn: 324239
show more ...
|
#
0dc13cdc |
| 05-Feb-2018 |
Mark Zeren <mzeren@vmware.com> |
[clang-format] Fixup #include guard indents after parseFile()
Summary: When a preprocessor indent closes after the last line of normal code we do not correctly fixup include guard indents. For examp
[clang-format] Fixup #include guard indents after parseFile()
Summary: When a preprocessor indent closes after the last line of normal code we do not correctly fixup include guard indents. For example:
#ifndef HEADER_H #define HEADER_H #if 1 int i; # define A 0 #endif #endif
incorrectly reformats to:
#ifndef HEADER_H #define HEADER_H #if 1 int i; # define A 0 # endif #endif
To resolve this issue we must fixup levels after parseFile(). Delaying the fixup introduces a new state, so consolidate include guard search state into an enum.
Reviewers: krasimir, klimek
Reviewed By: krasimir
Subscribers: cfe-commits
Differential Revision: https://reviews.llvm.org/D42035
llvm-svn: 324238
show more ...
|
#
d2b2ac68 |
| 31-Jan-2018 |
Mark Zeren <mzeren@vmware.com> |
[clang-format] Align preprocessor comments with #
Summary: r312125, which introduced preprocessor indentation, shipped with a known issue where "indentation of comments immediately before indented p
[clang-format] Align preprocessor comments with #
Summary: r312125, which introduced preprocessor indentation, shipped with a known issue where "indentation of comments immediately before indented preprocessor lines is toggled on each run". For example these two forms toggle:
#ifndef HEADER_H #define HEADER_H #if 1 // comment # define A 0 #endif #endif
#ifndef HEADER_H #define HEADER_H #if 1 // comment # define A 0 #endif #endif
This happens because we check vertical alignment against the '#' yet indent to the level of the 'define'. This patch resolves this issue by aligning against the '#'.
Reviewers: krasimir, klimek, djasper
Reviewed By: krasimir
Subscribers: cfe-commits Differential Revision: https://reviews.llvm.org/D42408
llvm-svn: 323904
show more ...
|
#
412ed095 |
| 19-Jan-2018 |
Krasimir Georgiev <krasimir@google.com> |
[clang-format] Adds a canonical delimiter to raw string formatting
Summary: This patch adds canonical delimiter support to the raw string formatting. This allows matching delimiters to be updated to
[clang-format] Adds a canonical delimiter to raw string formatting
Summary: This patch adds canonical delimiter support to the raw string formatting. This allows matching delimiters to be updated to the canonical one.
Reviewers: bkramer
Reviewed By: bkramer
Subscribers: klimek, cfe-commits
Differential Revision: https://reviews.llvm.org/D42187
llvm-svn: 322956
show more ...
|
#
bf4cddaa |
| 19-Jan-2018 |
Krasimir Georgiev <krasimir@google.com> |
[clang-format] Fix shortening blocks in macros causing merged next line
Summary: This patch addresses bug 36002, where a combination of options causes the line following a short block in macro to be
[clang-format] Fix shortening blocks in macros causing merged next line
Summary: This patch addresses bug 36002, where a combination of options causes the line following a short block in macro to be merged with that macro.
Reviewers: bkramer
Reviewed By: bkramer
Subscribers: klimek, cfe-commits
Differential Revision: https://reviews.llvm.org/D42298
llvm-svn: 322954
show more ...
|
#
2537e220 |
| 17-Jan-2018 |
Krasimir Georgiev <krasimir@google.com> |
[clang-format] adds enclosing function detection to raw string formatting
Summary: This patch adds enclosing function detection to raw string formatting.
Reviewers: bkramer
Reviewed By: bkramer
S
[clang-format] adds enclosing function detection to raw string formatting
Summary: This patch adds enclosing function detection to raw string formatting.
Reviewers: bkramer
Reviewed By: bkramer
Subscribers: klimek, cfe-commits
Differential Revision: https://reviews.llvm.org/D42167
llvm-svn: 322678
show more ...
|
#
4527f13a |
| 17-Jan-2018 |
Krasimir Georgiev <krasimir@google.com> |
[clang-format] Reorganize RawStringFormat based on language
Summary: This patch changes the structure for raw string formatting options by making it language based (enumerate delimiters per language
[clang-format] Reorganize RawStringFormat based on language
Summary: This patch changes the structure for raw string formatting options by making it language based (enumerate delimiters per language) as opposed to delimiter-based (specify the language for a delimiter). The raw string formatting now uses an appropriate style from the .clang-format file, if exists.
Reviewers: bkramer
Reviewed By: bkramer
Subscribers: cfe-commits, klimek
Differential Revision: https://reviews.llvm.org/D42098
llvm-svn: 322634
show more ...
|