2 * sparse/smatch_recurse.c
4 * Copyright (C) 2013 Oracle.
6 * Licensed under the Open Software License version 1.1
12 #define RECURSE_LIMIT 10
14 static int recurse(struct expression
*expr
,
15 int (func
)(struct expression
*expr
, void *p
),
23 ret
= func(expr
, param
);
27 if (nr
> RECURSE_LIMIT
)
33 ret
= recurse(expr
->unop
, func
, param
, nr
);
36 ret
= recurse(expr
->unop
, func
, param
, nr
);
45 ret
= recurse(expr
->left
, func
, param
, nr
);
48 ret
= recurse(expr
->right
, func
, param
, nr
);
51 ret
= recurse(expr
->right
, func
, param
, nr
);
54 ret
= recurse(expr
->left
, func
, param
, nr
);
57 ret
= recurse(expr
->deref
, func
, param
, nr
);
60 ret
= recurse(expr
->base
, func
, param
, nr
);
64 ret
= recurse(expr
->cast_expression
, func
, param
, nr
);
70 case EXPR_CONDITIONAL
:
72 ret
= recurse(expr
->conditional
, func
, param
, nr
);
75 ret
= recurse(expr
->cond_true
, func
, param
, nr
);
78 ret
= recurse(expr
->cond_false
, func
, param
, nr
);
83 case EXPR_INITIALIZER
:
87 ret
= recurse(expr
->ident_expression
, func
, param
, nr
);
90 ret
= recurse(expr
->idx_expression
, func
, param
, nr
);
93 ret
= recurse(expr
->init_expr
, func
, param
, nr
);
106 static int has_symbol_helper(struct expression
*expr
, void *_sym
)
108 struct symbol
*sym
= _sym
;
110 if (!expr
|| expr
->type
!= EXPR_SYMBOL
)
112 if (expr
->symbol
== sym
)
117 int has_symbol(struct expression
*expr
, struct symbol
*sym
)
119 return recurse(expr
, has_symbol_helper
, sym
, 0);
122 int has_variable(struct expression
*expr
, struct expression
*var
)
127 name
= expr_to_var_sym(var
, &sym
);
131 return has_symbol(expr
, sym
);