Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions crates/stub-parser/src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -959,7 +959,7 @@ impl ArgInfoBuilder<'_> {
{class_attributes_str}\
\n{space}class_entry\
\n}}",
properties.join("\n "),
properties.join("\n"),
constants.join("\n"),
methods_param = registration_params.join(", "),
module_parts = module_parts.join("\n"),
Expand Down Expand Up @@ -1485,11 +1485,16 @@ impl ArgInfoBuilder<'_> {
} else {
String::new()
};
format!(
"{}{extra_uses_code}{}\n{}\n",
let result = format!(
"{}{extra_uses_code}{}\n{}",
self.scope.as_uses(),
verification_code,
self.parts.join("\n")
)
);
let trimmed = result.trim().to_owned() + "\n";
if let Ok(regex) = Regex::new("\n\n\n+") {
return regex.replace_all(&trimmed, "\n\n").into_owned();
}
trimmed
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

/// Module for `CustomCastable` class.
pub(crate) mod CustomCastable {
use rsphp_macros_c::ZVAL_LONG;
Expand All @@ -24,7 +23,6 @@ pub(crate) mod CustomCastable {
)
};


unsafe {
let name: *mut zend_string = (zend_string_init_interned.expect("zend_string_init_interned should be set"))(
c"Attribute".as_ptr(),
Expand Down
3 changes: 0 additions & 3 deletions crates/stub-parser/tests/cases/backed_enum.expected
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@

/// Module for `Demo` enum.
pub(crate) mod Demo {
use rsphp_macros_c::ZVAL_STR;
use rsphp_sys::{IS_STRING, zend_class_entry, zend_enum_add_case_cstr, zend_string, zend_string_init, zval};


/// Register the `Demo` enum.
pub(crate) fn register_enum() -> *mut zend_class_entry {
let class_entry: *mut zend_class_entry = unsafe {
Expand Down Expand Up @@ -37,7 +35,6 @@ pub(crate) mod Demo {
}
};


class_entry
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@

/// Module for `Demo` class.
pub(crate) mod Demo {
use rsphp_macros_c::{ZEND_TYPE_INIT_MASK, ZVAL_LONG};
use rsphp_sys::{MAY_BE_LONG, ZEND_ACC_DEPRECATED, ZEND_ACC_PUBLIC, zend_class_entry, zend_declare_typed_class_constant, zend_string, zend_string_init_interned, zend_string_release_ex, zval};


/// Register the `Demo` class.
pub(crate) fn register_class() -> *mut zend_class_entry {
let mut ce: zend_class_entry = unsafe { std::mem::zeroed() };
Expand Down
3 changes: 0 additions & 3 deletions crates/stub-parser/tests/cases/class_constants.expected
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

/// Module for `CustomCastable` class.
pub(crate) mod CustomCastable {
use rsphp_macros_c::{ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE, ZEND_TYPE_INIT_MASK, ZVAL_LONG, ZVAL_UNDEF};
Expand Down Expand Up @@ -111,7 +110,6 @@ pub(crate) mod ConstantValues {
use rsphp_macros_c::{ZEND_TYPE_INIT_MASK, ZVAL_DOUBLE, ZVAL_STR};
use rsphp_sys::{MAY_BE_DOUBLE, MAY_BE_STRING, PHP_OS, ZEND_ACC_PUBLIC, ZEND_DEBUG, zend_class_entry, zend_declare_typed_class_constant, zend_string, zend_string_init, zend_string_init_interned, zend_string_release_ex, zval};


/// Register the `ConstantValues` class.
pub(crate) fn register_class() -> *mut zend_class_entry {
let mut ce: zend_class_entry = unsafe { std::mem::zeroed() };
Expand Down Expand Up @@ -164,7 +162,6 @@ pub(crate) mod ImplicitPublicConstant {
use rsphp_macros_c::{ZEND_TYPE_INIT_MASK, ZVAL_LONG};
use rsphp_sys::{MAY_BE_LONG, ZEND_ACC_PUBLIC, zend_class_entry, zend_declare_typed_class_constant, zend_string, zend_string_init_interned, zend_string_release_ex, zval};


/// Register the `ImplicitPublicConstant` class.
pub(crate) fn register_class() -> *mut zend_class_entry {
let mut ce: zend_class_entry = unsafe { std::mem::zeroed() };
Expand Down
5 changes: 0 additions & 5 deletions crates/stub-parser/tests/cases/class_extends.expected
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@

/// Module for `Base` class.
pub(crate) mod Base {
use rsphp_sys::zend_class_entry;


/// Register the `Base` class.
pub(crate) fn register_class() -> *mut zend_class_entry {
let mut ce: zend_class_entry = unsafe { std::mem::zeroed() };
Expand All @@ -16,15 +14,13 @@ pub(crate) mod Base {
)
};


class_entry
}
}
/// Module for `Demo` class.
pub(crate) mod Demo {
use rsphp_sys::zend_class_entry;


/// Register the `Demo` class.
pub(crate) fn register_class(zend_ce_Base: *mut zend_class_entry) -> *mut zend_class_entry {
let mut ce: zend_class_entry = unsafe { std::mem::zeroed() };
Expand All @@ -37,7 +33,6 @@ pub(crate) mod Demo {
)
};


class_entry
}
}
13 changes: 0 additions & 13 deletions crates/stub-parser/tests/cases/class_flags.expected
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@

/// Module for `Demo` class.
pub(crate) mod Demo {
use rsphp_sys::{ZEND_ACC_FINAL, ZEND_ACC_NO_DYNAMIC_PROPERTIES, zend_class_entry};


/// Register the `Demo` class.
pub(crate) fn register_class() -> *mut zend_class_entry {
let mut ce: zend_class_entry = unsafe { std::mem::zeroed() };
Expand All @@ -16,15 +14,13 @@ pub(crate) mod Demo {
)
};


class_entry
}
}
/// Module for `Demo2` class.
pub(crate) mod Demo2 {
use rsphp_sys::{ZEND_ACC_FINAL, ZEND_ACC_NOT_SERIALIZABLE, zend_class_entry};


/// Register the `Demo2` class.
pub(crate) fn register_class() -> *mut zend_class_entry {
let mut ce: zend_class_entry = unsafe { std::mem::zeroed() };
Expand All @@ -37,15 +33,13 @@ pub(crate) mod Demo2 {
)
};


class_entry
}
}
/// Module for `Demo3` class.
pub(crate) mod Demo3 {
use rsphp_sys::{ZEND_ACC_FINAL, ZEND_ACC_NOT_SERIALIZABLE, ZEND_ACC_NO_DYNAMIC_PROPERTIES, zend_class_entry};


/// Register the `Demo3` class.
pub(crate) fn register_class() -> *mut zend_class_entry {
let mut ce: zend_class_entry = unsafe { std::mem::zeroed() };
Expand All @@ -58,15 +52,13 @@ pub(crate) mod Demo3 {
)
};


class_entry
}
}
/// Module for `IsAbstract` class.
pub(crate) mod IsAbstract {
use rsphp_sys::{ZEND_ACC_ABSTRACT, zend_class_entry};


/// Register the `IsAbstract` class.
pub(crate) fn register_class() -> *mut zend_class_entry {
let mut ce: zend_class_entry = unsafe { std::mem::zeroed() };
Expand All @@ -79,15 +71,13 @@ pub(crate) mod IsAbstract {
)
};


class_entry
}
}
/// Module for `IsReadOnly` class.
pub(crate) mod IsReadOnly {
use rsphp_sys::{ZEND_ACC_FINAL, ZEND_ACC_READONLY_CLASS, zend_class_entry};


/// Register the `IsReadOnly` class.
pub(crate) fn register_class() -> *mut zend_class_entry {
let mut ce: zend_class_entry = unsafe { std::mem::zeroed() };
Expand All @@ -100,15 +90,13 @@ pub(crate) mod IsReadOnly {
)
};


class_entry
}
}
/// Module for `AllowsDynamicProperties` class.
pub(crate) mod AllowsDynamicProperties {
use rsphp_sys::{ZEND_ACC_ALLOW_DYNAMIC_PROPERTIES, zend_add_class_attribute, zend_class_entry, zend_string, zend_string_init_interned, zend_string_release_ex};


/// Register the `AllowsDynamicProperties` class.
pub(crate) fn register_class() -> *mut zend_class_entry {
let mut ce: zend_class_entry = unsafe { std::mem::zeroed() };
Expand All @@ -121,7 +109,6 @@ pub(crate) mod AllowsDynamicProperties {
)
};


unsafe {
let name: *mut zend_string = (zend_string_init_interned.expect("zend_string_init_interned should be set"))(
c"AllowDynamicProperties".as_ptr(),
Expand Down
5 changes: 0 additions & 5 deletions crates/stub-parser/tests/cases/class_implements.expected
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@

/// Module for `IDemo` interface.
pub(crate) mod IDemo {
use rsphp_sys::zend_class_entry;


/// Register the `IDemo` interface.
pub(crate) fn register_interface() -> *mut zend_class_entry {
let mut ce: zend_class_entry = unsafe { std::mem::zeroed() };
Expand All @@ -14,15 +12,13 @@ pub(crate) mod IDemo {
)
};


class_entry
}
}
/// Module for `Demo` class.
pub(crate) mod Demo {
use rsphp_sys::{zend_class_entry, zend_class_implements};


/// Register the `Demo` class.
pub(crate) fn register_class(zend_ce_IDemo: *mut zend_class_entry) -> *mut zend_class_entry {
let mut ce: zend_class_entry = unsafe { std::mem::zeroed() };
Expand All @@ -42,7 +38,6 @@ pub(crate) mod Demo {
)
};


class_entry
}
}
2 changes: 0 additions & 2 deletions crates/stub-parser/tests/cases/class_registration.expected
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@

/// Module for `Demo` class.
pub(crate) mod Demo {
use rsphp_macros_c::{ZEND_TYPE_INIT_MASK, ZVAL_UNDEF};
use rsphp_sys::{MAY_BE_LONG, ZEND_ACC_PRIVATE, zend_class_entry, zend_declare_typed_property, zend_string, zend_string_init, zend_string_release, zval};


/// Register the `Demo` class.
pub(crate) fn register_class() -> *mut zend_class_entry {
let mut ce: zend_class_entry = unsafe { std::mem::zeroed() };
Expand Down
2 changes: 0 additions & 2 deletions crates/stub-parser/tests/cases/default_unknown_param.expected
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

/// Module for `Demo` class.
pub(crate) mod Demo {
use rsphp_macros_c::ZEND_ARG_TYPE_INFO;
Expand All @@ -25,7 +24,6 @@ pub(crate) mod Demo {
)
};


class_entry
}
}
3 changes: 0 additions & 3 deletions crates/stub-parser/tests/cases/enum.expected
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@

/// Module for `CustomCasting\CastableTarget` enum.
pub(crate) mod CustomCasting_CastableTarget {
use rsphp_sys::{IS_UNDEF, zend_class_entry, zend_enum_add_case_cstr};


/// Register the `CustomCasting\CastableTarget` enum.
pub(crate) fn register_enum() -> *mut zend_class_entry {
let class_entry: *mut zend_class_entry = unsafe {
Expand All @@ -19,7 +17,6 @@ pub(crate) mod CustomCasting_CastableTarget {
zend_enum_add_case_cstr(class_entry, c"CAST_LONG".as_ptr(), std::ptr::null_mut());
};


class_entry
}
}
7 changes: 0 additions & 7 deletions crates/stub-parser/tests/cases/enum_types.expected
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@

/// Module for `Unbacked` enum.
pub(crate) mod Unbacked {
use rsphp_sys::{IS_UNDEF, zend_class_entry, zend_enum_add_case_cstr};


/// Register the `Unbacked` enum.
pub(crate) fn register_enum() -> *mut zend_class_entry {
let class_entry: *mut zend_class_entry = unsafe {
Expand All @@ -18,7 +16,6 @@ pub(crate) mod Unbacked {
zend_enum_add_case_cstr(class_entry, c"Bar".as_ptr(), std::ptr::null_mut());
};


class_entry
}
}
Expand All @@ -27,7 +24,6 @@ pub(crate) mod IntBacked {
use rsphp_macros_c::ZVAL_LONG;
use rsphp_sys::{IS_LONG, zend_class_entry, zend_enum_add_case_cstr, zval};


/// Register the `IntBacked` enum.
pub(crate) fn register_enum() -> *mut zend_class_entry {
let class_entry: *mut zend_class_entry = unsafe {
Expand All @@ -50,7 +46,6 @@ pub(crate) mod IntBacked {
}
};


class_entry
}
}
Expand All @@ -59,7 +54,6 @@ pub(crate) mod StringBacked {
use rsphp_macros_c::ZVAL_STR;
use rsphp_sys::{IS_STRING, zend_class_entry, zend_enum_add_case_cstr, zend_string, zend_string_init, zval};


/// Register the `StringBacked` enum.
pub(crate) fn register_enum() -> *mut zend_class_entry {
let class_entry: *mut zend_class_entry = unsafe {
Expand Down Expand Up @@ -92,7 +86,6 @@ pub(crate) mod StringBacked {
}
};


class_entry
}
}
1 change: 0 additions & 1 deletion crates/stub-parser/tests/cases/functions.expected
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,3 @@ pub(crate) const ARGINFO_TEST6: [zend_internal_arg_info; 2] = [
ZEND_ARG_INFO_FOR_FUNCTION_WITH_RETURN_TYPE_MASK!(0, 0, MAY_BE_LONG, 0),
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE!(0, "v", IS_LONG, 0, "123"),
];

3 changes: 0 additions & 3 deletions crates/stub-parser/tests/cases/interface_extends.expected
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@

/// Module for `HasMagic` interface.
pub(crate) mod HasMagic {
use rsphp_sys::{zend_class_entry, zend_class_implements};


/// Register the `HasMagic` interface.
pub(crate) fn register_interface(zend_ce_Countable: *mut zend_class_entry, zend_ce_Stringable: *mut zend_class_entry) -> *mut zend_class_entry {
let mut ce: zend_class_entry = unsafe { std::mem::zeroed() };
Expand All @@ -22,7 +20,6 @@ pub(crate) mod HasMagic {
)
};


class_entry
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@

/// Module for `CustomCasting\CastableTarget` enum.
pub(crate) mod CustomCasting_CastableTarget {
use rsphp_sys::{IS_UNDEF, zend_class_entry, zend_enum_add_case_cstr};


/// Register the `CustomCasting\CastableTarget` enum.
pub(crate) fn register_enum() -> *mut zend_class_entry {
let class_entry: *mut zend_class_entry = unsafe {
Expand All @@ -19,7 +17,6 @@ pub(crate) mod CustomCasting_CastableTarget {
zend_enum_add_case_cstr(class_entry, c"CAST_LONG".as_ptr(), std::ptr::null_mut());
};


class_entry
}
}
Expand Down Expand Up @@ -47,7 +44,6 @@ pub(crate) mod CustomCasting_HasCustomCast {
)
};


class_entry
}
}
Loading
Loading