Skip to content

Commit 0ebaa7a

Browse files
access specifier filtering, and another case of the type-parameter-N-M problem cracked.
1 parent 8c0a344 commit 0ebaa7a

16 files changed

+247
-40
lines changed

emitters/yaml_base_emitter.cpp

+25-2
Original file line numberDiff line numberDiff line change
@@ -631,6 +631,24 @@ bool yaml_base_emitter::reconcile(json expected,
631631
static const std::string front_matter_delimiter_k("---\n");
632632
bool failure{false};
633633

634+
/* begin hack */ {
635+
// I hope to remove this soon. Paths with '...' in them make Perforce go
636+
// stir-crazy (it's a special token for the tool), so we remove them.
637+
static const std::string needle = "...";
638+
std::string p_str = path.string();
639+
auto pos = 0;
640+
auto found = false;
641+
while (true) {
642+
pos = p_str.find(needle, pos);
643+
if (pos == std::string::npos) break;
644+
found = true;
645+
p_str.replace(pos, needle.size(), "");
646+
}
647+
if (found) {
648+
path = boost::filesystem::path(p_str);
649+
}
650+
}
651+
634652
std::string relative_path(("." / relative(path, root_path)).string());
635653

636654
failure |= create_path_directories(path);
@@ -716,8 +734,13 @@ std::string yaml_base_emitter::subcomponent(const boost::filesystem::path& src_p
716734
void yaml_base_emitter::maybe_annotate(const json& j, json& node) {
717735
std::string annotation;
718736

719-
if (j.count("access"))
720-
node["annotation"].push_back(static_cast<const std::string&>(j["access"]));
737+
if (j.count("access")) {
738+
const std::string& access = j["access"];
739+
740+
if (access != "public") {
741+
node["annotation"].push_back(access);
742+
}
743+
}
721744

722745
if (j.count("default") && j["default"])
723746
node["annotation"].push_back("default");

matchers/class_matcher.cpp

+24-6
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ NOTICE: Adobe permits you to use, modify, and distribute this file in
66
accordance with the terms of the Adobe license agreement accompanying
77
it. If you have received this file from a source other than Adobe,
88
then 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,8 +62,11 @@ class FindConstructor : public RecursiveASTVisitor<FindConstructor> {
6262

6363
class FindStaticMembers : public RecursiveASTVisitor<FindStaticMembers> {
6464
public:
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) {
@@ -80,6 +83,7 @@ class FindStaticMembers : public RecursiveASTVisitor<FindStaticMembers> {
8083

8184
private:
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);
143154
fieldInfo["type"] = hyde::to_string(Result.Context, 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,6 +171,8 @@ 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);
162177
typedefInfo["type"] = hyde::to_string(Result.Context, type_def->getUnderlyingType());
163178

@@ -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);
174191
typealiasInfo["type"] = hyde::to_string(Result.Context, 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));

matchers/class_matcher.hpp

+5-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ NOTICE: Adobe permits you to use, modify, and distribute this file in
66
accordance with the terms of the Adobe license agreement accompanying
77
it. If you have received this file from a source other than Adobe,
88
then your use, modification, or distribution of it requires the prior
9-
written permission of Adobe.
9+
written permission of Adobe.
1010
*/
1111

1212
#pragma once
@@ -17,6 +17,7 @@ written permission of Adobe.
1717

1818
// application
1919
#include "json.hpp"
20+
#include "matchers/matcher_fwd.hpp"
2021

2122
using namespace clang;
2223
using namespace clang::ast_matchers;
@@ -29,7 +30,8 @@ namespace hyde {
2930

3031
class ClassInfo : public MatchFinder::MatchCallback {
3132
public:
32-
explicit ClassInfo(std::vector<std::string> paths) : _paths(std::move(paths)) {
33+
explicit ClassInfo(std::vector<std::string> paths, ToolAccessFilter filter)
34+
: _paths(std::move(paths)), _access_filter(filter) {
3335
_j["class"] = json::array();
3436
}
3537

@@ -41,6 +43,7 @@ class ClassInfo : public MatchFinder::MatchCallback {
4143

4244
private:
4345
std::vector<std::string> _paths;
46+
ToolAccessFilter _access_filter;
4447
json _j;
4548
};
4649

matchers/enum_matcher.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ void EnumInfo::run(const MatchFinder::MatchResult& Result) {
3838

3939
if (!PathCheck(_paths, enumeration, Result.Context)) return;
4040

41+
if (!AccessCheck(_access_filter, enumeration->getAccess())) return;
42+
4143
json info = StandardDeclInfo(Result.Context, enumeration);
4244
//info["scoped"] = enumeration->isScoped();
4345
//info["fixed"] = enumeration->isFixed();

matchers/enum_matcher.hpp

+5-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ NOTICE: Adobe permits you to use, modify, and distribute this file in
66
accordance with the terms of the Adobe license agreement accompanying
77
it. If you have received this file from a source other than Adobe,
88
then your use, modification, or distribution of it requires the prior
9-
written permission of Adobe.
9+
written permission of Adobe.
1010
*/
1111

1212
#pragma once
@@ -17,6 +17,7 @@ written permission of Adobe.
1717

1818
// application
1919
#include "json.hpp"
20+
#include "matchers/matcher_fwd.hpp"
2021

2122
using namespace clang;
2223
using namespace clang::ast_matchers;
@@ -29,7 +30,8 @@ namespace hyde {
2930

3031
class EnumInfo : public MatchFinder::MatchCallback {
3132
public:
32-
EnumInfo(std::vector<std::string> paths) : _paths(std::move(paths)) {
33+
EnumInfo(std::vector<std::string> paths, ToolAccessFilter filter)
34+
: _paths(std::move(paths)), _access_filter(filter) {
3335
_j["enums"] = json::array();
3436
}
3537

@@ -41,6 +43,7 @@ class EnumInfo : public MatchFinder::MatchCallback {
4143

4244
private:
4345
std::vector<std::string> _paths;
46+
ToolAccessFilter _access_filter;
4447
json _j;
4548
};
4649

matchers/function_matcher.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ void FunctionInfo::run(const MatchFinder::MatchResult& Result) {
4242

4343
if (!PathCheck(_paths, function, Result.Context)) return;
4444

45+
if (!AccessCheck(_access_filter, function->getAccess())) return;
46+
4547
auto info = DetailFunctionDecl(Result.Context, function);
4648

4749
_j["functions"][static_cast<const std::string&>(info["short_name"])].

matchers/function_matcher.hpp

+5-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ NOTICE: Adobe permits you to use, modify, and distribute this file in
66
accordance with the terms of the Adobe license agreement accompanying
77
it. If you have received this file from a source other than Adobe,
88
then your use, modification, or distribution of it requires the prior
9-
written permission of Adobe.
9+
written permission of Adobe.
1010
*/
1111

1212
#pragma once
@@ -17,6 +17,7 @@ written permission of Adobe.
1717

1818
// application
1919
#include "json.hpp"
20+
#include "matchers/matcher_fwd.hpp"
2021

2122
using namespace clang;
2223
using namespace clang::ast_matchers;
@@ -29,7 +30,8 @@ namespace hyde {
2930

3031
class FunctionInfo : public MatchFinder::MatchCallback {
3132
public:
32-
FunctionInfo(std::vector<std::string> paths) : _paths(std::move(paths)) {
33+
FunctionInfo(std::vector<std::string> paths, ToolAccessFilter filter)
34+
: _paths(std::move(paths)), _access_filter(filter) {
3335
_j["functions"] = json::object();
3436
}
3537

@@ -41,6 +43,7 @@ class FunctionInfo : public MatchFinder::MatchCallback {
4143

4244
private:
4345
std::vector<std::string> _paths;
46+
ToolAccessFilter _access_filter;
4447
json _j;
4548
};
4649

matchers/namespace_matcher.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ void NamespaceInfo::run(const MatchFinder::MatchResult& Result) {
3838

3939
if (!PathCheck(_paths, ns, Result.Context)) return;
4040

41+
if (!AccessCheck(_access_filter, ns->getAccess())) return;
42+
4143
_j["namespaces"].push_back(StandardDeclInfo(Result.Context, ns));
4244
}
4345

matchers/namespace_matcher.hpp

+5-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ NOTICE: Adobe permits you to use, modify, and distribute this file in
66
accordance with the terms of the Adobe license agreement accompanying
77
it. If you have received this file from a source other than Adobe,
88
then your use, modification, or distribution of it requires the prior
9-
written permission of Adobe.
9+
written permission of Adobe.
1010
*/
1111

1212
#pragma once
@@ -17,6 +17,7 @@ written permission of Adobe.
1717

1818
// application
1919
#include "json.hpp"
20+
#include "matchers/matcher_fwd.hpp"
2021

2122
using namespace clang;
2223
using namespace clang::ast_matchers;
@@ -29,7 +30,8 @@ namespace hyde {
2930

3031
class NamespaceInfo : public MatchFinder::MatchCallback {
3132
public:
32-
NamespaceInfo(std::vector<std::string> paths) : _paths(std::move(paths)) {
33+
NamespaceInfo(std::vector<std::string> paths, ToolAccessFilter filter)
34+
: _paths(std::move(paths)), _access_filter(filter) {
3335
_j["namespaces"] = json::array();
3436
}
3537

@@ -41,6 +43,7 @@ class NamespaceInfo : public MatchFinder::MatchCallback {
4143

4244
private:
4345
std::vector<std::string> _paths;
46+
ToolAccessFilter _access_filter;
4447
json _j;
4548
};
4649

matchers/typealias_matcher.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ void TypeAliasInfo::run(const MatchFinder::MatchResult& Result) {
3838

3939
if (!PathCheck(_paths, node, Result.Context)) return;
4040

41+
if (!AccessCheck(_access_filter, node->getAccess())) return;
42+
4143
json info = StandardDeclInfo(Result.Context, node);
4244

4345
// do not process class type aliases here.

matchers/typealias_matcher.hpp

+5-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ NOTICE: Adobe permits you to use, modify, and distribute this file in
66
accordance with the terms of the Adobe license agreement accompanying
77
it. If you have received this file from a source other than Adobe,
88
then your use, modification, or distribution of it requires the prior
9-
written permission of Adobe.
9+
written permission of Adobe.
1010
*/
1111

1212
#pragma once
@@ -17,6 +17,7 @@ written permission of Adobe.
1717

1818
// application
1919
#include "json.hpp"
20+
#include "matchers/matcher_fwd.hpp"
2021

2122
using namespace clang;
2223
using namespace clang::ast_matchers;
@@ -29,7 +30,8 @@ namespace hyde {
2930

3031
class TypeAliasInfo : public MatchFinder::MatchCallback {
3132
public:
32-
TypeAliasInfo(std::vector<std::string> paths) : _paths(std::move(paths)) {
33+
TypeAliasInfo(std::vector<std::string> paths, ToolAccessFilter filter)
34+
: _paths(std::move(paths)), _access_filter(filter) {
3335
_j["typealiases"] = json::array();
3436
}
3537

@@ -41,6 +43,7 @@ class TypeAliasInfo : public MatchFinder::MatchCallback {
4143

4244
private:
4345
std::vector<std::string> _paths;
46+
ToolAccessFilter _access_filter;
4447
json _j;
4548
};
4649

matchers/typedef_matcher.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ void TypedefInfo::run(const MatchFinder::MatchResult& Result) {
3838

3939
if (!PathCheck(_paths, node, Result.Context)) return;
4040

41+
if (!AccessCheck(_access_filter, node->getAccess())) return;
42+
4143
json info = StandardDeclInfo(Result.Context, node);
4244

4345
// do not process class type aliases here.

0 commit comments

Comments
 (0)