diff options
| author | Luc Van Oostenryck <luc.vanoostenryck@gmail.com> | 2019-01-26 00:48:48 +0100 |
|---|---|---|
| committer | Luc Van Oostenryck <luc.vanoostenryck@gmail.com> | 2019-09-26 18:11:16 +0200 |
| commit | ddebbc1dff5701d2c97562de0f91e51cd5544382 (patch) | |
| tree | dcc8c10192f21e2b8c856bb1a08827de6f339fc1 /expression.c | |
| parent | e6d4cd7933a006aa71e8aa265e3c2c40ca9030d3 (diff) | |
| download | sparse-dev-ddebbc1dff5701d2c97562de0f91e51cd5544382.tar.gz | |
string: add helper string_expression()
This will help to detect earlier syntax errors concerning
string constants.
Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
Diffstat (limited to 'expression.c')
| -rw-r--r-- | expression.c | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/expression.c b/expression.c index f955fb15..ffb6cb9d 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 |
