From 7a6b8ad2ef32dd9e19556f6c14d912122230fafd Mon Sep 17 00:00:00 2001 From: Thibaut Lorrain Date: Fri, 21 Jul 2023 14:59:02 +0200 Subject: [PATCH] Add java support (using JNA) This builds on #853 and adds a new language backend capable of generating java bindings. The generated bindings use [JNA](https://github.com/java-native-access/jna) (I used the last version 5.13.0 while developping but this will probably work with earlier ones as well) Most of the new code lives in `bindgen/language_backend/java_jna.rs` and is pretty straightfowards generation as most on the complicated things were done in the previous refactoring. The test suite has been updated to generate and compile the bindings for java when running. On nice thing gained with this is the possibilibty to put a configuration file specific to a language alongside the stardard one and the test will take this one instead of the default one if it exists (quite a few test use the `header` config to add some more code inside the generated bindings, C or preprocessor code doesn't work well in a java source file :P) All tests are green, but that doesn't mean all the generated bindings are correct, some cases may fail at runtime as I didn't test all cases in a real program. I did however generate and use the bindings on a non trivial lib I'm developping and they worked as expected. --- src/bindgen/bindings.rs | 10 +- src/bindgen/builder.rs | 4 + src/bindgen/cargo/cargo.rs | 20 +- src/bindgen/cargo/cargo_toml.rs | 6 + src/bindgen/config.rs | 51 ++ src/bindgen/ir/cfg.rs | 48 +- src/bindgen/ir/constant.rs | 18 +- src/bindgen/ir/enumeration.rs | 2 + src/bindgen/language_backend/clike.rs | 3 +- src/bindgen/language_backend/java_jna.rs | 843 ++++++++++++++++++ src/bindgen/language_backend/mod.rs | 3 + src/bindgen/library.rs | 4 + src/bindgen/writer.rs | 4 +- src/main.rs | 32 +- tests/expectations/abi_string.java | 16 + tests/expectations/alias.java | 240 +++++ tests/expectations/annotation.java | 189 ++++ tests/expectations/array.java | 50 ++ tests/expectations/asserted_cast.java | 146 +++ tests/expectations/assoc_const_conflict.java | 15 + tests/expectations/assoc_constant.java | 44 + .../associated_constant_panic.java | 12 + tests/expectations/associated_in_body.java | 204 +++++ tests/expectations/bitfield.java | 46 + tests/expectations/bitflags.java | 233 +++++ tests/expectations/body.java | 297 ++++++ tests/expectations/box.java | 85 ++ tests/expectations/cdecl.java | 202 +++++ tests/expectations/cell.java | 80 ++ tests/expectations/cfg.java | 232 +++++ tests/expectations/cfg_2.java | 45 + tests/expectations/cfg_field.java | 12 + tests/expectations/char.java | 44 + tests/expectations/const_conflict.java | 15 + tests/expectations/const_generics.java | 85 ++ .../expectations/const_generics_arrayvec.java | 46 + tests/expectations/const_generics_bool.java | 140 +++ tests/expectations/const_generics_byte.java | 82 ++ tests/expectations/const_generics_char.java | 48 + .../expectations/const_generics_constant.java | 97 ++ tests/expectations/const_generics_thru.java | 136 +++ tests/expectations/const_transparent.java | 50 ++ tests/expectations/constant.java | 106 +++ tests/expectations/constant_big.java | 24 + tests/expectations/constant_constexpr.java | 59 ++ tests/expectations/constant_sort_name.java | 22 + tests/expectations/constant_sort_none.java | 22 + .../constant_user_defined_type.java | 122 +++ tests/expectations/custom_header.java | 21 + tests/expectations/cython_options.java | 12 + tests/expectations/decl_name_conflicting.java | 81 ++ tests/expectations/dep_v2.java | 46 + tests/expectations/deprecated.java | 192 ++++ tests/expectations/derive_eq.java | 85 ++ tests/expectations/derive_ostream.java | 260 ++++++ .../destructor_and_copy_ctor.java | 474 ++++++++++ tests/expectations/display_list.java | 124 +++ tests/expectations/doclength_short.java | 31 + tests/expectations/docstyle_auto.java | 18 + tests/expectations/docstyle_c99.java | 18 + tests/expectations/docstyle_doxy.java | 18 + tests/expectations/documentation.java | 35 + tests/expectations/documentation_attr.java | 29 + tests/expectations/enum.java | 703 +++++++++++++++ tests/expectations/enum_discriminant.java | 59 ++ tests/expectations/enum_self.java | 82 ++ tests/expectations/euclid.java | 619 +++++++++++++ .../exclude_generic_monomorph.java | 46 + tests/expectations/expand.java | 40 + .../expectations/expand_default_features.java | 42 + tests/expectations/expand_dep.java | 46 + tests/expectations/expand_dep_v2.java | 46 + tests/expectations/expand_features.java | 44 + .../expand_no_default_features.java | 40 + tests/expectations/export_name.java | 14 + tests/expectations/extern.java | 48 + tests/expectations/extern_2.java | 16 + .../external_workspace_child.java | 44 + tests/expectations/fns.java | 62 ++ tests/expectations/forward_declaration.java | 115 +++ tests/expectations/function_args.java | 18 + tests/expectations/function_noreturn.java | 46 + tests/expectations/function_ptr.java | 26 + tests/expectations/function_sort_name.java | 20 + tests/expectations/function_sort_none.java | 20 + tests/expectations/generic_pointer.java | 62 ++ tests/expectations/global_attr.java | 12 + tests/expectations/global_variable.java | 16 + tests/expectations/ignore.java | 14 + tests/expectations/include.java | 12 + tests/expectations/include_guard.java | 14 + tests/expectations/include_item.java | 74 ++ tests/expectations/include_specific.java | 12 + .../infinite_recursion_typedef_monomorph.java | 12 + tests/expectations/inner_mod.java | 44 + tests/expectations/item_types.java | 49 + tests/expectations/item_types_renamed.java | 49 + tests/expectations/layout.java | 459 ++++++++++ tests/expectations/layout_aligned_opaque.java | 221 +++++ tests/expectations/layout_packed_opaque.java | 305 +++++++ tests/expectations/lifetime_arg.java | 81 ++ tests/expectations/linestyle_cr.java | 1 + tests/expectations/linestyle_crlf.java | 46 + tests/expectations/linestyle_lf.java | 46 + tests/expectations/literal_target.java | 12 + tests/expectations/mangle.java | 99 ++ tests/expectations/manuallydrop.java | 115 +++ tests/expectations/maybeuninit.java | 81 ++ tests/expectations/mod_2015.java | 49 + tests/expectations/mod_2018.java | 81 ++ tests/expectations/mod_attr.java | 79 ++ tests/expectations/mod_path.java | 47 + tests/expectations/monomorph_1.java | 247 +++++ tests/expectations/monomorph_2.java | 116 +++ tests/expectations/monomorph_3.java | 247 +++++ tests/expectations/must_use.java | 82 ++ tests/expectations/namespace_constant.java | 50 ++ tests/expectations/namespaces_constant.java | 50 ++ tests/expectations/nested_import.java | 12 + tests/expectations/no_includes.java | 14 + tests/expectations/non_pub_extern.java | 20 + tests/expectations/nonnull.java | 78 ++ tests/expectations/nonnull_attribute.java | 133 +++ tests/expectations/nonzero.java | 91 ++ tests/expectations/opaque.java | 113 +++ tests/expectations/pin.java | 47 + tests/expectations/pragma_once.java | 14 + tests/expectations/prefix.java | 97 ++ .../expectations/prefixed_struct_literal.java | 51 ++ .../prefixed_struct_literal_deep.java | 81 ++ tests/expectations/ptrs_as_arrays.java | 22 + tests/expectations/raw_ident.java | 83 ++ tests/expectations/raw_lines.java | 14 + tests/expectations/rename.java | 177 ++++ tests/expectations/rename_case.java | 22 + tests/expectations/rename_crate.java | 81 ++ .../renaming_overrides_prefixing.java | 64 ++ tests/expectations/reserved.java | 188 ++++ tests/expectations/sentinel.java | 143 +++ tests/expectations/simplify_option_ptr.java | 127 +++ tests/expectations/size_types.java | 156 ++++ tests/expectations/static.java | 64 ++ tests/expectations/std_lib.java | 68 ++ tests/expectations/struct.java | 160 ++++ tests/expectations/struct_literal.java | 75 ++ tests/expectations/struct_literal_order.java | 94 ++ tests/expectations/struct_self.java | 76 ++ tests/expectations/style_crash.java | 12 + tests/expectations/swift_name.java | 129 +++ tests/expectations/transform_op.java | 306 +++++++ tests/expectations/transparent.java | 280 ++++++ tests/expectations/typedef.java | 64 ++ tests/expectations/union.java | 96 ++ tests/expectations/union_self.java | 76 ++ tests/expectations/using_namespaces.java | 14 + tests/expectations/va_list.java | 16 + tests/expectations/workspace.java | 47 + tests/expectations/zst.java | 46 + tests/rust/asserted_cast.java-jna.toml | 5 + tests/rust/box.java-jna.toml | 6 + tests/rust/cfg.java-jna.toml | 19 + tests/rust/cfg_2.java-jna.toml | 7 + tests/rust/custom_header.java-jna.toml | 11 + tests/rust/deprecated.java-jna.toml | 1 + .../destructor_and_copy_ctor.java-jna.toml | 14 + tests/rust/enum.java-jna.toml | 13 + .../exclude_generic_monomorph.java-jna.toml | 10 + tests/rust/forward_declaration.java-jna.toml | 5 + tests/rust/layout.java-jna.toml | 27 + .../rust/layout_aligned_opaque.java-jna.toml | 20 + tests/rust/layout_packed_opaque.java-jna.toml | 20 + tests/rust/manuallydrop.java-jna.toml | 6 + tests/rust/maybeuninit.java-jna.toml | 6 + tests/rust/mod_attr/cbindgen.java-jna.toml | 7 + tests/rust/must_use.java-jna.toml | 11 + tests/rust/nonnull_attribute.java-jna.toml | 5 + tests/rust/nonzero.java-jna.toml | 2 + tests/rust/opaque.java-jna.toml | 2 + tests/rust/pin.java-jna.toml | 7 + .../rust/rename_crate/cbindgen.java-jna.toml | 17 + tests/rust/swift_name.java-jna.toml | 4 + tests/tests.rs | 58 +- 182 files changed, 14512 insertions(+), 40 deletions(-) create mode 100644 src/bindgen/language_backend/java_jna.rs create mode 100644 tests/expectations/abi_string.java create mode 100644 tests/expectations/alias.java create mode 100644 tests/expectations/annotation.java create mode 100644 tests/expectations/array.java create mode 100644 tests/expectations/asserted_cast.java create mode 100644 tests/expectations/assoc_const_conflict.java create mode 100644 tests/expectations/assoc_constant.java create mode 100644 tests/expectations/associated_constant_panic.java create mode 100644 tests/expectations/associated_in_body.java create mode 100644 tests/expectations/bitfield.java create mode 100644 tests/expectations/bitflags.java create mode 100644 tests/expectations/body.java create mode 100644 tests/expectations/box.java create mode 100644 tests/expectations/cdecl.java create mode 100644 tests/expectations/cell.java create mode 100644 tests/expectations/cfg.java create mode 100644 tests/expectations/cfg_2.java create mode 100644 tests/expectations/cfg_field.java create mode 100644 tests/expectations/char.java create mode 100644 tests/expectations/const_conflict.java create mode 100644 tests/expectations/const_generics.java create mode 100644 tests/expectations/const_generics_arrayvec.java create mode 100644 tests/expectations/const_generics_bool.java create mode 100644 tests/expectations/const_generics_byte.java create mode 100644 tests/expectations/const_generics_char.java create mode 100644 tests/expectations/const_generics_constant.java create mode 100644 tests/expectations/const_generics_thru.java create mode 100644 tests/expectations/const_transparent.java create mode 100644 tests/expectations/constant.java create mode 100644 tests/expectations/constant_big.java create mode 100644 tests/expectations/constant_constexpr.java create mode 100644 tests/expectations/constant_sort_name.java create mode 100644 tests/expectations/constant_sort_none.java create mode 100644 tests/expectations/constant_user_defined_type.java create mode 100644 tests/expectations/custom_header.java create mode 100644 tests/expectations/cython_options.java create mode 100644 tests/expectations/decl_name_conflicting.java create mode 100644 tests/expectations/dep_v2.java create mode 100644 tests/expectations/deprecated.java create mode 100644 tests/expectations/derive_eq.java create mode 100644 tests/expectations/derive_ostream.java create mode 100644 tests/expectations/destructor_and_copy_ctor.java create mode 100644 tests/expectations/display_list.java create mode 100644 tests/expectations/doclength_short.java create mode 100644 tests/expectations/docstyle_auto.java create mode 100644 tests/expectations/docstyle_c99.java create mode 100644 tests/expectations/docstyle_doxy.java create mode 100644 tests/expectations/documentation.java create mode 100644 tests/expectations/documentation_attr.java create mode 100644 tests/expectations/enum.java create mode 100644 tests/expectations/enum_discriminant.java create mode 100644 tests/expectations/enum_self.java create mode 100644 tests/expectations/euclid.java create mode 100644 tests/expectations/exclude_generic_monomorph.java create mode 100644 tests/expectations/expand.java create mode 100644 tests/expectations/expand_default_features.java create mode 100644 tests/expectations/expand_dep.java create mode 100644 tests/expectations/expand_dep_v2.java create mode 100644 tests/expectations/expand_features.java create mode 100644 tests/expectations/expand_no_default_features.java create mode 100644 tests/expectations/export_name.java create mode 100644 tests/expectations/extern.java create mode 100644 tests/expectations/extern_2.java create mode 100644 tests/expectations/external_workspace_child.java create mode 100644 tests/expectations/fns.java create mode 100644 tests/expectations/forward_declaration.java create mode 100644 tests/expectations/function_args.java create mode 100644 tests/expectations/function_noreturn.java create mode 100644 tests/expectations/function_ptr.java create mode 100644 tests/expectations/function_sort_name.java create mode 100644 tests/expectations/function_sort_none.java create mode 100644 tests/expectations/generic_pointer.java create mode 100644 tests/expectations/global_attr.java create mode 100644 tests/expectations/global_variable.java create mode 100644 tests/expectations/ignore.java create mode 100644 tests/expectations/include.java create mode 100644 tests/expectations/include_guard.java create mode 100644 tests/expectations/include_item.java create mode 100644 tests/expectations/include_specific.java create mode 100644 tests/expectations/infinite_recursion_typedef_monomorph.java create mode 100644 tests/expectations/inner_mod.java create mode 100644 tests/expectations/item_types.java create mode 100644 tests/expectations/item_types_renamed.java create mode 100644 tests/expectations/layout.java create mode 100644 tests/expectations/layout_aligned_opaque.java create mode 100644 tests/expectations/layout_packed_opaque.java create mode 100644 tests/expectations/lifetime_arg.java create mode 100644 tests/expectations/linestyle_cr.java create mode 100644 tests/expectations/linestyle_crlf.java create mode 100644 tests/expectations/linestyle_lf.java create mode 100644 tests/expectations/literal_target.java create mode 100644 tests/expectations/mangle.java create mode 100644 tests/expectations/manuallydrop.java create mode 100644 tests/expectations/maybeuninit.java create mode 100644 tests/expectations/mod_2015.java create mode 100644 tests/expectations/mod_2018.java create mode 100644 tests/expectations/mod_attr.java create mode 100644 tests/expectations/mod_path.java create mode 100644 tests/expectations/monomorph_1.java create mode 100644 tests/expectations/monomorph_2.java create mode 100644 tests/expectations/monomorph_3.java create mode 100644 tests/expectations/must_use.java create mode 100644 tests/expectations/namespace_constant.java create mode 100644 tests/expectations/namespaces_constant.java create mode 100644 tests/expectations/nested_import.java create mode 100644 tests/expectations/no_includes.java create mode 100644 tests/expectations/non_pub_extern.java create mode 100644 tests/expectations/nonnull.java create mode 100644 tests/expectations/nonnull_attribute.java create mode 100644 tests/expectations/nonzero.java create mode 100644 tests/expectations/opaque.java create mode 100644 tests/expectations/pin.java create mode 100644 tests/expectations/pragma_once.java create mode 100644 tests/expectations/prefix.java create mode 100644 tests/expectations/prefixed_struct_literal.java create mode 100644 tests/expectations/prefixed_struct_literal_deep.java create mode 100644 tests/expectations/ptrs_as_arrays.java create mode 100644 tests/expectations/raw_ident.java create mode 100644 tests/expectations/raw_lines.java create mode 100644 tests/expectations/rename.java create mode 100644 tests/expectations/rename_case.java create mode 100644 tests/expectations/rename_crate.java create mode 100644 tests/expectations/renaming_overrides_prefixing.java create mode 100644 tests/expectations/reserved.java create mode 100644 tests/expectations/sentinel.java create mode 100644 tests/expectations/simplify_option_ptr.java create mode 100644 tests/expectations/size_types.java create mode 100644 tests/expectations/static.java create mode 100644 tests/expectations/std_lib.java create mode 100644 tests/expectations/struct.java create mode 100644 tests/expectations/struct_literal.java create mode 100644 tests/expectations/struct_literal_order.java create mode 100644 tests/expectations/struct_self.java create mode 100644 tests/expectations/style_crash.java create mode 100644 tests/expectations/swift_name.java create mode 100644 tests/expectations/transform_op.java create mode 100644 tests/expectations/transparent.java create mode 100644 tests/expectations/typedef.java create mode 100644 tests/expectations/union.java create mode 100644 tests/expectations/union_self.java create mode 100644 tests/expectations/using_namespaces.java create mode 100644 tests/expectations/va_list.java create mode 100644 tests/expectations/workspace.java create mode 100644 tests/expectations/zst.java create mode 100644 tests/rust/asserted_cast.java-jna.toml create mode 100644 tests/rust/box.java-jna.toml create mode 100644 tests/rust/cfg.java-jna.toml create mode 100644 tests/rust/cfg_2.java-jna.toml create mode 100644 tests/rust/custom_header.java-jna.toml create mode 100644 tests/rust/deprecated.java-jna.toml create mode 100644 tests/rust/destructor_and_copy_ctor.java-jna.toml create mode 100644 tests/rust/enum.java-jna.toml create mode 100644 tests/rust/exclude_generic_monomorph.java-jna.toml create mode 100644 tests/rust/forward_declaration.java-jna.toml create mode 100644 tests/rust/layout.java-jna.toml create mode 100644 tests/rust/layout_aligned_opaque.java-jna.toml create mode 100644 tests/rust/layout_packed_opaque.java-jna.toml create mode 100644 tests/rust/manuallydrop.java-jna.toml create mode 100644 tests/rust/maybeuninit.java-jna.toml create mode 100644 tests/rust/mod_attr/cbindgen.java-jna.toml create mode 100644 tests/rust/must_use.java-jna.toml create mode 100644 tests/rust/nonnull_attribute.java-jna.toml create mode 100644 tests/rust/nonzero.java-jna.toml create mode 100644 tests/rust/opaque.java-jna.toml create mode 100644 tests/rust/pin.java-jna.toml create mode 100644 tests/rust/rename_crate/cbindgen.java-jna.toml create mode 100644 tests/rust/swift_name.java-jna.toml diff --git a/src/bindgen/bindings.rs b/src/bindgen/bindings.rs index 329860ddf..aa278eb62 100644 --- a/src/bindgen/bindings.rs +++ b/src/bindgen/bindings.rs @@ -16,7 +16,8 @@ use crate::bindgen::ir::{ Constant, Function, ItemContainer, ItemMap, Path as BindgenPath, Static, Struct, Type, Typedef, }; use crate::bindgen::language_backend::{ - CLikeLanguageBackend, CythonLanguageBackend, LanguageBackend, NamespaceOperation, + CLikeLanguageBackend, CythonLanguageBackend, JavaJnaLanguageBackend, LanguageBackend, + NamespaceOperation, }; use crate::bindgen::writer::SourceWriter; @@ -36,6 +37,7 @@ pub struct Bindings { /// Bindings are generated by a recursive call to cbindgen /// and shouldn't do anything when written anywhere. noop: bool, + binding_crate_lib_name: String, } impl Bindings { @@ -50,6 +52,7 @@ impl Bindings { functions: Vec, source_files: Vec, noop: bool, + binding_crate_lib_name: String, ) -> Bindings { Bindings { config, @@ -62,6 +65,7 @@ impl Bindings { functions, source_files, noop, + binding_crate_lib_name, } } @@ -207,6 +211,10 @@ impl Bindings { Language::Cython => { self.write_with_backend(file, &CythonLanguageBackend::new(&self.config)) } + Language::JavaJna => self.write_with_backend( + file, + &JavaJnaLanguageBackend::new(&self.config, self.binding_crate_lib_name.clone()), + ), } } diff --git a/src/bindgen/builder.rs b/src/bindgen/builder.rs index a0328b409..2ea93e82a 100644 --- a/src/bindgen/builder.rs +++ b/src/bindgen/builder.rs @@ -361,6 +361,7 @@ impl Builder { Default::default(), Default::default(), true, + Default::default(), )); } @@ -405,6 +406,9 @@ impl Builder { result.typedefs, result.functions, result.source_files, + self.lib_cargo + .map(|cargo| cargo.binding_crate_lib_name().to_string()) + .unwrap_or_default(), ) .generate() } diff --git a/src/bindgen/cargo/cargo.rs b/src/bindgen/cargo/cargo.rs index 69cf938b3..b9b308fe0 100644 --- a/src/bindgen/cargo/cargo.rs +++ b/src/bindgen/cargo/cargo.rs @@ -25,6 +25,7 @@ fn parse_dep_string(dep_string: &str) -> (&str, Option<&str>) { pub(crate) struct Cargo { manifest_path: PathBuf, binding_crate_name: String, + binding_crate_lib_name: String, lock: Option, metadata: Metadata, clean: bool, @@ -63,19 +64,24 @@ impl Cargo { None }; + let manifest = cargo_toml::manifest(&toml_path) + .map_err(|x| Error::CargoToml(toml_path.to_str().unwrap().to_owned(), x))?; + // Use the specified binding crate name or infer it from the manifest let binding_crate_name = match binding_crate_name { Some(s) => s.to_owned(), - None => { - let manifest = cargo_toml::manifest(&toml_path) - .map_err(|x| Error::CargoToml(toml_path.to_str().unwrap().to_owned(), x))?; - manifest.package.name - } + None => manifest.package.name, }; + let binding_crate_lib_name = manifest + .lib + .and_then(|lib| lib.name) + .unwrap_or_else(|| binding_crate_name.clone()); + Ok(Cargo { manifest_path: toml_path, binding_crate_name, + binding_crate_lib_name, lock, metadata, clean, @@ -86,6 +92,10 @@ impl Cargo { &self.binding_crate_name } + pub(crate) fn binding_crate_lib_name(&self) -> &str { + &self.binding_crate_lib_name + } + pub(crate) fn binding_crate_ref(&self) -> PackageRef { match self.find_pkg_ref(&self.binding_crate_name) { Some(pkg_ref) => pkg_ref, diff --git a/src/bindgen/cargo/cargo_toml.rs b/src/bindgen/cargo/cargo_toml.rs index 998176e0d..4312e0766 100644 --- a/src/bindgen/cargo/cargo_toml.rs +++ b/src/bindgen/cargo/cargo_toml.rs @@ -50,6 +50,7 @@ impl error::Error for Error { #[derive(Clone, Deserialize, Debug)] pub struct Manifest { pub package: Package, + pub lib: Option, } #[derive(Clone, Deserialize, Debug)] @@ -57,6 +58,11 @@ pub struct Package { pub name: String, } +#[derive(Clone, Deserialize, Debug)] +pub struct Lib { + pub name: Option, +} + /// Parse the Cargo.toml for a given path pub fn manifest(manifest_path: &Path) -> Result { let mut s = String::new(); diff --git a/src/bindgen/config.rs b/src/bindgen/config.rs index 5012414b7..c1dfa82a3 100644 --- a/src/bindgen/config.rs +++ b/src/bindgen/config.rs @@ -4,6 +4,7 @@ use std::collections::{BTreeMap, HashMap}; use std::default::Default; +use std::fmt::{Display, Formatter}; use std::str::FromStr; use std::{fmt, fs, path::Path as StdPath, path::PathBuf as StdPathBuf}; @@ -23,6 +24,7 @@ pub enum Language { Cxx, C, Cython, + JavaJna, } impl FromStr for Language { @@ -42,11 +44,40 @@ impl FromStr for Language { "C" => Ok(Language::C), "cython" => Ok(Language::Cython), "Cython" => Ok(Language::Cython), + "Java-JNA" => Ok(Language::JavaJna), + "Java-Jna" => Ok(Language::JavaJna), + "java-jna" => Ok(Language::JavaJna), + "JavaJNA" => Ok(Language::JavaJna), + "JavaJna" => Ok(Language::JavaJna), + "javajna" => Ok(Language::JavaJna), _ => Err(format!("Unrecognized Language: '{}'.", s)), } } } +impl Display for Language { + fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { + write!( + f, + "{}", + match self { + Language::Cxx => { + "cxx" + } + Language::C => { + "c" + } + Language::Cython => { + "cython" + } + Language::JavaJna => { + "java-jna" + } + } + ) + } +} + deserialize_enum_str!(Language); impl Language { @@ -54,6 +85,7 @@ impl Language { match self { Language::Cxx | Language::C => "typedef", Language::Cython => "ctypedef", + _ => unimplemented!(), } } } @@ -888,6 +920,22 @@ pub struct CythonConfig { pub cimports: BTreeMap>, } +/// Settings specific to Java bindings. +#[derive(Debug, Clone, Default, Deserialize)] +#[serde(rename_all = "snake_case")] +#[serde(deny_unknown_fields)] +#[serde(default)] +pub struct JavaConfig { + /// Package to use + pub package: Option, + + /// Name of the generated interface + pub interface_name: Option, + + /// Extra definition to include inside the generated interface + pub extra_defs: Option, +} + /// A collection of settings to customize the generated bindings. #[derive(Debug, Clone, Deserialize)] #[serde(rename_all = "snake_case")] @@ -1010,6 +1058,8 @@ pub struct Config { pub only_target_dependencies: bool, /// Configuration options specific to Cython. pub cython: CythonConfig, + /// Configuration options specific to Java (JNA backend) + pub java_jna: JavaConfig, #[serde(skip)] pub(crate) config_path: Option, } @@ -1054,6 +1104,7 @@ impl Default for Config { pointer: PtrConfig::default(), only_target_dependencies: false, cython: CythonConfig::default(), + java_jna: JavaConfig::default(), config_path: None, } } diff --git a/src/bindgen/ir/cfg.rs b/src/bindgen/ir/cfg.rs index e8aa4126a..43d1e2b01 100644 --- a/src/bindgen/ir/cfg.rs +++ b/src/bindgen/ir/cfg.rs @@ -336,29 +336,43 @@ pub trait ConditionWrite { impl ConditionWrite for Option { fn write_before(&self, config: &Config, out: &mut SourceWriter) { if let Some(ref cfg) = *self { - if config.language == Language::Cython { - out.write("IF "); - cfg.write(config, out); - out.open_brace(); - } else { - out.push_set_spaces(0); - out.write("#if "); - cfg.write(config, out); - out.pop_set_spaces(); - out.new_line(); + match config.language { + Language::Cython => { + out.write("IF "); + cfg.write(config, out); + out.open_brace(); + } + Language::Cxx | Language::C => { + out.push_set_spaces(0); + out.write("#if "); + cfg.write(config, out); + out.pop_set_spaces(); + out.new_line(); + } + Language::JavaJna => { + write!(out, "/* begin condition not supported {self:?} */"); + out.new_line(); + } } } } fn write_after(&self, config: &Config, out: &mut SourceWriter) { if self.is_some() { - if config.language == Language::Cython { - out.close_brace(false); - } else { - out.new_line(); - out.push_set_spaces(0); - out.write("#endif"); - out.pop_set_spaces(); + match config.language { + Language::Cython => { + out.close_brace(false); + } + Language::Cxx | Language::C => { + out.new_line(); + out.push_set_spaces(0); + out.write("#endif"); + out.pop_set_spaces(); + } + Language::JavaJna => { + out.new_line(); + write!(out, "/* end condition not supported {self:?} */"); + } } } } diff --git a/src/bindgen/ir/constant.rs b/src/bindgen/ir/constant.rs index 3f2473f31..8c14c8aeb 100644 --- a/src/bindgen/ir/constant.rs +++ b/src/bindgen/ir/constant.rs @@ -16,7 +16,7 @@ use crate::bindgen::ir::{ AnnotationSet, Cfg, ConditionWrite, Documentation, GenericParams, Item, ItemContainer, Path, Struct, ToCondition, Type, }; -use crate::bindgen::language_backend::LanguageBackend; +use crate::bindgen::language_backend::{java_writable_literal, wrap_java_value, LanguageBackend}; use crate::bindgen::library::Library; use crate::bindgen::writer::SourceWriter; use crate::bindgen::Bindings; @@ -708,6 +708,22 @@ impl Constant { write!(out, " {} # = ", name); language_backend.write_literal(out, value); } + Language::JavaJna => { + if java_writable_literal(&self.ty, value) { + out.write("public static final "); + language_backend.write_type(out, &self.ty); + write!(out, " {} = ", self.export_name); + language_backend.write_literal(out, &wrap_java_value(value, &self.ty)); + out.write(";") + } else { + write!( + out, + "/* Unsupported literal for constant {} */", + self.export_name + ) + } + out.new_line(); + } } condition.write_after(config, out); diff --git a/src/bindgen/ir/enumeration.rs b/src/bindgen/ir/enumeration.rs index 6eccfe85d..c51495c8b 100644 --- a/src/bindgen/ir/enumeration.rs +++ b/src/bindgen/ir/enumeration.rs @@ -721,6 +721,7 @@ impl Enum { write!(out, "{}enum {}", config.style.cython_def(), tag_name); } } + _ => unimplemented!(), } out.open_brace(); @@ -775,6 +776,7 @@ impl Enum { Language::C if config.style.generate_typedef() => out.write("typedef "), Language::C | Language::Cxx => {} Language::Cython => out.write(config.style.cython_def()), + _ => unimplemented!(), } out.write(if inline_tag_field { "union" } else { "struct" }); diff --git a/src/bindgen/language_backend/clike.rs b/src/bindgen/language_backend/clike.rs index 7d5a55280..a5035e6dc 100644 --- a/src/bindgen/language_backend/clike.rs +++ b/src/bindgen/language_backend/clike.rs @@ -977,7 +977,7 @@ impl LanguageBackend for CLikeLanguageBackend<'_> { return write!(out, "{}", known); } let path_separator = match self.config.language { - Language::Cython | Language::C => "_", + Language::C => "_", Language::Cxx => { if self.config.structure.associated_constants_in_body { "::" @@ -985,6 +985,7 @@ impl LanguageBackend for CLikeLanguageBackend<'_> { "_" } } + _ => unreachable!(), }; write!(out, "{}{}", export_name, path_separator) } diff --git a/src/bindgen/language_backend/java_jna.rs b/src/bindgen/language_backend/java_jna.rs new file mode 100644 index 000000000..7e6cc206b --- /dev/null +++ b/src/bindgen/language_backend/java_jna.rs @@ -0,0 +1,843 @@ +use crate::bindgen::ir::{ + Constant, Documentation, Enum, Field, Function, IntKind, Item, Literal, OpaqueItem, + PrimitiveType, Static, Struct, Type, Typedef, Union, +}; +use crate::bindgen::language_backend::{LanguageBackend, NamespaceOperation}; +use crate::bindgen::writer::ListType::Join; +use crate::bindgen::writer::SourceWriter; +use crate::bindgen::{Config, Layout}; +use std::fmt::Debug; +use std::io::Write; + +pub struct JavaJnaLanguageBackend<'a> { + config: &'a Config, + binding_lib_crate_name: String, +} + +impl<'a> JavaJnaLanguageBackend<'a> { + pub fn new(config: &'a Config, binding_lib_crate_name: String) -> Self { + Self { + config, + binding_lib_crate_name, + } + } +} + +impl LanguageBackend for JavaJnaLanguageBackend<'_> { + fn write_headers(&self, out: &mut SourceWriter) { + if let Some(ref header) = self.config.header { + out.new_line_if_not_start(); + write!(out, "{header}"); + out.new_line(); + } + + if self.config.include_version { + out.new_line_if_not_start(); + write!( + out, + "/* Generated with cbindgen:{} */", + crate::bindgen::config::VERSION + ); + out.new_line(); + } + if let Some(ref autogen_warning) = self.config.autogen_warning { + out.new_line_if_not_start(); + write!(out, "{autogen_warning}"); + out.new_line(); + } + + if let Some(ref package) = self.config.java_jna.package { + out.new_line_if_not_start(); + write!(out, "package {package};"); + out.new_line(); + out.new_line(); + } + + out.write("import com.sun.jna.*;"); + out.new_line(); + out.write("import com.sun.jna.ptr.*;"); + out.new_line(); + } + + fn open_close_namespaces(&self, op: NamespaceOperation, out: &mut SourceWriter) { + if NamespaceOperation::Open == op { + out.new_line_if_not_start(); + let name = &self + .config + .java_jna + .interface_name + .clone() + .unwrap_or("Bindings".to_string()); + + write!(out, "enum {}Singleton", name); + out.open_brace(); + out.write("INSTANCE;"); + out.new_line(); + + write!( + out, + "final {} lib = Native.load(\"{}\", {}.class);", + name, self.binding_lib_crate_name, name + ); + out.close_brace(false); + out.new_line(); + out.new_line(); + + write!(out, "interface {} extends Library", name); + out.open_brace(); + + write!(out, "{} INSTANCE = {}Singleton.INSTANCE.lib;", name, name); + out.new_line(); + + if let Some(extra) = &self.config.java_jna.extra_defs { + write!(out, "{extra}"); + out.new_line(); + } + } else { + out.close_brace(false); + } + } + + fn write_footers(&self, _: &mut SourceWriter) {} + + fn write_enum(&self, out: &mut SourceWriter, e: &Enum) { + self.write_integer_type( + out, + &e.documentation, + &e.export_name, + JnaIntegerType::Int, /* enum are most of the time the same size as ints */ + &e.annotations.deprecated, + |out| { + let mut current_discriminant = 0; + for variant in &e.variants { + current_discriminant = variant + .discriminant + .clone() + .and_then(|it| match it { + Literal::Expr(e) => e.parse::().ok(), + _ => None, + }) + .unwrap_or(current_discriminant + 1); + self.write_documentation(out, &variant.documentation); + write!( + out, + "public static final {} {} = new {}({});", + e.export_name, variant.export_name, e.export_name, current_discriminant + ); + out.new_line(); + } + }, + ); + } + + fn write_struct(&self, out: &mut SourceWriter, s: &Struct) { + let constants: Vec<(&Constant, &Struct)> = + s.associated_constants.iter().map(|it| (it, s)).collect(); + if s.is_transparent { + let field = s.fields.first(); + match field { + Some(Field { + ty: Type::Primitive(PrimitiveType::Integer { kind, .. }), + .. + }) => { + self.write_integer_type( + out, + &s.documentation, + &s.export_name, + JnaIntegerType::from_kind(kind), + &s.annotations.deprecated, + |out| { + for (constant, assoc_struct) in constants { + constant.write(self.config, self, out, Some(assoc_struct)); + } + }, + ); + } + Some(Field { + ty: Type::Path(path), + .. + }) => { + self.write_jna_struct( + out, + &JnaStruct { + documentation: &s.documentation, + constants: &constants, + fields: &vec![], + name: &s.export_name, + superclass: path.export_name(), + interface: "Structure.ByValue", + deprecated: &s.annotations.deprecated, + }, + ); + self.write_jna_struct( + out, + &JnaStruct { + documentation: &s.documentation, + constants: &constants, + fields: &vec![], + name: &format!("{}ByReference", s.export_name()), + superclass: path.export_name(), + interface: "Structure.ByReference", + deprecated: &s.annotations.deprecated, + }, + ); + } + Some(Field { + ty: Type::Array(_, _), + .. + }) => self.write_pointer_type( + out, + &s.documentation, + &s.annotations.deprecated, + s.export_name(), + ), + _ => not_implemented(s, out), + } + } else { + self.write_jna_struct( + out, + &JnaStruct { + documentation: &s.documentation, + constants: &constants, + fields: &s.fields, + name: &s.export_name, + superclass: "Structure", + interface: "Structure.ByValue", + deprecated: &s.annotations.deprecated, + }, + ); + self.write_jna_struct( + out, + &JnaStruct { + documentation: &s.documentation, + constants: &constants, + fields: &s.fields, + name: &format!("{}ByReference", s.export_name), + superclass: "Structure", + interface: "Structure.ByReference", + deprecated: &s.annotations.deprecated, + }, + ); + } + } + + fn write_union(&self, out: &mut SourceWriter, u: &Union) { + self.write_jna_struct( + out, + &JnaStruct { + documentation: &u.documentation, + constants: &vec![], + fields: &u.fields, + name: &u.export_name, + superclass: "Union", + interface: "Structure.ByValue", + deprecated: &u.annotations.deprecated, + }, + ); + self.write_jna_struct( + out, + &JnaStruct { + documentation: &u.documentation, + constants: &vec![], + fields: &u.fields, + name: &format!("{}ByReference", &u.export_name), + superclass: "Union", + interface: "Structure.ByReference", + deprecated: &u.annotations.deprecated, + }, + ); + } + + fn write_opaque_item(&self, out: &mut SourceWriter, o: &OpaqueItem) { + self.write_pointer_type( + out, + &o.documentation, + &o.annotations.deprecated, + &o.export_name, + ); + } + fn write_type_def(&self, out: &mut SourceWriter, t: &Typedef) { + match &t.aliased { + Type::FuncPtr { ret, args, .. } => { + write!(out, "interface {} extends Callback", t.export_name); + out.open_brace(); + self.write_type(out, ret); + out.write(" invoke("); + self.write_indexed_function_args( + out, + &args + .iter() + .enumerate() + .map(|(index, (name, ty))| IndexedFunctionArg { name, index, ty }) + .collect::>(), + ); + out.write(");"); + out.close_brace(false) + } + Type::Path(path) => { + self.write_documentation(out, &t.documentation); + write!( + out, + "class {} extends {}", + t.export_name, + path.export_name() + ); + out.open_brace(); + write!(out, "public {}()", t.export_name); + out.open_brace(); + out.write("super();"); + out.close_brace(false); + out.new_line(); + write!(out, "public {}(Pointer p)", t.export_name); + out.open_brace(); + out.write("super(p);"); + out.close_brace(false); + out.close_brace(false); + out.new_line(); + out.new_line(); + self.write_documentation(out, &t.documentation); + write!( + out, + "class {}ByReference extends {}ByReference", + t.export_name, + path.export_name() + ); + out.open_brace(); + write!(out, "public {}ByReference()", t.export_name); + out.open_brace(); + out.write("super();"); + out.close_brace(false); + out.new_line(); + write!(out, "public {}ByReference(Pointer p)", t.export_name); + out.open_brace(); + out.write("super(p);"); + out.close_brace(false); + out.close_brace(false); + } + Type::Primitive(primitive) => match primitive { + PrimitiveType::Integer { kind, .. } => { + let jna_type = JnaIntegerType::from_kind(kind); + self.write_integer_type( + out, + &t.documentation, + &t.export_name, + jna_type, + &t.annotations.deprecated, + |_| {}, + ) + } + _ => not_implemented(&t, out), + }, + Type::Ptr { .. } => self.write_pointer_type( + out, + &t.documentation, + &t.annotations.deprecated, + &t.export_name, + ), + Type::Array(_, _) => self.write_pointer_type( + out, + &t.documentation, + &t.annotations.deprecated, + &t.export_name, + ), + } + } + + fn write_static(&self, out: &mut SourceWriter, s: &Static) { + not_implemented(s, out) + } + + fn write_function(&self, out: &mut SourceWriter, f: &Function) { + self.write_documentation(out, &f.documentation); + self.write_deprecated(out, &f.annotations.deprecated); + self.write_type(out, &f.ret); + write!(out, " {}(", f.path.name()); + + self.write_indexed_function_args( + out, + &f.args + .iter() + .enumerate() + .map(|(index, arg)| IndexedFunctionArg { + name: &arg.name, + ty: &arg.ty, + index, + }) + .collect::>(), + ); + + out.write(");"); + } + + fn write_type(&self, out: &mut SourceWriter, t: &Type) { + match t { + Type::Ptr { ty, .. } => match &**ty { + Type::Ptr { .. } => out.write("PointerByReference"), + Type::Path(path) => { + write!(out, "{}ByReference", path.export_name()) + } + Type::Primitive(primitive) => { + let typ = match primitive { + PrimitiveType::Void => "Pointer", + PrimitiveType::Bool => "Pointer", + PrimitiveType::Char => "ByteByReference", + PrimitiveType::SChar => "ByteByReference", + PrimitiveType::UChar => "ByteByReference", + PrimitiveType::Char32 => "Pointer", + PrimitiveType::Float => "FloatByReference", + PrimitiveType::Double => "DoubleByReference", + PrimitiveType::VaList => "PointerByReference", + PrimitiveType::PtrDiffT => "PointerByReference", + PrimitiveType::Integer { kind, .. } => { + match kind { + IntKind::Short => "ShortByReference", + IntKind::Int => "IntByReference", + IntKind::Long => "NativeLongByReference", + IntKind::LongLong => "LongByReference", + IntKind::SizeT => "NativeLongByReference", // TODO probably not right + IntKind::Size => "NativeLongByReference", // TODO probably not right + IntKind::B8 => "ByteByReference", + IntKind::B16 => "ShortByReference", + IntKind::B32 => "IntByReference", + IntKind::B64 => "LongByReference", + } + } + }; + write!(out, "{typ}") + } + Type::Array(_, _) => out.write("Pointer"), + Type::FuncPtr { .. } => out.write("CallbackReference"), + }, + + Type::Path(path) => { + write!(out, "{}", path.export_name()) + } + Type::Primitive(primitive) => { + //https://github.com/java-native-access/jna/blob/master/www/Mappings.md + let typ = match primitive { + PrimitiveType::Void => "void", + PrimitiveType::Bool => "boolean", + PrimitiveType::Char => "byte", + PrimitiveType::SChar => "byte", + PrimitiveType::UChar => "byte", + PrimitiveType::Char32 => "char", + PrimitiveType::Float => "float", + PrimitiveType::Double => "double", + PrimitiveType::VaList => "Pointer", + PrimitiveType::PtrDiffT => "Pointer", + PrimitiveType::Integer { kind, .. } => { + match kind { + IntKind::Short => "short", + IntKind::Int => "int", + IntKind::Long => "NativeLong", + IntKind::LongLong => "long", + IntKind::SizeT => "NativeLong", // TODO probably not right + IntKind::Size => "NativeLong", // TODO probably not right + IntKind::B8 => "byte", + IntKind::B16 => "short", + IntKind::B32 => "int", + IntKind::B64 => "long", + } + } + }; + write!(out, "{typ}") + } + Type::Array(ty, _len) => { + self.write_type(out, ty); + out.write("[]"); + } + Type::FuncPtr { .. } => out.write("Callback"), + } + } + + fn write_documentation(&self, out: &mut SourceWriter, d: &Documentation) { + if !d.doc_comment.is_empty() { + out.new_line_if_not_start(); + out.write("/**"); + for line in &d.doc_comment { + out.new_line(); + write!(out, " *{line}") + } + out.new_line(); + out.write(" */"); + out.new_line(); + } + } + + fn write_literal(&self, out: &mut SourceWriter, l: &Literal) { + match l { + Literal::Expr(expr) => { + write!(out, "{expr}") + } + Literal::Struct { export_name, .. } => { + // There is an hashmap in there that doesn't have stable debug output + not_implemented(&format!("Struct Literal {export_name}"), out) + } + _ => not_implemented(l, out), + } + } +} + +enum JnaIntegerType { + Byte, + Short, + Int, + NativeLong, + Long, + SizeT, +} + +impl JnaIntegerType { + pub fn size(&self) -> &str { + match self { + JnaIntegerType::Byte => "1", + JnaIntegerType::Short => "2", + JnaIntegerType::Int => "4", + JnaIntegerType::NativeLong => "Native.LONG_SIZE", + JnaIntegerType::Long => "8", + JnaIntegerType::SizeT => "Native.SIZE_T_SIZE", + } + } + + pub fn set_method(&self) -> &str { + match self { + JnaIntegerType::Byte => "setByte(0, (byte)value.intValue())", + JnaIntegerType::Short => "setShort(0, (short)value.intValue())", + JnaIntegerType::Int => "setInt(0, value.intValue())", + JnaIntegerType::NativeLong | JnaIntegerType::SizeT => { + "setNativeLong(0, new NativeLong(value.longValue()))" + } + JnaIntegerType::Long => "setLong(0, value.longValue())", + } + } + + pub fn get_method(&self) -> &str { + match self { + JnaIntegerType::Byte => "getByte(0)", + JnaIntegerType::Short => "getShort(0)", + JnaIntegerType::Int => "getInt(0)", + JnaIntegerType::NativeLong | JnaIntegerType::SizeT => "getNativeLong(0).longValue()", + JnaIntegerType::Long => "getLong(0)", + } + } + + pub fn from_kind(kind: &IntKind) -> Self { + match kind { + IntKind::Short => JnaIntegerType::Short, + IntKind::Int => JnaIntegerType::Int, + IntKind::Long => JnaIntegerType::NativeLong, + IntKind::LongLong => JnaIntegerType::Long, + IntKind::SizeT => JnaIntegerType::SizeT, + IntKind::Size => JnaIntegerType::SizeT, + IntKind::B8 => JnaIntegerType::Byte, + IntKind::B16 => JnaIntegerType::Short, + IntKind::B32 => JnaIntegerType::Int, + IntKind::B64 => JnaIntegerType::Long, + } + } +} + +struct JnaStruct<'a> { + documentation: &'a Documentation, + constants: &'a Vec<(&'a Constant, &'a Struct)>, + fields: &'a Vec, + name: &'a str, + superclass: &'a str, + interface: &'a str, + deprecated: &'a Option, +} + +struct IndexedFunctionArg<'a> { + ty: &'a Type, + name: &'a Option, + index: usize, +} + +impl JavaJnaLanguageBackend<'_> { + fn write_deprecated(&self, out: &mut SourceWriter, deprecated: &Option) { + if let Some(deprecated) = deprecated { + if !deprecated.is_empty() { + out.write("/**"); + out.new_line(); + write!(out, " * @deprecated {}", deprecated); + out.new_line(); + out.write(" */"); + out.new_line(); + } + out.write("@Deprecated"); + out.new_line() + } + } + + fn write_jna_struct(&self, out: &mut SourceWriter, s: &JnaStruct) { + out.new_line(); + self.write_documentation(out, s.documentation); + self.write_deprecated(out, s.deprecated); + let field_names = s + .fields + .iter() + .map(|it| format!("\"{}\"", it.name)) + .collect::>(); + + if !field_names.is_empty() { + out.write("@Structure.FieldOrder({"); + if !out.try_write( + |out| { + out.write_horizontal_source_list(self, &field_names, Join(", "), |_, out, s| { + write!(out, "{}", s) + }) + }, + self.config.line_length, + ) { + out.write_vertical_source_list(self, &field_names, Join(","), |_, out, s| { + write!(out, "{}", s) + }) + } + out.write("})"); + out.new_line(); + } + write!( + out, + "class {} extends {} implements {}", + s.name, s.superclass, s.interface + ); + out.open_brace(); + + for (constant, assoc_struct) in s.constants { + constant.write(self.config, self, out, Some(assoc_struct)); + } + + write!(out, "public {}()", s.name); + out.open_brace(); + out.write("super();"); + out.close_brace(false); + out.new_line(); + out.new_line(); + + write!(out, "public {}(Pointer p)", s.name); + out.open_brace(); + out.write("super(p);"); + out.close_brace(false); + out.new_line(); + out.new_line(); + + for field in s.fields { + self.write_documentation(out, &field.documentation); + out.write("public "); + self.write_type(out, &field.ty); + write!(out, " {};", field.name); + + out.new_line() + } + + out.close_brace(false); + out.new_line(); + } + + fn write_indexed_function_arg( + &self, + out: &mut SourceWriter, + a: &IndexedFunctionArg, + ) { + self.write_type(out, a.ty); + write!( + out, + " {}", + a.name + .clone() + .and_then(|it| if it == "_" { None } else { Some(it) }) + .unwrap_or(format!("arg{}", a.index)) + ); + } + + fn write_indexed_function_args( + &self, + out: &mut SourceWriter, + a: &[IndexedFunctionArg], + ) { + match self.config.function.args { + Layout::Horizontal => out.write_horizontal_source_list( + self, + a, + Join(", "), + Self::write_indexed_function_arg, + ), + Layout::Vertical => out.write_vertical_source_list( + self, + a, + Join(", "), + Self::write_indexed_function_arg, + ), + Layout::Auto => { + if !out.try_write( + |out| { + out.write_horizontal_source_list( + self, + a, + Join(", "), + Self::write_indexed_function_arg, + ) + }, + self.config.line_length, + ) { + out.write_vertical_source_list( + self, + a, + Join(", "), + Self::write_indexed_function_arg, + ) + } + } + } + } + + fn write_integer_type)>( + &self, + out: &mut SourceWriter, + documentation: &Documentation, + name: &str, + jna_underlying_type: JnaIntegerType, + deprecated: &Option, + extra: F, + ) { + let size = jna_underlying_type.size(); + self.write_documentation(out, documentation); + self.write_deprecated(out, deprecated); + write!(out, "class {} extends IntegerType", name); + out.open_brace(); + write!(out, "public {}()", name); + out.open_brace(); + write!(out, "super({size});"); + out.close_brace(false); + out.new_line(); + out.new_line(); + write!(out, "public {}(long value)", name); + out.open_brace(); + write!(out, "super({size}, value);"); + out.close_brace(false); + out.new_line(); + out.new_line(); + write!(out, "public {}(Pointer p)", name); + out.open_brace(); + write!(out, "this(p.{});", jna_underlying_type.get_method(),); + out.close_brace(false); + out.new_line(); + extra(out); + out.close_brace(false); + out.new_line(); + out.new_line(); + + write!(out, "class {}ByReference extends ByReference", name); + out.open_brace(); + write!(out, "public {}ByReference()", name); + out.open_brace(); + write!(out, "super({size});"); + out.close_brace(false); + out.new_line(); + out.new_line(); + write!(out, "public {}ByReference(Pointer p)", name); + out.open_brace(); + write!(out, "super({size});"); + out.new_line(); + out.write("setPointer(p);"); + out.close_brace(false); + out.new_line(); + out.new_line(); + write!(out, "public {name} getValue()"); + out.open_brace(); + write!( + out, + "return new {}(getPointer().{});", + name, + jna_underlying_type.get_method() + ); + out.close_brace(false); + out.new_line(); + out.new_line(); + write!(out, "public void setValue({name} value)"); + out.open_brace(); + write!(out, "getPointer().{};", jna_underlying_type.set_method()); + out.close_brace(false); + out.new_line(); + out.close_brace(false); + } + + fn write_pointer_type( + &self, + out: &mut SourceWriter, + documentation: &Documentation, + deprecated: &Option, + name: &str, + ) { + self.write_documentation(out, documentation); + self.write_deprecated(out, deprecated); + write!(out, "class {} extends PointerType", name); + out.open_brace(); + write!(out, "public {}()", name); + out.open_brace(); + out.write("super(null);"); + out.close_brace(false); + out.new_line(); + write!(out, "public {}(Pointer p)", name); + out.open_brace(); + out.write("super(p);"); + out.close_brace(false); + out.close_brace(false); + out.new_line(); + out.new_line(); + self.write_documentation(out, documentation); + self.write_deprecated(out, deprecated); + write!(out, "class {}ByReference extends {}", name, name,); + out.open_brace(); + write!(out, "public {}ByReference()", name); + out.open_brace(); + out.write("super(null);"); + out.close_brace(false); + out.new_line(); + write!(out, "public {}ByReference(Pointer p)", name); + out.open_brace(); + out.write("super(p);"); + out.close_brace(false); + out.close_brace(false); + } +} + +pub(crate) fn wrap_java_value(literal: &Literal, ty: &Type) -> Literal { + match literal { + Literal::Expr(expr) => match ty { + Type::Primitive(primitive) => match primitive { + PrimitiveType::Double => Literal::Expr(format!("{expr}d")), + PrimitiveType::Float => Literal::Expr(format!("{expr}f")), + PrimitiveType::Integer { + kind: IntKind::LongLong | IntKind::B64, + .. + } => Literal::Expr(format!("{expr}L")), + PrimitiveType::Integer { + kind: IntKind::Long | IntKind::Size | IntKind::SizeT, + .. + } => Literal::Expr(format!("new NativeLong({expr})")), + + _ => literal.clone(), + }, + Type::Path(path) => Literal::Expr(format!("new {}({expr})", path.export_name())), + _ => literal.clone(), + }, + _ => literal.clone(), + } +} + +pub(crate) fn java_writable_literal(ty: &Type, literal: &Literal) -> bool { + // quite crude for now + match literal { + Literal::Expr(e) => { + !((ty == &Type::Primitive(PrimitiveType::Char32) && e.starts_with("U'\\U")) + || (matches!(ty, Type::Primitive(PrimitiveType::Integer { .. })) + || e.ends_with("ull"))) + } + _ => false, + } +} + +fn not_implemented(value: &T, out: &mut SourceWriter) { + write!(out, "/* Not implemented yet : {value:?} */") +} diff --git a/src/bindgen/language_backend/mod.rs b/src/bindgen/language_backend/mod.rs index 2cbe768ac..b774a7589 100644 --- a/src/bindgen/language_backend/mod.rs +++ b/src/bindgen/language_backend/mod.rs @@ -7,9 +7,12 @@ use std::io::Write; mod clike; mod cython; +mod java_jna; pub use clike::CLikeLanguageBackend; pub use cython::CythonLanguageBackend; +pub use java_jna::JavaJnaLanguageBackend; +pub(crate) use java_jna::{java_writable_literal, wrap_java_value}; #[derive(PartialEq, Eq)] pub enum NamespaceOperation { diff --git a/src/bindgen/library.rs b/src/bindgen/library.rs index cb4cfbd3a..f96f6e78d 100644 --- a/src/bindgen/library.rs +++ b/src/bindgen/library.rs @@ -27,6 +27,7 @@ pub struct Library { typedefs: ItemMap, functions: Vec, source_files: Vec, + binding_crate_lib_name: String, } impl Library { @@ -42,6 +43,7 @@ impl Library { typedefs: ItemMap, functions: Vec, source_files: Vec, + binding_crate_lib_name: String, ) -> Library { Library { config, @@ -54,6 +56,7 @@ impl Library { typedefs, functions, source_files, + binding_crate_lib_name, } } @@ -141,6 +144,7 @@ impl Library { functions, self.source_files, false, + self.binding_crate_lib_name, )) } diff --git a/src/bindgen/writer.rs b/src/bindgen/writer.rs index 051451cc3..c08a6eeb9 100644 --- a/src/bindgen/writer.rs +++ b/src/bindgen/writer.rs @@ -159,7 +159,7 @@ impl<'a, F: Write> SourceWriter<'a, F> { pub fn open_brace(&mut self) { match self.bindings.config.language { - Language::Cxx | Language::C => match self.bindings.config.braces { + Language::Cxx | Language::C | Language::JavaJna => match self.bindings.config.braces { Braces::SameLine => { self.write(" {"); self.push_tab(); @@ -183,7 +183,7 @@ impl<'a, F: Write> SourceWriter<'a, F> { pub fn close_brace(&mut self, semicolon: bool) { self.pop_tab(); match self.bindings.config.language { - Language::Cxx | Language::C => { + Language::Cxx | Language::C | Language::JavaJna => { self.new_line(); if semicolon { self.write("};"); diff --git a/src/main.rs b/src/main.rs index eb78a080b..33b58ee6b 100644 --- a/src/main.rs +++ b/src/main.rs @@ -2,31 +2,31 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -use std::env; -use std::io; -use std::path::{Path, PathBuf}; -use std::str::FromStr; - extern crate clap; #[macro_use] extern crate log; extern crate proc_macro2; #[macro_use] +extern crate quote; +#[macro_use] extern crate serde; extern crate serde_json; #[macro_use] -extern crate quote; -#[macro_use] extern crate syn; extern crate toml; +use std::env; +use std::io; +use std::path::{Path, PathBuf}; +use std::str::FromStr; + use clap::{Arg, ArgMatches, Command}; +use crate::bindgen::{Bindings, Builder, Cargo, Config, Error, Profile, Style}; + mod bindgen; mod logging; -use crate::bindgen::{Bindings, Builder, Cargo, Config, Error, Profile, Style}; - fn apply_config_overrides(config: &mut Config, matches: &ArgMatches) { // We allow specifying a language to override the config default. This is // used by compile-tests. @@ -161,7 +161,19 @@ fn main() { .long("lang") .value_name("LANGUAGE") .help("Specify the language to output bindings in") - .possible_values(["c++", "C++", "c", "C", "cython", "Cython"]), + .possible_values([ + "c++", + "C++", + "c", + "C", + "cython", + "Cython", + "Java-JNA", + "Java-Jna", + "java-jna", + "JavaJNA", + "JavaJna", + "javajna"]), ) .arg( Arg::new("cpp-compat") diff --git a/tests/expectations/abi_string.java b/tests/expectations/abi_string.java new file mode 100644 index 000000000..a5409ae0a --- /dev/null +++ b/tests/expectations/abi_string.java @@ -0,0 +1,16 @@ +import com.sun.jna.*; +import com.sun.jna.ptr.*; + +enum BindingsSingleton { + INSTANCE; + final Bindings lib = Native.load("", Bindings.class); +} + +interface Bindings extends Library { + Bindings INSTANCE = BindingsSingleton.INSTANCE.lib; + + void c(); + + void c_unwind(); + +} \ No newline at end of file diff --git a/tests/expectations/alias.java b/tests/expectations/alias.java new file mode 100644 index 000000000..4bebbdb7a --- /dev/null +++ b/tests/expectations/alias.java @@ -0,0 +1,240 @@ +import com.sun.jna.*; +import com.sun.jna.ptr.*; + +enum BindingsSingleton { + INSTANCE; + final Bindings lib = Native.load("", Bindings.class); +} + +interface Bindings extends Library { + Bindings INSTANCE = BindingsSingleton.INSTANCE.lib; + + class Status extends IntegerType { + public Status() { + super(4); + } + + public Status(long value) { + super(4, value); + } + + public Status(Pointer p) { + this(p.getInt(0)); + } + public static final Status Ok = new Status(1); + public static final Status Err = new Status(2); + + } + + class StatusByReference extends ByReference { + public StatusByReference() { + super(4); + } + + public StatusByReference(Pointer p) { + super(4); + setPointer(p); + } + + public Status getValue() { + return new Status(getPointer().getInt(0)); + } + + public void setValue(Status value) { + getPointer().setInt(0, value.intValue()); + } + + } + + + @Structure.FieldOrder({"a", "b"}) + class Dep extends Structure implements Structure.ByValue { + public Dep() { + super(); + } + + public Dep(Pointer p) { + super(p); + } + + public int a; + public float b; + + } + + @Structure.FieldOrder({"a", "b"}) + class DepByReference extends Structure implements Structure.ByReference { + public DepByReference() { + super(); + } + + public DepByReference(Pointer p) { + super(p); + } + + public int a; + public float b; + + } + + + + @Structure.FieldOrder({"a", "b", "c"}) + class Foo_i32 extends Structure implements Structure.ByValue { + public Foo_i32() { + super(); + } + + public Foo_i32(Pointer p) { + super(p); + } + + public int a; + public int b; + public Dep c; + + } + + @Structure.FieldOrder({"a", "b", "c"}) + class Foo_i32ByReference extends Structure implements Structure.ByReference { + public Foo_i32ByReference() { + super(); + } + + public Foo_i32ByReference(Pointer p) { + super(p); + } + + public int a; + public int b; + public Dep c; + + } + + + class IntFoo extends Foo_i32 { + public IntFoo() { + super(); + } + public IntFoo(Pointer p) { + super(p); + } + } + + class IntFooByReference extends Foo_i32ByReference { + public IntFooByReference() { + super(); + } + public IntFooByReference(Pointer p) { + super(p); + } + } + + + @Structure.FieldOrder({"a", "b", "c"}) + class Foo_f64 extends Structure implements Structure.ByValue { + public Foo_f64() { + super(); + } + + public Foo_f64(Pointer p) { + super(p); + } + + public double a; + public double b; + public Dep c; + + } + + @Structure.FieldOrder({"a", "b", "c"}) + class Foo_f64ByReference extends Structure implements Structure.ByReference { + public Foo_f64ByReference() { + super(); + } + + public Foo_f64ByReference(Pointer p) { + super(p); + } + + public double a; + public double b; + public Dep c; + + } + + + class DoubleFoo extends Foo_f64 { + public DoubleFoo() { + super(); + } + public DoubleFoo(Pointer p) { + super(p); + } + } + + class DoubleFooByReference extends Foo_f64ByReference { + public DoubleFooByReference() { + super(); + } + public DoubleFooByReference(Pointer p) { + super(p); + } + } + + class Unit extends IntegerType { + public Unit() { + super(4); + } + + public Unit(long value) { + super(4, value); + } + + public Unit(Pointer p) { + this(p.getInt(0)); + } + + } + + class UnitByReference extends ByReference { + public UnitByReference() { + super(4); + } + + public UnitByReference(Pointer p) { + super(4); + setPointer(p); + } + + public Unit getValue() { + return new Unit(getPointer().getInt(0)); + } + + public void setValue(Unit value) { + getPointer().setInt(0, value.intValue()); + } + + } + + class SpecialStatus extends Status { + public SpecialStatus() { + super(); + } + public SpecialStatus(Pointer p) { + super(p); + } + } + + class SpecialStatusByReference extends StatusByReference { + public SpecialStatusByReference() { + super(); + } + public SpecialStatusByReference(Pointer p) { + super(p); + } + } + + void root(IntFoo x, DoubleFoo y, Unit z, SpecialStatus w); + +} \ No newline at end of file diff --git a/tests/expectations/annotation.java b/tests/expectations/annotation.java new file mode 100644 index 000000000..64be20033 --- /dev/null +++ b/tests/expectations/annotation.java @@ -0,0 +1,189 @@ +import com.sun.jna.*; +import com.sun.jna.ptr.*; + +enum BindingsSingleton { + INSTANCE; + final Bindings lib = Native.load("", Bindings.class); +} + +interface Bindings extends Library { + Bindings INSTANCE = BindingsSingleton.INSTANCE.lib; + + class C extends IntegerType { + public C() { + super(4); + } + + public C(long value) { + super(4, value); + } + + public C(Pointer p) { + this(p.getInt(0)); + } + public static final C X = new C(2); + public static final C Y = new C(3); + + } + + class CByReference extends ByReference { + public CByReference() { + super(4); + } + + public CByReference(Pointer p) { + super(4); + setPointer(p); + } + + public C getValue() { + return new C(getPointer().getInt(0)); + } + + public void setValue(C value) { + getPointer().setInt(0, value.intValue()); + } + + } + + + @Structure.FieldOrder({"m0"}) + class A extends Structure implements Structure.ByValue { + public A() { + super(); + } + + public A(Pointer p) { + super(p); + } + + public int m0; + + } + + @Structure.FieldOrder({"m0"}) + class AByReference extends Structure implements Structure.ByReference { + public AByReference() { + super(); + } + + public AByReference(Pointer p) { + super(p); + } + + public int m0; + + } + + + + @Structure.FieldOrder({"x", "y"}) + class B extends Structure implements Structure.ByValue { + public B() { + super(); + } + + public B(Pointer p) { + super(p); + } + + public int x; + public float y; + + } + + @Structure.FieldOrder({"x", "y"}) + class BByReference extends Structure implements Structure.ByReference { + public BByReference() { + super(); + } + + public BByReference(Pointer p) { + super(p); + } + + public int x; + public float y; + + } + + + class F extends IntegerType { + public F() { + super(4); + } + + public F(long value) { + super(4, value); + } + + public F(Pointer p) { + this(p.getInt(0)); + } + public static final F Foo = new F(1); + public static final F Bar = new F(2); + public static final F Baz = new F(3); + + } + + class FByReference extends ByReference { + public FByReference() { + super(4); + } + + public FByReference(Pointer p) { + super(4); + setPointer(p); + } + + public F getValue() { + return new F(getPointer().getInt(0)); + } + + public void setValue(F value) { + getPointer().setInt(0, value.intValue()); + } + + } + + class H extends IntegerType { + public H() { + super(4); + } + + public H(long value) { + super(4, value); + } + + public H(Pointer p) { + this(p.getInt(0)); + } + public static final H Hello = new H(1); + public static final H There = new H(2); + public static final H Everyone = new H(3); + + } + + class HByReference extends ByReference { + public HByReference() { + super(4); + } + + public HByReference(Pointer p) { + super(4); + setPointer(p); + } + + public H getValue() { + return new H(getPointer().getInt(0)); + } + + public void setValue(H value) { + getPointer().setInt(0, value.intValue()); + } + + } + + void root(A x, B y, C z, F f, H h); + +} \ No newline at end of file diff --git a/tests/expectations/array.java b/tests/expectations/array.java new file mode 100644 index 000000000..6d23f081e --- /dev/null +++ b/tests/expectations/array.java @@ -0,0 +1,50 @@ +import com.sun.jna.*; +import com.sun.jna.ptr.*; + +enum BindingsSingleton { + INSTANCE; + final Bindings lib = Native.load("", Bindings.class); +} + +interface Bindings extends Library { + Bindings INSTANCE = BindingsSingleton.INSTANCE.lib; + + class Foo extends IntegerType { + public Foo() { + super(4); + } + + public Foo(long value) { + super(4, value); + } + + public Foo(Pointer p) { + this(p.getInt(0)); + } + public static final Foo A = new Foo(1); + + } + + class FooByReference extends ByReference { + public FooByReference() { + super(4); + } + + public FooByReference(Pointer p) { + super(4); + setPointer(p); + } + + public Foo getValue() { + return new Foo(getPointer().getInt(0)); + } + + public void setValue(Foo value) { + getPointer().setInt(0, value.intValue()); + } + + } + + void root(Foo a); + +} \ No newline at end of file diff --git a/tests/expectations/asserted_cast.java b/tests/expectations/asserted_cast.java new file mode 100644 index 000000000..30a6d4355 --- /dev/null +++ b/tests/expectations/asserted_cast.java @@ -0,0 +1,146 @@ +import com.sun.jna.*; +import com.sun.jna.ptr.*; + +enum BindingsSingleton { + INSTANCE; + final Bindings lib = Native.load("", Bindings.class); +} + +interface Bindings extends Library { + Bindings INSTANCE = BindingsSingleton.INSTANCE.lib; + + class I extends PointerType { + public I() { + super(null); + } + public I(Pointer p) { + super(p); + } + } + + class IByReference extends I { + public IByReference() { + super(null); + } + public IByReference(Pointer p) { + super(p); + } + } + + class H extends IntegerType { + public H() { + super(4); + } + + public H(long value) { + super(4, value); + } + + public H(Pointer p) { + this(p.getInt(0)); + } + public static final H H_Foo = new H(1); + public static final H H_Bar = new H(2); + public static final H H_Baz = new H(3); + + } + + class HByReference extends ByReference { + public HByReference() { + super(4); + } + + public HByReference(Pointer p) { + super(4); + setPointer(p); + } + + public H getValue() { + return new H(getPointer().getInt(0)); + } + + public void setValue(H value) { + getPointer().setInt(0, value.intValue()); + } + + } + + class J extends IntegerType { + public J() { + super(4); + } + + public J(long value) { + super(4, value); + } + + public J(Pointer p) { + this(p.getInt(0)); + } + public static final J J_Foo = new J(1); + public static final J J_Bar = new J(2); + public static final J J_Baz = new J(3); + + } + + class JByReference extends ByReference { + public JByReference() { + super(4); + } + + public JByReference(Pointer p) { + super(4); + setPointer(p); + } + + public J getValue() { + return new J(getPointer().getInt(0)); + } + + public void setValue(J value) { + getPointer().setInt(0, value.intValue()); + } + + } + + class K extends IntegerType { + public K() { + super(4); + } + + public K(long value) { + super(4, value); + } + + public K(Pointer p) { + this(p.getInt(0)); + } + public static final K K_Foo = new K(1); + public static final K K_Bar = new K(2); + public static final K K_Baz = new K(3); + + } + + class KByReference extends ByReference { + public KByReference() { + super(4); + } + + public KByReference(Pointer p) { + super(4); + setPointer(p); + } + + public K getValue() { + return new K(getPointer().getInt(0)); + } + + public void setValue(K value) { + getPointer().setInt(0, value.intValue()); + } + + } + + void foo(H h, I i, J j, K k); + +} \ No newline at end of file diff --git a/tests/expectations/assoc_const_conflict.java b/tests/expectations/assoc_const_conflict.java new file mode 100644 index 000000000..1ac8f55f3 --- /dev/null +++ b/tests/expectations/assoc_const_conflict.java @@ -0,0 +1,15 @@ +import com.sun.jna.*; +import com.sun.jna.ptr.*; + +enum BindingsSingleton { + INSTANCE; + final Bindings lib = Native.load("", Bindings.class); +} + +interface Bindings extends Library { + Bindings INSTANCE = BindingsSingleton.INSTANCE.lib; + + /* Unsupported literal for constant Foo_FOO */ + + +} \ No newline at end of file diff --git a/tests/expectations/assoc_constant.java b/tests/expectations/assoc_constant.java new file mode 100644 index 000000000..e2b8653bb --- /dev/null +++ b/tests/expectations/assoc_constant.java @@ -0,0 +1,44 @@ +import com.sun.jna.*; +import com.sun.jna.ptr.*; + +enum BindingsSingleton { + INSTANCE; + final Bindings lib = Native.load("", Bindings.class); +} + +interface Bindings extends Library { + Bindings INSTANCE = BindingsSingleton.INSTANCE.lib; + + + class Foo extends Structure implements Structure.ByValue { + /* Unsupported literal for constant GA */ + public static final float ZO = 3.14f; + public Foo() { + super(); + } + + public Foo(Pointer p) { + super(p); + } + + + } + + class FooByReference extends Structure implements Structure.ByReference { + /* Unsupported literal for constant GA */ + public static final float ZO = 3.14f; + public FooByReference() { + super(); + } + + public FooByReference(Pointer p) { + super(p); + } + + + } + + + void root(Foo x); + +} \ No newline at end of file diff --git a/tests/expectations/associated_constant_panic.java b/tests/expectations/associated_constant_panic.java new file mode 100644 index 000000000..90cf1e1b0 --- /dev/null +++ b/tests/expectations/associated_constant_panic.java @@ -0,0 +1,12 @@ +import com.sun.jna.*; +import com.sun.jna.ptr.*; + +enum BindingsSingleton { + INSTANCE; + final Bindings lib = Native.load("", Bindings.class); +} + +interface Bindings extends Library { + Bindings INSTANCE = BindingsSingleton.INSTANCE.lib; + +} \ No newline at end of file diff --git a/tests/expectations/associated_in_body.java b/tests/expectations/associated_in_body.java new file mode 100644 index 000000000..7fffb454d --- /dev/null +++ b/tests/expectations/associated_in_body.java @@ -0,0 +1,204 @@ +import com.sun.jna.*; +import com.sun.jna.ptr.*; + +enum BindingsSingleton { + INSTANCE; + final Bindings lib = Native.load("", Bindings.class); +} + +interface Bindings extends Library { + Bindings INSTANCE = BindingsSingleton.INSTANCE.lib; + + + + /** + * Constants shared by multiple CSS Box Alignment properties + * + * These constants match Gecko's `NS_STYLE_ALIGN_*` constants. + */ + @Structure.FieldOrder({"bits"}) + class StyleAlignFlags extends Structure implements Structure.ByValue { + + /** + * 'auto' + */ + /* Unsupported literal for constant AUTO */ + + /** + * 'normal' + */ + /* Unsupported literal for constant NORMAL */ + + /** + * 'start' + */ + /* Unsupported literal for constant START */ + + /** + * 'end' + */ + /* Unsupported literal for constant END */ + /* Unsupported literal for constant ALIAS */ + + /** + * 'flex-start' + */ + /* Unsupported literal for constant FLEX_START */ + /* Unsupported literal for constant MIXED */ + /* Unsupported literal for constant MIXED_SELF */ + public StyleAlignFlags() { + super(); + } + + public StyleAlignFlags(Pointer p) { + super(p); + } + + public byte bits; + + } + + + /** + * Constants shared by multiple CSS Box Alignment properties + * + * These constants match Gecko's `NS_STYLE_ALIGN_*` constants. + */ + @Structure.FieldOrder({"bits"}) + class StyleAlignFlagsByReference extends Structure implements Structure.ByReference { + + /** + * 'auto' + */ + /* Unsupported literal for constant AUTO */ + + /** + * 'normal' + */ + /* Unsupported literal for constant NORMAL */ + + /** + * 'start' + */ + /* Unsupported literal for constant START */ + + /** + * 'end' + */ + /* Unsupported literal for constant END */ + /* Unsupported literal for constant ALIAS */ + + /** + * 'flex-start' + */ + /* Unsupported literal for constant FLEX_START */ + /* Unsupported literal for constant MIXED */ + /* Unsupported literal for constant MIXED_SELF */ + public StyleAlignFlagsByReference() { + super(); + } + + public StyleAlignFlagsByReference(Pointer p) { + super(p); + } + + public byte bits; + + } + + + + + /** + * An arbitrary identifier for a native (OS compositor) surface + */ + @Structure.FieldOrder({"_0"}) + class StyleNativeSurfaceId extends Structure implements Structure.ByValue { + + /** + * A special id for the native surface that is used for debug / profiler overlays. + */ + /* Unsupported literal for constant DEBUG_OVERLAY */ + public StyleNativeSurfaceId() { + super(); + } + + public StyleNativeSurfaceId(Pointer p) { + super(p); + } + + public long _0; + + } + + + /** + * An arbitrary identifier for a native (OS compositor) surface + */ + @Structure.FieldOrder({"_0"}) + class StyleNativeSurfaceIdByReference extends Structure implements Structure.ByReference { + + /** + * A special id for the native surface that is used for debug / profiler overlays. + */ + /* Unsupported literal for constant DEBUG_OVERLAY */ + public StyleNativeSurfaceIdByReference() { + super(); + } + + public StyleNativeSurfaceIdByReference(Pointer p) { + super(p); + } + + public long _0; + + } + + + + @Structure.FieldOrder({"surface_id", "x", "y"}) + class StyleNativeTileId extends Structure implements Structure.ByValue { + + /** + * A special id for the native surface that is used for debug / profiler overlays. + */ + /* Unsupported literal for constant DEBUG_OVERLAY */ + public StyleNativeTileId() { + super(); + } + + public StyleNativeTileId(Pointer p) { + super(p); + } + + public StyleNativeSurfaceId surface_id; + public int x; + public int y; + + } + + @Structure.FieldOrder({"surface_id", "x", "y"}) + class StyleNativeTileIdByReference extends Structure implements Structure.ByReference { + + /** + * A special id for the native surface that is used for debug / profiler overlays. + */ + /* Unsupported literal for constant DEBUG_OVERLAY */ + public StyleNativeTileIdByReference() { + super(); + } + + public StyleNativeTileIdByReference(Pointer p) { + super(p); + } + + public StyleNativeSurfaceId surface_id; + public int x; + public int y; + + } + + + void root(StyleAlignFlags flags, StyleNativeTileId tile); + +} \ No newline at end of file diff --git a/tests/expectations/bitfield.java b/tests/expectations/bitfield.java new file mode 100644 index 000000000..8232a5c0d --- /dev/null +++ b/tests/expectations/bitfield.java @@ -0,0 +1,46 @@ +import com.sun.jna.*; +import com.sun.jna.ptr.*; + +enum BindingsSingleton { + INSTANCE; + final Bindings lib = Native.load("bitfield", Bindings.class); +} + +interface Bindings extends Library { + Bindings INSTANCE = BindingsSingleton.INSTANCE.lib; + + + @Structure.FieldOrder({"foo", "bar"}) + class HasBitfields extends Structure implements Structure.ByValue { + public HasBitfields() { + super(); + } + + public HasBitfields(Pointer p) { + super(p); + } + + public long foo; + public long bar; + + } + + @Structure.FieldOrder({"foo", "bar"}) + class HasBitfieldsByReference extends Structure implements Structure.ByReference { + public HasBitfieldsByReference() { + super(); + } + + public HasBitfieldsByReference(Pointer p) { + super(p); + } + + public long foo; + public long bar; + + } + + + void root(HasBitfieldsByReference arg0); + +} \ No newline at end of file diff --git a/tests/expectations/bitflags.java b/tests/expectations/bitflags.java new file mode 100644 index 000000000..65fbd656a --- /dev/null +++ b/tests/expectations/bitflags.java @@ -0,0 +1,233 @@ +import com.sun.jna.*; +import com.sun.jna.ptr.*; + +enum BindingsSingleton { + INSTANCE; + final Bindings lib = Native.load("", Bindings.class); +} + +interface Bindings extends Library { + Bindings INSTANCE = BindingsSingleton.INSTANCE.lib; + + + + /** + * Constants shared by multiple CSS Box Alignment properties + * + * These constants match Gecko's `NS_STYLE_ALIGN_*` constants. + */ + @Structure.FieldOrder({"bits"}) + class AlignFlags extends Structure implements Structure.ByValue { + + /** + * 'auto' + */ + /* Unsupported literal for constant AUTO */ + + /** + * 'normal' + */ + /* Unsupported literal for constant NORMAL */ + + /** + * 'start' + */ + /* Unsupported literal for constant START */ + + /** + * 'end' + */ + /* Unsupported literal for constant END */ + /* Unsupported literal for constant ALIAS */ + + /** + * 'flex-start' + */ + /* Unsupported literal for constant FLEX_START */ + /* Unsupported literal for constant MIXED */ + /* Unsupported literal for constant MIXED_SELF */ + public AlignFlags() { + super(); + } + + public AlignFlags(Pointer p) { + super(p); + } + + public byte bits; + + } + + + /** + * Constants shared by multiple CSS Box Alignment properties + * + * These constants match Gecko's `NS_STYLE_ALIGN_*` constants. + */ + @Structure.FieldOrder({"bits"}) + class AlignFlagsByReference extends Structure implements Structure.ByReference { + + /** + * 'auto' + */ + /* Unsupported literal for constant AUTO */ + + /** + * 'normal' + */ + /* Unsupported literal for constant NORMAL */ + + /** + * 'start' + */ + /* Unsupported literal for constant START */ + + /** + * 'end' + */ + /* Unsupported literal for constant END */ + /* Unsupported literal for constant ALIAS */ + + /** + * 'flex-start' + */ + /* Unsupported literal for constant FLEX_START */ + /* Unsupported literal for constant MIXED */ + /* Unsupported literal for constant MIXED_SELF */ + public AlignFlagsByReference() { + super(); + } + + public AlignFlagsByReference(Pointer p) { + super(p); + } + + public byte bits; + + } + + + + @Structure.FieldOrder({"bits"}) + class DebugFlags extends Structure implements Structure.ByValue { + + /** + * Flag with the topmost bit set of the u32 + */ + /* Unsupported literal for constant BIGGEST_ALLOWED */ + public DebugFlags() { + super(); + } + + public DebugFlags(Pointer p) { + super(p); + } + + public int bits; + + } + + @Structure.FieldOrder({"bits"}) + class DebugFlagsByReference extends Structure implements Structure.ByReference { + + /** + * Flag with the topmost bit set of the u32 + */ + /* Unsupported literal for constant BIGGEST_ALLOWED */ + public DebugFlagsByReference() { + super(); + } + + public DebugFlagsByReference(Pointer p) { + super(p); + } + + public int bits; + + } + + + + @Structure.FieldOrder({"bits"}) + class LargeFlags extends Structure implements Structure.ByValue { + + /** + * Flag with a very large shift that usually would be narrowed. + */ + /* Unsupported literal for constant LARGE_SHIFT */ + /* Unsupported literal for constant INVERTED */ + public LargeFlags() { + super(); + } + + public LargeFlags(Pointer p) { + super(p); + } + + public long bits; + + } + + @Structure.FieldOrder({"bits"}) + class LargeFlagsByReference extends Structure implements Structure.ByReference { + + /** + * Flag with a very large shift that usually would be narrowed. + */ + /* Unsupported literal for constant LARGE_SHIFT */ + /* Unsupported literal for constant INVERTED */ + public LargeFlagsByReference() { + super(); + } + + public LargeFlagsByReference(Pointer p) { + super(p); + } + + public long bits; + + } + + + + @Structure.FieldOrder({"_0"}) + class OutOfLine extends Structure implements Structure.ByValue { + /* Unsupported literal for constant A */ + /* Unsupported literal for constant B */ + /* Unsupported literal for constant AB */ + public OutOfLine() { + super(); + } + + public OutOfLine(Pointer p) { + super(p); + } + + public int _0; + + } + + @Structure.FieldOrder({"_0"}) + class OutOfLineByReference extends Structure implements Structure.ByReference { + /* Unsupported literal for constant A */ + /* Unsupported literal for constant B */ + /* Unsupported literal for constant AB */ + public OutOfLineByReference() { + super(); + } + + public OutOfLineByReference(Pointer p) { + super(p); + } + + public int _0; + + } + + + void root(AlignFlags flags, + DebugFlags bigger_flags, + LargeFlags largest_flags, + OutOfLine out_of_line); + +} \ No newline at end of file diff --git a/tests/expectations/body.java b/tests/expectations/body.java new file mode 100644 index 000000000..fc6a2870b --- /dev/null +++ b/tests/expectations/body.java @@ -0,0 +1,297 @@ +import com.sun.jna.*; +import com.sun.jna.ptr.*; + +enum BindingsSingleton { + INSTANCE; + final Bindings lib = Native.load("", Bindings.class); +} + +interface Bindings extends Library { + Bindings INSTANCE = BindingsSingleton.INSTANCE.lib; + + class MyCLikeEnum extends IntegerType { + public MyCLikeEnum() { + super(4); + } + + public MyCLikeEnum(long value) { + super(4, value); + } + + public MyCLikeEnum(Pointer p) { + this(p.getInt(0)); + } + public static final MyCLikeEnum Foo1 = new MyCLikeEnum(1); + public static final MyCLikeEnum Bar1 = new MyCLikeEnum(2); + public static final MyCLikeEnum Baz1 = new MyCLikeEnum(3); + + } + + class MyCLikeEnumByReference extends ByReference { + public MyCLikeEnumByReference() { + super(4); + } + + public MyCLikeEnumByReference(Pointer p) { + super(4); + setPointer(p); + } + + public MyCLikeEnum getValue() { + return new MyCLikeEnum(getPointer().getInt(0)); + } + + public void setValue(MyCLikeEnum value) { + getPointer().setInt(0, value.intValue()); + } + + } + + class MyCLikeEnum_Prepended extends IntegerType { + public MyCLikeEnum_Prepended() { + super(4); + } + + public MyCLikeEnum_Prepended(long value) { + super(4, value); + } + + public MyCLikeEnum_Prepended(Pointer p) { + this(p.getInt(0)); + } + public static final MyCLikeEnum_Prepended Foo1_Prepended = new MyCLikeEnum_Prepended(1); + public static final MyCLikeEnum_Prepended Bar1_Prepended = new MyCLikeEnum_Prepended(2); + public static final MyCLikeEnum_Prepended Baz1_Prepended = new MyCLikeEnum_Prepended(3); + + } + + class MyCLikeEnum_PrependedByReference extends ByReference { + public MyCLikeEnum_PrependedByReference() { + super(4); + } + + public MyCLikeEnum_PrependedByReference(Pointer p) { + super(4); + setPointer(p); + } + + public MyCLikeEnum_Prepended getValue() { + return new MyCLikeEnum_Prepended(getPointer().getInt(0)); + } + + public void setValue(MyCLikeEnum_Prepended value) { + getPointer().setInt(0, value.intValue()); + } + + } + + + @Structure.FieldOrder({"i"}) + class MyFancyStruct extends Structure implements Structure.ByValue { + public MyFancyStruct() { + super(); + } + + public MyFancyStruct(Pointer p) { + super(p); + } + + public int i; + + } + + @Structure.FieldOrder({"i"}) + class MyFancyStructByReference extends Structure implements Structure.ByReference { + public MyFancyStructByReference() { + super(); + } + + public MyFancyStructByReference(Pointer p) { + super(p); + } + + public int i; + + } + + + class MyFancyEnum extends IntegerType { + public MyFancyEnum() { + super(4); + } + + public MyFancyEnum(long value) { + super(4, value); + } + + public MyFancyEnum(Pointer p) { + this(p.getInt(0)); + } + public static final MyFancyEnum Foo = new MyFancyEnum(1); + public static final MyFancyEnum Bar = new MyFancyEnum(2); + public static final MyFancyEnum Baz = new MyFancyEnum(3); + + } + + class MyFancyEnumByReference extends ByReference { + public MyFancyEnumByReference() { + super(4); + } + + public MyFancyEnumByReference(Pointer p) { + super(4); + setPointer(p); + } + + public MyFancyEnum getValue() { + return new MyFancyEnum(getPointer().getInt(0)); + } + + public void setValue(MyFancyEnum value) { + getPointer().setInt(0, value.intValue()); + } + + } + + + @Structure.FieldOrder({"f", "u"}) + class MyUnion extends Union implements Structure.ByValue { + public MyUnion() { + super(); + } + + public MyUnion(Pointer p) { + super(p); + } + + public float f; + public int u; + + } + + @Structure.FieldOrder({"f", "u"}) + class MyUnionByReference extends Union implements Structure.ByReference { + public MyUnionByReference() { + super(); + } + + public MyUnionByReference(Pointer p) { + super(p); + } + + public float f; + public int u; + + } + + + + @Structure.FieldOrder({"i"}) + class MyFancyStruct_Prepended extends Structure implements Structure.ByValue { + public MyFancyStruct_Prepended() { + super(); + } + + public MyFancyStruct_Prepended(Pointer p) { + super(p); + } + + public int i; + + } + + @Structure.FieldOrder({"i"}) + class MyFancyStruct_PrependedByReference extends Structure implements Structure.ByReference { + public MyFancyStruct_PrependedByReference() { + super(); + } + + public MyFancyStruct_PrependedByReference(Pointer p) { + super(p); + } + + public int i; + + } + + + class MyFancyEnum_Prepended extends IntegerType { + public MyFancyEnum_Prepended() { + super(4); + } + + public MyFancyEnum_Prepended(long value) { + super(4, value); + } + + public MyFancyEnum_Prepended(Pointer p) { + this(p.getInt(0)); + } + public static final MyFancyEnum_Prepended Foo_Prepended = new MyFancyEnum_Prepended(1); + public static final MyFancyEnum_Prepended Bar_Prepended = new MyFancyEnum_Prepended(2); + public static final MyFancyEnum_Prepended Baz_Prepended = new MyFancyEnum_Prepended(3); + + } + + class MyFancyEnum_PrependedByReference extends ByReference { + public MyFancyEnum_PrependedByReference() { + super(4); + } + + public MyFancyEnum_PrependedByReference(Pointer p) { + super(4); + setPointer(p); + } + + public MyFancyEnum_Prepended getValue() { + return new MyFancyEnum_Prepended(getPointer().getInt(0)); + } + + public void setValue(MyFancyEnum_Prepended value) { + getPointer().setInt(0, value.intValue()); + } + + } + + + @Structure.FieldOrder({"f", "u"}) + class MyUnion_Prepended extends Union implements Structure.ByValue { + public MyUnion_Prepended() { + super(); + } + + public MyUnion_Prepended(Pointer p) { + super(p); + } + + public float f; + public int u; + + } + + @Structure.FieldOrder({"f", "u"}) + class MyUnion_PrependedByReference extends Union implements Structure.ByReference { + public MyUnion_PrependedByReference() { + super(); + } + + public MyUnion_PrependedByReference(Pointer p) { + super(p); + } + + public float f; + public int u; + + } + + + void root(MyFancyStruct s, + MyFancyEnum e, + MyCLikeEnum c, + MyUnion u, + MyFancyStruct_Prepended sp, + MyFancyEnum_Prepended ep, + MyCLikeEnum_Prepended cp, + MyUnion_Prepended up); + +} \ No newline at end of file diff --git a/tests/expectations/box.java b/tests/expectations/box.java new file mode 100644 index 000000000..cb927ebac --- /dev/null +++ b/tests/expectations/box.java @@ -0,0 +1,85 @@ + +import com.sun.jna.*; +import com.sun.jna.ptr.*; + +enum BindingsSingleton { + INSTANCE; + final Bindings lib = Native.load("", Bindings.class); +} + +interface Bindings extends Library { + Bindings INSTANCE = BindingsSingleton.INSTANCE.lib; + + class NotReprC_____i32 extends PointerType { + public NotReprC_____i32() { + super(null); + } + public NotReprC_____i32(Pointer p) { + super(p); + } + } + + class NotReprC_____i32ByReference extends NotReprC_____i32 { + public NotReprC_____i32ByReference() { + super(null); + } + public NotReprC_____i32ByReference(Pointer p) { + super(p); + } + } + + class Foo extends NotReprC_____i32 { + public Foo() { + super(); + } + public Foo(Pointer p) { + super(p); + } + } + + class FooByReference extends NotReprC_____i32ByReference { + public FooByReference() { + super(); + } + public FooByReference(Pointer p) { + super(p); + } + } + + + @Structure.FieldOrder({"number"}) + class MyStruct extends Structure implements Structure.ByValue { + public MyStruct() { + super(); + } + + public MyStruct(Pointer p) { + super(p); + } + + public IntByReference number; + + } + + @Structure.FieldOrder({"number"}) + class MyStructByReference extends Structure implements Structure.ByReference { + public MyStructByReference() { + super(); + } + + public MyStructByReference(Pointer p) { + super(p); + } + + public IntByReference number; + + } + + + void root(FooByReference a, MyStructByReference with_box); + + void drop_box(IntByReference x); + + void drop_box_opt(IntByReference x); + +} \ No newline at end of file diff --git a/tests/expectations/cdecl.java b/tests/expectations/cdecl.java new file mode 100644 index 000000000..2e2174fb8 --- /dev/null +++ b/tests/expectations/cdecl.java @@ -0,0 +1,202 @@ +import com.sun.jna.*; +import com.sun.jna.ptr.*; + +enum BindingsSingleton { + INSTANCE; + final Bindings lib = Native.load("", Bindings.class); +} + +interface Bindings extends Library { + Bindings INSTANCE = BindingsSingleton.INSTANCE.lib; + + interface A extends Callback { + void invoke(); + } + + interface B extends Callback { + void invoke(); + } + + interface C extends Callback { + boolean invoke(int arg0, int arg1); + } + + interface D extends Callback { + Callback invoke(int arg0); + } + + interface E extends Callback { + Pointer invoke(); + } + + class F extends PointerType { + public F() { + super(null); + } + public F(Pointer p) { + super(p); + } + } + + class FByReference extends F { + public FByReference() { + super(null); + } + public FByReference(Pointer p) { + super(p); + } + } + + class G extends PointerType { + public G() { + super(null); + } + public G(Pointer p) { + super(p); + } + } + + class GByReference extends G { + public GByReference() { + super(null); + } + public GByReference(Pointer p) { + super(p); + } + } + + class H extends PointerType { + public H() { + super(null); + } + public H(Pointer p) { + super(p); + } + } + + class HByReference extends H { + public HByReference() { + super(null); + } + public HByReference(Pointer p) { + super(p); + } + } + + class I extends PointerType { + public I() { + super(null); + } + public I(Pointer p) { + super(p); + } + } + + class IByReference extends I { + public IByReference() { + super(null); + } + public IByReference(Pointer p) { + super(p); + } + } + + class J extends PointerType { + public J() { + super(null); + } + public J(Pointer p) { + super(p); + } + } + + class JByReference extends J { + public JByReference() { + super(null); + } + public JByReference(Pointer p) { + super(p); + } + } + + class K extends PointerType { + public K() { + super(null); + } + public K(Pointer p) { + super(p); + } + } + + class KByReference extends K { + public KByReference() { + super(null); + } + public KByReference(Pointer p) { + super(p); + } + } + + class L extends PointerType { + public L() { + super(null); + } + public L(Pointer p) { + super(p); + } + } + + class LByReference extends L { + public LByReference() { + super(null); + } + public LByReference(Pointer p) { + super(p); + } + } + + class M extends PointerType { + public M() { + super(null); + } + public M(Pointer p) { + super(p); + } + } + + class MByReference extends M { + public MByReference() { + super(null); + } + public MByReference(Pointer p) { + super(p); + } + } + + class N extends PointerType { + public N() { + super(null); + } + public N(Pointer p) { + super(p); + } + } + + class NByReference extends N { + public NByReference() { + super(null); + } + public NByReference(Pointer p) { + super(p); + } + } + + interface P extends Callback { + void invoke(int named1st, boolean arg1, boolean named3rd, int arg3); + } + + Callback O(); + + void root(A a, B b, C c, D d, E e, F f, G g, H h, I i, J j, K k, L l, M m, N n, P p); + +} \ No newline at end of file diff --git a/tests/expectations/cell.java b/tests/expectations/cell.java new file mode 100644 index 000000000..511665e0a --- /dev/null +++ b/tests/expectations/cell.java @@ -0,0 +1,80 @@ +import com.sun.jna.*; +import com.sun.jna.ptr.*; + +enum BindingsSingleton { + INSTANCE; + final Bindings lib = Native.load("", Bindings.class); +} + +interface Bindings extends Library { + Bindings INSTANCE = BindingsSingleton.INSTANCE.lib; + + class NotReprC_RefCell_i32 extends PointerType { + public NotReprC_RefCell_i32() { + super(null); + } + public NotReprC_RefCell_i32(Pointer p) { + super(p); + } + } + + class NotReprC_RefCell_i32ByReference extends NotReprC_RefCell_i32 { + public NotReprC_RefCell_i32ByReference() { + super(null); + } + public NotReprC_RefCell_i32ByReference(Pointer p) { + super(p); + } + } + + class Foo extends NotReprC_RefCell_i32 { + public Foo() { + super(); + } + public Foo(Pointer p) { + super(p); + } + } + + class FooByReference extends NotReprC_RefCell_i32ByReference { + public FooByReference() { + super(); + } + public FooByReference(Pointer p) { + super(p); + } + } + + + @Structure.FieldOrder({"number"}) + class MyStruct extends Structure implements Structure.ByValue { + public MyStruct() { + super(); + } + + public MyStruct(Pointer p) { + super(p); + } + + public int number; + + } + + @Structure.FieldOrder({"number"}) + class MyStructByReference extends Structure implements Structure.ByReference { + public MyStructByReference() { + super(); + } + + public MyStructByReference(Pointer p) { + super(p); + } + + public int number; + + } + + + void root(FooByReference a, MyStructByReference with_cell); + +} \ No newline at end of file diff --git a/tests/expectations/cfg.java b/tests/expectations/cfg.java new file mode 100644 index 000000000..5c20ed588 --- /dev/null +++ b/tests/expectations/cfg.java @@ -0,0 +1,232 @@ + +import com.sun.jna.*; +import com.sun.jna.ptr.*; + +enum BindingsSingleton { + INSTANCE; + final Bindings lib = Native.load("", Bindings.class); +} + +interface Bindings extends Library { + Bindings INSTANCE = BindingsSingleton.INSTANCE.lib; + + class BarType extends IntegerType { + public BarType() { + super(4); + } + + public BarType(long value) { + super(4, value); + } + + public BarType(Pointer p) { + this(p.getInt(0)); + } + public static final BarType A = new BarType(1); + public static final BarType B = new BarType(2); + public static final BarType C = new BarType(3); + + } + + class BarTypeByReference extends ByReference { + public BarTypeByReference() { + super(4); + } + + public BarTypeByReference(Pointer p) { + super(4); + setPointer(p); + } + + public BarType getValue() { + return new BarType(getPointer().getInt(0)); + } + + public void setValue(BarType value) { + getPointer().setInt(0, value.intValue()); + } + + } + + class FooType extends IntegerType { + public FooType() { + super(4); + } + + public FooType(long value) { + super(4, value); + } + + public FooType(Pointer p) { + this(p.getInt(0)); + } + public static final FooType A = new FooType(1); + public static final FooType B = new FooType(2); + public static final FooType C = new FooType(3); + + } + + class FooTypeByReference extends ByReference { + public FooTypeByReference() { + super(4); + } + + public FooTypeByReference(Pointer p) { + super(4); + setPointer(p); + } + + public FooType getValue() { + return new FooType(getPointer().getInt(0)); + } + + public void setValue(FooType value) { + getPointer().setInt(0, value.intValue()); + } + + } + + + @Structure.FieldOrder({"ty", "x", "y"}) + class FooHandle extends Structure implements Structure.ByValue { + public FooHandle() { + super(); + } + + public FooHandle(Pointer p) { + super(p); + } + + public FooType ty; + public int x; + public float y; + + } + + @Structure.FieldOrder({"ty", "x", "y"}) + class FooHandleByReference extends Structure implements Structure.ByReference { + public FooHandleByReference() { + super(); + } + + public FooHandleByReference(Pointer p) { + super(p); + } + + public FooType ty; + public int x; + public float y; + + } + + + class C extends IntegerType { + public C() { + super(4); + } + + public C(long value) { + super(4, value); + } + + public C(Pointer p) { + this(p.getInt(0)); + } + public static final C C1 = new C(1); + public static final C C2 = new C(2); + public static final C C3 = new C(3); + public static final C C5 = new C(4); + + } + + class CByReference extends ByReference { + public CByReference() { + super(4); + } + + public CByReference(Pointer p) { + super(4); + setPointer(p); + } + + public C getValue() { + return new C(getPointer().getInt(0)); + } + + public void setValue(C value) { + getPointer().setInt(0, value.intValue()); + } + + } + + + @Structure.FieldOrder({"ty", "x", "y"}) + class BarHandle extends Structure implements Structure.ByValue { + public BarHandle() { + super(); + } + + public BarHandle(Pointer p) { + super(p); + } + + public BarType ty; + public int x; + public float y; + + } + + @Structure.FieldOrder({"ty", "x", "y"}) + class BarHandleByReference extends Structure implements Structure.ByReference { + public BarHandleByReference() { + super(); + } + + public BarHandleByReference(Pointer p) { + super(p); + } + + public BarType ty; + public int x; + public float y; + + } + + + + @Structure.FieldOrder({"field"}) + class ConditionalField extends Structure implements Structure.ByValue { + public ConditionalField() { + super(); + } + + public ConditionalField(Pointer p) { + super(p); + } + + public int field; + + } + + @Structure.FieldOrder({"field"}) + class ConditionalFieldByReference extends Structure implements Structure.ByReference { + public ConditionalFieldByReference() { + super(); + } + + public ConditionalFieldByReference(Pointer p) { + super(p); + } + + public int field; + + } + + + void root(FooHandle a, C c); + + void root(BarHandle a, C c); + + void cond(ConditionalField a); + +} \ No newline at end of file diff --git a/tests/expectations/cfg_2.java b/tests/expectations/cfg_2.java new file mode 100644 index 000000000..c4f5b9d59 --- /dev/null +++ b/tests/expectations/cfg_2.java @@ -0,0 +1,45 @@ +import com.sun.jna.*; +import com.sun.jna.ptr.*; + +enum BindingsSingleton { + INSTANCE; + final Bindings lib = Native.load("", Bindings.class); +} + +interface Bindings extends Library { + Bindings INSTANCE = BindingsSingleton.INSTANCE.lib; + class Bar {} + + + @Structure.FieldOrder({"w"}) + class Root extends Structure implements Structure.ByValue { + public Root() { + super(); + } + + public Root(Pointer p) { + super(p); + } + + public Bar w; + + } + + @Structure.FieldOrder({"w"}) + class RootByReference extends Structure implements Structure.ByReference { + public RootByReference() { + super(); + } + + public RootByReference(Pointer p) { + super(p); + } + + public Bar w; + + } + + + void root(Root a); + +} \ No newline at end of file diff --git a/tests/expectations/cfg_field.java b/tests/expectations/cfg_field.java new file mode 100644 index 000000000..90cf1e1b0 --- /dev/null +++ b/tests/expectations/cfg_field.java @@ -0,0 +1,12 @@ +import com.sun.jna.*; +import com.sun.jna.ptr.*; + +enum BindingsSingleton { + INSTANCE; + final Bindings lib = Native.load("", Bindings.class); +} + +interface Bindings extends Library { + Bindings INSTANCE = BindingsSingleton.INSTANCE.lib; + +} \ No newline at end of file diff --git a/tests/expectations/char.java b/tests/expectations/char.java new file mode 100644 index 000000000..f9c48c66b --- /dev/null +++ b/tests/expectations/char.java @@ -0,0 +1,44 @@ +import com.sun.jna.*; +import com.sun.jna.ptr.*; + +enum BindingsSingleton { + INSTANCE; + final Bindings lib = Native.load("", Bindings.class); +} + +interface Bindings extends Library { + Bindings INSTANCE = BindingsSingleton.INSTANCE.lib; + + + @Structure.FieldOrder({"a"}) + class Foo extends Structure implements Structure.ByValue { + public Foo() { + super(); + } + + public Foo(Pointer p) { + super(p); + } + + public char a; + + } + + @Structure.FieldOrder({"a"}) + class FooByReference extends Structure implements Structure.ByReference { + public FooByReference() { + super(); + } + + public FooByReference(Pointer p) { + super(p); + } + + public char a; + + } + + + void root(Foo a); + +} \ No newline at end of file diff --git a/tests/expectations/const_conflict.java b/tests/expectations/const_conflict.java new file mode 100644 index 000000000..1ac8f55f3 --- /dev/null +++ b/tests/expectations/const_conflict.java @@ -0,0 +1,15 @@ +import com.sun.jna.*; +import com.sun.jna.ptr.*; + +enum BindingsSingleton { + INSTANCE; + final Bindings lib = Native.load("", Bindings.class); +} + +interface Bindings extends Library { + Bindings INSTANCE = BindingsSingleton.INSTANCE.lib; + + /* Unsupported literal for constant Foo_FOO */ + + +} \ No newline at end of file diff --git a/tests/expectations/const_generics.java b/tests/expectations/const_generics.java new file mode 100644 index 000000000..c851b6825 --- /dev/null +++ b/tests/expectations/const_generics.java @@ -0,0 +1,85 @@ +import com.sun.jna.*; +import com.sun.jna.ptr.*; + +enum BindingsSingleton { + INSTANCE; + final Bindings lib = Native.load("", Bindings.class); +} + +interface Bindings extends Library { + Bindings INSTANCE = BindingsSingleton.INSTANCE.lib; + + /* Unsupported literal for constant TITLE_SIZE */ + + + class CArrayString_TITLE_SIZE extends PointerType { + public CArrayString_TITLE_SIZE() { + super(null); + } + public CArrayString_TITLE_SIZE(Pointer p) { + super(p); + } + } + + class CArrayString_TITLE_SIZEByReference extends CArrayString_TITLE_SIZE { + public CArrayString_TITLE_SIZEByReference() { + super(null); + } + public CArrayString_TITLE_SIZEByReference(Pointer p) { + super(p); + } + } + + class CArrayString_40 extends PointerType { + public CArrayString_40() { + super(null); + } + public CArrayString_40(Pointer p) { + super(p); + } + } + + class CArrayString_40ByReference extends CArrayString_40 { + public CArrayString_40ByReference() { + super(null); + } + public CArrayString_40ByReference(Pointer p) { + super(p); + } + } + + + @Structure.FieldOrder({"title", "author"}) + class Book extends Structure implements Structure.ByValue { + public Book() { + super(); + } + + public Book(Pointer p) { + super(p); + } + + public CArrayString_TITLE_SIZE title; + public CArrayString_40 author; + + } + + @Structure.FieldOrder({"title", "author"}) + class BookByReference extends Structure implements Structure.ByReference { + public BookByReference() { + super(); + } + + public BookByReference(Pointer p) { + super(p); + } + + public CArrayString_TITLE_SIZE title; + public CArrayString_40 author; + + } + + + void root(BookByReference a); + +} \ No newline at end of file diff --git a/tests/expectations/const_generics_arrayvec.java b/tests/expectations/const_generics_arrayvec.java new file mode 100644 index 000000000..e7ad3b84e --- /dev/null +++ b/tests/expectations/const_generics_arrayvec.java @@ -0,0 +1,46 @@ +import com.sun.jna.*; +import com.sun.jna.ptr.*; + +enum BindingsSingleton { + INSTANCE; + final Bindings lib = Native.load("", Bindings.class); +} + +interface Bindings extends Library { + Bindings INSTANCE = BindingsSingleton.INSTANCE.lib; + + + @Structure.FieldOrder({"xs", "len"}) + class ArrayVec_____u8__100 extends Structure implements Structure.ByValue { + public ArrayVec_____u8__100() { + super(); + } + + public ArrayVec_____u8__100(Pointer p) { + super(p); + } + + public ByteByReference[] xs; + public int len; + + } + + @Structure.FieldOrder({"xs", "len"}) + class ArrayVec_____u8__100ByReference extends Structure implements Structure.ByReference { + public ArrayVec_____u8__100ByReference() { + super(); + } + + public ArrayVec_____u8__100ByReference(Pointer p) { + super(p); + } + + public ByteByReference[] xs; + public int len; + + } + + + int push(ArrayVec_____u8__100ByReference v, ByteByReference elem); + +} \ No newline at end of file diff --git a/tests/expectations/const_generics_bool.java b/tests/expectations/const_generics_bool.java new file mode 100644 index 000000000..e24500413 --- /dev/null +++ b/tests/expectations/const_generics_bool.java @@ -0,0 +1,140 @@ +import com.sun.jna.*; +import com.sun.jna.ptr.*; + +enum BindingsSingleton { + INSTANCE; + final Bindings lib = Native.load("", Bindings.class); +} + +interface Bindings extends Library { + Bindings INSTANCE = BindingsSingleton.INSTANCE.lib; + + class Str extends PointerType { + public Str() { + super(null); + } + public Str(Pointer p) { + super(p); + } + } + + class StrByReference extends Str { + public StrByReference() { + super(null); + } + public StrByReference(Pointer p) { + super(p); + } + } + + + @Structure.FieldOrder({"num_buckets", "capacity", "occupied", "keys", "vals"}) + class HashTable_Str__c_char__false extends Structure implements Structure.ByValue { + public HashTable_Str__c_char__false() { + super(); + } + + public HashTable_Str__c_char__false(Pointer p) { + super(p); + } + + public NativeLong num_buckets; + public NativeLong capacity; + public ByteByReference occupied; + public StrByReference keys; + public ByteByReference vals; + + } + + @Structure.FieldOrder({"num_buckets", "capacity", "occupied", "keys", "vals"}) + class HashTable_Str__c_char__falseByReference extends Structure implements Structure.ByReference { + public HashTable_Str__c_char__falseByReference() { + super(); + } + + public HashTable_Str__c_char__falseByReference(Pointer p) { + super(p); + } + + public NativeLong num_buckets; + public NativeLong capacity; + public ByteByReference occupied; + public StrByReference keys; + public ByteByReference vals; + + } + + + class MySet extends HashTable_Str__c_char__false { + public MySet() { + super(); + } + public MySet(Pointer p) { + super(p); + } + } + + class MySetByReference extends HashTable_Str__c_char__falseByReference { + public MySetByReference() { + super(); + } + public MySetByReference(Pointer p) { + super(p); + } + } + + interface SetCallback extends Callback { + void invoke(Str key); + } + + + @Structure.FieldOrder({"num_buckets", "capacity", "occupied", "keys", "vals"}) + class HashTable_Str__u64__true extends Structure implements Structure.ByValue { + public HashTable_Str__u64__true() { + super(); + } + + public HashTable_Str__u64__true(Pointer p) { + super(p); + } + + public NativeLong num_buckets; + public NativeLong capacity; + public ByteByReference occupied; + public StrByReference keys; + public LongByReference vals; + + } + + @Structure.FieldOrder({"num_buckets", "capacity", "occupied", "keys", "vals"}) + class HashTable_Str__u64__trueByReference extends Structure implements Structure.ByReference { + public HashTable_Str__u64__trueByReference() { + super(); + } + + public HashTable_Str__u64__trueByReference(Pointer p) { + super(p); + } + + public NativeLong num_buckets; + public NativeLong capacity; + public ByteByReference occupied; + public StrByReference keys; + public LongByReference vals; + + } + + + interface MapCallback extends Callback { + void invoke(Str key, long val); + } + + MySetByReference new_set(); + + void set_for_each(MySetByReference set, SetCallback callback); + + HashTable_Str__u64__trueByReference new_map(); + + void map_for_each(HashTable_Str__u64__trueByReference map, MapCallback callback); + +} \ No newline at end of file diff --git a/tests/expectations/const_generics_byte.java b/tests/expectations/const_generics_byte.java new file mode 100644 index 000000000..ecafaba7c --- /dev/null +++ b/tests/expectations/const_generics_byte.java @@ -0,0 +1,82 @@ +import com.sun.jna.*; +import com.sun.jna.ptr.*; + +enum BindingsSingleton { + INSTANCE; + final Bindings lib = Native.load("", Bindings.class); +} + +interface Bindings extends Library { + Bindings INSTANCE = BindingsSingleton.INSTANCE.lib; + + + @Structure.FieldOrder({"buf", "len"}) + class Parser_40__41 extends Structure implements Structure.ByValue { + public Parser_40__41() { + super(); + } + + public Parser_40__41(Pointer p) { + super(p); + } + + public ByteByReference buf; + public NativeLong len; + + } + + @Structure.FieldOrder({"buf", "len"}) + class Parser_40__41ByReference extends Structure implements Structure.ByReference { + public Parser_40__41ByReference() { + super(); + } + + public Parser_40__41ByReference(Pointer p) { + super(p); + } + + public ByteByReference buf; + public NativeLong len; + + } + + + + @Structure.FieldOrder({"buf", "len"}) + class Parser_123__125 extends Structure implements Structure.ByValue { + public Parser_123__125() { + super(); + } + + public Parser_123__125(Pointer p) { + super(p); + } + + public ByteByReference buf; + public NativeLong len; + + } + + @Structure.FieldOrder({"buf", "len"}) + class Parser_123__125ByReference extends Structure implements Structure.ByReference { + public Parser_123__125ByReference() { + super(); + } + + public Parser_123__125ByReference(Pointer p) { + super(p); + } + + public ByteByReference buf; + public NativeLong len; + + } + + + void init_parens_parser(Parser_40__41ByReference p, ByteByReference buf, NativeLong len); + + void destroy_parens_parser(Parser_40__41ByReference p); + + void init_braces_parser(Parser_123__125ByReference p, ByteByReference buf, NativeLong len); + +} \ No newline at end of file diff --git a/tests/expectations/const_generics_char.java b/tests/expectations/const_generics_char.java new file mode 100644 index 000000000..478e1e9e9 --- /dev/null +++ b/tests/expectations/const_generics_char.java @@ -0,0 +1,48 @@ +import com.sun.jna.*; +import com.sun.jna.ptr.*; + +enum BindingsSingleton { + INSTANCE; + final Bindings lib = Native.load("", Bindings.class); +} + +interface Bindings extends Library { + Bindings INSTANCE = BindingsSingleton.INSTANCE.lib; + + + @Structure.FieldOrder({"start", "len", "point"}) + class TakeUntil_0 extends Structure implements Structure.ByValue { + public TakeUntil_0() { + super(); + } + + public TakeUntil_0(Pointer p) { + super(p); + } + + public ByteByReference start; + public NativeLong len; + public NativeLong point; + + } + + @Structure.FieldOrder({"start", "len", "point"}) + class TakeUntil_0ByReference extends Structure implements Structure.ByReference { + public TakeUntil_0ByReference() { + super(); + } + + public TakeUntil_0ByReference(Pointer p) { + super(p); + } + + public ByteByReference start; + public NativeLong len; + public NativeLong point; + + } + + + TakeUntil_0 until_nul(ByteByReference start, NativeLong len); + +} \ No newline at end of file diff --git a/tests/expectations/const_generics_constant.java b/tests/expectations/const_generics_constant.java new file mode 100644 index 000000000..c33ff45f9 --- /dev/null +++ b/tests/expectations/const_generics_constant.java @@ -0,0 +1,97 @@ +import com.sun.jna.*; +import com.sun.jna.ptr.*; + +enum BindingsSingleton { + INSTANCE; + final Bindings lib = Native.load("", Bindings.class); +} + +interface Bindings extends Library { + Bindings INSTANCE = BindingsSingleton.INSTANCE.lib; + + /* Unsupported literal for constant FONT_WEIGHT_FRACTION_BITS */ + + + + @Structure.FieldOrder({"value"}) + class FixedPoint_FONT_WEIGHT_FRACTION_BITS extends Structure implements Structure.ByValue { + public FixedPoint_FONT_WEIGHT_FRACTION_BITS() { + super(); + } + + public FixedPoint_FONT_WEIGHT_FRACTION_BITS(Pointer p) { + super(p); + } + + public short value; + + } + + @Structure.FieldOrder({"value"}) + class FixedPoint_FONT_WEIGHT_FRACTION_BITSByReference extends Structure implements Structure.ByReference { + public FixedPoint_FONT_WEIGHT_FRACTION_BITSByReference() { + super(); + } + + public FixedPoint_FONT_WEIGHT_FRACTION_BITSByReference(Pointer p) { + super(p); + } + + public short value; + + } + + + class FontWeightFixedPoint extends FixedPoint_FONT_WEIGHT_FRACTION_BITS { + public FontWeightFixedPoint() { + super(); + } + public FontWeightFixedPoint(Pointer p) { + super(p); + } + } + + class FontWeightFixedPointByReference extends FixedPoint_FONT_WEIGHT_FRACTION_BITSByReference { + public FontWeightFixedPointByReference() { + super(); + } + public FontWeightFixedPointByReference(Pointer p) { + super(p); + } + } + + + @Structure.FieldOrder({"_0"}) + class FontWeight extends Structure implements Structure.ByValue { + /* Unsupported literal for constant NORMAL */ + public FontWeight() { + super(); + } + + public FontWeight(Pointer p) { + super(p); + } + + public FontWeightFixedPoint _0; + + } + + @Structure.FieldOrder({"_0"}) + class FontWeightByReference extends Structure implements Structure.ByReference { + /* Unsupported literal for constant NORMAL */ + public FontWeightByReference() { + super(); + } + + public FontWeightByReference(Pointer p) { + super(p); + } + + public FontWeightFixedPoint _0; + + } + + + void root(FontWeight w); + +} \ No newline at end of file diff --git a/tests/expectations/const_generics_thru.java b/tests/expectations/const_generics_thru.java new file mode 100644 index 000000000..01bb7063b --- /dev/null +++ b/tests/expectations/const_generics_thru.java @@ -0,0 +1,136 @@ +import com.sun.jna.*; +import com.sun.jna.ptr.*; + +enum BindingsSingleton { + INSTANCE; + final Bindings lib = Native.load("", Bindings.class); +} + +interface Bindings extends Library { + Bindings INSTANCE = BindingsSingleton.INSTANCE.lib; + + + @Structure.FieldOrder({"bytes"}) + class Inner_1 extends Structure implements Structure.ByValue { + public Inner_1() { + super(); + } + + public Inner_1(Pointer p) { + super(p); + } + + public byte[] bytes; + + } + + @Structure.FieldOrder({"bytes"}) + class Inner_1ByReference extends Structure implements Structure.ByReference { + public Inner_1ByReference() { + super(); + } + + public Inner_1ByReference(Pointer p) { + super(p); + } + + public byte[] bytes; + + } + + + + @Structure.FieldOrder({"inner"}) + class Outer_1 extends Structure implements Structure.ByValue { + public Outer_1() { + super(); + } + + public Outer_1(Pointer p) { + super(p); + } + + public Inner_1 inner; + + } + + @Structure.FieldOrder({"inner"}) + class Outer_1ByReference extends Structure implements Structure.ByReference { + public Outer_1ByReference() { + super(); + } + + public Outer_1ByReference(Pointer p) { + super(p); + } + + public Inner_1 inner; + + } + + + + @Structure.FieldOrder({"bytes"}) + class Inner_2 extends Structure implements Structure.ByValue { + public Inner_2() { + super(); + } + + public Inner_2(Pointer p) { + super(p); + } + + public byte[] bytes; + + } + + @Structure.FieldOrder({"bytes"}) + class Inner_2ByReference extends Structure implements Structure.ByReference { + public Inner_2ByReference() { + super(); + } + + public Inner_2ByReference(Pointer p) { + super(p); + } + + public byte[] bytes; + + } + + + + @Structure.FieldOrder({"inner"}) + class Outer_2 extends Structure implements Structure.ByValue { + public Outer_2() { + super(); + } + + public Outer_2(Pointer p) { + super(p); + } + + public Inner_2 inner; + + } + + @Structure.FieldOrder({"inner"}) + class Outer_2ByReference extends Structure implements Structure.ByReference { + public Outer_2ByReference() { + super(); + } + + public Outer_2ByReference(Pointer p) { + super(p); + } + + public Inner_2 inner; + + } + + + Outer_1 one(); + + Outer_2 two(); + +} \ No newline at end of file diff --git a/tests/expectations/const_transparent.java b/tests/expectations/const_transparent.java new file mode 100644 index 000000000..dba1b4a0c --- /dev/null +++ b/tests/expectations/const_transparent.java @@ -0,0 +1,50 @@ +import com.sun.jna.*; +import com.sun.jna.ptr.*; + +enum BindingsSingleton { + INSTANCE; + final Bindings lib = Native.load("", Bindings.class); +} + +interface Bindings extends Library { + Bindings INSTANCE = BindingsSingleton.INSTANCE.lib; + + class Transparent extends IntegerType { + public Transparent() { + super(1); + } + + public Transparent(long value) { + super(1, value); + } + + public Transparent(Pointer p) { + this(p.getByte(0)); + } + + } + + class TransparentByReference extends ByReference { + public TransparentByReference() { + super(1); + } + + public TransparentByReference(Pointer p) { + super(1); + setPointer(p); + } + + public Transparent getValue() { + return new Transparent(getPointer().getByte(0)); + } + + public void setValue(Transparent value) { + getPointer().setByte(0, (byte)value.intValue()); + } + + } + + public static final Transparent FOO = new Transparent(0); + + +} \ No newline at end of file diff --git a/tests/expectations/constant.java b/tests/expectations/constant.java new file mode 100644 index 000000000..e1bded314 --- /dev/null +++ b/tests/expectations/constant.java @@ -0,0 +1,106 @@ +import com.sun.jna.*; +import com.sun.jna.ptr.*; + +enum BindingsSingleton { + INSTANCE; + final Bindings lib = Native.load("", Bindings.class); +} + +interface Bindings extends Library { + Bindings INSTANCE = BindingsSingleton.INSTANCE.lib; + + /* Unsupported literal for constant FOO */ + + + public static final char DELIMITER = ':'; + + + public static final char LEFTCURLY = '{'; + + + public static final char QUOTE = '\''; + + + public static final char TAB = '\t'; + + + public static final char NEWLINE = '\n'; + + + /* Unsupported literal for constant HEART */ + + + /* Unsupported literal for constant EQUID */ + + + public static final float ZOM = 3.14f; + + + + /** + * A single-line doc comment. + */ + /* Unsupported literal for constant POS_ONE */ + + + + /** + * A + * multi-line + * doc + * comment. + */ + /* Unsupported literal for constant NEG_ONE */ + + + /* Unsupported literal for constant SHIFT */ + + + /* Unsupported literal for constant XBOOL */ + + + /* Unsupported literal for constant XFALSE */ + + + /* Unsupported literal for constant XTRUE */ + + + /* Unsupported literal for constant CAST */ + + + /* Unsupported literal for constant DOUBLE_CAST */ + + + + @Structure.FieldOrder({"x"}) + class Foo extends Structure implements Structure.ByValue { + public Foo() { + super(); + } + + public Foo(Pointer p) { + super(p); + } + + public int[] x; + + } + + @Structure.FieldOrder({"x"}) + class FooByReference extends Structure implements Structure.ByReference { + public FooByReference() { + super(); + } + + public FooByReference(Pointer p) { + super(p); + } + + public int[] x; + + } + + + void root(Foo x); + +} \ No newline at end of file diff --git a/tests/expectations/constant_big.java b/tests/expectations/constant_big.java new file mode 100644 index 000000000..2079a4b09 --- /dev/null +++ b/tests/expectations/constant_big.java @@ -0,0 +1,24 @@ +import com.sun.jna.*; +import com.sun.jna.ptr.*; + +enum BindingsSingleton { + INSTANCE; + final Bindings lib = Native.load("", Bindings.class); +} + +interface Bindings extends Library { + Bindings INSTANCE = BindingsSingleton.INSTANCE.lib; + + /* Unsupported literal for constant UNSIGNED_NEEDS_ULL_SUFFIX */ + + + /* Unsupported literal for constant UNSIGNED_DOESNT_NEED_ULL_SUFFIX */ + + + /* Unsupported literal for constant SIGNED_NEEDS_ULL_SUFFIX */ + + + /* Unsupported literal for constant SIGNED_DOESNT_NEED_ULL_SUFFIX */ + + +} \ No newline at end of file diff --git a/tests/expectations/constant_constexpr.java b/tests/expectations/constant_constexpr.java new file mode 100644 index 000000000..10bce5452 --- /dev/null +++ b/tests/expectations/constant_constexpr.java @@ -0,0 +1,59 @@ +import com.sun.jna.*; +import com.sun.jna.ptr.*; + +enum BindingsSingleton { + INSTANCE; + final Bindings lib = Native.load("", Bindings.class); +} + +interface Bindings extends Library { + Bindings INSTANCE = BindingsSingleton.INSTANCE.lib; + + /* Unsupported literal for constant CONSTANT_I64 */ + + + public static final float CONSTANT_FLOAT32 = 312.292f; + + + public static final char DELIMITER = ':'; + + + public static final char LEFTCURLY = '{'; + + + + @Structure.FieldOrder({"x"}) + class Foo extends Structure implements Structure.ByValue { + /* Unsupported literal for constant CONSTANT_I64_BODY */ + public Foo() { + super(); + } + + public Foo(Pointer p) { + super(p); + } + + public int x; + + } + + @Structure.FieldOrder({"x"}) + class FooByReference extends Structure implements Structure.ByReference { + /* Unsupported literal for constant CONSTANT_I64_BODY */ + public FooByReference() { + super(); + } + + public FooByReference(Pointer p) { + super(p); + } + + public int x; + + } + + + /* Unsupported literal for constant SomeFoo */ + + +} \ No newline at end of file diff --git a/tests/expectations/constant_sort_name.java b/tests/expectations/constant_sort_name.java new file mode 100644 index 000000000..c318c5a3a --- /dev/null +++ b/tests/expectations/constant_sort_name.java @@ -0,0 +1,22 @@ +import com.sun.jna.*; +import com.sun.jna.ptr.*; + +enum BindingsSingleton { + INSTANCE; + final Bindings lib = Native.load("", Bindings.class); +} + +interface Bindings extends Library { + Bindings INSTANCE = BindingsSingleton.INSTANCE.lib; + + /* Unsupported literal for constant A */ + + + /* Unsupported literal for constant B */ + + + /* Not implemented yet : Static { path: Path { name: "C" }, export_name: "C", ty: Primitive(Integer { zeroable: true, signed: false, kind: B8 }), mutable: false, cfg: None, annotations: AnnotationSet { annotations: {}, must_use: false, deprecated: None }, documentation: Documentation { doc_comment: [] } } */ + + /* Not implemented yet : Static { path: Path { name: "D" }, export_name: "D", ty: Primitive(Integer { zeroable: true, signed: false, kind: B8 }), mutable: false, cfg: None, annotations: AnnotationSet { annotations: {}, must_use: false, deprecated: None }, documentation: Documentation { doc_comment: [] } } */ + +} \ No newline at end of file diff --git a/tests/expectations/constant_sort_none.java b/tests/expectations/constant_sort_none.java new file mode 100644 index 000000000..b71c807b6 --- /dev/null +++ b/tests/expectations/constant_sort_none.java @@ -0,0 +1,22 @@ +import com.sun.jna.*; +import com.sun.jna.ptr.*; + +enum BindingsSingleton { + INSTANCE; + final Bindings lib = Native.load("", Bindings.class); +} + +interface Bindings extends Library { + Bindings INSTANCE = BindingsSingleton.INSTANCE.lib; + + /* Unsupported literal for constant B */ + + + /* Unsupported literal for constant A */ + + + /* Not implemented yet : Static { path: Path { name: "D" }, export_name: "D", ty: Primitive(Integer { zeroable: true, signed: false, kind: B8 }), mutable: false, cfg: None, annotations: AnnotationSet { annotations: {}, must_use: false, deprecated: None }, documentation: Documentation { doc_comment: [] } } */ + + /* Not implemented yet : Static { path: Path { name: "C" }, export_name: "C", ty: Primitive(Integer { zeroable: true, signed: false, kind: B8 }), mutable: false, cfg: None, annotations: AnnotationSet { annotations: {}, must_use: false, deprecated: None }, documentation: Documentation { doc_comment: [] } } */ + +} \ No newline at end of file diff --git a/tests/expectations/constant_user_defined_type.java b/tests/expectations/constant_user_defined_type.java new file mode 100644 index 000000000..45f26eea5 --- /dev/null +++ b/tests/expectations/constant_user_defined_type.java @@ -0,0 +1,122 @@ +import com.sun.jna.*; +import com.sun.jna.ptr.*; + +enum BindingsSingleton { + INSTANCE; + final Bindings lib = Native.load("", Bindings.class); +} + +interface Bindings extends Library { + Bindings INSTANCE = BindingsSingleton.INSTANCE.lib; + + class E extends IntegerType { + public E() { + super(4); + } + + public E(long value) { + super(4, value); + } + + public E(Pointer p) { + this(p.getInt(0)); + } + public static final E V = new E(1); + + } + + class EByReference extends ByReference { + public EByReference() { + super(4); + } + + public EByReference(Pointer p) { + super(4); + setPointer(p); + } + + public E getValue() { + return new E(getPointer().getInt(0)); + } + + public void setValue(E value) { + getPointer().setInt(0, value.intValue()); + } + + } + + + @Structure.FieldOrder({"field"}) + class S extends Structure implements Structure.ByValue { + public S() { + super(); + } + + public S(Pointer p) { + super(p); + } + + public byte field; + + } + + @Structure.FieldOrder({"field"}) + class SByReference extends Structure implements Structure.ByReference { + public SByReference() { + super(); + } + + public SByReference(Pointer p) { + super(p); + } + + public byte field; + + } + + + class A extends IntegerType { + public A() { + super(1); + } + + public A(long value) { + super(1, value); + } + + public A(Pointer p) { + this(p.getByte(0)); + } + + } + + class AByReference extends ByReference { + public AByReference() { + super(1); + } + + public AByReference(Pointer p) { + super(1); + setPointer(p); + } + + public A getValue() { + return new A(getPointer().getByte(0)); + } + + public void setValue(A value) { + getPointer().setByte(0, (byte)value.intValue()); + } + + } + + /* Unsupported literal for constant C1 */ + + + /* Unsupported literal for constant C2 */ + + + public static final A C3 = new A(0); + + +} \ No newline at end of file diff --git a/tests/expectations/custom_header.java b/tests/expectations/custom_header.java new file mode 100644 index 000000000..098201862 --- /dev/null +++ b/tests/expectations/custom_header.java @@ -0,0 +1,21 @@ +/* + * This file is generated by cbindgen. DO NOT EDIT + */ + +import com.sun.jna.*; +import com.sun.jna.ptr.*; + +enum BindingsSingleton { + INSTANCE; + final Bindings lib = Native.load("", Bindings.class); +} + +interface Bindings extends Library { + Bindings INSTANCE = BindingsSingleton.INSTANCE.lib; + + void root(); + +} +/* + * This is a simple test to ensure that trailers do not cause extra newlines in files + */ diff --git a/tests/expectations/cython_options.java b/tests/expectations/cython_options.java new file mode 100644 index 000000000..90cf1e1b0 --- /dev/null +++ b/tests/expectations/cython_options.java @@ -0,0 +1,12 @@ +import com.sun.jna.*; +import com.sun.jna.ptr.*; + +enum BindingsSingleton { + INSTANCE; + final Bindings lib = Native.load("", Bindings.class); +} + +interface Bindings extends Library { + Bindings INSTANCE = BindingsSingleton.INSTANCE.lib; + +} \ No newline at end of file diff --git a/tests/expectations/decl_name_conflicting.java b/tests/expectations/decl_name_conflicting.java new file mode 100644 index 000000000..67d7023e9 --- /dev/null +++ b/tests/expectations/decl_name_conflicting.java @@ -0,0 +1,81 @@ +import com.sun.jna.*; +import com.sun.jna.ptr.*; + +enum BindingsSingleton { + INSTANCE; + final Bindings lib = Native.load("", Bindings.class); +} + +interface Bindings extends Library { + Bindings INSTANCE = BindingsSingleton.INSTANCE.lib; + + class BindingType extends IntegerType { + public BindingType() { + super(4); + } + + public BindingType(long value) { + super(4, value); + } + + public BindingType(Pointer p) { + this(p.getInt(0)); + } + public static final BindingType Buffer = new BindingType(0); + public static final BindingType NotBuffer = new BindingType(1); + + } + + class BindingTypeByReference extends ByReference { + public BindingTypeByReference() { + super(4); + } + + public BindingTypeByReference(Pointer p) { + super(4); + setPointer(p); + } + + public BindingType getValue() { + return new BindingType(getPointer().getInt(0)); + } + + public void setValue(BindingType value) { + getPointer().setInt(0, value.intValue()); + } + + } + + + @Structure.FieldOrder({"ty"}) + class BindGroupLayoutEntry extends Structure implements Structure.ByValue { + public BindGroupLayoutEntry() { + super(); + } + + public BindGroupLayoutEntry(Pointer p) { + super(p); + } + + public BindingType ty; + + } + + @Structure.FieldOrder({"ty"}) + class BindGroupLayoutEntryByReference extends Structure implements Structure.ByReference { + public BindGroupLayoutEntryByReference() { + super(); + } + + public BindGroupLayoutEntryByReference(Pointer p) { + super(p); + } + + public BindingType ty; + + } + + + void root(BindGroupLayoutEntry entry); + +} \ No newline at end of file diff --git a/tests/expectations/dep_v2.java b/tests/expectations/dep_v2.java new file mode 100644 index 000000000..8a1a0787b --- /dev/null +++ b/tests/expectations/dep_v2.java @@ -0,0 +1,46 @@ +import com.sun.jna.*; +import com.sun.jna.ptr.*; + +enum BindingsSingleton { + INSTANCE; + final Bindings lib = Native.load("dep-2", Bindings.class); +} + +interface Bindings extends Library { + Bindings INSTANCE = BindingsSingleton.INSTANCE.lib; + + + @Structure.FieldOrder({"x", "y"}) + class dep_struct extends Structure implements Structure.ByValue { + public dep_struct() { + super(); + } + + public dep_struct(Pointer p) { + super(p); + } + + public int x; + public double y; + + } + + @Structure.FieldOrder({"x", "y"}) + class dep_structByReference extends Structure implements Structure.ByReference { + public dep_structByReference() { + super(); + } + + public dep_structByReference(Pointer p) { + super(p); + } + + public int x; + public double y; + + } + + + int get_x(dep_structByReference dep_struct); + +} \ No newline at end of file diff --git a/tests/expectations/deprecated.java b/tests/expectations/deprecated.java new file mode 100644 index 000000000..003cabb39 --- /dev/null +++ b/tests/expectations/deprecated.java @@ -0,0 +1,192 @@ +import com.sun.jna.*; +import com.sun.jna.ptr.*; + +enum BindingsSingleton { + INSTANCE; + final Bindings lib = Native.load("", Bindings.class); +} + +interface Bindings extends Library { + Bindings INSTANCE = BindingsSingleton.INSTANCE.lib; + + @Deprecated + class DeprecatedEnum extends IntegerType { + public DeprecatedEnum() { + super(4); + } + + public DeprecatedEnum(long value) { + super(4, value); + } + + public DeprecatedEnum(Pointer p) { + this(p.getInt(0)); + } + public static final DeprecatedEnum A = new DeprecatedEnum(0); + + } + + class DeprecatedEnumByReference extends ByReference { + public DeprecatedEnumByReference() { + super(4); + } + + public DeprecatedEnumByReference(Pointer p) { + super(4); + setPointer(p); + } + + public DeprecatedEnum getValue() { + return new DeprecatedEnum(getPointer().getInt(0)); + } + + public void setValue(DeprecatedEnum value) { + getPointer().setInt(0, value.intValue()); + } + + } + + /** + * @deprecated This is a note + */ + @Deprecated + class DeprecatedEnumWithNote extends IntegerType { + public DeprecatedEnumWithNote() { + super(4); + } + + public DeprecatedEnumWithNote(long value) { + super(4, value); + } + + public DeprecatedEnumWithNote(Pointer p) { + this(p.getInt(0)); + } + public static final DeprecatedEnumWithNote B = new DeprecatedEnumWithNote(0); + + } + + class DeprecatedEnumWithNoteByReference extends ByReference { + public DeprecatedEnumWithNoteByReference() { + super(4); + } + + public DeprecatedEnumWithNoteByReference(Pointer p) { + super(4); + setPointer(p); + } + + public DeprecatedEnumWithNote getValue() { + return new DeprecatedEnumWithNote(getPointer().getInt(0)); + } + + public void setValue(DeprecatedEnumWithNote value) { + getPointer().setInt(0, value.intValue()); + } + + } + + + @Deprecated + @Structure.FieldOrder({"a"}) + class DeprecatedStruct extends Structure implements Structure.ByValue { + public DeprecatedStruct() { + super(); + } + + public DeprecatedStruct(Pointer p) { + super(p); + } + + public int a; + + } + + @Deprecated + @Structure.FieldOrder({"a"}) + class DeprecatedStructByReference extends Structure implements Structure.ByReference { + public DeprecatedStructByReference() { + super(); + } + + public DeprecatedStructByReference(Pointer p) { + super(p); + } + + public int a; + + } + + + + /** + * @deprecated This is a note + */ + @Deprecated + @Structure.FieldOrder({"a"}) + class DeprecatedStructWithNote extends Structure implements Structure.ByValue { + public DeprecatedStructWithNote() { + super(); + } + + public DeprecatedStructWithNote(Pointer p) { + super(p); + } + + public int a; + + } + + /** + * @deprecated This is a note + */ + @Deprecated + @Structure.FieldOrder({"a"}) + class DeprecatedStructWithNoteByReference extends Structure implements Structure.ByReference { + public DeprecatedStructWithNoteByReference() { + super(); + } + + public DeprecatedStructWithNoteByReference(Pointer p) { + super(p); + } + + public int a; + + } + + + @Deprecated + void deprecated_without_note(); + + /** + * @deprecated This is a note + */ + @Deprecated + void deprecated_without_bracket(); + + /** + * @deprecated This is a note + */ + @Deprecated + void deprecated_with_note(); + + /** + * @deprecated This is a note + */ + @Deprecated + void deprecated_with_note_and_since(); + + /** + * @deprecated This quote " requires to be quoted, and this [ +] requires to be escaped + */ + @Deprecated + void deprecated_with_note_which_requires_to_be_escaped(); + + void dummy(DeprecatedEnum a, + DeprecatedEnumWithNote b, + DeprecatedStruct c, + DeprecatedStructWithNote d); + +} \ No newline at end of file diff --git a/tests/expectations/derive_eq.java b/tests/expectations/derive_eq.java new file mode 100644 index 000000000..7698fa3f0 --- /dev/null +++ b/tests/expectations/derive_eq.java @@ -0,0 +1,85 @@ +import com.sun.jna.*; +import com.sun.jna.ptr.*; + +enum BindingsSingleton { + INSTANCE; + final Bindings lib = Native.load("derive-eq", Bindings.class); +} + +interface Bindings extends Library { + Bindings INSTANCE = BindingsSingleton.INSTANCE.lib; + + + @Structure.FieldOrder({"a", "b"}) + class Foo extends Structure implements Structure.ByValue { + public Foo() { + super(); + } + + public Foo(Pointer p) { + super(p); + } + + public boolean a; + public int b; + + } + + @Structure.FieldOrder({"a", "b"}) + class FooByReference extends Structure implements Structure.ByReference { + public FooByReference() { + super(); + } + + public FooByReference(Pointer p) { + super(p); + } + + public boolean a; + public int b; + + } + + + class Bar extends IntegerType { + public Bar() { + super(4); + } + + public Bar(long value) { + super(4, value); + } + + public Bar(Pointer p) { + this(p.getInt(0)); + } + public static final Bar Baz = new Bar(1); + public static final Bar Bazz = new Bar(2); + public static final Bar FooNamed = new Bar(3); + public static final Bar FooParen = new Bar(4); + + } + + class BarByReference extends ByReference { + public BarByReference() { + super(4); + } + + public BarByReference(Pointer p) { + super(4); + setPointer(p); + } + + public Bar getValue() { + return new Bar(getPointer().getInt(0)); + } + + public void setValue(Bar value) { + getPointer().setInt(0, value.intValue()); + } + + } + + Foo root(Bar aBar); + +} \ No newline at end of file diff --git a/tests/expectations/derive_ostream.java b/tests/expectations/derive_ostream.java new file mode 100644 index 000000000..bcb839a7f --- /dev/null +++ b/tests/expectations/derive_ostream.java @@ -0,0 +1,260 @@ +import com.sun.jna.*; +import com.sun.jna.ptr.*; + +enum BindingsSingleton { + INSTANCE; + final Bindings lib = Native.load("", Bindings.class); +} + +interface Bindings extends Library { + Bindings INSTANCE = BindingsSingleton.INSTANCE.lib; + + class C extends IntegerType { + public C() { + super(4); + } + + public C(long value) { + super(4, value); + } + + public C(Pointer p) { + this(p.getInt(0)); + } + public static final C X = new C(2); + public static final C Y = new C(3); + + } + + class CByReference extends ByReference { + public CByReference() { + super(4); + } + + public CByReference(Pointer p) { + super(4); + setPointer(p); + } + + public C getValue() { + return new C(getPointer().getInt(0)); + } + + public void setValue(C value) { + getPointer().setInt(0, value.intValue()); + } + + } + + + @Structure.FieldOrder({"_0"}) + class A extends Structure implements Structure.ByValue { + public A() { + super(); + } + + public A(Pointer p) { + super(p); + } + + public int _0; + + } + + @Structure.FieldOrder({"_0"}) + class AByReference extends Structure implements Structure.ByReference { + public AByReference() { + super(); + } + + public AByReference(Pointer p) { + super(p); + } + + public int _0; + + } + + + + @Structure.FieldOrder({"x", "y"}) + class B extends Structure implements Structure.ByValue { + public B() { + super(); + } + + public B(Pointer p) { + super(p); + } + + public int x; + public float y; + + } + + @Structure.FieldOrder({"x", "y"}) + class BByReference extends Structure implements Structure.ByReference { + public BByReference() { + super(); + } + + public BByReference(Pointer p) { + super(p); + } + + public int x; + public float y; + + } + + + + @Structure.FieldOrder({"List", "Of", "Things"}) + class D extends Structure implements Structure.ByValue { + public D() { + super(); + } + + public D(Pointer p) { + super(p); + } + + public byte List; + public NativeLong Of; + public B Things; + + } + + @Structure.FieldOrder({"List", "Of", "Things"}) + class DByReference extends Structure implements Structure.ByReference { + public DByReference() { + super(); + } + + public DByReference(Pointer p) { + super(p); + } + + public byte List; + public NativeLong Of; + public B Things; + + } + + + class F extends IntegerType { + public F() { + super(4); + } + + public F(long value) { + super(4, value); + } + + public F(Pointer p) { + this(p.getInt(0)); + } + public static final F Foo = new F(1); + public static final F Bar = new F(2); + public static final F Baz = new F(3); + + } + + class FByReference extends ByReference { + public FByReference() { + super(4); + } + + public FByReference(Pointer p) { + super(4); + setPointer(p); + } + + public F getValue() { + return new F(getPointer().getInt(0)); + } + + public void setValue(F value) { + getPointer().setInt(0, value.intValue()); + } + + } + + class H extends IntegerType { + public H() { + super(4); + } + + public H(long value) { + super(4, value); + } + + public H(Pointer p) { + this(p.getInt(0)); + } + public static final H Hello = new H(1); + public static final H There = new H(2); + public static final H Everyone = new H(3); + + } + + class HByReference extends ByReference { + public HByReference() { + super(4); + } + + public HByReference(Pointer p) { + super(4); + setPointer(p); + } + + public H getValue() { + return new H(getPointer().getInt(0)); + } + + public void setValue(H value) { + getPointer().setInt(0, value.intValue()); + } + + } + + class I extends IntegerType { + public I() { + super(4); + } + + public I(long value) { + super(4, value); + } + + public I(Pointer p) { + this(p.getInt(0)); + } + public static final I ThereAgain = new I(1); + public static final I SomethingElse = new I(2); + + } + + class IByReference extends ByReference { + public IByReference() { + super(4); + } + + public IByReference(Pointer p) { + super(4); + setPointer(p); + } + + public I getValue() { + return new I(getPointer().getInt(0)); + } + + public void setValue(I value) { + getPointer().setInt(0, value.intValue()); + } + + } + + void root(A a, B b, C c, D d, F f, H h, I i); + +} \ No newline at end of file diff --git a/tests/expectations/destructor_and_copy_ctor.java b/tests/expectations/destructor_and_copy_ctor.java new file mode 100644 index 000000000..6b333831e --- /dev/null +++ b/tests/expectations/destructor_and_copy_ctor.java @@ -0,0 +1,474 @@ + +import com.sun.jna.*; +import com.sun.jna.ptr.*; + +enum BindingsSingleton { + INSTANCE; + final Bindings lib = Native.load("", Bindings.class); +} + +interface Bindings extends Library { + Bindings INSTANCE = BindingsSingleton.INSTANCE.lib; + + class FillRule extends IntegerType { + public FillRule() { + super(4); + } + + public FillRule(long value) { + super(4, value); + } + + public FillRule(Pointer p) { + this(p.getInt(0)); + } + public static final FillRule A = new FillRule(1); + public static final FillRule B = new FillRule(2); + + } + + class FillRuleByReference extends ByReference { + public FillRuleByReference() { + super(4); + } + + public FillRuleByReference(Pointer p) { + super(4); + setPointer(p); + } + + public FillRule getValue() { + return new FillRule(getPointer().getInt(0)); + } + + public void setValue(FillRule value) { + getPointer().setInt(0, value.intValue()); + } + + } + + + + /** + * This will have a destructor manually implemented via variant_body, and + * similarly a Drop impl in Rust. + */ + @Structure.FieldOrder({"len", "ptr"}) + class OwnedSlice_u32 extends Structure implements Structure.ByValue { + public OwnedSlice_u32() { + super(); + } + + public OwnedSlice_u32(Pointer p) { + super(p); + } + + public NativeLong len; + public IntByReference ptr; + + } + + + /** + * This will have a destructor manually implemented via variant_body, and + * similarly a Drop impl in Rust. + */ + @Structure.FieldOrder({"len", "ptr"}) + class OwnedSlice_u32ByReference extends Structure implements Structure.ByReference { + public OwnedSlice_u32ByReference() { + super(); + } + + public OwnedSlice_u32ByReference(Pointer p) { + super(p); + } + + public NativeLong len; + public IntByReference ptr; + + } + + + + @Structure.FieldOrder({"fill", "coordinates"}) + class Polygon_u32 extends Structure implements Structure.ByValue { + public Polygon_u32() { + super(); + } + + public Polygon_u32(Pointer p) { + super(p); + } + + public FillRule fill; + public OwnedSlice_u32 coordinates; + + } + + @Structure.FieldOrder({"fill", "coordinates"}) + class Polygon_u32ByReference extends Structure implements Structure.ByReference { + public Polygon_u32ByReference() { + super(); + } + + public Polygon_u32ByReference(Pointer p) { + super(p); + } + + public FillRule fill; + public OwnedSlice_u32 coordinates; + + } + + + + + /** + * This will have a destructor manually implemented via variant_body, and + * similarly a Drop impl in Rust. + */ + @Structure.FieldOrder({"len", "ptr"}) + class OwnedSlice_i32 extends Structure implements Structure.ByValue { + public OwnedSlice_i32() { + super(); + } + + public OwnedSlice_i32(Pointer p) { + super(p); + } + + public NativeLong len; + public IntByReference ptr; + + } + + + /** + * This will have a destructor manually implemented via variant_body, and + * similarly a Drop impl in Rust. + */ + @Structure.FieldOrder({"len", "ptr"}) + class OwnedSlice_i32ByReference extends Structure implements Structure.ByReference { + public OwnedSlice_i32ByReference() { + super(); + } + + public OwnedSlice_i32ByReference(Pointer p) { + super(p); + } + + public NativeLong len; + public IntByReference ptr; + + } + + + class Foo_u32 extends IntegerType { + public Foo_u32() { + super(4); + } + + public Foo_u32(long value) { + super(4, value); + } + + public Foo_u32(Pointer p) { + this(p.getInt(0)); + } + public static final Foo_u32 Bar_u32 = new Foo_u32(1); + public static final Foo_u32 Polygon1_u32 = new Foo_u32(2); + public static final Foo_u32 Slice1_u32 = new Foo_u32(3); + public static final Foo_u32 Slice2_u32 = new Foo_u32(4); + public static final Foo_u32 Slice3_u32 = new Foo_u32(5); + public static final Foo_u32 Slice4_u32 = new Foo_u32(6); + + } + + class Foo_u32ByReference extends ByReference { + public Foo_u32ByReference() { + super(4); + } + + public Foo_u32ByReference(Pointer p) { + super(4); + setPointer(p); + } + + public Foo_u32 getValue() { + return new Foo_u32(getPointer().getInt(0)); + } + + public void setValue(Foo_u32 value) { + getPointer().setInt(0, value.intValue()); + } + + } + + + @Structure.FieldOrder({"fill", "coordinates"}) + class Polygon_i32 extends Structure implements Structure.ByValue { + public Polygon_i32() { + super(); + } + + public Polygon_i32(Pointer p) { + super(p); + } + + public FillRule fill; + public OwnedSlice_i32 coordinates; + + } + + @Structure.FieldOrder({"fill", "coordinates"}) + class Polygon_i32ByReference extends Structure implements Structure.ByReference { + public Polygon_i32ByReference() { + super(); + } + + public Polygon_i32ByReference(Pointer p) { + super(p); + } + + public FillRule fill; + public OwnedSlice_i32 coordinates; + + } + + + class Baz_i32 extends IntegerType { + public Baz_i32() { + super(4); + } + + public Baz_i32(long value) { + super(4, value); + } + + public Baz_i32(Pointer p) { + this(p.getInt(0)); + } + public static final Baz_i32 Bar2_i32 = new Baz_i32(1); + public static final Baz_i32 Polygon21_i32 = new Baz_i32(2); + public static final Baz_i32 Slice21_i32 = new Baz_i32(3); + public static final Baz_i32 Slice22_i32 = new Baz_i32(4); + public static final Baz_i32 Slice23_i32 = new Baz_i32(5); + public static final Baz_i32 Slice24_i32 = new Baz_i32(6); + + } + + class Baz_i32ByReference extends ByReference { + public Baz_i32ByReference() { + super(4); + } + + public Baz_i32ByReference(Pointer p) { + super(4); + setPointer(p); + } + + public Baz_i32 getValue() { + return new Baz_i32(getPointer().getInt(0)); + } + + public void setValue(Baz_i32 value) { + getPointer().setInt(0, value.intValue()); + } + + } + + class Taz extends IntegerType { + public Taz() { + super(4); + } + + public Taz(long value) { + super(4, value); + } + + public Taz(Pointer p) { + this(p.getInt(0)); + } + public static final Taz Bar3 = new Taz(1); + public static final Taz Taz1 = new Taz(2); + public static final Taz Taz3 = new Taz(3); + + } + + class TazByReference extends ByReference { + public TazByReference() { + super(4); + } + + public TazByReference(Pointer p) { + super(4); + setPointer(p); + } + + public Taz getValue() { + return new Taz(getPointer().getInt(0)); + } + + public void setValue(Taz value) { + getPointer().setInt(0, value.intValue()); + } + + } + + class Tazz extends IntegerType { + public Tazz() { + super(4); + } + + public Tazz(long value) { + super(4, value); + } + + public Tazz(Pointer p) { + this(p.getInt(0)); + } + public static final Tazz Bar4 = new Tazz(1); + public static final Tazz Taz2 = new Tazz(2); + + } + + class TazzByReference extends ByReference { + public TazzByReference() { + super(4); + } + + public TazzByReference(Pointer p) { + super(4); + setPointer(p); + } + + public Tazz getValue() { + return new Tazz(getPointer().getInt(0)); + } + + public void setValue(Tazz value) { + getPointer().setInt(0, value.intValue()); + } + + } + + class Tazzz extends IntegerType { + public Tazzz() { + super(4); + } + + public Tazzz(long value) { + super(4, value); + } + + public Tazzz(Pointer p) { + this(p.getInt(0)); + } + public static final Tazzz Bar5 = new Tazzz(1); + public static final Tazzz Taz5 = new Tazzz(2); + + } + + class TazzzByReference extends ByReference { + public TazzzByReference() { + super(4); + } + + public TazzzByReference(Pointer p) { + super(4); + setPointer(p); + } + + public Tazzz getValue() { + return new Tazzz(getPointer().getInt(0)); + } + + public void setValue(Tazzz value) { + getPointer().setInt(0, value.intValue()); + } + + } + + class Tazzzz extends IntegerType { + public Tazzzz() { + super(4); + } + + public Tazzzz(long value) { + super(4, value); + } + + public Tazzzz(Pointer p) { + this(p.getInt(0)); + } + public static final Tazzzz Taz6 = new Tazzzz(1); + public static final Tazzzz Taz7 = new Tazzzz(2); + + } + + class TazzzzByReference extends ByReference { + public TazzzzByReference() { + super(4); + } + + public TazzzzByReference(Pointer p) { + super(4); + setPointer(p); + } + + public Tazzzz getValue() { + return new Tazzzz(getPointer().getInt(0)); + } + + public void setValue(Tazzzz value) { + getPointer().setInt(0, value.intValue()); + } + + } + + class Qux extends IntegerType { + public Qux() { + super(4); + } + + public Qux(long value) { + super(4, value); + } + + public Qux(Pointer p) { + this(p.getInt(0)); + } + public static final Qux Qux1 = new Qux(1); + public static final Qux Qux2 = new Qux(2); + + } + + class QuxByReference extends ByReference { + public QuxByReference() { + super(4); + } + + public QuxByReference(Pointer p) { + super(4); + setPointer(p); + } + + public Qux getValue() { + return new Qux(getPointer().getInt(0)); + } + + public void setValue(Qux value) { + getPointer().setInt(0, value.intValue()); + } + + } + + void root(Foo_u32ByReference a, + Baz_i32ByReference b, + TazByReference c, + Tazz d, + TazzzByReference e, + TazzzzByReference f, + QuxByReference g); + +} \ No newline at end of file diff --git a/tests/expectations/display_list.java b/tests/expectations/display_list.java new file mode 100644 index 000000000..61262f5bc --- /dev/null +++ b/tests/expectations/display_list.java @@ -0,0 +1,124 @@ +import com.sun.jna.*; +import com.sun.jna.ptr.*; + +enum BindingsSingleton { + INSTANCE; + final Bindings lib = Native.load("", Bindings.class); +} + +interface Bindings extends Library { + Bindings INSTANCE = BindingsSingleton.INSTANCE.lib; + + + @Structure.FieldOrder({"x", "y", "w", "h"}) + class Rect extends Structure implements Structure.ByValue { + public Rect() { + super(); + } + + public Rect(Pointer p) { + super(p); + } + + public float x; + public float y; + public float w; + public float h; + + } + + @Structure.FieldOrder({"x", "y", "w", "h"}) + class RectByReference extends Structure implements Structure.ByReference { + public RectByReference() { + super(); + } + + public RectByReference(Pointer p) { + super(p); + } + + public float x; + public float y; + public float w; + public float h; + + } + + + + @Structure.FieldOrder({"r", "g", "b", "a"}) + class Color extends Structure implements Structure.ByValue { + public Color() { + super(); + } + + public Color(Pointer p) { + super(p); + } + + public byte r; + public byte g; + public byte b; + public byte a; + + } + + @Structure.FieldOrder({"r", "g", "b", "a"}) + class ColorByReference extends Structure implements Structure.ByReference { + public ColorByReference() { + super(); + } + + public ColorByReference(Pointer p) { + super(p); + } + + public byte r; + public byte g; + public byte b; + public byte a; + + } + + + class DisplayItem extends IntegerType { + public DisplayItem() { + super(4); + } + + public DisplayItem(long value) { + super(4, value); + } + + public DisplayItem(Pointer p) { + this(p.getInt(0)); + } + public static final DisplayItem Fill = new DisplayItem(1); + public static final DisplayItem Image = new DisplayItem(2); + public static final DisplayItem ClearScreen = new DisplayItem(3); + + } + + class DisplayItemByReference extends ByReference { + public DisplayItemByReference() { + super(4); + } + + public DisplayItemByReference(Pointer p) { + super(4); + setPointer(p); + } + + public DisplayItem getValue() { + return new DisplayItem(getPointer().getInt(0)); + } + + public void setValue(DisplayItem value) { + getPointer().setInt(0, value.intValue()); + } + + } + + boolean push_item(DisplayItem item); + +} \ No newline at end of file diff --git a/tests/expectations/doclength_short.java b/tests/expectations/doclength_short.java new file mode 100644 index 000000000..cbe6402f5 --- /dev/null +++ b/tests/expectations/doclength_short.java @@ -0,0 +1,31 @@ +import com.sun.jna.*; +import com.sun.jna.ptr.*; + +enum BindingsSingleton { + INSTANCE; + final Bindings lib = Native.load("", Bindings.class); +} + +interface Bindings extends Library { + Bindings INSTANCE = BindingsSingleton.INSTANCE.lib; + + + /** + * The root of all evil. + * + * But at least it contains some more documentation as someone would expect + * from a simple test case like this. Though, this shouldn't appear in the + * output. + */ + void root(); + + + /** + * A little above the root, and a lot more visible, with a run-on sentence + * to test going over the first line. + * + * Still not here, though. + */ + void trunk(); + +} \ No newline at end of file diff --git a/tests/expectations/docstyle_auto.java b/tests/expectations/docstyle_auto.java new file mode 100644 index 000000000..5db3ec535 --- /dev/null +++ b/tests/expectations/docstyle_auto.java @@ -0,0 +1,18 @@ +import com.sun.jna.*; +import com.sun.jna.ptr.*; + +enum BindingsSingleton { + INSTANCE; + final Bindings lib = Native.load("", Bindings.class); +} + +interface Bindings extends Library { + Bindings INSTANCE = BindingsSingleton.INSTANCE.lib; + + + /** + * The root of all evil. + */ + void root(); + +} \ No newline at end of file diff --git a/tests/expectations/docstyle_c99.java b/tests/expectations/docstyle_c99.java new file mode 100644 index 000000000..5db3ec535 --- /dev/null +++ b/tests/expectations/docstyle_c99.java @@ -0,0 +1,18 @@ +import com.sun.jna.*; +import com.sun.jna.ptr.*; + +enum BindingsSingleton { + INSTANCE; + final Bindings lib = Native.load("", Bindings.class); +} + +interface Bindings extends Library { + Bindings INSTANCE = BindingsSingleton.INSTANCE.lib; + + + /** + * The root of all evil. + */ + void root(); + +} \ No newline at end of file diff --git a/tests/expectations/docstyle_doxy.java b/tests/expectations/docstyle_doxy.java new file mode 100644 index 000000000..5db3ec535 --- /dev/null +++ b/tests/expectations/docstyle_doxy.java @@ -0,0 +1,18 @@ +import com.sun.jna.*; +import com.sun.jna.ptr.*; + +enum BindingsSingleton { + INSTANCE; + final Bindings lib = Native.load("", Bindings.class); +} + +interface Bindings extends Library { + Bindings INSTANCE = BindingsSingleton.INSTANCE.lib; + + + /** + * The root of all evil. + */ + void root(); + +} \ No newline at end of file diff --git a/tests/expectations/documentation.java b/tests/expectations/documentation.java new file mode 100644 index 000000000..91406f051 --- /dev/null +++ b/tests/expectations/documentation.java @@ -0,0 +1,35 @@ +import com.sun.jna.*; +import com.sun.jna.ptr.*; + +enum BindingsSingleton { + INSTANCE; + final Bindings lib = Native.load("", Bindings.class); +} + +interface Bindings extends Library { + Bindings INSTANCE = BindingsSingleton.INSTANCE.lib; + + + /** + * The root of all evil. + * + * But at least it contains some more documentation as someone would expect + * from a simple test case like this. + * + * # Hint + * + * Always ensure that everything is properly documented, even if you feel lazy. + * **Sometimes** it is also helpful to include some markdown formatting. + * + * //////////////////////////////////////////////////////////////////////////// + * + * Attention: + * + * Rust is going to trim all leading `/` symbols. If you want to use them as a + * marker you need to add at least a single whitespace inbetween the tripple + * slash doc-comment marker and the rest. + * + */ + void root(); + +} \ No newline at end of file diff --git a/tests/expectations/documentation_attr.java b/tests/expectations/documentation_attr.java new file mode 100644 index 000000000..42d7f7552 --- /dev/null +++ b/tests/expectations/documentation_attr.java @@ -0,0 +1,29 @@ +import com.sun.jna.*; +import com.sun.jna.ptr.*; + +enum BindingsSingleton { + INSTANCE; + final Bindings lib = Native.load("", Bindings.class); +} + +interface Bindings extends Library { + Bindings INSTANCE = BindingsSingleton.INSTANCE.lib; + + + /** + *With doc attr, each attr contribute to one line of document + *like this one with a new line character at its end + *and this one as well. So they are in the same paragraph + * + *Line ends with one new line should not break + * + *Line ends with two spaces and a new line + *should break to next line + * + *Line ends with two new lines + * + *Should break to next paragraph + */ + void root(); + +} \ No newline at end of file diff --git a/tests/expectations/enum.java b/tests/expectations/enum.java new file mode 100644 index 000000000..906db0492 --- /dev/null +++ b/tests/expectations/enum.java @@ -0,0 +1,703 @@ + +import com.sun.jna.*; +import com.sun.jna.ptr.*; + +enum BindingsSingleton { + INSTANCE; + final Bindings lib = Native.load("", Bindings.class); +} + +interface Bindings extends Library { + Bindings INSTANCE = BindingsSingleton.INSTANCE.lib; + + class A extends IntegerType { + public A() { + super(4); + } + + public A(long value) { + super(4, value); + } + + public A(Pointer p) { + this(p.getInt(0)); + } + public static final A a1 = new A(0); + public static final A a2 = new A(2); + public static final A a3 = new A(3); + public static final A a4 = new A(5); + + } + + class AByReference extends ByReference { + public AByReference() { + super(4); + } + + public AByReference(Pointer p) { + super(4); + setPointer(p); + } + + public A getValue() { + return new A(getPointer().getInt(0)); + } + + public void setValue(A value) { + getPointer().setInt(0, value.intValue()); + } + + } + + class B extends IntegerType { + public B() { + super(4); + } + + public B(long value) { + super(4, value); + } + + public B(Pointer p) { + this(p.getInt(0)); + } + public static final B b1 = new B(0); + public static final B b2 = new B(2); + public static final B b3 = new B(3); + public static final B b4 = new B(5); + + } + + class BByReference extends ByReference { + public BByReference() { + super(4); + } + + public BByReference(Pointer p) { + super(4); + setPointer(p); + } + + public B getValue() { + return new B(getPointer().getInt(0)); + } + + public void setValue(B value) { + getPointer().setInt(0, value.intValue()); + } + + } + + class C extends IntegerType { + public C() { + super(4); + } + + public C(long value) { + super(4, value); + } + + public C(Pointer p) { + this(p.getInt(0)); + } + public static final C c1 = new C(0); + public static final C c2 = new C(2); + public static final C c3 = new C(3); + public static final C c4 = new C(5); + + } + + class CByReference extends ByReference { + public CByReference() { + super(4); + } + + public CByReference(Pointer p) { + super(4); + setPointer(p); + } + + public C getValue() { + return new C(getPointer().getInt(0)); + } + + public void setValue(C value) { + getPointer().setInt(0, value.intValue()); + } + + } + + class D extends IntegerType { + public D() { + super(4); + } + + public D(long value) { + super(4, value); + } + + public D(Pointer p) { + this(p.getInt(0)); + } + public static final D d1 = new D(0); + public static final D d2 = new D(2); + public static final D d3 = new D(3); + public static final D d4 = new D(5); + + } + + class DByReference extends ByReference { + public DByReference() { + super(4); + } + + public DByReference(Pointer p) { + super(4); + setPointer(p); + } + + public D getValue() { + return new D(getPointer().getInt(0)); + } + + public void setValue(D value) { + getPointer().setInt(0, value.intValue()); + } + + } + + class E extends IntegerType { + public E() { + super(4); + } + + public E(long value) { + super(4, value); + } + + public E(Pointer p) { + this(p.getInt(0)); + } + public static final E e1 = new E(0); + public static final E e2 = new E(2); + public static final E e3 = new E(3); + public static final E e4 = new E(5); + + } + + class EByReference extends ByReference { + public EByReference() { + super(4); + } + + public EByReference(Pointer p) { + super(4); + setPointer(p); + } + + public E getValue() { + return new E(getPointer().getInt(0)); + } + + public void setValue(E value) { + getPointer().setInt(0, value.intValue()); + } + + } + + class F extends IntegerType { + public F() { + super(4); + } + + public F(long value) { + super(4, value); + } + + public F(Pointer p) { + this(p.getInt(0)); + } + public static final F f1 = new F(0); + public static final F f2 = new F(2); + public static final F f3 = new F(3); + public static final F f4 = new F(5); + + } + + class FByReference extends ByReference { + public FByReference() { + super(4); + } + + public FByReference(Pointer p) { + super(4); + setPointer(p); + } + + public F getValue() { + return new F(getPointer().getInt(0)); + } + + public void setValue(F value) { + getPointer().setInt(0, value.intValue()); + } + + } + + class L extends IntegerType { + public L() { + super(4); + } + + public L(long value) { + super(4, value); + } + + public L(Pointer p) { + this(p.getInt(0)); + } + public static final L l1 = new L(1); + public static final L l2 = new L(2); + public static final L l3 = new L(3); + public static final L l4 = new L(4); + + } + + class LByReference extends ByReference { + public LByReference() { + super(4); + } + + public LByReference(Pointer p) { + super(4); + setPointer(p); + } + + public L getValue() { + return new L(getPointer().getInt(0)); + } + + public void setValue(L value) { + getPointer().setInt(0, value.intValue()); + } + + } + + class M extends IntegerType { + public M() { + super(4); + } + + public M(long value) { + super(4, value); + } + + public M(Pointer p) { + this(p.getInt(0)); + } + public static final M m1 = new M(1); + public static final M m2 = new M(0); + public static final M m3 = new M(1); + + } + + class MByReference extends ByReference { + public MByReference() { + super(4); + } + + public MByReference(Pointer p) { + super(4); + setPointer(p); + } + + public M getValue() { + return new M(getPointer().getInt(0)); + } + + public void setValue(M value) { + getPointer().setInt(0, value.intValue()); + } + + } + + class N extends IntegerType { + public N() { + super(4); + } + + public N(long value) { + super(4, value); + } + + public N(Pointer p) { + this(p.getInt(0)); + } + public static final N n1 = new N(1); + public static final N n2 = new N(2); + public static final N n3 = new N(3); + public static final N n4 = new N(4); + + } + + class NByReference extends ByReference { + public NByReference() { + super(4); + } + + public NByReference(Pointer p) { + super(4); + setPointer(p); + } + + public N getValue() { + return new N(getPointer().getInt(0)); + } + + public void setValue(N value) { + getPointer().setInt(0, value.intValue()); + } + + } + + class O extends IntegerType { + public O() { + super(4); + } + + public O(long value) { + super(4, value); + } + + public O(Pointer p) { + this(p.getInt(0)); + } + public static final O o1 = new O(1); + public static final O o2 = new O(2); + public static final O o3 = new O(3); + public static final O o4 = new O(4); + + } + + class OByReference extends ByReference { + public OByReference() { + super(4); + } + + public OByReference(Pointer p) { + super(4); + setPointer(p); + } + + public O getValue() { + return new O(getPointer().getInt(0)); + } + + public void setValue(O value) { + getPointer().setInt(0, value.intValue()); + } + + } + + class J extends PointerType { + public J() { + super(null); + } + public J(Pointer p) { + super(p); + } + } + + class JByReference extends J { + public JByReference() { + super(null); + } + public JByReference(Pointer p) { + super(p); + } + } + + class K extends PointerType { + public K() { + super(null); + } + public K(Pointer p) { + super(p); + } + } + + class KByReference extends K { + public KByReference() { + super(null); + } + public KByReference(Pointer p) { + super(p); + } + } + + class Opaque extends PointerType { + public Opaque() { + super(null); + } + public Opaque(Pointer p) { + super(p); + } + } + + class OpaqueByReference extends Opaque { + public OpaqueByReference() { + super(null); + } + public OpaqueByReference(Pointer p) { + super(p); + } + } + + class G extends IntegerType { + public G() { + super(4); + } + + public G(long value) { + super(4, value); + } + + public G(Pointer p) { + this(p.getInt(0)); + } + public static final G Foo = new G(1); + public static final G Bar = new G(2); + public static final G Baz = new G(3); + + } + + class GByReference extends ByReference { + public GByReference() { + super(4); + } + + public GByReference(Pointer p) { + super(4); + setPointer(p); + } + + public G getValue() { + return new G(getPointer().getInt(0)); + } + + public void setValue(G value) { + getPointer().setInt(0, value.intValue()); + } + + } + + class H extends IntegerType { + public H() { + super(4); + } + + public H(long value) { + super(4, value); + } + + public H(Pointer p) { + this(p.getInt(0)); + } + public static final H H_Foo = new H(1); + public static final H H_Bar = new H(2); + public static final H H_Baz = new H(3); + + } + + class HByReference extends ByReference { + public HByReference() { + super(4); + } + + public HByReference(Pointer p) { + super(4); + setPointer(p); + } + + public H getValue() { + return new H(getPointer().getInt(0)); + } + + public void setValue(H value) { + getPointer().setInt(0, value.intValue()); + } + + } + + class ExI extends IntegerType { + public ExI() { + super(4); + } + + public ExI(long value) { + super(4, value); + } + + public ExI(Pointer p) { + this(p.getInt(0)); + } + public static final ExI ExI_Foo = new ExI(1); + public static final ExI ExI_Bar = new ExI(2); + public static final ExI ExI_Baz = new ExI(3); + + } + + class ExIByReference extends ByReference { + public ExIByReference() { + super(4); + } + + public ExIByReference(Pointer p) { + super(4); + setPointer(p); + } + + public ExI getValue() { + return new ExI(getPointer().getInt(0)); + } + + public void setValue(ExI value) { + getPointer().setInt(0, value.intValue()); + } + + } + + class P extends IntegerType { + public P() { + super(4); + } + + public P(long value) { + super(4, value); + } + + public P(Pointer p) { + this(p.getInt(0)); + } + public static final P P0 = new P(1); + public static final P P1 = new P(2); + + } + + class PByReference extends ByReference { + public PByReference() { + super(4); + } + + public PByReference(Pointer p) { + super(4); + setPointer(p); + } + + public P getValue() { + return new P(getPointer().getInt(0)); + } + + public void setValue(P value) { + getPointer().setInt(0, value.intValue()); + } + + } + + class Q extends IntegerType { + public Q() { + super(4); + } + + public Q(long value) { + super(4, value); + } + + public Q(Pointer p) { + this(p.getInt(0)); + } + public static final Q Ok = new Q(1); + public static final Q Err = new Q(2); + + } + + class QByReference extends ByReference { + public QByReference() { + super(4); + } + + public QByReference(Pointer p) { + super(4); + setPointer(p); + } + + public Q getValue() { + return new Q(getPointer().getInt(0)); + } + + public void setValue(Q value) { + getPointer().setInt(0, value.intValue()); + } + + } + + class R extends IntegerType { + public R() { + super(4); + } + + public R(long value) { + super(4, value); + } + + public R(Pointer p) { + this(p.getInt(0)); + } + public static final R IRFoo = new R(1); + public static final R IRBar = new R(2); + public static final R IRBaz = new R(3); + + } + + class RByReference extends ByReference { + public RByReference() { + super(4); + } + + public RByReference(Pointer p) { + super(4); + setPointer(p); + } + + public R getValue() { + return new R(getPointer().getInt(0)); + } + + public void setValue(R value) { + getPointer().setInt(0, value.intValue()); + } + + } + + void root(OpaqueByReference opaque, + A a, + B b, + C c, + D d, + E e, + F f, + G g, + H h, + ExI i, + J j, + K k, + L l, + M m, + N n, + O o, + P p, + Q q, + R r); + +} + diff --git a/tests/expectations/enum_discriminant.java b/tests/expectations/enum_discriminant.java new file mode 100644 index 000000000..10d4eedbe --- /dev/null +++ b/tests/expectations/enum_discriminant.java @@ -0,0 +1,59 @@ +import com.sun.jna.*; +import com.sun.jna.ptr.*; + +enum BindingsSingleton { + INSTANCE; + final Bindings lib = Native.load("", Bindings.class); +} + +interface Bindings extends Library { + Bindings INSTANCE = BindingsSingleton.INSTANCE.lib; + + /* Unsupported literal for constant FOURTY_FOUR */ + + + class E extends IntegerType { + public E() { + super(4); + } + + public E(long value) { + super(4, value); + } + + public E(Pointer p) { + this(p.getInt(0)); + } + public static final E A = new E(1); + public static final E B = new E(2); + public static final E C = new E(3); + public static final E D = new E(4); + public static final E F = new E(5); + public static final E G = new E(6); + public static final E H = new E(7); + + } + + class EByReference extends ByReference { + public EByReference() { + super(4); + } + + public EByReference(Pointer p) { + super(4); + setPointer(p); + } + + public E getValue() { + return new E(getPointer().getInt(0)); + } + + public void setValue(E value) { + getPointer().setInt(0, value.intValue()); + } + + } + + void root(EByReference arg0); + +} \ No newline at end of file diff --git a/tests/expectations/enum_self.java b/tests/expectations/enum_self.java new file mode 100644 index 000000000..61f513473 --- /dev/null +++ b/tests/expectations/enum_self.java @@ -0,0 +1,82 @@ +import com.sun.jna.*; +import com.sun.jna.ptr.*; + +enum BindingsSingleton { + INSTANCE; + final Bindings lib = Native.load("", Bindings.class); +} + +interface Bindings extends Library { + Bindings INSTANCE = BindingsSingleton.INSTANCE.lib; + + + @Structure.FieldOrder({"something"}) + class Foo_Bar extends Structure implements Structure.ByValue { + public Foo_Bar() { + super(); + } + + public Foo_Bar(Pointer p) { + super(p); + } + + public IntByReference something; + + } + + @Structure.FieldOrder({"something"}) + class Foo_BarByReference extends Structure implements Structure.ByReference { + public Foo_BarByReference() { + super(); + } + + public Foo_BarByReference(Pointer p) { + super(p); + } + + public IntByReference something; + + } + + + class Bar extends IntegerType { + public Bar() { + super(4); + } + + public Bar(long value) { + super(4, value); + } + + public Bar(Pointer p) { + this(p.getInt(0)); + } + public static final Bar Min = new Bar(1); + public static final Bar Max = new Bar(2); + public static final Bar Other = new Bar(3); + + } + + class BarByReference extends ByReference { + public BarByReference() { + super(4); + } + + public BarByReference(Pointer p) { + super(4); + setPointer(p); + } + + public Bar getValue() { + return new Bar(getPointer().getInt(0)); + } + + public void setValue(Bar value) { + getPointer().setInt(0, value.intValue()); + } + + } + + void root(Bar b); + +} \ No newline at end of file diff --git a/tests/expectations/euclid.java b/tests/expectations/euclid.java new file mode 100644 index 000000000..bca936ee1 --- /dev/null +++ b/tests/expectations/euclid.java @@ -0,0 +1,619 @@ +import com.sun.jna.*; +import com.sun.jna.ptr.*; + +enum BindingsSingleton { + INSTANCE; + final Bindings lib = Native.load("", Bindings.class); +} + +interface Bindings extends Library { + Bindings INSTANCE = BindingsSingleton.INSTANCE.lib; + + + @Structure.FieldOrder({"_0"}) + class TypedLength_f32__UnknownUnit extends Structure implements Structure.ByValue { + public TypedLength_f32__UnknownUnit() { + super(); + } + + public TypedLength_f32__UnknownUnit(Pointer p) { + super(p); + } + + public float _0; + + } + + @Structure.FieldOrder({"_0"}) + class TypedLength_f32__UnknownUnitByReference extends Structure implements Structure.ByReference { + public TypedLength_f32__UnknownUnitByReference() { + super(); + } + + public TypedLength_f32__UnknownUnitByReference(Pointer p) { + super(p); + } + + public float _0; + + } + + + + @Structure.FieldOrder({"_0"}) + class TypedLength_f32__LayoutUnit extends Structure implements Structure.ByValue { + public TypedLength_f32__LayoutUnit() { + super(); + } + + public TypedLength_f32__LayoutUnit(Pointer p) { + super(p); + } + + public float _0; + + } + + @Structure.FieldOrder({"_0"}) + class TypedLength_f32__LayoutUnitByReference extends Structure implements Structure.ByReference { + public TypedLength_f32__LayoutUnitByReference() { + super(); + } + + public TypedLength_f32__LayoutUnitByReference(Pointer p) { + super(p); + } + + public float _0; + + } + + + class Length_f32 extends TypedLength_f32__UnknownUnit { + public Length_f32() { + super(); + } + public Length_f32(Pointer p) { + super(p); + } + } + + class Length_f32ByReference extends TypedLength_f32__UnknownUnitByReference { + public Length_f32ByReference() { + super(); + } + public Length_f32ByReference(Pointer p) { + super(p); + } + } + + class LayoutLength extends TypedLength_f32__LayoutUnit { + public LayoutLength() { + super(); + } + public LayoutLength(Pointer p) { + super(p); + } + } + + class LayoutLengthByReference extends TypedLength_f32__LayoutUnitByReference { + public LayoutLengthByReference() { + super(); + } + public LayoutLengthByReference(Pointer p) { + super(p); + } + } + + + @Structure.FieldOrder({"top", "right", "bottom", "left"}) + class TypedSideOffsets2D_f32__UnknownUnit extends Structure implements Structure.ByValue { + public TypedSideOffsets2D_f32__UnknownUnit() { + super(); + } + + public TypedSideOffsets2D_f32__UnknownUnit(Pointer p) { + super(p); + } + + public float top; + public float right; + public float bottom; + public float left; + + } + + @Structure.FieldOrder({"top", "right", "bottom", "left"}) + class TypedSideOffsets2D_f32__UnknownUnitByReference extends Structure implements Structure.ByReference { + public TypedSideOffsets2D_f32__UnknownUnitByReference() { + super(); + } + + public TypedSideOffsets2D_f32__UnknownUnitByReference(Pointer p) { + super(p); + } + + public float top; + public float right; + public float bottom; + public float left; + + } + + + + @Structure.FieldOrder({"top", "right", "bottom", "left"}) + class TypedSideOffsets2D_f32__LayoutUnit extends Structure implements Structure.ByValue { + public TypedSideOffsets2D_f32__LayoutUnit() { + super(); + } + + public TypedSideOffsets2D_f32__LayoutUnit(Pointer p) { + super(p); + } + + public float top; + public float right; + public float bottom; + public float left; + + } + + @Structure.FieldOrder({"top", "right", "bottom", "left"}) + class TypedSideOffsets2D_f32__LayoutUnitByReference extends Structure implements Structure.ByReference { + public TypedSideOffsets2D_f32__LayoutUnitByReference() { + super(); + } + + public TypedSideOffsets2D_f32__LayoutUnitByReference(Pointer p) { + super(p); + } + + public float top; + public float right; + public float bottom; + public float left; + + } + + + class SideOffsets2D_f32 extends TypedSideOffsets2D_f32__UnknownUnit { + public SideOffsets2D_f32() { + super(); + } + public SideOffsets2D_f32(Pointer p) { + super(p); + } + } + + class SideOffsets2D_f32ByReference extends TypedSideOffsets2D_f32__UnknownUnitByReference { + public SideOffsets2D_f32ByReference() { + super(); + } + public SideOffsets2D_f32ByReference(Pointer p) { + super(p); + } + } + + class LayoutSideOffsets2D extends TypedSideOffsets2D_f32__LayoutUnit { + public LayoutSideOffsets2D() { + super(); + } + public LayoutSideOffsets2D(Pointer p) { + super(p); + } + } + + class LayoutSideOffsets2DByReference extends TypedSideOffsets2D_f32__LayoutUnitByReference { + public LayoutSideOffsets2DByReference() { + super(); + } + public LayoutSideOffsets2DByReference(Pointer p) { + super(p); + } + } + + + @Structure.FieldOrder({"width", "height"}) + class TypedSize2D_f32__UnknownUnit extends Structure implements Structure.ByValue { + public TypedSize2D_f32__UnknownUnit() { + super(); + } + + public TypedSize2D_f32__UnknownUnit(Pointer p) { + super(p); + } + + public float width; + public float height; + + } + + @Structure.FieldOrder({"width", "height"}) + class TypedSize2D_f32__UnknownUnitByReference extends Structure implements Structure.ByReference { + public TypedSize2D_f32__UnknownUnitByReference() { + super(); + } + + public TypedSize2D_f32__UnknownUnitByReference(Pointer p) { + super(p); + } + + public float width; + public float height; + + } + + + + @Structure.FieldOrder({"width", "height"}) + class TypedSize2D_f32__LayoutUnit extends Structure implements Structure.ByValue { + public TypedSize2D_f32__LayoutUnit() { + super(); + } + + public TypedSize2D_f32__LayoutUnit(Pointer p) { + super(p); + } + + public float width; + public float height; + + } + + @Structure.FieldOrder({"width", "height"}) + class TypedSize2D_f32__LayoutUnitByReference extends Structure implements Structure.ByReference { + public TypedSize2D_f32__LayoutUnitByReference() { + super(); + } + + public TypedSize2D_f32__LayoutUnitByReference(Pointer p) { + super(p); + } + + public float width; + public float height; + + } + + + class Size2D_f32 extends TypedSize2D_f32__UnknownUnit { + public Size2D_f32() { + super(); + } + public Size2D_f32(Pointer p) { + super(p); + } + } + + class Size2D_f32ByReference extends TypedSize2D_f32__UnknownUnitByReference { + public Size2D_f32ByReference() { + super(); + } + public Size2D_f32ByReference(Pointer p) { + super(p); + } + } + + class LayoutSize2D extends TypedSize2D_f32__LayoutUnit { + public LayoutSize2D() { + super(); + } + public LayoutSize2D(Pointer p) { + super(p); + } + } + + class LayoutSize2DByReference extends TypedSize2D_f32__LayoutUnitByReference { + public LayoutSize2DByReference() { + super(); + } + public LayoutSize2DByReference(Pointer p) { + super(p); + } + } + + + @Structure.FieldOrder({"x", "y"}) + class TypedPoint2D_f32__UnknownUnit extends Structure implements Structure.ByValue { + public TypedPoint2D_f32__UnknownUnit() { + super(); + } + + public TypedPoint2D_f32__UnknownUnit(Pointer p) { + super(p); + } + + public float x; + public float y; + + } + + @Structure.FieldOrder({"x", "y"}) + class TypedPoint2D_f32__UnknownUnitByReference extends Structure implements Structure.ByReference { + public TypedPoint2D_f32__UnknownUnitByReference() { + super(); + } + + public TypedPoint2D_f32__UnknownUnitByReference(Pointer p) { + super(p); + } + + public float x; + public float y; + + } + + + + @Structure.FieldOrder({"x", "y"}) + class TypedPoint2D_f32__LayoutUnit extends Structure implements Structure.ByValue { + public TypedPoint2D_f32__LayoutUnit() { + super(); + } + + public TypedPoint2D_f32__LayoutUnit(Pointer p) { + super(p); + } + + public float x; + public float y; + + } + + @Structure.FieldOrder({"x", "y"}) + class TypedPoint2D_f32__LayoutUnitByReference extends Structure implements Structure.ByReference { + public TypedPoint2D_f32__LayoutUnitByReference() { + super(); + } + + public TypedPoint2D_f32__LayoutUnitByReference(Pointer p) { + super(p); + } + + public float x; + public float y; + + } + + + class Point2D_f32 extends TypedPoint2D_f32__UnknownUnit { + public Point2D_f32() { + super(); + } + public Point2D_f32(Pointer p) { + super(p); + } + } + + class Point2D_f32ByReference extends TypedPoint2D_f32__UnknownUnitByReference { + public Point2D_f32ByReference() { + super(); + } + public Point2D_f32ByReference(Pointer p) { + super(p); + } + } + + class LayoutPoint2D extends TypedPoint2D_f32__LayoutUnit { + public LayoutPoint2D() { + super(); + } + public LayoutPoint2D(Pointer p) { + super(p); + } + } + + class LayoutPoint2DByReference extends TypedPoint2D_f32__LayoutUnitByReference { + public LayoutPoint2DByReference() { + super(); + } + public LayoutPoint2DByReference(Pointer p) { + super(p); + } + } + + + @Structure.FieldOrder({"origin", "size"}) + class TypedRect_f32__UnknownUnit extends Structure implements Structure.ByValue { + public TypedRect_f32__UnknownUnit() { + super(); + } + + public TypedRect_f32__UnknownUnit(Pointer p) { + super(p); + } + + public TypedPoint2D_f32__UnknownUnit origin; + public TypedSize2D_f32__UnknownUnit size; + + } + + @Structure.FieldOrder({"origin", "size"}) + class TypedRect_f32__UnknownUnitByReference extends Structure implements Structure.ByReference { + public TypedRect_f32__UnknownUnitByReference() { + super(); + } + + public TypedRect_f32__UnknownUnitByReference(Pointer p) { + super(p); + } + + public TypedPoint2D_f32__UnknownUnit origin; + public TypedSize2D_f32__UnknownUnit size; + + } + + + + @Structure.FieldOrder({"origin", "size"}) + class TypedRect_f32__LayoutUnit extends Structure implements Structure.ByValue { + public TypedRect_f32__LayoutUnit() { + super(); + } + + public TypedRect_f32__LayoutUnit(Pointer p) { + super(p); + } + + public TypedPoint2D_f32__LayoutUnit origin; + public TypedSize2D_f32__LayoutUnit size; + + } + + @Structure.FieldOrder({"origin", "size"}) + class TypedRect_f32__LayoutUnitByReference extends Structure implements Structure.ByReference { + public TypedRect_f32__LayoutUnitByReference() { + super(); + } + + public TypedRect_f32__LayoutUnitByReference(Pointer p) { + super(p); + } + + public TypedPoint2D_f32__LayoutUnit origin; + public TypedSize2D_f32__LayoutUnit size; + + } + + + class Rect_f32 extends TypedRect_f32__UnknownUnit { + public Rect_f32() { + super(); + } + public Rect_f32(Pointer p) { + super(p); + } + } + + class Rect_f32ByReference extends TypedRect_f32__UnknownUnitByReference { + public Rect_f32ByReference() { + super(); + } + public Rect_f32ByReference(Pointer p) { + super(p); + } + } + + class LayoutRect extends TypedRect_f32__LayoutUnit { + public LayoutRect() { + super(); + } + public LayoutRect(Pointer p) { + super(p); + } + } + + class LayoutRectByReference extends TypedRect_f32__LayoutUnitByReference { + public LayoutRectByReference() { + super(); + } + public LayoutRectByReference(Pointer p) { + super(p); + } + } + + + @Structure.FieldOrder({"m11", "m12", "m21", "m22", "m31", "m32"}) + class TypedTransform2D_f32__UnknownUnit__LayoutUnit extends Structure implements Structure.ByValue { + public TypedTransform2D_f32__UnknownUnit__LayoutUnit() { + super(); + } + + public TypedTransform2D_f32__UnknownUnit__LayoutUnit(Pointer p) { + super(p); + } + + public float m11; + public float m12; + public float m21; + public float m22; + public float m31; + public float m32; + + } + + @Structure.FieldOrder({"m11", "m12", "m21", "m22", "m31", "m32"}) + class TypedTransform2D_f32__UnknownUnit__LayoutUnitByReference extends Structure implements Structure.ByReference { + public TypedTransform2D_f32__UnknownUnit__LayoutUnitByReference() { + super(); + } + + public TypedTransform2D_f32__UnknownUnit__LayoutUnitByReference(Pointer p) { + super(p); + } + + public float m11; + public float m12; + public float m21; + public float m22; + public float m31; + public float m32; + + } + + + + @Structure.FieldOrder({"m11", "m12", "m21", "m22", "m31", "m32"}) + class TypedTransform2D_f32__LayoutUnit__UnknownUnit extends Structure implements Structure.ByValue { + public TypedTransform2D_f32__LayoutUnit__UnknownUnit() { + super(); + } + + public TypedTransform2D_f32__LayoutUnit__UnknownUnit(Pointer p) { + super(p); + } + + public float m11; + public float m12; + public float m21; + public float m22; + public float m31; + public float m32; + + } + + @Structure.FieldOrder({"m11", "m12", "m21", "m22", "m31", "m32"}) + class TypedTransform2D_f32__LayoutUnit__UnknownUnitByReference extends Structure implements Structure.ByReference { + public TypedTransform2D_f32__LayoutUnit__UnknownUnitByReference() { + super(); + } + + public TypedTransform2D_f32__LayoutUnit__UnknownUnitByReference(Pointer p) { + super(p); + } + + public float m11; + public float m12; + public float m21; + public float m22; + public float m31; + public float m32; + + } + + + void root(TypedLength_f32__UnknownUnit length_a, + TypedLength_f32__LayoutUnit length_b, + Length_f32 length_c, + LayoutLength length_d, + TypedSideOffsets2D_f32__UnknownUnit side_offsets_a, + TypedSideOffsets2D_f32__LayoutUnit side_offsets_b, + SideOffsets2D_f32 side_offsets_c, + LayoutSideOffsets2D side_offsets_d, + TypedSize2D_f32__UnknownUnit size_a, + TypedSize2D_f32__LayoutUnit size_b, + Size2D_f32 size_c, + LayoutSize2D size_d, + TypedPoint2D_f32__UnknownUnit point_a, + TypedPoint2D_f32__LayoutUnit point_b, + Point2D_f32 point_c, + LayoutPoint2D point_d, + TypedRect_f32__UnknownUnit rect_a, + TypedRect_f32__LayoutUnit rect_b, + Rect_f32 rect_c, + LayoutRect rect_d, + TypedTransform2D_f32__UnknownUnit__LayoutUnit transform_a, + TypedTransform2D_f32__LayoutUnit__UnknownUnit transform_b); + +} \ No newline at end of file diff --git a/tests/expectations/exclude_generic_monomorph.java b/tests/expectations/exclude_generic_monomorph.java new file mode 100644 index 000000000..77cf617bf --- /dev/null +++ b/tests/expectations/exclude_generic_monomorph.java @@ -0,0 +1,46 @@ +import com.sun.jna.*; +import com.sun.jna.ptr.*; + +enum BindingsSingleton { + INSTANCE; + final Bindings lib = Native.load("", Bindings.class); +} + +interface Bindings extends Library { + Bindings INSTANCE = BindingsSingleton.INSTANCE.lib; + class Option_Foo {} + + + + @Structure.FieldOrder({"foo"}) + class Bar extends Structure implements Structure.ByValue { + public Bar() { + super(); + } + + public Bar(Pointer p) { + super(p); + } + + public Option_Foo foo; + + } + + @Structure.FieldOrder({"foo"}) + class BarByReference extends Structure implements Structure.ByReference { + public BarByReference() { + super(); + } + + public BarByReference(Pointer p) { + super(p); + } + + public Option_Foo foo; + + } + + + void root(Bar f); + +} \ No newline at end of file diff --git a/tests/expectations/expand.java b/tests/expectations/expand.java new file mode 100644 index 000000000..e75611c55 --- /dev/null +++ b/tests/expectations/expand.java @@ -0,0 +1,40 @@ +import com.sun.jna.*; +import com.sun.jna.ptr.*; + +enum BindingsSingleton { + INSTANCE; + final Bindings lib = Native.load("expand", Bindings.class); +} + +interface Bindings extends Library { + Bindings INSTANCE = BindingsSingleton.INSTANCE.lib; + + + class Foo extends Structure implements Structure.ByValue { + public Foo() { + super(); + } + + public Foo(Pointer p) { + super(p); + } + + + } + + class FooByReference extends Structure implements Structure.ByReference { + public FooByReference() { + super(); + } + + public FooByReference(Pointer p) { + super(p); + } + + + } + + + void root(Foo a); + +} \ No newline at end of file diff --git a/tests/expectations/expand_default_features.java b/tests/expectations/expand_default_features.java new file mode 100644 index 000000000..07770eaec --- /dev/null +++ b/tests/expectations/expand_default_features.java @@ -0,0 +1,42 @@ +import com.sun.jna.*; +import com.sun.jna.ptr.*; + +enum BindingsSingleton { + INSTANCE; + final Bindings lib = Native.load("expand", Bindings.class); +} + +interface Bindings extends Library { + Bindings INSTANCE = BindingsSingleton.INSTANCE.lib; + + + class Foo extends Structure implements Structure.ByValue { + public Foo() { + super(); + } + + public Foo(Pointer p) { + super(p); + } + + + } + + class FooByReference extends Structure implements Structure.ByReference { + public FooByReference() { + super(); + } + + public FooByReference(Pointer p) { + super(p); + } + + + } + + + void extra_debug_fn(); + + void root(Foo a); + +} \ No newline at end of file diff --git a/tests/expectations/expand_dep.java b/tests/expectations/expand_dep.java new file mode 100644 index 000000000..5cc3a4499 --- /dev/null +++ b/tests/expectations/expand_dep.java @@ -0,0 +1,46 @@ +import com.sun.jna.*; +import com.sun.jna.ptr.*; + +enum BindingsSingleton { + INSTANCE; + final Bindings lib = Native.load("expand-dep", Bindings.class); +} + +interface Bindings extends Library { + Bindings INSTANCE = BindingsSingleton.INSTANCE.lib; + + + @Structure.FieldOrder({"x", "y"}) + class dep_struct extends Structure implements Structure.ByValue { + public dep_struct() { + super(); + } + + public dep_struct(Pointer p) { + super(p); + } + + public int x; + public double y; + + } + + @Structure.FieldOrder({"x", "y"}) + class dep_structByReference extends Structure implements Structure.ByReference { + public dep_structByReference() { + super(); + } + + public dep_structByReference(Pointer p) { + super(p); + } + + public int x; + public double y; + + } + + + int get_x(dep_structByReference dep_struct); + +} \ No newline at end of file diff --git a/tests/expectations/expand_dep_v2.java b/tests/expectations/expand_dep_v2.java new file mode 100644 index 000000000..72afcfbbe --- /dev/null +++ b/tests/expectations/expand_dep_v2.java @@ -0,0 +1,46 @@ +import com.sun.jna.*; +import com.sun.jna.ptr.*; + +enum BindingsSingleton { + INSTANCE; + final Bindings lib = Native.load("expand-dep-2", Bindings.class); +} + +interface Bindings extends Library { + Bindings INSTANCE = BindingsSingleton.INSTANCE.lib; + + + @Structure.FieldOrder({"x", "y"}) + class dep_struct extends Structure implements Structure.ByValue { + public dep_struct() { + super(); + } + + public dep_struct(Pointer p) { + super(p); + } + + public int x; + public double y; + + } + + @Structure.FieldOrder({"x", "y"}) + class dep_structByReference extends Structure implements Structure.ByReference { + public dep_structByReference() { + super(); + } + + public dep_structByReference(Pointer p) { + super(p); + } + + public int x; + public double y; + + } + + + int get_x(dep_structByReference dep_struct); + +} \ No newline at end of file diff --git a/tests/expectations/expand_features.java b/tests/expectations/expand_features.java new file mode 100644 index 000000000..2e64a6df9 --- /dev/null +++ b/tests/expectations/expand_features.java @@ -0,0 +1,44 @@ +import com.sun.jna.*; +import com.sun.jna.ptr.*; + +enum BindingsSingleton { + INSTANCE; + final Bindings lib = Native.load("expand", Bindings.class); +} + +interface Bindings extends Library { + Bindings INSTANCE = BindingsSingleton.INSTANCE.lib; + + + class Foo extends Structure implements Structure.ByValue { + public Foo() { + super(); + } + + public Foo(Pointer p) { + super(p); + } + + + } + + class FooByReference extends Structure implements Structure.ByReference { + public FooByReference() { + super(); + } + + public FooByReference(Pointer p) { + super(p); + } + + + } + + + void extra_debug_fn(); + + void cbindgen(); + + void root(Foo a); + +} \ No newline at end of file diff --git a/tests/expectations/expand_no_default_features.java b/tests/expectations/expand_no_default_features.java new file mode 100644 index 000000000..e75611c55 --- /dev/null +++ b/tests/expectations/expand_no_default_features.java @@ -0,0 +1,40 @@ +import com.sun.jna.*; +import com.sun.jna.ptr.*; + +enum BindingsSingleton { + INSTANCE; + final Bindings lib = Native.load("expand", Bindings.class); +} + +interface Bindings extends Library { + Bindings INSTANCE = BindingsSingleton.INSTANCE.lib; + + + class Foo extends Structure implements Structure.ByValue { + public Foo() { + super(); + } + + public Foo(Pointer p) { + super(p); + } + + + } + + class FooByReference extends Structure implements Structure.ByReference { + public FooByReference() { + super(); + } + + public FooByReference(Pointer p) { + super(p); + } + + + } + + + void root(Foo a); + +} \ No newline at end of file diff --git a/tests/expectations/export_name.java b/tests/expectations/export_name.java new file mode 100644 index 000000000..ff117a637 --- /dev/null +++ b/tests/expectations/export_name.java @@ -0,0 +1,14 @@ +import com.sun.jna.*; +import com.sun.jna.ptr.*; + +enum BindingsSingleton { + INSTANCE; + final Bindings lib = Native.load("", Bindings.class); +} + +interface Bindings extends Library { + Bindings INSTANCE = BindingsSingleton.INSTANCE.lib; + + void do_the_thing_with_export_name(); + +} \ No newline at end of file diff --git a/tests/expectations/extern.java b/tests/expectations/extern.java new file mode 100644 index 000000000..afe99fcd1 --- /dev/null +++ b/tests/expectations/extern.java @@ -0,0 +1,48 @@ +import com.sun.jna.*; +import com.sun.jna.ptr.*; + +enum BindingsSingleton { + INSTANCE; + final Bindings lib = Native.load("", Bindings.class); +} + +interface Bindings extends Library { + Bindings INSTANCE = BindingsSingleton.INSTANCE.lib; + + + @Structure.FieldOrder({"x", "y"}) + class Normal extends Structure implements Structure.ByValue { + public Normal() { + super(); + } + + public Normal(Pointer p) { + super(p); + } + + public int x; + public float y; + + } + + @Structure.FieldOrder({"x", "y"}) + class NormalByReference extends Structure implements Structure.ByReference { + public NormalByReference() { + super(); + } + + public NormalByReference(Pointer p) { + super(p); + } + + public int x; + public float y; + + } + + + int foo(); + + void bar(Normal a); + +} \ No newline at end of file diff --git a/tests/expectations/extern_2.java b/tests/expectations/extern_2.java new file mode 100644 index 000000000..784f35f61 --- /dev/null +++ b/tests/expectations/extern_2.java @@ -0,0 +1,16 @@ +import com.sun.jna.*; +import com.sun.jna.ptr.*; + +enum BindingsSingleton { + INSTANCE; + final Bindings lib = Native.load("", Bindings.class); +} + +interface Bindings extends Library { + Bindings INSTANCE = BindingsSingleton.INSTANCE.lib; + + void first(); + + void second(); + +} \ No newline at end of file diff --git a/tests/expectations/external_workspace_child.java b/tests/expectations/external_workspace_child.java new file mode 100644 index 000000000..9adb9c01d --- /dev/null +++ b/tests/expectations/external_workspace_child.java @@ -0,0 +1,44 @@ +import com.sun.jna.*; +import com.sun.jna.ptr.*; + +enum BindingsSingleton { + INSTANCE; + final Bindings lib = Native.load("child", Bindings.class); +} + +interface Bindings extends Library { + Bindings INSTANCE = BindingsSingleton.INSTANCE.lib; + + + @Structure.FieldOrder({"data"}) + class ExtType extends Structure implements Structure.ByValue { + public ExtType() { + super(); + } + + public ExtType(Pointer p) { + super(p); + } + + public int data; + + } + + @Structure.FieldOrder({"data"}) + class ExtTypeByReference extends Structure implements Structure.ByReference { + public ExtTypeByReference() { + super(); + } + + public ExtTypeByReference(Pointer p) { + super(p); + } + + public int data; + + } + + + void consume_ext(ExtType _ext); + +} \ No newline at end of file diff --git a/tests/expectations/fns.java b/tests/expectations/fns.java new file mode 100644 index 000000000..2359ab6bd --- /dev/null +++ b/tests/expectations/fns.java @@ -0,0 +1,62 @@ +import com.sun.jna.*; +import com.sun.jna.ptr.*; + +enum BindingsSingleton { + INSTANCE; + final Bindings lib = Native.load("", Bindings.class); +} + +interface Bindings extends Library { + Bindings INSTANCE = BindingsSingleton.INSTANCE.lib; + + + @Structure.FieldOrder({"noArgs", + "anonymousArg", + "returnsNumber", + "namedArgs", + "namedArgsWildcards"}) + class Fns extends Structure implements Structure.ByValue { + public Fns() { + super(); + } + + public Fns(Pointer p) { + super(p); + } + + public Callback noArgs; + public Callback anonymousArg; + public Callback returnsNumber; + public Callback namedArgs; + public Callback namedArgsWildcards; + + } + + @Structure.FieldOrder({"noArgs", + "anonymousArg", + "returnsNumber", + "namedArgs", + "namedArgsWildcards"}) + class FnsByReference extends Structure implements Structure.ByReference { + public FnsByReference() { + super(); + } + + public FnsByReference(Pointer p) { + super(p); + } + + public Callback noArgs; + public Callback anonymousArg; + public Callback returnsNumber; + public Callback namedArgs; + public Callback namedArgsWildcards; + + } + + + void root(Fns _fns); + + void no_return(); + +} \ No newline at end of file diff --git a/tests/expectations/forward_declaration.java b/tests/expectations/forward_declaration.java new file mode 100644 index 000000000..5fbee40f9 --- /dev/null +++ b/tests/expectations/forward_declaration.java @@ -0,0 +1,115 @@ + +import com.sun.jna.*; +import com.sun.jna.ptr.*; + +enum BindingsSingleton { + INSTANCE; + final Bindings lib = Native.load("", Bindings.class); +} + +interface Bindings extends Library { + Bindings INSTANCE = BindingsSingleton.INSTANCE.lib; + + + @Structure.FieldOrder({"fields", "num_fields"}) + class StructInfo extends Structure implements Structure.ByValue { + public StructInfo() { + super(); + } + + public StructInfo(Pointer p) { + super(p); + } + + public PointerByReference fields; + public NativeLong num_fields; + + } + + @Structure.FieldOrder({"fields", "num_fields"}) + class StructInfoByReference extends Structure implements Structure.ByReference { + public StructInfoByReference() { + super(); + } + + public StructInfoByReference(Pointer p) { + super(p); + } + + public PointerByReference fields; + public NativeLong num_fields; + + } + + + class TypeData extends IntegerType { + public TypeData() { + super(4); + } + + public TypeData(long value) { + super(4, value); + } + + public TypeData(Pointer p) { + this(p.getInt(0)); + } + public static final TypeData Primitive = new TypeData(1); + public static final TypeData Struct = new TypeData(2); + + } + + class TypeDataByReference extends ByReference { + public TypeDataByReference() { + super(4); + } + + public TypeDataByReference(Pointer p) { + super(4); + setPointer(p); + } + + public TypeData getValue() { + return new TypeData(getPointer().getInt(0)); + } + + public void setValue(TypeData value) { + getPointer().setInt(0, value.intValue()); + } + + } + + + @Structure.FieldOrder({"data"}) + class TypeInfo extends Structure implements Structure.ByValue { + public TypeInfo() { + super(); + } + + public TypeInfo(Pointer p) { + super(p); + } + + public TypeData data; + + } + + @Structure.FieldOrder({"data"}) + class TypeInfoByReference extends Structure implements Structure.ByReference { + public TypeInfoByReference() { + super(); + } + + public TypeInfoByReference(Pointer p) { + super(p); + } + + public TypeData data; + + } + + + void root(TypeInfo x); + +} + diff --git a/tests/expectations/function_args.java b/tests/expectations/function_args.java new file mode 100644 index 000000000..1805af1a3 --- /dev/null +++ b/tests/expectations/function_args.java @@ -0,0 +1,18 @@ +import com.sun.jna.*; +import com.sun.jna.ptr.*; + +enum BindingsSingleton { + INSTANCE; + final Bindings lib = Native.load("", Bindings.class); +} + +interface Bindings extends Library { + Bindings INSTANCE = BindingsSingleton.INSTANCE.lib; + + void unnamed(LongByReference arg0); + + void pointer_test(LongByReference a); + + void print_from_rust(); + +} \ No newline at end of file diff --git a/tests/expectations/function_noreturn.java b/tests/expectations/function_noreturn.java new file mode 100644 index 000000000..3aea234c0 --- /dev/null +++ b/tests/expectations/function_noreturn.java @@ -0,0 +1,46 @@ +import com.sun.jna.*; +import com.sun.jna.ptr.*; + +enum BindingsSingleton { + INSTANCE; + final Bindings lib = Native.load("", Bindings.class); +} + +interface Bindings extends Library { + Bindings INSTANCE = BindingsSingleton.INSTANCE.lib; + + + @Structure.FieldOrder({"f"}) + class Example extends Structure implements Structure.ByValue { + public Example() { + super(); + } + + public Example(Pointer p) { + super(p); + } + + public Callback f; + + } + + @Structure.FieldOrder({"f"}) + class ExampleByReference extends Structure implements Structure.ByReference { + public ExampleByReference() { + super(); + } + + public ExampleByReference(Pointer p) { + super(p); + } + + public Callback f; + + } + + + void loop_forever(); + + byte normal_return(Example arg, Callback other); + +} \ No newline at end of file diff --git a/tests/expectations/function_ptr.java b/tests/expectations/function_ptr.java new file mode 100644 index 000000000..45a57d751 --- /dev/null +++ b/tests/expectations/function_ptr.java @@ -0,0 +1,26 @@ +import com.sun.jna.*; +import com.sun.jna.ptr.*; + +enum BindingsSingleton { + INSTANCE; + final Bindings lib = Native.load("", Bindings.class); +} + +interface Bindings extends Library { + Bindings INSTANCE = BindingsSingleton.INSTANCE.lib; + + interface MyCallback extends Callback { + void invoke(NativeLong a, NativeLong b); + } + + interface MyOtherCallback extends Callback { + void invoke(NativeLong a, + NativeLong lot, + NativeLong of, + NativeLong args, + NativeLong and_then_some); + } + + void my_function(MyCallback a, MyOtherCallback b); + +} \ No newline at end of file diff --git a/tests/expectations/function_sort_name.java b/tests/expectations/function_sort_name.java new file mode 100644 index 000000000..d433148b6 --- /dev/null +++ b/tests/expectations/function_sort_name.java @@ -0,0 +1,20 @@ +import com.sun.jna.*; +import com.sun.jna.ptr.*; + +enum BindingsSingleton { + INSTANCE; + final Bindings lib = Native.load("", Bindings.class); +} + +interface Bindings extends Library { + Bindings INSTANCE = BindingsSingleton.INSTANCE.lib; + + void A(); + + void B(); + + void C(); + + void D(); + +} \ No newline at end of file diff --git a/tests/expectations/function_sort_none.java b/tests/expectations/function_sort_none.java new file mode 100644 index 000000000..dc9c69eef --- /dev/null +++ b/tests/expectations/function_sort_none.java @@ -0,0 +1,20 @@ +import com.sun.jna.*; +import com.sun.jna.ptr.*; + +enum BindingsSingleton { + INSTANCE; + final Bindings lib = Native.load("", Bindings.class); +} + +interface Bindings extends Library { + Bindings INSTANCE = BindingsSingleton.INSTANCE.lib; + + void C(); + + void B(); + + void D(); + + void A(); + +} \ No newline at end of file diff --git a/tests/expectations/generic_pointer.java b/tests/expectations/generic_pointer.java new file mode 100644 index 000000000..7da2d218f --- /dev/null +++ b/tests/expectations/generic_pointer.java @@ -0,0 +1,62 @@ +import com.sun.jna.*; +import com.sun.jna.ptr.*; + +enum BindingsSingleton { + INSTANCE; + final Bindings lib = Native.load("", Bindings.class); +} + +interface Bindings extends Library { + Bindings INSTANCE = BindingsSingleton.INSTANCE.lib; + + + @Structure.FieldOrder({"a"}) + class Foo_____u8 extends Structure implements Structure.ByValue { + public Foo_____u8() { + super(); + } + + public Foo_____u8(Pointer p) { + super(p); + } + + public ByteByReference a; + + } + + @Structure.FieldOrder({"a"}) + class Foo_____u8ByReference extends Structure implements Structure.ByReference { + public Foo_____u8ByReference() { + super(); + } + + public Foo_____u8ByReference(Pointer p) { + super(p); + } + + public ByteByReference a; + + } + + + class Boo extends Foo_____u8 { + public Boo() { + super(); + } + public Boo(Pointer p) { + super(p); + } + } + + class BooByReference extends Foo_____u8ByReference { + public BooByReference() { + super(); + } + public BooByReference(Pointer p) { + super(p); + } + } + + void root(Boo x); + +} \ No newline at end of file diff --git a/tests/expectations/global_attr.java b/tests/expectations/global_attr.java new file mode 100644 index 000000000..90cf1e1b0 --- /dev/null +++ b/tests/expectations/global_attr.java @@ -0,0 +1,12 @@ +import com.sun.jna.*; +import com.sun.jna.ptr.*; + +enum BindingsSingleton { + INSTANCE; + final Bindings lib = Native.load("", Bindings.class); +} + +interface Bindings extends Library { + Bindings INSTANCE = BindingsSingleton.INSTANCE.lib; + +} \ No newline at end of file diff --git a/tests/expectations/global_variable.java b/tests/expectations/global_variable.java new file mode 100644 index 000000000..b881dbb40 --- /dev/null +++ b/tests/expectations/global_variable.java @@ -0,0 +1,16 @@ +import com.sun.jna.*; +import com.sun.jna.ptr.*; + +enum BindingsSingleton { + INSTANCE; + final Bindings lib = Native.load("", Bindings.class); +} + +interface Bindings extends Library { + Bindings INSTANCE = BindingsSingleton.INSTANCE.lib; + + /* Not implemented yet : Static { path: Path { name: "MUT_GLOBAL_ARRAY" }, export_name: "MUT_GLOBAL_ARRAY", ty: Array(Primitive(Char), Value("128")), mutable: true, cfg: None, annotations: AnnotationSet { annotations: {}, must_use: false, deprecated: None }, documentation: Documentation { doc_comment: [] } } */ + + /* Not implemented yet : Static { path: Path { name: "CONST_GLOBAL_ARRAY" }, export_name: "CONST_GLOBAL_ARRAY", ty: Array(Primitive(Char), Value("128")), mutable: false, cfg: None, annotations: AnnotationSet { annotations: {}, must_use: false, deprecated: None }, documentation: Documentation { doc_comment: [] } } */ + +} \ No newline at end of file diff --git a/tests/expectations/ignore.java b/tests/expectations/ignore.java new file mode 100644 index 000000000..b52ae1a4a --- /dev/null +++ b/tests/expectations/ignore.java @@ -0,0 +1,14 @@ +import com.sun.jna.*; +import com.sun.jna.ptr.*; + +enum BindingsSingleton { + INSTANCE; + final Bindings lib = Native.load("", Bindings.class); +} + +interface Bindings extends Library { + Bindings INSTANCE = BindingsSingleton.INSTANCE.lib; + + void no_ignore_root(); + +} \ No newline at end of file diff --git a/tests/expectations/include.java b/tests/expectations/include.java new file mode 100644 index 000000000..90cf1e1b0 --- /dev/null +++ b/tests/expectations/include.java @@ -0,0 +1,12 @@ +import com.sun.jna.*; +import com.sun.jna.ptr.*; + +enum BindingsSingleton { + INSTANCE; + final Bindings lib = Native.load("", Bindings.class); +} + +interface Bindings extends Library { + Bindings INSTANCE = BindingsSingleton.INSTANCE.lib; + +} \ No newline at end of file diff --git a/tests/expectations/include_guard.java b/tests/expectations/include_guard.java new file mode 100644 index 000000000..519182a41 --- /dev/null +++ b/tests/expectations/include_guard.java @@ -0,0 +1,14 @@ +import com.sun.jna.*; +import com.sun.jna.ptr.*; + +enum BindingsSingleton { + INSTANCE; + final Bindings lib = Native.load("", Bindings.class); +} + +interface Bindings extends Library { + Bindings INSTANCE = BindingsSingleton.INSTANCE.lib; + + void root(); + +} \ No newline at end of file diff --git a/tests/expectations/include_item.java b/tests/expectations/include_item.java new file mode 100644 index 000000000..abe230e96 --- /dev/null +++ b/tests/expectations/include_item.java @@ -0,0 +1,74 @@ +import com.sun.jna.*; +import com.sun.jna.ptr.*; + +enum BindingsSingleton { + INSTANCE; + final Bindings lib = Native.load("", Bindings.class); +} + +interface Bindings extends Library { + Bindings INSTANCE = BindingsSingleton.INSTANCE.lib; + + + @Structure.FieldOrder({"x", "y"}) + class A extends Structure implements Structure.ByValue { + public A() { + super(); + } + + public A(Pointer p) { + super(p); + } + + public int x; + public float y; + + } + + @Structure.FieldOrder({"x", "y"}) + class AByReference extends Structure implements Structure.ByReference { + public AByReference() { + super(); + } + + public AByReference(Pointer p) { + super(p); + } + + public int x; + public float y; + + } + + + + @Structure.FieldOrder({"data"}) + class B extends Structure implements Structure.ByValue { + public B() { + super(); + } + + public B(Pointer p) { + super(p); + } + + public A data; + + } + + @Structure.FieldOrder({"data"}) + class BByReference extends Structure implements Structure.ByReference { + public BByReference() { + super(); + } + + public BByReference(Pointer p) { + super(p); + } + + public A data; + + } + + +} \ No newline at end of file diff --git a/tests/expectations/include_specific.java b/tests/expectations/include_specific.java new file mode 100644 index 000000000..90cf1e1b0 --- /dev/null +++ b/tests/expectations/include_specific.java @@ -0,0 +1,12 @@ +import com.sun.jna.*; +import com.sun.jna.ptr.*; + +enum BindingsSingleton { + INSTANCE; + final Bindings lib = Native.load("", Bindings.class); +} + +interface Bindings extends Library { + Bindings INSTANCE = BindingsSingleton.INSTANCE.lib; + +} \ No newline at end of file diff --git a/tests/expectations/infinite_recursion_typedef_monomorph.java b/tests/expectations/infinite_recursion_typedef_monomorph.java new file mode 100644 index 000000000..90cf1e1b0 --- /dev/null +++ b/tests/expectations/infinite_recursion_typedef_monomorph.java @@ -0,0 +1,12 @@ +import com.sun.jna.*; +import com.sun.jna.ptr.*; + +enum BindingsSingleton { + INSTANCE; + final Bindings lib = Native.load("", Bindings.class); +} + +interface Bindings extends Library { + Bindings INSTANCE = BindingsSingleton.INSTANCE.lib; + +} \ No newline at end of file diff --git a/tests/expectations/inner_mod.java b/tests/expectations/inner_mod.java new file mode 100644 index 000000000..58880d02f --- /dev/null +++ b/tests/expectations/inner_mod.java @@ -0,0 +1,44 @@ +import com.sun.jna.*; +import com.sun.jna.ptr.*; + +enum BindingsSingleton { + INSTANCE; + final Bindings lib = Native.load("", Bindings.class); +} + +interface Bindings extends Library { + Bindings INSTANCE = BindingsSingleton.INSTANCE.lib; + + + @Structure.FieldOrder({"x"}) + class Foo extends Structure implements Structure.ByValue { + public Foo() { + super(); + } + + public Foo(Pointer p) { + super(p); + } + + public float x; + + } + + @Structure.FieldOrder({"x"}) + class FooByReference extends Structure implements Structure.ByReference { + public FooByReference() { + super(); + } + + public FooByReference(Pointer p) { + super(p); + } + + public float x; + + } + + + void root(Foo a); + +} \ No newline at end of file diff --git a/tests/expectations/item_types.java b/tests/expectations/item_types.java new file mode 100644 index 000000000..09e6af32c --- /dev/null +++ b/tests/expectations/item_types.java @@ -0,0 +1,49 @@ +import com.sun.jna.*; +import com.sun.jna.ptr.*; + +enum BindingsSingleton { + INSTANCE; + final Bindings lib = Native.load("", Bindings.class); +} + +interface Bindings extends Library { + Bindings INSTANCE = BindingsSingleton.INSTANCE.lib; + + class OnlyThisShouldBeGenerated extends IntegerType { + public OnlyThisShouldBeGenerated() { + super(4); + } + + public OnlyThisShouldBeGenerated(long value) { + super(4, value); + } + + public OnlyThisShouldBeGenerated(Pointer p) { + this(p.getInt(0)); + } + public static final OnlyThisShouldBeGenerated Foo = new OnlyThisShouldBeGenerated(1); + public static final OnlyThisShouldBeGenerated Bar = new OnlyThisShouldBeGenerated(2); + + } + + class OnlyThisShouldBeGeneratedByReference extends ByReference { + public OnlyThisShouldBeGeneratedByReference() { + super(4); + } + + public OnlyThisShouldBeGeneratedByReference(Pointer p) { + super(4); + setPointer(p); + } + + public OnlyThisShouldBeGenerated getValue() { + return new OnlyThisShouldBeGenerated(getPointer().getInt(0)); + } + + public void setValue(OnlyThisShouldBeGenerated value) { + getPointer().setInt(0, value.intValue()); + } + + } + +} \ No newline at end of file diff --git a/tests/expectations/item_types_renamed.java b/tests/expectations/item_types_renamed.java new file mode 100644 index 000000000..b6108649e --- /dev/null +++ b/tests/expectations/item_types_renamed.java @@ -0,0 +1,49 @@ +import com.sun.jna.*; +import com.sun.jna.ptr.*; + +enum BindingsSingleton { + INSTANCE; + final Bindings lib = Native.load("", Bindings.class); +} + +interface Bindings extends Library { + Bindings INSTANCE = BindingsSingleton.INSTANCE.lib; + + class StyleOnlyThisShouldBeGenerated extends IntegerType { + public StyleOnlyThisShouldBeGenerated() { + super(4); + } + + public StyleOnlyThisShouldBeGenerated(long value) { + super(4, value); + } + + public StyleOnlyThisShouldBeGenerated(Pointer p) { + this(p.getInt(0)); + } + public static final StyleOnlyThisShouldBeGenerated Foo = new StyleOnlyThisShouldBeGenerated(1); + public static final StyleOnlyThisShouldBeGenerated Bar = new StyleOnlyThisShouldBeGenerated(2); + + } + + class StyleOnlyThisShouldBeGeneratedByReference extends ByReference { + public StyleOnlyThisShouldBeGeneratedByReference() { + super(4); + } + + public StyleOnlyThisShouldBeGeneratedByReference(Pointer p) { + super(4); + setPointer(p); + } + + public StyleOnlyThisShouldBeGenerated getValue() { + return new StyleOnlyThisShouldBeGenerated(getPointer().getInt(0)); + } + + public void setValue(StyleOnlyThisShouldBeGenerated value) { + getPointer().setInt(0, value.intValue()); + } + + } + +} \ No newline at end of file diff --git a/tests/expectations/layout.java b/tests/expectations/layout.java new file mode 100644 index 000000000..63bfb8b78 --- /dev/null +++ b/tests/expectations/layout.java @@ -0,0 +1,459 @@ + +import com.sun.jna.*; +import com.sun.jna.ptr.*; + +enum BindingsSingleton { + INSTANCE; + final Bindings lib = Native.load("", Bindings.class); +} + +interface Bindings extends Library { + Bindings INSTANCE = BindingsSingleton.INSTANCE.lib; + + class RustAlign4Struct extends PointerType { + public RustAlign4Struct() { + super(null); + } + public RustAlign4Struct(Pointer p) { + super(p); + } + } + + class RustAlign4StructByReference extends RustAlign4Struct { + public RustAlign4StructByReference() { + super(null); + } + public RustAlign4StructByReference(Pointer p) { + super(p); + } + } + + class RustAlign4Union extends PointerType { + public RustAlign4Union() { + super(null); + } + public RustAlign4Union(Pointer p) { + super(p); + } + } + + class RustAlign4UnionByReference extends RustAlign4Union { + public RustAlign4UnionByReference() { + super(null); + } + public RustAlign4UnionByReference(Pointer p) { + super(p); + } + } + + class RustPackedStruct extends PointerType { + public RustPackedStruct() { + super(null); + } + public RustPackedStruct(Pointer p) { + super(p); + } + } + + class RustPackedStructByReference extends RustPackedStruct { + public RustPackedStructByReference() { + super(null); + } + public RustPackedStructByReference(Pointer p) { + super(p); + } + } + + class RustPackedUnion extends PointerType { + public RustPackedUnion() { + super(null); + } + public RustPackedUnion(Pointer p) { + super(p); + } + } + + class RustPackedUnionByReference extends RustPackedUnion { + public RustPackedUnionByReference() { + super(null); + } + public RustPackedUnionByReference(Pointer p) { + super(p); + } + } + + class UnsupportedAlign4Enum extends PointerType { + public UnsupportedAlign4Enum() { + super(null); + } + public UnsupportedAlign4Enum(Pointer p) { + super(p); + } + } + + class UnsupportedAlign4EnumByReference extends UnsupportedAlign4Enum { + public UnsupportedAlign4EnumByReference() { + super(null); + } + public UnsupportedAlign4EnumByReference(Pointer p) { + super(p); + } + } + + class UnsupportedPacked4Struct extends PointerType { + public UnsupportedPacked4Struct() { + super(null); + } + public UnsupportedPacked4Struct(Pointer p) { + super(p); + } + } + + class UnsupportedPacked4StructByReference extends UnsupportedPacked4Struct { + public UnsupportedPacked4StructByReference() { + super(null); + } + public UnsupportedPacked4StructByReference(Pointer p) { + super(p); + } + } + + class UnsupportedPacked4Union extends PointerType { + public UnsupportedPacked4Union() { + super(null); + } + public UnsupportedPacked4Union(Pointer p) { + super(p); + } + } + + class UnsupportedPacked4UnionByReference extends UnsupportedPacked4Union { + public UnsupportedPacked4UnionByReference() { + super(null); + } + public UnsupportedPacked4UnionByReference(Pointer p) { + super(p); + } + } + + + @Structure.FieldOrder({"arg1", "arg2"}) + class Align1Struct extends Structure implements Structure.ByValue { + public Align1Struct() { + super(); + } + + public Align1Struct(Pointer p) { + super(p); + } + + public NativeLong arg1; + public ByteByReference arg2; + + } + + @Structure.FieldOrder({"arg1", "arg2"}) + class Align1StructByReference extends Structure implements Structure.ByReference { + public Align1StructByReference() { + super(); + } + + public Align1StructByReference(Pointer p) { + super(p); + } + + public NativeLong arg1; + public ByteByReference arg2; + + } + + + + @Structure.FieldOrder({"arg1", "arg2"}) + class Align2Struct extends Structure implements Structure.ByValue { + public Align2Struct() { + super(); + } + + public Align2Struct(Pointer p) { + super(p); + } + + public NativeLong arg1; + public ByteByReference arg2; + + } + + @Structure.FieldOrder({"arg1", "arg2"}) + class Align2StructByReference extends Structure implements Structure.ByReference { + public Align2StructByReference() { + super(); + } + + public Align2StructByReference(Pointer p) { + super(p); + } + + public NativeLong arg1; + public ByteByReference arg2; + + } + + + + @Structure.FieldOrder({"arg1", "arg2"}) + class Align4Struct extends Structure implements Structure.ByValue { + public Align4Struct() { + super(); + } + + public Align4Struct(Pointer p) { + super(p); + } + + public NativeLong arg1; + public ByteByReference arg2; + + } + + @Structure.FieldOrder({"arg1", "arg2"}) + class Align4StructByReference extends Structure implements Structure.ByReference { + public Align4StructByReference() { + super(); + } + + public Align4StructByReference(Pointer p) { + super(p); + } + + public NativeLong arg1; + public ByteByReference arg2; + + } + + + + @Structure.FieldOrder({"arg1", "arg2"}) + class Align8Struct extends Structure implements Structure.ByValue { + public Align8Struct() { + super(); + } + + public Align8Struct(Pointer p) { + super(p); + } + + public NativeLong arg1; + public ByteByReference arg2; + + } + + @Structure.FieldOrder({"arg1", "arg2"}) + class Align8StructByReference extends Structure implements Structure.ByReference { + public Align8StructByReference() { + super(); + } + + public Align8StructByReference(Pointer p) { + super(p); + } + + public NativeLong arg1; + public ByteByReference arg2; + + } + + + + @Structure.FieldOrder({"arg1", "arg2"}) + class Align32Struct extends Structure implements Structure.ByValue { + public Align32Struct() { + super(); + } + + public Align32Struct(Pointer p) { + super(p); + } + + public NativeLong arg1; + public ByteByReference arg2; + + } + + @Structure.FieldOrder({"arg1", "arg2"}) + class Align32StructByReference extends Structure implements Structure.ByReference { + public Align32StructByReference() { + super(); + } + + public Align32StructByReference(Pointer p) { + super(p); + } + + public NativeLong arg1; + public ByteByReference arg2; + + } + + + + @Structure.FieldOrder({"arg1", "arg2"}) + class PackedStruct extends Structure implements Structure.ByValue { + public PackedStruct() { + super(); + } + + public PackedStruct(Pointer p) { + super(p); + } + + public NativeLong arg1; + public ByteByReference arg2; + + } + + @Structure.FieldOrder({"arg1", "arg2"}) + class PackedStructByReference extends Structure implements Structure.ByReference { + public PackedStructByReference() { + super(); + } + + public PackedStructByReference(Pointer p) { + super(p); + } + + public NativeLong arg1; + public ByteByReference arg2; + + } + + + + @Structure.FieldOrder({"variant1", "variant2"}) + class Align1Union extends Union implements Structure.ByValue { + public Align1Union() { + super(); + } + + public Align1Union(Pointer p) { + super(p); + } + + public NativeLong variant1; + public ByteByReference variant2; + + } + + @Structure.FieldOrder({"variant1", "variant2"}) + class Align1UnionByReference extends Union implements Structure.ByReference { + public Align1UnionByReference() { + super(); + } + + public Align1UnionByReference(Pointer p) { + super(p); + } + + public NativeLong variant1; + public ByteByReference variant2; + + } + + + + @Structure.FieldOrder({"variant1", "variant2"}) + class Align4Union extends Union implements Structure.ByValue { + public Align4Union() { + super(); + } + + public Align4Union(Pointer p) { + super(p); + } + + public NativeLong variant1; + public ByteByReference variant2; + + } + + @Structure.FieldOrder({"variant1", "variant2"}) + class Align4UnionByReference extends Union implements Structure.ByReference { + public Align4UnionByReference() { + super(); + } + + public Align4UnionByReference(Pointer p) { + super(p); + } + + public NativeLong variant1; + public ByteByReference variant2; + + } + + + + @Structure.FieldOrder({"variant1", "variant2"}) + class Align16Union extends Union implements Structure.ByValue { + public Align16Union() { + super(); + } + + public Align16Union(Pointer p) { + super(p); + } + + public NativeLong variant1; + public ByteByReference variant2; + + } + + @Structure.FieldOrder({"variant1", "variant2"}) + class Align16UnionByReference extends Union implements Structure.ByReference { + public Align16UnionByReference() { + super(); + } + + public Align16UnionByReference(Pointer p) { + super(p); + } + + public NativeLong variant1; + public ByteByReference variant2; + + } + + + + @Structure.FieldOrder({"variant1", "variant2"}) + class PackedUnion extends Union implements Structure.ByValue { + public PackedUnion() { + super(); + } + + public PackedUnion(Pointer p) { + super(p); + } + + public NativeLong variant1; + public ByteByReference variant2; + + } + + @Structure.FieldOrder({"variant1", "variant2"}) + class PackedUnionByReference extends Union implements Structure.ByReference { + public PackedUnionByReference() { + super(); + } + + public PackedUnionByReference(Pointer p) { + super(p); + } + + public NativeLong variant1; + public ByteByReference variant2; + + } + + +} \ No newline at end of file diff --git a/tests/expectations/layout_aligned_opaque.java b/tests/expectations/layout_aligned_opaque.java new file mode 100644 index 000000000..187099c97 --- /dev/null +++ b/tests/expectations/layout_aligned_opaque.java @@ -0,0 +1,221 @@ + +import com.sun.jna.*; +import com.sun.jna.ptr.*; + +enum BindingsSingleton { + INSTANCE; + final Bindings lib = Native.load("", Bindings.class); +} + +interface Bindings extends Library { + Bindings INSTANCE = BindingsSingleton.INSTANCE.lib; + + class OpaqueAlign16Union extends PointerType { + public OpaqueAlign16Union() { + super(null); + } + public OpaqueAlign16Union(Pointer p) { + super(p); + } + } + + class OpaqueAlign16UnionByReference extends OpaqueAlign16Union { + public OpaqueAlign16UnionByReference() { + super(null); + } + public OpaqueAlign16UnionByReference(Pointer p) { + super(p); + } + } + + class OpaqueAlign1Struct extends PointerType { + public OpaqueAlign1Struct() { + super(null); + } + public OpaqueAlign1Struct(Pointer p) { + super(p); + } + } + + class OpaqueAlign1StructByReference extends OpaqueAlign1Struct { + public OpaqueAlign1StructByReference() { + super(null); + } + public OpaqueAlign1StructByReference(Pointer p) { + super(p); + } + } + + class OpaqueAlign1Union extends PointerType { + public OpaqueAlign1Union() { + super(null); + } + public OpaqueAlign1Union(Pointer p) { + super(p); + } + } + + class OpaqueAlign1UnionByReference extends OpaqueAlign1Union { + public OpaqueAlign1UnionByReference() { + super(null); + } + public OpaqueAlign1UnionByReference(Pointer p) { + super(p); + } + } + + class OpaqueAlign2Struct extends PointerType { + public OpaqueAlign2Struct() { + super(null); + } + public OpaqueAlign2Struct(Pointer p) { + super(p); + } + } + + class OpaqueAlign2StructByReference extends OpaqueAlign2Struct { + public OpaqueAlign2StructByReference() { + super(null); + } + public OpaqueAlign2StructByReference(Pointer p) { + super(p); + } + } + + class OpaqueAlign32Struct extends PointerType { + public OpaqueAlign32Struct() { + super(null); + } + public OpaqueAlign32Struct(Pointer p) { + super(p); + } + } + + class OpaqueAlign32StructByReference extends OpaqueAlign32Struct { + public OpaqueAlign32StructByReference() { + super(null); + } + public OpaqueAlign32StructByReference(Pointer p) { + super(p); + } + } + + class OpaqueAlign4Struct extends PointerType { + public OpaqueAlign4Struct() { + super(null); + } + public OpaqueAlign4Struct(Pointer p) { + super(p); + } + } + + class OpaqueAlign4StructByReference extends OpaqueAlign4Struct { + public OpaqueAlign4StructByReference() { + super(null); + } + public OpaqueAlign4StructByReference(Pointer p) { + super(p); + } + } + + class OpaqueAlign4Union extends PointerType { + public OpaqueAlign4Union() { + super(null); + } + public OpaqueAlign4Union(Pointer p) { + super(p); + } + } + + class OpaqueAlign4UnionByReference extends OpaqueAlign4Union { + public OpaqueAlign4UnionByReference() { + super(null); + } + public OpaqueAlign4UnionByReference(Pointer p) { + super(p); + } + } + + class OpaqueAlign8Struct extends PointerType { + public OpaqueAlign8Struct() { + super(null); + } + public OpaqueAlign8Struct(Pointer p) { + super(p); + } + } + + class OpaqueAlign8StructByReference extends OpaqueAlign8Struct { + public OpaqueAlign8StructByReference() { + super(null); + } + public OpaqueAlign8StructByReference(Pointer p) { + super(p); + } + } + + + @Structure.FieldOrder({"arg1", "arg2"}) + class PackedStruct extends Structure implements Structure.ByValue { + public PackedStruct() { + super(); + } + + public PackedStruct(Pointer p) { + super(p); + } + + public NativeLong arg1; + public ByteByReference arg2; + + } + + @Structure.FieldOrder({"arg1", "arg2"}) + class PackedStructByReference extends Structure implements Structure.ByReference { + public PackedStructByReference() { + super(); + } + + public PackedStructByReference(Pointer p) { + super(p); + } + + public NativeLong arg1; + public ByteByReference arg2; + + } + + + + @Structure.FieldOrder({"variant1", "variant2"}) + class PackedUnion extends Union implements Structure.ByValue { + public PackedUnion() { + super(); + } + + public PackedUnion(Pointer p) { + super(p); + } + + public NativeLong variant1; + public ByteByReference variant2; + + } + + @Structure.FieldOrder({"variant1", "variant2"}) + class PackedUnionByReference extends Union implements Structure.ByReference { + public PackedUnionByReference() { + super(); + } + + public PackedUnionByReference(Pointer p) { + super(p); + } + + public NativeLong variant1; + public ByteByReference variant2; + + } + + +} \ No newline at end of file diff --git a/tests/expectations/layout_packed_opaque.java b/tests/expectations/layout_packed_opaque.java new file mode 100644 index 000000000..dd70b9a84 --- /dev/null +++ b/tests/expectations/layout_packed_opaque.java @@ -0,0 +1,305 @@ + +import com.sun.jna.*; +import com.sun.jna.ptr.*; + +enum BindingsSingleton { + INSTANCE; + final Bindings lib = Native.load("", Bindings.class); +} + +interface Bindings extends Library { + Bindings INSTANCE = BindingsSingleton.INSTANCE.lib; + + class OpaquePackedStruct extends PointerType { + public OpaquePackedStruct() { + super(null); + } + public OpaquePackedStruct(Pointer p) { + super(p); + } + } + + class OpaquePackedStructByReference extends OpaquePackedStruct { + public OpaquePackedStructByReference() { + super(null); + } + public OpaquePackedStructByReference(Pointer p) { + super(p); + } + } + + class OpaquePackedUnion extends PointerType { + public OpaquePackedUnion() { + super(null); + } + public OpaquePackedUnion(Pointer p) { + super(p); + } + } + + class OpaquePackedUnionByReference extends OpaquePackedUnion { + public OpaquePackedUnionByReference() { + super(null); + } + public OpaquePackedUnionByReference(Pointer p) { + super(p); + } + } + + + @Structure.FieldOrder({"variant1", "variant2"}) + class Align1Union extends Union implements Structure.ByValue { + public Align1Union() { + super(); + } + + public Align1Union(Pointer p) { + super(p); + } + + public NativeLong variant1; + public ByteByReference variant2; + + } + + @Structure.FieldOrder({"variant1", "variant2"}) + class Align1UnionByReference extends Union implements Structure.ByReference { + public Align1UnionByReference() { + super(); + } + + public Align1UnionByReference(Pointer p) { + super(p); + } + + public NativeLong variant1; + public ByteByReference variant2; + + } + + + + @Structure.FieldOrder({"variant1", "variant2"}) + class Align4Union extends Union implements Structure.ByValue { + public Align4Union() { + super(); + } + + public Align4Union(Pointer p) { + super(p); + } + + public NativeLong variant1; + public ByteByReference variant2; + + } + + @Structure.FieldOrder({"variant1", "variant2"}) + class Align4UnionByReference extends Union implements Structure.ByReference { + public Align4UnionByReference() { + super(); + } + + public Align4UnionByReference(Pointer p) { + super(p); + } + + public NativeLong variant1; + public ByteByReference variant2; + + } + + + + @Structure.FieldOrder({"variant1", "variant2"}) + class Align16Union extends Union implements Structure.ByValue { + public Align16Union() { + super(); + } + + public Align16Union(Pointer p) { + super(p); + } + + public NativeLong variant1; + public ByteByReference variant2; + + } + + @Structure.FieldOrder({"variant1", "variant2"}) + class Align16UnionByReference extends Union implements Structure.ByReference { + public Align16UnionByReference() { + super(); + } + + public Align16UnionByReference(Pointer p) { + super(p); + } + + public NativeLong variant1; + public ByteByReference variant2; + + } + + + + @Structure.FieldOrder({"arg1", "arg2"}) + class Align1Struct extends Structure implements Structure.ByValue { + public Align1Struct() { + super(); + } + + public Align1Struct(Pointer p) { + super(p); + } + + public NativeLong arg1; + public ByteByReference arg2; + + } + + @Structure.FieldOrder({"arg1", "arg2"}) + class Align1StructByReference extends Structure implements Structure.ByReference { + public Align1StructByReference() { + super(); + } + + public Align1StructByReference(Pointer p) { + super(p); + } + + public NativeLong arg1; + public ByteByReference arg2; + + } + + + + @Structure.FieldOrder({"arg1", "arg2"}) + class Align2Struct extends Structure implements Structure.ByValue { + public Align2Struct() { + super(); + } + + public Align2Struct(Pointer p) { + super(p); + } + + public NativeLong arg1; + public ByteByReference arg2; + + } + + @Structure.FieldOrder({"arg1", "arg2"}) + class Align2StructByReference extends Structure implements Structure.ByReference { + public Align2StructByReference() { + super(); + } + + public Align2StructByReference(Pointer p) { + super(p); + } + + public NativeLong arg1; + public ByteByReference arg2; + + } + + + + @Structure.FieldOrder({"arg1", "arg2"}) + class Align4Struct extends Structure implements Structure.ByValue { + public Align4Struct() { + super(); + } + + public Align4Struct(Pointer p) { + super(p); + } + + public NativeLong arg1; + public ByteByReference arg2; + + } + + @Structure.FieldOrder({"arg1", "arg2"}) + class Align4StructByReference extends Structure implements Structure.ByReference { + public Align4StructByReference() { + super(); + } + + public Align4StructByReference(Pointer p) { + super(p); + } + + public NativeLong arg1; + public ByteByReference arg2; + + } + + + + @Structure.FieldOrder({"arg1", "arg2"}) + class Align8Struct extends Structure implements Structure.ByValue { + public Align8Struct() { + super(); + } + + public Align8Struct(Pointer p) { + super(p); + } + + public NativeLong arg1; + public ByteByReference arg2; + + } + + @Structure.FieldOrder({"arg1", "arg2"}) + class Align8StructByReference extends Structure implements Structure.ByReference { + public Align8StructByReference() { + super(); + } + + public Align8StructByReference(Pointer p) { + super(p); + } + + public NativeLong arg1; + public ByteByReference arg2; + + } + + + + @Structure.FieldOrder({"arg1", "arg2"}) + class Align32Struct extends Structure implements Structure.ByValue { + public Align32Struct() { + super(); + } + + public Align32Struct(Pointer p) { + super(p); + } + + public NativeLong arg1; + public ByteByReference arg2; + + } + + @Structure.FieldOrder({"arg1", "arg2"}) + class Align32StructByReference extends Structure implements Structure.ByReference { + public Align32StructByReference() { + super(); + } + + public Align32StructByReference(Pointer p) { + super(p); + } + + public NativeLong arg1; + public ByteByReference arg2; + + } + + +} \ No newline at end of file diff --git a/tests/expectations/lifetime_arg.java b/tests/expectations/lifetime_arg.java new file mode 100644 index 000000000..98b4b7de0 --- /dev/null +++ b/tests/expectations/lifetime_arg.java @@ -0,0 +1,81 @@ +import com.sun.jna.*; +import com.sun.jna.ptr.*; + +enum BindingsSingleton { + INSTANCE; + final Bindings lib = Native.load("", Bindings.class); +} + +interface Bindings extends Library { + Bindings INSTANCE = BindingsSingleton.INSTANCE.lib; + + + @Structure.FieldOrder({"data"}) + class A extends Structure implements Structure.ByValue { + public A() { + super(); + } + + public A(Pointer p) { + super(p); + } + + public IntByReference data; + + } + + @Structure.FieldOrder({"data"}) + class AByReference extends Structure implements Structure.ByReference { + public AByReference() { + super(); + } + + public AByReference(Pointer p) { + super(p); + } + + public IntByReference data; + + } + + + class E extends IntegerType { + public E() { + super(4); + } + + public E(long value) { + super(4, value); + } + + public E(Pointer p) { + this(p.getInt(0)); + } + public static final E V = new E(1); + public static final E U = new E(2); + + } + + class EByReference extends ByReference { + public EByReference() { + super(4); + } + + public EByReference(Pointer p) { + super(4); + setPointer(p); + } + + public E getValue() { + return new E(getPointer().getInt(0)); + } + + public void setValue(E value) { + getPointer().setInt(0, value.intValue()); + } + + } + + void root(A _a, E _e); + +} \ No newline at end of file diff --git a/tests/expectations/linestyle_cr.java b/tests/expectations/linestyle_cr.java new file mode 100644 index 000000000..dca4a566b --- /dev/null +++ b/tests/expectations/linestyle_cr.java @@ -0,0 +1 @@ +import com.sun.jna.*; import com.sun.jna.ptr.*; enum BindingsSingleton { INSTANCE; final Bindings lib = Native.load("", Bindings.class); } interface Bindings extends Library { Bindings INSTANCE = BindingsSingleton.INSTANCE.lib; @Structure.FieldOrder({"x", "y"}) class Dummy extends Structure implements Structure.ByValue { public Dummy() { super(); } public Dummy(Pointer p) { super(p); } public int x; public float y; } @Structure.FieldOrder({"x", "y"}) class DummyByReference extends Structure implements Structure.ByReference { public DummyByReference() { super(); } public DummyByReference(Pointer p) { super(p); } public int x; public float y; } void root(Dummy d); } \ No newline at end of file diff --git a/tests/expectations/linestyle_crlf.java b/tests/expectations/linestyle_crlf.java new file mode 100644 index 000000000..1840c5d55 --- /dev/null +++ b/tests/expectations/linestyle_crlf.java @@ -0,0 +1,46 @@ +import com.sun.jna.*; +import com.sun.jna.ptr.*; + +enum BindingsSingleton { + INSTANCE; + final Bindings lib = Native.load("", Bindings.class); +} + +interface Bindings extends Library { + Bindings INSTANCE = BindingsSingleton.INSTANCE.lib; + + + @Structure.FieldOrder({"x", "y"}) + class Dummy extends Structure implements Structure.ByValue { + public Dummy() { + super(); + } + + public Dummy(Pointer p) { + super(p); + } + + public int x; + public float y; + + } + + @Structure.FieldOrder({"x", "y"}) + class DummyByReference extends Structure implements Structure.ByReference { + public DummyByReference() { + super(); + } + + public DummyByReference(Pointer p) { + super(p); + } + + public int x; + public float y; + + } + + + void root(Dummy d); + +} \ No newline at end of file diff --git a/tests/expectations/linestyle_lf.java b/tests/expectations/linestyle_lf.java new file mode 100644 index 000000000..770ac639d --- /dev/null +++ b/tests/expectations/linestyle_lf.java @@ -0,0 +1,46 @@ +import com.sun.jna.*; +import com.sun.jna.ptr.*; + +enum BindingsSingleton { + INSTANCE; + final Bindings lib = Native.load("", Bindings.class); +} + +interface Bindings extends Library { + Bindings INSTANCE = BindingsSingleton.INSTANCE.lib; + + + @Structure.FieldOrder({"x", "y"}) + class Dummy extends Structure implements Structure.ByValue { + public Dummy() { + super(); + } + + public Dummy(Pointer p) { + super(p); + } + + public int x; + public float y; + + } + + @Structure.FieldOrder({"x", "y"}) + class DummyByReference extends Structure implements Structure.ByReference { + public DummyByReference() { + super(); + } + + public DummyByReference(Pointer p) { + super(p); + } + + public int x; + public float y; + + } + + + void root(Dummy d); + +} \ No newline at end of file diff --git a/tests/expectations/literal_target.java b/tests/expectations/literal_target.java new file mode 100644 index 000000000..c569aefa2 --- /dev/null +++ b/tests/expectations/literal_target.java @@ -0,0 +1,12 @@ +import com.sun.jna.*; +import com.sun.jna.ptr.*; + +enum BindingsSingleton { + INSTANCE; + final Bindings lib = Native.load("literal_target", Bindings.class); +} + +interface Bindings extends Library { + Bindings INSTANCE = BindingsSingleton.INSTANCE.lib; + +} \ No newline at end of file diff --git a/tests/expectations/mangle.java b/tests/expectations/mangle.java new file mode 100644 index 000000000..ef786fbc8 --- /dev/null +++ b/tests/expectations/mangle.java @@ -0,0 +1,99 @@ +import com.sun.jna.*; +import com.sun.jna.ptr.*; + +enum BindingsSingleton { + INSTANCE; + final Bindings lib = Native.load("", Bindings.class); +} + +interface Bindings extends Library { + Bindings INSTANCE = BindingsSingleton.INSTANCE.lib; + + class Bar extends IntegerType { + public Bar() { + super(4); + } + + public Bar(long value) { + super(4, value); + } + + public Bar(Pointer p) { + this(p.getInt(0)); + } + public static final Bar BarSome = new Bar(1); + public static final Bar BarThing = new Bar(2); + + } + + class BarByReference extends ByReference { + public BarByReference() { + super(4); + } + + public BarByReference(Pointer p) { + super(4); + setPointer(p); + } + + public Bar getValue() { + return new Bar(getPointer().getInt(0)); + } + + public void setValue(Bar value) { + getPointer().setInt(0, value.intValue()); + } + + } + + + @Structure.FieldOrder({"a"}) + class FooU8 extends Structure implements Structure.ByValue { + public FooU8() { + super(); + } + + public FooU8(Pointer p) { + super(p); + } + + public byte a; + + } + + @Structure.FieldOrder({"a"}) + class FooU8ByReference extends Structure implements Structure.ByReference { + public FooU8ByReference() { + super(); + } + + public FooU8ByReference(Pointer p) { + super(p); + } + + public byte a; + + } + + + class Boo extends FooU8 { + public Boo() { + super(); + } + public Boo(Pointer p) { + super(p); + } + } + + class BooByReference extends FooU8ByReference { + public BooByReference() { + super(); + } + public BooByReference(Pointer p) { + super(p); + } + } + + void root(Boo x, Bar y); + +} \ No newline at end of file diff --git a/tests/expectations/manuallydrop.java b/tests/expectations/manuallydrop.java new file mode 100644 index 000000000..febdccffb --- /dev/null +++ b/tests/expectations/manuallydrop.java @@ -0,0 +1,115 @@ + +import com.sun.jna.*; +import com.sun.jna.ptr.*; + +enum BindingsSingleton { + INSTANCE; + final Bindings lib = Native.load("", Bindings.class); +} + +interface Bindings extends Library { + Bindings INSTANCE = BindingsSingleton.INSTANCE.lib; + + class NotReprC_Point extends PointerType { + public NotReprC_Point() { + super(null); + } + public NotReprC_Point(Pointer p) { + super(p); + } + } + + class NotReprC_PointByReference extends NotReprC_Point { + public NotReprC_PointByReference() { + super(null); + } + public NotReprC_PointByReference(Pointer p) { + super(p); + } + } + + class Foo extends NotReprC_Point { + public Foo() { + super(); + } + public Foo(Pointer p) { + super(p); + } + } + + class FooByReference extends NotReprC_PointByReference { + public FooByReference() { + super(); + } + public FooByReference(Pointer p) { + super(p); + } + } + + + @Structure.FieldOrder({"x", "y"}) + class Point extends Structure implements Structure.ByValue { + public Point() { + super(); + } + + public Point(Pointer p) { + super(p); + } + + public int x; + public int y; + + } + + @Structure.FieldOrder({"x", "y"}) + class PointByReference extends Structure implements Structure.ByReference { + public PointByReference() { + super(); + } + + public PointByReference(Pointer p) { + super(p); + } + + public int x; + public int y; + + } + + + + @Structure.FieldOrder({"point"}) + class MyStruct extends Structure implements Structure.ByValue { + public MyStruct() { + super(); + } + + public MyStruct(Pointer p) { + super(p); + } + + public Point point; + + } + + @Structure.FieldOrder({"point"}) + class MyStructByReference extends Structure implements Structure.ByReference { + public MyStructByReference() { + super(); + } + + public MyStructByReference(Pointer p) { + super(p); + } + + public Point point; + + } + + + void root(FooByReference a, MyStructByReference with_manual_drop); + + void take(Point with_manual_drop); + +} \ No newline at end of file diff --git a/tests/expectations/maybeuninit.java b/tests/expectations/maybeuninit.java new file mode 100644 index 000000000..78bcb4eed --- /dev/null +++ b/tests/expectations/maybeuninit.java @@ -0,0 +1,81 @@ + +import com.sun.jna.*; +import com.sun.jna.ptr.*; + +enum BindingsSingleton { + INSTANCE; + final Bindings lib = Native.load("", Bindings.class); +} + +interface Bindings extends Library { + Bindings INSTANCE = BindingsSingleton.INSTANCE.lib; + + class NotReprC______i32 extends PointerType { + public NotReprC______i32() { + super(null); + } + public NotReprC______i32(Pointer p) { + super(p); + } + } + + class NotReprC______i32ByReference extends NotReprC______i32 { + public NotReprC______i32ByReference() { + super(null); + } + public NotReprC______i32ByReference(Pointer p) { + super(p); + } + } + + class Foo extends NotReprC______i32 { + public Foo() { + super(); + } + public Foo(Pointer p) { + super(p); + } + } + + class FooByReference extends NotReprC______i32ByReference { + public FooByReference() { + super(); + } + public FooByReference(Pointer p) { + super(p); + } + } + + + @Structure.FieldOrder({"number"}) + class MyStruct extends Structure implements Structure.ByValue { + public MyStruct() { + super(); + } + + public MyStruct(Pointer p) { + super(p); + } + + public IntByReference number; + + } + + @Structure.FieldOrder({"number"}) + class MyStructByReference extends Structure implements Structure.ByReference { + public MyStructByReference() { + super(); + } + + public MyStructByReference(Pointer p) { + super(p); + } + + public IntByReference number; + + } + + + void root(FooByReference a, MyStructByReference with_maybe_uninit); + +} \ No newline at end of file diff --git a/tests/expectations/mod_2015.java b/tests/expectations/mod_2015.java new file mode 100644 index 000000000..af4555604 --- /dev/null +++ b/tests/expectations/mod_2015.java @@ -0,0 +1,49 @@ +import com.sun.jna.*; +import com.sun.jna.ptr.*; + +enum BindingsSingleton { + INSTANCE; + final Bindings lib = Native.load("mod_2015", Bindings.class); +} + +interface Bindings extends Library { + Bindings INSTANCE = BindingsSingleton.INSTANCE.lib; + + /* Unsupported literal for constant EXPORT_ME_TOO */ + + + + @Structure.FieldOrder({"val"}) + class ExportMe extends Structure implements Structure.ByValue { + public ExportMe() { + super(); + } + + public ExportMe(Pointer p) { + super(p); + } + + public long val; + + } + + @Structure.FieldOrder({"val"}) + class ExportMeByReference extends Structure implements Structure.ByReference { + public ExportMeByReference() { + super(); + } + + public ExportMeByReference(Pointer p) { + super(p); + } + + public long val; + + } + + + void export_me(ExportMeByReference val); + + void from_really_nested_mod(); + +} \ No newline at end of file diff --git a/tests/expectations/mod_2018.java b/tests/expectations/mod_2018.java new file mode 100644 index 000000000..2c1f10079 --- /dev/null +++ b/tests/expectations/mod_2018.java @@ -0,0 +1,81 @@ +import com.sun.jna.*; +import com.sun.jna.ptr.*; + +enum BindingsSingleton { + INSTANCE; + final Bindings lib = Native.load("mod_2018", Bindings.class); +} + +interface Bindings extends Library { + Bindings INSTANCE = BindingsSingleton.INSTANCE.lib; + + /* Unsupported literal for constant EXPORT_ME_TOO */ + + + + @Structure.FieldOrder({"val"}) + class ExportMe extends Structure implements Structure.ByValue { + public ExportMe() { + super(); + } + + public ExportMe(Pointer p) { + super(p); + } + + public long val; + + } + + @Structure.FieldOrder({"val"}) + class ExportMeByReference extends Structure implements Structure.ByReference { + public ExportMeByReference() { + super(); + } + + public ExportMeByReference(Pointer p) { + super(p); + } + + public long val; + + } + + + + @Structure.FieldOrder({"val"}) + class ExportMe2 extends Structure implements Structure.ByValue { + public ExportMe2() { + super(); + } + + public ExportMe2(Pointer p) { + super(p); + } + + public long val; + + } + + @Structure.FieldOrder({"val"}) + class ExportMe2ByReference extends Structure implements Structure.ByReference { + public ExportMe2ByReference() { + super(); + } + + public ExportMe2ByReference(Pointer p) { + super(p); + } + + public long val; + + } + + + void export_me(ExportMeByReference val); + + void export_me_2(ExportMe2ByReference arg0); + + void from_really_nested_mod(); + +} \ No newline at end of file diff --git a/tests/expectations/mod_attr.java b/tests/expectations/mod_attr.java new file mode 100644 index 000000000..ae9b20519 --- /dev/null +++ b/tests/expectations/mod_attr.java @@ -0,0 +1,79 @@ + +import com.sun.jna.*; +import com.sun.jna.ptr.*; + +enum BindingsSingleton { + INSTANCE; + final Bindings lib = Native.load("mod_attr", Bindings.class); +} + +interface Bindings extends Library { + Bindings INSTANCE = BindingsSingleton.INSTANCE.lib; + + /* begin condition not supported Some(Define("FOO")) */ + /* Unsupported literal for constant FOO */ + + /* end condition not supported Some(Define("FOO")) */ + + /* begin condition not supported Some(Define("BAR")) */ + /* Unsupported literal for constant BAR */ + + /* end condition not supported Some(Define("BAR")) */ + + + class Foo extends Structure implements Structure.ByValue { + public Foo() { + super(); + } + + public Foo(Pointer p) { + super(p); + } + + + } + + class FooByReference extends Structure implements Structure.ByReference { + public FooByReference() { + super(); + } + + public FooByReference(Pointer p) { + super(p); + } + + + } + + + + class Bar extends Structure implements Structure.ByValue { + public Bar() { + super(); + } + + public Bar(Pointer p) { + super(p); + } + + + } + + class BarByReference extends Structure implements Structure.ByReference { + public BarByReference() { + super(); + } + + public BarByReference(Pointer p) { + super(p); + } + + + } + + + void foo(FooByReference foo); + + void bar(BarByReference bar); + +} \ No newline at end of file diff --git a/tests/expectations/mod_path.java b/tests/expectations/mod_path.java new file mode 100644 index 000000000..32e836624 --- /dev/null +++ b/tests/expectations/mod_path.java @@ -0,0 +1,47 @@ +import com.sun.jna.*; +import com.sun.jna.ptr.*; + +enum BindingsSingleton { + INSTANCE; + final Bindings lib = Native.load("mod_path", Bindings.class); +} + +interface Bindings extends Library { + Bindings INSTANCE = BindingsSingleton.INSTANCE.lib; + + /* Unsupported literal for constant EXPORT_ME_TOO */ + + + + @Structure.FieldOrder({"val"}) + class ExportMe extends Structure implements Structure.ByValue { + public ExportMe() { + super(); + } + + public ExportMe(Pointer p) { + super(p); + } + + public long val; + + } + + @Structure.FieldOrder({"val"}) + class ExportMeByReference extends Structure implements Structure.ByReference { + public ExportMeByReference() { + super(); + } + + public ExportMeByReference(Pointer p) { + super(p); + } + + public long val; + + } + + + void export_me(ExportMeByReference val); + +} \ No newline at end of file diff --git a/tests/expectations/monomorph_1.java b/tests/expectations/monomorph_1.java new file mode 100644 index 000000000..aeedfd526 --- /dev/null +++ b/tests/expectations/monomorph_1.java @@ -0,0 +1,247 @@ +import com.sun.jna.*; +import com.sun.jna.ptr.*; + +enum BindingsSingleton { + INSTANCE; + final Bindings lib = Native.load("", Bindings.class); +} + +interface Bindings extends Library { + Bindings INSTANCE = BindingsSingleton.INSTANCE.lib; + + class Bar_Bar_f32 extends PointerType { + public Bar_Bar_f32() { + super(null); + } + public Bar_Bar_f32(Pointer p) { + super(p); + } + } + + class Bar_Bar_f32ByReference extends Bar_Bar_f32 { + public Bar_Bar_f32ByReference() { + super(null); + } + public Bar_Bar_f32ByReference(Pointer p) { + super(p); + } + } + + class Bar_Foo_f32 extends PointerType { + public Bar_Foo_f32() { + super(null); + } + public Bar_Foo_f32(Pointer p) { + super(p); + } + } + + class Bar_Foo_f32ByReference extends Bar_Foo_f32 { + public Bar_Foo_f32ByReference() { + super(null); + } + public Bar_Foo_f32ByReference(Pointer p) { + super(p); + } + } + + class Bar_f32 extends PointerType { + public Bar_f32() { + super(null); + } + public Bar_f32(Pointer p) { + super(p); + } + } + + class Bar_f32ByReference extends Bar_f32 { + public Bar_f32ByReference() { + super(null); + } + public Bar_f32ByReference(Pointer p) { + super(p); + } + } + + + @Structure.FieldOrder({"data"}) + class Foo_i32 extends Structure implements Structure.ByValue { + public Foo_i32() { + super(); + } + + public Foo_i32(Pointer p) { + super(p); + } + + public IntByReference data; + + } + + @Structure.FieldOrder({"data"}) + class Foo_i32ByReference extends Structure implements Structure.ByReference { + public Foo_i32ByReference() { + super(); + } + + public Foo_i32ByReference(Pointer p) { + super(p); + } + + public IntByReference data; + + } + + + + @Structure.FieldOrder({"data"}) + class Foo_f32 extends Structure implements Structure.ByValue { + public Foo_f32() { + super(); + } + + public Foo_f32(Pointer p) { + super(p); + } + + public FloatByReference data; + + } + + @Structure.FieldOrder({"data"}) + class Foo_f32ByReference extends Structure implements Structure.ByReference { + public Foo_f32ByReference() { + super(); + } + + public Foo_f32ByReference(Pointer p) { + super(p); + } + + public FloatByReference data; + + } + + + + @Structure.FieldOrder({"data"}) + class Foo_Bar_f32 extends Structure implements Structure.ByValue { + public Foo_Bar_f32() { + super(); + } + + public Foo_Bar_f32(Pointer p) { + super(p); + } + + public Bar_f32ByReference data; + + } + + @Structure.FieldOrder({"data"}) + class Foo_Bar_f32ByReference extends Structure implements Structure.ByReference { + public Foo_Bar_f32ByReference() { + super(); + } + + public Foo_Bar_f32ByReference(Pointer p) { + super(p); + } + + public Bar_f32ByReference data; + + } + + + + @Structure.FieldOrder({"a", "b"}) + class Tuple_Foo_f32_____f32 extends Structure implements Structure.ByValue { + public Tuple_Foo_f32_____f32() { + super(); + } + + public Tuple_Foo_f32_____f32(Pointer p) { + super(p); + } + + public Foo_f32ByReference a; + public FloatByReference b; + + } + + @Structure.FieldOrder({"a", "b"}) + class Tuple_Foo_f32_____f32ByReference extends Structure implements Structure.ByReference { + public Tuple_Foo_f32_____f32ByReference() { + super(); + } + + public Tuple_Foo_f32_____f32ByReference(Pointer p) { + super(p); + } + + public Foo_f32ByReference a; + public FloatByReference b; + + } + + + + @Structure.FieldOrder({"a", "b"}) + class Tuple_f32__f32 extends Structure implements Structure.ByValue { + public Tuple_f32__f32() { + super(); + } + + public Tuple_f32__f32(Pointer p) { + super(p); + } + + public FloatByReference a; + public FloatByReference b; + + } + + @Structure.FieldOrder({"a", "b"}) + class Tuple_f32__f32ByReference extends Structure implements Structure.ByReference { + public Tuple_f32__f32ByReference() { + super(); + } + + public Tuple_f32__f32ByReference(Pointer p) { + super(p); + } + + public FloatByReference a; + public FloatByReference b; + + } + + + class Indirection_f32 extends Tuple_f32__f32 { + public Indirection_f32() { + super(); + } + public Indirection_f32(Pointer p) { + super(p); + } + } + + class Indirection_f32ByReference extends Tuple_f32__f32ByReference { + public Indirection_f32ByReference() { + super(); + } + public Indirection_f32ByReference(Pointer p) { + super(p); + } + } + + void root(Foo_i32 a, + Foo_f32 b, + Bar_f32 c, + Foo_Bar_f32 d, + Bar_Foo_f32 e, + Bar_Bar_f32 f, + Tuple_Foo_f32_____f32 g, + Indirection_f32 h); + +} \ No newline at end of file diff --git a/tests/expectations/monomorph_2.java b/tests/expectations/monomorph_2.java new file mode 100644 index 000000000..16c567502 --- /dev/null +++ b/tests/expectations/monomorph_2.java @@ -0,0 +1,116 @@ +import com.sun.jna.*; +import com.sun.jna.ptr.*; + +enum BindingsSingleton { + INSTANCE; + final Bindings lib = Native.load("", Bindings.class); +} + +interface Bindings extends Library { + Bindings INSTANCE = BindingsSingleton.INSTANCE.lib; + + class A extends PointerType { + public A() { + super(null); + } + public A(Pointer p) { + super(p); + } + } + + class AByReference extends A { + public AByReference() { + super(null); + } + public AByReference(Pointer p) { + super(p); + } + } + + class B extends PointerType { + public B() { + super(null); + } + public B(Pointer p) { + super(p); + } + } + + class BByReference extends B { + public BByReference() { + super(null); + } + public BByReference(Pointer p) { + super(p); + } + } + + + @Structure.FieldOrder({"members", "count"}) + class List_A extends Structure implements Structure.ByValue { + public List_A() { + super(); + } + + public List_A(Pointer p) { + super(p); + } + + public AByReference members; + public NativeLong count; + + } + + @Structure.FieldOrder({"members", "count"}) + class List_AByReference extends Structure implements Structure.ByReference { + public List_AByReference() { + super(); + } + + public List_AByReference(Pointer p) { + super(p); + } + + public AByReference members; + public NativeLong count; + + } + + + + @Structure.FieldOrder({"members", "count"}) + class List_B extends Structure implements Structure.ByValue { + public List_B() { + super(); + } + + public List_B(Pointer p) { + super(p); + } + + public BByReference members; + public NativeLong count; + + } + + @Structure.FieldOrder({"members", "count"}) + class List_BByReference extends Structure implements Structure.ByReference { + public List_BByReference() { + super(); + } + + public List_BByReference(Pointer p) { + super(p); + } + + public BByReference members; + public NativeLong count; + + } + + + void foo(List_A a); + + void bar(List_B b); + +} \ No newline at end of file diff --git a/tests/expectations/monomorph_3.java b/tests/expectations/monomorph_3.java new file mode 100644 index 000000000..f2d2cf7dd --- /dev/null +++ b/tests/expectations/monomorph_3.java @@ -0,0 +1,247 @@ +import com.sun.jna.*; +import com.sun.jna.ptr.*; + +enum BindingsSingleton { + INSTANCE; + final Bindings lib = Native.load("", Bindings.class); +} + +interface Bindings extends Library { + Bindings INSTANCE = BindingsSingleton.INSTANCE.lib; + + class Bar_Bar_f32 extends PointerType { + public Bar_Bar_f32() { + super(null); + } + public Bar_Bar_f32(Pointer p) { + super(p); + } + } + + class Bar_Bar_f32ByReference extends Bar_Bar_f32 { + public Bar_Bar_f32ByReference() { + super(null); + } + public Bar_Bar_f32ByReference(Pointer p) { + super(p); + } + } + + class Bar_Foo_f32 extends PointerType { + public Bar_Foo_f32() { + super(null); + } + public Bar_Foo_f32(Pointer p) { + super(p); + } + } + + class Bar_Foo_f32ByReference extends Bar_Foo_f32 { + public Bar_Foo_f32ByReference() { + super(null); + } + public Bar_Foo_f32ByReference(Pointer p) { + super(p); + } + } + + class Bar_f32 extends PointerType { + public Bar_f32() { + super(null); + } + public Bar_f32(Pointer p) { + super(p); + } + } + + class Bar_f32ByReference extends Bar_f32 { + public Bar_f32ByReference() { + super(null); + } + public Bar_f32ByReference(Pointer p) { + super(p); + } + } + + + @Structure.FieldOrder({"data"}) + class Foo_i32 extends Union implements Structure.ByValue { + public Foo_i32() { + super(); + } + + public Foo_i32(Pointer p) { + super(p); + } + + public IntByReference data; + + } + + @Structure.FieldOrder({"data"}) + class Foo_i32ByReference extends Union implements Structure.ByReference { + public Foo_i32ByReference() { + super(); + } + + public Foo_i32ByReference(Pointer p) { + super(p); + } + + public IntByReference data; + + } + + + + @Structure.FieldOrder({"data"}) + class Foo_f32 extends Union implements Structure.ByValue { + public Foo_f32() { + super(); + } + + public Foo_f32(Pointer p) { + super(p); + } + + public FloatByReference data; + + } + + @Structure.FieldOrder({"data"}) + class Foo_f32ByReference extends Union implements Structure.ByReference { + public Foo_f32ByReference() { + super(); + } + + public Foo_f32ByReference(Pointer p) { + super(p); + } + + public FloatByReference data; + + } + + + + @Structure.FieldOrder({"data"}) + class Foo_Bar_f32 extends Union implements Structure.ByValue { + public Foo_Bar_f32() { + super(); + } + + public Foo_Bar_f32(Pointer p) { + super(p); + } + + public Bar_f32ByReference data; + + } + + @Structure.FieldOrder({"data"}) + class Foo_Bar_f32ByReference extends Union implements Structure.ByReference { + public Foo_Bar_f32ByReference() { + super(); + } + + public Foo_Bar_f32ByReference(Pointer p) { + super(p); + } + + public Bar_f32ByReference data; + + } + + + + @Structure.FieldOrder({"a", "b"}) + class Tuple_Foo_f32_____f32 extends Union implements Structure.ByValue { + public Tuple_Foo_f32_____f32() { + super(); + } + + public Tuple_Foo_f32_____f32(Pointer p) { + super(p); + } + + public Foo_f32ByReference a; + public FloatByReference b; + + } + + @Structure.FieldOrder({"a", "b"}) + class Tuple_Foo_f32_____f32ByReference extends Union implements Structure.ByReference { + public Tuple_Foo_f32_____f32ByReference() { + super(); + } + + public Tuple_Foo_f32_____f32ByReference(Pointer p) { + super(p); + } + + public Foo_f32ByReference a; + public FloatByReference b; + + } + + + + @Structure.FieldOrder({"a", "b"}) + class Tuple_f32__f32 extends Union implements Structure.ByValue { + public Tuple_f32__f32() { + super(); + } + + public Tuple_f32__f32(Pointer p) { + super(p); + } + + public FloatByReference a; + public FloatByReference b; + + } + + @Structure.FieldOrder({"a", "b"}) + class Tuple_f32__f32ByReference extends Union implements Structure.ByReference { + public Tuple_f32__f32ByReference() { + super(); + } + + public Tuple_f32__f32ByReference(Pointer p) { + super(p); + } + + public FloatByReference a; + public FloatByReference b; + + } + + + class Indirection_f32 extends Tuple_f32__f32 { + public Indirection_f32() { + super(); + } + public Indirection_f32(Pointer p) { + super(p); + } + } + + class Indirection_f32ByReference extends Tuple_f32__f32ByReference { + public Indirection_f32ByReference() { + super(); + } + public Indirection_f32ByReference(Pointer p) { + super(p); + } + } + + void root(Foo_i32 a, + Foo_f32 b, + Bar_f32 c, + Foo_Bar_f32 d, + Bar_Foo_f32 e, + Bar_Bar_f32 f, + Tuple_Foo_f32_____f32 g, + Indirection_f32 h); + +} \ No newline at end of file diff --git a/tests/expectations/must_use.java b/tests/expectations/must_use.java new file mode 100644 index 000000000..1e1942d2d --- /dev/null +++ b/tests/expectations/must_use.java @@ -0,0 +1,82 @@ + +import com.sun.jna.*; +import com.sun.jna.ptr.*; + +enum BindingsSingleton { + INSTANCE; + final Bindings lib = Native.load("", Bindings.class); +} + +interface Bindings extends Library { + Bindings INSTANCE = BindingsSingleton.INSTANCE.lib; + + class MaybeOwnedPtr_i32 extends IntegerType { + public MaybeOwnedPtr_i32() { + super(4); + } + + public MaybeOwnedPtr_i32(long value) { + super(4, value); + } + + public MaybeOwnedPtr_i32(Pointer p) { + this(p.getInt(0)); + } + public static final MaybeOwnedPtr_i32 Owned_i32 = new MaybeOwnedPtr_i32(1); + public static final MaybeOwnedPtr_i32 None_i32 = new MaybeOwnedPtr_i32(2); + + } + + class MaybeOwnedPtr_i32ByReference extends ByReference { + public MaybeOwnedPtr_i32ByReference() { + super(4); + } + + public MaybeOwnedPtr_i32ByReference(Pointer p) { + super(4); + setPointer(p); + } + + public MaybeOwnedPtr_i32 getValue() { + return new MaybeOwnedPtr_i32(getPointer().getInt(0)); + } + + public void setValue(MaybeOwnedPtr_i32 value) { + getPointer().setInt(0, value.intValue()); + } + + } + + + @Structure.FieldOrder({"ptr"}) + class OwnedPtr_i32 extends Structure implements Structure.ByValue { + public OwnedPtr_i32() { + super(); + } + + public OwnedPtr_i32(Pointer p) { + super(p); + } + + public IntByReference ptr; + + } + + @Structure.FieldOrder({"ptr"}) + class OwnedPtr_i32ByReference extends Structure implements Structure.ByReference { + public OwnedPtr_i32ByReference() { + super(); + } + + public OwnedPtr_i32ByReference(Pointer p) { + super(p); + } + + public IntByReference ptr; + + } + + + MaybeOwnedPtr_i32 maybe_consume(OwnedPtr_i32 input); + +} \ No newline at end of file diff --git a/tests/expectations/namespace_constant.java b/tests/expectations/namespace_constant.java new file mode 100644 index 000000000..665040605 --- /dev/null +++ b/tests/expectations/namespace_constant.java @@ -0,0 +1,50 @@ +import com.sun.jna.*; +import com.sun.jna.ptr.*; + +enum BindingsSingleton { + INSTANCE; + final Bindings lib = Native.load("", Bindings.class); +} + +interface Bindings extends Library { + Bindings INSTANCE = BindingsSingleton.INSTANCE.lib; + + /* Unsupported literal for constant FOO */ + + + public static final float ZOM = 3.14f; + + + + @Structure.FieldOrder({"x"}) + class Foo extends Structure implements Structure.ByValue { + public Foo() { + super(); + } + + public Foo(Pointer p) { + super(p); + } + + public int[] x; + + } + + @Structure.FieldOrder({"x"}) + class FooByReference extends Structure implements Structure.ByReference { + public FooByReference() { + super(); + } + + public FooByReference(Pointer p) { + super(p); + } + + public int[] x; + + } + + + void root(Foo x); + +} \ No newline at end of file diff --git a/tests/expectations/namespaces_constant.java b/tests/expectations/namespaces_constant.java new file mode 100644 index 000000000..665040605 --- /dev/null +++ b/tests/expectations/namespaces_constant.java @@ -0,0 +1,50 @@ +import com.sun.jna.*; +import com.sun.jna.ptr.*; + +enum BindingsSingleton { + INSTANCE; + final Bindings lib = Native.load("", Bindings.class); +} + +interface Bindings extends Library { + Bindings INSTANCE = BindingsSingleton.INSTANCE.lib; + + /* Unsupported literal for constant FOO */ + + + public static final float ZOM = 3.14f; + + + + @Structure.FieldOrder({"x"}) + class Foo extends Structure implements Structure.ByValue { + public Foo() { + super(); + } + + public Foo(Pointer p) { + super(p); + } + + public int[] x; + + } + + @Structure.FieldOrder({"x"}) + class FooByReference extends Structure implements Structure.ByReference { + public FooByReference() { + super(); + } + + public FooByReference(Pointer p) { + super(p); + } + + public int[] x; + + } + + + void root(Foo x); + +} \ No newline at end of file diff --git a/tests/expectations/nested_import.java b/tests/expectations/nested_import.java new file mode 100644 index 000000000..90cf1e1b0 --- /dev/null +++ b/tests/expectations/nested_import.java @@ -0,0 +1,12 @@ +import com.sun.jna.*; +import com.sun.jna.ptr.*; + +enum BindingsSingleton { + INSTANCE; + final Bindings lib = Native.load("", Bindings.class); +} + +interface Bindings extends Library { + Bindings INSTANCE = BindingsSingleton.INSTANCE.lib; + +} \ No newline at end of file diff --git a/tests/expectations/no_includes.java b/tests/expectations/no_includes.java new file mode 100644 index 000000000..519182a41 --- /dev/null +++ b/tests/expectations/no_includes.java @@ -0,0 +1,14 @@ +import com.sun.jna.*; +import com.sun.jna.ptr.*; + +enum BindingsSingleton { + INSTANCE; + final Bindings lib = Native.load("", Bindings.class); +} + +interface Bindings extends Library { + Bindings INSTANCE = BindingsSingleton.INSTANCE.lib; + + void root(); + +} \ No newline at end of file diff --git a/tests/expectations/non_pub_extern.java b/tests/expectations/non_pub_extern.java new file mode 100644 index 000000000..0e104c4d0 --- /dev/null +++ b/tests/expectations/non_pub_extern.java @@ -0,0 +1,20 @@ +import com.sun.jna.*; +import com.sun.jna.ptr.*; + +enum BindingsSingleton { + INSTANCE; + final Bindings lib = Native.load("", Bindings.class); +} + +interface Bindings extends Library { + Bindings INSTANCE = BindingsSingleton.INSTANCE.lib; + + /* Not implemented yet : Static { path: Path { name: "FIRST" }, export_name: "FIRST", ty: Primitive(Integer { zeroable: true, signed: false, kind: B32 }), mutable: false, cfg: None, annotations: AnnotationSet { annotations: {}, must_use: false, deprecated: None }, documentation: Documentation { doc_comment: [] } } */ + + /* Not implemented yet : Static { path: Path { name: "RENAMED" }, export_name: "RENAMED", ty: Primitive(Integer { zeroable: true, signed: false, kind: B32 }), mutable: false, cfg: None, annotations: AnnotationSet { annotations: {}, must_use: false, deprecated: None }, documentation: Documentation { doc_comment: [] } } */ + + void first(); + + void renamed(); + +} \ No newline at end of file diff --git a/tests/expectations/nonnull.java b/tests/expectations/nonnull.java new file mode 100644 index 000000000..1f8f01842 --- /dev/null +++ b/tests/expectations/nonnull.java @@ -0,0 +1,78 @@ +import com.sun.jna.*; +import com.sun.jna.ptr.*; + +enum BindingsSingleton { + INSTANCE; + final Bindings lib = Native.load("", Bindings.class); +} + +interface Bindings extends Library { + Bindings INSTANCE = BindingsSingleton.INSTANCE.lib; + + class Opaque extends PointerType { + public Opaque() { + super(null); + } + public Opaque(Pointer p) { + super(p); + } + } + + class OpaqueByReference extends Opaque { + public OpaqueByReference() { + super(null); + } + public OpaqueByReference(Pointer p) { + super(p); + } + } + + + @Structure.FieldOrder({"a", "b", "c", "d", "e", "f", "g", "h", "i"}) + class Foo_u64 extends Structure implements Structure.ByValue { + public Foo_u64() { + super(); + } + + public Foo_u64(Pointer p) { + super(p); + } + + public FloatByReference a; + public LongByReference b; + public OpaqueByReference c; + public PointerByReference d; + public PointerByReference e; + public PointerByReference f; + public LongByReference g; + public IntByReference h; + public PointerByReference i; + + } + + @Structure.FieldOrder({"a", "b", "c", "d", "e", "f", "g", "h", "i"}) + class Foo_u64ByReference extends Structure implements Structure.ByReference { + public Foo_u64ByReference() { + super(); + } + + public Foo_u64ByReference(Pointer p) { + super(p); + } + + public FloatByReference a; + public LongByReference b; + public OpaqueByReference c; + public PointerByReference d; + public PointerByReference e; + public PointerByReference f; + public LongByReference g; + public IntByReference h; + public PointerByReference i; + + } + + + void root(IntByReference arg, Foo_u64ByReference foo, PointerByReference d); + +} \ No newline at end of file diff --git a/tests/expectations/nonnull_attribute.java b/tests/expectations/nonnull_attribute.java new file mode 100644 index 000000000..b9b758fd6 --- /dev/null +++ b/tests/expectations/nonnull_attribute.java @@ -0,0 +1,133 @@ + +import com.sun.jna.*; +import com.sun.jna.ptr.*; + +enum BindingsSingleton { + INSTANCE; + final Bindings lib = Native.load("", Bindings.class); +} + +interface Bindings extends Library { + Bindings INSTANCE = BindingsSingleton.INSTANCE.lib; + + class Opaque extends PointerType { + public Opaque() { + super(null); + } + public Opaque(Pointer p) { + super(p); + } + } + + class OpaqueByReference extends Opaque { + public OpaqueByReference() { + super(null); + } + public OpaqueByReference(Pointer p) { + super(p); + } + } + + + @Structure.FieldOrder({"a", "b", "c", "d"}) + class References extends Structure implements Structure.ByValue { + public References() { + super(); + } + + public References(Pointer p) { + super(p); + } + + public OpaqueByReference a; + public OpaqueByReference b; + public OpaqueByReference c; + public OpaqueByReference d; + + } + + @Structure.FieldOrder({"a", "b", "c", "d"}) + class ReferencesByReference extends Structure implements Structure.ByReference { + public ReferencesByReference() { + super(); + } + + public ReferencesByReference(Pointer p) { + super(p); + } + + public OpaqueByReference a; + public OpaqueByReference b; + public OpaqueByReference c; + public OpaqueByReference d; + + } + + + + @Structure.FieldOrder({"a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k"}) + class Pointers_u64 extends Structure implements Structure.ByValue { + public Pointers_u64() { + super(); + } + + public Pointers_u64(Pointer p) { + super(p); + } + + public FloatByReference a; + public LongByReference b; + public OpaqueByReference c; + public PointerByReference d; + public PointerByReference e; + public PointerByReference f; + public LongByReference g; + public IntByReference h; + public PointerByReference i; + public LongByReference j; + public LongByReference k; + + } + + @Structure.FieldOrder({"a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k"}) + class Pointers_u64ByReference extends Structure implements Structure.ByReference { + public Pointers_u64ByReference() { + super(); + } + + public Pointers_u64ByReference(Pointer p) { + super(p); + } + + public FloatByReference a; + public LongByReference b; + public OpaqueByReference c; + public PointerByReference d; + public PointerByReference e; + public PointerByReference f; + public LongByReference g; + public IntByReference h; + public PointerByReference i; + public LongByReference j; + public LongByReference k; + + } + + + void value_arg(References arg); + + void mutltiple_args(IntByReference arg, Pointers_u64ByReference foo, PointerByReference d); + + void ref_arg(Pointers_u64ByReference arg); + + void mut_ref_arg(Pointers_u64ByReference arg); + + void optional_ref_arg(Pointers_u64ByReference arg); + + void optional_mut_ref_arg(Pointers_u64ByReference arg); + + void nullable_const_ptr(Pointers_u64ByReference arg); + + void nullable_mut_ptr(Pointers_u64ByReference arg); + +} \ No newline at end of file diff --git a/tests/expectations/nonzero.java b/tests/expectations/nonzero.java new file mode 100644 index 000000000..271ab3e33 --- /dev/null +++ b/tests/expectations/nonzero.java @@ -0,0 +1,91 @@ + +import com.sun.jna.*; +import com.sun.jna.ptr.*; + +enum BindingsSingleton { + INSTANCE; + final Bindings lib = Native.load("", Bindings.class); +} + +interface Bindings extends Library { + Bindings INSTANCE = BindingsSingleton.INSTANCE.lib; + + class Option_i64 extends PointerType { + public Option_i64() { + super(null); + } + public Option_i64(Pointer p) { + super(p); + } + } + + class Option_i64ByReference extends Option_i64 { + public Option_i64ByReference() { + super(null); + } + public Option_i64ByReference(Pointer p) { + super(p); + } + } + + + @Structure.FieldOrder({"a", "b", "c", "d", "e", "f", "g", "h", "i", "j"}) + class NonZeroTest extends Structure implements Structure.ByValue { + public NonZeroTest() { + super(); + } + + public NonZeroTest(Pointer p) { + super(p); + } + + public byte a; + public short b; + public int c; + public long d; + public byte e; + public short f; + public int g; + public long h; + public long i; + public Option_i64ByReference j; + + } + + @Structure.FieldOrder({"a", "b", "c", "d", "e", "f", "g", "h", "i", "j"}) + class NonZeroTestByReference extends Structure implements Structure.ByReference { + public NonZeroTestByReference() { + super(); + } + + public NonZeroTestByReference(Pointer p) { + super(p); + } + + public byte a; + public short b; + public int c; + public long d; + public byte e; + public short f; + public int g; + public long h; + public long i; + public Option_i64ByReference j; + + } + + + void root(NonZeroTest test, + byte a, + short b, + int c, + long d, + byte e, + short f, + int g, + long h, + long i, + Option_i64ByReference j); + +} \ No newline at end of file diff --git a/tests/expectations/opaque.java b/tests/expectations/opaque.java new file mode 100644 index 000000000..92607419a --- /dev/null +++ b/tests/expectations/opaque.java @@ -0,0 +1,113 @@ + +import com.sun.jna.*; +import com.sun.jna.ptr.*; + +enum BindingsSingleton { + INSTANCE; + final Bindings lib = Native.load("", Bindings.class); +} + +interface Bindings extends Library { + Bindings INSTANCE = BindingsSingleton.INSTANCE.lib; + + class HashMap_i32__i32__BuildHasherDefault_DefaultHasher extends PointerType { + public HashMap_i32__i32__BuildHasherDefault_DefaultHasher() { + super(null); + } + public HashMap_i32__i32__BuildHasherDefault_DefaultHasher(Pointer p) { + super(p); + } + } + + class HashMap_i32__i32__BuildHasherDefault_DefaultHasherByReference extends HashMap_i32__i32__BuildHasherDefault_DefaultHasher { + public HashMap_i32__i32__BuildHasherDefault_DefaultHasherByReference() { + super(null); + } + public HashMap_i32__i32__BuildHasherDefault_DefaultHasherByReference(Pointer p) { + super(p); + } + } + + class Result_Foo extends PointerType { + public Result_Foo() { + super(null); + } + public Result_Foo(Pointer p) { + super(p); + } + } + + class Result_FooByReference extends Result_Foo { + public Result_FooByReference() { + super(null); + } + public Result_FooByReference(Pointer p) { + super(p); + } + } + + + /** + * Fast hash map used internally. + */ + class FastHashMap_i32__i32 extends HashMap_i32__i32__BuildHasherDefault_DefaultHasher { + public FastHashMap_i32__i32() { + super(); + } + public FastHashMap_i32__i32(Pointer p) { + super(p); + } + } + + + /** + * Fast hash map used internally. + */ + class FastHashMap_i32__i32ByReference extends HashMap_i32__i32__BuildHasherDefault_DefaultHasherByReference { + public FastHashMap_i32__i32ByReference() { + super(); + } + public FastHashMap_i32__i32ByReference(Pointer p) { + super(p); + } + } + + class Foo extends FastHashMap_i32__i32 { + public Foo() { + super(); + } + public Foo(Pointer p) { + super(p); + } + } + + class FooByReference extends FastHashMap_i32__i32ByReference { + public FooByReference() { + super(); + } + public FooByReference(Pointer p) { + super(p); + } + } + + class Bar extends Result_Foo { + public Bar() { + super(); + } + public Bar(Pointer p) { + super(p); + } + } + + class BarByReference extends Result_FooByReference { + public BarByReference() { + super(); + } + public BarByReference(Pointer p) { + super(p); + } + } + + void root(FooByReference a, BarByReference b); + +} \ No newline at end of file diff --git a/tests/expectations/pin.java b/tests/expectations/pin.java new file mode 100644 index 000000000..0419990a7 --- /dev/null +++ b/tests/expectations/pin.java @@ -0,0 +1,47 @@ + +import com.sun.jna.*; +import com.sun.jna.ptr.*; + +enum BindingsSingleton { + INSTANCE; + final Bindings lib = Native.load("", Bindings.class); +} + +interface Bindings extends Library { + Bindings INSTANCE = BindingsSingleton.INSTANCE.lib; + + + @Structure.FieldOrder({"pinned_box", "pinned_ref"}) + class PinTest extends Structure implements Structure.ByValue { + public PinTest() { + super(); + } + + public PinTest(Pointer p) { + super(p); + } + + public IntByReference pinned_box; + public IntByReference pinned_ref; + + } + + @Structure.FieldOrder({"pinned_box", "pinned_ref"}) + class PinTestByReference extends Structure implements Structure.ByReference { + public PinTestByReference() { + super(); + } + + public PinTestByReference(Pointer p) { + super(p); + } + + public IntByReference pinned_box; + public IntByReference pinned_ref; + + } + + + void root(IntByReference s, PinTest p); + +} \ No newline at end of file diff --git a/tests/expectations/pragma_once.java b/tests/expectations/pragma_once.java new file mode 100644 index 000000000..519182a41 --- /dev/null +++ b/tests/expectations/pragma_once.java @@ -0,0 +1,14 @@ +import com.sun.jna.*; +import com.sun.jna.ptr.*; + +enum BindingsSingleton { + INSTANCE; + final Bindings lib = Native.load("", Bindings.class); +} + +interface Bindings extends Library { + Bindings INSTANCE = BindingsSingleton.INSTANCE.lib; + + void root(); + +} \ No newline at end of file diff --git a/tests/expectations/prefix.java b/tests/expectations/prefix.java new file mode 100644 index 000000000..560f687a1 --- /dev/null +++ b/tests/expectations/prefix.java @@ -0,0 +1,97 @@ +import com.sun.jna.*; +import com.sun.jna.ptr.*; + +enum BindingsSingleton { + INSTANCE; + final Bindings lib = Native.load("", Bindings.class); +} + +interface Bindings extends Library { + Bindings INSTANCE = BindingsSingleton.INSTANCE.lib; + + /* Unsupported literal for constant PREFIX_LEN */ + + + /* Unsupported literal for constant PREFIX_X */ + + + /* Unsupported literal for constant PREFIX_Y */ + + + class PREFIX_NamedLenArray extends PointerType { + public PREFIX_NamedLenArray() { + super(null); + } + public PREFIX_NamedLenArray(Pointer p) { + super(p); + } + } + + class PREFIX_NamedLenArrayByReference extends PREFIX_NamedLenArray { + public PREFIX_NamedLenArrayByReference() { + super(null); + } + public PREFIX_NamedLenArrayByReference(Pointer p) { + super(p); + } + } + + class PREFIX_ValuedLenArray extends PointerType { + public PREFIX_ValuedLenArray() { + super(null); + } + public PREFIX_ValuedLenArray(Pointer p) { + super(p); + } + } + + class PREFIX_ValuedLenArrayByReference extends PREFIX_ValuedLenArray { + public PREFIX_ValuedLenArrayByReference() { + super(null); + } + public PREFIX_ValuedLenArrayByReference(Pointer p) { + super(p); + } + } + + class PREFIX_AbsoluteFontWeight extends IntegerType { + public PREFIX_AbsoluteFontWeight() { + super(4); + } + + public PREFIX_AbsoluteFontWeight(long value) { + super(4, value); + } + + public PREFIX_AbsoluteFontWeight(Pointer p) { + this(p.getInt(0)); + } + public static final PREFIX_AbsoluteFontWeight Weight = new PREFIX_AbsoluteFontWeight(1); + public static final PREFIX_AbsoluteFontWeight Normal = new PREFIX_AbsoluteFontWeight(2); + public static final PREFIX_AbsoluteFontWeight Bold = new PREFIX_AbsoluteFontWeight(3); + + } + + class PREFIX_AbsoluteFontWeightByReference extends ByReference { + public PREFIX_AbsoluteFontWeightByReference() { + super(4); + } + + public PREFIX_AbsoluteFontWeightByReference(Pointer p) { + super(4); + setPointer(p); + } + + public PREFIX_AbsoluteFontWeight getValue() { + return new PREFIX_AbsoluteFontWeight(getPointer().getInt(0)); + } + + public void setValue(PREFIX_AbsoluteFontWeight value) { + getPointer().setInt(0, value.intValue()); + } + + } + + void root(PREFIX_NamedLenArray x, PREFIX_ValuedLenArray y, PREFIX_AbsoluteFontWeight z); + +} \ No newline at end of file diff --git a/tests/expectations/prefixed_struct_literal.java b/tests/expectations/prefixed_struct_literal.java new file mode 100644 index 000000000..64fc8b1e6 --- /dev/null +++ b/tests/expectations/prefixed_struct_literal.java @@ -0,0 +1,51 @@ +import com.sun.jna.*; +import com.sun.jna.ptr.*; + +enum BindingsSingleton { + INSTANCE; + final Bindings lib = Native.load("", Bindings.class); +} + +interface Bindings extends Library { + Bindings INSTANCE = BindingsSingleton.INSTANCE.lib; + + + @Structure.FieldOrder({"a", "b"}) + class PREFIXFoo extends Structure implements Structure.ByValue { + /* Unsupported literal for constant FOO */ + public PREFIXFoo() { + super(); + } + + public PREFIXFoo(Pointer p) { + super(p); + } + + public int a; + public int b; + + } + + @Structure.FieldOrder({"a", "b"}) + class PREFIXFooByReference extends Structure implements Structure.ByReference { + /* Unsupported literal for constant FOO */ + public PREFIXFooByReference() { + super(); + } + + public PREFIXFooByReference(Pointer p) { + super(p); + } + + public int a; + public int b; + + } + + + /* Unsupported literal for constant PREFIXBAR */ + + + void root(PREFIXFoo x); + +} \ No newline at end of file diff --git a/tests/expectations/prefixed_struct_literal_deep.java b/tests/expectations/prefixed_struct_literal_deep.java new file mode 100644 index 000000000..0a05e2353 --- /dev/null +++ b/tests/expectations/prefixed_struct_literal_deep.java @@ -0,0 +1,81 @@ +import com.sun.jna.*; +import com.sun.jna.ptr.*; + +enum BindingsSingleton { + INSTANCE; + final Bindings lib = Native.load("", Bindings.class); +} + +interface Bindings extends Library { + Bindings INSTANCE = BindingsSingleton.INSTANCE.lib; + + + @Structure.FieldOrder({"a"}) + class PREFIXBar extends Structure implements Structure.ByValue { + public PREFIXBar() { + super(); + } + + public PREFIXBar(Pointer p) { + super(p); + } + + public int a; + + } + + @Structure.FieldOrder({"a"}) + class PREFIXBarByReference extends Structure implements Structure.ByReference { + public PREFIXBarByReference() { + super(); + } + + public PREFIXBarByReference(Pointer p) { + super(p); + } + + public int a; + + } + + + + @Structure.FieldOrder({"a", "b", "bar"}) + class PREFIXFoo extends Structure implements Structure.ByValue { + public PREFIXFoo() { + super(); + } + + public PREFIXFoo(Pointer p) { + super(p); + } + + public int a; + public int b; + public PREFIXBar bar; + + } + + @Structure.FieldOrder({"a", "b", "bar"}) + class PREFIXFooByReference extends Structure implements Structure.ByReference { + public PREFIXFooByReference() { + super(); + } + + public PREFIXFooByReference(Pointer p) { + super(p); + } + + public int a; + public int b; + public PREFIXBar bar; + + } + + + /* Unsupported literal for constant PREFIXVAL */ + + + void root(PREFIXFoo x); + +} \ No newline at end of file diff --git a/tests/expectations/ptrs_as_arrays.java b/tests/expectations/ptrs_as_arrays.java new file mode 100644 index 000000000..bd2bed626 --- /dev/null +++ b/tests/expectations/ptrs_as_arrays.java @@ -0,0 +1,22 @@ +import com.sun.jna.*; +import com.sun.jna.ptr.*; + +enum BindingsSingleton { + INSTANCE; + final Bindings lib = Native.load("", Bindings.class); +} + +interface Bindings extends Library { + Bindings INSTANCE = BindingsSingleton.INSTANCE.lib; + + void ptr_as_array(int n, IntByReference arg, LongByReference v); + + void ptr_as_array1(int n, IntByReference arg, LongByReference v); + + void ptr_as_array2(int n, IntByReference arg, LongByReference v); + + void ptr_as_array_wrong_syntax(IntByReference arg, IntByReference v, IntByReference arg2); + + void ptr_as_array_unnamed(IntByReference arg0, IntByReference arg1); + +} \ No newline at end of file diff --git a/tests/expectations/raw_ident.java b/tests/expectations/raw_ident.java new file mode 100644 index 000000000..0f7605462 --- /dev/null +++ b/tests/expectations/raw_ident.java @@ -0,0 +1,83 @@ +import com.sun.jna.*; +import com.sun.jna.ptr.*; + +enum BindingsSingleton { + INSTANCE; + final Bindings lib = Native.load("", Bindings.class); +} + +interface Bindings extends Library { + Bindings INSTANCE = BindingsSingleton.INSTANCE.lib; + + class Enum extends IntegerType { + public Enum() { + super(4); + } + + public Enum(long value) { + super(4, value); + } + + public Enum(Pointer p) { + this(p.getInt(0)); + } + public static final Enum a = new Enum(1); + public static final Enum b = new Enum(2); + + } + + class EnumByReference extends ByReference { + public EnumByReference() { + super(4); + } + + public EnumByReference(Pointer p) { + super(4); + setPointer(p); + } + + public Enum getValue() { + return new Enum(getPointer().getInt(0)); + } + + public void setValue(Enum value) { + getPointer().setInt(0, value.intValue()); + } + + } + + + @Structure.FieldOrder({"field"}) + class Struct extends Structure implements Structure.ByValue { + public Struct() { + super(); + } + + public Struct(Pointer p) { + super(p); + } + + public Enum field; + + } + + @Structure.FieldOrder({"field"}) + class StructByReference extends Structure implements Structure.ByReference { + public StructByReference() { + super(); + } + + public StructByReference(Pointer p) { + super(p); + } + + public Enum field; + + } + + + /* Not implemented yet : Static { path: Path { name: "STATIC" }, export_name: "STATIC", ty: Path(GenericPath { path: Path { name: "Enum" }, export_name: "Enum", generics: [], ctype: None }), mutable: false, cfg: None, annotations: AnnotationSet { annotations: {}, must_use: false, deprecated: None }, documentation: Documentation { doc_comment: [] } } */ + + void fn(Struct arg); + +} \ No newline at end of file diff --git a/tests/expectations/raw_lines.java b/tests/expectations/raw_lines.java new file mode 100644 index 000000000..519182a41 --- /dev/null +++ b/tests/expectations/raw_lines.java @@ -0,0 +1,14 @@ +import com.sun.jna.*; +import com.sun.jna.ptr.*; + +enum BindingsSingleton { + INSTANCE; + final Bindings lib = Native.load("", Bindings.class); +} + +interface Bindings extends Library { + Bindings INSTANCE = BindingsSingleton.INSTANCE.lib; + + void root(); + +} \ No newline at end of file diff --git a/tests/expectations/rename.java b/tests/expectations/rename.java new file mode 100644 index 000000000..b60a2f159 --- /dev/null +++ b/tests/expectations/rename.java @@ -0,0 +1,177 @@ +import com.sun.jna.*; +import com.sun.jna.ptr.*; + +enum BindingsSingleton { + INSTANCE; + final Bindings lib = Native.load("", Bindings.class); +} + +interface Bindings extends Library { + Bindings INSTANCE = BindingsSingleton.INSTANCE.lib; + + /* Unsupported literal for constant C_H */ + + + class C_E extends IntegerType { + public C_E() { + super(4); + } + + public C_E(long value) { + super(4, value); + } + + public C_E(Pointer p) { + this(p.getInt(0)); + } + public static final C_E x = new C_E(0); + public static final C_E y = new C_E(1); + + } + + class C_EByReference extends ByReference { + public C_EByReference() { + super(4); + } + + public C_EByReference(Pointer p) { + super(4); + setPointer(p); + } + + public C_E getValue() { + return new C_E(getPointer().getInt(0)); + } + + public void setValue(C_E value) { + getPointer().setInt(0, value.intValue()); + } + + } + + class C_A extends PointerType { + public C_A() { + super(null); + } + public C_A(Pointer p) { + super(p); + } + } + + class C_AByReference extends C_A { + public C_AByReference() { + super(null); + } + public C_AByReference(Pointer p) { + super(p); + } + } + + class C_C extends PointerType { + public C_C() { + super(null); + } + public C_C(Pointer p) { + super(p); + } + } + + class C_CByReference extends C_C { + public C_CByReference() { + super(null); + } + public C_CByReference(Pointer p) { + super(p); + } + } + + + @Structure.FieldOrder({"x", "y"}) + class C_AwesomeB extends Structure implements Structure.ByValue { + public C_AwesomeB() { + super(); + } + + public C_AwesomeB(Pointer p) { + super(p); + } + + public int x; + public float y; + + } + + @Structure.FieldOrder({"x", "y"}) + class C_AwesomeBByReference extends Structure implements Structure.ByReference { + public C_AwesomeBByReference() { + super(); + } + + public C_AwesomeBByReference(Pointer p) { + super(p); + } + + public int x; + public float y; + + } + + + + @Structure.FieldOrder({"x", "y"}) + class C_D extends Union implements Structure.ByValue { + public C_D() { + super(); + } + + public C_D(Pointer p) { + super(p); + } + + public int x; + public float y; + + } + + @Structure.FieldOrder({"x", "y"}) + class C_DByReference extends Union implements Structure.ByReference { + public C_DByReference() { + super(); + } + + public C_DByReference(Pointer p) { + super(p); + } + + public int x; + public float y; + + } + + + class C_F extends C_A { + public C_F() { + super(); + } + public C_F(Pointer p) { + super(p); + } + } + + class C_FByReference extends C_AByReference { + public C_FByReference() { + super(); + } + public C_FByReference(Pointer p) { + super(p); + } + } + + /* Unsupported literal for constant C_I */ + + + /* Not implemented yet : Static { path: Path { name: "G" }, export_name: "G", ty: Primitive(Integer { zeroable: true, signed: true, kind: B32 }), mutable: false, cfg: None, annotations: AnnotationSet { annotations: {}, must_use: false, deprecated: None }, documentation: Documentation { doc_comment: [] } } */ + + void root(C_AByReference a, C_AwesomeB b, C_C c, C_D d, C_E e, C_F f); + +} \ No newline at end of file diff --git a/tests/expectations/rename_case.java b/tests/expectations/rename_case.java new file mode 100644 index 000000000..b0d421d07 --- /dev/null +++ b/tests/expectations/rename_case.java @@ -0,0 +1,22 @@ +import com.sun.jna.*; +import com.sun.jna.ptr.*; + +enum BindingsSingleton { + INSTANCE; + final Bindings lib = Native.load("", Bindings.class); +} + +interface Bindings extends Library { + Bindings INSTANCE = BindingsSingleton.INSTANCE.lib; + + void test_camel_case(int fooBar); + + void test_pascal_case(int FooBar); + + void test_snake_case(int foo_bar); + + void test_screaming_snake_case(int FOO_BAR); + + void test_gecko_case(int aFooBar); + +} \ No newline at end of file diff --git a/tests/expectations/rename_crate.java b/tests/expectations/rename_crate.java new file mode 100644 index 000000000..c89178f90 --- /dev/null +++ b/tests/expectations/rename_crate.java @@ -0,0 +1,81 @@ + +import com.sun.jna.*; +import com.sun.jna.ptr.*; + +enum BindingsSingleton { + INSTANCE; + final Bindings lib = Native.load("rename_crate", Bindings.class); +} + +interface Bindings extends Library { + Bindings INSTANCE = BindingsSingleton.INSTANCE.lib; + class ContainsNoExternTy {} + + + + @Structure.FieldOrder({"x"}) + class Foo extends Structure implements Structure.ByValue { + public Foo() { + super(); + } + + public Foo(Pointer p) { + super(p); + } + + public int x; + + } + + @Structure.FieldOrder({"x"}) + class FooByReference extends Structure implements Structure.ByReference { + public FooByReference() { + super(); + } + + public FooByReference(Pointer p) { + super(p); + } + + public int x; + + } + + + + @Structure.FieldOrder({"y"}) + class RenamedTy extends Structure implements Structure.ByValue { + public RenamedTy() { + super(); + } + + public RenamedTy(Pointer p) { + super(p); + } + + public long y; + + } + + @Structure.FieldOrder({"y"}) + class RenamedTyByReference extends Structure implements Structure.ByReference { + public RenamedTyByReference() { + super(); + } + + public RenamedTyByReference(Pointer p) { + super(p); + } + + public long y; + + } + + + void root(Foo a); + + void renamed_func(RenamedTy a); + + void no_extern_func(ContainsNoExternTy a); + +} \ No newline at end of file diff --git a/tests/expectations/renaming_overrides_prefixing.java b/tests/expectations/renaming_overrides_prefixing.java new file mode 100644 index 000000000..2f486bf79 --- /dev/null +++ b/tests/expectations/renaming_overrides_prefixing.java @@ -0,0 +1,64 @@ +import com.sun.jna.*; +import com.sun.jna.ptr.*; + +enum BindingsSingleton { + INSTANCE; + final Bindings lib = Native.load("", Bindings.class); +} + +interface Bindings extends Library { + Bindings INSTANCE = BindingsSingleton.INSTANCE.lib; + + class StyleA extends PointerType { + public StyleA() { + super(null); + } + public StyleA(Pointer p) { + super(p); + } + } + + class StyleAByReference extends StyleA { + public StyleAByReference() { + super(null); + } + public StyleAByReference(Pointer p) { + super(p); + } + } + + + @Structure.FieldOrder({"x", "y"}) + class B extends Structure implements Structure.ByValue { + public B() { + super(); + } + + public B(Pointer p) { + super(p); + } + + public int x; + public float y; + + } + + @Structure.FieldOrder({"x", "y"}) + class BByReference extends Structure implements Structure.ByReference { + public BByReference() { + super(); + } + + public BByReference(Pointer p) { + super(p); + } + + public int x; + public float y; + + } + + + void root(StyleAByReference a, B b); + +} \ No newline at end of file diff --git a/tests/expectations/reserved.java b/tests/expectations/reserved.java new file mode 100644 index 000000000..6c1d4609d --- /dev/null +++ b/tests/expectations/reserved.java @@ -0,0 +1,188 @@ +import com.sun.jna.*; +import com.sun.jna.ptr.*; + +enum BindingsSingleton { + INSTANCE; + final Bindings lib = Native.load("", Bindings.class); +} + +interface Bindings extends Library { + Bindings INSTANCE = BindingsSingleton.INSTANCE.lib; + + + @Structure.FieldOrder({"namespace_", "float_"}) + class A extends Structure implements Structure.ByValue { + public A() { + super(); + } + + public A(Pointer p) { + super(p); + } + + public int namespace_; + public float float_; + + } + + @Structure.FieldOrder({"namespace_", "float_"}) + class AByReference extends Structure implements Structure.ByReference { + public AByReference() { + super(); + } + + public AByReference(Pointer p) { + super(p); + } + + public int namespace_; + public float float_; + + } + + + + @Structure.FieldOrder({"namespace_", "float_"}) + class B extends Structure implements Structure.ByValue { + public B() { + super(); + } + + public B(Pointer p) { + super(p); + } + + public int namespace_; + public float float_; + + } + + @Structure.FieldOrder({"namespace_", "float_"}) + class BByReference extends Structure implements Structure.ByReference { + public BByReference() { + super(); + } + + public BByReference(Pointer p) { + super(p); + } + + public int namespace_; + public float float_; + + } + + + class C extends IntegerType { + public C() { + super(4); + } + + public C(long value) { + super(4, value); + } + + public C(Pointer p) { + this(p.getInt(0)); + } + public static final C D = new C(1); + + } + + class CByReference extends ByReference { + public CByReference() { + super(4); + } + + public CByReference(Pointer p) { + super(4); + setPointer(p); + } + + public C getValue() { + return new C(getPointer().getInt(0)); + } + + public void setValue(C value) { + getPointer().setInt(0, value.intValue()); + } + + } + + class E extends IntegerType { + public E() { + super(4); + } + + public E(long value) { + super(4, value); + } + + public E(Pointer p) { + this(p.getInt(0)); + } + public static final E Double = new E(1); + public static final E Float = new E(2); + + } + + class EByReference extends ByReference { + public EByReference() { + super(4); + } + + public EByReference(Pointer p) { + super(4); + setPointer(p); + } + + public E getValue() { + return new E(getPointer().getInt(0)); + } + + public void setValue(E value) { + getPointer().setInt(0, value.intValue()); + } + + } + + class F extends IntegerType { + public F() { + super(4); + } + + public F(long value) { + super(4, value); + } + + public F(Pointer p) { + this(p.getInt(0)); + } + public static final F double_ = new F(1); + public static final F float_ = new F(2); + + } + + class FByReference extends ByReference { + public FByReference() { + super(4); + } + + public FByReference(Pointer p) { + super(4); + setPointer(p); + } + + public F getValue() { + return new F(getPointer().getInt(0)); + } + + public void setValue(F value) { + getPointer().setInt(0, value.intValue()); + } + + } + + void root(A a, B b, C c, E e, F f, int namespace_, float float_); + +} \ No newline at end of file diff --git a/tests/expectations/sentinel.java b/tests/expectations/sentinel.java new file mode 100644 index 000000000..3d2e741b4 --- /dev/null +++ b/tests/expectations/sentinel.java @@ -0,0 +1,143 @@ +import com.sun.jna.*; +import com.sun.jna.ptr.*; + +enum BindingsSingleton { + INSTANCE; + final Bindings lib = Native.load("", Bindings.class); +} + +interface Bindings extends Library { + Bindings INSTANCE = BindingsSingleton.INSTANCE.lib; + + class A extends IntegerType { + public A() { + super(4); + } + + public A(long value) { + super(4, value); + } + + public A(Pointer p) { + this(p.getInt(0)); + } + public static final A A_A1 = new A(1); + public static final A A_A2 = new A(2); + public static final A A_A3 = new A(3); + + /** + * Must be last for serialization purposes + */ + public static final A A_Sentinel = new A(4); + + } + + class AByReference extends ByReference { + public AByReference() { + super(4); + } + + public AByReference(Pointer p) { + super(4); + setPointer(p); + } + + public A getValue() { + return new A(getPointer().getInt(0)); + } + + public void setValue(A value) { + getPointer().setInt(0, value.intValue()); + } + + } + + class B extends IntegerType { + public B() { + super(4); + } + + public B(long value) { + super(4, value); + } + + public B(Pointer p) { + this(p.getInt(0)); + } + public static final B B_B1 = new B(1); + public static final B B_B2 = new B(2); + public static final B B_B3 = new B(3); + + /** + * Must be last for serialization purposes + */ + public static final B B_Sentinel = new B(4); + + } + + class BByReference extends ByReference { + public BByReference() { + super(4); + } + + public BByReference(Pointer p) { + super(4); + setPointer(p); + } + + public B getValue() { + return new B(getPointer().getInt(0)); + } + + public void setValue(B value) { + getPointer().setInt(0, value.intValue()); + } + + } + + class C extends IntegerType { + public C() { + super(4); + } + + public C(long value) { + super(4, value); + } + + public C(Pointer p) { + this(p.getInt(0)); + } + public static final C C_C1 = new C(1); + public static final C C_C2 = new C(2); + public static final C C_C3 = new C(3); + + /** + * Must be last for serialization purposes + */ + public static final C C_Sentinel = new C(4); + + } + + class CByReference extends ByReference { + public CByReference() { + super(4); + } + + public CByReference(Pointer p) { + super(4); + setPointer(p); + } + + public C getValue() { + return new C(getPointer().getInt(0)); + } + + public void setValue(C value) { + getPointer().setInt(0, value.intValue()); + } + + } + + void root(A a, B b, C c); + +} \ No newline at end of file diff --git a/tests/expectations/simplify_option_ptr.java b/tests/expectations/simplify_option_ptr.java new file mode 100644 index 000000000..1fac62767 --- /dev/null +++ b/tests/expectations/simplify_option_ptr.java @@ -0,0 +1,127 @@ +import com.sun.jna.*; +import com.sun.jna.ptr.*; + +enum BindingsSingleton { + INSTANCE; + final Bindings lib = Native.load("", Bindings.class); +} + +interface Bindings extends Library { + Bindings INSTANCE = BindingsSingleton.INSTANCE.lib; + + class Opaque extends PointerType { + public Opaque() { + super(null); + } + public Opaque(Pointer p) { + super(p); + } + } + + class OpaqueByReference extends Opaque { + public OpaqueByReference() { + super(null); + } + public OpaqueByReference(Pointer p) { + super(p); + } + } + + class Option_____Opaque extends PointerType { + public Option_____Opaque() { + super(null); + } + public Option_____Opaque(Pointer p) { + super(p); + } + } + + class Option_____OpaqueByReference extends Option_____Opaque { + public Option_____OpaqueByReference() { + super(null); + } + public Option_____OpaqueByReference(Pointer p) { + super(p); + } + } + + + @Structure.FieldOrder({"x", "y", "z", "zz"}) + class Foo extends Structure implements Structure.ByValue { + public Foo() { + super(); + } + + public Foo(Pointer p) { + super(p); + } + + public OpaqueByReference x; + public OpaqueByReference y; + public Callback z; + public CallbackReference zz; + + } + + @Structure.FieldOrder({"x", "y", "z", "zz"}) + class FooByReference extends Structure implements Structure.ByReference { + public FooByReference() { + super(); + } + + public FooByReference(Pointer p) { + super(p); + } + + public OpaqueByReference x; + public OpaqueByReference y; + public Callback z; + public CallbackReference zz; + + } + + + + @Structure.FieldOrder({"x", "y", "z", "zz"}) + class Bar extends Union implements Structure.ByValue { + public Bar() { + super(); + } + + public Bar(Pointer p) { + super(p); + } + + public OpaqueByReference x; + public OpaqueByReference y; + public Callback z; + public CallbackReference zz; + + } + + @Structure.FieldOrder({"x", "y", "z", "zz"}) + class BarByReference extends Union implements Structure.ByReference { + public BarByReference() { + super(); + } + + public BarByReference(Pointer p) { + super(p); + } + + public OpaqueByReference x; + public OpaqueByReference y; + public Callback z; + public CallbackReference zz; + + } + + + void root(OpaqueByReference a, + OpaqueByReference b, + Foo c, + Bar d, + Option_____OpaqueByReference e, + Callback f); + +} \ No newline at end of file diff --git a/tests/expectations/size_types.java b/tests/expectations/size_types.java new file mode 100644 index 000000000..907bd9fa4 --- /dev/null +++ b/tests/expectations/size_types.java @@ -0,0 +1,156 @@ +import com.sun.jna.*; +import com.sun.jna.ptr.*; + +enum BindingsSingleton { + INSTANCE; + final Bindings lib = Native.load("", Bindings.class); +} + +interface Bindings extends Library { + Bindings INSTANCE = BindingsSingleton.INSTANCE.lib; + + class IE extends IntegerType { + public IE() { + super(4); + } + + public IE(long value) { + super(4, value); + } + + public IE(Pointer p) { + this(p.getInt(0)); + } + public static final IE IV = new IE(1); + + } + + class IEByReference extends ByReference { + public IEByReference() { + super(4); + } + + public IEByReference(Pointer p) { + super(4); + setPointer(p); + } + + public IE getValue() { + return new IE(getPointer().getInt(0)); + } + + public void setValue(IE value) { + getPointer().setInt(0, value.intValue()); + } + + } + + class UE extends IntegerType { + public UE() { + super(4); + } + + public UE(long value) { + super(4, value); + } + + public UE(Pointer p) { + this(p.getInt(0)); + } + public static final UE UV = new UE(1); + + } + + class UEByReference extends ByReference { + public UEByReference() { + super(4); + } + + public UEByReference(Pointer p) { + super(4); + setPointer(p); + } + + public UE getValue() { + return new UE(getPointer().getInt(0)); + } + + public void setValue(UE value) { + getPointer().setInt(0, value.intValue()); + } + + } + + class Usize extends IntegerType { + public Usize() { + super(Native.SIZE_T_SIZE); + } + + public Usize(long value) { + super(Native.SIZE_T_SIZE, value); + } + + public Usize(Pointer p) { + this(p.getNativeLong(0).longValue()); + } + + } + + class UsizeByReference extends ByReference { + public UsizeByReference() { + super(Native.SIZE_T_SIZE); + } + + public UsizeByReference(Pointer p) { + super(Native.SIZE_T_SIZE); + setPointer(p); + } + + public Usize getValue() { + return new Usize(getPointer().getNativeLong(0).longValue()); + } + + public void setValue(Usize value) { + getPointer().setNativeLong(0, new NativeLong(value.longValue())); + } + + } + + class Isize extends IntegerType { + public Isize() { + super(Native.SIZE_T_SIZE); + } + + public Isize(long value) { + super(Native.SIZE_T_SIZE, value); + } + + public Isize(Pointer p) { + this(p.getNativeLong(0).longValue()); + } + + } + + class IsizeByReference extends ByReference { + public IsizeByReference() { + super(Native.SIZE_T_SIZE); + } + + public IsizeByReference(Pointer p) { + super(Native.SIZE_T_SIZE); + setPointer(p); + } + + public Isize getValue() { + return new Isize(getPointer().getNativeLong(0).longValue()); + } + + public void setValue(Isize value) { + getPointer().setNativeLong(0, new NativeLong(value.longValue())); + } + + } + + void root(Usize arg0, Isize arg1, UE arg2, IE arg3); + +} \ No newline at end of file diff --git a/tests/expectations/static.java b/tests/expectations/static.java new file mode 100644 index 000000000..65225b68d --- /dev/null +++ b/tests/expectations/static.java @@ -0,0 +1,64 @@ +import com.sun.jna.*; +import com.sun.jna.ptr.*; + +enum BindingsSingleton { + INSTANCE; + final Bindings lib = Native.load("", Bindings.class); +} + +interface Bindings extends Library { + Bindings INSTANCE = BindingsSingleton.INSTANCE.lib; + + class Bar extends PointerType { + public Bar() { + super(null); + } + public Bar(Pointer p) { + super(p); + } + } + + class BarByReference extends Bar { + public BarByReference() { + super(null); + } + public BarByReference(Pointer p) { + super(p); + } + } + + + class Foo extends Structure implements Structure.ByValue { + public Foo() { + super(); + } + + public Foo(Pointer p) { + super(p); + } + + + } + + class FooByReference extends Structure implements Structure.ByReference { + public FooByReference() { + super(); + } + + public FooByReference(Pointer p) { + super(p); + } + + + } + + + /* Not implemented yet : Static { path: Path { name: "NUMBER" }, export_name: "NUMBER", ty: Primitive(Integer { zeroable: true, signed: true, kind: B32 }), mutable: false, cfg: None, annotations: AnnotationSet { annotations: {}, must_use: false, deprecated: None }, documentation: Documentation { doc_comment: [] } } */ + + /* Not implemented yet : Static { path: Path { name: "FOO" }, export_name: "FOO", ty: Path(GenericPath { path: Path { name: "Foo" }, export_name: "Foo", generics: [], ctype: None }), mutable: true, cfg: None, annotations: AnnotationSet { annotations: {}, must_use: false, deprecated: None }, documentation: Documentation { doc_comment: [] } } */ + + /* Not implemented yet : Static { path: Path { name: "BAR" }, export_name: "BAR", ty: Path(GenericPath { path: Path { name: "Bar" }, export_name: "Bar", generics: [], ctype: None }), mutable: false, cfg: None, annotations: AnnotationSet { annotations: {}, must_use: false, deprecated: None }, documentation: Documentation { doc_comment: [] } } */ + + void root(); + +} \ No newline at end of file diff --git a/tests/expectations/std_lib.java b/tests/expectations/std_lib.java new file mode 100644 index 000000000..e9e08f44f --- /dev/null +++ b/tests/expectations/std_lib.java @@ -0,0 +1,68 @@ +import com.sun.jna.*; +import com.sun.jna.ptr.*; + +enum BindingsSingleton { + INSTANCE; + final Bindings lib = Native.load("", Bindings.class); +} + +interface Bindings extends Library { + Bindings INSTANCE = BindingsSingleton.INSTANCE.lib; + + class Option_i32 extends PointerType { + public Option_i32() { + super(null); + } + public Option_i32(Pointer p) { + super(p); + } + } + + class Option_i32ByReference extends Option_i32 { + public Option_i32ByReference() { + super(null); + } + public Option_i32ByReference(Pointer p) { + super(p); + } + } + + class Result_i32__String extends PointerType { + public Result_i32__String() { + super(null); + } + public Result_i32__String(Pointer p) { + super(p); + } + } + + class Result_i32__StringByReference extends Result_i32__String { + public Result_i32__StringByReference() { + super(null); + } + public Result_i32__StringByReference(Pointer p) { + super(p); + } + } + + class Vec_String extends PointerType { + public Vec_String() { + super(null); + } + public Vec_String(Pointer p) { + super(p); + } + } + + class Vec_StringByReference extends Vec_String { + public Vec_StringByReference() { + super(null); + } + public Vec_StringByReference(Pointer p) { + super(p); + } + } + + void root(Vec_StringByReference a, Option_i32ByReference b, Result_i32__StringByReference c); + +} \ No newline at end of file diff --git a/tests/expectations/struct.java b/tests/expectations/struct.java new file mode 100644 index 000000000..1e49520ad --- /dev/null +++ b/tests/expectations/struct.java @@ -0,0 +1,160 @@ +import com.sun.jna.*; +import com.sun.jna.ptr.*; + +enum BindingsSingleton { + INSTANCE; + final Bindings lib = Native.load("", Bindings.class); +} + +interface Bindings extends Library { + Bindings INSTANCE = BindingsSingleton.INSTANCE.lib; + + class Opaque extends PointerType { + public Opaque() { + super(null); + } + public Opaque(Pointer p) { + super(p); + } + } + + class OpaqueByReference extends Opaque { + public OpaqueByReference() { + super(null); + } + public OpaqueByReference(Pointer p) { + super(p); + } + } + + + @Structure.FieldOrder({"x", "y"}) + class Normal extends Structure implements Structure.ByValue { + public Normal() { + super(); + } + + public Normal(Pointer p) { + super(p); + } + + public int x; + public float y; + + } + + @Structure.FieldOrder({"x", "y"}) + class NormalByReference extends Structure implements Structure.ByReference { + public NormalByReference() { + super(); + } + + public NormalByReference(Pointer p) { + super(p); + } + + public int x; + public float y; + + } + + + + @Structure.FieldOrder({"x", "y"}) + class NormalWithZST extends Structure implements Structure.ByValue { + public NormalWithZST() { + super(); + } + + public NormalWithZST(Pointer p) { + super(p); + } + + public int x; + public float y; + + } + + @Structure.FieldOrder({"x", "y"}) + class NormalWithZSTByReference extends Structure implements Structure.ByReference { + public NormalWithZSTByReference() { + super(); + } + + public NormalWithZSTByReference(Pointer p) { + super(p); + } + + public int x; + public float y; + + } + + + + @Structure.FieldOrder({"m0", "m1"}) + class TupleRenamed extends Structure implements Structure.ByValue { + public TupleRenamed() { + super(); + } + + public TupleRenamed(Pointer p) { + super(p); + } + + public int m0; + public float m1; + + } + + @Structure.FieldOrder({"m0", "m1"}) + class TupleRenamedByReference extends Structure implements Structure.ByReference { + public TupleRenamedByReference() { + super(); + } + + public TupleRenamedByReference(Pointer p) { + super(p); + } + + public int m0; + public float m1; + + } + + + + @Structure.FieldOrder({"x", "y"}) + class TupleNamed extends Structure implements Structure.ByValue { + public TupleNamed() { + super(); + } + + public TupleNamed(Pointer p) { + super(p); + } + + public int x; + public float y; + + } + + @Structure.FieldOrder({"x", "y"}) + class TupleNamedByReference extends Structure implements Structure.ByReference { + public TupleNamedByReference() { + super(); + } + + public TupleNamedByReference(Pointer p) { + super(p); + } + + public int x; + public float y; + + } + + + void root(OpaqueByReference a, Normal b, NormalWithZST c, TupleRenamed d, TupleNamed e); + +} \ No newline at end of file diff --git a/tests/expectations/struct_literal.java b/tests/expectations/struct_literal.java new file mode 100644 index 000000000..85b60bde8 --- /dev/null +++ b/tests/expectations/struct_literal.java @@ -0,0 +1,75 @@ +import com.sun.jna.*; +import com.sun.jna.ptr.*; + +enum BindingsSingleton { + INSTANCE; + final Bindings lib = Native.load("", Bindings.class); +} + +interface Bindings extends Library { + Bindings INSTANCE = BindingsSingleton.INSTANCE.lib; + + class Bar extends PointerType { + public Bar() { + super(null); + } + public Bar(Pointer p) { + super(p); + } + } + + class BarByReference extends Bar { + public BarByReference() { + super(null); + } + public BarByReference(Pointer p) { + super(p); + } + } + + + @Structure.FieldOrder({"a", "b"}) + class Foo extends Structure implements Structure.ByValue { + /* Unsupported literal for constant FOO */ + /* Unsupported literal for constant FOO2 */ + /* Unsupported literal for constant FOO3 */ + public Foo() { + super(); + } + + public Foo(Pointer p) { + super(p); + } + + public int a; + public int b; + + } + + @Structure.FieldOrder({"a", "b"}) + class FooByReference extends Structure implements Structure.ByReference { + /* Unsupported literal for constant FOO */ + /* Unsupported literal for constant FOO2 */ + /* Unsupported literal for constant FOO3 */ + public FooByReference() { + super(); + } + + public FooByReference(Pointer p) { + super(p); + } + + public int a; + public int b; + + } + + + /* Unsupported literal for constant BAR */ + + + + + void root(Foo x, Bar bar); + +} \ No newline at end of file diff --git a/tests/expectations/struct_literal_order.java b/tests/expectations/struct_literal_order.java new file mode 100644 index 000000000..3433e32e2 --- /dev/null +++ b/tests/expectations/struct_literal_order.java @@ -0,0 +1,94 @@ +import com.sun.jna.*; +import com.sun.jna.ptr.*; + +enum BindingsSingleton { + INSTANCE; + final Bindings lib = Native.load("", Bindings.class); +} + +interface Bindings extends Library { + Bindings INSTANCE = BindingsSingleton.INSTANCE.lib; + + + @Structure.FieldOrder({"a", "b", "c"}) + class ABC extends Structure implements Structure.ByValue { + /* Unsupported literal for constant abc */ + /* Unsupported literal for constant bac */ + /* Unsupported literal for constant cba */ + public ABC() { + super(); + } + + public ABC(Pointer p) { + super(p); + } + + public float a; + public int b; + public int c; + + } + + @Structure.FieldOrder({"a", "b", "c"}) + class ABCByReference extends Structure implements Structure.ByReference { + /* Unsupported literal for constant abc */ + /* Unsupported literal for constant bac */ + /* Unsupported literal for constant cba */ + public ABCByReference() { + super(); + } + + public ABCByReference(Pointer p) { + super(p); + } + + public float a; + public int b; + public int c; + + } + + + + @Structure.FieldOrder({"b", "a", "c"}) + class BAC extends Structure implements Structure.ByValue { + /* Unsupported literal for constant abc */ + /* Unsupported literal for constant bac */ + /* Unsupported literal for constant cba */ + public BAC() { + super(); + } + + public BAC(Pointer p) { + super(p); + } + + public int b; + public float a; + public int c; + + } + + @Structure.FieldOrder({"b", "a", "c"}) + class BACByReference extends Structure implements Structure.ByReference { + /* Unsupported literal for constant abc */ + /* Unsupported literal for constant bac */ + /* Unsupported literal for constant cba */ + public BACByReference() { + super(); + } + + public BACByReference(Pointer p) { + super(p); + } + + public int b; + public float a; + public int c; + + } + + + void root(ABC a1, BAC a2); + +} \ No newline at end of file diff --git a/tests/expectations/struct_self.java b/tests/expectations/struct_self.java new file mode 100644 index 000000000..4a2d8765e --- /dev/null +++ b/tests/expectations/struct_self.java @@ -0,0 +1,76 @@ +import com.sun.jna.*; +import com.sun.jna.ptr.*; + +enum BindingsSingleton { + INSTANCE; + final Bindings lib = Native.load("", Bindings.class); +} + +interface Bindings extends Library { + Bindings INSTANCE = BindingsSingleton.INSTANCE.lib; + + + @Structure.FieldOrder({"something"}) + class Foo_Bar extends Structure implements Structure.ByValue { + public Foo_Bar() { + super(); + } + + public Foo_Bar(Pointer p) { + super(p); + } + + public IntByReference something; + + } + + @Structure.FieldOrder({"something"}) + class Foo_BarByReference extends Structure implements Structure.ByReference { + public Foo_BarByReference() { + super(); + } + + public Foo_BarByReference(Pointer p) { + super(p); + } + + public IntByReference something; + + } + + + + @Structure.FieldOrder({"something", "subexpressions"}) + class Bar extends Structure implements Structure.ByValue { + public Bar() { + super(); + } + + public Bar(Pointer p) { + super(p); + } + + public int something; + public Foo_Bar subexpressions; + + } + + @Structure.FieldOrder({"something", "subexpressions"}) + class BarByReference extends Structure implements Structure.ByReference { + public BarByReference() { + super(); + } + + public BarByReference(Pointer p) { + super(p); + } + + public int something; + public Foo_Bar subexpressions; + + } + + + void root(Bar b); + +} \ No newline at end of file diff --git a/tests/expectations/style_crash.java b/tests/expectations/style_crash.java new file mode 100644 index 000000000..90cf1e1b0 --- /dev/null +++ b/tests/expectations/style_crash.java @@ -0,0 +1,12 @@ +import com.sun.jna.*; +import com.sun.jna.ptr.*; + +enum BindingsSingleton { + INSTANCE; + final Bindings lib = Native.load("", Bindings.class); +} + +interface Bindings extends Library { + Bindings INSTANCE = BindingsSingleton.INSTANCE.lib; + +} \ No newline at end of file diff --git a/tests/expectations/swift_name.java b/tests/expectations/swift_name.java new file mode 100644 index 000000000..8cb7e2a8e --- /dev/null +++ b/tests/expectations/swift_name.java @@ -0,0 +1,129 @@ + +import com.sun.jna.*; +import com.sun.jna.ptr.*; + +enum BindingsSingleton { + INSTANCE; + final Bindings lib = Native.load("", Bindings.class); +} + +interface Bindings extends Library { + Bindings INSTANCE = BindingsSingleton.INSTANCE.lib; + + class Opaque extends PointerType { + public Opaque() { + super(null); + } + public Opaque(Pointer p) { + super(p); + } + } + + class OpaqueByReference extends Opaque { + public OpaqueByReference() { + super(null); + } + public OpaqueByReference(Pointer p) { + super(p); + } + } + + + @Structure.FieldOrder({"times"}) + class SelfTypeTestStruct extends Structure implements Structure.ByValue { + public SelfTypeTestStruct() { + super(); + } + + public SelfTypeTestStruct(Pointer p) { + super(p); + } + + public byte times; + + } + + @Structure.FieldOrder({"times"}) + class SelfTypeTestStructByReference extends Structure implements Structure.ByReference { + public SelfTypeTestStructByReference() { + super(); + } + + public SelfTypeTestStructByReference(Pointer p) { + super(p); + } + + public byte times; + + } + + + + @Structure.FieldOrder({"ptr"}) + class PointerToOpaque extends Structure implements Structure.ByValue { + public PointerToOpaque() { + super(); + } + + public PointerToOpaque(Pointer p) { + super(p); + } + + public OpaqueByReference ptr; + + } + + @Structure.FieldOrder({"ptr"}) + class PointerToOpaqueByReference extends Structure implements Structure.ByReference { + public PointerToOpaqueByReference() { + super(); + } + + public PointerToOpaqueByReference(Pointer p) { + super(p); + } + + public OpaqueByReference ptr; + + } + + + void rust_print_hello_world(); + + void SelfTypeTestStruct_should_exist_ref(SelfTypeTestStructByReference self); + + void SelfTypeTestStruct_should_exist_ref_mut(SelfTypeTestStructByReference self); + + void SelfTypeTestStruct_should_not_exist_box(SelfTypeTestStructByReference self); + + SelfTypeTestStructByReference SelfTypeTestStruct_should_not_exist_return_box(); + + void SelfTypeTestStruct_should_exist_annotated_self(SelfTypeTestStruct self); + + void SelfTypeTestStruct_should_exist_annotated_mut_self(SelfTypeTestStruct self); + + void SelfTypeTestStruct_should_exist_annotated_by_name(SelfTypeTestStruct self); + + void SelfTypeTestStruct_should_exist_annotated_mut_by_name(SelfTypeTestStruct self); + + void SelfTypeTestStruct_should_exist_unannotated(SelfTypeTestStruct self); + + void SelfTypeTestStruct_should_exist_mut_unannotated(SelfTypeTestStruct self); + + void free_function_should_exist_ref(SelfTypeTestStructByReference test_struct); + + void free_function_should_exist_ref_mut(SelfTypeTestStructByReference test_struct); + + void unnamed_argument(SelfTypeTestStructByReference arg0); + + void free_function_should_not_exist_box(SelfTypeTestStructByReference boxed); + + void free_function_should_exist_annotated_by_name(SelfTypeTestStruct test_struct); + + void free_function_should_exist_annotated_mut_by_name(SelfTypeTestStruct test_struct); + + PointerToOpaque PointerToOpaque_create(byte times); + + void PointerToOpaque_sayHello(PointerToOpaque self); + +} \ No newline at end of file diff --git a/tests/expectations/transform_op.java b/tests/expectations/transform_op.java new file mode 100644 index 000000000..fc6bfc72e --- /dev/null +++ b/tests/expectations/transform_op.java @@ -0,0 +1,306 @@ +import com.sun.jna.*; +import com.sun.jna.ptr.*; + +enum BindingsSingleton { + INSTANCE; + final Bindings lib = Native.load("", Bindings.class); +} + +interface Bindings extends Library { + Bindings INSTANCE = BindingsSingleton.INSTANCE.lib; + + + @Structure.FieldOrder({"x", "y"}) + class StylePoint_i32 extends Structure implements Structure.ByValue { + public StylePoint_i32() { + super(); + } + + public StylePoint_i32(Pointer p) { + super(p); + } + + public int x; + public int y; + + } + + @Structure.FieldOrder({"x", "y"}) + class StylePoint_i32ByReference extends Structure implements Structure.ByReference { + public StylePoint_i32ByReference() { + super(); + } + + public StylePoint_i32ByReference(Pointer p) { + super(p); + } + + public int x; + public int y; + + } + + + + @Structure.FieldOrder({"x", "y"}) + class StylePoint_f32 extends Structure implements Structure.ByValue { + public StylePoint_f32() { + super(); + } + + public StylePoint_f32(Pointer p) { + super(p); + } + + public float x; + public float y; + + } + + @Structure.FieldOrder({"x", "y"}) + class StylePoint_f32ByReference extends Structure implements Structure.ByReference { + public StylePoint_f32ByReference() { + super(); + } + + public StylePoint_f32ByReference(Pointer p) { + super(p); + } + + public float x; + public float y; + + } + + + class StyleFoo_i32 extends IntegerType { + public StyleFoo_i32() { + super(4); + } + + public StyleFoo_i32(long value) { + super(4, value); + } + + public StyleFoo_i32(Pointer p) { + this(p.getInt(0)); + } + public static final StyleFoo_i32 Foo_i32 = new StyleFoo_i32(1); + public static final StyleFoo_i32 Bar_i32 = new StyleFoo_i32(2); + public static final StyleFoo_i32 Baz_i32 = new StyleFoo_i32(3); + public static final StyleFoo_i32 Bazz_i32 = new StyleFoo_i32(4); + + } + + class StyleFoo_i32ByReference extends ByReference { + public StyleFoo_i32ByReference() { + super(4); + } + + public StyleFoo_i32ByReference(Pointer p) { + super(4); + setPointer(p); + } + + public StyleFoo_i32 getValue() { + return new StyleFoo_i32(getPointer().getInt(0)); + } + + public void setValue(StyleFoo_i32 value) { + getPointer().setInt(0, value.intValue()); + } + + } + + class StyleBar_i32 extends IntegerType { + public StyleBar_i32() { + super(4); + } + + public StyleBar_i32(long value) { + super(4, value); + } + + public StyleBar_i32(Pointer p) { + this(p.getInt(0)); + } + public static final StyleBar_i32 Bar1_i32 = new StyleBar_i32(1); + public static final StyleBar_i32 Bar2_i32 = new StyleBar_i32(2); + public static final StyleBar_i32 Bar3_i32 = new StyleBar_i32(3); + public static final StyleBar_i32 Bar4_i32 = new StyleBar_i32(4); + + } + + class StyleBar_i32ByReference extends ByReference { + public StyleBar_i32ByReference() { + super(4); + } + + public StyleBar_i32ByReference(Pointer p) { + super(4); + setPointer(p); + } + + public StyleBar_i32 getValue() { + return new StyleBar_i32(getPointer().getInt(0)); + } + + public void setValue(StyleBar_i32 value) { + getPointer().setInt(0, value.intValue()); + } + + } + + + @Structure.FieldOrder({"x", "y"}) + class StylePoint_u32 extends Structure implements Structure.ByValue { + public StylePoint_u32() { + super(); + } + + public StylePoint_u32(Pointer p) { + super(p); + } + + public int x; + public int y; + + } + + @Structure.FieldOrder({"x", "y"}) + class StylePoint_u32ByReference extends Structure implements Structure.ByReference { + public StylePoint_u32ByReference() { + super(); + } + + public StylePoint_u32ByReference(Pointer p) { + super(p); + } + + public int x; + public int y; + + } + + + class StyleBar_u32 extends IntegerType { + public StyleBar_u32() { + super(4); + } + + public StyleBar_u32(long value) { + super(4, value); + } + + public StyleBar_u32(Pointer p) { + this(p.getInt(0)); + } + public static final StyleBar_u32 Bar1_u32 = new StyleBar_u32(1); + public static final StyleBar_u32 Bar2_u32 = new StyleBar_u32(2); + public static final StyleBar_u32 Bar3_u32 = new StyleBar_u32(3); + public static final StyleBar_u32 Bar4_u32 = new StyleBar_u32(4); + + } + + class StyleBar_u32ByReference extends ByReference { + public StyleBar_u32ByReference() { + super(4); + } + + public StyleBar_u32ByReference(Pointer p) { + super(4); + setPointer(p); + } + + public StyleBar_u32 getValue() { + return new StyleBar_u32(getPointer().getInt(0)); + } + + public void setValue(StyleBar_u32 value) { + getPointer().setInt(0, value.intValue()); + } + + } + + class StyleBaz extends IntegerType { + public StyleBaz() { + super(4); + } + + public StyleBaz(long value) { + super(4, value); + } + + public StyleBaz(Pointer p) { + this(p.getInt(0)); + } + public static final StyleBaz Baz1 = new StyleBaz(1); + public static final StyleBaz Baz2 = new StyleBaz(2); + public static final StyleBaz Baz3 = new StyleBaz(3); + + } + + class StyleBazByReference extends ByReference { + public StyleBazByReference() { + super(4); + } + + public StyleBazByReference(Pointer p) { + super(4); + setPointer(p); + } + + public StyleBaz getValue() { + return new StyleBaz(getPointer().getInt(0)); + } + + public void setValue(StyleBaz value) { + getPointer().setInt(0, value.intValue()); + } + + } + + class StyleTaz extends IntegerType { + public StyleTaz() { + super(4); + } + + public StyleTaz(long value) { + super(4, value); + } + + public StyleTaz(Pointer p) { + this(p.getInt(0)); + } + public static final StyleTaz Taz1 = new StyleTaz(1); + public static final StyleTaz Taz2 = new StyleTaz(2); + public static final StyleTaz Taz3 = new StyleTaz(3); + + } + + class StyleTazByReference extends ByReference { + public StyleTazByReference() { + super(4); + } + + public StyleTazByReference(Pointer p) { + super(4); + setPointer(p); + } + + public StyleTaz getValue() { + return new StyleTaz(getPointer().getInt(0)); + } + + public void setValue(StyleTaz value) { + getPointer().setInt(0, value.intValue()); + } + + } + + void foo(StyleFoo_i32ByReference foo, + StyleBar_i32ByReference bar, + StyleBazByReference baz, + StyleTazByReference taz); + +} \ No newline at end of file diff --git a/tests/expectations/transparent.java b/tests/expectations/transparent.java new file mode 100644 index 000000000..d5b2b2244 --- /dev/null +++ b/tests/expectations/transparent.java @@ -0,0 +1,280 @@ +import com.sun.jna.*; +import com.sun.jna.ptr.*; + +enum BindingsSingleton { + INSTANCE; + final Bindings lib = Native.load("", Bindings.class); +} + +interface Bindings extends Library { + Bindings INSTANCE = BindingsSingleton.INSTANCE.lib; + + class DummyStruct extends PointerType { + public DummyStruct() { + super(null); + } + public DummyStruct(Pointer p) { + super(p); + } + } + + class DummyStructByReference extends DummyStruct { + public DummyStructByReference() { + super(null); + } + public DummyStructByReference(Pointer p) { + super(p); + } + } + + class EnumWithAssociatedConstantInImpl extends PointerType { + public EnumWithAssociatedConstantInImpl() { + super(null); + } + public EnumWithAssociatedConstantInImpl(Pointer p) { + super(p); + } + } + + class EnumWithAssociatedConstantInImplByReference extends EnumWithAssociatedConstantInImpl { + public EnumWithAssociatedConstantInImplByReference() { + super(null); + } + public EnumWithAssociatedConstantInImplByReference(Pointer p) { + super(p); + } + } + + + class TransparentComplexWrappingStructTuple extends DummyStruct implements Structure.ByValue { + public TransparentComplexWrappingStructTuple() { + super(); + } + + public TransparentComplexWrappingStructTuple(Pointer p) { + super(p); + } + + + } + + class TransparentComplexWrappingStructTupleByReference extends DummyStruct implements Structure.ByReference { + public TransparentComplexWrappingStructTupleByReference() { + super(); + } + + public TransparentComplexWrappingStructTupleByReference(Pointer p) { + super(p); + } + + + } + + + class TransparentPrimitiveWrappingStructTuple extends IntegerType { + public TransparentPrimitiveWrappingStructTuple() { + super(4); + } + + public TransparentPrimitiveWrappingStructTuple(long value) { + super(4, value); + } + + public TransparentPrimitiveWrappingStructTuple(Pointer p) { + this(p.getInt(0)); + } + + } + + class TransparentPrimitiveWrappingStructTupleByReference extends ByReference { + public TransparentPrimitiveWrappingStructTupleByReference() { + super(4); + } + + public TransparentPrimitiveWrappingStructTupleByReference(Pointer p) { + super(4); + setPointer(p); + } + + public TransparentPrimitiveWrappingStructTuple getValue() { + return new TransparentPrimitiveWrappingStructTuple(getPointer().getInt(0)); + } + + public void setValue(TransparentPrimitiveWrappingStructTuple value) { + getPointer().setInt(0, value.intValue()); + } + + } + + + class TransparentComplexWrappingStructure extends DummyStruct implements Structure.ByValue { + public TransparentComplexWrappingStructure() { + super(); + } + + public TransparentComplexWrappingStructure(Pointer p) { + super(p); + } + + + } + + class TransparentComplexWrappingStructureByReference extends DummyStruct implements Structure.ByReference { + public TransparentComplexWrappingStructureByReference() { + super(); + } + + public TransparentComplexWrappingStructureByReference(Pointer p) { + super(p); + } + + + } + + + class TransparentPrimitiveWrappingStructure extends IntegerType { + public TransparentPrimitiveWrappingStructure() { + super(4); + } + + public TransparentPrimitiveWrappingStructure(long value) { + super(4, value); + } + + public TransparentPrimitiveWrappingStructure(Pointer p) { + this(p.getInt(0)); + } + + } + + class TransparentPrimitiveWrappingStructureByReference extends ByReference { + public TransparentPrimitiveWrappingStructureByReference() { + super(4); + } + + public TransparentPrimitiveWrappingStructureByReference(Pointer p) { + super(4); + setPointer(p); + } + + public TransparentPrimitiveWrappingStructure getValue() { + return new TransparentPrimitiveWrappingStructure(getPointer().getInt(0)); + } + + public void setValue(TransparentPrimitiveWrappingStructure value) { + getPointer().setInt(0, value.intValue()); + } + + } + + + class TransparentComplexWrapper_i32 extends DummyStruct implements Structure.ByValue { + public TransparentComplexWrapper_i32() { + super(); + } + + public TransparentComplexWrapper_i32(Pointer p) { + super(p); + } + + + } + + class TransparentComplexWrapper_i32ByReference extends DummyStruct implements Structure.ByReference { + public TransparentComplexWrapper_i32ByReference() { + super(); + } + + public TransparentComplexWrapper_i32ByReference(Pointer p) { + super(p); + } + + + } + + + class TransparentPrimitiveWrapper_i32 extends IntegerType { + public TransparentPrimitiveWrapper_i32() { + super(4); + } + + public TransparentPrimitiveWrapper_i32(long value) { + super(4, value); + } + + public TransparentPrimitiveWrapper_i32(Pointer p) { + this(p.getInt(0)); + } + + } + + class TransparentPrimitiveWrapper_i32ByReference extends ByReference { + public TransparentPrimitiveWrapper_i32ByReference() { + super(4); + } + + public TransparentPrimitiveWrapper_i32ByReference(Pointer p) { + super(4); + setPointer(p); + } + + public TransparentPrimitiveWrapper_i32 getValue() { + return new TransparentPrimitiveWrapper_i32(getPointer().getInt(0)); + } + + public void setValue(TransparentPrimitiveWrapper_i32 value) { + getPointer().setInt(0, value.intValue()); + } + + } + + class TransparentPrimitiveWithAssociatedConstants extends IntegerType { + public TransparentPrimitiveWithAssociatedConstants() { + super(4); + } + + public TransparentPrimitiveWithAssociatedConstants(long value) { + super(4, value); + } + + public TransparentPrimitiveWithAssociatedConstants(Pointer p) { + this(p.getInt(0)); + } + public static final TransparentPrimitiveWithAssociatedConstants ZERO = new TransparentPrimitiveWithAssociatedConstants(0); + public static final TransparentPrimitiveWithAssociatedConstants ONE = new TransparentPrimitiveWithAssociatedConstants(1); + + } + + class TransparentPrimitiveWithAssociatedConstantsByReference extends ByReference { + public TransparentPrimitiveWithAssociatedConstantsByReference() { + super(4); + } + + public TransparentPrimitiveWithAssociatedConstantsByReference(Pointer p) { + super(4); + setPointer(p); + } + + public TransparentPrimitiveWithAssociatedConstants getValue() { + return new TransparentPrimitiveWithAssociatedConstants(getPointer().getInt(0)); + } + + public void setValue(TransparentPrimitiveWithAssociatedConstants value) { + getPointer().setInt(0, value.intValue()); + } + + } + + public static final TransparentPrimitiveWrappingStructure TEN = new TransparentPrimitiveWrappingStructure(10); + + + void root(TransparentComplexWrappingStructTuple a, + TransparentPrimitiveWrappingStructTuple b, + TransparentComplexWrappingStructure c, + TransparentPrimitiveWrappingStructure d, + TransparentComplexWrapper_i32 e, + TransparentPrimitiveWrapper_i32 f, + TransparentPrimitiveWithAssociatedConstants g, + EnumWithAssociatedConstantInImpl h); + +} \ No newline at end of file diff --git a/tests/expectations/typedef.java b/tests/expectations/typedef.java new file mode 100644 index 000000000..3e9ae0240 --- /dev/null +++ b/tests/expectations/typedef.java @@ -0,0 +1,64 @@ +import com.sun.jna.*; +import com.sun.jna.ptr.*; + +enum BindingsSingleton { + INSTANCE; + final Bindings lib = Native.load("", Bindings.class); +} + +interface Bindings extends Library { + Bindings INSTANCE = BindingsSingleton.INSTANCE.lib; + + + @Structure.FieldOrder({"x", "y"}) + class Foo_i32__i32 extends Structure implements Structure.ByValue { + public Foo_i32__i32() { + super(); + } + + public Foo_i32__i32(Pointer p) { + super(p); + } + + public int x; + public int y; + + } + + @Structure.FieldOrder({"x", "y"}) + class Foo_i32__i32ByReference extends Structure implements Structure.ByReference { + public Foo_i32__i32ByReference() { + super(); + } + + public Foo_i32__i32ByReference(Pointer p) { + super(p); + } + + public int x; + public int y; + + } + + + class IntFoo_i32 extends Foo_i32__i32 { + public IntFoo_i32() { + super(); + } + public IntFoo_i32(Pointer p) { + super(p); + } + } + + class IntFoo_i32ByReference extends Foo_i32__i32ByReference { + public IntFoo_i32ByReference() { + super(); + } + public IntFoo_i32ByReference(Pointer p) { + super(p); + } + } + + void root(IntFoo_i32 a); + +} \ No newline at end of file diff --git a/tests/expectations/union.java b/tests/expectations/union.java new file mode 100644 index 000000000..ef027f552 --- /dev/null +++ b/tests/expectations/union.java @@ -0,0 +1,96 @@ +import com.sun.jna.*; +import com.sun.jna.ptr.*; + +enum BindingsSingleton { + INSTANCE; + final Bindings lib = Native.load("", Bindings.class); +} + +interface Bindings extends Library { + Bindings INSTANCE = BindingsSingleton.INSTANCE.lib; + + class Opaque extends PointerType { + public Opaque() { + super(null); + } + public Opaque(Pointer p) { + super(p); + } + } + + class OpaqueByReference extends Opaque { + public OpaqueByReference() { + super(null); + } + public OpaqueByReference(Pointer p) { + super(p); + } + } + + + @Structure.FieldOrder({"x", "y"}) + class Normal extends Union implements Structure.ByValue { + public Normal() { + super(); + } + + public Normal(Pointer p) { + super(p); + } + + public int x; + public float y; + + } + + @Structure.FieldOrder({"x", "y"}) + class NormalByReference extends Union implements Structure.ByReference { + public NormalByReference() { + super(); + } + + public NormalByReference(Pointer p) { + super(p); + } + + public int x; + public float y; + + } + + + + @Structure.FieldOrder({"x", "y"}) + class NormalWithZST extends Union implements Structure.ByValue { + public NormalWithZST() { + super(); + } + + public NormalWithZST(Pointer p) { + super(p); + } + + public int x; + public float y; + + } + + @Structure.FieldOrder({"x", "y"}) + class NormalWithZSTByReference extends Union implements Structure.ByReference { + public NormalWithZSTByReference() { + super(); + } + + public NormalWithZSTByReference(Pointer p) { + super(p); + } + + public int x; + public float y; + + } + + + void root(OpaqueByReference a, Normal b, NormalWithZST c); + +} \ No newline at end of file diff --git a/tests/expectations/union_self.java b/tests/expectations/union_self.java new file mode 100644 index 000000000..5616f05ec --- /dev/null +++ b/tests/expectations/union_self.java @@ -0,0 +1,76 @@ +import com.sun.jna.*; +import com.sun.jna.ptr.*; + +enum BindingsSingleton { + INSTANCE; + final Bindings lib = Native.load("", Bindings.class); +} + +interface Bindings extends Library { + Bindings INSTANCE = BindingsSingleton.INSTANCE.lib; + + + @Structure.FieldOrder({"something"}) + class Foo_Bar extends Structure implements Structure.ByValue { + public Foo_Bar() { + super(); + } + + public Foo_Bar(Pointer p) { + super(p); + } + + public IntByReference something; + + } + + @Structure.FieldOrder({"something"}) + class Foo_BarByReference extends Structure implements Structure.ByReference { + public Foo_BarByReference() { + super(); + } + + public Foo_BarByReference(Pointer p) { + super(p); + } + + public IntByReference something; + + } + + + + @Structure.FieldOrder({"something", "subexpressions"}) + class Bar extends Union implements Structure.ByValue { + public Bar() { + super(); + } + + public Bar(Pointer p) { + super(p); + } + + public int something; + public Foo_Bar subexpressions; + + } + + @Structure.FieldOrder({"something", "subexpressions"}) + class BarByReference extends Union implements Structure.ByReference { + public BarByReference() { + super(); + } + + public BarByReference(Pointer p) { + super(p); + } + + public int something; + public Foo_Bar subexpressions; + + } + + + void root(Bar b); + +} \ No newline at end of file diff --git a/tests/expectations/using_namespaces.java b/tests/expectations/using_namespaces.java new file mode 100644 index 000000000..519182a41 --- /dev/null +++ b/tests/expectations/using_namespaces.java @@ -0,0 +1,14 @@ +import com.sun.jna.*; +import com.sun.jna.ptr.*; + +enum BindingsSingleton { + INSTANCE; + final Bindings lib = Native.load("", Bindings.class); +} + +interface Bindings extends Library { + Bindings INSTANCE = BindingsSingleton.INSTANCE.lib; + + void root(); + +} \ No newline at end of file diff --git a/tests/expectations/va_list.java b/tests/expectations/va_list.java new file mode 100644 index 000000000..1ee5558ca --- /dev/null +++ b/tests/expectations/va_list.java @@ -0,0 +1,16 @@ +import com.sun.jna.*; +import com.sun.jna.ptr.*; + +enum BindingsSingleton { + INSTANCE; + final Bindings lib = Native.load("", Bindings.class); +} + +interface Bindings extends Library { + Bindings INSTANCE = BindingsSingleton.INSTANCE.lib; + + int va_list_test(Pointer ap); + + int va_list_test2(Pointer ap); + +} \ No newline at end of file diff --git a/tests/expectations/workspace.java b/tests/expectations/workspace.java new file mode 100644 index 000000000..df8819f1c --- /dev/null +++ b/tests/expectations/workspace.java @@ -0,0 +1,47 @@ +import com.sun.jna.*; +import com.sun.jna.ptr.*; + +enum BindingsSingleton { + INSTANCE; + final Bindings lib = Native.load("workspace", Bindings.class); +} + +interface Bindings extends Library { + Bindings INSTANCE = BindingsSingleton.INSTANCE.lib; + + /* Unsupported literal for constant EXT_CONST */ + + + + @Structure.FieldOrder({"data"}) + class ExtType extends Structure implements Structure.ByValue { + public ExtType() { + super(); + } + + public ExtType(Pointer p) { + super(p); + } + + public int data; + + } + + @Structure.FieldOrder({"data"}) + class ExtTypeByReference extends Structure implements Structure.ByReference { + public ExtTypeByReference() { + super(); + } + + public ExtTypeByReference(Pointer p) { + super(p); + } + + public int data; + + } + + + void consume_ext(ExtType _ext); + +} \ No newline at end of file diff --git a/tests/expectations/zst.java b/tests/expectations/zst.java new file mode 100644 index 000000000..7e7827bfc --- /dev/null +++ b/tests/expectations/zst.java @@ -0,0 +1,46 @@ +import com.sun.jna.*; +import com.sun.jna.ptr.*; + +enum BindingsSingleton { + INSTANCE; + final Bindings lib = Native.load("", Bindings.class); +} + +interface Bindings extends Library { + Bindings INSTANCE = BindingsSingleton.INSTANCE.lib; + + + @Structure.FieldOrder({"data", "vtable"}) + class TraitObject extends Structure implements Structure.ByValue { + public TraitObject() { + super(); + } + + public TraitObject(Pointer p) { + super(p); + } + + public Pointer data; + public Pointer vtable; + + } + + @Structure.FieldOrder({"data", "vtable"}) + class TraitObjectByReference extends Structure implements Structure.ByReference { + public TraitObjectByReference() { + super(); + } + + public TraitObjectByReference(Pointer p) { + super(p); + } + + public Pointer data; + public Pointer vtable; + + } + + + Pointer root(Pointer ptr, TraitObject t); + +} \ No newline at end of file diff --git a/tests/rust/asserted_cast.java-jna.toml b/tests/rust/asserted_cast.java-jna.toml new file mode 100644 index 000000000..1459f0f09 --- /dev/null +++ b/tests/rust/asserted_cast.java-jna.toml @@ -0,0 +1,5 @@ +[enum] +derive_helper_methods = true +derive_const_casts = true +derive_mut_casts = true +cast_assert_name = "MY_ASSERT" diff --git a/tests/rust/box.java-jna.toml b/tests/rust/box.java-jna.toml new file mode 100644 index 000000000..453be44bd --- /dev/null +++ b/tests/rust/box.java-jna.toml @@ -0,0 +1,6 @@ +header = """ +""" +[export] +exclude = [ + "Box", +] diff --git a/tests/rust/cfg.java-jna.toml b/tests/rust/cfg.java-jna.toml new file mode 100644 index 000000000..f6cb9f848 --- /dev/null +++ b/tests/rust/cfg.java-jna.toml @@ -0,0 +1,19 @@ +header = """ +""" + +[defines] +"unix" = "PLATFORM_UNIX" +"windows" = "PLATFORM_WIN" +"x11" = "X11" +"target_pointer_width = 32" = "M_32" + +[enum] +derive_tagged_enum_destructor = true +derive_tagged_enum_copy_constructor = true +derive_tagged_enum_copy_assignment = true +derive_helper_methods = true +private_default_tagged_enum_constructor = true + +[struct] +derive_eq = true +derive_neq = true diff --git a/tests/rust/cfg_2.java-jna.toml b/tests/rust/cfg_2.java-jna.toml new file mode 100644 index 000000000..b9bf9109b --- /dev/null +++ b/tests/rust/cfg_2.java-jna.toml @@ -0,0 +1,7 @@ +[java_jna] +extra_defs = "class Bar {}" + +[export] +exclude = [ + "DEFAULT_X", "Bar" +] diff --git a/tests/rust/custom_header.java-jna.toml b/tests/rust/custom_header.java-jna.toml new file mode 100644 index 000000000..7987c9324 --- /dev/null +++ b/tests/rust/custom_header.java-jna.toml @@ -0,0 +1,11 @@ +no_includes = true +header = """ +/* + * This file is generated by cbindgen. DO NOT EDIT + */ +""" +trailer = """ +/* + * This is a simple test to ensure that trailers do not cause extra newlines in files + */ +""" diff --git a/tests/rust/deprecated.java-jna.toml b/tests/rust/deprecated.java-jna.toml new file mode 100644 index 000000000..730551d2b --- /dev/null +++ b/tests/rust/deprecated.java-jna.toml @@ -0,0 +1 @@ +# nothing to configure for java \ No newline at end of file diff --git a/tests/rust/destructor_and_copy_ctor.java-jna.toml b/tests/rust/destructor_and_copy_ctor.java-jna.toml new file mode 100644 index 000000000..c3d7b7444 --- /dev/null +++ b/tests/rust/destructor_and_copy_ctor.java-jna.toml @@ -0,0 +1,14 @@ +header = """ +""" + +[enum] +derive_tagged_enum_destructor = true +derive_tagged_enum_copy_constructor = true +derive_tagged_enum_copy_assignment = true +derive_helper_methods = true +private_default_tagged_enum_constructor = true + +[export.body] +"OwnedSlice" = """ + ~OwnedSlice() {} +""" diff --git a/tests/rust/enum.java-jna.toml b/tests/rust/enum.java-jna.toml new file mode 100644 index 000000000..3f6f69864 --- /dev/null +++ b/tests/rust/enum.java-jna.toml @@ -0,0 +1,13 @@ +header = """ +""" + +trailer = """ +""" + +[export] +exclude = [ + "Box", +] + +[export.rename] +"I" = "ExI" diff --git a/tests/rust/exclude_generic_monomorph.java-jna.toml b/tests/rust/exclude_generic_monomorph.java-jna.toml new file mode 100644 index 000000000..a7c649bcc --- /dev/null +++ b/tests/rust/exclude_generic_monomorph.java-jna.toml @@ -0,0 +1,10 @@ + +[java_jna] +extra_defs = """ +class Option_Foo {} +""" + +[export] +exclude = [ + "Option_Foo", +] diff --git a/tests/rust/forward_declaration.java-jna.toml b/tests/rust/forward_declaration.java-jna.toml new file mode 100644 index 000000000..11bc5bd60 --- /dev/null +++ b/tests/rust/forward_declaration.java-jna.toml @@ -0,0 +1,5 @@ +header = """ +""" + +trailer = """ +""" diff --git a/tests/rust/layout.java-jna.toml b/tests/rust/layout.java-jna.toml new file mode 100644 index 000000000..5e5a0a7e5 --- /dev/null +++ b/tests/rust/layout.java-jna.toml @@ -0,0 +1,27 @@ +header = """ +""" + +[layout] +packed = "CBINDGEN_PACKED" +aligned_n = "CBINDGEN_ALIGNED" + +[export] +include = [ + "Align1Struct", + "Align2Struct", + "Align4Struct", + "Align8Struct", + "Align32Struct", + "PackedStruct", + "Align1Union", + "Align4Union", + "Align16Union", + "PackedUnion", + "UnsupportedPacked4Struct", + "UnsupportedPacked4Union", + "UnsupportedAlign4Enum", + "RustAlign4Struct", + "RustPackedStruct", + "RustAlign4Union", + "RustPackedUnion", +] diff --git a/tests/rust/layout_aligned_opaque.java-jna.toml b/tests/rust/layout_aligned_opaque.java-jna.toml new file mode 100644 index 000000000..1d7ed22d4 --- /dev/null +++ b/tests/rust/layout_aligned_opaque.java-jna.toml @@ -0,0 +1,20 @@ +header = """ +""" + +[layout] +# We do not define aligned_n. +packed = "CBINDGEN_PACKED" + +[export] +include = [ + "PackedStruct", + "PackedUnion", + "OpaqueAlign1Union", + "OpaqueAlign4Union", + "OpaqueAlign16Union", + "OpaqueAlign1Struct", + "OpaqueAlign2Struct", + "OpaqueAlign4Struct", + "OpaqueAlign8Struct", + "OpaqueAlign32Struct", +] diff --git a/tests/rust/layout_packed_opaque.java-jna.toml b/tests/rust/layout_packed_opaque.java-jna.toml new file mode 100644 index 000000000..ed447e8b1 --- /dev/null +++ b/tests/rust/layout_packed_opaque.java-jna.toml @@ -0,0 +1,20 @@ +header = """ +""" + +[layout] +# We do not define packed. +aligned_n = "CBINDGEN_ALIGNED" + +[export] +include = [ + "Align1Union", + "Align4Union", + "Align16Union", + "Align1Struct", + "Align2Struct", + "Align4Struct", + "Align8Struct", + "Align32Struct", + "OpaquePackedStruct", + "OpaquePackedUnion", +] diff --git a/tests/rust/manuallydrop.java-jna.toml b/tests/rust/manuallydrop.java-jna.toml new file mode 100644 index 000000000..c8ded9bc8 --- /dev/null +++ b/tests/rust/manuallydrop.java-jna.toml @@ -0,0 +1,6 @@ +header = """ +""" +[export] +exclude = [ + "ManuallyDrop", +] diff --git a/tests/rust/maybeuninit.java-jna.toml b/tests/rust/maybeuninit.java-jna.toml new file mode 100644 index 000000000..8174363c9 --- /dev/null +++ b/tests/rust/maybeuninit.java-jna.toml @@ -0,0 +1,6 @@ +header = """ +""" +[export] +exclude = [ + "MaybeUninit", +] diff --git a/tests/rust/mod_attr/cbindgen.java-jna.toml b/tests/rust/mod_attr/cbindgen.java-jna.toml new file mode 100644 index 000000000..8599f7911 --- /dev/null +++ b/tests/rust/mod_attr/cbindgen.java-jna.toml @@ -0,0 +1,7 @@ +header = """ +""" + +[defines] +"foo" = "FOO" +"bar" = "BAR" +# "feature = foobar" = "FOOBAR" diff --git a/tests/rust/must_use.java-jna.toml b/tests/rust/must_use.java-jna.toml new file mode 100644 index 000000000..e869bec09 --- /dev/null +++ b/tests/rust/must_use.java-jna.toml @@ -0,0 +1,11 @@ +header = """ +""" + +[fn] +must_use = "MUST_USE_FUNC" + +[struct] +must_use = "MUST_USE_STRUCT" + +[enum] +must_use = "MUST_USE_ENUM" diff --git a/tests/rust/nonnull_attribute.java-jna.toml b/tests/rust/nonnull_attribute.java-jna.toml new file mode 100644 index 000000000..9407464f4 --- /dev/null +++ b/tests/rust/nonnull_attribute.java-jna.toml @@ -0,0 +1,5 @@ +header = """ +""" + +[ptr] +non_null_attribute = "CBINDGEN_NONNULL" \ No newline at end of file diff --git a/tests/rust/nonzero.java-jna.toml b/tests/rust/nonzero.java-jna.toml new file mode 100644 index 000000000..4ad023477 --- /dev/null +++ b/tests/rust/nonzero.java-jna.toml @@ -0,0 +1,2 @@ +header = """ +""" diff --git a/tests/rust/opaque.java-jna.toml b/tests/rust/opaque.java-jna.toml new file mode 100644 index 000000000..4ad023477 --- /dev/null +++ b/tests/rust/opaque.java-jna.toml @@ -0,0 +1,2 @@ +header = """ +""" diff --git a/tests/rust/pin.java-jna.toml b/tests/rust/pin.java-jna.toml new file mode 100644 index 000000000..9eba0c87e --- /dev/null +++ b/tests/rust/pin.java-jna.toml @@ -0,0 +1,7 @@ +header = """ +""" +[export] +exclude = [ + "Pin", + "Box" +] diff --git a/tests/rust/rename_crate/cbindgen.java-jna.toml b/tests/rust/rename_crate/cbindgen.java-jna.toml new file mode 100644 index 000000000..e73c53f36 --- /dev/null +++ b/tests/rust/rename_crate/cbindgen.java-jna.toml @@ -0,0 +1,17 @@ +header = """ +""" + +[parse] +parse_deps = true +[defines] +"target_os = freebsd" = "DEFINE_FREEBSD" + +[export] +exclude = [ + "ContainsNoExternTy" +] + +[java_jna] +extra_defs = """ +class ContainsNoExternTy {} +""" diff --git a/tests/rust/swift_name.java-jna.toml b/tests/rust/swift_name.java-jna.toml new file mode 100644 index 000000000..e81e1ce5b --- /dev/null +++ b/tests/rust/swift_name.java-jna.toml @@ -0,0 +1,4 @@ +header = "" + +[fn] +swift_name_macro = "CF_SWIFT_NAME" diff --git a/tests/tests.rs b/tests/tests.rs index 3846f326e..2e297eb7c 100644 --- a/tests/tests.rs +++ b/tests/tests.rs @@ -1,6 +1,5 @@ extern crate cbindgen; -use cbindgen::*; use std::collections::HashSet; use std::fs::File; use std::io::Read; @@ -8,6 +7,8 @@ use std::path::Path; use std::process::Command; use std::{env, fs, str}; +use cbindgen::*; + // Set automatically by cargo for integration tests static CBINDGEN_PATH: &str = env!("CARGO_BIN_EXE_cbindgen"); @@ -56,14 +57,24 @@ fn run_cbindgen( Language::Cython => { command.arg("--lang").arg("cython"); } + Language::JavaJna => { + command.arg("--lang").arg("java-jna"); + } } if let Some(style) = style { command.arg("--style").arg(style_str(style)); } + let specific_config = path.with_extension(format!("{}.toml", language)); + let specific_config_folder = path.join(format!("cbindgen.{}.toml", language)); let config = path.with_extension("toml"); - if config.exists() { + + if specific_config.exists() { + command.arg("--config").arg(specific_config); + } else if specific_config_folder.exists() { + command.arg("--config").arg(specific_config_folder); + } else if config.exists() { command.arg("--config").arg(config); } @@ -116,6 +127,7 @@ fn compile( Language::Cxx => env::var("CXX").unwrap_or_else(|_| "g++".to_owned()), Language::C => env::var("CC").unwrap_or_else(|_| "gcc".to_owned()), Language::Cython => env::var("CYTHON").unwrap_or_else(|_| "cython".to_owned()), + Language::JavaJna => env::var("JAVAC").unwrap_or_else(|_| "javac".to_string()), }; let file_name = cbindgen_output @@ -178,11 +190,40 @@ fn compile( command.arg("-o").arg(&object); command.arg(cbindgen_output); } + Language::JavaJna => { + let jna_jar = Path::new(env!("CARGO_TARGET_TMPDIR")).join("jna-5.13.0.jar"); + + println!("using {jna_jar:?}"); + if !jna_jar.exists() { + if !Command::new("curl") + .arg("--output") + .arg(&jna_jar) + .arg( + "https://repo1.maven.org/maven2/net/java/dev/jna/jna/5.13.0/jna-5.13.0.jar", + ) + .status() + .unwrap() + .success() + { + panic!("Failed to download JNA for java tests"); + } + } + + command.arg("-cp").arg(&jna_jar); + command.arg("-d").arg(tmp_dir); + command.arg(cbindgen_output); + } } println!("Running: {:?}", command); let out = command.output().expect("failed to compile"); - assert!(out.status.success(), "Output failed to compile: {:?}", out); + assert!( + out.status.success(), + "Output failed to compile: status {}\nstdout:\n{}\n\n\nstderr:\n{}", + out.status, + String::from_utf8_lossy(&out.stdout), + String::from_utf8_lossy(&out.stderr) + ); if object.exists() { fs::remove_file(object).unwrap(); @@ -222,6 +263,7 @@ fn run_compile_test( // is extension-sensitive and won't work on them, so we use implementation files (`.pyx`) // in the test suite. Language::Cython => ".pyx", + Language::JavaJna => ".java", }; let skip_warning_as_error = name.rfind(SKIP_WARNING_AS_ERROR_SUFFIX).is_some(); @@ -356,6 +398,16 @@ fn test_file(name: &'static str, filename: &'static str) { &mut cbindgen_outputs, ); } + + run_compile_test( + name, + test, + tmp_dir, + Language::JavaJna, + /* cpp_compat = */ false, + None, + &mut HashSet::new(), + ); } macro_rules! test_file {