Merge "Filter ABI if exported include dir is specified."

This commit is contained in:
Hsin-Yi Chen
2020-04-16 03:49:50 +00:00
committed by Gerrit Code Review
3 changed files with 12 additions and 19 deletions

View File

@@ -156,10 +156,6 @@ bool HeaderASTVisitor::VisitVarDecl(const clang::VarDecl *decl) {
return global_var_decl_wrapper.GetGlobalVarDecl(); return global_var_decl_wrapper.GetGlobalVarDecl();
} }
static bool AreHeadersExported(const std::set<std::string> &exported_headers) {
return !exported_headers.empty();
}
// We don't need to recurse into Declarations which are not exported. // We don't need to recurse into Declarations which are not exported.
bool HeaderASTVisitor::TraverseDecl(clang::Decl *decl) { bool HeaderASTVisitor::TraverseDecl(clang::Decl *decl) {
if (!decl) { if (!decl) {
@@ -170,7 +166,8 @@ bool HeaderASTVisitor::TraverseDecl(clang::Decl *decl) {
std::make_pair(decl, source_file)); std::make_pair(decl, source_file));
// If no exported headers are specified we assume the whole AST is exported. // If no exported headers are specified we assume the whole AST is exported.
const auto &exported_headers = options_.exported_headers_; const auto &exported_headers = options_.exported_headers_;
if ((decl != tu_decl_) && AreHeadersExported(exported_headers) && if ((decl != tu_decl_) && options_.dump_exported_only_ &&
source_file != ast_caches_->translation_unit_source_ &&
(exported_headers.find(source_file) == exported_headers.end())) { (exported_headers.find(source_file) == exported_headers.end())) {
return true; return true;
} }
@@ -198,12 +195,7 @@ void HeaderASTConsumer::HandleTranslationUnit(clang::ASTContext &ctx) {
clang::TranslationUnitDecl *translation_unit = ctx.getTranslationUnitDecl(); clang::TranslationUnitDecl *translation_unit = ctx.getTranslationUnitDecl();
std::unique_ptr<clang::MangleContext> mangle_contextp( std::unique_ptr<clang::MangleContext> mangle_contextp(
ctx.createMangleContext()); ctx.createMangleContext());
const std::string &translation_unit_source = ASTCaches ast_caches(ABIWrapper::GetDeclSourceFile(translation_unit, cip_));
ABIWrapper::GetDeclSourceFile(translation_unit, cip_);
ASTCaches ast_caches(translation_unit_source);
if (!options_.exported_headers_.empty()) {
options_.exported_headers_.insert(translation_unit_source);
}
std::unique_ptr<repr::ModuleIR> module( std::unique_ptr<repr::ModuleIR> module(
new repr::ModuleIR(nullptr /*FIXME*/)); new repr::ModuleIR(nullptr /*FIXME*/));

View File

@@ -128,16 +128,16 @@ int main(int argc, const char **argv) {
::exit(1); ::exit(1);
} }
std::set<std::string> exported_headers; bool dump_exported_only = (!no_filter && !exported_header_dirs.empty());
if (!no_filter) { std::set<std::string> exported_headers =
exported_headers = CollectAllExportedHeaders(exported_header_dirs); CollectAllExportedHeaders(exported_header_dirs);
}
// Initialize clang tools and run front-end action. // Initialize clang tools and run front-end action.
std::vector<std::string> header_files{ header_file }; std::vector<std::string> header_files{ header_file };
HeaderCheckerOptions options(RealPath(header_file), out_dump, HeaderCheckerOptions options(RealPath(header_file), out_dump,
std::move(exported_headers), output_format, std::move(exported_headers), output_format,
dump_function_declarations, suppress_errors); dump_exported_only, dump_function_declarations,
suppress_errors);
clang::tooling::ClangTool tool(*compilations, header_files); clang::tooling::ClangTool tool(*compilations, header_files);
std::unique_ptr<clang::tooling::FrontendActionFactory> factory( std::unique_ptr<clang::tooling::FrontendActionFactory> factory(

View File

@@ -29,19 +29,20 @@ class HeaderCheckerOptions {
public: public:
std::string source_file_; std::string source_file_;
std::string dump_name_; std::string dump_name_;
std::set<std::string> exported_headers_; const std::set<std::string> exported_headers_;
repr::TextFormatIR text_format_; repr::TextFormatIR text_format_;
const bool dump_exported_only_;
bool dump_function_declarations_; bool dump_function_declarations_;
bool suppress_errors_; bool suppress_errors_;
public: public:
HeaderCheckerOptions(std::string source_file, std::string dump_name, HeaderCheckerOptions(std::string source_file, std::string dump_name,
std::set<std::string> exported_headers, std::set<std::string> exported_headers,
repr::TextFormatIR text_format, repr::TextFormatIR text_format, bool dump_exported_only,
bool dump_function_declarations, bool suppress_errors) bool dump_function_declarations, bool suppress_errors)
: source_file_(std::move(source_file)), dump_name_(std::move(dump_name)), : source_file_(std::move(source_file)), dump_name_(std::move(dump_name)),
exported_headers_(std::move(exported_headers)), exported_headers_(std::move(exported_headers)),
text_format_(text_format), text_format_(text_format), dump_exported_only_(dump_exported_only),
dump_function_declarations_(dump_function_declarations), dump_function_declarations_(dump_function_declarations),
suppress_errors_(suppress_errors) {} suppress_errors_(suppress_errors) {}
}; };