interned strings
[m6w6/ext-psi] / src / parser_proc_grammar.y
index 5f78335bfbd781e1fd5ee3a9ac2abf49da8c6d9b..1b40555e3fa9e777039cf1010ab48c8c13d9b020 100644 (file)
@@ -60,8 +60,8 @@ static inline void psi_parser_proc_deanon_typedef(struct psi_decl_arg *def)
        default:
                return;
        }
-       free(def->type->name);
-       def->type->name = strdup(def->var->name);
+       zend_string_release(def->type->name);
+       def->type->name = zend_string_copy(def->var->name);
 }
 static inline void psi_parser_proc_add_typedef(struct psi_parser *P, struct psi_decl_arg *def)
 {
@@ -83,7 +83,7 @@ static inline void psi_parser_proc_add_const(struct psi_parser *P, struct psi_co
 static inline void psi_parser_proc_add_decl(struct psi_parser *P, struct psi_decl *decl) {
        assert(decl);
        
-       if (psi_decl_is_blacklisted(decl->func->var->name)) {
+       if (psi_decl_is_blacklisted(decl->func->var->name->val)) {
                psi_decl_free(&decl);
                return;
        }
@@ -456,7 +456,7 @@ block:
        }
 }
 |      lib {
-       char *libname = strdup($lib->text);
+       char *libname = strdup($lib->text->val);
        P->file.libnames = psi_plist_add(P->file.libnames, &libname);
 }
 |      constant {
@@ -470,7 +470,7 @@ block:
 }
 |      ignored_decl {
        if (P->flags & PSI_DEBUG) {
-               P->error(PSI_DATA(P), $ignored_decl->func->token, PSI_NOTICE, "Ignored decl: %s", $ignored_decl->func->var->name);
+               P->error(PSI_DATA(P), $ignored_decl->func->token, PSI_NOTICE, "Ignored decl: %s", $ignored_decl->func->var->name->val);
        }
        psi_decl_free(&$ignored_decl);
 }
@@ -519,7 +519,7 @@ cpp_exp[exp]:
                        while (psi_plist_get($tokens, index++, &next)) {
                                struct psi_token *old = msg;
                                msg = psi_token_cat(" ", 2, msg, next);
-                               free(old);
+                               psi_token_free(&old);
                        }
                }
                psi_plist_free($tokens);
@@ -770,7 +770,7 @@ impl_def_val[val]:
 }
 |      quoted_strings[token] {
        $val = psi_impl_def_val_init($token->type, $token->text);
-       $val->token = psi_token_copy($token);
+       $val->token = $token;
 }
 ;
 
@@ -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);
 }
@@ -986,7 +986,7 @@ decl_int_type[type]:
 |      int_signed int_signed_types {
        if ($2) {
                $type = psi_token_cat(" ", 2, $1, $2);
-               free($2);
+               psi_token_free(&$2);
        } else {
                $type = psi_token_copy($1);
        }
@@ -994,15 +994,15 @@ decl_int_type[type]:
 |      int_width int_width_types {
        if ($2) {
                $type = psi_token_cat(" ", 2, $1, $2);
-               free($1);
-               free($2);
+               psi_token_free(&$1);
+               psi_token_free(&$2);
        } else {
                $type = $1;
        }
 }
 ;
 
-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;
 }
@@ -1056,7 +1056,7 @@ int_width_types[type]:
 |      int_signed int_signed_types {
        if ($2) {
                $type = psi_token_cat(" ", 2, $1, $2);
-               free($2);
+               psi_token_free(&$2);
        } else {
                $type = psi_token_copy($1);
        }
@@ -1067,15 +1067,15 @@ decl_stmt:
        decl decl_asm EOS {
        $decl_stmt = $decl;
        if ($decl_asm) {
-               $decl->redir = strdup($decl_asm->text);
-               free($decl_asm);
+               $decl->redir = zend_string_copy($decl_asm->text);
+               psi_token_free(&$decl_asm);
        }
 }
 |      CPP_EXTENSION decl decl_asm EOS {
        $decl_stmt = $decl;
        if ($decl_asm) {
-               $decl->redir = strdup($decl_asm->text);
-               free($decl_asm);
+               $decl->redir = zend_string_copy($decl_asm->text);
+               psi_token_free(&$decl_asm);
        }
 }
 ;
@@ -1095,7 +1095,7 @@ quoted_strings[strings]:
 }
 |      quoted_strings[strings_] QUOTED_STRING {
        $strings = psi_token_cat("", 2, $strings_, $QUOTED_STRING);
-       free($strings_);
+       psi_token_free(&$strings_);
 }
 ;
 
