@@ -498,7 +498,7 @@ namespace Cpp {
498
498
499
499
TCppScope_t GetGlobalScope ()
500
500
{
501
- return getSema ().getASTContext ().getTranslationUnitDecl ();
501
+ return getSema ().getASTContext ().getTranslationUnitDecl ()-> getFirstDecl () ;
502
502
}
503
503
504
504
static Decl *GetScopeFromType (QualType QT) {
@@ -604,8 +604,12 @@ namespace Cpp {
604
604
if (!ParentDC)
605
605
return 0 ;
606
606
607
- return (TCppScope_t) clang::Decl::castFromDeclContext (
608
- ParentDC)->getCanonicalDecl ();
607
+ auto * P = clang::Decl::castFromDeclContext (ParentDC)->getCanonicalDecl ();
608
+
609
+ if (auto * TU = llvm::dyn_cast_or_null<TranslationUnitDecl>(P))
610
+ return (TCppScope_t)TU->getFirstDecl ();
611
+
612
+ return (TCppScope_t)P;
609
613
}
610
614
611
615
TCppIndex_t GetNumBases (TCppScope_t klass)
@@ -3088,27 +3092,22 @@ namespace Cpp {
3088
3092
}
3089
3093
3090
3094
void GetEnums (TCppScope_t scope, std::vector<std::string>& Result) {
3091
- auto *D = (clang::Decl *)scope;
3092
- clang::DeclContext *DC;
3093
- clang::DeclContext::decl_iterator decl;
3095
+ auto * D = static_cast <clang::Decl*>(scope);
3094
3096
3095
- if (auto *TD = dyn_cast_or_null<TagDecl>(D)) {
3096
- DC = clang::TagDecl::castToDeclContext (TD);
3097
- decl = DC->decls_begin ();
3098
- decl++;
3099
- } else if (auto *ND = dyn_cast_or_null<NamespaceDecl>(D)) {
3100
- DC = clang::NamespaceDecl::castToDeclContext (ND);
3101
- decl = DC->decls_begin ();
3102
- } else if (auto *TUD = dyn_cast_or_null<TranslationUnitDecl>(D)) {
3103
- DC = clang::TranslationUnitDecl::castToDeclContext (TUD);
3104
- decl = DC->decls_begin ();
3105
- } else {
3097
+ if (!llvm::isa_and_nonnull<clang::DeclContext>(D))
3106
3098
return ;
3107
- }
3108
3099
3109
- for (/* decl set above */ ; decl != DC->decls_end (); decl++) {
3110
- if (auto *ND = llvm::dyn_cast_or_null<EnumDecl>(*decl)) {
3111
- Result.push_back (ND->getNameAsString ());
3100
+ auto * DC = llvm::dyn_cast<clang::DeclContext>(D);
3101
+
3102
+ llvm::SmallVector<clang::DeclContext*, 4 > DCs;
3103
+ DC->collectAllContexts (DCs);
3104
+
3105
+ // FIXME: We should use a lookup based approach instead of brute force
3106
+ for (auto * DC : DCs) {
3107
+ for (auto decl = DC->decls_begin (); decl != DC->decls_end (); decl++) {
3108
+ if (auto * ND = llvm::dyn_cast_or_null<EnumDecl>(*decl)) {
3109
+ Result.push_back (ND->getNameAsString ());
3110
+ }
3112
3111
}
3113
3112
}
3114
3113
}
0 commit comments