Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 25 additions & 2 deletions emitters/yaml_base_emitter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -631,6 +631,24 @@ bool yaml_base_emitter::reconcile(json expected,
static const std::string front_matter_delimiter_k("---\n");
bool failure{false};

/* begin hack */ {
// I hope to remove this soon. Paths with '...' in them make Perforce go
// stir-crazy (it's a special token for the tool), so we remove them.
static const std::string needle = "...";
std::string p_str = path.string();
auto pos = 0;
auto found = false;
while (true) {
pos = p_str.find(needle, pos);
if (pos == std::string::npos) break;
found = true;
p_str.replace(pos, needle.size(), "");
}
if (found) {
path = boost::filesystem::path(p_str);
}
}

std::string relative_path(("." / relative(path, root_path)).string());

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

if (j.count("access"))
node["annotation"].push_back(static_cast<const std::string&>(j["access"]));
if (j.count("access")) {
const std::string& access = j["access"];

if (access != "public") {
node["annotation"].push_back(access);
}
}

if (j.count("default") && j["default"])
node["annotation"].push_back("default");
Expand Down
38 changes: 28 additions & 10 deletions matchers/class_matcher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ NOTICE: Adobe permits you to use, modify, and distribute this file in
accordance with the terms of the Adobe license agreement accompanying
it. If you have received this file from a source other than Adobe,
then your use, modification, or distribution of it requires the prior
written permission of Adobe.
written permission of Adobe.
*/

// identity
Expand Down Expand Up @@ -62,15 +62,18 @@ class FindConstructor : public RecursiveASTVisitor<FindConstructor> {

class FindStaticMembers : public RecursiveASTVisitor<FindStaticMembers> {
public:
FindStaticMembers(ASTContext* context) : context(context), static_members(hyde::json::object()) {}
FindStaticMembers(ASTContext* context, hyde::ToolAccessFilter access_filter)
: context(context), _access_filter(access_filter), static_members(hyde::json::object()) {}
bool VisitVarDecl(const VarDecl* d) {
if (!AccessCheck(_access_filter, d->getAccess())) return true;

auto storage = d->getStorageClass();
// TODO(Wyles): Do we want to worry about other kinds of storage?
if (storage == SC_Static) {
auto type = hyde::StandardDeclInfo(context, d);
auto name = type["qualified_name"].get<std::string>();
type["static"] = true;
type["type"] = hyde::to_string(context, d->getType());
type["type"] = hyde::to_string(d, d->getType());
static_members[name] = type;
}
return true;
Expand All @@ -80,6 +83,7 @@ class FindStaticMembers : public RecursiveASTVisitor<FindStaticMembers> {

private:
ASTContext* context = nullptr;
hyde::ToolAccessFilter _access_filter;
hyde::json static_members;
};

Expand All @@ -92,6 +96,8 @@ void ClassInfo::run(const MatchFinder::MatchResult& Result) {

if (!PathCheck(_paths, clas, Result.Context)) return;

if (!AccessCheck(_access_filter, clas->getAccess())) return;

if (!clas->isCompleteDefinition()) return; // e.g., a forward declaration.

if (clas->isLambda()) return;
Expand All @@ -100,8 +106,7 @@ void ClassInfo::run(const MatchFinder::MatchResult& Result) {

// e.g., compiler-injected class specializations not caught by the above
if (auto s = llvm::dyn_cast_or_null<ClassTemplateSpecializationDecl>(clas)) {
if (!s->getTypeAsWritten())
return;
if (!s->getTypeAsWritten()) return;
}

json info = DetailCXXRecordDecl(Result.Context, clas);
Expand All @@ -116,20 +121,24 @@ void ClassInfo::run(const MatchFinder::MatchResult& Result) {
dtor_finder.TraverseDecl(const_cast<Decl*>(static_cast<const Decl*>(clas)));
if (!dtor_finder) info["dtor"] = "unspecified";

FindStaticMembers static_finder(Result.Context);
FindStaticMembers static_finder(Result.Context, _access_filter);
static_finder.TraverseDecl(const_cast<Decl*>(static_cast<const Decl*>(clas)));

if (const auto& template_decl = clas->getDescribedClassTemplate()) {
info["template_parameters"] = GetTemplateParameters(Result.Context, template_decl);
}

for (const auto& method : clas->methods()) {
if (!AccessCheck(_access_filter, method->getAccess())) continue;

json methodInfo = DetailFunctionDecl(Result.Context, method);
info["methods"][static_cast<const std::string&>(methodInfo["short_name"])].push_back(
std::move(methodInfo));
}

for (const auto& decl : clas->decls()) {
if (!AccessCheck(_access_filter, decl->getAccess())) continue;

auto* function_template_decl = dyn_cast<FunctionTemplateDecl>(decl);
if (!function_template_decl) continue;
json methodInfo =
Expand All @@ -139,12 +148,16 @@ void ClassInfo::run(const MatchFinder::MatchResult& Result) {
}

for (const auto& field : clas->fields()) {
if (!AccessCheck(_access_filter, field->getAccess())) continue;

json fieldInfo = StandardDeclInfo(Result.Context, field);
fieldInfo["type"] = hyde::to_string(Result.Context, field->getType());
fieldInfo["type"] = hyde::to_string(field, field->getType());
info["fields"][static_cast<const std::string&>(fieldInfo["qualified_name"])] =
fieldInfo; // can't move this into place for some reason.
}

hyde::json static_members = static_finder.get_results();

if (static_members.size() > 0) {
if (info["fields"].size() == 0) {
info["fields"] = hyde::json::object();
Expand All @@ -158,8 +171,10 @@ void ClassInfo::run(const MatchFinder::MatchResult& Result) {
typedef_iterator(CXXRecordDecl::decl_iterator()));
for (const auto& type_def : typedefs) {
// REVISIT (fbrereto) : Refactor this block and TypedefInfo::run's.
if (!AccessCheck(_access_filter, type_def->getAccess())) continue;

json typedefInfo = StandardDeclInfo(Result.Context, type_def);
typedefInfo["type"] = hyde::to_string(Result.Context, type_def->getUnderlyingType());
typedefInfo["type"] = hyde::to_string(type_def, type_def->getUnderlyingType());

info["typedefs"].push_back(std::move(typedefInfo));
}
Expand All @@ -170,10 +185,13 @@ void ClassInfo::run(const MatchFinder::MatchResult& Result) {
typealias_iterator(CXXRecordDecl::decl_iterator()));
for (const auto& type_alias : typealiases) {
// REVISIT (fbrereto) : Refactor this block and TypeAliasInfo::run's.
if (!AccessCheck(_access_filter, type_alias->getAccess())) continue;

json typealiasInfo = StandardDeclInfo(Result.Context, type_alias);
typealiasInfo["type"] = hyde::to_string(Result.Context, type_alias->getUnderlyingType());
typealiasInfo["type"] = hyde::to_string(type_alias, type_alias->getUnderlyingType());
if (auto template_decl = type_alias->getDescribedAliasTemplate()) {
typealiasInfo["template_parameters"] = GetTemplateParameters(Result.Context, template_decl);
typealiasInfo["template_parameters"] =
GetTemplateParameters(Result.Context, template_decl);
}

info["typealiases"].push_back(std::move(typealiasInfo));
Expand Down
7 changes: 5 additions & 2 deletions matchers/class_matcher.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ NOTICE: Adobe permits you to use, modify, and distribute this file in
accordance with the terms of the Adobe license agreement accompanying
it. If you have received this file from a source other than Adobe,
then your use, modification, or distribution of it requires the prior
written permission of Adobe.
written permission of Adobe.
*/

#pragma once
Expand All @@ -17,6 +17,7 @@ written permission of Adobe.

// application
#include "json.hpp"
#include "matchers/matcher_fwd.hpp"

using namespace clang;
using namespace clang::ast_matchers;
Expand All @@ -29,7 +30,8 @@ namespace hyde {

class ClassInfo : public MatchFinder::MatchCallback {
public:
explicit ClassInfo(std::vector<std::string> paths) : _paths(std::move(paths)) {
explicit ClassInfo(std::vector<std::string> paths, ToolAccessFilter filter)
: _paths(std::move(paths)), _access_filter(filter) {
_j["class"] = json::array();
}

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

private:
std::vector<std::string> _paths;
ToolAccessFilter _access_filter;
json _j;
};

Expand Down
4 changes: 3 additions & 1 deletion matchers/enum_matcher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,12 @@ void EnumInfo::run(const MatchFinder::MatchResult& Result) {

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

if (!AccessCheck(_access_filter, enumeration->getAccess())) return;

json info = StandardDeclInfo(Result.Context, enumeration);
//info["scoped"] = enumeration->isScoped();
//info["fixed"] = enumeration->isFixed();
info["type"] = hyde::to_string(Result.Context, enumeration->getIntegerType());
info["type"] = hyde::to_string(enumeration, enumeration->getIntegerType());
info["values"] = json::array();

for (const auto& p : enumeration->enumerators()) {
Expand Down
7 changes: 5 additions & 2 deletions matchers/enum_matcher.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ NOTICE: Adobe permits you to use, modify, and distribute this file in
accordance with the terms of the Adobe license agreement accompanying
it. If you have received this file from a source other than Adobe,
then your use, modification, or distribution of it requires the prior
written permission of Adobe.
written permission of Adobe.
*/

#pragma once
Expand All @@ -17,6 +17,7 @@ written permission of Adobe.

// application
#include "json.hpp"
#include "matchers/matcher_fwd.hpp"

using namespace clang;
using namespace clang::ast_matchers;
Expand All @@ -29,7 +30,8 @@ namespace hyde {

class EnumInfo : public MatchFinder::MatchCallback {
public:
EnumInfo(std::vector<std::string> paths) : _paths(std::move(paths)) {
EnumInfo(std::vector<std::string> paths, ToolAccessFilter filter)
: _paths(std::move(paths)), _access_filter(filter) {
_j["enums"] = json::array();
}

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

private:
std::vector<std::string> _paths;
ToolAccessFilter _access_filter;
json _j;
};

Expand Down
2 changes: 2 additions & 0 deletions matchers/function_matcher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ void FunctionInfo::run(const MatchFinder::MatchResult& Result) {

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

if (!AccessCheck(_access_filter, function->getAccess())) return;

auto info = DetailFunctionDecl(Result.Context, function);

_j["functions"][static_cast<const std::string&>(info["short_name"])].
Expand Down
7 changes: 5 additions & 2 deletions matchers/function_matcher.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ NOTICE: Adobe permits you to use, modify, and distribute this file in
accordance with the terms of the Adobe license agreement accompanying
it. If you have received this file from a source other than Adobe,
then your use, modification, or distribution of it requires the prior
written permission of Adobe.
written permission of Adobe.
*/

#pragma once
Expand All @@ -17,6 +17,7 @@ written permission of Adobe.

// application
#include "json.hpp"
#include "matchers/matcher_fwd.hpp"

using namespace clang;
using namespace clang::ast_matchers;
Expand All @@ -29,7 +30,8 @@ namespace hyde {

class FunctionInfo : public MatchFinder::MatchCallback {
public:
FunctionInfo(std::vector<std::string> paths) : _paths(std::move(paths)) {
FunctionInfo(std::vector<std::string> paths, ToolAccessFilter filter)
: _paths(std::move(paths)), _access_filter(filter) {
_j["functions"] = json::object();
}

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

private:
std::vector<std::string> _paths;
ToolAccessFilter _access_filter;
json _j;
};

Expand Down
30 changes: 30 additions & 0 deletions matchers/matcher_fwd.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
Copyright 2018 Adobe
All Rights Reserved.

NOTICE: Adobe permits you to use, modify, and distribute this file in
accordance with the terms of the Adobe license agreement accompanying
it. If you have received this file from a source other than Adobe,
then your use, modification, or distribution of it requires the prior
written permission of Adobe.
*/

#pragma once

/**************************************************************************************************/

namespace hyde {

/**************************************************************************************************/

enum ToolAccessFilter {
ToolAccessFilterPrivate,
ToolAccessFilterProtected,
ToolAccessFilterPublic,
};

/**************************************************************************************************/

} // namespace hyde

/**************************************************************************************************/
2 changes: 2 additions & 0 deletions matchers/namespace_matcher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ void NamespaceInfo::run(const MatchFinder::MatchResult& Result) {

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

if (!AccessCheck(_access_filter, ns->getAccess())) return;

_j["namespaces"].push_back(StandardDeclInfo(Result.Context, ns));
}

Expand Down
7 changes: 5 additions & 2 deletions matchers/namespace_matcher.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ NOTICE: Adobe permits you to use, modify, and distribute this file in
accordance with the terms of the Adobe license agreement accompanying
it. If you have received this file from a source other than Adobe,
then your use, modification, or distribution of it requires the prior
written permission of Adobe.
written permission of Adobe.
*/

#pragma once
Expand All @@ -17,6 +17,7 @@ written permission of Adobe.

// application
#include "json.hpp"
#include "matchers/matcher_fwd.hpp"

using namespace clang;
using namespace clang::ast_matchers;
Expand All @@ -29,7 +30,8 @@ namespace hyde {

class NamespaceInfo : public MatchFinder::MatchCallback {
public:
NamespaceInfo(std::vector<std::string> paths) : _paths(std::move(paths)) {
NamespaceInfo(std::vector<std::string> paths, ToolAccessFilter filter)
: _paths(std::move(paths)), _access_filter(filter) {
_j["namespaces"] = json::array();
}

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

private:
std::vector<std::string> _paths;
ToolAccessFilter _access_filter;
json _j;
};

Expand Down
4 changes: 3 additions & 1 deletion matchers/typealias_matcher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,14 @@ void TypeAliasInfo::run(const MatchFinder::MatchResult& Result) {

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

if (!AccessCheck(_access_filter, node->getAccess())) return;

json info = StandardDeclInfo(Result.Context, node);

// do not process class type aliases here.
if (!info["parents"].empty()) return;

info["type"] = hyde::to_string(Result.Context, node->getUnderlyingType());
info["type"] = hyde::to_string(node, node->getUnderlyingType());

if (auto template_decl = node->getDescribedAliasTemplate()) {
info["template_parameters"] = GetTemplateParameters(Result.Context, template_decl);
Expand Down
Loading