Commit Graph

914 Commits

Author SHA1 Message Date
Dmitri Gribenko 1e50cbf366 Comment parsing: fix a bug where a line with whitespace between two paragraphs
would cause us to concatenate these paragraphs into a single one.

The no-op whitespace churn in test/Index test happened because these tests
don't use the correct approach for testing and are more strict than required
for they are testing.

llvm-svn: 189126
2013-08-23 18:03:40 +00:00
Daniel Jasper 0649d36172 clang-format: Fix indentation relative to unary expressions.
This should be done, only if we are still in the unary expression's
scope.

Before:
  bool aaaa = !aaaaaaaa(  // break
                   aaaaaaaaaaa);
  *aaaaaa = aaaaaaa( // break
       aaaaaaaaaaaaaaaa);

After:
  bool aaaa = !aaaaaaaa(  // break
                   aaaaaaaaaaa); // <- (unchanged)
  *aaaaaa = aaaaaaa( // break
      aaaaaaaaaaaaaaaa); // <- (no longer indented relative to "*")

llvm-svn: 189108
2013-08-23 15:14:03 +00:00
Daniel Jasper f438cb7619 clang-format: Fix corner case for string splitting ..
.. in conjunction with Style.AlwaysBreakBeforeMultilineStrings. Also,
simplify the implementation by handling newly split strings and already
split strings by the same code.

llvm-svn: 189102
2013-08-23 11:57:34 +00:00
Daniel Jasper f93551c8b1 clang-format: Handle trailing commas in column layout of braced list.
Before, this was causing errors.

Also exit early in breakProtrudingToken() (before the expensive call to
SourceManager::getSpellingColumnNumber()). This makes formatting huge
(100k+-item) braced lists possible.

llvm-svn: 189094
2013-08-23 10:05:49 +00:00
Jordan Rose a1e4b12223 Fix dependencies now that the ARC migrator depends on the static analyzer.
Thanks for pointing this out, Stephen. I think this is right now -- I
attempted to try all four valid combinations with both the autoconf and
CMake builds.

See also LLVM changes to the configure script.

llvm-svn: 189027
2013-08-22 15:50:02 +00:00
Daniel Jasper 8de9ed05b7 clang-format: Add column layout formatting for braced lists
With this patch, braced lists (with more than 3 elements are formatted in a
column layout if possible). E.g.:

  static const uint16_t CallerSavedRegs64Bit[] = {
    X86::RAX, X86::RDX, X86::RCX, X86::RSI, X86::RDI,
    X86::R8,  X86::R9,  X86::R10, X86::R11, 0
  };

Required other changes:
- FormatTokens can now have a special role that contains extra data and can do
  special formattings. A comma separated list is currently the only
  implementation.
- Move penalty calculation entirely into ContinuationIndenter (there was a last
  piece still in UnwrappedLineFormatter).

Review: http://llvm-reviews.chandlerc.com/D1457
llvm-svn: 189018
2013-08-22 15:00:41 +00:00
Daniel Jasper f110e201e4 clang-format: Indent relative to unary operators.
Before:
  if (!aaaaaaaaaa(  // break
          aaaaa)) {
  }

After:
  if (!aaaaaaaaaa(  // break
           aaaaa)) {
  }

Also cleaned up formatting using clang-format.

llvm-svn: 188891
2013-08-21 08:39:01 +00:00
Edwin Vane d7e2278f6c Adding Replacement serialization support
Adding a new data structure for storing the Replacements generated for a single
translation unit. Structure contains a vector of Replacements as well a field
indicating the main source file of the translation unit. An optional 'Context'
field allows for tools to provide any information they want about the context
the Replacements were generated in. This context is printed, for example, when
detecting conflicts during Replacement deduplication.

YAML serialization for this data structure is implemented in this patch. Tests
are included.

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

llvm-svn: 188818
2013-08-20 19:07:21 +00:00
Daniel Jasper 2b41a82e61 clang-format: Format enum struct/class like enum.
Patch by Joe Hermaszewski. Thank you!

