4 * Copyright (C) 2009 Dan Carpenter.
6 * Licensed under the Open Software License version 1.1
11 #include "smatch_slist.h" // blast this was supposed to be internal only stuff
15 static void match_all_values(const char *fn
, struct expression
*expr
, void *info
)
17 struct state_list
*slist
;
19 slist
= get_all_states(SMATCH_EXTRA
);
24 static void match_cur_slist(const char *fn
, struct expression
*expr
, void *info
)
29 static void match_print_value(const char *fn
, struct expression
*expr
, void *info
)
31 struct state_list
*slist
;
33 struct expression
*arg_expr
;
35 arg_expr
= get_argument_from_call_expr(expr
->args
, 0);
36 if (arg_expr
->type
!= EXPR_STRING
) {
37 sm_msg("error: the argument to %s is supposed to be a string literal", fn
);
41 slist
= get_all_states(SMATCH_EXTRA
);
42 FOR_EACH_PTR(slist
, tmp
) {
43 if (!strcmp(tmp
->name
, arg_expr
->string
->data
))
44 sm_msg("%s = %s", tmp
->name
, tmp
->state
->name
);
45 } END_FOR_EACH_PTR(tmp
);
49 static void match_print_implied_min(const char *fn
, struct expression
*expr
, void *info
)
51 struct expression
*arg
;
55 arg
= get_argument_from_call_expr(expr
->args
, 0);
56 name
= get_variable_from_expr_complex(arg
, NULL
);
57 if (!get_implied_min(arg
, &val
))
58 val
= whole_range
.min
;
59 sm_msg("implied min: %s = %lld", name
, val
);
62 static void match_print_implied_max(const char *fn
, struct expression
*expr
, void *info
)
64 struct expression
*arg
;
68 arg
= get_argument_from_call_expr(expr
->args
, 0);
69 name
= get_variable_from_expr_complex(arg
, NULL
);
70 if (!get_implied_max(arg
, &val
))
71 val
= whole_range
.max
;
72 sm_msg("implied max: %s = %lld", name
, val
);
75 static void print_possible(struct sm_state
*sm
)
79 sm_msg("Possible values for %s", sm
->name
);
80 FOR_EACH_PTR(sm
->possible
, tmp
) {
81 printf("%s\n", tmp
->state
->name
);
82 } END_FOR_EACH_PTR(tmp
);
86 static void match_possible(const char *fn
, struct expression
*expr
, void *info
)
88 struct state_list
*slist
;
90 struct expression
*arg_expr
;
92 arg_expr
= get_argument_from_call_expr(expr
->args
, 0);
93 if (arg_expr
->type
!= EXPR_STRING
) {
94 sm_msg("error: the argument to %s is supposed to be a string literal", fn
);
98 slist
= get_all_states(SMATCH_EXTRA
);
99 FOR_EACH_PTR(slist
, tmp
) {
100 if (!strcmp(tmp
->name
, arg_expr
->string
->data
))
102 } END_FOR_EACH_PTR(tmp
);
106 static void match_note(const char *fn
, struct expression
*expr
, void *info
)
108 struct expression
*arg_expr
;
110 arg_expr
= get_argument_from_call_expr(expr
->args
, 0);
111 if (arg_expr
->type
!= EXPR_STRING
) {
112 sm_msg("error: the argument to %s is supposed to be a string literal", fn
);
115 sm_msg("%s", arg_expr
->string
->data
);
118 static void match_debug_on(const char *fn
, struct expression
*expr
, void *info
)
123 static void match_debug_off(const char *fn
, struct expression
*expr
, void *info
)
127 void check_debug(int id
)
130 add_function_hook("__smatch_all_values", &match_all_values
, NULL
);
131 add_function_hook("__smatch_value", &match_print_value
, NULL
);
132 add_function_hook("__smatch_implied_min", &match_print_implied_min
, NULL
);
133 add_function_hook("__smatch_implied_max", &match_print_implied_max
, NULL
);
134 add_function_hook("__smatch_possible", &match_possible
, NULL
);
135 add_function_hook("__smatch_cur_slist", &match_cur_slist
, NULL
);
136 add_function_hook("__smatch_note", &match_note
, NULL
);
137 add_function_hook("__smatch_debug_on", &match_debug_on
, NULL
);
138 add_function_hook("__smatch_debug_off", &match_debug_off
, NULL
);