Skip to content

Commit 582d5d3

Browse files
committed
Replace is_variadic with is_extern
1 parent 0c3a442 commit 582d5d3

4 files changed

Lines changed: 15 additions & 13 deletions

File tree

cpp2rust/converter/translation_rule.cpp

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -98,14 +98,17 @@ ExprRule ParseExprRuleJSON(const llvm::json::Object &obj) {
9898
}
9999
}
100100

101-
if (auto *rt = obj.getObject("return_type"))
101+
if (auto *rt = obj.getObject("return_type")) {
102102
ir.return_type = ParseTypeInfoJSON(*rt);
103+
}
103104

104-
if (auto ms = obj.getBoolean("multi_statement"))
105+
if (auto ms = obj.getBoolean("multi_statement")) {
105106
ir.multi_statement = *ms;
107+
}
106108

107-
if (auto v = obj.getBoolean("is_variadic"))
108-
ir.is_variadic = *v;
109+
if (auto v = obj.getBoolean("is_extern")) {
110+
ir.is_extern = *v;
111+
}
109112

110113
if (auto *generics = obj.getObject("generics")) {
111114
for (auto &[key, val] : *generics) {

cpp2rust/converter/translation_rule.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ struct ExprRule {
7070
std::vector<std::vector<std::string>> generics; // "T1" -> ["Ord", "Clone"]
7171
std::vector<BodyFragment> body;
7272
bool multi_statement = false;
73-
bool is_variadic = false;
73+
bool is_extern = false;
7474

7575
void dump() const;
7676
void validate(const std::string &name) const;

rule-preprocessor/src/ir.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ pub struct FnIr {
5858
#[serde(skip_serializing_if = "Option::is_none")]
5959
pub return_type: Option<TypeInfo>,
6060
#[serde(skip_serializing_if = "Option::is_none")]
61-
pub is_variadic: Option<bool>,
61+
pub is_extern: Option<bool>,
6262
}
6363

6464
impl FnIr {
@@ -107,7 +107,7 @@ impl FnIr {
107107
&format!("Rule {name} generics"),
108108
);
109109
assert!(
110-
self.is_variadic == Some(true) || !self.body.is_empty(),
110+
self.is_extern == Some(true) || !self.body.is_empty(),
111111
"Rule {name}: body must not be empty"
112112
);
113113
}

rule-preprocessor/src/syntactic.rs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -416,12 +416,11 @@ impl<'a> FnIrBuilder<'a> {
416416
.unwrap_or(Access::Read)
417417
}
418418

419-
fn is_variadic(&self) -> bool {
419+
fn is_extern(&self) -> bool {
420420
self.fn_item
421-
.param_list()
422-
.into_iter()
423-
.flat_map(|pl| pl.params())
424-
.any(|p| p.dotdotdot_token().is_some())
421+
.syntax()
422+
.ancestors()
423+
.any(|a| a.kind() == SyntaxKind::EXTERN_BLOCK)
425424
}
426425

427426
fn returns_mut_ref(&self) -> bool {
@@ -525,7 +524,7 @@ impl<'a> FnIrBuilder<'a> {
525524
},
526525
multi_statement,
527526
body,
528-
is_variadic: self.is_variadic().then_some(true),
527+
is_extern: self.is_extern().then_some(true),
529528
};
530529
ir.validate(&format!("{}:{}", path.display(), fn_name));
531530
ir

0 commit comments

Comments
 (0)