Skip to content

Commit 92f7cf4

Browse files
committed
Move cpp_init_type in TypeInfo
1 parent adb23e7 commit 92f7cf4

5 files changed

Lines changed: 12 additions & 10 deletions

File tree

‎cpp2rust/converter/rules/registry.cpp‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -442,7 +442,7 @@ clang::QualType GetInitType(clang::ASTContext &ctx, const clang::Expr *expr) {
442442
auto match = findExpr(expr);
443443
assert(match.rule_decl && "expression must have a translation rule");
444444
const auto &rule = match.rule_decl->rule;
445-
if (rule.init_cpp_type.empty()) {
445+
if (rule.init.cpp_type.empty()) {
446446
llvm::StringRef type = rule.init.type;
447447
unsigned n = 0;
448448
[[maybe_unused]] bool bad =
@@ -481,7 +481,9 @@ std::string InitCppType(Model model, const std::string &dir,
481481
if (!rule) {
482482
return {};
483483
}
484-
auto cpp_type = rule->getString("init_cpp_type");
484+
auto params = rule->getObject("params");
485+
auto init = params ? params->getObject("init") : nullptr;
486+
auto cpp_type = init ? init->getString("cpp_type") : std::nullopt;
485487
return cpp_type ? cpp_type->str() : std::string();
486488
}
487489

‎cpp2rust/converter/translation_rule.cpp‎

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ TypeInfo ParseTypeInfoJSON(const llvm::json::Object &obj) {
2020
TypeInfo info;
2121
if (auto ty = obj.getString("type"))
2222
info.type = ty->str();
23+
if (auto cpp_type = obj.getString("cpp_type"))
24+
info.cpp_type = cpp_type->str();
2325
if (auto v = obj.getBoolean("is_refcount_pointer"))
2426
info.is_refcount_pointer = *v;
2527
if (auto v = obj.getBoolean("is_unsafe_pointer"))
@@ -355,10 +357,6 @@ ExprRule ParseExprRuleJSON(const llvm::json::Object &obj) {
355357
ir.body = ParseBodyFragmentsJSON(*body);
356358
}
357359

358-
if (auto init_cpp_type = obj.getString("init_cpp_type")) {
359-
ir.init_cpp_type = init_cpp_type->str();
360-
}
361-
362360
return ir;
363361
}
364362

‎cpp2rust/converter/translation_rule.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ bool AnyFragment(const std::vector<BodyFragment> &body,
9292
struct TypeInfo {
9393
std::vector<std::string> derives;
9494
std::string type;
95+
std::string cpp_type;
9596
bool is_refcount_pointer = false;
9697
bool is_unsafe_pointer = false;
9798

@@ -103,7 +104,6 @@ struct TypeInfo {
103104
struct ExprRule {
104105
std::vector<TypeInfo> params;
105106
TypeInfo init;
106-
std::string init_cpp_type;
107107
TypeInfo return_type;
108108
std::vector<std::vector<Bound>> generics; // "T1" -> [Ord, Clone]
109109
std::vector<BodyFragment> body;

‎rule-preprocessor/src/ir.rs‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,8 @@ pub struct TypeInfo {
7070
pub is_unsafe_pointer: bool,
7171
#[serde(default, skip_serializing_if = "Vec::is_empty")]
7272
pub derives: Vec<String>,
73+
#[serde(default, skip_serializing_if = "Option::is_none")]
74+
pub cpp_type: Option<String>,
7375
}
7476

7577
#[derive(Debug, Clone, Serialize, Deserialize)]
@@ -85,8 +87,6 @@ pub struct FnIr {
8587
pub return_type: Option<TypeInfo>,
8688
#[serde(skip_serializing_if = "Option::is_none")]
8789
pub is_extern: Option<bool>,
88-
#[serde(skip_serializing_if = "Option::is_none")]
89-
pub init_cpp_type: Option<String>,
9090
}
9191

9292
impl FnIr {

‎rule-preprocessor/src/syntactic.rs‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -440,6 +440,7 @@ impl<'a> FnIrBuilder<'a> {
440440
is_refcount_pointer,
441441
is_unsafe_pointer,
442442
derives: Vec::new(),
443+
cpp_type: None,
443444
})
444445
}
445446
}
@@ -656,6 +657,7 @@ impl<'a> FnIrBuilder<'a> {
656657
is_refcount_pointer: p.is_refcount_pointer,
657658
is_unsafe_pointer: p.is_unsafe_pointer,
658659
derives: Vec::new(),
660+
cpp_type: p.cpp_type.clone(),
659661
},
660662
)
661663
})
@@ -692,7 +694,6 @@ impl<'a> FnIrBuilder<'a> {
692694
multi_statement,
693695
body,
694696
is_extern: self.is_extern().then_some(true),
695-
init_cpp_type: params.iter().find_map(|p| p.cpp_type.clone()),
696697
};
697698
ir.validate(&format!("{}:{}", path.display(), fn_name));
698699
ir
@@ -767,6 +768,7 @@ impl<'a> TypeIrBuilder<'a> {
767768
is_refcount_pointer,
768769
is_unsafe_pointer,
769770
derives: Vec::new(),
771+
cpp_type: None,
770772
},
771773
}
772774
}

0 commit comments

Comments
 (0)