- 将StdUnorderedMap重命名为StdOrderedMap并在所有相关文件中更新引用 - 修改polyfills.php中std::unordered_map为std::ordered_map,std::map为std::unordered_map - 更新文档中关于标准容器的命名和功能描述 - 修复所有测试文件中关于容器类型的断言和期望值 - 调整编译器内部类型标识符从TYPE_STD_UNORDERED_MAP到TYPE_STD_ORDERED_MAP - 修改解析器中对标准容器类型的判断和处理逻辑 - 更新单元测试中的类型检查和声明获取方法pull/3/head
parent
18b4bf4ed6
commit
b3e489d334
25 changed files with 122 additions and 433 deletions
@ -1,19 +0,0 @@ |
|||||||
--TEST-- |
|
||||||
std unordered map: 001 |
|
||||||
--FILE-- |
|
||||||
<?php |
|
||||||
function main() { |
|
||||||
$map = std::unordered_map(native_types::type_int, native_types::type_int); |
|
||||||
$map[10] = 32; |
|
||||||
$map[10] += 10; |
|
||||||
$map[20] = 7; |
|
||||||
|
|
||||||
var_dump($map[10]); |
|
||||||
var_dump($map[20]); |
|
||||||
var_dump(count($map)); |
|
||||||
} |
|
||||||
?> |
|
||||||
--EXPECT-- |
|
||||||
int(42) |
|
||||||
int(7) |
|
||||||
int(2) |
|
||||||
@ -1,25 +0,0 @@ |
|||||||
--TEST-- |
|
||||||
std unordered map: string key |
|
||||||
--FILE-- |
|
||||||
<?php |
|
||||||
function main() { |
|
||||||
$map = std::unordered_map(complex_types::type_string, native_types::type_float); |
|
||||||
$map["alpha"] = 1.5; |
|
||||||
$map["beta"] = 2.5; |
|
||||||
$map["beta"] += 0.25; |
|
||||||
|
|
||||||
$key = "alpha"; |
|
||||||
var_dump($map[$key] == 1.5); |
|
||||||
var_dump($map["beta"] == 2.75); |
|
||||||
var_dump(count($map)); |
|
||||||
|
|
||||||
$map2 = std::unordered_map(complex_types::type_str, native_types::type_int); |
|
||||||
$map2["answer"] = 42; |
|
||||||
var_dump($map2["answer"]); |
|
||||||
} |
|
||||||
?> |
|
||||||
--EXPECT-- |
|
||||||
bool(true) |
|
||||||
bool(true) |
|
||||||
int(2) |
|
||||||
int(42) |
|
||||||
@ -1,48 +0,0 @@ |
|||||||
--TEST-- |
|
||||||
std unordered map: complex value types |
|
||||||
--FILE-- |
|
||||||
<?php |
|
||||||
class StdUnorderedMapComplexValue |
|
||||||
{ |
|
||||||
public function __construct(public int $value) |
|
||||||
{ |
|
||||||
} |
|
||||||
|
|
||||||
public function getValue(): int |
|
||||||
{ |
|
||||||
return $this->value; |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
function main() { |
|
||||||
$strings = std::unordered_map(native_types::type_int, complex_types::type_string); |
|
||||||
$strings[1] = 789; |
|
||||||
var_dump($strings[1]); |
|
||||||
|
|
||||||
$arrays = std::unordered_map(complex_types::type_string, complex_types::type_array); |
|
||||||
$arrays["item"] = ["name" => "unordered", "value" => 168]; |
|
||||||
$array = $arrays["item"]; |
|
||||||
var_dump($array["name"]); |
|
||||||
var_dump($array["value"]); |
|
||||||
|
|
||||||
$objects = std::unordered_map(native_types::type_int, complex_types::type_object); |
|
||||||
$objects[2] = new StdUnorderedMapComplexValue(21); |
|
||||||
var_dump($objects[2] instanceof StdUnorderedMapComplexValue); |
|
||||||
$object = $objects[2]->toObject(StdUnorderedMapComplexValue::class); |
|
||||||
var_dump($object->getValue()); |
|
||||||
|
|
||||||
$variants = std::unordered_map(native_types::type_int, complex_types::type_var); |
|
||||||
$variants[3] = false; |
|
||||||
$variants[4] = "variant"; |
|
||||||
var_dump($variants[3]); |
|
||||||
var_dump($variants[4]); |
|
||||||
} |
|
||||||
?> |
|
||||||
--EXPECT-- |
|
||||||
string(3) "789" |
|
||||||
string(9) "unordered" |
|
||||||
int(168) |
|
||||||
bool(true) |
|
||||||
int(21) |
|
||||||
bool(false) |
|
||||||
string(7) "variant" |
|
||||||
@ -1,44 +0,0 @@ |
|||||||
--TEST-- |
|
||||||
std unordered map: exact class value type |
|
||||||
--FILE-- |
|
||||||
<?php |
|
||||||
class StdUnorderedMapClassValue |
|
||||||
{ |
|
||||||
public function __construct(public int $value) |
|
||||||
{ |
|
||||||
} |
|
||||||
|
|
||||||
public function getValue(): int |
|
||||||
{ |
|
||||||
return $this->value; |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
class StdUnorderedMapClassValueChild extends StdUnorderedMapClassValue |
|
||||||
{ |
|
||||||
} |
|
||||||
|
|
||||||
function std_unordered_map_class_value_mixed(mixed $value): mixed |
|
||||||
{ |
|
||||||
return $value; |
|
||||||
} |
|
||||||
|
|
||||||
function main() { |
|
||||||
$map = std::unordered_map(complex_types::type_str, StdUnorderedMapClassValue::class); |
|
||||||
$map["a"] = new StdUnorderedMapClassValue(1); |
|
||||||
var_dump($map["a"]->getValue()); |
|
||||||
|
|
||||||
$map["b"] = std_unordered_map_class_value_mixed(new StdUnorderedMapClassValue(2)); |
|
||||||
var_dump($map["b"]->getValue()); |
|
||||||
|
|
||||||
try { |
|
||||||
$map["c"] = std_unordered_map_class_value_mixed(new StdUnorderedMapClassValueChild(3)); |
|
||||||
} catch (Throwable $e) { |
|
||||||
echo $e->getMessage(), "\n"; |
|
||||||
} |
|
||||||
} |
|
||||||
?> |
|
||||||
--EXPECT-- |
|
||||||
int(1) |
|
||||||
int(2) |
|
||||||
The parameter `object` must be instance of class `StdUnorderedMapClassValue`, object of `StdUnorderedMapClassValueChild` given |
|
||||||
@ -1,24 +0,0 @@ |
|||||||
--TEST-- |
|
||||||
std unordered map: unsafe_cast |
|
||||||
--FILE-- |
|
||||||
<?php |
|
||||||
function std_unordered_map_unsafe_ptr_update($source): void |
|
||||||
{ |
|
||||||
$map = $source->toStdUnorderedMap(native_types::type_int, native_types::type_int); |
|
||||||
var_dump($map[2]); |
|
||||||
$map[3] = 9; |
|
||||||
} |
|
||||||
|
|
||||||
function main() { |
|
||||||
$map = std::unordered_map(native_types::type_int, native_types::type_int); |
|
||||||
$map[1] = 1; |
|
||||||
$map[2] = 7; |
|
||||||
$map[3] = 3; |
|
||||||
|
|
||||||
std_unordered_map_unsafe_ptr_update($map); |
|
||||||
var_dump($map[3]); |
|
||||||
} |
|
||||||
?> |
|
||||||
--EXPECT-- |
|
||||||
int(7) |
|
||||||
int(9) |
|
||||||
@ -1,20 +0,0 @@ |
|||||||
--TEST-- |
|
||||||
std unordered map: unsafe_cast type mismatch |
|
||||||
--FILE-- |
|
||||||
<?php |
|
||||||
function std_unordered_map_unsafe_ptr_type_mismatch($source): void |
|
||||||
{ |
|
||||||
$map = $source->toStdUnorderedMap(native_types::type_int, native_types::type_float); |
|
||||||
} |
|
||||||
|
|
||||||
function main() { |
|
||||||
$map = std::unordered_map(native_types::type_int, native_types::type_int); |
|
||||||
try { |
|
||||||
std_unordered_map_unsafe_ptr_type_mismatch($map); |
|
||||||
} catch (TypeError $e) { |
|
||||||
echo $e->getMessage(), "\n"; |
|
||||||
} |
|
||||||
} |
|
||||||
?> |
|
||||||
--EXPECT-- |
|
||||||
std container type mismatch |
|
||||||
@ -1,21 +0,0 @@ |
|||||||
--TEST-- |
|
||||||
std unordered map: assign to PHP array |
|
||||||
--FILE-- |
|
||||||
<?php |
|
||||||
function main() { |
|
||||||
$map = std::unordered_map(native_types::type_int, native_types::type_int); |
|
||||||
$map[10] = 100; |
|
||||||
$map[20] = 200; |
|
||||||
|
|
||||||
$copy = $map; |
|
||||||
var_dump(is_array($copy)); |
|
||||||
var_dump(count($copy)); |
|
||||||
var_dump($copy[10]); |
|
||||||
var_dump($copy[20]); |
|
||||||
} |
|
||||||
?> |
|
||||||
--EXPECT-- |
|
||||||
bool(true) |
|
||||||
int(2) |
|
||||||
int(100) |
|
||||||
int(200) |
|
||||||
@ -1,25 +0,0 @@ |
|||||||
--TEST-- |
|
||||||
std unordered map: same type copy |
|
||||||
--FILE-- |
|
||||||
<?php |
|
||||||
function main() { |
|
||||||
$a = std::unordered_map(native_types::type_int, native_types::type_int); |
|
||||||
$b = std::unordered_map(native_types::type_int, native_types::type_int); |
|
||||||
|
|
||||||
$b[10] = 100; |
|
||||||
$b[20] = 200; |
|
||||||
$a = $b; |
|
||||||
|
|
||||||
var_dump(count($a)); |
|
||||||
var_dump($a[10]); |
|
||||||
var_dump($a[20]); |
|
||||||
|
|
||||||
$a[10] = 999; |
|
||||||
var_dump($b[10]); |
|
||||||
} |
|
||||||
?> |
|
||||||
--EXPECT-- |
|
||||||
int(2) |
|
||||||
int(100) |
|
||||||
int(200) |
|
||||||
int(100) |
|
||||||
@ -1,24 +0,0 @@ |
|||||||
--TEST-- |
|
||||||
std unordered_map: unset |
|
||||||
--FILE-- |
|
||||||
<?php |
|
||||||
function main() { |
|
||||||
$map = std::unordered_map(complex_types::type_string, native_types::type_int); |
|
||||||
$map["alpha"] = 10; |
|
||||||
$map["beta"] = 20; |
|
||||||
var_dump($map); |
|
||||||
unset($map["alpha"]); |
|
||||||
var_dump($map); |
|
||||||
} |
|
||||||
?> |
|
||||||
--EXPECT-- |
|
||||||
array(2) { |
|
||||||
["beta"]=> |
|
||||||
int(20) |
|
||||||
["alpha"]=> |
|
||||||
int(10) |
|
||||||
} |
|
||||||
array(1) { |
|
||||||
["beta"]=> |
|
||||||
int(20) |
|
||||||
} |
|
||||||
@ -1,32 +0,0 @@ |
|||||||
--TEST-- |
|
||||||
std map: unset |
|
||||||
--FILE-- |
|
||||||
<?php |
|
||||||
function main() { |
|
||||||
$map = std::unordered_map(complex_types::type_string, native_types::type_int); |
|
||||||
$map["alpha"] = 10; |
|
||||||
$map["beta"] = 20; |
|
||||||
$map["gamma"] = 30; |
|
||||||
|
|
||||||
foreach ($map as $k => $v) { |
|
||||||
var_dump($k, $v); |
|
||||||
} |
|
||||||
unset($map["beta"]); |
|
||||||
echo "unset-------------\n"; |
|
||||||
foreach ($map as $k => $v) { |
|
||||||
var_dump($k, $v); |
|
||||||
} |
|
||||||
} |
|
||||||
?> |
|
||||||
--EXPECT-- |
|
||||||
string(5) "gamma" |
|
||||||
int(30) |
|
||||||
string(4) "beta" |
|
||||||
int(20) |
|
||||||
string(5) "alpha" |
|
||||||
int(10) |
|
||||||
unset------------- |
|
||||||
string(5) "gamma" |
|
||||||
int(30) |
|
||||||
string(5) "alpha" |
|
||||||
int(10) |
|
||||||
Loading…
Reference in new issue