Commit Graph

783 Commits

Author SHA1 Message Date
Martin Probst 2083f31b88 clang-format: [JS] keep triple slash directives intact.
Summary:
TypeScript uses triple slash directives of the form:
    /// <reference path="..."/>

For various non-source instructions that should not be wrapped.

Reference:
https://www.typescriptlang.org/docs/handbook/triple-slash-directives.html

Reviewers: djasper

Subscribers: cfe-commits, klimek

Differential Revision: https://reviews.llvm.org/D32997

llvm-svn: 302523
2017-05-09 12:45:48 +00:00
Daniel Jasper 7fdbb3feda [clang-format] Convert AlignEscapedNewlinesLeft to an enum, adding
DontAlign

This converts the clang-format option AlignEscapedNewlinesLeft from a
boolean to an enum, named AlignEscapedNewlines, with options Left (prev.
true), Right (prev. false), and a new option DontAlign.

When set to DontAlign, the backslashes are placed just after the last token in each line:
  #define EXAMPLE \
    do { \
        int x = aaaaa; \
        int b; \
        int dddddddddd; \
    } while (0)

Patch by jtbandes. Thank you!

llvm-svn: 302428
2017-05-08 15:08:00 +00:00
Krasimir Georgiev bcda54b69d [clang-format] Replace IncompleteFormat by a struct with Line
Summary: This patch replaces the boolean IncompleteFormat that is used to notify the client if an unrecoverable syntax error occurred by a struct that also contains a line number.

Reviewers: djasper

Reviewed By: djasper

Subscribers: cfe-commits, klimek

Differential Revision: https://reviews.llvm.org/D32298

llvm-svn: 300985
2017-04-21 14:35:20 +00:00
Nico Weber dc06518ff4 clang-format: Support formatting utf-8 character literals in C++11+ mode.
clang-format <<END
auto c1 = u8'a';
auto c2 = u'a';
END

Before:
  auto c1 = u8 'a';
  auto c2 = u'a';

Now:
  auto c1 = u8'a';
  auto c2 = u'a';

Patch from Denis Gladkikh <llvm@denis.gladkikh.email>!

llvm-svn: 299574
2017-04-05 18:10:42 +00:00
Daniel Jasper 1dbc2105dc clang-format: Fix post-commit review comment of r299204, use Style.isCpp().
Also, while at it, s/IsCpp/isCpp/ so that it follows LLVM style.

