-
Notifications
You must be signed in to change notification settings - Fork 1.1k
ctest: Add extraction of relevant types. #4485
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
use crate::BoxStr; | ||
|
||
/// Represents a constant variable defined in Rust. | ||
#[derive(Debug, Clone)] | ||
pub struct Const { | ||
#[expect(unused)] | ||
pub(crate) public: bool, | ||
pub(crate) ident: BoxStr, | ||
#[expect(unused)] | ||
pub(crate) ty: syn::Type, | ||
#[expect(unused)] | ||
pub(crate) expr: syn::Expr, | ||
} | ||
|
||
impl Const { | ||
/// Return the identifier of the constant as a string. | ||
pub fn ident(&self) -> &str { | ||
&self.ident | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
use crate::BoxStr; | ||
|
||
/// Represents a field in a struct or union defined in Rust. | ||
#[derive(Debug, Clone)] | ||
pub struct Field { | ||
#[expect(unused)] | ||
pub(crate) public: bool, | ||
pub(crate) ident: BoxStr, | ||
#[expect(unused)] | ||
pub(crate) ty: syn::Type, | ||
} | ||
|
||
impl Field { | ||
/// Return the identifier of the field as a string if it exists. | ||
pub fn ident(&self) -> &str { | ||
&self.ident | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
use crate::{Abi, BoxStr, Parameter}; | ||
|
||
/// Represents a function signature defined in Rust. | ||
/// | ||
/// This structure is only used for parsing functions in extern blocks. | ||
#[derive(Debug, Clone)] | ||
pub struct Fn { | ||
#[expect(unused)] | ||
pub(crate) public: bool, | ||
#[expect(unused)] | ||
pub(crate) abi: Abi, | ||
pub(crate) ident: 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. | ||
pub fn ident(&self) -> &str { | ||
&self.ident | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
mod constant; | ||
mod field; | ||
mod function; | ||
mod parameter; | ||
mod static_variable; | ||
mod structure; | ||
mod type_alias; | ||
mod union; | ||
|
||
pub use constant::Const; | ||
pub use field::Field; | ||
pub use function::Fn; | ||
pub use parameter::Parameter; | ||
pub use static_variable::Static; | ||
pub use structure::Struct; | ||
pub use type_alias::Type; | ||
pub use union::Union; | ||
|
||
/// The ABI as defined by the extern block. | ||
#[derive(Debug, Clone, PartialEq, Eq)] | ||
pub enum Abi { | ||
/// The C ABI. | ||
C, | ||
/// The Rust ABI. | ||
Rust, | ||
/// Any other ABI. | ||
Other(String), | ||
} | ||
|
||
impl From<&str> for Abi { | ||
fn from(value: &str) -> Self { | ||
match value.to_lowercase().as_str() { | ||
"c" => Abi::C, | ||
"rust" => Abi::Rust, | ||
s => Abi::Other(s.to_string()), | ||
} | ||
} | ||
} | ||
|
||
/// Things that can appear directly inside of a module or scope. | ||
/// | ||
/// This is not an exhaustive list and only contains variants directly useful | ||
/// for our purposes. | ||
#[derive(Debug, Clone)] | ||
#[expect(unused)] | ||
pub(crate) enum Item { | ||
/// Represents a constant defined in Rust. | ||
Const(Const), | ||
/// Represents a function defined in Rust. | ||
Fn(Fn), | ||
/// Represents a static variable defined in Rust. | ||
Static(Static), | ||
/// Represents a type alias defined in Rust. | ||
Type(Type), | ||
/// Represents a struct defined in Rust. | ||
Struct(Struct), | ||
/// Represents a union defined in Rust. | ||
Union(Union), | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
/// Represents a parameter in a function signature defined in Rust. | ||
#[derive(Debug, Clone)] | ||
pub struct Parameter { | ||
#[expect(unused)] | ||
pub(crate) pattern: syn::Pat, | ||
#[expect(unused)] | ||
pub(crate) ty: syn::Type, | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
use crate::{Abi, BoxStr}; | ||
|
||
/// Represents a static variable in Rust. | ||
/// | ||
/// This structure is only used for parsing statics in extern blocks, | ||
/// as a result it does not have a field for storing the expression. | ||
#[derive(Debug, Clone)] | ||
pub struct Static { | ||
#[expect(unused)] | ||
pub(crate) public: bool, | ||
#[expect(unused)] | ||
pub(crate) abi: Abi, | ||
pub(crate) ident: BoxStr, | ||
#[expect(unused)] | ||
pub(crate) ty: syn::Type, | ||
} | ||
|
||
impl Static { | ||
/// Return the identifier of the static variable as a string. | ||
pub fn ident(&self) -> &str { | ||
&self.ident | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
use crate::{BoxStr, Field}; | ||
|
||
/// Represents a struct defined in Rust. | ||
#[derive(Debug, Clone)] | ||
pub struct Struct { | ||
#[expect(unused)] | ||
pub(crate) public: bool, | ||
pub(crate) ident: BoxStr, | ||
#[expect(unused)] | ||
pub(crate) fields: Vec<Field>, | ||
} | ||
|
||
impl Struct { | ||
/// Return the identifier of the struct as a string. | ||
pub fn ident(&self) -> &str { | ||
&self.ident | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
use crate::BoxStr; | ||
|
||
/// Represents a type alias defined in Rust. | ||
#[derive(Debug, Clone)] | ||
pub struct Type { | ||
#[expect(unused)] | ||
pub(crate) public: bool, | ||
pub(crate) ident: BoxStr, | ||
#[expect(unused)] | ||
pub(crate) ty: syn::Type, | ||
} | ||
|
||
impl Type { | ||
/// Return the identifier of the type alias as a string. | ||
pub fn ident(&self) -> &str { | ||
&self.ident | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
use crate::{BoxStr, Field}; | ||
|
||
/// Represents a union defined in Rust. | ||
#[derive(Debug, Clone)] | ||
pub struct Union { | ||
#[expect(unused)] | ||
pub(crate) public: bool, | ||
pub(crate) ident: BoxStr, | ||
#[expect(unused)] | ||
pub(crate) fields: Vec<Field>, | ||
} | ||
|
||
impl Union { | ||
/// Return the identifier of the union as a string. | ||
pub fn ident(&self) -> &str { | ||
&self.ident | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.