diff --git a/core/src/hir/defs.rs b/core/src/hir/defs.rs index fbc2b586e..16bd42ed8 100644 --- a/core/src/hir/defs.rs +++ b/core/src/hir/defs.rs @@ -152,15 +152,9 @@ impl EnumDef { } } -impl<'a> From<&'a StructDef> for TypeDef<'a> { - fn from(x: &'a StructDef) -> Self { - TypeDef::Struct(x) - } -} - -impl<'a> From<&'a OutStructDef> for TypeDef<'a> { - fn from(x: &'a OutStructDef) -> Self { - TypeDef::OutStruct(x) +impl<'a, P: TyPosition> From<&'a StructDef

> for TypeDef<'a> { + fn from(x: &'a StructDef

) -> Self { + P::wrap_struct_def(x) } } diff --git a/core/src/hir/ty_position.rs b/core/src/hir/ty_position.rs index 87916a7f7..4312681eb 100644 --- a/core/src/hir/ty_position.rs +++ b/core/src/hir/ty_position.rs @@ -1,7 +1,7 @@ use super::lifetimes::{Lifetime, Lifetimes, MaybeStatic}; use super::{ - Borrow, LinkedLifetimes, MaybeOwn, Mutability, OutStructId, ReturnableStructPath, StructId, - StructPath, TypeContext, TypeId, + Borrow, LinkedLifetimes, MaybeOwn, Mutability, OutStructId, ReturnableStructPath, StructDef, + StructId, StructPath, TypeContext, TypeDef, TypeId, }; use core::fmt::Debug; @@ -87,7 +87,10 @@ use core::fmt::Debug; /// Therefore, this trait allows be extremely precise about making invalid states /// unrepresentable, while also reducing duplicated code. /// -pub trait TyPosition: Debug + Copy { +pub trait TyPosition: Debug + Copy +where + for<'tcx> TypeDef<'tcx>: From<&'tcx StructDef>, +{ const IS_OUT_ONLY: bool; /// Type representing how we can point to opaques, which must always be behind a pointer. @@ -102,6 +105,8 @@ pub trait TyPosition: Debug + Copy { type StructId: Debug; type StructPath: Debug + StructPathLike; + + fn wrap_struct_def<'tcx>(def: &'tcx StructDef) -> TypeDef<'tcx>; } /// One of two types implementing [`TyPosition`], representing types that can be @@ -125,6 +130,10 @@ impl TyPosition for Everywhere { type OpaqueOwnership = Borrow; type StructId = StructId; type StructPath = StructPath; + + fn wrap_struct_def<'tcx>(def: &'tcx StructDef) -> TypeDef<'tcx> { + TypeDef::Struct(def) + } } impl TyPosition for OutputOnly { @@ -132,6 +141,10 @@ impl TyPosition for OutputOnly { type OpaqueOwnership = MaybeOwn; type StructId = OutStructId; type StructPath = ReturnableStructPath; + + fn wrap_struct_def<'tcx>(def: &'tcx StructDef) -> TypeDef<'tcx> { + TypeDef::OutStruct(def) + } } pub trait StructPathLike { diff --git a/example/cpp2/include/ICU4XDataProvider.d.h b/example/cpp2/include/ICU4XDataProvider.d.h deleted file mode 100644 index 8a6432968..000000000 --- a/example/cpp2/include/ICU4XDataProvider.d.h +++ /dev/null @@ -1,20 +0,0 @@ -#ifndef ICU4XDataProvider_D_H -#define ICU4XDataProvider_D_H - -#include -#include -#include -#include -#include "diplomat_runtime.h" - - -namespace capi { - - -typedef struct ICU4XDataProvider ICU4XDataProvider; - - - -} // namespace capi - -#endif // ICU4XDataProvider_D_H diff --git a/example/cpp2/include/ICU4XDataProvider.d.hpp b/example/cpp2/include/ICU4XDataProvider.d.hpp index 65b9baab7..4b31caaa0 100644 --- a/example/cpp2/include/ICU4XDataProvider.d.hpp +++ b/example/cpp2/include/ICU4XDataProvider.d.hpp @@ -8,9 +8,12 @@ #include #include #include "diplomat_runtime.hpp" -#include "ICU4XDataProvider.d.h" +namespace capi { + typedef struct ICU4XDataProvider ICU4XDataProvider; +} + class ICU4XDataProvider { public: diff --git a/example/cpp2/include/ICU4XDataProvider.h b/example/cpp2/include/ICU4XDataProvider.h deleted file mode 100644 index 9a9b91187..000000000 --- a/example/cpp2/include/ICU4XDataProvider.h +++ /dev/null @@ -1,30 +0,0 @@ -#ifndef ICU4XDataProvider_H -#define ICU4XDataProvider_H - -#include -#include -#include -#include -#include "diplomat_runtime.h" - - -#include "ICU4XDataProvider.d.h" - -namespace capi { - - -extern "C" { - -ICU4XDataProvider* ICU4XDataProvider_new_static(); - -struct ICU4XDataProvider_returns_result_result { bool is_ok;}; -struct ICU4XDataProvider_returns_result_result ICU4XDataProvider_returns_result(); - - -void ICU4XDataProvider_destroy(ICU4XDataProvider* self); - -} // extern "C" - -} // namespace capi - -#endif // ICU4XDataProvider_H diff --git a/example/cpp2/include/ICU4XDataProvider.hpp b/example/cpp2/include/ICU4XDataProvider.hpp index 5e2c0140d..e6d738d18 100644 --- a/example/cpp2/include/ICU4XDataProvider.hpp +++ b/example/cpp2/include/ICU4XDataProvider.hpp @@ -10,9 +10,22 @@ #include #include #include "diplomat_runtime.hpp" -#include "ICU4XDataProvider.h" +namespace capi { + extern "C" { + + ICU4XDataProvider* ICU4XDataProvider_new_static(); + + struct ICU4XDataProvider_returns_result_result { bool is_ok;}; + struct ICU4XDataProvider_returns_result_result ICU4XDataProvider_returns_result(); + + + void ICU4XDataProvider_destroy(ICU4XDataProvider* self); + + } // extern "C" +} + inline std::unique_ptr ICU4XDataProvider::new_static() { auto result = capi::ICU4XDataProvider_new_static(); return std::unique_ptr(ICU4XDataProvider::FromFFI(result)); diff --git a/example/cpp2/include/ICU4XFixedDecimal.d.h b/example/cpp2/include/ICU4XFixedDecimal.d.h deleted file mode 100644 index 45cb0a614..000000000 --- a/example/cpp2/include/ICU4XFixedDecimal.d.h +++ /dev/null @@ -1,20 +0,0 @@ -#ifndef ICU4XFixedDecimal_D_H -#define ICU4XFixedDecimal_D_H - -#include -#include -#include -#include -#include "diplomat_runtime.h" - - -namespace capi { - - -typedef struct ICU4XFixedDecimal ICU4XFixedDecimal; - - - -} // namespace capi - -#endif // ICU4XFixedDecimal_D_H diff --git a/example/cpp2/include/ICU4XFixedDecimal.d.hpp b/example/cpp2/include/ICU4XFixedDecimal.d.hpp index e13f0adc5..45b9a5763 100644 --- a/example/cpp2/include/ICU4XFixedDecimal.d.hpp +++ b/example/cpp2/include/ICU4XFixedDecimal.d.hpp @@ -8,9 +8,12 @@ #include #include #include "diplomat_runtime.hpp" -#include "ICU4XFixedDecimal.d.h" +namespace capi { + typedef struct ICU4XFixedDecimal ICU4XFixedDecimal; +} + class ICU4XFixedDecimal { public: diff --git a/example/cpp2/include/ICU4XFixedDecimal.h b/example/cpp2/include/ICU4XFixedDecimal.h deleted file mode 100644 index 22de29f4d..000000000 --- a/example/cpp2/include/ICU4XFixedDecimal.h +++ /dev/null @@ -1,32 +0,0 @@ -#ifndef ICU4XFixedDecimal_H -#define ICU4XFixedDecimal_H - -#include -#include -#include -#include -#include "diplomat_runtime.h" - - -#include "ICU4XFixedDecimal.d.h" - -namespace capi { - - -extern "C" { - -ICU4XFixedDecimal* ICU4XFixedDecimal_new(int32_t v); - -void ICU4XFixedDecimal_multiply_pow10(ICU4XFixedDecimal* self, int16_t power); - -struct ICU4XFixedDecimal_to_string_result { bool is_ok;}; -struct ICU4XFixedDecimal_to_string_result ICU4XFixedDecimal_to_string(const ICU4XFixedDecimal* self, DiplomatWrite* write); - - -void ICU4XFixedDecimal_destroy(ICU4XFixedDecimal* self); - -} // extern "C" - -} // namespace capi - -#endif // ICU4XFixedDecimal_H diff --git a/example/cpp2/include/ICU4XFixedDecimal.hpp b/example/cpp2/include/ICU4XFixedDecimal.hpp index 4c2de6585..c95f80aa9 100644 --- a/example/cpp2/include/ICU4XFixedDecimal.hpp +++ b/example/cpp2/include/ICU4XFixedDecimal.hpp @@ -10,9 +10,24 @@ #include #include #include "diplomat_runtime.hpp" -#include "ICU4XFixedDecimal.h" +namespace capi { + extern "C" { + + ICU4XFixedDecimal* ICU4XFixedDecimal_new(int32_t v); + + void ICU4XFixedDecimal_multiply_pow10(ICU4XFixedDecimal* self, int16_t power); + + struct ICU4XFixedDecimal_to_string_result { bool is_ok;}; + struct ICU4XFixedDecimal_to_string_result ICU4XFixedDecimal_to_string(const ICU4XFixedDecimal* self, DiplomatWrite* write); + + + void ICU4XFixedDecimal_destroy(ICU4XFixedDecimal* self); + + } // extern "C" +} + inline std::unique_ptr ICU4XFixedDecimal::new_(int32_t v) { auto result = capi::ICU4XFixedDecimal_new(v); return std::unique_ptr(ICU4XFixedDecimal::FromFFI(result)); diff --git a/example/cpp2/include/ICU4XFixedDecimalFormatter.d.h b/example/cpp2/include/ICU4XFixedDecimalFormatter.d.h deleted file mode 100644 index 42fb93618..000000000 --- a/example/cpp2/include/ICU4XFixedDecimalFormatter.d.h +++ /dev/null @@ -1,20 +0,0 @@ -#ifndef ICU4XFixedDecimalFormatter_D_H -#define ICU4XFixedDecimalFormatter_D_H - -#include -#include -#include -#include -#include "diplomat_runtime.h" - - -namespace capi { - - -typedef struct ICU4XFixedDecimalFormatter ICU4XFixedDecimalFormatter; - - - -} // namespace capi - -#endif // ICU4XFixedDecimalFormatter_D_H diff --git a/example/cpp2/include/ICU4XFixedDecimalFormatter.d.hpp b/example/cpp2/include/ICU4XFixedDecimalFormatter.d.hpp index 31616a878..c31dc2bb9 100644 --- a/example/cpp2/include/ICU4XFixedDecimalFormatter.d.hpp +++ b/example/cpp2/include/ICU4XFixedDecimalFormatter.d.hpp @@ -8,7 +8,6 @@ #include #include #include "diplomat_runtime.hpp" -#include "ICU4XFixedDecimalFormatter.d.h" #include "ICU4XFixedDecimalFormatterOptions.d.hpp" class ICU4XDataProvider; @@ -17,6 +16,10 @@ class ICU4XLocale; struct ICU4XFixedDecimalFormatterOptions; +namespace capi { + typedef struct ICU4XFixedDecimalFormatter ICU4XFixedDecimalFormatter; +} + class ICU4XFixedDecimalFormatter { public: diff --git a/example/cpp2/include/ICU4XFixedDecimalFormatter.h b/example/cpp2/include/ICU4XFixedDecimalFormatter.h deleted file mode 100644 index abc9131f8..000000000 --- a/example/cpp2/include/ICU4XFixedDecimalFormatter.h +++ /dev/null @@ -1,34 +0,0 @@ -#ifndef ICU4XFixedDecimalFormatter_H -#define ICU4XFixedDecimalFormatter_H - -#include -#include -#include -#include -#include "diplomat_runtime.h" - -#include "ICU4XDataProvider.d.h" -#include "ICU4XFixedDecimal.d.h" -#include "ICU4XFixedDecimalFormatterOptions.d.h" -#include "ICU4XLocale.d.h" - -#include "ICU4XFixedDecimalFormatter.d.h" - -namespace capi { - - -extern "C" { - -struct ICU4XFixedDecimalFormatter_try_new_result {union {ICU4XFixedDecimalFormatter* ok; }; bool is_ok;}; -struct ICU4XFixedDecimalFormatter_try_new_result ICU4XFixedDecimalFormatter_try_new(const ICU4XLocale* locale, const ICU4XDataProvider* provider, ICU4XFixedDecimalFormatterOptions options); - -void ICU4XFixedDecimalFormatter_format_write(const ICU4XFixedDecimalFormatter* self, const ICU4XFixedDecimal* value, DiplomatWrite* write); - - -void ICU4XFixedDecimalFormatter_destroy(ICU4XFixedDecimalFormatter* self); - -} // extern "C" - -} // namespace capi - -#endif // ICU4XFixedDecimalFormatter_H diff --git a/example/cpp2/include/ICU4XFixedDecimalFormatter.hpp b/example/cpp2/include/ICU4XFixedDecimalFormatter.hpp index 1a75e2f36..3e44149ae 100644 --- a/example/cpp2/include/ICU4XFixedDecimalFormatter.hpp +++ b/example/cpp2/include/ICU4XFixedDecimalFormatter.hpp @@ -12,11 +12,24 @@ #include "diplomat_runtime.hpp" #include "ICU4XDataProvider.hpp" #include "ICU4XFixedDecimal.hpp" -#include "ICU4XFixedDecimalFormatter.h" #include "ICU4XFixedDecimalFormatterOptions.hpp" #include "ICU4XLocale.hpp" +namespace capi { + extern "C" { + + struct ICU4XFixedDecimalFormatter_try_new_result {union {ICU4XFixedDecimalFormatter* ok; }; bool is_ok;}; + struct ICU4XFixedDecimalFormatter_try_new_result ICU4XFixedDecimalFormatter_try_new(const ICU4XLocale* locale, const ICU4XDataProvider* provider, ICU4XFixedDecimalFormatterOptions options); + + void ICU4XFixedDecimalFormatter_format_write(const ICU4XFixedDecimalFormatter* self, const ICU4XFixedDecimal* value, DiplomatWrite* write); + + + void ICU4XFixedDecimalFormatter_destroy(ICU4XFixedDecimalFormatter* self); + + } // extern "C" +} + inline diplomat::result, std::monostate> ICU4XFixedDecimalFormatter::try_new(const ICU4XLocale& locale, const ICU4XDataProvider& provider, ICU4XFixedDecimalFormatterOptions options) { auto result = capi::ICU4XFixedDecimalFormatter_try_new(locale.AsFFI(), provider.AsFFI(), diff --git a/example/cpp2/include/ICU4XFixedDecimalFormatterOptions.d.h b/example/cpp2/include/ICU4XFixedDecimalFormatterOptions.d.h deleted file mode 100644 index 8a6379933..000000000 --- a/example/cpp2/include/ICU4XFixedDecimalFormatterOptions.d.h +++ /dev/null @@ -1,24 +0,0 @@ -#ifndef ICU4XFixedDecimalFormatterOptions_D_H -#define ICU4XFixedDecimalFormatterOptions_D_H - -#include -#include -#include -#include -#include "diplomat_runtime.h" - -#include "ICU4XFixedDecimalGroupingStrategy.d.h" - -namespace capi { - - -typedef struct ICU4XFixedDecimalFormatterOptions { - ICU4XFixedDecimalGroupingStrategy grouping_strategy; - bool some_other_config; -} ICU4XFixedDecimalFormatterOptions; - - - -} // namespace capi - -#endif // ICU4XFixedDecimalFormatterOptions_D_H diff --git a/example/cpp2/include/ICU4XFixedDecimalFormatterOptions.d.hpp b/example/cpp2/include/ICU4XFixedDecimalFormatterOptions.d.hpp index 6f29b1666..6a62baeab 100644 --- a/example/cpp2/include/ICU4XFixedDecimalFormatterOptions.d.hpp +++ b/example/cpp2/include/ICU4XFixedDecimalFormatterOptions.d.hpp @@ -8,12 +8,18 @@ #include #include #include "diplomat_runtime.hpp" -#include "ICU4XFixedDecimalFormatterOptions.d.h" #include "ICU4XFixedDecimalGroupingStrategy.d.hpp" class ICU4XFixedDecimalGroupingStrategy; +namespace capi { + typedef struct ICU4XFixedDecimalFormatterOptions { + ICU4XFixedDecimalGroupingStrategy grouping_strategy; + bool some_other_config; + } ICU4XFixedDecimalFormatterOptions; +} + struct ICU4XFixedDecimalFormatterOptions { ICU4XFixedDecimalGroupingStrategy grouping_strategy; bool some_other_config; diff --git a/example/cpp2/include/ICU4XFixedDecimalFormatterOptions.h b/example/cpp2/include/ICU4XFixedDecimalFormatterOptions.h deleted file mode 100644 index 6893b8316..000000000 --- a/example/cpp2/include/ICU4XFixedDecimalFormatterOptions.h +++ /dev/null @@ -1,25 +0,0 @@ -#ifndef ICU4XFixedDecimalFormatterOptions_H -#define ICU4XFixedDecimalFormatterOptions_H - -#include -#include -#include -#include -#include "diplomat_runtime.h" - - -#include "ICU4XFixedDecimalFormatterOptions.d.h" - -namespace capi { - - -extern "C" { - -ICU4XFixedDecimalFormatterOptions ICU4XFixedDecimalFormatterOptions_default(); - - -} // extern "C" - -} // namespace capi - -#endif // ICU4XFixedDecimalFormatterOptions_H diff --git a/example/cpp2/include/ICU4XFixedDecimalFormatterOptions.hpp b/example/cpp2/include/ICU4XFixedDecimalFormatterOptions.hpp index b287290bd..f343f07a4 100644 --- a/example/cpp2/include/ICU4XFixedDecimalFormatterOptions.hpp +++ b/example/cpp2/include/ICU4XFixedDecimalFormatterOptions.hpp @@ -10,10 +10,18 @@ #include #include #include "diplomat_runtime.hpp" -#include "ICU4XFixedDecimalFormatterOptions.h" #include "ICU4XFixedDecimalGroupingStrategy.hpp" +namespace capi { + extern "C" { + + ICU4XFixedDecimalFormatterOptions ICU4XFixedDecimalFormatterOptions_default(); + + + } // extern "C" +} + inline ICU4XFixedDecimalFormatterOptions ICU4XFixedDecimalFormatterOptions::default_() { auto result = capi::ICU4XFixedDecimalFormatterOptions_default(); return ICU4XFixedDecimalFormatterOptions::FromFFI(result); diff --git a/example/cpp2/include/ICU4XFixedDecimalGroupingStrategy.d.h b/example/cpp2/include/ICU4XFixedDecimalGroupingStrategy.d.h deleted file mode 100644 index 8dede3bc8..000000000 --- a/example/cpp2/include/ICU4XFixedDecimalGroupingStrategy.d.h +++ /dev/null @@ -1,25 +0,0 @@ -#ifndef ICU4XFixedDecimalGroupingStrategy_D_H -#define ICU4XFixedDecimalGroupingStrategy_D_H - -#include -#include -#include -#include -#include "diplomat_runtime.h" - - -namespace capi { - - -typedef enum ICU4XFixedDecimalGroupingStrategy { - ICU4XFixedDecimalGroupingStrategy_Auto = 0, - ICU4XFixedDecimalGroupingStrategy_Never = 1, - ICU4XFixedDecimalGroupingStrategy_Always = 2, - ICU4XFixedDecimalGroupingStrategy_Min2 = 3, -} ICU4XFixedDecimalGroupingStrategy; - - - -} // namespace capi - -#endif // ICU4XFixedDecimalGroupingStrategy_D_H diff --git a/example/cpp2/include/ICU4XFixedDecimalGroupingStrategy.d.hpp b/example/cpp2/include/ICU4XFixedDecimalGroupingStrategy.d.hpp index cda9c1b20..559f88553 100644 --- a/example/cpp2/include/ICU4XFixedDecimalGroupingStrategy.d.hpp +++ b/example/cpp2/include/ICU4XFixedDecimalGroupingStrategy.d.hpp @@ -8,9 +8,17 @@ #include #include #include "diplomat_runtime.hpp" -#include "ICU4XFixedDecimalGroupingStrategy.d.h" +namespace capi { + typedef enum ICU4XFixedDecimalGroupingStrategy { + ICU4XFixedDecimalGroupingStrategy_Auto = 0, + ICU4XFixedDecimalGroupingStrategy_Never = 1, + ICU4XFixedDecimalGroupingStrategy_Always = 2, + ICU4XFixedDecimalGroupingStrategy_Min2 = 3, + } ICU4XFixedDecimalGroupingStrategy; +} + class ICU4XFixedDecimalGroupingStrategy { public: enum Value { diff --git a/example/cpp2/include/ICU4XFixedDecimalGroupingStrategy.h b/example/cpp2/include/ICU4XFixedDecimalGroupingStrategy.h deleted file mode 100644 index d9603d573..000000000 --- a/example/cpp2/include/ICU4XFixedDecimalGroupingStrategy.h +++ /dev/null @@ -1,23 +0,0 @@ -#ifndef ICU4XFixedDecimalGroupingStrategy_H -#define ICU4XFixedDecimalGroupingStrategy_H - -#include -#include -#include -#include -#include "diplomat_runtime.h" - - -#include "ICU4XFixedDecimalGroupingStrategy.d.h" - -namespace capi { - - -extern "C" { - - -} // extern "C" - -} // namespace capi - -#endif // ICU4XFixedDecimalGroupingStrategy_H diff --git a/example/cpp2/include/ICU4XFixedDecimalGroupingStrategy.hpp b/example/cpp2/include/ICU4XFixedDecimalGroupingStrategy.hpp index 068adea39..1703f9886 100644 --- a/example/cpp2/include/ICU4XFixedDecimalGroupingStrategy.hpp +++ b/example/cpp2/include/ICU4XFixedDecimalGroupingStrategy.hpp @@ -10,7 +10,14 @@ #include #include #include "diplomat_runtime.hpp" -#include "ICU4XFixedDecimalGroupingStrategy.h" + + +namespace capi { + extern "C" { + + + } // extern "C" +} inline capi::ICU4XFixedDecimalGroupingStrategy ICU4XFixedDecimalGroupingStrategy::AsFFI() const { diff --git a/example/cpp2/include/ICU4XLocale.d.h b/example/cpp2/include/ICU4XLocale.d.h deleted file mode 100644 index 47841fa68..000000000 --- a/example/cpp2/include/ICU4XLocale.d.h +++ /dev/null @@ -1,20 +0,0 @@ -#ifndef ICU4XLocale_D_H -#define ICU4XLocale_D_H - -#include -#include -#include -#include -#include "diplomat_runtime.h" - - -namespace capi { - - -typedef struct ICU4XLocale ICU4XLocale; - - - -} // namespace capi - -#endif // ICU4XLocale_D_H diff --git a/example/cpp2/include/ICU4XLocale.d.hpp b/example/cpp2/include/ICU4XLocale.d.hpp index d18ba44be..402a82408 100644 --- a/example/cpp2/include/ICU4XLocale.d.hpp +++ b/example/cpp2/include/ICU4XLocale.d.hpp @@ -8,9 +8,12 @@ #include #include #include "diplomat_runtime.hpp" -#include "ICU4XLocale.d.h" +namespace capi { + typedef struct ICU4XLocale ICU4XLocale; +} + class ICU4XLocale { public: diff --git a/example/cpp2/include/ICU4XLocale.h b/example/cpp2/include/ICU4XLocale.h deleted file mode 100644 index 8f9340ef5..000000000 --- a/example/cpp2/include/ICU4XLocale.h +++ /dev/null @@ -1,27 +0,0 @@ -#ifndef ICU4XLocale_H -#define ICU4XLocale_H - -#include -#include -#include -#include -#include "diplomat_runtime.h" - - -#include "ICU4XLocale.d.h" - -namespace capi { - - -extern "C" { - -ICU4XLocale* ICU4XLocale_new(const char* name_data, size_t name_len); - - -void ICU4XLocale_destroy(ICU4XLocale* self); - -} // extern "C" - -} // namespace capi - -#endif // ICU4XLocale_H diff --git a/example/cpp2/include/ICU4XLocale.hpp b/example/cpp2/include/ICU4XLocale.hpp index eab8f3bce..e99aebba4 100644 --- a/example/cpp2/include/ICU4XLocale.hpp +++ b/example/cpp2/include/ICU4XLocale.hpp @@ -10,9 +10,19 @@ #include #include #include "diplomat_runtime.hpp" -#include "ICU4XLocale.h" +namespace capi { + extern "C" { + + ICU4XLocale* ICU4XLocale_new(const char* name_data, size_t name_len); + + + void ICU4XLocale_destroy(ICU4XLocale* self); + + } // extern "C" +} + inline std::unique_ptr ICU4XLocale::new_(std::string_view name) { auto result = capi::ICU4XLocale_new(name.data(), name.size()); diff --git a/feature_tests/cpp2/include/AttrEnum.d.h b/feature_tests/cpp2/include/AttrEnum.d.h deleted file mode 100644 index 15f6c0763..000000000 --- a/feature_tests/cpp2/include/AttrEnum.d.h +++ /dev/null @@ -1,24 +0,0 @@ -#ifndef AttrEnum_D_H -#define AttrEnum_D_H - -#include -#include -#include -#include -#include "diplomat_runtime.h" - - -namespace capi { - - -typedef enum AttrEnum { - AttrEnum_A = 0, - AttrEnum_B = 1, - AttrEnum_C = 2, -} AttrEnum; - - - -} // namespace capi - -#endif // AttrEnum_D_H diff --git a/feature_tests/cpp2/include/AttrEnum.h b/feature_tests/cpp2/include/AttrEnum.h deleted file mode 100644 index 1dd13cf4c..000000000 --- a/feature_tests/cpp2/include/AttrEnum.h +++ /dev/null @@ -1,23 +0,0 @@ -#ifndef AttrEnum_H -#define AttrEnum_H - -#include -#include -#include -#include -#include "diplomat_runtime.h" - - -#include "AttrEnum.d.h" - -namespace capi { - - -extern "C" { - - -} // extern "C" - -} // namespace capi - -#endif // AttrEnum_H diff --git a/feature_tests/cpp2/include/AttrOpaque1.d.h b/feature_tests/cpp2/include/AttrOpaque1.d.h deleted file mode 100644 index 478bf76fb..000000000 --- a/feature_tests/cpp2/include/AttrOpaque1.d.h +++ /dev/null @@ -1,20 +0,0 @@ -#ifndef AttrOpaque1_D_H -#define AttrOpaque1_D_H - -#include -#include -#include -#include -#include "diplomat_runtime.h" - - -namespace capi { - - -typedef struct AttrOpaque1 AttrOpaque1; - - - -} // namespace capi - -#endif // AttrOpaque1_D_H diff --git a/feature_tests/cpp2/include/AttrOpaque1.h b/feature_tests/cpp2/include/AttrOpaque1.h deleted file mode 100644 index 87d1bebef..000000000 --- a/feature_tests/cpp2/include/AttrOpaque1.h +++ /dev/null @@ -1,37 +0,0 @@ -#ifndef AttrOpaque1_H -#define AttrOpaque1_H - -#include -#include -#include -#include -#include "diplomat_runtime.h" - -#include "AttrEnum.d.h" -#include "Unnamespaced.d.h" - -#include "AttrOpaque1.d.h" - -namespace capi { - - -extern "C" { - -AttrOpaque1* namespace_AttrOpaque1_new(); - -uint8_t namespace_AttrOpaque1_method(const AttrOpaque1* self); - -uint8_t renamed_on_abi_only(const AttrOpaque1* self); - -void namespace_AttrOpaque1_use_unnamespaced(const AttrOpaque1* self, const Unnamespaced* _un); - -void namespace_AttrOpaque1_use_namespaced(const AttrOpaque1* self, AttrEnum _n); - - -void namespace_AttrOpaque1_destroy(AttrOpaque1* self); - -} // extern "C" - -} // namespace capi - -#endif // AttrOpaque1_H diff --git a/feature_tests/cpp2/include/AttrOpaque1Renamed.d.hpp b/feature_tests/cpp2/include/AttrOpaque1Renamed.d.hpp index 7268655f1..25dfa8201 100644 --- a/feature_tests/cpp2/include/AttrOpaque1Renamed.d.hpp +++ b/feature_tests/cpp2/include/AttrOpaque1Renamed.d.hpp @@ -8,7 +8,6 @@ #include #include #include "diplomat_runtime.hpp" -#include "AttrOpaque1.d.h" #include "CPPRenamedAttrEnum.d.hpp" class Unnamespaced; @@ -18,6 +17,10 @@ class CPPRenamedAttrEnum; } +namespace capi { + typedef struct AttrOpaque1 AttrOpaque1; +} + namespace ns { class AttrOpaque1Renamed { public: diff --git a/feature_tests/cpp2/include/AttrOpaque1Renamed.hpp b/feature_tests/cpp2/include/AttrOpaque1Renamed.hpp index 21b85bef9..05007a2de 100644 --- a/feature_tests/cpp2/include/AttrOpaque1Renamed.hpp +++ b/feature_tests/cpp2/include/AttrOpaque1Renamed.hpp @@ -10,11 +10,29 @@ #include #include #include "diplomat_runtime.hpp" -#include "AttrOpaque1.h" #include "CPPRenamedAttrEnum.hpp" #include "Unnamespaced.hpp" +namespace capi { + extern "C" { + + AttrOpaque1* namespace_AttrOpaque1_new(); + + uint8_t namespace_AttrOpaque1_method(const AttrOpaque1* self); + + uint8_t renamed_on_abi_only(const AttrOpaque1* self); + + void namespace_AttrOpaque1_use_unnamespaced(const AttrOpaque1* self, const Unnamespaced* _un); + + void namespace_AttrOpaque1_use_namespaced(const AttrOpaque1* self, AttrEnum _n); + + + void namespace_AttrOpaque1_destroy(AttrOpaque1* self); + + } // extern "C" +} + inline std::unique_ptr ns::AttrOpaque1Renamed::totally_not_new() { auto result = capi::namespace_AttrOpaque1_new(); return std::unique_ptr(ns::AttrOpaque1Renamed::FromFFI(result)); diff --git a/feature_tests/cpp2/include/AttrOpaque2.d.h b/feature_tests/cpp2/include/AttrOpaque2.d.h deleted file mode 100644 index 199832f92..000000000 --- a/feature_tests/cpp2/include/AttrOpaque2.d.h +++ /dev/null @@ -1,20 +0,0 @@ -#ifndef AttrOpaque2_D_H -#define AttrOpaque2_D_H - -#include -#include -#include -#include -#include "diplomat_runtime.h" - - -namespace capi { - - -typedef struct AttrOpaque2 AttrOpaque2; - - - -} // namespace capi - -#endif // AttrOpaque2_D_H diff --git a/feature_tests/cpp2/include/AttrOpaque2.h b/feature_tests/cpp2/include/AttrOpaque2.h deleted file mode 100644 index f7dbbcaca..000000000 --- a/feature_tests/cpp2/include/AttrOpaque2.h +++ /dev/null @@ -1,25 +0,0 @@ -#ifndef AttrOpaque2_H -#define AttrOpaque2_H - -#include -#include -#include -#include -#include "diplomat_runtime.h" - - -#include "AttrOpaque2.d.h" - -namespace capi { - - -extern "C" { - - -void namespace_AttrOpaque2_destroy(AttrOpaque2* self); - -} // extern "C" - -} // namespace capi - -#endif // AttrOpaque2_H diff --git a/feature_tests/cpp2/include/Bar.d.h b/feature_tests/cpp2/include/Bar.d.h deleted file mode 100644 index 35b5aec25..000000000 --- a/feature_tests/cpp2/include/Bar.d.h +++ /dev/null @@ -1,20 +0,0 @@ -#ifndef Bar_D_H -#define Bar_D_H - -#include -#include -#include -#include -#include "diplomat_runtime.h" - - -namespace capi { - - -typedef struct Bar Bar; - - - -} // namespace capi - -#endif // Bar_D_H diff --git a/feature_tests/cpp2/include/Bar.d.hpp b/feature_tests/cpp2/include/Bar.d.hpp index 91e24a10d..7af995cf9 100644 --- a/feature_tests/cpp2/include/Bar.d.hpp +++ b/feature_tests/cpp2/include/Bar.d.hpp @@ -8,11 +8,14 @@ #include #include #include "diplomat_runtime.hpp" -#include "Bar.d.h" class Foo; +namespace capi { + typedef struct Bar Bar; +} + class Bar { public: diff --git a/feature_tests/cpp2/include/Bar.h b/feature_tests/cpp2/include/Bar.h deleted file mode 100644 index 89e74d2c3..000000000 --- a/feature_tests/cpp2/include/Bar.h +++ /dev/null @@ -1,28 +0,0 @@ -#ifndef Bar_H -#define Bar_H - -#include -#include -#include -#include -#include "diplomat_runtime.h" - -#include "Foo.d.h" - -#include "Bar.d.h" - -namespace capi { - - -extern "C" { - -const Foo* Bar_foo(const Bar* self); - - -void Bar_destroy(Bar* self); - -} // extern "C" - -} // namespace capi - -#endif // Bar_H diff --git a/feature_tests/cpp2/include/Bar.hpp b/feature_tests/cpp2/include/Bar.hpp index caf1fd600..29942602f 100644 --- a/feature_tests/cpp2/include/Bar.hpp +++ b/feature_tests/cpp2/include/Bar.hpp @@ -10,10 +10,20 @@ #include #include #include "diplomat_runtime.hpp" -#include "Bar.h" #include "Foo.hpp" +namespace capi { + extern "C" { + + const Foo* Bar_foo(const Bar* self); + + + void Bar_destroy(Bar* self); + + } // extern "C" +} + inline const Foo& Bar::foo() const { auto result = capi::Bar_foo(this->AsFFI()); return *Foo::FromFFI(result); diff --git a/feature_tests/cpp2/include/BorrowedFields.d.h b/feature_tests/cpp2/include/BorrowedFields.d.h deleted file mode 100644 index 284b6c738..000000000 --- a/feature_tests/cpp2/include/BorrowedFields.d.h +++ /dev/null @@ -1,24 +0,0 @@ -#ifndef BorrowedFields_D_H -#define BorrowedFields_D_H - -#include -#include -#include -#include -#include "diplomat_runtime.h" - - -namespace capi { - - -typedef struct BorrowedFields { - DiplomatString16View a; - DiplomatStringView b; - DiplomatStringView c; -} BorrowedFields; - - - -} // namespace capi - -#endif // BorrowedFields_D_H diff --git a/feature_tests/cpp2/include/BorrowedFields.d.hpp b/feature_tests/cpp2/include/BorrowedFields.d.hpp index a651544e7..c9964e203 100644 --- a/feature_tests/cpp2/include/BorrowedFields.d.hpp +++ b/feature_tests/cpp2/include/BorrowedFields.d.hpp @@ -8,11 +8,18 @@ #include #include #include "diplomat_runtime.hpp" -#include "BorrowedFields.d.h" class Bar; +namespace capi { + typedef struct BorrowedFields { + DiplomatString16View a; + DiplomatStringView b; + DiplomatStringView c; + } BorrowedFields; +} + struct BorrowedFields { std::u16string_view a; std::string_view b; diff --git a/feature_tests/cpp2/include/BorrowedFields.h b/feature_tests/cpp2/include/BorrowedFields.h deleted file mode 100644 index d9aaaa7b8..000000000 --- a/feature_tests/cpp2/include/BorrowedFields.h +++ /dev/null @@ -1,26 +0,0 @@ -#ifndef BorrowedFields_H -#define BorrowedFields_H - -#include -#include -#include -#include -#include "diplomat_runtime.h" - -#include "Bar.d.h" - -#include "BorrowedFields.d.h" - -namespace capi { - - -extern "C" { - -BorrowedFields BorrowedFields_from_bar_and_strings(const Bar* bar, const char16_t* dstr16_data, size_t dstr16_len, const char* utf8_str_data, size_t utf8_str_len); - - -} // extern "C" - -} // namespace capi - -#endif // BorrowedFields_H diff --git a/feature_tests/cpp2/include/BorrowedFields.hpp b/feature_tests/cpp2/include/BorrowedFields.hpp index 14d004404..da62bcabe 100644 --- a/feature_tests/cpp2/include/BorrowedFields.hpp +++ b/feature_tests/cpp2/include/BorrowedFields.hpp @@ -11,9 +11,17 @@ #include #include "diplomat_runtime.hpp" #include "Bar.hpp" -#include "BorrowedFields.h" +namespace capi { + extern "C" { + + BorrowedFields BorrowedFields_from_bar_and_strings(const Bar* bar, const char16_t* dstr16_data, size_t dstr16_len, const char* utf8_str_data, size_t utf8_str_len); + + + } // extern "C" +} + inline diplomat::result BorrowedFields::from_bar_and_strings(const Bar& bar, std::u16string_view dstr16, std::string_view utf8_str) { if (!capi::diplomat_is_str(utf8_str.data(), utf8_str.size())) { return diplomat::Err(diplomat::Utf8Error()); diff --git a/feature_tests/cpp2/include/BorrowedFieldsReturning.d.h b/feature_tests/cpp2/include/BorrowedFieldsReturning.d.h deleted file mode 100644 index 6845d297b..000000000 --- a/feature_tests/cpp2/include/BorrowedFieldsReturning.d.h +++ /dev/null @@ -1,22 +0,0 @@ -#ifndef BorrowedFieldsReturning_D_H -#define BorrowedFieldsReturning_D_H - -#include -#include -#include -#include -#include "diplomat_runtime.h" - - -namespace capi { - - -typedef struct BorrowedFieldsReturning { - DiplomatStringView bytes; -} BorrowedFieldsReturning; - - - -} // namespace capi - -#endif // BorrowedFieldsReturning_D_H diff --git a/feature_tests/cpp2/include/BorrowedFieldsReturning.d.hpp b/feature_tests/cpp2/include/BorrowedFieldsReturning.d.hpp index 0c5fe993b..86b01d0e5 100644 --- a/feature_tests/cpp2/include/BorrowedFieldsReturning.d.hpp +++ b/feature_tests/cpp2/include/BorrowedFieldsReturning.d.hpp @@ -8,9 +8,14 @@ #include #include #include "diplomat_runtime.hpp" -#include "BorrowedFieldsReturning.d.h" +namespace capi { + typedef struct BorrowedFieldsReturning { + DiplomatStringView bytes; + } BorrowedFieldsReturning; +} + struct BorrowedFieldsReturning { std::string_view bytes; diff --git a/feature_tests/cpp2/include/BorrowedFieldsReturning.h b/feature_tests/cpp2/include/BorrowedFieldsReturning.h deleted file mode 100644 index 72588db6d..000000000 --- a/feature_tests/cpp2/include/BorrowedFieldsReturning.h +++ /dev/null @@ -1,23 +0,0 @@ -#ifndef BorrowedFieldsReturning_H -#define BorrowedFieldsReturning_H - -#include -#include -#include -#include -#include "diplomat_runtime.h" - - -#include "BorrowedFieldsReturning.d.h" - -namespace capi { - - -extern "C" { - - -} // extern "C" - -} // namespace capi - -#endif // BorrowedFieldsReturning_H diff --git a/feature_tests/cpp2/include/BorrowedFieldsReturning.hpp b/feature_tests/cpp2/include/BorrowedFieldsReturning.hpp index c4722e3bb..f7d76f523 100644 --- a/feature_tests/cpp2/include/BorrowedFieldsReturning.hpp +++ b/feature_tests/cpp2/include/BorrowedFieldsReturning.hpp @@ -10,9 +10,15 @@ #include #include #include "diplomat_runtime.hpp" -#include "BorrowedFieldsReturning.h" +namespace capi { + extern "C" { + + + } // extern "C" +} + inline capi::BorrowedFieldsReturning BorrowedFieldsReturning::AsFFI() const { return capi::BorrowedFieldsReturning { diff --git a/feature_tests/cpp2/include/BorrowedFieldsWithBounds.d.h b/feature_tests/cpp2/include/BorrowedFieldsWithBounds.d.h deleted file mode 100644 index 3c342a20d..000000000 --- a/feature_tests/cpp2/include/BorrowedFieldsWithBounds.d.h +++ /dev/null @@ -1,24 +0,0 @@ -#ifndef BorrowedFieldsWithBounds_D_H -#define BorrowedFieldsWithBounds_D_H - -#include -#include -#include -#include -#include "diplomat_runtime.h" - - -namespace capi { - - -typedef struct BorrowedFieldsWithBounds { - DiplomatString16View field_a; - DiplomatStringView field_b; - DiplomatStringView field_c; -} BorrowedFieldsWithBounds; - - - -} // namespace capi - -#endif // BorrowedFieldsWithBounds_D_H diff --git a/feature_tests/cpp2/include/BorrowedFieldsWithBounds.d.hpp b/feature_tests/cpp2/include/BorrowedFieldsWithBounds.d.hpp index eedfb6d5d..6256c8a8b 100644 --- a/feature_tests/cpp2/include/BorrowedFieldsWithBounds.d.hpp +++ b/feature_tests/cpp2/include/BorrowedFieldsWithBounds.d.hpp @@ -8,11 +8,18 @@ #include #include #include "diplomat_runtime.hpp" -#include "BorrowedFieldsWithBounds.d.h" class Foo; +namespace capi { + typedef struct BorrowedFieldsWithBounds { + DiplomatString16View field_a; + DiplomatStringView field_b; + DiplomatStringView field_c; + } BorrowedFieldsWithBounds; +} + struct BorrowedFieldsWithBounds { std::u16string_view field_a; std::string_view field_b; diff --git a/feature_tests/cpp2/include/BorrowedFieldsWithBounds.h b/feature_tests/cpp2/include/BorrowedFieldsWithBounds.h deleted file mode 100644 index 335a32968..000000000 --- a/feature_tests/cpp2/include/BorrowedFieldsWithBounds.h +++ /dev/null @@ -1,26 +0,0 @@ -#ifndef BorrowedFieldsWithBounds_H -#define BorrowedFieldsWithBounds_H - -#include -#include -#include -#include -#include "diplomat_runtime.h" - -#include "Foo.d.h" - -#include "BorrowedFieldsWithBounds.d.h" - -namespace capi { - - -extern "C" { - -BorrowedFieldsWithBounds BorrowedFieldsWithBounds_from_foo_and_strings(const Foo* foo, const char16_t* dstr16_x_data, size_t dstr16_x_len, const char* utf8_str_z_data, size_t utf8_str_z_len); - - -} // extern "C" - -} // namespace capi - -#endif // BorrowedFieldsWithBounds_H diff --git a/feature_tests/cpp2/include/BorrowedFieldsWithBounds.hpp b/feature_tests/cpp2/include/BorrowedFieldsWithBounds.hpp index a4ade36c3..aab7b48f7 100644 --- a/feature_tests/cpp2/include/BorrowedFieldsWithBounds.hpp +++ b/feature_tests/cpp2/include/BorrowedFieldsWithBounds.hpp @@ -10,10 +10,18 @@ #include #include #include "diplomat_runtime.hpp" -#include "BorrowedFieldsWithBounds.h" #include "Foo.hpp" +namespace capi { + extern "C" { + + BorrowedFieldsWithBounds BorrowedFieldsWithBounds_from_foo_and_strings(const Foo* foo, const char16_t* dstr16_x_data, size_t dstr16_x_len, const char* utf8_str_z_data, size_t utf8_str_z_len); + + + } // extern "C" +} + inline diplomat::result BorrowedFieldsWithBounds::from_foo_and_strings(const Foo& foo, std::u16string_view dstr16_x, std::string_view utf8_str_z) { if (!capi::diplomat_is_str(utf8_str_z.data(), utf8_str_z.size())) { return diplomat::Err(diplomat::Utf8Error()); diff --git a/feature_tests/cpp2/include/CPPRenamedAttrEnum.d.hpp b/feature_tests/cpp2/include/CPPRenamedAttrEnum.d.hpp index 7c953a7a7..95cef376c 100644 --- a/feature_tests/cpp2/include/CPPRenamedAttrEnum.d.hpp +++ b/feature_tests/cpp2/include/CPPRenamedAttrEnum.d.hpp @@ -8,9 +8,16 @@ #include #include #include "diplomat_runtime.hpp" -#include "AttrEnum.d.h" +namespace capi { + typedef enum AttrEnum { + AttrEnum_A = 0, + AttrEnum_B = 1, + AttrEnum_C = 2, + } AttrEnum; +} + namespace ns { class CPPRenamedAttrEnum { public: diff --git a/feature_tests/cpp2/include/CPPRenamedAttrEnum.hpp b/feature_tests/cpp2/include/CPPRenamedAttrEnum.hpp index 73b181465..f7c639963 100644 --- a/feature_tests/cpp2/include/CPPRenamedAttrEnum.hpp +++ b/feature_tests/cpp2/include/CPPRenamedAttrEnum.hpp @@ -10,7 +10,14 @@ #include #include #include "diplomat_runtime.hpp" -#include "AttrEnum.h" + + +namespace capi { + extern "C" { + + + } // extern "C" +} inline capi::AttrEnum ns::CPPRenamedAttrEnum::AsFFI() const { diff --git a/feature_tests/cpp2/include/CPPRenamedAttrOpaque2.d.hpp b/feature_tests/cpp2/include/CPPRenamedAttrOpaque2.d.hpp index 0db5dabd8..df8dca681 100644 --- a/feature_tests/cpp2/include/CPPRenamedAttrOpaque2.d.hpp +++ b/feature_tests/cpp2/include/CPPRenamedAttrOpaque2.d.hpp @@ -8,9 +8,12 @@ #include #include #include "diplomat_runtime.hpp" -#include "AttrOpaque2.d.h" +namespace capi { + typedef struct AttrOpaque2 AttrOpaque2; +} + namespace ns { class CPPRenamedAttrOpaque2 { public: diff --git a/feature_tests/cpp2/include/CPPRenamedAttrOpaque2.hpp b/feature_tests/cpp2/include/CPPRenamedAttrOpaque2.hpp index 2ca7711dc..f3792ff3e 100644 --- a/feature_tests/cpp2/include/CPPRenamedAttrOpaque2.hpp +++ b/feature_tests/cpp2/include/CPPRenamedAttrOpaque2.hpp @@ -10,9 +10,17 @@ #include #include #include "diplomat_runtime.hpp" -#include "AttrOpaque2.h" +namespace capi { + extern "C" { + + + void namespace_AttrOpaque2_destroy(AttrOpaque2* self); + + } // extern "C" +} + inline const capi::AttrOpaque2* ns::CPPRenamedAttrOpaque2::AsFFI() const { return reinterpret_cast(this); } diff --git a/feature_tests/cpp2/include/ContiguousEnum.d.h b/feature_tests/cpp2/include/ContiguousEnum.d.h deleted file mode 100644 index 6873e7b74..000000000 --- a/feature_tests/cpp2/include/ContiguousEnum.d.h +++ /dev/null @@ -1,25 +0,0 @@ -#ifndef ContiguousEnum_D_H -#define ContiguousEnum_D_H - -#include -#include -#include -#include -#include "diplomat_runtime.h" - - -namespace capi { - - -typedef enum ContiguousEnum { - ContiguousEnum_C = 0, - ContiguousEnum_D = 1, - ContiguousEnum_E = 2, - ContiguousEnum_F = 3, -} ContiguousEnum; - - - -} // namespace capi - -#endif // ContiguousEnum_D_H diff --git a/feature_tests/cpp2/include/ContiguousEnum.d.hpp b/feature_tests/cpp2/include/ContiguousEnum.d.hpp index 8b10990e0..de16c94d6 100644 --- a/feature_tests/cpp2/include/ContiguousEnum.d.hpp +++ b/feature_tests/cpp2/include/ContiguousEnum.d.hpp @@ -8,9 +8,17 @@ #include #include #include "diplomat_runtime.hpp" -#include "ContiguousEnum.d.h" +namespace capi { + typedef enum ContiguousEnum { + ContiguousEnum_C = 0, + ContiguousEnum_D = 1, + ContiguousEnum_E = 2, + ContiguousEnum_F = 3, + } ContiguousEnum; +} + class ContiguousEnum { public: enum Value { diff --git a/feature_tests/cpp2/include/ContiguousEnum.h b/feature_tests/cpp2/include/ContiguousEnum.h deleted file mode 100644 index 49eee3982..000000000 --- a/feature_tests/cpp2/include/ContiguousEnum.h +++ /dev/null @@ -1,23 +0,0 @@ -#ifndef ContiguousEnum_H -#define ContiguousEnum_H - -#include -#include -#include -#include -#include "diplomat_runtime.h" - - -#include "ContiguousEnum.d.h" - -namespace capi { - - -extern "C" { - - -} // extern "C" - -} // namespace capi - -#endif // ContiguousEnum_H diff --git a/feature_tests/cpp2/include/ContiguousEnum.hpp b/feature_tests/cpp2/include/ContiguousEnum.hpp index cebe3b167..a8d3e4722 100644 --- a/feature_tests/cpp2/include/ContiguousEnum.hpp +++ b/feature_tests/cpp2/include/ContiguousEnum.hpp @@ -10,7 +10,14 @@ #include #include #include "diplomat_runtime.hpp" -#include "ContiguousEnum.h" + + +namespace capi { + extern "C" { + + + } // extern "C" +} inline capi::ContiguousEnum ContiguousEnum::AsFFI() const { diff --git a/feature_tests/cpp2/include/ErrorEnum.d.h b/feature_tests/cpp2/include/ErrorEnum.d.h deleted file mode 100644 index 71215c371..000000000 --- a/feature_tests/cpp2/include/ErrorEnum.d.h +++ /dev/null @@ -1,23 +0,0 @@ -#ifndef ErrorEnum_D_H -#define ErrorEnum_D_H - -#include -#include -#include -#include -#include "diplomat_runtime.h" - - -namespace capi { - - -typedef enum ErrorEnum { - ErrorEnum_Foo = 0, - ErrorEnum_Bar = 1, -} ErrorEnum; - - - -} // namespace capi - -#endif // ErrorEnum_D_H diff --git a/feature_tests/cpp2/include/ErrorEnum.d.hpp b/feature_tests/cpp2/include/ErrorEnum.d.hpp index 0e75aaf40..99bf99d26 100644 --- a/feature_tests/cpp2/include/ErrorEnum.d.hpp +++ b/feature_tests/cpp2/include/ErrorEnum.d.hpp @@ -8,9 +8,15 @@ #include #include #include "diplomat_runtime.hpp" -#include "ErrorEnum.d.h" +namespace capi { + typedef enum ErrorEnum { + ErrorEnum_Foo = 0, + ErrorEnum_Bar = 1, + } ErrorEnum; +} + class ErrorEnum { public: enum Value { diff --git a/feature_tests/cpp2/include/ErrorEnum.h b/feature_tests/cpp2/include/ErrorEnum.h deleted file mode 100644 index 5788d9b92..000000000 --- a/feature_tests/cpp2/include/ErrorEnum.h +++ /dev/null @@ -1,23 +0,0 @@ -#ifndef ErrorEnum_H -#define ErrorEnum_H - -#include -#include -#include -#include -#include "diplomat_runtime.h" - - -#include "ErrorEnum.d.h" - -namespace capi { - - -extern "C" { - - -} // extern "C" - -} // namespace capi - -#endif // ErrorEnum_H diff --git a/feature_tests/cpp2/include/ErrorEnum.hpp b/feature_tests/cpp2/include/ErrorEnum.hpp index 8e7b14947..33a97bef4 100644 --- a/feature_tests/cpp2/include/ErrorEnum.hpp +++ b/feature_tests/cpp2/include/ErrorEnum.hpp @@ -10,7 +10,14 @@ #include #include #include "diplomat_runtime.hpp" -#include "ErrorEnum.h" + + +namespace capi { + extern "C" { + + + } // extern "C" +} inline capi::ErrorEnum ErrorEnum::AsFFI() const { diff --git a/feature_tests/cpp2/include/ErrorStruct.d.h b/feature_tests/cpp2/include/ErrorStruct.d.h deleted file mode 100644 index cd568e894..000000000 --- a/feature_tests/cpp2/include/ErrorStruct.d.h +++ /dev/null @@ -1,23 +0,0 @@ -#ifndef ErrorStruct_D_H -#define ErrorStruct_D_H - -#include -#include -#include -#include -#include "diplomat_runtime.h" - - -namespace capi { - - -typedef struct ErrorStruct { - int32_t i; - int32_t j; -} ErrorStruct; - - - -} // namespace capi - -#endif // ErrorStruct_D_H diff --git a/feature_tests/cpp2/include/ErrorStruct.d.hpp b/feature_tests/cpp2/include/ErrorStruct.d.hpp index 25e1079c7..df399bb16 100644 --- a/feature_tests/cpp2/include/ErrorStruct.d.hpp +++ b/feature_tests/cpp2/include/ErrorStruct.d.hpp @@ -8,9 +8,15 @@ #include #include #include "diplomat_runtime.hpp" -#include "ErrorStruct.d.h" +namespace capi { + typedef struct ErrorStruct { + int32_t i; + int32_t j; + } ErrorStruct; +} + struct ErrorStruct { int32_t i; int32_t j; diff --git a/feature_tests/cpp2/include/ErrorStruct.h b/feature_tests/cpp2/include/ErrorStruct.h deleted file mode 100644 index b042d4f50..000000000 --- a/feature_tests/cpp2/include/ErrorStruct.h +++ /dev/null @@ -1,23 +0,0 @@ -#ifndef ErrorStruct_H -#define ErrorStruct_H - -#include -#include -#include -#include -#include "diplomat_runtime.h" - - -#include "ErrorStruct.d.h" - -namespace capi { - - -extern "C" { - - -} // extern "C" - -} // namespace capi - -#endif // ErrorStruct_H diff --git a/feature_tests/cpp2/include/ErrorStruct.hpp b/feature_tests/cpp2/include/ErrorStruct.hpp index 009597293..87afb7132 100644 --- a/feature_tests/cpp2/include/ErrorStruct.hpp +++ b/feature_tests/cpp2/include/ErrorStruct.hpp @@ -10,9 +10,15 @@ #include #include #include "diplomat_runtime.hpp" -#include "ErrorStruct.h" +namespace capi { + extern "C" { + + + } // extern "C" +} + inline capi::ErrorStruct ErrorStruct::AsFFI() const { return capi::ErrorStruct { diff --git a/feature_tests/cpp2/include/Float64Vec.d.h b/feature_tests/cpp2/include/Float64Vec.d.h deleted file mode 100644 index 74ab64931..000000000 --- a/feature_tests/cpp2/include/Float64Vec.d.h +++ /dev/null @@ -1,20 +0,0 @@ -#ifndef Float64Vec_D_H -#define Float64Vec_D_H - -#include -#include -#include -#include -#include "diplomat_runtime.h" - - -namespace capi { - - -typedef struct Float64Vec Float64Vec; - - - -} // namespace capi - -#endif // Float64Vec_D_H diff --git a/feature_tests/cpp2/include/Float64Vec.d.hpp b/feature_tests/cpp2/include/Float64Vec.d.hpp index 7599382ca..d9a422de0 100644 --- a/feature_tests/cpp2/include/Float64Vec.d.hpp +++ b/feature_tests/cpp2/include/Float64Vec.d.hpp @@ -8,9 +8,12 @@ #include #include #include "diplomat_runtime.hpp" -#include "Float64Vec.d.h" +namespace capi { + typedef struct Float64Vec Float64Vec; +} + class Float64Vec { public: diff --git a/feature_tests/cpp2/include/Float64Vec.h b/feature_tests/cpp2/include/Float64Vec.h deleted file mode 100644 index 8e2d14c86..000000000 --- a/feature_tests/cpp2/include/Float64Vec.h +++ /dev/null @@ -1,54 +0,0 @@ -#ifndef Float64Vec_H -#define Float64Vec_H - -#include -#include -#include -#include -#include "diplomat_runtime.h" - - -#include "Float64Vec.d.h" - -namespace capi { - - -extern "C" { - -Float64Vec* Float64Vec_new(const double* v_data, size_t v_len); - -Float64Vec* Float64Vec_new_bool(const bool* v_data, size_t v_len); - -Float64Vec* Float64Vec_new_i16(const int16_t* v_data, size_t v_len); - -Float64Vec* Float64Vec_new_u16(const uint16_t* v_data, size_t v_len); - -Float64Vec* Float64Vec_new_isize(const intptr_t* v_data, size_t v_len); - -Float64Vec* Float64Vec_new_usize(const size_t* v_data, size_t v_len); - -Float64Vec* Float64Vec_new_f64_be_bytes(const uint8_t* v_data, size_t v_len); - -DiplomatF64View Float64Vec_as_boxed_slice(const Float64Vec* self); - -DiplomatF64View Float64Vec_as_slice(const Float64Vec* self); - -void Float64Vec_fill_slice(const Float64Vec* self, double* v_data, size_t v_len); - -void Float64Vec_set_value(Float64Vec* self, const double* new_slice_data, size_t new_slice_len); - -void Float64Vec_to_string(const Float64Vec* self, DiplomatWrite* write); - -DiplomatF64View Float64Vec_borrow(const Float64Vec* self); - -struct Float64Vec_get_result {union {double ok; }; bool is_ok;}; -struct Float64Vec_get_result Float64Vec_get(const Float64Vec* self, size_t i); - - -void Float64Vec_destroy(Float64Vec* self); - -} // extern "C" - -} // namespace capi - -#endif // Float64Vec_H diff --git a/feature_tests/cpp2/include/Float64Vec.hpp b/feature_tests/cpp2/include/Float64Vec.hpp index 1bef39de9..e8d52c3af 100644 --- a/feature_tests/cpp2/include/Float64Vec.hpp +++ b/feature_tests/cpp2/include/Float64Vec.hpp @@ -10,9 +10,46 @@ #include #include #include "diplomat_runtime.hpp" -#include "Float64Vec.h" +namespace capi { + extern "C" { + + Float64Vec* Float64Vec_new(const double* v_data, size_t v_len); + + Float64Vec* Float64Vec_new_bool(const bool* v_data, size_t v_len); + + Float64Vec* Float64Vec_new_i16(const int16_t* v_data, size_t v_len); + + Float64Vec* Float64Vec_new_u16(const uint16_t* v_data, size_t v_len); + + Float64Vec* Float64Vec_new_isize(const intptr_t* v_data, size_t v_len); + + Float64Vec* Float64Vec_new_usize(const size_t* v_data, size_t v_len); + + Float64Vec* Float64Vec_new_f64_be_bytes(const uint8_t* v_data, size_t v_len); + + DiplomatF64View Float64Vec_as_boxed_slice(const Float64Vec* self); + + DiplomatF64View Float64Vec_as_slice(const Float64Vec* self); + + void Float64Vec_fill_slice(const Float64Vec* self, double* v_data, size_t v_len); + + void Float64Vec_set_value(Float64Vec* self, const double* new_slice_data, size_t new_slice_len); + + void Float64Vec_to_string(const Float64Vec* self, DiplomatWrite* write); + + DiplomatF64View Float64Vec_borrow(const Float64Vec* self); + + struct Float64Vec_get_result {union {double ok; }; bool is_ok;}; + struct Float64Vec_get_result Float64Vec_get(const Float64Vec* self, size_t i); + + + void Float64Vec_destroy(Float64Vec* self); + + } // extern "C" +} + inline std::unique_ptr Float64Vec::new_(diplomat::span v) { auto result = capi::Float64Vec_new(v.data(), v.size()); diff --git a/feature_tests/cpp2/include/Foo.d.h b/feature_tests/cpp2/include/Foo.d.h deleted file mode 100644 index 7b535dd3e..000000000 --- a/feature_tests/cpp2/include/Foo.d.h +++ /dev/null @@ -1,20 +0,0 @@ -#ifndef Foo_D_H -#define Foo_D_H - -#include -#include -#include -#include -#include "diplomat_runtime.h" - - -namespace capi { - - -typedef struct Foo Foo; - - - -} // namespace capi - -#endif // Foo_D_H diff --git a/feature_tests/cpp2/include/Foo.d.hpp b/feature_tests/cpp2/include/Foo.d.hpp index 9a8ef9183..17bd5f5c2 100644 --- a/feature_tests/cpp2/include/Foo.d.hpp +++ b/feature_tests/cpp2/include/Foo.d.hpp @@ -11,7 +11,6 @@ #include "BorrowedFields.d.hpp" #include "BorrowedFieldsReturning.d.hpp" #include "BorrowedFieldsWithBounds.d.hpp" -#include "Foo.d.h" class Bar; struct BorrowedFields; @@ -19,6 +18,10 @@ struct BorrowedFieldsReturning; struct BorrowedFieldsWithBounds; +namespace capi { + typedef struct Foo Foo; +} + class Foo { public: diff --git a/feature_tests/cpp2/include/Foo.h b/feature_tests/cpp2/include/Foo.h deleted file mode 100644 index 45e5112bc..000000000 --- a/feature_tests/cpp2/include/Foo.h +++ /dev/null @@ -1,41 +0,0 @@ -#ifndef Foo_H -#define Foo_H - -#include -#include -#include -#include -#include "diplomat_runtime.h" - -#include "Bar.d.h" -#include "BorrowedFields.d.h" -#include "BorrowedFieldsReturning.d.h" -#include "BorrowedFieldsWithBounds.d.h" - -#include "Foo.d.h" - -namespace capi { - - -extern "C" { - -Foo* Foo_new(const char* x_data, size_t x_len); - -Bar* Foo_get_bar(const Foo* self); - -Foo* Foo_new_static(const char* x_data, size_t x_len); - -BorrowedFieldsReturning Foo_as_returning(const Foo* self); - -Foo* Foo_extract_from_fields(BorrowedFields fields); - -Foo* Foo_extract_from_bounds(BorrowedFieldsWithBounds bounds, const char* another_string_data, size_t another_string_len); - - -void Foo_destroy(Foo* self); - -} // extern "C" - -} // namespace capi - -#endif // Foo_H diff --git a/feature_tests/cpp2/include/Foo.hpp b/feature_tests/cpp2/include/Foo.hpp index 0b856871a..ce4b7bba8 100644 --- a/feature_tests/cpp2/include/Foo.hpp +++ b/feature_tests/cpp2/include/Foo.hpp @@ -14,9 +14,29 @@ #include "BorrowedFields.hpp" #include "BorrowedFieldsReturning.hpp" #include "BorrowedFieldsWithBounds.hpp" -#include "Foo.h" +namespace capi { + extern "C" { + + Foo* Foo_new(const char* x_data, size_t x_len); + + Bar* Foo_get_bar(const Foo* self); + + Foo* Foo_new_static(const char* x_data, size_t x_len); + + BorrowedFieldsReturning Foo_as_returning(const Foo* self); + + Foo* Foo_extract_from_fields(BorrowedFields fields); + + Foo* Foo_extract_from_bounds(BorrowedFieldsWithBounds bounds, const char* another_string_data, size_t another_string_len); + + + void Foo_destroy(Foo* self); + + } // extern "C" +} + inline std::unique_ptr Foo::new_(std::string_view x) { auto result = capi::Foo_new(x.data(), x.size()); diff --git a/feature_tests/cpp2/include/ImportedStruct.d.h b/feature_tests/cpp2/include/ImportedStruct.d.h deleted file mode 100644 index 336d96177..000000000 --- a/feature_tests/cpp2/include/ImportedStruct.d.h +++ /dev/null @@ -1,24 +0,0 @@ -#ifndef ImportedStruct_D_H -#define ImportedStruct_D_H - -#include -#include -#include -#include -#include "diplomat_runtime.h" - -#include "UnimportedEnum.d.h" - -namespace capi { - - -typedef struct ImportedStruct { - UnimportedEnum foo; - uint8_t count; -} ImportedStruct; - - - -} // namespace capi - -#endif // ImportedStruct_D_H diff --git a/feature_tests/cpp2/include/ImportedStruct.d.hpp b/feature_tests/cpp2/include/ImportedStruct.d.hpp index 30df7c046..d03898fb3 100644 --- a/feature_tests/cpp2/include/ImportedStruct.d.hpp +++ b/feature_tests/cpp2/include/ImportedStruct.d.hpp @@ -8,12 +8,18 @@ #include #include #include "diplomat_runtime.hpp" -#include "ImportedStruct.d.h" #include "UnimportedEnum.d.hpp" class UnimportedEnum; +namespace capi { + typedef struct ImportedStruct { + UnimportedEnum foo; + uint8_t count; + } ImportedStruct; +} + struct ImportedStruct { UnimportedEnum foo; uint8_t count; diff --git a/feature_tests/cpp2/include/ImportedStruct.h b/feature_tests/cpp2/include/ImportedStruct.h deleted file mode 100644 index 4dc84cf34..000000000 --- a/feature_tests/cpp2/include/ImportedStruct.h +++ /dev/null @@ -1,23 +0,0 @@ -#ifndef ImportedStruct_H -#define ImportedStruct_H - -#include -#include -#include -#include -#include "diplomat_runtime.h" - - -#include "ImportedStruct.d.h" - -namespace capi { - - -extern "C" { - - -} // extern "C" - -} // namespace capi - -#endif // ImportedStruct_H diff --git a/feature_tests/cpp2/include/ImportedStruct.hpp b/feature_tests/cpp2/include/ImportedStruct.hpp index 755d2330e..a4f15f45d 100644 --- a/feature_tests/cpp2/include/ImportedStruct.hpp +++ b/feature_tests/cpp2/include/ImportedStruct.hpp @@ -10,10 +10,16 @@ #include #include #include "diplomat_runtime.hpp" -#include "ImportedStruct.h" #include "UnimportedEnum.hpp" +namespace capi { + extern "C" { + + + } // extern "C" +} + inline capi::ImportedStruct ImportedStruct::AsFFI() const { return capi::ImportedStruct { diff --git a/feature_tests/cpp2/include/MyEnum.d.h b/feature_tests/cpp2/include/MyEnum.d.h deleted file mode 100644 index ec7b19200..000000000 --- a/feature_tests/cpp2/include/MyEnum.d.h +++ /dev/null @@ -1,27 +0,0 @@ -#ifndef MyEnum_D_H -#define MyEnum_D_H - -#include -#include -#include -#include -#include "diplomat_runtime.h" - - -namespace capi { - - -typedef enum MyEnum { - MyEnum_A = -2, - MyEnum_B = -1, - MyEnum_C = 0, - MyEnum_D = 1, - MyEnum_E = 2, - MyEnum_F = 3, -} MyEnum; - - - -} // namespace capi - -#endif // MyEnum_D_H diff --git a/feature_tests/cpp2/include/MyEnum.d.hpp b/feature_tests/cpp2/include/MyEnum.d.hpp index 32f419ac8..93e59b716 100644 --- a/feature_tests/cpp2/include/MyEnum.d.hpp +++ b/feature_tests/cpp2/include/MyEnum.d.hpp @@ -8,9 +8,19 @@ #include #include #include "diplomat_runtime.hpp" -#include "MyEnum.d.h" +namespace capi { + typedef enum MyEnum { + MyEnum_A = -2, + MyEnum_B = -1, + MyEnum_C = 0, + MyEnum_D = 1, + MyEnum_E = 2, + MyEnum_F = 3, + } MyEnum; +} + class MyEnum { public: enum Value { diff --git a/feature_tests/cpp2/include/MyEnum.h b/feature_tests/cpp2/include/MyEnum.h deleted file mode 100644 index b372830e3..000000000 --- a/feature_tests/cpp2/include/MyEnum.h +++ /dev/null @@ -1,27 +0,0 @@ -#ifndef MyEnum_H -#define MyEnum_H - -#include -#include -#include -#include -#include "diplomat_runtime.h" - - -#include "MyEnum.d.h" - -namespace capi { - - -extern "C" { - -int8_t MyEnum_into_value(MyEnum self); - -MyEnum MyEnum_get_a(); - - -} // extern "C" - -} // namespace capi - -#endif // MyEnum_H diff --git a/feature_tests/cpp2/include/MyEnum.hpp b/feature_tests/cpp2/include/MyEnum.hpp index 01bf23b38..3f0e3652a 100644 --- a/feature_tests/cpp2/include/MyEnum.hpp +++ b/feature_tests/cpp2/include/MyEnum.hpp @@ -10,7 +10,18 @@ #include #include #include "diplomat_runtime.hpp" -#include "MyEnum.h" + + +namespace capi { + extern "C" { + + int8_t MyEnum_into_value(MyEnum self); + + MyEnum MyEnum_get_a(); + + + } // extern "C" +} inline capi::MyEnum MyEnum::AsFFI() const { diff --git a/feature_tests/cpp2/include/MyString.d.h b/feature_tests/cpp2/include/MyString.d.h deleted file mode 100644 index c5c33397c..000000000 --- a/feature_tests/cpp2/include/MyString.d.h +++ /dev/null @@ -1,20 +0,0 @@ -#ifndef MyString_D_H -#define MyString_D_H - -#include -#include -#include -#include -#include "diplomat_runtime.h" - - -namespace capi { - - -typedef struct MyString MyString; - - - -} // namespace capi - -#endif // MyString_D_H diff --git a/feature_tests/cpp2/include/MyString.d.hpp b/feature_tests/cpp2/include/MyString.d.hpp index 2e255d8f9..e30f4f686 100644 --- a/feature_tests/cpp2/include/MyString.d.hpp +++ b/feature_tests/cpp2/include/MyString.d.hpp @@ -8,9 +8,12 @@ #include #include #include "diplomat_runtime.hpp" -#include "MyString.d.h" +namespace capi { + typedef struct MyString MyString; +} + class MyString { public: diff --git a/feature_tests/cpp2/include/MyString.h b/feature_tests/cpp2/include/MyString.h deleted file mode 100644 index 99707e01e..000000000 --- a/feature_tests/cpp2/include/MyString.h +++ /dev/null @@ -1,39 +0,0 @@ -#ifndef MyString_H -#define MyString_H - -#include -#include -#include -#include -#include "diplomat_runtime.h" - - -#include "MyString.d.h" - -namespace capi { - - -extern "C" { - -MyString* MyString_new(const char* v_data, size_t v_len); - -MyString* MyString_new_unsafe(const char* v_data, size_t v_len); - -MyString* MyString_new_owned(const char* v_data, size_t v_len); - -MyString* MyString_new_from_first(DiplomatStringsView* v_data, size_t v_len); - -void MyString_set_str(MyString* self, const char* new_str_data, size_t new_str_len); - -void MyString_get_str(const MyString* self, DiplomatWrite* write); - -DiplomatStringView MyString_get_boxed_str(const MyString* self); - - -void MyString_destroy(MyString* self); - -} // extern "C" - -} // namespace capi - -#endif // MyString_H diff --git a/feature_tests/cpp2/include/MyString.hpp b/feature_tests/cpp2/include/MyString.hpp index 3f5541adc..8c3121c92 100644 --- a/feature_tests/cpp2/include/MyString.hpp +++ b/feature_tests/cpp2/include/MyString.hpp @@ -10,9 +10,31 @@ #include #include #include "diplomat_runtime.hpp" -#include "MyString.h" +namespace capi { + extern "C" { + + MyString* MyString_new(const char* v_data, size_t v_len); + + MyString* MyString_new_unsafe(const char* v_data, size_t v_len); + + MyString* MyString_new_owned(const char* v_data, size_t v_len); + + MyString* MyString_new_from_first(DiplomatStringsView* v_data, size_t v_len); + + void MyString_set_str(MyString* self, const char* new_str_data, size_t new_str_len); + + void MyString_get_str(const MyString* self, DiplomatWrite* write); + + DiplomatStringView MyString_get_boxed_str(const MyString* self); + + + void MyString_destroy(MyString* self); + + } // extern "C" +} + inline std::unique_ptr MyString::new_(std::string_view v) { auto result = capi::MyString_new(v.data(), v.size()); diff --git a/feature_tests/cpp2/include/MyStruct.d.h b/feature_tests/cpp2/include/MyStruct.d.h deleted file mode 100644 index a6e3544f9..000000000 --- a/feature_tests/cpp2/include/MyStruct.d.h +++ /dev/null @@ -1,29 +0,0 @@ -#ifndef MyStruct_D_H -#define MyStruct_D_H - -#include -#include -#include -#include -#include "diplomat_runtime.h" - -#include "MyEnum.d.h" - -namespace capi { - - -typedef struct MyStruct { - uint8_t a; - bool b; - uint8_t c; - uint64_t d; - int32_t e; - char32_t f; - MyEnum g; -} MyStruct; - - - -} // namespace capi - -#endif // MyStruct_D_H diff --git a/feature_tests/cpp2/include/MyStruct.d.hpp b/feature_tests/cpp2/include/MyStruct.d.hpp index 53fc23070..c22a19699 100644 --- a/feature_tests/cpp2/include/MyStruct.d.hpp +++ b/feature_tests/cpp2/include/MyStruct.d.hpp @@ -9,13 +9,24 @@ #include #include "diplomat_runtime.hpp" #include "MyEnum.d.hpp" -#include "MyStruct.d.h" #include "MyZst.d.hpp" struct MyZst; class MyEnum; +namespace capi { + typedef struct MyStruct { + uint8_t a; + bool b; + uint8_t c; + uint64_t d; + int32_t e; + char32_t f; + MyEnum g; + } MyStruct; +} + struct MyStruct { uint8_t a; bool b; diff --git a/feature_tests/cpp2/include/MyStruct.h b/feature_tests/cpp2/include/MyStruct.h deleted file mode 100644 index f7f09e7bc..000000000 --- a/feature_tests/cpp2/include/MyStruct.h +++ /dev/null @@ -1,30 +0,0 @@ -#ifndef MyStruct_H -#define MyStruct_H - -#include -#include -#include -#include -#include "diplomat_runtime.h" - - -#include "MyStruct.d.h" - -namespace capi { - - -extern "C" { - -MyStruct MyStruct_new(); - -uint8_t MyStruct_into_a(MyStruct self); - -struct MyStruct_returns_zst_result_result { bool is_ok;}; -struct MyStruct_returns_zst_result_result MyStruct_returns_zst_result(); - - -} // extern "C" - -} // namespace capi - -#endif // MyStruct_H diff --git a/feature_tests/cpp2/include/MyStruct.hpp b/feature_tests/cpp2/include/MyStruct.hpp index 9191f5108..504b5d0e6 100644 --- a/feature_tests/cpp2/include/MyStruct.hpp +++ b/feature_tests/cpp2/include/MyStruct.hpp @@ -11,10 +11,23 @@ #include #include "diplomat_runtime.hpp" #include "MyEnum.hpp" -#include "MyStruct.h" #include "MyZst.hpp" +namespace capi { + extern "C" { + + MyStruct MyStruct_new(); + + uint8_t MyStruct_into_a(MyStruct self); + + struct MyStruct_returns_zst_result_result { bool is_ok;}; + struct MyStruct_returns_zst_result_result MyStruct_returns_zst_result(); + + + } // extern "C" +} + inline MyStruct MyStruct::new_() { auto result = capi::MyStruct_new(); return MyStruct::FromFFI(result); diff --git a/feature_tests/cpp2/include/MyZst.d.hpp b/feature_tests/cpp2/include/MyZst.d.hpp index 9133753e4..9936750e6 100644 --- a/feature_tests/cpp2/include/MyZst.d.hpp +++ b/feature_tests/cpp2/include/MyZst.d.hpp @@ -10,6 +10,11 @@ #include "diplomat_runtime.hpp" +namespace capi { + typedef struct MyZst { + } MyZst; +} + struct MyZst { }; diff --git a/feature_tests/cpp2/include/MyZst.hpp b/feature_tests/cpp2/include/MyZst.hpp index 239a5bbef..01ad6e435 100644 --- a/feature_tests/cpp2/include/MyZst.hpp +++ b/feature_tests/cpp2/include/MyZst.hpp @@ -12,6 +12,13 @@ #include "diplomat_runtime.hpp" +namespace capi { + extern "C" { + + + } // extern "C" +} + diff --git a/feature_tests/cpp2/include/NestedBorrowedFields.d.h b/feature_tests/cpp2/include/NestedBorrowedFields.d.h deleted file mode 100644 index 5d230e266..000000000 --- a/feature_tests/cpp2/include/NestedBorrowedFields.d.h +++ /dev/null @@ -1,26 +0,0 @@ -#ifndef NestedBorrowedFields_D_H -#define NestedBorrowedFields_D_H - -#include -#include -#include -#include -#include "diplomat_runtime.h" - -#include "BorrowedFields.d.h" -#include "BorrowedFieldsWithBounds.d.h" - -namespace capi { - - -typedef struct NestedBorrowedFields { - BorrowedFields fields; - BorrowedFieldsWithBounds bounds; - BorrowedFieldsWithBounds bounds2; -} NestedBorrowedFields; - - - -} // namespace capi - -#endif // NestedBorrowedFields_D_H diff --git a/feature_tests/cpp2/include/NestedBorrowedFields.d.hpp b/feature_tests/cpp2/include/NestedBorrowedFields.d.hpp index 47dfefefb..c29af1886 100644 --- a/feature_tests/cpp2/include/NestedBorrowedFields.d.hpp +++ b/feature_tests/cpp2/include/NestedBorrowedFields.d.hpp @@ -10,7 +10,6 @@ #include "diplomat_runtime.hpp" #include "BorrowedFields.d.hpp" #include "BorrowedFieldsWithBounds.d.hpp" -#include "NestedBorrowedFields.d.h" class Bar; class Foo; @@ -18,6 +17,14 @@ struct BorrowedFields; struct BorrowedFieldsWithBounds; +namespace capi { + typedef struct NestedBorrowedFields { + BorrowedFields fields; + BorrowedFieldsWithBounds bounds; + BorrowedFieldsWithBounds bounds2; + } NestedBorrowedFields; +} + struct NestedBorrowedFields { BorrowedFields fields; BorrowedFieldsWithBounds bounds; diff --git a/feature_tests/cpp2/include/NestedBorrowedFields.h b/feature_tests/cpp2/include/NestedBorrowedFields.h deleted file mode 100644 index 46aa7327c..000000000 --- a/feature_tests/cpp2/include/NestedBorrowedFields.h +++ /dev/null @@ -1,27 +0,0 @@ -#ifndef NestedBorrowedFields_H -#define NestedBorrowedFields_H - -#include -#include -#include -#include -#include "diplomat_runtime.h" - -#include "Bar.d.h" -#include "Foo.d.h" - -#include "NestedBorrowedFields.d.h" - -namespace capi { - - -extern "C" { - -NestedBorrowedFields NestedBorrowedFields_from_bar_and_foo_and_strings(const Bar* bar, const Foo* foo, const char16_t* dstr16_x_data, size_t dstr16_x_len, const char16_t* dstr16_z_data, size_t dstr16_z_len, const char* utf8_str_y_data, size_t utf8_str_y_len, const char* utf8_str_z_data, size_t utf8_str_z_len); - - -} // extern "C" - -} // namespace capi - -#endif // NestedBorrowedFields_H diff --git a/feature_tests/cpp2/include/NestedBorrowedFields.hpp b/feature_tests/cpp2/include/NestedBorrowedFields.hpp index 584170372..252cfb0b7 100644 --- a/feature_tests/cpp2/include/NestedBorrowedFields.hpp +++ b/feature_tests/cpp2/include/NestedBorrowedFields.hpp @@ -14,9 +14,17 @@ #include "BorrowedFields.hpp" #include "BorrowedFieldsWithBounds.hpp" #include "Foo.hpp" -#include "NestedBorrowedFields.h" +namespace capi { + extern "C" { + + NestedBorrowedFields NestedBorrowedFields_from_bar_and_foo_and_strings(const Bar* bar, const Foo* foo, const char16_t* dstr16_x_data, size_t dstr16_x_len, const char16_t* dstr16_z_data, size_t dstr16_z_len, const char* utf8_str_y_data, size_t utf8_str_y_len, const char* utf8_str_z_data, size_t utf8_str_z_len); + + + } // extern "C" +} + inline diplomat::result NestedBorrowedFields::from_bar_and_foo_and_strings(const Bar& bar, const Foo& foo, std::u16string_view dstr16_x, std::u16string_view dstr16_z, std::string_view utf8_str_y, std::string_view utf8_str_z) { if (!capi::diplomat_is_str(utf8_str_y.data(), utf8_str_y.size())) { return diplomat::Err(diplomat::Utf8Error()); diff --git a/feature_tests/cpp2/include/One.d.h b/feature_tests/cpp2/include/One.d.h deleted file mode 100644 index 27231a91f..000000000 --- a/feature_tests/cpp2/include/One.d.h +++ /dev/null @@ -1,20 +0,0 @@ -#ifndef One_D_H -#define One_D_H - -#include -#include -#include -#include -#include "diplomat_runtime.h" - - -namespace capi { - - -typedef struct One One; - - - -} // namespace capi - -#endif // One_D_H diff --git a/feature_tests/cpp2/include/One.d.hpp b/feature_tests/cpp2/include/One.d.hpp index 7c01f894c..7052b953d 100644 --- a/feature_tests/cpp2/include/One.d.hpp +++ b/feature_tests/cpp2/include/One.d.hpp @@ -8,11 +8,14 @@ #include #include #include "diplomat_runtime.hpp" -#include "One.d.h" class Two; +namespace capi { + typedef struct One One; +} + class One { public: diff --git a/feature_tests/cpp2/include/One.h b/feature_tests/cpp2/include/One.h deleted file mode 100644 index 85a2f88c5..000000000 --- a/feature_tests/cpp2/include/One.h +++ /dev/null @@ -1,48 +0,0 @@ -#ifndef One_H -#define One_H - -#include -#include -#include -#include -#include "diplomat_runtime.h" - -#include "Two.d.h" - -#include "One.d.h" - -namespace capi { - - -extern "C" { - -One* One_transitivity(const One* hold, const One* nohold); - -One* One_cycle(const Two* hold, const One* nohold); - -One* One_many_dependents(const One* a, const One* b, const Two* c, const Two* d, const Two* nohold); - -One* One_return_outlives_param(const Two* hold, const One* nohold); - -One* One_diamond_top(const One* top, const One* left, const One* right, const One* bottom); - -One* One_diamond_left(const One* top, const One* left, const One* right, const One* bottom); - -One* One_diamond_right(const One* top, const One* left, const One* right, const One* bottom); - -One* One_diamond_bottom(const One* top, const One* left, const One* right, const One* bottom); - -One* One_diamond_and_nested_types(const One* a, const One* b, const One* c, const One* d, const One* nohold); - -One* One_implicit_bounds(const One* explicit_hold, const One* implicit_hold, const One* nohold); - -One* One_implicit_bounds_deep(const One* explicit_, const One* implicit_1, const One* implicit_2, const One* nohold); - - -void One_destroy(One* self); - -} // extern "C" - -} // namespace capi - -#endif // One_H diff --git a/feature_tests/cpp2/include/One.hpp b/feature_tests/cpp2/include/One.hpp index cb8788dcf..54ff6539f 100644 --- a/feature_tests/cpp2/include/One.hpp +++ b/feature_tests/cpp2/include/One.hpp @@ -10,10 +10,40 @@ #include #include #include "diplomat_runtime.hpp" -#include "One.h" #include "Two.hpp" +namespace capi { + extern "C" { + + One* One_transitivity(const One* hold, const One* nohold); + + One* One_cycle(const Two* hold, const One* nohold); + + One* One_many_dependents(const One* a, const One* b, const Two* c, const Two* d, const Two* nohold); + + One* One_return_outlives_param(const Two* hold, const One* nohold); + + One* One_diamond_top(const One* top, const One* left, const One* right, const One* bottom); + + One* One_diamond_left(const One* top, const One* left, const One* right, const One* bottom); + + One* One_diamond_right(const One* top, const One* left, const One* right, const One* bottom); + + One* One_diamond_bottom(const One* top, const One* left, const One* right, const One* bottom); + + One* One_diamond_and_nested_types(const One* a, const One* b, const One* c, const One* d, const One* nohold); + + One* One_implicit_bounds(const One* explicit_hold, const One* implicit_hold, const One* nohold); + + One* One_implicit_bounds_deep(const One* explicit_, const One* implicit_1, const One* implicit_2, const One* nohold); + + + void One_destroy(One* self); + + } // extern "C" +} + inline std::unique_ptr One::transitivity(const One& hold, const One& nohold) { auto result = capi::One_transitivity(hold.AsFFI(), nohold.AsFFI()); diff --git a/feature_tests/cpp2/include/Opaque.d.h b/feature_tests/cpp2/include/Opaque.d.h deleted file mode 100644 index 4001de81d..000000000 --- a/feature_tests/cpp2/include/Opaque.d.h +++ /dev/null @@ -1,20 +0,0 @@ -#ifndef Opaque_D_H -#define Opaque_D_H - -#include -#include -#include -#include -#include "diplomat_runtime.h" - - -namespace capi { - - -typedef struct Opaque Opaque; - - - -} // namespace capi - -#endif // Opaque_D_H diff --git a/feature_tests/cpp2/include/Opaque.d.hpp b/feature_tests/cpp2/include/Opaque.d.hpp index 37e2dec97..1f3828bc6 100644 --- a/feature_tests/cpp2/include/Opaque.d.hpp +++ b/feature_tests/cpp2/include/Opaque.d.hpp @@ -10,12 +10,15 @@ #include "diplomat_runtime.hpp" #include "ImportedStruct.d.hpp" #include "MyStruct.d.hpp" -#include "Opaque.d.h" struct ImportedStruct; struct MyStruct; +namespace capi { + typedef struct Opaque Opaque; +} + class Opaque { public: diff --git a/feature_tests/cpp2/include/Opaque.h b/feature_tests/cpp2/include/Opaque.h deleted file mode 100644 index bef068141..000000000 --- a/feature_tests/cpp2/include/Opaque.h +++ /dev/null @@ -1,43 +0,0 @@ -#ifndef Opaque_H -#define Opaque_H - -#include -#include -#include -#include -#include "diplomat_runtime.h" - -#include "ImportedStruct.d.h" -#include "MyStruct.d.h" - -#include "Opaque.d.h" - -namespace capi { - - -extern "C" { - -Opaque* Opaque_new(); - -Opaque* Opaque_try_from_utf8(const char* input_data, size_t input_len); - -Opaque* Opaque_from_str(const char* input_data, size_t input_len); - -void Opaque_get_debug_str(const Opaque* self, DiplomatWrite* write); - -void Opaque_assert_struct(const Opaque* self, MyStruct s); - -size_t Opaque_returns_usize(); - -ImportedStruct Opaque_returns_imported(); - -int8_t Opaque_cmp(); - - -void Opaque_destroy(Opaque* self); - -} // extern "C" - -} // namespace capi - -#endif // Opaque_H diff --git a/feature_tests/cpp2/include/Opaque.hpp b/feature_tests/cpp2/include/Opaque.hpp index 5886e5d8f..d29bbb137 100644 --- a/feature_tests/cpp2/include/Opaque.hpp +++ b/feature_tests/cpp2/include/Opaque.hpp @@ -12,9 +12,33 @@ #include "diplomat_runtime.hpp" #include "ImportedStruct.hpp" #include "MyStruct.hpp" -#include "Opaque.h" +namespace capi { + extern "C" { + + Opaque* Opaque_new(); + + Opaque* Opaque_try_from_utf8(const char* input_data, size_t input_len); + + Opaque* Opaque_from_str(const char* input_data, size_t input_len); + + void Opaque_get_debug_str(const Opaque* self, DiplomatWrite* write); + + void Opaque_assert_struct(const Opaque* self, MyStruct s); + + size_t Opaque_returns_usize(); + + ImportedStruct Opaque_returns_imported(); + + int8_t Opaque_cmp(); + + + void Opaque_destroy(Opaque* self); + + } // extern "C" +} + inline std::unique_ptr Opaque::new_() { auto result = capi::Opaque_new(); return std::unique_ptr(Opaque::FromFFI(result)); diff --git a/feature_tests/cpp2/include/OpaqueMutexedString.d.h b/feature_tests/cpp2/include/OpaqueMutexedString.d.h deleted file mode 100644 index ffaa14e34..000000000 --- a/feature_tests/cpp2/include/OpaqueMutexedString.d.h +++ /dev/null @@ -1,20 +0,0 @@ -#ifndef OpaqueMutexedString_D_H -#define OpaqueMutexedString_D_H - -#include -#include -#include -#include -#include "diplomat_runtime.h" - - -namespace capi { - - -typedef struct OpaqueMutexedString OpaqueMutexedString; - - - -} // namespace capi - -#endif // OpaqueMutexedString_D_H diff --git a/feature_tests/cpp2/include/OpaqueMutexedString.d.hpp b/feature_tests/cpp2/include/OpaqueMutexedString.d.hpp index d7dfa417f..cb4436c7e 100644 --- a/feature_tests/cpp2/include/OpaqueMutexedString.d.hpp +++ b/feature_tests/cpp2/include/OpaqueMutexedString.d.hpp @@ -8,11 +8,14 @@ #include #include #include "diplomat_runtime.hpp" -#include "OpaqueMutexedString.d.h" class Utf16Wrap; +namespace capi { + typedef struct OpaqueMutexedString OpaqueMutexedString; +} + class OpaqueMutexedString { public: diff --git a/feature_tests/cpp2/include/OpaqueMutexedString.h b/feature_tests/cpp2/include/OpaqueMutexedString.h deleted file mode 100644 index f1d1a23b5..000000000 --- a/feature_tests/cpp2/include/OpaqueMutexedString.h +++ /dev/null @@ -1,42 +0,0 @@ -#ifndef OpaqueMutexedString_H -#define OpaqueMutexedString_H - -#include -#include -#include -#include -#include "diplomat_runtime.h" - -#include "Utf16Wrap.d.h" - -#include "OpaqueMutexedString.d.h" - -namespace capi { - - -extern "C" { - -OpaqueMutexedString* OpaqueMutexedString_from_usize(size_t number); - -void OpaqueMutexedString_change(const OpaqueMutexedString* self, size_t number); - -const OpaqueMutexedString* OpaqueMutexedString_borrow(const OpaqueMutexedString* self); - -const OpaqueMutexedString* OpaqueMutexedString_borrow_other(const OpaqueMutexedString* other); - -const OpaqueMutexedString* OpaqueMutexedString_borrow_self_or_other(const OpaqueMutexedString* self, const OpaqueMutexedString* other); - -size_t OpaqueMutexedString_get_len_and_add(const OpaqueMutexedString* self, size_t other); - -DiplomatStringView OpaqueMutexedString_dummy_str(const OpaqueMutexedString* self); - -Utf16Wrap* OpaqueMutexedString_wrapper(const OpaqueMutexedString* self); - - -void OpaqueMutexedString_destroy(OpaqueMutexedString* self); - -} // extern "C" - -} // namespace capi - -#endif // OpaqueMutexedString_H diff --git a/feature_tests/cpp2/include/OpaqueMutexedString.hpp b/feature_tests/cpp2/include/OpaqueMutexedString.hpp index 7859f5d0c..e9f45bc96 100644 --- a/feature_tests/cpp2/include/OpaqueMutexedString.hpp +++ b/feature_tests/cpp2/include/OpaqueMutexedString.hpp @@ -10,10 +10,34 @@ #include #include #include "diplomat_runtime.hpp" -#include "OpaqueMutexedString.h" #include "Utf16Wrap.hpp" +namespace capi { + extern "C" { + + OpaqueMutexedString* OpaqueMutexedString_from_usize(size_t number); + + void OpaqueMutexedString_change(const OpaqueMutexedString* self, size_t number); + + const OpaqueMutexedString* OpaqueMutexedString_borrow(const OpaqueMutexedString* self); + + const OpaqueMutexedString* OpaqueMutexedString_borrow_other(const OpaqueMutexedString* other); + + const OpaqueMutexedString* OpaqueMutexedString_borrow_self_or_other(const OpaqueMutexedString* self, const OpaqueMutexedString* other); + + size_t OpaqueMutexedString_get_len_and_add(const OpaqueMutexedString* self, size_t other); + + DiplomatStringView OpaqueMutexedString_dummy_str(const OpaqueMutexedString* self); + + Utf16Wrap* OpaqueMutexedString_wrapper(const OpaqueMutexedString* self); + + + void OpaqueMutexedString_destroy(OpaqueMutexedString* self); + + } // extern "C" +} + inline std::unique_ptr OpaqueMutexedString::from_usize(size_t number) { auto result = capi::OpaqueMutexedString_from_usize(number); return std::unique_ptr(OpaqueMutexedString::FromFFI(result)); diff --git a/feature_tests/cpp2/include/OptionOpaque.d.h b/feature_tests/cpp2/include/OptionOpaque.d.h deleted file mode 100644 index 238de08ca..000000000 --- a/feature_tests/cpp2/include/OptionOpaque.d.h +++ /dev/null @@ -1,20 +0,0 @@ -#ifndef OptionOpaque_D_H -#define OptionOpaque_D_H - -#include -#include -#include -#include -#include "diplomat_runtime.h" - - -namespace capi { - - -typedef struct OptionOpaque OptionOpaque; - - - -} // namespace capi - -#endif // OptionOpaque_D_H diff --git a/feature_tests/cpp2/include/OptionOpaque.d.hpp b/feature_tests/cpp2/include/OptionOpaque.d.hpp index dc8aa5f9b..dd7c6e540 100644 --- a/feature_tests/cpp2/include/OptionOpaque.d.hpp +++ b/feature_tests/cpp2/include/OptionOpaque.d.hpp @@ -8,12 +8,15 @@ #include #include #include "diplomat_runtime.hpp" -#include "OptionOpaque.d.h" #include "OptionStruct.d.hpp" struct OptionStruct; +namespace capi { + typedef struct OptionOpaque OptionOpaque; +} + class OptionOpaque { public: diff --git a/feature_tests/cpp2/include/OptionOpaque.h b/feature_tests/cpp2/include/OptionOpaque.h deleted file mode 100644 index 6ebd62115..000000000 --- a/feature_tests/cpp2/include/OptionOpaque.h +++ /dev/null @@ -1,53 +0,0 @@ -#ifndef OptionOpaque_H -#define OptionOpaque_H - -#include -#include -#include -#include -#include "diplomat_runtime.h" - -#include "OptionStruct.d.h" - -#include "OptionOpaque.d.h" - -namespace capi { - - -extern "C" { - -OptionOpaque* OptionOpaque_new(int32_t i); - -OptionOpaque* OptionOpaque_new_none(); - -struct OptionOpaque_returns_result {union {OptionStruct ok; }; bool is_ok;}; -struct OptionOpaque_returns_result OptionOpaque_returns(); - -struct OptionOpaque_option_isize_result {union {intptr_t ok; }; bool is_ok;}; -struct OptionOpaque_option_isize_result OptionOpaque_option_isize(const OptionOpaque* self); - -struct OptionOpaque_option_usize_result {union {size_t ok; }; bool is_ok;}; -struct OptionOpaque_option_usize_result OptionOpaque_option_usize(const OptionOpaque* self); - -struct OptionOpaque_option_i32_result {union {int32_t ok; }; bool is_ok;}; -struct OptionOpaque_option_i32_result OptionOpaque_option_i32(const OptionOpaque* self); - -struct OptionOpaque_option_u32_result {union {uint32_t ok; }; bool is_ok;}; -struct OptionOpaque_option_u32_result OptionOpaque_option_u32(const OptionOpaque* self); - -OptionStruct OptionOpaque_new_struct(); - -OptionStruct OptionOpaque_new_struct_nones(); - -void OptionOpaque_assert_integer(const OptionOpaque* self, int32_t i); - -bool OptionOpaque_option_opaque_argument(const OptionOpaque* arg); - - -void OptionOpaque_destroy(OptionOpaque* self); - -} // extern "C" - -} // namespace capi - -#endif // OptionOpaque_H diff --git a/feature_tests/cpp2/include/OptionOpaque.hpp b/feature_tests/cpp2/include/OptionOpaque.hpp index b84bb7be3..7fb5ece3f 100644 --- a/feature_tests/cpp2/include/OptionOpaque.hpp +++ b/feature_tests/cpp2/include/OptionOpaque.hpp @@ -10,10 +10,45 @@ #include #include #include "diplomat_runtime.hpp" -#include "OptionOpaque.h" #include "OptionStruct.hpp" +namespace capi { + extern "C" { + + OptionOpaque* OptionOpaque_new(int32_t i); + + OptionOpaque* OptionOpaque_new_none(); + + struct OptionOpaque_returns_result {union {OptionStruct ok; }; bool is_ok;}; + struct OptionOpaque_returns_result OptionOpaque_returns(); + + struct OptionOpaque_option_isize_result {union {intptr_t ok; }; bool is_ok;}; + struct OptionOpaque_option_isize_result OptionOpaque_option_isize(const OptionOpaque* self); + + struct OptionOpaque_option_usize_result {union {size_t ok; }; bool is_ok;}; + struct OptionOpaque_option_usize_result OptionOpaque_option_usize(const OptionOpaque* self); + + struct OptionOpaque_option_i32_result {union {int32_t ok; }; bool is_ok;}; + struct OptionOpaque_option_i32_result OptionOpaque_option_i32(const OptionOpaque* self); + + struct OptionOpaque_option_u32_result {union {uint32_t ok; }; bool is_ok;}; + struct OptionOpaque_option_u32_result OptionOpaque_option_u32(const OptionOpaque* self); + + OptionStruct OptionOpaque_new_struct(); + + OptionStruct OptionOpaque_new_struct_nones(); + + void OptionOpaque_assert_integer(const OptionOpaque* self, int32_t i); + + bool OptionOpaque_option_opaque_argument(const OptionOpaque* arg); + + + void OptionOpaque_destroy(OptionOpaque* self); + + } // extern "C" +} + inline std::unique_ptr OptionOpaque::new_(int32_t i) { auto result = capi::OptionOpaque_new(i); return std::unique_ptr(OptionOpaque::FromFFI(result)); diff --git a/feature_tests/cpp2/include/OptionOpaqueChar.d.h b/feature_tests/cpp2/include/OptionOpaqueChar.d.h deleted file mode 100644 index 80561c4cf..000000000 --- a/feature_tests/cpp2/include/OptionOpaqueChar.d.h +++ /dev/null @@ -1,20 +0,0 @@ -#ifndef OptionOpaqueChar_D_H -#define OptionOpaqueChar_D_H - -#include -#include -#include -#include -#include "diplomat_runtime.h" - - -namespace capi { - - -typedef struct OptionOpaqueChar OptionOpaqueChar; - - - -} // namespace capi - -#endif // OptionOpaqueChar_D_H diff --git a/feature_tests/cpp2/include/OptionOpaqueChar.d.hpp b/feature_tests/cpp2/include/OptionOpaqueChar.d.hpp index 23ef5b149..788a0c195 100644 --- a/feature_tests/cpp2/include/OptionOpaqueChar.d.hpp +++ b/feature_tests/cpp2/include/OptionOpaqueChar.d.hpp @@ -8,9 +8,12 @@ #include #include #include "diplomat_runtime.hpp" -#include "OptionOpaqueChar.d.h" +namespace capi { + typedef struct OptionOpaqueChar OptionOpaqueChar; +} + class OptionOpaqueChar { public: diff --git a/feature_tests/cpp2/include/OptionOpaqueChar.h b/feature_tests/cpp2/include/OptionOpaqueChar.h deleted file mode 100644 index 79f790c09..000000000 --- a/feature_tests/cpp2/include/OptionOpaqueChar.h +++ /dev/null @@ -1,27 +0,0 @@ -#ifndef OptionOpaqueChar_H -#define OptionOpaqueChar_H - -#include -#include -#include -#include -#include "diplomat_runtime.h" - - -#include "OptionOpaqueChar.d.h" - -namespace capi { - - -extern "C" { - -void OptionOpaqueChar_assert_char(const OptionOpaqueChar* self, char32_t ch); - - -void OptionOpaqueChar_destroy(OptionOpaqueChar* self); - -} // extern "C" - -} // namespace capi - -#endif // OptionOpaqueChar_H diff --git a/feature_tests/cpp2/include/OptionOpaqueChar.hpp b/feature_tests/cpp2/include/OptionOpaqueChar.hpp index 3a7263117..ab9d18bad 100644 --- a/feature_tests/cpp2/include/OptionOpaqueChar.hpp +++ b/feature_tests/cpp2/include/OptionOpaqueChar.hpp @@ -10,9 +10,19 @@ #include #include #include "diplomat_runtime.hpp" -#include "OptionOpaqueChar.h" +namespace capi { + extern "C" { + + void OptionOpaqueChar_assert_char(const OptionOpaqueChar* self, char32_t ch); + + + void OptionOpaqueChar_destroy(OptionOpaqueChar* self); + + } // extern "C" +} + inline void OptionOpaqueChar::assert_char(char32_t ch) const { capi::OptionOpaqueChar_assert_char(this->AsFFI(), ch); diff --git a/feature_tests/cpp2/include/OptionString.d.h b/feature_tests/cpp2/include/OptionString.d.h deleted file mode 100644 index 3d31c33d2..000000000 --- a/feature_tests/cpp2/include/OptionString.d.h +++ /dev/null @@ -1,20 +0,0 @@ -#ifndef OptionString_D_H -#define OptionString_D_H - -#include -#include -#include -#include -#include "diplomat_runtime.h" - - -namespace capi { - - -typedef struct OptionString OptionString; - - - -} // namespace capi - -#endif // OptionString_D_H diff --git a/feature_tests/cpp2/include/OptionString.d.hpp b/feature_tests/cpp2/include/OptionString.d.hpp index 5b454b050..af0ad92a9 100644 --- a/feature_tests/cpp2/include/OptionString.d.hpp +++ b/feature_tests/cpp2/include/OptionString.d.hpp @@ -8,9 +8,12 @@ #include #include #include "diplomat_runtime.hpp" -#include "OptionString.d.h" +namespace capi { + typedef struct OptionString OptionString; +} + class OptionString { public: diff --git a/feature_tests/cpp2/include/OptionString.h b/feature_tests/cpp2/include/OptionString.h deleted file mode 100644 index d02ba625d..000000000 --- a/feature_tests/cpp2/include/OptionString.h +++ /dev/null @@ -1,33 +0,0 @@ -#ifndef OptionString_H -#define OptionString_H - -#include -#include -#include -#include -#include "diplomat_runtime.h" - - -#include "OptionString.d.h" - -namespace capi { - - -extern "C" { - -OptionString* OptionString_new(const char* diplomat_str_data, size_t diplomat_str_len); - -struct OptionString_write_result { bool is_ok;}; -struct OptionString_write_result OptionString_write(const OptionString* self, DiplomatWrite* write); - -struct OptionString_borrow_result {union {DiplomatStringView ok; }; bool is_ok;}; -struct OptionString_borrow_result OptionString_borrow(const OptionString* self); - - -void OptionString_destroy(OptionString* self); - -} // extern "C" - -} // namespace capi - -#endif // OptionString_H diff --git a/feature_tests/cpp2/include/OptionString.hpp b/feature_tests/cpp2/include/OptionString.hpp index 721bd6dcb..2276acfca 100644 --- a/feature_tests/cpp2/include/OptionString.hpp +++ b/feature_tests/cpp2/include/OptionString.hpp @@ -10,9 +10,25 @@ #include #include #include "diplomat_runtime.hpp" -#include "OptionString.h" +namespace capi { + extern "C" { + + OptionString* OptionString_new(const char* diplomat_str_data, size_t diplomat_str_len); + + struct OptionString_write_result { bool is_ok;}; + struct OptionString_write_result OptionString_write(const OptionString* self, DiplomatWrite* write); + + struct OptionString_borrow_result {union {DiplomatStringView ok; }; bool is_ok;}; + struct OptionString_borrow_result OptionString_borrow(const OptionString* self); + + + void OptionString_destroy(OptionString* self); + + } // extern "C" +} + inline std::unique_ptr OptionString::new_(std::string_view diplomat_str) { auto result = capi::OptionString_new(diplomat_str.data(), diplomat_str.size()); diff --git a/feature_tests/cpp2/include/OptionStruct.d.h b/feature_tests/cpp2/include/OptionStruct.d.h deleted file mode 100644 index 999783bbb..000000000 --- a/feature_tests/cpp2/include/OptionStruct.d.h +++ /dev/null @@ -1,27 +0,0 @@ -#ifndef OptionStruct_D_H -#define OptionStruct_D_H - -#include -#include -#include -#include -#include "diplomat_runtime.h" - -#include "OptionOpaque.d.h" -#include "OptionOpaqueChar.d.h" - -namespace capi { - - -typedef struct OptionStruct { - OptionOpaque* a; - OptionOpaqueChar* b; - uint32_t c; - OptionOpaque* d; -} OptionStruct; - - - -} // namespace capi - -#endif // OptionStruct_D_H diff --git a/feature_tests/cpp2/include/OptionStruct.d.hpp b/feature_tests/cpp2/include/OptionStruct.d.hpp index 2aeab0010..a66032994 100644 --- a/feature_tests/cpp2/include/OptionStruct.d.hpp +++ b/feature_tests/cpp2/include/OptionStruct.d.hpp @@ -8,12 +8,20 @@ #include #include #include "diplomat_runtime.hpp" -#include "OptionStruct.d.h" class OptionOpaque; class OptionOpaqueChar; +namespace capi { + typedef struct OptionStruct { + OptionOpaque* a; + OptionOpaqueChar* b; + uint32_t c; + OptionOpaque* d; + } OptionStruct; +} + struct OptionStruct { std::unique_ptr a; std::unique_ptr b; diff --git a/feature_tests/cpp2/include/OptionStruct.h b/feature_tests/cpp2/include/OptionStruct.h deleted file mode 100644 index 997f1c3ca..000000000 --- a/feature_tests/cpp2/include/OptionStruct.h +++ /dev/null @@ -1,23 +0,0 @@ -#ifndef OptionStruct_H -#define OptionStruct_H - -#include -#include -#include -#include -#include "diplomat_runtime.h" - - -#include "OptionStruct.d.h" - -namespace capi { - - -extern "C" { - - -} // extern "C" - -} // namespace capi - -#endif // OptionStruct_H diff --git a/feature_tests/cpp2/include/OptionStruct.hpp b/feature_tests/cpp2/include/OptionStruct.hpp index 6e8aea5af..32c8ca62d 100644 --- a/feature_tests/cpp2/include/OptionStruct.hpp +++ b/feature_tests/cpp2/include/OptionStruct.hpp @@ -12,9 +12,15 @@ #include "diplomat_runtime.hpp" #include "OptionOpaque.hpp" #include "OptionOpaqueChar.hpp" -#include "OptionStruct.h" +namespace capi { + extern "C" { + + + } // extern "C" +} + inline capi::OptionStruct OptionStruct::AsFFI() const { return capi::OptionStruct { diff --git a/feature_tests/cpp2/include/RefList.d.h b/feature_tests/cpp2/include/RefList.d.h deleted file mode 100644 index 5b279b684..000000000 --- a/feature_tests/cpp2/include/RefList.d.h +++ /dev/null @@ -1,20 +0,0 @@ -#ifndef RefList_D_H -#define RefList_D_H - -#include -#include -#include -#include -#include "diplomat_runtime.h" - - -namespace capi { - - -typedef struct RefList RefList; - - - -} // namespace capi - -#endif // RefList_D_H diff --git a/feature_tests/cpp2/include/RefList.d.hpp b/feature_tests/cpp2/include/RefList.d.hpp index bfb73ccbb..a7bbb38b5 100644 --- a/feature_tests/cpp2/include/RefList.d.hpp +++ b/feature_tests/cpp2/include/RefList.d.hpp @@ -8,11 +8,14 @@ #include #include #include "diplomat_runtime.hpp" -#include "RefList.d.h" class RefListParameter; +namespace capi { + typedef struct RefList RefList; +} + class RefList { public: diff --git a/feature_tests/cpp2/include/RefList.h b/feature_tests/cpp2/include/RefList.h deleted file mode 100644 index 981d6bd97..000000000 --- a/feature_tests/cpp2/include/RefList.h +++ /dev/null @@ -1,28 +0,0 @@ -#ifndef RefList_H -#define RefList_H - -#include -#include -#include -#include -#include "diplomat_runtime.h" - -#include "RefListParameter.d.h" - -#include "RefList.d.h" - -namespace capi { - - -extern "C" { - -RefList* RefList_node(const RefListParameter* data); - - -void RefList_destroy(RefList* self); - -} // extern "C" - -} // namespace capi - -#endif // RefList_H diff --git a/feature_tests/cpp2/include/RefList.hpp b/feature_tests/cpp2/include/RefList.hpp index f866ae6c4..68ec6d11a 100644 --- a/feature_tests/cpp2/include/RefList.hpp +++ b/feature_tests/cpp2/include/RefList.hpp @@ -10,10 +10,20 @@ #include #include #include "diplomat_runtime.hpp" -#include "RefList.h" #include "RefListParameter.hpp" +namespace capi { + extern "C" { + + RefList* RefList_node(const RefListParameter* data); + + + void RefList_destroy(RefList* self); + + } // extern "C" +} + inline std::unique_ptr RefList::node(const RefListParameter& data) { auto result = capi::RefList_node(data.AsFFI()); return std::unique_ptr(RefList::FromFFI(result)); diff --git a/feature_tests/cpp2/include/RefListParameter.d.h b/feature_tests/cpp2/include/RefListParameter.d.h deleted file mode 100644 index 2152e3680..000000000 --- a/feature_tests/cpp2/include/RefListParameter.d.h +++ /dev/null @@ -1,20 +0,0 @@ -#ifndef RefListParameter_D_H -#define RefListParameter_D_H - -#include -#include -#include -#include -#include "diplomat_runtime.h" - - -namespace capi { - - -typedef struct RefListParameter RefListParameter; - - - -} // namespace capi - -#endif // RefListParameter_D_H diff --git a/feature_tests/cpp2/include/RefListParameter.d.hpp b/feature_tests/cpp2/include/RefListParameter.d.hpp index 37d355cc4..e7deae501 100644 --- a/feature_tests/cpp2/include/RefListParameter.d.hpp +++ b/feature_tests/cpp2/include/RefListParameter.d.hpp @@ -8,9 +8,12 @@ #include #include #include "diplomat_runtime.hpp" -#include "RefListParameter.d.h" +namespace capi { + typedef struct RefListParameter RefListParameter; +} + class RefListParameter { public: diff --git a/feature_tests/cpp2/include/RefListParameter.h b/feature_tests/cpp2/include/RefListParameter.h deleted file mode 100644 index e78b57cb4..000000000 --- a/feature_tests/cpp2/include/RefListParameter.h +++ /dev/null @@ -1,25 +0,0 @@ -#ifndef RefListParameter_H -#define RefListParameter_H - -#include -#include -#include -#include -#include "diplomat_runtime.h" - - -#include "RefListParameter.d.h" - -namespace capi { - - -extern "C" { - - -void RefListParameter_destroy(RefListParameter* self); - -} // extern "C" - -} // namespace capi - -#endif // RefListParameter_H diff --git a/feature_tests/cpp2/include/RefListParameter.hpp b/feature_tests/cpp2/include/RefListParameter.hpp index 576b25b62..a64765834 100644 --- a/feature_tests/cpp2/include/RefListParameter.hpp +++ b/feature_tests/cpp2/include/RefListParameter.hpp @@ -10,9 +10,17 @@ #include #include #include "diplomat_runtime.hpp" -#include "RefListParameter.h" +namespace capi { + extern "C" { + + + void RefListParameter_destroy(RefListParameter* self); + + } // extern "C" +} + inline const capi::RefListParameter* RefListParameter::AsFFI() const { return reinterpret_cast(this); } diff --git a/feature_tests/cpp2/include/ResultOpaque.d.h b/feature_tests/cpp2/include/ResultOpaque.d.h deleted file mode 100644 index cbdacacd0..000000000 --- a/feature_tests/cpp2/include/ResultOpaque.d.h +++ /dev/null @@ -1,20 +0,0 @@ -#ifndef ResultOpaque_D_H -#define ResultOpaque_D_H - -#include -#include -#include -#include -#include "diplomat_runtime.h" - - -namespace capi { - - -typedef struct ResultOpaque ResultOpaque; - - - -} // namespace capi - -#endif // ResultOpaque_D_H diff --git a/feature_tests/cpp2/include/ResultOpaque.d.hpp b/feature_tests/cpp2/include/ResultOpaque.d.hpp index 8687cf2d5..c894d23f0 100644 --- a/feature_tests/cpp2/include/ResultOpaque.d.hpp +++ b/feature_tests/cpp2/include/ResultOpaque.d.hpp @@ -10,12 +10,15 @@ #include "diplomat_runtime.hpp" #include "ErrorEnum.d.hpp" #include "ErrorStruct.d.hpp" -#include "ResultOpaque.d.h" struct ErrorStruct; class ErrorEnum; +namespace capi { + typedef struct ResultOpaque ResultOpaque; +} + class ResultOpaque { public: diff --git a/feature_tests/cpp2/include/ResultOpaque.h b/feature_tests/cpp2/include/ResultOpaque.h deleted file mode 100644 index 7ba87b663..000000000 --- a/feature_tests/cpp2/include/ResultOpaque.h +++ /dev/null @@ -1,53 +0,0 @@ -#ifndef ResultOpaque_H -#define ResultOpaque_H - -#include -#include -#include -#include -#include "diplomat_runtime.h" - -#include "ErrorEnum.d.h" -#include "ErrorStruct.d.h" - -#include "ResultOpaque.d.h" - -namespace capi { - - -extern "C" { - -struct ResultOpaque_new_result {union {ResultOpaque* ok; ErrorEnum err;}; bool is_ok;}; -struct ResultOpaque_new_result ResultOpaque_new(int32_t i); - -struct ResultOpaque_new_failing_foo_result {union {ResultOpaque* ok; ErrorEnum err;}; bool is_ok;}; -struct ResultOpaque_new_failing_foo_result ResultOpaque_new_failing_foo(); - -struct ResultOpaque_new_failing_bar_result {union {ResultOpaque* ok; ErrorEnum err;}; bool is_ok;}; -struct ResultOpaque_new_failing_bar_result ResultOpaque_new_failing_bar(); - -struct ResultOpaque_new_failing_unit_result {union {ResultOpaque* ok; }; bool is_ok;}; -struct ResultOpaque_new_failing_unit_result ResultOpaque_new_failing_unit(); - -struct ResultOpaque_new_failing_struct_result {union {ResultOpaque* ok; ErrorStruct err;}; bool is_ok;}; -struct ResultOpaque_new_failing_struct_result ResultOpaque_new_failing_struct(int32_t i); - -struct ResultOpaque_new_in_err_result {union { ResultOpaque* err;}; bool is_ok;}; -struct ResultOpaque_new_in_err_result ResultOpaque_new_in_err(int32_t i); - -struct ResultOpaque_new_int_result {union {int32_t ok; }; bool is_ok;}; -struct ResultOpaque_new_int_result ResultOpaque_new_int(int32_t i); - -struct ResultOpaque_new_in_enum_err_result {union {ErrorEnum ok; ResultOpaque* err;}; bool is_ok;}; -struct ResultOpaque_new_in_enum_err_result ResultOpaque_new_in_enum_err(int32_t i); - -void ResultOpaque_assert_integer(const ResultOpaque* self, int32_t i); - - -void ResultOpaque_destroy(ResultOpaque* self); - -} // extern "C" - -} // namespace capi - -#endif // ResultOpaque_H diff --git a/feature_tests/cpp2/include/ResultOpaque.hpp b/feature_tests/cpp2/include/ResultOpaque.hpp index 70a2e2b9d..ec5d17c96 100644 --- a/feature_tests/cpp2/include/ResultOpaque.hpp +++ b/feature_tests/cpp2/include/ResultOpaque.hpp @@ -12,9 +12,43 @@ #include "diplomat_runtime.hpp" #include "ErrorEnum.hpp" #include "ErrorStruct.hpp" -#include "ResultOpaque.h" +namespace capi { + extern "C" { + + struct ResultOpaque_new_result {union {ResultOpaque* ok; ErrorEnum err;}; bool is_ok;}; + struct ResultOpaque_new_result ResultOpaque_new(int32_t i); + + struct ResultOpaque_new_failing_foo_result {union {ResultOpaque* ok; ErrorEnum err;}; bool is_ok;}; + struct ResultOpaque_new_failing_foo_result ResultOpaque_new_failing_foo(); + + struct ResultOpaque_new_failing_bar_result {union {ResultOpaque* ok; ErrorEnum err;}; bool is_ok;}; + struct ResultOpaque_new_failing_bar_result ResultOpaque_new_failing_bar(); + + struct ResultOpaque_new_failing_unit_result {union {ResultOpaque* ok; }; bool is_ok;}; + struct ResultOpaque_new_failing_unit_result ResultOpaque_new_failing_unit(); + + struct ResultOpaque_new_failing_struct_result {union {ResultOpaque* ok; ErrorStruct err;}; bool is_ok;}; + struct ResultOpaque_new_failing_struct_result ResultOpaque_new_failing_struct(int32_t i); + + struct ResultOpaque_new_in_err_result {union { ResultOpaque* err;}; bool is_ok;}; + struct ResultOpaque_new_in_err_result ResultOpaque_new_in_err(int32_t i); + + struct ResultOpaque_new_int_result {union {int32_t ok; }; bool is_ok;}; + struct ResultOpaque_new_int_result ResultOpaque_new_int(int32_t i); + + struct ResultOpaque_new_in_enum_err_result {union {ErrorEnum ok; ResultOpaque* err;}; bool is_ok;}; + struct ResultOpaque_new_in_enum_err_result ResultOpaque_new_in_enum_err(int32_t i); + + void ResultOpaque_assert_integer(const ResultOpaque* self, int32_t i); + + + void ResultOpaque_destroy(ResultOpaque* self); + + } // extern "C" +} + inline diplomat::result, ErrorEnum> ResultOpaque::new_(int32_t i) { auto result = capi::ResultOpaque_new(i); return result.is_ok ? diplomat::result, ErrorEnum>(diplomat::Ok>(std::unique_ptr(ResultOpaque::FromFFI(result.ok)))) : diplomat::result, ErrorEnum>(diplomat::Err(ErrorEnum::FromFFI(result.err))); diff --git a/feature_tests/cpp2/include/Two.d.h b/feature_tests/cpp2/include/Two.d.h deleted file mode 100644 index 9d3afaa42..000000000 --- a/feature_tests/cpp2/include/Two.d.h +++ /dev/null @@ -1,20 +0,0 @@ -#ifndef Two_D_H -#define Two_D_H - -#include -#include -#include -#include -#include "diplomat_runtime.h" - - -namespace capi { - - -typedef struct Two Two; - - - -} // namespace capi - -#endif // Two_D_H diff --git a/feature_tests/cpp2/include/Two.d.hpp b/feature_tests/cpp2/include/Two.d.hpp index 4fbd2eed1..06d699e26 100644 --- a/feature_tests/cpp2/include/Two.d.hpp +++ b/feature_tests/cpp2/include/Two.d.hpp @@ -8,9 +8,12 @@ #include #include #include "diplomat_runtime.hpp" -#include "Two.d.h" +namespace capi { + typedef struct Two Two; +} + class Two { public: diff --git a/feature_tests/cpp2/include/Two.h b/feature_tests/cpp2/include/Two.h deleted file mode 100644 index 98c73e61f..000000000 --- a/feature_tests/cpp2/include/Two.h +++ /dev/null @@ -1,25 +0,0 @@ -#ifndef Two_H -#define Two_H - -#include -#include -#include -#include -#include "diplomat_runtime.h" - - -#include "Two.d.h" - -namespace capi { - - -extern "C" { - - -void Two_destroy(Two* self); - -} // extern "C" - -} // namespace capi - -#endif // Two_H diff --git a/feature_tests/cpp2/include/Two.hpp b/feature_tests/cpp2/include/Two.hpp index d7c064edd..f40c9265a 100644 --- a/feature_tests/cpp2/include/Two.hpp +++ b/feature_tests/cpp2/include/Two.hpp @@ -10,9 +10,17 @@ #include #include #include "diplomat_runtime.hpp" -#include "Two.h" +namespace capi { + extern "C" { + + + void Two_destroy(Two* self); + + } // extern "C" +} + inline const capi::Two* Two::AsFFI() const { return reinterpret_cast(this); } diff --git a/feature_tests/cpp2/include/UnimportedEnum.d.h b/feature_tests/cpp2/include/UnimportedEnum.d.h deleted file mode 100644 index 22be16f4a..000000000 --- a/feature_tests/cpp2/include/UnimportedEnum.d.h +++ /dev/null @@ -1,24 +0,0 @@ -#ifndef UnimportedEnum_D_H -#define UnimportedEnum_D_H - -#include -#include -#include -#include -#include "diplomat_runtime.h" - - -namespace capi { - - -typedef enum UnimportedEnum { - UnimportedEnum_A = 0, - UnimportedEnum_B = 1, - UnimportedEnum_C = 2, -} UnimportedEnum; - - - -} // namespace capi - -#endif // UnimportedEnum_D_H diff --git a/feature_tests/cpp2/include/UnimportedEnum.d.hpp b/feature_tests/cpp2/include/UnimportedEnum.d.hpp index 87d4cd708..0c54a9206 100644 --- a/feature_tests/cpp2/include/UnimportedEnum.d.hpp +++ b/feature_tests/cpp2/include/UnimportedEnum.d.hpp @@ -8,9 +8,16 @@ #include #include #include "diplomat_runtime.hpp" -#include "UnimportedEnum.d.h" +namespace capi { + typedef enum UnimportedEnum { + UnimportedEnum_A = 0, + UnimportedEnum_B = 1, + UnimportedEnum_C = 2, + } UnimportedEnum; +} + class UnimportedEnum { public: enum Value { diff --git a/feature_tests/cpp2/include/UnimportedEnum.h b/feature_tests/cpp2/include/UnimportedEnum.h deleted file mode 100644 index 9c4ea29a5..000000000 --- a/feature_tests/cpp2/include/UnimportedEnum.h +++ /dev/null @@ -1,23 +0,0 @@ -#ifndef UnimportedEnum_H -#define UnimportedEnum_H - -#include -#include -#include -#include -#include "diplomat_runtime.h" - - -#include "UnimportedEnum.d.h" - -namespace capi { - - -extern "C" { - - -} // extern "C" - -} // namespace capi - -#endif // UnimportedEnum_H diff --git a/feature_tests/cpp2/include/UnimportedEnum.hpp b/feature_tests/cpp2/include/UnimportedEnum.hpp index 45421f370..7cd747ee1 100644 --- a/feature_tests/cpp2/include/UnimportedEnum.hpp +++ b/feature_tests/cpp2/include/UnimportedEnum.hpp @@ -10,7 +10,14 @@ #include #include #include "diplomat_runtime.hpp" -#include "UnimportedEnum.h" + + +namespace capi { + extern "C" { + + + } // extern "C" +} inline capi::UnimportedEnum UnimportedEnum::AsFFI() const { diff --git a/feature_tests/cpp2/include/Unnamespaced.d.h b/feature_tests/cpp2/include/Unnamespaced.d.h deleted file mode 100644 index 3b4a6fcf0..000000000 --- a/feature_tests/cpp2/include/Unnamespaced.d.h +++ /dev/null @@ -1,20 +0,0 @@ -#ifndef Unnamespaced_D_H -#define Unnamespaced_D_H - -#include -#include -#include -#include -#include "diplomat_runtime.h" - - -namespace capi { - - -typedef struct Unnamespaced Unnamespaced; - - - -} // namespace capi - -#endif // Unnamespaced_D_H diff --git a/feature_tests/cpp2/include/Unnamespaced.d.hpp b/feature_tests/cpp2/include/Unnamespaced.d.hpp index 9a289f55a..58b6a896b 100644 --- a/feature_tests/cpp2/include/Unnamespaced.d.hpp +++ b/feature_tests/cpp2/include/Unnamespaced.d.hpp @@ -9,7 +9,6 @@ #include #include "diplomat_runtime.hpp" #include "CPPRenamedAttrEnum.d.hpp" -#include "Unnamespaced.d.h" namespace ns { class AttrOpaque1Renamed; @@ -17,6 +16,10 @@ class CPPRenamedAttrEnum; } +namespace capi { + typedef struct Unnamespaced Unnamespaced; +} + class Unnamespaced { public: diff --git a/feature_tests/cpp2/include/Unnamespaced.h b/feature_tests/cpp2/include/Unnamespaced.h deleted file mode 100644 index 6daddb5de..000000000 --- a/feature_tests/cpp2/include/Unnamespaced.h +++ /dev/null @@ -1,31 +0,0 @@ -#ifndef Unnamespaced_H -#define Unnamespaced_H - -#include -#include -#include -#include -#include "diplomat_runtime.h" - -#include "AttrEnum.d.h" -#include "AttrOpaque1.d.h" - -#include "Unnamespaced.d.h" - -namespace capi { - - -extern "C" { - -Unnamespaced* namespace_Unnamespaced_make(AttrEnum _e); - -void namespace_Unnamespaced_use_namespaced(const Unnamespaced* self, const AttrOpaque1* _n); - - -void namespace_Unnamespaced_destroy(Unnamespaced* self); - -} // extern "C" - -} // namespace capi - -#endif // Unnamespaced_H diff --git a/feature_tests/cpp2/include/Unnamespaced.hpp b/feature_tests/cpp2/include/Unnamespaced.hpp index bbe0fb0b3..dca229cc9 100644 --- a/feature_tests/cpp2/include/Unnamespaced.hpp +++ b/feature_tests/cpp2/include/Unnamespaced.hpp @@ -12,9 +12,21 @@ #include "diplomat_runtime.hpp" #include "AttrOpaque1Renamed.hpp" #include "CPPRenamedAttrEnum.hpp" -#include "Unnamespaced.h" +namespace capi { + extern "C" { + + Unnamespaced* namespace_Unnamespaced_make(AttrEnum _e); + + void namespace_Unnamespaced_use_namespaced(const Unnamespaced* self, const AttrOpaque1* _n); + + + void namespace_Unnamespaced_destroy(Unnamespaced* self); + + } // extern "C" +} + inline std::unique_ptr Unnamespaced::make(ns::CPPRenamedAttrEnum _e) { auto result = capi::namespace_Unnamespaced_make(_e.AsFFI()); return std::unique_ptr(Unnamespaced::FromFFI(result)); diff --git a/feature_tests/cpp2/include/Utf16Wrap.d.h b/feature_tests/cpp2/include/Utf16Wrap.d.h deleted file mode 100644 index 028c61fd2..000000000 --- a/feature_tests/cpp2/include/Utf16Wrap.d.h +++ /dev/null @@ -1,20 +0,0 @@ -#ifndef Utf16Wrap_D_H -#define Utf16Wrap_D_H - -#include -#include -#include -#include -#include "diplomat_runtime.h" - - -namespace capi { - - -typedef struct Utf16Wrap Utf16Wrap; - - - -} // namespace capi - -#endif // Utf16Wrap_D_H diff --git a/feature_tests/cpp2/include/Utf16Wrap.d.hpp b/feature_tests/cpp2/include/Utf16Wrap.d.hpp index c75fb6267..55eae1142 100644 --- a/feature_tests/cpp2/include/Utf16Wrap.d.hpp +++ b/feature_tests/cpp2/include/Utf16Wrap.d.hpp @@ -8,9 +8,12 @@ #include #include #include "diplomat_runtime.hpp" -#include "Utf16Wrap.d.h" +namespace capi { + typedef struct Utf16Wrap Utf16Wrap; +} + class Utf16Wrap { public: diff --git a/feature_tests/cpp2/include/Utf16Wrap.h b/feature_tests/cpp2/include/Utf16Wrap.h deleted file mode 100644 index 36806a674..000000000 --- a/feature_tests/cpp2/include/Utf16Wrap.h +++ /dev/null @@ -1,33 +0,0 @@ -#ifndef Utf16Wrap_H -#define Utf16Wrap_H - -#include -#include -#include -#include -#include "diplomat_runtime.h" - - -#include "Utf16Wrap.d.h" - -namespace capi { - - -extern "C" { - -Utf16Wrap* Utf16Wrap_from_utf16(const char16_t* input_data, size_t input_len); - -void Utf16Wrap_get_debug_str(const Utf16Wrap* self, DiplomatWrite* write); - -DiplomatString16View Utf16Wrap_borrow_cont(const Utf16Wrap* self); - -DiplomatString16View Utf16Wrap_owned(const Utf16Wrap* self); - - -void Utf16Wrap_destroy(Utf16Wrap* self); - -} // extern "C" - -} // namespace capi - -#endif // Utf16Wrap_H diff --git a/feature_tests/cpp2/include/Utf16Wrap.hpp b/feature_tests/cpp2/include/Utf16Wrap.hpp index cb114e6e8..8e3427d26 100644 --- a/feature_tests/cpp2/include/Utf16Wrap.hpp +++ b/feature_tests/cpp2/include/Utf16Wrap.hpp @@ -10,9 +10,25 @@ #include #include #include "diplomat_runtime.hpp" -#include "Utf16Wrap.h" +namespace capi { + extern "C" { + + Utf16Wrap* Utf16Wrap_from_utf16(const char16_t* input_data, size_t input_len); + + void Utf16Wrap_get_debug_str(const Utf16Wrap* self, DiplomatWrite* write); + + DiplomatString16View Utf16Wrap_borrow_cont(const Utf16Wrap* self); + + DiplomatString16View Utf16Wrap_owned(const Utf16Wrap* self); + + + void Utf16Wrap_destroy(Utf16Wrap* self); + + } // extern "C" +} + inline std::unique_ptr Utf16Wrap::from_utf16(std::u16string_view input) { auto result = capi::Utf16Wrap_from_utf16(input.data(), input.size()); diff --git a/tool/src/c2/mod.rs b/tool/src/c2/mod.rs index c3c7a5641..4923717b4 100644 --- a/tool/src/c2/mod.rs +++ b/tool/src/c2/mod.rs @@ -3,6 +3,8 @@ mod header; mod ty; pub use self::formatter::CFormatter; +pub(crate) use self::header::Header; +pub(crate) use self::ty::TyGenContext; use crate::common::{ErrorStore, FileMap}; use askama::Template; @@ -22,8 +24,8 @@ pub struct CContext<'tcx> { #[derive(Template)] #[template(path = "c2/runtime.h.jinja", escape = "none")] -struct RuntimeTemplate { - is_for_cpp: bool, +pub(crate) struct RuntimeTemplate { + pub is_for_cpp: bool, } impl<'tcx> CContext<'tcx> { diff --git a/tool/src/c2/ty.rs b/tool/src/c2/ty.rs index d8623c6ef..2cc920835 100644 --- a/tool/src/c2/ty.rs +++ b/tool/src/c2/ty.rs @@ -1,6 +1,8 @@ use super::formatter::CFormatter; use super::header::Header; +use crate::common::ErrorStore; use askama::Template; +use diplomat_core::hir::TypeContext; use diplomat_core::hir::{ self, FloatType, IntSizeType, IntType, OpaqueOwner, ReturnableStructDef, StructPathLike, TyPosition, Type, TypeDef, TypeId, @@ -31,20 +33,39 @@ impl<'tcx> super::CContext<'tcx> { let impl_header_path = self.formatter.fmt_impl_header_path(id); let _guard = self.errors.set_context_ty(ty.name().as_str().into()); + let tygen = self.ty_gen_context(id, decl_header_path, impl_header_path); + let decl_header = match ty { - TypeDef::Enum(e) => self.gen_enum_def(e, id, &decl_header_path), - TypeDef::Opaque(o) => self.gen_opaque_def(o, id, &decl_header_path), - TypeDef::Struct(s) => self.gen_struct_def(s, id, &decl_header_path), - TypeDef::OutStruct(s) => self.gen_struct_def(s, id, &decl_header_path), + TypeDef::Enum(e) => tygen.gen_enum_def(e), + TypeDef::Opaque(o) => tygen.gen_opaque_def(o), + TypeDef::Struct(s) => tygen.gen_struct_def(s), + TypeDef::OutStruct(s) => tygen.gen_struct_def(s), _ => unreachable!("unknown AST/HIR variant"), }; - let impl_header = self.gen_impl(ty, id, &decl_header_path, &impl_header_path); + let impl_header = tygen.gen_impl(ty); self.files - .add_file(decl_header_path, decl_header.to_string()); + .add_file(tygen.decl_header_path, decl_header.to_string()); self.files - .add_file(impl_header_path, impl_header.to_string()); + .add_file(tygen.impl_header_path, impl_header.to_string()); + } + + pub(crate) fn ty_gen_context<'cx>( + &'cx self, + id: TypeId, + decl_header_path: String, + impl_header_path: String, + ) -> TyGenContext<'cx, 'tcx> { + TyGenContext { + tcx: self.tcx, + formatter: &self.formatter, + errors: &self.errors, + is_for_cpp: self.is_for_cpp, + id, + decl_header_path, + impl_header_path, + } } } @@ -84,18 +105,26 @@ struct MethodTemplate<'a> { name: Cow<'a, str>, } -impl<'tcx> super::CContext<'tcx> { - pub fn gen_enum_def( - &self, - def: &'tcx hir::EnumDef, - id: TypeId, - decl_header_path: &str, - ) -> Header { - let mut decl_header = Header::new(decl_header_path.into(), self.is_for_cpp); - let ty_name = self.formatter.fmt_type_name(id); +/// The context used for generating a particular type +/// +/// Also used by C++ generation code +pub(crate) struct TyGenContext<'cx, 'tcx> { + pub(crate) tcx: &'tcx TypeContext, + pub(crate) formatter: &'cx CFormatter<'tcx>, + pub(crate) errors: &'cx ErrorStore<'tcx, String>, + pub(crate) is_for_cpp: bool, + pub(crate) id: TypeId, + pub(crate) decl_header_path: String, + pub(crate) impl_header_path: String, +} + +impl<'cx, 'tcx> TyGenContext<'cx, 'tcx> { + pub fn gen_enum_def(&self, def: &'tcx hir::EnumDef) -> Header { + let mut decl_header = Header::new(self.decl_header_path.clone(), self.is_for_cpp); + let ty_name = self.formatter.fmt_type_name(self.id); EnumTemplate { ty: def, - fmt: &self.formatter, + fmt: self.formatter, ty_name: &ty_name, } .render_into(&mut decl_header) @@ -104,14 +133,9 @@ impl<'tcx> super::CContext<'tcx> { decl_header } - pub fn gen_opaque_def( - &self, - _def: &'tcx hir::OpaqueDef, - id: TypeId, - decl_header_path: &str, - ) -> Header { - let mut decl_header = Header::new(decl_header_path.into(), self.is_for_cpp); - let ty_name = self.formatter.fmt_type_name(id); + pub fn gen_opaque_def(&self, _def: &'tcx hir::OpaqueDef) -> Header { + let mut decl_header = Header::new(self.decl_header_path.clone(), self.is_for_cpp); + let ty_name = self.formatter.fmt_type_name(self.id); OpaqueTemplate { ty_name } .render_into(&mut decl_header) .unwrap(); @@ -119,14 +143,9 @@ impl<'tcx> super::CContext<'tcx> { decl_header } - pub fn gen_struct_def( - &self, - def: &'tcx hir::StructDef

