@@ -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)
@@ -3074,27 +3078,22 @@ namespace Cpp {
3074
3078
}
3075
3079
3076
3080
void GetEnums (TCppScope_t scope, std::vector<std::string>& Result) {
3077
- auto *D = (clang::Decl *)scope;
3078
- clang::DeclContext *DC;
3079
- clang::DeclContext::decl_iterator decl;
3081
+ auto * D = static_cast <clang::Decl*>(scope);
3080
3082
3081
- if (auto *TD = dyn_cast_or_null<TagDecl>(D)) {
3082
- DC = clang::TagDecl::castToDeclContext (TD);
3083
- decl = DC->decls_begin ();
3084
- decl++;
3085
- } else if (auto *ND = dyn_cast_or_null<NamespaceDecl>(D)) {
3086
- DC = clang::NamespaceDecl::castToDeclContext (ND);
3087
- decl = DC->decls_begin ();
3088
- } else if (auto *TUD = dyn_cast_or_null<TranslationUnitDecl>(D)) {
3089
- DC = clang::TranslationUnitDecl::castToDeclContext (TUD);
3090
- decl = DC->decls_begin ();
3091
- } else {
3083
+ if (!llvm::isa_and_nonnull<clang::DeclContext>(D))
3092
3084
return ;
3093
- }
3094
3085
3095
- for (/* decl set above */ ; decl != DC->decls_end (); decl++) {
3096
- if (auto *ND = llvm::dyn_cast_or_null<EnumDecl>(*decl)) {
3097
- Result.push_back (ND->getNameAsString ());
3086
+ auto * DC = llvm::dyn_cast<clang::DeclContext>(D);
3087
+
3088
+ llvm::SmallVector<clang::DeclContext*, 4 > DCs;
3089
+ DC->collectAllContexts (DCs);
3090
+
3091
+ // FIXME: We should use a lookup based approach instead of brute force
3092
+ for (auto * DC : DCs) {
3093
+ for (auto decl = DC->decls_begin (); decl != DC->decls_end (); decl++) {
3094
+ if (auto * ND = llvm::dyn_cast_or_null<EnumDecl>(*decl)) {
3095
+ Result.push_back (ND->getNameAsString ());
3096
+ }
3098
3097
}
3099
3098
}
3100
3099
}
0 commit comments