Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rfc: inner class2 #3

Open
wants to merge 44 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
a6e974c
add new token
withinboredom Mar 8, 2025
ad91fee
create the new grammar
withinboredom Mar 8, 2025
095af03
add new ast pieces
withinboredom Mar 8, 2025
86b0c22
handle modifiers
withinboredom Mar 8, 2025
3ac09a6
handle compiling class declarations
withinboredom Mar 8, 2025
2042a8e
add initial implementation;
withinboredom Mar 8, 2025
6f196e2
get return types working
withinboredom Mar 9, 2025
2e7d28a
make ::class work
withinboredom Mar 9, 2025
92b0dc6
fix failing test
withinboredom Mar 9, 2025
f3f2c16
add another class
withinboredom Mar 9, 2025
551e139
add more tests to validate scope resolution keywords
withinboredom Mar 9, 2025
13d8b39
update reflection
withinboredom Mar 9, 2025
3f5e6af
enable visibility
withinboredom Mar 9, 2025
10551f5
add tests for autoloading
withinboredom Mar 9, 2025
78ef744
properly persist classes in opcache
withinboredom Mar 9, 2025
8855f01
handle return type visibility enforcement
withinboredom Mar 9, 2025
d1694f9
fix static member access
withinboredom Mar 11, 2025
5386389
move tests
withinboredom Mar 13, 2025
05ab0e0
add more tests and fix access modifiers
withinboredom Mar 13, 2025
b510b5f
add support for lexical scope
withinboredom Mar 13, 2025
eefea57
handle type visibility
withinboredom Mar 14, 2025
356c0f1
fix opcache
withinboredom Mar 14, 2025
d4bf058
fix test
withinboredom Mar 14, 2025
c669844
refine some error messages
withinboredom Mar 14, 2025
49a9427
add type check to return type
withinboredom Mar 14, 2025
4313dfb
fix tests
withinboredom Mar 14, 2025
0414f58
temporarily fix this test -- might want to undo this
withinboredom Mar 14, 2025
42eee19
clean up a bit and check readonly
withinboredom Mar 14, 2025
9f654a1
handle visibility of methods
withinboredom Mar 14, 2025
910fc8c
just do not cache -- more trouble than it is worth right now
withinboredom Mar 14, 2025
490ea8b
properly handle lexical scope
withinboredom Mar 14, 2025
15ea80c
handle long names
withinboredom Mar 14, 2025
4ee4332
handle more visibility
withinboredom Mar 14, 2025
566884c
handle constructor visibility
withinboredom Mar 15, 2025
53701d1
prevent static access
withinboredom Mar 15, 2025
b33d9c1
start making \\ the separator instead of :>
withinboredom Mar 23, 2025
8d471c7
update tests
withinboredom Mar 23, 2025
17fa07c
finish up edge cases and tests
withinboredom Mar 23, 2025
71a7f6d
fix traits
withinboredom Mar 23, 2025
2767025
make autoloading more effecient
withinboredom Mar 23, 2025
7119f6c
fix attributes
withinboredom Mar 23, 2025
a05c5db
properly handle searching up the scope
withinboredom Mar 23, 2025
3f31e15
refactor all-the-things
withinboredom Mar 24, 2025
141995f
refactor all-the-things
withinboredom Mar 24, 2025
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
2 changes: 1 addition & 1 deletion Zend/Optimizer/ssa_integrity.c
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ static inline bool is_defined(const zend_ssa *ssa, const zend_op_array *op_array
#define FAIL(...) do { \
if (status == SUCCESS) { \
fprintf(stderr, "\nIn function %s::%s (%s):\n", \
op_array->scope ? ZSTR_VAL(op_array->scope->name) : "", \
op_array->scope ? ZSTR_VAL(op_array->scope->namespaced_name.name) : "", \
op_array->function_name ? ZSTR_VAL(op_array->function_name) : "{main}", extra); \
} \
fprintf(stderr, __VA_ARGS__); \
Expand Down
12 changes: 6 additions & 6 deletions Zend/Optimizer/zend_dump.c
Original file line number Diff line number Diff line change
Expand Up @@ -221,9 +221,9 @@ static void zend_dump_type_info(uint32_t info, zend_class_entry *ce, int is_inst
fprintf(stderr, "class");
if (ce) {
if (is_instanceof) {
fprintf(stderr, " (instanceof %s)", ce->name->val);
fprintf(stderr, " (instanceof %s)", (ce->namespaced_name.name)->val);
} else {
fprintf(stderr, " (%s)", ce->name->val);
fprintf(stderr, " (%s)", (ce->namespaced_name.name)->val);
}
}
} else if ((info & MAY_BE_ANY) == MAY_BE_ANY) {
Expand Down Expand Up @@ -356,9 +356,9 @@ static void zend_dump_type_info(uint32_t info, zend_class_entry *ce, int is_inst
fprintf(stderr, "object");
if (ce) {
if (is_instanceof) {
fprintf(stderr, " (instanceof %s)", ce->name->val);
fprintf(stderr, " (instanceof %s)", (ce->namespaced_name.name)->val);
} else {
fprintf(stderr, " (%s)", ce->name->val);
fprintf(stderr, " (%s)", (ce->namespaced_name.name)->val);
}
}
}
Expand Down Expand Up @@ -931,8 +931,8 @@ static void zend_dump_block_header(const zend_cfg *cfg, const zend_op_array *op_
void zend_dump_op_array_name(const zend_op_array *op_array)
{
if (op_array->function_name) {
if (op_array->scope && op_array->scope->name) {
fprintf(stderr, "%s::%s", op_array->scope->name->val, op_array->function_name->val);
if (op_array->scope && op_array->scope->namespaced_name.name) {
fprintf(stderr, "%s::%s", (op_array->scope->namespaced_name.name)->val, op_array->function_name->val);
} else {
fprintf(stderr, "%s", op_array->function_name->val);
}
Expand Down
2 changes: 1 addition & 1 deletion Zend/Optimizer/zend_optimizer.c
Original file line number Diff line number Diff line change
Expand Up @@ -842,7 +842,7 @@ zend_class_entry *zend_optimizer_get_class_entry(
return Z_PTR_P(ce_zv);
}

if (op_array && op_array->scope && zend_string_equals_ci(op_array->scope->name, lcname)) {
if (op_array && op_array->scope && zend_string_equals_ci(op_array->scope->namespaced_name.name, lcname)) {
return op_array->scope;
}

Expand Down
2 changes: 1 addition & 1 deletion Zend/tests/errmsg/errmsg_027.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ class test {
echo "Done\n";
?>
--EXPECTF--
Fatal error: Class declarations may not be nested in %s on line %d
Fatal error: Class declarations may not be declared inside functions in %s on line %d
27 changes: 23 additions & 4 deletions Zend/zend.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,21 @@ struct _zend_unserialize_data;
typedef struct _zend_serialize_data zend_serialize_data;
typedef struct _zend_unserialize_data zend_unserialize_data;

typedef enum _zend_name_resolution_kind {
ZEND_NAME_LEXICAL_SCOPE,
ZEND_NAME_NAMESPACE,
} zend_name_resolution_kind;

typedef struct _zend_namespaced_name {
zend_string *name;
zend_string *resolved_name;
zend_name_resolution_kind kind;
union {
zend_class_entry *lexical_scope;
zend_string *namespace_name;
};
} zend_namespaced_name;

typedef struct _zend_class_name {
zend_string *name;
zend_string *lc_name;
Expand Down Expand Up @@ -146,11 +161,11 @@ struct _zend_inheritance_cache_entry {

struct _zend_class_entry {
char type;
zend_string *name;
zend_namespaced_name namespaced_name;
/* class_entry or string depending on ZEND_ACC_LINKED */
union {
zend_class_entry *parent;
zend_string *parent_name;
zend_namespaced_name *parent_name;
};
int refcount;
uint32_t ce_flags;
Expand All @@ -164,6 +179,10 @@ struct _zend_class_entry {
HashTable properties_info;
HashTable constants_table;

zend_class_entry *required_scope;
zend_class_entry *lexical_scope;
char required_scope_absolute;

ZEND_MAP_PTR_DEF(zend_class_mutable_data*, mutable_data);
zend_inheritance_cache_entry *inheritance_cache;

Expand Down Expand Up @@ -210,10 +229,10 @@ struct _zend_class_entry {
/* class_entry or string(s) depending on ZEND_ACC_LINKED */
union {
zend_class_entry **interfaces;
zend_class_name *interface_names;
zend_namespaced_name *interface_names;
};

zend_class_name *trait_names;
zend_namespaced_name *trait_names;
zend_trait_alias **trait_aliases;
zend_trait_precedence **trait_precedences;
HashTable *attributes;
Expand Down
Loading
Loading