[clang] 9e9e096 - [clang-format] Fix dropped 'else'.

2023-04-21 Thread Manuel Klimek via cfe-commits

Author: Manuel Klimek
Date: 2023-04-21T11:59:45Z
New Revision: 9e9e096ae95b9a41bf855cda01963a65313e9560

URL: 
https://github.com/llvm/llvm-project/commit/9e9e096ae95b9a41bf855cda01963a65313e9560
DIFF: 
https://github.com/llvm/llvm-project/commit/9e9e096ae95b9a41bf855cda01963a65313e9560.diff

LOG: [clang-format] Fix dropped 'else'.

'else' was dropped accidentally in 398cddf6acec.

Patch by Jared Grubb.

Differential revision: https://reviews.llvm.org/D146310

Added: 


Modified: 
clang/lib/Format/UnwrappedLineFormatter.cpp

Removed: 




diff  --git a/clang/lib/Format/UnwrappedLineFormatter.cpp 
b/clang/lib/Format/UnwrappedLineFormatter.cpp
index b545fa02cefb..ee0de2c8e20d 100644
--- a/clang/lib/Format/UnwrappedLineFormatter.cpp
+++ b/clang/lib/Format/UnwrappedLineFormatter.cpp
@@ -511,10 +511,9 @@ class LineJoiner {
 ShouldMerge = !Style.BraceWrapping.AfterClass ||
   (NextLine.First->is(tok::r_brace) &&
!Style.BraceWrapping.SplitEmptyRecord);
-  }
-  if (TheLine->InPPDirective ||
-  !TheLine->First->isOneOf(tok::kw_class, tok::kw_enum,
-   tok::kw_struct)) {
+  } else if (TheLine->InPPDirective ||
+ !TheLine->First->isOneOf(tok::kw_class, tok::kw_enum,
+  tok::kw_struct)) {
 // Try to merge a block with left brace unwrapped that wasn't yet
 // covered.
 ShouldMerge = !Style.BraceWrapping.AfterFunction ||



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D144170: [clang-format] Add simple macro replacements in formatting.

2023-03-23 Thread Manuel Klimek via cfe-commits
I am so sorry, thanks for sending out the patch already and fixing the
layout!

On Thu, Mar 23, 2023 at 10:08 AM MyDeveloperDay via Phabricator <
revi...@reviews.llvm.org> wrote:

> MyDeveloperDay added a comment.
>
> I know this is like "telling my grandmother to suck eggs" but  @klimek the
> change here to Format.h means you need to regenerate
> ClangFormatStyleOptions.rst via docs/tools/dump_format_style.py
>
> Impacting the next change to generate - D125171: Add a new clang-format
> option AlwaysBreakBeforeFunctionParameters <
> https://reviews.llvm.org/D125171>
>
>
> Repository:
>   rG LLVM Github Monorepo
>
> CHANGES SINCE LAST ACTION
>   https://reviews.llvm.org/D144170/new/
>
> https://reviews.llvm.org/D144170
>
>
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] f8d10d5 - [clang-format][NFC] Refactor formatting unit tests.

2023-03-01 Thread Manuel Klimek via cfe-commits

Author: Manuel Klimek
Date: 2023-03-01T12:36:07Z
New Revision: f8d10d5ac9ab4b45b388c74357fc82fb96562e66

URL: 
https://github.com/llvm/llvm-project/commit/f8d10d5ac9ab4b45b388c74357fc82fb96562e66
DIFF: 
https://github.com/llvm/llvm-project/commit/f8d10d5ac9ab4b45b388c74357fc82fb96562e66.diff

LOG: [clang-format][NFC] Refactor formatting unit tests.

Pull out common base class for formatting unit tests, removing duplicate
code that accumulated over the years.

Pull out macro expansion test into its own test file.

Added: 
clang/unittests/Format/FormatReplacementTest.cpp
clang/unittests/Format/FormatTestBase.h
clang/unittests/Format/FormatTestMacroExpansion.cpp

Modified: 
clang/unittests/Format/BracesInserterTest.cpp
clang/unittests/Format/BracesRemoverTest.cpp
clang/unittests/Format/CMakeLists.txt
clang/unittests/Format/FormatTest.cpp
clang/unittests/Format/FormatTestComments.cpp
clang/unittests/Format/FormatTestObjC.cpp
clang/unittests/Format/FormatTestTextProto.cpp
clang/unittests/Format/FormatTestUtils.h
clang/unittests/Format/IntegerLiteralSeparatorTest.cpp
clang/unittests/Format/QualifierFixerTest.cpp

Removed: 




diff  --git a/clang/unittests/Format/BracesInserterTest.cpp 
b/clang/unittests/Format/BracesInserterTest.cpp
index c685907451835..e0c447d671f45 100644
--- a/clang/unittests/Format/BracesInserterTest.cpp
+++ b/clang/unittests/Format/BracesInserterTest.cpp
@@ -6,64 +6,16 @@
 //
 
//===--===//
 
-#include "clang/Format/Format.h"
-
-#include "../Tooling/ReplacementTest.h"
-#include "FormatTestUtils.h"
+#include "FormatTestBase.h"
 
 #define DEBUG_TYPE "braces-inserter-test"
 
 namespace clang {
 namespace format {
+namespace test {
 namespace {
 
-class BracesInserterTest : public ::testing::Test {
-protected:
-  std::string format(llvm::StringRef Code, const FormatStyle ,
- const std::vector ) {
-LLVM_DEBUG(llvm::errs() << "---\n");
-LLVM_DEBUG(llvm::errs() << Code << "\n\n");
-auto NonEmptyRanges = Ranges;
-if (Ranges.empty())
-  NonEmptyRanges = {1, tooling::Range(0, Code.size())};
-FormattingAttemptStatus Status;
-tooling::Replacements Replaces =
-reformat(Style, Code, NonEmptyRanges, "", );
-EXPECT_EQ(true, Status.FormatComplete) << Code << "\n\n";
-ReplacementCount = Replaces.size();
-auto Result = applyAllReplacements(Code, Replaces);
-EXPECT_TRUE(static_cast(Result));
-LLVM_DEBUG(llvm::errs() << "\n" << *Result << "\n\n");
-return *Result;
-  }
-
-  void _verifyFormat(const char *File, int Line, llvm::StringRef Expected,
- llvm::StringRef Code,
- const FormatStyle  = getLLVMStyle(),
- const std::vector  = {}) {
-testing::ScopedTrace t(File, Line, ::testing::Message() << Code.str());
-EXPECT_EQ(Expected.str(), format(Expected, Style, Ranges))
-<< "Expected code is not stable";
-EXPECT_EQ(Expected.str(), format(Code, Style, Ranges));
-if (Style.Language == FormatStyle::LK_Cpp && Ranges.empty()) {
-  // Objective-C++ is a superset of C++, so everything checked for C++
-  // needs to be checked for Objective-C++ as well.
-  FormatStyle ObjCStyle = Style;
-  ObjCStyle.Language = FormatStyle::LK_ObjC;
-  EXPECT_EQ(Expected.str(), format(test::messUp(Code), ObjCStyle, Ranges));
-}
-  }
-
-  void _verifyFormat(const char *File, int Line, llvm::StringRef Code,
- const FormatStyle  = getLLVMStyle(),
- const std::vector  = {}) {
-_verifyFormat(File, Line, Code, Code, Style, Ranges);
-  }
-
-  int ReplacementCount;
-};
-
-#define verifyFormat(...) _verifyFormat(__FILE__, __LINE__, __VA_ARGS__)
+class BracesInserterTest : public FormatTestBase {};
 
 TEST_F(BracesInserterTest, InsertBraces) {
   FormatStyle Style = getLLVMStyle();
@@ -328,9 +280,10 @@ TEST_F(BracesInserterTest, InsertBracesRange) {
"  }",
Code, Style, {tooling::Range(10, 8)}); // line 2
 
-  verifyFormat(Code, Style, {tooling::Range(19, 11)}); // line 3
+  verifyFormat(Code, Code, Style, {tooling::Range(19, 11)}); // line 3
 }
 
 } // namespace
+} // namespace test
 } // namespace format
 } // namespace clang

diff  --git a/clang/unittests/Format/BracesRemoverTest.cpp 
b/clang/unittests/Format/BracesRemoverTest.cpp
index ba0b3eb53d155..5155eefb9e08c 100644
--- a/clang/unittests/Format/BracesRemoverTest.cpp
+++ b/clang/unittests/Format/BracesRemoverTest.cpp
@@ -6,66 +6,16 @@
 //
 
//===--===//
 
