Commit Graph

2474 Commits

Author SHA1 Message Date
Daniel Jasper fd36f0b504 clang-format: Support ObjC selectors with unnamed parameters.
This fixes llvm.org/PR28063.

llvm-svn: 286715
2016-11-12 07:38:22 +00:00
Nico Weber b2673a1e48 [clang-format] Fix PR30527: Regression when clang-format insert spaces in [] when in template
Actual regression was introduced in r272668. This revision fixes JS script, but
also regress Cpp case. It manifests with spaces added when template is followed
with array. Bug 30527 mentions case of array as a nested template type
(foo<bar<baz>[]>). Fix is to detect such case and to prevent treating it as
array initialization, but as a subscript case. However, before r272668, this
case was treated simple because we were detecting it as a StartsObjCMethodExpr.
Same was true for other similar case - array of templates (foo<int>[]). This
patch tries to address two problems: 1) fixing regression 2) making sure both
cases (array as a nested type, array of templates) which were entering
StartsObjCMethodExpr branch are handled now appropriately.

https://reviews.llvm.org/D26163
Patch from Branko Kokanovic <branko@kokanovic.org>!

llvm-svn: 286507
2016-11-10 21:49:25 +00:00
Martin Probst 72fd75a0d1 clang-format: [JS] do not break after declare namespace.
See TypeScript grammar for tokens following 'declare':
https://github.com/Microsoft/TypeScript/blob/master/doc/spec.md#A.10

llvm-svn: 286467
2016-11-10 16:20:58 +00:00
Serge Pavlov a67a4d2f3c Make output of -ast-print a valid C++ code.
Output generated by option -ast-print looks like C/C++ code, and it
really is for plain C. For C++ the produced output was not valid C++
code, but the differences were small. With this change the output
is fixed and can be compiled. Tests are changed so that output produced
by -ast-print is compiled again with the same flags and both outputs are
compared.

Option -ast-print is extensively used in clang tests but it itself
was tested poorly, existing tests only checked that compiler did not
crash. There are unit tests in file DeclPrinterTest.cpp, but they test
only terse output mode.

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

llvm-svn: 286439
2016-11-10 08:49:37 +00:00
Daniel Jasper 8315ea1613 clang-format: [TypeScript] Fix bug in handling of non-null operator.
Before:
  var i = x!-1;

After:
  var i = x! - 1;

llvm-svn: 286367
2016-11-09 14:12:55 +00:00
Pavel Labath ac71c8e298 [VFS] Replace TimeValue usage with std::chrono
Summary: NFCI

Reviewers: benlangmuir, zturner

Subscribers: cfe-commits

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

llvm-svn: 286356
2016-11-09 10:52:22 +00:00
Alexander Kornienko 8df2a62ae6 Add a method to get the list of registered static analyzer checkers.
Summary:
This provides a better interface for clang-tidy and encapsulates the knowledge
about experimental checkers instead of leaving this to the clients.

Reviewers: zaks.anna

Subscribers: a.sidorin, NoQ, dcoughlin, cfe-commits

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

llvm-svn: 286218
2016-11-08 07:23:32 +00:00
Eric Liu 6b3a7ccc7c Fix memory leak caused by r286096.
llvm-svn: 286132
2016-11-07 18:40:41 +00:00
Eric Liu cf2913c6f1 Deduplicate replacements by FileEntry instead of file names.
Summary:
The current version does not deduplicate equivalent file paths correctly.
For example, a relative path and an absolute path are considered inequivalent.
Comparing FileEnry addresses these issues.

Reviewers: djasper

Subscribers: alexshap, klimek, cfe-commits

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

llvm-svn: 286096
2016-11-07 06:08:23 +00:00
Daniel Jasper a432208bca clang-format: Better support for CUDA's triple brackets.
Before:
  aaaaaaaaaaaaaaa<
      aaaaaaaaa, aaaaaaaaaa,
      aaaaaaaaaaaaaa><<<aaaaaaaaa, aaaaaaaaaa, aaaaaaaaaaaaaaaaaa>>>();

After:
  aaaaaaaaaaaaaaa<aaaaaaaaa, aaaaaaaaaa, aaaaaaaaaaaaaa>
      <<<aaaaaaaaa, aaaaaaaaaa, aaaaaaaaaaaaaaaaaa>>>();

