Commit Graph

1480 Commits

Author SHA1 Message Date
Daniel Jasper a58dd5db29 clang-format: Fix another false positive in the lambda detection.
Before:
  int i = (*b)[a] -> f();

After:
  int i = (*b)[a]->f();

llvm-svn: 203557
2014-03-11 10:03:33 +00:00
Daniel Jasper d3c7ab975f clang-format: Fix incorrect lambda recognition exposed by r203452.
Before:
  int i = a[a][a] -> f();

After:
  int i = a[a][a]->f();

llvm-svn: 203556
2014-03-11 09:59:36 +00:00
Daniel Jasper c580af96fa clang-format: Detect weird macro lambda usage.
Before:
  void f() {
    MACRO((const AA & a) { return 1; });
  }

After:
  void f() {
    MACRO((const AA &a) { return 1; });
  }

llvm-svn: 203551
2014-03-11 09:29:46 +00:00
David Blaikie 0e18ed2eba Fix use of uninitialized variable in ExternalASTSourceTest.cpp (introduced in 203525)
llvm-svn: 203545
2014-03-11 06:49:26 +00:00
Richard Smith 023d2ca451 Add a unittest for the ExternalASTSource.
llvm-svn: 203525
2014-03-11 01:18:47 +00:00
Samuel Benzaquen a083935d0a Add loc() to the dynamic registry.
Summary:
Add loc() to the dynamic registry.
Other fixes:
 - Fix the polymorphic variant value to accept an exact match, even if
   there are other possible conversions.
 - Fix specifiesTypeLoc() to not crash on an empty
   NestedNameSpecifierLoc.

Reviewers: klimek

CC: cfe-commits, klimek

Differential Revision: http://llvm-reviews.chandlerc.com/D2928

llvm-svn: 203467
2014-03-10 15:40:23 +00:00
Daniel Jasper 84a12e18d3 clang-format: Add spaces between lambdas and comments.
Before:
  void f() {
    bar([]() {}// Does not respect SpacesBeforeTrailingComments
        );
  }

After:
  void f() {
    bar([]() {} // Does not respect SpacesBeforeTrailingComments
        );
  }

This fixes llvm.org/PR19017.

llvm-svn: 203466
2014-03-10 15:06:25 +00:00
Alexander Kornienko 4504f93901 Preserve hanging indent when breaking line comments.
Summary:
If we need to break the second line here:
// something: aaaaa aaaaa aaaaaa aaaaa aaaaa
//            aaaaa aaaaa aaaaaa aaaaa aaaaa aaaaa

with the patch it will be turned to

// something: aaaaa aaaaa aaaaaa aaaaa aaaaa
//            aaaaa aaaaa aaaaaa aaaaa aaaaa
//            aaaaa

instead of

// something: aaaaa aaaaa aaaaaa aaaaa aaaaa
//            aaaaa aaaaa aaaaaa aaaaa aaaaa
// aaaaa

Reviewers: djasper, klimek

Reviewed By: klimek

CC: cfe-commits, klimek

Differential Revision: http://llvm-reviews.chandlerc.com/D2988

llvm-svn: 203458
2014-03-10 13:14:56 +00:00
Daniel Jasper 81a20787db clang-format: Add spaces around trailing/lambda return types.
Before:
  int c = []()->int { return 2; }();

After:
  int c = []() -> int { return 2; }();

llvm-svn: 203452
2014-03-10 10:02:02 +00:00
Richard Smith 664b32b814 Revert accidentally-committed file.
llvm-svn: 203318
2014-03-08 00:04:19 +00:00
Richard Smith 9bca298f6d Module [extern_c] attribute: inherit to submodules, don't write 'extern "C"'
blocks when building in C mode, and serialize and deserialize the attribute.

llvm-svn: 203317
2014-03-08 00:03:56 +00:00
Ahmed Charles b89843299a Replace OwningPtr with std::unique_ptr.
This compiles cleanly with lldb/lld/clang-tools-extra/llvm.

llvm-svn: 203279
2014-03-07 20:03:18 +00:00
Ahmed Charles d72a5f103d Replace OwningPtr::isValid() with conversion to bool.
This is a precursor to moving to std::unique_ptr.

llvm-svn: 203277
2014-03-07 19:51:06 +00:00
Ahmed Charles 9a16beb8bc Change OwningPtr::take() to OwningPtr::release().
This is a precursor to moving to std::unique_ptr.

llvm-svn: 203275
2014-03-07 19:33:25 +00:00
Alexander Kornienko 86b2dfdc3b Fix operator<< recognition (PR19064).
llvm-svn: 203123
2014-03-06 15:13:08 +00:00
Ben Langmuir 9385323747 Attempt to re-enable the VFS unittests on Windows
Using a //net/ path to hopefully avoid problems with non-absolute paths
on Windows.

llvm-svn: 203010
2014-03-05 21:32:20 +00:00
NAKAMURA Takumi 6a927ecb7a Disable BasicTests/VFS on win32 for now. Investigating.
Failing Tests (5):
    Clang-Unit :: Basic/BasicTests.exe/VFSFromYAMLTest.CaseInsensitive
    Clang-Unit :: Basic/BasicTests.exe/VFSFromYAMLTest.MappedFiles
    Clang-Unit :: Basic/BasicTests.exe/VFSFromYAMLTest.MultiComponentPath
    Clang-Unit :: Basic/BasicTests.exe/VFSFromYAMLTest.TrailingSlashes
    Clang-Unit :: Basic/BasicTests.exe/VFSFromYAMLTest.UseExternalName

llvm-svn: 202952
2014-03-05 09:10:04 +00:00
David Majnemer 197e2103a2 Speculatively fix MSVC buildbots
llvm-svn: 202938
2014-03-05 06:32:38 +00:00
Chandler Carruth 757fcd6d1f [cleanup] Re-sort includes with llvm/utils/sort_includes.py and fix
a missing include from CLog.h.

CLog.h referenced most of the core libclang types but never directly
included Index.h that provides them. Previously it got lucky and other
headers were always included first but with the sorting it ended up
first in one case and stopped compiling. Adding the Index.h include
fixes it right up.

llvm-svn: 202810
2014-03-04 10:05:20 +00:00
Dmitri Gribenko 5ea34fcc8d Decl printing: add tests for typedefs
Patch by Konrad Kleine.

llvm-svn: 202709
2014-03-03 13:21:00 +00:00
Peter Collingbourne f93725459a MSVC 2012 doesn't support std::initializer_list at all, so don't rely on
that std::vector constructor.

llvm-svn: 202684
2014-03-03 08:13:06 +00:00
Peter Collingbourne 2bbb029599 MSVC cannot understand temporaries formed from initializer lists.
llvm-svn: 202682
2014-03-03 07:49:35 +00:00
Argyrios Kyrtzidis d502a10c5e [libclang] Introduce APIs that assist in constructing a simple module.map file for a user framework.
rdar://16092858

llvm-svn: 202681
2014-03-03 07:41:45 +00:00
Argyrios Kyrtzidis 74c96c0c75 [libclang] Change clang_VirtualFileOverlay_writeToBuffer to return a malloc'ed buffer.
Returning CXString is not appropriate if we want to switch to a non-string format buffer.

llvm-svn: 202675
2014-03-03 06:38:52 +00:00
Peter Collingbourne c0423b349b Disable all dependency output options when using the Tooling library.
It isn't appropriate for a tool to be stomping over the dependency files,
especially if the actual build uses a compiler other than Clang or the tool
cannot find all the headers for some reason (which would cause the existing
dependency file to be deleted).

If a tool actually needs to care about dependency files we can think about
adding a mechanism for getting to this information.

Differential Revision: http://llvm-reviews.chandlerc.com/D2912

llvm-svn: 202669
2014-03-02 23:37:26 +00:00
Chandler Carruth f8b7266d57 [C++11] Switch the clang-format LLVM style to use C++11 style braced
init list formatting. This suggestion has now gone into the LLVM coding
standards, and is particularly relevant now that we're using C++11.

Updated a really ridiculous number of tests to reflect this change.

llvm-svn: 202637
2014-03-02 12:37:31 +00:00
Craig Topper a798a9db93 Switch all uses of LLVM_OVERRIDE to just use 'override' directly.
llvm-svn: 202625
2014-03-02 09:32:10 +00:00
Ben Langmuir d066d4c849 Reapply fixed "Honour 'use-external-names' in FileManager"
Was r202442

There were two issues with the original patch that have now been fixed.
1. We were memset'ing over a FileEntry in a test case. After adding a
   std::string to FileEntry, this still happened to not break for me.
2. I didn't pass the FileManager into the new compiler instance in
   compileModule. This was hidden in some cases by the fact I didn't
   clear the module cache in the test.

Also, I changed the copy constructor for FileEntry, which was memcpy'ing
in a (now) unsafe way.

llvm-svn: 202539
2014-02-28 21:16:07 +00:00
Ben Langmuir 1b8d44f59b Revert "Honour 'use-external-names' in FileManager"
Revert r202442, which broke the buildbots.

llvm-svn: 202443
2014-02-27 23:48:03 +00:00
Ben Langmuir 09e0d5c1bb Honour 'use-external-names' in FileManager
Pass through the externally-visible names that we got from the VFS down
to FileManager, and test that this is the name showing up in __FILE__,
diagnostics, and debug information.

llvm-svn: 202442
2014-02-27 23:27:54 +00:00
Ben Langmuir b59cf679e8 Add a 'use-external-names' option to VFS overlay files
When true, sets the name of the file to be the name from
'external-contents'. Otherwise, you get the virtual path that the file
was looked up by. This will not affect any non-virtual paths, or fully
virtual paths (for which there is no reasonable 'external' name anyway).

The setting is available globally, but can be overriden on a per-file
basis.

The goal is that this setting will control which path you see in debug
info, diagnostics, etc. which are sensitive to which path is used. That
will come in future patches that pass the name through to FileManager.

llvm-svn: 202329
2014-02-27 00:25:12 +00:00
Benjamin Kramer 594802f744 Add a StmtPrinter test for implicit and explicit conversion operator calls.
Put back a comment that I removed too aggressively.

llvm-svn: 202255
2014-02-26 10:23:43 +00:00
Benjamin Kramer 2907b08219 Pretty Printer: Print constexpr and ref qualifiers. Don't print return types on destructors.
llvm-svn: 202181
2014-02-25 18:49:49 +00:00
Benjamin Kramer 00e8a1915a Reapply "Pretty Printer: Fix printing of conversion operator decls and calls."
There were many additional tests that had the bad behavior baked in.

llvm-svn: 202174
2014-02-25 18:03:55 +00:00
Ben Langmuir 47ff9ab1be Allow multi-component paths in VFS file nodes
This allows the 'name' field to contain a path, like

{ 'type': 'directory',
  'name': '/path/to/dir',
  'contents': [ ... ] }

which not only simplifies reading and writing these files (for humans),
but makes it possible to easily modify locations via textual
replacement, which would not have worked in the old scheme.

E.g. sed s:<ROOT>:<NEW ROOT>

llvm-svn: 202109
2014-02-25 04:34:14 +00:00
Argyrios Kyrtzidis 0b9682efa4 [libclang] Introduce libclang APIs for creating a buffer with a JSON virtual file overlay description.
The current API only supports adding 'virtual file path' -> 'real file path' mappings.

rdar://15986708

llvm-svn: 202105
2014-02-25 03:59:23 +00:00
Ben Langmuir 509fe8fd63 Improve some gtest assertions
As requested during review, compare pointers to NULL explicitly to make what's
going on more clear.

llvm-svn: 202090
2014-02-24 23:44:17 +00:00
Ben Langmuir 97882e7b7f Pass through context for DiagHandler in VFS
This allows the unit tests to not use global state when checking
diagnostics.

llvm-svn: 202072
2014-02-24 20:56:37 +00:00
Dmitri Gribenko 51c1b55bc2 ASTMatchers: added CXXMethodDecl matcher isPure()
The isPure() CXXMethodDecl matcher matches pure method declaration like "A::x"
in this example:

class A {
  virtual void x() = 0;
}

Patch by Konrad Kleine.

llvm-svn: 202012
2014-02-24 09:27:46 +00:00
Peter Collingbourne b8d17e7a3b Correctly set brace range for CXXConstructExprs formed by list initialization.
Differential Revision: http://llvm-reviews.chandlerc.com/D2711

llvm-svn: 201926
2014-02-22 02:59:41 +00:00
Ben Langmuir d51ba0b39f Add a VFSFromYAML class and a parser to create it
Provides a way to create a virtual file system using a YAML file that
supports mapping a file to a path on an 'external' file system. The
external file system will typically be the 'real' file system, but for
testing it can be changed.

A future patch will add a clang option to allow the user to specify such
a file and overlay it, but for now this code is only exercised by the
unit tests.

Differential Revision: http://llvm-reviews.chandlerc.com/D2835

llvm-svn: 201905
2014-02-21 23:39:37 +00:00
Ben Langmuir c8130a74f4 Recommit virtual file system
Previously reverted in r201755 due to causing an assertion failure.

I've removed the offending assertion, and taught the CompilerInstance to
create a default virtual file system inside createFileManager. In the
future, we should be able to reach into the CompilerInvocation to
customize this behaviour without breaking clients that don't care.

llvm-svn: 201818
2014-02-20 21:59:23 +00:00
Peter Collingbourne 564597fd26 Add TemplateSpecializationType polymorphism for hasTemplateArgument and
hasAnyTemplateArgument, and (out of necessity) an isExpr matcher.

Also updates the TemplateArgument doxygen to reflect reality for
non-canonical template arguments.

Differential Revision: http://llvm-reviews.chandlerc.com/D2810

llvm-svn: 201804
2014-02-20 19:18:03 +00:00
Juergen Ributzka a32575e4f6 Reverting the virtual file system implementation, because it triggers an assertion
in our internal build bots.

This reverts commits 201618, 201635, 201636, 201639, 201685, 201691, and 201696.

llvm-svn: 201755
2014-02-20 05:24:58 +00:00
Ben Langmuir ac7a74a836 Fix some test issues in VirtualFileSystemTest
Use camel-case names, remove some dead code, and fix a copy-and-pasted test.

llvm-svn: 201691
2014-02-19 15:58:49 +00:00
Dmitri Gribenko 8850cdad34 libclang: ensure clang_createTranslationUnit2 always initializes *TU
llvm-svn: 201657
2014-02-19 10:24:00 +00:00
Ben Langmuir 6f95efb683 Attempt to appease C++11 buildbots
Explicit operator bool doesn't not play nicely with gtest assertion
macros (i.e. it performs as advertised and I wish that gtest subverted
it for me).

