[clang-tools-extra] f88c6b9 - Move definitions to prevent incomplete types.

2023-01-13 Thread Jens Massberg via cfe-commits

Author: Jens Massberg
Date: 2023-01-13T16:44:49+01:00
New Revision: f88c6b9166f885e7089cb15095e38868aaba04da

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

LOG: Move definitions to prevent incomplete types.

C++20 is more strict when erroring out due to incomplete types.
Thus the code required some restructoring so that it complies in C++20.

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

Added: 


Modified: 
clang-tools-extra/clang-doc/Representation.cpp
clang-tools-extra/clang-doc/Representation.h

Removed: 




diff  --git a/clang-tools-extra/clang-doc/Representation.cpp 
b/clang-tools-extra/clang-doc/Representation.cpp
index c1279997813a8..31bb07d04b35d 100644
--- a/clang-tools-extra/clang-doc/Representation.cpp
+++ b/clang-tools-extra/clang-doc/Representation.cpp
@@ -128,6 +128,41 @@ mergeInfos(std::vector> &Values) {
   }
 }
 
+bool CommentInfo::operator==(const CommentInfo &Other) const {
+  auto FirstCI = std::tie(Kind, Text, Name, Direction, ParamName, CloseName,
+  SelfClosing, Explicit, AttrKeys, AttrValues, Args);
+  auto SecondCI =
+  std::tie(Other.Kind, Other.Text, Other.Name, Other.Direction,
+   Other.ParamName, Other.CloseName, Other.SelfClosing,
+   Other.Explicit, Other.AttrKeys, Other.AttrValues, Other.Args);
+
+  if (FirstCI != SecondCI || Children.size() != Other.Children.size())
+return false;
+
+  return std::equal(Children.begin(), Children.end(), Other.Children.begin(),
+llvm::deref>{});
+}
+
+bool CommentInfo::operator<(const CommentInfo &Other) const {
+  auto FirstCI = std::tie(Kind, Text, Name, Direction, ParamName, CloseName,
+  SelfClosing, Explicit, AttrKeys, AttrValues, Args);
+  auto SecondCI =
+  std::tie(Other.Kind, Other.Text, Other.Name, Other.Direction,
+   Other.ParamName, Other.CloseName, Other.SelfClosing,
+   Other.Explicit, Other.AttrKeys, Other.AttrValues, Other.Args);
+
+  if (FirstCI < SecondCI)
+return true;
+
+  if (FirstCI == SecondCI) {
+return std::lexicographical_compare(
+Children.begin(), Children.end(), Other.Children.begin(),
+Other.Children.end(), llvm::deref>());
+  }
+
+  return false;
+}
+
 static llvm::SmallString<64>
 calculateRelativeFilePath(const InfoType &Type, const StringRef &Path,
   const StringRef &Name, const StringRef &CurrentPath) 
{
@@ -220,6 +255,9 @@ void SymbolInfo::merge(SymbolInfo &&Other) {
   mergeBase(std::move(Other));
 }
 
+NamespaceInfo::NamespaceInfo(SymbolID USR, StringRef Name, StringRef Path)
+  : Info(InfoType::IT_namespace, USR, Name, Path) {}
+
 void NamespaceInfo::merge(NamespaceInfo &&Other) {
   assert(mergeable(Other));
   // Reduce children if necessary.
@@ -231,6 +269,9 @@ void NamespaceInfo::merge(NamespaceInfo &&Other) {
   mergeBase(std::move(Other));
 }
 
+RecordInfo::RecordInfo(SymbolID USR, StringRef Name, StringRef Path)
+: SymbolInfo(InfoType::IT_record, USR, Name, Path) {}
+
 void RecordInfo::merge(RecordInfo &&Other) {
   assert(mergeable(Other));
   if (!TagType)
@@ -289,6 +330,14 @@ void TypedefInfo::merge(TypedefInfo &&Other) {
   SymbolInfo::merge(std::move(Other));
 }
 
+BaseRecordInfo::BaseRecordInfo() : RecordInfo() {}
+
+BaseRecordInfo::BaseRecordInfo(SymbolID USR, StringRef Name, StringRef Path,
+   bool IsVirtual, AccessSpecifier Access,
+   bool IsParent)
+: RecordInfo(USR, Name, Path), IsVirtual(IsVirtual), Access(Access),
+  IsParent(IsParent) {}
+
 llvm::SmallString<16> Info::extractName() const {
   if (!Name.empty())
 return Name;

diff  --git a/clang-tools-extra/clang-doc/Representation.h 
b/clang-tools-extra/clang-doc/Representation.h
index 564488ceb027f..15e1abf858aaa 100644
--- a/clang-tools-extra/clang-doc/Representation.h
+++ b/clang-tools-extra/clang-doc/Representation.h
@@ -52,44 +52,13 @@ struct CommentInfo {
   CommentInfo(CommentInfo &&Other) = default;
   CommentInfo &operator=(CommentInfo &&Other) = default;
 
-  bool operator==(const CommentInfo &Other) const {
-auto FirstCI = std::tie(Kind, Text, Name, Direction, ParamName, CloseName,
-SelfClosing, Explicit, AttrKeys, AttrValues, Args);
-auto SecondCI =
-std::tie(Other.Kind, Other.Text, Other.Name, Other.Direction,
- Other.ParamName, Other.CloseName, Other.SelfClosing,
- Other.Explicit, Other.AttrKeys, Other.AttrValues, Other.Args);
-
-if (FirstCI != SecondCI || Children.size() != Other.Children.size())
-  return false;
-
-return std::equal(Children.begin(), Children.end(), Other.Children.begin(),
-  llvm::deref>{});

[clang-tools-extra] e9ab43d - [clangd][c++20] Add concept Hover tests.

2023-07-18 Thread Jens Massberg via cfe-commits

Author: Jens Massberg
Date: 2023-07-18T10:19:46+02:00
New Revision: e9ab43dd44cafe5a67f0a12b9ff1021d47074970

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

LOG: [clangd][c++20] Add concept Hover tests.

Concepts aren't fully supporteb by hover yet. For the currently
supported case we add a test here to prevent regressions in the future.

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

Added: 


Modified: 
clang-tools-extra/clangd/unittests/HoverTests.cpp

Removed: 




diff  --git a/clang-tools-extra/clangd/unittests/HoverTests.cpp 
b/clang-tools-extra/clangd/unittests/HoverTests.cpp
index 91060a517de530..2ad7f0ee55d726 100644
--- a/clang-tools-extra/clangd/unittests/HoverTests.cpp
+++ b/clang-tools-extra/clangd/unittests/HoverTests.cpp
@@ -523,6 +523,32 @@ class Foo final {})cpp";
  HI.Kind = index::SymbolKind::TypeAlias;
  HI.Definition = "Foo";
}},
+  // constrained template parameter
+  {R"cpp(
+template concept Fooable = true;
+template<[[Foo^able]] T>
+void bar(T t) {}
+)cpp",
+   [](HoverInfo &HI) {
+ HI.NamespaceScope = "";
+ HI.Name = "Fooable";
+ HI.Kind = index::SymbolKind::Concept;
+ HI.Definition = "template \nconcept Fooable = true";
+   }},
+   {R"cpp(
+template concept Fooable = true;
+template
+void bar(TT t) {}
+)cpp",
+   [](HoverInfo &HI) {
+ HI.Name = "TT";
+ HI.Type = "class";
+ HI.AccessSpecifier = "public";
+ HI.NamespaceScope = "";
+ HI.LocalScope = "bar::";
+ HI.Kind = index::SymbolKind::TemplateTypeParm;
+ HI.Definition = "Fooable TT";
+   }},
 
   // empty macro
   {R"cpp(
@@ -3025,17 +3051,17 @@ TEST(Hover, Providers) {
 const char *Code;
 const std::function ExpectedBuilder;
   } Cases[] = {{R"cpp(
-  struct Foo {}; 
+  struct Foo {};
   Foo F = Fo^o{};
 )cpp",
 [](HoverInfo &HI) { HI.Provider = ""; }},
{R"cpp(
-  #include "foo.h"   
+  #include "foo.h"
   Foo F = Fo^o{};
 )cpp",
 [](HoverInfo &HI) { HI.Provider = "\"foo.h\""; }},
{R"cpp(
-  #include "all.h"  
+  #include "all.h"
   Foo F = Fo^o{};
 )cpp",
 [](HoverInfo &HI) { HI.Provider = "\"foo.h\""; }},
@@ -3055,7 +3081,7 @@ TEST(Hover, Providers) {
 )cpp",
 [](HoverInfo &HI) { HI.Provider = "\"foo.h\""; }},
{R"cpp(
-  #include "foo.h"
+  #include "foo.h"
   Foo A;
   Foo B;
   Foo C = A ^+ B;



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


[clang-tools-extra] 8af016a - [clangd][c++20] Add concept semantic highlighting test case

2023-08-02 Thread Jens Massberg via cfe-commits

Author: Jens Massberg
Date: 2023-08-02T10:37:30+02:00
New Revision: 8af016aefd8391d083cdf745420826ce162a41a5

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

LOG: [clangd][c++20] Add concept semantic highlighting test case

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

Added: 


Modified: 
clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp

Removed: 




diff  --git a/clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp 
b/clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp
index 6eee6ec30ac024..da12accc7898b6 100644
--- a/clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp
+++ b/clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp
@@ -657,6 +657,7 @@ sizeof...($TemplateParameter[[Elements]]);
   void $Function_def[[Bar]]($Concept[[Fooable]] $TemplateParameter[[auto]] 
$Parameter_def[[x]]) {}
 
   template$Bracket[[<]]$Concept[[Fooable]] auto 
$TemplateParameter_def_readonly[[x]]$Bracket[[>]] void $Function_def[[Boo]]() {}
+  bool $Variable_def[[b]] = 
$Concept[[Fooable]]$Bracket[[<]]int$Bracket[[>]];
 )cpp",
   // Dependent template name
   R"cpp(
@@ -886,10 +887,10 @@ sizeof...($TemplateParameter[[Elements]]);
   // Issue 1222: readonly modifier for generic parameter
   R"cpp(
 template $Bracket[[<]]typename $TemplateParameter_def[[T]]$Bracket[[>]]
-auto $Function_def[[foo]](const $TemplateParameter[[T]] 
$Parameter_def_readonly[[template_type]], 
-  const $TemplateParameter[[auto]] 
$Parameter_def_readonly[[auto_type]], 
+auto $Function_def[[foo]](const $TemplateParameter[[T]] 
$Parameter_def_readonly[[template_type]],
+  const $TemplateParameter[[auto]] 
$Parameter_def_readonly[[auto_type]],
   const int 
$Parameter_def_readonly[[explicit_type]]) {
-return $Parameter_readonly[[template_type]] 
+return $Parameter_readonly[[template_type]]
  $Operator_userDefined[[+]] $Parameter_readonly[[auto_type]]
  $Operator_userDefined[[+]] 
$Parameter_readonly[[explicit_type]];
 }
@@ -1002,7 +1003,7 @@ sizeof...($TemplateParameter[[Elements]]);
 template $Bracket[[<]]class $TemplateParameter_def[[T]]$Bracket[[>]]
 class $Class_def[[B]] {
   template $Bracket[[<]]class $TemplateParameter_def[[U]]$Bracket[[>]] 
void $Method_def[[foo]]($TemplateParameter[[U]]) { }
-  template$Bracket[[<]]$Bracket[[>]] void 
$Method_def[[foo]]$Bracket[[<]]int$Bracket[[>]](int) { } 
+  template$Bracket[[<]]$Bracket[[>]] void 
$Method_def[[foo]]$Bracket[[<]]int$Bracket[[>]](int) { }
   friend void 
$Function_decl[[foo]]$Bracket[[<]]$Bracket[[>]]($TemplateParameter[[T]]);
 };
   )cpp",



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


