X-Git-Url: https://git.m6w6.name/?a=blobdiff_plain;f=src%2Ftypes%2Fcpp_macro_decl.c;h=25bafd848ecb3c11aa4f106b9e4501ee3029911e;hb=a0f437f26cd0f121ee911a55327a68a3544bf15f;hp=bfa230c3cf5963bb6a4edb0c7672cd41325a7543;hpb=6509a2053456d0e63b6f383b757289d3016ed1a5;p=m6w6%2Fext-psi diff --git a/src/types/cpp_macro_decl.c b/src/types/cpp_macro_decl.c index bfa230c..25bafd8 100644 --- a/src/types/cpp_macro_decl.c +++ b/src/types/cpp_macro_decl.c @@ -31,7 +31,7 @@ struct psi_cpp_macro_decl *psi_cpp_macro_decl_init(struct psi_plist *sig, struct psi_plist *tokens, struct psi_num_exp *exp) { - struct psi_cpp_macro_decl *macro = calloc(1, sizeof(*macro)); + struct psi_cpp_macro_decl *macro = pecalloc(1, sizeof(*macro), 1); macro->exp = exp; macro->sig = sig; macro->tokens = tokens; @@ -44,9 +44,7 @@ void psi_cpp_macro_decl_free(struct psi_cpp_macro_decl **macro_ptr) struct psi_cpp_macro_decl *macro = *macro_ptr; *macro_ptr = NULL; - if (macro->token) { - free(macro->token); - } + psi_token_free(¯o->token); if (macro->exp) { psi_num_exp_free(¯o->exp); } @@ -60,18 +58,95 @@ void psi_cpp_macro_decl_free(struct psi_cpp_macro_decl **macro_ptr) } } -void psi_cpp_macro_decl_dump(int fd, struct psi_cpp_macro_decl *macro) +void psi_cpp_macro_decl_dump(struct psi_dump *dump, struct psi_cpp_macro_decl *macro) { - dprintf(fd, "%s", macro->token->text); + PSI_DUMP(dump, "%s", macro->token->text->val); if (macro->sig) { size_t i = 0; struct psi_token *tok; - dprintf(fd, "("); + PSI_DUMP(dump, "("); while (psi_plist_get(macro->sig, i++, &tok)) { - dprintf(fd, "%s%s", i>1?",":"", tok->text); + PSI_DUMP(dump, "%s%s", i>1?",":"", tok->text->val); + } + PSI_DUMP(dump, ")"); + } + + if (macro->exp) { + PSI_DUMP(dump, " "); + psi_num_exp_dump(dump, macro->exp); + + assert(macro->tokens); + + } else if (macro->tokens) { + size_t i = 0; + struct psi_token *tok; + + while (psi_plist_get(macro->tokens, i++, &tok)) { + switch (tok->type) { + case PSI_T_QUOTED_STRING: + PSI_DUMP(dump, " \"%s\"", tok->text->val); + break; + case PSI_T_QUOTED_CHAR: + PSI_DUMP(dump, " '%s'", tok->text->val); + break; + default: + PSI_DUMP(dump, " %s", tok->text->val); + } + } + } +} + +static inline bool cmp_token_list(struct psi_plist *l1, struct psi_plist *l2) +{ + size_t c = psi_plist_count(l1), i; + + if (c != psi_plist_count(l2)) { + return false; + } + + for (i = 0; i < c; ++i) { + struct psi_token *t1, *t2; + + psi_plist_get(l1, i, &t1); + psi_plist_get(l2, i, &t2); + + if (!zend_string_equals(t1->text, t2->text)) { + return false; } - dprintf(fd, ")"); } + + return true; +} + +bool psi_cpp_macro_decl_equal(struct psi_cpp_macro_decl *d1, struct psi_cpp_macro_decl *d2) +{ + if (d1->sig) { + if (!d2->sig) { + return false; + } + + if (!cmp_token_list(d1->sig, d2->sig)) { + return false; + } + } else if (d2->sig) { + return false; + } + + if (d1->tokens) { + if (!d2->tokens) { + return false; + } + + if (!cmp_token_list(d1->tokens, d2->tokens)) { + return false; + } + } else if (d2->tokens) { + return false; + } + + /* FIXME compare num_exps */ + + return true; }