forked from zephir-lang/php-zephir-parser
-
Notifications
You must be signed in to change notification settings - Fork 0
/
zephir_parser.c
135 lines (116 loc) · 3.02 KB
/
zephir_parser.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
/* zephir_parser.c
*
* This file is part of the Zephir Parser.
*
* (c) Zephir Team <team@zephir-lang.com>
*
* For the full copyright and license information, please view
* the LICENSE file that was distributed with this source code.
*/
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#include <php.h>
#include <php_ini.h>
#include <ext/standard/info.h>
#include "zephir_parser.h"
extern void *xx_parse_program(zval *return_value, char *program, size_t program_length, char *file_path, zval *error_msg);
/* {{{ proto array zephir_parse_file(string content, string filepath)
Parses a file and returning an intermediate array representation */
static PHP_FUNCTION(zephir_parse_file)
{
size_t filepath_len = 0;
size_t content_len = 0;
char *content = NULL;
char *filepath = NULL;
zval error_msg;
zval ret;
zval *e = &error_msg;
zval *r = &ret;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss", &content, &content_len, &filepath, &filepath_len) == FAILURE) {
RETURN_FALSE;
}
ZVAL_NULL(e);
ZVAL_NULL(r);
xx_parse_program(r, content, content_len, filepath, e);
if (Z_TYPE_P(e) == IS_ARRAY) {
zval_ptr_dtor(&ret);
RETURN_ZVAL(e, 0, 0);
}
assert(Z_TYPE_P(r) == IS_ARRAY);
zval_ptr_dtor(&error_msg);
RETURN_ZVAL(r, 1, 1);
}
/* }}} */
/* {{{ PHP_MINIT_FUNCTION
*/
PHP_MINIT_FUNCTION(zephir_parser)
{
return SUCCESS;
}
/* }}} */
/* {{{ PHP_MSHUTDOWN_FUNCTION
*/
PHP_MSHUTDOWN_FUNCTION(zephir_parser)
{
return SUCCESS;
}
/* }}} */
/* {{{ PHP_MINFO_FUNCTION
*/
PHP_MINFO_FUNCTION(zephir_parser)
{
php_info_print_box_start(0);
php_printf("%s", PHP_ZEPHIR_PARSER_DESCRIPTION);
php_info_print_box_end();
php_info_print_table_start();
php_info_print_table_header(2, PHP_ZEPHIR_PARSER_NAME, "enabled");
php_info_print_table_row(2, "Author", PHP_ZEPHIR_PARSER_AUTHOR);
php_info_print_table_row(2, "Version", PHP_ZEPHIR_PARSER_VERSION);
php_info_print_table_row(2, "Build Date", __DATE__ " " __TIME__);
php_info_print_table_end();
}
/* }}} */
ZEND_BEGIN_ARG_INFO_EX(arginfo_zephir_parse_file, 0, 0, 2)
ZEND_ARG_TYPE_INFO(0, content, IS_STRING, 0)
ZEND_ARG_TYPE_INFO(0, filepath, IS_STRING, 0)
ZEND_END_ARG_INFO()
/* {{{ zephir_parser_functions[]
*
* Every user visible function must have an entry in zephir_parser_functions[].
*/
static const zend_function_entry zephir_parser_functions[] = {
PHP_FE(zephir_parse_file, arginfo_zephir_parse_file)
PHP_FE_END
};
/* }}} */
/* {{{ zephir_parser_module_entry
*/
zend_module_entry zephir_parser_module_entry = {
STANDARD_MODULE_HEADER,
PHP_ZEPHIR_PARSER_NAME,
zephir_parser_functions,
PHP_MINIT(zephir_parser),
PHP_MSHUTDOWN(zephir_parser),
NULL,
NULL,
PHP_MINFO(zephir_parser),
PHP_ZEPHIR_PARSER_VERSION,
STANDARD_MODULE_PROPERTIES
};
/* }}} */
/* implement standard "stub" routine to introduce ourselves to Zend */
#ifdef COMPILE_DL_ZEPHIR_PARSER
# ifdef ZTS
ZEND_TSRMLS_CACHE_DEFINE()
# endif
ZEND_GET_MODULE(zephir_parser)
#endif
/*
* Local variables:
* tab-width: 4
* c-basic-offset: 4
* End:
* vim600: noet sw=4 ts=4 fdm=marker
* vim<600: noet sw=4 ts=4
*/