@@ -1108,17 +1108,18 @@ decl_extvar_stmt[list]:
                struct psi_decl_var *var;
                
                while (psi_plist_get($vars, i++, &var)) {
-                       if (psi_decl_extvar_is_blacklisted(var->name)) {
+                       if (psi_decl_extvar_is_blacklisted(var->name->val)) {
                                psi_decl_var_free(&var);
                        } else {
-                               list = psi_plist_add(list, psi_decl_extvar_init(
-                                       psi_decl_arg_init(psi_decl_type_copy($decl_arg->type), var)));
-                               }
+                               struct psi_decl_extvar *evar = psi_decl_extvar_init(
+                                       psi_decl_arg_init(psi_decl_type_copy($decl_arg->type), var));
+                               list = psi_plist_add(list, &evar);
+                       }
                }
                free($vars);
        }
        
-       if (psi_decl_extvar_is_blacklisted($decl_arg->var->name)) {
+       if (psi_decl_extvar_is_blacklisted($decl_arg->var->name->val)) {
                psi_decl_arg_free(&$decl_arg);
        } else {
                struct psi_decl_extvar *evar = psi_decl_extvar_init($decl_arg);
@@ -1148,20 +1149,20 @@ decl_vars[vars]:
 ;
 
 ignored_decl:
-       STATIC decl_body ignored_decl_body {
-       $ignored_decl = $decl_body;
-}
-|      STATIC CPP_INLINE decl_body ignored_decl_body {
-       $ignored_decl = $decl_body;
-}
-|      CPP_INLINE decl_body ignored_decl_body {
-       $ignored_decl = $decl_body;
-}
-|      NAME CPP_INLINE decl_body ignored_decl_body {
+       ignored_decl_qualifiers decl_body ignored_decl_body {
        $ignored_decl = $decl_body;
 }
 ;
 
+ignored_decl_qualifiers:
+       STATIC
+|      STATIC CPP_INLINE
+|      CPP_EXTENSION CPP_INLINE
+|      CPP_EXTENSION STATIC CPP_INLINE
+|      CPP_INLINE
+|      NAME CPP_INLINE
+;
+
 ignored_decl_body:
        LBRACE ignored_decl_body_stmts RBRACE
 ;
@@ -1269,6 +1270,7 @@ decl_functor_body[decl]:
        type->real.func = rval_decl;
        func->var->token = psi_token_copy($NAME);
        func->token = psi_token_copy($NAME);
+       type->token = type_token;
        
        $decl = psi_decl_init(func, $args);
 }
@@ -1420,7 +1422,7 @@ decl_anon_arg[arg]:
        char digest[17];
        struct psi_token *name;
 
-       psi_token_hash($decl->func      ->token, digest);
+       psi_token_hash($decl->func->token, digest);
        name = psi_token_append("@", psi_token_copy($decl->func->token), 2, "funct", digest);
        
        $arg = psi_decl_arg_init(
@@ -1719,7 +1721,7 @@ sizeof_body_notypes[sizeof]:
        $sizeof = psi_number_init(PSI_T_INT8, &sizeof_a, 0);
 }
 |      QUOTED_STRING {
-       uint64_t len = $QUOTED_STRING->size + 1;
+       uint64_t len = $QUOTED_STRING->text->len + 1;
        $sizeof = psi_number_init(PSI_T_UINT64, &len, 0);
 }
 ;
@@ -1783,13 +1785,13 @@ decl_layout[l]:
        $l = NULL;
 }
 |      COLON NUMBER[width] {
-       $l = psi_layout_init(0, 0, psi_layout_init(0, atol($width->text), NULL));
+       $l = psi_layout_init(0, 0, psi_layout_init(0, atol($width->text->val), NULL));
 }
 |      COLON COLON LPAREN NUMBER[align] COMMA NUMBER[size] RPAREN {
-       $l = psi_layout_init(atol($align->text), atol($size->text), NULL);
+       $l = psi_layout_init(atol($align->text->val), atol($size->text->val), NULL);
 }
 |      COLON NUMBER[width] COLON COLON LPAREN NUMBER[align] COMMA NUMBER[size] RPAREN {
-       $l = psi_layout_init(atol($align->text), atol($size->text), psi_layout_init(0, atol($width->text), NULL));
+       $l = psi_layout_init(atol($align->text->val), atol($size->text->val), psi_layout_init(0, atol($width->text->val), NULL));
 }
 ;
 
@@ -1799,8 +1801,8 @@ align_and_size[as]:
        $as.len = 0;
 }
 |      COLON COLON LPAREN NUMBER[align] COMMA NUMBER[size] RPAREN {
-       $as.pos = atol($align->text);
-       $as.len = atol($size->text);
+       $as.pos = atol($align->text->val);
+       $as.len = atol($size->text->val);
 }
 ;