This will help to detect earlier syntax errors concerning string constants. Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@xxxxxxxxx> --- expression.c | 11 +++++++++++ expression.h | 1 + 2 files changed, 12 insertions(+) diff --git a/expression.c b/expression.c index f955fb159..ffb6cb9dc 100644 --- a/expression.c +++ b/expression.c @@ -83,6 +83,17 @@ struct token *parens_expression(struct token *token, struct expression **expr, c return expect(token, ')', where); } +struct token *string_expression(struct token *token, struct expression **expr, const char *where) +{ + struct token *next = primary_expression(token, expr); + + if (!*expr || (*expr)->type != EXPR_STRING) { + sparse_error(token->pos, "string literal expected for %s", where); + *expr = NULL; + } + return next; +} + /* * Handle __func__, __FUNCTION__ and __PRETTY_FUNCTION__ token * conversion diff --git a/expression.h b/expression.h index ed6f4d65d..13f35e64b 100644 --- a/expression.h +++ b/expression.h @@ -270,6 +270,7 @@ struct token *parse_expression(struct token *token, struct expression **tree); struct token *conditional_expression(struct token *token, struct expression **tree); struct token *primary_expression(struct token *token, struct expression **tree); struct token *parens_expression(struct token *token, struct expression **expr, const char *where); +struct token *string_expression(struct token *token, struct expression **expr, const char *where); struct token *assignment_expression(struct token *token, struct expression **tree); extern int expand_symbol(struct symbol *); -- 2.20.0