2 * Copyright (C) 2014 Oracle.
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; either version 2
7 * of the License, or (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, see http://www.gnu.org/copyleft/gpl.txt
19 #include "smatch_slist.h"
23 static int *auto_copy
;
25 void set_auto_copy(int owner
)
27 if (owner
<= 1 || owner
> num_checks
) {
28 printf("bogus set_auto_copy()\n");
34 static void match_assign(struct expression
*expr
)
36 char *left_name
= NULL
;
37 char *right_name
= NULL
;
38 struct symbol
*left_sym
, *right_sym
;
39 struct state_list
*slist
= NULL
;
42 left_name
= expr_to_var_sym(expr
->left
, &left_sym
);
43 if (!left_name
|| !left_sym
)
45 right_name
= expr_to_var_sym(expr
->right
, &right_sym
);
46 if (!right_name
|| !right_sym
)
49 FOR_EACH_SM(__get_cur_stree(), sm
) {
50 if (sm
->owner
<= 1 || sm
->owner
> num_checks
)
52 if (!auto_copy
[sm
->owner
])
54 if (right_sym
!= sm
->sym
)
56 if (strcmp(right_name
, sm
->name
) != 0)
58 add_ptr_list(&slist
, sm
);
59 } END_FOR_EACH_SM(sm
);
62 FOR_EACH_PTR(slist
, sm
) {
63 set_state(sm
->owner
, left_name
, left_sym
, sm
->state
);
64 } END_FOR_EACH_PTR(sm
);
68 free_string(left_name
);
69 free_string(right_name
);
72 void register_auto_copy(int id
)
75 auto_copy
= malloc((num_checks
+ 1) * sizeof(*auto_copy
));
76 memset(auto_copy
, 0, (num_checks
+ 1) * sizeof(*auto_copy
));
78 add_hook(&match_assign
, ASSIGNMENT_HOOK
);