projects
/
m6w6
/
ext-psi
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
|
github
raw
|
patch
|
inline
| side by side (parent:
9c906fa
)
cpp: inherit macro token's file, line and col information
author
Michael Wallner
<mike@php.net>
Fri, 7 Jul 2017 07:18:05 +0000
(09:18 +0200)
committer
Michael Wallner
<mike@php.net>
Fri, 7 Jul 2017 07:18:05 +0000
(09:18 +0200)
src/cpp_tokiter.c
patch
|
blob
|
history
diff --git
a/src/cpp_tokiter.c
b/src/cpp_tokiter.c
index 51daaa9bb794a850e3ae215b152471a941255a62..2fa1763dceb05b1b5dec1a204b6656b1ee6ad532 100644
(file)
--- a/
src/cpp_tokiter.c
+++ b/
src/cpp_tokiter.c
@@
-233,7
+233,8
@@
bool psi_cpp_tokiter_defined(struct psi_cpp *cpp)
return false;
}
return false;
}
-void psi_cpp_tokiter_expand_tokens(struct psi_cpp *cpp, struct psi_plist *tokens)
+void psi_cpp_tokiter_expand_tokens(struct psi_cpp *cpp, struct psi_token *target,
+ struct psi_plist *tokens)
{
if (tokens && psi_plist_count(tokens)) {
size_t i = 0, n = 0;
{
if (tokens && psi_plist_count(tokens)) {
size_t i = 0, n = 0;
@@
-255,17
+256,21
@@
void psi_cpp_tokiter_expand_tokens(struct psi_cpp *cpp, struct psi_plist *tokens
continue;
}
continue;
}
- if (paste && n > 0 && exp_tokens[n - 1] &&
- (new_tok = psi_token_cat(NULL, 2, exp_tokens[n - 1], tok))) {
- free(exp_tokens[n - 1]);
+ if (paste && n > 0 && exp_tokens[n - 1]) {
+ struct psi_token *old_tok = exp_tokens[n - 1];
+
+ new_tok = psi_token_init(old_tok->type, "", 0,
+ target->col, target->line, target->file);
+
+ new_tok = psi_token_cat(NULL, 2, new_tok, old_tok, tok);
+ free(old_tok);
+
exp_tokens[n - 1] = new_tok;
} else {
exp_tokens[n - 1] = new_tok;
} else {
- struct psi_token *cpy = psi_token_copy(tok);
+ new_tok = psi_token_init(stringify ? PSI_T_QUOTED_STRING : tok->type,
+ tok->text, tok->size, target->col, target->line, target->file);
- if (stringify) {
- cpy->type = PSI_T_QUOTED_STRING;
- }
- exp_tokens[n++] = cpy;
+ exp_tokens[n++] = new_tok;
}
#if PSI_CPP_DEBUG
}
#if PSI_CPP_DEBUG
@@
-374,7
+379,8
@@
fail:
}
static void psi_cpp_tokiter_expand_call_tokens(struct psi_cpp *cpp,
}
static void psi_cpp_tokiter_expand_call_tokens(struct psi_cpp *cpp,
- struct psi_cpp_macro_decl *macro, struct psi_plist **arg_tokens_list)
+ struct psi_token *target, struct psi_cpp_macro_decl *macro,
+ struct psi_plist **arg_tokens_list)
{
size_t i;
struct psi_token *tok;
{
size_t i;
struct psi_token *tok;
@@
-404,12
+410,12
@@
static void psi_cpp_tokiter_expand_call_tokens(struct psi_cpp *cpp,
}
}
}
}
- psi_cpp_tokiter_expand_tokens(cpp, tokens);
+ psi_cpp_tokiter_expand_tokens(cpp, t
arget, t
okens);
psi_plist_free(tokens);
}
static bool psi_cpp_tokiter_expand_call(struct psi_cpp *cpp,
psi_plist_free(tokens);
}
static bool psi_cpp_tokiter_expand_call(struct psi_cpp *cpp,
- struct psi_cpp_macro_decl *macro)
+ struct psi_
token *target, struct psi_
cpp_macro_decl *macro)
{
/* function-like macro
* #define FOO(a,b) a>b // macro->sig == {a, b}, macro->tokens = {a, >, b}
{
/* function-like macro
* #define FOO(a,b) a>b // macro->sig == {a, b}, macro->tokens = {a, >, b}
@@
-430,7
+436,7
@@
static bool psi_cpp_tokiter_expand_call(struct psi_cpp *cpp,
psi_cpp_tokiter_seek(cpp, start);
/* insert and expand macro tokens */
psi_cpp_tokiter_seek(cpp, start);
/* insert and expand macro tokens */
- psi_cpp_tokiter_expand_call_tokens(cpp, macro, arg_tokens_list);
+ psi_cpp_tokiter_expand_call_tokens(cpp,
target,
macro, arg_tokens_list);
psi_cpp_tokiter_free_call_tokens(arg_tokens_list, psi_plist_count(macro->sig), true);
/* back to where we took off */
psi_cpp_tokiter_free_call_tokens(arg_tokens_list, psi_plist_count(macro->sig), true);
/* back to where we took off */
@@
-455,20
+461,21
@@
bool psi_cpp_tokiter_expand(struct psi_cpp *cpp)
psi_token_dump(2, current);
#endif
if (macro->sig) {
psi_token_dump(2, current);
#endif
if (macro->sig) {
- return psi_cpp_tokiter_expand_call(cpp, macro);
+ return psi_cpp_tokiter_expand_call(cpp,
current,
macro);
} else {
size_t index = psi_cpp_tokiter_index(cpp);
/* delete current token from stream */
} else {
size_t index = psi_cpp_tokiter_index(cpp);
/* delete current token from stream */
- psi_cpp_tokiter_del_cur(cpp,
tru
e);
+ psi_cpp_tokiter_del_cur(cpp,
fals
e);
if (index != psi_cpp_tokiter_index(cpp)) {
/* might have been last token */
psi_cpp_tokiter_next(cpp);
}
/* replace with tokens from macro */
if (index != psi_cpp_tokiter_index(cpp)) {
/* might have been last token */
psi_cpp_tokiter_next(cpp);
}
/* replace with tokens from macro */
- psi_cpp_tokiter_expand_tokens(cpp, macro->tokens);
+ psi_cpp_tokiter_expand_tokens(cpp,
current,
macro->tokens);
+ free(current);
++cpp->expanded;
return true;
}
++cpp->expanded;
return true;
}