diff --git a/cpp2rust/converter/mapper.cpp b/cpp2rust/converter/mapper.cpp index c3cc0897..f3a4af9a 100644 --- a/cpp2rust/converter/mapper.cpp +++ b/cpp2rust/converter/mapper.cpp @@ -32,6 +32,7 @@ std::unordered_map clang::PrintingPolicy getPrintPolicy() { assert(ctx_); clang::PrintingPolicy policy(ctx_->getLangOpts()); + policy.Bool = true; policy.SuppressTagKeyword = true; policy.SuppressScope = false; policy.FullyQualifiedName = true; @@ -562,6 +563,11 @@ std::string normalizeTranslationRule(std::string rule) { } // namespace +PushASTContext::PushASTContext(clang::ASTContext &ctx) : prev_(ctx_) { + ctx_ = &ctx; +} +PushASTContext::~PushASTContext() { ctx_ = prev_; } + bool Contains(clang::QualType qual_type) { return search(qual_type) != types_.end(); } diff --git a/cpp2rust/converter/mapper.h b/cpp2rust/converter/mapper.h index 14de1808..f2b706ab 100644 --- a/cpp2rust/converter/mapper.h +++ b/cpp2rust/converter/mapper.h @@ -3,6 +3,7 @@ // Copyright (c) 2022-present INESC-ID. // Distributed under the MIT license that can be found in the LICENSE file. +#include #include #include @@ -14,6 +15,17 @@ #include "converter/translation_rule.h" namespace cpp2rust::Mapper { +class PushASTContext { +public: + explicit PushASTContext(clang::ASTContext &ctx); + ~PushASTContext(); + PushASTContext(const PushASTContext &) = delete; + PushASTContext &operator=(const PushASTContext &) = delete; + +private: + clang::ASTContext *prev_; +}; + bool Contains(clang::QualType qual_type); bool Contains(const clang::Expr *expr); diff --git a/cpp2rust/converter/translation_rule.cpp b/cpp2rust/converter/translation_rule.cpp index 748bbab7..be57303a 100644 --- a/cpp2rust/converter/translation_rule.cpp +++ b/cpp2rust/converter/translation_rule.cpp @@ -86,6 +86,7 @@ class Callback : public clang::ast_matchers::MatchFinder::MatchCallback { void run(const clang::ast_matchers::MatchFinder::MatchResult &R) override { assert(sema_); + Mapper::PushASTContext scoped(*R.Context); if (auto var = R.Nodes.getNodeAs("tvar")) { clang::QualType type; if (auto *tdecl = var->getDescribedAliasTemplate()) {