Skip to content

Commit b506865

Browse files
committed
Add PhpToken::__construct()
1 parent bb655e6 commit b506865

File tree

4 files changed

+77
-0
lines changed

4 files changed

+77
-0
lines changed
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
--TEST--
2+
PhpToken constructor
3+
--FILE--
4+
<?php
5+
6+
$token = new PhpToken(300, 'function');
7+
var_dump($token);
8+
$token = new PhpToken(300, 'function', 10);
9+
var_dump($token);
10+
$token = new PhpToken(300, 'function', 10, 100);
11+
var_dump($token);
12+
13+
?>
14+
--EXPECT--
15+
object(PhpToken)#1 (4) {
16+
["id"]=>
17+
int(300)
18+
["text"]=>
19+
string(8) "function"
20+
["line"]=>
21+
int(-1)
22+
["pos"]=>
23+
int(-1)
24+
}
25+
object(PhpToken)#2 (4) {
26+
["id"]=>
27+
int(300)
28+
["text"]=>
29+
string(8) "function"
30+
["line"]=>
31+
int(10)
32+
["pos"]=>
33+
int(-1)
34+
}
35+
object(PhpToken)#1 (4) {
36+
["id"]=>
37+
int(300)
38+
["text"]=>
39+
string(8) "function"
40+
["line"]=>
41+
int(10)
42+
["pos"]=>
43+
int(100)
44+
}

ext/tokenizer/tokenizer.c

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,29 @@ PHP_METHOD(PhpToken, getAll)
119119
}
120120
}
121121

122+
PHP_METHOD(PhpToken, __construct)
123+
{
124+
zend_long id;
125+
zend_string *text;
126+
zend_long line = -1;
127+
zend_long pos = -1;
128+
zend_object *obj = Z_OBJ_P(ZEND_THIS);
129+
130+
ZEND_PARSE_PARAMETERS_START(2, 4)
131+
Z_PARAM_LONG(id)
132+
Z_PARAM_STR(text)
133+
Z_PARAM_OPTIONAL
134+
Z_PARAM_LONG(line)
135+
Z_PARAM_LONG(pos)
136+
ZEND_PARSE_PARAMETERS_END();
137+
138+
ZVAL_LONG(OBJ_PROP_NUM(obj, 0), id);
139+
zval_ptr_dtor(OBJ_PROP_NUM(obj, 1));
140+
ZVAL_STR_COPY(OBJ_PROP_NUM(obj, 1), text);
141+
ZVAL_LONG(OBJ_PROP_NUM(obj, 2), line);
142+
ZVAL_LONG(OBJ_PROP_NUM(obj, 3), pos);
143+
}
144+
122145
PHP_METHOD(PhpToken, is)
123146
{
124147
zval *kind;
@@ -208,6 +231,7 @@ PHP_METHOD(PhpToken, getTokenName)
208231

209232
static const zend_function_entry php_token_methods[] = {
210233
PHP_ME(PhpToken, getAll, arginfo_class_PhpToken_getAll, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC)
234+
PHP_ME(PhpToken, __construct, arginfo_class_PhpToken___construct, ZEND_ACC_PUBLIC)
211235
PHP_ME(PhpToken, is, arginfo_class_PhpToken_is, ZEND_ACC_PUBLIC)
212236
PHP_ME(PhpToken, isIgnorable, arginfo_class_PhpToken_isIgnorable, ZEND_ACC_PUBLIC)
213237
PHP_ME(PhpToken, getTokenName, arginfo_class_PhpToken_getTokenName, ZEND_ACC_PUBLIC)

ext/tokenizer/tokenizer.stub.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ class PhpToken {
88
/** @return PhpToken[] */
99
public static function getAll(string $code, int $flags = 0): array;
1010

11+
public function __construct(int $id, string $text, int $line = -1, int $pos = -1);
12+
1113
/** @param int|string|array $kind */
1214
public function is($kind): bool;
1315

ext/tokenizer/tokenizer_arginfo.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,13 @@ ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_class_PhpToken_getAll, 0, 1, IS_
1414
ZEND_ARG_TYPE_INFO(0, flags, IS_LONG, 0)
1515
ZEND_END_ARG_INFO()
1616

17+
ZEND_BEGIN_ARG_INFO_EX(arginfo_class_PhpToken___construct, 0, 0, 2)
18+
ZEND_ARG_TYPE_INFO(0, id, IS_LONG, 0)
19+
ZEND_ARG_TYPE_INFO(0, text, IS_STRING, 0)
20+
ZEND_ARG_TYPE_INFO(0, line, IS_LONG, 0)
21+
ZEND_ARG_TYPE_INFO(0, pos, IS_LONG, 0)
22+
ZEND_END_ARG_INFO()
23+
1724
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_class_PhpToken_is, 0, 1, _IS_BOOL, 0)
1825
ZEND_ARG_INFO(0, kind)
1926
ZEND_END_ARG_INFO()

0 commit comments

Comments
 (0)