From: Michael Wallner Date: Fri, 2 Nov 2018 06:36:31 +0000 (+0100) Subject: interned strings X-Git-Url: https://git.m6w6.name/?a=commitdiff_plain;h=2559f07a178b681dc240e20153ff5abdff54cb34;p=m6w6%2Fext-psi interned strings --- diff --git a/Makefile.frag b/Makefile.frag index 1cd17bd..7ad6301 100644 --- a/Makefile.frag +++ b/Makefile.frag @@ -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 $@ diff --git a/src/call.c b/src/call.c index c5aa4b7..22516c7 100644 --- a/src/call.c +++ b/src/call.c @@ -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); diff --git a/src/context.c b/src/context.c index da36c8e..8fdbf22 100644 --- a/src/context.c +++ b/src/context.c @@ -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); diff --git a/src/cpp.c b/src/cpp.c index 64a1b55..1300d57 100644 --- 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; } diff --git a/src/parser.c b/src/parser.c index dfeb970..47b89cb 100644 --- a/src/parser.c +++ b/src/parser.c @@ -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 . @@ -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("", strlen(""), 1); + sb->file = zend_string_init_interned("", strlen(""), 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(""), 1); + type_str = zend_string_init_interned(ZEND_STRL(""), 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) { diff --git a/src/parser.re b/src/parser.re index 926cc7c..72587f0 100644 --- a/src/parser.re +++ b/src/parser.re @@ -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("", strlen(""), 1); + sb->file = zend_string_init_interned("", strlen(""), 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(""), 1); + type_str = zend_string_init_interned(ZEND_STRL(""), 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) { diff --git a/src/parser_proc_grammar.y b/src/parser_proc_grammar.y index 32e673b..1b40555 100644 --- a/src/parser_proc_grammar.y +++ b/src/parser_proc_grammar.y @@ -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; } diff --git a/src/token.c b/src/token.c index 5dbb2ec..316c734 100644 --- a/src/token.c +++ b/src/token.c @@ -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 diff --git a/src/types/decl_abi.c b/src/types/decl_abi.c index bf05239..794005b 100644 --- a/src/types/decl_abi.c +++ b/src/types/decl_abi.c @@ -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; } diff --git a/src/types/decl_extvar.c b/src/types/decl_extvar.c index fc4a5ef..c6a77aa 100644 --- a/src/types/decl_extvar.c +++ b/src/types/decl_extvar.c @@ -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); diff --git a/src/types/impl_def_val.c b/src/types/impl_def_val.c index 311b39d..f78a6b9 100644 --- a/src/types/impl_def_val.c +++ b/src/types/impl_def_val.c @@ -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);