summaryrefslogtreecommitdiff
path: root/src/parser
diff options
context:
space:
mode:
Diffstat (limited to 'src/parser')
-rw-r--r--src/parser/parser.h5
-rw-r--r--src/parser/parser_expr.c4
-rw-r--r--src/parser/parser_stmt.c14
3 files changed, 15 insertions, 8 deletions
diff --git a/src/parser/parser.h b/src/parser/parser.h
index 8857641..e1d6bb9 100644
--- a/src/parser/parser.h
+++ b/src/parser/parser.h
@@ -272,7 +272,8 @@ struct ParserContext
// Type Validation
struct TypeUsage *pending_type_validations;
- int is_speculative; // Flag to suppress side effects during speculative parsing
+ int is_speculative; // Flag to suppress side effects during speculative parsing
+ int silent_warnings; // Suppress warnings (for example, during codegen interpolation)
};
typedef struct TypeUsage
@@ -433,7 +434,7 @@ ASTNode *parse_match(ParserContext *ctx, Lexer *l);
ASTNode *parse_return(ParserContext *ctx, Lexer *l);
char *process_printf_sugar(ParserContext *ctx, const char *content, int newline, const char *target,
- char ***used_syms, int *count);
+ char ***used_syms, int *count, int check_symbols);
ASTNode *parse_assert(ParserContext *ctx, Lexer *l);
ASTNode *parse_defer(ParserContext *ctx, Lexer *l);
ASTNode *parse_asm(ParserContext *ctx, Lexer *l);
diff --git a/src/parser/parser_expr.c b/src/parser/parser_expr.c
index 0951475..07f133e 100644
--- a/src/parser/parser_expr.c
+++ b/src/parser/parser_expr.c
@@ -3470,7 +3470,7 @@ ASTNode *parse_expr_prec(ParserContext *ctx, Lexer *l, Precedence min_prec)
}
// Reuse printf sugar to generate the prompt print
- char *print_code = process_printf_sugar(ctx, inner, 0, "stdout", NULL, NULL);
+ char *print_code = process_printf_sugar(ctx, inner, 0, "stdout", NULL, NULL, 1);
free(inner);
// Checks for (args...) suffix for SCAN mode
@@ -3638,7 +3638,7 @@ ASTNode *parse_expr_prec(ParserContext *ctx, Lexer *l, Precedence min_prec)
newline = 0;
}
- char *code = process_printf_sugar(ctx, inner, newline, "stderr", NULL, NULL);
+ char *code = process_printf_sugar(ctx, inner, newline, "stderr", NULL, NULL, 1);
free(inner);
ASTNode *n = ast_create(NODE_RAW_STMT);
diff --git a/src/parser/parser_stmt.c b/src/parser/parser_stmt.c
index 1b3a5d9..4b09c83 100644
--- a/src/parser/parser_stmt.c
+++ b/src/parser/parser_stmt.c
@@ -1345,8 +1345,10 @@ ASTNode *parse_for(ParserContext *ctx, Lexer *l)
}
char *process_printf_sugar(ParserContext *ctx, const char *content, int newline, const char *target,
- char ***used_syms, int *count)
+ char ***used_syms, int *count, int check_symbols)
{
+ int saved_silent = ctx->silent_warnings;
+ ctx->silent_warnings = !check_symbols;
char *gen = xmalloc(8192);
strcpy(gen, "({ ");
@@ -1447,7 +1449,7 @@ char *process_printf_sugar(ParserContext *ctx, const char *content, int newline,
// Analyze usage & Type Check for to_string()
char *final_expr = xstrdup(clean_expr);
- // Use final_expr in usage analysis if needed, but mainly for symbol tracking
+ if (check_symbols)
{
Lexer lex;
lexer_init(&lex, clean_expr); // Scan original for symbols
@@ -1483,6 +1485,7 @@ char *process_printf_sugar(ParserContext *ctx, const char *content, int newline,
// Parse expression fully
Lexer lex;
lexer_init(&lex, clean_expr);
+
ASTNode *expr_node = parse_expression(ctx, &lex);
char *rw_expr = NULL;
@@ -1696,6 +1699,7 @@ char *process_printf_sugar(ParserContext *ctx, const char *content, int newline,
strcat(gen, "0; })");
free(s);
+ ctx->silent_warnings = saved_silent;
return gen;
}
@@ -1871,7 +1875,8 @@ ASTNode *parse_statement(ParserContext *ctx, Lexer *l)
int is_ln = (next_type == TOK_SEMICOLON);
char **used_syms = NULL;
int used_count = 0;
- char *code = process_printf_sugar(ctx, inner, is_ln, "stdout", &used_syms, &used_count);
+ char *code =
+ process_printf_sugar(ctx, inner, is_ln, "stdout", &used_syms, &used_count, 1);
if (next_type == TOK_SEMICOLON)
{
@@ -2428,7 +2433,8 @@ ASTNode *parse_statement(ParserContext *ctx, Lexer *l)
char **used_syms = NULL;
int used_count = 0;
- char *code = process_printf_sugar(ctx, inner, is_ln, target, &used_syms, &used_count);
+ char *code =
+ process_printf_sugar(ctx, inner, is_ln, target, &used_syms, &used_count, 1);
free(inner);
if (lexer_peek(l).type == TOK_SEMICOLON)