aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/parse.c
diff options
authorLuc Van Oostenryck <luc.vanoostenryck@gmail.com>2018-05-24 02:01:21 +0200
committerLuc Van Oostenryck <luc.vanoostenryck@gmail.com>2018-05-26 17:04:29 +0200
commit63369a98d8ee0c72d28122539e4e542e62308ad2 (patch)
tree53fd0641ac26a7e8bcf3a91c1f11904f2b542b1c /parse.c
parentbf28f6e2b80f81dd5ebd6431209712e0287f0587 (diff)
downloadsparse-dev-63369a98d8ee0c72d28122539e4e542e62308ad2.tar.gz
context: stricter syntax for __context__ statement
The expected syntax for the __context__ statement is: __context__(<expression>); or __context__(<context>, <expression>); but originally it was just: __context__ <expression> In other words the parenthesis were not needed and are still not needed when no context is given. One problem with the current way to parse these statements is that very few validation is done. For example, code like: __context__; is silently accepted, as is: __context__ a, b; which is of course not the same as: __context__(a,b); And code like: __context__(,1); results in a confusing error message: error: an expression is expected before ')' error: Expected ) in expression error: got , So, given that: * the kernel has always used the syntax with parenthesis, * the two arguments form requires the parenthesis and thus a function-like syntax use a more direct, robust and simpl parsing which enforce the function-like syntax for both forms. Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
Diffstat (limited to 'parse.c')
-rw-r--r--parse.c18
1 files changed, 8 insertions, 10 deletions
diff --git a/parse.c b/parse.c
index 42b3fd20..cdf034de 100644
--- a/parse.c
+++ b/parse.c
@@ -2338,17 +2338,15 @@ static struct token *parse_goto_statement(struct token *token, struct statement
static struct token *parse_context_statement(struct token *token, struct statement *stmt)
{
stmt->type = STMT_CONTEXT;
- token = parse_expression(token->next, &stmt->expression);
- if (stmt->expression
- && stmt->expression->type == EXPR_PREOP
- && stmt->expression->op == '('
- && stmt->expression->unop
- && stmt->expression->unop->type == EXPR_COMMA) {
- struct expression *expr;
- expr = stmt->expression->unop;
- stmt->context = expr->left;
- stmt->expression = expr->right;
+ token = token->next;
+ token = expect(token, '(', "after __context__ statement");
+ token = assignment_expression(token, &stmt->expression);
+ if (match_op(token, ',')) {
+ token = token->next;
+ stmt->context = stmt->expression;
+ token = assignment_expression(token, &stmt->expression);
}
+ token = expect(token, ')', "at end of __context__ statement");
return expect(token, ';', "at end of statement");
}