summaryrefslogtreecommitdiffstats
path: root/clang/unittests
Commit message (Collapse)AuthorAgeFilesLines
...
* clang-format: Don't force-wrap multiline RHSs for 2-operand experssions.Daniel Jasper2017-02-011-25/+55
| | | | | | | | | | | | | | | | | | | | This rows back on r288120, r291801 and r292110. I apologize in advance for the churn. All of those revisions where meant to make the wrapping of RHS expressions more consistent. However, now that they are consistent, we seem to be a bit too eager. The reasoning here is that I think it is generally correct that we want to line-wrap before multiline RHS expressions (or multiline arguments to a function call). However, if there are only two of such operands or arguments, there is always a clear vertical separation between them and the additional line break seems much less desirable. Somewhat good examples are expressions like: EXPECT_EQ(2, someLongExpression( orCall)); llvm-svn: 293752
* [clang-format] Fix regression about adding leading whitespace to the content ↵Krasimir Georgiev2017-01-311-0/+19
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | of line comments Summary: The reflower didn't measure precisely the line column of a line in the middle of a line comment section that has a prefix that needs to be adapted. source: ``` /// a //b ``` format before: ``` /// a //b ``` format after: ``` /// a // b ``` Reviewers: djasper Reviewed By: djasper Subscribers: sammccall, cfe-commits, klimek Differential Revision: https://reviews.llvm.org/D29329 llvm-svn: 293641
* clang-format: [JS] Indent expressions in ${} relative to their surroundingDaniel Jasper2017-01-311-0/+57
| | | | | | | | | | | | | | | | | | | | This only affects expressions inside ${} scopes of template strings. Here, we want to indent relative to the surrounding template string and not the surrounding expression. Otherwise, this can create quite a mess. Before: var f = ` aaaaaaaaaaaaaaaaaa: ${someFunction( aaaaa + // bbbb)}`; After: var f = ` aaaaaaaaaaaaaaaaaa: ${someFunction( aaaaa + // bbbb)}`; llvm-svn: 293636
* [clang-format] Fix reflow in block comment lines with leading whitespace.Krasimir Georgiev2017-01-311-0/+17
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Summary: The reflower was not taking into account the additional leading whitespace in block comment lines. source: ``` { /* * long long long long * long * long long long long */ } ``` format (with column limit 20) before: ``` { /* * long long long * long long long long * long long */ } ``` format after: ``` { /* * long long long * long long long * long long long */ } ``` Reviewers: djasper, klimek Reviewed By: djasper Subscribers: cfe-commits, sammccall, klimek Differential Revision: https://reviews.llvm.org/D29326 llvm-svn: 293633
* [clang-format] Fix regression merging comments across newlines.Krasimir Georgiev2017-01-311-0/+18
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Summary: This fixes a regression that causes example: ``` enum A { a, // line a // line b b }; ``` to be formatted as follows: ``` enum A { a, // line a // line b b }; ``` Reviewers: djasper, klimek Reviewed By: klimek Subscribers: cfe-commits, sammccall, djasper, klimek Differential Revision: https://reviews.llvm.org/D29322 llvm-svn: 293624
* clang-format: [JS] Properly set scopes inside template strings.Daniel Jasper2017-01-311-0/+7
| | | | | | | | | | | | | Before: var f = `aaaaaaaaaaaaa:${aaaaaaa .aaaaa} aaaaaaaa aaaaaaaaaaaaa:${aaaaaaa.aaaaa} aaaaaaaa`; After: var f = `aaaaaaaaaaaaa:${aaaaaaa.aaaaa} aaaaaaaa aaaaaaaaaaaaa:${aaaaaaa.aaaaa} aaaaaaaa`; llvm-svn: 293622
* clang-format: [JS] Fix incorrect line break in template strings.Daniel Jasper2017-01-311-0/+4
| | | | | | | | | | | Before: var f = `aaaa ${a ? 'a' : 'b' }`; After: var f = `aaaa ${a ? 'a' : 'b'}`; llvm-svn: 293618
* [clang-format] Don't reflow comment lines starting with '@'.Krasimir Georgiev2017-01-311-0/+9
| | | | | | | | | | | | | | | | Summary: This patch stops reflowing comment lines starting with '@', since they commonly have a special meaning. Reviewers: djasper Reviewed By: djasper Subscribers: cfe-commits, klimek Differential Revision: https://reviews.llvm.org/D29323 llvm-svn: 293617
* [clang-format] Fix regression that breaks comments without a comment prefixKrasimir Georgiev2017-01-301-0/+12
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Summary: Consider formatting the following code fragment with column limit 20: ``` { // line 1 // line 2\ // long long long line } ``` Before this fix the output is: ``` { // line 1 // line 2\ // long long long line } ``` This patch fixes a regression that breaks the last comment line without adding the '//' prefix. Reviewers: djasper Reviewed By: djasper Subscribers: cfe-commits, klimek Differential Revision: https://reviews.llvm.org/D29298 llvm-svn: 293548
* [clang-format] Separate line comment sections after a right brace from ↵Krasimir Georgiev2017-01-301-0/+58
| | | | | | | | | | | | | | | | | | | | | | | | | | | comment sections in the scope. Summary: The following two comment lines form a single comment section: ``` if (1) { // line 1 // line 2 } ``` This is because the break of a comment section was based on the original column of the first token of the previous line (in this case, the 'if'). This patch splits these two comment lines into different sections by taking into account the original column of the right brace preceding the first line comment where applicable. Reviewers: djasper Reviewed By: djasper Subscribers: cfe-commits, klimek Differential Revision: https://reviews.llvm.org/D29291 llvm-svn: 293539
* clang-format: [JavaScript] Undo r291974 for JavaScript.Daniel Jasper2017-01-301-0/+10
| | | | | | | | | | | | | | | | | | | | | This had significant negative consequences and I don't have a good solution for it yet. Before: var string = [ 'aaaaaa', 'bbbbbb', ] .join('+'); After: var string = [ 'aaaaaa', 'bbbbbb', ].join('+'); llvm-svn: 293465
* clang-format: [JS] do not format MPEG transport streams.Martin Probst2017-01-271-0/+9
| | | | | | | | | | | | | | | Summary: The MPEG transport stream file format also uses ".ts" as its file extension. This change detects its specific framing format (0x47 every 189 bytes) and simply ignores MPEG TS files. Reviewers: djasper, sammccall Subscribers: klimek, cfe-commits Differential Revision: https://reviews.llvm.org/D29186 llvm-svn: 293270
* [clang-format] Implement comment reflowing.Krasimir Georgiev2017-01-252-5/+486
| | | | | | | | | | | | | | | | | | Summary: This presents a version of the comment reflowing with less mutable state inside the comment breakable token subclasses. The state has been pushed into the driving breakProtrudingToken method. For this, the API of BreakableToken is enriched by the methods getSplitBefore and getLineLengthAfterSplitBefore. Reviewers: klimek Reviewed By: klimek Subscribers: djasper, klimek, mgorny, cfe-commits, ioeric Differential Revision: https://reviews.llvm.org/D28764 llvm-svn: 293055
* clang-format: fix fallback style set to "none" not always formattingAntonio Maiorano2017-01-201-1/+19
| | | | | | | | | | | This fixes clang-format not formatting if fallback-style is explicitly set to "none", and either a config file is found or YAML is passed in without a "BasedOnStyle". With this change, passing "none" in these cases will have no affect, and LLVM style will be used as the base style. Differential Revision: https://reviews.llvm.org/D28844 llvm-svn: 292562
* clang-format: Make GetStyle return Expected<FormatStyle> instead of FormatStyleAntonio Maiorano2017-01-172-9/+42
| | | | | | | | | | Change the contract of GetStyle so that it returns an error when an error occurs (i.e. when it writes to stderr), and only returns the fallback style when it can't find a configuration file. Differential Revision: https://reviews.llvm.org/D28081 llvm-svn: 292174
* clang-format: Always wrap before multi-line parameters/operands.Daniel Jasper2017-01-161-24/+32
| | | | | | | | | | | | | | | | | Before: aaaaaaaaaaaaaaaaaa(aaaaaaaa, aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa:: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa, aaaaaaaaaaaaaaaaaaaaa); After: aaaaaaaaaaaaaaaaaa(aaaaaaaa, aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa:: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa, aaaaaaaaaaaaaaaaaaaaa); No new test cases, as the existing ones cover this fairly well. llvm-svn: 292110
* clang-format: [JS] revert over-eager ASI check.Martin Probst2017-01-161-4/+22
| | | | | | | | | | | | Summary: Change r291428 introduced ASI detection after closing curly braces. That would generally be correct, however this breaks indentation for structural statements. What happens is that CompoundStatementIndenter increases indentation for the current line, then after reading ASI creates a new line (with the increased line level), and only after the structural parser sees e.g. the if/then/else branch closed, line level is reduced. That leads to the new line started by ASI having a level too high. Reviewers: djasper Subscribers: sammccall, cfe-commits, klimek Differential Revision: https://reviews.llvm.org/D28763 llvm-svn: 292099
* clang-format: Fix bug in making line break decisions.Daniel Jasper2017-01-131-0/+6
| | | | | | | | | | | | | | | | | | | | | Here, the optimization to not line wrap when it would not lead to a reduction in columns was overwriting and enforced break that we want to do no matter what. Before: int i = someFunction( aaaaaaa, 0).aaa(aaaaaaaaaaaaa) * aaaaaaa + aaaaaaa; After: int i = someFunction(aaaaaaa, 0) .aaa(aaaaaaaaaaaaa) * aaaaaaa + aaaaaaa; llvm-svn: 291974
* Fix shared library build after r291938 by adding missing dependency on libOptionDavid Blaikie2017-01-131-0/+1
| | | | | | Thanks to Reid Kleckner for the help reproducing/fixing. llvm-svn: 291953
* clang-format: Fix regression introduced by r291801.Daniel Jasper2017-01-121-0/+2
| | | | | | | | | | | | | | Uncovered by polly tests. Before: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa(aaaaaaaaaaaaaaaaaaa, {}, aaaaaaaaaaaaaaaaaaaaaaa); After: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa(aaaaaaaaaaaaaaaaaaa, {}, aaaaaaaaaaaaaaaaaaaaaaa); llvm-svn: 291807
* clang-format: Treat braced lists like other complex parameters.Daniel Jasper2017-01-121-0/+6
| | | | | | | | | | | | | | | | | Specifically, wrap before them if they are multi-line so that we don't create long hanging indents. This prevents having a lot of code indented a lot in some cases. Before: someFunction(Param, {List1, List2, List3}); After: someFunction(Param, {List1, List2, List3}); llvm-svn: 291801
* Tracking exception specification source locationsMalcolm Parsons2017-01-121-0/+67
| | | | | | | | | | | | | | | | | | | | Summary: We do not currently track the source locations for exception specifications such that their source range can be queried through the AST. This leads to trying to write more complex code to determine the source range for uses like FixItHints (see D18575 for an example). In addition to use within tools like clang-tidy, I think this information may become more important to track as exception specifications become more integrated into the type system. Patch by Don Hinton. Reviewers: rsmith Subscribers: malcolm.parsons, sbarzowski, alexfh, hintonda, cfe-commits Differential Revision: https://reviews.llvm.org/D20428 llvm-svn: 291771
* clang-format: Improve support for override/final as variable names.Daniel Jasper2017-01-091-0/+4
| | | | | | | | | | | | | | | | Before: bool a = f() &&override.f(); bool a = f() &&final.f(); void f(const MyOverride & override); void f(const MyFinal & final); After: bool a = f() && override.f(); bool a = f() && final.f(); void f(const MyOverride &override); void f(const MyFinal &final); llvm-svn: 291434
* clang-format: [JS] fix broken test.Martin Probst2017-01-091-1/+3
| | | | llvm-svn: 291429
* clang-format: [JS] ASI after importsMartin Probst2017-01-091-0/+18
| | | | | | | | | | | | | | | | | | | | | | | | | | | Summary: Automatic semicolon insertion should break import and export statements: Before, this would format on one line: // Note: no semi after 'x' below! import {x} from 'x' export function foo() {} Into: import {x} from 'x' export function foo() {} With this change, the statements get separated. This also improves automatic semicolon insertion to consider closing braces preceding declarations and statements. Reviewers: klimek Subscribers: cfe-commits Differential Revision: https://reviews.llvm.org/D28465 llvm-svn: 291428
* Reapply "IntrusiveRefCntPtr -> std::shared_ptr for CompilerInvocationBase ↵David Blaikie2017-01-063-14/+14
| | | | | | | | | | | | | | and CodeCompleteConsumer" Aleksey Shlypanikov pointed out my mistake in migrating an explicit unique_ptr to auto - I was expecting the function returned a unique_ptr, but instead it returned a raw pointer - introducing a leak. Thanks Aleksey! This reapplies r291184, reverted in r291249. llvm-svn: 291270
* Revert "IntrusiveRefCntPtr -> std::shared_ptr for CompilerInvocationBase and ↵David Blaikie2017-01-063-14/+14
| | | | | | | | | | CodeCompleteConsumer" Caused a memory leak reported by asan. Reverting while I investigate. This reverts commit r291184. llvm-svn: 291249
* shared_ptrify (from InclusiveRefCntPtr) HeaderSearchOptionsDavid Blaikie2017-01-064-15/+14
| | | | llvm-svn: 291202
* IntrusiveRefCntPtr -> std::shared_ptr for CompilerInvocationBase and ↵David Blaikie2017-01-053-14/+14
| | | | | | CodeCompleteConsumer llvm-svn: 291184
* Move PreprocessorOptions to std::shared_ptr from IntrusiveRefCntPtrDavid Blaikie2017-01-054-14/+15
| | | | llvm-svn: 291160
* TypoJoerg Sonnenberger2017-01-051-2/+2
| | | | llvm-svn: 291148
* [gtest] The way EXPECT_TEST now works after upgrading gtest triggers anChandler Carruth2017-01-041-3/+6
| | | | | | | | ODR use. These traits don't have a definition as they're intended to be used strictly at compile time. Change the tests to use static_assert to move the entire thing into compile-time. llvm-svn: 291036
* clang-format: [JS] avoid indent after ambient function declarations.Martin Probst2017-01-041-0/+10
| | | | | | | | | | | | | | | | | | | | | 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
* [clang-tidy] Add check name to YAML exportAlexander Kornienko2017-01-031-9/+2
| | | | | | | | | | | | Add a field indicating the associated check for every replacement to the YAML report generated with the '-export-fixes' option. Update clang-apply-replacements to handle the new format. Patch by Alpha Abdoulaye! Differential revision: https://reviews.llvm.org/D26137 llvm-svn: 290892
* DR1315: a non-type template argument in a partial specialization is permittedRichard Smith2016-12-281-2/+2
| | | | | | | | | | to make reference to template parameters. This is only a partial implementation; we retain the restriction that the argument must not be type-dependent, since it's unclear how that would work given the existence of other language rules requiring an exact type match in this context, even for type-dependent cases (a question has been raised on the core reflector). llvm-svn: 290647
* [ASTMatchers] Add hasInClassInitializer traversal matcher for FieldDecl.Malcolm Parsons2016-12-241-0/+10
| | | | | | | | | | | | | | | Summary: I needed to know whether a FieldDecl had an in-class initializer for D26453. I used a narrowing matcher there, but a traversal matcher might be generally useful. Reviewers: sbenza, bkramer, klimek, aaron.ballman Subscribers: aaron.ballman, Prazek, cfe-commits Differential Revision: https://reviews.llvm.org/D28034 llvm-svn: 290492
* clang-format: Less eagerly try to keep label-value pairs on a line.Daniel Jasper2016-12-221-0/+4
| | | | | | | | | | | | | | | 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-6/+0
| | | | | | | | | | | 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-0/+8
| | | | | | | | | | | | | | | | | | | 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-0/+6
| | | | | | | | | | | | | | | 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
* clang-format: Slightly tweak the behavior of <<-wrapping.Daniel Jasper2016-12-191-0/+3
| | | | | | | | | | | | | | | 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-0/+13
| | | | llvm-svn: 290093
* clang-format: Fix regression introduced in r290084.Daniel Jasper2016-12-191-1/+1
| | | | | | | | | | | | | | | | | | | 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-0/+12
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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
* Remove custom handling of array copies in lambda by-value array capture andRichard Smith2016-12-141-19/+0
| | | | | | | | | | | copy constructors of classes with array members, instead using ArrayInitLoopExpr to represent the initialization loop. This exposed a bug in the static analyzer where it was unable to differentiate between zero-initialized and unknown array values, which has also been fixed here. llvm-svn: 289618
* Remove deprecated methods ast_matchers::BoundNodes::{getStmtAs,getDeclAs}Alexander Kornienko2016-12-132-2/+2
| | | | llvm-svn: 289543
* clang-format: Keep string-literal-label + value pairs on a line.Daniel Jasper2016-12-131-39/+49
| | | | | | | | | | | | | | | | | | | | | 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-0/+13
| | | | | | | | | | | 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-738/+827
| | | | | | | | | | | | | 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/+24
| | | | | | | | | | Reviewers: djasper Subscribers: klimek, cfe-commits Differential Revision: https://reviews.llvm.org/D27615 llvm-svn: 289203
OpenPOWER on IntegriCloud