Skip to content

Commit bfa4f0d

Browse files
committed
Intial extension code
1 parent 6c1008b commit bfa4f0d

File tree

3 files changed

+183
-1
lines changed

3 files changed

+183
-1
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
[![Build Status](https://travis-ci.org/phalcon/php-zephir-parser.svg?branch=master)](https://travis-ci.org/phalcon/php-zephir-parser)
44

5-
Zephir Parser delivered as a C extension for the PHP language.
5+
The Zephir Parser delivered as a C extension for the PHP language.
66

77
## Get Started
88

php_zephir_parser.h

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
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+
#ifndef PHP_ZEPHIR_PARSER_H
21+
#define PHP_ZEPHIR_PARSER_H 1
22+
23+
extern zend_module_entry zephir_parser_module_entry;
24+
#define phpext_zephir_parser_ptr &zephir_parser_module_entry
25+
26+
#define PHP_ZEPHIR_PARSER_NAME "zephir_parser"
27+
#define PHP_ZEPHIR_PARSER_VERSION "1.0.0"
28+
#define PHP_ZEPHIR_PARSER_AUTHOR "Zephir Team and contributors"
29+
#define PHP_ZEPHIR_PARSER_DESCRIPTION "The Zephir Parser delivered as a C extension for the PHP language."
30+
31+
#ifdef PHP_WIN32
32+
# define PHP_ZEPHIR_PARSER_API __declspec(dllexport)
33+
#elif defined(__GNUC__) && __GNUC__ >= 4
34+
# define PHP_ZEPHIR_PARSER_API __attribute__ ((visibility("default")))
35+
#else
36+
# define PHP_ZEPHIR_PARSER_API
37+
#endif
38+
39+
#ifdef ZTS
40+
#include "TSRM.h"
41+
#endif
42+
43+
#define ZEPHIR_PARSER_G(v) ZEND_MODULE_GLOBALS_ACCESSOR(zephir_parser, v)
44+
45+
#if defined(ZTS) && defined(COMPILE_DL_ZEPHIR_PARSER)
46+
ZEND_TSRMLS_CACHE_EXTERN();
47+
#endif
48+
49+
#endif

zephir_parser.c

Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
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

Comments
 (0)