#![warn(missing_docs)]
#![warn(unreachable_pub)]
#![warn(missing_debug_implementations)]
#[cfg(test)]
mod tests;
mod ast;
mod cdecl;
mod ffi_items;
mod generator;
mod macro_expansion;
mod runner;
mod template;
mod translator;
use std::env;
pub use ast::{
Abi,
Const,
Field,
Fn,
Parameter,
Static,
Struct,
Type,
Union,
};
pub use generator::TestGenerator;
pub use macro_expansion::expand;
pub use runner::{
__compile_test,
__run_test,
generate_test,
};
pub use translator::TranslationError;
use crate::generator::GenerationError;
pub type Error = Box<dyn std::error::Error>;
pub type Result<T, E = Error> = std::result::Result<T, E>;
type BoxStr = Box<str>;
pub(crate) const EDITION: &str = "2021";
#[derive(Debug, Clone)]
#[non_exhaustive]
pub enum VolatileItemKind {
StructField(Struct, Field),
Static(Static),
FnArgument(Fn, Box<Parameter>),
FnReturnType(Fn),
}
#[derive(Debug, Clone)]
pub(crate) enum MapInput<'a> {
Struct(&'a Struct),
Union(&'a Union),
Fn(&'a crate::Fn),
StructField(&'a Struct, &'a Field),
UnionField(&'a Union, &'a Field),
Alias(&'a Type),
Const(&'a Const),
Static(&'a Static),
Type(&'a str),
StructType(&'a str),
UnionType(&'a str),
CEnumType(&'a str),
StructFieldType(&'a Struct, &'a Field),
UnionFieldType(&'a Union, &'a Field),
}
#[derive(Debug, Default, Clone)]
#[non_exhaustive]
pub enum Language {
#[default]
C,
CXX,
}
impl Language {
pub(crate) fn extension(&self) -> &str {
match self {
Self::C => "c",
Self::CXX => "cpp",
}
}
}
fn get_build_target(generator: &TestGenerator) -> Result<String, GenerationError> {
generator
.target
.clone()
.or_else(|| env::var("TARGET").ok())
.or_else(|| env::var("TARGET_PLATFORM").ok())
.ok_or(GenerationError::EnvVarNotFound(
"TARGET, TARGET_PLATFORM".to_string(),
))
}
impl<'a> From<&'a Const> for MapInput<'a> {
fn from(c: &'a Const) -> Self {
MapInput::Const(c)
}
}
impl<'a> From<&'a crate::Fn> for MapInput<'a> {
fn from(f: &'a crate::Fn) -> Self {
MapInput::Fn(f)
}
}
impl<'a> From<&'a Type> for MapInput<'a> {
fn from(a: &'a Type) -> Self {
MapInput::Alias(a)
}
}
impl<'a> From<&'a Static> for MapInput<'a> {
fn from(s: &'a Static) -> Self {
MapInput::Static(s)
}
}
impl<'a> From<&'a Struct> for MapInput<'a> {
fn from(s: &'a Struct) -> Self {
MapInput::Struct(s)
}
}
impl<'a> From<&'a Union> for MapInput<'a> {
fn from(u: &'a Union) -> Self {
MapInput::Union(u)
}
}