[clang-tools-extra] 1af0e34 - [clangd][c++20] Drop first template argument in code completion in some contexts.

2023-07-05 Thread Jens Massberg via cfe-commits

Author: Jens Massberg
Date: 2023-07-05T12:04:24+02:00
New Revision: 1af0e34477a3b4a28a1c251e527c9f75f5cf69e1

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

LOG: [clangd][c++20] Drop first template argument in code completion in some 
contexts.

In case of a top level context the first template argument of a concept
should be dropped. Currently the indexer doesn't support different
signatures for different contexts (for an index entry always the default
`Symbol` context is used). Thus we add a hack which checks if we are in
a top level context and have a concept and in that case removes the
first argment of the signature and snippet suffix. If there is only a
single argument, the signature and snippet suffix are completly
removed. The check for the first argument is done by simply looking for
the first comma which should be sufficient in most cases.

Additionally extend test environment to support adding artificial index
entries with signature and completion snippet suffix.

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

Added: 


Modified: 
clang-tools-extra/clangd/CodeComplete.cpp
clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp

Removed: 




diff  --git a/clang-tools-extra/clangd/CodeComplete.cpp 
b/clang-tools-extra/clangd/CodeComplete.cpp
index 70f2634aa7763e..68e12b2fb00167 100644
--- a/clang-tools-extra/clangd/CodeComplete.cpp
+++ b/clang-tools-extra/clangd/CodeComplete.cpp
@@ -316,6 +316,15 @@ struct ScoredBundleGreater {
   }
 };
 
+// Remove the first template argument from Signature.
+// If Signature only contains a single argument an empty string is returned.
+std::string removeFirstTemplateArg(llvm::StringRef Signature) {
+  auto Rest = Signature.split(",").second;
+  if (Rest.empty())
+return "";
+  return ("<" + Rest.ltrim()).str();
+}
+
 // Assembles a code completion out of a bundle of >=1 completion candidates.
 // Many of the expensive strings are only computed at this point, once we know
 // the candidate bundle is going to be returned.
@@ -336,7 +345,7 @@ struct CodeCompletionBuilder {
 EnableFunctionArgSnippets(Opts.EnableFunctionArgSnippets),
 IsUsingDeclaration(IsUsingDeclaration), NextTokenKind(NextTokenKind) {
 Completion.Deprecated = true; // cleared by any non-deprecated overload.
-add(C, SemaCCS);
+add(C, SemaCCS, ContextKind);
 if (C.SemaResult) {
   assert(ASTCtx);
   Completion.Origin |= SymbolOrigin::AST;
@@ -443,21 +452,40 @@ struct CodeCompletionBuilder {
   });
   }
 
-  void add(const CompletionCandidate &C, CodeCompletionString *SemaCCS) {
+  void add(const CompletionCandidate &C, CodeCompletionString *SemaCCS,
+   CodeCompletionContext::Kind ContextKind) {
 assert(bool(C.SemaResult) == bool(SemaCCS));
 Bundled.emplace_back();
 BundledEntry &S = Bundled.back();
+bool IsConcept = false;
 if (C.SemaResult) {
   getSignature(*SemaCCS, &S.Signature, &S.SnippetSuffix, 
C.SemaResult->Kind,
C.SemaResult->CursorKind, &Completion.RequiredQualifier);
   if (!C.SemaResult->FunctionCanBeCall)
 S.SnippetSuffix.clear();
   S.ReturnType = getReturnType(*SemaCCS);
+  if (C.SemaResult->Kind == CodeCompletionResult::RK_Declaration)
+if (const auto *D = C.SemaResult->getDeclaration())
+  if (isa(D))
+IsConcept = true;
 } else if (C.IndexResult) {
   S.Signature = std::string(C.IndexResult->Signature);
   S.SnippetSuffix = std::string(C.IndexResult->CompletionSnippetSuffix);
   S.ReturnType = std::string(C.IndexResult->ReturnType);
+  if (C.IndexResult->SymInfo.Kind == index::SymbolKind::Concept)
+IsConcept = true;
 }
+
+/// When a concept is used as a type-constraint (e.g. `Iterator auto x`),
+/// and in some other contexts, its first type argument is not written.
+/// Drop the parameter from the signature.
+if (IsConcept && ContextKind == CodeCompletionContext::CCC_TopLevel) {
+  S.Signature = removeFirstTemplateArg(S.Signature);
+  // Dropping the first placeholder from the suffix will leave a $2
+  // with no $1.
+  S.SnippetSuffix = removeFirstTemplateArg(S.SnippetSuffix);
+}
+
 if (!Completion.Documentation) {
   auto SetDoc = [&](llvm::StringRef Doc) {
 if (!Doc.empty()) {
@@ -2020,7 +2048,7 @@ class CodeCompleteFlow {
 Item, SemaCCS, AccessibleScopes, *Inserter, FileName,
 CCContextKind, Opts, IsUsingDeclaration, 
NextTokenKind);
   else
-Builder->add(Item, SemaCCS);
+Builder->add(Item, SemaCCS, CCContextKind);
 }
 return Builder->build();
   }

diff  --git a/clang-tools-extra/clangd/unittests/CodeComplete

[clang-tools-extra] 8af9a37 - Add missing semantic highlighing for concepts.

2023-07-06 Thread Jens Massberg via cfe-commits

Author: Jens Massberg
Date: 2023-07-06T16:28:57+02:00
New Revision: 8af9a373ad95ef49e2f2aa83c021b8043f848ab9

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

LOG: Add missing semantic highlighing for concepts.

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

Added: 


Modified: 
clang-tools-extra/clangd/SemanticHighlighting.cpp
clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp

Removed: 




diff  --git a/clang-tools-extra/clangd/SemanticHighlighting.cpp 
b/clang-tools-extra/clangd/SemanticHighlighting.cpp
index f6a3f7ac66aa09..8003a3c98f0ad8 100644
--- a/clang-tools-extra/clangd/SemanticHighlighting.cpp
+++ b/clang-tools-extra/clangd/SemanticHighlighting.cpp
@@ -737,8 +737,10 @@ class CollectExtraHighlightings
   }
 
   bool VisitAutoTypeLoc(AutoTypeLoc L) {
-if (L.isConstrained())
+if (L.isConstrained()) {
   H.addAngleBracketTokens(L.getLAngleLoc(), L.getRAngleLoc());
+  H.addToken(L.getConceptNameInfo().getLoc(), HighlightingKind::Concept);
+}
 return true;
   }
 
@@ -953,13 +955,18 @@ class CollectExtraHighlightings
 kindForType(AT->getDeducedType().getTypePtrOrNull(), H.getResolver());
 if (!K)
   return true;
-SourceLocation StartLoc = D->getTypeSpecStartLoc();
+auto *TSI = D->getTypeSourceInfo();
+if (!TSI)
+  return true;
+SourceLocation StartLoc =
+TSI->getTypeLoc().getContainedAutoTypeLoc().getNameLoc();
 // The AutoType may not have a corresponding token, e.g. in the case of
 // init-captures. In this case, StartLoc overlaps with the location
 // of the decl itself, and producing a token for the type here would result
 // in both it and the token for the decl being dropped due to conflict.
 if (StartLoc == D->getLocation())
   return true;
+
 auto &Tok =
 H.addToken(StartLoc, *K).addModifier(HighlightingModifier::Deduced);
 const Type *Deduced = AT->getDeducedType().getTypePtrOrNull();

diff  --git a/clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp 
b/clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp
index ff052e6be9549c..6eee6ec30ac024 100644
--- a/clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp
+++ b/clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp
@@ -648,6 +648,15 @@ sizeof...($TemplateParameter[[Elements]]);
   void $Function_def[[bar]]($TemplateParameter[[T]] $Parameter_def[[F]]) {
 $Parameter[[F]].$Unknown_dependentName[[foo]]();
   }
+
+  struct $Class_def[[F]] {
+void $Method_def[[foo]]() {};
+  };
+  $Concept[[Fooable]] $Class_deduced[[auto]] $Variable_def[[f]] = 
$Class[[F]]();
+
+  void $Function_def[[Bar]]($Concept[[Fooable]] $TemplateParameter[[auto]] 
$Parameter_def[[x]]) {}
+
+  template$Bracket[[<]]$Concept[[Fooable]] auto 
$TemplateParameter_def_readonly[[x]]$Bracket[[>]] void $Function_def[[Boo]]() {}
 )cpp",
   // Dependent template name
   R"cpp(



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


[clang-tools-extra] 7ec9e20 - [clangd][c++20]Check for correct auto location in DeducedTypeVisitor

2023-07-10 Thread Jens Massberg via cfe-commits

Author: Jens Massberg
Date: 2023-07-10T11:33:42+02:00
New Revision: 7ec9e2048024daa2fbd02a1b64f62194326abbbd

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

LOG: [clangd][c++20]Check for correct auto location in DeducedTypeVisitor

In case of a constrained auto the correct location has to chosen.

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

Added: 


Modified: 
clang-tools-extra/clangd/AST.cpp
clang-tools-extra/clangd/unittests/HoverTests.cpp

Removed: 




diff  --git a/clang-tools-extra/clangd/AST.cpp 
b/clang-tools-extra/clangd/AST.cpp
index 17c4dbf6dbe70d..5b81ec213ff984 100644
--- a/clang-tools-extra/clangd/AST.cpp
+++ b/clang-tools-extra/clangd/AST.cpp
@@ -482,7 +482,11 @@ class DeducedTypeVisitor : public 
RecursiveASTVisitor {
   //- auto* i = &a;
   bool VisitDeclaratorDecl(DeclaratorDecl *D) {
 if (!D->getTypeSourceInfo() ||
-D->getTypeSourceInfo()->getTypeLoc().getBeginLoc() != SearchedLocation)
+!D->getTypeSourceInfo()->getTypeLoc().getContainedAutoTypeLoc() ||
+D->getTypeSourceInfo()
+->getTypeLoc()
+.getContainedAutoTypeLoc()
+.getNameLoc() != SearchedLocation)
   return true;
 
 if (auto *AT = D->getType()->getContainedAutoType()) {

diff  --git a/clang-tools-extra/clangd/unittests/HoverTests.cpp 
b/clang-tools-extra/clangd/unittests/HoverTests.cpp
index 0f45e7851bc87e..91060a517de530 100644
--- a/clang-tools-extra/clangd/unittests/HoverTests.cpp
+++ b/clang-tools-extra/clangd/unittests/HoverTests.cpp
@@ -477,6 +477,16 @@ class Foo final {})cpp";
  HI.Kind = index::SymbolKind::TypeAlias;
  HI.Definition = "/* not deduced */";
}},
+  // constrained auto
+  {R"cpp(
+template  concept F = true;
+F [[au^to]] x = 1;
+)cpp",
+   [](HoverInfo &HI) {
+ HI.Name = "auto";
+ HI.Kind = index::SymbolKind::TypeAlias;
+ HI.Definition = "int";
+   }},
   // auto on lambda
   {R"cpp(
 void foo() {
@@ -1314,7 +1324,7 @@ class Foo final {})cpp";
 
 Annotations T(Case.Code);
 TestTU TU = TestTU::withCode(T.code());
-TU.ExtraArgs.push_back("-std=c++17");
+TU.ExtraArgs.push_back("-std=c++20");
 // Types might be 
diff erent depending on the target triplet, we chose a
 // fixed one to make sure tests passes on 
diff erent platform.
 TU.ExtraArgs.push_back("--target=x86_64-pc-linux-gnu");



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


[clang] c2bf9ba - Add a concept AST node.

2023-08-31 Thread Jens Massberg via cfe-commits

Author: Jens Massberg
Date: 2023-08-31T10:22:21+02:00
New Revision: c2bf9baf59870532d0c503066634bf438c35184f

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

LOG: Add a concept AST node.

This patch adds a concept AST node (`ConceptLoc`) and uses it at the 
corresponding places.

There are three objects that might have constraints via concepts:
`TypeConstraint`,  `ConceptSpecializationExpr` and `AutoTypeLoc`.
The first two inherit from `ConceptReference` while the latter has
the information about a possible constraint directly stored in 
`AutoTypeLocInfo`. It would be nice if the concept information would be stored 
the same way in all three cases.

Moreover the current structure makes it difficult to deal with these concepts. 
For example in Clangd accessing the locations of constraints of a `AutoTypeLoc` 
can only be done with quite ugly hacks.

So we think that it makes sense to create a new AST node for such concepts.

In details we propose the following:
- Rename `ConceptReference` to `ConceptLoc` (or something else what is 
approriate)
and make it the new AST node.
- `TypeConstraint` and `ConceptSpecializationExpr` do not longer inherit from 
`ConceptReference` but store a pointer to a `ConceptLoc`.
- `AutoTypeLoc` stores a pointer to `ConceptLoc` instead of storing the concept 
info in `AutoTypeLocInfo`.

This patch implements a first version of this idea which compiles and where the 
existing tests pass.
To make this patch as small as possible we keep the existing member functions 
to access concept data. Later these can be replaced by directly calling the 
corresponding functions of the `ConceptLoc`s.

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

Added: 


Modified: 
clang/include/clang/AST/ASTConcept.h
clang/include/clang/AST/DeclTemplate.h
clang/include/clang/AST/ExprConcepts.h
clang/include/clang/AST/RecursiveASTVisitor.h
clang/include/clang/AST/TypeLoc.h
clang/include/clang/Serialization/ASTRecordReader.h
clang/include/clang/Serialization/ASTRecordWriter.h
clang/lib/AST/ASTContext.cpp
clang/lib/AST/ASTImporter.cpp
clang/lib/AST/DeclTemplate.cpp
clang/lib/AST/ExprConcepts.cpp
clang/lib/AST/TypeLoc.cpp
clang/lib/Sema/SemaTemplate.cpp
clang/lib/Sema/SemaTemplateInstantiate.cpp
clang/lib/Sema/SemaType.cpp
clang/lib/Sema/TreeTransform.h
clang/lib/Serialization/ASTReader.cpp
clang/lib/Serialization/ASTReaderDecl.cpp
clang/lib/Serialization/ASTReaderStmt.cpp
clang/lib/Serialization/ASTWriter.cpp
clang/lib/Serialization/ASTWriterDecl.cpp
clang/lib/Serialization/ASTWriterStmt.cpp
clang/unittests/AST/SourceLocationTest.cpp
clang/unittests/Tooling/RecursiveASTVisitorTests/Concept.cpp

Removed: 




diff  --git a/clang/include/clang/AST/ASTConcept.h 
b/clang/include/clang/AST/ASTConcept.h
index e6e2d57597ea02..832918785434d4 100644
--- a/clang/include/clang/AST/ASTConcept.h
+++ b/clang/include/clang/AST/ASTConcept.h
@@ -14,7 +14,9 @@
 #ifndef LLVM_CLANG_AST_ASTCONCEPT_H
 #define LLVM_CLANG_AST_ASTCONCEPT_H
 
+#include "clang/AST/Decl.h"
 #include "clang/AST/Expr.h"
+#include "clang/AST/PrettyPrinter.h"
 #include "clang/Basic/SourceLocation.h"
 #include "llvm/ADT/PointerUnion.h"
 #include "llvm/ADT/SmallVector.h"
@@ -107,10 +109,18 @@ struct ASTConstraintSatisfaction final :
   Rebuild(const ASTContext &C, const ASTConstraintSatisfaction &Satisfaction);
 };
 
