interned strings
authorMichael Wallner <mike@php.net>
Fri, 2 Nov 2018 06:36:31 +0000 (07:36 +0100)
committerMichael Wallner <mike@php.net>
Fri, 2 Nov 2018 06:36:31 +0000 (07:36 +0100)
Makefile.frag
src/call.c
src/context.c
src/cpp.c
src/parser.c
src/parser.re
src/parser_proc_grammar.y
src/token.c
src/types/decl_abi.c
src/types/decl_extvar.c
src/types/impl_def_val.c

index 1cd17bd25cc5296e3d40fe58bdda5e9ab620d6a5..7ad630192d2b91b200284de54fbdcdbe6cf4d628 100644 (file)
@@ -36,7 +36,8 @@ psi-generated: $(PHP_PSI_GENERATED)
 PHP_PSI_DEPEND = $(patsubst $(PHP_PSI_SRCDIR)/%,$(PHP_PSI_BUILDDIR)/%,$(PHP_PSI_SOURCES:.c=.dep))
 
 $(PHP_PSI_BUILDDIR)/%.dep: $(PHP_PSI_SRCDIR)/%.c | $(PHP_PSI_GENERATED)
-       $(CC) -MM -MG -MF $@ -MT $(patsubst $(PHP_PSI_SRCDIR)/%,$(PHP_PSI_BUILDDIR)/%,$(@:.dep=.lo)) \
+       @echo Generating $@ ...
+       @$(CC) -MM -MG -MF $@ -MT $(patsubst $(PHP_PSI_SRCDIR)/%,$(PHP_PSI_BUILDDIR)/%,$(@:.dep=.lo)) \
                $(CPPFLAGS) $(DEFS) $(INCLUDES) $< \
                        || touch $@
 