-#include "clang/Format/Format.h"
-
-#include "../Tooling/ReplacementTest.h"
-#include "FormatTestUtils.h"
+#include "FormatTestBase.h"
 
 #define DEBUG_TYPE "braces-remover-test"
 
 namespace clang {
 namespace 

[clang] 398cddf - [clang-format] Fix assertion that doesn't hold under fuzzing.

2023-02-27 Thread Manuel Klimek via cfe-commits

Author: Manuel Klimek
Date: 2023-02-27T10:50:42Z
New Revision: 398cddf6acecfb12b5997c2d639ee3cf31b787ad

URL: 
https://github.com/llvm/llvm-project/commit/398cddf6acecfb12b5997c2d639ee3cf31b787ad
DIFF: 
https://github.com/llvm/llvm-project/commit/398cddf6acecfb12b5997c2d639ee3cf31b787ad.diff

LOG: [clang-format] Fix assertion that doesn't hold under fuzzing.

Added: 


Modified: 
clang/lib/Format/UnwrappedLineFormatter.cpp

Removed: 




diff  --git a/clang/lib/Format/UnwrappedLineFormatter.cpp 
b/clang/lib/Format/UnwrappedLineFormatter.cpp
index b0314d6cfa75f..c789f2907dac9 100644
--- a/clang/lib/Format/UnwrappedLineFormatter.cpp
+++ b/clang/lib/Format/UnwrappedLineFormatter.cpp
@@ -511,12 +511,11 @@ class LineJoiner {
 ShouldMerge = !Style.BraceWrapping.AfterClass ||
   (NextLine.First->is(tok::r_brace) &&
!Style.BraceWrapping.SplitEmptyRecord);
-  } else {
+  } if(TheLine->InPPDirective ||
+   !TheLine->First->isOneOf(tok::kw_class, tok::kw_enum,
+tok::kw_struct)) {
 // Try to merge a block with left brace unwrapped that wasn't yet
 // covered.
-assert(TheLine->InPPDirective ||
-   !TheLine->First->isOneOf(tok::kw_class, tok::kw_enum,
-tok::kw_struct));
 ShouldMerge = !Style.BraceWrapping.AfterFunction ||
   (NextLine.First->is(tok::r_brace) &&
!Style.BraceWrapping.SplitEmptyFunction);



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] f600a5a - [clang-format] Add macro replacement to fuzzing.

2023-02-27 Thread Manuel Klimek via cfe-commits

Author: Manuel Klimek
Date: 2023-02-27T10:40:22Z
New Revision: f600a5aec52c0aa56e4e47c992b6f10e5cd7b7af

URL: 
https://github.com/llvm/llvm-project/commit/f600a5aec52c0aa56e4e47c992b6f10e5cd7b7af
DIFF: 
https://github.com/llvm/llvm-project/commit/f600a5aec52c0aa56e4e47c992b6f10e5cd7b7af.diff

LOG: [clang-format] Add macro replacement to fuzzing.

Added: 


Modified: 
clang/tools/clang-format/fuzzer/ClangFormatFuzzer.cpp

Removed: 




diff  --git a/clang/tools/clang-format/fuzzer/ClangFormatFuzzer.cpp 
b/clang/tools/clang-format/fuzzer/ClangFormatFuzzer.cpp
index f90cdf5ab60db..a8a783ba1a53e 100644
--- a/clang/tools/clang-format/fuzzer/ClangFormatFuzzer.cpp
+++ b/clang/tools/clang-format/fuzzer/ClangFormatFuzzer.cpp
@@ -19,6 +19,9 @@ extern "C" int LLVMFuzzerTestOneInput(uint8_t *data, size_t 
size) {
   std::string s((const char *)data, size);
   auto Style = getGoogleStyle(clang::format::FormatStyle::LK_Cpp);
   Style.ColumnLimit = 60;
+  Style.Macros.push_back("ASSIGN_OR_RETURN(a, b)=a = (b)");
+  Style.Macros.push_back("ASSIGN_OR_RETURN(a, b, c)=a = (b); if (x) return c");
+  Style.Macros.push_back("MOCK_METHOD(r, n, a, s)=r n a s");
   auto Replaces = reformat(Style, s, clang::tooling::Range(0, s.size()));
   auto Result = applyAllReplacements(s, Replaces);
 



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 0140283 - [clang-format] Add simple macro replacements in formatting.

2023-02-24 Thread Manuel Klimek via cfe-commits

Author: Manuel Klimek
Date: 2023-02-24T15:44:24Z
New Revision: 01402831aaae76e9c61595f9aa81a506b0d926eb

URL: 
https://github.com/llvm/llvm-project/commit/01402831aaae76e9c61595f9aa81a506b0d926eb
DIFF: 
https://github.com/llvm/llvm-project/commit/01402831aaae76e9c61595f9aa81a506b0d926eb.diff

LOG: [clang-format] Add simple macro replacements in formatting.

Add configuration to specify macros.
Macros will be expanded, and the code will be parsed and annotated
in the expanded state. In a second step, the formatting decisions
in the annotated expanded code will be reconstructed onto the
original unexpanded macro call.

Eventually, this will allow to remove special-case code for
various macro options we accumulated over the years in favor of
one principled mechanism.

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

Added: 


Modified: 
clang/include/clang/Format/Format.h
clang/lib/Format/ContinuationIndenter.cpp
clang/lib/Format/Format.cpp
clang/lib/Format/FormatToken.h
clang/lib/Format/MacroExpander.cpp
clang/lib/Format/Macros.h
clang/lib/Format/TokenAnalyzer.cpp
clang/lib/Format/TokenAnalyzer.h
clang/lib/Format/TokenAnnotator.cpp
clang/lib/Format/TokenAnnotator.h
clang/lib/Format/UnwrappedLineFormatter.cpp
clang/lib/Format/UnwrappedLineParser.cpp
clang/lib/Format/UnwrappedLineParser.h
clang/lib/Format/WhitespaceManager.cpp
clang/unittests/Format/FormatTest.cpp
clang/unittests/Format/MacroCallReconstructorTest.cpp
clang/unittests/Format/MacroExpanderTest.cpp
clang/unittests/Format/TestLexer.h

Removed: 




diff  --git a/clang/include/clang/Format/Format.h 
b/clang/include/clang/Format/Format.h
index 0d57d7996525a..66904a6a11232 100644
--- a/clang/include/clang/Format/Format.h
+++ b/clang/include/clang/Format/Format.h
@@ -2745,6 +2745,39 @@ struct FormatStyle {
   /// \version 3.7
   std::string MacroBlockEnd;
 
+  /// A list of macros of the form \c = .
+  ///
+  /// Code will be parsed with macros expanded, in order to determine how to
+  /// interpret and format the macro arguments.
+  ///
+  /// For example, the code:
+  /// \code
+  ///   A(a*b);
+  /// \endcode
+  /// will usually be interpreted as a call to a function A, and the
+  /// multiplication expression will be formatted as `a * b`.
+  ///
+  /// If we specify the macro definition:
+  /// \code
+  ///   Macros:
+  ///   - A(x)=x
+  /// \endcode
+  /// the code will now be parsed as a declaration of the variable b of type 
a*,
+  /// and formatted as `a* b` (depending on pointer-binding rules).
+  ///
+  /// Features and restrictions:
+  /// *  Both function-like macros and object-like macros are supported.
+  /// *  Macro arguments must be used exactly once in the expansion.
+  /// *  No recursive expansion; macros referencing other macros will be
+  ///ignored.
+  /// *  Overloading by arity is supported: for example, given the macro
+  ///definitions A=x, A()=y, A(a)=a,
+  ///'A;' -> 'x;'
+  ///'A();' -> 'y;'
+  ///'A(z);' -> 'z;'
+  ///'A(a, b) will not be expanded.
+  std::vector Macros;
+
   /// The maximum number of consecutive empty lines to keep.
   /// \code
   ///MaxEmptyLinesToKeep: 1 vs. MaxEmptyLinesToKeep: 0
@@ -4306,7 +4339,8 @@ struct FormatStyle {
StatementAttributeLikeMacros == R.StatementAttributeLikeMacros &&
StatementMacros == R.StatementMacros && TabWidth == R.TabWidth &&
TypenameMacros == R.TypenameMacros && UseTab == R.UseTab &&
-   WhitespaceSensitiveMacros == R.WhitespaceSensitiveMacros;
+   WhitespaceSensitiveMacros == R.WhitespaceSensitiveMacros &&
+   Macros == R.Macros;
   }
 
   std::optional GetLanguageStyle(LanguageKind Language) const;

diff  --git a/clang/lib/Format/ContinuationIndenter.cpp 
b/clang/lib/Format/ContinuationIndenter.cpp
index c7559874fd4c7..d2f309f3874ed 100644
--- a/clang/lib/Format/ContinuationIndenter.cpp
+++ b/clang/lib/Format/ContinuationIndenter.cpp
@@ -18,6 +18,7 @@
 #include "WhitespaceManager.h"
 #include "clang/Basic/OperatorPrecedence.h"
 #include "clang/Basic/SourceManager.h"
+#include "clang/Basic/TokenKinds.h"
 #include "clang/Format/Format.h"
 #include "llvm/ADT/StringSet.h"
 #include "llvm/Support/Debug.h"
@@ -739,9 +740,14 @@ void ContinuationIndenter::addTokenOnCurrentLine(LineState 
, bool DryRun,
   if (Previous.is(TT_TemplateString) && Previous.opensScope())
 CurrentState.NoLineBreak = true;
 
+  // Align following lines within parentheses / brackets if configured.
+  // Note: This doesn't apply to macro expansion lines, which are MACRO( , , )
+  // with args as children of the '(' and ',' tokens. It does not make sense to
+  // align the commas with the opening paren.
   if (Style.AlignAfterOpenBracket != FormatStyle::BAS_DontAlign &&
   !CurrentState.IsCSharpGenericTypeConstraint && 

[clang] 8c1f77a - [clang-format] Fix windows build.

2023-02-15 Thread Manuel Klimek via cfe-commits

Author: Manuel Klimek
Date: 2023-02-15T20:59:43Z
New Revision: 8c1f77af7fd14d5a611246aa16b9693d3ebcee22

URL: 
https://github.com/llvm/llvm-project/commit/8c1f77af7fd14d5a611246aa16b9693d3ebcee22
DIFF: 
https://github.com/llvm/llvm-project/commit/8c1f77af7fd14d5a611246aa16b9693d3ebcee22.diff

LOG: [clang-format] Fix windows build.

MSVC needs a return after llvm_unreachable.

Added: 


Modified: 
clang/lib/Format/FormatTokenSource.h

Removed: 




diff  --git a/clang/lib/Format/FormatTokenSource.h 
b/clang/lib/Format/FormatTokenSource.h
index 0be46287f6b74..d93efaf676087 100644
--- a/clang/lib/Format/FormatTokenSource.h
+++ b/clang/lib/Format/FormatTokenSource.h
@@ -18,6 +18,7 @@
 #include "FormatToken.h"
 #include "UnwrappedLineParser.h"
 #include "llvm/ADT/DenseMap.h"
+#include 
 
 #define DEBUG_TYPE "format-token-source"
 
@@ -237,6 +238,7 @@ class ScopedMacroState : public FormatTokenSource {
 
   FormatToken *insertTokens(ArrayRef Tokens) override {
 llvm_unreachable("Cannot insert tokens while parsing a macro.");
+return nullptr;
   }
 
 private:



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 1995d44 - [clang-format] Enable FormatTokenSource to insert tokens.

2023-02-15 Thread Manuel Klimek via cfe-commits

Author: Manuel Klimek
Date: 2023-02-15T12:39:24Z
New Revision: 1995d4424505cb5a1c3f0e5f851a660ec32d7af1

URL: 
https://github.com/llvm/llvm-project/commit/1995d4424505cb5a1c3f0e5f851a660ec32d7af1
DIFF: 
https://github.com/llvm/llvm-project/commit/1995d4424505cb5a1c3f0e5f851a660ec32d7af1.diff

LOG: [clang-format] Enable FormatTokenSource to insert tokens.

In preparation for configured macro replacements in formatting,
add the ability to insert tokens to FormatTokenSource, and implement
token insertion in IndexedTokenSource.

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

Added: 


Modified: 
clang/lib/Format/FormatTokenSource.h
clang/lib/Format/UnwrappedLineParser.h
clang/unittests/Format/FormatTokenSourceTest.cpp

Removed: 




diff  --git a/clang/lib/Format/FormatTokenSource.h 
b/clang/lib/Format/FormatTokenSource.h
index 0bef45a7ff980..8bf7e6932c895 100644
--- a/clang/lib/Format/FormatTokenSource.h
+++ b/clang/lib/Format/FormatTokenSource.h
@@ -1,4 +1,3 @@
-
 //===--- FormatTokenSource.h - Format C++ code --*- C++ 
-*-===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
@@ -8,7 +7,7 @@
 
//===--===//
 ///
 /// \file
-/// This file defines the \c TokenSource interface, which provides a token
+/// This file defines the \c FormatTokenSource interface, which provides a 
token
 /// stream as well as the ability to manipulate the token stream.
 ///
 
//===--===//
@@ -18,12 +17,17 @@
 
 #include "FormatToken.h"
 #include "UnwrappedLineParser.h"
+#include "llvm/ADT/DenseMap.h"
 
 #define DEBUG_TYPE "format-token-source"
 
 namespace clang {
 namespace format {
 
+// Navigate a token stream.
+//
+// Enables traversal of a token stream, resetting the position in a token
+// stream, as well as inserting new tokens.
 class FormatTokenSource {
 public:
   virtual ~FormatTokenSource() {}
@@ -33,6 +37,9 @@ class FormatTokenSource {
 
   // Returns the token preceding the token returned by the last call to
   // getNextToken() in the token stream, or nullptr if no such token exists.
+  //
+  // Must not be called directly at the position directly after insertTokens()
+  // is called.
   virtual FormatToken *getPreviousToken() = 0;
 
   // Returns the token that would be returned by the next call to
@@ -45,14 +52,31 @@ class FormatTokenSource {
   virtual bool isEOF() = 0;
 
   // Gets the current position in the token stream, to be used by 
setPosition().
+  //
+  // Note that the value of the position is not meaningful, and specifically
+  // should not be used to get relative token positions.
   virtual unsigned getPosition() = 0;
 
   // Resets the token stream to the state it was in when getPosition() returned
   // Position, and return the token at that position in the stream.
   virtual FormatToken *setPosition(unsigned Position) = 0;
+
+  // Insert the given tokens before the current position.
+  // Returns the first token in \c Tokens.
+  // The next returned token will be the second token in \c Tokens.
+  // Requires the last token in Tokens to be EOF; once the EOF token is 
reached,
+  // the next token will be the last token returned by getNextToken();
+  //
+  // For example, given the token sequence 'a1 a2':
+  // getNextToken() -> a1
+  // insertTokens('b1 b2') -> b1
+  // getNextToken() -> b2
+  // getNextToken() -> a1
+  // getNextToken() -> a2
+  virtual FormatToken *insertTokens(ArrayRef Tokens) = 0;
 };
 
-class LLVM_GSL_POINTER IndexedTokenSource : public FormatTokenSource {
+class IndexedTokenSource : public FormatTokenSource {
 public:
   IndexedTokenSource(ArrayRef Tokens)
   : Tokens(Tokens), Position(-1) {}
@@ -65,7 +89,7 @@ class LLVM_GSL_POINTER IndexedTokenSource : public 
FormatTokenSource {
   });
   return Tokens[Position];
 }
-++Position;
+Position = successor(Position);
 LLVM_DEBUG({
   llvm::dbgs() << "Next ";
   dbgToken(Position);
@@ -74,16 +98,17 @@ class LLVM_GSL_POINTER IndexedTokenSource : public 
FormatTokenSource {
   }
 
   FormatToken *getPreviousToken() override {
+assert(Position <= 0 || !Tokens[Position - 1]->is(tok::eof));
 return Position > 0 ? Tokens[Position - 1] : nullptr;
   }
 
   FormatToken *peekNextToken(bool SkipComment = false) override {
 if (isEOF())
   return Tokens[Position];
-int Next = Position + 1;
+int Next = successor(Position);
 if (SkipComment)
   while (Tokens[Next]->is(tok::comment))
-++Next;
+Next = successor(Next);
 LLVM_DEBUG({
   llvm::dbgs() << "Peeking ";
   dbgToken(Next);
@@ -107,9 +132,40 @@ class LLVM_GSL_POINTER IndexedTokenSource : public 
FormatTokenSource {
 return Tokens[Position];
   }
 
+  FormatToken *insertTokens(ArrayRef New) 

[clang] 04ed86f - [clang-format][NFC] Bring FormatTokenSource under test.

2023-01-31 Thread Manuel Klimek via cfe-commits

Author: Manuel Klimek
Date: 2023-01-31T16:06:46Z
New Revision: 04ed86ff1b7272faf8e62fa32da4acaa2d3c6add

URL: 
https://github.com/llvm/llvm-project/commit/04ed86ff1b7272faf8e62fa32da4acaa2d3c6add
DIFF: 
https://github.com/llvm/llvm-project/commit/04ed86ff1b7272faf8e62fa32da4acaa2d3c6add.diff

LOG: [clang-format][NFC] Bring FormatTokenSource under test.

Add tests for FormatTokenSource and harden it against edge cases.

Added: 
clang/unittests/Format/FormatTokenSourceTest.cpp

Modified: 
clang/lib/Format/FormatTokenSource.h
clang/unittests/Format/CMakeLists.txt

Removed: 




diff  --git a/clang/lib/Format/FormatTokenSource.h 
b/clang/lib/Format/FormatTokenSource.h
index e14f72b7d1f44..359e0e52878bb 100644
--- a/clang/lib/Format/FormatTokenSource.h
+++ b/clang/lib/Format/FormatTokenSource.h
@@ -77,7 +77,9 @@ class IndexedTokenSource : public FormatTokenSource {
 return Position > 0 ? Tokens[Position - 1] : nullptr;
   }
 
-  FormatToken *peekNextToken(bool SkipComment) override {
+  FormatToken *peekNextToken(bool SkipComment = false) override {
+if (isEOF())
+  return Tokens[Position];
 int Next = Position + 1;
 if (SkipComment)
   while (Tokens[Next]->is(tok::comment))
@@ -89,7 +91,9 @@ class IndexedTokenSource : public FormatTokenSource {
 return Tokens[Next];
   }
 
-  bool isEOF() override { return Tokens[Position]->is(tok::eof); }
+  bool isEOF() override {
+return Position == -1 ? false : Tokens[Position]->is(tok::eof);
+  }
 
   unsigned getPosition() override {
 LLVM_DEBUG(llvm::dbgs() << "Getting Position: " << Position << "\n");

diff  --git a/clang/unittests/Format/CMakeLists.txt 
b/clang/unittests/Format/CMakeLists.txt
index 09457c105ca30..1db1f602415bb 100644
--- a/clang/unittests/Format/CMakeLists.txt
+++ b/clang/unittests/Format/CMakeLists.txt
@@ -21,6 +21,7 @@ add_clang_unittest(FormatTests
   FormatTestTableGen.cpp
   FormatTestTextProto.cpp
   FormatTestVerilog.cpp
+  FormatTokenSourceTest.cpp
   IntegerLiteralSeparatorTest.cpp
   MacroCallReconstructorTest.cpp
   MacroExpanderTest.cpp

diff  --git a/clang/unittests/Format/FormatTokenSourceTest.cpp 
b/clang/unittests/Format/FormatTokenSourceTest.cpp
new file mode 100644
index 0..3c2f317adf5c3
--- /dev/null
+++ b/clang/unittests/Format/FormatTokenSourceTest.cpp
@@ -0,0 +1,75 @@
+//===- unittest/Format/FormatTokenSourceTest.cpp 
--===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "../../lib/Format/FormatTokenSource.h"
+#include "TestLexer.h"
+#include "clang/Basic/TokenKinds.h"
+#include "gtest/gtest.h"
+
+namespace clang {
+namespace format {
+namespace {
+
+class IndexedTokenSourceTest : public ::testing::Test {
+protected:
+  TokenList lex(llvm::StringRef Code,
+const FormatStyle  = getLLVMStyle()) {
+return TestLexer(Allocator, Buffers, Style).lex(Code);
+  }
+  llvm::SpecificBumpPtrAllocator Allocator;
+  std::vector> Buffers;
+};
+
+#define EXPECT_TOKEN_KIND(FormatTok, Kind) 
\
+  do { 
\
+FormatToken *Tok = FormatTok;  
\
+EXPECT_EQ((Tok)->Tok.getKind(), Kind) << *(Tok);   
\
+  } while (false);
+
+TEST_F(IndexedTokenSourceTest, EmptyInput) {
+  IndexedTokenSource Source(lex(""));
+  EXPECT_FALSE(Source.isEOF());
+  EXPECT_TOKEN_KIND(Source.getNextToken(), tok::eof);
+  EXPECT_TRUE(Source.isEOF());
+  EXPECT_TOKEN_KIND(Source.getNextToken(), tok::eof);
+  EXPECT_TRUE(Source.isEOF());
+  EXPECT_TOKEN_KIND(Source.peekNextToken(/*SkipComment=*/false), tok::eof);
+  EXPECT_TOKEN_KIND(Source.peekNextToken(/*SkipComment=*/true), tok::eof);
+  EXPECT_EQ(Source.getPreviousToken(), nullptr);
+  EXPECT_TRUE(Source.isEOF());
+}
+
+TEST_F(IndexedTokenSourceTest, NavigateTokenStream) {
+  IndexedTokenSource Source(lex("int a;"));
+  EXPECT_TOKEN_KIND(Source.peekNextToken(), tok::kw_int);
+  EXPECT_TOKEN_KIND(Source.getNextToken(), tok::kw_int);
+  EXPECT_EQ(Source.getPreviousToken(), nullptr);
+  EXPECT_TOKEN_KIND(Source.peekNextToken(), tok::identifier);
+  EXPECT_TOKEN_KIND(Source.getNextToken(), tok::identifier);
+  EXPECT_TOKEN_KIND(Source.getPreviousToken(), tok::kw_int);
+  EXPECT_TOKEN_KIND(Source.peekNextToken(), tok::semi);
+  EXPECT_TOKEN_KIND(Source.getNextToken(), tok::semi);
+  EXPECT_TOKEN_KIND(Source.getPreviousToken(), tok::identifier);
+  EXPECT_TOKEN_KIND(Source.peekNextToken(), tok::eof);
+  EXPECT_TOKEN_KIND(Source.getNextToken(), tok::eof);
+  EXPECT_TOKEN_KIND(Source.getPreviousToken(), tok::semi);

[clang] be31f2c - [clang-format][NFC] Move IndexedTokenSource to FormatTokenSource header.

2023-01-31 Thread Manuel Klimek via cfe-commits

Author: Manuel Klimek
Date: 2023-01-31T15:06:20Z
New Revision: be31f2c11d47d3eca28d922a06de181d6e23b355

URL: 
https://github.com/llvm/llvm-project/commit/be31f2c11d47d3eca28d922a06de181d6e23b355
DIFF: 
https://github.com/llvm/llvm-project/commit/be31f2c11d47d3eca28d922a06de181d6e23b355.diff

LOG: [clang-format][NFC] Move IndexedTokenSource to FormatTokenSource header.

Finish refactoring of the token sources towards a single location.

Added: 


Modified: 
clang/lib/Format/FormatTokenSource.h
clang/lib/Format/UnwrappedLineParser.cpp

Removed: 




diff  --git a/clang/lib/Format/FormatTokenSource.h 
b/clang/lib/Format/FormatTokenSource.h
index 11c735d36864..e14f72b7d1f4 100644
--- a/clang/lib/Format/FormatTokenSource.h
+++ b/clang/lib/Format/FormatTokenSource.h
@@ -52,6 +52,71 @@ class FormatTokenSource {
   virtual FormatToken *setPosition(unsigned Position) = 0;
 };
 
+class IndexedTokenSource : public FormatTokenSource {
+public:
+  IndexedTokenSource(ArrayRef Tokens)
+  : Tokens(Tokens), Position(-1) {}
+
+  FormatToken *getNextToken() override {
+if (Position >= 0 && isEOF()) {
+  LLVM_DEBUG({
+llvm::dbgs() << "Next ";
+dbgToken(Position);
+  });
+  return Tokens[Position];
+}
+++Position;
+LLVM_DEBUG({
+  llvm::dbgs() << "Next ";
+  dbgToken(Position);
+});
+return Tokens[Position];
+  }
+
+  FormatToken *getPreviousToken() override {
+return Position > 0 ? Tokens[Position - 1] : nullptr;
+  }
+
+  FormatToken *peekNextToken(bool SkipComment) override {
+int Next = Position + 1;
+if (SkipComment)
+  while (Tokens[Next]->is(tok::comment))
+++Next;
+LLVM_DEBUG({
+  llvm::dbgs() << "Peeking ";
+  dbgToken(Next);
+});
+return Tokens[Next];
+  }
+
+  bool isEOF() override { return Tokens[Position]->is(tok::eof); }
+
+  unsigned getPosition() override {
+LLVM_DEBUG(llvm::dbgs() << "Getting Position: " << Position << "\n");
+assert(Position >= 0);
+return Position;
+  }
+
+  FormatToken *setPosition(unsigned P) override {
+LLVM_DEBUG(llvm::dbgs() << "Setting Position: " << P << "\n");
+Position = P;
+return Tokens[Position];
+  }
+
+  void reset() { Position = -1; }
+
+private:
+  void dbgToken(int Position, llvm::StringRef Indent = "") {
+FormatToken *Tok = Tokens[Position];
+llvm::dbgs() << Indent << "[" << Position
+ << "] Token: " << Tok->Tok.getName() << " / " << 
Tok->TokenText
+ << ", Macro: " << !!Tok->MacroCtx << "\n";
+  }
+
+  ArrayRef Tokens;
+  int Position;
+};
+
 class ScopedMacroState : public FormatTokenSource {
 public:
   ScopedMacroState(UnwrappedLine , FormatTokenSource *,

diff  --git a/clang/lib/Format/UnwrappedLineParser.cpp 
b/clang/lib/Format/UnwrappedLineParser.cpp
index 9d90e5390bb8..c211c0ceb067 100644
--- a/clang/lib/Format/UnwrappedLineParser.cpp
+++ b/clang/lib/Format/UnwrappedLineParser.cpp
@@ -143,75 +143,6 @@ class CompoundStatementIndenter {
   unsigned OldLineLevel;
 };
 
-namespace {
-
-class IndexedTokenSource : public FormatTokenSource {
-public:
-  IndexedTokenSource(ArrayRef Tokens)
-  : Tokens(Tokens), Position(-1) {}
-
-  FormatToken *getNextToken() override {
-if (Position >= 0 && isEOF()) {
-  LLVM_DEBUG({
-llvm::dbgs() << "Next ";
-dbgToken(Position);
-  });
-  return Tokens[Position];
-}
-++Position;
-LLVM_DEBUG({
-  llvm::dbgs() << "Next ";
-  dbgToken(Position);
-});
-return Tokens[Position];
-  }
-
-  FormatToken *getPreviousToken() override {
-return Position > 0 ? Tokens[Position - 1] : nullptr;
-  }
-
-  FormatToken *peekNextToken(bool SkipComment) override {
-int Next = Position + 1;
-if (SkipComment)
-  while (Tokens[Next]->is(tok::comment))
-++Next;
-LLVM_DEBUG({
-  llvm::dbgs() << "Peeking ";
-  dbgToken(Next);
-});
-return Tokens[Next];
-  }
-
-  bool isEOF() override { return Tokens[Position]->is(tok::eof); }
-
-  unsigned getPosition() override {
-LLVM_DEBUG(llvm::dbgs() << "Getting Position: " << Position << "\n");
-assert(Position >= 0);
-return Position;
-  }
-
-  FormatToken *setPosition(unsigned P) override {
-LLVM_DEBUG(llvm::dbgs() << "Setting Position: " << P << "\n");
-Position = P;
-return Tokens[Position];
-  }
-
-  void reset() { Position = -1; }
-
-private:
-  void dbgToken(int Position, llvm::StringRef Indent = "") {
-FormatToken *Tok = Tokens[Position];
-llvm::dbgs() << Indent << "[" << Position
- << "] Token: " << Tok->Tok.getName() << " / " << 
Tok->TokenText
- << ", Macro: " << !!Tok->MacroCtx << "\n";
-  }
-
-  ArrayRef Tokens;
-  int Position;
-};
-
-} // end anonymous namespace
-
 UnwrappedLineParser::UnwrappedLineParser(const FormatStyle ,
  const 

[clang] c3bc61d - [clang-format][NFC] Pull FormatTokenSource into its own header.

2023-01-31 Thread Manuel Klimek via cfe-commits

Author: Manuel Klimek
Date: 2023-01-31T14:32:31Z
New Revision: c3bc61d72f8da9a2b45e610ee3c2ccfc5f884f69

URL: 
https://github.com/llvm/llvm-project/commit/c3bc61d72f8da9a2b45e610ee3c2ccfc5f884f69
DIFF: 
https://github.com/llvm/llvm-project/commit/c3bc61d72f8da9a2b45e610ee3c2ccfc5f884f69.diff

LOG: [clang-format][NFC] Pull FormatTokenSource into its own header.

Prepare getting FormatTokenSource under unit testing.

Added: 
clang/lib/Format/FormatTokenSource.h

Modified: 
clang/lib/Format/FormatToken.h
clang/lib/Format/UnwrappedLineParser.cpp

Removed: 




diff  --git a/clang/lib/Format/FormatToken.h b/clang/lib/Format/FormatToken.h
index 9d055efd80075..f3349a4dc2dfa 100644
--- a/clang/lib/Format/FormatToken.h
+++ b/clang/lib/Format/FormatToken.h
@@ -1803,6 +1803,25 @@ struct AdditionalKeywords {
   std::unordered_set VerilogExtraKeywords;
 };
 
+inline bool isLineComment(const FormatToken ) {
+  return FormatTok.is(tok::comment) && !FormatTok.TokenText.startswith("/*");
+}
+
+// Checks if \p FormatTok is a line comment that continues the line comment
+// \p Previous. The original column of \p MinColumnToken is used to determine
+// whether \p FormatTok is indented enough to the right to continue \p 
Previous.
+inline bool continuesLineComment(const FormatToken ,
+ const FormatToken *Previous,
+ const FormatToken *MinColumnToken) {
+  if (!Previous || !MinColumnToken)
+return false;
+  unsigned MinContinueColumn =
+  MinColumnToken->OriginalColumn + (isLineComment(*MinColumnToken) ? 0 : 
1);
+  return isLineComment(FormatTok) && FormatTok.NewlinesBefore == 1 &&
+ isLineComment(*Previous) &&
+ FormatTok.OriginalColumn >= MinContinueColumn;
+}
+
 } // namespace format
 } // namespace clang
 

diff  --git a/clang/lib/Format/FormatTokenSource.h 
b/clang/lib/Format/FormatTokenSource.h
new file mode 100644
index 0..11c735d368647
--- /dev/null
+++ b/clang/lib/Format/FormatTokenSource.h
@@ -0,0 +1,132 @@
+
+//===--- FormatTokenSource.h - Format C++ code --*- C++ 
-*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+///
+/// \file
+/// This file defines the \c TokenSource interface, which provides a token
+/// stream as well as the ability to manipulate the token stream.
+///
+//===--===//
+
+#ifndef LLVM_CLANG_LIB_FORMAT_FORMATTOKENSOURCE_H
+#define LLVM_CLANG_LIB_FORMAT_FORMATTOKENSOURCE_H
+
+#include "FormatToken.h"
+#include "UnwrappedLineParser.h"
+
+#define DEBUG_TYPE "format-token-source"
+
+namespace clang {
+namespace format {
+
+class FormatTokenSource {
+public:
+  virtual ~FormatTokenSource() {}
+
+  // Returns the next token in the token stream.
+  virtual FormatToken *getNextToken() = 0;
+
+  // Returns the token preceding the token returned by the last call to
+  // getNextToken() in the token stream, or nullptr if no such token exists.
+  virtual FormatToken *getPreviousToken() = 0;
+
+  // Returns the token that would be returned by the next call to
+  // getNextToken().
+  virtual FormatToken *peekNextToken(bool SkipComment = false) = 0;
+
+  // Returns whether we are at the end of the file.
+  // This can be 
diff erent from whether getNextToken() returned an eof token
+  // when the FormatTokenSource is a view on a part of the token stream.
+  virtual bool isEOF() = 0;
+
+  // Gets the current position in the token stream, to be used by 
setPosition().
+  virtual unsigned getPosition() = 0;
+
+  // Resets the token stream to the state it was in when getPosition() returned
+  // Position, and return the token at that position in the stream.
+  virtual FormatToken *setPosition(unsigned Position) = 0;
+};
+
+class ScopedMacroState : public FormatTokenSource {
+public:
+  ScopedMacroState(UnwrappedLine , FormatTokenSource *,
+   FormatToken *)
+  : Line(Line), TokenSource(TokenSource), ResetToken(ResetToken),
+PreviousLineLevel(Line.Level), PreviousTokenSource(TokenSource),
+Token(nullptr), PreviousToken(nullptr) {
+FakeEOF.Tok.startToken();
+FakeEOF.Tok.setKind(tok::eof);
+TokenSource = this;
+Line.Level = 0;
+Line.InPPDirective = true;
+// InMacroBody gets set after the `#define x` part.
+  }
+
+  ~ScopedMacroState() override {
+TokenSource = PreviousTokenSource;
+ResetToken = Token;
+Line.InPPDirective = false;
+Line.InMacroBody = false;
+Line.Level = PreviousLineLevel;
+  }
+
+  FormatToken *getNextToken() override {
+// The \c UnwrappedLineParser guards against this by never calling
+

[clang] 49aca00 - [NFC] Remove peekNextToken(int).

2022-11-26 Thread Manuel Klimek via cfe-commits

Author: Manuel Klimek
Date: 2022-11-26T18:23:42Z
New Revision: 49aca00d63e14df8bc68fc4329e6cbc9c9805eb8

URL: 
https://github.com/llvm/llvm-project/commit/49aca00d63e14df8bc68fc4329e6cbc9c9805eb8
DIFF: 
https://github.com/llvm/llvm-project/commit/49aca00d63e14df8bc68fc4329e6cbc9c9805eb8.diff

LOG: [NFC] Remove peekNextToken(int).

Arbitrary lookahead restricts the implementation of our TokenSource,
specifically getting in the way of changes to handle macros better.

Instead, use getNextToken to parse lookahead linearly, and
getPosition/setPosition to unwind our lookahead.

Added: 


Modified: 
clang/lib/Format/UnwrappedLineParser.cpp

Removed: 




diff  --git a/clang/lib/Format/UnwrappedLineParser.cpp 
b/clang/lib/Format/UnwrappedLineParser.cpp
index 3bc7d2454c93a..e6bb9c4333b98 100644
--- a/clang/lib/Format/UnwrappedLineParser.cpp
+++ b/clang/lib/Format/UnwrappedLineParser.cpp
@@ -43,12 +43,6 @@ class FormatTokenSource {
   // getNextToken().
   virtual FormatToken *peekNextToken() = 0;
 
-  // Returns the token that would be returned after the next N calls to
-  // getNextToken(). N needs to be greater than zero, and small enough that
-  // there are still tokens. Check for tok::eof with N-1 before calling it with
-  // N.
-  virtual FormatToken *peekNextToken(int N) = 0;
-
   // Returns whether we are at the end of the file.
   // This can be 
diff erent from whether getNextToken() returned an eof token
   // when the FormatTokenSource is a view on a part of the token stream.
@@ -181,13 +175,6 @@ class ScopedMacroState : public FormatTokenSource {
 return PreviousTokenSource->peekNextToken();
   }
 
-  FormatToken *peekNextToken(int N) override {
-assert(N > 0);
-if (eof())
-  return 
-return PreviousTokenSource->peekNextToken(N);
-  }
-
   bool isEOF() override { return PreviousTokenSource->isEOF(); }
 
   unsigned getPosition() override { return PreviousTokenSource->getPosition(); 
}
@@ -310,16 +297,6 @@ class IndexedTokenSource : public FormatTokenSource {
 return Tokens[Next];
   }
 
-  FormatToken *peekNextToken(int N) override {
-assert(N > 0);
-int Next = Position + N;
-LLVM_DEBUG({
-  llvm::dbgs() << "Peeking (+" << (N - 1) << ") ";
-  dbgToken(Next);
-});
-return Tokens[Next];
-  }
-
   bool isEOF() override { return Tokens[Position]->is(tok::eof); }
 
   unsigned getPosition() override {
@@ -3389,37 +3366,41 @@ bool 
clang::format::UnwrappedLineParser::parseRequires() {
   // So we want basically to check for TYPE NAME, but TYPE can contain all 
kinds
   // of stuff: typename, const, *, &, &&, ::, identifiers.
 
-  int NextTokenOffset = 1;
-  auto NextToken = Tokens->peekNextToken(NextTokenOffset);
-  auto PeekNext = [, , this] {
-++NextTokenOffset;
-NextToken = Tokens->peekNextToken(NextTokenOffset);
+  unsigned StoredPosition = Tokens->getPosition();
+  FormatToken *NextToken = Tokens->getNextToken();
+  int Lookahead = 0;
+  auto PeekNext = [, , this] {
+++Lookahead;
+NextToken = Tokens->getNextToken();
   };
 
   bool FoundType = false;
   bool LastWasColonColon = false;
   int OpenAngles = 0;
 
-  for (; NextTokenOffset < 50; PeekNext()) {
+  for (; Lookahead < 50; PeekNext()) {
 switch (NextToken->Tok.getKind()) {
 case tok::kw_volatile:
 case tok::kw_const:
 case tok::comma:
+  FormatTok = Tokens->setPosition(StoredPosition);
   parseRequiresExpression(RequiresToken);
   return false;
 case tok::r_paren:
 case tok::pipepipe:
+  FormatTok = Tokens->setPosition(StoredPosition);
   parseRequiresClause(RequiresToken);
   return true;
 case tok::eof:
   // Break out of the loop.
-  NextTokenOffset = 50;
+  Lookahead = 50;
   break;
 case tok::coloncolon:
   LastWasColonColon = true;
   break;
 case tok::identifier:
   if (FoundType && !LastWasColonColon && OpenAngles == 0) {
+FormatTok = Tokens->setPosition(StoredPosition);
 parseRequiresExpression(RequiresToken);
 return false;
   }
@@ -3434,14 +3415,15 @@ bool 
clang::format::UnwrappedLineParser::parseRequires() {
   break;
 default:
   if (NextToken->isSimpleTypeSpecifier()) {
+FormatTok = Tokens->setPosition(StoredPosition);
 parseRequiresExpression(RequiresToken);
 return false;
   }
   break;
 }
   }
-
   // This seems to be a complicated expression, just assume it's a clause.
+  FormatTok = Tokens->setPosition(StoredPosition);
   parseRequiresClause(RequiresToken);
   return true;
 }



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] d65019b - [NFC] Clean up printing of UnwrappedLines.

2022-11-25 Thread Manuel Klimek via cfe-commits

Author: Manuel Klimek
Date: 2022-11-25T14:26:47Z
New Revision: d65019bbcb0a33502ebfc3cfc492e4d3cee9c7b7

URL: 
https://github.com/llvm/llvm-project/commit/d65019bbcb0a33502ebfc3cfc492e4d3cee9c7b7
DIFF: 
https://github.com/llvm/llvm-project/commit/d65019bbcb0a33502ebfc3cfc492e4d3cee9c7b7.diff

LOG: [NFC] Clean up printing of UnwrappedLines.

Move print functions to start of UnwarppedLineParser so they can be
used from everywhere in the file.
Pull out function that doesn't hard-code the stream.

Added: 


Modified: 
clang/lib/Format/UnwrappedLineParser.cpp

Removed: 




diff  --git a/clang/lib/Format/UnwrappedLineParser.cpp 
b/clang/lib/Format/UnwrappedLineParser.cpp
index 4dc70e2d56c70..3bc7d2454c93a 100644
--- a/clang/lib/Format/UnwrappedLineParser.cpp
+++ b/clang/lib/Format/UnwrappedLineParser.cpp
@@ -64,6 +64,39 @@ class FormatTokenSource {
 
 namespace {
 
+void printLine(llvm::raw_ostream , const UnwrappedLine ,
+   StringRef Prefix = "", bool PrintText = false) {
+  OS << Prefix << "Line(" << Line.Level << ", FSC=" << Line.FirstStartColumn
+ << ")" << (Line.InPPDirective ? " MACRO" : "") << ": ";
+  bool NewLine = false;
+  for (std::list::const_iterator I = Line.Tokens.begin(),
+E = Line.Tokens.end();
+   I != E; ++I) {
+if (NewLine) {
+  OS << Prefix;
+  NewLine = false;
+}
+OS << I->Tok->Tok.getName() << "["
+   << "T=" << (unsigned)I->Tok->getType()
+   << ", OC=" << I->Tok->OriginalColumn << ", \"" << I->Tok->TokenText
+   << "\"] ";
+for (SmallVectorImpl::const_iterator
+ CI = I->Children.begin(),
+ CE = I->Children.end();
+ CI != CE; ++CI) {
+  OS << "\n";
+  printLine(OS, *CI, (Prefix + "  ").str());
+  NewLine = true;
+}
+  }
+  if (!NewLine)
+OS << "\n";
+}
+
+LLVM_ATTRIBUTE_UNUSED static void printDebugInfo(const UnwrappedLine ) {
+  printLine(llvm::dbgs(), Line);
+}
+
 class ScopedDeclarationState {
 public:
   ScopedDeclarationState(UnwrappedLine , llvm::BitVector ,
@@ -4314,23 +4347,6 @@ void UnwrappedLineParser::parseVerilogCaseLabel() {
   Line->Level = OrigLevel;
 }
 
-LLVM_ATTRIBUTE_UNUSED static void printDebugInfo(const UnwrappedLine ,
- StringRef Prefix = "") {
-  llvm::dbgs() << Prefix << "Line(" << Line.Level
-   << ", FSC=" << Line.FirstStartColumn << ")"
-   << (Line.InPPDirective ? " MACRO" : "") << ": ";
-  for (const auto  : Line.Tokens) {
-llvm::dbgs() << Node.Tok->Tok.getName() << "["
- << "T=" << static_cast(Node.Tok->getType())
- << ", OC=" << Node.Tok->OriginalColumn << "] ";
-  }
-  for (const auto  : Line.Tokens)
-for (const auto  : Node.Children)
-  printDebugInfo(ChildNode, "\nChild: ");
-
-  llvm::dbgs() << "\n";
-}
-
 void UnwrappedLineParser::addUnwrappedLine(LineLevel AdjustLevel) {
   if (Line->Tokens.empty())
 return;



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [clang] ee88c0c - [NFCI] Fix unused variable/function warnings in MacroCallReconstructorTest.cpp when asserts are disabled.

2022-11-25 Thread Manuel Klimek via cfe-commits
Fixed in ca8c6156f27003ffa0e24bace2be7c25307f50a3.

On Thu, Jul 21, 2022 at 3:21 PM Manuel Klimek  wrote:

> Ping :)
>
> On Mon, Jul 18, 2022 at 1:22 PM Manuel Klimek  wrote:
>
>> Ping :)
>>
>> On Wed, Jul 13, 2022 at 11:43 AM Manuel Klimek  wrote:
>>
>>> This is a functional change, as it removes the debug output when the
>>> tokens do not match, which is important for understanding test failures.
>>>
>>> On Wed, Jul 13, 2022 at 1:47 AM Jorge Gorbe Moya via cfe-commits <
>>> cfe-commits@lists.llvm.org> wrote:
>>>

 Author: Jorge Gorbe Moya
 Date: 2022-07-12T16:46:58-07:00
 New Revision: ee88c0cf09969ba44307068797e12533b94768a6

 URL:
 https://github.com/llvm/llvm-project/commit/ee88c0cf09969ba44307068797e12533b94768a6
 DIFF:
 https://github.com/llvm/llvm-project/commit/ee88c0cf09969ba44307068797e12533b94768a6.diff

 LOG: [NFCI] Fix unused variable/function warnings in
 MacroCallReconstructorTest.cpp when asserts are disabled.

 Added:


 Modified:
 clang/unittests/Format/MacroCallReconstructorTest.cpp

 Removed:




 
 diff  --git a/clang/unittests/Format/MacroCallReconstructorTest.cpp
 b/clang/unittests/Format/MacroCallReconstructorTest.cpp
 index 2bda62aa42be..3abe0383aeae 100644
 --- a/clang/unittests/Format/MacroCallReconstructorTest.cpp
 +++ b/clang/unittests/Format/MacroCallReconstructorTest.cpp
 @@ -91,14 +91,6 @@ struct Chunk {
llvm::SmallVector Children;
  };

 -bool tokenMatches(const FormatToken *Left, const FormatToken *Right) {
 -  if (Left->getType() == Right->getType() &&
 -  Left->TokenText == Right->TokenText)
 -return true;
 -  llvm::dbgs() << Left->TokenText << " != " << Right->TokenText <<
 "\n";
 -  return false;
 -}
 -
  // Allows to produce chunks of a token list by typing the code of
 equal tokens.
  //
  // Created from a list of tokens, users call "consume" to get the next
 chunk
 @@ -110,7 +102,9 @@ struct Matcher {
Chunk consume(StringRef Tokens) {
  TokenList Result;
  for (const FormatToken *Token : uneof(Lex.lex(Tokens))) {
 -  assert(tokenMatches(*It, Token));
 +  (void)Token;  // Fix unused variable warning when asserts are
 disabled.
 +  assert((*It)->getType() == Token->getType() &&
 + (*It)->TokenText == Token->TokenText);
Result.push_back(*It);
++It;
  }



 ___
 cfe-commits mailing list
 cfe-commits@lists.llvm.org
 https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

>>>
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] ca8c615 - Fix test output regression from ee88c0cf09969ba44307068797e12533b94768a6.

2022-11-25 Thread Manuel Klimek via cfe-commits

Author: Manuel Klimek
Date: 2022-11-25T13:53:34Z
New Revision: ca8c6156f27003ffa0e24bace2be7c25307f50a3

URL: 
https://github.com/llvm/llvm-project/commit/ca8c6156f27003ffa0e24bace2be7c25307f50a3
DIFF: 
https://github.com/llvm/llvm-project/commit/ca8c6156f27003ffa0e24bace2be7c25307f50a3.diff

LOG: Fix test output regression from ee88c0cf09969ba44307068797e12533b94768a6.

The unused variable fix also remove the test output of the tokens
that do not match, making debugging tests harder. Undo the semantic
changes of the build fix.

Added: 


Modified: 
clang/unittests/Format/MacroCallReconstructorTest.cpp

Removed: 




diff  --git a/clang/unittests/Format/MacroCallReconstructorTest.cpp 
b/clang/unittests/Format/MacroCallReconstructorTest.cpp
index 2b880d75b514f..eee980bae8d8b 100644
--- a/clang/unittests/Format/MacroCallReconstructorTest.cpp
+++ b/clang/unittests/Format/MacroCallReconstructorTest.cpp
@@ -97,12 +97,20 @@ struct Matcher {
   Matcher(const TokenList , TestLexer )
   : Tokens(Tokens), It(this->Tokens.begin()), Lex(Lex) {}
 
+  bool tokenMatches(const FormatToken *Left, const FormatToken *Right) {
+if (Left->getType() == Right->getType() &&
+Left->TokenText == Right->TokenText) {
+  return true;
+}
+llvm::dbgs() << Left->TokenText << " != " << Right->TokenText << "\n";
+return false;
+  }
+
   Chunk consume(StringRef Tokens) {
 TokenList Result;
 for (const FormatToken *Token : uneof(Lex.lex(Tokens))) {
   (void)Token; // Fix unused variable warning when asserts are disabled.
-  assert((*It)->getType() == Token->getType() &&
- (*It)->TokenText == Token->TokenText);
+  assert(tokenMatches(*It, Token));
   Result.push_back(*It);
   ++It;
 }



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [clang] ee88c0c - [NFCI] Fix unused variable/function warnings in MacroCallReconstructorTest.cpp when asserts are disabled.

2022-07-21 Thread Manuel Klimek via cfe-commits
Ping :)

On Mon, Jul 18, 2022 at 1:22 PM Manuel Klimek  wrote:

> Ping :)
>
> On Wed, Jul 13, 2022 at 11:43 AM Manuel Klimek  wrote:
>
>> This is a functional change, as it removes the debug output when the
>> tokens do not match, which is important for understanding test failures.
>>
>> On Wed, Jul 13, 2022 at 1:47 AM Jorge Gorbe Moya via cfe-commits <
>> cfe-commits@lists.llvm.org> wrote:
>>
>>>
>>> Author: Jorge Gorbe Moya
>>> Date: 2022-07-12T16:46:58-07:00
>>> New Revision: ee88c0cf09969ba44307068797e12533b94768a6
>>>
>>> URL:
>>> https://github.com/llvm/llvm-project/commit/ee88c0cf09969ba44307068797e12533b94768a6
>>> DIFF:
>>> https://github.com/llvm/llvm-project/commit/ee88c0cf09969ba44307068797e12533b94768a6.diff
>>>
>>> LOG: [NFCI] Fix unused variable/function warnings in
>>> MacroCallReconstructorTest.cpp when asserts are disabled.
>>>
>>> Added:
>>>
>>>
>>> Modified:
>>> clang/unittests/Format/MacroCallReconstructorTest.cpp
>>>
>>> Removed:
>>>
>>>
>>>
>>>
>>> 
>>> diff  --git a/clang/unittests/Format/MacroCallReconstructorTest.cpp
>>> b/clang/unittests/Format/MacroCallReconstructorTest.cpp
>>> index 2bda62aa42be..3abe0383aeae 100644
>>> --- a/clang/unittests/Format/MacroCallReconstructorTest.cpp
>>> +++ b/clang/unittests/Format/MacroCallReconstructorTest.cpp
>>> @@ -91,14 +91,6 @@ struct Chunk {
>>>llvm::SmallVector Children;
>>>  };
>>>
>>> -bool tokenMatches(const FormatToken *Left, const FormatToken *Right) {
>>> -  if (Left->getType() == Right->getType() &&
>>> -  Left->TokenText == Right->TokenText)
>>> -return true;
>>> -  llvm::dbgs() << Left->TokenText << " != " << Right->TokenText << "\n";
>>> -  return false;
>>> -}
>>> -
>>>  // Allows to produce chunks of a token list by typing the code of equal
>>> tokens.
>>>  //
>>>  // Created from a list of tokens, users call "consume" to get the next
>>> chunk
>>> @@ -110,7 +102,9 @@ struct Matcher {
>>>Chunk consume(StringRef Tokens) {
>>>  TokenList Result;
>>>  for (const FormatToken *Token : uneof(Lex.lex(Tokens))) {
>>> -  assert(tokenMatches(*It, Token));
>>> +  (void)Token;  // Fix unused variable warning when asserts are
>>> disabled.
>>> +  assert((*It)->getType() == Token->getType() &&
>>> + (*It)->TokenText == Token->TokenText);
>>>Result.push_back(*It);
>>>++It;
>>>  }
>>>
>>>
>>>
>>> ___
>>> cfe-commits mailing list
>>> cfe-commits@lists.llvm.org
>>> https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
>>>
>>
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [clang] ee88c0c - [NFCI] Fix unused variable/function warnings in MacroCallReconstructorTest.cpp when asserts are disabled.

2022-07-18 Thread Manuel Klimek via cfe-commits
Ping :)

On Wed, Jul 13, 2022 at 11:43 AM Manuel Klimek  wrote:

> This is a functional change, as it removes the debug output when the
> tokens do not match, which is important for understanding test failures.
>
> On Wed, Jul 13, 2022 at 1:47 AM Jorge Gorbe Moya via cfe-commits <
> cfe-commits@lists.llvm.org> wrote:
>
>>
>> Author: Jorge Gorbe Moya
>> Date: 2022-07-12T16:46:58-07:00
>> New Revision: ee88c0cf09969ba44307068797e12533b94768a6
>>
>> URL:
>> https://github.com/llvm/llvm-project/commit/ee88c0cf09969ba44307068797e12533b94768a6
>> DIFF:
>> https://github.com/llvm/llvm-project/commit/ee88c0cf09969ba44307068797e12533b94768a6.diff
>>
>> LOG: [NFCI] Fix unused variable/function warnings in
>> MacroCallReconstructorTest.cpp when asserts are disabled.
>>
>> Added:
>>
>>
>> Modified:
>> clang/unittests/Format/MacroCallReconstructorTest.cpp
>>
>> Removed:
>>
>>
>>
>>
>> 
>> diff  --git a/clang/unittests/Format/MacroCallReconstructorTest.cpp
>> b/clang/unittests/Format/MacroCallReconstructorTest.cpp
>> index 2bda62aa42be..3abe0383aeae 100644
>> --- a/clang/unittests/Format/MacroCallReconstructorTest.cpp
>> +++ b/clang/unittests/Format/MacroCallReconstructorTest.cpp
>> @@ -91,14 +91,6 @@ struct Chunk {
>>llvm::SmallVector Children;
>>  };
>>
>> -bool tokenMatches(const FormatToken *Left, const FormatToken *Right) {
>> -  if (Left->getType() == Right->getType() &&
>> -  Left->TokenText == Right->TokenText)
>> -return true;
>> -  llvm::dbgs() << Left->TokenText << " != " << Right->TokenText << "\n";
>> -  return false;
>> -}
>> -
>>  // Allows to produce chunks of a token list by typing the code of equal
>> tokens.
>>  //
>>  // Created from a list of tokens, users call "consume" to get the next
>> chunk
>> @@ -110,7 +102,9 @@ struct Matcher {
>>Chunk consume(StringRef Tokens) {
>>  TokenList Result;
>>  for (const FormatToken *Token : uneof(Lex.lex(Tokens))) {
>> -  assert(tokenMatches(*It, Token));
>> +  (void)Token;  // Fix unused variable warning when asserts are
>> disabled.
>> +  assert((*It)->getType() == Token->getType() &&
>> + (*It)->TokenText == Token->TokenText);
>>Result.push_back(*It);
>>++It;
>>  }
>>
>>
>>
>> ___
>> cfe-commits mailing list
>> cfe-commits@lists.llvm.org
>> https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
>>
>
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [clang] ee88c0c - [NFCI] Fix unused variable/function warnings in MacroCallReconstructorTest.cpp when asserts are disabled.

2022-07-13 Thread Manuel Klimek via cfe-commits
This is a functional change, as it removes the debug output when the tokens
do not match, which is important for understanding test failures.

On Wed, Jul 13, 2022 at 1:47 AM Jorge Gorbe Moya via cfe-commits <
cfe-commits@lists.llvm.org> wrote:

>
> Author: Jorge Gorbe Moya
> Date: 2022-07-12T16:46:58-07:00
> New Revision: ee88c0cf09969ba44307068797e12533b94768a6
>
> URL:
> https://github.com/llvm/llvm-project/commit/ee88c0cf09969ba44307068797e12533b94768a6
> DIFF:
> https://github.com/llvm/llvm-project/commit/ee88c0cf09969ba44307068797e12533b94768a6.diff
>
> LOG: [NFCI] Fix unused variable/function warnings in
> MacroCallReconstructorTest.cpp when asserts are disabled.
>
> Added:
>
>
> Modified:
> clang/unittests/Format/MacroCallReconstructorTest.cpp
>
> Removed:
>
>
>
>
> 
> diff  --git a/clang/unittests/Format/MacroCallReconstructorTest.cpp
> b/clang/unittests/Format/MacroCallReconstructorTest.cpp
> index 2bda62aa42be..3abe0383aeae 100644
> --- a/clang/unittests/Format/MacroCallReconstructorTest.cpp
> +++ b/clang/unittests/Format/MacroCallReconstructorTest.cpp
> @@ -91,14 +91,6 @@ struct Chunk {
>llvm::SmallVector Children;
>  };
>
> -bool tokenMatches(const FormatToken *Left, const FormatToken *Right) {
> -  if (Left->getType() == Right->getType() &&
> -  Left->TokenText == Right->TokenText)
> -return true;
> -  llvm::dbgs() << Left->TokenText << " != " << Right->TokenText << "\n";
> -  return false;
> -}
> -
>  // Allows to produce chunks of a token list by typing the code of equal
> tokens.
>  //
>  // Created from a list of tokens, users call "consume" to get the next
> chunk
> @@ -110,7 +102,9 @@ struct Matcher {
>Chunk consume(StringRef Tokens) {
>  TokenList Result;
>  for (const FormatToken *Token : uneof(Lex.lex(Tokens))) {
> -  assert(tokenMatches(*It, Token));
> +  (void)Token;  // Fix unused variable warning when asserts are
> disabled.
> +  assert((*It)->getType() == Token->getType() &&
> + (*It)->TokenText == Token->TokenText);
>Result.push_back(*It);
>++It;
>  }
>
>
>
> ___
> cfe-commits mailing list
> cfe-commits@lists.llvm.org
> https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
>
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] f44d28f - Fix build errors.

2022-07-12 Thread Manuel Klimek via cfe-commits

Author: Manuel Klimek
Date: 2022-07-12T07:43:26Z
New Revision: f44d28f840c0b0877b09d5547fd09e191bbdc90e

URL: 
https://github.com/llvm/llvm-project/commit/f44d28f840c0b0877b09d5547fd09e191bbdc90e
DIFF: 
https://github.com/llvm/llvm-project/commit/f44d28f840c0b0877b09d5547fd09e191bbdc90e.diff

LOG: Fix build errors.

Added: 


Modified: 
clang/lib/Format/MacroCallReconstructor.cpp
clang/lib/Format/Macros.h

Removed: 




diff  --git a/clang/lib/Format/MacroCallReconstructor.cpp 
b/clang/lib/Format/MacroCallReconstructor.cpp
index 67711cc91d0b8..ccff183cf0da1 100644
--- a/clang/lib/Format/MacroCallReconstructor.cpp
+++ b/clang/lib/Format/MacroCallReconstructor.cpp
@@ -98,7 +98,7 @@ void MacroCallReconstructor::add(FormatToken *Token,
   if (!ActiveExpansions.empty() && Token->MacroCtx &&
   (Token->MacroCtx->Role != MR_Hidden ||
ActiveExpansions.size() != Token->MacroCtx->ExpandedFrom.size())) {
-if (bool PassedMacroComma = reconstructActiveCallUntil(Token))
+if (/*PassedMacroComma = */ reconstructActiveCallUntil(Token))
   First = true;
   }
 
@@ -172,7 +172,7 @@ void MacroCallReconstructor::prepareParent(FormatToken 
*ExpandedParent,
 }
 assert(!ActiveReconstructedLines.empty());
 ActiveReconstructedLines.back()->Tokens.back()->Children.push_back(
-std::make_unique());
+std::make_unique());
 ActiveReconstructedLines.push_back(
 &*ActiveReconstructedLines.back()->Tokens.back()->Children.back());
   } else if (parentLine().Tokens.back()->Tok != Parent) {
@@ -498,14 +498,16 @@ void MacroCallReconstructor::finalize() {
   Top.Children.resize(1);
 }
 
-void MacroCallReconstructor::appendToken(FormatToken *Token, Line *L) {
+void MacroCallReconstructor::appendToken(FormatToken *Token,
+ ReconstructedLine *L) {
   L = L ? L : currentLine();
   LLVM_DEBUG(llvm::dbgs() << "-> " << Token->TokenText << "\n");
   L->Tokens.push_back(std::make_unique(Token));
 }
 
-UnwrappedLine MacroCallReconstructor::createUnwrappedLine(const Line ,
-  int Level) {
+UnwrappedLine
+MacroCallReconstructor::createUnwrappedLine(const ReconstructedLine ,
+int Level) {
   UnwrappedLine Result;
   Result.Level = Level;
   for (const auto  : Line.Tokens) {
@@ -526,7 +528,7 @@ UnwrappedLine 
MacroCallReconstructor::createUnwrappedLine(const Line ,
   return Result;
 }
 
-void MacroCallReconstructor::debug(const Line , int Level) {
+void MacroCallReconstructor::debug(const ReconstructedLine , int Level) {
   for (int i = 0; i < Level; ++i)
 llvm::dbgs() << " ";
   for (const auto  : Line.Tokens) {
@@ -544,17 +546,19 @@ void MacroCallReconstructor::debug(const Line , int 
Level) {
   llvm::dbgs() << "\n";
 }
 
-MacroCallReconstructor::Line ::parentLine() {
+MacroCallReconstructor::ReconstructedLine &
+MacroCallReconstructor::parentLine() {
   return **std::prev(std::prev(ActiveReconstructedLines.end()));
 }
 
-MacroCallReconstructor::Line *MacroCallReconstructor::currentLine() {
+MacroCallReconstructor::ReconstructedLine *
+MacroCallReconstructor::currentLine() {
   return ActiveReconstructedLines.back();
 }
 
 MacroCallReconstructor::MacroCallState::MacroCallState(
-MacroCallReconstructor::Line *Line, FormatToken *ParentLastToken,
-FormatToken *MacroCallLParen)
+MacroCallReconstructor::ReconstructedLine *Line,
+FormatToken *ParentLastToken, FormatToken *MacroCallLParen)
 : Line(Line), ParentLastToken(ParentLastToken),
   MacroCallLParen(MacroCallLParen) {
   LLVM_DEBUG(

diff  --git a/clang/lib/Format/Macros.h b/clang/lib/Format/Macros.h
index 59774647a5694..ded792c628701 100644
--- a/clang/lib/Format/Macros.h
+++ b/clang/lib/Format/Macros.h
@@ -234,13 +234,13 @@ class MacroCallReconstructor {
   bool processNextReconstructed();
   void finalize();
 
-  struct Line;
+  struct ReconstructedLine;
 
-  void appendToken(FormatToken *Token, Line *L = nullptr);
-  UnwrappedLine createUnwrappedLine(const Line , int Level);
-  void debug(const Line , int Level);
-  Line ();
-  Line *currentLine();
+  void appendToken(FormatToken *Token, ReconstructedLine *L = nullptr);
+  UnwrappedLine createUnwrappedLine(const ReconstructedLine , int Level);
+  void debug(const ReconstructedLine , int Level);
+  ReconstructedLine ();
+  ReconstructedLine *currentLine();
   void debugParentMap() const;
 
 #ifndef NDEBUG
@@ -258,13 +258,13 @@ class MacroCallReconstructor {
 LineNode() = default;
 LineNode(FormatToken *Tok) : Tok(Tok) {}
 FormatToken *Tok = nullptr;
-llvm::SmallVector> Children;
+llvm::SmallVector> Children;
   };
 
   // Line in which we build up the resulting unwrapped line.
   // FIXME: Investigate changing UnwrappedLine to a pointer type and using it
   // instead of rolling our own type.
-  struct Line {

[clang] d6d0dc1 - [clang-format] Add MacroUnexpander.

2022-07-12 Thread Manuel Klimek via cfe-commits

Author: Manuel Klimek
Date: 2022-07-12T07:11:46Z
New Revision: d6d0dc1f45377ddaf5c10a48d64b09308b71501a

URL: 
https://github.com/llvm/llvm-project/commit/d6d0dc1f45377ddaf5c10a48d64b09308b71501a
DIFF: 
https://github.com/llvm/llvm-project/commit/d6d0dc1f45377ddaf5c10a48d64b09308b71501a.diff

LOG: [clang-format] Add MacroUnexpander.

MacroUnexpander applies the structural formatting of expanded lines into
UnwrappedLines to the corresponding unexpanded macro calls, resulting in
UnwrappedLines for the macro calls the user typed.

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

Added: 
clang/lib/Format/MacroCallReconstructor.cpp
clang/unittests/Format/MacroCallReconstructorTest.cpp

Modified: 
clang/lib/Format/CMakeLists.txt
clang/lib/Format/FormatToken.h
clang/lib/Format/Macros.h
clang/lib/Format/UnwrappedLineParser.h
clang/unittests/Format/CMakeLists.txt

Removed: 




diff  --git a/clang/lib/Format/CMakeLists.txt b/clang/lib/Format/CMakeLists.txt
index ca455157ae44a..4ea02ea72bc77 100644
--- a/clang/lib/Format/CMakeLists.txt
+++ b/clang/lib/Format/CMakeLists.txt
@@ -8,6 +8,7 @@ add_clang_library(clangFormat
   Format.cpp
   FormatToken.cpp
   FormatTokenLexer.cpp
+  MacroCallReconstructor.cpp
   MacroExpander.cpp
   NamespaceEndCommentsFixer.cpp
   QualifierAlignmentFixer.cpp

diff  --git a/clang/lib/Format/FormatToken.h b/clang/lib/Format/FormatToken.h
index b6cc021affae3..73e32979853f5 100644
--- a/clang/lib/Format/FormatToken.h
+++ b/clang/lib/Format/FormatToken.h
@@ -497,6 +497,15 @@ struct FormatToken {
   // in a configured macro expansion.
   llvm::Optional MacroCtx;
 
+  /// When macro expansion introduces nodes with children, those are marked as
+  /// \c MacroParent.
+  /// FIXME: The formatting code currently hard-codes the assumption that
+  /// child nodes are introduced by blocks following an opening brace.
+  /// This is deeply baked into the code and disentangling this will require
+  /// signficant refactorings. \c MacroParent allows us to special-case the
+  /// cases in which we treat parents as block-openers for now.
+  bool MacroParent = false;
+
   bool is(tok::TokenKind Kind) const { return Tok.is(Kind); }
   bool is(TokenType TT) const { return getType() == TT; }
   bool is(const IdentifierInfo *II) const {

diff  --git a/clang/lib/Format/MacroCallReconstructor.cpp 
b/clang/lib/Format/MacroCallReconstructor.cpp
new file mode 100644
index 0..67711cc91d0b8
--- /dev/null
+++ b/clang/lib/Format/MacroCallReconstructor.cpp
@@ -0,0 +1,569 @@
+//===--- MacroCallReconstructor.cpp - Format C++ code ---*- C++ 
-*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+///
+/// \file
+/// This file contains the implementation of MacroCallReconstructor, which fits
+/// an reconstructed macro call to a parsed set of UnwrappedLines.
+///
+//===--===//
+
+#include "Macros.h"
+
+#include "UnwrappedLineParser.h"
+#include "clang/Basic/TokenKinds.h"
+#include "llvm/ADT/DenseSet.h"
+#include "llvm/Support/Debug.h"
+#include 
+
+#define DEBUG_TYPE "format-reconstruct"
+
+namespace clang {
+namespace format {
+
+// Call \p Call for each token in the unwrapped line given, passing
+// the token, its parent and whether it is the first token in the line.
+template 
+void forEachToken(const UnwrappedLine , const T ,
+  FormatToken *Parent = nullptr) {
+  bool First = true;
+  for (const auto  : Line.Tokens) {
+Call(N.Tok, Parent, First);
+First = false;
+for (const auto  : N.Children) {
+  forEachToken(Child, Call, N.Tok);
+}
+  }
+}
+
+MacroCallReconstructor::MacroCallReconstructor(
+unsigned Level,
+const llvm::DenseMap>
+)
+: Level(Level), IdToReconstructed(ActiveExpansions) {
+  Result.Tokens.push_back(std::make_unique());
+  ActiveReconstructedLines.push_back();
+}
+
+void MacroCallReconstructor::addLine(const UnwrappedLine ) {
+  assert(State != Finalized);
+  LLVM_DEBUG(llvm::dbgs() << "MCR: new line...\n");
+  forEachToken(Line, [&](FormatToken *Token, FormatToken *Parent, bool First) {
+add(Token, Parent, First);
+  });
+  assert(InProgress || finished());
+}
+
+UnwrappedLine MacroCallReconstructor::takeResult() && {
+  finalize();
+  assert(Result.Tokens.size() == 1 && Result.Tokens.front()->Children.size() 
== 1);
+  UnwrappedLine Final =
+  createUnwrappedLine(*Result.Tokens.front()->Children.front(), Level);
+  assert(!Final.Tokens.empty());
+  return Final;
+}
+
+// Reconstruct the position of the next \p Token, given its parent \p
+// ExpandedParent in the incoming unwrapped line. \p First specifies whether it

[clang] 4de0680 - Fix use of pointer arithmetic instead of iterators.

2022-07-05 Thread Manuel Klimek via cfe-commits

Author: Manuel Klimek
Date: 2022-07-05T08:23:42Z
New Revision: 4de0680fbf4e4a9b9136ab5ee1ca549954eb8590

URL: 
https://github.com/llvm/llvm-project/commit/4de0680fbf4e4a9b9136ab5ee1ca549954eb8590
DIFF: 
https://github.com/llvm/llvm-project/commit/4de0680fbf4e4a9b9136ab5ee1ca549954eb8590.diff

LOG: Fix use of pointer arithmetic instead of iterators.

Added: 


Modified: 
clang/lib/Format/UnwrappedLineParser.cpp

Removed: 




diff  --git a/clang/lib/Format/UnwrappedLineParser.cpp 
b/clang/lib/Format/UnwrappedLineParser.cpp
index d3383292f7a38..97c3d86282a02 100644
--- a/clang/lib/Format/UnwrappedLineParser.cpp
+++ b/clang/lib/Format/UnwrappedLineParser.cpp
@@ -15,6 +15,7 @@
 #include "UnwrappedLineParser.h"
 #include "FormatToken.h"
 #include "TokenAnnotator.h"
+#include "clang/Basic/TokenKinds.h"
 #include "llvm/ADT/STLExtras.h"
 #include "llvm/Support/Debug.h"
 #include "llvm/Support/raw_ostream.h"
@@ -1910,15 +1911,12 @@ void UnwrappedLineParser::parseStructuralElement(
 break;
 
   auto OneTokenSoFar = [&]() {
-const UnwrappedLineNode *Tok = >Tokens.front(),
-*End = Tok + Line->Tokens.size();
-while (Tok != End && Tok->Tok->is(tok::comment))
-  ++Tok;
-// In Verilog, macro invocations start with a backtick which the code
-// treats as a hash.  Skip it.
-if (Style.isVerilog() && Tok != End && Tok->Tok->is(tok::hash))
-  ++Tok;
-return End - Tok == 1;
+auto I = Line->Tokens.begin(), E = Line->Tokens.end();
+while (I != E && I->Tok->is(tok::comment))
+  ++I;
+while (I != E && Style.isVerilog() && I->Tok->is(tok::hash))
+  ++I;
+return I != E && (++I == E);
   };
   if (OneTokenSoFar()) {
 if (FormatTok->is(tok::colon) && !Line->MustBeDeclaration) {



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 4dcfae6 - Fix a violated precondition in clang-format.

2021-12-01 Thread Manuel Klimek via cfe-commits

Author: Manuel Klimek
Date: 2021-12-01T14:39:00+01:00
New Revision: 4dcfae6a003aa541600e5af42c0bec5d8e1abef0

URL: 
https://github.com/llvm/llvm-project/commit/4dcfae6a003aa541600e5af42c0bec5d8e1abef0
DIFF: 
https://github.com/llvm/llvm-project/commit/4dcfae6a003aa541600e5af42c0bec5d8e1abef0.diff

LOG: Fix a violated precondition in clang-format.

Make sure we do not try to change line comments that are non-regular, i.e. do
not start with "//" or "#". This can for example happen when "//" is
broken into two lines with an escaped newline.

Added: 


Modified: 
clang/lib/Format/ContinuationIndenter.cpp
clang/unittests/Format/FormatTestComments.cpp

Removed: 




diff  --git a/clang/lib/Format/ContinuationIndenter.cpp 
b/clang/lib/Format/ContinuationIndenter.cpp
index f56b7c70d18e7..5073f5105d051 100644
--- a/clang/lib/Format/ContinuationIndenter.cpp
+++ b/clang/lib/Format/ContinuationIndenter.cpp
@@ -1984,11 +1984,17 @@ ContinuationIndenter::createBreakableToken(const 
FormatToken ,
   } else if (Current.is(TT_LineComment) &&
  (Current.Previous == nullptr ||
   Current.Previous->isNot(TT_ImplicitStringLiteral))) {
+bool RegularComments = [&]() {
+  for (const FormatToken *T =  T && T->is(TT_LineComment);
+   T = T->Next) {
+if (!(T->TokenText.startswith("//") || T->TokenText.startswith("#")))
+  return false;
+  }
+  return true;
+}();
 if (!Style.ReflowComments ||
 CommentPragmasRegex.match(Current.TokenText.substr(2)) ||
-switchesFormatting(Current) ||
-!(Current.TokenText.startswith("//") ||
-  Current.TokenText.startswith("#")))
+switchesFormatting(Current) || !RegularComments)
   return nullptr;
 return std::make_unique(
 Current, StartColumn, /*InPPDirective=*/false, Encoding, Style);

diff  --git a/clang/unittests/Format/FormatTestComments.cpp 
b/clang/unittests/Format/FormatTestComments.cpp
index 2a7ead62ba5b4..b5db353d4ae0a 100644
--- a/clang/unittests/Format/FormatTestComments.cpp
+++ b/clang/unittests/Format/FormatTestComments.cpp
@@ -3978,6 +3978,18 @@ TEST_F(FormatTestComments, SpaceAtLineCommentBegin) {
 format(Code, Style));
 }
 
+TEST_F(FormatTestComments, SplitCommentIntroducers) {
+  EXPECT_EQ(R"(//
+/\
+/
+)",
+format(R"(//
+/\
+/ 
+  )",
+   getLLVMStyleWithColumns(10)));
+}
+
 } // end namespace
 } // end namespace format
 } // end namespace clang



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] d688b31 - Fix segfault in clang-format.

2021-12-01 Thread Manuel Klimek via cfe-commits

Author: Manuel Klimek
Date: 2021-12-01T11:57:41+01:00
New Revision: d688b31628004ed9e109e63c2b43701f97252ff3

URL: 
https://github.com/llvm/llvm-project/commit/d688b31628004ed9e109e63c2b43701f97252ff3
DIFF: 
https://github.com/llvm/llvm-project/commit/d688b31628004ed9e109e63c2b43701f97252ff3.diff

LOG: Fix segfault in clang-format.

Fix bug where we'd read past the end of the tokens after merging _T
macro strings.

Added: 


Modified: 
clang/lib/Format/FormatTokenLexer.cpp
clang/unittests/Format/FormatTest.cpp

Removed: 




diff  --git a/clang/lib/Format/FormatTokenLexer.cpp 
b/clang/lib/Format/FormatTokenLexer.cpp
index 972f59ead5d8f..64fbd2d5d45b1 100644
--- a/clang/lib/Format/FormatTokenLexer.cpp
+++ b/clang/lib/Format/FormatTokenLexer.cpp
@@ -752,6 +752,8 @@ bool FormatTokenLexer::tryMerge_TMacro() {
   Tokens.pop_back();
   Tokens.pop_back();
   Tokens.back() = String;
+  if (FirstInLineIndex >= Tokens.size())
+FirstInLineIndex = Tokens.size() - 1;
   return true;
 }
 

diff  --git a/clang/unittests/Format/FormatTest.cpp 
b/clang/unittests/Format/FormatTest.cpp
index 65809ab5e7579..9b6607b46d93a 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -12879,6 +12879,12 @@ TEST_F(FormatTest, BreaksStringLiteralsWithin_TMacro) {
 format("f(\n"
"\n"
"_T(\"Xn\"));"));
+  // Regression test for accessing tokens past the end of a vector in the
+  // TokenLexer.
+  verifyNoCrash(R"(_T(
+"
+)
+)");
 }
 
 TEST_F(FormatTest, BreaksStringLiteralOperands) {



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 5978842 - Fix clang-format bug when handling conflict markers.

2021-12-01 Thread Manuel Klimek via cfe-commits

Author: Manuel Klimek
Date: 2021-12-01T11:23:04+01:00
New Revision: 59788422609433c50c3d3c16ca531fa56b9acb4f

URL: 
https://github.com/llvm/llvm-project/commit/59788422609433c50c3d3c16ca531fa56b9acb4f
DIFF: 
https://github.com/llvm/llvm-project/commit/59788422609433c50c3d3c16ca531fa56b9acb4f.diff

LOG: Fix clang-format bug when handling conflict markers.

Previously, clang-format would not correctly identify preprocessor
directives directly following a conflict marker, which would result in
violating the formatter's invariants.

The provided test fails in assert mode before this change.

Added: 


Modified: 
clang/lib/Format/UnwrappedLineParser.cpp
clang/unittests/Format/FormatTest.cpp

Removed: 




diff  --git a/clang/lib/Format/UnwrappedLineParser.cpp 
b/clang/lib/Format/UnwrappedLineParser.cpp
index da35648ef1ca0..a7e0422e3146c 100644
--- a/clang/lib/Format/UnwrappedLineParser.cpp
+++ b/clang/lib/Format/UnwrappedLineParser.cpp
@@ -3388,6 +3388,20 @@ void UnwrappedLineParser::readToken(int LevelDifference) 
{
   do {
 FormatTok = Tokens->getNextToken();
 assert(FormatTok);
+while (FormatTok->getType() == TT_ConflictStart ||
+   FormatTok->getType() == TT_ConflictEnd ||
+   FormatTok->getType() == TT_ConflictAlternative) {
+  if (FormatTok->getType() == TT_ConflictStart) {
+conditionalCompilationStart(/*Unreachable=*/false);
+  } else if (FormatTok->getType() == TT_ConflictAlternative) {
+conditionalCompilationAlternative();
+  } else if (FormatTok->getType() == TT_ConflictEnd) {
+conditionalCompilationEnd();
+  }
+  FormatTok = Tokens->getNextToken();
+  FormatTok->MustBreakBefore = true;
+}
+
 while (!Line->InPPDirective && FormatTok->Tok.is(tok::hash) &&
(FormatTok->HasUnescapedNewline || FormatTok->IsFirst)) {
   distributeComments(Comments, FormatTok);
@@ -3409,19 +3423,6 @@ void UnwrappedLineParser::readToken(int LevelDifference) 
{
   flushComments(isOnNewLine(*FormatTok));
   parsePPDirective();
 }
-while (FormatTok->getType() == TT_ConflictStart ||
-   FormatTok->getType() == TT_ConflictEnd ||
-   FormatTok->getType() == TT_ConflictAlternative) {
-  if (FormatTok->getType() == TT_ConflictStart) {
-conditionalCompilationStart(/*Unreachable=*/false);
-  } else if (FormatTok->getType() == TT_ConflictAlternative) {
-conditionalCompilationAlternative();
-  } else if (FormatTok->getType() == TT_ConflictEnd) {
-conditionalCompilationEnd();
-  }
-  FormatTok = Tokens->getNextToken();
-  FormatTok->MustBreakBefore = true;
-}
 
 if (!PPStack.empty() && (PPStack.back().Kind == PP_Unreachable) &&
 !Line->InPPDirective) {

diff  --git a/clang/unittests/Format/FormatTest.cpp 
b/clang/unittests/Format/FormatTest.cpp
index 39f1b835fb766..65809ab5e7579 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -21117,6 +21117,14 @@ TEST_F(FormatTest, HandleConflictMarkers) {
">>>\n"
"  End\n"
"int i;\n"));
+
+  verifyFormat(R"(
+#ifdef A
+a
+#else
+b
+#endif
+)");
 }
 
 TEST_F(FormatTest, DisableRegions) {



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 1b5a43a - Clean up clang-format tech debt.

2021-11-24 Thread Manuel Klimek via cfe-commits

Author: Manuel Klimek
Date: 2021-11-24T12:58:35+01:00
New Revision: 1b5a43ac3f1113cd0512752e021fc70740726698

URL: 
https://github.com/llvm/llvm-project/commit/1b5a43ac3f1113cd0512752e021fc70740726698
DIFF: 
https://github.com/llvm/llvm-project/commit/1b5a43ac3f1113cd0512752e021fc70740726698.diff

LOG: Clean up clang-format tech debt.

Make all code go through FormatTokenSource instead of going around it, which
makes changes to TokenSource brittle.

Add LLVM_DEBUG in FormatTokenSource to be able to follow the token stream.

Added: 


Modified: 
clang/lib/Format/UnwrappedLineParser.cpp

Removed: 




diff  --git a/clang/lib/Format/UnwrappedLineParser.cpp 
b/clang/lib/Format/UnwrappedLineParser.cpp
index c12c7c6ecfa69..12f912305f590 100644
--- a/clang/lib/Format/UnwrappedLineParser.cpp
+++ b/clang/lib/Format/UnwrappedLineParser.cpp
@@ -28,9 +28,28 @@ namespace format {
 class FormatTokenSource {
 public:
   virtual ~FormatTokenSource() {}
+
+  // Returns the next token in the token stream.
   virtual FormatToken *getNextToken() = 0;
 
+  // Returns the token precedint the token returned by the last call to
+  // getNextToken() in the token stream, or nullptr if no such token exists.
+  virtual FormatToken *getPreviousToken() = 0;
+
+  // Returns the token that would be returned by the next call to
+  // getNextToken().
+  virtual FormatToken *peekNextToken() = 0;
+
+  // Returns whether we are at the end of the file.
+  // This can be 
diff erent from whether getNextToken() returned an eof token
+  // when the FormatTokenSource is a view on a part of the token stream.
+  virtual bool isEOF() = 0;
+
+  // Gets the current position in the token stream, to be used by 
setPosition().
   virtual unsigned getPosition() = 0;
+
+  // Resets the token stream to the state it was in when getPosition() returned
+  // Position, and return the token at that position in the stream.
   virtual FormatToken *setPosition(unsigned Position) = 0;
 };
 
@@ -108,6 +127,18 @@ class ScopedMacroState : public FormatTokenSource {
 return Token;
   }
 
+  FormatToken *getPreviousToken() override {
+return PreviousTokenSource->getPreviousToken();
+  }
+
+  FormatToken *peekNextToken() override {
+if (eof())
+  return 
+return PreviousTokenSource->peekNextToken();
+  }
+
+  bool isEOF() override { return PreviousTokenSource->isEOF(); }
+
   unsigned getPosition() override { return PreviousTokenSource->getPosition(); 
}
 
   FormatToken *setPosition(unsigned Position) override {
@@ -199,18 +230,45 @@ class IndexedTokenSource : public FormatTokenSource {
   : Tokens(Tokens), Position(-1) {}
 
   FormatToken *getNextToken() override {
-if (Position >= 0 && Tokens[Position]->is(tok::eof))
+if (Position >= 0 && Tokens[Position]->is(tok::eof)) {
+  LLVM_DEBUG({
+llvm::dbgs() << "Next ";
+dbgToken(Position);
+  });
   return Tokens[Position];
+}
 ++Position;
+LLVM_DEBUG({
+  llvm::dbgs() << "Next ";
+  dbgToken(Position);
+});
 return Tokens[Position];
   }
 
+  FormatToken *getPreviousToken() override {
+assert(Position > 0);
+return Tokens[Position - 1];
+  }
+
+  FormatToken *peekNextToken() override {
+int Next = Position + 1;
+LLVM_DEBUG({
+  llvm::dbgs() << "Peeking ";
+  dbgToken(Next);
+});
+return Tokens[Next];
+  }
+
+  bool isEOF() override { return Tokens[Position]->is(tok::eof); }
+
   unsigned getPosition() override {
+LLVM_DEBUG(llvm::dbgs() << "Getting Position: " << Position << "\n");
 assert(Position >= 0);
 return Position;
   }
 
   FormatToken *setPosition(unsigned P) override {
+LLVM_DEBUG(llvm::dbgs() << "Setting Position: " << P << "\n");
 Position = P;
 return Tokens[Position];
   }
@@ -218,6 +276,13 @@ class IndexedTokenSource : public FormatTokenSource {
   void reset() { Position = -1; }
 
 private:
+  void dbgToken(int Position, llvm::StringRef Indent = "") {
+FormatToken *Tok = Tokens[Position];
+llvm::dbgs() << Indent << "[" << Position
+ << "] Token: " << Tok->Tok.getName() << " / " << 
Tok->TokenText
+ << ", Macro: " << !!Tok->MacroCtx << "\n";
+  }
+
   ArrayRef Tokens;
   int Position;
 };
@@ -877,10 +942,7 @@ void UnwrappedLineParser::parsePPEndIf() {
   parsePPUnknown();
   // If the #endif of a potential include guard is the last thing in the file,
   // then we found an include guard.
-  unsigned TokenPosition = Tokens->getPosition();
-  FormatToken *PeekNext = AllTokens[TokenPosition];
-  if (IncludeGuard == IG_Defined && PPBranchLevel == -1 &&
-  PeekNext->is(tok::eof) &&
+  if (IncludeGuard == IG_Defined && PPBranchLevel == -1 && Tokens->isEOF() &&
   Style.IndentPPDirectives != FormatStyle::PPDIS_None)
 IncludeGuard = IG_Found;
 }
@@ -1403,9 +1465,7 @@ void UnwrappedLineParser::parseStructuralElement(bool 
IsTopLevel) 

[clang] 84bf5e3 - Fix various problems found by fuzzing.

2021-11-22 Thread Manuel Klimek via cfe-commits

Author: Manuel Klimek
Date: 2021-11-22T11:08:38+01:00
New Revision: 84bf5e328664db2e744c4651c52d2460b1733d09

URL: 
https://github.com/llvm/llvm-project/commit/84bf5e328664db2e744c4651c52d2460b1733d09
DIFF: 
https://github.com/llvm/llvm-project/commit/84bf5e328664db2e744c4651c52d2460b1733d09.diff

LOG: Fix various problems found by fuzzing.

1. IndexTokenSource::getNextToken cannot return nullptr; some code was
still written assuming it can; make getNextToken more resilient against
incorrect input and fix its call-sites.

2. Change various asserts that can happen due to user provided input to
conditionals in the code.

Added: 


Modified: 
clang/lib/Format/ContinuationIndenter.cpp
clang/lib/Format/TokenAnnotator.cpp
clang/lib/Format/UnwrappedLineParser.cpp
clang/lib/Format/WhitespaceManager.cpp

Removed: 




diff  --git a/clang/lib/Format/ContinuationIndenter.cpp 
b/clang/lib/Format/ContinuationIndenter.cpp
index 1e4f5690ef241..f56b7c70d18e7 100644
--- a/clang/lib/Format/ContinuationIndenter.cpp
+++ b/clang/lib/Format/ContinuationIndenter.cpp
@@ -1986,7 +1986,9 @@ ContinuationIndenter::createBreakableToken(const 
FormatToken ,
   Current.Previous->isNot(TT_ImplicitStringLiteral))) {
 if (!Style.ReflowComments ||
 CommentPragmasRegex.match(Current.TokenText.substr(2)) ||
-switchesFormatting(Current))
+switchesFormatting(Current) ||
+!(Current.TokenText.startswith("//") ||
+  Current.TokenText.startswith("#")))
   return nullptr;
 return std::make_unique(
 Current, StartColumn, /*InPPDirective=*/false, Encoding, Style);
@@ -2195,11 +2197,10 @@ ContinuationIndenter::breakProtrudingToken(const 
FormatToken ,
   // When breaking before a tab character, it may be moved by a few 
columns,
   // but will still be expanded to the next tab stop, so we don't save any
   // columns.
-  if (NewRemainingTokenColumns == RemainingTokenColumns) {
+  if (NewRemainingTokenColumns >= RemainingTokenColumns) {
 // FIXME: Do we need to adjust the penalty?
 break;
   }
-  assert(NewRemainingTokenColumns < RemainingTokenColumns);
 
   LLVM_DEBUG(llvm::dbgs() << "Breaking at: " << TailOffset + 
Split.first
   << ", " << Split.second << "\n");

diff  --git a/clang/lib/Format/TokenAnnotator.cpp 
b/clang/lib/Format/TokenAnnotator.cpp
index 3897241cb8589..f3f63b4cad234 100644
--- a/clang/lib/Format/TokenAnnotator.cpp
+++ b/clang/lib/Format/TokenAnnotator.cpp
@@ -946,11 +946,15 @@ class AnnotatingParser {
  !Line.First->isOneOf(tok::kw_enum, tok::kw_case,
   tok::kw_default)) {
 FormatToken *Prev = Tok->getPreviousNonComment();
+if (!Prev)
+  break;
 if (Prev->isOneOf(tok::r_paren, tok::kw_noexcept))
   Tok->setType(TT_CtorInitializerColon);
 else if (Prev->is(tok::kw_try)) {
   // Member initializer list within function try block.
   FormatToken *PrevPrev = Prev->getPreviousNonComment();
+  if (!PrevPrev)
+break;
   if (PrevPrev && PrevPrev->isOneOf(tok::r_paren, tok::kw_noexcept))
 Tok->setType(TT_CtorInitializerColon);
 } else
@@ -1578,6 +1582,8 @@ class AnnotatingParser {
 if (TemplateCloser->is(tok::l_paren)) {
   // No Matching Paren yet so skip to matching paren
   TemplateCloser = untilMatchingParen(TemplateCloser);
+  if (!TemplateCloser)
+break;
 }
 if (TemplateCloser->is(tok::less))
   NestingLevel++;
@@ -2639,8 +2645,8 @@ void 
TokenAnnotator::calculateFormattingInformation(AnnotatedLine ) {
 if (Current->Role)
   Current->Role->precomputeFormattingInfos(Current);
 if (Current->MatchingParen &&
-Current->MatchingParen->opensBlockOrBlockTypeList(Style)) {
-  assert(IndentLevel > 0);
+Current->MatchingParen->opensBlockOrBlockTypeList(Style) &&
+IndentLevel > 0) {
   --IndentLevel;
 }
 Current->IndentLevel = IndentLevel;

diff  --git a/clang/lib/Format/UnwrappedLineParser.cpp 
b/clang/lib/Format/UnwrappedLineParser.cpp
index 28d925858f776..c12c7c6ecfa69 100644
--- a/clang/lib/Format/UnwrappedLineParser.cpp
+++ b/clang/lib/Format/UnwrappedLineParser.cpp
@@ -199,6 +199,8 @@ class IndexedTokenSource : public FormatTokenSource {
   : Tokens(Tokens), Position(-1) {}
 
   FormatToken *getNextToken() override {
+if (Position >= 0 && Tokens[Position]->is(tok::eof))
+  return Tokens[Position];
 ++Position;
 return Tokens[Position];
   }
@@ -399,7 +401,7 @@ void UnwrappedLineParser::parseLevel(bool HasOpeningBrace) {
   FormatToken *Next;
   do {
 Next = Tokens->getNextToken();
-  } while (Next && Next->is(tok::comment));
+  } while (Next->is(tok::comment));

[clang] c227192 - Make clang-format fuzz through Lexing with asserts enabled.

2021-11-19 Thread Manuel Klimek via cfe-commits

Author: Manuel Klimek
Date: 2021-11-19T14:44:06+01:00
New Revision: c2271926a4fc395e05cf75a8e57c2dfab1f02d3d

URL: 
https://github.com/llvm/llvm-project/commit/c2271926a4fc395e05cf75a8e57c2dfab1f02d3d
DIFF: 
https://github.com/llvm/llvm-project/commit/c2271926a4fc395e05cf75a8e57c2dfab1f02d3d.diff

LOG: Make clang-format fuzz through Lexing with asserts enabled.

Makes clang-format bail out if an in-memory source file with an
unsupported BOM is handed in instead of creating source locations that
are violating clang's assumptions.

In the future, we should add support to better transport error messages
like this through clang-format instead of printing to stderr and not
creating any changes.

Added: 


Modified: 
clang/lib/Format/Format.cpp
clang/lib/Format/QualifierAlignmentFixer.cpp
clang/lib/Format/SortJavaScriptImports.cpp
clang/lib/Format/TokenAnalyzer.cpp
clang/lib/Format/TokenAnalyzer.h

Removed: 




diff  --git a/clang/lib/Format/Format.cpp b/clang/lib/Format/Format.cpp
index 1d60f2b3a321b..085cca8853e62 100644
--- a/clang/lib/Format/Format.cpp
+++ b/clang/lib/Format/Format.cpp
@@ -2989,8 +2989,10 @@ reformat(const FormatStyle , StringRef Code,
   if (Style.isJson()) {
 std::vector Ranges(1, tooling::Range(0, Code.size()));
 auto Env =
-std::make_unique(Code, FileName, Ranges, FirstStartColumn,
+Environment::make(Code, FileName, Ranges, FirstStartColumn,
   NextStartColumn, LastStartColumn);
+if (!Env)
+  return {};
 // Perform the actual formatting pass.
 tooling::Replacements Replaces =
 Formatter(*Env, Style, Status).process().first;
@@ -3046,9 +3048,10 @@ reformat(const FormatStyle , StringRef Code,
   return TrailingCommaInserter(Env, Expanded).process();
 });
 
-  auto Env =
-  std::make_unique(Code, FileName, Ranges, FirstStartColumn,
-NextStartColumn, LastStartColumn);
+  auto Env = Environment::make(Code, FileName, Ranges, FirstStartColumn,
+   NextStartColumn, LastStartColumn);
+  if (!Env)
+return {};
   llvm::Optional CurrentCode = None;
   tooling::Replacements Fixes;
   unsigned Penalty = 0;
@@ -3061,10 +3064,12 @@ reformat(const FormatStyle , StringRef Code,
   Penalty += PassFixes.second;
   if (I + 1 < E) {
 CurrentCode = std::move(*NewCode);
-Env = std::make_unique(
+Env = Environment::make(
 *CurrentCode, FileName,
 tooling::calculateRangesAfterReplacements(Fixes, Ranges),
 FirstStartColumn, NextStartColumn, LastStartColumn);
+if (!Env)
+  return {};
   }
 }
   }
@@ -3090,7 +3095,10 @@ tooling::Replacements cleanup(const FormatStyle , 
StringRef Code,
   // cleanups only apply to C++ (they mostly concern ctor commas etc.)
   if (Style.Language != FormatStyle::LK_Cpp)
 return tooling::Replacements();
-  return Cleaner(Environment(Code, FileName, Ranges), Style).process().first;
+  auto Env = Environment::make(Code, FileName, Ranges);
+  if (!Env)
+return {};
+  return Cleaner(*Env, Style).process().first;
 }
 
 tooling::Replacements reformat(const FormatStyle , StringRef Code,
@@ -3107,7 +3115,10 @@ tooling::Replacements fixNamespaceEndComments(const 
FormatStyle ,
   StringRef Code,
   ArrayRef Ranges,
   StringRef FileName) {
-  return NamespaceEndCommentsFixer(Environment(Code, FileName, Ranges), Style)
+  auto Env = Environment::make(Code, FileName, Ranges);
+  if (!Env)
+return {};
+  return NamespaceEndCommentsFixer(*Env, Style)
   .process()
   .first;
 }
@@ -3116,7 +3127,10 @@ tooling::Replacements sortUsingDeclarations(const 
FormatStyle ,
 StringRef Code,
 ArrayRef Ranges,
 StringRef FileName) {
-  return UsingDeclarationsSorter(Environment(Code, FileName, Ranges), Style)
+  auto Env = Environment::make(Code, FileName, Ranges);
+  if (!Env)
+return {};
+  return UsingDeclarationsSorter(*Env, Style)
   .process()
   .first;
 }

diff  --git a/clang/lib/Format/QualifierAlignmentFixer.cpp 
b/clang/lib/Format/QualifierAlignmentFixer.cpp
index c70705a1cd7ff..5a89225c7fc86 100644
--- a/clang/lib/Format/QualifierAlignmentFixer.cpp
+++ b/clang/lib/Format/QualifierAlignmentFixer.cpp
@@ -61,10 +61,10 @@ QualifierAlignmentFixer::QualifierAlignmentFixer(
 std::pair QualifierAlignmentFixer::analyze(
 TokenAnnotator , SmallVectorImpl 
,
 FormatTokenLexer ) {
-
-  auto Env =
-  std::make_unique(Code, FileName, Ranges, FirstStartColumn,
-NextStartColumn, LastStartColumn);
+  auto Env = 

[clang] e336b74 - [clang-format] Add a MacroExpander.

2020-09-25 Thread Manuel Klimek via cfe-commits

Author: Manuel Klimek
Date: 2020-09-25T14:08:13+02:00
New Revision: e336b74c995d665bc3fb75164375bbb0f78f516c

URL: 
https://github.com/llvm/llvm-project/commit/e336b74c995d665bc3fb75164375bbb0f78f516c
DIFF: 
https://github.com/llvm/llvm-project/commit/e336b74c995d665bc3fb75164375bbb0f78f516c.diff

LOG: [clang-format] Add a MacroExpander.

Summary:
The MacroExpander allows to expand simple (non-resursive) macro
definitions from a macro identifier token and macro arguments. It
annotates the tokens with a newly introduced MacroContext that keeps
track of the role a token played in expanding the macro in order to
be able to reconstruct the macro expansion from an expanded (formatted)
token stream.

Made Token explicitly copy-able to enable copying tokens from the parsed
macro definition.

Reviewers: sammccall

Subscribers: mgorny, cfe-commits

Tags: #clang

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

Added: 
clang/lib/Format/MacroExpander.cpp
clang/lib/Format/Macros.h
clang/unittests/Format/MacroExpanderTest.cpp
clang/unittests/Format/TestLexer.h

Modified: 
clang/lib/Format/CMakeLists.txt
clang/lib/Format/FormatToken.h
clang/unittests/Format/CMakeLists.txt

Removed: 




diff  --git a/clang/lib/Format/CMakeLists.txt b/clang/lib/Format/CMakeLists.txt
index 0019d045cd06..ec1522db7e87 100644
--- a/clang/lib/Format/CMakeLists.txt
+++ b/clang/lib/Format/CMakeLists.txt
@@ -7,6 +7,7 @@ add_clang_library(clangFormat
   Format.cpp
   FormatToken.cpp
   FormatTokenLexer.cpp
+  MacroExpander.cpp
   NamespaceEndCommentsFixer.cpp
   SortJavaScriptImports.cpp
   TokenAnalyzer.cpp

diff  --git a/clang/lib/Format/FormatToken.h b/clang/lib/Format/FormatToken.h
index 76ef99e72d58..c6af71a768a1 100644
--- a/clang/lib/Format/FormatToken.h
+++ b/clang/lib/Format/FormatToken.h
@@ -136,6 +136,68 @@ enum ParameterPackingKind { PPK_BinPacked, PPK_OnePerLine, 
PPK_Inconclusive };
 
 enum FormatDecision { FD_Unformatted, FD_Continue, FD_Break };
 
+/// Roles a token can take in a configured macro expansion.
+enum MacroRole {
+  /// The token was expanded from a macro argument when formatting the expanded
+  /// token sequence.
+  MR_ExpandedArg,
+  /// The token is part of a macro argument that was previously formatted as
+  /// expansion when formatting the unexpanded macro call.
+  MR_UnexpandedArg,
+  /// The token was expanded from a macro definition, and is not visible as 
part
+  /// of the macro call.
+  MR_Hidden,
+};
+
+struct FormatToken;
+
+/// Contains information on the token's role in a macro expansion.
+///
+/// Given the following definitions:
+/// A(X) = [ X ]
+/// B(X) = < X >
+/// C(X) = X
+///
+/// Consider the macro call:
+/// A({B(C(C(x)))}) -> [{}]
+///
+/// In this case, the tokens of the unexpanded macro call will have the
+/// following relevant entries in their macro context (note that formatting
+/// the unexpanded macro call happens *after* formatting the expanded macro
+/// call):
+///   A( { B( C( C(x) ) ) } )
+/// Role: NN U NN NN NNUN N N U N  (N=None, U=UnexpandedArg)
+///
+///   [  { <   x> } ]
+/// Role: H  E H   EH E H  (H=Hidden, E=ExpandedArg)
+/// ExpandedFrom[0]:  A  A A   AA A A
+/// ExpandedFrom[1]:   B   BB
+/// ExpandedFrom[2]:   C
+/// ExpandedFrom[3]:   C
+/// StartOfExpansion: 1  0 1   20 0 0
+/// EndOfExpansion:   0  0 0   21 0 1
+struct MacroExpansion {
+  MacroExpansion(MacroRole Role) : Role(Role) {}
+
+  /// The token's role in the macro expansion.
+  /// When formatting an expanded macro, all tokens that are part of macro
+  /// arguments will be MR_ExpandedArg, while all tokens that are not visible 
in
+  /// the macro call will be MR_Hidden.
+  /// When formatting an unexpanded macro call, all tokens that are part of
+  /// macro arguments will be MR_UnexpandedArg.
+  MacroRole Role;
+
+  /// The stack of macro call identifier tokens this token was expanded from.
+  llvm::SmallVector ExpandedFrom;
+
+  /// The number of expansions of which this macro is the first entry.
+  unsigned StartOfExpansion = 0;
+
+  /// The number of currently open expansions in \c ExpandedFrom this macro is
+  /// the last token in.
+  unsigned EndOfExpansion = 0;
+};
+
 class TokenRole;
 class AnnotatedLine;
 
@@ -163,7 +225,9 @@ struct FormatToken {
 
   /// A token can have a special role that can carry extra information
   /// about the token's formatting.
-  std::unique_ptr Role;
+  /// FIXME: Make FormatToken for parsing and AnnotatedToken two 
diff erent
+  /// classes and make this a unique_ptr in the AnnotatedToken class.
+  std::shared_ptr Role;
 
   /// The range of the whitespace immediately preceding the \c Token.
   SourceRange WhitespaceRange;
@@ -378,6 +442,10 @@ struct FormatToken {
   /// in it.
   SmallVector Children;
 
+  // 

[clang] 8c2a613 - Hand Allocator and IdentifierTable into FormatTokenLexer.

2020-07-07 Thread Manuel Klimek via cfe-commits

Author: Manuel Klimek
Date: 2020-07-07T11:56:34+02:00
New Revision: 8c2a613976075368a1f6e3ac3c9c8b1927b465ec

URL: 
https://github.com/llvm/llvm-project/commit/8c2a613976075368a1f6e3ac3c9c8b1927b465ec
DIFF: 
https://github.com/llvm/llvm-project/commit/8c2a613976075368a1f6e3ac3c9c8b1927b465ec.diff

LOG: Hand Allocator and IdentifierTable into FormatTokenLexer.

This allows us to share the allocator in the future so we can create tokens 
while parsing.

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

Added: 


Modified: 
clang/lib/Format/FormatTokenLexer.cpp
clang/lib/Format/FormatTokenLexer.h
clang/lib/Format/TokenAnalyzer.cpp

Removed: 




diff  --git a/clang/lib/Format/FormatTokenLexer.cpp 
b/clang/lib/Format/FormatTokenLexer.cpp
index dbbe6f814ace..1fd153d1112e 100644
--- a/clang/lib/Format/FormatTokenLexer.cpp
+++ b/clang/lib/Format/FormatTokenLexer.cpp
@@ -22,13 +22,15 @@
 namespace clang {
 namespace format {
 
-FormatTokenLexer::FormatTokenLexer(const SourceManager , FileID ID,
-   unsigned Column, const FormatStyle ,
-   encoding::Encoding Encoding)
+FormatTokenLexer::FormatTokenLexer(
+const SourceManager , FileID ID, unsigned Column,
+const FormatStyle , encoding::Encoding Encoding,
+llvm::SpecificBumpPtrAllocator ,
+IdentifierTable )
 : FormatTok(nullptr), IsFirstToken(true), StateStack({LexerState::NORMAL}),
   Column(Column), TrailingWhitespace(0), SourceMgr(SourceMgr), ID(ID),
-  Style(Style), IdentTable(getFormattingLangOpts(Style)),
-  Keywords(IdentTable), Encoding(Encoding), FirstInLineIndex(0),
+  Style(Style), IdentTable(IdentTable), Keywords(IdentTable),
+  Encoding(Encoding), Allocator(Allocator), FirstInLineIndex(0),
   FormattingDisabled(false), MacroBlockBeginRegex(Style.MacroBlockBegin),
   MacroBlockEndRegex(Style.MacroBlockEnd) {
   Lex.reset(new Lexer(ID, SourceMgr.getBuffer(ID), SourceMgr,

diff  --git a/clang/lib/Format/FormatTokenLexer.h 
b/clang/lib/Format/FormatTokenLexer.h
index 219cd46f98ed..6b08677e3369 100644
--- a/clang/lib/Format/FormatTokenLexer.h
+++ b/clang/lib/Format/FormatTokenLexer.h
@@ -38,7 +38,9 @@ enum LexerState {
 class FormatTokenLexer {
 public:
   FormatTokenLexer(const SourceManager , FileID ID, unsigned Column,
-   const FormatStyle , encoding::Encoding Encoding);
+   const FormatStyle , encoding::Encoding Encoding,
+   llvm::SpecificBumpPtrAllocator ,
+   IdentifierTable );
 
   ArrayRef lex();
 
@@ -103,10 +105,10 @@ class FormatTokenLexer {
   const SourceManager 
   FileID ID;
   const FormatStyle 
-  IdentifierTable IdentTable;
+  IdentifierTable 
   AdditionalKeywords Keywords;
   encoding::Encoding Encoding;
-  llvm::SpecificBumpPtrAllocator Allocator;
+  llvm::SpecificBumpPtrAllocator 
   // Index (in 'Tokens') of the last token that starts a new line.
   unsigned FirstInLineIndex;
   SmallVector Tokens;

diff  --git a/clang/lib/Format/TokenAnalyzer.cpp 
b/clang/lib/Format/TokenAnalyzer.cpp
index eb98a205d526..f1459a808ff8 100644
--- a/clang/lib/Format/TokenAnalyzer.cpp
+++ b/clang/lib/Format/TokenAnalyzer.cpp
@@ -64,11 +64,16 @@ TokenAnalyzer::TokenAnalyzer(const Environment , const 
FormatStyle )
 
 std::pair TokenAnalyzer::process() {
   tooling::Replacements Result;
-  FormatTokenLexer Tokens(Env.getSourceManager(), Env.getFileID(),
-  Env.getFirstStartColumn(), Style, Encoding);
+  llvm::SpecificBumpPtrAllocator Allocator;
+  IdentifierTable IdentTable(getFormattingLangOpts(Style));
+  FormatTokenLexer Lex(Env.getSourceManager(), Env.getFileID(),
+   Env.getFirstStartColumn(), Style, Encoding, Allocator,
 
-  UnwrappedLineParser Parser(Style, Tokens.getKeywords(),
- Env.getFirstStartColumn(), Tokens.lex(), *this);
+   IdentTable);
+  ArrayRef Toks(Lex.lex());
+  SmallVector Tokens(Toks.begin(), Toks.end());
+  UnwrappedLineParser Parser(Style, Lex.getKeywords(),
+ Env.getFirstStartColumn(), Tokens, *this);
   Parser.parse();
   assert(UnwrappedLines.rbegin()->empty());
   unsigned Penalty = 0;
@@ -76,14 +81,14 @@ std::pair 
TokenAnalyzer::process() {
 LLVM_DEBUG(llvm::dbgs() << "Run " << Run << "...\n");
 SmallVector AnnotatedLines;
 
-TokenAnnotator Annotator(Style, Tokens.getKeywords());
+TokenAnnotator Annotator(Style, Lex.getKeywords());
 for (unsigned i = 0, e = UnwrappedLines[Run].size(); i != e; ++i) {
   AnnotatedLines.push_back(new AnnotatedLine(UnwrappedLines[Run][i]));
   Annotator.annotate(*AnnotatedLines.back());
 }
 
 std::pair RunResult =
-analyze(Annotator, AnnotatedLines, Tokens);
+analyze(Annotator, AnnotatedLines, Lex);
 
 LLVM_DEBUG({
   llvm::dbgs() << 

[clang] 53cc90f - Make FormatToken::Type private.

2020-05-13 Thread Manuel Klimek via cfe-commits

Author: Manuel Klimek
Date: 2020-05-13T16:37:58+02:00
New Revision: 53cc90f789996d1e1edc6a9233a85ce8d658aadd

URL: 
https://github.com/llvm/llvm-project/commit/53cc90f789996d1e1edc6a9233a85ce8d658aadd
DIFF: 
https://github.com/llvm/llvm-project/commit/53cc90f789996d1e1edc6a9233a85ce8d658aadd.diff

LOG: Make FormatToken::Type private.

This enables us to intercept changes to the token type via setType(), which
is a precondition for being able to use multi-pass formatting for macro
arguments.

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

Added: 


Modified: 
clang/lib/Format/Format.cpp
clang/lib/Format/FormatToken.cpp
clang/lib/Format/FormatToken.h
clang/lib/Format/FormatTokenLexer.cpp
clang/lib/Format/TokenAnnotator.cpp
clang/lib/Format/UnwrappedLineParser.cpp

Removed: 




diff  --git a/clang/lib/Format/Format.cpp b/clang/lib/Format/Format.cpp
index 655df7e45ba7..2e39b03563ae 100644
--- a/clang/lib/Format/Format.cpp
+++ b/clang/lib/Format/Format.cpp
@@ -1914,7 +1914,7 @@ class ObjCHeaderStyleGuesser : public TokenAnalyzer {
  << FormatTok->Tok.getLocation().printToString(
 SourceManager)
  << " token: " << FormatTok->TokenText << " token type: "
- << getTokenTypeName(FormatTok->Type) << "\n");
+ << getTokenTypeName(FormatTok->getType()) << "\n");
   return true;
 }
 if (guessIsObjC(SourceManager, Line->Children, Keywords))

diff  --git a/clang/lib/Format/FormatToken.cpp 
b/clang/lib/Format/FormatToken.cpp
index 90d09064bb43..ee35f3afae37 100644
--- a/clang/lib/Format/FormatToken.cpp
+++ b/clang/lib/Format/FormatToken.cpp
@@ -84,8 +84,8 @@ unsigned CommaSeparatedList::formatAfterToken(LineState 
,
   const FormatToken *LBrace =
   State.NextToken->Previous->getPreviousNonComment();
   if (!LBrace || !LBrace->isOneOf(tok::l_brace, TT_ArrayInitializerLSquare) ||
-  LBrace->BlockKind == BK_Block || LBrace->Type == TT_DictLiteral ||
-  LBrace->Next->Type == TT_DesignatedInitializerPeriod)
+  LBrace->BlockKind == BK_Block || LBrace->getType() == TT_DictLiteral ||
+  LBrace->Next->getType() == TT_DesignatedInitializerPeriod)
 return 0;
 
   // Calculate the number of code points we have to format this list. As the

diff  --git a/clang/lib/Format/FormatToken.h b/clang/lib/Format/FormatToken.h
index c67cf192ab1f..7b6b1e8ddce7 100644
--- a/clang/lib/Format/FormatToken.h
+++ b/clang/lib/Format/FormatToken.h
@@ -113,6 +113,8 @@ namespace format {
   TYPE(CSharpGenericTypeConstraintComma)   
\
   TYPE(Unknown)
 
+/// Determines the semantic type of a syntactic token, e.g. whether "<" is a
+/// template opener or binary operator.
 enum TokenType {
 #define TYPE(X) TT_##X,
   LIST_TOKEN_TYPES
@@ -192,7 +194,10 @@ struct FormatToken {
   /// Contains the kind of block if this token is a brace.
   BraceBlockKind BlockKind = BK_Unknown;
 
-  TokenType Type = TT_Unknown;
+  /// Returns the token's type, e.g. whether "<" is a template opener or
+  /// binary operator.
+  TokenType getType() const { return Type; }
+  void setType(TokenType T) { Type = T; }
 
   /// The number of spaces that should be inserted before this token.
   unsigned SpacesRequiredBefore = 0;
@@ -590,6 +595,8 @@ struct FormatToken {
   return Previous->endsSequenceInternal(K1, Tokens...);
 return is(K1) && Previous && Previous->endsSequenceInternal(Tokens...);
   }
+
+  TokenType Type = TT_Unknown;
 };
 
 class ContinuationIndenter;

diff  --git a/clang/lib/Format/FormatTokenLexer.cpp 
b/clang/lib/Format/FormatTokenLexer.cpp
index 9e081e1495d0..249d3ac39c3e 100644
--- a/clang/lib/Format/FormatTokenLexer.cpp
+++ b/clang/lib/Format/FormatTokenLexer.cpp
@@ -158,7 +158,7 @@ bool FormatTokenLexer::tryMergeNSStringLiteral() {
   At->TokenText = StringRef(At->TokenText.begin(),
 String->TokenText.end() - At->TokenText.begin());
   At->ColumnWidth += String->ColumnWidth;
-  At->Type = TT_ObjCStringLiteral;
+  At->setType(TT_ObjCStringLiteral);
   Tokens.erase(Tokens.end() - 1);
   return true;
 }
@@ -177,7 +177,7 @@ bool FormatTokenLexer::tryMergeJSPrivateIdentifier() {
   StringRef(Hash->TokenText.begin(),
 Identifier->TokenText.end() - Hash->TokenText.begin());
   Hash->ColumnWidth += Identifier->ColumnWidth;
-  Hash->Type = TT_JsPrivateIdentifier;
+  Hash->setType(TT_JsPrivateIdentifier);
   Tokens.erase(Tokens.end() - 1);
   return true;
 }
@@ -201,7 +201,7 @@ bool FormatTokenLexer::tryMergeCSharpStringLiteral() {
   // would require similar work as that done for JavaScript template strings
   // in `handleTemplateStrings()`.
   auto  = *(Tokens.end() - 2);
-  if (CSharpInterpolatedString->Type == TT_CSharpStringLiteral &&
+  if (CSharpInterpolatedString->getType() == TT_CSharpStringLiteral 

Re: [PATCH] D28462: clang-format: Add new style option AlignConsecutiveMacros

2019-05-10 Thread Manuel Klimek via cfe-commits
*From: *MyDeveloperDay via Phabricator 
*Date: *Fri, May 10, 2019 at 12:30 PM
*To: * , , , <
krasi...@google.com>, , 
*Cc: * , , , <
marcosbe...@gmail.com>, , , <
shua2...@gmail.com>, , , <
vit9...@avp.su>, , , <
mydeveloper...@gmail.com>, , <
bderickson+llvm...@gmail.com>, , <
vee...@veegee.org>, , , <
up752...@myport.ac.uk>, , ,
, , , <
jorisae...@gmail.com>, , , <
llvm-comm...@lists.llvm.org>, , , <
zarevucky.j...@gmail.com>, , ,
, , 

MyDeveloperDay added a comment.
>
> When I spoke with one of the code owners, they seemed to have a problem
> accepting this review based on there not being a general
> description/understanding of how this algorithm works.
>
> Having said that, all of the "AlignToken" based functions
> (alignConsecutive) are hard to understand unless you take the
> AlignTokens() function as read, and just look at the Lambda.
>
> As a relative new comer, I find some areas of clang-format hard to
> understand, I tend to learn them as and when I need to, but the gist of
> AlignTokens is in its comment, but with comments like 'There is a
> non-obvious subtlety' probably means you really need to be in it and inside
> a debugger to see what is going on.
>
> For this review I actually don't personally see what is Macro specific
> about AlignMacroSequence(), it seems to be almost identical to
> AlignTokenSequence without the scope and comment handling, (which actually
> makes it  a lot simpler), my feeling is it could be used for more than just
> this, maybe pulling this out into its own set of functions wasn't the
> correct thing to do, and actually the original design might have been
> better, but this solution seems more simplistic and because its isolated
> means it doesn't break the other functions.
>
> All I feel I can add to the review process, is that perhaps a few more
> comments explaining the subtlety of the various "if statements" in both the
> Lambda and in the main alignment might help bring some clarify..


That is basically what I thought.


> but to be honest I'm OK with how it works and I'd like it in.
>
> Ultimately I'd also like to see this revision land, especially as its off
> by default, I would like to see some ability to be able to set a Minimum
> Column distance to the value (this would allow Visual Studio to not keep
> playing the hokey-cokey (https://en.wikipedia.org/wiki/Hokey_cokey)  with
> resource.h files.), but perhaps that is for a later change once this is
> accepted.
>
> From my perspective it LGTM, if the code owners are present they should
> really rubber stamp it, If not well...
>

If you believe you understand this code well enough to LG it, I'm fine with
it going in. I think we need one reviewer spending enough to time
understand why the code is the way it is, and given the quality of code
I've seen from you, I do trust your ability to understand code :)


>
>
> CHANGES SINCE LAST ACTION
>   https://reviews.llvm.org/D28462/new/
>
> https://reviews.llvm.org/D28462
>
>
>
>
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D49840: [AST] Add MatchFinder::matchSubtree

2018-08-27 Thread Manuel Klimek via cfe-commits
On Mon, Aug 6, 2018 at 4:47 PM Gabor Marton via Phabricator <
revi...@reviews.llvm.org> wrote:

> martong added a comment.
>
> Ping.
>
> Manuel, I still don't see how could we apply `match(anyOf(node),
> hasDescendant(node))` to the problem of general subtree traversal.
> (I'd like to have support for not just `decl()` but other kind of nodes
> too.)
>
Could you please advise how to move on? Also, could you please describe
> your specific technical arguments against this patch?
>

I'm still trying to understand why it's a good idea :) The general
technical argument why I'm asking all these questions is that we shouldn't
add new things unless they provide significant new features.
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D49840: [AST] Add MatchFinder::matchSubtree

2018-07-30 Thread Manuel Klimek via cfe-commits
On Mon, Jul 30, 2018 at 10:02 AM Stephen Kelly via Phabricator <
revi...@reviews.llvm.org> wrote:

> steveire added a comment.
>
> In https://reviews.llvm.org/D49840#1176405, @klimek wrote:
>
> > Usually we use match(anyOf(node), hasDescendant(node)). Or did I
> misunderstand what you want?
>
>
> See http://lists.llvm.org/pipermail/cfe-dev/2018-July/058625.html for a
> bug that prevents this working.
>

Answered on the bug. I don't think that applies here.
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D49840: [AST] Add MatchFinder::matchSubtree

2018-07-27 Thread Manuel Klimek via cfe-commits
On Fri, Jul 27, 2018 at 12:43 PM Gabor Marton via Phabricator <
revi...@reviews.llvm.org> wrote:

> martong added a comment.
>
> > Finder.match also has an overload that takes the node. Can you wrap
> "Pattern" above in the anyOf(hasDescendant(...), ...) and match on the node
> instead of the full AST?
>
> Ok, I changed and wrapped the pattern:
>
>   template 
>   NodeType *match(const Decl *D, const MatcherType ) {
> MatchFinder Finder;
> auto WrappedMatcher = anyOf(AMatcher.bind(""),
> hasDescendant(AMatcher.bind("")));
> Finder.addMatcher(WrappedMatcher, this);
> // ...
>   }
>

If you know the node is a decl, wrapping it in decl() should be enough.
Does this work?
auto WrappedMatcher = decl(anyOf(...));
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D49840: [AST] Add MatchFinder::matchSubtree

2018-07-27 Thread Manuel Klimek via cfe-commits
On Fri, Jul 27, 2018 at 10:39 AM Gabor Marton via Phabricator <
revi...@reviews.llvm.org> wrote:

> martong added a comment.
>
> > MatchFinder::match allows you to match a node. Wrapping your matcher
> code with:
> >  auto m = ;
> >  ast_matchers::match(anyOf(m, hashDescendant(m)), node, context);
>
> Okay, I understand and accept that.
> However, I consider that a different level of abstraction.
> `ast_matchers::match` uses `internal::CollectMatchesCallback` in its
> implementation. If I already have my own custom MatchCallback implemented
> then there is no way to achieve the desired behavior.
>
> For example, in `ASTImporter` tests we use the following customized
> callback class:
>
>   enum class DeclMatcherKind { First, Last };
>
>   // Matcher class to retrieve the first/last matched node under a given
> AST.
>   template 
>   class DeclMatcher : public MatchFinder::MatchCallback {
> NodeType *Node = nullptr;
> void run(const MatchFinder::MatchResult ) override {
>   if ((MatcherKind == DeclMatcherKind::First && Node == nullptr) ||
>   MatcherKind == DeclMatcherKind::Last) {
> Node = const_cast *>(Result.Nodes.getNodeAs(""));
>   }
> }
>   public:
> // Returns the first/last matched node under the tree rooted in `D`.
> template 
> NodeType *match(const Decl *D, const MatcherType ) {
>   MatchFinder Finder;
>   Finder.addMatcher(AMatcher.bind(""), this);
>   Finder.matchAST(D->getASTContext());
>   assert(Node);
>   return Node;
> }
>   };
>   template 
>   using LastDeclMatcher = DeclMatcher;
>   template 
>   using FirstDeclMatcher = DeclMatcher;
>
> And this is how we use it in the tests:
>
>   Decl *FromTU = getTuDecl("void f(); void f(); void f();", Lang_CXX);
>   auto Pattern = functionDecl(hasName("f"));
>   auto *D0 = FirstDeclMatcher().match(FromTU, Pattern);
>   auto *D2 = LastDeclMatcher().match(FromTU, Pattern);
>
> At this point we would like to extend this `DeclMatcher` to be able to
> match a subtree, and be able to start the traverse from a specific `Decl`,
> something like this :
>
>   auto *DV = FirsDeclMatcher().match(D2, SomeOtherPattern);
>
> Currently, I don't see how we could do this extension without the proposed
> `matchSubtree`.
> (Perhaps, we could refactor our `DeclMatcher` to not use a customized
> MatchCallback, rather use `ast_matchers::match`, but that sounds like a bad
> workaround to me.)
>
> Hope this makes the the goal of this patch cleaner.
>

Finder.match also has an overload that takes the node. Can you wrap
"Pattern" above in the anyOf(hasDescendant(...), ...) and match on the node
instead of the full AST?


>
>
> Repository:
>   rC Clang
>
> https://reviews.llvm.org/D49840
>
>
>
>
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D49840: [AST] Add MatchFinder::matchSubtree

2018-07-27 Thread Manuel Klimek via cfe-commits
On Thu, Jul 26, 2018 at 12:44 PM Gabor Marton via Phabricator <
revi...@reviews.llvm.org> wrote:

> martong added a comment.
>
> > Usually we use match(anyOf(node), hasDescendant(node)). Or did I
> misunderstand what you want?
>
> My understanding is that, the free function template `match` uses
> `MatchFinder::matchAST`, which will start the traverse from the
> TranslationUnitDecl.
> And there is no option to pick a specific node and specify that as the
> root of the traverse. I'd like an option to be able to start the traverse
> from a specific node, if it makes sense.
>

MatchFinder::match allows you to match a node. Wrapping your matcher code
with:
auto m = ;
ast_matchers::match(anyOf(m, hashDescendant(m)), node, context);
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] r331875 - Do not warn on unused parameters for functions with empty bodies.

2018-05-09 Thread Manuel Klimek via cfe-commits
Author: klimek
Date: Wed May  9 06:20:03 2018
New Revision: 331875

URL: http://llvm.org/viewvc/llvm-project?rev=331875=rev
Log:
Do not warn on unused parameters for functions with empty bodies.

If a function has an empty body, all parameters are trivially unused.

Modified:
clang-tools-extra/trunk/clang-tidy/misc/UnusedParametersCheck.cpp
clang-tools-extra/trunk/test/clang-tidy/misc-unused-parameters.c
clang-tools-extra/trunk/test/clang-tidy/misc-unused-parameters.cpp

Modified: clang-tools-extra/trunk/clang-tidy/misc/UnusedParametersCheck.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/misc/UnusedParametersCheck.cpp?rev=331875=331874=331875=diff
==
--- clang-tools-extra/trunk/clang-tidy/misc/UnusedParametersCheck.cpp (original)
+++ clang-tools-extra/trunk/clang-tidy/misc/UnusedParametersCheck.cpp Wed May  
9 06:20:03 2018
@@ -29,10 +29,11 @@ bool isOverrideMethod(const FunctionDecl
 } // namespace
 
 void UnusedParametersCheck::registerMatchers(MatchFinder *Finder) {
-  Finder->addMatcher(
-  functionDecl(isDefinition(), hasBody(stmt()), hasAnyParameter(decl()))
-  .bind("function"),
-  this);
+  Finder->addMatcher(functionDecl(isDefinition(),
+  hasBody(stmt(hasDescendant(stmt(,
+  hasAnyParameter(decl()))
+ .bind("function"),
+ this);
 }
 
 template 

Modified: clang-tools-extra/trunk/test/clang-tidy/misc-unused-parameters.c
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/misc-unused-parameters.c?rev=331875=331874=331875=diff
==
--- clang-tools-extra/trunk/test/clang-tidy/misc-unused-parameters.c (original)
+++ clang-tools-extra/trunk/test/clang-tidy/misc-unused-parameters.c Wed May  9 
06:20:03 2018
@@ -2,14 +2,14 @@
 
 // Basic removal
 // =
-void a(int i) {}
+void a(int i) {;}
 // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: parameter 'i' is unused 
[misc-unused-parameters]
-// CHECK-FIXES: {{^}}void a(int  /*i*/) {}{{$}}
+// CHECK-FIXES: {{^}}void a(int  /*i*/) {;}{{$}}
 
 static void b(); // In C, forward declarations can leave out parameters.
-static void b(int i) {}
+static void b(int i) {;}
 // CHECK-MESSAGES: :[[@LINE-1]]:19: warning: parameter 'i' is unused 
[misc-unused-parameters]
-// CHECK-FIXES: {{^}}static void b() {}{{$}}
+// CHECK-FIXES: {{^}}static void b() {;}{{$}}
 
 // Unchanged cases
 // ===

Modified: clang-tools-extra/trunk/test/clang-tidy/misc-unused-parameters.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/misc-unused-parameters.cpp?rev=331875=331874=331875=diff
==
--- clang-tools-extra/trunk/test/clang-tidy/misc-unused-parameters.cpp 
(original)
+++ clang-tools-extra/trunk/test/clang-tidy/misc-unused-parameters.cpp Wed May  
9 06:20:03 2018
@@ -1,5 +1,5 @@
-// RUN: echo "static void staticFunctionHeader(int i) {}" > %T/header.h
-// RUN: echo "static void staticFunctionHeader(int  /*i*/) {}" > 
%T/header-fixed.h
+// RUN: echo "static void staticFunctionHeader(int i) {;}" > %T/header.h
+// RUN: echo "static void staticFunctionHeader(int  /*i*/) {;}" > 
%T/header-fixed.h
 // RUN: %check_clang_tidy %s misc-unused-parameters %t -- -header-filter='.*' 
-- -std=c++11 -fno-delayed-template-parsing
 // RUN: diff %T/header.h %T/header-fixed.h
 
@@ -8,29 +8,29 @@
 
 // Basic removal
 // =
-void a(int i) {}
+void a(int i) {;}
 // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: parameter 'i' is unused 
[misc-unused-parameters]
-// CHECK-FIXES: {{^}}void a(int  /*i*/) {}{{$}}
+// CHECK-FIXES: {{^}}void a(int  /*i*/) {;}{{$}}
 
-void b(int i = 1) {}
+void b(int i = 1) {;}
 // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: parameter 'i' is unused 
[misc-unused-parameters]
-// CHECK-FIXES: {{^}}void b(int  /*i*/ = 1) {}{{$}}
+// CHECK-FIXES: {{^}}void b(int  /*i*/ = 1) {;}{{$}}
 
-void c(int *i) {}
+void c(int *i) {;}
 // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: parameter 'i' is unused 
[misc-unused-parameters]
-// CHECK-FIXES: {{^}}void c(int * /*i*/) {}{{$}}
+// CHECK-FIXES: {{^}}void c(int * /*i*/) {;}{{$}}
 
-void d(int i[]) {}
+void d(int i[]) {;}
 // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: parameter 'i' is unused 
[misc-unused-parameters]
-// CHECK-FIXES: {{^}}void d(int  /*i*/[]) {}{{$}}
+// CHECK-FIXES: {{^}}void d(int  /*i*/[]) {;}{{$}}
 
-void e(int i[1]) {}
+void e(int i[1]) {;}
 // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: parameter 'i' is unused 
[misc-unused-parameters]
-// CHECK-FIXES: {{^}}void e(int  /*i*/[1]) {}{{$}}
+// CHECK-FIXES: {{^}}void e(int  /*i*/[1]) {;}{{$}}
 
-void f(void (*fn)()) {}
+void f(void (*fn)()) {;}
 // CHECK-MESSAGES: :[[@LINE-1]]:15: warning: parameter 'fn' is 

[clang-tools-extra] r330580 - Fix tests after changes to clang-format in r330573.

2018-04-23 Thread Manuel Klimek via cfe-commits
Author: klimek
Date: Mon Apr 23 04:47:59 2018
New Revision: 330580

URL: http://llvm.org/viewvc/llvm-project?rev=330580=rev
Log:
Fix tests after changes to clang-format in r330573.

We do now both:
- stop reformatting a sequence after a closing brace in more cases, in
  order to not misindent after an incorrect closing brace
- format the closing brace when formatting the line containing the
  opening brace

Modified:

clang-tools-extra/trunk/test/clang-tidy/readability-braces-around-statements-format.cpp
clang-tools-extra/trunk/unittests/include-fixer/IncludeFixerTest.cpp

Modified: 
clang-tools-extra/trunk/test/clang-tidy/readability-braces-around-statements-format.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/readability-braces-around-statements-format.cpp?rev=330580=330579=330580=diff
==
--- 
clang-tools-extra/trunk/test/clang-tidy/readability-braces-around-statements-format.cpp
 (original)
+++ 
clang-tools-extra/trunk/test/clang-tidy/readability-braces-around-statements-format.cpp
 Mon Apr 23 04:47:59 2018
@@ -19,15 +19,15 @@ void test() {
   // CHECK-MESSAGES: :[[@LINE-3]]:26: warning: statement should be inside 
braces
   // CHECK-MESSAGES: :[[@LINE-4]]:35: warning: statement should be inside 
braces
   // CHECK-MESSAGES: :[[@LINE-5]]:38: warning: statement should be inside 
braces
-  // CHECK-FIXES:  {{^}}   if (1) {{{$}}
-  // CHECK-FIXES-NEXT: {{^}}  while (2) {
-  // CHECK-FIXES-NEXT: {{^}} if (3) {
-  // CHECK-FIXES-NEXT: {{^}}for (;;) {
-  // CHECK-FIXES-NEXT: {{^}}   do {
-  // CHECK-FIXES-NEXT: {{^}}  ;
-  // CHECK-FIXES-NEXT: {{^}}   } while (false) /**/; /**/
-  // CHECK-FIXES-NEXT: {{^}}}
-  // CHECK-FIXES-NEXT: {{^}} }
-  // CHECK-FIXES-NEXT: {{^}}  }
-  // CHECK-FIXES-NEXT: {{^}}   }
+  // CHECK-FIXES:  {{^}}  if (1) {{{$}}
+  // CHECK-FIXES-NEXT: {{^}} while (2) {
+  // CHECK-FIXES-NEXT: {{^}}if (3) {
+  // CHECK-FIXES-NEXT: {{^}}   for (;;) {
+  // CHECK-FIXES-NEXT: {{^}}  do {
+  // CHECK-FIXES-NEXT: {{^}} ;
+  // CHECK-FIXES-NEXT: {{^}}  } while (false) /**/; /**/
+  // CHECK-FIXES-NEXT: {{^}}   }
+  // CHECK-FIXES-NEXT: {{^}}}
+  // CHECK-FIXES-NEXT: {{^}} }
+  // CHECK-FIXES-NEXT: {{^}}  }
 }

Modified: clang-tools-extra/trunk/unittests/include-fixer/IncludeFixerTest.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/unittests/include-fixer/IncludeFixerTest.cpp?rev=330580=330579=330580=diff
==
--- clang-tools-extra/trunk/unittests/include-fixer/IncludeFixerTest.cpp 
(original)
+++ clang-tools-extra/trunk/unittests/include-fixer/IncludeFixerTest.cpp Mon 
Apr 23 04:47:59 2018
@@ -196,7 +196,8 @@ TEST(IncludeFixer, ScopedNamespaceSymbol
 runIncludeFixer("namespace a {\nb::bar b;\n}"));
   EXPECT_EQ("#include \"bar.h\"\nnamespace A {\na::b::bar b;\n}",
 runIncludeFixer("namespace A {\na::b::bar b;\n}"));
-  EXPECT_EQ("#include \"bar.h\"\nnamespace a {\nvoid func() { b::bar b; }\n}",
+  EXPECT_EQ("#include \"bar.h\"\nnamespace a {\nvoid func() { b::bar b; }\n} "
+"// namespace a",
 runIncludeFixer("namespace a {\nvoid func() { b::bar b; }\n}"));
   EXPECT_EQ("namespace A { c::b::bar b; }\n",
 runIncludeFixer("namespace A { c::b::bar b; }\n"));
@@ -258,7 +259,8 @@ TEST(IncludeFixer, FixNamespaceQualifier
 runIncludeFixer("namespace a {\nb::bar b;\n}\n"));
   EXPECT_EQ("#include \"bar.h\"\nnamespace a {\nb::bar b;\n}\n",
 runIncludeFixer("namespace a {\nbar b;\n}\n"));
-  EXPECT_EQ("#include \"bar.h\"\nnamespace a {\nnamespace b{\nbar b;\n}\n}\n",
+  EXPECT_EQ("#include \"bar.h\"\nnamespace a {\nnamespace b{\nbar b;\n}\n} "
+"// namespace a\n",
 runIncludeFixer("namespace a {\nnamespace b{\nbar b;\n}\n}\n"));
   EXPECT_EQ("c::b::bar b;\n",
 runIncludeFixer("c::b::bar b;\n"));
@@ -268,12 +270,12 @@ TEST(IncludeFixer, FixNamespaceQualifier
 runIncludeFixer("namespace c {\nbar b;\n}\n"));
 
   // Test common qualifers reduction.
-  EXPECT_EQ(
-  "#include \"bar.h\"\nnamespace a {\nnamespace d {\nb::bar b;\n}\n}\n",
-  runIncludeFixer("namespace a {\nnamespace d {\nbar b;\n}\n}\n"));
-  EXPECT_EQ(
-  "#include \"bar.h\"\nnamespace d {\nnamespace a {\na::b::bar b;\n}\n}\n",
-  runIncludeFixer("namespace d {\nnamespace a {\nbar b;\n}\n}\n"));
+  EXPECT_EQ("#include \"bar.h\"\nnamespace a {\nnamespace d {\nb::bar b;\n}\n} 
"
+"// namespace a\n",
+runIncludeFixer("namespace a {\nnamespace d {\nbar b;\n}\n}\n"));
+  EXPECT_EQ("#include \"bar.h\"\nnamespace d {\nnamespace a {\na::b::bar "
+"b;\n}\n} // namespace d\n",
+   

r330573 - Format closing braces when reformatting the line containing the opening brace.

2018-04-23 Thread Manuel Klimek via cfe-commits
Author: klimek
Date: Mon Apr 23 02:34:26 2018
New Revision: 330573

URL: http://llvm.org/viewvc/llvm-project?rev=330573=rev
Log:
Format closing braces when reformatting the line containing the opening brace.

This required a couple of yaks to be shaved:
1. MatchingOpeningBlockLineIndex was misused to also store the
   closing index; instead, use a second variable, as this doesn't
   work correctly for "} else {".
2. We needed to change the API of AffectedRangeManager to not
   use iterators; we always passed in begin / end for the whole
   container before, so there was no mismatch in generality.
3. We need an extra check to discontinue formatting at the top
   level, as we now sometimes change the indent of the closing
   brace, but want to bail out immediately afterwards, for
   example:
 void f() {
   if (a) {
 }
 void g();
   Previously:
 void f() {
   if (a) {
 }
 void g();
   Now:
 void f() {
   if (a) {
   }
 void g();

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

Modified:
cfe/trunk/lib/Format/AffectedRangeManager.cpp
cfe/trunk/lib/Format/AffectedRangeManager.h
cfe/trunk/lib/Format/Format.cpp
cfe/trunk/lib/Format/NamespaceEndCommentsFixer.cpp
cfe/trunk/lib/Format/SortJavaScriptImports.cpp
cfe/trunk/lib/Format/TokenAnnotator.h
cfe/trunk/lib/Format/UnwrappedLineFormatter.cpp
cfe/trunk/lib/Format/UnwrappedLineParser.cpp
cfe/trunk/lib/Format/UnwrappedLineParser.h
cfe/trunk/lib/Format/UsingDeclarationsSorter.cpp
cfe/trunk/unittests/Format/FormatTestSelective.cpp

Modified: cfe/trunk/lib/Format/AffectedRangeManager.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/AffectedRangeManager.cpp?rev=330573=330572=330573=diff
==
--- cfe/trunk/lib/Format/AffectedRangeManager.cpp (original)
+++ cfe/trunk/lib/Format/AffectedRangeManager.cpp Mon Apr 23 02:34:26 2018
@@ -21,8 +21,9 @@ namespace clang {
 namespace format {
 
 bool AffectedRangeManager::computeAffectedLines(
-SmallVectorImpl::iterator I,
-SmallVectorImpl::iterator E) {
+SmallVectorImpl ) {
+  SmallVectorImpl::iterator I = Lines.begin();
+  SmallVectorImpl::iterator E = Lines.end();
   bool SomeLineAffected = false;
   const AnnotatedLine *PreviousLine = nullptr;
   while (I != E) {
@@ -48,7 +49,7 @@ bool AffectedRangeManager::computeAffect
   continue;
 }
 
-if (nonPPLineAffected(Line, PreviousLine))
+if (nonPPLineAffected(Line, PreviousLine, Lines))
   SomeLineAffected = true;
 
 PreviousLine = Line;
@@ -99,10 +100,10 @@ void AffectedRangeManager::markAllAsAffe
 }
 
 bool AffectedRangeManager::nonPPLineAffected(
-AnnotatedLine *Line, const AnnotatedLine *PreviousLine) {
+AnnotatedLine *Line, const AnnotatedLine *PreviousLine,
+SmallVectorImpl ) {
   bool SomeLineAffected = false;
-  Line->ChildrenAffected =
-  computeAffectedLines(Line->Children.begin(), Line->Children.end());
+  Line->ChildrenAffected = computeAffectedLines(Line->Children);
   if (Line->ChildrenAffected)
 SomeLineAffected = true;
 
@@ -138,8 +139,13 @@ bool AffectedRangeManager::nonPPLineAffe
   Line->First->NewlinesBefore < 2 && PreviousLine &&
   PreviousLine->Affected && PreviousLine->Last->is(tok::comment);
 
+  bool IsAffectedClosingBrace =
+  Line->First->is(tok::r_brace) &&
+  Line->MatchingOpeningBlockLineIndex != UnwrappedLine::kInvalidIndex &&
+  Lines[Line->MatchingOpeningBlockLineIndex]->Affected;
+
   if (SomeTokenAffected || SomeFirstChildAffected || LineMoved ||
-  IsContinuedComment) {
+  IsContinuedComment || IsAffectedClosingBrace) {
 Line->Affected = true;
 SomeLineAffected = true;
   }

Modified: cfe/trunk/lib/Format/AffectedRangeManager.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/AffectedRangeManager.h?rev=330573=330572=330573=diff
==
--- cfe/trunk/lib/Format/AffectedRangeManager.h (original)
+++ cfe/trunk/lib/Format/AffectedRangeManager.h Mon Apr 23 02:34:26 2018
@@ -30,10 +30,9 @@ public:
   : SourceMgr(SourceMgr), Ranges(Ranges.begin(), Ranges.end()) {}
 
   // Determines which lines are affected by the SourceRanges given as input.
-  // Returns \c true if at least one line between I and E or one of their
+  // Returns \c true if at least one line in \p Lines or one of their
   // children is affected.
-  bool computeAffectedLines(SmallVectorImpl::iterator I,
-SmallVectorImpl::iterator E);
+  bool computeAffectedLines(SmallVectorImpl );
 
   // Returns true if 'Range' intersects with one of the input ranges.
   bool affectsCharSourceRange(const CharSourceRange );
@@ -54,8 +53,8 @@ private:
 
   // Determines whether 'Line' is affected by the SourceRanges given as input.
   // Returns \c true if line or one if its children is affected.
-  bool 

r329816 - Fix bugs around handling C++11 attributes.

2018-04-11 Thread Manuel Klimek via cfe-commits
Author: klimek
Date: Wed Apr 11 07:51:54 2018
New Revision: 329816

URL: http://llvm.org/viewvc/llvm-project?rev=329816=rev
Log:
Fix bugs around handling C++11 attributes.

Previously, we would format:
  int a() { ... }
  [[unused]] int b() { ... }
as...
  int a() {} [[unused] int b() {}
Now we correctly format each on its own line.

Similarly, we would detect:
  [[unused]] int b() { return 42; }
As a lambda and leave it on a single line, even if that was disallowed
by the format style.

Modified:
cfe/trunk/lib/Format/UnwrappedLineParser.cpp
cfe/trunk/unittests/Format/FormatTest.cpp

Modified: cfe/trunk/lib/Format/UnwrappedLineParser.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/UnwrappedLineParser.cpp?rev=329816=329815=329816=diff
==
--- cfe/trunk/lib/Format/UnwrappedLineParser.cpp (original)
+++ cfe/trunk/lib/Format/UnwrappedLineParser.cpp Wed Apr 11 07:51:54 2018
@@ -449,12 +449,19 @@ void UnwrappedLineParser::calculateBrace
   (Style.isCpp() && NextTok->is(tok::l_paren)) ||
   NextTok->isOneOf(tok::comma, tok::period, tok::colon,
tok::r_paren, tok::r_square, tok::l_brace,
-   tok::l_square, tok::ellipsis) ||
+   tok::ellipsis) ||
   (NextTok->is(tok::identifier) &&
!PrevTok->isOneOf(tok::semi, tok::r_brace, tok::l_brace)) ||
   (NextTok->is(tok::semi) &&
(!ExpectClassBody || LBraceStack.size() != 1)) ||
   (NextTok->isBinaryOperator() && !NextIsObjCMethod);
+  if (NextTok->is(tok::l_square)) {
+// We can have an array subscript after a braced init
+// list, but C++11 attributes are expected after blocks.
+NextTok = Tokens->getNextToken();
+++ReadTokens;
+ProbablyBracedList = NextTok->isNot(tok::l_square);
+  }
 }
 if (ProbablyBracedList) {
   Tok->BlockKind = BK_BracedInit;
@@ -1406,13 +1413,16 @@ bool UnwrappedLineParser::tryToParseLamb
   const FormatToken *Previous = FormatTok->Previous;
   if (Previous &&
   (Previous->isOneOf(tok::identifier, tok::kw_operator, tok::kw_new,
- tok::kw_delete) ||
+ tok::kw_delete, tok::l_square) ||
FormatTok->isCppStructuredBinding(Style) || Previous->closesScope() ||
Previous->isSimpleTypeSpecifier())) {
 nextToken();
 return false;
   }
   nextToken();
+  if (FormatTok->is(tok::l_square)) {
+return false;
+  }
   parseSquare(/*LambdaIntroducer=*/true);
   return true;
 }

Modified: cfe/trunk/unittests/Format/FormatTest.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTest.cpp?rev=329816=329815=329816=diff
==
--- cfe/trunk/unittests/Format/FormatTest.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTest.cpp Wed Apr 11 07:51:54 2018
@@ -6078,6 +6078,21 @@ TEST_F(FormatTest, UnderstandsSquareAttr
   verifyFormat("void f() [[deprecated(\"so sorry\")]];");
   verifyFormat("aa\n"
"[[unused]] aaa(int i);");
+
+  // Make sure we do not mistake attributes for array subscripts.
+  verifyFormat("int a() {}\n"
+   "[[unused]] int b() {}\n");
+
+  // On the other hand, we still need to correctly find array subscripts.
+  verifyFormat("int a = std::vector{1, 2, 3}[0];");
+
+  // Make sure we do not parse attributes as lambda introducers.
+  FormatStyle MultiLineFunctions = getLLVMStyle();
+  MultiLineFunctions.AllowShortFunctionsOnASingleLine = FormatStyle::SFS_None;
+  verifyFormat("[[unused]] int b() {\n"
+   "  return 42;\n"
+   "}\n",
+   MultiLineFunctions);
 }
 
 TEST_F(FormatTest, UnderstandsEllipsis) {


___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r319642 - Fix bug where we wouldn't break columns over the limit.

2017-12-04 Thread Manuel Klimek via cfe-commits
Author: klimek
Date: Mon Dec  4 00:53:16 2017
New Revision: 319642

URL: http://llvm.org/viewvc/llvm-project?rev=319642=rev
Log:
Fix bug where we wouldn't break columns over the limit.

Before, we would not break:
  int a = foo(/* trailing */);
when the end of /* trailing */ was exactly the column limit; the reason
is that block comments can have an unbreakable tail length - in this case
2, for the trailing ");"; we would unconditionally account that when
calculating the column state at the end of the token, but not correctly
add it into the remaining column length before, as we do for string
literals.
The fix is to correctly account the trailing unbreakable sequence length
into our formatting decisions for block comments. Line comments cannot
have a trailing unbreakable sequence, so no change is needed for them.

Modified:
cfe/trunk/lib/Format/BreakableToken.cpp
cfe/trunk/lib/Format/BreakableToken.h
cfe/trunk/unittests/Format/FormatTestComments.cpp

Modified: cfe/trunk/lib/Format/BreakableToken.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/BreakableToken.cpp?rev=319642=319641=319642=diff
==
--- cfe/trunk/lib/Format/BreakableToken.cpp (original)
+++ cfe/trunk/lib/Format/BreakableToken.cpp Mon Dec  4 00:53:16 2017
@@ -316,7 +316,8 @@ BreakableBlockComment::BreakableBlockCom
 unsigned OriginalStartColumn, bool FirstInLine, bool InPPDirective,
 encoding::Encoding Encoding, const FormatStyle )
 : BreakableComment(Token, StartColumn, InPPDirective, Encoding, Style),
-  DelimitersOnNewline(false) {
+  DelimitersOnNewline(false),
+  UnbreakableTailLength(Token.UnbreakableTailLength) {
   assert(Tok.is(TT_BlockComment) &&
  "block comment section must start with a block comment");
 
@@ -497,7 +498,8 @@ unsigned BreakableBlockComment::getRange
 unsigned BreakableBlockComment::getRemainingLength(unsigned LineIndex,
unsigned Offset,
unsigned StartColumn) const 
{
-  return getRangeLength(LineIndex, Offset, StringRef::npos, StartColumn);
+  return UnbreakableTailLength +
+ getRangeLength(LineIndex, Offset, StringRef::npos, StartColumn);
 }
 
 unsigned BreakableBlockComment::getContentStartColumn(unsigned LineIndex,

Modified: cfe/trunk/lib/Format/BreakableToken.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/BreakableToken.h?rev=319642=319641=319642=diff
==
--- cfe/trunk/lib/Format/BreakableToken.h (original)
+++ cfe/trunk/lib/Format/BreakableToken.h Mon Dec  4 00:53:16 2017
@@ -405,6 +405,10 @@ private:
   // If true, make sure that the opening '/**' and the closing '*/' ends on a
   // line of itself. Styles like jsdoc require this for multiline comments.
   bool DelimitersOnNewline;
+
+  // Length of the sequence of tokens after this string literal that cannot
+  // contain line breaks.
+  unsigned UnbreakableTailLength;
 };
 
 class BreakableLineCommentSection : public BreakableComment {

Modified: cfe/trunk/unittests/Format/FormatTestComments.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTestComments.cpp?rev=319642=319641=319642=diff
==
--- cfe/trunk/unittests/Format/FormatTestComments.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTestComments.cpp Mon Dec  4 00:53:16 2017
@@ -3080,6 +3080,15 @@ TEST_F(FormatTestComments, PythonStyleCo
getTextProtoStyleWithColumns(20)));
 }
 
+TEST_F(FormatTestComments, BreaksBeforeTrailingUnbreakableSequence) {
+  // The end of /* trail */ is exactly at 80 columns, but the unbreakable
+  // trailing sequence ); after it exceeds the column limit. Make sure we
+  // correctly break the line in that case.
+  verifyFormat("int a =\n"
+   "foo(/* trail */);",
+   getLLVMStyleWithColumns(23));
+}
+
 } // end namespace
 } // end namespace format
 } // end namespace clang


___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r319541 - Better trade-off for excess characters vs. staying within the column limits.

2017-12-01 Thread Manuel Klimek via cfe-commits
Author: klimek
Date: Fri Dec  1 05:28:08 2017
New Revision: 319541

URL: http://llvm.org/viewvc/llvm-project?rev=319541=rev
Log:
Better trade-off for excess characters vs. staying within the column limits.

When we break a long line like:
Column limit: 21
  |
  // foo foo foo foo foo foo foo foo foo foo foo foo

The local decision when to allow protruding vs. breaking can lead to this
outcome (2 excess characters, 2 breaks):
  // foo foo foo foo foo
  // foo foo foo foo foo
  // foo foo

While strictly staying within the column limit leads to this strictly better
outcome (fully below the column limit, 2 breaks):
  // foo foo foo foo
  // foo foo foo foo
  // foo foo foo foo

To get an optimal solution, we would need to consider all combinations of excess
characters vs. breaking for all lines, but that would lead to a significant
increase in the search space of the algorithm for little gain.

Instead, we blindly try both approches and·select the one that leads to the
overall lower penalty.

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

Modified:
cfe/trunk/lib/Format/ContinuationIndenter.cpp
cfe/trunk/lib/Format/ContinuationIndenter.h
cfe/trunk/unittests/Format/FormatTest.cpp

Modified: cfe/trunk/lib/Format/ContinuationIndenter.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/ContinuationIndenter.cpp?rev=319541=319540=319541=diff
==
--- cfe/trunk/lib/Format/ContinuationIndenter.cpp (original)
+++ cfe/trunk/lib/Format/ContinuationIndenter.cpp Fri Dec  1 05:28:08 2017
@@ -1390,7 +1390,36 @@ unsigned ContinuationIndenter::handleEnd
 Penalty = addMultilineToken(Current, State);
   } else if (State.Line->Type != LT_ImportStatement) {
 // We generally don't break import statements.
-Penalty = breakProtrudingToken(Current, State, AllowBreak, DryRun);
+LineState OriginalState = State;
+
+// Whether we force the reflowing algorithm to stay strictly within the
+// column limit.
+bool Strict = false;
+// Whether the first non-strict attempt at reflowing did intentionally
+// exceed the column limit.
+bool Exceeded = false;
+std::tie(Penalty, Exceeded) = breakProtrudingToken(
+Current, State, AllowBreak, /*DryRun=*/true, Strict);
+if (Exceeded) {
+  // If non-strict reflowing exceeds the column limit, try whether strict
+  // reflowing leads to an overall lower penalty.
+  LineState StrictState = OriginalState;
+  unsigned StrictPenalty =
+  breakProtrudingToken(Current, StrictState, AllowBreak,
+   /*DryRun=*/true, /*Strict=*/true)
+  .first;
+  Strict = StrictPenalty <= Penalty;
+  if (Strict) {
+Penalty = StrictPenalty;
+State = StrictState;
+  }
+}
+if (!DryRun) {
+  // If we're not in dry-run mode, apply the changes with the decision on
+  // strictness made above.
+  breakProtrudingToken(Current, OriginalState, AllowBreak, 
/*DryRun=*/false,
+   Strict);
+}
   }
   if (State.Column > getColumnLimit(State)) {
 unsigned ExcessCharacters = State.Column - getColumnLimit(State);
@@ -1480,14 +1509,14 @@ std::unique_ptr Continua
   return nullptr;
 }
 
-unsigned ContinuationIndenter::breakProtrudingToken(const FormatToken ,
-LineState ,
-bool AllowBreak,
-bool DryRun) {
+std::pair
+ContinuationIndenter::breakProtrudingToken(const FormatToken ,
+   LineState , bool AllowBreak,
+   bool DryRun, bool Strict) {
   std::unique_ptr Token =
   createBreakableToken(Current, State, AllowBreak);
   if (!Token)
-return 0;
+return {0, false};
   assert(Token->getLineCount() > 0);
   unsigned ColumnLimit = getColumnLimit(State);
   if (Current.is(TT_LineComment)) {
@@ -1495,13 +1524,16 @@ unsigned ContinuationIndenter::breakProt
 ColumnLimit = Style.ColumnLimit;
   }
   if (Current.UnbreakableTailLength >= ColumnLimit)
-return 0;
+return {0, false};
   // ColumnWidth was already accounted into State.Column before calling
   // breakProtrudingToken.
   unsigned StartColumn = State.Column - Current.ColumnWidth;
   unsigned NewBreakPenalty = Current.isStringLiteral()
  ? Style.PenaltyBreakString
  : Style.PenaltyBreakComment;
+  // Stores whether we intentionally decide to let a line exceed the column
+  // limit.
+  bool Exceeded = false;
   // Stores whether we introduce a break anywhere in the token.
   bool BreakInserted = Token->introducesBreakBeforeToken();
   // Store whether we inserted a new line break at the end of the previous
@@ -1612,7 +1644,7 @@ unsigned 

r319318 - Fix 'control reaches end of non-void' warning by using llvm_unreachable.

2017-11-29 Thread Manuel Klimek via cfe-commits
Author: klimek
Date: Wed Nov 29 07:09:12 2017
New Revision: 319318

URL: http://llvm.org/viewvc/llvm-project?rev=319318=rev
Log:
Fix 'control reaches end of non-void' warning by using llvm_unreachable.

Modified:
cfe/trunk/lib/Format/BreakableToken.cpp

Modified: cfe/trunk/lib/Format/BreakableToken.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/BreakableToken.cpp?rev=319318=319317=319318=diff
==
--- cfe/trunk/lib/Format/BreakableToken.cpp (original)
+++ cfe/trunk/lib/Format/BreakableToken.cpp Wed Nov 29 07:09:12 2017
@@ -195,9 +195,8 @@ unsigned BreakableStringLiteral::getRang
 unsigned Offset,
 StringRef::size_type Length,
 unsigned StartColumn) const {
-  assert(false &&
- "Getting the length of a part of the string literal indicates that "
- "the code tries to reflow it.");
+  llvm_unreachable("Getting the length of a part of the string literal "
+   "indicates that the code tries to reflow it.");
 }
 
 unsigned


___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r319314 - Restructure how we break tokens.

2017-11-29 Thread Manuel Klimek via cfe-commits
Author: klimek
Date: Wed Nov 29 06:29:43 2017
New Revision: 319314

URL: http://llvm.org/viewvc/llvm-project?rev=319314=rev
Log:
Restructure how we break tokens.

This fixes some bugs in the reflowing logic and splits out the concerns
of reflowing from BreakableToken.

Things to do after this patch:
- Refactor the breakProtrudingToken function possibly into a class, so we
  can split it up into methods that operate on the common state.
- Optimize whitespace compression when reflowing by using the next possible
  split point instead of the latest possible split point.
- Retry different strategies for reflowing (strictly staying below the
  column limit vs. allowing excess characters if possible).

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

Modified:
cfe/trunk/lib/Format/BreakableToken.cpp
cfe/trunk/lib/Format/BreakableToken.h
cfe/trunk/lib/Format/ContinuationIndenter.cpp
cfe/trunk/unittests/Format/FormatTest.cpp
cfe/trunk/unittests/Format/FormatTestComments.cpp

Modified: cfe/trunk/lib/Format/BreakableToken.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/BreakableToken.cpp?rev=319314=319313=319314=diff
==
--- cfe/trunk/lib/Format/BreakableToken.cpp (original)
+++ cfe/trunk/lib/Format/BreakableToken.cpp Wed Nov 29 06:29:43 2017
@@ -67,6 +67,8 @@ static BreakableToken::Split getCommentS
  unsigned ColumnLimit,
  unsigned TabWidth,
  encoding::Encoding Encoding) {
+  DEBUG(llvm::dbgs() << "Comment split: \"" << Text << ", " << ColumnLimit
+ << "\", Content start: " << ContentStartColumn << "\n");
   if (ColumnLimit <= ContentStartColumn + 1)
 return BreakableToken::Split(StringRef::npos, 0);
 
@@ -171,7 +173,7 @@ bool switchesFormatting(const FormatToke
 }
 
 unsigned
-BreakableToken::getLineLengthAfterCompression(unsigned RemainingTokenColumns,
+BreakableToken::getLengthAfterCompression(unsigned RemainingTokenColumns,
   Split Split) const {
   // Example: consider the content
   // lala  lala
@@ -181,50 +183,58 @@ BreakableToken::getLineLengthAfterCompre
   // We compute the number of columns when the split is compressed into a 
single
   // space, like:
   // lala lala
+  //
+  // FIXME: Correctly measure the length of whitespace in Split.second so it
+  // works with tabs.
   return RemainingTokenColumns + 1 - Split.second;
 }
 
-unsigned BreakableSingleLineToken::getLineCount() const { return 1; }
+unsigned BreakableStringLiteral::getLineCount() const { return 1; }
 
-unsigned BreakableSingleLineToken::getLineLengthAfterSplit(
-unsigned LineIndex, unsigned TailOffset,
-StringRef::size_type Length) const {
-  return StartColumn + Prefix.size() + Postfix.size() +
- encoding::columnWidthWithTabs(Line.substr(TailOffset, Length),
-   StartColumn + Prefix.size(),
-   Style.TabWidth, Encoding);
+unsigned BreakableStringLiteral::getRangeLength(unsigned LineIndex,
+unsigned Offset,
+StringRef::size_type Length,
+unsigned StartColumn) const {
+  assert(false &&
+ "Getting the length of a part of the string literal indicates that "
+ "the code tries to reflow it.");
 }
 
-BreakableSingleLineToken::BreakableSingleLineToken(
+unsigned
+BreakableStringLiteral::getRemainingLength(unsigned LineIndex, unsigned Offset,
+   unsigned StartColumn) const {
+  return UnbreakableTailLength + Postfix.size() +
+ encoding::columnWidthWithTabs(Line.substr(Offset, StringRef::npos),
+   StartColumn, Style.TabWidth, Encoding);
+}
+
+unsigned BreakableStringLiteral::getContentStartColumn(unsigned LineIndex,
+   bool Break) const {
+  return StartColumn + Prefix.size();
+}
+
+BreakableStringLiteral::BreakableStringLiteral(
 const FormatToken , unsigned StartColumn, StringRef Prefix,
 StringRef Postfix, bool InPPDirective, encoding::Encoding Encoding,
 const FormatStyle )
 : BreakableToken(Tok, InPPDirective, Encoding, Style),
-  StartColumn(StartColumn), Prefix(Prefix), Postfix(Postfix) {
+  StartColumn(StartColumn), Prefix(Prefix), Postfix(Postfix),
+  UnbreakableTailLength(Tok.UnbreakableTailLength) {
   assert(Tok.TokenText.startswith(Prefix) && Tok.TokenText.endswith(Postfix));
   Line = Tok.TokenText.substr(
   Prefix.size(), Tok.TokenText.size() - Prefix.size() - Postfix.size());
 }
 
-BreakableStringLiteral::BreakableStringLiteral(
-const FormatToken , unsigned StartColumn, StringRef Prefix,
-

r318515 - Implement more accurate penalty & trade-offs while breaking protruding tokens.

2017-11-17 Thread Manuel Klimek via cfe-commits
Author: klimek
Date: Fri Nov 17 03:17:15 2017
New Revision: 318515

URL: http://llvm.org/viewvc/llvm-project?rev=318515=rev
Log:
Implement more accurate penalty & trade-offs while breaking protruding tokens.

For each line that we break in a protruding token, compute whether the
penalty of breaking is actually larger than the penalty of the excess
characters. Only break if that is the case.

Modified:
cfe/trunk/lib/Format/BreakableToken.cpp
cfe/trunk/lib/Format/BreakableToken.h
cfe/trunk/lib/Format/ContinuationIndenter.cpp
cfe/trunk/unittests/Format/FormatTest.cpp
cfe/trunk/unittests/Format/FormatTestComments.cpp

Modified: cfe/trunk/lib/Format/BreakableToken.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/BreakableToken.cpp?rev=318515=318514=318515=diff
==
--- cfe/trunk/lib/Format/BreakableToken.cpp (original)
+++ cfe/trunk/lib/Format/BreakableToken.cpp Fri Nov 17 03:17:15 2017
@@ -605,9 +605,9 @@ unsigned BreakableBlockComment::getLineL
   }
 }
 
-bool BreakableBlockComment::introducesBreakBefore(unsigned LineIndex) const {
+bool BreakableBlockComment::introducesBreakBeforeToken() const {
   // A break is introduced when we want delimiters on newline.
-  return LineIndex == 0 && DelimitersOnNewline &&
+  return DelimitersOnNewline &&
  Lines[0].substr(1).find_first_not_of(Blanks) != StringRef::npos;
 }
 

Modified: cfe/trunk/lib/Format/BreakableToken.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/BreakableToken.h?rev=318515=318514=318515=diff
==
--- cfe/trunk/lib/Format/BreakableToken.h (original)
+++ cfe/trunk/lib/Format/BreakableToken.h Fri Nov 17 03:17:15 2017
@@ -137,9 +137,9 @@ public:
 return Split(StringRef::npos, 0);
   }
 
-  /// \brief Returns if a break before the content at \p LineIndex will be
-  /// inserted after the whitespace preceding the content has been reformatted.
-  virtual bool introducesBreakBefore(unsigned LineIndex) const {
+  /// \brief Returns whether there will be a line break at the start of the
+  /// token.
+  virtual bool introducesBreakBeforeToken() const {
 return false;
   }
 
@@ -347,7 +347,7 @@ public:
   Split getSplitBefore(unsigned LineIndex, unsigned PreviousEndColumn,
unsigned ColumnLimit,
llvm::Regex ) const override;
-  bool introducesBreakBefore(unsigned LineIndex) const override;
+  bool introducesBreakBeforeToken() const override;
   unsigned getLineLengthAfterSplitBefore(unsigned LineIndex,
  unsigned TailOffset,
  unsigned PreviousEndColumn,

Modified: cfe/trunk/lib/Format/ContinuationIndenter.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/ContinuationIndenter.cpp?rev=318515=318514=318515=diff
==
--- cfe/trunk/lib/Format/ContinuationIndenter.cpp (original)
+++ cfe/trunk/lib/Format/ContinuationIndenter.cpp Fri Nov 17 03:17:15 2017
@@ -1487,8 +1487,14 @@ unsigned ContinuationIndenter::breakProt
   if (Current.UnbreakableTailLength >= ColumnLimit)
 return 0;
 
+  unsigned NewBreakPenalty = Current.isStringLiteral()
+ ? Style.PenaltyBreakString
+ : Style.PenaltyBreakComment;
   unsigned RemainingSpace = ColumnLimit - Current.UnbreakableTailLength;
-  bool BreakInserted = false;
+  bool BreakInserted = Token->introducesBreakBeforeToken();
+  // Store whether we inserted a new line break at the end of the previous
+  // logical line.
+  bool NewBreakBefore = false;
   // We use a conservative reflowing strategy. Reflow starts after a line is
   // broken or the corresponding whitespace compressed. Reflow ends as soon as 
a
   // line that doesn't get reflown with the previous line is reached.
@@ -1496,23 +1502,50 @@ unsigned ContinuationIndenter::breakProt
   unsigned Penalty = 0;
   unsigned RemainingTokenColumns = 0;
   unsigned TailOffset = 0;
+  DEBUG(llvm::dbgs() << "Breaking protruding token at column " << StartColumn
+ << ".\n");
   for (unsigned LineIndex = 0, EndIndex = Token->getLineCount();
LineIndex != EndIndex; ++LineIndex) {
+DEBUG(llvm::dbgs() << "  Line: " << LineIndex
+   << " (Reflow: " << ReflowInProgress << ")\n");
 BreakableToken::Split SplitBefore(StringRef::npos, 0);
 if (ReflowInProgress) {
   SplitBefore = Token->getSplitBefore(LineIndex, RemainingTokenColumns,
   RemainingSpace, CommentPragmasRegex);
 }
 ReflowInProgress = SplitBefore.first != StringRef::npos;
+DEBUG({
+  if (ReflowInProgress)
+llvm::dbgs() << "  Reflowing.\n";
+});
 TailOffset =
 ReflowInProgress ? (SplitBefore.first 

r318141 - Refactor ContinuationIndenter's breakProtrudingToken logic.

2017-11-14 Thread Manuel Klimek via cfe-commits
Author: klimek
Date: Tue Nov 14 01:19:53 2017
New Revision: 318141

URL: http://llvm.org/viewvc/llvm-project?rev=318141=rev
Log:
Refactor ContinuationIndenter's breakProtrudingToken logic.

Create more orthogonal pieces. The restructuring made it easy to try out
several alternatives to D33589, and while none of the alternatives
turned out to be the right solution, the underlying simplification of
the structure is helpful.

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

Modified:
cfe/trunk/lib/Format/BreakableToken.cpp
cfe/trunk/lib/Format/ContinuationIndenter.cpp
cfe/trunk/lib/Format/ContinuationIndenter.h
cfe/trunk/unittests/Format/FormatTest.cpp
cfe/trunk/unittests/Format/FormatTestComments.cpp

Modified: cfe/trunk/lib/Format/BreakableToken.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/BreakableToken.cpp?rev=318141=318140=318141=diff
==
--- cfe/trunk/lib/Format/BreakableToken.cpp (original)
+++ cfe/trunk/lib/Format/BreakableToken.cpp Tue Nov 14 01:19:53 2017
@@ -749,6 +749,7 @@ BreakableLineCommentSection::BreakableLi
 Prefix.resize(Lines.size());
 OriginalPrefix.resize(Lines.size());
 for (size_t i = FirstLineIndex, e = Lines.size(); i < e; ++i) {
+  Lines[i] = Lines[i].ltrim(Blanks);
   // We need to trim the blanks in case this is not the first line in a
   // multiline comment. Then the indent is included in Lines[i].
   StringRef IndentPrefix =

Modified: cfe/trunk/lib/Format/ContinuationIndenter.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/ContinuationIndenter.cpp?rev=318141=318140=318141=diff
==
--- cfe/trunk/lib/Format/ContinuationIndenter.cpp (original)
+++ cfe/trunk/lib/Format/ContinuationIndenter.cpp Tue Nov 14 01:19:53 2017
@@ -1008,8 +1008,8 @@ unsigned ContinuationIndenter::moveState
 
   moveStatePastFakeLParens(State, Newline);
   moveStatePastScopeCloser(State);
-  bool CanBreakProtrudingToken = !State.Stack.back().NoLineBreak &&
- !State.Stack.back().NoLineBreakInOperand;
+  bool AllowBreak = !State.Stack.back().NoLineBreak &&
+!State.Stack.back().NoLineBreakInOperand;
   moveStatePastScopeOpener(State, Newline);
   moveStatePastFakeRParens(State);
 
@@ -1023,13 +1023,9 @@ unsigned ContinuationIndenter::moveState
 
   State.Column += Current.ColumnWidth;
   State.NextToken = State.NextToken->Next;
-  unsigned Penalty = 0;
-  if (CanBreakProtrudingToken)
-Penalty = breakProtrudingToken(Current, State, DryRun);
-  if (State.Column > getColumnLimit(State)) {
-unsigned ExcessCharacters = State.Column - getColumnLimit(State);
-Penalty += Style.PenaltyExcessCharacter * ExcessCharacters;
-  }
+
+  unsigned Penalty =
+  handleEndOfLine(Current, State, DryRun, AllowBreak);
 
   if (Current.Role)
 Current.Role->formatFromToken(State, this, DryRun);
@@ -1282,8 +1278,10 @@ static unsigned getLastLineEndColumn(Str
 }
 
 unsigned ContinuationIndenter::reformatRawStringLiteral(
-const FormatToken , unsigned StartColumn, LineState ,
-StringRef Delimiter, const FormatStyle , bool DryRun) {
+const FormatToken , LineState ,
+const FormatStyle , bool DryRun) {
+  unsigned StartColumn = State.Column - Current.ColumnWidth;
+  auto Delimiter = *getRawStringDelimiter(Current.TokenText);
   // The text of a raw string is between the leading 'R"delimiter(' and the
   // trailing 'delimiter)"'.
   unsigned PrefixSize = 3 + Delimiter.size();
@@ -1353,9 +1351,6 @@ unsigned ContinuationIndenter::reformatR
 
 unsigned ContinuationIndenter::addMultilineToken(const FormatToken ,
  LineState ) {
-  if (!Current.IsMultiline)
-return 0;
-
   // Break before further function parameters on all levels.
   for (unsigned i = 0, e = State.Stack.size(); i != e; ++i)
 State.Stack[i].BreakBeforeParameter = true;
@@ -1370,42 +1365,56 @@ unsigned ContinuationIndenter::addMultil
   return 0;
 }
 
-unsigned ContinuationIndenter::breakProtrudingToken(const FormatToken ,
-LineState ,
-bool DryRun) {
+unsigned ContinuationIndenter::handleEndOfLine(const FormatToken ,
+   LineState , bool DryRun,
+   bool AllowBreak) {
+  unsigned Penalty = 0;
   // Compute the raw string style to use in case this is a raw string literal
   // that can be reformatted.
-  llvm::Optional Delimiter = None;
-  llvm::Optional RawStringStyle = None;
-  if (Current.isStringLiteral())
-Delimiter = getRawStringDelimiter(Current.TokenText);
-  if (Delimiter)
-RawStringStyle = RawStringFormats.get(*Delimiter);
-
-  // Don't break multi-line tokens other than block comments and raw 

Re: [PATCH] D5767: Template Instantiation Observer + a few other templight-related changes

2017-11-09 Thread Manuel Klimek via cfe-commits
On Thu, Nov 9, 2017 at 4:02 AM Richard Smith - zygoloid via Phabricator <
revi...@reviews.llvm.org> wrote:

> rsmith added a comment.
>
> I'm not entirely sure what's happening with this and
> https://reviews.llvm.org/D38818, but the direction looks good to me, and
> I left a couple of comments on the other review thread.
>

This patch had some of my comments addressed :(
(around how the interface is structured)
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r313744 - clang-format clang-format.

2017-09-20 Thread Manuel Klimek via cfe-commits
Author: klimek
Date: Wed Sep 20 02:51:03 2017
New Revision: 313744

URL: http://llvm.org/viewvc/llvm-project?rev=313744=rev
Log:
clang-format clang-format.

Modified:
cfe/trunk/lib/Format/BreakableToken.cpp
cfe/trunk/lib/Format/ContinuationIndenter.cpp
cfe/trunk/lib/Format/Format.cpp
cfe/trunk/lib/Format/FormatToken.cpp
cfe/trunk/lib/Format/FormatToken.h
cfe/trunk/lib/Format/FormatTokenLexer.cpp
cfe/trunk/lib/Format/SortJavaScriptImports.cpp
cfe/trunk/lib/Format/TokenAnalyzer.cpp
cfe/trunk/lib/Format/TokenAnnotator.cpp
cfe/trunk/lib/Format/UnwrappedLineFormatter.cpp
cfe/trunk/lib/Format/UnwrappedLineFormatter.h
cfe/trunk/lib/Format/UnwrappedLineParser.cpp
cfe/trunk/lib/Format/UnwrappedLineParser.h
cfe/trunk/lib/Format/WhitespaceManager.cpp

Modified: cfe/trunk/lib/Format/BreakableToken.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/BreakableToken.cpp?rev=313744=313743=313744=diff
==
--- cfe/trunk/lib/Format/BreakableToken.cpp (original)
+++ cfe/trunk/lib/Format/BreakableToken.cpp Wed Sep 20 02:51:03 2017
@@ -41,8 +41,8 @@ static bool IsBlank(char C) {
 }
 
 static StringRef getLineCommentIndentPrefix(StringRef Comment) {
-  static const char *const KnownPrefixes[] = {
-  "///<", "//!<", "///", "//", "//!"};
+  static const char *const KnownPrefixes[] = {"///<", "//!<", "///", "//",
+  "//!"};
   StringRef LongestPrefix;
   for (StringRef KnownPrefix : KnownPrefixes) {
 if (Comment.startswith(KnownPrefix)) {
@@ -225,8 +225,7 @@ void BreakableStringLiteral::insertBreak
 }
 
 BreakableComment::BreakableComment(const FormatToken ,
-   unsigned StartColumn,
-   bool InPPDirective,
+   unsigned StartColumn, bool InPPDirective,
encoding::Encoding Encoding,
const FormatStyle )
 : BreakableToken(Token, InPPDirective, Encoding, Style),
@@ -309,7 +308,7 @@ static bool mayReflowContent(StringRef C
   // Lines starting with '@' commonly have special meaning.
   // Lines starting with '-', '-#', '+' or '*' are bulleted/numbered lists.
   static const SmallVector kSpecialMeaningPrefixes = {
-  "@", "TODO", "FIXME", "XXX", "-# ", "- ", "+ ", "* " };
+  "@", "TODO", "FIXME", "XXX", "-# ", "- ", "+ ", "* "};
   bool hasSpecialMeaningPrefix = false;
   for (StringRef Prefix : kSpecialMeaningPrefixes) {
 if (Content.startswith(Prefix)) {
@@ -322,8 +321,8 @@ static bool mayReflowContent(StringRef C
   // To avoid issues if a line starts with a number which is actually the end
   // of a previous line, we only consider numbers with up to 2 digits.
   static llvm::Regex kNumberedListRegexp = llvm::Regex("^[1-9][0-9]?\\. ");
-  hasSpecialMeaningPrefix = hasSpecialMeaningPrefix ||
-kNumberedListRegexp.match(Content);
+  hasSpecialMeaningPrefix =
+  hasSpecialMeaningPrefix || kNumberedListRegexp.match(Content);
 
   // Simple heuristic for what to reflow: content should contain at least two
   // characters and either the first or second character must be
@@ -385,8 +384,7 @@ BreakableBlockComment::BreakableBlockCom
 // If the last line is empty, the closing "*/" will have a star.
 if (i + 1 == e && Content[i].empty())
   break;
-if (!Content[i].empty() && i + 1 != e &&
-Decoration.startswith(Content[i]))
+if (!Content[i].empty() && i + 1 != e && Decoration.startswith(Content[i]))
   continue;
 while (!Content[i].startswith(Decoration))
   Decoration = Decoration.substr(0, Decoration.size() - 1);
@@ -428,8 +426,7 @@ BreakableBlockComment::BreakableBlockCom
   IndentAtLineBreak =
   std::min(IndentAtLineBreak, std::max(0, ContentColumn[i]));
   }
-  IndentAtLineBreak =
-  std::max(IndentAtLineBreak, Decoration.size());
+  IndentAtLineBreak = std::max(IndentAtLineBreak, Decoration.size());
 
   // Detect a multiline jsdoc comment and set DelimitersOnNewline in that case.
   if (Style.Language == FormatStyle::LK_JavaScript ||
@@ -441,8 +438,11 @@ BreakableBlockComment::BreakableBlockCom
   // Detect a long single-line comment, like:
   // /** long long long */
   // Below, '2' is the width of '*/'.
-  unsigned EndColumn = ContentColumn[0] + encoding::columnWidthWithTabs(
-  Lines[0], ContentColumn[0], Style.TabWidth, Encoding) + 2;
+  unsigned EndColumn =
+  ContentColumn[0] +
+  encoding::columnWidthWithTabs(Lines[0], ContentColumn[0],
+Style.TabWidth, Encoding) +
+  2;
   DelimitersOnNewline = EndColumn > Style.ColumnLimit;
 }
   }
@@ -559,27 +559,24 @@ BreakableToken::Split BreakableBlockComm
   return Result;
 }
 
-unsigned 

r313742 - Fix clang-format's detection of structured bindings.

2017-09-20 Thread Manuel Klimek via cfe-commits
Author: klimek
Date: Wed Sep 20 02:29:37 2017
New Revision: 313742

URL: http://llvm.org/viewvc/llvm-project?rev=313742=rev
Log:
Fix clang-format's detection of structured bindings.

Correctly determine when [ is part of a structured binding instead of a
lambda.

To be able to reuse the implementation already available, this patch also:
- sets the Previous link of FormatTokens in the UnwrappedLineParser
- moves the isCppStructuredBinding function into FormatToken

Before:
  auto const const &&[x, y] { A *i };

After:
  auto const const && [x, y]{A * i};

Fixing formatting of the type of the structured binding is still missing.

Modified:
cfe/trunk/lib/Format/FormatToken.h
cfe/trunk/lib/Format/TokenAnnotator.cpp
cfe/trunk/lib/Format/UnwrappedLineParser.cpp
cfe/trunk/lib/Format/UnwrappedLineParser.h
cfe/trunk/unittests/Format/FormatTest.cpp

Modified: cfe/trunk/lib/Format/FormatToken.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/FormatToken.h?rev=313742=313741=313742=diff
==
--- cfe/trunk/lib/Format/FormatToken.h (original)
+++ cfe/trunk/lib/Format/FormatToken.h Wed Sep 20 02:29:37 2017
@@ -472,6 +472,19 @@ struct FormatToken {
   Style.Language == FormatStyle::LK_TextProto));
   }
 
+  /// \brief Returns whether the token is the left square bracket of a C++
+  /// structured binding declaration.
+  bool isCppStructuredBinding(const FormatStyle ) const {
+if (!Style.isCpp() || isNot(tok::l_square))
+  return false;
+const FormatToken* T = this;
+do {
+  T = T->getPreviousNonComment();
+} while (T && T->isOneOf(tok::kw_const, tok::kw_volatile, tok::amp,
+ tok::ampamp));
+return T && T->is(tok::kw_auto);
+  }
+
   /// \brief Same as opensBlockOrBlockTypeList, but for the closing token.
   bool closesBlockOrBlockTypeList(const FormatStyle ) const {
 if (is(TT_TemplateString) && closesScope())

Modified: cfe/trunk/lib/Format/TokenAnnotator.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/TokenAnnotator.cpp?rev=313742=313741=313742=diff
==
--- cfe/trunk/lib/Format/TokenAnnotator.cpp (original)
+++ cfe/trunk/lib/Format/TokenAnnotator.cpp Wed Sep 20 02:29:37 2017
@@ -310,16 +310,6 @@ private:
 return false;
   }
 
-  bool isCppStructuredBinding(const FormatToken *Tok) {
-if (!Style.isCpp() || !Tok->is(tok::l_square))
-  return false;
-do {
-  Tok = Tok->getPreviousNonComment();
-} while (Tok && Tok->isOneOf(tok::kw_const, tok::kw_volatile, tok::amp,
- tok::ampamp));
-return Tok && Tok->is(tok::kw_auto);
-  }
-
   bool parseSquare() {
 if (!CurrentToken)
   return false;
@@ -354,7 +344,7 @@ private:
 
 unsigned BindingIncrease = 1;
 if (Left->is(TT_Unknown)) {
-  if (isCppStructuredBinding(Left)) {
+  if (Left->isCppStructuredBinding(Style)) {
 Left->Type = TT_StructuredBindingLSquare;
   } else if (StartsObjCMethodExpr) {
 Left->Type = TT_ObjCMethodExpr;

Modified: cfe/trunk/lib/Format/UnwrappedLineParser.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/UnwrappedLineParser.cpp?rev=313742=313741=313742=diff
==
--- cfe/trunk/lib/Format/UnwrappedLineParser.cpp (original)
+++ cfe/trunk/lib/Format/UnwrappedLineParser.cpp Wed Sep 20 02:29:37 2017
@@ -356,7 +356,7 @@ void UnwrappedLineParser::calculateBrace
   // definitions, too.
   unsigned StoredPosition = Tokens->getPosition();
   FormatToken *Tok = FormatTok;
-  const FormatToken *PrevTok = getPreviousToken();
+  const FormatToken *PrevTok =  Tok->Previous;
   // Keep a stack of positions of lbrace tokens. We will
   // update information about whether an lbrace starts a
   // braced init list or a different block during the loop.
@@ -1100,7 +1100,7 @@ void UnwrappedLineParser::parseStructura
 break;
   }
   do {
-const FormatToken *Previous = getPreviousToken();
+const FormatToken *Previous = FormatTok->Previous;
 switch (FormatTok->Tok.getKind()) {
 case tok::at:
   nextToken();
@@ -1356,10 +1356,11 @@ bool UnwrappedLineParser::tryToParseLamb
 }
 
 bool UnwrappedLineParser::tryToParseLambdaIntroducer() {
-  const FormatToken* Previous = getPreviousToken();
+  const FormatToken* Previous = FormatTok->Previous;
   if (Previous &&
   (Previous->isOneOf(tok::identifier, tok::kw_operator, tok::kw_new,
  tok::kw_delete) ||
+   FormatTok->isCppStructuredBinding(Style) ||
Previous->closesScope() || Previous->isSimpleTypeSpecifier())) {
 nextToken();
 return false;
@@ -2232,6 +2233,8 @@ void UnwrappedLineParser::addUnwrappedLi
 std::make_move_iterator(PreprocessorDirectives.end()));
 

r313622 - Fix formatting of lambda introducers with initializers.

2017-09-19 Thread Manuel Klimek via cfe-commits
Author: klimek
Date: Tue Sep 19 02:59:30 2017
New Revision: 313622

URL: http://llvm.org/viewvc/llvm-project?rev=313622=rev
Log:
Fix formatting of lambda introducers with initializers.

Most of the work was already done when we introduced a look-behind based
lambda introducer detection.

This patch finishes the transition by completely relying on the simple
lambda introducer detection and simply recursing into normal
brace-parsing code to parse until the end of the introducer.

This fixes initializers in lambdas, including nested lambdas.

Before:
  auto a = [b = [c = 42]{}]{};
  auto b = [c =  + 23]{};

After:
  auto a = [b = [c = 42] {}] {};
  auto b = [c =  + 23] {};

Modified:
cfe/trunk/lib/Format/UnwrappedLineParser.cpp
cfe/trunk/lib/Format/UnwrappedLineParser.h
cfe/trunk/unittests/Format/FormatTest.cpp

Modified: cfe/trunk/lib/Format/UnwrappedLineParser.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/UnwrappedLineParser.cpp?rev=313622=313621=313622=diff
==
--- cfe/trunk/lib/Format/UnwrappedLineParser.cpp (original)
+++ cfe/trunk/lib/Format/UnwrappedLineParser.cpp Tue Sep 19 02:59:30 2017
@@ -1314,14 +1314,6 @@ bool UnwrappedLineParser::tryToParseLamb
 nextToken();
 return false;
   }
-  const FormatToken* Previous = getPreviousToken();
-  if (Previous &&
-  (Previous->isOneOf(tok::identifier, tok::kw_operator, tok::kw_new,
- tok::kw_delete) ||
-   Previous->closesScope() || Previous->isSimpleTypeSpecifier())) {
-nextToken();
-return false;
-  }
   assert(FormatTok->is(tok::l_square));
   FormatToken  = *FormatTok;
   if (!tryToParseLambdaIntroducer())
@@ -1364,49 +1356,17 @@ bool UnwrappedLineParser::tryToParseLamb
 }
 
 bool UnwrappedLineParser::tryToParseLambdaIntroducer() {
-  nextToken();
-  if (FormatTok->is(tok::equal)) {
-nextToken();
-if (FormatTok->is(tok::r_square)) {
-  nextToken();
-  return true;
-}
-if (FormatTok->isNot(tok::comma))
-  return false;
-nextToken();
-  } else if (FormatTok->is(tok::amp)) {
-nextToken();
-if (FormatTok->is(tok::r_square)) {
-  nextToken();
-  return true;
-}
-if (!FormatTok->isOneOf(tok::comma, tok::identifier)) {
-  return false;
-}
-if (FormatTok->is(tok::comma))
-  nextToken();
-  } else if (FormatTok->is(tok::r_square)) {
+  const FormatToken* Previous = getPreviousToken();
+  if (Previous &&
+  (Previous->isOneOf(tok::identifier, tok::kw_operator, tok::kw_new,
+ tok::kw_delete) ||
+   Previous->closesScope() || Previous->isSimpleTypeSpecifier())) {
 nextToken();
-return true;
+return false;
   }
-  do {
-if (FormatTok->is(tok::amp))
-  nextToken();
-if (!FormatTok->isOneOf(tok::identifier, tok::kw_this))
-  return false;
-nextToken();
-if (FormatTok->is(tok::ellipsis))
-  nextToken();
-if (FormatTok->is(tok::comma)) {
-  nextToken();
-} else if (FormatTok->is(tok::r_square)) {
-  nextToken();
-  return true;
-} else {
-  return false;
-}
-  } while (!eof());
-  return false;
+  nextToken();
+  parseSquare(/*LambdaIntroducer=*/true);
+  return true;
 }
 
 void UnwrappedLineParser::tryToParseJSFunction() {
@@ -1608,10 +1568,12 @@ void UnwrappedLineParser::parseParens()
   } while (!eof());
 }
 
-void UnwrappedLineParser::parseSquare() {
-  assert(FormatTok->Tok.is(tok::l_square) && "'[' expected.");
-  if (tryToParseLambda())
-return;
+void UnwrappedLineParser::parseSquare(bool LambdaIntroducer) {
+  if (!LambdaIntroducer) {
+assert(FormatTok->Tok.is(tok::l_square) && "'[' expected.");
+if (tryToParseLambda())
+  return;
+  }
   do {
 switch (FormatTok->Tok.getKind()) {
 case tok::l_paren:

Modified: cfe/trunk/lib/Format/UnwrappedLineParser.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/UnwrappedLineParser.h?rev=313622=313621=313622=diff
==
--- cfe/trunk/lib/Format/UnwrappedLineParser.h (original)
+++ cfe/trunk/lib/Format/UnwrappedLineParser.h Tue Sep 19 02:59:30 2017
@@ -96,7 +96,7 @@ private:
   bool parseBracedList(bool ContinueOnSemicolons = false,
tok::TokenKind ClosingBraceKind = tok::r_brace);
   void parseParens();
-  void parseSquare();
+  void parseSquare(bool LambdaIntroducer = false);
   void parseIfThenElse();
   void parseTryCatch();
   void parseForOrWhileLoop();

Modified: cfe/trunk/unittests/Format/FormatTest.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTest.cpp?rev=313622=313621=313622=diff
==
--- cfe/trunk/unittests/Format/FormatTest.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTest.cpp Tue Sep 19 02:59:30 2017
@@ -10770,6 +10770,8 @@ TEST_F(FormatTest, 

r310041 - Fix typo and update documentation.

2017-08-04 Thread Manuel Klimek via cfe-commits
Author: klimek
Date: Fri Aug  4 01:41:42 2017
New Revision: 310041

URL: http://llvm.org/viewvc/llvm-project?rev=310041=rev
Log:
Fix typo and update documentation.

The hasDeclaration documentation was outdated after r288366.

Modified:
cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h

Modified: cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h?rev=310041=310040=310041=diff
==
--- cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h (original)
+++ cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h Fri Aug  4 01:41:42 2017
@@ -2566,8 +2566,21 @@ const internal::VariadicOperatorMatcherF
 /// - for CXXConstructExpr, the declaration of the constructor
 /// - for CXXNewExpr, the declaration of the operator new
 ///
-/// Also usable as Matcher for any T supporting the getDecl() member
-/// function. e.g. various subtypes of clang::Type and various expressions.
+/// For type nodes, hasDeclaration will generally match the declaration of the
+/// sugared type. Given
+/// \code
+///   class X {};
+///   typedef X Y;
+///   Y y;
+/// \endcode
+/// in varDecl(hasType(hasDeclaration(decl( the decl will match the
+/// typedefDecl. A common use case is to match the underlying, desugared type.
+/// This can be achieved by using the hasUnqualifiedDesugaredType matcher:
+/// \code
+///   varDecl(hasType(hasUnqualifiedDesugaredType(
+///   recordType(hasDeclaration(decl())
+/// \endcode
+/// In this matcher, the decl will match the CXXRecordDecl of class X.
 ///
 /// Usable as: Matcher, Matcher,
 ///   Matcher, Matcher, Matcher,
@@ -2860,7 +2873,7 @@ AST_MATCHER_P_OVERLOAD(QualType, pointsT
 ///   class A {};
 ///   using B = A;
 /// \endcode
-/// The matcher type(hasUniqualifeidDesugaredType(recordType())) matches
+/// The matcher type(hasUnqualifeidDesugaredType(recordType())) matches
 /// both B and A.
 AST_MATCHER_P(Type, hasUnqualifiedDesugaredType, internal::Matcher,
   InnerMatcher) {


___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] r309810 - Adapt clang-tidy checks to changing semantics of hasDeclaration.

2017-08-02 Thread Manuel Klimek via cfe-commits
Author: klimek
Date: Wed Aug  2 06:13:11 2017
New Revision: 309810

URL: http://llvm.org/viewvc/llvm-project?rev=309810=rev
Log:
Adapt clang-tidy checks to changing semantics of hasDeclaration.

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

Modified:
clang-tools-extra/trunk/clang-tidy/google/StringReferenceMemberCheck.cpp
clang-tools-extra/trunk/clang-tidy/misc/DanglingHandleCheck.cpp
clang-tools-extra/trunk/clang-tidy/misc/InaccurateEraseCheck.cpp
clang-tools-extra/trunk/clang-tidy/misc/UseAfterMoveCheck.cpp
clang-tools-extra/trunk/clang-tidy/modernize/LoopConvertCheck.cpp
clang-tools-extra/trunk/clang-tidy/modernize/MakeSharedCheck.cpp
clang-tools-extra/trunk/clang-tidy/modernize/MakeUniqueCheck.cpp
clang-tools-extra/trunk/clang-tidy/performance/FasterStringFindCheck.cpp

clang-tools-extra/trunk/clang-tidy/performance/InefficientStringConcatenationCheck.cpp
clang-tools-extra/trunk/clang-tidy/readability/ContainerSizeEmptyCheck.cpp
clang-tools-extra/trunk/clang-tidy/readability/RedundantStringCStrCheck.cpp
clang-tools-extra/trunk/clang-tidy/readability/RedundantStringInitCheck.cpp
clang-tools-extra/trunk/include-fixer/find-all-symbols/FindAllSymbols.cpp

Modified: 
clang-tools-extra/trunk/clang-tidy/google/StringReferenceMemberCheck.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/google/StringReferenceMemberCheck.cpp?rev=309810=309809=309810=diff
==
--- clang-tools-extra/trunk/clang-tidy/google/StringReferenceMemberCheck.cpp 
(original)
+++ clang-tools-extra/trunk/clang-tidy/google/StringReferenceMemberCheck.cpp 
Wed Aug  2 06:13:11 2017
@@ -27,8 +27,8 @@ void StringReferenceMemberCheck::registe
 return;
 
   // Look for const references to std::string or ::string.
-  auto String = anyOf(recordDecl(hasName("::std::basic_string")),
-  recordDecl(hasName("::string")));
+  auto String = anyOf(namedDecl(hasName("::std::string")),
+  namedDecl(hasName("::string")));
   auto ConstString = qualType(isConstQualified(), hasDeclaration(String));
 
   // Ignore members in template instantiations.

Modified: clang-tools-extra/trunk/clang-tidy/misc/DanglingHandleCheck.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/misc/DanglingHandleCheck.cpp?rev=309810=309809=309810=diff
==
--- clang-tools-extra/trunk/clang-tidy/misc/DanglingHandleCheck.cpp (original)
+++ clang-tools-extra/trunk/clang-tidy/misc/DanglingHandleCheck.cpp Wed Aug  2 
06:13:11 2017
@@ -71,11 +71,13 @@ ast_matchers::internal::BindableMatcher<
   // For sequences: assign, push_back, resize.
   cxxMemberCallExpr(
   callee(functionDecl(hasAnyName("assign", "push_back", 
"resize"))),
-  on(expr(hasType(recordDecl(isASequence()),
+  on(expr(hasType(hasUnqualifiedDesugaredType(
+  recordType(hasDeclaration(recordDecl(isASequence(),
   // For sequences and sets: insert.
-  cxxMemberCallExpr(
-  callee(functionDecl(hasName("insert"))),
-  on(expr(hasType(recordDecl(anyOf(isASequence(), isASet())),
+  cxxMemberCallExpr(callee(functionDecl(hasName("insert"))),
+on(expr(hasType(hasUnqualifiedDesugaredType(
+recordType(hasDeclaration(recordDecl(
+anyOf(isASequence(), isASet()),
   // For maps: operator[].
   cxxOperatorCallExpr(callee(cxxMethodDecl(ofClass(isAMap(,
   hasOverloadedOperatorName("[]";
@@ -103,7 +105,8 @@ void DanglingHandleCheck::registerMatche
 
   // Find 'Handle foo(ReturnsAValue());'
   Finder->addMatcher(
-  varDecl(hasType(cxxRecordDecl(IsAHandle)),
+  varDecl(hasType(hasUnqualifiedDesugaredType(
+  recordType(hasDeclaration(cxxRecordDecl(IsAHandle),
   hasInitializer(
   exprWithCleanups(has(ignoringParenImpCasts(ConvertedHandle)))
   .bind("bad_stmt"))),
@@ -112,7 +115,9 @@ void DanglingHandleCheck::registerMatche
   // Find 'Handle foo = ReturnsAValue();'
   Finder->addMatcher(
   varDecl(
-  hasType(cxxRecordDecl(IsAHandle)), unless(parmVarDecl()),
+  hasType(hasUnqualifiedDesugaredType(
+  recordType(hasDeclaration(cxxRecordDecl(IsAHandle),
+  unless(parmVarDecl()),
   hasInitializer(exprWithCleanups(has(ignoringParenImpCasts(handleFrom(
   IsAHandle, ConvertedHandle
  .bind("bad_stmt"))),
@@ -139,13 +144,15 @@ void DanglingHandleCheck::registerMatche
   // We have to match both.
   has(ignoringImplicit(handleFrom(
 

r309809 - Unify and simplify the behavior of the hasDeclaration matcher.

2017-08-02 Thread Manuel Klimek via cfe-commits
Author: klimek
Date: Wed Aug  2 06:04:44 2017
New Revision: 309809

URL: http://llvm.org/viewvc/llvm-project?rev=309809=rev
Log:
Unify and simplify the behavior of the hasDeclaration matcher.

Originally, we weren't able to match on Type nodes themselves (only QualType),
so the hasDeclaration matcher was initially written to give what we thought are
reasonable results for QualType matches.

When we chagned the matchers to allow matching on Type nodes, it turned out
that the hasDeclaration matcher was by chance written templated enough to now
allow hasDeclaration to also match on (some) Type nodes.

This patch change the hasDeclaration matcher to:
a) work the same on Type and QualType nodes,
b) be completely explicit about what nodes we can match instead of just allowing
   anything with a getDecl() to match,
c) explicitly control desugaring only one level in very specific instances.
d) adds hasSpecializedTemplate and tagType matchers to allow migrating
  existing use cases that now need more explicit matchers

Note: This patch breaks clang-tools-extra. The corresponding patch there
is approved and will land in a subsequent patch.

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

Modified:
cfe/trunk/docs/LibASTMatchersReference.html
cfe/trunk/docs/ReleaseNotes.rst
cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h
cfe/trunk/include/clang/ASTMatchers/ASTMatchersInternal.h
cfe/trunk/unittests/AST/ASTImporterTest.cpp
cfe/trunk/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp

Modified: cfe/trunk/docs/LibASTMatchersReference.html
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/docs/LibASTMatchersReference.html?rev=309809=309808=309809=diff
==
--- cfe/trunk/docs/LibASTMatchersReference.html (original)
+++ cfe/trunk/docs/LibASTMatchersReference.html Wed Aug  2 06:04:44 2017
@@ -1729,6 +1729,21 @@ substTemplateTypeParmType() matches the
 
 
 
+Matcherhttp://clang.llvm.org/doxygen/classclang_1_1Type.html;>TypetagTypeMatcherhttp://clang.llvm.org/doxygen/classclang_1_1TagType.html;>TagType...
+Matches tag types (record 
and enum types).
+
+Given
+  enum E {};
+  class C {};
+
+  E e;
+  C c;
+
+tagType() matches the type of the variable declarations of both e
+and c.
+
+
+
 Matcherhttp://clang.llvm.org/doxygen/classclang_1_1Type.html;>TypetemplateSpecializationTypeMatcherhttp://clang.llvm.org/doxygen/classclang_1_1TemplateSpecializationType.html;>TemplateSpecializationType...
 Matches 
template specialization types.
 
@@ -4546,6 +4561,18 @@ functionDecl(hasAnyTemplateArgument(refe
 
 
 
+Matcherhttp://clang.llvm.org/doxygen/classclang_1_1ClassTemplateSpecializationDecl.html;>ClassTemplateSpecializationDeclhasSpecializedTemplateMatcherhttp://clang.llvm.org/doxygen/classclang_1_1ClassTemplateDecl.html;>ClassTemplateDecl
 InnerMatcher
+Matches the 
specialized template of a specialization declaration.
+
+Given
+  tempalatetypename T class A {};
+  typedef Aint B;
+classTemplateSpecializationDecl(hasSpecializedTemplate(classTemplateDecl()))
+  matches 'B' with classTemplateDecl() matching the class template
+  declaration of 'A'.
+
+
+
 Matcherhttp://clang.llvm.org/doxygen/classclang_1_1ClassTemplateSpecializationDecl.html;>ClassTemplateSpecializationDeclhasTemplateArgumentunsigned N, 
Matcherhttp://clang.llvm.org/doxygen/classclang_1_1TemplateArgument.html;>TemplateArgument
 InnerMatcher
 Matches 
classTemplateSpecializations, templateSpecializationType and
 functionDecl where the n'th TemplateArgument matches the given InnerMatcher.

Modified: cfe/trunk/docs/ReleaseNotes.rst
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/docs/ReleaseNotes.rst?rev=309809=309808=309809=diff
==
--- cfe/trunk/docs/ReleaseNotes.rst (original)
+++ cfe/trunk/docs/ReleaseNotes.rst Wed Aug  2 06:04:44 2017
@@ -151,8 +151,33 @@ this section should help get you past th
 AST Matchers
 
 
-...
+The hasDeclaration matcher now works the same for Type and QualType and only
+ever looks through one level of sugaring in a limited number of cases.
 
+There are two main patterns affected by this:
+
+-  qualType(hasDeclaration(recordDecl(...))): previously, we would look through
+   sugar like TypedefType to get at the underlying recordDecl; now, we need
+   to explicitly remove the sugaring:
+   qualType(hasUnqualifiedDesugaredType(hasDeclaration(recordDecl(...
+
+-  hasType(recordDecl(...)): hasType internally uses hasDeclaration; 
previously,
+   this matcher used to match for example TypedefTypes of the RecordType, but
+   after the change they don't; to fix, use:
+
+::
+   hasType(hasUnqualifiedDesugaredType(
+   recordType(hasDeclaration(recordDecl(...)
+
+-  templateSpecializationType(hasDeclaration(classTemplateDecl(...))):
+   previously, we would directly match the underlying ClassTemplateDecl;
+   now, we can explicitly match the 

r308969 - Fix spelling of FileCheck in test.

2017-07-25 Thread Manuel Klimek via cfe-commits
Author: klimek
Date: Tue Jul 25 04:34:55 2017
New Revision: 308969

URL: http://llvm.org/viewvc/llvm-project?rev=308969=rev
Log:
Fix spelling of FileCheck in test.

Modified:
cfe/trunk/test/CodeGen/x86-ms-inline-asm-enum_feature.cpp

Modified: cfe/trunk/test/CodeGen/x86-ms-inline-asm-enum_feature.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/x86-ms-inline-asm-enum_feature.cpp?rev=308969=308968=308969=diff
==
--- cfe/trunk/test/CodeGen/x86-ms-inline-asm-enum_feature.cpp (original)
+++ cfe/trunk/test/CodeGen/x86-ms-inline-asm-enum_feature.cpp Tue Jul 25 
04:34:55 2017
@@ -1,5 +1,5 @@
 // REQUIRES: x86-registered-target
-// RUN: %clang_cc1 %s -fasm-blocks -emit-llvm -o - | FileCHECK %s
+// RUN: %clang_cc1 %s -fasm-blocks -emit-llvm -o - | FileCheck %s
 namespace x {
 enum { A = 12 };
 struct y_t {


___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r308962 - Fix incorrect use of current directory to find moved paths in ASTReader.

2017-07-25 Thread Manuel Klimek via cfe-commits
Author: klimek
Date: Tue Jul 25 03:22:06 2017
New Revision: 308962

URL: http://llvm.org/viewvc/llvm-project?rev=308962=rev
Log:
Fix incorrect use of current directory to find moved paths in ASTReader.

CurrentDir was set as the path of the current module, but that can change as
part of a chain of loaded modules.

When we try to locate a file mentioned in a module that does not exist, we use
a heuristic to look at the relative path between the original location of the
module and the file we look for, and use that relatively to the CurrentDir.

This only works if CurrentDir is the same as the (current) path of the module
file the file was mentioned in; if it is not, we look at the path relatively to
the wrong directory, and can end up reading random unrelated files that happen
to have the same name.

This patch fixes this by using the BaseDirectory of the module file the file
we look for was mentioned in instead of the CurrentDir heuristic.

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

Added:
cfe/trunk/test/Modules/path-resolution.modulemap
Modified:
cfe/trunk/include/clang/Serialization/ASTReader.h
cfe/trunk/lib/Serialization/ASTReader.cpp

Modified: cfe/trunk/include/clang/Serialization/ASTReader.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Serialization/ASTReader.h?rev=308962=308961=308962=diff
==
--- cfe/trunk/include/clang/Serialization/ASTReader.h (original)
+++ cfe/trunk/include/clang/Serialization/ASTReader.h Tue Jul 25 03:22:06 2017
@@ -867,9 +867,6 @@ private:
   SmallVector ImportedModules;
   //@}
 
-  /// \brief The directory that the PCH we are reading is stored in.
-  std::string CurrentDir;
-
   /// \brief The system include root to be used when loading the
   /// precompiled header.
   std::string isysroot;

Modified: cfe/trunk/lib/Serialization/ASTReader.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Serialization/ASTReader.cpp?rev=308962=308961=308962=diff
==
--- cfe/trunk/lib/Serialization/ASTReader.cpp (original)
+++ cfe/trunk/lib/Serialization/ASTReader.cpp Tue Jul 25 03:22:06 2017
@@ -2060,14 +2060,12 @@ InputFile ASTReader::getInputFile(Module
   StringRef Filename = FI.Filename;
 
   const FileEntry *File = FileMgr.getFile(Filename, /*OpenFile=*/false);
-
   // If we didn't find the file, resolve it relative to the
   // original directory from which this AST file was created.
-  if (File == nullptr && !F.OriginalDir.empty() && !CurrentDir.empty() &&
-  F.OriginalDir != CurrentDir) {
-std::string Resolved = resolveFileRelativeToOriginalDir(Filename,
-F.OriginalDir,
-CurrentDir);
+  if (File == nullptr && !F.OriginalDir.empty() && !F.BaseDirectory.empty() &&
+  F.OriginalDir != F.BaseDirectory) {
+std::string Resolved = resolveFileRelativeToOriginalDir(
+Filename, F.OriginalDir, F.BaseDirectory);
 if (!Resolved.empty())
   File = FileMgr.getFile(Resolved);
   }
@@ -4065,13 +4063,6 @@ ASTReader::ReadASTCore(StringRef FileNam
 
   assert(M && "Missing module file");
 
-  // FIXME: This seems rather a hack. Should CurrentDir be part of the
-  // module?
-  if (FileName != "-") {
-CurrentDir = llvm::sys::path::parent_path(FileName);
-if (CurrentDir.empty()) CurrentDir = ".";
-  }
-
   ModuleFile  = *M;
   BitstreamCursor  = F.Stream;
   Stream = BitstreamCursor(PCHContainerRdr.ExtractPCH(*F.Buffer));

Added: cfe/trunk/test/Modules/path-resolution.modulemap
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/path-resolution.modulemap?rev=308962=auto
==
--- cfe/trunk/test/Modules/path-resolution.modulemap (added)
+++ cfe/trunk/test/Modules/path-resolution.modulemap Tue Jul 25 03:22:06 2017
@@ -0,0 +1,70 @@
+// RUN: rm -rf %t
+//
+// First, create two modules a and b, with a dependency b -> a, both within
+// the same directory p1.
+//
+// RUN: mkdir -p %t/p1
+// RUN: cd %t/p1
+//
+// RUN: grep "" %s > %t/p1/a.modulemap
+// RUN: %clang_cc1 -x c++ -fmodules -emit-module -fmodule-map-file-home-is-cwd 
\
+// RUN:   -fmodules-embed-all-files -fmodules-local-submodule-visibility \
+// RUN:   -fmodule-name="a" -o a.pcm a.modulemap
+//
+// RUN: grep "" %s > %t/p1/b.modulemap
+// RUN: %clang_cc1 -x c++ -fmodules -emit-module -fmodule-map-file-home-is-cwd 
\
+// RUN:   -fmodules-embed-all-files -fmodules-local-submodule-visibility \
+// RUN:   -fmodule-name="b" -o b.pcm b.modulemap
+//
+// Next, move the whole tree p1 -> p2.
+//
+// RUN: cd %t
+// RUN: mv %t/p1 %t/p2
+// RUN: cd %t/p2
+//
+// Compile a new module c in the newly generated tree that depends on b; c.pcm
+// has to be within a subdirectory so a.modulemap will be 

[clang-tools-extra] r308290 - Add autoload cookies for clang-include-fixer lisp functions.

2017-07-18 Thread Manuel Klimek via cfe-commits
Author: klimek
Date: Tue Jul 18 03:15:07 2017
New Revision: 308290

URL: http://llvm.org/viewvc/llvm-project?rev=308290=rev
Log:
Add autoload cookies for clang-include-fixer lisp functions.

Annotate all public functions with the autoload magic cookie so that
update-directory-autoloads will find them.

Patch by Brendan O'Dea.

Modified:
clang-tools-extra/trunk/include-fixer/tool/clang-include-fixer.el

Modified: clang-tools-extra/trunk/include-fixer/tool/clang-include-fixer.el
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/include-fixer/tool/clang-include-fixer.el?rev=308290=308289=308290=diff
==
--- clang-tools-extra/trunk/include-fixer/tool/clang-include-fixer.el (original)
+++ clang-tools-extra/trunk/include-fixer/tool/clang-include-fixer.el Tue Jul 
18 03:15:07 2017
@@ -58,6 +58,7 @@ This string is passed as -input argument
 (defface clang-include-fixer-highlight '((t :background "green"))
   "Used for highlighting the symbol for which a header file is being added.")
 
+;;;###autoload
 (defun clang-include-fixer ()
   "Invoke the Include Fixer to insert missing C++ headers."
   (interactive)
@@ -66,6 +67,7 @@ This string is passed as -input argument
   (clang-include-fixer--start #'clang-include-fixer--add-header
   "-output-headers"))
 
+;;;###autoload
 (defun clang-include-fixer-at-point ()
   "Invoke the Clang include fixer for the symbol at point."
   (interactive)
@@ -74,6 +76,7 @@ This string is passed as -input argument
   (user-error "No symbol at current location"))
 (clang-include-fixer-from-symbol symbol)))
 
+;;;###autoload
 (defun clang-include-fixer-from-symbol (symbol)
   "Invoke the Clang include fixer for the SYMBOL.
 When called interactively, prompts the user for a symbol."


___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: clang-format: Fix deref treated as binary op in throw

2017-07-17 Thread Manuel Klimek via cfe-commits
Thx. Submitted as r308185.

On Mon, Jul 17, 2017 at 4:28 PM Erik Uhlmann  wrote:

> I don’t have commit access, so I’d need you to check it in. Thanks for
> your help!
>
>
>
> *From: *Manuel Klimek 
> *Date: *Monday, July 17, 2017 at 03:31
> *To: *Erik Uhlmann , "cfe-commits@lists.llvm.org" <
> cfe-commits@lists.llvm.org>
> *Subject: *Re: clang-format: Fix deref treated as binary op in throw
>
>
>
> LG, thanks for the patch. For next time, it helps to use phabricator to
> make people catch patches faster :)
>
>
>
> Do you have commit access or do you need me to check it in?
>
>
>
> On Thu, Jul 6, 2017 at 6:53 PM Erik Uhlmann via cfe-commits <
> cfe-commits@lists.llvm.org> wrote:
>
> When dereferencing a pointer in a throw statement, clang-format assigns
> TT_BinaryOperator to the star token, so it gets formatted as:
>
> throw * x;
>
> With this change the above becomes
>
> throw *x;
>
> Bug tracker: https://bugs.llvm.org/show_bug.cgi?id=33665
> 
>
> Attached is a patch containing the fix.
>
> ___
> cfe-commits mailing list
> cfe-commits@lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
> 
>
>
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r308185 - Fix dereference of pointers in throw statements.

2017-07-17 Thread Manuel Klimek via cfe-commits
Author: klimek
Date: Mon Jul 17 08:27:53 2017
New Revision: 308185

URL: http://llvm.org/viewvc/llvm-project?rev=308185=rev
Log:
Fix dereference of pointers in throw statements.

Before:
  throw * x;

After:
  throw *x;

Patch by Erik Uhlmann.

Modified:
cfe/trunk/lib/Format/TokenAnnotator.cpp
cfe/trunk/unittests/Format/FormatTest.cpp

Modified: cfe/trunk/lib/Format/TokenAnnotator.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/TokenAnnotator.cpp?rev=308185=308184=308185=diff
==
--- cfe/trunk/lib/Format/TokenAnnotator.cpp (original)
+++ cfe/trunk/lib/Format/TokenAnnotator.cpp Mon Jul 17 08:27:53 2017
@@ -1383,7 +1383,8 @@ private:
 
 if (PrevToken->isOneOf(tok::l_paren, tok::l_square, tok::l_brace,
tok::comma, tok::semi, tok::kw_return, tok::colon,
-   tok::equal, tok::kw_delete, tok::kw_sizeof) ||
+   tok::equal, tok::kw_delete, tok::kw_sizeof,
+   tok::kw_throw) ||
 PrevToken->isOneOf(TT_BinaryOperator, TT_ConditionalExpr,
TT_UnaryOperator, TT_CastRParen))
   return TT_UnaryOperator;

Modified: cfe/trunk/unittests/Format/FormatTest.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTest.cpp?rev=308185=308184=308185=diff
==
--- cfe/trunk/unittests/Format/FormatTest.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTest.cpp Mon Jul 17 08:27:53 2017
@@ -5350,6 +5350,7 @@ TEST_F(FormatTest, UnderstandsUsesOfStar
   verifyFormat("x = *a(x) = *a(y);", Left);
   verifyFormat("for (;; *a = b) {\n}", Left);
   verifyFormat("return *this += 1;", Left);
+  verifyFormat("throw *x;", Left);
 
   verifyIndependentOfContext("a = *(x + y);");
   verifyIndependentOfContext("a = &(x + y);");


___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: clang-format: Fix deref treated as binary op in throw

2017-07-17 Thread Manuel Klimek via cfe-commits
LG, thanks for the patch. For next time, it helps to use phabricator to
make people catch patches faster :)

Do you have commit access or do you need me to check it in?

On Thu, Jul 6, 2017 at 6:53 PM Erik Uhlmann via cfe-commits <
cfe-commits@lists.llvm.org> wrote:

> When dereferencing a pointer in a throw statement, clang-format assigns
> TT_BinaryOperator to the star token, so it gets formatted as:
>
> throw * x;
>
> With this change the above becomes
>
> throw *x;
>
> Bug tracker: https://bugs.llvm.org/show_bug.cgi?id=33665
>
> Attached is a patch containing the fix.
>
> ___
> cfe-commits mailing list
> cfe-commits@lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
>
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D35131: Prevent ClangTools from generating dependency files.D34304 created a way for ToolInvocations to conditionally generatedependency files, and updated call sites to preserve the old b

2017-07-12 Thread Manuel Klimek via cfe-commits
Lg

On Tue, Jul 11, 2017, 8:07 PM Sterling Augustine via Phabricator <
revi...@reviews.llvm.org> wrote:

> saugustine added a comment.
>
> Manuel, What do you think?
>
>
> https://reviews.llvm.org/D35131
>
>
>
>
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D34252: Add arbitrary file/path support to clang-format style file selection

2017-06-19 Thread Manuel Klimek via cfe-commits
On Fri, Jun 16, 2017 at 8:26 PM Dan Ciliske via Phabricator <
revi...@reviews.llvm.org> wrote:

> dciliske added a comment.
>
> So... how should I get something added? That patch has been sitting for a
> couple weeks.
>
> Should I work on that patch? If so, how do I work on it? This is the first
> time I'm working on a large OSS project.
>

First, ping that thread, link to your patch here, and ask whether the
author on the other thread is intending to make progress.


>
>
> https://reviews.llvm.org/D34252
>
>
>
>
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: r305044 - [libclang] Introduce a new parsing option 'CXTranslationUnit_SingleFileParse' that puts preprocessor in a mode for parsing a single file only.

2017-06-09 Thread Manuel Klimek via cfe-commits
Hey ho,

this looks like a really cool new feature, and the CL looks good to me; I
was wondering whether in the future we can send CLs like this through
pre-commit review, or have an RFC email thread. If you have more stuff
landing, a single RFC email thread describing how the features work
together would also be super useful, as it makes it easier to follow along
the patches later.

Cheers,
/Manuel

On Fri, Jun 9, 2017 at 3:21 AM Argyrios Kyrtzidis via cfe-commits <
cfe-commits@lists.llvm.org> wrote:

> Author: akirtzidis
> Date: Thu Jun  8 20:20:48 2017
> New Revision: 305044
>
> URL: http://llvm.org/viewvc/llvm-project?rev=305044=rev
> Log:
> [libclang] Introduce a new parsing option
> 'CXTranslationUnit_SingleFileParse' that puts preprocessor in a mode for
> parsing a single file only.
>
> This is useful for parsing a single file, as a fast/inaccurate 'mode' that
> can still provide declarations from the file, like the classes and their
> methods.
>
> Added:
> cfe/trunk/test/Index/singe-file-parse.m
> Modified:
> cfe/trunk/include/clang-c/Index.h
> cfe/trunk/include/clang/Frontend/ASTUnit.h
> cfe/trunk/include/clang/Lex/PreprocessorOptions.h
> cfe/trunk/lib/Frontend/ASTUnit.cpp
> cfe/trunk/lib/Lex/PPDirectives.cpp
> cfe/trunk/tools/c-index-test/c-index-test.c
> cfe/trunk/tools/libclang/CIndex.cpp
>
> Modified: cfe/trunk/include/clang-c/Index.h
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang-c/Index.h?rev=305044=305043=305044=diff
>
> ==
> --- cfe/trunk/include/clang-c/Index.h (original)
> +++ cfe/trunk/include/clang-c/Index.h Thu Jun  8 20:20:48 2017
> @@ -32,7 +32,7 @@
>   * compatible, thus CINDEX_VERSION_MAJOR is expected to remain stable.
>   */
>  #define CINDEX_VERSION_MAJOR 0
> -#define CINDEX_VERSION_MINOR 42
> +#define CINDEX_VERSION_MINOR 43
>
>  #define CINDEX_VERSION_ENCODE(major, minor) ( \
>((major) * 1)   \
> @@ -1234,7 +1234,12 @@ enum CXTranslationUnit_Flags {
> * purposes of an IDE, this is undesirable behavior and as much
> information
> * as possible should be reported. Use this flag to enable this
> behavior.
> */
> -  CXTranslationUnit_KeepGoing = 0x200
> +  CXTranslationUnit_KeepGoing = 0x200,
> +
> +  /**
> +   * \brief Sets the preprocessor in a mode for parsing a single file
> only.
> +   */
> +  CXTranslationUnit_SingleFileParse = 0x400
>  };
>
>  /**
>
> Modified: cfe/trunk/include/clang/Frontend/ASTUnit.h
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Frontend/ASTUnit.h?rev=305044=305043=305044=diff
>
> ==
> --- cfe/trunk/include/clang/Frontend/ASTUnit.h (original)
> +++ cfe/trunk/include/clang/Frontend/ASTUnit.h Thu Jun  8 20:20:48 2017
> @@ -871,6 +871,7 @@ public:
>bool CacheCodeCompletionResults = false,
>bool IncludeBriefCommentsInCodeCompletion = false,
>bool AllowPCHWithCompilerErrors = false, bool SkipFunctionBodies =
> false,
> +  bool SingleFileParse = false,
>bool UserFilesAreVolatile = false, bool ForSerialization = false,
>llvm::Optional ModuleFormat = llvm::None,
>std::unique_ptr *ErrAST = nullptr,
>
> Modified: cfe/trunk/include/clang/Lex/PreprocessorOptions.h
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Lex/PreprocessorOptions.h?rev=305044=305043=305044=diff
>
> ==
> --- cfe/trunk/include/clang/Lex/PreprocessorOptions.h (original)
> +++ cfe/trunk/include/clang/Lex/PreprocessorOptions.h Thu Jun  8 20:20:48
> 2017
> @@ -95,6 +95,9 @@ public:
>/// If given, a PTH cache file to use for speeding up header parsing.
>std::string TokenCache;
>
> +  /// When enabled, preprocessor is in a mode for parsing a single file
> only.
> +  bool SingleFileParseMode = false;
> +
>/// \brief True if the SourceManager should report the original file
> name for
>/// contents of files that were remapped to other files. Defaults to
> true.
>bool RemappedFilesKeepOriginalName;
> @@ -181,6 +184,7 @@ public:
>  ImplicitPCHInclude.clear();
>  ImplicitPTHInclude.clear();
>  TokenCache.clear();
> +SingleFileParseMode = false;
>  RetainRemappedFileBuffers = true;
>  PrecompiledPreambleBytes.first = 0;
>  PrecompiledPreambleBytes.second = 0;
>
> Modified: cfe/trunk/lib/Frontend/ASTUnit.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/ASTUnit.cpp?rev=305044=305043=305044=diff
>
> ==
> --- cfe/trunk/lib/Frontend/ASTUnit.cpp (original)
> +++ cfe/trunk/lib/Frontend/ASTUnit.cpp Thu Jun  8 20:20:48 2017
> @@ -1982,7 +1982,7 @@ ASTUnit *ASTUnit::LoadFromCommandLine(
>  unsigned PrecompilePreambleAfterNParses, TranslationUnitKind 

Re: [PATCH] D30210: [include-fixer] Add usage count to find-all-symbols.

2017-02-24 Thread Manuel Klimek via cfe-commits
On Thu, Feb 23, 2017 at 10:40 PM Sam McCall  wrote:

>
>
> On Feb 23, 2017 8:48 PM, "Haojian Wu via Phabricator" <
> revi...@reviews.llvm.org> wrote:
>
> hokein added inline comments.
>
>
> 
> Comment at:
> unittests/include-fixer/find-all-symbols/FindAllSymbolsTests.cpp:40
> +  void reportSymbols(llvm::StringRef FileName,
> + SymbolInfo::SignalMap NewSymbols) override {
> +for (const auto  : NewSymbols)
> 
> A new catch: `NewSymbols` should be passed by reference, otherwise a copy
> will be generated.
>
> I did actually intend by-value here, FindAllSymbols no longer needs the
> map once it's reported, so it is moved rather than copied (see the end of
> FindAllSymbols.cpp)
>
> If this is too surprising, I can change it.
>

I'd say that that couples the call site and the function too much.


>
>
>
>
>
> https://reviews.llvm.org/D30210
>
>
>
>
>
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] r295988 - Make clang-include-fixer--insert-line work when the difference is on an empty line

2017-02-23 Thread Manuel Klimek via cfe-commits
Author: klimek
Date: Thu Feb 23 10:02:53 2017
New Revision: 295988

URL: http://llvm.org/viewvc/llvm-project?rev=295988=rev
Log:
Make clang-include-fixer--insert-line work when the difference is on an empty 
line

`clang-include-fixer--insert-line` has an off-by-one error because it
uses `(goto-char (point-min)) (forward-char chars)`, which is (goto-char
(1+ chars))`. Because of this, when the first difference was on an empty
line (i.e. an include was appended to the block of includes), the
pointer in the `to` buffer would be on the next line.

Also wrapped calls inside another process sentinel inside `with-local-quit`.

Patch by Torsten Marek.

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

Modified:
clang-tools-extra/trunk/include-fixer/tool/clang-include-fixer-test.el
clang-tools-extra/trunk/include-fixer/tool/clang-include-fixer.el

Modified: clang-tools-extra/trunk/include-fixer/tool/clang-include-fixer-test.el
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/include-fixer/tool/clang-include-fixer-test.el?rev=295988=295987=295988=diff
==
--- clang-tools-extra/trunk/include-fixer/tool/clang-include-fixer-test.el 
(original)
+++ clang-tools-extra/trunk/include-fixer/tool/clang-include-fixer-test.el Thu 
Feb 23 10:02:53 2017
@@ -23,6 +23,18 @@
   (should (equal (buffer-string) "aa\nab\nac\nad\n")
 (should (equal (buffer-string) "aa\nab\nac\nad\n"
 
+(ert-deftest clang-include-fixer--insert-line-diff-on-empty-line ()
+  "Unit test for `clang-include-fixer--insert-line'."
+  (with-temp-buffer
+(insert "aa\nab\n\nac\nad\n")
+(let ((from (current-buffer)))
+  (with-temp-buffer
+(insert "aa\n\nac\nad\n")
+(let ((to (current-buffer)))
+  (should (clang-include-fixer--insert-line from to))
+  (should (equal (buffer-string) "aa\nab\n\nac\nad\n")
+(should (equal (buffer-string) "aa\nab\n\nac\nad\n"
+
 (ert-deftest clang-include-fixer--symbol-at-point ()
   "Unit test for `clang-include-fixer--symbol-at-point'."
   (with-temp-buffer

Modified: clang-tools-extra/trunk/include-fixer/tool/clang-include-fixer.el
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/include-fixer/tool/clang-include-fixer.el?rev=295988=295987=295988=diff
==
--- clang-tools-extra/trunk/include-fixer/tool/clang-include-fixer.el (original)
+++ clang-tools-extra/trunk/include-fixer/tool/clang-include-fixer.el Thu Feb 
23 10:02:53 2017
@@ -213,16 +213,14 @@ return nil.  Buffer restrictions are ign
 (if (zerop chars)
 ;; Buffer contents are equal, nothing to do.
 t
-  (goto-char (point-min))
-  (forward-char chars)
+  (goto-char chars)
   ;; We might have ended up in the middle of a line if the
   ;; current line partially matches.  In this case we would
   ;; have to insert more than a line.  Move to the beginning of
   ;; the line to avoid this situation.
   (beginning-of-line)
   (with-current-buffer from
-(goto-char (point-min))
-(forward-char chars)
+(goto-char chars)
 (beginning-of-line)
 (let ((from-begin (point))
   (from-end (progn (forward-line) (point)))
@@ -268,9 +266,10 @@ clang-include-fixer to insert the select
(clang-include-fixer--replace-buffer stdout)
(let-alist context
  (let-alist (car .HeaderInfos)
-   (run-hook-with-args 'clang-include-fixer-add-include-hook
-   (substring .Header 1 -1)
-   (string= (substring .Header 0 1) 
"<"))
+   (with-local-quit
+ (run-hook-with-args 'clang-include-fixer-add-include-hook
+ (substring .Header 1 -1)
+ (string= (substring .Header 0 1) 
"<")))
(format "-insert-header=%s"
(clang-include-fixer--encode-json context
   nil)


___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] r295818 - Completion related fixes for clang-include-fixer.el.

2017-02-22 Thread Manuel Klimek via cfe-commits
Author: klimek
Date: Wed Feb 22 03:21:22 2017
New Revision: 295818

URL: http://llvm.org/viewvc/llvm-project?rev=295818=rev
Log:
Completion related fixes for clang-include-fixer.el.

1. Quitting inside a process sentinel is not allowed, but the sentinel invokes
completion, where the user is free to hit C-g. By wrapping the call in
with-local-quit, the process sentinel invocation can finish without triggering
an error
2. Invoke completing-read instead of ido-completing-read, since this may
interfere with user customizations to completing-read-function. The user should
use something like ido-ubiquitous if ido completion is wanted
3. Compare the string returned from completion with string=, since it may be a
copy of the original string in the collection

Patch by Torsten Marek.

Modified:
clang-tools-extra/trunk/include-fixer/tool/clang-include-fixer.el

Modified: clang-tools-extra/trunk/include-fixer/tool/clang-include-fixer.el
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/include-fixer/tool/clang-include-fixer.el?rev=295818=295817=295818=diff
==
--- clang-tools-extra/trunk/include-fixer/tool/clang-include-fixer.el (original)
+++ clang-tools-extra/trunk/include-fixer/tool/clang-include-fixer.el Wed Feb 
22 03:21:22 2017
@@ -251,25 +251,28 @@ clang-include-fixer to insert the select
 (message "Couldn't find header for '%s'"
  (let-alist (car .QuerySymbolInfos) .RawIdentifier)))
(t
-;; Replace the HeaderInfos list by a single header selected by
-;; the user.
-(clang-include-fixer--select-header context)
-;; Call clang-include-fixer again to insert the selected header.
-(clang-include-fixer--start
- (let ((old-tick (buffer-chars-modified-tick)))
-   (lambda (stdout)
- (when (/= old-tick (buffer-chars-modified-tick))
-   ;; Replacing the buffer now would undo the user’s changes.
-   (user-error (concat "The buffer has been changed "
-   "before the header could be inserted")))
- (clang-include-fixer--replace-buffer stdout)
- (let-alist context
-   (let-alist (car .HeaderInfos)
- (run-hook-with-args 'clang-include-fixer-add-include-hook
- (substring .Header 1 -1)
- (string= (substring .Header 0 1) "<"))
- (format "-insert-header=%s"
- (clang-include-fixer--encode-json context)))
+;; Users may C-g in prompts, make sure the process sentinel
+;; behaves correctly.
+(with-local-quit
+  ;; Replace the HeaderInfos list by a single header selected by
+  ;; the user.
+  (clang-include-fixer--select-header context)
+  ;; Call clang-include-fixer again to insert the selected header.
+  (clang-include-fixer--start
+   (let ((old-tick (buffer-chars-modified-tick)))
+ (lambda (stdout)
+   (when (/= old-tick (buffer-chars-modified-tick))
+ ;; Replacing the buffer now would undo the user’s changes.
+ (user-error (concat "The buffer has been changed "
+ "before the header could be inserted")))
+   (clang-include-fixer--replace-buffer stdout)
+   (let-alist context
+ (let-alist (car .HeaderInfos)
+   (run-hook-with-args 'clang-include-fixer-add-include-hook
+   (substring .Header 1 -1)
+   (string= (substring .Header 0 1) 
"<"))
+   (format "-insert-header=%s"
+   (clang-include-fixer--encode-json context
   nil)
 
 (defun clang-include-fixer--select-header (context)
@@ -305,13 +308,13 @@ They are replaced by the single element
 (goto-char (clang-include-fixer--closest-overlay overlays))
 (cl-flet ((header (info) (let-alist info .Header)))
   ;; The header-infos is already sorted by include-fixer.
-  (let* ((header (ido-completing-read
+  (let* ((header (completing-read
   (clang-include-fixer--format-message
"Select include for '%s': " symbol)
   (mapcar #'header .HeaderInfos)
   nil :require-match nil
   'clang-include-fixer--history))
- (info (cl-find header .HeaderInfos :key #'header)))
+ (info (cl-find header .HeaderInfos :key #'header :test 
#'string=)))
 (cl-assert info)
 (setcar .HeaderInfos info)
 (setcdr .HeaderInfos nil


___
cfe-commits mailing list

[clang-tools-extra] r295814 - Adds a hook clang-include-fixer-add-include-hook that is invoked with the path and type of the added include.

2017-02-22 Thread Manuel Klimek via cfe-commits
Author: klimek
Date: Wed Feb 22 02:26:04 2017
New Revision: 295814

URL: http://llvm.org/viewvc/llvm-project?rev=295814=rev
Log:
Adds a hook clang-include-fixer-add-include-hook that is invoked with the path 
and type of the added include.

This patch also adds a new function clang-include-fixer-from-symbol, which 
prompts the user for a symbol to resolve and include.

Patch by Torsten Marek.

Modified:
clang-tools-extra/trunk/include-fixer/tool/clang-include-fixer.el

Modified: clang-tools-extra/trunk/include-fixer/tool/clang-include-fixer.el
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/include-fixer/tool/clang-include-fixer.el?rev=295814=295813=295814=diff
==
--- clang-tools-extra/trunk/include-fixer/tool/clang-include-fixer.el (original)
+++ clang-tools-extra/trunk/include-fixer/tool/clang-include-fixer.el Wed Feb 
22 02:26:04 2017
@@ -20,6 +20,11 @@
   "Clang-based include fixer."
   :group 'tools)
 
+(defvar clang-include-fixer-add-include-hook nil
+  "A hook that will be called for every added include.
+The first argument is the filename of the include, the second argument is
+non-nil if the include is a system-header.")
+
 (defcustom clang-include-fixer-executable
   "clang-include-fixer"
   "Location of the clang-include-fixer executable.
@@ -67,8 +72,15 @@ This string is passed as -input argument
   (let ((symbol (clang-include-fixer--symbol-at-point)))
 (unless symbol
   (user-error "No symbol at current location"))
-(clang-include-fixer--start #'clang-include-fixer--add-header
-(format "-query-symbol=%s" symbol
+(clang-include-fixer-from-symbol symbol)))
+
+(defun clang-include-fixer-from-symbol (symbol)
+  "Invoke the Clang include fixer for the SYMBOL.
+When called interactively, prompts the user for a symbol."
+  (interactive
+   (list (read-string "Symbol: " (clang-include-fixer--symbol-at-point
+  (clang-include-fixer--start #'clang-include-fixer--add-header
+  (format "-query-symbol=%s" symbol)))
 
 (defun clang-include-fixer--start (callback  args)
   "Asynchronously start clang-include-fixer with parameters ARGS.
@@ -250,7 +262,12 @@ clang-include-fixer to insert the select
;; Replacing the buffer now would undo the user’s changes.
(user-error (concat "The buffer has been changed "
"before the header could be inserted")))
- (clang-include-fixer--replace-buffer stdout)))
+ (clang-include-fixer--replace-buffer stdout)
+ (let-alist context
+   (let-alist (car .HeaderInfos)
+ (run-hook-with-args 'clang-include-fixer-add-include-hook
+ (substring .Header 1 -1)
+ (string= (substring .Header 0 1) "<"))
  (format "-insert-header=%s"
  (clang-include-fixer--encode-json context)))
   nil)


___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D28548: Improve include fixer's ranking by taking the paths into account.

2017-01-17 Thread Manuel Klimek via cfe-commits
It's by design. Do we want to change this? I always had the impression
turning on the state changes for the list is a bit noisy, but I'm happy if
that's not the general sentiment.

On Mon, Jan 16, 2017, 11:07 PM Benjamin Kramer  wrote:

I got an email where it says that I accepted the revision. Looks like
phab didn't add cfe-commits to the list of recipients though :(

On Mon, Jan 16, 2017 at 6:43 PM, David Blaikie  wrote:
> Looks like Ben signed off on this on Phab - but the email didn't go to the
> list (making this look like code was sent for review, then committed,
> without review/approval happening)
>
> Ben: I think Phab doesn't send mail for an approval with no text, so at
> least as a workaround you can write something in the comments section when
> approving (people often write "LGTM" or similar) to ensure the approval is
> reflected on the mailing list.
>
> On Wed, Jan 11, 2017 at 1:59 AM Manuel Klimek via Phabricator via
> cfe-commits  wrote:
>>
>> klimek created this revision.
>> klimek added a reviewer: bkramer.
>> klimek added a subscriber: cfe-commits.
>>
>> Instead of just using popularity, we also take into account how similar
>> the
>> path of the current file is to the path of the header.
>> Our first approach is to get popularity into a reasonably small scale by
>> taking
>> log2 (which is roughly intuitive to how humans would bucket popularity),
>> and
>> multiply that with the number of matching prefix path fragments of the
>> included
>> header with the current file.
>> Note that currently we do not take special care for unclean paths
>> containing
>> "../" or "./".
>>
>>
>> https://reviews.llvm.org/D28548
>>
>> Files:
>>   include-fixer/IncludeFixer.cpp
>>   include-fixer/SymbolIndexManager.cpp
>>   include-fixer/SymbolIndexManager.h
>>   include-fixer/tool/ClangIncludeFixer.cpp
>>   test/include-fixer/Inputs/fake_yaml_db.yaml
>>   test/include-fixer/ranking.cpp
>>
>> ___
>> cfe-commits mailing list
>> cfe-commits@lists.llvm.org
>> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] r291664 - Improve include fixer's ranking by taking the paths into account.

2017-01-11 Thread Manuel Klimek via cfe-commits
Author: klimek
Date: Wed Jan 11 04:32:47 2017
New Revision: 291664

URL: http://llvm.org/viewvc/llvm-project?rev=291664=rev
Log:
Improve include fixer's ranking by taking the paths into account.

Instead of just using popularity, we also take into account how similar the
path of the current file is to the path of the header.
Our first approach is to get popularity into a reasonably small scale by taking
log2 (which is roughly intuitive to how humans would bucket popularity), and
multiply that with the number of matching prefix path fragments of the included
header with the current file.
Note that currently we do not take special care for unclean paths containing
"../" or "./".

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

Modified:
clang-tools-extra/trunk/include-fixer/IncludeFixer.cpp
clang-tools-extra/trunk/include-fixer/SymbolIndexManager.cpp
clang-tools-extra/trunk/include-fixer/SymbolIndexManager.h
clang-tools-extra/trunk/include-fixer/tool/ClangIncludeFixer.cpp
clang-tools-extra/trunk/test/include-fixer/Inputs/fake_yaml_db.yaml
clang-tools-extra/trunk/test/include-fixer/ranking.cpp

Modified: clang-tools-extra/trunk/include-fixer/IncludeFixer.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/include-fixer/IncludeFixer.cpp?rev=291664=291663=291664=diff
==
--- clang-tools-extra/trunk/include-fixer/IncludeFixer.cpp (original)
+++ clang-tools-extra/trunk/include-fixer/IncludeFixer.cpp Wed Jan 11 04:32:47 
2017
@@ -365,6 +365,9 @@ IncludeFixerSemaSource::query(StringRef
 .getLocWithOffset(Range.getOffset())
 .print(llvm::dbgs(), CI->getSourceManager()));
   DEBUG(llvm::dbgs() << " ...");
+  llvm::StringRef FileName = CI->getSourceManager().getFilename(
+  CI->getSourceManager().getLocForStartOfFile(
+  CI->getSourceManager().getMainFileID()));
 
   QuerySymbolInfos.push_back({Query.str(), ScopedQualifiers, Range});
 
@@ -385,9 +388,10 @@ IncludeFixerSemaSource::query(StringRef
   // context, it might treat the identifier as a nested class of the scoped
   // namespace.
   std::vector MatchedSymbols =
-  SymbolIndexMgr.search(QueryString, /*IsNestedSearch=*/false);
+  SymbolIndexMgr.search(QueryString, /*IsNestedSearch=*/false, FileName);
   if (MatchedSymbols.empty())
-MatchedSymbols = SymbolIndexMgr.search(Query);
+MatchedSymbols =
+SymbolIndexMgr.search(Query, /*IsNestedSearch=*/true, FileName);
   DEBUG(llvm::dbgs() << "Having found " << MatchedSymbols.size()
  << " symbols\n");
   // We store a copy of MatchedSymbols in a place where it's globally 
reachable.

Modified: clang-tools-extra/trunk/include-fixer/SymbolIndexManager.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/include-fixer/SymbolIndexManager.cpp?rev=291664=291663=291664=diff
==
--- clang-tools-extra/trunk/include-fixer/SymbolIndexManager.cpp (original)
+++ clang-tools-extra/trunk/include-fixer/SymbolIndexManager.cpp Wed Jan 11 
04:32:47 2017
@@ -12,6 +12,7 @@
 #include "llvm/ADT/DenseMap.h"
 #include "llvm/ADT/SmallVector.h"
 #include "llvm/Support/Debug.h"
+#include "llvm/Support/Path.h"
 
 #define DEBUG_TYPE "include-fixer"
 
@@ -20,30 +21,57 @@ namespace include_fixer {
 
 using clang::find_all_symbols::SymbolInfo;
 
-/// Sorts SymbolInfos based on the popularity info in SymbolInfo.
-static void rankByPopularity(std::vector ) {
-  // First collect occurrences per header file.
-  llvm::DenseMap HeaderPopularity;
-  for (const SymbolInfo  : Symbols) {
-unsigned  = HeaderPopularity[Symbol.getFilePath()];
-Popularity = std::max(Popularity, Symbol.getNumOccurrences());
+// Calculate a score based on whether we think the given header is closely
+// related to the given source file.
+static double similarityScore(llvm::StringRef FileName,
+  llvm::StringRef Header) {
+  // Compute the maximum number of common path segements between Header and
+  // a suffix of FileName.
+  // We do not do a full longest common substring computation, as Header
+  // specifies the path we would directly #include, so we assume it is rooted
+  // relatively to a subproject of the repository.
+  int MaxSegments = 1;
+  for (auto FileI = llvm::sys::path::begin(FileName),
+FileE = llvm::sys::path::end(FileName);
+   FileI != FileE; ++FileI) {
+int Segments = 0;
+for (auto HeaderI = llvm::sys::path::begin(Header),
+  HeaderE = llvm::sys::path::end(Header), I = FileI;
+ HeaderI != HeaderE && *I == *HeaderI && I != FileE; ++I, ++HeaderI) {
+  ++Segments;
+}
+MaxSegments = std::max(Segments, MaxSegments);
   }
+  return MaxSegments;
+}
 
-  // Sort by the gathered popularities. Use file name as a tie breaker so we 
can
+static void rank(std::vector 

[clang-tools-extra] r291653 - Only launch asynchronously if threading is enabled.

2017-01-10 Thread Manuel Klimek via cfe-commits
Author: klimek
Date: Wed Jan 11 01:20:46 2017
New Revision: 291653

URL: http://llvm.org/viewvc/llvm-project?rev=291653=rev
Log:
Only launch asynchronously if threading is enabled.

Modified:
clang-tools-extra/trunk/include-fixer/SymbolIndexManager.h

Modified: clang-tools-extra/trunk/include-fixer/SymbolIndexManager.h
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/include-fixer/SymbolIndexManager.h?rev=291653=291652=291653=diff
==
--- clang-tools-extra/trunk/include-fixer/SymbolIndexManager.h (original)
+++ clang-tools-extra/trunk/include-fixer/SymbolIndexManager.h Wed Jan 11 
01:20:46 2017
@@ -23,7 +23,12 @@ namespace include_fixer {
 class SymbolIndexManager {
 public:
   void addSymbolIndex(std::function F) {
-SymbolIndices.push_back(std::async(std::launch::async, F));
+#if LLVM_ENABLE_THREADS
+auto Strategy = std::launch::async;
+#else
+auto Strategy = std::launch::deferred;
+#endif
+SymbolIndices.push_back(std::async(Strategy, F));
   }
 
   /// Search for header files to be included for an identifier.


___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D28279: [clang-move] Support moving type alias declarations.

2017-01-09 Thread Manuel Klimek via cfe-commits
Testing phab parsing...

On Wed, Jan 4, 2017 at 4:01 PM Haojian Wu via Phabricator via cfe-commits <
cfe-commits@lists.llvm.org> wrote:

> This revision was automatically updated to reflect the committed changes.
> Closed by commit rL290967: [clang-move] Support moving type alias
> declarations. (authored by hokein).
>
> Changed prior to commit:
>   https://reviews.llvm.org/D28279?vs=83016=83053#toc
>
> Repository:
>   rL LLVM
>
> https://reviews.llvm.org/D28279
>
> Files:
>   clang-tools-extra/trunk/clang-move/ClangMove.cpp
>   clang-tools-extra/trunk/test/clang-move/Inputs/type_alias.h
>   clang-tools-extra/trunk/test/clang-move/move-type-alias.cpp
>   clang-tools-extra/trunk/unittests/clang-move/ClangMoveTests.cpp
>
> ___
> cfe-commits mailing list
> cfe-commits@lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
>
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: clang-format-vsix: versioning patch and show stderrors patch

2016-12-05 Thread Manuel Klimek via cfe-commits
On Mon, Dec 5, 2016 at 3:53 PM Antonio Maiorano  wrote:

> Hi Manuel,
>
> Okay, I'll submit both patches via phabricator as you recommend. I'll add
> you, and I'll add Hans Wennborg and Zachary Turner, who were both involved
> with the first clang-format-vsix patch I worked on:
> http://lists.llvm.org/pipermail/cfe-commits/Week-of-Mon-20161128/178569.html
>
> Does that make sense? I'm still learning the common workflow for
> submitting patches :)
>

Yep, perfect. Thanks!!


>
> - Antonio
>
>
>
> On Mon, 5 Dec 2016 at 06:24 Manuel Klimek  wrote:
>
> Awesome, thanks for working on this. If you submit the patches via
> phabricator (http://llvm.org/docs/Phabricator.html) I'll get to it faster
> :) Feel free to directly add me as reviewer, btw (add 'klimek').
>
> On Sat, Dec 3, 2016 at 6:53 AM Antonio Maiorano via cfe-commits <
> cfe-commits@lists.llvm.org> wrote:
>
> Hello,
>
> I have two patches for clang-format-vsix to offer up for review:
>
> 0001-clang-format-vsix-versioning.patch
> clang-format-vsix: add a date stamp to the VSIX version number to ensure
> upgradability
>
> Presently, the version number of the VSIX matches the LLVM version number.
> However, as this number doesn't change often, it means that as we release
> new versions of this VSIX, it will have the same version number, which
> means users must first uninstall the old version before installing the new
> one. With this change, we generate a 4th part to the version number that is
> a date stamp (year, month, day); for example: 4.0.0.161203.
>
>
> 0001-clang-format-vsix-show-stderrs.patch
> clang-format-vsix: fail when clang-format outputs to stderr
>
> When clang-format outputs to stderr but returns 0, the extension will
> format the code anyway. This happens, for instance, when there's a syntax
> error or unknown value in a .clang-format file; the result is that the
> extension silently formats using the fallback style without informing the
> user of the problem. This change treats stderr output as an error, making
> sure it gets displayed to the user, and not formatting the code. (I've also
> attached a screenshot of the message box I now get when my .clang-format
> has an invalid field named SomeInvalidField).
>
>
> ___
> cfe-commits mailing list
> cfe-commits@lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
>
>
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: clang-format-vsix: versioning patch and show stderrors patch

2016-12-05 Thread Manuel Klimek via cfe-commits
Awesome, thanks for working on this. If you submit the patches via
phabricator (http://llvm.org/docs/Phabricator.html) I'll get to it faster
:) Feel free to directly add me as reviewer, btw (add 'klimek').

On Sat, Dec 3, 2016 at 6:53 AM Antonio Maiorano via cfe-commits <
cfe-commits@lists.llvm.org> wrote:

> Hello,
>
> I have two patches for clang-format-vsix to offer up for review:
>
> 0001-clang-format-vsix-versioning.patch
> clang-format-vsix: add a date stamp to the VSIX version number to ensure
> upgradability
>
> Presently, the version number of the VSIX matches the LLVM version number.
> However, as this number doesn't change often, it means that as we release
> new versions of this VSIX, it will have the same version number, which
> means users must first uninstall the old version before installing the new
> one. With this change, we generate a 4th part to the version number that is
> a date stamp (year, month, day); for example: 4.0.0.161203.
>
>
> 0001-clang-format-vsix-show-stderrs.patch
> clang-format-vsix: fail when clang-format outputs to stderr
>
> When clang-format outputs to stderr but returns 0, the extension will
> format the code anyway. This happens, for instance, when there's a syntax
> error or unknown value in a .clang-format file; the result is that the
> extension silently formats using the fallback style without informing the
> user of the problem. This change treats stderr output as an error, making
> sure it gets displayed to the user, and not formatting the code. (I've also
> attached a screenshot of the message box I now get when my .clang-format
> has an invalid field named SomeInvalidField).
>
>
> ___
> cfe-commits mailing list
> cfe-commits@lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
>
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r288366 - Adds hasUnqualifiedDesugaredType to allow matching through type sugar.

2016-12-01 Thread Manuel Klimek via cfe-commits
Author: klimek
Date: Thu Dec  1 09:45:06 2016
New Revision: 288366

URL: http://llvm.org/viewvc/llvm-project?rev=288366=rev
Log:
Adds hasUnqualifiedDesugaredType to allow matching through type sugar.

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

Modified:
cfe/trunk/docs/LibASTMatchersReference.html
cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h
cfe/trunk/lib/ASTMatchers/Dynamic/Registry.cpp
cfe/trunk/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp

Modified: cfe/trunk/docs/LibASTMatchersReference.html
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/docs/LibASTMatchersReference.html?rev=288366=288365=288366=diff
==
--- cfe/trunk/docs/LibASTMatchersReference.html (original)
+++ cfe/trunk/docs/LibASTMatchersReference.html Thu Dec  1 09:45:06 2016
@@ -3758,8 +3758,8 @@ Example 2 (conditional binary operator):
 
 
 
-Matcherhttp://clang.llvm.org/doxygen/classclang_1_1AddrLabelExpr.html;>AddrLabelExprhasDeclarationMatcherhttp://clang.llvm.org/doxygen/classclang_1_1Decl.html;>Decl  
InnerMatcher
-Matches a node if 
the declaration associated with that node
+Matcherhttp://clang.llvm.org/doxygen/classclang_1_1AddrLabelExpr.html;>AddrLabelExprhasDeclarationMatcherhttp://clang.llvm.org/doxygen/classclang_1_1Decl.html;>Decl  
InnerMatcher
+Matches a node if 
the declaration associated with that node
 matches the given matcher.
 
 The associated declaration is:
@@ -3772,13 +3772,13 @@ The associated declaration is:
 Also usable as MatcherT for any T supporting the getDecl() member
 function. e.g. various subtypes of clang::Type and various expressions.
 
-Usable as: Matcherhttp://clang.llvm.org/doxygen/classclang_1_1CallExpr.html;>CallExpr,
 Matcherhttp://clang.llvm.org/doxygen/classclang_1_1CXXConstructExpr.html;>CXXConstructExpr,
-  Matcherhttp://clang.llvm.org/doxygen/classclang_1_1CXXNewExpr.html;>CXXNewExpr,
-  Matcherhttp://clang.llvm.org/doxygen/classclang_1_1DeclRefExpr.html;>DeclRefExpr,
 Matcherhttp://clang.llvm.org/doxygen/classclang_1_1EnumType.html;>EnumType,
 Matcherhttp://clang.llvm.org/doxygen/classclang_1_1InjectedClassNameType.html;>InjectedClassNameType,
-  Matcherhttp://clang.llvm.org/doxygen/classclang_1_1LabelStmt.html;>LabelStmt,
 Matcherhttp://clang.llvm.org/doxygen/classclang_1_1AddrLabelExpr.html;>AddrLabelExpr,
 Matcherhttp://clang.llvm.org/doxygen/classclang_1_1MemberExpr.html;>MemberExpr,
-  Matcherhttp://clang.llvm.org/doxygen/classclang_1_1QualType.html;>QualType,
 Matcherhttp://clang.llvm.org/doxygen/classclang_1_1RecordType.html;>RecordType,
 Matcherhttp://clang.llvm.org/doxygen/classclang_1_1TagType.html;>TagType,
-  Matcherhttp://clang.llvm.org/doxygen/classclang_1_1TemplateSpecializationType.html;>TemplateSpecializationType,
 Matcherhttp://clang.llvm.org/doxygen/classclang_1_1TemplateTypeParmType.html;>TemplateTypeParmType,
-  Matcherhttp://clang.llvm.org/doxygen/classclang_1_1TypedefType.html;>TypedefType,
 Matcherhttp://clang.llvm.org/doxygen/classclang_1_1UnresolvedUsingType.html;>UnresolvedUsingType
+Usable as: Matcherhttp://clang.llvm.org/doxygen/classclang_1_1AddrLabelExpr.html;>AddrLabelExpr,
 Matcherhttp://clang.llvm.org/doxygen/classclang_1_1CallExpr.html;>CallExpr,
+  Matcherhttp://clang.llvm.org/doxygen/classclang_1_1CXXConstructExpr.html;>CXXConstructExpr,
 Matcherhttp://clang.llvm.org/doxygen/classclang_1_1CXXNewExpr.html;>CXXNewExpr,
 Matcherhttp://clang.llvm.org/doxygen/classclang_1_1DeclRefExpr.html;>DeclRefExpr,
+  Matcherhttp://clang.llvm.org/doxygen/classclang_1_1EnumType.html;>EnumType,
 Matcherhttp://clang.llvm.org/doxygen/classclang_1_1InjectedClassNameType.html;>InjectedClassNameType,
 Matcherhttp://clang.llvm.org/doxygen/classclang_1_1LabelStmt.html;>LabelStmt,
+  Matcherhttp://clang.llvm.org/doxygen/classclang_1_1MemberExpr.html;>MemberExpr,
 Matcherhttp://clang.llvm.org/doxygen/classclang_1_1QualType.html;>QualType,
 Matcherhttp://clang.llvm.org/doxygen/classclang_1_1RecordType.html;>RecordType,
+  Matcherhttp://clang.llvm.org/doxygen/classclang_1_1TagType.html;>TagType,
 Matcherhttp://clang.llvm.org/doxygen/classclang_1_1TemplateSpecializationType.html;>TemplateSpecializationType,
+  Matcherhttp://clang.llvm.org/doxygen/classclang_1_1TemplateTypeParmType.html;>TemplateTypeParmType,
 Matcherhttp://clang.llvm.org/doxygen/classclang_1_1TypedefType.html;>TypedefType,
+  Matcherhttp://clang.llvm.org/doxygen/classclang_1_1UnresolvedUsingType.html;>UnresolvedUsingType
 
 
 
@@ -4004,13 +4004,13 @@ The associated declaration is:
 Also usable as MatcherT for any T supporting the getDecl() member
 function. e.g. various subtypes of clang::Type and various expressions.
 
-Usable as: Matcherhttp://clang.llvm.org/doxygen/classclang_1_1CallExpr.html;>CallExpr,
 Matcherhttp://clang.llvm.org/doxygen/classclang_1_1CXXConstructExpr.html;>CXXConstructExpr,
-  Matcherhttp://clang.llvm.org/doxygen/classclang_1_1CXXNewExpr.html;>CXXNewExpr,
-  

[PATCH] D27104: Unify and simplify the behavior of the hasDeclaration matcher.

2016-11-24 Thread Manuel Klimek via cfe-commits
klimek created this revision.
klimek added reviewers: rsmith, lukasza.
klimek added a subscriber: cfe-commits.

Originally, we weren't able to match on Type nodes themselves (only QualType),
so the hasDeclaration matcher was initially written to give what we thought are
reasonable results for QualType matches.

When we chagned the matchers to allow matching on Type nodes, it turned out
that the hasDeclaration matcher was by chance written templated enough to now
allow hasDeclaration to also match on (some) Type nodes.

This patch change the hasDeclaration matcher to:
a) work the same on Type and QualType nodes,
b) be completely explicit about what nodes we can match instead of just allowing

  anything with a getDecl() to match,

c) explicitly control desugaring only one level in very specific instances.


https://reviews.llvm.org/D27104

Files:
  include/clang/ASTMatchers/ASTMatchersInternal.h
  unittests/ASTMatchers/ASTMatchersTraversalTest.cpp

Index: unittests/ASTMatchers/ASTMatchersTraversalTest.cpp
===
--- unittests/ASTMatchers/ASTMatchersTraversalTest.cpp
+++ unittests/ASTMatchers/ASTMatchersTraversalTest.cpp
@@ -239,6 +239,13 @@
   EXPECT_TRUE(matches("template  class A {}; A a;",
   varDecl(hasType(templateSpecializationType(
 hasDeclaration(namedDecl(hasName("A";
+  EXPECT_TRUE(matches("template  class A {};"
+  "template  class B { A a; };",
+  fieldDecl(hasType(templateSpecializationType(
+hasDeclaration(namedDecl(hasName("A";
+  EXPECT_TRUE(matches("template  class A {}; A a;",
+  varDecl(hasType(templateSpecializationType(
+  hasDeclaration(cxxRecordDecl()));
 }
 
 TEST(HasDeclaration, HasDeclarationOfCXXNewExpr) {
Index: include/clang/ASTMatchers/ASTMatchersInternal.h
===
--- include/clang/ASTMatchers/ASTMatchersInternal.h
+++ include/clang/ASTMatchers/ASTMatchersInternal.h
@@ -728,48 +728,84 @@
   }
 
 private:
-  /// \brief If getDecl exists as a member of U, returns whether the inner
-  /// matcher matches Node.getDecl().
-  template 
-  bool matchesSpecialized(
-  const U , ASTMatchFinder *Finder, BoundNodesTreeBuilder *Builder,
-  typename std::enable_if::type = 0) const {
-return matchesDecl(Node.getDecl(), Finder, Builder);
-  }
-
-  /// \brief Extracts the TagDecl of a QualType and returns whether the inner
-  /// matcher matches on it.
+  /// \brief Forwards to matching on the underlying type of the QualType.
   bool matchesSpecialized(const QualType , ASTMatchFinder *Finder,
   BoundNodesTreeBuilder *Builder) const {
 if (Node.isNull())
   return false;
 
-if (auto *TD = Node->getAsTagDecl())
-  return matchesDecl(TD, Finder, Builder);
-else if (auto *TT = Node->getAs())
-  return matchesDecl(TT->getDecl(), Finder, Builder);
-// Do not use getAs instead of the direct dyn_cast.
-// Calling getAs will return the canonical type, but that type does not
-// store a TemplateTypeParmDecl. We *need* the uncanonical type, if it is
-// available, and using dyn_cast ensures that.
-else if (auto *TTP = dyn_cast(Node.getTypePtr()))
-  return matchesDecl(TTP->getDecl(), Finder, Builder);
-else if (auto *OCIT = Node->getAs())
-  return matchesDecl(OCIT->getDecl(), Finder, Builder);
-else if (auto *UUT = Node->getAs())
-  return matchesDecl(UUT->getDecl(), Finder, Builder);
-else if (auto *ICNT = Node->getAs())
-  return matchesDecl(ICNT->getDecl(), Finder, Builder);
+return matchesSpecialized(*Node, Finder, Builder);
+  }
+
+  /// \brief Finds the best declaration for a type and returns whether the inner
+  /// matcher matches on it.
+  bool matchesSpecialized(const Type , ASTMatchFinder *Finder,
+  BoundNodesTreeBuilder *Builder) const {
+// First, for any types that have a declaration, extract the declaration and
+// match on it.
+if (const auto *S = dyn_cast()) {
+  return matchesDecl(S->getDecl(), Finder, Builder);
+}
+if (const auto *S = dyn_cast()) {
+  return matchesDecl(S->getDecl(), Finder, Builder);
+}
+if (const auto *S = dyn_cast()) {
+  return matchesDecl(S->getDecl(), Finder, Builder);
+}
+if (const auto *S = dyn_cast()) {
+  return matchesDecl(S->getDecl(), Finder, Builder);
+}
+if (const auto *S = dyn_cast()) {
+  return matchesDecl(S->getDecl(), Finder, Builder);
+}
+if (const auto *S = dyn_cast()) {
+  return matchesDecl(S->getInterface(), Finder, Builder);
+}
+
+// A SubstTemplateTypeParmType exists solely to mark a type substitution
+// on the instantiated template. As users usually want to match the
+// template parameter on the 

[PATCH] D26745: [Frontend] Allow attaching an external sema source to compiler instance and extra diags to TypoCorrections

2016-11-16 Thread Manuel Klimek via cfe-commits
klimek accepted this revision.
klimek added a comment.
This revision is now accepted and ready to land.

LG


https://reviews.llvm.org/D26745



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] Warning for main returning a bool.

2016-11-07 Thread Manuel Klimek via cfe-commits
On Sun, Nov 6, 2016 at 1:18 AM Michał Górny via cfe-commits <
cfe-commits@lists.llvm.org> wrote:

> On Fri, 14 Oct 2016 17:17:59 +
> Joshua Hurwitz via cfe-commits  wrote:
>
> > See attached.
> >
> > Returning a bool from main is a special case of return type mismatch. The
> > common convention when returning a bool is that 'true' (== 1) indicates
> > success and 'false' (== 0) failure. But since main expects a return value
> > of 0 on success, returning a bool is usually unintended.
>
> This triggers a false positive if you use a boolean expression like:
>
>   return !foo;
>
> i.e. whenever user intentionally inverts a 'non-zero success' into 'zero
> success'.
>

I would imagine that not everybody's going to switch on that warning, but I
wouldn't consider this a false positive on !foo, mainly because it still
looks unclear whether the author thought about the semantics of the return
value.


>
> --
> Best regards,
> Michał Górny
> 
> ___
> cfe-commits mailing list
> cfe-commits@lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
>
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D26288: Deduplicate replacements by FileEntry instead of file names.

2016-11-05 Thread Manuel Klimek via cfe-commits
klimek added a comment.

In https://reviews.llvm.org/D26288#586932, @ioeric wrote:

> - Addressed comments: handle non-existing files.


We're not really handling them now though? We're just printing an error?

My point is that we might run the replacement generation on a distributed 
system, and then group/deduplicate/apply them somewhere where the files might 
not actually exist (think the reduce stage of a mapreduce). If possible, I'd 
like to not rely on the existence of the file when we deal with Replacements. 
I'd find it especially problematic if the existence or non-existence of files 
changes the semantics of those operations.


https://reviews.llvm.org/D26288



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] Warning for main returning a bool.

2016-11-05 Thread Manuel Klimek via cfe-commits
+richard

On Fri, Oct 14, 2016 at 10:18 AM Joshua Hurwitz via cfe-commits <
cfe-commits@lists.llvm.org> wrote:

> See attached.
>
> Returning a bool from main is a special case of return type mismatch. The
> common convention when returning a bool is that 'true' (== 1) indicates
> success and 'false' (== 0) failure. But since main expects a return value
> of 0 on success, returning a bool is usually unintended.
> ___
> cfe-commits mailing list
> cfe-commits@lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
>
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D26288: Deduplicate replacements by FileEntry instead of file names.

2016-11-03 Thread Manuel Klimek via cfe-commits
klimek added a comment.

If the files do not exist, how does this work? Won't that potentially give 
different results if the files exist locally vs if they don't?


https://reviews.llvm.org/D26288



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r285685 - Fix parenthesized assert (nfc).

2016-11-01 Thread Manuel Klimek via cfe-commits
Author: klimek
Date: Tue Nov  1 05:30:50 2016
New Revision: 285685

URL: http://llvm.org/viewvc/llvm-project?rev=285685=rev
Log:
Fix parenthesized assert (nfc).

Modified:
cfe/trunk/lib/AST/Decl.cpp

Modified: cfe/trunk/lib/AST/Decl.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/Decl.cpp?rev=285685=285684=285685=diff
==
--- cfe/trunk/lib/AST/Decl.cpp (original)
+++ cfe/trunk/lib/AST/Decl.cpp Tue Nov  1 05:30:50 2016
@@ -3048,8 +3048,8 @@ const Attr *FunctionDecl::getUnusedResul
 /// an externally visible symbol, but "extern inline" will not create an 
 /// externally visible symbol.
 bool FunctionDecl::isInlineDefinitionExternallyVisible() const {
-  assert(doesThisDeclarationHaveABody() ||
- willHaveBody() && "Must be a function definition");
+  assert((doesThisDeclarationHaveABody() || willHaveBody()) &&
+ "Must be a function definition");
   assert(isInlined() && "Function must be inline");
   ASTContext  = getASTContext();
   


___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D26032: [ASTMatcher] Add CXXNewExpr support to hasDeclaration

2016-10-31 Thread Manuel Klimek via cfe-commits
klimek accepted this revision.
klimek added a comment.

Yep, makes sense. Open issues are all about types :)


https://reviews.llvm.org/D26032



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D21075: Correct invalid end location in diagnostics for some identifiers.

2016-10-27 Thread Manuel Klimek via cfe-commits
klimek added a comment.

> It's mostly about how much is "underlined". If there is only a caret, that 
> quite often translates into a single character being pointed out, instead of 
> an identifier (i.e. the first character). Hene the extension of the range.

Aren't we mostly doing token positions? It's basically always wrong to point at 
a single character, right?


https://reviews.llvm.org/D21075



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] r285060 - include-fixer: Don't overwrite buffer changes

2016-10-25 Thread Manuel Klimek via cfe-commits
Author: klimek
Date: Tue Oct 25 06:31:22 2016
New Revision: 285060

URL: http://llvm.org/viewvc/llvm-project?rev=285060=rev
Log:
include-fixer: Don't overwrite buffer changes

Raise a signal if the buffer has been modified before replacing it, to
avoid overwriting users' changes.

Patch by Philipp Stephani.

Modified:
clang-tools-extra/trunk/include-fixer/tool/clang-include-fixer.el

Modified: clang-tools-extra/trunk/include-fixer/tool/clang-include-fixer.el
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/include-fixer/tool/clang-include-fixer.el?rev=285060=285059=285060=diff
==
--- clang-tools-extra/trunk/include-fixer/tool/clang-include-fixer.el (original)
+++ clang-tools-extra/trunk/include-fixer/tool/clang-include-fixer.el Tue Oct 
25 06:31:22 2016
@@ -244,7 +244,13 @@ clang-include-fixer to insert the select
 (clang-include-fixer--select-header context)
 ;; Call clang-include-fixer again to insert the selected header.
 (clang-include-fixer--start
- #'clang-include-fixer--replace-buffer
+ (let ((old-tick (buffer-chars-modified-tick)))
+   (lambda (stdout)
+ (when (/= old-tick (buffer-chars-modified-tick))
+   ;; Replacing the buffer now would undo the user’s changes.
+   (user-error (concat "The buffer has been changed "
+   "before the header could be inserted")))
+ (clang-include-fixer--replace-buffer stdout)))
  (format "-insert-header=%s"
  (clang-include-fixer--encode-json context)))
   nil)


___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] r285059 - Load clang-include-fixer.el from the unit test suite so that the unit tests can run in batch mode.

2016-10-25 Thread Manuel Klimek via cfe-commits
Author: klimek
Date: Tue Oct 25 06:30:28 2016
New Revision: 285059

URL: http://llvm.org/viewvc/llvm-project?rev=285059=rev
Log:
Load clang-include-fixer.el from the unit test suite so that the unit tests can 
run in batch mode.

Patch by Philipp Stephani.

Modified:
clang-tools-extra/trunk/include-fixer/tool/clang-include-fixer-test.el

Modified: clang-tools-extra/trunk/include-fixer/tool/clang-include-fixer-test.el
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/include-fixer/tool/clang-include-fixer-test.el?rev=285059=285058=285059=diff
==
--- clang-tools-extra/trunk/include-fixer/tool/clang-include-fixer-test.el 
(original)
+++ clang-tools-extra/trunk/include-fixer/tool/clang-include-fixer-test.el Tue 
Oct 25 06:30:28 2016
@@ -6,6 +6,8 @@
 
 ;;; Code:
 
+(require 'clang-include-fixer)
+
 (require 'cc-mode)
 (require 'ert)
 


___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D24361: hasDeclaration(qualType(...)) matcher should unwrap ElaboratedType and TemplateSpecializationType

2016-10-24 Thread Manuel Klimek via cfe-commits
klimek added inline comments.



Comment at: unittests/ASTMatchers/ASTMatchersTraversalTest.cpp:2119
+  "template \n"
+  "void Function(Namespace::Template param) {\n"
+  "  param.Method();\n"

lukasza wrote:
> klimek wrote:
> > Given your use case: why do we need hasDeclaration here at all?
> > I'd have expected this working with just matching on the nested name 
> > specifier of the type instead of saying hasDeclaration on the template type.
> > Btw, if you add a type alias for a class not in the namespace into the 
> > namespace (typedef / using), do you wan that to rename or not? :)
> > 
> > I'd personally probably have expected (2), but I'm never sure in these 
> > cases without playing around with more test cases...
> > Given your use case: why do we need hasDeclaration here at all?
> > I'd have expected this working with just matching on the nested name 
> > specifier of the type instead of saying hasDeclaration on the template type.
> 
> Because I want "namespace-of-user-provided-declaration" matching to work both 
> for ElaboratedType nodes (with explicit nested name specifier) and for other 
> kinds of nodes (where there might be no nested name specifier).  I was hoping 
> that I could do this with a single hasDeclaration matcher, rather than 
> listing all possible type nodes myself (when building my own matcher) like I 
> sort of do in a workaround.  In particular, after this CL a single, simple 
> hasDeclaration-based matcher can be used in
> //auto blink_qual_type_base_matcher =
> //qualType(hasDeclaration(in_blink_namespace));
> inside https://codereview.chromium.org/2256913002/patch/180001/190001.
> 
> > Btw, if you add a type alias for a class not in the namespace into the 
> > namespace (typedef / using), do you wan that to rename or not? :)
> 
> Good question.  I want a rename to happen if I have 
> ::SomeOtherNamespace::Typedef resolving to 
> ::NamespaceWithRenamedMethods::Class, but I do not want rename to happen if I 
> have ::NamespaceWithRenamtedMethods::Typedef resolving to 
> ::SomeOtherNamespace::Class.  I guess my current hasDeclaration-based matcher 
> will match both cases :-(  One way to fix this would be to exclude typedefs 
> in |decl_under_blink_namespace| at 
> https://chromium.googlesource.com/chromium/src/+/14d095b4df6754fa4e6959220b2b332db0b4f504/tools/clang/rewrite_to_chrome_style/RewriteToChromeStyle.cpp#646
> 
> But... this question+answer should have no impact on the CL under review, 
> right?
> 
> > I'd personally probably have expected (2), but I'm never sure in these 
> > cases without playing around with more test cases...
> 
> Ok.  This (#2) is what the current patch results in.
You're right that regardless of what the right solution for your tool is, we 
should close this hole :)

Richard, can you elaborate on why you would have expected (3) to happen? I'm 
reluctant to put something into the matchers that you think is unexpected...


https://reviews.llvm.org/D24361



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r283864 - Delete clang-completion-mode.el.

2016-10-11 Thread Manuel Klimek via cfe-commits
Author: klimek
Date: Tue Oct 11 04:25:34 2016
New Revision: 283864

URL: http://llvm.org/viewvc/llvm-project?rev=283864=rev
Log:
Delete clang-completion-mode.el.

It has been unmaintained for a while (last change was more than four
years ago), and it appears not widely used.
By now there are multiple well-maintained alternatives (emacs-ycmd,
atuo-complete-clang), and if users try to make this work they'll likely
have a bad user experience.

Reasoning and problems pointed out by Philipp Stephani.

Removed:
cfe/trunk/utils/clang-completion-mode.el

Removed: cfe/trunk/utils/clang-completion-mode.el
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/utils/clang-completion-mode.el?rev=283863=auto
==
--- cfe/trunk/utils/clang-completion-mode.el (original)
+++ cfe/trunk/utils/clang-completion-mode.el (removed)
@@ -1,248 +0,0 @@
-;;; Clang Code-Completion minor mode, for use with C/Objective-C/C++.
-
-;;; Commentary:
-
-;; This minor mode uses Clang's command line interface for code
-;; completion to provide code completion results for C, Objective-C,
-;; and C++ source files. When enabled, Clang will provide
-;; code-completion results in a secondary buffer based on the code
-;; being typed. For example, after typing "struct " (triggered via the
-;; space), Clang will provide the names of all structs visible from
-;; the current scope. After typing "p->" (triggered via the ">"),
-;; Clang will provide the names of all of the members of whatever
-;; class/struct/union "p" points to. Note that this minor mode isn't
-;; meant for serious use: it is meant to help experiment with code
-;; completion based on Clang. It needs your help to make it better!
-;;
-;; To use the Clang code completion mode, first make sure that the
-;; "clang" variable below refers to the "clang" executable,
-;; which is typically installed in libexec/. Then, place
-;; clang-completion-mode.el somewhere in your Emacs load path. You can
-;; add a new load path to Emacs by adding some like the following to
-;; your .emacs:
-;;
-;;   (setq load-path (cons "~/.emacs.d" load-path))
-;;
-;; Then, use
-;;
-;;   M-x load-library
-;;
-;; to load the library in your Emacs session or add the following to
-;; your .emacs to always load this mode (not recommended):
-;;
-;;   (load-library "clang-completion-mode")
-;;
-;; Once you have done this, you can set various parameters with
-;;
-;;   M-x customize-group RET clang-completion-mode RET
-;;
-;; Finally, to try Clang-based code completion in a particular buffer,
-;; use M-x clang-completion-mode. When "Clang" shows up in the mode
-;; line, Clang's code-completion is enabled.
-;;
-;; Clang's code completion is based on parsing the complete source
-;; file up to the point where the cursor is located. Therefore, Clang
-;; needs all of the various compilation flags (include paths, dialect
-;; options, etc.) to provide code-completion results. Currently, these
-;; need to be placed into the clang-flags variable in a format
-;; acceptable to clang. This is a hack: patches are welcome to
-;; improve the interface between this Emacs mode and Clang! 
-;;
-
-;;; Code:
-;;; The clang executable
-(defcustom clang "clang"
-  "The location of the Clang compiler executable"
-  :type 'file
-  :group 'clang-completion-mode)
-
-;;; Extra compilation flags to pass to clang.
-(defcustom clang-flags nil
-  "Extra flags to pass to the Clang executable.
-This variable will typically contain include paths, e.g., -I~/MyProject."
-  :type '(repeat (string :tag "Argument" ""))
-  :group 'clang-completion-mode)
-
-;;; The prefix header to use with Clang code completion. 
-(defvar clang-completion-prefix-header "")
-
-;;; The substring we will use to filter completion results
-(defvar clang-completion-substring "")
-
-;;; The current completion buffer
-(defvar clang-completion-buffer nil)
-
-(defvar clang-result-string "")
-
-;;; Compute the current line in the buffer 
-(defun current-line ()
-  "Return the vertical position of point..."
-  (+ (count-lines (point-min) (point))
- (if (= (current-column) 0) 1 0)
- -1))
-
-;;; Set the Clang prefix header
-(defun clang-prefix-header ()
-  (interactive)
-  (setq clang-completion-prefix-header
-(read-string "Clang prefix header> " "" clang-completion-prefix-header
- "")))
-
-;; Process "filter" that keeps track of the code-completion results
-;; produced. We store all of the results in a string, then the
-;; sentinel processes the entire string at once.
-(defun clang-completion-stash-filter (proc string)
-  (setq clang-result-string (concat clang-result-string string)))
-
-;; Filter the given list based on a predicate.
-(defun filter (condp lst)
-(delq nil
-  (mapcar (lambda (x) (and (funcall condp x) x)) lst)))
-
-;; Determine whether FIXME: explain better
-(defun is-completion-line (line)
-  (or (string-match "OVERLOAD:" line)
-  (string-match (concat 

[clang-tools-extra] r283863 - clang-include-fixer.el: Don't prompt the user about killing clang-include-fixer processes

2016-10-11 Thread Manuel Klimek via cfe-commits
Author: klimek
Date: Tue Oct 11 04:21:20 2016
New Revision: 283863

URL: http://llvm.org/viewvc/llvm-project?rev=283863=rev
Log:
clang-include-fixer.el: Don't prompt the user about killing clang-include-fixer 
processes

By default, Emacs prompts the user when killing processes on exit. This is 
useful for stateful processes such as interactive shells. However, 
clang-include-fixer processes are stateless; the only effect of killing them is 
to cancel a clang-include-fixer operation. Therefore prompting the user is just 
a nuisance.

Patch by Philipp Stephani.

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

Modified:
clang-tools-extra/trunk/include-fixer/tool/clang-include-fixer.el

Modified: clang-tools-extra/trunk/include-fixer/tool/clang-include-fixer.el
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/include-fixer/tool/clang-include-fixer.el?rev=283863=283862=283863=diff
==
--- clang-tools-extra/trunk/include-fixer/tool/clang-include-fixer.el (original)
+++ clang-tools-extra/trunk/include-fixer/tool/clang-include-fixer.el Tue Oct 
11 04:21:20 2016
@@ -101,6 +101,7 @@ arguments.  Return the new process objec
   :buffer stdout
   :command (clang-include-fixer--command args)
   :coding 'utf-8-unix
+  :noquery t
   :connection-type 'pipe
   :sentinel (clang-include-fixer--sentinel stdin stdout stderr
callback)
@@ -118,6 +119,7 @@ arguments.  Return the new process objec
  (process (apply #'start-process "clang-include-fixer" stdout
  (clang-include-fixer--command args
 (set-process-coding-system process 'utf-8-unix 'utf-8-unix)
+(set-process-query-on-exit-flag process nil)
 (set-process-sentinel process
   (clang-include-fixer--sentinel stdin stdout nil
  callback))


___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] r283861 - Make Emacs libraries compatible with Emacs 24.

2016-10-11 Thread Manuel Klimek via cfe-commits
Author: klimek
Date: Tue Oct 11 04:15:10 2016
New Revision: 283861

URL: http://llvm.org/viewvc/llvm-project?rev=283861=rev
Log:
Make Emacs libraries compatible with Emacs 24.

Emacs 24 doesn't have format-message, fall back to format in that case.

Patch by Philipp Stephani.

Modified:
clang-tools-extra/trunk/clang-rename/tool/clang-rename.el
clang-tools-extra/trunk/include-fixer/tool/clang-include-fixer.el

Modified: clang-tools-extra/trunk/clang-rename/tool/clang-rename.el
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-rename/tool/clang-rename.el?rev=283861=283860=283861=diff
==
--- clang-tools-extra/trunk/clang-rename/tool/clang-rename.el (original)
+++ clang-tools-extra/trunk/clang-rename/tool/clang-rename.el Tue Oct 11 
04:15:10 2016
@@ -52,7 +52,7 @@
 (kill-buffer output-buffer)
 (revert-buffer :ignore-auto :noconfirm :preserve-modes))
 ;; Failure; append exit code to output buffer and display it.
-(let ((message (format-message
+(let ((message (clang-rename--format-message
 "clang-rename failed with %s %s"
 (if (integerp exit-code) "exit status" "signal")
 exit-code)))
@@ -69,6 +69,11 @@
 (lambda (position  _quality _coding-system)
   (1- (position-bytes position)
 
+;; ‘format-message’ is new in Emacs 25.1.  Provide a fallback for older
+;; versions.
+(defalias 'clang-rename--format-message
+  (if (fboundp 'format-message) 'format-message 'format))
+
 (provide 'clang-rename)
 
 ;;; clang-rename.el ends here

Modified: clang-tools-extra/trunk/include-fixer/tool/clang-include-fixer.el
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/include-fixer/tool/clang-include-fixer.el?rev=283861=283860=283861=diff
==
--- clang-tools-extra/trunk/include-fixer/tool/clang-include-fixer.el (original)
+++ clang-tools-extra/trunk/include-fixer/tool/clang-include-fixer.el Tue Oct 
11 04:15:10 2016
@@ -281,8 +281,8 @@ They are replaced by the single element
 (cl-flet ((header (info) (let-alist info .Header)))
   ;; The header-infos is already sorted by include-fixer.
   (let* ((header (ido-completing-read
-  (format-message "Select include for '%s': "
-  symbol)
+  (clang-include-fixer--format-message
+   "Select include for '%s': " symbol)
   (mapcar #'header .HeaderInfos)
   nil :require-match nil
   'clang-include-fixer--history))
@@ -402,5 +402,10 @@ non-nil.  Otherwise return nil."
 (lambda (byte  _quality _coding-system)
   (byte-to-position (1+ byte)
 
+;; ‘format-message’ is new in Emacs 25.1.  Provide a fallback for older
+;; versions.
+(defalias 'clang-include-fixer--format-message
+  (if (fboundp 'format-message) 'format-message 'format))
+
 (provide 'clang-include-fixer)
 ;;; clang-include-fixer.el ends here


___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] r283736 - Use `let' instead of `let*' in one place where `let*' isn't necessary

2016-10-10 Thread Manuel Klimek via cfe-commits
Author: klimek
Date: Mon Oct 10 05:22:40 2016
New Revision: 283736

URL: http://llvm.org/viewvc/llvm-project?rev=283736=rev
Log:
Use `let' instead of `let*' in one place where `let*' isn't necessary

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

Patch by Philipp Stephani.

Modified:
clang-tools-extra/trunk/include-fixer/tool/clang-include-fixer.el

Modified: clang-tools-extra/trunk/include-fixer/tool/clang-include-fixer.el
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/include-fixer/tool/clang-include-fixer.el?rev=283736=283735=283736=diff
==
--- clang-tools-extra/trunk/include-fixer/tool/clang-include-fixer.el (original)
+++ clang-tools-extra/trunk/include-fixer/tool/clang-include-fixer.el Mon Oct 
10 05:22:40 2016
@@ -94,9 +94,9 @@ CALLBACK is called after the process fin
 called with a single argument, the buffer where standard output
 has been inserted.  ARGS is a list of additional command line
 arguments.  Return the new process object."
-  (let* ((stdin (current-buffer))
- (stdout (generate-new-buffer "*clang-include-fixer output*"))
- (stderr (generate-new-buffer "*clang-include-fixer errors*")))
+  (let ((stdin (current-buffer))
+(stdout (generate-new-buffer "*clang-include-fixer output*"))
+(stderr (generate-new-buffer "*clang-include-fixer errors*")))
 (make-process :name "clang-include-fixer"
   :buffer stdout
   :command (clang-include-fixer--command args)


___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r283206 - Minor cleanups in clang-format.el.

2016-10-04 Thread Manuel Klimek via cfe-commits
Author: klimek
Date: Tue Oct  4 04:53:04 2016
New Revision: 283206

URL: http://llvm.org/viewvc/llvm-project?rev=283206=rev
Log:
Minor cleanups in clang-format.el.

- Enable lexical binding
- Formatting
- Enable file name completion for the clang-format-executable variable
- Add a missing docstring
- When available, use bufferpos-to-filepos and filepos-to-bufferpos. These 
functions given more precise mapping than byte-to-position and position-bytes.
- Rename arguments of clang-format-region to match the docstring
- Instead of binding local variables to nil and then assigning them, bind them 
directly to their values
- Make use of the fact that insert-file-contents returns the number of 
characters it inserted
- Use cl-destructuring-bind to make the code a bit shorter
- Use standard iteration (dolist) instead of mapc with a lambda, which is more 
common and shorter
- Remove a message that was most likely only present for debugging purposes

Patch by Philipp Stephani.

Modified:
cfe/trunk/tools/clang-format/clang-format.el

Modified: cfe/trunk/tools/clang-format/clang-format.el
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/clang-format/clang-format.el?rev=283206=283205=283206=diff
==
--- cfe/trunk/tools/clang-format/clang-format.el (original)
+++ cfe/trunk/tools/clang-format/clang-format.el Tue Oct  4 04:53:04 2016
@@ -1,4 +1,4 @@
-;;; clang-format.el --- Format code using clang-format
+;;; clang-format.el --- Format code using clang-format  -*- lexical-binding: 
t; -*-
 
 ;; Keywords: tools, c
 ;; Package-Requires: ((cl-lib "0.3"))
@@ -15,7 +15,7 @@
 ;;   M-x package-install clang-format
 ;;
 ;; when ("melpa" . "http://melpa.org/packages/;) is included in
-;; `package-archives'. Alternatively, ensure the directory of this
+;; `package-archives'.  Alternatively, ensure the directory of this
 ;; file is in your `load-path' and add
 ;;
 ;;   (require 'clang-format)
@@ -42,7 +42,7 @@
 
 A string containing the name or the full path of the executable."
   :group 'clang-format
-  :type 'string
+  :type '(file :must-match t)
   :risky t)
 
 (defcustom clang-format-style "file"
@@ -93,15 +93,32 @@ of the buffer."
 (list replacements cursor (string= incomplete-format "true"
 
 (defun clang-format--replace (offset length  text)
-  (let ((start (byte-to-position (1+ offset)))
-(end (byte-to-position (+ 1 offset length
+  "Replace the region defined by OFFSET and LENGTH with TEXT.
+OFFSET and LENGTH are measured in bytes, not characters.  OFFSET
+is a zero-based file offset."
+  (let ((start (clang-format--filepos-to-bufferpos offset 'exact))
+(end (clang-format--filepos-to-bufferpos (+ offset length) 'exact)))
 (goto-char start)
 (delete-region start end)
 (when text
   (insert text
 
+;; ‘bufferpos-to-filepos’ and ‘filepos-to-bufferpos’ are new in Emacs 
25.1.
+;; Provide fallbacks for older versions.
+(defalias 'clang-format--bufferpos-to-filepos
+  (if (fboundp 'bufferpos-to-filepos)
+  'bufferpos-to-filepos
+(lambda (position  _quality _coding-system)
+  (1- (position-bytes position)
+
+(defalias 'clang-format--filepos-to-bufferpos
+  (if (fboundp 'filepos-to-bufferpos)
+  'filepos-to-bufferpos
+(lambda (byte  _quality _coding-system)
+  (byte-to-position (1+ byte)
+
 ;;;###autoload
-(defun clang-format-region (char-start char-end  style)
+(defun clang-format-region (start end  style)
   "Use clang-format to format the code between START and END according to 
STYLE.
 If called interactively uses the region or the current statement if there
 is no active region.  If no style is given uses `clang-format-style'."
@@ -113,51 +130,41 @@ is no active region.  If no style is giv
   (unless style
 (setq style clang-format-style))
 
-  (let ((start (1- (position-bytes char-start)))
-(end (1- (position-bytes char-end)))
-(cursor (1- (position-bytes (point
+  (let ((file-start (clang-format--bufferpos-to-filepos start 'approximate))
+(file-end (clang-format--bufferpos-to-filepos end 'approximate))
+(cursor (clang-format--bufferpos-to-filepos (point) 'exact))
 (temp-buffer (generate-new-buffer " *clang-format-temp*"))
 (temp-file (make-temp-file "clang-format")))
 (unwind-protect
-(let (status stderr operations)
-  (setq status
-(call-process-region
- nil nil clang-format-executable
- nil `(,temp-buffer ,temp-file) nil
-
- "-output-replacements-xml"
- "-assume-filename" (or (buffer-file-name) "")
- "-style" style
- "-offset" (number-to-string start)
- "-length" (number-to-string (- end start))
- "-cursor" (number-to-string cursor)))
-  (setq stderr
-(with-temp-buffer
-  (insert-file-contents 

[PATCH] [Commented On] D24380: [migrate-tool] Framework for a codebase-dependent migration tool.

2016-09-30 Thread Manuel Klimek via cfe-commits
klimek added inline comments.


> ioeric wrote in MigrateTool.cpp:52
> That sounds like a good design, but I'm not sure if we need this at this 
> point since actions on affected files would simply be renaming and include 
> fixing now and in the foreseeable future.

Well, my main concern is how we hook this up to full codebase wide analyses. 
Currently, we basically hard-code the execution strategy, right?

https://reviews.llvm.org/D24380



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] [Accepted] D25049: Add missing std::move in Replacements::add

2016-09-30 Thread Manuel Klimek via cfe-commits
klimek accepted this revision.
klimek added a comment.
This revision is now accepted and ready to land.

lg


Repository:
  rL LLVM

https://reviews.llvm.org/D25049



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] [Commented On] D24380: [migrate-tool] Framework for a codebase-dependent migration tool.

2016-09-30 Thread Manuel Klimek via cfe-commits
klimek added inline comments.


> MigrateTool.cpp:52
> +  // Get all files that are affected by the migration, i.e. users of the 
> symbol.
> +  auto Files = 
> Env.getAffectedFilesFinder().getAffectedFiles(Spec.getOldName());
> +  if (!Files)

I'm wondering whether we really want to evolve this to a callback / executor 
based design. That is, have AffectedFilesFinder give an interface like 
RunOnAffectedFiles(...)

https://reviews.llvm.org/D24380



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: r282583 - Trying to buildbot failures caused by r282577.

2016-09-28 Thread Manuel Klimek via cfe-commits
On Wed, Sep 28, 2016 at 2:58 PM Eric Liu via cfe-commits <
cfe-commits@lists.llvm.org> wrote:

> Author: ioeric
> Date: Wed Sep 28 07:49:14 2016
> New Revision: 282583
>
> URL: http://llvm.org/viewvc/llvm-project?rev=282583=rev
> Log:
> Trying to buildbot failures caused by r282577.
>

A bit more explanation of what failed, and why this fixes it, would be nice
in the future :)


>
> Modified:
> cfe/trunk/lib/Tooling/Core/Replacement.cpp
>
> Modified: cfe/trunk/lib/Tooling/Core/Replacement.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Tooling/Core/Replacement.cpp?rev=282583=282582=282583=diff
>
> ==
> --- cfe/trunk/lib/Tooling/Core/Replacement.cpp (original)
> +++ cfe/trunk/lib/Tooling/Core/Replacement.cpp Wed Sep 28 07:49:14 2016
> @@ -287,8 +287,13 @@ llvm::Error Replacements::add(const Repl
>  // with them and replace them with the merged replacements.
>  auto MergeBegin = I;
>  auto MergeEnd = std::next(I);
> -while (I-- != Replaces.begin() && Overlap(R, *I))
> +while (I != Replaces.begin()) {
> +  --I;
> +  // If `I` doesn't overlap with `R`, don't merge it.
> +  if (!Overlap(R, *I))
> +break;
>MergeBegin = I;
> +}
>  Replacements OverlapReplaces(MergeBegin, MergeEnd);
>  llvm::Expected Merged =
>  OverlapReplaces.mergeIfOrderIndependent(R);
>
>
> ___
> cfe-commits mailing list
> cfe-commits@lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
>
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r282573 - Fix warnings in clang-completion-mode.el.

2016-09-28 Thread Manuel Klimek via cfe-commits
Author: klimek
Date: Wed Sep 28 05:20:10 2016
New Revision: 282573

URL: http://llvm.org/viewvc/llvm-project?rev=282573=rev
Log:
Fix warnings in clang-completion-mode.el.

- Use defvar to declare variables
- Don't use delete-backward-char, which is for interactive use only

Patch by Philipp Stephani

Modified:
cfe/trunk/utils/clang-completion-mode.el

Modified: cfe/trunk/utils/clang-completion-mode.el
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/utils/clang-completion-mode.el?rev=282573=282572=282573=diff
==
--- cfe/trunk/utils/clang-completion-mode.el (original)
+++ cfe/trunk/utils/clang-completion-mode.el Wed Sep 28 05:20:10 2016
@@ -64,15 +64,15 @@ This variable will typically contain inc
   :group 'clang-completion-mode)
 
 ;;; The prefix header to use with Clang code completion. 
-(setq clang-completion-prefix-header "")
+(defvar clang-completion-prefix-header "")
 
 ;;; The substring we will use to filter completion results
-(setq clang-completion-substring "")
+(defvar clang-completion-substring "")
 
 ;;; The current completion buffer
-(setq clang-completion-buffer nil)
+(defvar clang-completion-buffer nil)
 
-(setq clang-result-string "")
+(defvar clang-result-string "")
 
 ;;; Compute the current line in the buffer 
 (defun current-line ()
@@ -199,14 +199,14 @@ This variable will typically contain inc
 ;; for the currently-active code completion.
 (defun clang-backspace ()
   (interactive)
-  (delete-backward-char 1)
+  (delete-char -1)
   (clang-update-filter))
 
 ;; Invoked when the user types the delete key to update the filter
 ;; for the currently-active code completion.
 (defun clang-delete ()
   (interactive)
-  (delete-backward-char 1)
+  (delete-char -1)
   (clang-update-filter))
 
 ;; Set up the keymap for the Clang minor mode.
@@ -246,4 +246,3 @@ This variable will typically contain inc
   nil
   " Clang"
   clang-completion-mode-map)
-


___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D24800: Merge conflicting replacements when they are order-independent.

2016-09-28 Thread Manuel Klimek via cfe-commits
klimek accepted this revision.
klimek added a comment.
This revision is now accepted and ready to land.

lg



Comment at: lib/Tooling/Core/Replacement.cpp:179-181
@@ +178,5 @@
+// `R` and `Replaces` are order-independent if applying them in either order
+// has the same effect, so we need to compare replacements associated to
+// applying them in either order.
+llvm::Expected
+Replacements::mergeIfOrderIndependent(const Replacement ) const {

Much better. Thanks.


https://reviews.llvm.org/D24800



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D24800: Merge conflicting replacements when they are order-independent.

2016-09-27 Thread Manuel Klimek via cfe-commits
klimek added inline comments.


Comment at: lib/Tooling/Core/Replacement.cpp:179-181
@@ +178,5 @@
+llvm::Expected
+Replacements::mergeIfOrderIndependent(const Replacement ) const {
+  Replacements Rs(R);
+  Replacements RsShiftedByReplaces(getReplacementInChangedCode(R));
+  Replacements ReplacesShiftedByRs;

I think this is a bit subtle and needs a lot more comments to guide me along 
what is happening and why ...


https://reviews.llvm.org/D24800



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D24800: Merge conflicting replacements when they are order-independent.

2016-09-27 Thread Manuel Klimek via cfe-commits
klimek added inline comments.


Comment at: include/clang/Tooling/Core/Replacement.h:177-178
@@ +176,4 @@
+  ///   - are insertions at the same offset and applying them in either order
+  /// has the same effect, i.e. X + Y = Y + X if one inserts text X and the
+  /// other inserts text Y.
+  /// Examples:

ioeric wrote:
> klimek wrote:
> > This seems incorrect. What am I missing?
> Here is the discussion about this: https://reviews.llvm.org/D24717
I misunderstood :) Perhaps change to:
, i.e. if X + Y == Y + X when inserting X and Y respectively.


Comment at: include/clang/Tooling/Core/Replacement.h:242
@@ +241,3 @@
+  // If `R` and all existing replacements are order-indepedent, then merge it
+  // with `Replaces` and returns the merged replacements; otheriwse, returns an
+  // error.

typo: otheriwse


Comment at: lib/Tooling/Core/Replacement.cpp:162
@@ +161,3 @@
+auto  = NewReplaces.back();
+auto PrevEnd = Prev.getOffset() + Prev.getLength();
+if (PrevEnd < R.getOffset()) {

I'd not use auto for simple integer types.


Comment at: lib/Tooling/Core/Replacement.cpp:166
@@ +165,3 @@
+} else {
+  assert(PrevEnd == R.getOffset());
+  Replacement NewR(

Add comment why we can assert this.


Comment at: lib/Tooling/Core/Replacement.cpp:179-181
@@ +178,5 @@
+Replacements::mergeIfOrderIndependent(const Replacement ) const {
+  Replacements Rs(R);
+  Replacements ShiftedRs(getReplacementInChangedCode(R));
+  Replacements ShiftedReplaces;
+  for (const auto  : Replaces)

These names are confusing me...



Comment at: lib/Tooling/Core/Replacement.cpp:184
@@ +183,3 @@
+ShiftedReplaces.Replaces.insert(Rs.getReplacementInChangedCode(Replace));
+  auto MergeRs = merge(ShiftedRs);
+  auto MergeReplaces = Rs.merge(ShiftedReplaces);

This comes from a single replacement - why do we need to call merge?


https://reviews.llvm.org/D24800



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D24800: Merge conflicting replacements when they are order-independent.

2016-09-27 Thread Manuel Klimek via cfe-commits
klimek added inline comments.


Comment at: include/clang/Tooling/Core/Replacement.h:177-178
@@ +176,4 @@
+  ///   - are insertions at the same offset and applying them in either order
+  /// has the same effect, i.e. X + Y = Y + X if one inserts text X and the
+  /// other inserts text Y.
+  /// Examples:

This seems incorrect. What am I missing?


https://reviews.llvm.org/D24800



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D24380: [migrate-tool] Framework for a codebase-dependent migration tool.

2016-09-26 Thread Manuel Klimek via cfe-commits
klimek added inline comments.


Comment at: migrate-tool/AffectedFilesFinder.h:24-25
@@ +23,4 @@
+public:
+  // Get all files that need to be updated when a symbol is renamed and/or
+  // moved.
+  virtual llvm::Expected

Comment a bit on what the contract here is: will these be absolute or relative 
paths?


Comment at: migrate-tool/BuildManager.h:28
@@ +27,3 @@
+
+  // Adds a new dependency to the build target.
+  virtual bool addDependency(llvm::StringRef BuildTarget,

I think this needs more comments explaining what BuildTarget / Dependency will 
be. Similarly for Name above.


Comment at: migrate-tool/DummyMigrationEnvironment.h:18-20
@@ +17,5 @@
+
+// Creates a dummy migration environment whose components do not perform actual
+// work and only print messages.
+std::unique_ptr createDummyMigrationEnvironment();
+

Do we perhaps want to create fakes here, where we can later query the libraries 
/ dependencies that exist?


https://reviews.llvm.org/D24380



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


  1   2   3   4   5   6   >