projects
/
m6w6
/
ext-psi
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
|
github
raw
|
inline
| side by side
administrativa
[m6w6/ext-psi]
/
src
/
token.c
diff --git
a/src/token.c
b/src/token.c
index 29dcb42657497bc1732bfa358f02d615c424324e..316c734384843e16e275face12f3c9c81cf382ad 100644
(file)
--- a/
src/token.c
+++ b/
src/token.c
@@
-32,9
+32,9
@@
#include "token.h"
#include "parser.h"
#include "token.h"
#include "parser.h"
-size_t psi_token_alloc_size(size_t token_len, size_t fname_len) {
- return sizeof(struct psi_token) + token_len + fname_len + 2;
-}
+#ifndef PSI_DEBUG_TOKEN_ALLOC
+# define PSI_DEBUG_TOKEN_ALLOC 0
+#endif
struct psi_token *psi_token_init(token_t token_typ, const char *token_txt,
size_t token_len, unsigned col, unsigned line, zend_string *file)
struct psi_token *psi_token_init(token_t token_typ, const char *token_txt,
size_t token_len, unsigned col, unsigned line, zend_string *file)
@@
-46,15
+46,19
@@
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->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
return T;
}
void psi_token_free(struct psi_token **token_ptr) {
if (*token_ptr) {
struct psi_token *token = *token_ptr;
return T;
}
void psi_token_free(struct psi_token **token_ptr) {
if (*token_ptr) {
struct psi_token *token = *token_ptr;
-
+#if PSI_DEBUG_TOKEN_ALLOC
+ fprintf(stderr, "PSI: token_free %p\n", token);
+#endif
*token_ptr = NULL;
zend_string_release(token->text);
zend_string_release(token->file);
*token_ptr = NULL;
zend_string_release(token->text);
zend_string_release(token->file);
@@
-66,7
+70,9
@@
struct psi_token *psi_token_copy(struct psi_token *src) {
struct psi_token *ptr = malloc(sizeof(*ptr));
*ptr = *src;
struct psi_token *ptr = malloc(sizeof(*ptr));
*ptr = *src;
-
+#if PSI_DEBUG_TOKEN_ALLOC
+ fprintf(stderr, "PSI: token_copy %p <= %p\n", ptr, src);
+#endif
ptr->text = zend_string_copy(ptr->text);
ptr->file = zend_string_copy(ptr->file);
ptr->text = zend_string_copy(ptr->text);
ptr->file = zend_string_copy(ptr->file);
@@
-91,19
+97,21
@@
struct psi_token *psi_token_cat(const char *sep, unsigned argc, ...) {
T->type = PSI_T_NAME;
T->file = zend_string_copy(T->file);
T->type = PSI_T_NAME;
T->file = zend_string_copy(T->file);
+ smart_str_append_ex(&text, T->text, 1);
+
for (i = 1; i < argc; ++i) {
struct psi_token *arg = va_arg(argv, struct psi_token *);
for (i = 1; i < argc; ++i) {
struct psi_token *arg = va_arg(argv, struct psi_token *);
- if (sep_len && text.a) {
- smart_str_appendl_ex(&text, sep, sep_len, 1);
- }
-
+ smart_str_appendl_ex(&text, sep, sep_len, 1);
smart_str_append_ex(&text, arg->text, 1);
}
va_end(argv);
T->text = smart_str_extract(&text);
smart_str_append_ex(&text, arg->text, 1);
}
va_end(argv);
T->text = smart_str_extract(&text);
+#if PSI_DEBUG_TOKEN_ALLOC
+ fprintf(stderr, "PSI: token_cat %p\n", T);
+#endif
return T;
}
return T;
}