projects
/
m6w6
/
ext-psi
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
|
github
raw
|
inline
| side by side
build: fix package.xml
[m6w6/ext-psi]
/
src
/
cpp_tokiter.c
diff --git
a/src/cpp_tokiter.c
b/src/cpp_tokiter.c
index d980e61fde38353c33dba25d3ef613c8be9a638d..51daaa9bb794a850e3ae215b152471a941255a62 100644
(file)
--- a/
src/cpp_tokiter.c
+++ b/
src/cpp_tokiter.c
@@
-28,17
+28,28
@@
#include "cpp.h"
#include "parser.h"
#include "cpp.h"
#include "parser.h"
-
+#if PSI_CPP_DEBUG > 1
void psi_cpp_tokiter_dump(int fd, struct psi_cpp *cpp)
{
void psi_cpp_tokiter_dump(int fd, struct psi_cpp *cpp)
{
- size_t i;
+ size_t i
= cpp->index
;
struct psi_token *T;
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);
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)
{
void psi_cpp_tokiter_reset(struct psi_cpp *cpp)
{
@@
-150,9
+161,16
@@
bool psi_cpp_tokiter_del_range(struct psi_cpp *cpp, size_t offset, size_t num_el
deleted = psi_plist_del_r(cpp->tokens, offset, num_eles, (void *) ptr);
if (deleted) {
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]) {
if (free_tokens) {
while (num_eles--) {
if (ptr[num_eles]) {
@@
-225,13
+243,15
@@
void psi_cpp_tokiter_expand_tokens(struct psi_cpp *cpp, struct psi_plist *tokens
while (psi_plist_get(tokens, i++, &tok)) {
struct psi_token *new_tok;
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 (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;
}
continue;
}
@@
-243,8
+263,6
@@
void psi_cpp_tokiter_expand_tokens(struct psi_cpp *cpp, struct psi_plist *tokens
struct psi_token *cpy = psi_token_copy(tok);
if (stringify) {
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;
cpy->type = PSI_T_QUOTED_STRING;
}
exp_tokens[n++] = cpy;
@@
-254,6
+272,7
@@
void psi_cpp_tokiter_expand_tokens(struct psi_cpp *cpp, struct psi_plist *tokens
fprintf(stderr, "PSI: CPP expand > ");
psi_token_dump(2, tok);
#endif
fprintf(stderr, "PSI: CPP expand > ");
psi_token_dump(2, tok);
#endif
+
paste = false;
stringify = false;
}
paste = false;
stringify = false;
}
@@
-427,7
+446,7
@@
bool psi_cpp_tokiter_expand(struct psi_cpp *cpp)
if (current) {
struct psi_cpp_macro_decl *macro = zend_hash_str_find_ptr(
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) {
/* don't expand itself */
if (macro && macro->token != current) {