index c5aa4b7b7c624f92e5f5427cf4d6cef92a711f1e..22516c77cf7f2280d627fc6bffbd745f9b19868b 100644 (file)
@@ -199,7 +199,7 @@ zval *psi_call_frame_sub_argument(struct psi_call_frame *frame,
        if (!iarg) {
                struct psi_call_frame_argument *frame_arg;
                impl_val empty_val = {0};
-               zend_string *type_str = zend_string_init(ZEND_STRL("mixed"), 1);
+               zend_string *type_str = zend_string_init_interned(ZEND_STRL("mixed"), 1);
                struct psi_impl_arg *carg_spec = psi_impl_arg_init(
                                psi_impl_type_init(PSI_T_MIXED, type_str),
                                psi_impl_var_copy(inner_var), NULL);
index da36c8ef6b13693cbbdb7931889433f5b8872e0a..8fdbf22f41a2701b60833ce59407f3c48b078122 100644 (file)
@@ -196,6 +196,9 @@ zend_function_entry *psi_context_compile(struct psi_context *C)
                        case PSI_T_STRING:
                        case PSI_T_QUOTED_STRING:
                                ZVAL_NEW_STR(&zc.value, zend_string_copy(c->val->ival.zend.str));
+                               if (ZSTR_IS_INTERNED(Z_STR(zc.value))) {
+                                       Z_TYPE_FLAGS(zc.value) = 0;
+                               }
                                break;
                        default:
                                assert(0);
index 64a1b55562aef6e778f81f1264ebe37e7df91b50..1300d57e9513e5b5a43410386ce5733df2bf47d8 100644 (file)
--- a/src/cpp.c
+++ b/src/cpp.c
@@ -173,7 +173,7 @@ static bool psi_cpp_stage1(struct psi_cpp *cpp)
 
                                        no_ws->type = PSI_T_NO_WHITESPACE;
                                        zend_string_release(no_ws->text);
-                                       no_ws->text = zend_string_init("\xA0", 1, 1);
+                                       no_ws->text = zend_string_init_interned("\xA0", 1, 1);
                                        psi_cpp_tokiter_add(cpp, no_ws);
                                        continue;
                                }
index dfeb9701542f1b4f5144df73cf10ff7ad44bfb3a..47b89cb615d3f3e40150eeb67afbba281a68330e 100644 (file)
@@ -1,4 +1,4 @@
-/* Generated by re2c 1.1.1 on Thu Nov  1 08:10:31 2018 */
+/* Generated by re2c 1.1.1 on Fri Nov  2 07:35:40 2018 */
 #line 1 "src/parser.re"
 /*******************************************************************************
  Copyright (c) 2016, Michael Wallner <mike@php.net>.
@@ -103,7 +103,7 @@ struct psi_parser_input *psi_parser_open_file(struct psi_parser *P, const char *
        }
 
        fb->length = sb.st_size;
-       fb->file = zend_string_init(filename, strlen(filename), 1);
+       fb->file = zend_string_init_interned(filename, strlen(filename), 1);
 
        return fb;
 }
@@ -123,7 +123,7 @@ struct psi_parser_input *psi_parser_open_string(struct psi_parser *P, const char
        memset(sb->buffer + length, 0, YYMAXFILL);
 
        sb->length = length;
-       sb->file = zend_string_init("<stdin>", strlen("<stdin>"), 1);
+       sb->file = zend_string_init_interned("<stdin>", strlen("<stdin>"), 1);
 
        return sb;
 }
@@ -172,7 +172,7 @@ void psi_parser_postprocess(struct psi_parser *P)
                                smart_str_appendl_ex(&ns_name, ZEND_STRL("psi\\"), 1);
                                smart_str_append_ex(&ns_name, name, 1);
                                name_str = smart_str_extract(&ns_name);
-                               type_str = zend_string_init(ZEND_STRL("<eval number>"), 1);
+                               type_str = zend_string_init_interned(ZEND_STRL("<eval number>"), 1);
 
                                num = psi_num_exp_copy(scope.macro->exp);
                                def = psi_impl_def_val_init(PSI_T_NUMBER, num);
@@ -197,7 +197,7 @@ void psi_parser_postprocess(struct psi_parser *P)
                                                smart_str_appendl_ex(&ns_name, ZEND_STRL("psi\\"), 1);
                                                smart_str_append_ex(&ns_name, name, 1);
                                                name_str = smart_str_extract(&ns_name);
-                                               type_str = zend_string_init(ZEND_STRL("string"), 1);
+                                               type_str = zend_string_init_interned(ZEND_STRL("string"), 1);
 
                                                type = psi_impl_type_init(PSI_T_STRING, type_str);
                                                def = psi_impl_def_val_init(PSI_T_QUOTED_STRING, t->text);
@@ -264,17 +264,17 @@ void psi_parser_free(struct psi_parser **P)
        ++I->lines
 
 #define NEWTOKEN(t) \
-       token = psi_token_init(t, tok, cur - tok, tok - eol + 1, I->lines, I->file); \
+       if (t == PSI_T_COMMENT || t == PSI_T_WHITESPACE) { \
+               token = psi_token_init(t, "", 0, tok - eol + 1, I->lines, I->file); \
+       } else { \
+               token = psi_token_init(t, tok, cur - tok, tok - eol + 1, I->lines, I->file); \
+       } \
        tokens = psi_plist_add(tokens, &token); \
        if (P->flags & PSI_DEBUG) { \
                fprintf(stderr, "PSI< "); \
                psi_token_dump(2, token); \
        }
 
-union int_suffix {
-       char s[4];
-       uint32_t i;
-};
 
 struct psi_plist *psi_parser_scan(struct psi_parser *P, struct psi_parser_input *I)
 {
index 926cc7cf02a279dc38a4c9b8bf8d9c89ea430705..72587f0917755df8aed11c5a805a7dc822d5811f 100644 (file)
@@ -100,7 +100,7 @@ struct psi_parser_input *psi_parser_open_file(struct psi_parser *P, const char *
        }
 
        fb->length = sb.st_size;
-       fb->file = zend_string_init(filename, strlen(filename), 1);
+       fb->file = zend_string_init_interned(filename, strlen(filename), 1);
 
        return fb;
 }
@@ -120,7 +120,7 @@ struct psi_parser_input *psi_parser_open_string(struct psi_parser *P, const char
        memset(sb->buffer + length, 0, YYMAXFILL);
 
        sb->length = length;
-       sb->file = zend_string_init("<stdin>", strlen("<stdin>"), 1);
+       sb->file = zend_string_init_interned("<stdin>", strlen("<stdin>"), 1);
 
        return sb;
 }
@@ -169,7 +169,7 @@ void psi_parser_postprocess(struct psi_parser *P)
                                smart_str_appendl_ex(&ns_name, ZEND_STRL("psi\\"), 1);
                                smart_str_append_ex(&ns_name, name, 1);
                                name_str = smart_str_extract(&ns_name);
-                               type_str = zend_string_init(ZEND_STRL("<eval number>"), 1);
+                               type_str = zend_string_init_interned(ZEND_STRL("<eval number>"), 1);
 
                                num = psi_num_exp_copy(scope.macro->exp);
                                def = psi_impl_def_val_init(PSI_T_NUMBER, num);
@@ -194,7 +194,7 @@ void psi_parser_postprocess(struct psi_parser *P)
                                                smart_str_appendl_ex(&ns_name, ZEND_STRL("psi\\"), 1);
                                                smart_str_append_ex(&ns_name, name, 1);
                                                name_str = smart_str_extract(&ns_name);
-                                               type_str = zend_string_init(ZEND_STRL("string"), 1);
+                                               type_str = zend_string_init_interned(ZEND_STRL("string"), 1);
 
                                                type = psi_impl_type_init(PSI_T_STRING, type_str);
                                                def = psi_impl_def_val_init(PSI_T_QUOTED_STRING, t->text);
@@ -261,17 +261,17 @@ void psi_parser_free(struct psi_parser **P)
        ++I->lines
 
 #define NEWTOKEN(t) \
-       token = psi_token_init(t, tok, cur - tok, tok - eol + 1, I->lines, I->file); \
+       if (t == PSI_T_COMMENT || t == PSI_T_WHITESPACE) { \
+               token = psi_token_init(t, "", 0, tok - eol + 1, I->lines, I->file); \
+       } else { \
+               token = psi_token_init(t, tok, cur - tok, tok - eol + 1, I->lines, I->file); \
+       } \
        tokens = psi_plist_add(tokens, &token); \
        if (P->flags & PSI_DEBUG) { \
                fprintf(stderr, "PSI< "); \
                psi_token_dump(2, token); \
        }
 
-union int_suffix {
-       char s[4];
-       uint32_t i;
-};
 
 struct psi_plist *psi_parser_scan(struct psi_parser *P, struct psi_parser_input *I)
 {
index 32e673b4d591287b0bec1662be750080a7f47c3c..1b40555e3fa9e777039cf1010ab48c8c13d9b020 100644 (file)
@@ -947,7 +947,7 @@ decl_type_simple[type]:
 }
 ;
 
-decl_real_type[type]:
+decl_real_type[type]: /* allocated, so free, if set */
        FLOAT[type_] {
        $type = psi_token_copy($type_);
 }
@@ -964,7 +964,7 @@ int_signed[i]:
 |      UNSIGNED
 ;
 
-int_width[i]:
+int_width[i]: /* allocated, so free, if set */
        SHORT {
        $i = psi_token_copy($SHORT);
 }
@@ -976,7 +976,7 @@ int_width[i]:
 }
 ;
 
