summaryrefslogtreecommitdiffstats
path: root/clang/lib/Format
Commit message (Collapse)AuthorAgeFilesLines
...
* clang-format: Extend detection of the "main" #include to use the filenameDaniel Jasper2015-12-211-18/+16
| | | | | | | | | | | Before, the first (non-system) header in a file was considered to be the main include. This is conservative as it makes clang-format change the #include order less often. Instead implement some basic usage of the filename itself. With this patch, clang-format considers every header to be a main include if the header file's basename is a prefix to the filename the #include is in. llvm-svn: 256148
* Support AlwaysBreakAfterReturnTypeZachary Turner2015-12-184-13/+72
| | | | | | | | | | | This changes the behavior of AlwaysBreakAfterDeclarationReturnType so that it supports breaking after declarations, definitions, or both. Differential Revision: http://reviews.llvm.org/D10370 Reviewed By: Daniel Jasper llvm-svn: 256046
* clang-format: Extend header sort category implementation.Daniel Jasper2015-12-161-3/+3
| | | | | | | | | | Specifically, it is sometimes necessary to keep certain #includes as the first #include, even before the main #include for a .cc file. Switching the category to be signed instead of unsigned isn't ideal, but it seems as good of an option as any and is fully backwards compatible. llvm-svn: 255757
* clang-format: Fix style default for WebKit and Linux styles.Daniel Jasper2015-12-141-2/+0
| | | | | | | | Brought up in codereviews: http://reviews.llvm.org/D15445 http://reviews.llvm.org/D15485 llvm-svn: 255484
* clang-format: Make wrapping after "./->" cheaper, even if the elementDaniel Jasper2015-12-071-4/+14
| | | | | | | | | | | | | | | | | | | before it is not a closing parenthesis. Otherwise, this frequently leads to "hanging" indents that users perceive as "weird". Before: return !soooooooooooooome_map.insert( aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa) .second; After: return !soooooooooooooome_map .insert(aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa) .second; llvm-svn: 254933
* clang-format: Make it possible to turn off comment reflowing.Daniel Jasper2015-12-012-3/+7
| | | | llvm-svn: 254414
* clang-format: treat Q_SIGNALS as an access modifierDaniel Jasper2015-12-013-3/+6
| | | | | | Patch by Alexander Richardson, thank you! llvm-svn: 254407
* This fixes https://llvm.org/bugs/show_bug.cgi?id=25329, as well asDaniel Jasper2015-12-012-202/+133
| | | | | | | | | | | misalignments like the following: int a, b = 2; int c = 3; Patch by Beren Minor, thanks! llvm-svn: 254406
* clang-format: Re-add code path deleted in r253873 and add missing test.Daniel Jasper2015-11-231-0/+9
| | | | llvm-svn: 253900
* clang-format: Signficantly refactor the cast detection.Daniel Jasper2015-11-231-49/+60
| | | | | | No functional changes intended. llvm-svn: 253873
* clang-format: Fix incorrect cast detection.Daniel Jasper2015-11-231-17/+15
| | | | | | | | | | Before: bool b = f(g<int>)&&c; After: bool b = f(g<int>) && c; llvm-svn: 253872
* clang-format: If the template list of a variable declaration spansDaniel Jasper2015-11-231-0/+1
| | | | | | | | | | | | | | | multiple lines, also break before the variable name. Before: std::vector<aaaaaa, // wrap aa> aaa; After: std::vector<aaaaaa, // wrap aa> aaa; llvm-svn: 253871
* clang-format: Make moving of the Cursor work properly when sorting #includes.Daniel Jasper2015-11-231-8/+20
| | | | llvm-svn: 253860
* clang-format: Make sorting includes respect // clang-format offDaniel Jasper2015-11-211-1/+10
| | | | llvm-svn: 253772
* clang-format: [JS] Make AllowShortFunctionsOnASingle line value "Empty"Daniel Jasper2015-11-201-0/+1
| | | | | | work properly. llvm-svn: 253674
* clang-format: [JS] Properly add a space after "in" in for loops.Daniel Jasper2015-11-201-1/+2
| | | | llvm-svn: 253672
* clang-format: [JS] struct and union aren't keywords / reserved words.Daniel Jasper2015-11-201-0/+4
| | | | llvm-svn: 253671
* clang-format: Don't use incorrect space in macro calls with operators.Daniel Jasper2015-11-201-1/+2
| | | | | | | | | | | | Before: MACRO(> ); After: MACRO(>); Not overly important, but easy and good for symmetry reasons :-). llvm-svn: 253669
* clang-format: [Proto] Support extending message.Daniel Jasper2015-11-202-1/+3
| | | | | | | | | | | | Before: extend.foo.Bar { } After: extend .foo.Bar { } llvm-svn: 253667
* clang-format: Enable #include sorting by default.Daniel Jasper2015-11-161-0/+6
| | | | | | | | | This has seen quite some usage and I am not aware of any issues. Also add a style option to enable/disable include sorting. The existing command line flag can from now on be used to override whatever is set in the style. llvm-svn: 253202
* Add support for GCC's '__auto_type' extension, per the GCC manual:Richard Smith2015-11-111-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | https://gcc.gnu.org/onlinedocs/gcc/Typeof.html Differences from the GCC extension: * __auto_type is also permitted in C++ (but only in places where it could appear in C), allowing its use in headers that might be shared across C and C++, or used from C++98 * __auto_type can be combined with a declarator, as with C++ auto (for instance, "__auto_type *p") * multiple variables can be declared in a single __auto_type declaration, with the C++ semantics (the deduced type must be the same in each case) This patch also adds a missing restriction on applying typeof to a bit-field, which GCC has historically rejected in C (due to lack of clarity as to whether the operand should be promoted). The same restriction also applies to __auto_type in C (in both GCC and Clang). This also fixes PR25449. Patch by Nicholas Allegra! llvm-svn: 252690
* clang-format: Turn on wrapping before "else" for WebKit style.Daniel Jasper2015-11-041-0/+1
| | | | llvm-svn: 252089
* clang-format: Simplify and improve stop condition for formattingDaniel Jasper2015-11-021-4/+1
| | | | | | | | | | | | | | | | | | | | | | | | unaffected lines with incorrect initial indent. Starting from: namespace { int i; // There shouldn't be indentation here. int j; // <- call clang-format on this line. } Before: namespace { int i; int j; } After: namespace { int i; int j; } llvm-svn: 251824
* clang-format: Be slightly more cautious when formatting subsequent lines ↵Daniel Jasper2015-11-011-4/+19
| | | | | | | | | | | | | | | | | after a change. With r251474, clang-format could indent the entire rest of the file, if there is a missing closing brace, e.g. while writing code in an editor. Summary: With this change, clang-format stops formatting when either it leaves the current scope or when it comes back to the initial scope after going into a nested one. Reviewers: klimek Subscribers: cfe-commits, klimek Differential Revision: http://reviews.llvm.org/D14213 llvm-svn: 251760
* Format: support inline namespacesSaleem Abdulrasool2015-10-301-1/+1
| | | | | | | | Correct handling for C++17 inline namespaces. We would previously fail to identify the inline namespaces as a namespace name since multiple ones may be concatenated now with C++17. llvm-svn: 251690
* clang-format: [JS] Add goog.setTestOnly to the list of stuff thatDaniel Jasper2015-10-291-3/+4
| | | | | | is import-statement-like and shouldn't be wrapped. llvm-svn: 251643
* clang-format: When a line is formatted, also format subsequence lines if ↵Daniel Jasper2015-10-281-2/+5
| | | | | | | | | | | | | | their indent is off. Summary: This is especially important so that if a change is solely inserting a block around a few statements, clang-format-diff.py will still clean up and add indentation to the inner parts. Reviewers: klimek Subscribers: cfe-commits, klimek Differential Revision: http://reviews.llvm.org/D14105 llvm-svn: 251474
* clang-format: Increase cut-off limit for number of analyzed states.Daniel Jasper2015-10-271-1/+1
| | | | | | | | | | | With more complex structures in C++ Lambdas and JavaScript function literals, the old value was simply to small. However, this is a temporary solution, I need to look at this more closely a) to find a fundamentally better approach and b) to look at whether the more recent usage of NoLineBreak makes us visit stuff in an unfortunate order where clang-format waste many states in dead ends. llvm-svn: 251463
* clang-format: Undo unwanted format change done in r251405.Daniel Jasper2015-10-272-15/+17
| | | | | | | | Specifically, don't wrap between the {} of an empty constructor if the "}" falls on column 81 and ConstructorInitializerAllOnOneLineOrOnePerLine is set. llvm-svn: 251406
* clang-format: Add an additional value to AlignAfterOpenBracket: AlwaysBreak.Daniel Jasper2015-10-274-21/+44
| | | | | | | | | | | | | | | | | | | | Summary: If this option is set, clang-format will always insert a line wrap, e.g. before the first parameter of a function call unless all parameters fit on the same line. This obviates the need to make a decision on the alignment itself. Use this style for Google's JavaScript style and add some minor tweaks to correctly handle nested blocks etc. with it. Don't use this option for for/while loops. Reviewers: klimek Subscribers: klimek, cfe-commits Differential Revision: http://reviews.llvm.org/D14104 llvm-svn: 251405
* clang-format: Fix false positive in cast detection.Daniel Jasper2015-10-261-1/+2
| | | | | | | | | | Before (with spaces in parentheses): void inFunction() { std::function<void( int, int )> fct; } After: void inFunction() { std::function<void( int, int)> fct; } llvm-svn: 251284
* clang-format: Teach --sort-includes to interleave #include and #import.Nico Weber2015-10-211-4/+5
| | | | | | | | | | clang accepts both #include and #import for includes (the latter having an implicit header guard). Let clang-format interleave both types if --sort-includes is passed. #import is used frequently in Objective-C code. http://reviews.llvm.org/D13853 llvm-svn: 250909
* Roll-back r250822.Angel Garcia Gomez2015-10-205-5/+5
| | | | | | | | | | Summary: It breaks the build for the ASTMatchers Subscribers: klimek, cfe-commits Differential Revision: http://reviews.llvm.org/D13893 llvm-svn: 250827
* Apply modernize-use-default to clang.Angel Garcia Gomez2015-10-205-5/+5
| | | | | | | | | | | | Summary: Replace empty bodies of default constructors and destructors with '= default'. Reviewers: bkramer, klimek Subscribers: klimek, alexfh, cfe-commits Differential Revision: http://reviews.llvm.org/D13890 llvm-svn: 250822
* clang-format: Extend main header include sorting heuristic to Objective-C files.Nico Weber2015-10-191-1/+3
| | | | llvm-svn: 250675
* clang-format: [JS] Handle string literals spanning character classes.Daniel Jasper2015-10-181-92/+80
| | | | | | | | | | | | | | | If a RegExp contains a character group with a quote (/["]/), the trailing end of it is first tokenized as a string literal, which leads to the merging code seeing an unbalanced bracket. This change parses regex literals from the left hand side. That simplifies the parsing code and also allows correctly handling escapes and character classes, hopefully correctly parsing all regex literals. Patch by Martin Probst, thank you. Review: http://reviews.llvm.org/D13765 llvm-svn: 250648
* clang-format/java: Break after annotations on fields in Chromium style.Nico Weber2015-10-152-2/+4
| | | | | | | | | | | Chromium follows the Android style guide for Java code, and that doesn't make the distinction between fields and non-fields that the Google Java style guide makes: https://source.android.com/source/code-style.html#use-standard-java-annotations https://google.github.io/styleguide/javaguide.html#s4.8.5-annotations llvm-svn: 250422
* clang-format: Fixed typecast getting put on a separate line from theDaniel Jasper2015-10-121-1/+3
| | | | | | | | | | key in Obj-C dictionary literals This fixes: https://llvm.org/PR22647 Patch by Kent Sutherland. Thank you. llvm-svn: 250010
* clang-format: [JS] handle character classes in regexes.Daniel Jasper2015-10-121-1/+12
| | | | | | | | | Slashes in regular expressions do not need to be escaped and do not terminate the regular expression even without a preceding backslash. Patch by Martin Probst. Thank you. llvm-svn: 250009
* clang-format: Fixed missing space between Obj-C for/in and a typecast.Daniel Jasper2015-10-071-1/+2
| | | | | | | | | | | | | | | | | Fixes this bug: https://llvm.org/bugs/show_bug.cgi?id=24504 TokenAnnotator::spaceRequiredBetween was handling TT_ForEachMacro but not TT_ObjCForIn, so lines that look like: for (id nextObject in (NSArray *)myArray) would incorrectly turn into: for (id nextObject in(NSArray *)myArray) Patch by Kent Sutherland, thank you. llvm-svn: 249553
* [clang-format] Stop alignment sequences on open braces and parens whenDaniel Jasper2015-10-071-8/+28
| | | | | | | | | | | | | | | | | aligning assignments. This was done correctly when aligning the declarations, but not when aligning assignments. FIXME: The code between assignments and declarations alignment is roughly duplicated and would benefit from factorization. Bug 25090: https://llvm.org/bugs/show_bug.cgi?id=25090 Patch by Beren Minor. Thank you. llvm-svn: 249552
* Make clang-format actually respect custom brace wrapping flags.Daniel Jasper2015-10-071-0/+4
| | | | | | This fixes llvm.org/PR25073. llvm-svn: 249519
* clang-format: Fix false ObjC block detection.Daniel Jasper2015-10-071-0/+5
| | | | | | | | | | | Before: inline A operator^(const A &lhs, const A &rhs) {} int i; After: inline A operator^(const A &lhs, const A &rhs) {} int i; llvm-svn: 249517
* clang-format: Understand array reference types.Daniel Jasper2015-10-071-1/+1
| | | | | | | | | | | | Before: void f(Type(&parameter)[10]) {} void f(Type (*parameter)[10]) {} After: void f(Type (&parameter)[10]) {} void f(Type (*parameter)[10]) {} llvm-svn: 249502
* clang-format: Fix false positive in pointer/reference detection.Daniel Jasper2015-10-071-1/+3
| | | | | | | | | | Before: return options != nullptr &&operator==(*options); After: return options != nullptr && operator==(*options); llvm-svn: 249501
* clang-format: Make IncludeCategories configurable in .clang-format file.Daniel Jasper2015-10-061-3/+12
| | | | | | | | | This was made much easier by introducing an IncludeCategory struct to replace the previously used std::pair. Also, cleaned up documentation and added examples. llvm-svn: 249392
* [VFS] Transition clang-format to use an in-memory FS.Benjamin Kramer2015-10-061-8/+7
| | | | | | | | | | | Apart from being cleaner this also means that clang-format no longer has access to the host file system. This isn't necessary because clang-format never reads includes :) Includes minor tweaks and bugfixes found in the VFS implementation while running clang-format tests. llvm-svn: 249385
* Add -f[no-]declspec to control recognition of __declspec as a keywordSaleem Abdulrasool2015-10-041-0/+1
| | | | | | | | | | | | | | | In versions of clang prior to r238238, __declspec was recognized as a keyword in all modes. It was then changed to only be enabled when Microsoft or Borland extensions were enabled (and for CUDA, as a temporary measure). There is a desire to support __declspec in Playstation code, and possibly other environments. This commit adds a command-line switch to allow explicit enabling/disabling of the recognition of __declspec as a keyword. Recognition is enabled by default in Microsoft, Borland, CUDA, and PS4 environments, and disabled in all other environments. Patch by Warren Ristow! llvm-svn: 249279
* SourceRanges are small and trivially copyable, don't them by reference.Craig Topper2015-10-042-4/+4
| | | | llvm-svn: 249259
* [clang-format] Add support of consecutive declarations alignmentDaniel Jasper2015-10-013-11/+146
| | | | | | | | | | | | | | | | | | | This allows clang-format to align identifiers in consecutive declarations. This is useful for increasing the readability of the code in the same way the alignment of assignations is. The code is a slightly modified version of the consecutive assignment alignment code. Currently only the identifiers are aligned, and there is no support of alignment of the pointer star or reference symbol. The patch also solve the issue of alignments not being possible due to the ColumnLimit for both the existing AlignConsecutiveAligments and the new AlignConsecutiveDeclarations. Patch by Beren Minor, thank you. Review: http://reviews.llvm.org/D12362 llvm-svn: 248999
OpenPOWER on IntegriCloud