[clang-tools-extra] r336318 - [clangd] Treat class constructor as in the same scope as the class in ranking.
Mikael Holmén via cfe-commits
cfe-commits at lists.llvm.org
Thu Jul 5 04:03:59 PDT 2018
Ah, already fixed in r336329 I see.
On 07/05/2018 12:56 PM, Mikael Holmén via cfe-commits wrote:
> Hi Eric,
>
> I get the following with this patch:
>
> /proj/flexasic/app/clang/3.6/bin/clang++ -march=corei7
> -DGTEST_HAS_RTTI=0 -D_DEBUG -D_GNU_SOURCE -D__STDC_CONSTANT_MACROS
> -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS
> -Itools/clang/tools/extra/clangd -I../tools/clang/tools/extra/clangd
> -I../tools/clang/include -Itools/clang/include -I/usr/include/libxml2
> -Iinclude -I../include -fPIC -fvisibility-inlines-hidden -Werror
> -Werror=date-time -std=c++11 -Wall -Wextra -Wno-unused-parameter
> -Wwrite-strings -Wcast-qual -Wmissing-field-initializers -pedantic
> -Wno-long-long -Wcovered-switch-default -Wnon-virtual-dtor
> -Wdelete-non-virtual-dtor -Wstring-conversion -fdiagnostics-color
> -ffunction-sections -fdata-sections -fno-common -Woverloaded-virtual
> -Wno-nested-anon-types -O3 -UNDEBUG -fno-exceptions -fno-rtti -MMD
> -MT
> tools/clang/tools/extra/clangd/CMakeFiles/clangDaemon.dir/Quality.cpp.o
> -MF
> tools/clang/tools/extra/clangd/CMakeFiles/clangDaemon.dir/Quality.cpp.o.d -o
> tools/clang/tools/extra/clangd/CMakeFiles/clangDaemon.dir/Quality.cpp.o
> -c ../tools/clang/tools/extra/clangd/Quality.cpp
> ../tools/clang/tools/extra/clangd/Quality.cpp:201:19: error: unused
> variable 'Ctor' [-Werror,-Wunused-variable]
> if (const auto *Ctor = llvm::dyn_cast<CXXConstructorDecl>(D))
> ^
> 1 error generated.
>
> Regards,
> Mikael
>
> On 07/05/2018 10:14 AM, Eric Liu via cfe-commits wrote:
>> Author: ioeric
>> Date: Thu Jul 5 01:14:04 2018
>> New Revision: 336318
>>
>> URL: http://llvm.org/viewvc/llvm-project?rev=336318&view=rev
>> Log:
>> [clangd] Treat class constructor as in the same scope as the class in
>> ranking.
>>
>> Reviewers: sammccall
>>
>> Subscribers: ilya-biryukov, MaskRay, jkorous, cfe-commits
>>
>> Differential Revision: https://reviews.llvm.org/D48933
>>
>> Modified:
>> clang-tools-extra/trunk/clangd/Quality.cpp
>> clang-tools-extra/trunk/unittests/clangd/QualityTests.cpp
>> clang-tools-extra/trunk/unittests/clangd/TestTU.cpp
>> clang-tools-extra/trunk/unittests/clangd/TestTU.h
>>
>> Modified: clang-tools-extra/trunk/clangd/Quality.cpp
>> URL:
>> http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/Quality.cpp?rev=336318&r1=336317&r2=336318&view=diff
>>
>> ==============================================================================
>>
>> --- clang-tools-extra/trunk/clangd/Quality.cpp (original)
>> +++ clang-tools-extra/trunk/clangd/Quality.cpp Thu Jul 5 01:14:04 2018
>> @@ -11,10 +11,12 @@
>> #include "URI.h"
>> #include "index/Index.h"
>> #include "clang/AST/ASTContext.h"
>> +#include "clang/AST/DeclCXX.h"
>> #include "clang/AST/DeclVisitor.h"
>> #include "clang/Basic/CharInfo.h"
>> #include "clang/Basic/SourceManager.h"
>> #include "clang/Sema/CodeCompleteConsumer.h"
>> +#include "llvm/Support/Casting.h"
>> #include "llvm/Support/FormatVariadic.h"
>> #include "llvm/Support/MathExtras.h"
>> #include "llvm/Support/raw_ostream.h"
>> @@ -195,6 +197,9 @@ ComputeScope(const NamedDecl *D) {
>> if (auto *R = dyn_cast_or_null<RecordDecl>(D))
>> if (R->isInjectedClassName())
>> DC = DC->getParent();
>> + // Class constructor should have the same scope as the class.
>> + if (const auto *Ctor = llvm::dyn_cast<CXXConstructorDecl>(D))
>> + DC = DC->getParent();
>> bool InClass = false;
>> for (; !DC->isFileContext(); DC = DC->getParent()) {
>> if (DC->isFunctionOrMethod())
>>
>> Modified: clang-tools-extra/trunk/unittests/clangd/QualityTests.cpp
>> URL:
>> http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/unittests/clangd/QualityTests.cpp?rev=336318&r1=336317&r2=336318&view=diff
>>
>> ==============================================================================
>>
>> --- clang-tools-extra/trunk/unittests/clangd/QualityTests.cpp (original)
>> +++ clang-tools-extra/trunk/unittests/clangd/QualityTests.cpp Thu Jul
>> 5 01:14:04 2018
>> @@ -21,6 +21,9 @@
>> #include "Quality.h"
>> #include "TestFS.h"
>> #include "TestTU.h"
>> +#include "clang/AST/Decl.h"
>> +#include "clang/AST/DeclCXX.h"
>> +#include "llvm/Support/Casting.h"
>> #include "gmock/gmock.h"
>> #include "gtest/gtest.h"
>> @@ -199,6 +202,31 @@ TEST(QualityTests, SortText) {
>> EXPECT_LT(sortText(0, "a"), sortText(0, "z"));
>> }
>> +TEST(QualityTests, NoBoostForClassConstructor) {
>> + auto Header = TestTU::withHeaderCode(R"cpp(
>> + class Foo {
>> + public:
>> + Foo(int);
>> + };
>> + )cpp");
>> + auto Symbols = Header.headerSymbols();
>> + auto AST = Header.build();
>> +
>> + const NamedDecl *Foo = &findDecl(AST, "Foo");
>> + SymbolRelevanceSignals Cls;
>> + Cls.merge(CodeCompletionResult(Foo, /*Priority=*/0));
>> +
>> + const NamedDecl *CtorDecl = &findAnyDecl(AST, [](const NamedDecl
>> &ND) {
>> + return (ND.getQualifiedNameAsString() == "Foo::Foo") &&
>> + llvm::isa<CXXConstructorDecl>(&ND);
>> + });
>> + SymbolRelevanceSignals Ctor;
>> + Ctor.merge(CodeCompletionResult(CtorDecl, /*Priority=*/0));
>> +
>> + EXPECT_EQ(Cls.Scope, SymbolRelevanceSignals::GlobalScope);
>> + EXPECT_EQ(Ctor.Scope, SymbolRelevanceSignals::GlobalScope);
>> +}
>> +
>> } // namespace
>> } // namespace clangd
>> } // namespace clang
>>
>> Modified: clang-tools-extra/trunk/unittests/clangd/TestTU.cpp
>> URL:
>> http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/unittests/clangd/TestTU.cpp?rev=336318&r1=336317&r2=336318&view=diff
>>
>> ==============================================================================
>>
>> --- clang-tools-extra/trunk/unittests/clangd/TestTU.cpp (original)
>> +++ clang-tools-extra/trunk/unittests/clangd/TestTU.cpp Thu Jul 5
>> 01:14:04 2018
>> @@ -93,26 +93,35 @@ const NamedDecl &findDecl(ParsedAST &AST
>> return LookupDecl(*Scope, Components.back());
>> }
>> -const NamedDecl &findAnyDecl(ParsedAST &AST, llvm::StringRef Name) {
>> +const NamedDecl &findAnyDecl(ParsedAST &AST,
>> + std::function<bool(const NamedDecl &)>
>> Callback) {
>> struct Visitor : RecursiveASTVisitor<Visitor> {
>> - llvm::StringRef Name;
>> + decltype(Callback) CB;
>> llvm::SmallVector<const NamedDecl *, 1> Decls;
>> bool VisitNamedDecl(const NamedDecl *ND) {
>> - if (auto *ID = ND->getIdentifier())
>> - if (ID->getName() == Name)
>> - Decls.push_back(ND);
>> + if (CB(*ND))
>> + Decls.push_back(ND);
>> return true;
>> }
>> } Visitor;
>> - Visitor.Name = Name;
>> + Visitor.CB = Callback;
>> for (Decl *D : AST.getLocalTopLevelDecls())
>> Visitor.TraverseDecl(D);
>> if (Visitor.Decls.size() != 1) {
>> - ADD_FAILURE() << Visitor.Decls.size() << " symbols named " << Name;
>> + ADD_FAILURE() << Visitor.Decls.size() << " symbols matched.";
>> assert(Visitor.Decls.size() == 1);
>> }
>> return *Visitor.Decls.front();
>> }
>> +const NamedDecl &findAnyDecl(ParsedAST &AST, llvm::StringRef Name) {
>> + return findAnyDecl(AST, [Name](const NamedDecl &ND) {
>> + if (auto *ID = ND.getIdentifier())
>> + if (ID->getName() == Name)
>> + return true;
>> + return false;
>> + });
>> +}
>> +
>> } // namespace clangd
>> } // namespace clang
>>
>> Modified: clang-tools-extra/trunk/unittests/clangd/TestTU.h
>> URL:
>> http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/unittests/clangd/TestTU.h?rev=336318&r1=336317&r2=336318&view=diff
>>
>> ==============================================================================
>>
>> --- clang-tools-extra/trunk/unittests/clangd/TestTU.h (original)
>> +++ clang-tools-extra/trunk/unittests/clangd/TestTU.h Thu Jul 5
>> 01:14:04 2018
>> @@ -56,6 +56,9 @@ struct TestTU {
>> const Symbol &findSymbol(const SymbolSlab &, llvm::StringRef QName);
>> // Look up an AST symbol by qualified name, which must be unique and
>> top-level.
>> const NamedDecl &findDecl(ParsedAST &AST, llvm::StringRef QName);
>> +// Look up a main-file AST symbol that satisfies \p Filter.
>> +const NamedDecl &findAnyDecl(ParsedAST &AST,
>> + std::function<bool(const NamedDecl &)>
>> Filter);
>> // Look up a main-file AST symbol by unqualified name, which must be
>> unique.
>> const NamedDecl &findAnyDecl(ParsedAST &AST, llvm::StringRef Name);
>>
>>
>> _______________________________________________
>> cfe-commits mailing list
>> cfe-commits at lists.llvm.org
>> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
>>
> _______________________________________________
> cfe-commits mailing list
> cfe-commits at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
More information about the cfe-commits
mailing list