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
6 changes: 6 additions & 0 deletions cpp2rust/converter/mapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ std::unordered_map<std::string, TranslationRule::TypeTgt>
clang::PrintingPolicy getPrintPolicy() {
assert(ctx_);
clang::PrintingPolicy policy(ctx_->getLangOpts());
policy.Bool = true;
policy.SuppressTagKeyword = true;
policy.SuppressScope = false;
policy.FullyQualifiedName = true;
Expand Down Expand Up @@ -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();
}
Expand Down
12 changes: 12 additions & 0 deletions cpp2rust/converter/mapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// Copyright (c) 2022-present INESC-ID.
// Distributed under the MIT license that can be found in the LICENSE file.

#include <clang/AST/ASTContext.h>
#include <clang/AST/Expr.h>
#include <clang/AST/Type.h>

Expand All @@ -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);

Expand Down
1 change: 1 addition & 0 deletions cpp2rust/converter/translation_rule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<clang::TypeAliasDecl>("tvar")) {
clang::QualType type;
if (auto *tdecl = var->getDescribedAliasTemplate()) {
Expand Down
Loading