aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorLuc Van Oostenryck <luc.vanoostenryck@gmail.com>2020-05-17 23:21:33 +0200
committerLuc Van Oostenryck <luc.vanoostenryck@gmail.com>2020-05-17 23:23:01 +0200
commitd3a25d90664d833e9657689d920ee05bdba30f7f (patch)
tree974856091dfab9fecb2ad623305dc9f1c1686f4c
parent98fa204a2da0fb34320544a90e886466a102ac4a (diff)
downloadsparse-d3a25d90664d833e9657689d920ee05bdba30f7f.tar.gz
attribute: add helper apply_mod() and use it
to avoid duplicated code checking for ... duplicated modifiers! Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
-rw-r--r--parse.c16
1 files changed, 9 insertions, 7 deletions
diff --git a/parse.c b/parse.c
index a29c67c8..974ff7a1 100644
--- a/parse.c
+++ b/parse.c
@@ -1127,11 +1127,16 @@ static struct token *attribute_aligned(struct token *token, struct symbol *attr,
return token;
}
+static void apply_mod(struct position *pos, unsigned long *mods, unsigned long mod)
+{
+ if (*mods & mod)
+ warning(*pos, "duplicate %s", modifier_string(mod));
+ *mods |= mod;
+}
+
static void apply_qualifier(struct position *pos, struct ctype *ctx, unsigned long qual)
{
- if (ctx->modifiers & qual)
- warning(*pos, "duplicate %s", modifier_string(qual));
- ctx->modifiers |= qual;
+ apply_mod(pos, &ctx->modifiers, qual);
}
static struct token *attribute_modifier(struct token *token, struct symbol *attr, struct decl_state *ctx)
@@ -1142,10 +1147,7 @@ static struct token *attribute_modifier(struct token *token, struct symbol *attr
static struct token *attribute_function(struct token *token, struct symbol *attr, struct decl_state *ctx)
{
- unsigned long mod = attr->ctype.modifiers;
- if (ctx->f_modifiers & mod)
- warning(token->pos, "duplicate %s", modifier_string(mod));
- ctx->f_modifiers |= mod;
+ apply_mod(&token->pos, &ctx->f_modifiers, attr->ctype.modifiers);
return token;
}