MCPcopy Create free account
hub / github.com/csmith-project/csmith / count_expr_key_var

Function count_expr_key_var

src/ArrayVariable.cpp:67–94  ·  view source on GitHub ↗

* count the "key" variable of an binary/unary operation. * return 0 for constants, 2 for function calls */

Source from the content-addressed store, hash-verified

65 * return 0 for constants, 2 for function calls
66 */
67static int count_expr_key_var(const Expression* e)
68{
69 if (e->term_type == eVariable) {
70 return 1;
71 }
72 else if (e->term_type == eConstant) {
73 return 0;
74 }
75 else if (e->term_type == eFunction) {
76 const ExpressionFuncall* ef = dynamic_cast<const ExpressionFuncall*>(e);
77 assert(ef);
78 const FunctionInvocation* fi = ef->get_invoke();
79 // for calls
80 if (fi->invoke_type == eFuncCall) {
81 return 2;
82 }
83 // for unary operations
84 if (fi->param_value.size()==1) {
85 return count_expr_key_var(fi->param_value[0]);
86 }
87 // for binary operations
88 assert(fi->param_value.size() == 2);
89 return count_expr_key_var(fi->param_value[0]) + count_expr_key_var(fi->param_value[1]);
90 }
91 // shouldn't be here
92 assert(0);
93 return 0;
94}
95
96/*
97 * find the "key" variable of an expression.

Callers 1

is_variantMethod · 0.85

Calls 2

sizeMethod · 0.80
get_invokeMethod · 0.45

Tested by

no test coverage detected