, - id: TypeId, - decl_header_path: &str, - ) -> Header { - let mut decl_header = Header::new(decl_header_path.into(), self.is_for_cpp); - let ty_name = self.formatter.fmt_type_name(id); + pub fn gen_struct_def(&self, def: &'tcx hir::StructDef

) -> Header { + let mut decl_header = Header::new(self.decl_header_path.clone(), self.is_for_cpp); + let ty_name = self.formatter.fmt_type_name(self.id); let mut fields = vec![]; for field in def.fields.iter() { self.gen_ty_decl( @@ -145,14 +164,8 @@ impl<'tcx> super::CContext<'tcx> { decl_header } - pub fn gen_impl( - &self, - ty: hir::TypeDef<'tcx>, - id: TypeId, - decl_header_path: &str, - impl_header_path: &str, - ) -> Header { - let mut impl_header = Header::new(impl_header_path.into(), self.is_for_cpp); + pub fn gen_impl(&self, ty: hir::TypeDef<'tcx>) -> Header { + let mut impl_header = Header::new(self.impl_header_path.clone(), self.is_for_cpp); let mut methods = vec![]; for method in ty.methods() { if method.attrs.disable { @@ -160,16 +173,16 @@ impl<'tcx> super::CContext<'tcx> { continue; } let _guard = self.errors.set_context_method( - self.formatter.fmt_type_name_diagnostics(id), + self.formatter.fmt_type_name_diagnostics(self.id), method.name.as_str().into(), ); - methods.push(self.gen_method(id, method, &mut impl_header)); + methods.push(self.gen_method(method, &mut impl_header)); } - let ty_name = self.formatter.fmt_type_name(id); + let ty_name = self.formatter.fmt_type_name(self.id); let dtor_name = if let TypeDef::Opaque(_) = ty { - Some(self.formatter.fmt_dtor_name(id)) + Some(self.formatter.fmt_dtor_name(self.id)) } else { None }; @@ -182,26 +195,21 @@ impl<'tcx> super::CContext<'tcx> { .render_into(&mut impl_header) .unwrap(); - impl_header.decl_include = Some(decl_header_path.into()); + impl_header.decl_include = Some(self.decl_header_path.clone()); // In some cases like generating decls for `self` parameters, // a header will get its own includes. Instead of // trying to avoid pushing them, it's cleaner to just pull them out // once done - impl_header.includes.remove(impl_header_path); - impl_header.includes.remove(decl_header_path); + impl_header.includes.remove(&self.impl_header_path); + impl_header.includes.remove(&self.decl_header_path); impl_header } - fn gen_method( - &self, - id: TypeId, - method: &'tcx hir::Method, - header: &mut Header, - ) -> MethodTemplate<'tcx> { + fn gen_method(&self, method: &'tcx hir::Method, header: &mut Header) -> MethodTemplate<'tcx> { use diplomat_core::hir::{ReturnType, SuccessType}; - let method_name = self.formatter.fmt_method_name(id, method); + let method_name = self.formatter.fmt_method_name(self.id, method); let mut param_decls = Vec::new(); if let Some(ref self_ty) = method.param_self { let self_ty = self_ty.ty.clone().into(); diff --git a/tool/src/cpp2/formatter.rs b/tool/src/cpp2/formatter.rs index 5121d8e00..c539899ad 100644 --- a/tool/src/cpp2/formatter.rs +++ b/tool/src/cpp2/formatter.rs @@ -14,7 +14,7 @@ use std::borrow::Cow; /// This type may be used by other backends attempting to figure out the names /// of C types and methods. pub struct Cpp2Formatter<'tcx> { - c: CFormatter<'tcx>, + pub(crate) c: CFormatter<'tcx>, } impl<'tcx> Cpp2Formatter<'tcx> { @@ -64,13 +64,6 @@ impl<'tcx> Cpp2Formatter<'tcx> { format!("{type_name}.hpp") } - pub fn fmt_c_decl_header_path(&self, id: TypeId) -> String { - self.c.fmt_decl_header_path(id) - } - pub fn fmt_c_impl_header_path(&self, id: TypeId) -> String { - self.c.fmt_impl_header_path(id) - } - /// Format an enum variant. pub fn fmt_enum_variant(&self, variant: &'tcx hir::EnumVariant) -> Cow<'tcx, str> { variant.attrs.rename.apply(variant.name.as_str().into()) diff --git a/tool/src/cpp2/mod.rs b/tool/src/cpp2/mod.rs index cc0bc6de1..76a77fcde 100644 --- a/tool/src/cpp2/mod.rs +++ b/tool/src/cpp2/mod.rs @@ -3,6 +3,7 @@ mod header; mod ty; use crate::common::{ErrorStore, FileMap}; +use askama::Template; use diplomat_core::hir::TypeContext; use formatter::Cpp2Formatter; @@ -29,10 +30,22 @@ impl<'tcx> Cpp2Context<'tcx> { /// /// Will populate self.files as a result pub fn run(&self) { + let mut c_runtime = String::new(); + crate::c2::RuntimeTemplate { is_for_cpp: true } + .render_into(&mut c_runtime) + .unwrap(); + + self.files.add_file( + // TODO rename to diplomat_c_runtime.hpp once C++1 is removed + "diplomat_runtime.h".into(), + c_runtime, + ); + self.files.add_file( "diplomat_runtime.hpp".into(), crate::cpp::RUNTIME_HPP.into(), ); + for (id, ty) in self.tcx.all_types() { self.gen_ty(id, ty) } diff --git a/tool/src/cpp2/ty.rs b/tool/src/cpp2/ty.rs index f08360efe..d36dbcc78 100644 --- a/tool/src/cpp2/ty.rs +++ b/tool/src/cpp2/ty.rs @@ -1,6 +1,8 @@ use super::header::Header; use super::Cpp2Context; use super::Cpp2Formatter; +use crate::c2::Header as C2Header; +use crate::c2::TyGenContext as C2TyGenContext; use askama::Template; use diplomat_core::hir::{ self, Mutability, OpaqueOwner, ReturnType, SelfType, StructPathLike, SuccessType, TyPosition, @@ -20,20 +22,15 @@ impl<'tcx> super::Cpp2Context<'tcx> { let impl_header_path = self.formatter.fmt_impl_header_path(id); let mut impl_header = Header::new(impl_header_path.clone()); + let c = self.c2_gen_context(id, decl_header_path.clone(), impl_header_path.clone()); + let mut context = TyGenContext { cx: self, + c, decl_header: &mut decl_header, impl_header: &mut impl_header, }; context.impl_header.decl_include = Some(decl_header_path.clone()); - context - .decl_header - .includes - .insert(self.formatter.fmt_c_decl_header_path(id)); - context - .impl_header - .includes - .insert(self.formatter.fmt_c_impl_header_path(id)); let guard = self.errors.set_context_ty(ty.name().as_str().into()); match ty { @@ -60,6 +57,23 @@ impl<'tcx> super::Cpp2Context<'tcx> { self.files .add_file(impl_header_path, impl_header.to_string()); } + + fn c2_gen_context<'cx>( + &'cx self, + id: TypeId, + decl_header_path: String, + impl_header_path: String, + ) -> C2TyGenContext<'cx, 'tcx> { + C2TyGenContext { + tcx: self.tcx, + formatter: &self.formatter.c, + errors: &self.errors, + is_for_cpp: true, + id, + decl_header_path, + impl_header_path, + } + } } /// An expression with a corresponding variable name, such as a struct field or a function parameter. @@ -109,6 +123,7 @@ struct MethodInfo<'a> { /// Context for generating a particular type's header pub struct TyGenContext<'ccx, 'tcx, 'header> { pub cx: &'ccx Cpp2Context<'tcx>, + pub c: C2TyGenContext<'ccx, 'tcx>, pub impl_header: &'header mut Header, pub decl_header: &'header mut Header, } @@ -124,6 +139,8 @@ impl<'ccx, 'tcx: 'ccx, 'header> TyGenContext<'ccx, 'tcx, 'header> { let type_name = self.cx.formatter.fmt_type_name(id); let type_name_unnamespaced = self.cx.formatter.fmt_type_name_unnamespaced(id); let ctype = self.cx.formatter.fmt_c_type_name(id); + let c_header = self.c.gen_enum_def(ty); + let c_impl_header = self.c.gen_impl(ty.into()); let methods = ty .methods @@ -141,6 +158,7 @@ impl<'ccx, 'tcx: 'ccx, 'header> TyGenContext<'ccx, 'tcx, 'header> { methods: &'a [MethodInfo<'a>], namespace: Option<&'a str>, type_name_unnamespaced: &'a str, + c_header: C2Header, } DeclTemplate { @@ -151,6 +169,7 @@ impl<'ccx, 'tcx: 'ccx, 'header> TyGenContext<'ccx, 'tcx, 'header> { methods: methods.as_slice(), namespace: ty.attrs.namespace.as_deref(), type_name_unnamespaced: &type_name_unnamespaced, + c_header, } .render_into(self.decl_header) .unwrap(); @@ -163,6 +182,7 @@ impl<'ccx, 'tcx: 'ccx, 'header> TyGenContext<'ccx, 'tcx, 'header> { type_name: &'a str, ctype: &'a str, methods: &'a [MethodInfo<'a>], + c_impl_header: C2Header, } ImplTemplate { @@ -171,13 +191,10 @@ impl<'ccx, 'tcx: 'ccx, 'header> TyGenContext<'ccx, 'tcx, 'header> { type_name: &type_name, ctype: &ctype, methods: methods.as_slice(), + c_impl_header, } .render_into(self.impl_header) .unwrap(); - - self.decl_header - .includes - .insert(self.cx.formatter.fmt_c_decl_header_path(id)); } pub fn gen_opaque_def(&mut self, ty: &'tcx hir::OpaqueDef, id: TypeId) { @@ -185,6 +202,8 @@ impl<'ccx, 'tcx: 'ccx, 'header> TyGenContext<'ccx, 'tcx, 'header> { let type_name_unnamespaced = self.cx.formatter.fmt_type_name_unnamespaced(id); let ctype = self.cx.formatter.fmt_c_type_name(id); let dtor_name = self.cx.formatter.fmt_c_dtor_name(id); + let c_header = self.c.gen_opaque_def(ty); + let c_impl_header = self.c.gen_impl(ty.into()); let methods = ty .methods @@ -202,6 +221,7 @@ impl<'ccx, 'tcx: 'ccx, 'header> TyGenContext<'ccx, 'tcx, 'header> { methods: &'a [MethodInfo<'a>], namespace: Option<&'a str>, type_name_unnamespaced: &'a str, + c_header: C2Header, } DeclTemplate { @@ -212,6 +232,7 @@ impl<'ccx, 'tcx: 'ccx, 'header> TyGenContext<'ccx, 'tcx, 'header> { methods: methods.as_slice(), namespace: ty.attrs.namespace.as_deref(), type_name_unnamespaced: &type_name_unnamespaced, + c_header, } .render_into(self.decl_header) .unwrap(); @@ -225,6 +246,7 @@ impl<'ccx, 'tcx: 'ccx, 'header> TyGenContext<'ccx, 'tcx, 'header> { ctype: &'a str, dtor_name: &'a str, methods: &'a [MethodInfo<'a>], + c_impl_header: C2Header, } ImplTemplate { @@ -234,13 +256,10 @@ impl<'ccx, 'tcx: 'ccx, 'header> TyGenContext<'ccx, 'tcx, 'header> { ctype: &ctype, dtor_name: &dtor_name, methods: methods.as_slice(), + c_impl_header, } .render_into(self.impl_header) .unwrap(); - - self.decl_header - .includes - .insert(self.cx.formatter.fmt_c_decl_header_path(id)); } pub fn gen_struct_def(&mut self, def: &'tcx hir::StructDef

, id: TypeId) { @@ -248,6 +267,9 @@ impl<'ccx, 'tcx: 'ccx, 'header> TyGenContext<'ccx, 'tcx, 'header> { let type_name_unnamespaced = self.cx.formatter.fmt_type_name_unnamespaced(id); let ctype = self.cx.formatter.fmt_c_type_name(id); + let c_header = self.c.gen_struct_def(def); + let c_impl_header = self.c.gen_impl(def.into()); + let field_decls = def .fields .iter() @@ -283,6 +305,7 @@ impl<'ccx, 'tcx: 'ccx, 'header> TyGenContext<'ccx, 'tcx, 'header> { methods: &'a [MethodInfo<'a>], namespace: Option<&'a str>, type_name_unnamespaced: &'a str, + c_header: C2Header, } DeclTemplate { @@ -294,6 +317,7 @@ impl<'ccx, 'tcx: 'ccx, 'header> TyGenContext<'ccx, 'tcx, 'header> { methods: methods.as_slice(), namespace: def.attrs.namespace.as_deref(), type_name_unnamespaced: &type_name_unnamespaced, + c_header, } .render_into(self.decl_header) .unwrap(); @@ -308,15 +332,7 @@ impl<'ccx, 'tcx: 'ccx, 'header> TyGenContext<'ccx, 'tcx, 'header> { cpp_to_c_fields: &'a [NamedExpression<'a>], c_to_cpp_fields: &'a [NamedExpression<'a>], methods: &'a [MethodInfo<'a>], - } - - if def.fields.is_empty() { - self.impl_header - .includes - .remove(&self.cx.formatter.fmt_c_impl_header_path(id)); - self.decl_header - .includes - .remove(&self.cx.formatter.fmt_c_decl_header_path(id)); + c_impl_header: C2Header, } ImplTemplate { @@ -327,6 +343,7 @@ impl<'ccx, 'tcx: 'ccx, 'header> TyGenContext<'ccx, 'tcx, 'header> { cpp_to_c_fields: cpp_to_c_fields.as_slice(), c_to_cpp_fields: c_to_cpp_fields.as_slice(), methods: methods.as_slice(), + c_impl_header, } .render_into(self.impl_header) .unwrap(); diff --git a/tool/src/lib.rs b/tool/src/lib.rs index 8b0cc03d0..e23dfd410 100644 --- a/tool/src/lib.rs +++ b/tool/src/lib.rs @@ -191,7 +191,7 @@ pub fn gen( let files = common::FileMap::default(); let mut context = cpp2::Cpp2Context::new(&tcx, files); context.run(); - out_texts.extend(context.files.take_files()); + out_texts = context.files.take_files(); let errors = context.errors.take_all(); diff --git a/tool/templates/cpp2/enum_decl.h.jinja b/tool/templates/cpp2/enum_decl.h.jinja index ba3e1b902..e5f8c32b1 100644 --- a/tool/templates/cpp2/enum_decl.h.jinja +++ b/tool/templates/cpp2/enum_decl.h.jinja @@ -1,4 +1,8 @@ -{%- if let Some(ns) = namespace -%} +namespace capi { + {{ c_header.body|trim|indent(4) }} +} + +{% if let Some(ns) = namespace -%} namespace {{ns}} { {%endif-%} class {{type_name_unnamespaced}} { diff --git a/tool/templates/cpp2/enum_impl.h.jinja b/tool/templates/cpp2/enum_impl.h.jinja index 7aa560102..837209c9e 100644 --- a/tool/templates/cpp2/enum_impl.h.jinja +++ b/tool/templates/cpp2/enum_impl.h.jinja @@ -1,3 +1,8 @@ +namespace capi { + {{ c_impl_header.body|trim|indent(4) }} +} + + inline {{ctype}} {{type_name}}::AsFFI() const { return static_cast<{{ctype}}>(value); } diff --git a/tool/templates/cpp2/opaque_decl.h.jinja b/tool/templates/cpp2/opaque_decl.h.jinja index d6c154916..34b4852fa 100644 --- a/tool/templates/cpp2/opaque_decl.h.jinja +++ b/tool/templates/cpp2/opaque_decl.h.jinja @@ -1,3 +1,7 @@ +namespace capi { + {{ c_header.body|trim|indent(4) }} +} + {% let const_ptr = fmt.fmt_c_ptr(type_name, Mutability::Immutable) -%} {% let mut_ptr = fmt.fmt_c_ptr(type_name, Mutability::Mutable) -%} {% let const_cptr = fmt.fmt_c_ptr(ctype, Mutability::Immutable) -%} diff --git a/tool/templates/cpp2/opaque_impl.h.jinja b/tool/templates/cpp2/opaque_impl.h.jinja index 44c04d15e..8cdd5dad1 100644 --- a/tool/templates/cpp2/opaque_impl.h.jinja +++ b/tool/templates/cpp2/opaque_impl.h.jinja @@ -1,3 +1,7 @@ +namespace capi { + {{ c_impl_header.body|trim|indent(4) }} +} + {% let const_ptr = fmt.fmt_c_ptr(type_name, Mutability::Immutable) -%} {% let mut_ptr = fmt.fmt_c_ptr(type_name, Mutability::Mutable) -%} {% let const_cptr = fmt.fmt_c_ptr(ctype, Mutability::Immutable) -%} diff --git a/tool/templates/cpp2/struct_decl.h.jinja b/tool/templates/cpp2/struct_decl.h.jinja index 65720ed22..561524540 100644 --- a/tool/templates/cpp2/struct_decl.h.jinja +++ b/tool/templates/cpp2/struct_decl.h.jinja @@ -1,4 +1,8 @@ -{%- if let Some(ns) = namespace -%} +namespace capi { + {{ c_header.body|trim|indent(4) }} +} + +{% if let Some(ns) = namespace -%} namespace {{ns}} { {%endif-%} struct {{type_name_unnamespaced}} { diff --git a/tool/templates/cpp2/struct_impl.h.jinja b/tool/templates/cpp2/struct_impl.h.jinja index b45a41849..a3da4a147 100644 --- a/tool/templates/cpp2/struct_impl.h.jinja +++ b/tool/templates/cpp2/struct_impl.h.jinja @@ -1,3 +1,7 @@ +namespace capi { + {{ c_impl_header.body|trim|indent(4) }} +} + {% for m in methods -%} {% include "method_impl.h.jinja" %}