summaryrefslogtreecommitdiffstats
path: root/clang/lib/Format/NamespaceEndCommentsFixer.cpp
Commit message (Collapse)AuthorAgeFilesLines
* [clang][NFC] Make various uses of Regex constThomas Preud'homme2019-11-191-10/+10
| | | | | | | | | | | | | | | | The const-correctness of match() was fixed in rL372764, which allows uses of Regex objects to be const in cases they couldn't be before. This patch tightens up the const-ness of Regex in various such cases. Reviewers: thopre Reviewed By: thopre Subscribers: cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D68155
* clang-format: Fix namespace end comments for namespaces with attributes and ↵Nico Weber2019-07-231-2/+14
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | macros. Fixes PR39247. While here, also make C++20 `namespace A::inline B::inline C` nested inline namespaced definitions work. Before: #define DEPRECATE_WOOF [[deprecated("meow")]] namespace DEPRECATE_WOOF woof { void f() {} } // namespace DEPRECATE_WOOFwoof namespace [[deprecated("meow")]] woof { void f() {} } // namespace [[deprecated("meow")]]woof namespace woof::inline bark { void f() {} } // namespace woof::inlinebark Now: #define DEPRECATE_WOOF [[deprecated("meow")]] namespace DEPRECATE_WOOF woof { void f() {} } // namespace woof namespace [[deprecated("meow")]] woof { void f() {} } // namespace woof namespace woof::inline bark { void f() {} } // namespace woof::inline bark (In addition to the fixed namespace end comments, also note the correct indent of the namespace contents.) Differential Revision: https://reviews.llvm.org/D65125 llvm-svn: 366831
* clang-format: better handle namespace macrosFrancois Ferrand2019-06-061-24/+67
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Summary: Other macros are used to declare namespaces, and should thus be handled similarly. This is the case for crpcut's TESTSUITE macro, or for unittest-cpp's SUITE macro: TESTSUITE(Foo) { TEST(MyFirstTest) { assert(0); } } // TESTSUITE(Foo) This patch deals with this cases by introducing a new option to specify lists of namespace macros. Internally, it re-uses the system already in place for foreach and statement macros, to ensure there is no impact on performance. Reviewers: krasimir, djasper, klimek Reviewed By: klimek Subscribers: acoomans, cfe-commits, klimek Tags: #clang Differential Revision: https://reviews.llvm.org/D37813 llvm-svn: 362740
* 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: Fix formatting C++ namespaces with preceding 'inline' or ↵Sam McCall2018-09-051-6/+1
| | | | | | | | | | | | | | | | | | | | | | 'export' specifier This fixes formatting namespaces with preceding 'inline' and 'export' (Modules TS) specifiers. This change fixes namespaces not being identified as such with preceding 'inline' or 'export' specifiers. Motivation: I was experimenting with the Modules TS (-fmodules-ts) and found it would be useful if clang-format would correctly format 'export namespace'. While making the changes, I noticed that similar issues still exist with 'inline namespace', and addressed them as well. Patch by Marco Elver! Reviewers: klimek, djasper, owenpan, sammccall Reviewed By: owenpan, sammccall Subscribers: owenpan, cfe-commits Differential Revision: https://reviews.llvm.org/D51036 llvm-svn: 341450
* Remove \brief commands from doxygen comments.Adrian Prantl2018-05-091-1/+1
| | | | | | | | | | | | | | | | | | | 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] Fix clang-tidy readability problems, NFCIKrasimir Georgiev2018-04-231-3/+3
| | | | llvm-svn: 330574
* Format closing braces when reformatting the line containing the opening brace.Manuel Klimek2018-04-231-2/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This required a couple of yaks to be shaved: 1. MatchingOpeningBlockLineIndex was misused to also store the closing index; instead, use a second variable, as this doesn't work correctly for "} else {". 2. We needed to change the API of AffectedRangeManager to not use iterators; we always passed in begin / end for the whole container before, so there was no mismatch in generality. 3. We need an extra check to discontinue formatting at the top level, as we now sometimes change the indent of the closing brace, but want to bail out immediately afterwards, for example: void f() { if (a) { } void g(); Previously: void f() { if (a) { } void g(); Now: void f() { if (a) { } void g(); Differential Revision: https://reviews.llvm.org/D45726 llvm-svn: 330573
* [clang-format] Don't remove empty lines before namespace endingsKrasimir Georgiev2018-04-191-1/+1
| | | | | | | | | | | | | | Summary: This implements an alternative to r327861, namely preserving empty lines before namespace endings. Reviewers: djasper Reviewed By: djasper Subscribers: klimek, cfe-commits Differential Revision: https://reviews.llvm.org/D45373 llvm-svn: 330324
* [format] Initialize regex lazilyBenjamin Kramer2018-03-201-8/+8
| | | | | | | No need to pay for this on program startup, and also no need to destroy it on process end. llvm-svn: 328041
* [clang-format] Format raw string literalsKrasimir Georgiev2017-10-301-2/+2
| | | | | | | | | | | | | | | Summary: This patch adds raw string literal formatting. Reviewers: djasper, klimek Reviewed By: klimek Subscribers: klimek, mgorny Differential Revision: https://reviews.llvm.org/D35943 llvm-svn: 316903
* [clang-format] Fix FixNamespaceComments when BraceWrapping AfterNamespace is ↵Marek Kurdej2017-09-271-0/+6
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | true. Summary: NamespaceEndCommentsFixer did not fix namespace comments when the brace opening the namespace was not on the same line as the "namespace" keyword. It occurs in Allman, GNU and Linux styles and whenever BraceWrapping.AfterNamespace is true. Before: ```lang=cpp namespace a { void f(); void g(); } ``` After: ```lang=cpp namespace a { void f(); void g(); } // namespace a ``` Reviewers: krasimir Reviewed By: krasimir Subscribers: klimek, cfe-commits Differential Revision: https://reviews.llvm.org/D37904 llvm-svn: 314279
* [clang-format] Fix a clang-tidy warning, NFCKrasimir Georgiev2017-06-271-1/+1
| | | | llvm-svn: 306409
* clang-format: Add CompactNamespaces optionFrancois Ferrand2017-06-141-16/+48
| | | | | | | | | | | | | | | | | | | | | | | | | Summary: Add CompactNamespaces option, to pack namespace declarations on the same line (somewhat similar to C++17 nested namespace definition). With this option, consecutive namespace declarations are kept on the same line: namespace foo { namespace bar { ... }} // namespace foo::bar Reviewers: krasimir, djasper, klimek Reviewed By: djasper Subscribers: kimgr, cfe-commits, klimek Tags: #clang-tools-extra Differential Revision: https://reviews.llvm.org/D32480 llvm-svn: 305384
* [clang-format] fix crash in NamespaceEndCommentsFixer (PR32438)Matthias Gehre2017-04-041-1/+1
| | | | | | | | | | | | | | Summary: The new test case was crashing before. Now it passes as expected. Reviewers: djasper Subscribers: klimek, cfe-commits Differential Revision: https://reviews.llvm.org/D31441 llvm-svn: 299465
* [clang-format] Support namespaces ending in semicolonKrasimir Georgiev2017-03-071-7/+21
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Summary: This patch adds support for namespaces ending in semicolon to the namespace comment fixer. source: ``` namespace A { int i; int j; }; ``` clang-format before: ``` namespace A { int i; int j; } // namespace A; ``` clang-format after: ``` namespace A { int i; int j; }; // namespace A ``` Reviewers: djasper Reviewed By: djasper Subscribers: cfe-commits, klimek Differential Revision: https://reviews.llvm.org/D30688 llvm-svn: 297140
* [clang-format] Make NamespaceEndCommentFixer add at most one commentKrasimir Georgiev2017-03-061-1/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Summary: Until now, NamespaceEndCommentFixer was adding missing comments for every run, which results in multiple end comments for: ``` namespace { int i; int j; } #if A int a = 1; #else int a = 2; #endif ``` result before: ``` namespace { int i; int j; }// namespace // namespace #if A int a = 1; #else int a = 2; #endif ``` result after: ``` namespace { int i; int j; }// namespace #if A int a = 1; #else int a = 2; #endif ``` Reviewers: djasper Reviewed By: djasper Subscribers: klimek, cfe-commits Differential Revision: https://reviews.llvm.org/D30659 llvm-svn: 297028
* [clang-format] Use number of unwrapped lines for short namespaceKrasimir Georgiev2017-03-021-10/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Summary: This patch makes the namespace comment fixer use the number of unwrapped lines that a namespace spans to detect it that namespace is short, thus not needing end comments to be added. This is needed to ensure clang-format is idempotent. Previously, a short namespace was detected by the original source code lines. This has the effect of requiring two runs for this example: ``` namespace { class A; } ``` after first run: ``` namespace { class A; } ``` after second run: ``` namespace { class A; } // namespace ``` Reviewers: djasper Reviewed By: djasper Subscribers: cfe-commits, klimek Differential Revision: https://reviews.llvm.org/D30528 llvm-svn: 296736
* [clang-format] Add a NamespaceEndCommentsFixerKrasimir Georgiev2017-02-271-0/+165
Summary: This patch adds a NamespaceEndCommentsFixer TokenAnalyzer for clang-format, which fixes end namespace comments. It currently supports inserting and updating existing wrong comments. Example source: ``` namespace A { int i; } namespace B { int j; } // namespace A ``` after formatting: ``` namespace A { int i; } // namespace A namespace B { int j; } // namespace B ``` Reviewers: klimek, djasper Reviewed By: djasper Subscribers: klimek, mgorny Differential Revision: https://reviews.llvm.org/D30269 llvm-svn: 296341
OpenPOWER on IntegriCloud