Skip to content

Commit 74e9a28

Browse files
committed
Add Rust rule counterpart
1 parent d7555a2 commit 74e9a28

6 files changed

Lines changed: 36 additions & 1 deletion

File tree

rule-preprocessor/src/ir.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,8 @@ pub struct FnIr {
5757
pub params: Option<BTreeMap<String, TypeInfo>>,
5858
#[serde(skip_serializing_if = "Option::is_none")]
5959
pub return_type: Option<TypeInfo>,
60+
#[serde(skip_serializing_if = "Option::is_none")]
61+
pub is_variadic: Option<bool>,
6062
}
6163

6264
impl FnIr {
@@ -104,7 +106,10 @@ impl FnIr {
104106
1,
105107
&format!("Rule {name} generics"),
106108
);
107-
assert!(!self.body.is_empty(), "Rule {name}: body must not be empty");
109+
assert!(
110+
self.is_variadic == Some(true) || !self.body.is_empty(),
111+
"Rule {name}: body must not be empty"
112+
);
108113
}
109114
}
110115

rule-preprocessor/src/syntactic.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -410,6 +410,14 @@ impl<'a> FnIrBuilder<'a> {
410410
.unwrap_or(Access::Read)
411411
}
412412

413+
fn is_variadic(&self) -> bool {
414+
self.fn_item
415+
.param_list()
416+
.into_iter()
417+
.flat_map(|pl| pl.params())
418+
.any(|p| p.dotdotdot_token().is_some())
419+
}
420+
413421
fn returns_mut_ref(&self) -> bool {
414422
self.fn_item
415423
.ret_type()
@@ -511,6 +519,7 @@ impl<'a> FnIrBuilder<'a> {
511519
},
512520
multi_statement,
513521
body,
522+
is_variadic: self.is_variadic().then_some(true),
514523
};
515524
ir.validate(&format!("{}:{}", path.display(), fn_name));
516525
ir

rules/fcntl/tgt_unsafe.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// Copyright (c) 2022-present INESC-ID.
2+
// Distributed under the MIT license that can be found in the LICENSE file.
3+
4+
unsafe extern "C" {
5+
fn f1(a0: i32, a1: i32, ...) -> i32;
6+
fn f2(a0: *const u8, a1: i32, ...) -> i32;
7+
}

rules/ioctl/tgt_unsafe.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
// Copyright (c) 2022-present INESC-ID.
2+
// Distributed under the MIT license that can be found in the LICENSE file.
3+
4+
unsafe extern "C" {
5+
fn f1(a0: i32, a1: u64, ...) -> i32;
6+
}

rules/src/modules.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,16 @@ pub mod deque_tgt_refcount;
3838
pub mod deque_tgt_unsafe;
3939
#[path = r#"../errno/tgt_unsafe.rs"#]
4040
pub mod errno_tgt_unsafe;
41+
#[path = r#"../fcntl/tgt_unsafe.rs"#]
42+
pub mod fcntl_tgt_unsafe;
4143
#[path = r#"../fstream/tgt_refcount.rs"#]
4244
pub mod fstream_tgt_refcount;
4345
#[path = r#"../fstream/tgt_unsafe.rs"#]
4446
pub mod fstream_tgt_unsafe;
4547
#[path = r#"../initializer_list/tgt_unsafe.rs"#]
4648
pub mod initializer_list_tgt_unsafe;
49+
#[path = r#"../ioctl/tgt_unsafe.rs"#]
50+
pub mod ioctl_tgt_unsafe;
4751
#[path = r#"../iomanip/tgt_unsafe.rs"#]
4852
pub mod iomanip_tgt_unsafe;
4953
#[path = r#"../iostream/tgt_refcount.rs"#]

rules/stdio/tgt_unsafe.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,3 +85,7 @@ unsafe fn f19(a0: *mut ::libc::FILE, a1: i64, a2: i32) -> i32 {
8585
unsafe fn f20(a0: i32, a1: *const u8) -> *mut ::libc::FILE {
8686
libc::fdopen(a0, a1 as *const i8)
8787
}
88+
89+
unsafe extern "C" {
90+
fn f21(a0: *mut u8, a1: u64, a2: *const u8, ...) -> i32;
91+
}

0 commit comments

Comments
 (0)