Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
100 commits
Select commit Hold shift + click to select a range
218d76a
ctest: parse rust modules in crates
dybucc Sep 2, 2026
54e6897
ctest: add support for filtering modules
dybucc Sep 3, 2026
60b0cdd
ctest(remove): showcase skipping items with mods
dybucc Sep 4, 2026
30cf354
ctest: fmt comments
dybucc Sep 4, 2026
c75758b
ctest: differentiate between `ident` and `path`
dybucc Sep 6, 2026
3c74044
ctest: adjust `ident` call sites with new fns
dybucc Sep 6, 2026
b6de492
ctest(maybe_remove): tweak a little something
dybucc Sep 4, 2026
da30907
ctest: tweak tests and test template to pass them
dybucc Sep 6, 2026
a15dd2f
ctest: update test templates
dybucc Sep 6, 2026
5cc36f1
ctest: fmt a string to 80 characters wide
dybucc Sep 7, 2026
56204ba
chore: wip
dybucc Sep 13, 2026
372aa56
chore: wip
dybucc Sep 14, 2026
7e16883
chore: wip
dybucc Sep 15, 2026
eec5bcf
chore: wip
dybucc Sep 15, 2026
3969d83
chore: wip
dybucc Sep 16, 2026
4fb056d
chore: wip
dybucc Sep 16, 2026
ac79172
chore: wip
dybucc Sep 16, 2026
c2573e7
chore: wip
dybucc Sep 18, 2026
c7b1d2a
chore: wip
dybucc Sep 19, 2026
c89b68e
chore: wip
dybucc Sep 19, 2026
e9c28d4
chore: wip
dybucc Sep 19, 2026
5cbef5a
chore: wip
dybucc Sep 20, 2026
add0dcb
chore: wip
dybucc Sep 20, 2026
cf666c4
chore: wip
dybucc Sep 20, 2026
1e2e440
chore: wip
dybucc Sep 20, 2026
ab44844
chore: wip
dybucc Sep 21, 2026
2463ee8
chore: wip
dybucc Sep 21, 2026
87890d9
chore: wip
dybucc Sep 21, 2026
0c419dd
chore: wip
dybucc Sep 21, 2026
4b05ed4
chore: wip
dybucc Sep 22, 2026
8ae9aaa
chore: wip
dybucc Sep 22, 2026
1bce5b4
chore: wip
dybucc Sep 23, 2026
c9507dd
chore: wip
dybucc Sep 25, 2026
3c4553d
chore: wip
dybucc Sep 25, 2026
a9b1dd6
chore: wip
dybucc Sep 25, 2026
9a86503
chore: wip
dybucc Sep 26, 2026
1b1e58e
chore: wip
dybucc Sep 27, 2026
dbccfb9
chore: wip
dybucc Sep 27, 2026
366231b
chore: wip
dybucc Sep 28, 2026
4135ca6
chore: wip
dybucc Sep 28, 2026
0114011
chore: wip
dybucc Sep 28, 2026
6c58b3c
chore: wip
dybucc Sep 28, 2026
b376b8d
chore: wip
dybucc Sep 29, 2026
68f45b5
chore: wip
dybucc Oct 1, 2026
a37e9be
chore: wip
dybucc Oct 5, 2026
4b7454b
chore: wip
dybucc Oct 5, 2026
bb13837
chore: wip
dybucc Oct 5, 2026
f3032eb
chore: wip
dybucc Oct 6, 2026
68cb6e1
chore: wip
dybucc Oct 6, 2026
35051cc
chore: wip
dybucc Oct 7, 2026
cf06ec2
chore: wip
dybucc Oct 7, 2026
eeb55b1
chore: wip
dybucc Oct 8, 2026
7fa5dbd
chore: wip
dybucc Oct 8, 2026
328fde6
chore: wip
dybucc Oct 8, 2026
e2b41f9
chore: wip
dybucc Oct 9, 2026
75de193
chore: wip
dybucc Oct 9, 2026
64021b8
chore: wip
dybucc Oct 12, 2026
a9ec090
chore: wip
dybucc Oct 12, 2026
1802430
chore: wip
dybucc Oct 12, 2026
3234a5e
chore: wip
dybucc Oct 13, 2026
f200494
chore: wip
dybucc Oct 13, 2026
7045a17
chore: wip
dybucc Oct 14, 2026
03755ad
chore: wip
dybucc Oct 14, 2026
8d2e81d
chore: wip
dybucc Oct 15, 2026
b2935cc
chore: wip
dybucc Oct 15, 2026
4cf8c4f
chore: wip
dybucc Oct 15, 2026
434af88
chore: wip
dybucc Oct 16, 2026
612934c
chore: wip
dybucc Oct 16, 2026
f8b0a01
chore: wip
dybucc Oct 19, 2026
fbb78a0
chore: wip
dybucc Oct 19, 2026
d6d6632
chore: wip
dybucc Oct 20, 2026
8ecebe6
chore: wip
dybucc Oct 20, 2026
5236670
chore: wip
dybucc Oct 20, 2026
cd67391
chore: wip
dybucc Oct 20, 2026
6b1e4a5
chore: wip
dybucc Oct 21, 2026
bbb379b
chore: wip
dybucc Oct 21, 2026
2f0d41f
chore: wip
dybucc Oct 21, 2026
979518f
chore: wip
dybucc Oct 21, 2026
cd78d96
chore: wip
dybucc Oct 22, 2026
b8b9d7d
chore: wip
dybucc Oct 22, 2026
f0fd893
chore: wip
dybucc Oct 22, 2026
80ad720
chore: wip
dybucc Oct 23, 2026
c849cee
chore: wip
dybucc Oct 23, 2026
88895c9
chore: wip
dybucc Oct 23, 2026
72f52fd
chore: wip
dybucc Oct 23, 2026
05a734d
chore: wip
dybucc Oct 26, 2026
abc63f4
chore: wip
dybucc Oct 27, 2026
4077968
chore: wip
dybucc Oct 29, 2026
9df2270
chore: wip
dybucc Oct 30, 2026
75eb6ff
chore: wip
dybucc Nov 2, 2026
6786cd3
chore: wip
dybucc Nov 2, 2026
acd903b
chore: wip
dybucc Nov 3, 2026
77f2eeb
chore: wip
dybucc Nov 3, 2026
52ec4b1
chore: wip
dybucc Nov 3, 2026
4d6ee90
chore: wip
dybucc Nov 4, 2026
2db4255
chore: wip
dybucc Nov 4, 2026
845db16
chore: wip
dybucc Nov 4, 2026
44c7819
chore: wip
dybucc Nov 5, 2026
ac54788
chore: wip
dybucc Nov 5, 2026
986475a
chore: wip
dybucc Nov 5, 2026
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
20 changes: 10 additions & 10 deletions ctest-test/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,19 @@ fn test_ctest() {
.header("t1.h")
.include("src")
.skip_private(true)
.rename_fn(|f| f.link_name().unwrap_or(f.ident()).to_string().into())
.rename_static(|s| s.link_name().unwrap_or(s.ident()).to_string().into())
.rename_fn(|f| f.link_name().unwrap_or(f.path()).to_string().into())
.rename_static(|s| s.link_name().unwrap_or(s.path()).to_string().into())
.rename_union_ty(|ty| (ty == "T1Union").then_some(ty.to_string()))
.rename_struct_ty(|ty| (ty == "Transparent").then_some(ty.to_string()))
.volatile_struct_field(|s, f| s.ident() == "V" && f.ident() == "v")
.volatile_static(|s| s.ident() == "vol_ptr")
.volatile_static(|s| s.ident() == "T1_fn_ptr_vol")
.volatile_fn_arg(|f, p| f.ident() == "T1_vol0" && p.ident() == "arg0")
.volatile_fn_arg(|f, p| f.ident() == "T1_vol2" && p.ident() == "arg1")
.volatile_fn_return_type(|f| f.ident() == "T1_vol1")
.volatile_fn_return_type(|f| f.ident() == "T1_vol2")
.volatile_struct_field(|s, f| s.path() == "V" && f.ident() == "v")
.volatile_static(|s| s.path() == "vol_ptr")
.volatile_static(|s| s.path() == "T1_fn_ptr_vol")
.volatile_fn_arg(|f, p| f.path() == "T1_vol0" && p.ident() == "arg0")
.volatile_fn_arg(|f, p| f.path() == "T1_vol2" && p.ident() == "arg1")
.volatile_fn_return_type(|f| f.path() == "T1_vol1")
.volatile_fn_return_type(|f| f.path() == "T1_vol2")
// The parameter `a` of the functions `T1r`, `T1s`, `T1t`, `T1v` is an array.
.array_arg(|f, p| matches!(f.ident(), "T1r" | "T1s" | "T1t" | "T1v") && p.ident() == "a")
.array_arg(|f, p| matches!(f.path(), "T1r" | "T1s" | "T1t" | "T1v") && p.ident() == "a")
.skip_roundtrip(|n| n == "Arr");
ctest::generate_test(&mut t1gen, "src/t1.rs", "t1gen.rs").unwrap();

Expand Down
58 changes: 53 additions & 5 deletions ctest/src/ast/constant.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,64 @@
use syn::{
Path,
Type,
};

use crate::BoxStr;
use crate::ast::{
PathAggregateStore,
PathUtils,
};

/// Represents a constant variable defined in Rust.
#[derive(Debug, Clone)]
#[derive(Debug, Clone, PartialEq)]
pub struct Const {
pub(crate) public: bool,
pub(crate) ident: BoxStr,
pub(crate) ty: syn::Type,
pub(crate) cached_path: BoxStr,
pub(crate) cached_ident: BoxStr,
pub(crate) path: Path,
pub(crate) path_aggregate: PathAggregateStore,
pub(crate) ty: Type,
}

impl Const {
/// Return the identifier of the constant as a string.
/// Return the full path to the constant variable as a string.
///
/// If inside a nested module, this will return a top-level-relative path,
/// but not a crate-relative path. For some item `foo` in module
/// `crate::bar`, the returned string will be `bar::foo`, and not
/// `crate::bar::foo`.
pub fn path(&self) -> &str {
&self.cached_path
}

/// Returns the last segment of the constant's path; Namely, its identifier.
pub fn ident(&self) -> &str {
&self.ident
&self.cached_ident
}
}

impl PathUtils for Const {
fn path_aggregate(&self) -> &PathAggregateStore {
&self.path_aggregate
}

fn path(&self) -> &Path {
&self.path
}

fn mk(
self,
cached_path: BoxStr,
cached_ident: BoxStr,
path: Path,
path_aggregate: PathAggregateStore,
) -> Self {
Self {
cached_path,
cached_ident,
path,
path_aggregate,
..self
}
}

@tgross35 tgross35 Oct 16, 2026 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the syn::Path isn't needed for anything else, instead store an ident_start: usize and make ident return &self.path[self.ident_start..]

View changes since the review

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, but I don't think this is nearly ready for review just yet.
There's too much of a mess in the patchset to expect anyone to review
it.

}
2 changes: 1 addition & 1 deletion ctest/src/ast/field.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::BoxStr;

/// Represents a field in a struct or union defined in Rust.
#[derive(Debug, Clone)]
#[derive(Debug, Clone, PartialEq)]
pub struct Field {
pub(crate) public: bool,
pub(crate) ident: BoxStr,
Expand Down
56 changes: 49 additions & 7 deletions ctest/src/ast/function.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
use syn::Path;

use crate::ast::{
PathAggregateStore,
PathUtils,
};
use crate::{
Abi,
BoxStr,
Expand All @@ -7,27 +13,63 @@ use crate::{
/// Represents a function signature defined in Rust.
///
/// This structure is only used for parsing functions in extern blocks.
#[derive(Debug, Clone)]
#[derive(Debug, Clone, PartialEq)]
pub struct Fn {
pub(crate) public: bool,
#[expect(unused)]
pub(crate) abi: Abi,
pub(crate) ident: BoxStr,
pub(crate) cached_path: BoxStr,
pub(crate) cached_ident: BoxStr,
pub(crate) path: Path,
pub(crate) path_aggregate: PathAggregateStore,
pub(crate) link_name: Option<BoxStr>,
#[expect(unused)]
pub(crate) parameters: Vec<Parameter>,
#[expect(unused)]
pub(crate) return_type: Option<syn::Type>,
}

impl Fn {
/// Return the identifier of the function as a string.
/// Return the full path to the function item as a string.
///
/// If inside a nested module, this will return a top-level-relative path,
/// but not a crate-relative path. For some item `foo` in module
/// `crate::bar`, the returned string will be `bar::foo`, and not
/// `crate::bar::foo`.
pub fn path(&self) -> &str {
&self.cached_path
}

/// Returns the last segment of the function's path; Namely, its identifier.
pub fn ident(&self) -> &str {
&self.ident
&self.cached_ident
}

/// Return the name of the function to be linked C side with.
pub fn link_name(&self) -> Option<&str> {
self.link_name.as_deref()
}
}

impl PathUtils for Fn {
fn path_aggregate(&self) -> &PathAggregateStore {
&self.path_aggregate
}

fn path(&self) -> &Path {
&self.path
}

fn mk(
self,
cached_path: BoxStr,
cached_ident: BoxStr,
path: Path,
addressable_paths: PathAggregateStore,
) -> Self {
Self {
cached_path,
cached_ident,
path,
path_aggregate: addressable_paths,
..self
}
}
}
Loading