summaryrefslogtreecommitdiff
path: root/engine-macros/src/reflection/visibility.rs
diff options
context:
space:
mode:
Diffstat (limited to 'engine-macros/src/reflection/visibility.rs')
-rw-r--r--engine-macros/src/reflection/visibility.rs45
1 files changed, 45 insertions, 0 deletions
diff --git a/engine-macros/src/reflection/visibility.rs b/engine-macros/src/reflection/visibility.rs
new file mode 100644
index 0000000..c9e8524
--- /dev/null
+++ b/engine-macros/src/reflection/visibility.rs
@@ -0,0 +1,45 @@
+use quote::quote;
+
+use crate::util::syn_path_to_string;
+
+pub fn generate(
+ visibility: &syn::Visibility,
+ engine_crate_path: &syn::Path,
+) -> proc_macro2::TokenStream
+{
+ match visibility {
+ syn::Visibility::Public(_) => {
+ quote! { #engine_crate_path::reflection::Visibility::Pub }
+ }
+ syn::Visibility::Restricted(vis_restricted) => {
+ let vis_scope = if vis_restricted.in_token.is_some() {
+ let in_path = syn_path_to_string(&vis_restricted.path);
+
+ quote! {
+ #engine_crate_path::reflection::VisibilityScope::In(
+ std::borrow::Cow::Borrowed(#in_path)
+ )
+ }
+ } else {
+ let Some(scope) = vis_restricted.path.get_ident() else {
+ unreachable!();
+ };
+
+ if scope == "crate" {
+ quote! { #engine_crate_path::reflection::VisibilityScope::Crate }
+ } else if scope == "super" {
+ quote! { #engine_crate_path::reflection::VisibilityScope::Super }
+ } else if scope == "self" {
+ quote! { #engine_crate_path::reflection::VisibilityScope::SelfModule }
+ } else {
+ unreachable!();
+ }
+ };
+
+ quote! { #engine_crate_path::reflection::Visibility::PubScoped(#vis_scope) }
+ }
+ syn::Visibility::Inherited => {
+ quote! { #engine_crate_path::reflection::Visibility::Private }
+ }
+ }
+}