Unifies the name-lookup mechanisms used in various parts of the AST
and separates lexical name lookup from qualified name lookup. In
particular:
  * Make DeclContext the central data structure for storing and
    looking up declarations within existing declarations, e.g., members
    of structs/unions/classes, enumerators in C++0x enums, members of
    C++ namespaces, and (later) members of Objective-C
    interfaces/implementations. DeclContext uses a lazily-constructed
    data structure optimized for fast lookup (array for small contexts,
    hash table for larger contexts). 

  * Implement C++ qualified name lookup in terms of lookup into
    DeclContext.

  * Implement C++ unqualified name lookup in terms of
    qualified+unqualified name lookup (since unqualified lookup is not
    purely lexical in C++!)

  * Limit the use of the chains of declarations stored in
    IdentifierInfo to those names declared lexically.

  * Eliminate CXXFieldDecl, collapsing its behavior into
    FieldDecl. (FieldDecl is now a ScopedDecl).

  * Make RecordDecl into a DeclContext and eliminates its
    Members/NumMembers fields (since one can just iterate through the
    DeclContext to get the fields).



git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@60878 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Sema/SemaCXXScopeSpec.cpp b/lib/Sema/SemaCXXScopeSpec.cpp
index 1f92b6f..d01552c 100644
--- a/lib/Sema/SemaCXXScopeSpec.cpp
+++ b/lib/Sema/SemaCXXScopeSpec.cpp
@@ -20,7 +20,25 @@
 

 namespace {

   Decl *LookupNestedName(DeclContext *LookupCtx, bool LookInParentCtx,

-                         DeclarationName Name, bool &IdIsUndeclared) {

+                         DeclarationName Name, bool &IdIsUndeclared,

+                        ASTContext &Context) {

+    if (LookupCtx && !LookInParentCtx) {

+      IdIsUndeclared = true;

+      for (DeclContext::lookup_const_result I = LookupCtx->lookup(Context, Name);

+          I.first != I.second; ++I.first) {

+       IdIsUndeclared = false;

+       if (((*I.first)->getIdentifierNamespace() & Decl::IDNS_Tag) &&

+           !isa<EnumDecl>(*I.first))

+         return *I.first;

+      }

+

+      return 0;

+    }

+

+    // FIXME: Decouple this from the IdentifierResolver so that we can

+    // deal with lookups into the semantic parent contexts that aren't

+    // lexical parent contexts.

+

     IdentifierResolver::iterator

       I = IdentifierResolver::begin(Name, LookupCtx, LookInParentCtx),

       E = IdentifierResolver::end();

@@ -73,10 +91,11 @@
   bool IdIsUndeclared;

 

   if (DC)

-    SD = LookupNestedName(DC, false/*LookInParentCtx*/, &II, IdIsUndeclared);

+    SD = LookupNestedName(DC, false/*LookInParentCtx*/, &II, IdIsUndeclared,

+                         Context);

   else

     SD = LookupNestedName(CurContext, true/*LookInParent*/, &II, 

-                          IdIsUndeclared);

+                          IdIsUndeclared, Context);

 

   if (SD) {

     if (TypedefDecl *TD = dyn_cast<TypedefDecl>(SD)) {