X-Git-Url: https://git.m6w6.name/?p=m6w6%2Fext-psi;a=blobdiff_plain;f=src%2Fcontext.c;h=d1eb05e35323aed7137f258c808b24420cb402e6;hp=11b2abd00dcf1265e607e8b23e378aeaa7dfa316;hb=c5b2de8ed1d92dd42f910d4347d9175f27e3acbb;hpb=f74ce3f29e2dadd9f839c33ad5292e56e9203efd diff --git a/src/context.c b/src/context.c index 11b2abd..d1eb05e 100644 --- a/src/context.c +++ b/src/context.c @@ -97,10 +97,25 @@ struct psi_context *psi_context_init(struct psi_context *C, struct psi_context_o T.types = psi_plist_add(T.types, &def); } for (predef_const = &psi_predef_consts[0]; predef_const->type_tag; ++predef_const) { - struct psi_impl_def_val *val = psi_impl_def_val_init(predef_const->val_type_tag, predef_const->val_text); struct psi_const_type *type = psi_const_type_init(predef_const->type_tag, predef_const->type_name); - struct psi_const *constant = psi_const_init(type, predef_const->var_name, val); + struct psi_impl_def_val *val; + struct psi_const *constant; + switch (type->type) { + case PSI_T_INT: + val = psi_impl_def_val_init(PSI_T_INT, NULL); + val->ival.zend.lval = predef_const->value.lval; + break; + case PSI_T_STRING: + val = psi_impl_def_val_init(PSI_T_STRING, NULL); + val->ival.zend.str = zend_string_init(predef_const->value.ptr, strlen(predef_const->value.ptr), 1); + break; + default: + assert(0); + break; + } + + constant = psi_const_init(type, predef_const->var_name, val); T.consts = psi_plist_add(T.consts, &constant); } for (predef_composite = &psi_predef_composites[0]; predef_composite->type_tag; ++predef_composite) { @@ -163,7 +178,7 @@ struct psi_context *psi_context_init(struct psi_context *C, struct psi_context_o struct psi_decl_var *fname = psi_decl_var_init(predef_decl->var_name, predef_decl->pointer_level, predef_decl->array_size); struct psi_decl_arg *tdef, *func = psi_decl_arg_init(ftype, fname); struct psi_plist *args = psi_plist_init((psi_plist_dtor) psi_decl_arg_free); - struct psi_decl *decl = psi_decl_init(psi_decl_abi_init("default"), func, args); + struct psi_decl *decl = psi_decl_init(func, args); for (farg = &predef_decl[1]; farg->type_tag; ++farg) { struct psi_decl_type *arg_type = psi_decl_type_init(farg->type_tag, farg->type_name); @@ -225,6 +240,7 @@ void psi_context_build(struct psi_context *C, const char *paths) for (i = 0; i < n; ++i) { char psi[MAXPATHLEN]; struct psi_parser P; + struct psi_parser_input *I; if (MAXPATHLEN <= slprintf(psi, MAXPATHLEN, "%s/%s", ptr, entries[i]->d_name)) { C->error(PSI_DATA(C), NULL, PSI_WARNING, "Path to PSI file too long: %s/%s", @@ -235,22 +251,15 @@ void psi_context_build(struct psi_context *C, const char *paths) psi, strerror(errno)); continue; } - if (!psi_parser_open_file(&P, psi)) { + if (!(I = psi_parser_open_file(&P, psi, true))) { C->error(PSI_DATA(C), NULL, PSI_WARNING, "Failed to open PSI file (%s): %s", psi, strerror(errno)); continue; } - - while (0 < psi_parser_scan(&P)) { - psi_parser_parse(&P, psi_token_alloc(&P)); - if (P.num == PSI_T_EOF) { - break; - } - } - - psi_parser_parse(&P, NULL); + psi_parser_parse(&P, I); psi_context_add_data(C, PSI_DATA(&P)); psi_parser_dtor(&P); + free(I); } } @@ -289,7 +298,7 @@ zend_function_entry *psi_context_compile(struct psi_context *C) continue; } - zc.name = zend_string_init(c->name + (c->name[0] == '\\'), strlen(c->name) - (c->name[0] == '\\'), 1); + zc.name = zend_string_init(c->name, strlen(c->name), 1); switch (c->type->type) { case PSI_T_BOOL: @@ -303,7 +312,7 @@ zend_function_entry *psi_context_compile(struct psi_context *C) break; case PSI_T_STRING: case PSI_T_QUOTED_STRING: - ZVAL_NEW_STR(&zc.value, zend_string_init(c->val->text, strlen(c->val->text), 1)); + ZVAL_NEW_STR(&zc.value, zend_string_copy(c->val->ival.zend.str)); break; default: assert(0); @@ -326,7 +335,7 @@ zend_function_entry *psi_context_compile(struct psi_context *C) zend_string *name = strpprintf(0, "psi\\%s\\%s", e->name, item->name); zc.name = zend_string_dup(name, 1); - ZVAL_LONG(&zc.value, psi_long_num_exp(item->num, NULL)); + ZVAL_LONG(&zc.value, psi_long_num_exp(item->num, NULL, NULL)); zend_register_constant(&zc); zend_string_release(name); } @@ -358,7 +367,22 @@ ZEND_RESULT_CODE psi_context_call(struct psi_context *C, zend_execute_data *exec return FAILURE; } + if (SUCCESS != psi_call_frame_do_assert(frame, PSI_ASSERT_PRE)) { + psi_call_frame_do_return(frame, return_value); + psi_call_frame_free(frame); + + return FAILURE; + } + psi_call_frame_do_call(frame); + + if (SUCCESS != psi_call_frame_do_assert(frame, PSI_ASSERT_POST)) { + psi_call_frame_do_return(frame, return_value); + psi_call_frame_free(frame); + + return FAILURE; + } + psi_call_frame_do_return(frame, return_value); psi_call_frame_do_set(frame); psi_call_frame_do_free(frame);