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 0c2678cde2daf48ca431443c1aab8bbd34d09b47..6361ce8131360412851da2a833b10a3e0f1fe658 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 febe0bb307b8bae747487d7b63c1ff07f2109aff..7b48c921044706c84b0fad5e20a5a6a5e2734bc0 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 fb94d302b0bd20b905783f8730cd0b49d4a1c750..9bcd493d711b9eca7a2449cfcbac380a5f117b9f 100644 (file)
@@ -24,6 +24,7 @@
  *******************************************************************************/
 
 #include "php_psi_stdinc.h"
+#include "php_psi.h"
 #include "data.h"
 
 #include "php_globals.h"
index ca7bf9089f8b1488d22b826451800de81945d419..6ab34905f7e62e4d10e1ddedcc26139593b245b0 100644 (file)
@@ -31,8 +31,6 @@
 #include "plist.h"
 #include "validate.h"
 
-#include "php_network.h"
-
 #include <stdarg.h>
 #include <dlfcn.h>
 
index a7777d3063cddb18b0d7f7797cd927329aaa3a3f..9880f522f5f975b7b7e0e701687627d654eed0f8 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 08db8149c8db7ae22a65346237b1fe779dc8c453..c369dc604f896d6f71f1f118df27812354efc42f 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 9475ff9bf029f65eed38221be97ad4e150dc34a8..9d3395cead126fa366552b0f434395e5b2880fde 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 1a0e4d3f17c8b5eaf6038b6606d8018bc807243d..62fe215ffc068f6198cf512c2f59b789032f1db3 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 690919111a66beb921d106e5b73c7d205988c5a6..916c96e2b4761b488423cdd691bea193aa00980a 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 fd1a165ee65841943e1667138866da8e0c27f58d..627707078b289af3a4365c18234070f55befb08b 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 44f8b4c007daf5cc4716b1087a389870f11d993a..d17895a1beece66708fa212e5069140cfa123e91 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 164f33ffc0953ca210e47a0f1a57230dc68ea878..9db6de14a3c87c1e34f1e7f692884ade87a45f0d 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 d51220d64ca6dac748d19988e80e32d6a922aef7..e929651b5bf779d300839823f0acd7d69a1ee3cf 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 a2daf2cd977ee82b67e6e3cd9072946b36f93e70..146bc62b3e10ad03dd096f985753852446d03217 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 1345005e45110478e3b0814c5479e71be3fdca27..360ebb64c329de4db028ce544765ad15adb33bed 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 186a0801073ff1a7a6756c05620f855a98ac3709..0e5231834de4c7efff886e88961a87bf20b16768 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) \