llvm-svn: 188794
2013-08-20 12:42:50 +00:00
Daniel Jasper b55acad91c clang-format: Additional options for spaces around parentheses.
This patch adds four new options to control:
- Spaces after control keyworks (if(..) vs if (..))
- Spaces in empty parentheses (f( ) vs f())
- Spaces in c-style casts (( int )1.0 vs (int)1.0)
- Spaces in other parentheses (f(a) vs f( a ))

Patch by Joe Hermaszewski. Thank you for working on this!

llvm-svn: 188793
2013-08-20 12:36:34 +00:00
Daniel Jasper 5364306e12 clang-format: Fix return type line break decision.
This accidentally introduced by r186077, as function names were not
correctly recognized in templated declarations.

Before:
  template <class TemplateIt>
  SomeReturnType
  SomeFunction(TemplateIt begin, TemplateIt end, TemplateIt* stop) {}

After:
  template <class TemplateIt>
  SomeReturnType SomeFunction(TemplateIt begin, TemplateIt end,
                              TemplateIt* stop) {}

llvm-svn: 188665
2013-08-19 10:16:18 +00:00
Edwin Vane c514848d1b Have Range::overlapsWith use positive logic
Improved test to catch missing case.

llvm-svn: 188304
2013-08-13 18:11:16 +00:00
Edwin Vane 349e1c18eb Adding a vector version of tooling::applyAllReplacements
One day soon, tooling::Replacements will be changed from being implemented as
an std::set to being implemented as an std::vector. Until then, some new code
using vectors of Replacements would enjoy having a version of
applyAllReplacements that takes a vector.

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

llvm-svn: 188295
2013-08-13 17:38:19 +00:00
Edwin Vane f59b1a9211 Fixing a conflict detection bug in tooling::deduplicate
If a Replacment is contained within the conflict range being built, the
conflict range would be erroneously shortened. Now fixed. Tests updated to
catch this case.

llvm-svn: 188287
2013-08-13 16:26:44 +00:00
Samuel Benzaquen 0239b69167 Refactor "MatcherList" into "VariantMatcher" and abstract the notion of a list of matchers for the polymorphic case.
Summary:
Refactor "MatcherList" into "VariantMatcher" and abstract the notion of a list of matchers for the polymorphic case.
This work is to support future changes needed for eachOf/allOf/anyOf matchers. We will add a new type on VariantMatcher.

Reviewers: klimek

CC: cfe-commits, revane

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

llvm-svn: 188272
2013-08-13 14:54:51 +00:00
Daniel Jasper cdaffa45d4 clang-format: Add option for the offset of constructor initializers.
Some coding styles use a different indent for constructor initializers.

Patch by Klemens Baum. Thank you.
Review: http://llvm-reviews.chandlerc.com/D1360

Post review changes: Changed data type to unsigned as a negative indent
width does not make sense and added test for configuration parsing.

llvm-svn: 188260
2013-08-13 10:58:30 +00:00
Daniel Jasper 29a98cfca0 clang-format: Improve boolean expression formatting in macros.
Before:
  #define IF(a, b, c) if (a&&(b == c))

After:
  #define IF(a, b, c) if (a && (b == c))

llvm-svn: 188256
2013-08-13 09:09:09 +00:00
Daniel Jasper 70dc91aaf1 clang-format: Activate WebKit-style tests for MS compilers.
They were accidentally placed in the #if.

llvm-svn: 188255
2013-08-13 08:29:26 +00:00
Daniel Jasper 301d017139 clang-format: Slightly adapt line break penalties.
Before:
  aaaaaaaaaaaaaaaaaaaaaaaa(aaaaaaaaaaaaa(aaaaaaaaaaaaaaaaaaaaaaaaa)
                               ->aaaaaaaaa());
After:
  aaaaaaaaaaaaaaaaaaaaaaaa(
      aaaaaaaaaaaaa(aaaaaaaaaaaaaaaaaaaaaaaaa)->aaaaaaaaa());

