Skip to content

Collections #15429

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

Draft
wants to merge 48 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
48 commits
Select commit Hold shift + click to select a range
31167bb
Collection: Add Token
derickr May 12, 2023
93c8497
Collection: Add Parser Rules
derickr May 12, 2023
1babb8c
Collection: Add AST Code
derickr May 12, 2023
1e6faf2
Collection: Clean Up Class Entry
derickr May 12, 2023
4b8fce9
Collection: Init and Storage
derickr May 12, 2023
982c297
Collection: Add test file
derickr May 12, 2023
1c4bb90
Collection: Add Interface
derickr May 12, 2023
84bf653
Collection: Add Write Handler
derickr May 12, 2023
56c4223
Collection: Make Check Type Public
derickr May 12, 2023
f845b94
Collection: Add Read Handler
derickr May 12, 2023
91e1ddc
Collection: Add Has Handler
derickr May 12, 2023
6d695b1
Collection: Add Unset Handler
derickr May 12, 2023
19c22ce
Collection: Add more tests
derickr May 4, 2023
97b0f82
Add 'collection' name for AST output
derickr May 5, 2023
546a89f
Split up collection syntax into collection(Seq|Dict)
derickr Jun 22, 2023
e7815be
Separated interfaces into SeqCollection and DictCollection
derickr Jun 22, 2023
41df61d
Add Seq::add and Dict:add functions
derickr Jun 22, 2023
c2084d3
Test for type checking against generic collection types.
Crell Jun 23, 2023
48d5e71
Add a representative sample of additional operations.
Crell Jun 24, 2023
7958ca1
Add tests for the sample operations. These will not pass yet, naturally.
Crell Jun 24, 2023
ac6e449
Comment out unimplemented functions
derickr Jun 26, 2023
1493f6b
Rename test file with logical names
derickr Jun 26, 2023
6c844dc
Mark tests as XFAIL
derickr Jun 26, 2023
052885d
Macro-ify function registration
derickr Jun 26, 2023
b7031ca
Implement Sequence' remove/has/get
derickr Jun 27, 2023
1c06826
Implement sequence 'update/with/without' functions
derickr Jun 28, 2023
1ff66ab
Implement dict 'remove/has/get/update/with/without' functions
derickr Jun 28, 2023
5128b48
Better error messages and more tests for unhappy paths
derickr Jun 30, 2023
ad6cbfc
Change syntax to: collection(Variant) name<<K => T>>
derickr Jun 30, 2023
41eabba
Use two seperate tokens so we can have a 'Collection' class again
derickr Jul 11, 2023
9ef908e
Implement Sequence::map()
derickr Jul 17, 2023
cf2b4c9
Change syntax to: collection(Variant) name<K => T>
derickr Jul 17, 2023
2ea005b
Implement Dictionary::map()
derickr Jul 18, 2023
3133071
Add new tokens to tokenizer extension
derickr Jul 28, 2023
ec42167
Simplify scanner as there can't be a classname with () in it anyway
derickr Jul 28, 2023
0beda3c
Implement Sequence::concat()
derickr Jul 31, 2023
ad90408
Implement Dictionary::concat()
derickr Jul 31, 2023
db2616d
Remove superfluous and wrong code
derickr Aug 7, 2023
de78df6
Implement Sequence::equals()
derickr Aug 7, 2023
93e95e3
Implement Sequence's compare_objects handler
derickr Aug 7, 2023
91d6fbc
Fixed segfault when value wasn't an object
derickr Aug 8, 2023
9b6ba6a
Implement Dictionary::equals() and comparison handler
derickr Aug 8, 2023
7128fff
Add short cut for comparisons if both objects are identical
derickr Aug 8, 2023
3ba4b11
Add test case to compare Seq with Dict
derickr Aug 8, 2023
d5c03b9
Implement Sequence::+ and Sequence::+= operators
derickr Aug 14, 2023
874d099
Renumber indexes in Sequence collections when an item is removed
derickr Aug 8, 2023
383b3e1
Fixed invocation for zend_compile_typename
derickr Jun 3, 2024
4693f3b
Add extra test file
derickr Jun 3, 2024
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
Prev Previous commit
Next Next commit
Collection: Add Read Handler
  • Loading branch information
derickr committed Aug 15, 2024
commit f845b94eaa1a74e959485b73775a891c39ed1e43
37 changes: 37 additions & 0 deletions Zend/zend_collection.c
Original file line number Diff line number Diff line change
Expand Up @@ -145,3 +145,40 @@ void zend_collection_add_item(zend_object *object, zval *offset, zval *value)
}

}

static int key_type_allowed(zend_class_entry *ce, zval *offset)
{
ZEND_ASSERT(ce->ce_flags & ZEND_ACC_COLLECTION);

if (ce->collection_key_type != Z_TYPE_P(offset)) {
zend_type_error(
"Key type %s of element does not match collection key type %s",
offset ? zend_zval_type_name(offset) : zend_get_type_by_const(IS_NULL),
zend_get_type_by_const(ce->collection_key_type)
);
return false;
}

return true;
}

zval *zend_collection_read_item(zend_object *object, zval *offset)
{
zval rv;
zval *value_prop, *value;
zend_class_entry *ce = object->ce;

if (!key_type_allowed(ce, offset)) {
return NULL;
}

value_prop = zend_read_property_ex(ce, object, ZSTR_KNOWN(ZEND_STR_VALUE), true, &rv);

if (Z_TYPE_P(offset) == IS_STRING) {
value = zend_hash_find(HASH_OF(value_prop), Z_STR_P(offset));
} else {
value = zend_hash_index_find(HASH_OF(value_prop), Z_LVAL_P(offset));
}

return value;
}
1 change: 1 addition & 0 deletions Zend/zend_collection.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ void zend_collection_register_handlers(zend_class_entry *ce);
void zend_collection_register_props(zend_class_entry *ce);

void zend_collection_add_item(zend_object *object, zval *offset, zval *value);
zval *zend_collection_read_item(zend_object *object, zval *offset);

END_EXTERN_C()

Expand Down
2 changes: 2 additions & 0 deletions Zend/zend_object_handlers.c
Original file line number Diff line number Diff line change
Expand Up @@ -1183,6 +1183,8 @@ ZEND_API zval *zend_std_read_dimension(zend_object *object, zval *offset, int ty
return NULL;
}
return rv;
} else if (zend_class_implements_interface(ce, zend_ce_collection)) {
return zend_collection_read_item(object, offset);
} else {
zend_bad_array_access(ce);
return NULL;
Expand Down