llvm-svn: 286041
2016-11-05 17:43:16 +00:00
Malcolm Parsons 6af3f14efb Fixed column shift when formatting line containing bit shift operators
Summary:
During clang-format source lexing >> and << operators are split and
treated as two less/greater operators but column position of following
tokens was not adjusted accordingly.

Fixes PR26887

Patch by Paweł Żukowski.

Reviewers: djasper

Subscribers: malcolm.parsons, mprobst, klimek, cfe-commits

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

llvm-svn: 285934
2016-11-03 16:57:30 +00:00
Aaron Ballman 6b42a5b0fd Turn on the /bigobj switch for RecursiveASTVisitorTest.cpp; we are now bumping up against that limit with MSVC 2015 in Win64 debug build mode.
llvm-svn: 285810
2016-11-02 14:31:36 +00:00
Malcolm Parsons f76f6507c2 Fix Clang-tidy readability-redundant-string-cstr warnings
Reviewers: aaron.ballman, mehdi_amini, dblaikie

Subscribers: cfe-commits

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

llvm-svn: 285799
2016-11-02 10:39:27 +00:00
Daniel Jasper 28b4d5133c clang-format: Fix bug in function reference qualifier detection.
Before:
  template <typename T>
      void F(T) &&
      = delete;

After:
  template <typename T>
  void F(T) && = delete;

llvm-svn: 285674
2016-11-01 06:23:19 +00:00
Daniel Jasper d0d27aa59b clang-format: Fix incorrect pointer detection.
Before:
  void f() { f(float{1}, a *a); }

After:
  void f() { f(float{1}, a * a); }

llvm-svn: 285673
2016-11-01 06:23:14 +00:00
Daniel Jasper b559b43802 clang-format: [JS] Fix incorrect space when "as" is used as identifier.
Before:
  aaaaa.as ();

After:
  aaaaa.as();

llvm-svn: 285672
2016-11-01 06:23:10 +00:00
Daniel Jasper 3ade3be2a1 clang-format: Fix incorrect binary operator detection.
Before:
  int x = f(* + [] {});

After:
  int x = f(*+[] {});

llvm-svn: 285671
2016-11-01 06:23:05 +00:00
Daniel Jasper 71e50af675 clang-format: [JS] Fix formatting of generator functions.
Before:
  var x = {
    a: function*
	() {
	  //
	}
  }

After:
  var x = {
    a: function*() {
      //
    }
  }

llvm-svn: 285670
2016-11-01 06:22:59 +00:00
Daniel Jasper 4d67dd77a1 clang-format: [JS] Fix space when for is used as regular identifier.
Before:
  x.for () = 1;

After:
  x.for() = 1;

llvm-svn: 285669
2016-11-01 06:22:54 +00:00
Malcolm Parsons 7d96c334d2 [ASTMatcher] Add CXXNewExpr support to hasDeclaration
Reviewers: sbenza, lukasza, aaron.ballman, klimek

Subscribers: lukasza, sbenza, cfe-commits

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

llvm-svn: 285644
2016-10-31 22:04:07 +00:00
Daniel Jasper fda47cd873 Skip over AnnotatedLines with >50 levels of nesting; don't format them.
Reasoning:
- ExpressionParser uses a lot of stack for these, bad in some environments.
- Our formatting algorithm is N^3 and gets really slow.
- The resulting formatting is unlikely to be any good.
- This is probably generated code we're formatting by accident.

We treat these as unparseable, and signal incomplete formatting. 50 is
an arbitrary number, I've only seen real problems from ~150 levels.

Patch by Sam McCall. Thank you.

llvm-svn: 285570
2016-10-31 13:23:00 +00:00
Daniel Jasper eb886635d9 clang-format: [JS] Fix missing space after 'yield'.
Before:
  class X {
    delete(val) {
      return null;
    }
    * gen() {
      yield[1, 2];
    }
    * gen() {
      yield{a: 1};
    }
  };

After:
  class X {
    delete(val) {
      return null;
    }
    * gen() {
      yield [1, 2];
    }
    * gen() {
      yield {a: 1};
    }
  };

llvm-svn: 285569
2016-10-31 13:18:25 +00:00
Malcolm Parsons 9bd85d2286 [RecursiveASTVisitor] Visit the implicit expression of a CXXDefaultArgExpr
Summary:
The matcher
varDecl(hasDescendant(
    callExpr(hasDeclaration(functionDecl(unless(isNoThrow()))))))