llvm-svn: 299214
2017-03-31 13:30:24 +00:00
Martin Probst b4cdb65e5f clang-format: [JS] do not wrap @see tags.
Summary:
@see is special among JSDoc tags in that it is commonly followed by URLs. The JSDoc spec suggests that users should wrap URLs in an additional {@link url...} tag (@see http://usejsdoc.org/tags-see.html), but this is very commonly violated, with @see being followed by a "naked" URL.

This change special cases all JSDoc lines that contain an @see not to be wrapped to account for that.

Reviewers: djasper

Subscribers: klimek, cfe-commits

Differential Revision: https://reviews.llvm.org/D30883

llvm-svn: 297607
2017-03-13 09:39:23 +00:00
Andi-Bogdan Postelnicu 0ef8ee19f8 [clang-format] Add option to break before inheritance separation operator in class declaration.
Differential Revision: https://reviews.llvm.org/D30487

llvm-svn: 297467
2017-03-10 15:10:37 +00:00
Krasimir Georgiev 317c539e19 [clang-format] Fixed a typo in Format.cpp and a clang-tidy nit about std::function copying; NFC
llvm-svn: 297265
2017-03-08 09:13:25 +00:00
Nico Weber 3ffedcdfa3 Don't write to LLVMStyle.JavaScriptQuotes twice. No behavior change.
llvm-svn: 296749
2017-03-02 14:51:54 +00:00
Krasimir Georgiev 32eaa864e3 [clang-format] Add a new flag FixNamespaceComments to FormatStyle
Summary:
This patch enables namespace end comments under a new flag FixNamespaceComments,
which is enabled for the LLVM and Google styles.

Reviewers: djasper

Reviewed By: djasper

Subscribers: cfe-commits, klimek

Differential Revision: https://reviews.llvm.org/D30405

llvm-svn: 296632
2017-03-01 15:35:39 +00:00
Martin Probst bb46a7dd2a Blacklist arbitrary @\\w+ JSDoc tags from wrapping.
Summary:
Also limits the blacklisting to only apply when the tag is actually
followed by a parameter in curly braces.

    /** @mods {long.type.must.not.wrap} */

vs

    /** @const this is a long description that may wrap. */

Reviewers: djasper

Subscribers: klimek, krasimir, cfe-commits

Differential Revision: https://reviews.llvm.org/D30452

llvm-svn: 296467
2017-02-28 11:08:24 +00:00
Krasimir Georgiev 7cb267af75 [clang-format] Add a NamespaceEndCommentsFixer
Summary:
This patch adds a NamespaceEndCommentsFixer TokenAnalyzer for clang-format,
which fixes end namespace comments.
It currently supports inserting and updating existing wrong comments.

Example source:
```
namespace A {
int i;
}

namespace B {
int j;
} // namespace A
```

after formatting:
```
namespace A {
int i;
} // namespace A

namespace B {
int j;
} // namespace B
```

Reviewers: klimek, djasper

Reviewed By: djasper

Subscribers: klimek, mgorny

Differential Revision: https://reviews.llvm.org/D30269

llvm-svn: 296341
2017-02-27 13:28:36 +00:00
Nico Weber 004d5245c0 clang-format: Enable include sorting for style=Chromium
llvm-svn: 296161
2017-02-24 19:13:59 +00:00
Nico Weber d96ae86735 clang-format: Fix many Objective-C formatting regressions from r289428
r289428 added a separate language kind for Objective-C, but kept many
"Language == LK_Cpp" checks untouched.  This introduced a "IsCpp()"
method that returns true for both C++ and Objective-C++, and replaces
all comparisons of Language with LK_Cpp with calls to this new method.

Also add a lot more test coverge for formatting things in LK_ObjC mode,
by having FormatTest's verifyFormat() test for LK_ObjC everything that's
being tested for LK_Cpp at the moment.

Fixes PR32060 and many other things.

llvm-svn: 296160
2017-02-24 19:10:12 +00:00
Nico Weber 9e2bc306ba Keep Chromium ObjC column limit at 80 for consistency with C++
https://reviews.llvm.org/D29337
Patch from Dan Beam <dbeam@chromium.org>!

llvm-svn: 293675
2017-01-31 18:42:05 +00:00
Martin Probst fa37b18f94 clang-format: [JS] do not format MPEG transport streams.
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
2017-01-27 09:09:11 +00:00
Antonio Maiorano 7eb7507aeb clang-format: fix fallback style set to "none" not always formatting
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
2017-01-20 01:22:42 +00:00
Antonio Maiorano 3adfb6a3ee clang-format: Make GetStyle return Expected<FormatStyle> instead of FormatStyle
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
2017-01-17 00:12:27 +00:00
Nico Weber ea64969763 Change clang-format's Chromium JavaScript defaults
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
2017-01-04 02:33:36 +00:00
Piotr Padlewski 1ec383c74a Use after move bug fixes
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
2016-12-23 11:40:44 +00:00
Antonio Maiorano 34c037641b Make FormatStyle.GetStyleOfFile test work on MSVC
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
2016-12-22 05:10:07 +00:00
Eric Liu 93459d3142 [clang-format] revert an unintended change in r288493 and add a test case.
llvm-svn: 290093
2016-12-19 10:41:05 +00:00
Sylvestre Ledru dcb038d4f2 Update the default of the Mozilla coding style
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
2016-12-14 16:09:29 +00:00
Daniel Jasper 03a04fe95f clang-format: Separate out a language kind for ObjC.
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
2016-12-12 12:42:29 +00:00
Eric Liu 21d1032855 [clang-format] calculate MaxInsertOffset in the original code correctly.
Reviewers: djasper

Subscribers: klimek, cfe-commits

Differential Revision: https://reviews.llvm.org/D27615

llvm-svn: 289203
2016-12-09 11:45:50 +00:00
Eric Liu 964782adbb [ClangFormat] Only insert #include into the #include block in the beginning 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
2016-12-02 11:01:43 +00:00
Benjamin Kramer ebac56ebb0 [Format] Avoid copying std::sets and simplify code a bit.
No functional change.

llvm-svn: 287892
2016-11-24 15:42:29 +00:00
Daniel Jasper 528d682ff6 [clang-format] Remove (SourceManager, FileID) variants
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
2016-11-08 16:11:33 +00:00
Malcolm Parsons 5d8cdb83db [Format] Cleanup after replacing constructor body with = default
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
2016-10-20 14:58:45 +00:00
Reid Kleckner 6432d45f7b Use noexcept instead of LLVM_NOEXCEPT now that all compilers support it
llvm-svn: 284667
2016-10-19 23:39:55 +00:00
Eric Liu 7956c4004d Make DeletedLines local variables in checkEmptyNamespace.
Summary: Patch by Sam McCall!

Reviewers: djasper

Subscribers: klimek, cfe-commits

Differential Revision: https://reviews.llvm.org/D25162

llvm-svn: 283332
2016-10-05 15:49:01 +00:00
Eric Liu 11a4237b23 [clang-format] append newline after code when inserting new headers at the 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
2016-10-05 15:42:19 +00:00
Eric Liu c0d3a80123 [clang-format] support header deletion in cleanupAroundReplacemnts.
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
2016-09-23 15:10:56 +00:00
Martin Probst 6f99d2433b clang-format: [JS] do not wrapp @returns tags.
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
2016-09-21 06:56:38 +00:00
Martin Probst fbbe75b1fe clang-format: [JS] Do not wrap taze annotation comments.
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
2016-09-18 17:33:51 +00:00
Eric Liu 2574d15c5b Remove redundant comma around parenthesis in parameter list.
Reviewers: djasper

Subscribers: cfe-commits, klimek

Differential Revision: https://reviews.llvm.org/D24501

llvm-svn: 281344
2016-09-13 15:02:43 +00:00
Eric Liu 01426ff875 Also cleanup comments around redundant colons/commas in format::cleanup.
Reviewers: djasper

Subscribers: klimek, cfe-commits

Differential Revision: https://reviews.llvm.org/D24400

llvm-svn: 281064
2016-09-09 17:50:49 +00:00
Daniel Jasper 28d8a5ab43 clang-format: [JavaScript] Change default AllowShortFunctionsOnASingleLine
for Google style to "empty".

llvm-svn: 280878
2016-09-07 23:01:13 +00:00
Daniel Jasper 496c199959 clang-format: [JavaScript] Do requoting in a separate pass
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
2016-09-07 22:48:53 +00:00
Martin Probst a9855afedf clang-format: [JS] merge requoting replacements.
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
2016-09-02 14:29:48 +00:00
Daniel Jasper 3042713b4b clang-format: Set default WebKit style to use C++11.
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
2016-08-31 14:05:56 +00:00
Daniel Jasper d6a0078039 clang-format: Correctly calculate affected ranges when sorting #includes.
affectedRanges takes a start and an end offset, not offset and length.

llvm-svn: 280165
2016-08-30 21:33:41 +00:00
Eric Liu a992afe809 Make clang-format remove duplicate headers when sorting #includes.
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
2016-08-10 09:32:23 +00:00
Sylvestre Ledru 83bbd5731b clang-format: Add SpaceAfterTemplate
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
2016-08-09 14:24:40 +00:00
Eric Liu 40ef2fb363 Implement tooling::Replacements as a class.
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
2016-08-01 10:16:37 +00:00
Mehdi Amini 9670f847b8 [NFC] Header cleanup
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
2016-07-18 19:02:11 +00:00
Eric Liu 4f8d99433d Make tooling::applyAllReplacements return llvm::Expected<string> instead of 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
2016-07-11 13:53:12 +00:00
Daniel Jasper f8bcc2445d clang-format: [JS] Add a Closure Compiler JSDoc tags to the default
Google configuration so that it isn't line-wrapped.

llvm-svn: 273285
2016-06-21 17:00:20 +00:00
Eric Liu 3753f912bf [clang-format] do not add existing includes.
Summary: do not add existing includes.

Reviewers: djasper

Subscribers: klimek, cfe-commits

Differential Revision: http://reviews.llvm.org/D21323

llvm-svn: 272669
2016-06-14 14:09:21 +00:00
Martin Probst fb2342d274 clang-format: [JS] Initialize new configuration value.
llvm-svn: 272569
2016-06-13 17:50:10 +00:00
Martin Probst ece8c0c65f clang-format: [JS] Indent namespaces in JavaScript/TS by default.
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
2016-06-13 16:41:28 +00:00
Martin Probst 0cd74ee875 clang-format: [JS] Introduce JavaScriptWrapImports option.
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
2016-06-13 16:39:50 +00:00
Eric Liu 43d67b6883 [clang-format] pass Style by reference instead of value.
llvm-svn: 272465
2016-06-11 11:45:08 +00:00
Eric Liu 3528832930 [clang-format] make header guard identification stricter (with Lexer).
Summary: make header guard identification stricter with Lexer.

Reviewers: djasper

Subscribers: klimek, cfe-commits

Differential Revision: http://reviews.llvm.org/D20959

llvm-svn: 271883
2016-06-06 11:00:13 +00:00
Eric Liu 303baf53b1 [clang-format] skip empty lines and comments in the top of the code when 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
2016-06-03 12:52:59 +00:00
Martin Probst 081f176a62 clang-format: [JS] Sort imported symbols.
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
2016-06-01 15:19:53 +00:00
Benjamin Kramer 1cb7ee1300 Avoid unused variable warning in release builds.
llvm-svn: 271280
2016-05-31 14:14:42 +00:00
Eric Liu 659afd55fa [clang-format] insert new #includes into correct blocks when cleaning up 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
2016-05-31 13:34:20 +00:00
Martin Probst c4a0dd49a3 clang-format: [JS] sort ES6 imports.
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
2016-05-20 11:24:24 +00:00
Eric Liu baf58c2309 [clang-format] Make formatReplacements() also sort #includes.
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
2016-05-18 13:43:48 +00:00
Eric Liu 2874ac3e28 [clang-format] Make FormatTokenLess::operator() const.
llvm-svn: 269889
2016-05-18 08:14:49 +00:00
Eric Liu ce5e4bc7ac Make clang-format cleaner remove redundant commas in list and redundant 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
2016-05-18 08:02:56 +00:00
Martin Probst cb6e042040 clang-format: [JS] simplify logic by parsing forward.
This also reduces complexity to O(n) from O(n^2) by avoiding backtracking
re-parses, and fixes length calculation.

llvm-svn: 269748
2016-05-17 06:29:33 +00:00
Martin Probst e71b4cbdd1 clang-format: [JS] fix template string width counting.
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
2016-05-17 06:29:29 +00:00
Martin Probst a166979e45 clang-format: [JS] respect clang-format off when requoting strings.
Reviewers: djasper

Subscribers: klimek, cfe-commits

Differential Revision: http://reviews.llvm.org/D20200

llvm-svn: 269282
2016-05-12 11:20:32 +00:00
Eric Liu 635423e618 Addressed reviewer's post-submission comments from http://reviews.llvm.org/D18551.
Summary: Make SourceManager in Environment, WhitespaceManager, and FormatTokenAnalyzer etc constant members.

Reviewers: djasper, klimek

Subscribers: cfe-commits, klimek

Differential Revision: http://reviews.llvm.org/D19587

llvm-svn: 267859
2016-04-28 07:52:03 +00:00
Eric Liu c5cad396dd Addressed review's comments.
llvm-svn: 267858
2016-04-28 07:51:47 +00:00
Eric Liu 4cfb88a936 Added Fixer implementation and fix() interface in clang-format for removing redundant code.
Summary:
After applying replacements, redundant code like extra commas or empty namespaces
might be introduced. Fixer can detect and remove any redundant code introduced by replacements.
The current implementation only handles redundant commas.

Reviewers: djasper, klimek

Subscribers: ioeric, mprobst, klimek, cfe-commits

Differential Revision: http://reviews.llvm.org/D18551

llvm-svn: 267416
2016-04-25 15:09:22 +00:00
Marianne Mailhot-Sarrasin 51fe279fbb clang-format: Implemented tab usage for continuation and indentation
Use tabs to fill whitespace at the start of a line.

Patch by Maxime Beaulieu

Differential Revision: http://reviews.llvm.org/D19028

llvm-svn: 266320
2016-04-14 14:52:26 +00:00
Marianne Mailhot-Sarrasin 4988fa1bc5 clang-format: Allow include of clangFormat.h in managed context
Including VirtualFileSystem.h in the clangFormat.h indirectly includes <atomic>.
This header is blocked when compiling with /clr.

Patch by Maxime Beaulieu

Differential Revision: http://reviews.llvm.org/D19064

llvm-svn: 266319
2016-04-14 14:47:37 +00:00
Eric Liu 4c1ef97adb Added formatAndApplyAllReplacements that works on multiple files in libTooling.
Summary:
formatAndApplyAllReplacements takes a set of Replacements, applies them on a
Rewriter, and reformats the changed code.

Reviewers: klimek, djasper

Subscribers: ioeric, klimek, cfe-commits

Differential Revision: http://reviews.llvm.org/D17852

llvm-svn: 264745
2016-03-29 16:31:53 +00:00
Eric Liu 547d87912a Added support for different VFSs in format::getStyle. Disable platform-related test case for MS compilers to avoid breaking buildbot.
llvm-svn: 264277
2016-03-24 13:22:42 +00:00
Eric Liu d47583232a Revert "Added support for different VFSs in format::getStyle."
This reverts commit r264253. It is breaking the buildbot http://lab.llvm.org:8011/builders/llvm-clang-lld-x86_64-scei-ps4-windows10pro-fast/builds/2203

llvm-svn: 264276
2016-03-24 13:22:37 +00:00
Eric Liu 295915ceb7 Revert "removed redundant comment in format::getStyle."
This reverts commit r264254.

llvm-svn: 264275
2016-03-24 13:22:28 +00:00
Eric Liu 6b47faad53 Revert "Added support for different VFSs in format::getStyle."
This reverts commit r264253. It is breaking the buildbot http://lab.llvm.org:8011/builders/llvm-clang-lld-x86_64-scei-ps4-windows10pro-fast/builds/2203

llvm-svn: 264257
2016-03-24 11:25:28 +00:00
Eric Liu b38a9e16bb Revert "removed redundant comment in format::getStyle."
This reverts commit r264254.

llvm-svn: 264256
2016-03-24 11:24:49 +00:00
Eric Liu 883df1782e removed redundant comment in format::getStyle.
llvm-svn: 264254
2016-03-24 10:50:26 +00:00
Eric Liu b72f6098df Added support for different VFSs in format::getStyle.
Summary:
Previously, format::getStyle assumes that the given file resides in
the real file system, which prevents the use of virtual file system in testing etc.
This patch adds a parameter in format::getStyle interface so that users can specify
the right file system. By default, the file system is the real file system.

Reviewers: djasper, klimek

Subscribers: cfe-commits, klimek

Differential Revision: http://reviews.llvm.org/D18399

llvm-svn: 264253
2016-03-24 10:50:17 +00:00
Eric Liu 8c6f72f790 Test commit access to clang repo.
Summary: Test commit access to clang repo.

Reviewers: cfe-commits

Subscribers: klimek

Differential Revision: http://reviews.llvm.org/D18432

llvm-svn: 264252
2016-03-24 10:21:00 +00:00
Daniel Jasper 9c8ff3551a clang-format: Make include sorting's main include detection configurable.
This patch adds a regular expression to configure suffixes of an
included file to check whether it is the "main" include of the current
file. Previously, clang-format has allowed arbitrary suffixes on the
formatted file, which is still the case when no IncludeMainRegex is
specified.

llvm-svn: 263943
2016-03-21 14:11:27 +00:00
Daniel Jasper 97439926e4 clang-format: [JS] Make requoting of JavaScript string literals only
change affected ranges.

llvm-svn: 263713
2016-03-17 13:03:41 +00:00
Daniel Jasper 94a96fcebe clang-format: Use stable_sort when sorting #includes.
Otherwise, clang-format can output useless replacements in the presence
of identical #includes

llvm-svn: 262630
2016-03-03 17:34:14 +00:00
Daniel Jasper abd1f57453 clang-format: [JS] Optionally re-quote string literals.
Turns "foo" into 'foo' (or vice versa, depending on configuration).
This makes it more convenient to follow the Google JavaScript style
guide:
https://google.github.io/styleguide/javascriptguide.xml?showone=Strings#Strings

This functionality is behind the option "JavaScriptQuotes", which can be:

  * "leave" (no re-quoting)
  * "single" (change to single quotes)
  * "double" (change to double quotes)

This also changes single quoted JavaScript string literals to be treated
as tok::string_literal, not tok::char_literal, which fixes two unrelated
tests.

Patch by Martin Probst. Thank you.

llvm-svn: 262534
2016-03-02 22:44:03 +00:00
Manuel Klimek b12e5a5ccd Add functions to apply replacements and reformat them.
This is a commonly useful feature to have, and we have implemented it
multiple times with different kinds of bugs. This implementation
centralizes the idea in a set of functions that we can then use from the various
tools.

Reverts r262234, which is a revert of r262232, and puts the functions
into FOrmat.h, as they are closely coupled to clang-format, and we
otherwise introduce a cyclic dependency between libFormat and
libTooling.

Patch by Eric Liu.

llvm-svn: 262323
2016-03-01 12:37:30 +00:00
Daniel Jasper 2bc3870185 clang-format: [JS] Add @return to the supported JSDoc pragmas in Google
style.

llvm-svn: 261563
2016-02-22 20:24:11 +00:00
Daniel Jasper 8cde3b4b1e clang-format: [JS] Support @see annotations in JSDoc comments in Google
style.

llvm-svn: 260057
2016-02-07 21:22:16 +00:00
Daniel Jasper e1a7b76338 clang-format: Add option to disable string literal formatting.
llvm-svn: 259352
2016-02-01 11:21:02 +00:00
Daniel Jasper e1f72a6727 clang-format: Fix the counting of leading whitespace in tok::unknown tokens
Previously, all whitespace characters would increase the starting
column, which doesn't make sense. This fixes a problem, e.g. with the
length calculation in JS template strings.

llvm-svn: 257267
2016-01-09 21:12:45 +00:00
Daniel Jasper 88c163460c Make clang::format::reformat work with non 0-terminated strings.
llvm-svn: 257259
2016-01-09 15:56:57 +00:00
Daniel Jasper d196abbba3 clang-format: [JS] Add some Closure Compiler JSDoc tags to the default
Google configuration so that they aren't line-wrapped.

llvm-svn: 257159
2016-01-08 08:14:58 +00:00
Daniel Jasper 498f558fcf clang-format: [TableGen] Support ;-less include lines.
llvm-svn: 256412
2015-12-25 08:53:31 +00:00
Nico Weber b10423ad49 Disable include sorting by default for Chromium style.
Include sorting generally can break .cc files, especially on Windows.  Make
this opt-in for Chromium style to give us some more time to roll this out.

(Given that the Google style guide is used by many companies, some of them
probably writing code on Windows, one could argue this should be opt-in in
general...)

llvm-svn: 256288
2015-12-22 22:42:56 +00:00
Daniel Jasper 72a1b6a5f2 clang-format: [JS] "operator" is not a keyword in Java/JavaScript.
llvm-svn: 256245
2015-12-22 15:47:56 +00:00
Daniel Jasper a252f5d56d clang-format: Only consider the first #include that looks right to be
the main #include.

llvm-svn: 256170
2015-12-21 17:28:24 +00:00
Daniel Jasper 41a2bf74ed clang-format: [JS] Change Google-style default for aligning operands.
The style guide allows both, but apparently, this is the more dominant use.

llvm-svn: 256154
2015-12-21 13:52:19 +00:00
Daniel Jasper 32d75fa293 clang-format: Only try to find the "main" include in the first block of
includes.

llvm-svn: 256153
2015-12-21 13:40:49 +00:00
Daniel Jasper 0bfdeb4b6d clang-format: Extend detection of the "main" #include to use the filename
Before, the first (non-system) header in a file was considered to be
the main include. This is conservative as it makes clang-format change
the #include order less often. Instead implement some basic usage of
the filename itself. With this patch, clang-format considers every
header to be a main include if the header file's basename is a prefix
to the filename the #include is in.

llvm-svn: 256148
2015-12-21 12:14:17 +00:00
Zachary Turner 448592eeac Support AlwaysBreakAfterReturnType
This changes the behavior of AlwaysBreakAfterDeclarationReturnType
so that it supports breaking after declarations, definitions, or
both.

Differential Revision: http://reviews.llvm.org/D10370
Reviewed By: Daniel Jasper

llvm-svn: 256046
2015-12-18 22:20:15 +00:00
Daniel Jasper d2629dc812 clang-format: Extend header sort category implementation.
Specifically, it is sometimes necessary to keep certain #includes as
the first #include, even before the main #include for a .cc file.
Switching the category to be signed instead of unsigned isn't ideal,
but it seems as good of an option as any and is fully backwards
compatible.

llvm-svn: 255757
2015-12-16 10:10:16 +00:00
Daniel Jasper e87f5cf4ef clang-format: Fix style default for WebKit and Linux styles.
Brought up in codereviews:
http://reviews.llvm.org/D15445
http://reviews.llvm.org/D15485

llvm-svn: 255484
2015-12-14 08:24:16 +00:00