summaryrefslogtreecommitdiffstats
path: root/clang/lib/Format/FormatToken.h
Commit message (Collapse)AuthorAgeFilesLines
* clang-format: Fix behavior around pointer-to-member invocations.Daniel Jasper2014-07-091-1/+1
| | | | | | | | | | | | Before: (aaaaaaaaaa->* bbbbbbb)(aaaaaaaaaaaaaaaaaaaaaaaaaaa(aaaaaaaaaaaaaaaaaaaaaaaaaaa)); After: (aaaaaaaaaa->*bbbbbbb)( aaaaaaaaaaaaaaaaaaaaaaaaaaa(aaaaaaaaaaaaaaaaaaaaaaaaaaa)); llvm-svn: 212617
* clang-format: Revamp function declaration/definition indentation.Daniel Jasper2014-07-091-0/+1
| | | | | | | | | | | | | | Key changes: - Correctly (well ...) distinguish function declarations and variable declarations with ()-initialization. - Don't indent when breaking function declarations/definitions after the return type. - Indent variable declarations and typedefs when breaking after the type. This fixes llvm.org/PR17999. llvm-svn: 212591
* clang-format: [JS] Treat dict literals similar to objc method exprs.Daniel Jasper2014-06-101-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Before: return { link: function() { f(); // } }; return { a: a, link: function() { f(); // } } After: return { link: function() { f(); // } }; return { a: a, link: function() { f(); // } }; llvm-svn: 210537
* clang-format: Refactor indentation behavior for multiple nested blocks.Daniel Jasper2014-06-031-3/+8
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This fixes a few oddities when formatting multiple nested JavaScript blocks, e.g.: Before: promise.then( function success() { doFoo(); doBar(); }, [], function error() { doFoo(); doBaz(); }); promise.then([], function success() { doFoo(); doBar(); }, function error() { doFoo(); doBaz(); }); After: promise.then( function success() { doFoo(); doBar(); }, [], function error() { doFoo(); doBaz(); }); promise.then([], function success() { doFoo(); doBar(); }, function error() { doFoo(); doBaz(); }); llvm-svn: 210097
* clang-format: Fix bug introduced by r208392.Daniel Jasper2014-05-091-1/+3
| | | | | | Also run clang-format over clang-format's files. llvm-svn: 208409
* [C++11] Use 'nullptr'.Craig Topper2014-05-091-3/+3
| | | | llvm-svn: 208392
* clang-format: [JS] Initial support for regex literals.Daniel Jasper2014-05-081-0/+1
| | | | llvm-svn: 208281
* clang-format: Add special case to reduce indentaiton in streams.Daniel Jasper2014-04-161-4/+10
| | | | | | | | | | | | | | | | This is similar to how we treat assignments and seems to be generally desirable. Before: llvm::errs() << aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa( aaaaaaaaaaaaaaaaaaaaaaaaaaaa, aaaaaaaaaaaaaaaaaaaaaaaaaaaa); After: llvm::errs() << aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa( aaaaaaaaaaaaaaaaaaaaaaaaaaaa, aaaaaaaaaaaaaaaaaaaaaaaaaaaa); llvm-svn: 206384
* Format code around VCS conflict markers.Manuel Klimek2014-04-141-4/+7
| | | | | | | | | | | | | | | | | | | | | Now correctly formats: { int a; void f() { callme(some(parameter1, <<<<<<< text by the vcs parameter2), ||||||| text by the vcs parameter2), parameter3, ======= text by the vcs parameter2, parameter3), >>>>>>> text by the vcs otherparameter); } } llvm-svn: 206157
* clang-format: Support configurable list of foreach-macros.Daniel Jasper2014-04-011-1/+4
| | | | | | | | This fixes llvm.org/PR17242. Patch by Brian Green, thank you! llvm-svn: 205307
* Get rid of the adapted isLiteral method.Manuel Klimek2014-03-281-4/+0
| | | | | | We don't want to deviate from clang's standard terminology. llvm-svn: 204997
* Improve handling of bool expressions in template arguments.Manuel Klimek2014-03-271-0/+4
| | | | | | | Now correctly formats: foo<true && false>(); llvm-svn: 204950
* clang-format: Correctly identify ObjC Block with return type.Daniel Jasper2014-03-271-0/+1
| | | | llvm-svn: 204905
* [C++11] Add 'override' keyword to virtual methods that override their base ↵Craig Topper2014-03-151-7/+6
| | | | | | class. llvm-svn: 203999
* [C++11] Replace OwningPtr include with <memory>.Ahmed Charles2014-03-091-1/+1
| | | | llvm-svn: 203389
* Replace OwningPtr with std::unique_ptr.Ahmed Charles2014-03-071-1/+1
| | | | | | This compiles cleanly with lldb/lld/clang-tools-extra/llvm. llvm-svn: 203279
* clang-format: Understand __attribute__s preceding parameter lists.Daniel Jasper2014-01-281-0/+1
| | | | | | | | | | | | | | Before: ReturnType __attribute__((unused)) function(int i); After: ReturnType __attribute__((unused)) function(int i); This fixes llvm.org/PR18632. llvm-svn: 200337
* clang-format: Enable formatting of lambdas with explicit return type.Daniel Jasper2014-01-161-0/+3
| | | | | | | | | So clang-format can now format: int c = []()->int { return 2; }(); int c = []()->vector<int> { return { 2 }; }(); llvm-svn: 199368
* clang-format: Some tweaks to braces list formatting:Daniel Jasper2014-01-091-5/+23
| | | | | | | | | - Format a braced list with one element per line if it has nested braced lists. - Use a column layout only when the list has 6+ elements (instead of the current 4+ elements). llvm-svn: 198869
* clang-format: Fix various problems in formatting ObjC blocks.Daniel Jasper2013-12-231-0/+3
| | | | | | Among other things, this fixes llvm.org/PR15269. llvm-svn: 197900
* clang-format: Better support for multi-line wide string literals.Daniel Jasper2013-12-201-0/+1
| | | | | | | | | | | Before: SomeFunction(L"A" L"B"); After: SomeFunction(L"A" L"B"); llvm-svn: 197785
* clang-format: Keep trailing annotations together.Daniel Jasper2013-12-161-0/+1
| | | | | | | | | | | | | | | | Before: virtual void aaaaa(aaaaaaaaaaaaaaaaaaaaaaaaaa aaaa, aaaaaaaaaaa aaaaa) const override; virtual void aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa() const override; After: virtual void aaaaa(aaaaaaaaaaaaaaaaaaaaaaaaaa aaaa, aaaaaaaaaaa aaaaa) const override; virtual void aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa() const override; llvm-svn: 197391
* clang-format: Be more conservative about braced list column layout.Daniel Jasper2013-12-091-2/+6
| | | | | | | | | | | | | | | | | | | | | | | | | | | Specifically disable it for nested braced lists as it commonly can look really weird. Eventually, we'll want to become smarter and format some of the nested lists better. Before: SomeStruct my_struct_array = { { aaaaaa, aaaaaaaa, aaaaaaaaaa, aaaaaaaaa, aaaaaaaaa, aaaaaaaaaa, aaaaaaaaaa, aaaaaaa, aaa }, { aaaa, aaaa, aaaa, aaaa, aaaa, aaaa, aaaa, aaa }, { aaaaaaaaaaaaaaaaa, aaaaaaaaaaaaaaaaa, aaaaaaaaaaaaaaaaaaaaaaaa, aaaaaaaaaaaa, a, aaaaaaaaaa, aaaaaaaaa, aaa }, }; After: SomeStruct my_struct_array = { { aaaaaa, aaaaaaaa, aaaaaaaaaa, aaaaaaaaa, aaaaaaaaa, aaaaaaaaaa, aaaaaaaaaaaa, aaaaaaa, aaa }, { aaaa, aaaa, aaaa, aaaa, aaaa, aaaa, aaaa, aaa }, { aaaaaaaaaaaaaaaaa, aaaaaaaaaaaaaaaaa, aaaaaaaaaaaaaaaaaaaaaaaa, aaaaaaaaaaaa, a, aaaaaaaaaa, aaaaaaaaa, aaa }, }; llvm-svn: 196783
* Fix a tranche of comment, test and doc typosAlp Toker2013-12-051-2/+2
| | | | llvm-svn: 196510
* Added an option to allow short function bodies be placed on a single line.Alexander Kornienko2013-11-201-0/+1
| | | | | | | | | | | | | | | | | | | Summary: The AllowShortFunctionsOnASingleLine option now controls short function body placement on a single line independent of the BreakBeforeBraces option. Updated tests using BreakBeforeBraces other than BS_Attach. Addresses http://llvm.org/PR17888 Reviewers: klimek, djasper Reviewed By: klimek CC: cfe-commits, klimek Differential Revision: http://llvm-reviews.chandlerc.com/D2230 llvm-svn: 195256
* clang-format: Cleanup array initializer and dict initializer formatting.Daniel Jasper2013-10-241-2/+2
| | | | | | | | Significant changes: - Also recognize these literals with missing "@" for robustness. - Reorganize tests. llvm-svn: 193325
* clang-format: Fix ObjC literal indentation in Google style.Daniel Jasper2013-10-221-8/+11
| | | | | | | | | | | | | | | | | | | | | | Style guide demands a two-space indent. Before: NSArray *arguments = @[ kind == kUserTicket ? @"--user-store" : @"--system-store", @"--print-tickets", @"--productid", @"com.google.Chrome" ]; After: NSArray *arguments = @[ kind == kUserTicket ? @"--user-store" : @"--system-store", @"--print-tickets", @"--productid", @"com.google.Chrome" ]; llvm-svn: 193168
* clang-format: Improve formatting of ObjC array literals.Daniel Jasper2013-10-221-1/+13
| | | | | | | | | | | | | | | | | | Before: NSArray *arguments = @[ kind == kUserTicket ? @"--user-store" : @"--system-store", @"--print-tickets", @"--productid", @"com.google.Chrome" ]; After: NSArray *arguments = @[ kind == kUserTicket ? @"--user-store" : @"--system-store", @"--print-tickets", @"--productid", @"com.google.Chrome" ]; This fixes llvm.org/PR15231. llvm-svn: 193167
* Support formatting of preprocessor branches.Manuel Klimek2013-10-111-1/+16
| | | | | | | | | | | | | | | | | | | | | We now correctly format: void SomeFunction(int param1, #ifdef X NoTemplate param2, #else template < #ifdef A MyType<Some> > #else Type1, Type2> #endif param2, #endif param3) { f(); } llvm-svn: 192503
* Correctly detect colon in bit fields. Fixes PR17333.Alexander Kornienko2013-10-101-0/+1
| | | | | | | | | | | | | | Summary: Colon was incorrectly detected as a start of inheritance list. Fixed. Reviewers: djasper Reviewed By: djasper CC: cfe-commits, klimek Differential Revision: http://llvm-reviews.chandlerc.com/D1884 llvm-svn: 192349
* Calculate and store ColumnWidth instead of CodePointCount in FormatTokens.Alexander Kornienko2013-09-101-18/+9
| | | | | | | | | | | | | | | | Summary: This fixes various issues with mixed tabs and spaces handling, e.g. when realigning block comments. Reviewers: klimek, djasper Reviewed By: djasper CC: cfe-commits Differential Revision: http://llvm-reviews.chandlerc.com/D1608 llvm-svn: 190395
* clang-format: Fix regression introduced by r189337.Daniel Jasper2013-09-061-3/+10
| | | | | | | | | | | | | | | Before: if (aaaaaaaaaaaaaaaaaaaaaaaaaa.aaaaaaaaaaaaaaaaaaaaaa( aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa) == 5) ... After: if (aaaaaaaaaaaaaaaaaaaaaaaaaa.aaaaaaaaaaaaaaaaaaaaaa( aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa) == 5) ... Also precompute startsBinaryExpression() to improve performance. llvm-svn: 190124
* Handle zero-width and double-width characters in string literals and comments.Alexander Kornienko2013-09-051-4/+4
| | | | | | | | | | | | | | | | | | Summary: Count column width instead of the number of code points. This also includes correct handling of tabs inside string literals and comments (with an exception of multiline string literals/comments, where tabs are present before the first escaped newline). Reviewers: djasper, klimek Reviewed By: klimek CC: cfe-commits, klimek Differential Revision: http://llvm-reviews.chandlerc.com/D1601 llvm-svn: 190052
* clang-format: Enable formatting of nested blocks.Daniel Jasper2013-09-051-0/+4
| | | | | | | | | | | | | | | | | | Among other things, this enables (better) formatting lambdas and constructs like: MACRO({ long_statement(); long_statement_2(); }, { long_statement(); long_statement_2(); }, { short_statement(); }, ""); This fixes llvm.org/PR15381. llvm-svn: 190038
* Store first and last newline position in the token text for string literals ↵Alexander Kornienko2013-09-021-6/+16
| | | | | | | | | | | | | | | | | | and comments. Summary: Store first and last newline position in the token text for string literals and comments to avoid doing .find('\n') for each possible solution. Reviewers: djasper Reviewed By: djasper CC: cfe-commits, klimek Differential Revision: http://llvm-reviews.chandlerc.com/D1556 llvm-svn: 189758
* Better support for multiline string literals (including C++11 raw string ↵Alexander Kornienko2013-08-291-8/+11
| | | | | | | | | | | | | | | | | | literals). Summary: Calculate characters in the first and the last line correctly so that we only break before the literal when needed. Reviewers: djasper Reviewed By: djasper CC: cfe-commits, klimek Differential Revision: http://llvm-reviews.chandlerc.com/D1544 llvm-svn: 189595
* Fixes various problems with accounting for tabs in the original code.Manuel Klimek2013-08-291-1/+10
| | | | | | | | | | | | | | | We now count the original token's column directly when lexing the tokens, where we already have all knowledge about where lines start. Before this patch, formatting: void f() { \tg(); \th(); } would incorrectly count the \t's as 1 character if only the line containing h() was reformatted, and thus indent h() at offset 1. llvm-svn: 189585
* clang-format: Format segments of builder-type calls one per line.Daniel Jasper2013-08-271-0/+8
| | | | | | | | | | | | | | | | | | | | | | This fixes llvm.org/PR14818. Before: return llvm::StringSwitch<Reference::Kind>(name) .StartsWith(".eh_frame_hdr", ORDER_EH_FRAMEHDR) .StartsWith(".eh_frame", ORDER_EH_FRAME) .StartsWith(".init", ORDER_INIT).StartsWith(".fini", ORDER_FINI) .StartsWith(".hash", ORDER_HASH).Default(ORDER_TEXT); After: return llvm::StringSwitch<Reference::Kind>(name) .StartsWith(".eh_frame_hdr", ORDER_EH_FRAMEHDR) .StartsWith(".eh_frame", ORDER_EH_FRAME) .StartsWith(".init", ORDER_INIT) .StartsWith(".fini", ORDER_FINI) .StartsWith(".hash", ORDER_HASH) .Default(ORDER_TEXT); llvm-svn: 189353
* clang-format: Add column layout formatting for braced listsDaniel Jasper2013-08-221-0/+83
| | | | | | | | | | | | | | | | | | | | With this patch, braced lists (with more than 3 elements are formatted in a column layout if possible). E.g.: static const uint16_t CallerSavedRegs64Bit[] = { X86::RAX, X86::RDX, X86::RCX, X86::RSI, X86::RDI, X86::R8, X86::R9, X86::R10, X86::R11, 0 }; Required other changes: - FormatTokens can now have a special role that contains extra data and can do special formattings. A comma separated list is currently the only implementation. - Move penalty calculation entirely into ContinuationIndenter (there was a last piece still in UnwrappedLineFormatter). Review: http://llvm-reviews.chandlerc.com/D1457 llvm-svn: 189018
* clang-format: Add two new style options to support WebKit style.Daniel Jasper2013-07-261-0/+1
| | | | | | | | | | | | | New options: * Break before the commas of constructor initializers and align the commas with the colon. * Break before binary operators Additionally, for styles without column limit, don't just accept linebreaks done by the user, but instead remove 'invalid' (according to the current style) linebreaks and add 'required' ones. llvm-svn: 187210
* clang-format: Improve handling of unterminated string literals.Daniel Jasper2013-07-161-5/+9
| | | | | | | Before, clang-format would simply eat these as they were recognized as whitespace. With this patch, they are mostly left alone. llvm-svn: 186454
* Add experimental flag for adaptive parameter bin-packing.Daniel Jasper2013-07-101-3/+13
| | | | | | | | | | | | | | | | | | | | | | | | | This is not activated for any style, might change or go away completely. For those that want to play around with it, set ExperimentalAutoDetectBinPacking to true. clang-format will then: Look at whether function calls/declarations/definitions are currently formatted with one parameter per line (on a case-by-case basis). If so, clang-format will avoid bin-packing the parameters. If all parameters are on one line (thus that line is "inconclusive"), clang-format will make the choice dependent on whether there are other bin-packed calls/declarations in the same file. The reason for this change is that bin-packing in some situations can be really bad and an author might opt to put one parameter on each line. If the author does that, he might want clang-format not to mess with that. If the author is unhappy with the one-per-line formatting, clang-format can easily be convinced to bin-pack by putting any two parameters on the same line. llvm-svn: 186003
* Initial support for formatting trailing return types.Daniel Jasper2013-07-091-0/+1
| | | | | | | | | | | | This fixes llvm.org/PR15170. For now, the basic formatting rules are (based on the C++11 standard): * Surround the "->" with spaces. * Break before "->". Also fix typo. llvm-svn: 185938
* Fix alignment of closing brace in braced initializers.Daniel Jasper2013-07-091-4/+15
| | | | | | | | | | | | | | | | | | | | | | Before: someFunction(OtherParam, BracedList{ // comment 1 (Forcing intersting break) param1, param2, // comment 2 param3, param4 }); After: someFunction(OtherParam, BracedList{ // comment 1 (Forcing intersting break) param1, param2, // comment 2 param3, param4 }); To do so, the UnwrappedLineParser now stores the information about the kind of brace in the FormatToken. llvm-svn: 185914
* Reformat clang-format's source files after r185822 and others.Daniel Jasper2013-07-081-1/+0
| | | | llvm-svn: 185823
* Fixed typo: NoneComment -> NonComment, no other changes.Alexander Kornienko2013-07-041-2/+2
| | | | llvm-svn: 185640
* Use LLVM_DELETED_FUNCTION on unimplemented copy constructor and assignment ↵Craig Topper2013-07-011-2/+2
| | | | | | operator. llvm-svn: 185302
* Fix a comment.Nico Weber2013-06-251-1/+1
| | | | llvm-svn: 184873
* Improved handling of escaped newlines at the token start.Alexander Kornienko2013-06-071-11/+5
| | | | | | | | | | | | | | Summary: Remove them from the TokenText as well. Reviewers: klimek Reviewed By: klimek CC: cfe-commits Differential Revision: http://llvm-reviews.chandlerc.com/D935 llvm-svn: 183536
* UTF-8 support for clang-format.Alexander Kornienko2013-06-051-8/+13
| | | | | | | | | | | | | | | | | | | | Summary: Detect if the file is valid UTF-8, and if this is the case, count code points instead of just using number of bytes in all (hopefully) places, where number of columns is needed. In particular, use the new FormatToken.CodePointCount instead of TokenLength where appropriate. Changed BreakableToken implementations to respect utf-8 character boundaries when in utf-8 mode. Reviewers: klimek, djasper Reviewed By: djasper CC: cfe-commits, rsmith, gribozavr Differential Revision: http://llvm-reviews.chandlerc.com/D918 llvm-svn: 183312
OpenPOWER on IntegriCloud