}
while (psi_plist_get(cpp->tokens.iter, i, &T)) {
PSI_DUMP(dump, "PSI: CPP tokens %5zu %c ", i, cpp->index == i ? '*' : ' ');
- if (T) {
- psi_token_dump(dump, T);
- } else {
- PSI_DUMP(dump, "TOKEN deleted\n");
- }
+ psi_token_dump(dump, T);
if (i >= cpp->index + 40) {
PSI_DUMP(dump, "PSI: CPP tokens .....\n");
break;
void psi_cpp_tokiter_reset(struct psi_cpp *cpp)
{
-#if PSI_CPP_DEBUG
- PSI_DEBUG_PRINT(cpp->parser, "PSI: CPP reset -> iter.count=%zu, next.count=%zu\n",
- psi_plist_count(cpp->tokens.iter),
- psi_plist_count(cpp->tokens.next));
-# if PSI_CPP_DEBUG > 1
- PSI_DEBUG_DUMP(cpp->parser, psi_cpp_tokiter_dump, cpp);
-# endif
-#endif
cpp->index = 0;
cpp->expanded = 0;
cpp->skip = 0;
cpp->do_cpp = false;
if (cpp->tokens.next) {
- free(cpp->tokens.iter);
+ psi_plist_free(cpp->tokens.iter);
cpp->tokens.iter = cpp->tokens.next;
}
cpp->tokens.next = psi_plist_init((psi_plist_dtor) psi_token_free);
- cpp->tokens.exec = psi_plist_init((psi_plist_dtor) psi_token_free);
+ if (cpp->tokens.exec) {
+ assert(!psi_plist_count(cpp->tokens.exec));
+ psi_plist_clean(cpp->tokens.exec);
+ } else {
+ cpp->tokens.exec = psi_plist_init((psi_plist_dtor) psi_token_free);
+ }
+#if PSI_CPP_DEBUG
+ PSI_DEBUG_PRINT(cpp->parser,
+ "PSI: CPP reset -> iter.count=%zu, next.count=%zu, exec.count=%zu\n",
+ psi_plist_count(cpp->tokens.iter),
+ psi_plist_count(cpp->tokens.next),
+ psi_plist_count(cpp->tokens.exec));
+# if PSI_CPP_DEBUG > 1
+ PSI_DEBUG_DUMP(cpp->parser, psi_cpp_tokiter_dump, cpp);
+# endif
+#endif
}
bool psi_cpp_tokiter_seek(struct psi_cpp *cpp, size_t index)
struct psi_token *cur = NULL;
if (psi_plist_get(cpp->tokens.iter, cpp->index, &cur)) {
+ psi_plist_unset(cpp->tokens.iter, cpp->index);
if (cpp->do_cpp) {
cpp->tokens.exec = psi_plist_add(cpp->tokens.exec, &cur);
} else {
bool psi_cpp_tokiter_add_range(struct psi_cpp *cpp, size_t num_eles, void **eles)
{
- struct psi_plist *tokens;
-
if (!num_eles) {
return true;
}
bool psi_cpp_tokiter_valid(struct psi_cpp *cpp)
{
-#if 0 && PSI_CPP_DEBUG
- PSI_DEBUG_PRINT(cpp->parser, "PSI: CPP valid -> index=%zu -> %d\n",
- cpp->index, cpp->index < psi_plist_count(cpp->tokens.iter));
+#if PSI_CPP_DEBUG > 1
+ PSI_DEBUG_PRINT(cpp->parser, "PSI: CPP valid -> index=%zu -> %s\n",
+ cpp->index, cpp->index < psi_plist_count(cpp->tokens.iter)
+ ? "true" : "false");
#endif
return cpp->index < psi_plist_count(cpp->tokens.iter);
}
#endif
if (cpp->do_cpp) {
- if (!psi_plist_pop(cpp->tokens.exec, NULL)) {
+ if (!psi_plist_pop(cpp->tokens.exec, &cur)) {
return false;
}
- } else if (!psi_plist_pop(cpp->tokens.next, NULL)) {
- return false;
- }
-
- if (!psi_plist_get(cpp->tokens.iter, cpp->index - 1, &cur)) {
+ } else if (!psi_plist_pop(cpp->tokens.next, &cur)) {
return false;
}
- psi_plist_unset(cpp->tokens.iter, cpp->index - 1);
if (free_token && cur) {
psi_token_free(&cur);
}
#if PSI_CPP_DEBUG
PSI_DEBUG_DUMP(cpp->parser, psi_token_dump, cur);
#endif
- psi_plist_unset(cpp->tokens.iter, cpp->index);
+ if (cpp->index == psi_plist_count(cpp->tokens.iter) - 1) {
+ psi_plist_pop(cpp->tokens.iter, NULL);
+ } else {
+ psi_plist_unset(cpp->tokens.iter, cpp->index);
+ }
if (free_token && cur) {
psi_token_free(&cur);
}
return false;
}
#if PSI_CPP_DEBUG
- PSI_DEBUG_PRINT(cpp->parser, "PSI: CPP del_range -> ");
- PSI_DEBUG_DUMP(cpp->parser, psi_token_dump, ptr);
+ PSI_DEBUG_LOCK(cpp->parser,
+ PSI_DEBUG_PRINT(cpp->parser, "PSI: CPP del_range -> ");
+ PSI_DEBUG_DUMP(cpp->parser, psi_token_dump, ptr);
+ );
#endif
psi_plist_unset(cpp->tokens.iter, i);
if (free_tokens && ptr) {
return true;
}
-bool psi_cpp_tokiter_ins_range(struct psi_cpp *cpp, size_t num_eles, void **eles)
-{
- struct psi_plist *tokens;
-
- if (!num_eles) {
- return true;
- }
-
- cpp->tokens.iter = psi_plist_ins_r(cpp->tokens.iter, cpp->index, num_eles, eles);
-
-#if PSI_CPP_DEBUG
- PSI_DEBUG_PRINT(cpp->parser,
- "PSI: CPP ins_range -> index=%zu, num_eles=%zu, iter.count=%zu, next.count=%zu, exec.count=%zu\n",
- cpp->index, num_eles, psi_plist_count(cpp->tokens.iter), psi_plist_count(cpp->tokens.next),
- psi_plist_count(cpp->tokens.exec));
-#endif
-
- return true;
-}
-
bool psi_cpp_tokiter_defined(struct psi_cpp *cpp)
{
if (psi_cpp_tokiter_valid(cpp)) {
return false;
}
} else {
- psi_cpp_tokiter_next(cpp);
+ psi_cpp_tokiter_del_cur(cpp, false);
}
psi_cpp_tokiter_expand_builtin_tokens(cpp, target, builtin, arg_tokens_list);
static inline bool psi_cpp_tokiter_expand_def(struct psi_cpp *cpp,
struct psi_token *target, struct psi_cpp_macro_decl *macro)
{
- /* delete current token from stream */
- psi_cpp_tokiter_del_cur(cpp, false);
-
if (macro->tokens) {
struct psi_plist *tokens = psi_plist_copy(macro->tokens,
(void (*)(void *)) psi_token_copy_ctor);
/* replace with tokens from macro */
psi_cpp_tokiter_expand_tokens(cpp, target, tokens);
}
+ psi_plist_free(tokens);
++cpp->expanded;
}
- psi_token_free(&target);
+ psi_cpp_tokiter_del_cur(cpp, true);
return true;
}
return false;
}
- /* don't expand itself */
-// if (zend_string_equals(macro->token->text, target->text)) {
-// PSI_DEBUG_PRINT(cpp->parser, "PSI: CPP expand ~ skipping self token\n");
-// return false;
-// }
-
if (macro->sig) {
return psi_cpp_tokiter_expand_call(cpp, target, macro);
} else if (psi_cpp_tokiter_expand_cmp(target, macro)) {