summaryrefslogtreecommitdiffstats
path: root/clang/lib/Format/Format.cpp
Commit message (Collapse)AuthorAgeFilesLines
* clang-format: Fix bad merging of lines in nested blocks.Daniel Jasper2014-10-271-0/+3
| | | | | | | | | | | | | | | Before: SomeFunction([]() { #define A a return 43; }); After: SomeFunction([]() { #define A a return 43; }); llvm-svn: 220684
* clang-format: Add option to control call argument bin-packing separatelyDaniel Jasper2014-10-091-0/+2
| | | | | | | This is desirable for the Chromium style guide: http://www.chromium.org/developers/coding-style llvm-svn: 219400
* Format: ArrayRefize some implicit copies away.Benjamin Kramer2014-10-031-8/+8
| | | | | | NFC. llvm-svn: 219000
* clang-format: [JS] Support AllowShortFunctionsOnASingleLine.Daniel Jasper2014-09-301-0/+1
| | | | | | | | | Specifically, this also counts for stuff like (with style "inline"): var x = function() { return 1; }; llvm-svn: 218689
* clang-format: Don't let -style=Chromium imply c++03 template formatting.Nico Weber2014-09-241-1/+0
| | | | | | | Chromium's now using some c++11 language features, so it's now fine that clang-format produces vector<vector<int>>. llvm-svn: 218392
* clang-format: Basic support for Java.Daniel Jasper2014-09-151-2/+13
| | | | llvm-svn: 217759
* clang-format: Add option to break before non-assignment operators.Daniel Jasper2014-09-151-3/+13
| | | | | | | | | This will allow: int aaaaaaaaaaaaaa = bbbbbbbbbbbbbb + ccccccccccccccc; llvm-svn: 217757
* Fix bug 20892 - clang-format does not handle C-style commentsRoman Kashitsyn2014-09-111-2/+9
| | | | | | | | | | | | | | | | | | | | | | Summary: http://llvm.org/bugs/show_bug.cgi?id=20892 Add support of C-style formatting enabling/disabling directives. Now the following two styles are supported: // clang-format on /* clang-format on */ The flexibility in comments (support of extra spaces and/or slashes, etc.) is deliberately avoided to simplify search in large code bases. Reviewers: djasper Reviewed By: djasper Subscribers: cfe-commits, curdeius, klimek Differential Revision: http://reviews.llvm.org/D5309 llvm-svn: 217588
* clang-format: Add option to allow short case labels on a single line.Daniel Jasper2014-09-101-0/+32
| | | | | | | | | | | | | | | | | | | | | | | | | | On a single line: switch (a) { case 1: x = 1; return; case 2: x = 2; return; default: break; } Not on a single line: switch (a) { case 1: x = 1; return; case 2: x = 2; return; default: break; } This partly addresses llvm.org/PR16535. In the long run, we probably want to lay these out in columns. llvm-svn: 217501
* clang-format: [JS] Support regex literals with trailing escaped slash.Daniel Jasper2014-09-091-26/+58
| | | | | | | | | | | | | | | | | | Before: var regex = / a\//; int i; After: var regex = /a\//; int i; This required pushing the Lexer into its wrapper class and generating a new one in this specific case. Otherwise, the sequence get lexed as a //-comment. This is hacky, but I don't know a better way (short of supporting regex literals in the Lexer). Pushing the Lexer down seems to make all the call sites simpler. llvm-svn: 217444
* clang-format: [JS] Support alternative operator names as identifiers.Daniel Jasper2014-09-041-7/+8
| | | | | | | | | | Before: not. and . or . not_eq = 1; After: not.and.or.not_eq = 1; llvm-svn: 217179
* clang-format: Add an option 'SpaceAfterCStyleCast'.Daniel Jasper2014-09-031-0/+2
| | | | | | | | | | | | | | | | | This permits to add a space after closing parenthesis of a C-style cast. Defaults to false to preserve old behavior. Fixes llvm.org/PR19982. Before: (int)i; After: (int) i; Patch by Marek Kurdej. llvm-svn: 217022
* Overload SourceManager::overrideFileContents so that unconditionally passing ↵David Blaikie2014-08-271-1/+1
| | | | | | | | | | ownership is explicitly done using unique_ptr. Only those callers who are dynamically passing ownership should need the 3 argument form. Those accepting the default ("do pass ownership") should do so explicitly with a unique_ptr now. llvm-svn: 216614
* Update for LLVM api change.Rafael Espindola2014-08-271-2/+3
| | | | llvm-svn: 216585
* clang-format: New option SpacesInSquareBrackets.Daniel Jasper2014-08-261-0/+2
| | | | | | | | | | | | | | | | Before: int a[5]; a[3] += 42; After: int a[ 5 ]; a[ 3 ] += 42; Fixes LLVM bug #17887 (http://llvm.org/bugs/show_bug.cgi?id=17887). Patch by Marek Kurdej, thank you! llvm-svn: 216449
* C++1y is now C++14!Aaron Ballman2014-08-191-1/+1
| | | | | | Changes diagnostic options, language standard options, diagnostic identifiers, diagnostic wording to use c++14 instead of c++1y. It also modifies related test cases to use the updated diagnostic wording. llvm-svn: 215982
* FormatTokenLexer: Avoid non-static member initializer.NAKAMURA Takumi2014-08-061-2/+2
| | | | llvm-svn: 214976
* clang-format: Add special comments to disable formatting.Daniel Jasper2014-08-061-0/+7
| | | | | | | | | | | | | | | | With this patch: int ThisWillBeFormatted; // clang-format off int ThisWontBeFormatted; // clang-format on int Formatted; This is for regions where a significantly nicer code layout can be found knowing the content of the code. This fixes llvm.org/PR20463. llvm-svn: 214966
* clang-format: Add option to always break after a function's return type.Daniel Jasper2014-08-051-0/+4
| | | | | | | | | | This is required for GNU coding style, among others. Also update the configuration documentation. Modified from an original patch by Jarkko Hietaniemi, thank you! llvm-svn: 214858
* Fix typosAlp Toker2014-07-141-1/+1
| | | | | | Also consolidate 'backward compatibility' llvm-svn: 212974
* clang-format: Add new option to indent wrapped function declarations.Daniel Jasper2014-07-091-0/+5
| | | | | | | | | Though not completely identical, make former IndentFunctionDeclarationAfterType change this flag for backwards compatibility (it is somewhat close in meaning and better the err'ing on an unknown config flag). llvm-svn: 212597
* clang-format: Revamp function declaration/definition indentation.Daniel Jasper2014-07-091-4/+0
| | | | | | | | | | | | | | 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
* Update for llvm api change.Rafael Espindola2014-07-061-5/+6
| | | | llvm-svn: 212408
* clang-format: Introduce style with spaces on both sides of */&.Daniel Jasper2014-06-171-13/+29
| | | | | | | Patch by Janusz Sobczak (slightly extended). This fixes llvm.org/19929. llvm-svn: 211098
* Permit -Wswitch coverage for enumerations.Saleem Abdulrasool2014-06-121-1/+1
| | | | | | | | Thanks to David Blakie and Richard Smith for pointing out that we can retain the -Wswitch coverage while avoiding the warning from GCC by pushing the unreachable outside of the switch! llvm-svn: 210812
* Basic: fix warnings from GCCSaleem Abdulrasool2014-06-121-0/+1
| | | | | | | | | | | | tools/clang/lib/Basic/DiagnosticIDs.cpp: In function ‘clang::DiagnosticIDs::Level toLevel(clang::diag::Severity)’: tools/clang/lib/Basic/DiagnosticIDs.cpp:382:1: warning: control reaches end of non-void function [-Wreturn-type] tools/clang/lib/Format/Format.cpp: In member function ‘virtual std::string clang::format::ParseErrorCategory::message(int) const’: tools/clang/lib/Format/Format.cpp:282:1: warning: control reaches end of non-void function [-Wreturn-type] Add a default cases that asserts that we handle the severity, parse error. llvm-svn: 210804
* Replace llvm::error_code with std::error_code.Rafael Espindola2014-06-121-4/+4
| | | | llvm-svn: 210780
* Fix typo.Rafael Espindola2014-06-121-2/+2
| | | | | | Thanks to Alp Toker for noticing. llvm-svn: 210744
* Give clang-format its own error category.Rafael Espindola2014-06-121-6/+29
| | | | | | | | | The posix errno values are probably to the best thing to use for describing parse errors. This should also fix the mingw build. llvm-svn: 210739
* Use std::error_code instead of llvm::error_code.Rafael Espindola2014-06-111-5/+5
| | | | | | This is an update for a llvm api change. llvm-svn: 210688
* clang-format: Fix incorrect indentation.Daniel Jasper2014-06-061-1/+2
| | | | | | | | | | | | | | | | | | | | | | | | Before (JavaScript example, but can extend to other languages): return { a: 'E', b: function() { return function() { f(); // This is wrong. }; } }; After: return { a: 'E', b: function() { return function() { f(); // This is better. }; } }; llvm-svn: 210334
* Use error_code() instead of error_code::succes()Rafael Espindola2014-05-311-1/+1
| | | | | | | There is no std::error_code::success, so this removes much of the noise in transitioning to std::error_code. llvm-svn: 209949
* Use error_code::success() instead of make_error_code(llvm::errc::success).Alexander Kornienko2014-05-221-1/+1
| | | | llvm-svn: 209477
* clang-format: Introduce DisableFormat that prevents formatting.Daniel Jasper2014-05-221-0/+16
| | | | | | | | | | | | | | | | | And "none" pseudo-style indicating that formatting should be not applied. (1) Using .clang-format with "DisableFormat: true" effectively prevents formatting for all files within the folder containing such .clang-format file. (2) Using -fallback-style=none together with -style=file prevents formatting when .clang-format is not found, which can be used in on-save callback. Patch by Adam Strzelecki. Thank you! llvm-svn: 209446
* clang-format: Fix corner case in AllowShortBlocksOnASingleLine.Daniel Jasper2014-05-221-2/+1
| | | | | | | | | | | | | | | | Before: template <int> struct A4 { A4() { } }; After: template <int i> struct A4 { A4() {} }; This fixes llvm.org/PR19813 (at least the part that isn't working as intended). llvm-svn: 209438
* clang-format: Store pointers to seen formatting states.Daniel Jasper2014-05-221-2/+8
| | | | | | | | | | | As the memory ownership is handled by the SpecificBumpPtrAllocator anyway, there is no need to duplicate states when inserting them into the Seen-set. This leads to an improvement of ~10% on the benchmark formatting file. No functional changes intended. llvm-svn: 209422
* clang-format: Correctly identify multiplications in braces init lists.Daniel Jasper2014-05-221-1/+1
| | | | | | | | | | | | | Before: int i{a *b}; After: int i{a * b}; Also fix unrelated issue where braced init lists were counted as blocks and prevented single-line functions. llvm-svn: 209412
* clang-format: Correctly calculate line lenghts for nest blocks.Daniel Jasper2014-05-221-1/+3
| | | | | | | | | | | | | | | If simple (one-statement) blocks can be inlined, the length needs to be calculated correctly. Before (in JavaScript but this also affects lambdas, etc.): var x = { valueOf: function() { return 1; } }; After: var x = {valueOf: function() { return 1; }}; llvm-svn: 209410
* clang-format: [JS] Support different function literal style.Daniel Jasper2014-05-211-2/+7
| | | | | | | | | | | | | | | | | Before: goog.array.forEach(array, function() { doSomething(); doSomething(); }, this); After: goog.array.forEach(array, function() { doSomething(); doSomething(); }, this); llvm-svn: 209291
* clang-format: [JS] Support for EC6 arrow functions.Daniel Jasper2014-05-191-0/+3
| | | | | | | | | | Before: var b = a.map((x) = > x + 1); After: var b = a.map((x) => x + 1); llvm-svn: 209112
* Fix typosAlp Toker2014-05-151-1/+1
| | | | llvm-svn: 208838
* clang-format: Add option to allow short blocks on a single line.Daniel Jasper2014-05-141-10/+29
| | | | | | | | | With AllowShortBlocksOnASingleLine, clang-format allows: if (a) { return; } Based on patch by Gonzalo BG, thank you! llvm-svn: 208765
* clang-format: [JS] Basic support for escape sequences in regex literals.Daniel Jasper2014-05-121-1/+21
| | | | | | | | | | Before: var regex = /\\/ g; // This isn't even recognized as regex. After: var regex = /\\/g; // It now is. llvm-svn: 208539
* Decouple ExprCXX.h and DeclCXX.h and clean up includes a bit.Benjamin Kramer2014-05-101-0/+1
| | | | | | | Required pulling LambdaExpr::Capture into its own header. No functionality change. llvm-svn: 208470
* clang-format: Fix bug introduced by r208392.Daniel Jasper2014-05-091-37/+35
| | | | | | Also run clang-format over clang-format's files. llvm-svn: 208409
* clang-format: [JS] Allow up to 3 empty lines in Google's JS style.Daniel Jasper2014-05-091-1/+1
| | | | llvm-svn: 208404
* [C++11] Use 'nullptr'.Craig Topper2014-05-091-15/+16
| | | | llvm-svn: 208392
* clang-format: [JS] Support regex literals after 'return'.Daniel Jasper2014-05-081-5/+5
| | | | llvm-svn: 208285
* clang-format: [JS] Initial support for regex literals.Daniel Jasper2014-05-081-4/+39
| | | | llvm-svn: 208281
* Enable alternative tokens by default for clang-format.Nikola Smiljanic2014-05-081-0/+1
| | | | | | Patch by Bobby Moretti. llvm-svn: 208269
OpenPOWER on IntegriCloud