projects
/
m6w6
/
ext-psi
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
|
github
raw
|
inline
| side by side
travis: update
[m6w6/ext-psi]
/
src
/
parser.c
diff --git
a/src/parser.c
b/src/parser.c
index 24028166df0c3eb310bb7185e12a6b4cc8b09d1a..9cb5add1d17ed7834a679eddfeda1ec9b3804ffd 100644
(file)
--- a/
src/parser.c
+++ b/
src/parser.c
@@
-23,11
+23,16
@@
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*******************************************************************************/
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*******************************************************************************/
-#include "php_psi_stdinc.h"
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#else
+# include "php_config.h"
+#endif
#include <sys/mman.h>
#include <assert.h>
#include <errno.h>
#include <stdarg.h>
#include <sys/mman.h>
#include <assert.h>
#include <errno.h>
#include <stdarg.h>
+#include <time.h>
#include <Zend/zend_smart_str.h>
#include <Zend/zend_smart_str.h>
@@
-97,8
+102,9
@@
struct psi_parser_input *psi_parser_open_file(struct psi_parser *P,
memset(fb->buffer + sb.st_size, 0, psi_parser_maxfill());
memset(fb->buffer + sb.st_size, 0, psi_parser_maxfill());
+ fb->lmod = sb.st_mtime;
fb->length = sb.st_size;
fb->length = sb.st_size;
- fb->file =
zend
_string_init_interned(filename, strlen(filename), 1);
+ fb->file =
psi
_string_init_interned(filename, strlen(filename), 1);
return fb;
}
return fb;
}
@@
-118,8
+124,9
@@
struct psi_parser_input *psi_parser_open_string(struct psi_parser *P,
memcpy(sb->buffer, string, length);
memset(sb->buffer + length, 0, psi_parser_maxfill());
memcpy(sb->buffer, string, length);
memset(sb->buffer + length, 0, psi_parser_maxfill());
+ sb->lmod = time(NULL);
sb->length = length;
sb->length = length;
- sb->file =
zend
_string_init_interned("<stdin>", strlen("<stdin>"), 1);
+ sb->file =
psi
_string_init_interned("<stdin>", strlen("<stdin>"), 1);
return sb;
}
return sb;
}
@@
-127,7
+134,7
@@
struct psi_parser_input *psi_parser_open_string(struct psi_parser *P,
struct psi_plist *psi_parser_preprocess(struct psi_parser *P,
struct psi_plist **tokens)
{
struct psi_plist *psi_parser_preprocess(struct psi_parser *P,
struct psi_plist **tokens)
{
- if (psi_cpp_process(P->preproc, tokens)) {
+ if (psi_cpp_process(P->preproc, tokens
, NULL
)) {
return *tokens;
}
return NULL;
return *tokens;
}
return NULL;
@@
-146,27
+153,32
@@
static inline zend_string *macro_to_constant(struct psi_parser *parser,
zend_string *name, struct psi_validate_scope *scope)
{
smart_str str = {0};
zend_string *name, struct psi_validate_scope *scope)
{
smart_str str = {0};
-
size_t i = 0;
struct psi_token *tok;
size_t i = 0;
struct psi_token *tok;
+#if PSI_THREADED_PARSER
+ int persistent = 1;
+#else
+ int persistent = 0;
+#endif
-
smart_str_append
_printf(&str, "const psi\\%s = ", name->val);
+
psi_smart_str
_printf(&str, "const psi\\%s = ", name->val);
if (scope->macro->exp) {
struct psi_dump dump = {{.hn = &str},
if (scope->macro->exp) {
struct psi_dump dump = {{.hn = &str},
- .fun = (psi_dump_cb)
smart_str_append
_printf};
+ .fun = (psi_dump_cb)
psi_smart_str
_printf};
psi_num_exp_dump(&dump, scope->macro->exp);
psi_num_exp_dump(&dump, scope->macro->exp);
+
} else while (psi_plist_get(scope->macro->tokens, i++, &tok)) {
if (tok->type == PSI_T_QUOTED_STRING) {
} else while (psi_plist_get(scope->macro->tokens, i++, &tok)) {
if (tok->type == PSI_T_QUOTED_STRING) {
- smart_str_appendc
(&str, '"'
);
+ smart_str_appendc
_ex(&str, '"', persistent
);
}
}
- smart_str_append
(&str, tok->tex
t);
+ smart_str_append
_ex(&str, tok->text, persisten
t);
if (tok->type == PSI_T_QUOTED_STRING) {
if (tok->type == PSI_T_QUOTED_STRING) {
- smart_str_appendc
(&str, '"'
);
+ smart_str_appendc
_ex(&str, '"', persistent
);
}
}
- smart_str_appendc
(&str, ' '
);
+ smart_str_appendc
_ex(&str, ' ', persistent
);
}
}
- smart_str_appendl
(&str, ";\n", 2
);
+ smart_str_appendl
_ex(&str, ";\n", 2, persistent
);
return smart_str_extract(&str);
}
return smart_str_extract(&str);
}
@@
-203,13
+215,20
@@
void psi_parser_postprocess(struct psi_parser *P)
}
} else if (!psi_num_exp_validate(PSI_DATA(P), scope.macro->exp, &scope)) {
continue;
}
} else if (!psi_num_exp_validate(PSI_DATA(P), scope.macro->exp, &scope)) {
continue;
+ } else if (psi_plist_count(scope.macro->tokens) == 1) {
+ struct psi_token *tok;
+ if (!psi_plist_get(scope.macro->tokens, 0, &tok)) {
+ continue;
+ } else if (zend_string_equals(name, tok->text)) {
+ continue;
+ }
}
cnst = macro_to_constant(P, name, &scope);
if (!cnst) {
continue;
}
}
cnst = macro_to_constant(P, name, &scope);
if (!cnst) {
continue;
}
-//fprintf(stderr, "PARSE: %s", ZSTR_VAL(cnst));
+
I = psi_parser_open_string(P, ZSTR_VAL(cnst), ZSTR_LEN(cnst));
zend_string_release(cnst);
I = psi_parser_open_string(P, ZSTR_VAL(cnst), ZSTR_LEN(cnst));
zend_string_release(cnst);
@@
-241,16
+260,21
@@
bool psi_parser_parse(struct psi_parser *P, struct psi_parser_input *I)
struct psi_plist *scanned, *preproc;
size_t processed = 0;
struct psi_plist *scanned, *preproc;
size_t processed = 0;
+ P->input = I;
+
if (!(scanned = psi_parser_scan(P, I))) {
if (!(scanned = psi_parser_scan(P, I))) {
+ P->input = NULL;
return false;
}
if (!(preproc = psi_parser_preprocess(P, &scanned))) {
return false;
}
if (!(preproc = psi_parser_preprocess(P, &scanned))) {
+ P->input = NULL;
psi_plist_free(scanned);
return false;
}
if (!psi_parser_process(P, preproc, &processed)) {
psi_plist_free(scanned);
return false;
}
if (!psi_parser_process(P, preproc, &processed)) {
+ P->input = NULL;
psi_plist_free(preproc);
return false;
}
psi_plist_free(preproc);
return false;
}
@@
-258,6
+282,7
@@
bool psi_parser_parse(struct psi_parser *P, struct psi_parser_input *I)
psi_parser_postprocess(P);
psi_plist_free(preproc);
psi_parser_postprocess(P);
psi_plist_free(preproc);
+ P->input = NULL;
return true;
}
return true;
}