llvm-svn: 201639
2014-02-19 04:17:47 +00:00
Ben Langmuir 87ba87bc4d Add an OverlayFileSystem class
Provides a way to merge multiple vfs::FileSystem objects into a single
filesystem.

llvm-svn: 201635
2014-02-19 03:29:17 +00:00
Ben Langmuir 090610d37a Initial implementation of virtual file system
This adds the minimum virtual file system support to start migrating
FileManager onto the VFS.

Originally discussed here:
http://lists.cs.uiuc.edu/pipermail/cfe-dev/2014-February/035188.html

Differential Revision: http://llvm-reviews.chandlerc.com/D2745

llvm-svn: 201618
2014-02-19 00:10:30 +00:00
Dmitri Gribenko f85b929211 Add files that I forgot to svn add in 201578.
llvm-svn: 201579
2014-02-18 15:29:17 +00:00
Dmitri Gribenko 1bf8d9107b libclang: fix a bug in processing invalid arguments, introduced in r201249
Recommit r201346, reverted in r201373.

llvm-svn: 201578
2014-02-18 15:20:02 +00:00
Daniel Jasper 5550de684f clang-format: Don't wrap "const" etc. of function declarations.
Generally people seem to prefer wrapping the first function parameter
over wrapping the trailing tokens "const", "override" and "final". This
does not extend to function-like annotations and probably not to other
non-standard annotations.

Before:
  void someLongFunction(int SomeLongParameter)
      const { ... }

After:
  void someLongFunction(
      int SomeLongParameter) const { ... }

llvm-svn: 201504
2014-02-17 07:57:46 +00:00
NAKAMURA Takumi 7d2da0b2ae clang/unittests/AST,ASTMatchers: Remove _MSC_VER.
llvm-svn: 201485
2014-02-16 10:16:09 +00:00
David Blaikie 8972f4e966 Consistently print anonymous namespace names as "<anonymous namespace>"
For some reason we have two bits of code handling this printing:

lib/AST/Decl.cpp:        OS << "<anonymous namespace>";
lib/AST/TypePrinter.cpp:      OS << "<anonymous namespace>::";

it would be nice if we only had one...

llvm-svn: 201437
2014-02-14 22:12:54 +00:00
Daniel Jasper 3a122c029d clang-format: Fix formatting of class template declaration.
Before:
  template <class R, class C>
  struct Aaaaaaaaaaaaaaaaa<R (C::*)(int)
                           const> : Aaaaaaaaaaaaaaaaa<R (C::*)(int)> {};

After:
  template <class R, class C>
  struct Aaaaaaaaaaaaaaaaa<R (C::*)(int) const>
      : Aaaaaaaaaaaaaaaaa<R (C::*)(int)> {};

llvm-svn: 201424
2014-02-14 18:22:40 +00:00
Juergen Ributzka d59364086f Revert "[CMake] Disable libclangTests.exe on win32 for now."
Because I also reverted the original commit that required this change.

llvm-svn: 201374
2014-02-13 23:51:55 +00:00
Juergen Ributzka c67c93d031 Revert "libclang: fix a bug in processing invalid arguments, introduced in r201249,"
Reverting commit (201346) for now, because it is breaking our internal builds.

llvm-svn: 201373
2014-02-13 23:34:54 +00:00
NAKAMURA Takumi f98c7ac6e6 [CMake] Disable libclangTests.exe on win32 for now.
libclangTests.exe cannot find libclang.dll since it is not on $PATH.

llvm-svn: 201348
2014-02-13 17:51:35 +00:00
Dmitri Gribenko fbe5672746 libclang: fix a bug in processing invalid arguments, introduced in r201249,
pointed out by Daniel Jasper in r201329

llvm-svn: 201346
2014-02-13 16:51:38 +00:00
Jonathan Roelofs 2cea1bea87 Add Multilib selection machinery
This patch improves the support for picking Multilibs from gcc installations.
It also provides a better approximation for the flags '-print-multi-directory'
and '-print-multi-lib'.

This reverts r201203 (i.e. re-applying r201202 with small fixes in
unittests/CMakeLists.txtto make the build bots happy).

review: http://llvm-reviews.chandlerc.com/D2538
llvm-svn: 201205
2014-02-12 03:21:20 +00:00
Jonathan Roelofs 3fa96d8378 Revert 201202
Breaks cmake configure of new unit tests directory

llvm-svn: 201203
2014-02-12 01:36:51 +00:00
Jonathan Roelofs 0e7ec60b74 Add Multilib selection machinery
This patch improves the support for picking Multilibs from gcc installations.
It also provides a better approximation for the flags '-print-multi-directory'
and '-print-multi-lib'.

review: http://llvm-reviews.chandlerc.com/D2538
llvm-svn: 201202
2014-02-12 01:29:25 +00:00
Daniel Jasper 1067ab0a1a clang-format: Support lambdas with namespace-qualified return types.
E.g.:
  Foo([]()->std::vector<int> { return { 2 }; }());

llvm-svn: 201139
2014-02-11 10:16:55 +00:00
Daniel Jasper a0407740c3 clang-format: Fix alignment of comments inside statements.
Before:
  auto result = SomeObject
                // Calling someFunction on SomeObject
                    .someFunction();

After:
  auto result = SomeObject
                    // Calling someFunction on SomeObject
                    .someFunction();

llvm-svn: 201138
2014-02-11 10:08:11 +00:00
Daniel Jasper 649899685b clang-format: Fix column limit violation for merged lines in macros.
Before (81 columns):
  #define A                                                                       \
    void aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa() { return aaaaaaaa; } \
    int i;

After:
  #define A                                                    \
    void aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa() { \
      return aaaaaaaa;                                         \
    }                                                          \
    int i;

llvm-svn: 200974
2014-02-07 13:45:27 +00:00
Daniel Jasper 9cc3e97685 clang-format: Fix range-based for-loop formatting.
Before:
  for (aaaaaaaaa aaaaaaaaaaaaaaaaaaaaa : aaaaaaaaaaaa.aaaaaaaaaaaa()
           .aaaaaaaaa()
           .a()) {
  }

After:
  for (aaaaaaaaa aaaaaaaaaaaaaaaaaaaaa :
       aaaaaaaaaaaa.aaaaaaaaaaaa().aaaaaaaaa().a()) {
  }

llvm-svn: 200968
2014-02-07 10:09:46 +00:00
Peter Collingbourne 1fec3dfe43 Add isListInitialization matcher.
Differential Revision: http://llvm-reviews.chandlerc.com/D2708

llvm-svn: 200949
2014-02-06 21:52:24 +00:00
Richard Smith 3d584b0ced PR18128: a lambda capture-default is not permitted for a non-local lambda
expression.

llvm-svn: 200948
2014-02-06 21:49:08 +00:00
Alexander Kornienko 9b539e1dd9 Added the hasLoopVariable sub-matcher for forRangeStmt.
Summary:
This sub-matcher makes it possible to access directly the range-based for
loop variable: forRangeStmt(hasLoopVariable(anything()).bind(...)).
I've tried to re-generate the docs, but the diffs seem to include much more than
this change could cause, so I'd better leave docs update to someone who knows
the intended changes in the contents better.

Reviewers: klimek

Reviewed By: klimek

CC: cfe-commits, klimek

Differential Revision: http://llvm-reviews.chandlerc.com/D2702

llvm-svn: 200850
2014-02-05 16:35:08 +00:00
Daniel Jasper 0c214fa2e3 clang-format: Don't indent relative to unary operators.
It seems like most people see unary operators more like part of the
subsequent identifier and find relative indentation odd.

Before:
  aaaaaaaaaa(!aaaaaaaaaa( // break
                  aaaaa));
After:
  aaaaaaaaaa(!aaaaaaaaaa( // break
                 aaaaa));

llvm-svn: 200840
2014-02-05 13:43:04 +00:00
Nico Weber 514ecc8ce8 clang-format: Let chromium style inherit google style's javascript tweaks.
llvm-svn: 200652
2014-02-02 20:50:45 +00:00
Daniel Jasper 86fee2fa3d clang-format: (JavaScript) Don't crash on empty string literals.
Before, this would lead to a crash:
  f('', true);

llvm-svn: 200540
2014-01-31 12:49:42 +00:00
Peter Collingbourne 252444a777 Introduce Parser::completeExpression.
This function returns a list of completions for a given expression and
completion position.

Differential Revision: http://llvm-reviews.chandlerc.com/D2261

llvm-svn: 200497
2014-01-30 22:38:41 +00:00
Daniel Jasper a88f80a1be clang-format: Support ObjC's NS_ENUMs.
Before:
  typedef NS_ENUM(NSInteger, MyType) {
      /// Information about someDecentlyLongValue.
      someDecentlyLongValue,
      /// Information about anotherDecentlyLongValue.
      anotherDecentlyLongValue,
      /// Information about aThirdDecentlyLongValue.
      aThirdDecentlyLongValue};

After:
  typedef NS_ENUM(NSInteger, MyType) {
    /// Information about someDecentlyLongValue.
    someDecentlyLongValue,
    /// Information about anotherDecentlyLongValue.
    anotherDecentlyLongValue,
    /// Information about aThirdDecentlyLongValue.
    aThirdDecentlyLongValue
  };

llvm-svn: 200469
2014-01-30 14:38:37 +00:00
Daniel Jasper f24301d79c clang-format: More custom option fixes for protocol buffer files.
Before:
  repeated double value = 1 [(aaaaaaa.aaaaaaaaa) = {
                               aaaaaaaaaaaaaaaa : AAAAAAAAAA,
                               bbbbbbbbbbbbbbbb : BBBBBBBBBB
                             }];

After:
  repeated double value = 1
      [(aaaaaaa.aaaaaaaaa) = {aaaaaaaaaaaaaaaa : AAAAAAAAAA,
                              bbbbbbbbbbbbbbbb : BBBBBBBBBB}];

llvm-svn: 200406
2014-01-29 18:52:43 +00:00
Daniel Jasper 6e58feef76 clang-format: Fix formatting of custom proto options.
Before:
  repeated double value = 1 [(aaaaaaa.aaaaaaaaa) = {
                              aaaaaaaaaaaaaaaaa : AAAAAAAA
                            }];

After:
  repeated double value = 1
      [(aaaaaaa.aaaaaaaaa) = {aaaaaaaaaaaaaaaaa : AAAAAAAA}];

llvm-svn: 200405
2014-01-29 18:43:40 +00:00
Manuel Klimek 14bd917470 Fix crash on unmatched #endif's.
The following snippet would crash:
  #endif
  #if A

llvm-svn: 200381
2014-01-29 08:49:02 +00:00
Daniel Jasper 559b63cbb9 clang-format: Understand __attribute__s preceding parameter lists.
Before:
  ReturnType __attribute__((unused))
      function(int i);

After:
  ReturnType __attribute__((unused))
  function(int i);

This fixes llvm.org/PR18632.

llvm-svn: 200337
2014-01-28 20:13:43 +00:00
Daniel Jasper a0e9be2bb2 clang-format: Fix option formatting in protocol buffer files.
Before:
  optional int32 foo[ default = true, deprecated = true ];

After:
  optional int32 foo[default = true, deprecated = true];

llvm-svn: 200327
2014-01-28 18:51:11 +00:00
Daniel Jasper e9beea24ef clang-format: Add support for a space after @property
Mozilla and WebKit seem to use a space after @property (verified by
grepping their codebases) so we turn this on there as well.

Change by Christian Legnitto. Thank you!

llvm-svn: 200320
2014-01-28 15:20:33 +00:00
Dmitri Gribenko 6bf8f803f2 Comment parsing: don't crash while parsing \deprecated in a standalone comment
(comment without a decl).

I think this can not happen during normal compilation with -Wdocumentation,
only while using Clang APIs to parse comments outside of a source file.

Based on a patch by Olivier Goffart.

llvm-svn: 200230
2014-01-27 17:55:43 +00:00
Saleem Abdulrasool 8a8454bc31 unittests: explicit stringify StringRefs for conversion
When clang is built outside of the LLVM tree (against a corresponding version),
there is no definition providing for operator<<(std::ostream &, StringRef) which
is required for the assertion routines in google-test tests.  Avoid the
compilation failure by explicitly stringifying the StringRef prior to use.

llvm-svn: 200096
2014-01-25 20:04:44 +00:00
Daniel Jasper ff974ab88a clang-format: Fix incorrect space removal.
Before:
  Deleted &operator=(const Deleted &)&= default;
  Deleted &operator=(const Deleted &)&&= delete;

After:
  Deleted &operator=(const Deleted &)& = default;
  Deleted &operator=(const Deleted &)&& = delete;

llvm-svn: 200073
2014-01-25 09:16:02 +00:00
Manuel Klimek 421147ec65 Get rid of special parsing for return statements.
This was done when we were not able to parse lambdas to handle some
edge cases for block formatting different in return statements, but is
not necessary any more.

llvm-svn: 199982
2014-01-24 09:25:23 +00:00
Peter Collingbourne d32e28c87a Introduce Registry::getCompletions.
This returns a list of valid (and useful) completions for a context (a list
of outer matchers), ordered by decreasing relevance then alphabetically. It
will be used by the matcher parser to implement completion.

Differential Revision: http://llvm-reviews.chandlerc.com/D2210

llvm-svn: 199950
2014-01-23 22:48:38 +00:00
Daniel Jasper 6b70ec0d46 clang-format: Fix incorrect lambda recognition.
Before:
  std::unique_ptr<int[]> foo() {}

After:
  std::unique_ptr<int []> foo() {}

Also, the formatting could go severely wrong after such a function
before.

llvm-svn: 199817
2014-01-22 17:01:47 +00:00
Daniel Jasper 215d6c8c50 clang-format: Treat "." in protos like namespace separators.
Before:
  optional really.really.long.and.qualified.type.aaaaaaa
      .aaaaaaaa another_fiiiiiiiiiiiiiiiiiiiiield = 2;

After:
  optional
     really.really.long.and.qualified.type.aaaaaaa.aaaaaaaa
          another_fiiiiiiiiiiiiiiiiiiiiield = 2;

llvm-svn: 199796
2014-01-22 08:04:52 +00:00
Richard Smith e81daee21b When formatting a C++-only declaration name, enable C++ mode in the formatter's
language options. This is not really ideal -- we should require the right
language options to be passed in, or not require language options to format a
name -- but it fixes a number of *obviously* wrong formattings. Patch by
Olivier Goffart!