llvm-svn: 188253
2013-08-13 06:50:04 +00:00
Kaelyn Uhrain 2c351bbc25 Add hooks to ExternalSemaSource for after-the-fact diagnosis of
incomplete types, courtesy of Luke Zarko.

llvm-svn: 188212
2013-08-12 22:11:14 +00:00
Kaelyn Uhrain 4ebf57672d Forgot to add unittests/Sema/ before committing r188196 :(
llvm-svn: 188197
2013-08-12 19:57:06 +00:00
Kaelyn Uhrain f0aabdadc6 Add hooks for typo correction to ExternalSemaSource, courtesy of Luke Zarko.
llvm-svn: 188196
2013-08-12 19:54:38 +00:00
Daniel Jasper 467ddb161c clang-format: Improve stream-formatting.
Before:
  CHECK(controller->WriteProto(FLAGS_row_key, FLAGS_proto)) << "\""
                                                            << FLAGS_proto
                                                            << "\"";

After:
  SemaRef.Diag(Loc, diag::note_for_range_begin_end)
      << BEF << IsTemplate << Description << E->getType();

llvm-svn: 188175
2013-08-12 12:58:05 +00:00
Daniel Jasper 5903685a28 clang-format: Correctly format alias declarations.
Before:
  template <class CallbackClass>
  using MyCallback = void(CallbackClass::*)(SomeObject * Data);");

After:
  template <class CallbackClass>
  using MyCallback = void (CallbackClass::*)(SomeObject *Data);");

Also fix three wrong indentations.

llvm-svn: 188172
2013-08-12 12:16:34 +00:00
Manuel Klimek d57355031c This change fixes the formatting of statements such as catch (E& e).
Previously these were formatting as catch (E & e) because the inner parenthesis
was being marked as an expression.

Patch by Thomas Gibson-Robinson.

llvm-svn: 188153
2013-08-12 03:51:17 +00:00
James Dennett ddd36fff49 Expose LambdaIntroducer::DefaultLoc in the AST's LambdaExpr.
Summary:
Source-centric tools need access to the location of a C++11
lambda expression's capture-default ('&' or '=') when it's present.
It's possible for them to find it by re-lexing and re-implementing
rules that Clang's parser has already applied, but the cost of storing
the SourceLocation and making it available to them is 32 bits per
LambdaExpr (a small delta, proportionally), and the simplification in
client code is significant.

Reviewers: rsmith

Reviewed By: rsmith

CC: cfe-commits, klimek, revane

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

llvm-svn: 188121
2013-08-09 23:08:25 +00:00
Edwin Vane 938f68816a Introduce Replacement deduplication and conflict detection function
Summary:
This patch adds tooling::deduplicate() which removes duplicates from and
looks for conflicts in a vector of Replacements.

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

llvm-svn: 187979
2013-08-08 13:31:14 +00:00
Arnold Schwaighofer a8177a02ca Revert r187935 "Support for double width characters."
It broke a public build bot.

llvm-svn: 187957
2013-08-08 02:19:56 +00:00
Alexander Kornienko ca3e6311a1 Support for double width characters.
Summary: Only works for UTF-8-encoded files.

Reviewers: djasper

Reviewed By: djasper

CC: cfe-commits, klimek

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

llvm-svn: 187935
2013-08-07 23:29:01 +00:00
Manuel Klimek a027f306a6 Fixes a couple of bugs with the Allman brace breaking.
In particular, left braces after an enum declaration now occur on their
own line.  Further, when short ifs/whiles are allowed these no longer
cause the left brace to be on the same line as the if/while when a
brace is included.

Patch by Thomas Gibson-Robinson.

llvm-svn: 187901
2013-08-07 19:20:45 +00:00
Daniel Jasper 9613c81fd2 clang-format: Fix corner case in OpenMP pragma formatting.
Before:
  #pragma omp reduction( | : var)
After:
  #pragma omp reduction(| : var)

llvm-svn: 187892
2013-08-07 16:29:23 +00:00
Daniel Jasper d6877f0561 clang-format: Improve formatting of builder-type calls.
This removes a formatting choice that was added at one point, but is
not generally liked by users. Specifically, in builder-type calls, do
(easily) break if the object before the ./-> is either a field or a
parameter-less function call. I.e., don't break after "aa.aa.aa" or
"aa.aa.aa()". In general, these sequences in builder-type calls are
seen as a single entity and thus breaking them up is a bad idea.

llvm-svn: 187865
2013-08-07 05:34:02 +00:00
Manuel Klimek d3ed59ae15 Implement Allman style.
Patch by Frank Miller.

llvm-svn: 187678
2013-08-02 21:31:59 +00:00
Manuel Klimek 1863e505ce Fix crash when encountering alias templates in isDerivedFrom matches.
- pull out function to drill to the CXXRecordDecl from the type,
  to allow recursive resolution
- make the analysis more robust by rather skipping values we don't
  understand

llvm-svn: 187676
2013-08-02 21:24:09 +00:00
Daniel Jasper 3dcd7eca7a clang-format: Fix string breaking after "<<".
Before, clang-format would not break overly long string literals
following a "<<" with FormatStyle::AlwaysBreakBeforeMultilineStrings
being set.

llvm-svn: 187650
2013-08-02 11:01:15 +00:00
Daniel Jasper 7cdc78b39b clang-format: Operator precendence in ObjC method exprs.
Patch (mostly) by Adam Strzelecki. Thanks!

Before:
  [self aaaaaa:bbbbbbbbbbbbb
      aaaaaaaaaa:bbbbbbbbbbbbbbbbb
           aaaaa:bbbbbbbbbbb +
      bbbbbbbbbbbb aaaa:bbb];

After:
  [self aaaaaa:bbbbbbbbbbbbb
      aaaaaaaaaa:bbbbbbbbbbbbbbbbb
           aaaaa:bbbbbbbbbbb + bbbbbbbbbbbb
            aaaa:bbb];

This fixes llvm.org/PR16150.

llvm-svn: 187631
2013-08-01 23:13:03 +00:00
Daniel Jasper b1ae734ffc clang-format: Don't break empty 2nd operand of ternary expr.
Before:
  some_quite_long_variable_name_ptr
      ?
      : argv[9] ? ptr : argv[8] ? : argv[7] ? ptr : argv[6];
After:
  some_quite_long_variable_name_ptr
      ?: argv[9] ? ptr : argv[8] ?: argv[7] ? ptr : argv[6];

Patch by Adam Strzelecki, thank you!!

This fixed llvm.org/PR16758.

llvm-svn: 187622
2013-08-01 22:05:00 +00:00
Rafael Espindola f8f91b8976 Use llvm::sys::fs::UniqueID for windows and unix.
This unifies the unix and windows versions of FileManager::UniqueDirContainer
and FileManager::UniqueFileContainer by using UniqueID.

We cannot just replace "struct stat" with llvm::sys::fs::file_status, since we
want to be able to construct fake ones, and file_status has different members
on unix and windows.

What the patch does is:

* Record only the information that clang is actually using.
* Use llvm::sys::fs::status instead of stat and fstat.
* Use llvm::sys::fs::UniqueID
* Delete the old windows versions of UniqueDirContainer and
UniqueFileContainer since the "unix" one now works on windows too.

llvm-svn: 187619
2013-08-01 21:42:11 +00:00
Daniel Jasper 8b1c63543b Teach clang-format to understand static_asserts better.
Before:
  template <bool B, bool C>
  class A {
    static_assert(B &&C, "Something is wrong");
  };

After:
  template <bool B, bool C>
  class A {
    static_assert(B && C, "Something is wrong");
  };

(Note the spacing around '&&'). Also change the identifier table to always
understand all C++11 keywords (which seems like the right thing to do).

llvm-svn: 187589
2013-08-01 17:58:23 +00:00
Daniel Jasper 9688ff197e clang-format: Improve line breaks in @property.
Before:
  @property(nonatomic, assign,
            readonly) NSString *looooooooooooooooooooooooooooongName;

After:
  @property(nonatomic, assign, readonly)
      NSString *looooooooooooooooooooooooooooongName;

llvm-svn: 187577
2013-08-01 13:46:58 +00:00
Daniel Jasper 552f4a7e27 clang-format: Make alignment of trailing comments optional ..
.. in order to support WebKit style properly.

llvm-svn: 187549
2013-07-31 23:55:15 +00:00
Daniel Jasper 65ee347285 clang-format: Add more options to namespace indentation.
With this patch, clang-format can be configured to:
* not indent in namespace at all (former behavior).
* indent in namespace as in other blocks.
* indent only in inner namespaces (as required by WebKit style).

Also fix alignment of access specifiers in WebKit style.

Patch started by Marek Kurdej. Thank you!

llvm-svn: 187540
2013-07-31 23:16:02 +00:00
Daniel Jasper 62c0ac0acf clang-format: Improve detection of templates.
Before:
  template <typename... Types>
        typename enable_if < 0<sizeof...(Types)>::type Foo() {}
After:
  template <typename... Types>
  typename enable_if<0 < sizeof...(Types)>::type Foo() {}

llvm-svn: 187458
2013-07-30 22:37:19 +00:00
Rafael Espindola ee30546c00 Fix handling of "clang c:foo"
On windows, c:foo is a valid file path, but stat fails on just "c:". This
causes a problem for clang since its file manager wants to cache data about
the parent directory.

There are refactorings to be done in here, but this gives clang the correct
behavior and testing first.

Patch by Yunzhong Gao!

llvm-svn: 187359
2013-07-29 15:47:24 +00:00
Daniel Jasper 91f1c8ca27 Add matcher for float literals.
Patch by Chris Gray! Thanks!

llvm-svn: 187232
2013-07-26 18:52:58 +00:00
Daniel Jasper e33d4afa47 clang-format: Add two new style options to support WebKit style.
New options:
* Break before the commas of constructor initializers and align
  the commas with the colon.
* Break before binary operators

Additionally, for styles without column limit, don't just accept
linebreaks done by the user, but instead remove 'invalid' (according
to the current style) linebreaks and add 'required' ones.

llvm-svn: 187210
2013-07-26 16:56:36 +00:00
Daniel Jasper 516d7971b3 clang-format: Fix switch/case interaction with macros.
Before:
  #define OPERATION_CASE(name) \
    case OP_name:              \
    return operations::Operation##name

  switch (OpCode) {
      CASE(Add);
      CASE(Subtract);
    default:
      return operations::Unknown;
  }

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

  switch (OpCode) {
    CASE(Add);
    CASE(Subtract);
    default:
      return operations::Unknown;
  }

llvm-svn: 187118
2013-07-25 11:31:57 +00:00
Samuel Benzaquen 7f8a5b140a Add support for Adaptative matchers on the dynamic registry.
Summary:
Add support for Adaptative matchers on the dynamic registry.
Each adaptative matcher is created with a function template. We instantiate the function N times, one for each possible From type and apply the techniques used on argument overloaded and polymorphic matchers to add them to the registry.

Reviewers: klimek

CC: cfe-commits, revane

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

llvm-svn: 187044
2013-07-24 14:48:01 +00:00
Daniel Jasper ffefb3d1e0 clang-format: Initial (incomplete) support for the WebKit coding style.
This is far from implementing all the rules given by
http://www.webkit.org/coding/coding-style.html

The important new feature is the support for styles that don't have a
column limit. For such styles, clang-format will (at the moment) simply
respect the input's formatting decisions within statements.

llvm-svn: 187033
2013-07-24 13:10:59 +00:00
Samuel Benzaquen e0b2c8e478 Add support for overloaded matchers. ie different matcher function signatures with the same name.
Summary:
Add support for overloaded matchers.
This composes with other features, like supporting polymorphic matchers.

Reviewers: klimek

CC: cfe-commits, revane

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

llvm-svn: 186836
2013-07-22 16:13:57 +00:00