#include "token.h"
#include "types/impl_val.h"
-#define PRIfval ".13gF"
-#define PRIdval ".53g"
-#define PRIldval ".64LgL"
+#define PRIfval ".6g"
+#define PRIdval ".16g"
+#define PRIldval ".29Lg"
typedef token_t (*psi_calc)(token_t t1, impl_val *v1, token_t t2, impl_val *v2, impl_val *res);
}
zc.name = zend_string_copy(c->name);
- psi_impl_def_val_get_zval(c->val, c->type ? c->type->type : PSI_T_MIXED , &zc.value);
+ psi_impl_def_val_get_zval(c->val, c->type ? c->type->type : PSI_T_MIXED, &zc.value);
zend_register_constant(&zc);
}
*******************************************************************************/
#include "php_psi_stdinc.h"
+#include "php_psi.h"
#include "data.h"
#include "php_globals.h"
#include "plist.h"
#include "validate.h"
-#include "php_network.h"
-
#include <stdarg.h>
#include <dlfcn.h>
} else if (V >= -(1L<<52) && V <= (1L<<53)) { \
ZVAL_DOUBLE(z, V); \
} else if (V < ZEND_LONG_MIN || V > ZEND_LONG_MAX) { \
- ZVAL_STRING(z, psi_i128_to_buf(&buf[sizeof(buf) - 1], V)); \
+ char *str = psi_i128_to_buf(&buf[sizeof(buf) - 1], V); \
+ if (persistent) { \
+ ZVAL_PSTRING(z, str); \
+ } else { \
+ ZVAL_STRING(z, str); \
+ } \
} else { \
- ZVAL_STRING(z, zend_print_long_to_buf(&buf[sizeof(buf) - 1], V)); \
+ char *str = zend_print_long_to_buf(&buf[sizeof(buf) - 1], V); \
+ if (persistent) { \
+ ZVAL_PSTRING(z, str); \
+ } else { \
+ ZVAL_STRING(z, str); \
+ } \
} \
} else { \
if (V <= ZEND_LONG_MAX) { \
} else if (V <= (1L<<53)) { \
ZVAL_DOUBLE(z, V); \
} else if (V > ZEND_ULONG_MAX) { \
- ZVAL_STRING(z, psi_u128_to_buf(&buf[sizeof(buf) - 1], V)); \
+ char *str = psi_u128_to_buf(&buf[sizeof(buf) - 1], V); \
+ if (persistent) { \
+ ZVAL_PSTRING(z, str); \
+ } else { \
+ ZVAL_STRING(z, str); \
+ } \
} else { \
- ZVAL_STRING(z, zend_print_ulong_to_buf(&buf[sizeof(buf) - 1], V)); \
+ char *str = zend_print_ulong_to_buf(&buf[sizeof(buf) - 1], V); \
+ if (persistent) { \
+ ZVAL_PSTRING(z, str); \
+ } else { \
+ ZVAL_STRING(z, str); \
+ } \
} \
} \
} while (0)
{
php_stream *s;
zval *r = NULL;
- struct psi_dump dump = {.fun = php_stream_printf};
+ struct psi_dump dump = {.fun = (psi_dump_cb) php_stream_printf};
if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS(), "|r!", &r)) {
return;
token_t typ = psi_num_exp_exec(scope->macro->exp, &res, NULL, scope->cpp);
switch (typ) {
- CASE_IMPLVAL_NUM_PRINTF(smart_str_append_printf, &str, res);
+ CASE_IMPLVAL_NUM_PRINTF(smart_str_append_printf, &str, res, true);
default:
assert(0);
}
-/* Generated by re2c 1.1.1 on Tue Nov 13 09:05:21 2018 */
+/* Generated by re2c 1.1.1 on Tue Nov 20 15:59:31 2018 */
#line 1 "src/parser_scan.re"
/*******************************************************************************
Copyright (c) 2016, Michael Wallner <mike@php.net>.
{
struct psi_dump dump;
smart_str str = {0};
- zend_string *message;
dump.ctx.hn = &str;
dump.fun = (psi_dump_cb) smart_str_append_printf;
bool psi_const_validate(struct psi_data *data, struct psi_const *c,
struct psi_validate_scope *scope)
{
- if (c->type) {
- switch (c->type->type) {
- case PSI_T_BOOL:
- case PSI_T_INT:
- case PSI_T_FLOAT:
- case PSI_T_DOUBLE:
- case PSI_T_STRING:
- break;
- default:
- data->error(data, val->token, PSI_WARNING,
- "Invalid default value type '%s', "
- "expected one of bool, int, float/double or string.",
- type->name->val);
- return false;
- }
- }
if (!psi_impl_def_val_validate(data, c->val, c->type, scope)) {
return false;
}
PSI_DUMP(dump, "struct %s::(%zu, %zu)", strct->name->val, strct->align,
strct->size);
if (psi_plist_count(strct->args)) {
- psi_decl_type_dump_args_with_layout(fd, strct->args, 0);
+ psi_decl_type_dump_args_with_layout(dump, strct->args, 0);
} else {
PSI_DUMP(dump, ";");
}
return true;
}
-void psi_decl_type_dump_args_with_layout(int fd, struct psi_plist *args,
+void psi_decl_type_dump_args_with_layout(struct psi_dump *dump, struct psi_plist *args,
unsigned level)
{
size_t i = 0;
case PSI_T_STRUCT:
PSI_DUMP(dump, "struct ");
if (psi_decl_type_is_anon(t->name, "struct")) {
- psi_decl_type_dump_args_with_layout(fd, t->real.strct->args, level);
+ psi_decl_type_dump_args_with_layout(dump, t->real.strct->args, level);
return;
}
break;
case PSI_T_UNION:
PSI_DUMP(dump, "union ");
if (psi_decl_type_is_anon(t->name, "union")) {
- psi_decl_type_dump_args_with_layout(fd, t->real.unn->args, level);
+ psi_decl_type_dump_args_with_layout(dump, t->real.unn->args, level);
return;
}
break;
struct psi_decl_type *psi_decl_type_get_real(struct psi_decl_type *type);
struct psi_plist *psi_decl_type_get_args(struct psi_decl_type *dtyp, struct psi_decl_type **real_typ_ptr);
-void psi_decl_type_dump_args_with_layout(int fd, struct psi_plist *args, unsigned level);
+void psi_decl_type_dump_args_with_layout(struct psi_dump *dump, struct psi_plist *args, unsigned level);
size_t psi_decl_type_get_args_align(struct psi_plist *args);
{
PSI_DUMP(dump, "union %s::(%zu, %zu)", unn->name->val, unn->align, unn->size);
if (psi_plist_count(unn->args)) {
- psi_decl_type_dump_args_with_layout(fd, unn->args, 0);
+ psi_decl_type_dump_args_with_layout(dump, unn->args, 0);
} else {
PSI_DUMP(dump, ";");
}
void psi_impl_def_val_dump(struct psi_dump *dump, struct psi_impl_def_val *val);
bool psi_impl_def_val_validate(struct psi_data *data, struct psi_impl_def_val *def,
struct psi_impl_type *cmp, struct psi_validate_scope *scope);
-token_t psi_impl_def_val_get_zend(struct psi_impl_def_val *val, impl_val *res);
+void psi_impl_def_val_get_zval(struct psi_impl_def_val *val, token_t typ, zval *z);
#endif
} \
break;
#else
-# define CASE_IMPLVAL_LD_PRINTF(fun, to, ival)
+# define CASE_IMPLVAL_LD_PRINTF(fun, to, ival, with_suffix)
#endif
#define CASE_IMPLVAL_FLOAT_PRINTF(fun, to, ival, with_suffix) \