@@ -6,7 +6,7 @@ NOTICE: Adobe permits you to use, modify, and distribute this file in
66accordance with the terms of the Adobe license agreement accompanying
77it. If you have received this file from a source other than Adobe,
88then your use, modification, or distribution of it requires the prior
9- written permission of Adobe.
9+ written permission of Adobe.
1010*/
1111
1212// identity
@@ -62,15 +62,18 @@ class FindConstructor : public RecursiveASTVisitor<FindConstructor> {
6262
6363class FindStaticMembers : public RecursiveASTVisitor <FindStaticMembers> {
6464public:
65- FindStaticMembers (ASTContext* context) : context(context), static_members(hyde::json::object()) {}
65+ FindStaticMembers (ASTContext* context, hyde::ToolAccessFilter access_filter)
66+ : context(context), _access_filter(access_filter), static_members(hyde::json::object()) {}
6667 bool VisitVarDecl (const VarDecl* d) {
68+ if (!AccessCheck (_access_filter, d->getAccess ())) return true ;
69+
6770 auto storage = d->getStorageClass ();
6871 // TODO(Wyles): Do we want to worry about other kinds of storage?
6972 if (storage == SC_Static) {
7073 auto type = hyde::StandardDeclInfo (context, d);
7174 auto name = type[" qualified_name" ].get <std::string>();
7275 type[" static" ] = true ;
73- type[" type" ] = hyde::to_string (context , d->getType ());
76+ type[" type" ] = hyde::to_string (d , d->getType ());
7477 static_members[name] = type;
7578 }
7679 return true ;
@@ -80,6 +83,7 @@ class FindStaticMembers : public RecursiveASTVisitor<FindStaticMembers> {
8083
8184private:
8285 ASTContext* context = nullptr ;
86+ hyde::ToolAccessFilter _access_filter;
8387 hyde::json static_members;
8488};
8589
@@ -92,6 +96,8 @@ void ClassInfo::run(const MatchFinder::MatchResult& Result) {
9296
9397 if (!PathCheck (_paths, clas, Result.Context )) return ;
9498
99+ if (!AccessCheck (_access_filter, clas->getAccess ())) return ;
100+
95101 if (!clas->isCompleteDefinition ()) return ; // e.g., a forward declaration.
96102
97103 if (clas->isLambda ()) return ;
@@ -100,8 +106,7 @@ void ClassInfo::run(const MatchFinder::MatchResult& Result) {
100106
101107 // e.g., compiler-injected class specializations not caught by the above
102108 if (auto s = llvm::dyn_cast_or_null<ClassTemplateSpecializationDecl>(clas)) {
103- if (!s->getTypeAsWritten ())
104- return ;
109+ if (!s->getTypeAsWritten ()) return ;
105110 }
106111
107112 json info = DetailCXXRecordDecl (Result.Context , clas);
@@ -116,20 +121,24 @@ void ClassInfo::run(const MatchFinder::MatchResult& Result) {
116121 dtor_finder.TraverseDecl (const_cast <Decl*>(static_cast <const Decl*>(clas)));
117122 if (!dtor_finder) info[" dtor" ] = " unspecified" ;
118123
119- FindStaticMembers static_finder (Result.Context );
124+ FindStaticMembers static_finder (Result.Context , _access_filter );
120125 static_finder.TraverseDecl (const_cast <Decl*>(static_cast <const Decl*>(clas)));
121126
122127 if (const auto & template_decl = clas->getDescribedClassTemplate ()) {
123128 info[" template_parameters" ] = GetTemplateParameters (Result.Context , template_decl);
124129 }
125130
126131 for (const auto & method : clas->methods ()) {
132+ if (!AccessCheck (_access_filter, method->getAccess ())) continue ;
133+
127134 json methodInfo = DetailFunctionDecl (Result.Context , method);
128135 info[" methods" ][static_cast <const std::string&>(methodInfo[" short_name" ])].push_back (
129136 std::move (methodInfo));
130137 }
131138
132139 for (const auto & decl : clas->decls ()) {
140+ if (!AccessCheck (_access_filter, decl->getAccess ())) continue ;
141+
133142 auto * function_template_decl = dyn_cast<FunctionTemplateDecl>(decl);
134143 if (!function_template_decl) continue ;
135144 json methodInfo =
@@ -139,12 +148,16 @@ void ClassInfo::run(const MatchFinder::MatchResult& Result) {
139148 }
140149
141150 for (const auto & field : clas->fields ()) {
151+ if (!AccessCheck (_access_filter, field->getAccess ())) continue ;
152+
142153 json fieldInfo = StandardDeclInfo (Result.Context , field);
143- fieldInfo[" type" ] = hyde::to_string (Result. Context , field->getType ());
154+ fieldInfo[" type" ] = hyde::to_string (field , field->getType ());
144155 info[" fields" ][static_cast <const std::string&>(fieldInfo[" qualified_name" ])] =
145156 fieldInfo; // can't move this into place for some reason.
146157 }
158+
147159 hyde::json static_members = static_finder.get_results ();
160+
148161 if (static_members.size () > 0 ) {
149162 if (info[" fields" ].size () == 0 ) {
150163 info[" fields" ] = hyde::json::object ();
@@ -158,8 +171,10 @@ void ClassInfo::run(const MatchFinder::MatchResult& Result) {
158171 typedef_iterator (CXXRecordDecl::decl_iterator ()));
159172 for (const auto & type_def : typedefs) {
160173 // REVISIT (fbrereto) : Refactor this block and TypedefInfo::run's.
174+ if (!AccessCheck (_access_filter, type_def->getAccess ())) continue ;
175+
161176 json typedefInfo = StandardDeclInfo (Result.Context , type_def);
162- typedefInfo[" type" ] = hyde::to_string (Result. Context , type_def->getUnderlyingType ());
177+ typedefInfo[" type" ] = hyde::to_string (type_def , type_def->getUnderlyingType ());
163178
164179 info[" typedefs" ].push_back (std::move (typedefInfo));
165180 }
@@ -170,10 +185,13 @@ void ClassInfo::run(const MatchFinder::MatchResult& Result) {
170185 typealias_iterator (CXXRecordDecl::decl_iterator ()));
171186 for (const auto & type_alias : typealiases) {
172187 // REVISIT (fbrereto) : Refactor this block and TypeAliasInfo::run's.
188+ if (!AccessCheck (_access_filter, type_alias->getAccess ())) continue ;
189+
173190 json typealiasInfo = StandardDeclInfo (Result.Context , type_alias);
174- typealiasInfo[" type" ] = hyde::to_string (Result. Context , type_alias->getUnderlyingType ());
191+ typealiasInfo[" type" ] = hyde::to_string (type_alias , type_alias->getUnderlyingType ());
175192 if (auto template_decl = type_alias->getDescribedAliasTemplate ()) {
176- typealiasInfo[" template_parameters" ] = GetTemplateParameters (Result.Context , template_decl);
193+ typealiasInfo[" template_parameters" ] =
194+ GetTemplateParameters (Result.Context , template_decl);
177195 }
178196
179197 info[" typealiases" ].push_back (std::move (typealiasInfo));
0 commit comments