-
Notifications
You must be signed in to change notification settings - Fork 1
/
astkit-decl.c
137 lines (116 loc) · 4.68 KB
/
astkit-decl.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
#include "astkit.h"
zend_class_entry* astkit_decl_ce = NULL;
/* {{{ proto int AstKitDecl::numChildren() */
static PHP_METHOD(AstKitDecl, numChildren) {
RETURN_LONG(3);
} /* }}} */
/* {{{ proto object AstKitDecl::getChild(int child[, bool zval_as_value = true]) */
ZEND_BEGIN_ARG_INFO(AstKitDecl_getChild_arginfo, 0)
ZEND_ARG_INFO(0, child)
ZEND_ARG_INFO(0, zval_as_value)
ZEND_END_ARG_INFO()
static PHP_METHOD(AstKitDecl, getChild) {
astkit_object* objval = ASTKIT_FETCH_OBJ(getThis());
zend_ast_decl* declNode = (zend_ast_decl*)objval->node;
zend_long child;
zend_bool zval_as_value = 1;
if (zend_parse_parameters(ZEND_NUM_ARGS(), "l|b", &child, &zval_as_value) == FAILURE) {
return;
}
if ((child < 0) || (child > 3)) {
php_error_docref(NULL, E_WARNING,
"Invalid child " ZEND_LONG_FMT ", current node has %d children",
child, 3);
return;
}
if (declNode->child[child]) {
astkit_create_object(return_value, declNode->child[child], objval->tree, zval_as_value);
}
} /* }}} */
/* {{{ proto int AstKitDecl::getLineEnd() */
static PHP_METHOD(AstKitDecl, getLineEnd) {
astkit_object* objval = ASTKIT_FETCH_OBJ(getThis());
zend_ast_decl* declNode = (zend_ast_decl*)objval->node;
RETURN_LONG(declNode->end_lineno);
} /* }}} */
/* {{{ proto int AstKitDecl::geFlags() */
static PHP_METHOD(AstKitDecl, getFlags) {
astkit_object* objval = ASTKIT_FETCH_OBJ(getThis());
zend_ast_decl* declNode = (zend_ast_decl*)objval->node;
RETURN_LONG(declNode->flags);
} /* }}} */
/* {{{ proto string AstKitDecl::getDocComment() */
static PHP_METHOD(AstKitDecl, getDocComment) {
astkit_object* objval = ASTKIT_FETCH_OBJ(getThis());
zend_ast_decl* declNode = (zend_ast_decl*)objval->node;
if (declNode->doc_comment) {
RETURN_STRINGL(declNode->doc_comment->val, declNode->doc_comment->len);
} else {
RETURN_EMPTY_STRING();
}
} /* }}} */
/* {{{ proto string AstKitDecl::getName() */
static PHP_METHOD(AstKitDecl, getName) {
astkit_object* objval = ASTKIT_FETCH_OBJ(getThis());
zend_ast_decl* declNode = (zend_ast_decl*)objval->node;
RETURN_STRINGL(declNode->name->val, declNode->name->len);
} /* }}} */
/* {{{ proto bool AstKitDecl::hasParams() */
static PHP_METHOD(AstKitDecl, hasParams) {
astkit_object* objval = ASTKIT_FETCH_OBJ(getThis());
zend_ast_decl* declNode = (zend_ast_decl*)objval->node;
RETURN_BOOL(declNode->child[0]);
} /* }}} */
/* {{{ proto mixed AstKitDecl::getParams() */
static PHP_METHOD(AstKitDecl, getParams) {
astkit_object* objval = ASTKIT_FETCH_OBJ(getThis());
zend_ast_decl* declNode = (zend_ast_decl*)objval->node;
astkit_create_object(return_value, declNode->child[0], objval->tree, 0);
} /* }}} */
/* {{{ proto bool AstKitDecl::hasUse() */
static PHP_METHOD(AstKitDecl, hasUse) {
astkit_object* objval = ASTKIT_FETCH_OBJ(getThis());
zend_ast_decl* declNode = (zend_ast_decl*)objval->node;
RETURN_BOOL(declNode->child[1]);
} /* }}} */
/* {{{ proto mixed AstKitDecl::getUse() */
static PHP_METHOD(AstKitDecl, getUse) {
astkit_object* objval = ASTKIT_FETCH_OBJ(getThis());
zend_ast_decl* declNode = (zend_ast_decl*)objval->node;
astkit_create_object(return_value, declNode->child[1], objval->tree, 0);
} /* }}} */
/* {{{ proto bool AstKitDecl::hasStatements() */
static PHP_METHOD(AstKitDecl, hasStatements) {
astkit_object* objval = ASTKIT_FETCH_OBJ(getThis());
zend_ast_decl* declNode = (zend_ast_decl*)objval->node;
RETURN_BOOL(declNode->child[2]);
} /* }}} */
/* {{{ proto mixed AstKitDecl::getStatements() */
static PHP_METHOD(AstKitDecl, getStatements) {
astkit_object* objval = ASTKIT_FETCH_OBJ(getThis());
zend_ast_decl* declNode = (zend_ast_decl*)objval->node;
astkit_create_object(return_value, declNode->child[2], objval->tree, 0);
} /* }}} */
static zend_function_entry astkit_decl_methods[] = {
/* For compat with AstKit, but the hasFoo()/getFoo() APIs are more appropriate */
PHP_ME(AstKitDecl, numChildren, NULL, ZEND_ACC_PUBLIC)
PHP_ME(AstKitDecl, getChild, AstKitDecl_getChild_arginfo, ZEND_ACC_PUBLIC)
PHP_ME(AstKitDecl, getLineEnd, NULL, ZEND_ACC_PUBLIC)
PHP_ME(AstKitDecl, getFlags, NULL, ZEND_ACC_PUBLIC)
PHP_ME(AstKitDecl, getDocComment, NULL, ZEND_ACC_PUBLIC)
PHP_ME(AstKitDecl, getName, NULL, ZEND_ACC_PUBLIC)
PHP_ME(AstKitDecl, hasParams, NULL, ZEND_ACC_PUBLIC)
PHP_ME(AstKitDecl, getParams, NULL, ZEND_ACC_PUBLIC)
PHP_ME(AstKitDecl, hasUse, NULL, ZEND_ACC_PUBLIC)
PHP_ME(AstKitDecl, getUse, NULL, ZEND_ACC_PUBLIC)
PHP_ME(AstKitDecl, hasStatements, NULL, ZEND_ACC_PUBLIC)
PHP_ME(AstKitDecl, getStatements, NULL, ZEND_ACC_PUBLIC)
/* getLineEnd() */
PHP_FE_END
};
int astkit_decl_minit(INIT_FUNC_ARGS) {
zend_class_entry ce;
INIT_CLASS_ENTRY(ce, "AstKitDecl", astkit_decl_methods);
astkit_decl_ce = zend_register_internal_class_ex(&ce, astkit_node_ce);
return SUCCESS;
}