[PATCH] D13383: [clang] Add flag to DeclContext to distinguish between qualified and unqualified name lookups
Eugene Leviant via cfe-commits
cfe-commits at lists.llvm.org
Fri Oct 2 05:25:24 PDT 2015
evgeny777 created this revision.
evgeny777 added reviewers: aaron.ballman, klimek.
evgeny777 added subscribers: cfe-commits, dawn, KLapshin.
Hi, all!
Currently lldb evaluation of qualified global variables does not work properly.
I've created a revision addressing the issue, which is here:
http://reviews.llvm.org/D13350
To fix the issue in lldb one has to distinguish between qualified and unqualified identifier lookups. In case of qualified lookup the identifier search scope is restricted to DeclContext::DeclKind (Namespace, TranslationUnit). For unqualified lookups scopes are being searched from bottom to top, until you get the first name match
http://reviews.llvm.org/D13383
Files:
clang/include/clang/AST/DeclBase.h
clang/lib/Sema/SemaLookup.cpp
Index: clang/lib/Sema/SemaLookup.cpp
===================================================================
--- clang/lib/Sema/SemaLookup.cpp
+++ clang/lib/Sema/SemaLookup.cpp
@@ -204,6 +204,13 @@
UnqualUsingEntry::Comparator()));
}
};
+
+ class Deinitializer {
+ std::function<void()> Deinit;
+ public:
+ Deinitializer(const std::function<void()>& d): Deinit(d) {}
+ ~Deinitializer() { Deinit(); }
+ };
}
// Retrieve the set of identifier namespaces that correspond to a
@@ -1852,6 +1859,9 @@
"Declaration context must already be complete!");
// Perform qualified name lookup into the LookupCtx.
+ bool oldval = LookupCtx->setUseQualifiedLookup();
+ Deinitializer deinit([&]() { LookupCtx->setUseQualifiedLookup(oldval); });
+
if (LookupDirect(*this, R, LookupCtx)) {
R.resolveKind();
if (isa<CXXRecordDecl>(LookupCtx))
Index: clang/include/clang/AST/DeclBase.h
===================================================================
--- clang/include/clang/AST/DeclBase.h
+++ clang/include/clang/AST/DeclBase.h
@@ -1142,6 +1142,11 @@
/// that are missing from the lookup table.
mutable bool HasLazyExternalLexicalLookups : 1;
+ /// \brief If \c true, lookups should only return identifier from
+ /// DeclContext scope (for example TranslationUnit). Used in
+ /// LookupQualifiedName()
+ mutable bool UseQualifiedLookup : 1;
+
/// \brief Pointer to the data structure used to lookup declarations
/// within this context (or a DependentStoredDeclsMap if this is a
/// dependent context). We maintain the invariant that, if the map
@@ -1176,6 +1181,7 @@
ExternalVisibleStorage(false),
NeedToReconcileExternalVisibleStorage(false),
HasLazyLocalLexicalLookups(false), HasLazyExternalLexicalLookups(false),
+ UseQualifiedLookup(false),
LookupPtr(nullptr), FirstDecl(nullptr), LastDecl(nullptr) {}
public:
@@ -1756,6 +1762,16 @@
D == LastDecl);
}
+ bool setUseQualifiedLookup(bool use = true) {
+ bool old_value = UseQualifiedLookup;
+ UseQualifiedLookup = use;
+ return old_value;
+ }
+
+ bool shouldUseQualifiedLookup() const {
+ return UseQualifiedLookup;
+ }
+
static bool classof(const Decl *D);
static bool classof(const DeclContext *D) { return true; }
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D13383.36346.patch
Type: text/x-patch
Size: 2364 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20151002/583f0e28/attachment.bin>
More information about the cfe-commits
mailing list