]> granicus.if.org Git - clang/commitdiff
Make sure that we look into nested, transparent declaration contexts
authorDouglas Gregor <dgregor@apple.com>
Mon, 9 Nov 2009 21:35:27 +0000 (21:35 +0000)
committerDouglas Gregor <dgregor@apple.com>
Mon, 9 Nov 2009 21:35:27 +0000 (21:35 +0000)
when looking for a name within a given DeclContext. Now enumerators
will show up in code-completion results.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@86591 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Sema/SemaCodeComplete.cpp
test/Index/code-completion.cpp
tools/CIndex/CIndex.cpp

index c6323956cc91945c2ad3cebb7fa70b71c5d45300..072dfe9b73ad7d30cc16d9de11e8c902e2b2049e 100644 (file)
@@ -473,17 +473,24 @@ static unsigned CollectMemberLookupResults(DeclContext *Ctx,
   for (DeclContext *CurCtx = Ctx->getPrimaryContext(); CurCtx; 
        CurCtx = CurCtx->getNextContext()) {
     for (DeclContext::decl_iterator D = CurCtx->decls_begin(), 
-         DEnd = CurCtx->decls_end();
+                                 DEnd = CurCtx->decls_end();
          D != DEnd; ++D) {
       if (NamedDecl *ND = dyn_cast<NamedDecl>(*D))
         Results.MaybeAddResult(Result(ND, Rank, 0, InBaseClass), CurContext);
+      
+      // Visit transparent contexts inside this context.
+      if (DeclContext *InnerCtx = dyn_cast<DeclContext>(*D)) {
+        if (InnerCtx->isTransparentContext())
+          CollectMemberLookupResults(InnerCtx, Rank, CurContext, Visited,
+                                     Results, InBaseClass);
+      }
     }
   }
   
   // Traverse the contexts of inherited classes.
   if (CXXRecordDecl *Record = dyn_cast<CXXRecordDecl>(Ctx)) {
     for (CXXRecordDecl::base_class_iterator B = Record->bases_begin(),
-         BEnd = Record->bases_end();
+                                         BEnd = Record->bases_end();
          B != BEnd; ++B) {
       QualType BaseType = B->getType();
       
index 313e56d733935fec53bf9392384826752bb3d960..44bd9d28932e52e09700cb494deebb9090c750f5 100644 (file)
@@ -2,6 +2,8 @@
 #include "nonexistent_header.h"
 struct X {
   int member;
+  
+  enum E { Val1 };
 };
 
 struct Y {
@@ -17,7 +19,7 @@ struct Z : X, Y {
 struct Z get_Z();
 
 void test_Z() {
-  // RUN: c-index-test -code-completion-at=%s:21:11 %s | FileCheck -check-prefix=CHECK-MEMBER %s
+  // RUN: c-index-test -code-completion-at=%s:23:11 %s | FileCheck -check-prefix=CHECK-MEMBER %s
   get_Z().member = 17;
 }
 
@@ -27,12 +29,14 @@ double& overloaded(float f, int second);
 int& overloaded(Z z, int second);
                 
 void test_overloaded() {
-  // RUN: c-index-test -code-completion-at=%s:31:18 %s | FileCheck -check-prefix=CHECK-OVERLOAD %s
+  // RUN: c-index-test -code-completion-at=%s:33:18 %s | FileCheck -check-prefix=CHECK-OVERLOAD %s
   overloaded(Z(), 0);
 }
 
+// CHECK-MEMBER: EnumDecl:{Informative X::}{TypedText E}
 // CHECK-MEMBER: FieldDecl:{TypedText member}
 // CHECK-MEMBER: FunctionDecl:{Informative Y::}{TypedText memfunc}{LeftParen (}{Optional {Placeholder int i}}{RightParen )}
+// CHECK-MEMBER: EnumConstantDecl:{Informative E::}{TypedText Val1}
 // CHECK-MEMBER: FunctionDecl:{Informative X::}{TypedText ~X}{LeftParen (}{RightParen )}
 // CHECK-MEMBER: FunctionDecl:{TypedText operator int}{LeftParen (}{RightParen )}
 // CHECK-MEMBER: FunctionDecl:{TypedText operator=}{LeftParen (}{Placeholder struct Z const &}{RightParen )}
index 33d2032abaf18234e56300362c41e9f1105696a7..c98d14264adec32203949f2d9c8be9be020ca25f 100644 (file)
@@ -1141,6 +1141,7 @@ static CXCursorKind parseResultKind(llvm::StringRef Str) {
     .Case("Struct", CXCursor_StructDecl)
     .Case("Union", CXCursor_UnionDecl)
     .Case("Class", CXCursor_ClassDecl)
+    .Case("Enum", CXCursor_EnumDecl)
     .Case("Field", CXCursor_FieldDecl)
     .Case("EnumConstant", CXCursor_EnumConstantDecl)
     .Case("Function", CXCursor_FunctionDecl)