|
22 | 22 | #include "converter/lex.h" |
23 | 23 | #include "converter/mapper.h" |
24 | 24 |
|
| 25 | +namespace cpp2rust { |
| 26 | +std::unordered_map<std::string, std::string> Converter::inner_structs_; |
| 27 | +std::unordered_set<std::string> Converter::decl_ids_; |
| 28 | +std::unordered_set<std::string> Converter::globals_; |
| 29 | +std::unordered_set<std::string> Converter::abstract_structs_; |
| 30 | +Converter::RecordIndex Converter::record_decls_; |
| 31 | +std::map<std::string, Converter::MethodsOnPtr> Converter::methods_on_ptr_; |
| 32 | + |
25 | 33 | // `static mut` globals cannot have a `&`/`&mut` reference formed directly to |
26 | 34 | // them in Rust 2024 edition. Wrapping the variable in a `&raw mut` pointer |
27 | 35 | // followed by a deref sidesteps the restriction. |
28 | 36 | // Doesn't apply when a rule replaced the expression with custom Rust code. |
29 | 37 | static std::string WrapMutableStaticPlace(const clang::Decl *decl, std::string str) { |
30 | | - if (IsGlobalVar(decl) && !decl->getType()->isReferenceType() && |
| 38 | + auto decl = clang::dyn_cast<clang::VarDecl>(decl); |
| 39 | + if (decl && IsGlobalVar(decl) && !decl->getType()->isReferenceType() && |
31 | 40 | str == GetNamedDeclAsString(decl)) { |
32 | 41 | return std::format("(*&raw mut {})", str); |
33 | 42 | } |
34 | 43 | return str; |
35 | 44 | } |
36 | 45 |
|
37 | | -namespace cpp2rust { |
38 | | -std::unordered_map<std::string, std::string> Converter::inner_structs_; |
39 | | -std::unordered_set<std::string> Converter::decl_ids_; |
40 | | -std::unordered_set<std::string> Converter::globals_; |
41 | | -std::unordered_set<std::string> Converter::abstract_structs_; |
42 | | -Converter::RecordIndex Converter::record_decls_; |
43 | | -std::map<std::string, Converter::MethodsOnPtr> Converter::methods_on_ptr_; |
44 | | - |
45 | 46 | void Converter::ConvertUniquePtrDeref(clang::CXXOperatorCallExpr *expr) { |
46 | 47 | bool is_star = expr->getOperator() == clang::OverloadedOperatorKind::OO_Star; |
47 | 48 | PushParen paren(*this, is_star); |
|
0 commit comments