-decl_int_type[type]:
+decl_int_type[type]: /* allocated, so free, if set */
        CHAR {
        $type = psi_token_copy($CHAR);
 }
@@ -1002,7 +1002,7 @@ decl_int_type[type]:
 }
 ;
 
-int_signed_types[type]:
+int_signed_types[type]: /* allocated, so free, if set */
        %empty {
        $type = NULL;
 }
@@ -1046,7 +1046,7 @@ signed_long_types[type]:
 |      LONG INT
 ;
 
-int_width_types[type]:
+int_width_types[type]: /* allocated, so free, if set */
        %empty {
        $type = NULL;
 }
index 5dbb2eccad9df30bb227ac5157c656a4379f5756..316c734384843e16e275face12f3c9c81cf382ad 100644 (file)
@@ -46,7 +46,7 @@ struct psi_token *psi_token_init(token_t token_typ, const char *token_txt,
        T->col = col;
        T->line = line;
        T->file = zend_string_copy(file);
-       T->text = zend_string_init(token_txt, token_len, 1);
+       T->text = zend_string_init_interned(token_txt, token_len, 1);
 #if PSI_DEBUG_TOKEN_ALLOC
        fprintf(stderr, "PSI: token_init %p\n", T);
 #endif
index bf05239a00ac9bc36bd7a7ffe7f73e3bc192c1bd..794005b695d47e82fc7adec6561c3e150157a283 100644 (file)
@@ -31,7 +31,7 @@ struct psi_decl_abi *psi_decl_abi_init(zend_string *convention)
        struct psi_decl_abi *abi = calloc(1, sizeof(*abi));
        abi->convention = convention
                        ? zend_string_copy(convention)
-                       : zend_string_init(ZEND_STRL("default"), 1);
+                       : zend_string_init_interned(ZEND_STRL("default"), 1);
        return abi;
 }
 
index fc4a5efd27e9b6b9d31190147291d2c811bacfa4..c6a77aa436d6db0dda922b1ce536112a0f097a28 100644 (file)
@@ -115,7 +115,7 @@ void psi_decl_extvar_dump(int fd, struct psi_decl_extvar *evar)
 
 struct psi_decl *psi_decl_extvar_setter(struct psi_decl_extvar *evar)
 {
-       zend_string *type_str = zend_string_init(ZEND_STRS("void"), 1);
+       zend_string *type_str = zend_string_init_interned(ZEND_STRS("void"), 1);
        struct psi_decl_type *func_type = psi_decl_type_init(PSI_T_VOID, type_str);
        struct psi_decl_var *func_var = psi_decl_var_copy(evar->arg->var);
        struct psi_decl_arg *func = psi_decl_arg_init(func_type, func_var);
index 311b39d27cde78b07b0f78a0f480ee59d9ef9880..f78a6b9c0d4355523dd365c24a7e0fd43853b78a 100644 (file)
@@ -113,13 +113,13 @@ bool psi_impl_def_val_validate(struct psi_data *data,
                                val->type = PSI_T_FLOAT;
                                type->type = PSI_T_FLOAT;
                                zend_string_release(type->name);
-                               type->name = zend_string_init(ZEND_STRL("float"), 1);
+                               type->name = zend_string_init_interned(ZEND_STRL("float"), 1);
                                break;
                        default:
                                val->type = PSI_T_INT;
                                type->type = PSI_T_INT;
                                zend_string_release(type->name);
-                               type->name = zend_string_init(ZEND_STRL("int"), 1);
+                               type->name = zend_string_init_interned(ZEND_STRL("int"), 1);
                                break;
                        }
                        psi_num_exp_free(&val->data.num);