#include "cpp.h"
#include "parser.h"
-
+#if PSI_CPP_DEBUG > 1
void psi_cpp_tokiter_dump(int fd, struct psi_cpp *cpp)
{
- size_t i;
+ size_t i = cpp->index;
struct psi_token *T;
- for (i = 0; psi_plist_get(cpp->tokens, i, &T); ++i) {
+ if (i > 20) {
+ i -= 20;
+ } else {
+ i = 0;
+ }
+ while (psi_plist_get(cpp->tokens, i, &T)) {
dprintf(fd, "PSI: CPP tokens %5zu %c ", i, cpp->index == i ? '*' : ' ');
psi_token_dump(fd, T);
+ if (i >= cpp->index + 10) {
+ dprintf(fd, "PSI: CPP tokens .....\n");
+ break;
+ }
+ ++i;
}
}
+#endif
void psi_cpp_tokiter_reset(struct psi_cpp *cpp)
{
deleted = psi_plist_del_r(cpp->tokens, offset, num_eles, (void *) ptr);
if (deleted) {
- if (cpp->index >= psi_plist_count(cpp->tokens)) {
- cpp->index = MAX(0, psi_plist_count(cpp->tokens)-1);
+ size_t count = psi_plist_count(cpp->tokens);
+
+ if (cpp->index >= count) {
+ if (count > 0) {
+ cpp->index = count - 1;
+ } else {
+ cpp->index = 0;
+ }
}
+
if (free_tokens) {
while (num_eles--) {
if (ptr[num_eles]) {
while (psi_plist_get(tokens, i++, &tok)) {
struct psi_token *new_tok;
+ if (tok->type == PSI_T_EOL) {
+ continue;
+ }
if (tok->type == PSI_T_HASH) {
- if (stringify) {
- stringify = false;
- paste = true;
- } else {
- stringify = true;
- }
+ stringify = true;
+ continue;
+ }
+ if (tok->type == PSI_T_CPP_PASTE) {
+ paste = true;
continue;
}
struct psi_token *cpy = psi_token_copy(tok);
if (stringify) {
- cpy = psi_token_append(NULL,
- psi_token_prepend(NULL, cpy, 1, "\""), 1, "\"");
cpy->type = PSI_T_QUOTED_STRING;
}
exp_tokens[n++] = cpy;
fprintf(stderr, "PSI: CPP expand > ");
psi_token_dump(2, tok);
#endif
+
paste = false;
stringify = false;
}
if (current) {
struct psi_cpp_macro_decl *macro = zend_hash_str_find_ptr(
- cpp->defs, current->text, current->size);
+ &cpp->defs, current->text, current->size);
/* don't expand itself */
if (macro && macro->token != current) {