-/// \brief Common data class for constructs that reference concepts with
-/// template arguments.
+/// A reference to a concept and its template args, as it appears in the code.
+///
+/// Examples:
+///   template  requires is_even int half = X/2;
+/// ~~ (in ConceptSpecializationExpr)
+///
+///   std::input_iterator auto I = Container.begin();
+///   ~~~ (in AutoTypeLoc)
+///
+///   template  T> void dump();
+/// ~~~ (in TemplateTypeParmDecl)
 class ConceptReference {
-protected:
   // \brief The optional nested name specifier used when naming the concept.
   NestedNameSpecifierLoc NestedNameSpec;
 
@@ -134,7 +144,6 @@ class ConceptReference {
   /// concept.
   const ASTTemplateArgumentListInfo *ArgsAsWritten;
 
-public:
   ConceptReference(NestedNameSpecifierLoc NNS, SourceLocation TemplateKWLoc,
DeclarationNameInfo ConceptNameInfo, NamedDecl *FoundDecl,
ConceptDecl *NamedConcept,
@@ -143,8 +152,15 @@ class ConceptReference {
 ConceptName(ConceptNameInfo), FoundDecl(FoundDecl),
 NamedConcept(NamedConcept), ArgsAsWritten(ArgsAsWritten) {}
 
-  ConceptReference()
-  : FoundDecl(nullptr), NamedConcept(nullptr), ArgsAsWritten(nullptr) {}
+public:
+  static ConceptReference *
+  

[clang-tools-extra] c39dcd2 - [c++20][clangd] Simplify code using the new `ConceptReference` nodes.

2023-08-31 Thread Jens Massberg via cfe-commits

Author: Jens Massberg
Date: 2023-08-31T13:53:56+02:00
New Revision: c39dcd2c2bc7fd142ac8305b3a41f24e1addbd8c

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

LOG: [c++20][clangd] Simplify code using the new `ConceptReference` nodes.

Directly traverse `ConceptReference`s in FindTarget.cpp.

There is no need for the extra logic for `AutoTypeLoc`s in 
SemanticHightlighting.cpp as the concept information is stored in a 
`ConceptReference` which is now traversed.

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

Added: 


Modified: 
clang-tools-extra/clangd/FindTarget.cpp
clang-tools-extra/clangd/SemanticHighlighting.cpp

Removed: 




diff  --git a/clang-tools-extra/clangd/FindTarget.cpp 
b/clang-tools-extra/clangd/FindTarget.cpp
index 630b75059b6baf..c1ec030275c4f6 100644
--- a/clang-tools-extra/clangd/FindTarget.cpp
+++ b/clang-tools-extra/clangd/FindTarget.cpp
@@ -742,13 +742,6 @@ llvm::SmallVector refInStmt(const Stmt *S,
 // FIXME: handle more complicated cases: more ObjC, designated 
initializers.
 llvm::SmallVector Refs;
 
-void VisitConceptSpecializationExpr(const ConceptSpecializationExpr *E) {
-  Refs.push_back(ReferenceLoc{E->getNestedNameSpecifierLoc(),
-  E->getConceptNameLoc(),
-  /*IsDecl=*/false,
-  {E->getNamedConcept()}});
-}
-
 void VisitDeclRefExpr(const DeclRefExpr *E) {
   Refs.push_back(ReferenceLoc{E->getQualifierLoc(),
   E->getNameInfo().getLoc(),
@@ -1063,15 +1056,12 @@ class ExplicitReferenceCollector
 return RecursiveASTVisitor::TraverseConstructorInitializer(Init);
   }
 
-  bool TraverseTypeConstraint(const TypeConstraint *TC) {
-// We want to handle all ConceptReferences but RAV is missing a
-// polymorphic Visit or Traverse method for it, so we handle
-// TypeConstraints specially here.
-Out(ReferenceLoc{TC->getNestedNameSpecifierLoc(),
- TC->getConceptNameLoc(),
+  bool VisitConceptReference(ConceptReference *ConceptRef) {
+Out(ReferenceLoc{ConceptRef->getNestedNameSpecifierLoc(),
+ ConceptRef->getConceptNameLoc(),
  /*IsDecl=*/false,
- {TC->getNamedConcept()}});
-return RecursiveASTVisitor::TraverseTypeConstraint(TC);
+ {ConceptRef->getNamedConcept()}});
+return true;
   }
 
 private:

diff  --git a/clang-tools-extra/clangd/SemanticHighlighting.cpp 
b/clang-tools-extra/clangd/SemanticHighlighting.cpp
index 8003a3c98f0ad8..45c01634e2e38d 100644
--- a/clang-tools-extra/clangd/SemanticHighlighting.cpp
+++ b/clang-tools-extra/clangd/SemanticHighlighting.cpp
@@ -736,14 +736,6 @@ class CollectExtraHighlightings
 return true;
   }
 
-  bool VisitAutoTypeLoc(AutoTypeLoc L) {
-if (L.isConstrained()) {
-  H.addAngleBracketTokens(L.getLAngleLoc(), L.getRAngleLoc());
-  H.addToken(L.getConceptNameInfo().getLoc(), HighlightingKind::Concept);
-}
-return true;
-  }
-
   bool VisitFunctionDecl(FunctionDecl *D) {
 if (D->isOverloadedOperator()) {
   const auto AddOpDeclToken = [&](SourceLocation Loc) {



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


[clang] 6d2e756 - Initialize `ConceptReference` of new `AutoTypeLoc` with nullptr.

2023-09-05 Thread Jens Massberg via cfe-commits

Author: Jens Massberg
Date: 2023-09-05T18:17:44+02:00
New Revision: 6d2e756dacfd9276775a06bdd1fea4eccace5e0f

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

LOG: Initialize `ConceptReference` of new `AutoTypeLoc` with nullptr.

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

Added: 


Modified: 
clang/lib/Sema/TreeTransform.h

Removed: 




diff  --git a/clang/lib/Sema/TreeTransform.h b/clang/lib/Sema/TreeTransform.h
index cfcd19e57cf169..7323140bc336bc 100644
--- a/clang/lib/Sema/TreeTransform.h
+++ b/clang/lib/Sema/TreeTransform.h
@@ -6860,6 +6860,7 @@ QualType 
TreeTransform::TransformAutoType(TypeLocBuilder &TLB,
   AutoTypeLoc NewTL = TLB.push(Result);
   NewTL.setNameLoc(TL.getNameLoc());
   NewTL.setRParenLoc(TL.getRParenLoc());
+  NewTL.setConceptReference(nullptr);
 
   if (T->isConstrained()) {
 DeclarationNameInfo DNI = DeclarationNameInfo(



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


[clang] 849b650 - [clang] Skip defaulted functions in zero-as-null-pointer-constant.

2022-11-29 Thread Jens Massberg via cfe-commits

Author: Jens Massberg
Date: 2022-11-29T11:56:10+01:00
New Revision: 849b650cf3b60e60f5e3a6457fe52e9c63e76e4c

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

LOG: [clang] Skip defaulted functions in zero-as-null-pointer-constant.

The zero-as-null-pointer-constant check should not fire if it is inside
a defaulted function, e.g. defaulted spaceship operators.
Add C++20 tests with spaceship operators.

Fixes #50221

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

Added: 
clang/test/SemaCXX/warn-zero-nullptr-cxx20.cpp

Modified: 
clang/lib/Sema/Sema.cpp

Removed: 




diff  --git a/clang/lib/Sema/Sema.cpp b/clang/lib/Sema/Sema.cpp
index c229a77ff0b8d..ad53e874e9d32 100644
--- a/clang/lib/Sema/Sema.cpp
+++ b/clang/lib/Sema/Sema.cpp
@@ -597,6 +597,12 @@ void Sema::diagnoseZeroToNullptrConversion(CastKind Kind, 
const Expr *E) {
   CodeSynthesisContext::RewritingOperatorAsSpaceship)
 return;
 
+  // Ignore null pointers in defaulted comparison operators.
+  FunctionDecl *FD = getCurFunctionDecl();
+  if (FD && FD->isDefaulted()) {
+return;
+  }
+
   // If it is a macro from system header, and if the macro name is not "NULL",
   // do not warn.
   SourceLocation MaybeMacroLoc = E->getBeginLoc();

diff  --git a/clang/test/SemaCXX/warn-zero-nullptr-cxx20.cpp 
b/clang/test/SemaCXX/warn-zero-nullptr-cxx20.cpp
new file mode 100644
index 0..32b259d00aee2
--- /dev/null
+++ b/clang/test/SemaCXX/warn-zero-nullptr-cxx20.cpp
@@ -0,0 +1,51 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s -Wzero-as-null-pointer-constant 
-std=c++20
+
+namespace std {
+class strong_ordering;
+
+// Mock how STD defined unspecified parameters for the operators below.
+struct _CmpUnspecifiedParam {
+  consteval
+  _CmpUnspecifiedParam(int _CmpUnspecifiedParam::*) noexcept {}
+};
+
+struct strong_ordering {
+  signed char value;
+
+  friend constexpr bool operator==(strong_ordering v,
+   _CmpUnspecifiedParam) noexcept {
+return v.value == 0;
+  }
+  friend constexpr bool operator<(strong_ordering v,
+  _CmpUnspecifiedParam) noexcept {
+return v.value < 0;
+  }
+  friend constexpr bool operator>(strong_ordering v,
+  _CmpUnspecifiedParam) noexcept {
+return v.value > 0;
+  }
+  friend constexpr bool operator>=(strong_ordering v,
+   _CmpUnspecifiedParam) noexcept {
+return v.value >= 0;
+  }
+  static const strong_ordering equal, greater, less;
+};
+constexpr strong_ordering strong_ordering::equal = {0};
+constexpr strong_ordering strong_ordering::greater = {1};
+constexpr strong_ordering strong_ordering::less = {-1};
+} // namespace std
+
+struct A {
+  int a;
+  constexpr auto operator<=>(const A &other) const = default;
+};
+
+void test_cxx_rewritten_binary_ops() {
+  A a1, a2;
+  bool result;
+  result = (a1 < a2);
+  result = (a1 >= a2);
+  int *ptr = 0; // expected-warning{{zero as null pointer constant}}
+  result = (a1 > (ptr == 0 ? a1 : a2)); // expected-warning{{zero as null 
pointer constant}}
+  result = (a1 > ((a1 > (ptr == 0 ? a1 : a2)) ? a1 : a2)); // 
expected-warning{{zero as null pointer constant}}
+}



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


[clang-tools-extra] 6f065bf - [clangd][c++20]Consider rewritten binary operators in TargetFinder

2023-06-26 Thread Jens Massberg via cfe-commits

Author: Jens Massberg
Date: 2023-06-26T11:26:10+02:00
New Revision: 6f065bfd633d7ca006f62b894108d5369dc46836

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

LOG: [clangd][c++20]Consider rewritten binary operators in TargetFinder

In C++20 some binary operations can be rewritten, e.g. `a != b`
can be rewritten to `!(a == b)` if `!=` is not explicitly defined.
The `TargetFinder` hasn't considered the corresponding 
`CXXRewrittenBinaryOperator` yet. This resulted that the definition of such 
operators couldn't be found
when navigating to such a `!=` operator, see 
https://github.com/clangd/clangd/issues/1476.

In this patch we add support of `CXXRewrittenBinaryOperator` in `FindTarget`.
In such a case we redirect to the inner binary operator of the decomposed form.
E.g. in case that `a != b` has been rewritten to `!(a == b)` we go to the
`==` operator. The `==` operator might be implicitly defined (e.g. by a `<=>`
operator), but this case is already handled, see the new test.

I'm not sure if I the hover test which is added in this patch is the right one,
but at least is passed with this patch and fails without it :)

Note, that it might be a bit missleading that hovering over a `!=` refers to
"instance method operator==".

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

Added: 


Modified: 
clang-tools-extra/clangd/FindTarget.cpp
clang-tools-extra/clangd/unittests/FindTargetTests.cpp
clang-tools-extra/clangd/unittests/HoverTests.cpp

Removed: 




diff  --git a/clang-tools-extra/clangd/FindTarget.cpp 
b/clang-tools-extra/clangd/FindTarget.cpp
index efbd05e2b74d3..eead9e6a3a7a4 100644
--- a/clang-tools-extra/clangd/FindTarget.cpp
+++ b/clang-tools-extra/clangd/FindTarget.cpp
@@ -347,6 +347,10 @@ struct TargetFinder {
   void VisitCXXDeleteExpr(const CXXDeleteExpr *CDE) {
 Outer.add(CDE->getOperatorDelete(), Flags);
   }
+  void
+  VisitCXXRewrittenBinaryOperator(const CXXRewrittenBinaryOperator *RBO) {
+Outer.add(RBO->getDecomposedForm().InnerBinOp, Flags);
+  }
 };
 Visitor(*this, Flags).Visit(S);
   }

diff  --git a/clang-tools-extra/clangd/unittests/FindTargetTests.cpp 
b/clang-tools-extra/clangd/unittests/FindTargetTests.cpp
index 81e891b2db01e..9979628941bfe 100644
--- a/clang-tools-extra/clangd/unittests/FindTargetTests.cpp
+++ b/clang-tools-extra/clangd/unittests/FindTargetTests.cpp
@@ -618,6 +618,36 @@ TEST_F(TargetDeclTest, Coroutine) {
   EXPECT_DECLS("RecordTypeLoc", "struct executor");
 }
 
+TEST_F(TargetDeclTest, RewrittenBinaryOperator) {
+  Flags.push_back("-std=c++20");
+
+  Code = R"cpp(
+  namespace std {
+struct strong_ordering {
+  int n;
+  constexpr operator int() const { return n; }
+  static const strong_ordering equal, greater, less;
+};
+constexpr strong_ordering strong_ordering::equal = {0};
+constexpr strong_ordering strong_ordering::greater = {1};
+constexpr strong_ordering strong_ordering::less = {-1};
+}
+
+struct Foo
+{
+  int x;
+  auto operator<=>(const Foo&) const = default;
+};
+
+bool x = (Foo(1) [[!=]] Foo(2));
+  )cpp";
+  EXPECT_DECLS("CXXRewrittenBinaryOperator",
+   {"std::strong_ordering operator<=>(const Foo &) const = 
default",
+Rel::TemplatePattern},
+   {"bool operator==(const Foo &) const noexcept = default",
+Rel::TemplateInstantiation});
+}
+
 TEST_F(TargetDeclTest, FunctionTemplate) {
   Code = R"cpp(
 // Implicit specialization.

diff  --git a/clang-tools-extra/clangd/unittests/HoverTests.cpp 
b/clang-tools-extra/clangd/unittests/HoverTests.cpp
index 5338a680b787a..7002e27e9938f 100644
--- a/clang-tools-extra/clangd/unittests/HoverTests.cpp
+++ b/clang-tools-extra/clangd/unittests/HoverTests.cpp
@@ -2927,6 +2927,41 @@ TEST(Hover, All) {
  HI.Definition = "__attribute__((nonnull))";
  HI.Documentation = Attr::getDocumentation(attr::NonNull).str();
}},
+  {
+  R"cpp(
+  namespace std {
+  struct strong_ordering {
+int n;
+constexpr operator int() const { return n; }
+static const strong_ordering equal, greater, less;
+  };
+  constexpr strong_ordering strong_ordering::equal = {0};
+  constexpr strong_ordering strong_ordering::greater = {1};
+  constexpr strong_ordering strong_ordering::less = {-1};
+  }
+
+  struct Foo
+  {
+int x;
+// Foo spaceship
+auto operator<=>(const Foo&) const = default;
+  };
+
+  bool x = Foo(1) [[!^=]] Foo(2);
+ )cpp",
+  [](HoverInfo &HI) {
+HI.Type = "bool (const Foo &) const noexcept";
+HI

[clang] c3c0774 - [Clang][C++20] Error out if parameter types of a defaulted comparion operator are not all the same.

2023-05-24 Thread Jens Massberg via cfe-commits

Author: Jens Massberg
Date: 2023-05-24T10:02:58+02:00
New Revision: c3c0774b1d6ef524de3a25e1f13828d2f9861aad

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

LOG: [Clang][C++20] Error out if parameter types of a defaulted comparion 
operator are not all the same.

This fixes #62880

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

Added: 


Modified: 
clang/lib/Sema/SemaDeclCXX.cpp
clang/test/CXX/class/class.compare/class.compare.default/p1.cpp

Removed: 




diff  --git a/clang/lib/Sema/SemaDeclCXX.cpp b/clang/lib/Sema/SemaDeclCXX.cpp
index e2a1de9ee5be2..cbe4229b05d00 100644
--- a/clang/lib/Sema/SemaDeclCXX.cpp
+++ b/clang/lib/Sema/SemaDeclCXX.cpp
@@ -8626,8 +8626,7 @@ bool Sema::CheckExplicitlyDefaultedComparison(Scope *S, 
FunctionDecl *FD,
   const ParmVarDecl *KnownParm = nullptr;
   for (const ParmVarDecl *Param : FD->parameters()) {
 QualType ParmTy = Param->getType();
-if (ParmTy->isDependentType())
-  continue;
+
 if (!KnownParm) {
   auto CTy = ParmTy;
   // Is it `T const &`?

diff  --git a/clang/test/CXX/class/class.compare/class.compare.default/p1.cpp 
b/clang/test/CXX/class/class.compare/class.compare.default/p1.cpp
index eadb5718780a3..e469e31e1f696 100644
--- a/clang/test/CXX/class/class.compare/class.compare.default/p1.cpp
+++ b/clang/test/CXX/class/class.compare/class.compare.default/p1.cpp
@@ -27,6 +27,16 @@ struct A {
 bool operator==(const A&) const = default; // expected-error {{comparison 
operator template cannot be defaulted}}
 };
 
+template struct D {
+  C i;
+  friend bool operator==(const D&, D) = default; // expected-error {{must have 
the same type}}
+  friend bool operator>(D, const D&) = default; // expected-error {{must have 
the same type}}
+  friend bool operator<(const D&, const D&) = default;
+  friend bool operator<=(D, D) = default;
+
+  bool operator!=(D) const = default; // expected-error {{invalid parameter 
type for defaulted equality comparison operator}}
+};
+
 template struct Dependent {
   using U = typename T::type;
   bool operator==(U) const = default; // expected-error {{found 'U'}}



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


cfe-commits@lists.llvm.org

2023-06-07 Thread Jens Massberg via cfe-commits

Author: Jens Massberg
Date: 2023-06-07T12:56:35+02:00
New Revision: 593a2740f7a499e35f19e64d180d0b8246b52ba3

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

LOG: [clang] Show error if defaulted comparions operator function is volatile 
or has ref-qualifier &&.

This patch implemed the change proposed in [P2002R1] to 11.11.1 
[class.compare.default] paragraph 1.

A defaulted compariosn operator function must be non-volatile and must either 
have no ref-qualifier or the ref-qualifier &.

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

Added: 


Modified: 
clang/docs/ReleaseNotes.rst
clang/include/clang/Basic/DiagnosticSemaKinds.td
clang/lib/Sema/SemaDeclCXX.cpp
clang/test/CXX/class/class.compare/class.compare.default/p1.cpp
clang/test/CodeGenCXX/virtual-compare.cpp
clang/www/cxx_status.html

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 7ec9b3911ad5d..733a003f5321b 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -110,6 +110,7 @@ C++20 Feature Support
   unevaluated contexts will be surfaced as errors. They were previously 
handled as
   SFINAE.
 - Clang now supports `requires cplusplus20` for module maps.
+- Implemented missing parts of `P2002R1: Consistent comparison operators 
`_
 
 C++23 Feature Support
 ^

diff  --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 5895888c175fa..e03e27d196731 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -9462,6 +9462,10 @@ def note_defaulted_comparison_not_constexpr_here : Note<
 def note_in_declaration_of_implicit_equality_comparison : Note<
   "while declaring the corresponding implicit 'operator==' "
   "for this defaulted 'operator<=>'">;
+def err_volatile_comparison_operator : Error<
+  "defaulted comparison function must not be volatile">;
+def err_ref_qualifier_comparison_operator : Error<
+  "ref-qualifier '&&' is not allowed on a defaulted comparison operator">;
 
 def ext_implicit_exception_spec_mismatch : ExtWarn<
   "function previously declared with an %select{explicit|implicit}0 exception "

diff  --git a/clang/lib/Sema/SemaDeclCXX.cpp b/clang/lib/Sema/SemaDeclCXX.cpp
index 3169b381071bb..9b3bcc296ddb7 100644
--- a/clang/lib/Sema/SemaDeclCXX.cpp
+++ b/clang/lib/Sema/SemaDeclCXX.cpp
@@ -8582,8 +8582,8 @@ bool Sema::CheckExplicitlyDefaultedComparison(Scope *S, 
FunctionDecl *FD,
   // C++2a [class.compare.default]p1:
   //   A defaulted comparison operator function for some class C shall be a
   //   non-template function declared in the member-specification of C that is
-  //-- a non-static const member of C having one parameter of type
-  //   const C&, or
+  //-- a non-static const non-volatile member of C having one parameter of
+  //   type const C& and either no ref-qualifier or the ref-qualifier &, or
   //-- a friend of C having two parameters of type const C& or two
   //   parameters of type C.
 
@@ -8593,6 +8593,17 @@ bool Sema::CheckExplicitlyDefaultedComparison(Scope *S, 
FunctionDecl *FD,
 auto *MD = cast(FD);
 assert(!MD->isStatic() && "comparison function cannot be a static member");
 
+if (MD->getRefQualifier() == RQ_RValue) {
+  Diag(MD->getLocation(), diag::err_ref_qualifier_comparison_operator);
+
+  // Remove the ref qualifier to recover.
+  const auto *FPT = MD->getType()->castAs();
+  FunctionProtoType::ExtProtoInfo EPI = FPT->getExtProtoInfo();
+  EPI.RefQualifier = RQ_None;
+  MD->setType(Context.getFunctionType(FPT->getReturnType(),
+  FPT->getParamTypes(), EPI));
+}
+
 // If we're out-of-class, this is the class we're comparing.
 if (!RD)
   RD = MD->getParent();
@@ -8615,6 +8626,17 @@ bool Sema::CheckExplicitlyDefaultedComparison(Scope *S, 
FunctionDecl *FD,
   MD->setType(Context.getFunctionType(FPT->getReturnType(),
   FPT->getParamTypes(), EPI));
 }
+
+if (MD->isVolatile()) {
+  Diag(MD->getLocation(), diag::err_volatile_comparison_operator);
+
+  // Remove the 'volatile' from the type to recover.
+  const auto *FPT = MD->getType()->castAs();
+  FunctionProtoType::ExtProtoInfo EPI = FPT->getExtProtoInfo();
+  EPI.TypeQuals.removeVolatile();
+  MD->setType(Context.getFunctionType(FPT->getReturnType(),
+  FPT->getParamTypes(), EPI));
+}
   }
 
   if (FD->getNumParams() != (IsMethod ? 1 : 2)) {

diff  --git a/clang/test/CXX/class/class.compare/class.compare.default/p1.cpp 
b/clang/test/

[clang] 0a7ca80 - Fix parameter name in Sema::addInitCapture to ByRef.

2023-06-07 Thread Jens Massberg via cfe-commits

Author: Jens Massberg
Date: 2023-06-07T18:06:19+02:00
New Revision: 0a7ca80360584ff35cb58716e08855a913a3f4d0

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

LOG: Fix parameter name in Sema::addInitCapture to ByRef.

Rename parameter in Sema::addInitCapture as proposed in review of 
Sema::addInitCapture. Sorry, that I have missed the comment there!

Reviewed By: ilya-biryukov

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

Added: 


Modified: 
clang/include/clang/Sema/Sema.h
clang/lib/Sema/SemaLambda.cpp

Removed: 




diff  --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index cf25f39de0d19..a15846952fd01 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -7171,8 +7171,7 @@ class Sema final {
   IdentifierInfo *Id, unsigned InitStyle, Expr *Init, DeclContext 
*DeclCtx);
 
   /// Add an init-capture to a lambda scope.
-  void addInitCapture(sema::LambdaScopeInfo *LSI, VarDecl *Var,
-  bool isReferenceType);
+  void addInitCapture(sema::LambdaScopeInfo *LSI, VarDecl *Var, bool ByRef);
 
   /// Note that we have finished the explicit captures for the
   /// given lambda.

diff  --git a/clang/lib/Sema/SemaLambda.cpp b/clang/lib/Sema/SemaLambda.cpp
index 730f70e732579..c1d70ad8b08f9 100644
--- a/clang/lib/Sema/SemaLambda.cpp
+++ b/clang/lib/Sema/SemaLambda.cpp
@@ -798,12 +798,11 @@ VarDecl *Sema::createLambdaInitCaptureVarDecl(
   return NewVD;
 }
 
-void Sema::addInitCapture(LambdaScopeInfo *LSI, VarDecl *Var,
-  bool isReferenceType) {
+void Sema::addInitCapture(LambdaScopeInfo *LSI, VarDecl *Var, bool ByRef) {
   assert(Var->isInitCapture() && "init capture flag should be set");
-  LSI->addCapture(Var, /*isBlock*/ false, isReferenceType,
-  /*isNested*/ false, Var->getLocation(), SourceLocation(),
-  Var->getType(), /*Invalid*/ false);
+  LSI->addCapture(Var, /*isBlock=*/false, ByRef,
+  /*isNested=*/false, Var->getLocation(), SourceLocation(),
+  Var->getType(), /*Invalid=*/false);
 }
 
 // Unlike getCurLambda, getCurrentLambdaScopeUnsafe doesn't



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


[clang] edbea62 - [clang] Correctly handle by-reference capture with an initializer that is a pack expansion in lambdas.

2022-12-07 Thread Jens Massberg via cfe-commits

Author: Jens Massberg
Date: 2022-12-07T16:00:58+01:00
New Revision: edbea62f72f7b9a5ee19c709d675d6083789c71f

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

LOG: [clang] Correctly handle by-reference capture with an initializer that is 
a pack expansion in lambdas.

Ensure that the correct information whether an init-capture of a lambda
is passed by reference or by copy. This information is already computed
and has to be passed to the place where `NewInitCaptureType` is
created.

Before this fix it has been checked whether the VarDecl is a reference
type. This doesn't work for packed expansions, as the information
whether it is passed by reference or by copy is stored at the pattern of
a `PackExpansionType` and not at the type itself.

However, as the information has been already computed, we just have to
pass it.

Add tests that lambda captures with var decls which are reference types
are created in the AST and a disgnotics test for pack expansions.

Fixes #49266

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

Added: 
clang/test/SemaCXX/lambda-pack-expansion.cpp

Modified: 
clang/include/clang/Sema/Sema.h
clang/lib/Sema/SemaLambda.cpp
clang/lib/Sema/TreeTransform.h
clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp

Removed: 




diff  --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index 984de6307ec6..d699ef527e3b 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -7097,7 +7097,8 @@ class Sema final {
   unsigned InitStyle, Expr *Init);
 
   /// Add an init-capture to a lambda scope.
-  void addInitCapture(sema::LambdaScopeInfo *LSI, VarDecl *Var);
+  void addInitCapture(sema::LambdaScopeInfo *LSI, VarDecl *Var,
+  bool isReferenceType);
 
   /// Note that we have finished the explicit captures for the
   /// given lambda.

diff  --git a/clang/lib/Sema/SemaLambda.cpp b/clang/lib/Sema/SemaLambda.cpp
index 176b9c6a432c..bdca002e740e 100644
--- a/clang/lib/Sema/SemaLambda.cpp
+++ b/clang/lib/Sema/SemaLambda.cpp
@@ -887,11 +887,12 @@ VarDecl 
*Sema::createLambdaInitCaptureVarDecl(SourceLocation Loc,
   return NewVD;
 }
 
-void Sema::addInitCapture(LambdaScopeInfo *LSI, VarDecl *Var) {
+void Sema::addInitCapture(LambdaScopeInfo *LSI, VarDecl *Var,
+  bool isReferenceType) {
   assert(Var->isInitCapture() && "init capture flag should be set");
-  LSI->addCapture(Var, /*isBlock*/false, Var->getType()->isReferenceType(),
-  /*isNested*/false, Var->getLocation(), SourceLocation(),
-  Var->getType(), /*Invalid*/false);
+  LSI->addCapture(Var, /*isBlock*/ false, isReferenceType,
+  /*isNested*/ false, Var->getLocation(), SourceLocation(),
+  Var->getType(), /*Invalid*/ false);
 }
 
 void Sema::ActOnStartOfLambdaDefinition(LambdaIntroducer &Intro,
@@ -1261,7 +1262,7 @@ void Sema::ActOnStartOfLambdaDefinition(LambdaIntroducer 
&Intro,
 }
 
 if (C->Init.isUsable()) {
-  addInitCapture(LSI, cast(Var));
+  addInitCapture(LSI, cast(Var), C->Kind == LCK_ByRef);
 } else {
   TryCaptureKind Kind = C->Kind == LCK_ByRef ? TryCapture_ExplicitByRef :
TryCapture_ExplicitByVal;

diff  --git a/clang/lib/Sema/TreeTransform.h b/clang/lib/Sema/TreeTransform.h
index 4fa91a69661b..c60c7311bbda 100644
--- a/clang/lib/Sema/TreeTransform.h
+++ b/clang/lib/Sema/TreeTransform.h
@@ -13149,7 +13149,7 @@ TreeTransform::TransformLambdaExpr(LambdaExpr 
*E) {
 
   QualType NewInitCaptureType =
   getSema().buildLambdaInitCaptureInitialization(
-  C->getLocation(), OldVD->getType()->isReferenceType(),
+  C->getLocation(), C->getCaptureKind() == LCK_ByRef,
   EllipsisLoc, NumExpansions, OldVD->getIdentifier(),
   cast(C->getCapturedVar())->getInitStyle() !=
   VarDecl::CInit,
@@ -13331,7 +13331,7 @@ TreeTransform::TransformLambdaExpr(LambdaExpr 
*E) {
   break;
 }
 NewVDs.push_back(NewVD);
-getSema().addInitCapture(LSI, NewVD);
+getSema().addInitCapture(LSI, NewVD, C->getCaptureKind() == LCK_ByRef);
   }
 
   if (Invalid)

diff  --git a/clang/test/SemaCXX/lambda-pack-expansion.cpp 
b/clang/test/SemaCXX/lambda-pack-expansion.cpp
new file mode 100644
index ..e3e968e2704e
--- /dev/null
+++ b/clang/test/SemaCXX/lambda-pack-expansion.cpp
@@ -0,0 +1,22 @@
+// RUN: %clang_cc1 -std=c++20 -Wno-unused-value -fsyntax-only -verify %s
+
+namespace GH49266 {
+struct X {
+  X() = default;
+  X(X const&) = delete; // expected-note {{'X' has been explicitly marked 
deleted here}}
+};
+
+void take_by

Re: [PATCH] D24075: [include-fixer] Support finding headers for the symbol under cursor.

2016-09-07 Thread Jens Massberg via cfe-commits
massberg added a comment.

Added two comments. It took some time for me to recall Emacs Lisps ;)



Comment at: include-fixer/tool/clang-include-fixer.el:48
@@ +47,3 @@
+  :group 'clang-include-fixer
+  :type 'bool
+  :risky t)

Please use 'boolean here


Comment at: include-fixer/tool/clang-include-fixer.el:204
@@ -197,3 +203,3 @@
   (message (concat "Calling the include fixer. "
"This might take some seconds. Please wait."))
 

Is this message still accurate when using the new query mode?


https://reviews.llvm.org/D24075



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


Re: [PATCH] D24075: [include-fixer] Support finding headers for the symbol under cursor.

2016-09-07 Thread Jens Massberg via cfe-commits
massberg added a comment.

The Emacs part looks good for me now.



Comment at: include-fixer/tool/clang-include-fixer.el:204
@@ -197,3 +203,3 @@
   (message (concat "Calling the include fixer. "
"This might take some seconds. Please wait."))
 

Then it fine for me, too.


https://reviews.llvm.org/D24075



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


[PATCH] D25658: Load clang-include-fixer.el from the unit test suite so that the unit tests can run in batch mode

2016-10-25 Thread Jens Massberg via cfe-commits
massberg accepted this revision.
massberg added a comment.
This revision is now accepted and ready to land.

looks good to me


https://reviews.llvm.org/D25658



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


[PATCH] D25657: include-fixer: Don't overwrite buffer changes

2016-10-25 Thread Jens Massberg via cfe-commits
massberg accepted this revision.
massberg added a comment.
This revision is now accepted and ready to land.

looks good to me


https://reviews.llvm.org/D25657



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


[PATCH] D22805: [clang-include-fixer] Added Emacs integration for clang-include-fixer.

2016-07-26 Thread Jens Massberg via cfe-commits
massberg created this revision.
massberg added reviewers: bkramer, hokein.
massberg added a subscriber: cfe-commits.

[clang-include-fixer] Added Emacs integration for clang-include-fixer.

https://reviews.llvm.org/D22805

Files:
  include-fixer/tool/clang-include-fixer.el

Index: include-fixer/tool/clang-include-fixer.el
===
--- /dev/null
+++ include-fixer/tool/clang-include-fixer.el
@@ -0,0 +1,211 @@
+;;; clang-include-fxier.el --- Emacs integration of the clang include fixer
+
+;; Keywords: tools, c
+;; Package-Requires: ((json "1.2"))
+
+;;; Commentary:
+
+;; This package allows to envoke the 'clnag-include-fixer' within Emacs.
+;; 'clang-include-fixer' provides an automated way of adding #include
+;; directives for missing symbols in one translation unit, see
+;; .
+
+;;; Code:
+
+(require 'json)
+
+(defgroup clang-include-fixer nil
+  "Include fixer."
+  :group 'tools)
+
+(defcustom clang-include-fixer-executable
+  "clang-include-fixer"
+  "Location of the `clang-include-fixer' executable.
+
+A string containing the name or the full path of the executable."
+  :group 'clang-include-fixer
+  :type 'string
+  :risky t)
+
+(defcustom clang-include-fixer-input-format
+  "yaml"
+  "clang-include-fixer input format."
+  :group 'clang-include-fixer
+  :type 'string
+  :risky t)
+
+(defcustom clang-include-fixer-init-string
+  ""
+  "clang-include-fixer input format."
+  :group 'clang-include-fixer
+  :type 'string
+  :risky t)
+
+
+(defun clang-include-fixer-call-executable (callee
+include-fixer-parameter-a
+&optional include-fixer-parameter-b
+&optional include-fixer-parameter-c
+)
+  "Calls clang-include-fixer with parameters INCLUDE-FIXER-PARAMETER-[ABC].
+If the call was successful the returned result is stored in a temp buffer
+and the function CALLEE is called on this temp buffer."
+
+(let ((temp-buffer (generate-new-buffer " *clang-include-fixer-temp*"))
+  (temp-file (make-temp-file "clang-include-fixer")))
+  (unwind-protect
+  (let (status stderr operations)
+(if (eq include-fixer-parameter-c nil)
+(setq status
+  (call-process-region
+   (point-min) (point-max) clang-include-fixer-executable
+   nil `(,temp-buffer ,temp-file) nil
+
+   "-stdin"
+   include-fixer-parameter-a
+   (buffer-file-name)
+   ))
+  (setq status
+(call-process-region
+ (point-min) (point-max) clang-include-fixer-executable
+ nil `(,temp-buffer ,temp-file) nil
+
+ "-stdin"
+ include-fixer-parameter-a
+ include-fixer-parameter-b
+ include-fixer-parameter-c
+ (buffer-file-name)
+ )))
+
+(setq stderr
+  (with-temp-buffer
+(insert-file-contents temp-file)
+(when (> (point-max) (point-min))
+  (insert ": "))
+(buffer-substring-no-properties
+ (point-min) (line-end-position
+
+(cond
+ ((stringp status)
+  (error "(clang-include-fixer killed by signal %s%s)" status
+ stderr))
+ ((not (equal 0 status))
+  (error "(clang-include-fixer failed with code %d%s)" status
+ stderr)))
+(funcall callee temp-buffer))
+(delete-file temp-file)
+(when (buffer-name temp-buffer) (kill-buffer temp-buffer)
+
+
+(defun clang-include-fixer-replace_buffer (temp-buffer)
+  "Replace current buffer by content of TEMP-BUFFER"
+
+  (with-current-buffer temp-buffer
+(setq temp-start (point-min))
+(setq temp-end (point-max))
+)
+  (barf-if-buffer-read-only)
+  (erase-buffer)
+  (save-excursion
+(insert-buffer-substring temp-buffer temp-start temp-end)))
+
+
+(defun clang-include-fixer-add-header (temp-buffer)
+  "Analyse the result of include-fixer stored in TEMP_BUFFER and add a
+   missing header if there is any. If there are multiple possible headers
+   the user can select one of them to be included."
+
+  (with-current-buffer temp-buffer
+(setq result (buffer-substring (point-min) (point-max)))
+(setq include-fixer-context
+  (let ((json-object-type 'plist))
+(json-read-from-string result
+
+  ;; The header-infos is already sorted by include-fixer.
+  (setq header-infos (plist-get include-fixer-context :HeaderInfos))
+  (setq symbol (plist-get include-fixer-context :SymbolIdentifier))
+ 

Re: [PATCH] D22805: [clang-include-fixer] Added Emacs integration for clang-include-fixer.

2016-07-26 Thread Jens Massberg via cfe-commits
massberg updated this revision to Diff 65521.
massberg added a comment.

Updating https://reviews.llvm.org/D22805: [clang-include-fixer] Added Emacs 
integration for clang-include-fixer.

- Fixed typo
- Added documentation how to setup tools within emacs
- Removed unnecessary yes-no question


https://reviews.llvm.org/D22805

Files:
  docs/include-fixer.rst
  include-fixer/tool/clang-include-fixer.el

Index: include-fixer/tool/clang-include-fixer.el
===
--- /dev/null
+++ include-fixer/tool/clang-include-fixer.el
@@ -0,0 +1,203 @@
+;;; clang-include-fxier.el --- Emacs integration of the clang include fixer
+
+;; Keywords: tools, c
+;; Package-Requires: ((json "1.2"))
+
+;;; Commentary:
+
+;; This package allows to invoke the 'clnag-include-fixer' within Emacs.
+;; 'clang-include-fixer' provides an automated way of adding #include
+;; directives for missing symbols in one translation unit, see
+;; .
+
+;;; Code:
+
+(require 'json)
+
+(defgroup clang-include-fixer nil
+  "Include fixer."
+  :group 'tools)
+
+(defcustom clang-include-fixer-executable
+  "clang-include-fixer"
+  "Location of the `clang-include-fixer' executable.
+
+A string containing the name or the full path of the executable."
+  :group 'clang-include-fixer
+  :type 'string
+  :risky t)
+
+(defcustom clang-include-fixer-input-format
+  "yaml"
+  "clang-include-fixer input format."
+  :group 'clang-include-fixer
+  :type 'string
+  :risky t)
+
+(defcustom clang-include-fixer-init-string
+  ""
+  "clang-include-fixer input format."
+  :group 'clang-include-fixer
+  :type 'string
+  :risky t)
+
+
+(defun clang-include-fixer-call-executable (callee
+include-fixer-parameter-a
+&optional include-fixer-parameter-b
+&optional include-fixer-parameter-c
+)
+  "Calls clang-include-fixer with parameters INCLUDE-FIXER-PARAMETER-[ABC].
+If the call was successful the returned result is stored in a temp buffer
+and the function CALLEE is called on this temp buffer."
+
+(let ((temp-buffer (generate-new-buffer " *clang-include-fixer-temp*"))
+  (temp-file (make-temp-file "clang-include-fixer")))
+  (unwind-protect
+  (let (status stderr operations)
+(if (eq include-fixer-parameter-c nil)
+(setq status
+  (call-process-region
+   (point-min) (point-max) clang-include-fixer-executable
+   nil `(,temp-buffer ,temp-file) nil
+
+   "-stdin"
+   include-fixer-parameter-a
+   (buffer-file-name)
+   ))
+  (setq status
+(call-process-region
+ (point-min) (point-max) clang-include-fixer-executable
+ nil `(,temp-buffer ,temp-file) nil
+
+ "-stdin"
+ include-fixer-parameter-a
+ include-fixer-parameter-b
+ include-fixer-parameter-c
+ (buffer-file-name)
+ )))
+
+(setq stderr
+  (with-temp-buffer
+(insert-file-contents temp-file)
+(when (> (point-max) (point-min))
+  (insert ": "))
+(buffer-substring-no-properties
+ (point-min) (line-end-position
+
+(cond
+ ((stringp status)
+  (error "(clang-include-fixer killed by signal %s%s)" status
+ stderr))
+ ((not (equal 0 status))
+  (error "(clang-include-fixer failed with code %d%s)" status
+ stderr)))
+(funcall callee temp-buffer))
+(delete-file temp-file)
+(when (buffer-name temp-buffer) (kill-buffer temp-buffer)
+
+
+(defun clang-include-fixer-replace_buffer (temp-buffer)
+  "Replace current buffer by content of TEMP-BUFFER"
+
+  (with-current-buffer temp-buffer
+(setq temp-start (point-min))
+(setq temp-end (point-max))
+)
+  (barf-if-buffer-read-only)
+  (erase-buffer)
+  (save-excursion
+(insert-buffer-substring temp-buffer temp-start temp-end)))
+
+
+(defun clang-include-fixer-add-header (temp-buffer)
+  "Analyse the result of include-fixer stored in TEMP_BUFFER and add a
+   missing header if there is any. If there are multiple possible headers
+   the user can select one of them to be included."
+
+  (with-current-buffer temp-buffer
+(setq result (buffer-substring (point-min) (point-max)))
+(setq include-fixer-context
+  (let ((json-object-type 'plist))
+(json-read-from-string result
+
+  ;; The header-infos is already sorted by include-fixer.
+  (setq he

Re: [PATCH] D22805: [clang-include-fixer] Added Emacs integration for clang-include-fixer.

2016-07-26 Thread Jens Massberg via cfe-commits
massberg updated this revision to Diff 65524.
massberg added a comment.

Updating https://reviews.llvm.org/D22805: [clang-include-fixer] Added Emacs 
integration for clang-include-fixer.

-Fixed documentation


https://reviews.llvm.org/D22805

Files:
  docs/include-fixer.rst
  include-fixer/tool/clang-include-fixer.el

Index: include-fixer/tool/clang-include-fixer.el
===
--- /dev/null
+++ include-fixer/tool/clang-include-fixer.el
@@ -0,0 +1,203 @@
+;;; clang-include-fxier.el --- Emacs integration of the clang include fixer
+
+;; Keywords: tools, c
+;; Package-Requires: ((json "1.2"))
+
+;;; Commentary:
+
+;; This package allows to invoke the 'clnag-include-fixer' within Emacs.
+;; 'clang-include-fixer' provides an automated way of adding #include
+;; directives for missing symbols in one translation unit, see
+;; .
+
+;;; Code:
+
+(require 'json)
+
+(defgroup clang-include-fixer nil
+  "Include fixer."
+  :group 'tools)
+
+(defcustom clang-include-fixer-executable
+  "clang-include-fixer"
+  "Location of the `clang-include-fixer' executable.
+
+A string containing the name or the full path of the executable."
+  :group 'clang-include-fixer
+  :type 'string
+  :risky t)
+
+(defcustom clang-include-fixer-input-format
+  "yaml"
+  "clang-include-fixer input format."
+  :group 'clang-include-fixer
+  :type 'string
+  :risky t)
+
+(defcustom clang-include-fixer-init-string
+  ""
+  "clang-include-fixer input format."
+  :group 'clang-include-fixer
+  :type 'string
+  :risky t)
+
+
+(defun clang-include-fixer-call-executable (callee
+include-fixer-parameter-a
+&optional include-fixer-parameter-b
+&optional include-fixer-parameter-c
+)
+  "Calls clang-include-fixer with parameters INCLUDE-FIXER-PARAMETER-[ABC].
+If the call was successful the returned result is stored in a temp buffer
+and the function CALLEE is called on this temp buffer."
+
+(let ((temp-buffer (generate-new-buffer " *clang-include-fixer-temp*"))
+  (temp-file (make-temp-file "clang-include-fixer")))
+  (unwind-protect
+  (let (status stderr operations)
+(if (eq include-fixer-parameter-c nil)
+(setq status
+  (call-process-region
+   (point-min) (point-max) clang-include-fixer-executable
+   nil `(,temp-buffer ,temp-file) nil
+
+   "-stdin"
+   include-fixer-parameter-a
+   (buffer-file-name)
+   ))
+  (setq status
+(call-process-region
+ (point-min) (point-max) clang-include-fixer-executable
+ nil `(,temp-buffer ,temp-file) nil
+
+ "-stdin"
+ include-fixer-parameter-a
+ include-fixer-parameter-b
+ include-fixer-parameter-c
+ (buffer-file-name)
+ )))
+
+(setq stderr
+  (with-temp-buffer
+(insert-file-contents temp-file)
+(when (> (point-max) (point-min))
+  (insert ": "))
+(buffer-substring-no-properties
+ (point-min) (line-end-position
+
+(cond
+ ((stringp status)
+  (error "(clang-include-fixer killed by signal %s%s)" status
+ stderr))
+ ((not (equal 0 status))
+  (error "(clang-include-fixer failed with code %d%s)" status
+ stderr)))
+(funcall callee temp-buffer))
+(delete-file temp-file)
+(when (buffer-name temp-buffer) (kill-buffer temp-buffer)
+
+
+(defun clang-include-fixer-replace_buffer (temp-buffer)
+  "Replace current buffer by content of TEMP-BUFFER"
+
+  (with-current-buffer temp-buffer
+(setq temp-start (point-min))
+(setq temp-end (point-max))
+)
+  (barf-if-buffer-read-only)
+  (erase-buffer)
+  (save-excursion
+(insert-buffer-substring temp-buffer temp-start temp-end)))
+
+
+(defun clang-include-fixer-add-header (temp-buffer)
+  "Analyse the result of include-fixer stored in TEMP_BUFFER and add a
+   missing header if there is any. If there are multiple possible headers
+   the user can select one of them to be included."
+
+  (with-current-buffer temp-buffer
+(setq result (buffer-substring (point-min) (point-max)))
+(setq include-fixer-context
+  (let ((json-object-type 'plist))
+(json-read-from-string result
+
+  ;; The header-infos is already sorted by include-fixer.
+  (setq header-infos (plist-get include-fixer-context :HeaderInfos))
+  (setq symbol (plist-ge

Re: [PATCH] D22805: [clang-include-fixer] Added Emacs integration for clang-include-fixer.

2016-07-26 Thread Jens Massberg via cfe-commits
massberg updated this revision to Diff 65525.
massberg added a comment.

Updating https://reviews.llvm.org/D22805: [clang-include-fixer] Added Emacs 
integration for clang-include-fixer.

- Fixed typo


https://reviews.llvm.org/D22805

Files:
  docs/include-fixer.rst
  include-fixer/tool/clang-include-fixer.el

Index: include-fixer/tool/clang-include-fixer.el
===
--- /dev/null
+++ include-fixer/tool/clang-include-fixer.el
@@ -0,0 +1,203 @@
+;;; clang-include-fxier.el --- Emacs integration of the clang include fixer
+
+;; Keywords: tools, c
+;; Package-Requires: ((json "1.2"))
+
+;;; Commentary:
+
+;; This package allows to invoke the 'clang-include-fixer' within Emacs.
+;; 'clang-include-fixer' provides an automated way of adding #include
+;; directives for missing symbols in one translation unit, see
+;; .
+
+;;; Code:
+
+(require 'json)
+
+(defgroup clang-include-fixer nil
+  "Include fixer."
+  :group 'tools)
+
+(defcustom clang-include-fixer-executable
+  "clang-include-fixer"
+  "Location of the `clang-include-fixer' executable.
+
+A string containing the name or the full path of the executable."
+  :group 'clang-include-fixer
+  :type 'string
+  :risky t)
+
+(defcustom clang-include-fixer-input-format
+  "yaml"
+  "clang-include-fixer input format."
+  :group 'clang-include-fixer
+  :type 'string
+  :risky t)
+
+(defcustom clang-include-fixer-init-string
+  ""
+  "clang-include-fixer input format."
+  :group 'clang-include-fixer
+  :type 'string
+  :risky t)
+
+
+(defun clang-include-fixer-call-executable (callee
+include-fixer-parameter-a
+&optional include-fixer-parameter-b
+&optional include-fixer-parameter-c
+)
+  "Calls clang-include-fixer with parameters INCLUDE-FIXER-PARAMETER-[ABC].
+If the call was successful the returned result is stored in a temp buffer
+and the function CALLEE is called on this temp buffer."
+
+(let ((temp-buffer (generate-new-buffer " *clang-include-fixer-temp*"))
+  (temp-file (make-temp-file "clang-include-fixer")))
+  (unwind-protect
+  (let (status stderr operations)
+(if (eq include-fixer-parameter-c nil)
+(setq status
+  (call-process-region
+   (point-min) (point-max) clang-include-fixer-executable
+   nil `(,temp-buffer ,temp-file) nil
+
+   "-stdin"
+   include-fixer-parameter-a
+   (buffer-file-name)
+   ))
+  (setq status
+(call-process-region
+ (point-min) (point-max) clang-include-fixer-executable
+ nil `(,temp-buffer ,temp-file) nil
+
+ "-stdin"
+ include-fixer-parameter-a
+ include-fixer-parameter-b
+ include-fixer-parameter-c
+ (buffer-file-name)
+ )))
+
+(setq stderr
+  (with-temp-buffer
+(insert-file-contents temp-file)
+(when (> (point-max) (point-min))
+  (insert ": "))
+(buffer-substring-no-properties
+ (point-min) (line-end-position
+
+(cond
+ ((stringp status)
+  (error "(clang-include-fixer killed by signal %s%s)" status
+ stderr))
+ ((not (equal 0 status))
+  (error "(clang-include-fixer failed with code %d%s)" status
+ stderr)))
+(funcall callee temp-buffer))
+(delete-file temp-file)
+(when (buffer-name temp-buffer) (kill-buffer temp-buffer)
+
+
+(defun clang-include-fixer-replace_buffer (temp-buffer)
+  "Replace current buffer by content of TEMP-BUFFER"
+
+  (with-current-buffer temp-buffer
+(setq temp-start (point-min))
+(setq temp-end (point-max))
+)
+  (barf-if-buffer-read-only)
+  (erase-buffer)
+  (save-excursion
+(insert-buffer-substring temp-buffer temp-start temp-end)))
+
+
+(defun clang-include-fixer-add-header (temp-buffer)
+  "Analyse the result of include-fixer stored in TEMP_BUFFER and add a
+   missing header if there is any. If there are multiple possible headers
+   the user can select one of them to be included."
+
+  (with-current-buffer temp-buffer
+(setq result (buffer-substring (point-min) (point-max)))
+(setq include-fixer-context
+  (let ((json-object-type 'plist))
+(json-read-from-string result
+
+  ;; The header-infos is already sorted by include-fixer.
+  (setq header-infos (plist-get include-fixer-context :HeaderInfos))
+  (setq symbol (plist-get includ

Re: [PATCH] D22805: [clang-include-fixer] Added Emacs integration for clang-include-fixer.

2016-07-26 Thread Jens Massberg via cfe-commits
massberg marked 3 inline comments as done.
massberg added a comment.

Thanks for the comments. I fixed the typos and wrote a (short) documentation.


https://reviews.llvm.org/D22805



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


Re: [PATCH] D22805: [clang-include-fixer] Added Emacs integration for clang-include-fixer.

2016-07-26 Thread Jens Massberg via cfe-commits
massberg updated this revision to Diff 65546.
massberg added a comment.

Updating https://reviews.llvm.org/D22805: [clang-include-fixer] Added Emacs 
integration for clang-include-fixer.

Now working with the newest clang-include-fixer input/output format.


https://reviews.llvm.org/D22805

Files:
  docs/include-fixer.rst
  include-fixer/tool/clang-include-fixer.el

Index: include-fixer/tool/clang-include-fixer.el
===
--- /dev/null
+++ include-fixer/tool/clang-include-fixer.el
@@ -0,0 +1,209 @@
+;;; clang-include-fxier.el --- Emacs integration of the clang include fixer
+
+;; Keywords: tools, c
+;; Package-Requires: ((json "1.2"))
+
+;;; Commentary:
+
+;; This package allows to invoke the 'clang-include-fixer' within Emacs.
+;; 'clang-include-fixer' provides an automated way of adding #include
+;; directives for missing symbols in one translation unit, see
+;; .
+
+;;; Code:
+
+(require 'json)
+
+(defgroup clang-include-fixer nil
+  "Include fixer."
+  :group 'tools)
+
+(defcustom clang-include-fixer-executable
+  "clang-include-fixer"
+  "Location of the `clang-include-fixer' executable.
+
+A string containing the name or the full path of the executable."
+  :group 'clang-include-fixer
+  :type 'string
+  :risky t)
+
+(defcustom clang-include-fixer-input-format
+  "google3"
+  "/usr/local/google/home/massberg/Emacs_Lisp/include-fixer/clang-include-fixer input format."
+  :group 'clang-include-fixer
+  :type 'string
+  :risky t)
+
+(defcustom clang-include-fixer-init-string
+  ""
+  "clang-include-fixer input format."
+  :group 'clang-include-fixer
+  :type 'string
+  :risky t)
+
+
+(defun clang-include-fixer-call-executable (callee
+include-fixer-parameter-a
+&optional include-fixer-parameter-b
+&optional include-fixer-parameter-c
+)
+  "Calls clang-include-fixer with parameters INCLUDE-FIXER-PARAMETER-[ABC].
+If the call was successful the returned result is stored in a temp buffer
+and the function CALLEE is called on this temp buffer."
+
+(let ((temp-buffer (generate-new-buffer " *clang-include-fixer-temp*"))
+  (temp-file (make-temp-file "clang-include-fixer")))
+  (unwind-protect
+  (let (status stderr operations)
+(if (eq include-fixer-parameter-c nil)
+(setq status
+  (call-process-region
+   (point-min) (point-max) clang-include-fixer-executable
+   nil `(,temp-buffer ,temp-file) nil
+
+   "-stdin"
+   include-fixer-parameter-a
+   (buffer-file-name)
+   ))
+  (setq status
+(call-process-region
+ (point-min) (point-max) clang-include-fixer-executable
+ nil `(,temp-buffer ,temp-file) nil
+
+ "-stdin"
+ include-fixer-parameter-a
+ include-fixer-parameter-b
+ include-fixer-parameter-c
+ (buffer-file-name)
+ )))
+
+(setq stderr
+  (with-temp-buffer
+(insert-file-contents temp-file)
+(when (> (point-max) (point-min))
+  (insert ": "))
+(buffer-substring-no-properties
+ (point-min) (line-end-position
+
+(cond
+ ((stringp status)
+  (error "(clang-include-fixer killed by signal %s%s)" status
+ stderr))
+ ((not (equal 0 status))
+  (error "(clang-include-fixer failed with code %d%s)" status
+ stderr)))
+(funcall callee temp-buffer))
+(delete-file temp-file)
+(when (buffer-name temp-buffer) (kill-buffer temp-buffer)
+
+
+(defun clang-include-fixer-replace_buffer (temp-buffer)
+  "Replace current buffer by content of TEMP-BUFFER"
+
+  (with-current-buffer temp-buffer
+(setq temp-start (point-min))
+(setq temp-end (point-max))
+)
+  (barf-if-buffer-read-only)
+  (erase-buffer)
+  (save-excursion
+(insert-buffer-substring temp-buffer temp-start temp-end)))
+
+
+(defun clang-include-fixer-add-header (temp-buffer)
+  "Analyse the result of include-fixer stored in TEMP_BUFFER and add a
+   missing header if there is any. If there are multiple possible headers
+   the user can select one of them to be included."
+
+  (with-current-buffer temp-buffer
+(setq result (buffer-substring (point-min) (point-max)))
+(setq include-fixer-context
+  (let ((json-object-type 'plist))
+(json-read-from-string result
+
+  (message result)
+
+  ;; The header-infos i

Re: [PATCH] D22805: [clang-include-fixer] Added Emacs integration for clang-include-fixer.

2016-07-26 Thread Jens Massberg via cfe-commits
massberg marked an inline comment as done.
massberg added a comment.

Thanks, now supporting the new format.


https://reviews.llvm.org/D22805



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


Re: [PATCH] D22805: [clang-include-fixer] Added Emacs integration for clang-include-fixer.

2016-07-26 Thread Jens Massberg via cfe-commits
massberg updated this revision to Diff 65562.
massberg added a comment.

Updating https://reviews.llvm.org/D22805: [clang-include-fixer] Added Emacs 
integration for clang-include-fixer.

- fixed private path
- removed debug message


https://reviews.llvm.org/D22805

Files:
  docs/include-fixer.rst
  include-fixer/tool/clang-include-fixer.el

Index: include-fixer/tool/clang-include-fixer.el
===
--- /dev/null
+++ include-fixer/tool/clang-include-fixer.el
@@ -0,0 +1,207 @@
+;;; clang-include-fxier.el --- Emacs integration of the clang include fixer
+
+;; Keywords: tools, c
+;; Package-Requires: ((json "1.2"))
+
+;;; Commentary:
+
+;; This package allows to invoke the 'clang-include-fixer' within Emacs.
+;; 'clang-include-fixer' provides an automated way of adding #include
+;; directives for missing symbols in one translation unit, see
+;; .
+
+;;; Code:
+
+(require 'json)
+
+(defgroup clang-include-fixer nil
+  "Include fixer."
+  :group 'tools)
+
+(defcustom clang-include-fixer-executable
+  "clang-include-fixer"
+  "Location of the `clang-include-fixer' executable.
+
+A string containing the name or the full path of the executable."
+  :group 'clang-include-fixer
+  :type 'string
+  :risky t)
+
+(defcustom clang-include-fixer-input-format
+  "yaml"
+  "clang-include-fixer input format."
+  :group 'clang-include-fixer
+  :type 'string
+  :risky t)
+
+(defcustom clang-include-fixer-init-string
+  ""
+  "clang-include-fixer input format."
+  :group 'clang-include-fixer
+  :type 'string
+  :risky t)
+
+
+(defun clang-include-fixer-call-executable (callee
+include-fixer-parameter-a
+&optional include-fixer-parameter-b
+&optional include-fixer-parameter-c
+)
+  "Calls clang-include-fixer with parameters INCLUDE-FIXER-PARAMETER-[ABC].
+If the call was successful the returned result is stored in a temp buffer
+and the function CALLEE is called on this temp buffer."
+
+(let ((temp-buffer (generate-new-buffer " *clang-include-fixer-temp*"))
+  (temp-file (make-temp-file "clang-include-fixer")))
+  (unwind-protect
+  (let (status stderr operations)
+(if (eq include-fixer-parameter-c nil)
+(setq status
+  (call-process-region
+   (point-min) (point-max) clang-include-fixer-executable
+   nil `(,temp-buffer ,temp-file) nil
+
+   "-stdin"
+   include-fixer-parameter-a
+   (buffer-file-name)
+   ))
+  (setq status
+(call-process-region
+ (point-min) (point-max) clang-include-fixer-executable
+ nil `(,temp-buffer ,temp-file) nil
+
+ "-stdin"
+ include-fixer-parameter-a
+ include-fixer-parameter-b
+ include-fixer-parameter-c
+ (buffer-file-name)
+ )))
+
+(setq stderr
+  (with-temp-buffer
+(insert-file-contents temp-file)
+(when (> (point-max) (point-min))
+  (insert ": "))
+(buffer-substring-no-properties
+ (point-min) (line-end-position
+
+(cond
+ ((stringp status)
+  (error "(clang-include-fixer killed by signal %s%s)" status
+ stderr))
+ ((not (equal 0 status))
+  (error "(clang-include-fixer failed with code %d%s)" status
+ stderr)))
+(funcall callee temp-buffer))
+(delete-file temp-file)
+(when (buffer-name temp-buffer) (kill-buffer temp-buffer)
+
+
+(defun clang-include-fixer-replace_buffer (temp-buffer)
+  "Replace current buffer by content of TEMP-BUFFER"
+
+  (with-current-buffer temp-buffer
+(setq temp-start (point-min))
+(setq temp-end (point-max))
+)
+  (barf-if-buffer-read-only)
+  (erase-buffer)
+  (save-excursion
+(insert-buffer-substring temp-buffer temp-start temp-end)))
+
+
+(defun clang-include-fixer-add-header (temp-buffer)
+  "Analyse the result of include-fixer stored in TEMP_BUFFER and add a
+   missing header if there is any. If there are multiple possible headers
+   the user can select one of them to be included."
+
+  (with-current-buffer temp-buffer
+(setq result (buffer-substring (point-min) (point-max)))
+(setq include-fixer-context
+  (let ((json-object-type 'plist))
+(json-read-from-string result
+
+  ;; The header-infos is already sorted by include-fixer.
+  (setq header-infos (plist-get include-fixer-context :HeaderInfos))
+

Re: [PATCH] D22805: [clang-include-fixer] Added Emacs integration for clang-include-fixer.

2016-07-26 Thread Jens Massberg via cfe-commits
massberg marked 2 inline comments as done.
massberg added a comment.

Thanks for the comments!



Comment at: include-fixer/tool/clang-include-fixer.el:125
@@ +124,3 @@
+  ;; The header-infos is already sorted by include-fixer.
+  (setq header-infos (plist-get include-fixer-context :HeaderInfos))
+  (setq query-symbol-infos (plist-get include-fixer-context :QuerySymbolInfos))

You are right, removed.


https://reviews.llvm.org/D22805



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


Re: [PATCH] D22805: [clang-include-fixer] Added Emacs integration for clang-include-fixer.

2016-07-27 Thread Jens Massberg via cfe-commits
massberg updated this revision to Diff 65679.
massberg marked an inline comment as done.
massberg added a comment.

Updating https://reviews.llvm.org/D22805: [clang-include-fixer] Added Emacs 
integration for clang-include-fixer.

- Corrected typos and code indentation.


https://reviews.llvm.org/D22805

Files:
  docs/include-fixer.rst
  include-fixer/tool/clang-include-fixer.el

Index: include-fixer/tool/clang-include-fixer.el
===
--- /dev/null
+++ include-fixer/tool/clang-include-fixer.el
@@ -0,0 +1,207 @@
+;;; clang-include-fxier.el --- Emacs integration of the clang include fixer
+
+;; Keywords: tools, c
+;; Package-Requires: ((json "1.2"))
+
+;;; Commentary:
+
+;; This package allows to invoke the 'clang-include-fixer' within Emacs.
+;; 'clang-include-fixer' provides an automated way of adding #include
+;; directives for missing symbols in one translation unit, see
+;; .
+
+;;; Code:
+
+(require 'json)
+
+(defgroup clang-include-fixer nil
+  "Include fixer."
+  :group 'tools)
+
+(defcustom clang-include-fixer-executable
+  "clang-include-fixer"
+  "Location of the `clang-include-fixer' executable.
+
+   A string containing the name or the full path of the executable."
+  :group 'clang-include-fixer
+  :type 'string
+  :risky t)
+
+(defcustom clang-include-fixer-input-format
+  "yaml"
+  "clang-include-fixer input format."
+  :group 'clang-include-fixer
+  :type 'string
+  :risky t)
+
+(defcustom clang-include-fixer-init-string
+  ""
+  "clang-include-fixer input format."
+  :group 'clang-include-fixer
+  :type 'string
+  :risky t)
+
+
+(defun clang-include-fixer-call-executable (callee
+include-fixer-parameter-a
+&optional include-fixer-parameter-b
+&optional include-fixer-parameter-c
+)
+  "Calls clang-include-fixer with parameters INCLUDE-FIXER-PARAMETER-[ABC].
+   If the call was successful the returned result is stored in a temp buffer
+   and the function CALLEE is called on this temp buffer."
+
+(let ((temp-buffer (generate-new-buffer " *clang-include-fixer-temp*"))
+  (temp-file (make-temp-file "clang-include-fixer")))
+  (unwind-protect
+  (let (status stderr operations)
+(if (eq include-fixer-parameter-c nil)
+(setq status
+  (call-process-region
+   (point-min) (point-max) clang-include-fixer-executable
+   nil `(,temp-buffer ,temp-file) nil
+
+   "-stdin"
+   include-fixer-parameter-a
+   (buffer-file-name)
+   ))
+  (setq status
+(call-process-region
+ (point-min) (point-max) clang-include-fixer-executable
+ nil `(,temp-buffer ,temp-file) nil
+
+ "-stdin"
+ include-fixer-parameter-a
+ include-fixer-parameter-b
+ include-fixer-parameter-c
+ (buffer-file-name)
+ )))
+
+(setq stderr
+  (with-temp-buffer
+(insert-file-contents temp-file)
+(when (> (point-max) (point-min))
+  (insert ": "))
+(buffer-substring-no-properties
+ (point-min) (line-end-position
+
+(cond
+ ((stringp status)
+  (error "(clang-include-fixer killed by signal %s%s)" status
+ stderr))
+ ((not (equal 0 status))
+  (error "(clang-include-fixer failed with code %d%s)" status
+ stderr)))
+(funcall callee temp-buffer))
+(delete-file temp-file)
+(when (buffer-name temp-buffer) (kill-buffer temp-buffer)
+
+
+(defun clang-include-fixer-replace_buffer (temp-buffer)
+  "Replace current buffer by content of TEMP-BUFFER"
+
+  (with-current-buffer temp-buffer
+(setq temp-start (point-min))
+(setq temp-end (point-max))
+)
+  (barf-if-buffer-read-only)
+  (erase-buffer)
+  (save-excursion
+(insert-buffer-substring temp-buffer temp-start temp-end)))
+
+
+(defun clang-include-fixer-add-header (temp-buffer)
+  "Analyse the result of include-fixer stored in TEMP_BUFFER and add a
+   missing header if there is any. If there are multiple possible headers
+   the user can select one of them to be included."
+
+  (with-current-buffer temp-buffer
+(setq result (buffer-substring (point-min) (point-max)))
+(setq include-fixer-context
+  (let ((json-object-type 'plist))
+(json-read-from-string result
+
+  ;; The header-infos is already sorted by include-fixer.
+  (setq header-infos (p

Re: [PATCH] D22805: [clang-include-fixer] Added Emacs integration for clang-include-fixer.

2016-07-27 Thread Jens Massberg via cfe-commits
massberg marked 2 inline comments as done.
massberg added a comment.

Thanks for the comments!



Comment at: include-fixer/tool/clang-include-fixer.el:24
@@ +23,3 @@
+  "Location of the `clang-include-fixer' executable.
+
+   A string containing the name or the full path of the executable."

The ending  " is two lines below.


https://reviews.llvm.org/D22805



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