|
| 1 | +/* |
| 2 | + +--------------------------------------------------------------------------+ |
| 3 | + | Zephir Parser | |
| 4 | + +--------------------------------------------------------------------------+ |
| 5 | + | Copyright (c) 2013-2017 Zephir Team and contributors | |
| 6 | + +--------------------------------------------------------------------------+ |
| 7 | + | This source file is subject the MIT license, that is bundled with | |
| 8 | + | this package in the file LICENSE, and is available through the | |
| 9 | + | world-wide-web at the following url: | |
| 10 | + | https://zephir-lang.com/license.html | |
| 11 | + | | |
| 12 | + | If you did not receive a copy of the MIT license and are unable | |
| 13 | + | to obtain it through the world-wide-web, please send a note to | |
| 14 | + | license@zephir-lang.com so we can mail you a copy immediately. | |
| 15 | + +--------------------------------------------------------------------------+ |
| 16 | +*/ |
| 17 | + |
| 18 | +/* $Id$ */ |
| 19 | + |
| 20 | +#ifdef HAVE_CONFIG_H |
| 21 | +#include "config.h" |
| 22 | +#endif |
| 23 | + |
| 24 | +#include "php.h" |
| 25 | +#include "php_ini.h" |
| 26 | +#include "ext/standard/info.h" |
| 27 | +#include "php_zephir_parser.h" |
| 28 | + |
| 29 | +extern void *xx_parse_program(zval *return_value, char *program, size_t program_length, char *file_path, zval **error_msg); |
| 30 | + |
| 31 | +/* {{{ proto string zephir_parse_file(string arg) |
| 32 | + Return a string to confirm that the module is compiled in */ |
| 33 | +PHP_FUNCTION(zephir_parse_file) |
| 34 | +{ |
| 35 | + size_t filepath_len = 0; |
| 36 | + size_t content_len = 0; |
| 37 | + char *content = NULL; |
| 38 | + char *filepath = NULL; |
| 39 | +#if PHP_VERSION_ID >= 70000 |
| 40 | + zend_array *arr = NULL; |
| 41 | + zval ret; |
| 42 | + zval error, *error_ptr = &error; |
| 43 | + zval **error_msg = &error_ptr; |
| 44 | + ZVAL_UNDEF(error_ptr); |
| 45 | +#else |
| 46 | + zval *ret = NULL; |
| 47 | + zval **error_msg = NULL; |
| 48 | +#endif |
| 49 | + |
| 50 | + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss", &content, &content_len, &filepath, &filepath_len) == FAILURE) { |
| 51 | + return; |
| 52 | + } |
| 53 | + |
| 54 | +#if PHP_VERSION_ID >= 70000 |
| 55 | + xx_parse_program(&ret, content, content_len, filepath, error_msg); |
| 56 | +#else |
| 57 | + MAKE_STD_ZVAL(ret); |
| 58 | + xx_parse_program(ret, content, content_len, filepath, error_msg); |
| 59 | +#endif |
| 60 | + |
| 61 | +#if PHP_VERSION_ID >= 70000 |
| 62 | + if (Z_TYPE_P(error_ptr) != IS_UNDEF) { |
| 63 | + RETURN_ZVAL(error_ptr, 1, 1); |
| 64 | + } |
| 65 | + RETURN_ZVAL(&ret, 1, 1); |
| 66 | +#else |
| 67 | + RETVAL_ZVAL(ret, 1, 0); |
| 68 | +#endif |
| 69 | +} |
| 70 | +/* }}} */ |
| 71 | + |
| 72 | +/* {{{ PHP_MINIT_FUNCTION |
| 73 | + */ |
| 74 | +PHP_MINIT_FUNCTION(zephir_parser) |
| 75 | +{ |
| 76 | + return SUCCESS; |
| 77 | +} |
| 78 | +/* }}} */ |
| 79 | + |
| 80 | +/* {{{ PHP_MSHUTDOWN_FUNCTION |
| 81 | + */ |
| 82 | +PHP_MSHUTDOWN_FUNCTION(zephir_parser) |
| 83 | +{ |
| 84 | + return SUCCESS; |
| 85 | +} |
| 86 | +/* }}} */ |
| 87 | + |
| 88 | +/* {{{ PHP_MINFO_FUNCTION |
| 89 | + */ |
| 90 | +PHP_MINFO_FUNCTION(zephir_parser) |
| 91 | +{ |
| 92 | + php_info_print_box_start(0); |
| 93 | + php_printf("%s", PHP_ZEPHIR_PARSER_DESCRIPTION); |
| 94 | + php_info_print_box_end(); |
| 95 | + |
| 96 | + php_info_print_table_start(); |
| 97 | + php_info_print_table_header(2, PHP_ZEPHIR_PARSER_NAME, "enabled"); |
| 98 | + php_info_print_table_row(2, "Author", PHP_ZEPHIR_PARSER_AUTHOR); |
| 99 | + php_info_print_table_row(2, "Version", PHP_ZEPHIR_PARSER_VERSION); |
| 100 | + php_info_print_table_row(2, "Build Date", __DATE__ " " __TIME__); |
| 101 | + php_info_print_table_end(); |
| 102 | +} |
| 103 | +/* }}} */ |
| 104 | + |
| 105 | +/* {{{ zephir_parser_functions[] */ |
| 106 | +const zend_function_entry zephir_parser_functions[] = { |
| 107 | + PHP_FE(zephir_parse_file, NULL) /* For testing, remove later. */ |
| 108 | + PHP_FE_END /* Must be the last line in zephir_parser_functions[] */ |
| 109 | +}; |
| 110 | +/* }}} */ |
| 111 | + |
| 112 | +/* {{{ zephir_parser_module_entry |
| 113 | + */ |
| 114 | +zend_module_entry zephir_parser_module_entry = { |
| 115 | + STANDARD_MODULE_HEADER, |
| 116 | + PHP_ZEPHIR_PARSER_NAME, |
| 117 | + zephir_parser_functions, |
| 118 | + PHP_MINIT(zephir_parser), |
| 119 | + PHP_MSHUTDOWN(zephir_parser), |
| 120 | + NULL, |
| 121 | + NULL, |
| 122 | + PHP_MINFO(zephir_parser), |
| 123 | + PHP_ZEPHIR_PARSER_VERSION, |
| 124 | + STANDARD_MODULE_PROPERTIES |
| 125 | +}; |
| 126 | +/* }}} */ |
| 127 | + |
| 128 | +#ifdef COMPILE_DL_ZEPHIR_PARSER |
| 129 | +#ifdef ZTS |
| 130 | +ZEND_TSRMLS_CACHE_DEFINE(); |
| 131 | +#endif |
| 132 | +ZEND_GET_MODULE(zephir_parser) |
| 133 | +#endif |
0 commit comments