Commit Graph

2332 Commits

Author SHA1 Message Date
Aaron Ballman ba8dbbe86f Adding an AST matcher to ignore parenthesis in *types* (rather than expressions). This is required for traversing certain types (like function pointer types).
llvm-svn: 271927
2016-06-06 18:52:17 +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 48622090c7 clang-format: [JS] no ASI on `import {x as\n y}`.
Summary: ASI did not handle the ES6 `as` operator correctly.

Reviewers: djasper

Subscribers: klimek, cfe-commits

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

llvm-svn: 271401
2016-06-01 15:22:47 +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
Piotr Padlewski cfed2bf588 [ASTMatchers] Breaking change of `has` matcher
has matcher can now match to implicit and paren casts

http://reviews.llvm.org/D20801

llvm-svn: 271288
2016-05-31 15:25:05 +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
Etienne Bergeron 5500f95a00 [ASTMatchers] Add support of hasCondition for SwitchStmt.
Summary:
The switch statement could be added to the hasCondition matcher.

Example:
```
clang-query> match switchStmt(hasCondition(ignoringImpCasts(declRefExpr())))
```

Output:
```
Match #1:

Binding for "root":
SwitchStmt 0x2f9b528 </usr/local/google/home/etienneb/examples/enum.cc:35:3, line:38:3>
|-<<<NULL>>>
|-ImplicitCastExpr 0x2f9b510 <line:35:11> 'int' <IntegralCast>
| `-ImplicitCastExpr 0x2f9b4f8 <col:11> 'enum Color' <LValueToRValue>
|   `-DeclRefExpr 0x2f9b4d0 <col:11> 'enum Color' lvalue Var 0x2f9a118 'C' 'enum Color'
`-CompoundStmt 0x2f9b610 <col:14, line:38:3>
  |-CaseStmt 0x2f9b578 <line:36:3, col:22>
  | |-ImplicitCastExpr 0x2f9b638 <col:8> 'int' <IntegralCast>
  | | `-DeclRefExpr 0x2f9b550 <col:8> 'enum Size' EnumConstant 0x2f99e40 'Small' 'enum Size'
  | |-<<<NULL>>>
  | `-ReturnStmt 0x2f9b5d0 <col:15, col:22>
  |   `-IntegerLiteral 0x2f9b5b0 <col:22> 'int' 1
  `-DefaultStmt 0x2f9b5f0 <line:37:3, col:12>
    `-BreakStmt 0x2f9b5e8 <col:12>

1 match.
```

Reviewers: aaron.ballman, sbenza, klimek

Subscribers: klimek, cfe-commits

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

llvm-svn: 271208
2016-05-30 15:25:25 +00:00
Daniel Jasper e77f19c0af clang-format: Fix segfault introduced by allowing wraps after comments.
llvm-svn: 271191
2016-05-29 22:07:22 +00:00
Martin Probst 7ea9b6d783 clang-format: [JS] Support shebang lines on the very first line.
Summary:
Shebang lines (`#!/bin/blah`) can be used in JavaScript scripts to indicate
they should be run using e.g. node. This change treats # lines on the first line
as line comments.

Reviewers: djasper

Subscribers: klimek, cfe-commits

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

llvm-svn: 271185
2016-05-29 14:41:36 +00:00
Martin Probst 409697ecb9 clang-format: [JS] fix async parsing.
Summary:
Only treat the sequence `async function` as the start of a function expression,
as opposed to every occurrence of the token `async` (whoops).

Reviewers: djasper

Subscribers: klimek, cfe-commits

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

llvm-svn: 271184
2016-05-29 14:41:07 +00:00
Daniel Jasper 99302edd1c clang-format: Allow splitting the line after /**/-comments.
While it might change the meaning of the comment in rare circumstances,
it is better than violating the column limit.

llvm-svn: 270975
2016-05-27 08:59:34 +00:00
Eric Liu 1ef68456cf [clang-format] moved unit tests related to replacements cleaner from FormatTest.cpp to CleanUpTest.cpp.
llvm-svn: 270971
2016-05-27 08:20:02 +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
Daniel Jasper 997cf2fea8 clang-format: [JS] Treat "for" as a reserved word after a ".".
Otherwise, clang-format can get confused with statements like:

  x.for = 1;

