summaryrefslogtreecommitdiffstats
path: root/clang/lib/Format
Commit message (Collapse)AuthorAgeFilesLines
...
* clang-format: [JS] avoid indent after ambient function declarations.Martin Probst2017-01-041-1/+4
| | | | | | | | | | | | | | | | | | | | | Summary: Before: declare function foo(); let x = 1; After: declare function foo(); let x = 1; The problem was that clang-format would unconditionally try to parse a child block, even though ambient function declarations do not have a body (similar to forward declarations). Reviewers: djasper Subscribers: cfe-commits, klimek Differential Revision: https://reviews.llvm.org/D28246 llvm-svn: 290959
* Change clang-format's Chromium JavaScript defaultsNico Weber2017-01-041-0/+3
| | | | | | | | | | | | | | Chromium is starting to use clang-format on more JavaScript. In doing this, we discovered that our defaults were not doing a good job differentiating between JS and C++. This change moves some defaults to only apply to C++. https://reviews.llvm.org/D28165 Patch from Dan Beam <dbeam@chromium.org>! llvm-svn: 290930
* Use after move bug fixesPiotr Padlewski2016-12-233-10/+15
| | | | | | | | | | | | Summary: Bunch of fixed bugs in Clang after running misc-use-after-move in clang-tidy. Reviewers: rsmith, mboehme Subscribers: cfe-commits, klimek Differential Revision: https://reviews.llvm.org/D27752 llvm-svn: 290424
* clang-format: Less eagerly try to keep label-value pairs on a line.Daniel Jasper2016-12-221-1/+1
| | | | | | | | | | | | | | | Before: string v = StrCat("aaaaaaaaaaaaaaaaaaaaaaaaaaa: ", SomeFunction(aaaaaaaaaaaa, aaaaaaaaaaaaaaa), bbbbbbbbbbbbbbbbbbbbbbb); After: string v = StrCat("aaaaaaaaaaaaaaaaaaaaaaaaaaa: ", SomeFunction(aaaaaaaaaaaa, aaaaaaaaaaaaaaa), bbbbbbbbbbbbbbbbbbbbbbb); llvm-svn: 290337
* Make FormatStyle.GetStyleOfFile test work on MSVCAntonio Maiorano2016-12-221-1/+5
| | | | | | | | | | | Modify getStyle to use vfs::FileSystem::makeAbsolute just like FS.addFile does, rather than sys::fs::make_absolute. The latter gets the CWD from the platform, while the former expects it to be set by the client, causing a mismatch when converting relative paths to absolute. Differential Revision: https://reviews.llvm.org/D27971 llvm-svn: 290319
* clang-format: Fix bug in handling of single-column lists.Daniel Jasper2016-12-211-8/+6
| | | | | | | | | | | | | | | | | | | Members that are themselves wrapped in fake parentheses would lead to AvoidBinPacking be set on the wrong ParenState. After: vector<int> aaaa = { aaaaaa.aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa, aaaaaa.aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa, aaaaaa.aaaaaaa, aaaaaa.aaaaaaa, aaaaaa.aaaaaaa, aaaaaa.aaaaaaa, }; Before we were falling back to bin-packing these. llvm-svn: 290259
* clang-format: Fix bug in understanding string-label&value analysis.Daniel Jasper2016-12-201-2/+5
| | | | | | | | | | | | | | | While for <<-operators often used in log statments, a single key value pair is always on the second operator, e.g. llvm::errs() << "aaaaa=" << aaaaa; It is on the first operator for plus- or comma-concatenated strings: string s = "aaaaaaaaaa: " + aaaaaaaa; (the "=" not counting because that's a different operator precedence) llvm-svn: 290177
* [Format] Remove dead code.Benjamin Kramer2016-12-194-31/+0
| | | | | | No functionality change. llvm-svn: 290135
* clang-format: Slightly tweak the behavior of <<-wrapping.Daniel Jasper2016-12-192-3/+8
| | | | | | | | | | | | | | | Before: SomeLongLoggingStatementOrMacro() << "Some long text " << some_variable << "\n"; Before: SomeLongLoggingStatementOrMacro() << "Some long text " << some_variable << "\n"; Short logging statements are already special cased in a different part of the code. llvm-svn: 290094
* [clang-format] revert an unintended change in r288493 and add a test case.Eric Liu2016-12-191-1/+1
| | | | llvm-svn: 290093
* clang-format: Fix regression introduced in r290084.Daniel Jasper2016-12-191-0/+8
| | | | | | | | | | | | | | | | | | | We still want to try in linewrap within single elements of a 1-column list. After: Type *Params[] = {PointerType::getUnqual(FunctionType::get( Builder.getVoidTy(), Builder.getInt8PtrTy(), false)), Builder.getInt8PtrTy(), Builder.getInt32Ty(), LongType, LongType, LongType}; Before: No line break in the first element, so column limit violation. llvm-svn: 290090
* clang-format: Allow "single column" list layout even if that violates theDaniel Jasper2016-12-191-2/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | column limit. Single-column layout basically means that we format the list with one element per line. Not doing that when there is a column limit violation doesn't change the fact that there is an item that doesn't fit within the column limit. Before (with a column limit of 30): std::vector<int> a = { aaaaaaaa, aaaaaaaa, aaaaaaaa, aaaaaaaa, aaaaaaaaaa, aaaaaaaa, aaaaaaaaaaaaaaaaaaaaaaaaaaa}; After: std::vector<int> a = { aaaaaaaa, aaaaaaaa, aaaaaaaa, aaaaaaaa, aaaaaaaaaa, aaaaaaaa, aaaaaaaaaaaaaaaaaaaaaaaaaaa}; (and previously we would have formatted like "After" it wasn't for the one item that is too long) llvm-svn: 290084
* Update the default of the Mozilla coding styleSylvestre Ledru2016-12-141-1/+3
| | | | | | | | | | | | | | Summary: I also proposed the change in Firefox .clang-format file: https://bugzilla.mozilla.org/show_bug.cgi?id=1322321 Reviewers: klimek Subscribers: cfe-commits Differential Revision: https://reviews.llvm.org/D27557 llvm-svn: 289660
* clang-format: Keep string-literal-label + value pairs on a line.Daniel Jasper2016-12-132-17/+28
| | | | | | | | | | | | | | | | | | | | | We have previously done that for <<-operators. This patch also adds this logic for "," and "+". Before: string v = "aaaaaaaaaaaaaaaa: " + aaaaaaaaaaaaaaaa + "aaaaaaaaaaaaaaaa: " + aaaaaaaaaaaaaaaa + "aaaaaaaaaaaaaaaa: " + aaaaaaaaaaaaaaaa; string v = StrCat("aaaaaaaaaaaaaaaa: ", aaaaaaaaaaaaaaaa, "aaaaaaaaaaaaaaaa: ", aaaaaaaaaaaaaaaa, "aaaaaaaaaaaaaaaa: ", aaaaaaaaaaaaaaaa); After: string v = "aaaaaaaaaaaaaaaa: " + aaaaaaaaaaaaaaaa + "aaaaaaaaaaaaaaaa: " + aaaaaaaaaaaaaaaa + "aaaaaaaaaaaaaaaa: " + aaaaaaaaaaaaaaaa; string v = StrCat("aaaaaaaaaaaaaaaa: ", aaaaaaaaaaaaaaaa, "aaaaaaaaaaaaaaaa: ", aaaaaaaaaaaaaaaa, "aaaaaaaaaaaaaaaa: ", aaaaaaaaaaaaaaaa); llvm-svn: 289531
* clang-format: Improve braced-list detection.Daniel Jasper2016-12-131-2/+2
| | | | | | | | | | | Before: vector<int> v { 12 } GUARDED_BY(mutex); After: vector<int> v{12} GUARDED_BY(mutex); llvm-svn: 289525
* clang-format: Separate out a language kind for ObjC.Daniel Jasper2016-12-124-4/+23
| | | | | | | | | | | | | While C(++) and ObjC are generally formatted the same way and can be mixed, people might want to choose different styles based on the language. This patch recognizes .m and .mm files as ObjC and also implements a very crude detection of whether or not a .h file contains ObjC code. This can be improved over time. Also move most of the ObjC tests into their own test file to keep file size maintainable. llvm-svn: 289428
* [clang-format] calculate MaxInsertOffset in the original code correctly.Eric Liu2016-12-091-0/+2
| | | | | | | | | | Reviewers: djasper Subscribers: klimek, cfe-commits Differential Revision: https://reviews.llvm.org/D27615 llvm-svn: 289203
* [ClangFormat] Only insert #include into the #include block in the beginning ↵Eric Liu2016-12-021-30/+100
| | | | | | | | | | | | | | | | | | of the file. Summary: This avoid inserting #include into: - raw string literals containing #include. - #if block. - Special #include among declarations (e.g. functions). Reviewers: djasper Subscribers: cfe-commits, klimek Differential Revision: https://reviews.llvm.org/D26909 llvm-svn: 288493
* Removed DEBUG_TYPE from TokenAnalyzer.hKrasimir Georgiev2016-11-291-2/+0
| | | | | | | | | | | | | | Summary: Defining DEBUG_TYPE in a header file doesn't make sense. It is already defined in the corresponding source file. Reviewers: klimek, ioeric Subscribers: klimek Differential Revision: https://reviews.llvm.org/D27164 llvm-svn: 288125
* clang-format: [JS] Properly format dict literals that skip labels.Daniel Jasper2016-11-291-0/+3
| | | | llvm-svn: 288121
* clang-format: Wrap complex binary expressions on the RHS of a comma.Daniel Jasper2016-11-291-1/+1
| | | | | | | | | Specifically, if the RHS of a comma is a complex binary expression and spans multiple lines, insert a line break before it. This usually is often more readable compared to producing a hanging indent. See changes in FormatTest.cpp for examples. llvm-svn: 288120
* clang-format: Fix unnnecessary line break.Daniel Jasper2016-11-291-1/+2
| | | | | | | | | | | | | | | Before: aaaaaaaaaa(aaaa(aaaa, aaaa), // aaaa, aaaaa); After: aaaaaaaaaa(aaaa(aaaa, aaaa), // aaaa, aaaaa); llvm-svn: 288119
* [Format] Avoid copying std::sets and simplify code a bit.Benjamin Kramer2016-11-241-3/+3
| | | | | | No functional change. llvm-svn: 287892
* [clang-format] Fixed line merging of more than two linesCameron Desrochers2016-11-151-1/+1
| | | | | | Differential Revision: https://reviews.llvm.org/D19063 llvm-svn: 286973
* clang-format: Support ObjC selectors with unnamed parameters.Daniel Jasper2016-11-122-9/+33
| | | | | | This fixes llvm.org/PR28063. llvm-svn: 286715
* [clang-format] Fix PR30527: Regression when clang-format insert spaces in [] ↵Nico Weber2016-11-101-2/+12
| | | | | | | | | | | | | | | | | | | | when in template Actual regression was introduced in r272668. This revision fixes JS script, but also regress Cpp case. It manifests with spaces added when template is followed with array. Bug 30527 mentions case of array as a nested template type (foo<bar<baz>[]>). Fix is to detect such case and to prevent treating it as array initialization, but as a subscript case. However, before r272668, this case was treated simple because we were detecting it as a StartsObjCMethodExpr. Same was true for other similar case - array of templates (foo<int>[]). This patch tries to address two problems: 1) fixing regression 2) making sure both cases (array as a nested type, array of templates) which were entering StartsObjCMethodExpr branch are handled now appropriately. https://reviews.llvm.org/D26163 Patch from Branko Kokanovic <branko@kokanovic.org>! llvm-svn: 286507
* drop kw_module from ASI protection blockMartin Probst2016-11-101-2/+2
| | | | llvm-svn: 286469
* clang-format: [JS] do not break after declare namespace.Martin Probst2016-11-101-8/+8
| | | | | | | | | | | | | | | | | Summary: See TypeScript grammar for tokens following 'declare': https://github.com/Microsoft/TypeScript/blob/master/doc/spec.md#A.10 Additional minor change: clang-format: [JS] Prevent ASI before const. Reviewers: djasper Subscribers: cfe-commits, klimek Differential Revision: https://reviews.llvm.org/D26274 llvm-svn: 286468
* clang-format: [JS] do not break after declare namespace.Martin Probst2016-11-102-2/+18
| | | | | | | See TypeScript grammar for tokens following 'declare': https://github.com/Microsoft/TypeScript/blob/master/doc/spec.md#A.10 llvm-svn: 286467
* clang-format: [TypeScript] Fix bug in handling of non-null operator.Daniel Jasper2016-11-091-1/+7
| | | | | | | | | | Before: var i = x!-1; After: var i = x! - 1; llvm-svn: 286367
* [clang-format] Remove (SourceManager, FileID) variantsDaniel Jasper2016-11-081-19/+0
| | | | | | | | | | | | | In Format, remove the reformat() and clean() functions taking a SourceManager and a FileID. Keep the versions taking StringRef Code. - there was duplicated functionality - the FileID versions were harder to use - the clean() version is dead code anyways Patch by Krasimir Georgiev. Thank you. llvm-svn: 286243
* clang-format: Better support for CUDA's triple brackets.Daniel Jasper2016-11-051-0/+2
| | | | | | | | | | | | | Before: aaaaaaaaaaaaaaa< aaaaaaaaa, aaaaaaaaaa, aaaaaaaaaaaaaa><<<aaaaaaaaa, aaaaaaaaaa, aaaaaaaaaaaaaaaaaa>>>(); After: aaaaaaaaaaaaaaa<aaaaaaaaa, aaaaaaaaaa, aaaaaaaaaaaaaa> <<<aaaaaaaaa, aaaaaaaaaa, aaaaaaaaaaaaaaaaaa>>>(); llvm-svn: 286041
* Fixed column shift when formatting line containing bit shift operatorsMalcolm Parsons2016-11-031-0/+2
| | | | | | | | | | | | | | | | | | | Summary: During clang-format source lexing >> and << operators are split and treated as two less/greater operators but column position of following tokens was not adjusted accordingly. Fixes PR26887 Patch by Paweł Żukowski. Reviewers: djasper Subscribers: malcolm.parsons, mprobst, klimek, cfe-commits Differential Revision: https://reviews.llvm.org/D25439 llvm-svn: 285934
* clang-format: Fix bug in function reference qualifier detection.Daniel Jasper2016-11-011-1/+1
| | | | | | | | | | | | | Before: template <typename T> void F(T) && = delete; After: template <typename T> void F(T) && = delete; llvm-svn: 285674
* clang-format: Fix incorrect pointer detection.Daniel Jasper2016-11-011-2/+3
| | | | | | | | | | Before: void f() { f(float{1}, a *a); } After: void f() { f(float{1}, a * a); } llvm-svn: 285673
* clang-format: [JS] Fix incorrect space when "as" is used as identifier.Daniel Jasper2016-11-011-1/+1
| | | | | | | | | | Before: aaaaa.as (); After: aaaaa.as(); llvm-svn: 285672
* clang-format: Fix incorrect binary operator detection.Daniel Jasper2016-11-011-1/+1
| | | | | | | | | | Before: int x = f(* + [] {}); After: int x = f(*+[] {}); llvm-svn: 285671
* clang-format: [JS] Fix formatting of generator functions.Daniel Jasper2016-11-012-3/+6
| | | | | | | | | | | | | | | | | | | Before: var x = { a: function* () { // } } After: var x = { a: function*() { // } } llvm-svn: 285670
* clang-format: [JS] Fix space when for is used as regular identifier.Daniel Jasper2016-11-011-0/+3
| | | | | | | | | | Before: x.for () = 1; After: x.for() = 1; llvm-svn: 285669
* Skip over AnnotatedLines with >50 levels of nesting; don't format them.Daniel Jasper2016-10-311-0/+15
| | | | | | | | | | | | | | | Reasoning: - ExpressionParser uses a lot of stack for these, bad in some environments. - Our formatting algorithm is N^3 and gets really slow. - The resulting formatting is unlikely to be any good. - This is probably generated code we're formatting by accident. We treat these as unparseable, and signal incomplete formatting. 50 is an arbitrary number, I've only seen real problems from ~150 levels. Patch by Sam McCall. Thank you. llvm-svn: 285570
* clang-format: [JS] Fix missing space after 'yield'.Daniel Jasper2016-10-311-0/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Before: class X { delete(val) { return null; } * gen() { yield[1, 2]; } * gen() { yield{a: 1}; } }; After: class X { delete(val) { return null; } * gen() { yield [1, 2]; } * gen() { yield {a: 1}; } }; llvm-svn: 285569
* Bug 28065 - clang-format incorrectly aligns backslash.Andi-Bogdan Postelnicu2016-10-261-1/+1
| | | | llvm-svn: 285178
* clang-format: [JS] Fix template string ASI.Martin Probst2016-10-211-3/+8
| | | | | | | | | | | | | | | | | | | Summary: Previously, automatic semicolon insertion would add an unwrapped line when a template string contained a line break. var x = `foo${ bar}`; Would be formatted with `bar...` on a separate line and no indent. Reviewers: djasper Subscribers: cfe-commits, klimek Differential Revision: https://reviews.llvm.org/D25675 llvm-svn: 284807
* [Format] Cleanup after replacing constructor body with = defaultMalcolm Parsons2016-10-202-1/+3
| | | | | | | | | | | | | | Summary: Remove colon and commas after replacing constructor body with = default. Fix annotation of TT_CtorInitializerColon when preceded by a comment. Reviewers: djasper Subscribers: cfe-commits, klimek Differential Revision: https://reviews.llvm.org/D25768 llvm-svn: 284732
* Use noexcept instead of LLVM_NOEXCEPT now that all compilers support itReid Kleckner2016-10-191-1/+1
| | | | llvm-svn: 284667
* Don't copy replacements in for-range loop. NFC.Benjamin Kramer2016-10-191-1/+1
| | | | llvm-svn: 284589
* [clang-format] Add comment manipulation headerEric Liu2016-10-194-15/+71
| | | | | | | | | | | | | | | | | | | Summary: Introduces a separate target for comment manipulation. Currently, comment manipulation is in BreakableComment.cpp. Towards implementing comment reflowing, we want to factor out the comment-related functionality, so it can be reused. Start simple by just moving out getLineCommentIndentPrefix. Patch by Krasimir Georgiev! Reviewers: djasper Subscribers: klimek, beanz, mgorny, modocache Differential Revision: https://reviews.llvm.org/D25725 llvm-svn: 284573
* Removed duplicate header includeEric Liu2016-10-141-2/+1
| | | | | | | | | | | | Reviewers: ioeric Subscribers: klimek Patch by Krasimir Georgiev! Differential Revision: https://reviews.llvm.org/D25599 llvm-svn: 284228
* Make DeletedLines local variables in checkEmptyNamespace.Eric Liu2016-10-051-5/+6
| | | | | | | | | | | | Summary: Patch by Sam McCall! Reviewers: djasper Subscribers: klimek, cfe-commits Differential Revision: https://reviews.llvm.org/D25162 llvm-svn: 283332
* [clang-format] append newline after code when inserting new headers at the ↵Eric Liu2016-10-051-0/+9
| | | | | | | | | | | | | | | | end of the code which does not end with newline. Summary: append newline after code when inserting new headers at the end of the code which does not end with newline. Reviewers: djasper Subscribers: cfe-commits, klimek Differential Revision: https://reviews.llvm.org/D21026 llvm-svn: 283330
OpenPOWER on IntegriCloud