didn't match calls from default arguments because the expression
for a CXXDefaultArgExpr was not visited.

Reviewers: klimek, jdennett, alexfh, aaron.ballman

Subscribers: aaron.ballman, cfe-commits

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

llvm-svn: 285239
2016-10-26 20:39:54 +00:00
Andi-Bogdan Postelnicu a9a8fdee7e Bug 28065 - clang-format incorrectly aligns backslash.
llvm-svn: 285178
2016-10-26 07:44:51 +00:00
Malcolm Parsons 57c09c8e23 [Sema] Store a SourceRange for multi-token builtin types
Summary:
clang-tidy's modernize-use-auto check uses the SourceRange of a
TypeLoc when replacing the type with auto.
This was producing the wrong result for multi-token builtin types
like long long:

-long long *ll = new long long();
+auto long *ll = new long long();

Reviewers: alexfh, hokein, rsmith, Prazek, aaron.ballman

Subscribers: cfe-commits

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

llvm-svn: 284885
2016-10-21 21:13:56 +00:00
Martin Probst 717f6dcddc clang-format: [JS] Fix template string ASI.
Summary:
Previously, automatic semicolon insertion would add an unwrapped line
when a template string contained a line break.

    var x = `foo${
        bar}`;

Would be formatted with `bar...` on a separate line and no indent.

Reviewers: djasper

Subscribers: cfe-commits, klimek

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

llvm-svn: 284807
2016-10-21 05:11:38 +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
Eric Liu c45343ea28 Try to fix windows bot file path style failure caused by r284219.
llvm-svn: 284222
2016-10-14 10:10:26 +00:00
Eric Liu cefe763dd2 Deduplicate sets of replacements by file names.
Summary:
If there are multiple <File, Replacements> pairs with the same file
path after removing dots, we only keep one pair (with path after dots being
removed) and discard the rest.

Reviewers: djasper

Subscribers: klimek, hokein, bkramer, cfe-commits

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

