X-Git-Url: https://git.m6w6.name/?p=m6w6%2Fext-psi;a=blobdiff_plain;f=src%2Ftypes%2Fcpp_macro_decl.c;h=e540131243761d44281744acddfbb7190ca249a9;hp=d5e195c353fa0f35c442c064ceb79584ad4ef20c;hb=503860f8936b47b2d4e356d815c112c60d91a95a;hpb=6ebcb60416cad353f5aeacebe919cb6990ef5a7d diff --git a/src/types/cpp_macro_decl.c b/src/types/cpp_macro_decl.c index d5e195c..e540131 100644 --- a/src/types/cpp_macro_decl.c +++ b/src/types/cpp_macro_decl.c @@ -83,7 +83,65 @@ void psi_cpp_macro_decl_dump(int fd, struct psi_cpp_macro_decl *macro) struct psi_token *tok; while (psi_plist_get(macro->tokens, i++, &tok)) { - dprintf(fd, " %s", tok->text); + switch (tok->type) { + case PSI_T_QUOTED_STRING: + dprintf(fd, " \"%s\"", tok->text); + break; + case PSI_T_QUOTED_CHAR: + dprintf(fd, " '%s'", tok->text); + break; + default: + dprintf(fd, " %s", tok->text); + } } } } + +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 (strcmp(t1->text, t2->text)) { + return false; + } + } + + 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; + } + } + + if (d1->tokens) { + if (!d2->tokens) { + return false; + } + + if (!cmp_token_list(d1->tokens, d2->tokens)) { + return false; + } + } + + /* FIXME compare num_exps */ + + return true; +}