summaryrefslogtreecommitdiff
path: root/src/parser/parser_utils.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/parser/parser_utils.c')
-rw-r--r--src/parser/parser_utils.c32
1 files changed, 31 insertions, 1 deletions
diff --git a/src/parser/parser_utils.c b/src/parser/parser_utils.c
index 7733ef7..ba506a0 100644
--- a/src/parser/parser_utils.c
+++ b/src/parser/parser_utils.c
@@ -1554,7 +1554,7 @@ char *instantiate_function_template(ParserContext *ctx, const char *name, const
return mangled;
}
-char *process_fstring(ParserContext *ctx, const char *content)
+char *process_fstring(ParserContext *ctx, const char *content, char ***used_syms, int *count)
{
(void)ctx; // suppress unused parameter warning
char *gen = xmalloc(4096);
@@ -1621,6 +1621,36 @@ char *process_fstring(ParserContext *ctx, const char *content)
fmt = colon + 1;
}
+ // Analyze usage in expression
+ {
+ Lexer lex;
+ lexer_init(&lex, expr);
+ Token t;
+ while ((t = lexer_next(&lex)).type != TOK_EOF)
+ {
+ if (t.type == TOK_IDENT)
+ {
+ char *name = token_strdup(t);
+ Symbol *sym = find_symbol_entry(ctx, name);
+ if (sym)
+ {
+ sym->is_used = 1;
+ }
+
+ if (used_syms && count)
+ {
+ *used_syms = xrealloc(*used_syms, sizeof(char *) * (*count + 1));
+ (*used_syms)[*count] = name;
+ (*count)++;
+ }
+ else
+ {
+ free(name);
+ }
+ }
+ }
+ }
+
if (fmt)
{
strcat(gen, "sprintf(_t, \"%");