llvm-svn: 284219
2016-10-14 09:32:06 +00:00
Mehdi Amini 0df59d8c02 Turn FileManager DirectoryEntry::Name from raw pointer to StringRef (NFC)
llvm-svn: 283856
2016-10-11 07:31:29 +00:00
Mehdi Amini 004b9c7aae Store FileEntry::Filename as a StringRef instead of raw pointer (NFC)
llvm-svn: 283815
2016-10-10 22:52:47 +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
Daniel Jasper 85d1f0b610 clang-format: Fix bad multi-variable for-loop formatting.
Before:
  for (int*p, *q; p != q; p = p->next) {

After:
  for (int *p, *q; p != q; p = p->next) {

llvm-svn: 283246
2016-10-04 20:18:25 +00:00
Eric Liu 6ef82b6754 Merge conflicting replacements when they are order-independent.
Summary:
Now two replacements are considered order-independent if applying them in
either order produces the same result. These include (but not restricted
to) replacements that:
  - don't overlap (being directly adjacent is fine) and
  - are overlapping deletions.
  - are insertions at the same offset and applying them in either order
    has the same effect, i.e. X + Y = Y + X if one inserts text X and the
    other inserts text Y.

Discussion about this design can be found in D24717

Reviewers: djasper, klimek

Subscribers: omtcyfz, cfe-commits

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

llvm-svn: 282577
2016-09-28 11:02:16 +00:00
Aleksei Sidorin a693b37e14 [ASTImporter] Implement some expression-related AST node import (part 2)
* Some code cleanup
* Add tests not present in http://reviews.llvm.org/D14286
* Integrate a test suite from Serge Pavlov (http://reviews.llvm.org/D14224)
* ArrayTypeTraitExpr: serialize sub-expression to avoid keeping it undefined
* Implement import of some nodes:
  - ArrayTypeTraitExpr
  - ExpressionTraitExpr
  - OpaqueValueExpr
  - ArraySubscriptExpr
  - ExplicitCastExpr
  - ImplicitValueInitExpr
  - OffsetOfExpr
  - CXXThisExpr
  - CXXThrowExpr
  - CXXNoexceptExpr
  - CXXDefaultArgExpr
  - CXXScalarValueInitExpr
  - CXXBindTemporaryExpr
  - CXXTemporaryObjectExpr
  - MaterializeTemporaryExpr
  - ExprWithCleanups

  - StaticAssertDecl
  - FriendDecl

  - DecayedType

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

llvm-svn: 282572
2016-09-28 10:16:56 +00:00
Haojian Wu 398a8eaf33 [ASTMatcher] Clarify isStaticStorageClass and hasStaticStorageDuration documents.
Reviewers: aaron.ballman

Subscribers: klimek, cfe-commits

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

llvm-svn: 282474
2016-09-27 07:53:20 +00:00
Daniel Jasper e31388aee9 [clang-format] Don't allow newline after uppercase Obj-C block return types
Fixes the following:
  BOOL (^aaa)(void) = ^BOOL {
  };

The first BOOL's token was getting set to TT_FunctionAnnotationRParen
incorrectly, which was causing an unexpected newline after (^aaa). This
was introduced in r245846.

Patch by Kent Sutherland, thank you!

llvm-svn: 282448
2016-09-26 22:19:08 +00:00
Aaron Ballman 5fa302cb65 Complete support for the cxxCtorInitializer() AST matcher so that it can be used as a top-level matcher.
llvm-svn: 282417
2016-09-26 17:04:27 +00:00
Haojian Wu b3d2546c43 [ASTMatcher] Add isStaticStorageClass matcher for varDecl and functionDecl.
Reviewers: klimek

Subscribers: cfe-commits, klimek

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

llvm-svn: 282415
2016-09-26 16:01:52 +00:00
Daniel Jasper 3f2cde91d8 clang-format: Only special-case top-level */& in multivar-declstmts.
Before (even with PointerAlignment: Left):
  vector<int *> a, b;

After:
  vector<int*> a, b;

llvm-svn: 282410
2016-09-26 15:14:24 +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 4210d2fd1e clang-format: [JS] reserved words in method names.
Summary:
Before:
    class X {
      delete () {
        ...
      }
    }

After:
    class X {
      delete() {
        ...
      }
    }

Reviewers: djasper

Subscribers: cfe-commits, klimek

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

llvm-svn: 282138
2016-09-22 07:18:00 +00:00
Eric Liu 9df9b6fd6d Recommit r281457 "Supports adding insertion around non-insertion replacements".
Summary:
Diff to r281457:
- added a test case `CalculateRangesOfInsertionAroundReplacement`.

Reviewers: djasper

Subscribers: cfe-commits, klimek

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

llvm-svn: 281891
2016-09-19 08:40:42 +00:00
Martin Probst 63014581aa clang-format: [JS] Fix line breaks before comments when sorting imports.
Summary:
Previously, clang-format would always insert an additional line break after the
import block if the main body started with a comment, due to loosing track of
the first non-import line.

Reviewers: djasper

Subscribers: cfe-commits, klimek

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

llvm-svn: 281888
2016-09-19 07:02:34 +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
Martin Probst b9316ff849 clang-format: [JS] ASI insertion after boolean literals.
Summary:
Before when a semicolon was missing after a boolean literal:
    a = true
    return 1;

clang-format would parse this as one line and format as:
    a = true return 1;

It turns out that C++ does not consider `true` and `false` to be literals, we
have to check for that explicitly.

Reviewers: djasper

Subscribers: klimek, cfe-commits

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

llvm-svn: 281856
2016-09-18 17:21:52 +00:00
Daniel Jasper 58209dd9ad clang-format: [JS] Fix a crash in handledTemplateStrings.
llvm-svn: 281816
2016-09-17 07:20:36 +00:00
Artem Belevich 05a4034bc3 Revert r281457 "Supports adding insertion around non-insertion replacements."
Commit was breaking our internal tests.

llvm-svn: 281557
2016-09-14 23:03:06 +00:00
Eric Liu ac73ea34a4 Supports adding insertion around non-insertion replacements.
Summary:
Extend `tooling::Replacements::add()` to support adding order-independent replacements.

Two replacements are considered order-independent if one of the following conditions is true:
  - They do not overlap. (This is already supported.)
  - One replacement is insertion, and the other is a replacement with
    length > 0, and the insertion is adjecent to but not contained in the
    other replacement. In this case, the replacement should always change
    the original code instead of the inserted text.

Reviewers: klimek, djasper

Subscribers: cfe-commits, klimek

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

llvm-svn: 281457
2016-09-14 13:04:51 +00:00