llvm-svn: 199778
2014-01-22 00:27:42 +00:00
Daniel Jasper 7cfde414e1 clang-format: text following #if is likely an expression.
Before:
  #if AAAA &&BBBB

After:
  #if AAAA && BBBB

llvm-svn: 199713
2014-01-21 08:56:09 +00:00
Daniel Jasper 929b1db276 clang-format: Properly format custom options in protocol buffer definitions.
Before:
  option(my_option) = "abc";

After:
  option (my_option) = "abc";

llvm-svn: 199672
2014-01-20 16:47:22 +00:00
Daniel Jasper 7052ce6d8b clang-format: Better support and testing for protocol buffers.
With this patch, there is dedicated testing for protocol buffers
(https://developers.google.com/protocol-buffers/).

Also some minor tweaks formatting tweaks.

llvm-svn: 199580
2014-01-19 09:04:08 +00:00
Daniel Jasper 31745731e8 clang-format: Fix ObjC block as first call parameter formatting.
Before:
  foo (^{ bar(); });
After:
  foo(^{ bar(); });

llvm-svn: 199573
2014-01-19 07:46:32 +00:00
Ismail Pazarbasi 1121de36c2 Fix string-literal to char* conversion in overload resolution for C++11
String literal to char* conversion is deprecated in C++03, and is removed in
C++11. We still accept this conversion in C++11 mode as an extension, if we find
it in the best viable function.

llvm-svn: 199513
2014-01-17 21:08:52 +00:00
Daniel Jasper 47ef6ddece clang-format: Don't break lines starting with "import <string-literal>"
The author might be missing the "#" or these might be protocol buffer
definitions. Either way, we should not break the line or the string.

There don't seem to be other valid use cases.

llvm-svn: 199501
2014-01-17 16:21:39 +00:00
Daniel Jasper a225bcedb4 clang-format: Improve formatting of ObjC Blocks with return type.
Before:
  int a = [operation block:^int(int * i) { return 1; }];

After:
  int a = [operation block:^int(int *i) { return 1; }];

llvm-svn: 199411
2014-01-16 19:14:34 +00:00
Daniel Jasper cb51cf409b clang-format: Enable formatting of lambdas with explicit return type.
So clang-format can now format:

  int c = []()->int { return 2; }();
  int c = []()->vector<int> { return { 2 }; }();

llvm-svn: 199368
2014-01-16 09:11:55 +00:00
Daniel Jasper b2e10a5459 clang-format: Fixed formatting of JavaScript container literals
Before:
  var arr = [ 1, 2, 3 ];
  var obj = {a : 1, b : 2, c : 3};

After:
  var arr = [1, 2, 3];
  var obj = {a: 1, b: 2, c: 3};

llvm-svn: 199317
2014-01-15 15:09:08 +00:00
Daniel Jasper d07c2ee99e clang-format: Fix bug introduced in r198871.
We cannot simply change the start column to accomodate for the @ in an
ObjC string literal as that will make clang-format happily violate the
column limit.

Use a different workaround instead. However, a better long-term
solution might be to join the @ and the rest of the literal into a
single token.

llvm-svn: 199198
2014-01-14 09:53:07 +00:00
David Majnemer d4328ded85 Switch to ssize_t from size_t to unbreak windows builders.
Builders that have -fms-compatibility on by default define size_t implicitly.
Tests that provide conflicting definitions would cause unintended failures.

llvm-svn: 199195
2014-01-14 08:18:49 +00:00
Daniel Jasper f6c7c18b8e clang-format: Fix corner case with comment in ctor initializer.
Formatting:
  Constructor() :
      // Comment forcing unwanted break.
      aaaa(aaaa) {}

Before:
  Constructor()
      :
        // Comment forcing unwanted break.
        aaaa(aaaa) {}

After:
  Constructor()
      : // Comment forcing unwanted break.
        aaaa(aaaa) {}

llvm-svn: 199107
2014-01-13 14:10:04 +00:00
Daniel Jasper 85bde4cdd8 clang-format: Don't indent relative to ./->.
Before:
  SomeThing          // break
      .SomeFunction( // break
           param);
After:
  SomeThing          // break
      .SomeFunction( // break
          param);

Seems to be more common in editors and codebases I have looked at.

llvm-svn: 199105
2014-01-13 13:42:08 +00:00
NAKAMURA Takumi 9b435fec0d DynamicASTMatchers/VariantValueTest.cpp: It works with msvcrt since setmode(stderr, O_BINARY) were removed.
llvm-svn: 199059
2014-01-12 17:49:26 +00:00
Daniel Jasper 4d7a97adfc clang-format: Slightly adapt line break in edge case.
Before:
  SomeMap[std::pair(aaaaaaaaaaaa, bbbbbbbbbbbbbbb)]
      .insert(ccccccccccccccccccccccc);

After:
  SomeMap[std::pair(aaaaaaaaaaaa, bbbbbbbbbbbbbbb)].insert(
      ccccccccccccccccccccccc);

This seems to be about 3:1 more common in Google and Chromium style and I found
only a handful of instances inside the LLVM codebase.

llvm-svn: 198924
2014-01-10 08:40:17 +00:00
Daniel Jasper b1c19f8987 clang-format: Understand ObjC boxed expressions.
Before:
  [dictionary setObject:@(1)forKey:@"number"];
After:
  [dictionary setObject:@(1) forKey:@"number"];

llvm-svn: 198920
2014-01-10 07:44:53 +00:00
Daniel Jasper 174b012524 clang-format: Add @s when breaking NSString literals.
While it is allowed to not have an @ on subsequent lines, it seems
general practice to add them. If undesired, the code author can easily
remove them again and clang-format won't re-add them.

llvm-svn: 198871
2014-01-09 14:18:12 +00:00
Daniel Jasper dc32c1bf3a clang-format: Understand #pragma mark
Before:
  #pragma mark Any non - hyphenated or hyphenated string(including parentheses).
After:
  #pragma mark Any non-hyphenated or hyphenated string (including parentheses).

llvm-svn: 198870
2014-01-09 13:56:49 +00:00
Daniel Jasper 0160347b22 clang-format: Some tweaks to braces list formatting:
- Format a braced list with one element per line if it has nested
  braced lists.
- Use a column layout only when the list has 6+ elements (instead of the
  current 4+ elements).

llvm-svn: 198869
2014-01-09 13:42:56 +00:00
Benjamin Kramer e21cb74224 clang-format: Don't hang forever when encountering a stray "}" in an @implementation block.
PR18406.

llvm-svn: 198770
2014-01-08 15:59:42 +00:00
Daniel Jasper 7620b6628b clang-format: Fix spacing in Cpp11 braced lists:
Before:
  vector<int> foo{ ::SomeFunction()};

After:
  vector<int> foo{::SomeFunction()};

llvm-svn: 198769
2014-01-08 15:41:13 +00:00
Chandler Carruth 5553d0d4ca Sort all the #include lines with LLVM's utils/sort_includes.py which
encodes the canonical rules for LLVM's style. I noticed this had drifted
quite a bit when cleaning up LLVM, so wanted to clean up Clang as well.

llvm-svn: 198686
2014-01-07 11:51:46 +00:00
Daniel Jasper 1a148b4922 clang-format: Spacing inside enum braces.
Before (in Google style):
  enum ShortEnum {A, B, C};

After:
  enum ShortEnum { A, B, C };

llvm-svn: 198559
2014-01-05 13:23:23 +00:00
Daniel Jasper 9697281eec clang-format: Allow formatting short enums on a single line.
Before:
  enum ShortEnum {
    A,
    B,
    C
  };

After:
  enum ShortEnum { A, B, C };

This seems to be the predominant choice in LLVM/Clang as well as in
Google style.

llvm-svn: 198558
2014-01-05 12:38:10 +00:00
Alp Toker 8db6e7a972 Fix 'declartion' typos
llvm-svn: 198549
2014-01-05 06:38:57 +00:00
Alp Toker 59226f7811 Revert "ToolingTest.cpp: Fix r158592, runToolOnCode.FindsNoTopLevelDeclOnEmptyCode on msvc. LangOpts.MicrosoftExt still appends "class type_info;"."
type_info has been made an implicitly predeclared type in r198497 and will no
longer appear as a user-declared type so we can remove this old hack.

This reverts commit r158595.

llvm-svn: 198502
2014-01-04 15:58:28 +00:00
Daniel Jasper 352dae199a clang-format: Recognize single-line macro usages inside macros.
Before:
  #define LIST(L)                                                     \
    L(FirstElement) L(SecondElement) L(ThirdElement) L(FourthElement) \
        L(FifthElement)

After:
  #define LIST(L)    \
    L(FirstElement)  \
    L(SecondElement) \
    L(ThirdElement)  \
    L(FourthElement) \
    L(FifthElement)

llvm-svn: 198407
2014-01-03 11:50:46 +00:00
Alexander Kornienko ce9161a557 Added an option to avoid splitting certain kinds of comments into lines.
Summary: Added CommentPragmas option for this.

Reviewers: djasper, klimek

Reviewed By: klimek

CC: cfe-commits, klimek

Differential Revision: http://llvm-reviews.chandlerc.com/D2460

llvm-svn: 198310
2014-01-02 15:13:14 +00:00
DeLesley Hutchins c4a82438a7 Update RecursiveASTVisitor so that it visits attributes. This is currently
important for thread safety attributes, which contain expressions that were
not being visited, and were thus invisible to various tools.  There are now
Visit*Attr methods that can be overridden for every attribute.

llvm-svn: 198224
2013-12-30 17:24:36 +00:00
Alexander Kornienko d6bd74742b Changed the test to avoid EXPECT_EQ(false, ...), which leads to
-Wconversion-null warning in GCC.

llvm-svn: 198214
2013-12-30 16:11:28 +00:00
Daniel Jasper 126153ab87 clang-format: Break default arguments less eagerly.
Before:
  void aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa(int aaaaaaaaaaaaaaaaaaaaaaaaaaaa =
                                              1);

After:
  void aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa(
      int aaaaaaaaaaaaaaaaaaaaaaaaaaaa = 1);

llvm-svn: 198070
2013-12-27 06:39:56 +00:00
Daniel Jasper 234379fbf6 clang-format: (WebKit) Disallow 1-line constructors with initializers.
Before:
  Constructor() : a(a) {}

After:
  Constructor()
      : a(a)
  {
  }

This style guide is pretty precise about this.

llvm-svn: 197980
2013-12-24 13:31:25 +00:00
Daniel Jasper b88b25feec clang-format: Fix various problems in formatting ObjC blocks.
Among other things, this fixes llvm.org/PR15269.

llvm-svn: 197900
2013-12-23 07:29:06 +00:00
Daniel Jasper 04b6a081fc clang-format: Better support for multi-line wide string literals.
Before:
  SomeFunction(L"A" L"B");

After:
  SomeFunction(L"A"
               L"B");

llvm-svn: 197785
2013-12-20 06:22:01 +00:00
Daniel Jasper 5a611397a2 clang-format: Add special case for leading comments in braced lists.
A comment following the "{" of a braced list seems to almost always
refer to the first element of the list and thus should be aligned
to it.

Before (with Cpp11 braced list style):
  SomeFunction({  // Comment 1
                   "first entry",
                   // Comment 2
                   "second entry"});
After:
  SomeFunction({// Comment 1
                "first entry",
                // Comment 2
                "second entry"});

llvm-svn: 197725
2013-12-19 21:41:37 +00:00
Daniel Jasper 19a541eff0 clang-format: Increase penalty for breaking comments.
Unexpectedly, it seems that people commonly know what they were doing
when writing a comment.

Also, being more conservative about comment breaking has the advantage
of giving more flexibility. If a linebreak within the comment can
improve formatting, the author can add it (after which clang-format
won't undo it). There is no way to override clang-format's behavior if
it breaks a comment.

llvm-svn: 197698
2013-12-19 16:45:34 +00:00
Daniel Jasper 004177ee29 clang-format: Slightly adapt decision of when to break before <<.
Before:
  Diag(aaaaaaaaaaaaaaaaaaaa, aaaaaaaa) << aaaaaaaaaaaaaaaaaaaaaaaaa(
                                              aaaaaaaaaaaaa);

After:
  Diag(aaaaaaaaaaaaaaaaaaaa, aaaaaaaa)
      << aaaaaaaaaaaaaaaaaaaaaaaaa(aaaaaaaaaaaaa);

llvm-svn: 197690
2013-12-19 16:06:40 +00:00
Daniel Jasper 969643594e clang-format: Fix indentation corner case.
Before:
  aaaaaaaaaa(aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa(
      aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa)
                 .aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa);
  aaaaaaaaaa = aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa(
      aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa)
                   .aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa();

After:
  aaaaaaaaaa(aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa(
                 aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa)
                 .aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa);
  aaaaaaaaaa = aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa(
                   aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa)
                   .aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa();

Probably still not ideal, but should be a step into the right direction.

llvm-svn: 197557
2013-12-18 10:44:36 +00:00
Daniel Jasper 3460b2546c clang-format: Fix ObjC method expr in binary expressions.
Before:
  bool a = ([aaaaaaaa aaaaa] == aaaaaaaaaaaaaaaaa || [aaaaaaaa aaaaa] ==
                                                         aaaaaaaaaaaaaaaaaaaa);

After:
  bool a = ([aaaaaaaa aaaaa] == aaaaaaaaaaaaaaaaa ||
            [aaaaaaaa aaaaa] == aaaaaaaaaaaaaaaaaaaa);

This fixes llvm.org/PR18271.

llvm-svn: 197552
2013-12-18 07:08:51 +00:00
Daniel Jasper bad63ae2a5 clang-format: Don't adapt local format to macros.
Formatting this:
   void f() { // 1 space initial indent.
      int i;
  #define A   \
      int i;  \
     int j;
        int k; // Format this line.
   }
   void f() {
       #define A 1 // Format this line.
   }

Before:
   void f() { // 1 space initial indent.
      int i;
  #define A   \
      int i;  \
     int j;
     int k;  // Format this line.
   }
   void f() {
   #define A 1  // Format this line.
   }

After:
   void f() { // 1 space initial indent.
      int i;
  #define A   \
      int i;  \
     int j;
      int k;  // Format this line.
   }
   void f() {
  #define A 1  // Format this line.
   }

llvm-svn: 197494
2013-12-17 12:38:55 +00:00
Daniel Jasper 43e6a28d1f clang-format: Keep trailing annotations together.
Before:
  virtual void aaaaa(aaaaaaaaaaaaaaaaaaaaaaaaaa aaaa, aaaaaaaaaaa aaaaa) const
      override;
  virtual void aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa() const
      override;

After:
  virtual void aaaaa(aaaaaaaaaaaaaaaaaaaaaaaaaa aaaa,
                     aaaaaaaaaaa aaaaa) const override;
  virtual void aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa()
      const override;

llvm-svn: 197391
2013-12-16 15:01:54 +00:00
Alexander Kornienko a594ba8a76 Always break before the colon in constructor initializers, when
BreakConstructorInitializersBeforeComma is true.

This option is used in WebKit style, so this also ensures initializer lists are
not put on a single line, as per the WebKit coding guidelines.

Patch by Florian Sowade!

llvm-svn: 197386
2013-12-16 14:35:51 +00:00
Daniel Jasper 3682fcda17 clang-format: Fix formatting of function type parameters.
Before:
  void f() { typedef void (*f)(int * a); }
After:
  void f() { typedef void (*f)(int *a); }

llvm-svn: 197369
2013-12-16 08:36:18 +00:00
Daniel Jasper c39b56fe14 clang-format: Improve handling of raw string literals.
Especially try to keep existing line breaks before raw string literals,
as the code author might have aligned content to it.

Thereby, clang-format now keeps things like:

  parseStyle(R"(
      BasedOnStyle: Google,
      ColumnLimit: 100)");
  parseStyle(
      R"(BasedOnStyle: Google,
         ColumnLimit: 100)");

llvm-svn: 197368
2013-12-16 07:23:08 +00:00
Alp Toker 56b5cc91af ASTContext: Declare builtin types implicitly
__builtin_va_list and friends have been showing up where they shouldn't for way
to long, making unwanted appearences in -ast-print, tooling and source level
visitors and even the hello world tutorial on the clang website.

This commit factors down the implicit typedef and record creation facilities to
ensure they're marked implicit.

Also fixes a unit test that was testing incorrect behaviour, and removes old
hacks in the DeclPrinter that tried to skip implicit declarations manually.

llvm-svn: 197336
2013-12-15 10:36:26 +00:00
Alexander Kornienko 3a33f0292b Implemented GNU-style formatting for compound statements.
Summary:
Added BraceBreakingStyle::BS_GNU. I'm not sure about the correctness of
static initializer formatting, but compound statements should be fine.

Reviewers: djasper

Reviewed By: djasper

CC: cfe-commits, klimek

Differential Revision: http://llvm-reviews.chandlerc.com/D2372

llvm-svn: 197138
2013-12-12 09:49:52 +00:00
Alexander Kornienko fe7a57fa78 Early attempts to format in GNU style.
Summary:
This still misses a few important features, so there's no mention of
this style in the help message, but a few style rules are implemented.

Reviewers: djasper

Reviewed By: djasper

CC: cfe-commits, klimek

Differential Revision: http://llvm-reviews.chandlerc.com/D2371

llvm-svn: 196928
2013-12-10 15:42:15 +00:00
NAKAMURA Takumi ac85179219 [CMake] Update target_link_libraries() and LLVM_LINK_COMPONENTS for each CMakeLists.txt.
llvm-svn: 196916
2013-12-10 12:40:37 +00:00
Alexander Kornienko c1637f167c Allow predefined styles to define different options for different languages.
Summary:
Allow predefined styles to define different options for different
languages so that one can run:
  clang-format -style=google file1.cpp file2.js

or use a single .clang-format file with "BasedOnStyle: Google" for both c++ and
JS files.

Added Google style for JavaScript with "BreakBeforeTernaryOperators" set to
false.

Reviewers: djasper

Reviewed By: djasper

CC: cfe-commits, klimek

Differential Revision: http://llvm-reviews.chandlerc.com/D2364

llvm-svn: 196909
2013-12-10 11:28:13 +00:00
Alexander Kornienko fdca83d487 Support GNU style rule to put a space before opening parenthesis.
Summary:
The rule from the GNU style states:
"We find it easier to read a program when it has spaces before the open-parentheses and after the commas."

http://www.gnu.org/prep/standards/standards.html#index-spaces-before-open_002dparen

This patch makes clang-format adds an option to put spaces before almost all open parentheses, except the cases, where different behavior is dictated by the style rules or language syntax:
  * preprocessor:
    ** function-like macro definitions can't have a space between the macro name and the parenthesis;
    ** `#if defined(...)` can have a space, but it seems, that it's more frequently used without a space in GCC, for example;
  * never add spaces after unary operators;
  * adding spaces between two opening parentheses is controlled with the `SpacesInParentheses` option;
  * never add spaces between `[` and `(` (there's no option yet).

Reviewers: djasper

Reviewed By: djasper

CC: cfe-commits, klimek

Differential Revision: http://llvm-reviews.chandlerc.com/D2326

llvm-svn: 196901
2013-12-10 10:18:34 +00:00
Daniel Jasper 63af7c482d clang-format: Be more conservative about braced list column layout.
Specifically disable it for nested braced lists as it commonly can look
really weird. Eventually, we'll want to become smarter and format some of
the nested lists better.

Before:
  SomeStruct my_struct_array = {
    { aaaaaa,     aaaaaaaa,   aaaaaaaaaa, aaaaaaaaa, aaaaaaaaa,
      aaaaaaaaaa, aaaaaaaaaa, aaaaaaa,    aaa },
    { aaaa, aaaa, aaaa, aaaa, aaaa, aaaa, aaaa, aaa },
    { aaaaaaaaaaaaaaaaa, aaaaaaaaaaaaaaaaa, aaaaaaaaaaaaaaaaaaaaaaaa,
      aaaaaaaaaaaa,      a,                 aaaaaaaaaa,
      aaaaaaaaa,         aaa },
  };

After:
  SomeStruct my_struct_array = {
    { aaaaaa, aaaaaaaa, aaaaaaaaaa, aaaaaaaaa, aaaaaaaaa, aaaaaaaaaa,
      aaaaaaaaaaaa, aaaaaaa, aaa },
    { aaaa, aaaa, aaaa, aaaa, aaaa, aaaa, aaaa, aaa },
    { aaaaaaaaaaaaaaaaa, aaaaaaaaaaaaaaaaa, aaaaaaaaaaaaaaaaaaaaaaaa,
      aaaaaaaaaaaa, a, aaaaaaaaaa, aaaaaaaaa, aaa },
  };

llvm-svn: 196783
2013-12-09 14:40:19 +00:00
Daniel Jasper e0ab9e7936 clang-format: Change line break decisions for array subscripts.
Before:
  aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa<int> aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
      [aaaaaaaaaaaa];
After:
  aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa<int>
      aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa[aaaaaaaaaaaa];

llvm-svn: 196582
2013-12-06 15:19:50 +00:00
Alp Toker f6a24ce40f Fix a tranche of comment, test and doc typos
llvm-svn: 196510
2013-12-05 16:25:25 +00:00
Alexander Kornienko 06dd15a01a Added a regression test for the change in r196380
llvm-svn: 196384
2013-12-04 13:58:27 +00:00
Alexander Kornienko 31e9554024 Leave constructor initializer lists on one line in styles with no column limit.
Summary:
Allow tryFitMultipleLinesInOne join unwrapped lines when
ContinuationIndenter::mustBreak doesn't agree. But don't merge any lines, that
are separate in the input.

Reviewers: djasper

Reviewed By: djasper

CC: cfe-commits, klimek

Differential Revision: http://llvm-reviews.chandlerc.com/D2321

llvm-svn: 196378
2013-12-04 12:21:08 +00:00
Alexander Kornienko a48a12cf81 Create a separate file for JS-specific unit tests.
Reviewers: djasper

Reviewed By: djasper

CC: cfe-commits, klimek

Differential Revision: http://llvm-reviews.chandlerc.com/D2307

llvm-svn: 196266
2013-12-03 10:50:16 +00:00
Daniel Jasper 0e81f1ad43 clang-format: Fix excessive formatting caused by r195954.
Due to a bug in the patch, clang-format would more or less simply format
all multi-line comments.

llvm-svn: 196080
2013-12-02 09:19:27 +00:00
Alexander Kornienko cabdd738fc Added LanguageStandard::LS_JavaScript to gate all JS-specific parsing.
Summary:
Use LS_JavaScript for files ending with ".js". Added support for ">>>="
operator.

Reviewers: djasper, klimek

Reviewed By: djasper

CC: cfe-commits, klimek

Differential Revision: http://llvm-reviews.chandlerc.com/D2242

llvm-svn: 195961
2013-11-29 15:19:43 +00:00
Daniel Jasper 38c82408a7 clang-format: Extends formatted ranges to subsequent lines comments.
Before:
  int aaaa;     // This line is formatted.
                // The comment continues ..
                // .. here.

Before:
  int aaaa; // This line is formatted.
            // The comment continues ..
            // .. here.

This fixes llvm.org/PR17914.

llvm-svn: 195954
2013-11-29 09:27:43 +00:00
Daniel Jasper 1556b59338 clang-format: Correctly handle Qt's Q_SLOTS.
This should fix llvm.org/PR17241. Maybe it sticks this time :-).

llvm-svn: 195953
2013-11-29 08:51:56 +00:00
Daniel Jasper e40caf9ad2 clang-format: Fix bad indentation of nested blocks.
Before:
  DEBUG(  //
  { f(); });

After:
  DEBUG(  //
      { f(); });

Also add additional test to selected formatting of individual statements
in nested blocks.

llvm-svn: 195952
2013-11-29 08:46:20 +00:00
Daniel Jasper 9c19956845 clang-format: Improve selective formatting of nested statements.
Previously, clang-format could create quite corrupt formattings if
individual lines of nested blocks (e.g. in "DEBUG({})" or lambdas) were
used. With this patch, it tries to extend the formatted regions to leave
around some reasonable format without always formatting the entire
surrounding statement.

llvm-svn: 195925
2013-11-28 15:58:55 +00:00
Alexander Kornienko fd1d7002e2 Changed non-printable characters in the test to the escaped form. Apparently, not all tools display non-printable characters ;)
llvm-svn: 195761
2013-11-26 13:31:46 +00:00
Alexander Kornienko 71d95d6e51 Fix crash in getStringSplit.
Summary:
getStringSplit used to crash, when trying to split a long string
literal containing both printable and unprintable multi-byte UTF-8 characters.

Reviewers: djasper, klimek

Reviewed By: djasper

CC: cfe-commits, klimek

Differential Revision: http://llvm-reviews.chandlerc.com/D2268

llvm-svn: 195728
2013-11-26 10:38:53 +00:00
Daniel Jasper 5500f6163f clang-format: Refactor calculation of lines intersecting with -lines.
No functional changes intended. However, it seems to have found a buggy
behavior in one of the tests. I think this structure is generally
desirable and it will make a planned bugfix significantly easier.

llvm-svn: 195634
2013-11-25 11:08:59 +00:00
Argyrios Kyrtzidis 336fcd9c61 [Parser] Unbreak parsing with incremental parsing enabled and add a unit-test for it.
llvm-svn: 195564
2013-11-24 02:12:18 +00:00
Daniel Jasper 84c47a1074 clang-format: Support Qt's slot access specifiers.
This fixes llvm.org/PR17241.

llvm-svn: 195555
2013-11-23 17:53:41 +00:00
Daniel Jasper 40bc7466a8 clang-format: Fix incorrect space in parameters named by comment.
This fixes llvm.org/PR17979.

Before:
  void f() { g(/*aaa=*/x, /*bbb=*/ !y); }

After:
  void f() { g(/*aaa=*/x, /*bbb=*/!y); }

llvm-svn: 195553
2013-11-23 14:51:47 +00:00
Daniel Jasper 446d1cd32c clang-format: The "<" of a template argument is not a binary operator.
With Style.BreakBeforeBinaryOperators, clang-format breaks incorrectly.
This fixes llvm.org/PR17994.

Before:
  return boost::fusion::at_c<0>(iiii).second == boost::fusion::at_c
                                                <1>(iiii).second;

After:
  return boost::fusion::at_c<0>(iiii).second ==
         boost::fusion::at_c<1>(iiii).second;

llvm-svn: 195552
2013-11-23 14:45:49 +00:00
Daniel Jasper 4bf0d80993 clang-format: Fix bug in ObjC method declaration formatting.
Also disallow breaking between "@" and "{" or "[".

Before:
  - (NSAttributedString *)attributedStringForSegment:(NSUInteger)segment
                                               index:(NSUInteger)index
                                          attributes:(NSDictionary *)attributes
                                  nonDigitAttributes:(NSDictionary *)
      nonDigitAttributes;
  [mailComposeViewController
     setToRecipients:@
     [ NSBundle.mainBundle.infoDictionary[@"ABBFeedbackEmail"] ]];

After:
  - (NSAttributedString *)attributedStringForSegment:(NSUInteger)segment
                                               index:(NSUInteger)index
                                          attributes:(NSDictionary *)attributes
                                  nonDigitAttributes:
                                      (NSDictionary *)nonDigitAttributes;
  [mailComposeViewController
      setToRecipients:
          @[ NSBundle.mainBundle.infoDictionary[@"ABBFeedbackEmail"] ]];

This fixes llvm.org/PR18030.

llvm-svn: 195550
2013-11-23 14:27:27 +00:00
Daniel Jasper 1a1a2ab77e clang-format: Prefer column layout if possible.
Add a severe penalty for not using column layout for braced lists. If
there are solutions with column layout, these are generally preferable
over bin-packed solutions.

Before:
  std::vector<MyValues> aaaaaaaaaaaaaaaaaaa{ aaaaaaa, aaaaaaaaaa, aaaaa,
                                             aaaaaaaaaaaaaaa, aaa, aaaaaaaaaa, a,
                                             aaaaaaaaaaaaaaaaaaaaa, aaaaaaaaaaaa,
                                             aaaaaaaaaaaaaaaaaaa +
                                                 aaaaaaaaaaaaaaaaaaa,
                                             aaaaaaa, a };
After:
  std::vector<MyValues> aaaaaaaaaaaaaaaaaaa{
    aaaaaaa,      aaaaaaaaaa,
    aaaaa,        aaaaaaaaaaaaaaa,
    aaa,          aaaaaaaaaa,
    a,            aaaaaaaaaaaaaaaaaaaaa,
    aaaaaaaaaaaa, aaaaaaaaaaaaaaaaaaa + aaaaaaaaaaaaaaaaaaa,
    aaaaaaa,      a
  };

llvm-svn: 195546
2013-11-23 10:22:59 +00:00
Peter Collingbourne f0c1f59d7e Add Distance parameter to ASTNodeKind::isBaseOf.
This will allow the completer to order results by relevance.

Differential Revision: http://llvm-reviews.chandlerc.com/D2209

llvm-svn: 195540
2013-11-23 01:40:07 +00:00
Peter Collingbourne 00cba4f6dd Split registry matcher resolution into a lookup phase and a construction phase.
The looked-up matchers will be used during code completion.

Differential Revision: http://llvm-reviews.chandlerc.com/D2207

llvm-svn: 195534
2013-11-23 01:13:16 +00:00
Samuel Benzaquen ef77f3cca7 Make the negative test more specific.
Summary:
Make the negative test more specific.
Otherwise it can accidentally match injected code.

Reviewers: aaron.ballman

CC: klimek, cfe-commits, revane

Differential Revision: http://llvm-reviews.chandlerc.com/D2257

llvm-svn: 195512
2013-11-22 23:05:57 +00:00
Samuel Benzaquen 4d05874ba2 Add support for the 'unless' matcher in the dynamic layer.
Summary: Add support for the 'unless' matcher in the dynamic layer.

Reviewers: klimek

CC: cfe-commits, revane, klimek

Differential Revision: http://llvm-reviews.chandlerc.com/D2247

llvm-svn: 195466
2013-11-22 14:41:48 +00:00
Daniel Jasper 298c3403d2 clang-format: Fix bug in alignment of complex template parameters.
Before:
  template <typename aaaaaaaaaaa, typename bbbbbbbbbbbbb, template <typename>
            class cccccccccccccccccccccc, typename ddddddddddddd>
  class C {};

After:
  template <typename aaaaaaaaaaa, typename bbbbbbbbbbbbb,
            template <typename> class cccccccccccccccccccccc,
            typename ddddddddddddd>
  class C {};

llvm-svn: 195418
2013-11-22 07:48:15 +00:00
Daniel Jasper b631d5e6f3 clang-format: Recognize braced lists with trailing function call.
Before:
  int count = set<int> { f(), g(), h() }
      .size();

After:
  int count = set<int>{f(), g(), h()}.size();

llvm-svn: 195417
2013-11-22 07:26:53 +00:00
Alexander Kornienko 9aa62407f6 Better implementation of JavaScript === and !== operators.
Summary:
Now based on token merging. Now they are not only prevented from being
split, but are actually formatted as comparison operators.

Reviewers: djasper, klimek

Reviewed By: klimek

CC: cfe-commits, klimek

Differential Revision: http://llvm-reviews.chandlerc.com/D2240

llvm-svn: 195354
2013-11-21 12:43:57 +00:00
Daniel Jasper a78d7d4502 clang-format: Improve formatting of ObjC method expressions.
In particular, make breaking after a parameter's ":" more of a last
resort choice as it significantly affects the readability gained by
aligning the parameters.

Before (in Chromium style - which doesn't allow bin-packing):
  {
    popup_window_.reset([[RenderWidgetPopupWindow alloc]
        initWithContentRect:
            NSMakeRect(
                origin_global.x, origin_global.y, pos.width(), pos.height())
                  styleMask:NSBorderlessWindowMask
                    backing:NSBackingStoreBuffered
                      defer:NO]);
  }

After:
  {
    popup_window_.reset([[RenderWidgetPopupWindow alloc]
        initWithContentRect:NSMakeRect(origin_global.x,
                                       origin_global.y,
                                       pos.width(),
                                       pos.height())
                  styleMask:NSBorderlessWindowMask
                    backing:NSBackingStoreBuffered
                      defer:NO]);
  }

llvm-svn: 195301
2013-11-21 01:46:33 +00:00
Alexander Kornienko 3cfa973978 Added an option to allow short function bodies be placed on a single line.
Summary:
The AllowShortFunctionsOnASingleLine option now controls short function
body placement on a single line independent of the BreakBeforeBraces option.
Updated tests using BreakBeforeBraces other than BS_Attach.

Addresses http://llvm.org/PR17888

Reviewers: klimek, djasper

Reviewed By: klimek

CC: cfe-commits, klimek

Differential Revision: http://llvm-reviews.chandlerc.com/D2230

llvm-svn: 195256
2013-11-20 16:33:05 +00:00
Alexander Kornienko 7c9c050769 Support for JavaScript === and !== operators.
Reviewers: klimek, djasper

Reviewed By: klimek

CC: cfe-commits, klimek

Differential Revision: http://llvm-reviews.chandlerc.com/D2231

llvm-svn: 195251
2013-11-20 14:30:26 +00:00
Manuel Klimek 06c84f2e07 Fix bug where optimization would lead to strange line breaks.
Before:
  void f() {
    CHECK_EQ(aaaa, (
                       *bbbbbbbbb)->cccccc)
        << "qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq";
  }

After:
  void f() {
    CHECK_EQ(aaaa, (*bbbbbbbbb)->cccccc)
        << "qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq";
  }

llvm-svn: 195240
2013-11-20 11:20:32 +00:00
Samuel Benzaquen 464c1cbc3f Add partial support for the hasDeclaration() matcher in the dynamic layer.
Summary:
Add partial support for the hasDeclaration() matcher in the dynamic layer.
This matcher has some special logic to allow any type that has a getDecl() method.  We do not support this right now.

Reviewers: klimek

CC: cfe-commits, revane

Differential Revision: http://llvm-reviews.chandlerc.com/D1889

llvm-svn: 195013
2013-11-18 14:53:42 +00:00
Edwin Vane eb56f4fe2f Relax some preconditions for using FixedCompilationDatabase.
FixedCompilationDatabase (FCD) requires that the arguments it consumes after
'--' must not include positional parameters or the argv[0] of the tool. This
patch relaxes those restrictions.

llvm-svn: 194968
2013-11-17 16:08:04 +00:00
Alexander Kornienko 393e3088a1 Correctly mark first token in the presence of UTF-8 BOM.
Summary: Fixes http://llvm.org/PR17753

Reviewers: klimek

Reviewed By: klimek

CC: cfe-commits, klimek

Differential Revision: http://llvm-reviews.chandlerc.com/D2159

llvm-svn: 194576
2013-11-13 14:04:17 +00:00
NAKAMURA Takumi d3b07c6569 unittests/Tooling/ToolingTest.cpp: Suppress new tests on win32, due to handling of virtual file, such "/a.cc".
llvm-svn: 194534
2013-11-13 00:18:50 +00:00
Manuel Klimek 31cd3fc088 Add test for injecting diagnostic consumers into a ClangTool.
As suggested by pcc on 194226.

llvm-svn: 194494
2013-11-12 17:53:18 +00:00
Alexander Kornienko 875395f9f8 Remove extra whitespace instead of breaking the line in comments when possible.
Summary: Solves the problem described in http://llvm.org/PR17756

Reviewers: klimek

Reviewed By: klimek

CC: cfe-commits, klimek

Differential Revision: http://llvm-reviews.chandlerc.com/D2131

llvm-svn: 194493
2013-11-12 17:50:13 +00:00
Alexander Kornienko 3abbb8a433 Do not insert backslashes, when breaking line comments after preprocessor directives.
Summary: This solves http://llvm.org/PR17536

Reviewers: klimek, djasper

Reviewed By: klimek

CC: cfe-commits, klimek

Differential Revision: http://llvm-reviews.chandlerc.com/D2142

llvm-svn: 194491
2013-11-12 17:30:49 +00:00
Daniel Jasper 279430585a clang-format: Fix alignment of ObjC string literals.
This used to interfere with AlwaysBreakBeforeMultilineStrings.

This fixes llvm.org/PR17856.

llvm-svn: 194310
2013-11-09 03:08:25 +00:00
Daniel Jasper 0e93cdb0d0 clang-format: Improve clang-format's detection about comment binding.
Before, existing code in the form of:

  int a; // this is a.
  // This is
  // b.
  int b;

Got turned into:

  int a; // this is a.
         // This is
  // b.
  int b;

llvm-svn: 194294
2013-11-08 23:31:14 +00:00
Daniel Jasper 9e5ede0f8b clang-format: Improve formatting of operators forced to new lines.
Before:
  unsigned ContentSize =
      sizeof(int16_t) // DWARF ARange version number
      +
      sizeof(int32_t) // Offset of CU in the .debug_info section
      +
      sizeof(int8_t) // Pointer Size (in bytes)
      +
      sizeof(int8_t); // Segment Size (in bytes)

After:
  unsigned ContentSize =
      sizeof(int16_t)   // DWARF ARange version number
      + sizeof(int32_t) // Offset of CU in the .debug_info section
      + sizeof(int8_t)  // Pointer Size (in bytes)
      + sizeof(int8_t); // Segment Size (in bytes)

This fixes llvm.org/PR17687.

llvm-svn: 194276
2013-11-08 19:56:28 +00:00
Daniel Jasper 98fb6e1b9f clang-format: Don't auto-break short macros in WebKit style.
This fixes llvm.org/PR17842.

llvm-svn: 194268
2013-11-08 17:33:27 +00:00
Daniel Jasper 4478e5245e clang-format: Improve linebreaking and indentation for ObjC calls.
Before:
  popup_wdow_.reset([[RenderWidgetPopupWindow alloc]
      iniithContentRect:
          NSMakRet(origin_global.x, origin_global.y, pos.width(), pos.height())
                syeMask:NSBorderlessWindowMask
                  bking:NSBackingStoreBuffered
                    der:NO]);
  [self param:function( //
      parameter)]

After:
  popup_wdow_.reset([[RenderWidgetPopupWindow alloc]
      iniithContentRect:NSMakRet(origin_global.x, origin_global.y, pos.width(),
                                 pos.height())
                syeMask:NSBorderlessWindowMask
                  bking:NSBackingStoreBuffered
                    der:NO]);
  [self param:function( //
                  parameter)]

llvm-svn: 194267
2013-11-08 17:33:24 +00:00
Daniel Jasper b302f9a0fb clang-format: Properly indent ObjC calls wrapped before first selector
Before:
  [self // break
      a:a
     aa:aa
  aaaaa:aaa];

After:
  [self // break
          a:a
         aa:aa
      aaaaa:aaa];

llvm-svn: 194241
2013-11-08 02:08:01 +00:00
Daniel Jasper 165b29e2d2 clang-format: Make breaking before ternary operators configurable.
llvm-svn: 194229
2013-11-08 00:57:11 +00:00
Manuel Klimek 6408301421 Adds the ability to inject a DiagnosticConsumer into ClangTools.
llvm-svn: 194226
2013-11-07 23:18:05 +00:00
Peter Collingbourne a2334162cf Introduce MatchFinder::matchAST.
Differential Revision: http://llvm-reviews.chandlerc.com/D2115

llvm-svn: 194223
2013-11-07 22:30:36 +00:00
Peter Collingbourne 2b94713053 Re-introduce MatchFinder::addDynamicMatcher.
Differential Revision: http://llvm-reviews.chandlerc.com/D2114

llvm-svn: 194222
2013-11-07 22:30:32 +00:00
Daniel Jasper a98da3d236 clang-format: Improve binary operator detection in macros.
Before:
  #define M(NAME) assert(!Context.Verifying &&#NAME);

After:
  #define M(NAME) assert(!Context.Verifying && #NAME);

This fixes llvm.org/PR16156.

llvm-svn: 194216
2013-11-07 19:56:07 +00:00
Daniel Jasper f48b5abc49 clang-format: Improve ObjC variadic and binary expression parameters.
Before:
  [self aaaaaaaaaaaaaaa:aaaaaaaaaaaaaaa | aaaaaaaaaaaaaaa | aaaaaaaaaaaaaaa |
                           aaaaaaaaaaaaaaa | aaaaaaaaaaaaaaa | aaaaaaaaaaaaaaa |
                           aaaaaaaaaaaaaaa | aaaaaaaaaaaaaaa];
  [self aaaaaaaaaaaaaaa:aaaaaaaaaaaaaaa,
      aaaaaaaaaaaaaaa, aaaaaaaaaaaaaaa, aaaaaaaaaaaaaaa, aaaaaaaaaaaaaaa,
      aaaaaaaaaaaaaaa, aaaaaaaaaaaaaaa, aaaaaaaaaaaaaaa];

After:
  [self aaaaaaaaaaaaaaa:aaaaaaaaaaaaaaa | aaaaaaaaaaaaaaa | aaaaaaaaaaaaaaa |
                        aaaaaaaaaaaaaaa | aaaaaaaaaaaaaaa | aaaaaaaaaaaaaaa |
                        aaaaaaaaaaaaaaa | aaaaaaaaaaaaaaa];
  [self aaaaaaaaaaaaaaa:aaaaaaaaaaaaaaa, aaaaaaaaaaaaaaa, aaaaaaaaaaaaaaa,
                        aaaaaaaaaaaaaaa, aaaaaaaaaaaaaaa, aaaaaaaaaaaaaaa,
                        aaaaaaaaaaaaaaa, aaaaaaaaaaaaaaa];

This addresses llvm.org/PR15349 and llvm.org/PR16185.

llvm-svn: 194214
2013-11-07 19:23:49 +00:00
Daniel Jasper 4fcc8b91eb clang-format: Improve formatting of constructor initializers.
Before:
  Constructor()
      : aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa(aaaaaaaaaaaaaaaaaaaaaaaaa(aaaa,
                                                                      aaaa)) {}
After:
  Constructor()
      : aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa(
            aaaaaaaaaaaaaaaaaaaaaaaaa(aaaa, aaaa)) {}

llvm-svn: 194210
2013-11-07 17:52:51 +00:00
Daniel Jasper bc5cb4e369 clang-format: Remove old hack that mainly made incorrect tests pass.
As a side-effect, constructors definitions will correctly be recognized
and formatted as function declarations. Tests will be added in a
follow-up patch actually using the correct recognition.

llvm-svn: 194209
2013-11-07 17:43:07 +00:00
Daniel Jasper 6b6e7c37ea clang-format: Fix corner case for brace alignment.
Before:
  Constructor::Constructor()
      : some_value{ //
            aaaaaaa //
  } {}

After:
  Constructor::Constructor()
      : some_value{ //
            aaaaaaa //
        } {}

llvm-svn: 194204
2013-11-07 14:02:28 +00:00
Peter Collingbourne 671a1e4b37 Disable a tooling test on Windows.
llvm-svn: 194178
2013-11-06 23:02:51 +00:00
Peter Collingbourne c689ee76d4 Introduce ClangTool::buildASTs, and buildASTFromCode.
These allow clients to retrieve persistent AST objects (ASTUnits) which
can be used in an ad-hoc manner after parsing.

To accommodate this change, the code for processing a CompilerInvocation
using a FrontendAction has been factored out to FrontendActionFactory, and
a new base class, ToolAction, has been introduced, allowing the tool to do
arbitrary things with each CompilerInvocation.  This change was necessary
because ASTUnit does not use the FrontendAction interface directly.

This change also causes the FileManager in ClangTool to use shared ownership.
This will become necessary because ASTUnit takes shared ownership of
FileManager (ClangTool's FileManager is currently unused by ASTUnit; this
is a FIXME).  As shown in the tests, any client of ToolInvocation will
need to be modified to use shared ownership for FileManager.

Differential Revision: http://llvm-reviews.chandlerc.com/D2097

llvm-svn: 194164
2013-11-06 20:12:45 +00:00
Peter Collingbourne b23b39da21 Introduce DynTypedNode::print, dump and getSourceRange.
These functions can generally be applied to multiple kinds of AST node,
so it makes sense to add them to DynTypedNode.

Differential Revision: http://llvm-reviews.chandlerc.com/D2096

llvm-svn: 194113
2013-11-06 00:27:12 +00:00
Peter Collingbourne 093a729e03 Introduce BoundNodes::getMap.
The purpose of this function is to allow clients of the dynamic AST matcher
to enumerate each binding.

Differential Revision: http://llvm-reviews.chandlerc.com/D2095

llvm-svn: 194112
2013-11-06 00:27:07 +00:00
Daniel Jasper bbf5c1c965 clang-format: Allow line merging and partial formatting of nested blocks
Before, clang-format would always format entire nested blocks, which
can be unwanted e.g. for long DEBUG({...}) statements. Also
clang-format would not allow to merge lines in nested blocks (e.g. to
put "if (a) return;" on one line in Google style).

This is the first step of several refactorings mostly focussing on the
additional functionality (by reusing the "format many lines" code to
format the children of a nested block). The next steps are:
* Pull out the line merging into its own class.
* Seperate the formatting of many lines from the formatting of a single
  line (and the analysis of the solution space).

llvm-svn: 194090
2013-11-05 19:10:03 +00:00
Daniel Jasper 16fc754216 clang-format: Fix indenting corner case with comment and else.
Before:
  if (a) {
    f();
  }
      // or else ..
      else {
    g();
  }

After:
  if (a) {
    f();
  }
  // or else ..
  else {
    g();
  }

llvm-svn: 193684
2013-10-30 14:04:10 +00:00
Daniel Jasper 9885784d67 clang-format: Fix whitespaces in include directives.
Before (clang-format wouldn't change):
  #include  "a.h"
  #include<a>

After:
  #include "a.h"
  #include <a>

This fixes llvm.org/PR16151.

llvm-svn: 193683
2013-10-30 13:54:53 +00:00
Daniel Jasper 580da27616 clang-format: fix for \r\r\n produced in multiline block comments
Patch by Christopher Olsen. Thank you!

llvm-svn: 193678
2013-10-30 07:36:40 +00:00
Daniel Jasper dd978ae0e1 clang-format: Option to control spacing in template argument lists.
Same as SpacesInParentheses, this option allows adding a space inside
the '<' and '>' of a template parameter list.

Patch by Christopher Olsen.

This fixes llvm.org/PR17301.

llvm-svn: 193614
2013-10-29 14:52:02 +00:00
Samuel Benzaquen f34ac3ed2c Resubmit "Refactor DynTypedMatcher into a value type class, just like Matcher<T>."
Summary: This resubmits r193100, plus a fix for a breakage with MSVC.

Reviewers: klimek, rnk

CC: cfe-commits, revane

Differential Revision: http://llvm-reviews.chandlerc.com/D2005

llvm-svn: 193613
2013-10-29 14:37:15 +00:00
Daniel Jasper edc5f09175 clang-format: Fix overloaded operator for global-scoped conversions.
Before:
  operator::A();

After:
  operator ::A();

llvm-svn: 193605
2013-10-29 12:24:23 +00:00
Daniel Jasper a1ea4cbb80 clang-format: Fix ObjC method exprs with variadic parameters.
Before:
  _versionLabel.text = [
    NSString stringWithFormat:NSLocalizedString(@"version: %@", @"Label"),
    [NSBundle mainBundle].infoDictionary[@"CFBundleShortVersionString"]
  ];

After:
  _versionLabel.text =
      [NSString stringWithFormat:NSLocalizedString(@"version: %@", @"Label"),
          [NSBundle mainBundle].infoDictionary[@"CFBundleShortVersionString"]];

This fixed llvm.org/PR17695.

llvm-svn: 193475
2013-10-26 17:00:22 +00:00
Daniel Jasper 33b909c5f3 clang-format: Adapt line break penalties for LLVM style.
Specifically make clang-format less eager to break after the opening
parenthesis of a function call.

Before:
  aaaaaaaaaaaaaaaaa(
      aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa + aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa,
      aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa);

After:
  aaaaaaaaaaaaaaaaa(aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa +
                        aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa,
                    aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa);

Apparently that is preferable. This penalties are adapted
conservatively, we might have to increase them a little bit further.

llvm-svn: 193410
2013-10-25 14:29:37 +00:00
Daniel Jasper 472da8644e clang-format: Properly reset nested AnnotatedLine structure.
This fixes llvm.org/PR17682.

Without this patch, the following code leads to invalid reads/writes:
  DEBUG({
    return aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa +
           aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa;
  });
  #if a
  #else
  #endif

Because of the #if-#else structure, the code is formatted and annotated
twice and becauce of the nested block, the annotated lines form a
hierarchical structure. This structure was not properly reset between
runs.

llvm-svn: 193352
2013-10-24 15:23:11 +00:00
Daniel Jasper 7c72d9fef2 clang-format: Be more conservative about column layout formatting.
Specifically, if a braced list has at least one nested braced list,
format it either all on one line or in one column (i.e. one item per
line).

This seems in general to be an improvement as the structure of nested
braced lists can make a tightly packed outer braced list hard to read.

llvm-svn: 193345
2013-10-24 14:14:49 +00:00
Daniel Jasper b596fb2be2 clang-format: Cleanup array initializer and dict initializer formatting.
Significant changes:
- Also recognize these literals with missing "@" for robustness.
- Reorganize tests.

llvm-svn: 193325
2013-10-24 10:31:50 +00:00
Manuel Klimek 1f76c4e810 Use the same SourceManager for ModuleMaps and compilations.
This allows using virtual file mappings on the original SourceManager to
map in virtual module.map files. Without this patch, the ModuleMap
search will find a module.map file (as the FileEntry exists in the
FileManager), but will be unable to get the content from the
SourceManager (as ModuleMap previously created its own SourceManager).

Two problems needed to be fixed which this patch exposed:

1. Storing the inferred module map
When writing out a module, the ASTWriter stores the names of the files
in the main source manager; when loading the AST again, the ASTReader
errs out if such a file is found missing, unless it is overridden.
Previously CompilerInstance's compileModule method would store the
inferred module map to a temporary file; the problem with this approach
is that now that the module map is handled by the main source manager,
the ASTWriter stores the name of the temporary module map as source to
the compilation; later, when the module is loaded, the temporary file
has already been deleted, which leads to a compilation error. This patch
changes the inferred module map to instead inject a virtual file into
the source manager. This both saves some disk IO, and works with how the
ASTWriter/ASTReader handle overridden source files.

2. Changing test input in test/Modules/Inputs/*
Now that the module map file is handled by the main source manager, the
VerifyDiagnosticConsumer will not ignore diagnostics created while
parsing the module map file. The module test test/Modules/renamed.m uses
-I test/Modules/Inputs and triggers recursive loading of all module maps
in test/Modules/Inputs, some of which had conflicting names, thus
leading errors while parsing the module maps. Those diagnostics already
occur on trunk, but before this patch they would not break the test, as
they were ignored by the VerifyDiagnosticConsumer. This patch thus
changes the module maps that have been recently introduced which broke
the invariant of compatible modules maps in test/Modules/Inputs.

llvm-svn: 193314
2013-10-24 07:51:24 +00:00
Daniel Jasper b8f6168218 clang-format: Fix ObjC literal indentation in Google style.
Style guide demands a two-space indent.

Before:
  NSArray *arguments = @[
      kind == kUserTicket ? @"--user-store" : @"--system-store",
      @"--print-tickets",
      @"--productid",
      @"com.google.Chrome"
  ];

After:
  NSArray *arguments = @[
    kind == kUserTicket ? @"--user-store" : @"--system-store",
    @"--print-tickets",
    @"--productid",
    @"com.google.Chrome"
  ];

llvm-svn: 193168
2013-10-22 15:45:58 +00:00
Daniel Jasper 1db6c38687 clang-format: Improve formatting of ObjC array literals.
Before:
  NSArray *arguments =
      @[ kind == kUserTicket ? @"--user-store" : @"--system-store",
         @"--print-tickets", @"--productid", @"com.google.Chrome" ];
After:
  NSArray *arguments = @[
      kind == kUserTicket ? @"--user-store" : @"--system-store",
      @"--print-tickets",
      @"--productid",
      @"com.google.Chrome"
  ];

This fixes llvm.org/PR15231.

llvm-svn: 193167
2013-10-22 15:30:28 +00:00
Manuel Klimek f6fd3d3fcf Remove incorrect assert.
If we run into the second preprocessor branch chain, the first branch
chain might have already set the maximum branch count on that level to
something > 0.

Fixes PR17645.

llvm-svn: 193153
2013-10-22 08:27:19 +00:00
Reid Kleckner 9171f02528 Revert "Refactor DynTypedMatcher into a value type class, just like Matcher<T>."
This reverts commit r193100.

It was failing to compile with MSVC 2012 while instantiating
llvm::Optional<DynTypedMatcher>.

llvm-svn: 193123
2013-10-21 22:26:36 +00:00
Samuel Benzaquen f46e5f1c9a Refactor DynTypedMatcher into a value type class, just like Matcher<T>.
Summary:
Refactor DynTypedMatcher into a value type class, just like Matcher<T>.
This simplifies its usage and removes the virtual hierarchy from Matcher<T>.
It also enables planned changes to replace MatcherInteface<T>.
Too many instantiaions of this class hierarchy has been causing Registry.cpp.o to bloat in size and number of symbols.

Reviewers: klimek

CC: cfe-commits, revane

Differential Revision: http://llvm-reviews.chandlerc.com/D1661

llvm-svn: 193100
2013-10-21 18:40:51 +00:00
Manuel Klimek 88033d7a97 Fixes PR17617: Crash on joining short if statements.
Now that we iterate on the formatting multiple times when we
have chains of preprocessor branches, we need to correctly reset
the token's previous and next pointer for the first / last token.

llvm-svn: 193071
2013-10-21 08:11:15 +00:00
Daniel Jasper d46e07e26e clang-format: Better understand Lambda poarameters.
Before:
  auto PointerBinding = [](const char * S) {};

After:
  auto PointerBinding = [](const char *S) {};

This fixes llvm.org/PR17618.

llvm-svn: 193054
2013-10-20 18:15:30 +00:00
Daniel Jasper dcd5da1fd9 clang-format: Fix formatting of nested blocks after comment.
Before:
  DEBUG({ // Comment that used to confuse clang-format.
  fdafas();
  });
Before:
  DEBUG({ // Comments are now fine.
    fdafas();
  });

This fixed llvm.org/PR17619.

llvm-svn: 193051
2013-10-20 17:28:32 +00:00
Daniel Jasper 2d0cd49787 clang-format: Support case ranges.
Before (note the missing space before "..." which can lead to compile
errors):
  switch (x) {
    case 'A'... 'Z':
    case 1... 5:
        break;
  }

After:
  switch (x) {
    case 'A' ... 'Z':
    case 1 ... 5:
        break;
  }

llvm-svn: 193050
2013-10-20 16:56:16 +00:00
Daniel Jasper d489dd342b clang-format: Improve formatting of ObjC dict literals.
Before:
  NSDictionary *d = @{ @"nam" : NSUserNam(), @"dte" : [NSDate date],
                       @"processInfo" : [NSProcessInfo processInfo]
  };

After:
  NSDictionary *d = @{
    @"nam" : NSUserNam(),
    @"dte" : [NSDate date],
    @"processInfo" : [NSProcessInfo processInfo]
  };

llvm-svn: 193049
2013-10-20 16:45:46 +00:00
Ariel J. Bernal 3255134ac5 Reverted r192992 broke windows and freebsd builds.
llvm-svn: 192997
2013-10-18 19:48:31 +00:00
Ariel J. Bernal 4dc53c20fc This patch fixes replacements that are not applied when relative paths are
specified.

In particular it makes sure that  relative paths for non-virtual files aren't
made absolute.
Added unittest.

llvm-svn: 192992
2013-10-18 18:38:24 +00:00
Daniel Jasper fbc057ea73 clang-format: Be more aggressive on incorrect code.
Before, clang-format would not adjust leading indents if it found a
structural error (e.g. unmatched {}). It seems, however, that
clang-format has gotten good enough at parsing the code structure that
this hurts in almost all cases. Commonly, while writing code, it is
very useful to be able to correclty indent incomplete if statements or
for loops.

In case this leads to errors that we don't anticipate, we need to find
out and fix those.

This fixed llvm.org/PR17594.

llvm-svn: 192988
2013-10-18 17:20:57 +00:00
Daniel Jasper 2436fe95ea clang-format: Don't force linebreak between return and multiline string.
This looks ugly and leads to llvm.org/PR17590.

Before (with AlwaysBreakBeforeMultilineStrings):
  return
      "aaaa"
      "bbbb";

After:
  return "aaaa"
         "bbbb";

llvm-svn: 192984
2013-10-18 16:47:55 +00:00
Daniel Jasper d8c36d09b1 Make clang-format slightly more willing to break before trailing annotations.
Specifically, prefer breaking before trailing annotations over breaking
before the first parameter.

Before:
  void ffffffffffffffffffffffff(
      int aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa,
      int aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa) OVERRIDE;

After:
  void ffffffffffffffffffffffff(int aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa,
                                int aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa)
      OVERRIDE;

llvm-svn: 192983
2013-10-18 16:34:40 +00:00
Daniel Jasper cc3114d876 clang-format: Improve formatting of templated builder-type calls.
Before:
  aaaaaaaaaaaaaaaaaaaaaaaaaaa.aaaaaaaaaaaaaaaaaa().aaaaaaaaaaaaaaaaa().has<
      bbbbbbbbbbbbbbbbbbbbb>();

After:
  aaaaaaaaaaaaaaaaaaaaaaaaaaa.aaaaaaaaaaaaa()
      .aaaaaaaaaaaaaaaaaaaaaaaaaa()
      .has<bbbbbbbbbbbbbbbbbbbbb>();

llvm-svn: 192981
2013-10-18 15:23:06 +00:00
Daniel Jasper 6633ab8ad9 clang-format: Make continuation indent width configurable.
Patch by Kim Gräsman. Thank you!

llvm-svn: 192964
2013-10-18 10:38:14 +00:00
Alexey Samsonov 05747f3734 Fix use-after-free in PPCallbacksTest detected by ASan bootstrap bot
llvm-svn: 192572
2013-10-14 07:13:59 +00:00
Alexander Kornienko e2e0387f3e Keep track of indentation levels in static initializers for correct indentation with tabs.
Summary:
Store IndentationLevel in ParentState and use it instead of the
Line::Level when indening.
Also fixed incorrect indentation level calculation in formatFirstToken.

Reviewers: djasper

Reviewed By: djasper

CC: cfe-commits, klimek

Differential Revision: http://llvm-reviews.chandlerc.com/D1797

llvm-svn: 192563
2013-10-14 00:46:35 +00:00
Manuel Klimek b212f3baa1 Automatically munch semicolons after blocks.
While it is mostly a user error to have the extra semicolon,
formatting it graciously will correctly format in the cases
where we do not fully understand the code (macros).

llvm-svn: 192543
2013-10-12 22:46:56 +00:00
Daniel Jasper 53bd167c60 clang-format: Fix assertion on unterminated #ifs.
llvm-svn: 192535
2013-10-12 13:32:56 +00:00
Pekka Jaaskelainen 1db1da25bf Callback support for OpenCL extension pragmas.
Patch from Rami Ylimäki and Mikael Lepistö!

llvm-svn: 192531
2013-10-12 09:29:48 +00:00
Daniel Jasper fba84ff00d clang-format: No space in "<::" in C++11 mode.
llvm-svn: 192524
2013-10-12 05:16:06 +00:00
Alexander Kornienko 384b40b90d Don't break string literals inside preprocessor directives.
Summary:
This way we avoid breaking code which uses unknown preprocessor
directives with long string literals. The specific use case in
http://llvm.org/PR17035 isn't very common, but it seems to be a good idea to
avoid this kind of problem anyway.

Reviewers: djasper

Reviewed By: djasper

CC: cfe-commits, klimek

Differential Revision: http://llvm-reviews.chandlerc.com/D1813

llvm-svn: 192507
2013-10-11 21:43:05 +00:00
Manuel Klimek 71814b4465 Support formatting of preprocessor branches.
We now correctly format:
  void SomeFunction(int param1,
  #ifdef X
                    NoTemplate param2,
  #else
                    template <
  #ifdef A
                        MyType<Some> >
  #else
                        Type1, Type2>
  #endif
                    param2,
  #endif
                    param3) {
    f();
  }

llvm-svn: 192503
2013-10-11 21:25:45 +00:00
Daniel Jasper 877615ccfd clang-format: Don't remove 'unknown' tokens.
In certain macros or incorrect string literals, the token stream can
contain 'unknown' tokens, e.g. a single backslash or a set of empty
ticks. clang-format simply treated them as whitespace and removed them
prior to this patch.

This fixes llvm.org/PR17215

llvm-svn: 192490
2013-10-11 19:45:02 +00:00
Alexander Kornienko 60d1b046dd Correctly detect colon in bit fields. Fixes PR17333.
Summary: Colon was incorrectly detected as a start of inheritance list. Fixed.

Reviewers: djasper

Reviewed By: djasper

CC: cfe-commits, klimek

Differential Revision: http://llvm-reviews.chandlerc.com/D1884

llvm-svn: 192349
2013-10-10 13:36:20 +00:00
Ariel J. Bernal e7288fe233 Revert commit r192299 until find a way to account for simlinks in OS X.
llvm-svn: 192313
2013-10-09 18:27:27 +00:00
Ariel J. Bernal ee863cedc2 This patch fixes replacements that are not applied when relative paths are
specified.

In particular it makes sure that relative paths for non-virtual files aren't
made absolute.
Added unittest test.

llvm-svn: 192299
2013-10-09 16:09:23 +00:00
Daniel Jasper d3e014d404 clang-format: Fix template declaration line breaking with comment.
Before, clang-format would always insert a linebreak before the comment
in code like:
  template <typename T> // T can be A, B or C.
  struct S {};

llvm-svn: 192297
2013-10-09 15:06:17 +00:00
Daniel Jasper f9a5e4043c clang-format: Improve indentation when deriving from templated classes.
Before:
  struct aaaaaaaaaaaaa : public aaaaaaaaaaaaaaaaaaa< //
      aaaaaaaaaaaaaaaa> {};
  struct aaaaaaaaaaaaaaaaaaaa : public aaaaaaaaaaaaaaaaaaa<
      aaaaaaaaaaaaaaaaaaaaa, aaaaaaaaaaaaaaaaaaaaaa> {};

After:
  struct aaaaaaaaaaaaa : public aaaaaaaaaaaaaaaaaaa< //
                             aaaaaaaaaaaaaaaa> {};
  struct aaaaaaaaaaaaaaaaaaaa
      : public aaaaaaaaaaaaaaaaaaa<aaaaaaaaaaaaaaaaaaaaa,
                                   aaaaaaaaaaaaaaaaaaaaaa> {};

llvm-svn: 192187
2013-10-08 16:24:07 +00:00
Daniel Jasper ec01cd6e7f clang-format: Improve constructor initializer linewrapping.
Specifically make ConstructorInitializerAllOnOneLineOrOnePerLine work
nicely with BreakConstructorInitializersBeforeComma.

This fixes llvm.org/PR17395.

llvm-svn: 192168
2013-10-08 05:11:18 +00:00
Manuel Klimek 91e48586ae Fix incorrect detection of class definitions with alignas specification.
llvm-svn: 192094
2013-10-07 09:15:41 +00:00
Daniel Jasper 320997e6b3 clang-format: Remove empty lines after visibility modifiers.
Formatting:
  class C {
  public:

    f();
  };

Now leads to:
  class C {
  public:
    f();
  };

llvm-svn: 192062
2013-10-06 11:40:08 +00:00
Daniel Jasper eabede6d1b clang-format: Improve alignment after 'return'.
Previously, comments, could totally confuse it.

Before:
  return
             // true if code is one of a or b.
             code == a ||
         code == b;

After:
  return
      // true if code is one of a or b.
      code == a || code == b;

llvm-svn: 191654
2013-09-30 08:29:03 +00:00
Daniel Jasper 0b1f76b658 clang-format: Fix assertion on incomplete string literals.
Before, this could would lead to an assert:
  llvm::errs() << "
               << a;

llvm-svn: 191639
2013-09-29 12:02:57 +00:00
Alexander Kornienko 45dc1b2fd3 Added a comment and another test for the UT_ForIndentation option
llvm-svn: 191530
2013-09-27 16:40:11 +00:00
Alexander Kornienko 3c3d09c885 Implemented tab usage only for indentation (http://llvm.org/PR17363)
Summary:
Changed UseTab to be a enum with three options: Never, Always,
ForIndentation (true/false are still supported when reading .clang-format).
IndentLevel should currently be propagated correctly for all tokens, except for
block comments. Please take a look at the general idea before I start dealing
with block comments.

Reviewers: klimek, djasper

Reviewed By: klimek

CC: cfe-commits

Differential Revision: http://llvm-reviews.chandlerc.com/D1770

llvm-svn: 191527
2013-09-27 16:14:22 +00:00
Alexander Kornienko db4c21f994 Correctly indent with tabs when whitespace starts from the column not divisible by TabWidth.
Summary:
The width of the first inserted tab character depends on the initial
column, so we need to handle the first tab in a special manner.

Reviewers: klimek, djasper

Reviewed By: klimek

CC: cfe-commits

Differential Revision: http://llvm-reviews.chandlerc.com/D1763

llvm-svn: 191497
2013-09-27 09:45:40 +00:00
Daniel Jasper f3167903b8 clang-format: Improve formatting of functions with multiple trailing tokens.
Before:
  void SomeFunction(aaaaaaaaaaaaaaaaaaaaaaaaaa,
                    aaaaaaaaaaaaaaaaaaaaaaaaaa) override
  final;

After:
  void SomeFunction(aaaaaaaaaaaaaaaaaaaaaaaaaa,
                    aaaaaaaaaaaaaaaaaaaaaaaaaa) override final;

llvm-svn: 191494
2013-09-27 08:29:16 +00:00
Daniel Jasper 69bd8fb79a clang-format: Fix formatting bug with comment in weird place.
Before:
  template <typename T>
  // T should be one of {A, B}.
      void f() {}

After:
  template <typename T>
  // T should be one of {A, B}.
  void f() {}

llvm-svn: 191492
2013-09-27 07:49:08 +00:00
Daniel Jasper d94bff3721 clang-format: Option to removing the space before assignment operators.
Patch contributed by Aaron Wishnick. Thank you!

llvm-svn: 191375
2013-09-25 15:15:02 +00:00
Daniel Jasper df620b2457 clang-format: Improve address-of-operator detection
Before:
  size = sizeof * a;

After:
  size = sizeof *a;

llvm-svn: 191139
2013-09-21 17:31:51 +00:00
Daniel Jasper fb81b09d87 clang-format: Don't accidentally move tokens into preprocessor directive.
This fixes llvm.org/PR17265.

Before:
  Foo::Foo()
  #ifdef BAR
      : baz(0)
  #endif {
  }

After:
  Foo::Foo()
  #ifdef BAR
      : baz(0)
  #endif
  {
  }

llvm-svn: 190861
2013-09-17 09:52:48 +00:00
Daniel Jasper 545c652d75 clang-format: Add comment to tests explaining their grouping.
llvm-svn: 190858
2013-09-17 09:26:07 +00:00
Daniel Jasper 88f9222c4e clang-format: Fix line breaking bug after empty ifs.
Before:
  if () {
  }
    else {
  }

After:
  if () {
  } else {
  }

This fixed llvm.org/PR17262.

llvm-svn: 190855
2013-09-17 08:28:05 +00:00
Daniel Jasper 0de8efa63d clang-format: Don't split a >>-operator.
Before (with column limit 60):
  aaaaaaaaaaaaaaaaaaaaaaaaaaaa(aaaaaaaaaaaaaaaaaaaaaaaaaaaaa >
      > aaaaa);

After:
  aaaaaaaaaaaaaaaaaaaaaaaaaaaa(
      aaaaaaaaaaaaaaaaaaaaaaaaaaaaa >> aaaaa);

(Not sure how that could have stayed in that long without being
detected..)

llvm-svn: 190854
2013-09-17 08:15:46 +00:00
Alexander Kornienko 81e3294e7e When in pre-c++11 mode, treat _T("xxx") as a single string literal, repeat the _T() part around each fragment. This addresses http://llvm.org/PR17122
Reviewers: djasper

Reviewed By: djasper

CC: cfe-commits, klimek, rsmith

Differential Revision: http://llvm-reviews.chandlerc.com/D1640

llvm-svn: 190804
2013-09-16 20:20:49 +00:00
Daniel Jasper 5c9e3cdb6d clang-format: Fix bug in style option AlwaysBreakTemplateDeclarations.
Before:
  template <template <typename>
            class Fooooooo, template <typename>
            class Baaaaaaar>
  struct C {};

After:
  template <template <typename> class Fooooooo,
            template <typename> class Baaaaaaar>
  struct C {};

llvm-svn: 190747
2013-09-14 08:13:22 +00:00
Daniel Jasper f3d977979c clang-format: Detect braced lists in subscript expressions.
Before (even with Style.Cpp11BracedListStyle):
  f(MyMap[{ composite, key }]);

After:
  f(MyMap[{composite, key}]);

llvm-svn: 190678
2013-09-13 10:55:31 +00:00
Daniel Jasper 015ed028cf clang-format: Fix incorrect enum parsing / layouting.
Before:
  enum {
    Bar = Foo < int,
    int > ::value
  };

After:
  enum {
    Bar = Foo<int, int>::value
  };

llvm-svn: 190674
2013-09-13 09:20:45 +00:00
Michael Han 6ca01b4b6c Add a test case to test RAV visits parameters of implicit copy constructor.
llvm-svn: 190632
2013-09-12 20:59:33 +00:00
Daniel Jasper 5ca9b7141f clang-format: Fix bug in pointer detection
Before:
  for (int i = 0; i* 2 < z; i *= 2) {}
After:
  for (int i = 0; i * 2 < z; i *= 2) {}

llvm-svn: 190546
2013-09-11 20:37:10 +00:00
Michael Han c90d12d1df Teach RAV to visit parameter variable declarations of implicit functions. Fixes PR16182.
Normally RAV visits parameter variable declarations of a function by traversing the TypeLoc of
the parameter declarations. However, for implicit functions, their parameters don't have any
TypeLoc, because they are implicit.

So for implicit functions, we visit their parameter variable declarations by traversing them through
the function declaration, and visit them accordingly.

Reviewed by Richard Smith and Manuel Klimek.

llvm-svn: 190528
2013-09-11 15:53:29 +00:00
Alexander Kornienko 9e649af004 Support for CR LF newlines.
Summary:
reformat() tries to determine the newline style used in the input
(either LF or CR LF), and uses it for the output. Maybe not every single case is
supported, but at least the bug described in http://llvm.org/PR17182 should be
resolved.

Reviewers: djasper

Reviewed By: djasper

CC: cfe-commits, klimek

Differential Revision: http://llvm-reviews.chandlerc.com/D1643

llvm-svn: 190519
2013-09-11 12:25:57 +00:00
Rui Ueyama 2ceba7938d Do not quote YAML plain string myself. Let YAMLIO do that.
llvm-svn: 190486
2013-09-11 04:00:35 +00:00
Alexander Kornienko d8d47fa504 Don't divide L and #x in macro definitions. Fixes http://llvm.org/PR17144
Reviewers: djasper

Reviewed By: djasper

CC: cfe-commits, klimek

Differential Revision: http://llvm-reviews.chandlerc.com/D1639

llvm-svn: 190408
2013-09-10 13:41:43 +00:00
Alexander Kornienko 917f9e04b5 Correctly calculate OriginalColumn after multi-line tokens.
Summary: This also unifies the handling of escaped newlines for all tokens.

Reviewers: djasper

Reviewed By: djasper

CC: cfe-commits, klimek

Differential Revision: http://llvm-reviews.chandlerc.com/D1638

llvm-svn: 190405
2013-09-10 12:29:48 +00:00
Daniel Jasper 71665cd1fd clang-format: Understand function type typedefs with typeof.
Before:
  typedef typeof(int(int, int)) * MyFunc;
After:
  typedef typeof(int(int, int)) *MyFunc;

This fixes llvm.org/PR17178.

llvm-svn: 190401
2013-09-10 10:26:38 +00:00
Alexander Kornienko 39856b71a6 Calculate and store ColumnWidth instead of CodePointCount in FormatTokens.
Summary:
This fixes various issues with mixed tabs and spaces handling, e.g.
when realigning block comments.

Reviewers: klimek, djasper

Reviewed By: djasper

CC: cfe-commits

Differential Revision: http://llvm-reviews.chandlerc.com/D1608

llvm-svn: 190395
2013-09-10 09:38:25 +00:00
Daniel Jasper 9b246e09ce clang-format: Keep empty lines and format 1-line nested blocks.
Let clang-format consistently keep up to one empty line (configured via
FormatStyle::MaxEmptyLinesToKeep) in nested blocks, e.g. lambdas. Also,
actually format single statements in nested blocks.

Before:
  DEBUG({ int     i; });
  DEBUG({
    int i;
    // an empty line here would just be removed.
    int j;
  });

After:
  DEBUG({ int i; });
  DEBUG({
    int i;

    int j;
  });

llvm-svn: 190278
2013-09-08 14:07:57 +00:00
Enea Zaffanella 76e98feb57 Fix missing source location in CXXTemporaryObjectExpr nodes.
For clarity, renamed (get/set)ParenRange as (get/set)ParenOrBraceRange
in CXXConstructExpr nodes.
Added testcase.

llvm-svn: 190239
2013-09-07 05:49:53 +00:00
Daniel Jasper 87f18f1128 clang-format: Fix regression introduced by r190038.
Before:
  Constructor()
      : aaaaaaaaaaaaaaaaaaaa(a), bbbbbbbbbbbbbbbbbbbbbbbb(b) {
                                 }
After:
  Constructor()
      : aaaaaaaaaaaaaaaaaaaa(a), bbbbbbbbbbbbbbbbbbbbbbbb(b) {
  }

llvm-svn: 190209
2013-09-06 21:46:41 +00:00
Daniel Jasper 786a550b9f clang-format: Format typed enums with nested names.
The explicit type specified for an enum can actually have a nested name
specifier.

This fixes llvm.org/PR17125.

llvm-svn: 190208
2013-09-06 21:32:35 +00:00
Daniel Jasper b4b9998713 clang-format: Don't confuse operator[] with lambdas.
Before:
  double &operator[](int i) { return 0; } int i;

After:
  double &operator[](int i) { return 0; }
  int i;

This fixes llvm.org/PR17134.

llvm-svn: 190207
2013-09-06 21:25:51 +00:00
Alexander Kornienko 9ab4a77a5b Don't remove trailing escaped newline from line comments.
llvm-svn: 190175
2013-09-06 17:24:54 +00:00
Daniel Jasper 36c28ce38d clang-format: Fix regression introduced by r189353.
Before:
  FirstToken->WhitespaceRange.getBegin()
      .getLocWithOffset(First->LastNewlineOffset);

After:
  FirstToken->WhitespaceRange.getBegin().getLocWithOffset(
      First->LastNewlineOffset);

Re-add logic to prevent breaking after an empty set of parentheses.
Basically it seems that calling a function without parameters is more
like navigating along the same object than it is a separate step of a
builder-type call.

We might need to extends this in future to allow "short" parameters that
e.g. are an index accessing a specific element.

llvm-svn: 190126
2013-09-06 08:54:24 +00:00
Daniel Jasper 562ecd4444 clang-format: Fix regression introduced by r189337.
Before:
  if (aaaaaaaaaaaaaaaaaaaaaaaaaa.aaaaaaaaaaaaaaaaaaaaaa(
          aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa) == 5) ...

After:
  if (aaaaaaaaaaaaaaaaaaaaaaaaaa.aaaaaaaaaaaaaaaaaaaaaa(
          aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa)
      == 5) ...

Also precompute startsBinaryExpression() to improve performance.

llvm-svn: 190124
2013-09-06 08:08:14 +00:00
Daniel Jasper 1c5d9df8d1 clang-format: Fix comment formatting bugs in nested blocks.
This fixes two issues:
1) The indent of a line comment was not adapted to the subsequent
   statement as it would be outside of a nested block.
2) A missing DryRun flag caused actualy breaks to be inserted in
   overly long comments while trying to come up with the best line
   breaking decisions.

llvm-svn: 190123
2013-09-06 07:54:20 +00:00
James Dennett 8f60cdd54b Mark lambda closure classes as being implicitly-generated.
Summary: Closure classes for C++ lambdas are always compiler-generated.  This one-line change calls setImplicit(true) on them at creation time, such that a default RecursiveASTVisitor (or any for which shouldVisitImplicitCode returns false) will skip them.

Reviewers: rsmith, dblaikie

Reviewed By: dblaikie

CC: klimek, revane, cfe-commits, jordan_rose

Differential Revision: http://llvm-reviews.chandlerc.com/D1593

llvm-svn: 190073
2013-09-05 17:46:21 +00:00
Manuel Klimek 9a53c7f40d Fixes PR 17106 (explicitly typed enums are formatted differently).
Before:
 enum X : int { A, B, C };

After:
 enum X : int {
   A,
   B,
   C
 };

llvm-svn: 190054
2013-09-05 15:34:55 +00:00
Alexander Kornienko ebb43caae2 Handle zero-width and double-width characters in string literals and comments.
Summary:
Count column width instead of the number of code points. This also
includes correct handling of tabs inside string literals and comments (with an
exception of multiline string literals/comments, where tabs are present before
the first escaped newline).

Reviewers: djasper, klimek

Reviewed By: klimek

CC: cfe-commits, klimek

Differential Revision: http://llvm-reviews.chandlerc.com/D1601

llvm-svn: 190052
2013-09-05 14:08:34 +00:00
Daniel Jasper bf02b2c186 clang-format: Quickfix for braced init lists detected as lambdas.
Before:
  constexpr char hello [] { "hello" };

After:
  constexpr char hello[]{ "hello" };

llvm-svn: 190046
2013-09-05 11:49:39 +00:00
Daniel Jasper 9a8d48b5e1 clang-format: Fix parsing and indenting lambdas.
Before:
  void f() {
    other(x.begin(), x.end(), //
                         [&](int, int) { return 1; });
  }

After:
  void f() {
    other(x.begin(), x.end(), //
          [&](int, int) { return 1; });
  }

llvm-svn: 190039
2013-09-05 10:04:31 +00:00
Daniel Jasper 9fe0e8dacd clang-format: Enable formatting of nested blocks.
Among other things, this enables (better) formatting lambdas and
constructs like:
  MACRO({
          long_statement();
          long_statement_2();
        },
        {
          long_statement();
          long_statement_2();
        },
        { short_statement(); }, "");

This fixes llvm.org/PR15381.

llvm-svn: 190038
2013-09-05 09:29:45 +00:00
Alexander Kornienko b40cfe4866 Handle 'Cpp03' and 'Cpp11' strings in LanguageStandard serialization for
consistency of serialized form with the actual enum member names without
a prefix.

llvm-svn: 189936
2013-09-04 14:09:13 +00:00
Manuel Klimek 516e054c05 Implement parsing of blocks (^{ ... }) in the unwrapped line parser.
This patch makes sure we produce the right number of unwrapped lines,
a follow-up patch will make the whitespace formatting consistent.

Before:
 void f() {
   int i = {[operation setCompletionBlock : ^{ [self onOperationDone];
 }]
 }
 ;
 }

After:
 void f() {
   int i = {[operation setCompletionBlock : ^{
     [self onOperationDone];
   }] };
 }

llvm-svn: 189932
2013-09-04 13:25:30 +00:00
Manuel Klimek a1a43abe38 More lambda formatting tests; update test comments.
llvm-svn: 189928
2013-09-04 10:06:46 +00:00
Manuel Klimek bab25fdfa5 Fix layout of lambda captures.
Before:
 int c = [ &, &a, a]{
   [ =, c, &d]{
     return b++;
   }();
 }();

After:
 int c = [&, &a, a] {
   [=, c, &d] {
     return b++;
   }();
 }();

llvm-svn: 189924
2013-09-04 08:20:47 +00:00
Manuel Klimek ffdeb595ba First step towards correctly formatting lambdas.
Implements parsing of lambdas in the UnwrappedLineParser.
This introduces the correct line breaks; the formatting of
lambda captures are still incorrect, and the braces are also
still formatted as if they were braced init lists instead of
blocks.

llvm-svn: 189818
2013-09-03 15:10:01 +00:00
Daniel Jasper 42401c8d13 clang-format: Fix segfault in overloaded operator parsing.
Before, constructs like:
  using A::operator+;

caused a segfault. This fixes llvm.org/PR17050.

llvm-svn: 189749
2013-09-02 09:20:39 +00:00
Daniel Jasper 7240762504 clang-format: Fix case-indentation in macros.
Before:
  #define OPERATION_CASE(name)           \
    case OP_name:                        \
    return operations::Operation##name

After:
  #define OPERATION_CASE(name)           \
    case OP_name:                        \
      return operations::Operation##name

llvm-svn: 189743
2013-09-02 08:26:29 +00:00
Samuel Benzaquen 998cda23b9 Reduce the number of symbols by changing how templates are instantiated per function bound in the registry.
Summary:
Reduce the number of symbols by changing how templates are instantiated per function bound in the registry.
This change reduces the number of sections in Registry.cpp.o by a little over 10%.

Reviewers: klimek

CC: cfe-commits, revane

Differential Revision: http://llvm-reviews.chandlerc.com/D1557

llvm-svn: 189676
2013-08-30 15:09:52 +00:00
Daniel Jasper 8ddfa8489b clang-format: Enable formatting of protocol buffer definitions.
Almost by accident, clang-format seems to be able to format protocol
buffer definitions (https://code.google.com/p/protobuf/).

The only change is that a space is required between numeric constants
and opening square brackets (for default values). While this might in
theory be used for array subscripts (int val = 4[MyArray]), I have not
seen this pattern in practice much. If this is wrong, we can make this
smarter in the future.

llvm-svn: 189663
2013-08-30 10:36:58 +00:00
Daniel Jasper b715087278 clang-format: Improve recovery from enums with errors.
Before:
  namespace n {
  enum Type {
    One,
    Two, // missing };
    int i;
  } void g() {
  }

After:
  namespace n {
  enum Type {
    One,
    Two, // missing };
    int i;
  }
  void g() {}

llvm-svn: 189662
2013-08-30 10:10:19 +00:00
Daniel Jasper f79b0b1562 clang-format: Fix incorrect indentation.
Before:
aaaaaaaaaa(bbbbbbbbbbbbbbbbbbbbbbbbb.ccccccccccccccccc(
               dddddddddddddddddddddddddddddd));
aaaaaaaaaaa(bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb(
    dddddddddddddddddddddddddddddd));

After:
aaaaaaaaaaa(bbbbbbbbbbbbbbbbbbbbbbbbb.ccccccccccccccccc(
    dddddddddddddddddddddddddddddd));
aaaaaaaaaaa(bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb(
    dddddddddddddddddddddddddddddd));

This was overlooked when interducing the new builder-type call
detection in r189337. Also, some minor reorganization of a test.

llvm-svn: 189658
2013-08-30 08:29:25 +00:00
Daniel Jasper 2cf664fb86 clang-format: Don't indent builders relative to "return".
While this looks kind of nice, it wastes horizontal space and does not
seem to be common in the LLVM codebase.

Before:
  return llvm::StringSwitch<Reference::Kind>(name)
      .StartsWith(".eh_frame_hdr", ORDER_EH_FRAMEHDR)
      .StartsWith(".eh_frame", ORDER_EH_FRAME)
      .StartsWith(".init", ORDER_INIT)
      .StartsWith(".fini", ORDER_FINI)
      .StartsWith(".hash", ORDER_HASH)
      .Default(ORDER_TEXT);

After:
  return llvm::StringSwitch<Reference::Kind>(name)
             .StartsWith(".eh_frame_hdr", ORDER_EH_FRAMEHDR)
             .StartsWith(".eh_frame", ORDER_EH_FRAME)
             .StartsWith(".init", ORDER_INIT)
             .StartsWith(".fini", ORDER_FINI)
             .StartsWith(".hash", ORDER_HASH)
             .Default(ORDER_TEXT);

llvm-svn: 189657
2013-08-30 07:27:13 +00:00
Daniel Jasper f8151e9bc1 clang-format: Fix corner case in builder-type calls.
Before:
  aaaaaaaaaaaaa->aaaaaaaaaaaaaaaaaaaaaaaa()->aaaaaaaaaaaaaae(
                                                 0)->aaaaaaaaaaaaaaa();

After:
  aaaaaaaaaaaaa->aaaaaaaaaaaaaaaaaaaaaaaa()
      ->aaaaaaaaaaaaaae(0)
      ->aaaaaaaaaaaaaaa();

llvm-svn: 189655
2013-08-30 07:12:40 +00:00
Alexander Kornienko d7b837e78d Better support for multiline string literals (including C++11 raw string literals).
Summary:
Calculate characters in the first and the last line correctly so that
we only break before the literal when needed.

Reviewers: djasper

Reviewed By: djasper

CC: cfe-commits, klimek

Differential Revision: http://llvm-reviews.chandlerc.com/D1544

llvm-svn: 189595
2013-08-29 17:32:57 +00:00
Samuel Benzaquen 68cd396f82 Fix tests to be more specific.
The environments can inject some declaration in every translation unit,
which can match very generic matchers, thus failing the tests.

Summary:
Fix tests to be more specific.
The environments can inject some declaration in every translation unit,
which can match very generic matchers, thus failing the tests.

Reviewers: aaron.ballman

CC: klimek, cfe-commits, revane

Differential Revision: http://llvm-reviews.chandlerc.com/D1541

llvm-svn: 189587
2013-08-29 15:39:26 +00:00
Manuel Klimek 31c85921b2 Fixes various problems with accounting for tabs in the original code.
We now count the original token's column directly when lexing the
tokens, where we already have all knowledge about where lines start.

Before this patch, formatting:
 void f() {
 \tg();
 \th();
 }
would incorrectly count the \t's as 1 character if only the line
containing h() was reformatted, and thus indent h() at offset 1.

llvm-svn: 189585
2013-08-29 15:21:40 +00:00