aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/parse.c
diff options
authorLuc Van Oostenryck <luc.vanoostenryck@gmail.com>2017-07-14 20:40:13 +0200
committerLuc Van Oostenryck <luc.vanoostenryck@gmail.com>2017-09-17 09:47:14 +0200
commit6756731e9d22c831bc7ec2e96b1942d13d54ab84 (patch)
treedf04a88de4c31a6cfbcda3e803b447c57fd23b71 /parse.c
parent90859bb4e3f9ad11f76ad42e3dce84043bdc3176 (diff)
downloadsparse-dev-6756731e9d22c831bc7ec2e96b1942d13d54ab84.tar.gz
use a specific struct for asm operands
ASM operands have the following syntax: [<ident>] "<constraint>" '(' <expr> ')' For some reasons, during parsing this is stored as a sequence of 3 expressions. This has some serious disadvantages though: - <ident> has not the type of an expression - it complicates processing when compared to having a specific struct for it (need to loop & maintain some state). - <ident> is optional and stored as a null pointer when not present which is annoying, for example, if null pointers are used internally in ptr-lists to mark removed pointers. Fix this by using a specific structure to store the 3 elements of ASM operands. Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
Diffstat (limited to 'parse.c')
-rw-r--r--parse.c14
1 files changed, 5 insertions, 9 deletions
diff --git a/parse.c b/parse.c
index 02a55a74..8407eb85 100644
--- a/parse.c
+++ b/parse.c
@@ -1929,24 +1929,20 @@ static struct token *expression_statement(struct token *token, struct expression
static struct token *parse_asm_operands(struct token *token, struct statement *stmt,
struct expression_list **inout)
{
- struct expression *expr;
-
/* Allow empty operands */
if (match_op(token->next, ':') || match_op(token->next, ')'))
return token->next;
do {
- struct ident *ident = NULL;
+ struct expression *op = alloc_expression(token->pos, EXPR_ASM_OPERAND);
if (match_op(token->next, '[') &&
token_type(token->next->next) == TOKEN_IDENT &&
match_op(token->next->next->next, ']')) {
- ident = token->next->next->ident;
+ op->name = token->next->next->ident;
token = token->next->next->next;
}
- add_expression(inout, (struct expression *)ident); /* UGGLEE!!! */
- token = primary_expression(token->next, &expr);
- add_expression(inout, expr);
- token = parens_expression(token, &expr, "in asm parameter");
- add_expression(inout, expr);
+ token = primary_expression(token->next, &op->constraint);
+ token = parens_expression(token, &op->expr, "in asm parameter");
+ add_expression(inout, op);
} while (match_op(token, ','));
return token;
}