llvm-svn: 270188
2016-05-20 06:16:01 +00:00
Vedant Kumar 95a2a7f2a1 [Lexer] Don't merge macro args from different macro files
The lexer sets the end location of macro arguments incorrectly *if*,
while merging consecutive args to fit into a single SLocEntry, it finds
args which come from different macro files.

Fix the issue by using separate SLocEntries in this situation.

This fixes a code coverage crasher (rdar://problem/26181005). Because
the lexer reported end locations for certain macro args incorrectly, we
would generate bogus coverage mappings with negative line offsets.

Reviewed-by: akyrtzi

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

llvm-svn: 270160
2016-05-19 23:44:02 +00:00
Benjamin Kramer b872733851 [Sema] Allow an external sema source to handle delayed typo corrections.
This probably isn't perfectly perfect but allows correcting function calls
again.

llvm-svn: 270039
2016-05-19 10:46:10 +00:00
Daniel Jasper 5dbcd3bd07 clang-format: [JS] Fix spacing in destructuring assignments.
Before:
  const[a, b, c] = [1, 2, 3];

After:
  const [a, b, c] = [1, 2, 3];

llvm-svn: 270029
2016-05-19 07:18:07 +00:00
Daniel Jasper 451544ab57 clang-format: Fix incorrect indentation in last line of macro definition
Before:
  #define MACRO(a) \
    if (a) {       \
      f();         \
    } else         \
    g()

After:
  #define MACRO(a) \
    if (a) {       \
      f();         \
    } else         \
      g()

llvm-svn: 270028
2016-05-19 06:30:48 +00:00
Daniel Jasper e2fab13313 clang-format: Fix enumerator case ranges.
Before:
  case a... b: break;

After:
  case a ... b: break;

llvm-svn: 270027
2016-05-19 06:19:17 +00:00
Haojian Wu 40b1277135 [ASTMacther] A follow-up on unresolvedLookupExpr test fixing.
llvm-svn: 269957
2016-05-18 16:48:44 +00:00
Haojian Wu da5b1131de [ASTMatcher] Fix a ASTMatcher test failure on Windows.
Reviewers: alexfh, aaron.ballman

Subscribers: thakis, cfe-commits, klimek

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

llvm-svn: 269936
2016-05-18 15:15:12 +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
Haojian Wu 7751c92582 [ASTMatcher] Add a node matcher for UnresolvedLookupExpr.
Reviewers: alexfh, aaron.ballman

Subscribers: aaron.ballman, klimek, cfe-commits

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

llvm-svn: 269916
2016-05-18 12:53:59 +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
Piotr Padlewski c6e0502997 Dividied ASTMatcherTests into 4 files
fix for long compilation [20061]
http://reviews.llvm.org/D20210

llvm-svn: 269802
2016-05-17 19:22:57 +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
Aaron Ballman abdbbbc51f Add the hasDynamicExceptionSpec() AST matcher to match function declarations that have a dynamic exception specification.
Patch by Don Hinton.

llvm-svn: 269662
2016-05-16 16:49:01 +00:00
Bruno Cardoso Lopes 32b2897af6 [VFS] Add level() method to vfs::recursive_directory_iterator
Unlike sys::fs::recursive_directory_iterator,
vfs::recursive_directory_iterator does not implement the level() method,
which tells how deep in the directory tree the current iterator is. This
is needed in the vfs::recursive_directory_iterator so that future
improvements to the crash reproducer will be able to properly access
header for umbrellas when looking into the VFS.

rdar://problem/25880368

llvm-svn: 269520
2016-05-14 00:00:18 +00:00
Etienne Bergeron 75e52725e4 Add an AST matcher for CastExpr kind
Summary:
This AST matcher will match a given CastExpr kind.
It's an narrowing matcher on CastExpr.

Reviewers: klimek, alexfh, sbenza, aaron.ballman

Subscribers: Prazek, jroelofs, aaron.ballman, klimek, cfe-commits

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

llvm-svn: 269460
2016-05-13 19:36:55 +00:00
Bruno Cardoso Lopes f6a0a72dbe [VFS] Reapply #2: Reconstruct the VFS overlay tree for more accurate lookup
Reapply r269100 and r269270, reverted due to
https://llvm.org/bugs/show_bug.cgi?id=27725. Isolate the testcase that
corresponds to the new feature side of this commit and skip it on
windows hosts until we find why it does not work on these platforms.

Original commit message:

The way we currently build the internal VFS overlay representation leads
to inefficient path search and might yield wrong answers when asked for
recursive or regular directory iteration.

Currently, when reading an YAML file, each YAML root entry is placed
inside a new root in the filesystem overlay. In the crash reproducer, a
simple "@import Foundation" currently maps to 43 roots, and when looking
up paths, we traverse a directory tree for each of these different
roots, until we find a match (or don't). This has two consequences:

- It's slow.
- Directory iteration gives incomplete results since it only return
results within one root - since contents of the same directory can be
declared inside different roots, the result isn't accurate.

This is in part fault of the way we currently write out the YAML file
when emitting the crash reproducer - we could generate only one root and
that would make it fast and correct again. However, we should not rely
on how the client writes the YAML, but provide a good internal
representation regardless.

Build a proper virtual directory tree out of the YAML representation,
allowing faster search and proper iteration. Besides the crash
reproducer, this potentially benefits other VFS clients.

llvm-svn: 269327
2016-05-12 19:13:07 +00:00
Bruno Cardoso Lopes 2835c5c975 [Unittests] Reverse the order of arguments for correct debug output
llvm-svn: 269326
2016-05-12 19:13:04 +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
Bruno Cardoso Lopes 26092b2934 Revert "[VFS] Reapply r269100: Reconstruct the VFS overlay tree for more accurate lookup"
Reverts r269270, buildbots still failing:
http://lab.llvm.org:8011/builders/clang-x64-ninja-win7/builds/12119
http://bb.pgr.jp/builders/ninja-clang-i686-msc19-R/builds/2847

llvm-svn: 269276
2016-05-12 04:43:27 +00:00
Etienne Bergeron 3588be7fa1 Add an AST matcher for string-literal length
Summary:
This patch is adding support for a matcher to check string literal length.

This matcher is used in clang-tidy checkers and is part of this refactoring:
  see: http://reviews.llvm.org/D19841

Reviewers: sbenza, klimek, aaron.ballman

Subscribers: alexfh, klimek, cfe-commits

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

llvm-svn: 269274
2016-05-12 04:20:04 +00:00
Bruno Cardoso Lopes ab83dc646d [VFS] Reapply r269100: Reconstruct the VFS overlay tree for more accurate lookup
The way we currently build the internal VFS overlay representation leads
to inefficient path search and might yield wrong answers when asked for
recursive or regular directory iteration.

Currently, when reading an YAML file, each YAML root entry is placed
inside a new root in the filesystem overlay. In the crash reproducer, a
simple "@import Foundation" currently maps to 43 roots, and when looking
up paths, we traverse a directory tree for each of these different
roots, until we find a match (or don't). This has two consequences:

- It's slow.
- Directory iteration gives incomplete results since it only return
results within one root - since contents of the same directory can be
declared inside different roots, the result isn't accurate.

This is in part fault of the way we currently write out the YAML file
when emitting the crash reproducer - we could generate only one root and
that would make it fast and correct again. However, we should not rely
on how the client writes the YAML, but provide a good internal
representation regardless.

This patch builds a proper virtual directory tree out of the YAML
representation, allowing faster search and proper iteration. Besides the
crash reproducer, this potentially benefits other VFS clients.

llvm-svn: 269270
2016-05-12 03:23:36 +00:00
Bruno Cardoso Lopes 29ebd4979a [VFS][Unittests] Make dir iteration tests depend only on content
Do not rely on any specific order while comparing the results of
directory iteration.

llvm-svn: 269234
2016-05-11 20:58:47 +00:00
Etienne Bergeron 53276d1221 [tooling] FixItHint Tooling refactoring
Summary:
This is the refactoring to lift some FixItHint into tooling.
used by: http://reviews.llvm.org/D19807

Reviewers: klimek, alexfh

Subscribers: cfe-commits

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

llvm-svn: 269188
2016-05-11 14:31:39 +00:00
Sean Silva 7e61e1509a Hopefully bring llvm-clang-lld-x86_64-scei-ps4-windows10pro-fast back to life
Bruno made a couple valiant attempts but the bot is still red.

This reverts r269100 (primary commit), r269108 (fix attempt), r269133
(fix attempt).

llvm-svn: 269160
2016-05-11 04:04:59 +00:00
Bruno Cardoso Lopes 14e89e022a [VFS] One more unittest change to fix win10 buildbot
http://lab.llvm.org:8011/builders/llvm-clang-lld-x86_64-scei-ps4-windows10pro-fast/builds/5110
Follow up from r269100.

llvm-svn: 269133
2016-05-10 22:30:01 +00:00
Bruno Cardoso Lopes 7347fce4c3 [VFS] Change unittest to try appeasing win10 buildbot
http://lab.llvm.org:8011/builders/llvm-clang-lld-x86_64-scei-ps4-windows10pro-fast/builds/5103
Follow up from r269100.

llvm-svn: 269108
2016-05-10 20:20:55 +00:00
Bruno Cardoso Lopes ecf7d15d49 [VFS] Reconstruct the VFS overlay tree for more accurate lookup
The way we currently build the internal VFS overlay representation leads
to inefficient path search and might yield wrong answers when asked for
recursive or regular directory iteration.

Currently, when reading an YAML file, each YAML root entry is placed
inside a new root in the filesystem overlay. In the crash reproducer, a
simple "@import Foundation" currently maps to 43 roots, and when looking
up paths, we traverse a directory tree for each of these different
roots, until we find a match (or don't). This has two consequences:

- It's slow.
- Directory iteration gives incomplete results since it only return
results within one root - since contents of the same directory can be
declared inside different roots, the result isn't accurate.

This is in part fault of the way we currently write out the YAML file
when emitting the crash reproducer - we could generate only one root and
that would make it fast and correct again. However, we should not rely
on how the client writes the YAML, but provide a good internal
representation regardless.

This patch builds a proper virtual directory tree out of the YAML
representation, allowing faster search and proper iteration. Besides the
crash reproducer, this potentially benefits other VFS clients.

llvm-svn: 269100
2016-05-10 18:43:00 +00:00
Richard Smith 57443fce3f When forming a fully-qualified type name, put any qualifiers outside/before the
nested-name-specifier. Patch by Sterling Augustine!

llvm-svn: 268988
2016-05-09 23:06:14 +00:00
Daniel Jasper 2b2c967c1a clang-format: Fix space after argument comments.
Before:
  f(/*a=*/a, /*b=*/ ::b);

After:
  f(/*a=*/a, /*b=*/::b);

llvm-svn: 268879
2016-05-08 18:14:01 +00:00
Daniel Jasper a7900adf41 clang-format: Support enum type template arguments.
Before:
  template <enum E> class A { public : E *f(); };

After:
  template <enum E> class A {
  public:
    E *f();
  };

llvm-svn: 268878
2016-05-08 18:12:22 +00:00
Gabor Horvath 1b3f8db8b6 [ASTMatchers] New matcher forFunction
Summary: Matcher proposed in the review of checker misc-assign-operator (name pending). Its goal is to find the direct enclosing function declaration of a statement and run the inner matcher on it. Two version is attached in this patch (thus it will not compile), to be decided which approach to take. The second one always chooses one single parent while the first one does a depth-first search upwards (thus a height-first search) and returns the first positive match of the inner matcher (thus it always returns zero or one matches, not more). Further questions: is it enough to implement it in-place, or ASTMatchersInternals or maybe ASTMatchFinder should be involved?

Reviewers: sbenza

Subscribers: aaron.ballman, klimek, o.gyorgy, xazax.hun, cfe-commits

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

llvm-svn: 268490
2016-05-04 11:59:39 +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
Martin Probst 5f8445b32a clang-format: [JS] generator and async functions.
For generators, see:
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Iterators_and_generators
async functions are not quite in the spec yet, but stage 3 and already widely used:
http://tc39.github.io/ecmascript-asyncawait/

Reviewers: djasper

Subscribers: klimek

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

llvm-svn: 267368
2016-04-24 22:05:09 +00:00
Aaron Ballman 1978f7fe29 Clarify memory ownership semantics; NFC.
Patch by Clement Courbet

llvm-svn: 266986
2016-04-21 13:51:07 +00:00
Chaoren Lin e6f04f3553 [Tooling] Fix getting fully qualified names of template alias types.
Reviewers: rsmith, rnk

Subscribers: cfe-commits, klimek

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

llvm-svn: 266925
2016-04-20 22:12:07 +00:00