dump fixes
authorMichael Wallner <mike@php.net>
Tue, 20 Nov 2018 15:20:42 +0000 (16:20 +0100)
committerMichael Wallner <mike@php.net>
Tue, 4 Dec 2018 11:13:48 +0000 (12:13 +0100)
16 files changed:
src/calc.h
src/context.c
src/data.c
src/data.h
src/marshal.h
src/module.c
src/parser.c
src/parser_scan.c
src/types/assert_stmt.c
src/types/const.c
src/types/decl_struct.c
src/types/decl_type.c
src/types/decl_type.h
src/types/decl_union.c
src/types/impl_def_val.h
src/types/impl_val.h

index 0c2678c..6361ce8 100644 (file)
@@ -29,9 +29,9 @@
 #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);
 
index febe0bb..7b48c92 100644 (file)
@@ -235,7 +235,7 @@ zend_function_entry *psi_context_compile(struct psi_context *C)
                        }
 
                        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);
                }
index fb94d30..9bcd493 100644 (file)
@@ -24,6 +24,7 @@
  *******************************************************************************/
 
 #include "php_psi_stdinc.h"
+#include "php_psi.h"
 #include "data.h"
 
 #include "php_globals.h"
index ca7bf90..6ab3490 100644 (file)
@@ -31,8 +31,6 @@
 #include "plist.h"
 #include "validate.h"
 
-#include "php_network.h"
-
 #include <stdarg.h>
 #include <dlfcn.h>
 
index a7777d3..9880f52 100644 (file)
@@ -72,9 +72,19 @@ static inline char *psi_i128_to_buf(char *buf, __int128 i128)
                } 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) { \
@@ -82,9 +92,19 @@ static inline char *psi_i128_to_buf(char *buf, __int128 i128)
                } 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)
index 08db814..c369dc6 100644 (file)
@@ -166,7 +166,7 @@ static PHP_FUNCTION(psi_dump)
 {
        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;
index 9475ff9..9d3395c 100644 (file)
@@ -151,7 +151,7 @@ static inline zend_string *macro_to_constant(struct psi_parser *parser,
                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);
                }
index 1a0e4d3..62fe215 100644 (file)
@@ -1,4 +1,4 @@
-/* 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>.
index 6909191..916c96e 100644 (file)
@@ -89,7 +89,6 @@ void psi_assert_stmt_throw(struct psi_assert_stmt *stmt)
 {
        struct psi_dump dump;
        smart_str str = {0};
-       zend_string *message;
 
        dump.ctx.hn = &str;
        dump.fun = (psi_dump_cb) smart_str_append_printf;
index fd1a165..6277070 100644 (file)
@@ -69,22 +69,6 @@ void psi_const_dump(struct psi_dump *dump, struct psi_const *cnst)
 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;
        }
index 44f8b4c..d17895a 100644 (file)
@@ -60,7 +60,7 @@ void psi_decl_struct_dump(struct psi_dump *dump, struct psi_decl_struct *strct)
        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, ";");
        }
index 164f33f..9db6de1 100644 (file)
@@ -289,7 +289,7 @@ bool psi_decl_type_validate(struct psi_data *data, struct psi_decl_type *type,
        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;
@@ -349,7 +349,7 @@ void psi_decl_type_dump(struct psi_dump *dump, struct psi_decl_type *t, unsigned
        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;
@@ -357,7 +357,7 @@ void psi_decl_type_dump(struct psi_dump *dump, struct psi_decl_type *t, unsigned
        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;
index d51220d..e929651 100644 (file)
@@ -69,7 +69,7 @@ int psi_decl_type_is_weak(struct psi_decl_type *type);
 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);
 
 
index a2daf2c..146bc62 100644 (file)
@@ -56,7 +56,7 @@ void psi_decl_union_dump(struct psi_dump *dump, struct psi_decl_union *unn)
 {
        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, ";");
        }
index 1345005..360ebb6 100644 (file)
@@ -48,5 +48,5 @@ void psi_impl_def_val_free(struct psi_impl_def_val **def_ptr);
 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
index 186a080..0e52318 100644 (file)
@@ -80,7 +80,7 @@ typedef union impl_val {
                } \
                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) \