interned strings++
[m6w6/ext-psi] / src / parser.re
index 2085a1288f9b14fa0d23d88f32f1d53f81c617d6..ebd1e1628de46248bf97d3cafe3589a189786d4f 100644 (file)
@@ -41,7 +41,7 @@
 struct psi_parser *psi_parser_init(struct psi_parser *P, psi_error_cb error, unsigned flags)
 {
        if (!P) {
-               P = malloc(sizeof(*P));
+               P = pemalloc(sizeof(*P), 1);
        }
        memset(P, 0, sizeof(*P));
 
@@ -49,8 +49,6 @@ struct psi_parser *psi_parser_init(struct psi_parser *P, psi_error_cb error, uns
 
        P->preproc = psi_cpp_init(P);
 
-       psi_cpp_load_defaults(P->preproc);
-
        return P;
 }
 
@@ -69,7 +67,7 @@ struct psi_parser_input *psi_parser_open_file(struct psi_parser *P, const char *
                return NULL;
        }
 
-       if (!(fb = malloc(sizeof(*fb) + sb.st_size + YYMAXFILL))) {
+       if (!(fb = pemalloc(sizeof(*fb) + sb.st_size + YYMAXFILL, 1))) {
                if (report_errors) {
                        P->error(PSI_DATA(P), NULL, PSI_WARNING,
                                        "Could not allocate %zu bytes for reading '%s': %s",
@@ -100,7 +98,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;
 }
@@ -109,7 +107,7 @@ struct psi_parser_input *psi_parser_open_string(struct psi_parser *P, const char
 {
        struct psi_parser_input *sb;
 
-       if (!(sb = malloc(sizeof(*sb) + length + YYMAXFILL))) {
+       if (!(sb = pemalloc(sizeof(*sb) + length + YYMAXFILL, 1))) {
                P->error(PSI_DATA(P), NULL, PSI_WARNING,
                                "Could not allocate %zu bytes: %s",
                                length + YYMAXFILL, strerror(errno));
@@ -120,7 +118,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;
 }
@@ -164,19 +162,20 @@ void psi_parser_postprocess(struct psi_parser *P)
                                struct psi_const *cnst;
                                struct psi_num_exp *num;
                                smart_str ns_name = {0};
-                               zend_string *name_str;
+                               zend_string *name_str, *type_str;
 
                                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_interned(ZEND_STRL("<eval number>"), 1);
 
                                num = psi_num_exp_copy(scope.macro->exp);
                                def = psi_impl_def_val_init(PSI_T_NUMBER, num);
-                               type = psi_impl_type_init(PSI_T_NUMBER,
-                                               zend_string_init(ZEND_STRL("<eval number>"), 1));
+                               type = psi_impl_type_init(PSI_T_NUMBER, type_str);
                                cnst = psi_const_init(type, name_str, def);
                                P->consts = psi_plist_add(P->consts, &cnst);
                                zend_string_release(name_str);
+                               zend_string_release(type_str);
                        }
                } else {
                        if (psi_plist_count(scope.macro->tokens) == 1) {
@@ -188,18 +187,19 @@ void psi_parser_postprocess(struct psi_parser *P)
                                                struct psi_impl_def_val *def;
                                                struct psi_const *cnst;
                                                smart_str ns_name = {0};
-                                               zend_string *name_str;
+                                               zend_string *name_str, *type_str;
 
                                                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_interned(ZEND_STRL("string"), 1);
 
-                                               type = psi_impl_type_init(PSI_T_STRING,
-                                                               zend_string_init(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);
                                                cnst = psi_const_init(type, name_str, def);
                                                P->consts = psi_plist_add(P->consts, &cnst);
                                                zend_string_release(name_str);
+                                               zend_string_release(type_str);
                                        }
                                }
                        }
@@ -259,17 +259,19 @@ 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)
 {