summaryrefslogtreecommitdiffstats
path: root/clang/lib/Format/Format.cpp
Commit message (Collapse)AuthorAgeFilesLines
...
* Keep Chromium ObjC column limit at 80 for consistency with C++Nico Weber2017-01-311-0/+2
| | | | | | | https://reviews.llvm.org/D29337 Patch from Dan Beam <dbeam@chromium.org>! llvm-svn: 293675
* clang-format: [JS] do not format MPEG transport streams.Martin Probst2017-01-271-1/+12
| | | | | | | | | | | | | | | 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: fix fallback style set to "none" not always formattingAntonio Maiorano2017-01-201-6/+6
| | | | | | | | | | | 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-171-35/+29
| | | | | | | | | | 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
* 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-231-6/+9
| | | | | | | | | | | | 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
* 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] revert an unintended change in r288493 and add a test case.Eric Liu2016-12-191-1/+1
| | | | llvm-svn: 290093
* 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: Separate out a language kind for ObjC.Daniel Jasper2016-12-121-1/+15
| | | | | | | | | | | | | 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
* [Format] Avoid copying std::sets and simplify code a bit.Benjamin Kramer2016-11-241-3/+3
| | | | | | No functional change. llvm-svn: 287892
* [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
* [Format] Cleanup after replacing constructor body with = defaultMalcolm Parsons2016-10-201-0/+1
| | | | | | | | | | | | | | 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
* 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
* [clang-format] support header deletion in cleanupAroundReplacemnts.Eric Liu2016-09-231-2/+29
| | | | | | | | | | | | | | | | | | Summary: - If a replacement has offset UINT_MAX, length 0, and a replacement text that is an #include directive, this will insert the #include into the correct block in the \p Code. - If a replacement has offset UINT_MAX, length 1, and a replacement text that is the name of the header to be removed, the header will be removed from \p Code if it exists. Reviewers: djasper Subscribers: cfe-commits, klimek Differential Revision: https://reviews.llvm.org/D24829 llvm-svn: 282253
* clang-format: [JS] do not wrapp @returns tags.Martin Probst2016-09-211-1/+2
| | | | | | | | | | | | Summary: @returns is incorrect code, the standard is @return. However wrapping it can still confuse users. Reviewers: djasper Subscribers: klimek, cfe-commits Differential Revision: https://reviews.llvm.org/D24767 llvm-svn: 282056
* clang-format: [JS] Do not wrap taze annotation comments.Martin Probst2016-09-181-1/+1
| | | | | | | | | | | | | | | | | | | | | Summary: `// taze: ... from ...` comments are used help tools where a specific global symbol comes from. Before: // taze: many, different, symbols from // 'some_long_location_here' After: // taze: many, different, symbols from 'some_long_location_here' Reviewers: djasper Subscribers: klimek, cfe-commits Differential Revision: https://reviews.llvm.org/D24477 llvm-svn: 281857
* Remove redundant comma around parenthesis in parameter list.Eric Liu2016-09-131-0/+2
| | | | | | | | | | Reviewers: djasper Subscribers: cfe-commits, klimek Differential Revision: https://reviews.llvm.org/D24501 llvm-svn: 281344
* Also cleanup comments around redundant colons/commas in format::cleanup.Eric Liu2016-09-091-0/+2
| | | | | | | | | | Reviewers: djasper Subscribers: klimek, cfe-commits Differential Revision: https://reviews.llvm.org/D24400 llvm-svn: 281064
* clang-format: [JavaScript] Change default AllowShortFunctionsOnASingleLineDaniel Jasper2016-09-071-1/+1
| | | | | | for Google style to "empty". llvm-svn: 280878
* clang-format: [JavaScript] Do requoting in a separate passDaniel Jasper2016-09-071-44/+64
| | | | | | | | | | | | | | | | | | The attempt to fix requoting behavior in r280487 after changes to tooling::Replacements are incomplete. We essentially need to add to replacements at the same position, one to insert a line break and one to change the quoting and that's incompatible with the new tooling::Replacement API, which does not allow for order-dependent Replacements. To make the order clear, Replacements::merge() has to be used, but that requires the merged Replacement to actually refer to the changed text, which is hard to reproduce for the requoting. This change fixes the behavior by moving the requoting to a completely separate pass. The added benefit is that no weird ColumnWidth calculations are necessary anymore and this should just work even if we implement string literal splitting in the future. llvm-svn: 280874
* clang-format: [JS] merge requoting replacements.Martin Probst2016-09-021-4/+5
| | | | | | | | | | | | | | | | | Summary: When formatting source code that needs both requoting and reindentation, merge the replacements to avoid erroring out for conflicting replacements. Also removes the misleading Replacements parameter from the TokenAnalyzer API. Reviewers: djasper Subscribers: klimek, cfe-commits Differential Revision: https://reviews.llvm.org/D24155 llvm-svn: 280487
* clang-format: Set default WebKit style to use C++11.Daniel Jasper2016-08-311-1/+0
| | | | | | | | | The WebKit style page says to use nullptr, so this should be fine: https://webkit.org/code-style-guidelines/ This fixes: llvm.org/PR30220 llvm-svn: 280245
* clang-format: Correctly calculate affected ranges when sorting #includes.Daniel Jasper2016-08-301-4/+4
| | | | | | affectedRanges takes a start and an end offset, not offset and length. llvm-svn: 280165
* Make clang-format remove duplicate headers when sorting #includes.Eric Liu2016-08-101-26/+63
| | | | | | | | | | | | Summary: When sorting #includes, #include directives that have the same text will be deduplicated when sorting #includes, and only the first #include in the duplicate #includes remains. If the `Cursor` is provided and put on a deleted #include, it will be put on the remaining #include in the duplicate #includes. Reviewers: djasper Subscribers: cfe-commits, klimek Differential Revision: https://reviews.llvm.org/D23274 llvm-svn: 278206
* clang-format: Add SpaceAfterTemplateSylvestre Ledru2016-08-091-0/+3
| | | | | | | | | | | | | | | | Summary: This is required for compliance with the Mozilla style guide. This is a rebase+minor change of Birunthan Mohanathas's patch Reviewers: djasper Subscribers: klimek, cfe-commits, opilarium Differential Revision: https://reviews.llvm.org/D23317 llvm-svn: 278121
* Implement tooling::Replacements as a class.Eric Liu2016-08-011-16/+38
| | | | | | | | | | | | | | | | | | | Summary: - Implement clang::tooling::Replacements as a class to provide interfaces to control how replacements for a single file are combined and provide guarantee on the order of replacements being applied. - tooling::Replacements only contains replacements for the same file now. Use std::map<std::string, tooling::Replacements> to represent multi-file replacements. - Error handling for the interface change will be improved in followup patches. Reviewers: djasper, klimek Subscribers: cfe-commits Differential Revision: https://reviews.llvm.org/D21748 llvm-svn: 277335
* [NFC] Header cleanupMehdi Amini2016-07-181-1/+0
| | | | | | | | | | Summary: Removed unused headers, replaced some headers with forward class declarations Patch by: Eugene <claprix@yandex.ru> Differential Revision: https://reviews.llvm.org/D20100 llvm-svn: 275882
* Make tooling::applyAllReplacements return llvm::Expected<string> instead of ↵Eric Liu2016-07-111-9/+13
| | | | | | | | | | | | | | | | empty string to indicate potential error. Summary: return llvm::Expected<> to carry error status and error information. This is the first step towards introducing "Error" into tooling::Replacements. Reviewers: djasper, klimek Subscribers: ioeric, klimek, cfe-commits Differential Revision: http://reviews.llvm.org/D21601 llvm-svn: 275062
* clang-format: [JS] Add a Closure Compiler JSDoc tags to the defaultDaniel Jasper2016-06-211-1/+1
| | | | | | Google configuration so that it isn't line-wrapped. llvm-svn: 273285
* [clang-format] do not add existing includes.Eric Liu2016-06-141-1/+7
| | | | | | | | | | | | Summary: do not add existing includes. Reviewers: djasper Subscribers: klimek, cfe-commits Differential Revision: http://reviews.llvm.org/D21323 llvm-svn: 272669
* clang-format: [JS] Initialize new configuration value.Martin Probst2016-06-131-0/+2
| | | | llvm-svn: 272569
* clang-format: [JS] Indent namespaces in JavaScript/TS by default.Martin Probst2016-06-131-0/+1
| | | | | | | | | | | | Summary: There's no convention of avoiding the nested indentation. Reviewers: djasper Subscribers: klimek, alexeagle, cfe-commits Differential Revision: http://reviews.llvm.org/D21275 llvm-svn: 272559
* clang-format: [JS] Introduce JavaScriptWrapImports option.Martin Probst2016-06-131-1/+3
| | | | | | | | | | | | | | Summary: When turned on, clang-format wraps JavaScript imports (and importing exports), instead of forcing the entire import statement onto one line. Reviewers: djasper Subscribers: klimek, cfe-commits Differential Revision: http://reviews.llvm.org/D21273 llvm-svn: 272558
* [clang-format] pass Style by reference instead of value.Eric Liu2016-06-111-1/+1
| | | | llvm-svn: 272465
* [clang-format] make header guard identification stricter (with Lexer).Eric Liu2016-06-061-23/+51
| | | | | | | | | | | | Summary: make header guard identification stricter with Lexer. Reviewers: djasper Subscribers: klimek, cfe-commits Differential Revision: http://reviews.llvm.org/D20959 llvm-svn: 271883
* [clang-format] skip empty lines and comments in the top of the code when ↵Eric Liu2016-06-031-8/+23
| | | | | | | | | | | | | | | | | inserting new headers. Summary: [clang-format] skip empty lines and comments in the top of the code when inserting new headers. Pair-programmed with @hokein Reviewers: djasper Subscribers: ioeric, cfe-commits, hokein, klimek Differential Revision: http://reviews.llvm.org/D20898 llvm-svn: 271664
* clang-format: [JS] Sort imported symbols.Martin Probst2016-06-011-8/+2
| | | | | | | | | | | | Summary: E.g. sort `import {b, a} from 'x';` into `import {a, b} from 'x';`. Reviewers: djasper Subscribers: cfe-commits, klimek Differential Revision: http://reviews.llvm.org/D20798 llvm-svn: 271400
* Avoid unused variable warning in release builds.Benjamin Kramer2016-05-311-0/+1
| | | | llvm-svn: 271280
* [clang-format] insert new #includes into correct blocks when cleaning up ↵Eric Liu2016-05-311-34/+177
| | | | | | | | | | | | | | | | | Replacement with cleanupAroundReplacements(). Summary: When a replacement's offset is set to UINT_MAX or -1U, it is treated as a header insertion replacement by cleanupAroundReplacements(). The new #include directive is then inserted into the correct block. Reviewers: klimek, djasper Subscribers: klimek, cfe-commits, bkramer Differential Revision: http://reviews.llvm.org/D20734 llvm-svn: 271276
* clang-format: [JS] sort ES6 imports.Martin Probst2016-05-201-781/+24
| | | | | | | | | | | | | | | | | | Summary: This change automatically sorts ES6 imports and exports into four groups: absolute imports, parent imports, relative imports, and then exports. Exports are sorted in the same order, but not grouped further. To keep JS import sorting out of Format.cpp, this required extracting the TokenAnalyzer infrastructure to separate header and implementation files. Reviewers: djasper Subscribers: cfe-commits, klimek Differential Revision: http://reviews.llvm.org/D20198 llvm-svn: 270203
* [clang-format] Make formatReplacements() also sort #includes.Eric Liu2016-05-181-1/+11
| | | | | | | | | | | | Summary: [clang-format] Make formatReplacements() also sort #includes. Reviewers: bkramer, djasper Subscribers: klimek, cfe-commits Differential Revision: http://reviews.llvm.org/D20362 llvm-svn: 269924
* [clang-format] Make FormatTokenLess::operator() const.Eric Liu2016-05-181-1/+1
| | | | llvm-svn: 269889
* Make clang-format cleaner remove redundant commas in list and redundant ↵Eric Liu2016-05-181-0/+48
| | | | | | | | | | | | | | colon in constructor initializer. Summary: Make clang-format cleaner remove redundant commas/colons in constructor initializer list. Reviewers: klimek, djasper Subscribers: cfe-commits, klimek Differential Revision: http://reviews.llvm.org/D19804 llvm-svn: 269888
* clang-format: [JS] simplify logic by parsing forward.Martin Probst2016-05-171-65/+36
| | | | | | | This also reduces complexity to O(n) from O(n^2) by avoiding backtracking re-parses, and fixes length calculation. llvm-svn: 269748
* clang-format: [JS] fix template string width counting.Martin Probst2016-05-171-45/+23
| | | | | | | | | | | | | | | Summary: Simply looking at the final text greatly simplifies the algorithm and also fixes a reported issue. This requires duplicating the "actual encoding width" logic, but that seems cleaner than the column acrobatics before. Reviewers: djasper, bkramer Subscribers: cfe-commits, klimek Differential Revision: http://reviews.llvm.org/D20208 llvm-svn: 269747
OpenPOWER on IntegriCloud