2 * Copyright (C) 2006 Dan Carpenter.
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 * You have a lists of states. kernel = locked, foo = NULL, ...
20 * When you hit an if {} else {} statement then you swap the list
21 * of states for a different list of states. The lists are stored
24 * At the beginning of this file there are list of the stacks that
25 * we use. Each function in this file does something to one of
28 * So the smatch_flow.c understands code but it doesn't understand states.
29 * smatch_flow calls functions in this file. This file calls functions
30 * in smatch_slist.c which just has boring generic plumbing for handling
31 * state lists. But really it's this file where all the magic happens.
37 #include "smatch_slist.h"
38 #include "smatch_extra.h"
40 struct smatch_state undefined
= { .name
= "undefined" };
41 struct smatch_state ghost
= { .name
= "ghost" };
42 struct smatch_state merged
= { .name
= "merged" };
43 struct smatch_state true_state
= { .name
= "true" };
44 struct smatch_state false_state
= { .name
= "false" };
46 static struct stree
*cur_stree
; /* current states */
48 static struct stree_stack
*true_stack
; /* states after a t/f branch */
49 static struct stree_stack
*false_stack
;
50 static struct stree_stack
*pre_cond_stack
; /* states before a t/f branch */
52 static struct stree_stack
*cond_true_stack
; /* states affected by a branch */
53 static struct stree_stack
*cond_false_stack
;
55 static struct stree_stack
*fake_cur_stree_stack
;
58 static struct stree_stack
*break_stack
;
59 static struct stree_stack
*fake_break_stack
;
60 static struct stree_stack
*switch_stack
;
61 static struct range_list_stack
*remaining_cases
;
62 static struct stree_stack
*default_stack
;
63 static struct stree_stack
*continue_stack
;
65 static struct named_stree_stack
*goto_stack
;
67 static struct ptr_list
*backup
;
71 void __print_cur_stree(void)
73 __print_stree(cur_stree
);
83 struct sm_state
*set_state(int owner
, const char *name
, struct symbol
*sym
, struct smatch_state
*state
)
91 sm_msg("Smatch Internal Error: cur_stree is read only.");
93 if (option_debug
|| strcmp(check_name(owner
), option_debug_check
) == 0) {
94 struct smatch_state
*s
;
96 s
= get_state(owner
, name
, sym
);
98 sm_msg("%s new [%s] '%s' %s", __func__
,
99 check_name(owner
), name
, show_state(state
));
101 sm_msg("%s change [%s] '%s' %s => %s",
102 __func__
, check_name(owner
), name
, show_state(s
),
106 if (owner
!= -1 && unreachable())
109 if (fake_cur_stree_stack
)
110 set_state_stree_stack(&fake_cur_stree_stack
, owner
, name
, sym
, state
);
112 ret
= set_state_stree(&cur_stree
, owner
, name
, sym
, state
);
117 struct sm_state
*set_state_expr(int owner
, struct expression
*expr
, struct smatch_state
*state
)
121 struct sm_state
*ret
= NULL
;
123 expr
= strip_expr(expr
);
124 name
= expr_to_var_sym(expr
, &sym
);
127 ret
= set_state(owner
, name
, sym
, state
);
133 void __swap_cur_stree(struct stree
*stree
)
135 free_stree(&cur_stree
);
139 void __push_fake_cur_stree(void)
141 push_stree(&fake_cur_stree_stack
, NULL
);
142 __save_pre_cond_states();
145 struct stree
*__pop_fake_cur_stree(void)
147 if (!fake_cur_stree_stack
)
148 sm_msg("INTERNAL error: popping too many fake cur strees.");
149 __use_pre_cond_states();
150 return pop_stree(&fake_cur_stree_stack
);
153 void __free_fake_cur_stree(void)
157 stree
= __pop_fake_cur_stree();
161 void __set_fake_cur_stree_fast(struct stree
*stree
)
163 push_stree(&pre_cond_stack
, cur_stree
);
168 void __pop_fake_cur_stree_fast(void)
170 cur_stree
= pop_stree(&pre_cond_stack
);
174 void __merge_stree_into_cur(struct stree
*stree
)
177 struct sm_state
*orig
;
178 struct sm_state
*merged
;
180 FOR_EACH_SM(stree
, sm
) {
181 orig
= get_sm_state(sm
->owner
, sm
->name
, sm
->sym
);
183 merged
= merge_sm_states(orig
, sm
);
187 } END_FOR_EACH_SM(sm
);
190 void __set_sm(struct sm_state
*sm
)
193 sm_msg("Smatch Internal Error: cur_stree is read only.");
196 strcmp(check_name(sm
->owner
), option_debug_check
) == 0) {
197 struct smatch_state
*s
;
199 s
= get_state(sm
->owner
, sm
->name
, sm
->sym
);
201 sm_msg("%s new %s", __func__
, show_sm(sm
));
203 sm_msg("%s change %s (was %s)", __func__
, show_sm(sm
),
210 if (fake_cur_stree_stack
)
211 overwrite_sm_state_stree_stack(&fake_cur_stree_stack
, sm
);
213 overwrite_sm_state_stree(&cur_stree
, sm
);
216 void __set_sm_cur_stree(struct sm_state
*sm
)
219 sm_msg("Smatch Internal Error: cur_stree is read only.");
222 strcmp(check_name(sm
->owner
), option_debug_check
) == 0) {
223 struct smatch_state
*s
;
225 s
= get_state(sm
->owner
, sm
->name
, sm
->sym
);
227 sm_msg("%s new %s", __func__
, show_sm(sm
));
229 sm_msg("%s change %s (was %s)",
230 __func__
, show_sm(sm
), show_state(s
));
236 overwrite_sm_state_stree(&cur_stree
, sm
);
239 void __set_sm_fake_stree(struct sm_state
*sm
)
242 sm_msg("Smatch Internal Error: cur_stree is read only.");
245 strcmp(check_name(sm
->owner
), option_debug_check
) == 0) {
246 struct smatch_state
*s
;
248 s
= get_state(sm
->owner
, sm
->name
, sm
->sym
);
250 sm_msg("%s new %s", __func__
, show_sm(sm
));
252 sm_msg("%s change %s (was %s)",
253 __func__
, show_sm(sm
), show_state(s
));
259 overwrite_sm_state_stree_stack(&fake_cur_stree_stack
, sm
);
262 struct smatch_state
*get_state(int owner
, const char *name
, struct symbol
*sym
)
264 __get_state_hook(owner
, name
, sym
);
266 return get_state_stree(cur_stree
, owner
, name
, sym
);
269 struct smatch_state
*get_state_expr(int owner
, struct expression
*expr
)
273 struct smatch_state
*ret
= NULL
;
275 expr
= strip_expr(expr
);
276 name
= expr_to_var_sym(expr
, &sym
);
279 ret
= get_state(owner
, name
, sym
);
285 struct state_list
*get_possible_states(int owner
, const char *name
, struct symbol
*sym
)
287 struct sm_state
*sms
;
289 sms
= get_sm_state_stree(cur_stree
, owner
, name
, sym
);
291 return sms
->possible
;
295 struct state_list
*get_possible_states_expr(int owner
, struct expression
*expr
)
299 struct state_list
*ret
= NULL
;
301 expr
= strip_expr(expr
);
302 name
= expr_to_var_sym(expr
, &sym
);
305 ret
= get_possible_states(owner
, name
, sym
);
311 struct sm_state
*get_sm_state(int owner
, const char *name
, struct symbol
*sym
)
313 return get_sm_state_stree(cur_stree
, owner
, name
, sym
);
316 struct sm_state
*get_sm_state_expr(int owner
, struct expression
*expr
)
320 struct sm_state
*ret
= NULL
;
322 expr
= strip_expr(expr
);
323 name
= expr_to_var_sym(expr
, &sym
);
326 ret
= get_sm_state(owner
, name
, sym
);
332 void delete_state(int owner
, const char *name
, struct symbol
*sym
)
334 delete_state_stree(&cur_stree
, owner
, name
, sym
);
335 if (cond_true_stack
) {
336 delete_state_stree_stack(&pre_cond_stack
, owner
, name
, sym
);
337 delete_state_stree_stack(&cond_true_stack
, owner
, name
, sym
);
338 delete_state_stree_stack(&cond_false_stack
, owner
, name
, sym
);
342 void delete_state_expr(int owner
, struct expression
*expr
)
347 expr
= strip_expr(expr
);
348 name
= expr_to_var_sym(expr
, &sym
);
351 delete_state(owner
, name
, sym
);
356 static void delete_all_states_stree_sym(struct stree
**stree
, struct symbol
*sym
)
358 struct state_list
*slist
= NULL
;
361 FOR_EACH_SM(*stree
, sm
) {
363 add_ptr_list(&slist
, sm
);
364 } END_FOR_EACH_SM(sm
);
366 FOR_EACH_PTR(slist
, sm
) {
367 delete_state_stree(stree
, sm
->owner
, sm
->name
, sm
->sym
);
368 } END_FOR_EACH_PTR(sm
);
373 static void delete_all_states_stree_stack_sym(struct stree_stack
**stack
, struct symbol
*sym
)
380 stree
= pop_stree(stack
);
381 delete_all_states_stree_sym(&stree
, sym
);
382 push_stree(stack
, stree
);
385 void __delete_all_states_sym(struct symbol
*sym
)
387 delete_all_states_stree_sym(&cur_stree
, sym
);
389 delete_all_states_stree_stack_sym(&true_stack
, sym
);
390 delete_all_states_stree_stack_sym(&true_stack
, sym
);
391 delete_all_states_stree_stack_sym(&false_stack
, sym
);
392 delete_all_states_stree_stack_sym(&pre_cond_stack
, sym
);
393 delete_all_states_stree_stack_sym(&cond_true_stack
, sym
);
394 delete_all_states_stree_stack_sym(&cond_false_stack
, sym
);
395 delete_all_states_stree_stack_sym(&fake_cur_stree_stack
, sym
);
396 delete_all_states_stree_stack_sym(&break_stack
, sym
);
397 delete_all_states_stree_stack_sym(&fake_break_stack
, sym
);
398 delete_all_states_stree_stack_sym(&switch_stack
, sym
);
399 delete_all_states_stree_stack_sym(&continue_stack
, sym
);
402 * deleting from the goto stack is problematic because we don't know
403 * if the label is in scope and also we need the value for --two-passes.
407 struct stree
*get_all_states_from_stree(int owner
, struct stree
*source
)
409 struct stree
*ret
= NULL
;
410 struct sm_state
*tmp
;
412 FOR_EACH_SM(source
, tmp
) {
413 if (tmp
->owner
== owner
)
414 avl_insert(&ret
, tmp
);
415 } END_FOR_EACH_SM(tmp
);
420 struct stree
*get_all_states_stree(int owner
)
422 return get_all_states_from_stree(owner
, cur_stree
);
425 struct stree
*__get_cur_stree(void)
430 int is_reachable(void)
437 void set_true_false_states(int owner
, const char *name
, struct symbol
*sym
,
438 struct smatch_state
*true_state
,
439 struct smatch_state
*false_state
)
442 sm_msg("Smatch Internal Error: cur_stree is read only.");
444 if (option_debug
|| strcmp(check_name(owner
), option_debug_check
) == 0) {
445 struct smatch_state
*tmp
;
447 tmp
= get_state(owner
, name
, sym
);
448 sm_msg("%s [%s] '%s'. Was %s. Now T:%s F:%s", __func__
,
449 check_name(owner
), name
, show_state(tmp
),
450 show_state(true_state
), show_state(false_state
));
456 if (!cond_false_stack
|| !cond_true_stack
) {
457 printf("Error: missing true/false stacks\n");
462 set_state_stree_stack(&cond_true_stack
, owner
, name
, sym
, true_state
);
464 set_state_stree_stack(&cond_false_stack
, owner
, name
, sym
, false_state
);
467 void set_true_false_states_expr(int owner
, struct expression
*expr
,
468 struct smatch_state
*true_state
,
469 struct smatch_state
*false_state
)
474 expr
= strip_expr(expr
);
475 name
= expr_to_var_sym(expr
, &sym
);
478 set_true_false_states(owner
, name
, sym
, true_state
, false_state
);
483 void __set_true_false_sm(struct sm_state
*true_sm
, struct sm_state
*false_sm
)
489 if (!true_sm
&& !false_sm
)
495 owner
= true_sm
? true_sm
->owner
: false_sm
->owner
;
496 name
= true_sm
? true_sm
->name
: false_sm
->name
;
497 sym
= true_sm
? true_sm
->sym
: false_sm
->sym
;
498 if (option_debug
|| strcmp(check_name(owner
), option_debug_check
) == 0) {
499 struct smatch_state
*tmp
;
501 tmp
= get_state(owner
, name
, sym
);
502 sm_msg("%s [%s] '%s'. Was %s. Now T:%s F:%s", __func__
,
503 check_name(owner
), name
, show_state(tmp
),
504 show_state(true_sm
? true_sm
->state
: NULL
),
505 show_state(false_sm
? false_sm
->state
: NULL
));
508 if (!cond_false_stack
|| !cond_true_stack
) {
509 printf("Error: missing true/false stacks\n");
514 overwrite_sm_state_stree_stack(&cond_true_stack
, true_sm
);
516 overwrite_sm_state_stree_stack(&cond_false_stack
, false_sm
);
519 void nullify_path(void)
521 if (fake_cur_stree_stack
) {
522 __free_fake_cur_stree();
523 __push_fake_cur_stree();
525 free_stree(&cur_stree
);
528 void __match_nullify_path_hook(const char *fn
, struct expression
*expr
,
535 * At the start of every function we mark the path
536 * as unnull. That way there is always at least one state
537 * in the cur_stree until nullify_path is called. This
538 * is used in merge_slist() for the first null check.
540 void __unnullify_path(void)
543 set_state(-1, "unnull_path", NULL
, &true_state
);
546 int __path_is_null(void)
553 static void check_stree_stack_free(struct stree_stack
**stack
)
556 sm_msg("smatch internal error: stack not empty");
557 free_stack_and_strees(stack
);
561 void save_all_states(void)
563 __add_ptr_list(&backup
, cur_stree
, 0);
566 __add_ptr_list(&backup
, true_stack
, 0);
568 __add_ptr_list(&backup
, false_stack
, 0);
570 __add_ptr_list(&backup
, pre_cond_stack
, 0);
571 pre_cond_stack
= NULL
;
573 __add_ptr_list(&backup
, cond_true_stack
, 0);
574 cond_true_stack
= NULL
;
575 __add_ptr_list(&backup
, cond_false_stack
, 0);
576 cond_false_stack
= NULL
;
578 __add_ptr_list(&backup
, fake_cur_stree_stack
, 0);
579 fake_cur_stree_stack
= NULL
;
581 __add_ptr_list(&backup
, break_stack
, 0);
583 __add_ptr_list(&backup
, fake_break_stack
, 0);
584 fake_break_stack
= NULL
;
586 __add_ptr_list(&backup
, switch_stack
, 0);
588 __add_ptr_list(&backup
, remaining_cases
, 0);
589 remaining_cases
= NULL
;
590 __add_ptr_list(&backup
, default_stack
, 0);
591 default_stack
= NULL
;
592 __add_ptr_list(&backup
, continue_stack
, 0);
593 continue_stack
= NULL
;
595 __add_ptr_list(&backup
, goto_stack
, 0);
599 static void *pop_backup(void)
603 ret
= last_ptr_list(backup
);
604 delete_ptr_list_last(&backup
);
608 void restore_all_states(void)
610 goto_stack
= pop_backup();
612 continue_stack
= pop_backup();
613 default_stack
= pop_backup();
614 remaining_cases
= pop_backup();
615 switch_stack
= pop_backup();
616 fake_break_stack
= pop_backup();
617 break_stack
= pop_backup();
619 fake_cur_stree_stack
= pop_backup();
621 cond_false_stack
= pop_backup();
622 cond_true_stack
= pop_backup();
624 pre_cond_stack
= pop_backup();
625 false_stack
= pop_backup();
626 true_stack
= pop_backup();
628 cur_stree
= pop_backup();
631 void free_goto_stack(void)
633 struct named_stree
*named_stree
;
635 FOR_EACH_PTR(goto_stack
, named_stree
) {
636 free_stree(&named_stree
->stree
);
637 } END_FOR_EACH_PTR(named_stree
);
638 __free_ptr_list((struct ptr_list
**)&goto_stack
);
641 void clear_all_states(void)
644 check_stree_stack_free(&true_stack
);
645 check_stree_stack_free(&false_stack
);
646 check_stree_stack_free(&pre_cond_stack
);
647 check_stree_stack_free(&cond_true_stack
);
648 check_stree_stack_free(&cond_false_stack
);
649 check_stree_stack_free(&break_stack
);
650 check_stree_stack_free(&fake_break_stack
);
651 check_stree_stack_free(&switch_stack
);
652 check_stree_stack_free(&continue_stack
);
653 check_stree_stack_free(&fake_cur_stree_stack
);
657 free_every_single_sm_state();
660 void __push_cond_stacks(void)
662 push_stree(&cond_true_stack
, NULL
);
663 push_stree(&cond_false_stack
, NULL
);
664 __push_fake_cur_stree();
667 void __fold_in_set_states(void)
669 struct stree
*new_states
;
672 new_states
= __pop_fake_cur_stree();
673 FOR_EACH_SM(new_states
, sm
) {
675 __set_true_false_sm(sm
, sm
);
676 } END_FOR_EACH_SM(sm
);
677 free_stree(&new_states
);
680 void __free_set_states(void)
682 struct stree
*new_states
;
684 new_states
= __pop_fake_cur_stree();
685 free_stree(&new_states
);
688 struct stree
*__copy_cond_true_states(void)
692 ret
= pop_stree(&cond_true_stack
);
693 push_stree(&cond_true_stack
, clone_stree(ret
));
697 struct stree
*__copy_cond_false_states(void)
701 ret
= pop_stree(&cond_false_stack
);
702 push_stree(&cond_false_stack
, clone_stree(ret
));
706 struct stree
*__pop_cond_true_stack(void)
708 return pop_stree(&cond_true_stack
);
711 struct stree
*__pop_cond_false_stack(void)
713 return pop_stree(&cond_false_stack
);
717 * This combines the pre cond states with either the true or false states.
719 * a = kmalloc() ; if (a !! foo(a)
720 * In the pre state a is possibly null. In the true state it is non null.
721 * In the false state it is null. Combine the pre and the false to get
722 * that when we call 'foo', 'a' is null.
724 static void __use_cond_stack(struct stree_stack
**stack
)
728 free_stree(&cur_stree
);
730 cur_stree
= pop_stree(&pre_cond_stack
);
731 push_stree(&pre_cond_stack
, clone_stree(cur_stree
));
733 stree
= pop_stree(stack
);
734 overwrite_stree(stree
, &cur_stree
);
735 push_stree(stack
, stree
);
738 void __use_pre_cond_states(void)
740 free_stree(&cur_stree
);
741 cur_stree
= pop_stree(&pre_cond_stack
);
744 void __use_cond_true_states(void)
746 __use_cond_stack(&cond_true_stack
);
749 void __use_cond_false_states(void)
751 __use_cond_stack(&cond_false_stack
);
754 void __negate_cond_stacks(void)
756 struct stree
*old_false
, *old_true
;
758 __use_cond_stack(&cond_false_stack
);
759 old_false
= pop_stree(&cond_false_stack
);
760 old_true
= pop_stree(&cond_true_stack
);
761 push_stree(&cond_false_stack
, old_true
);
762 push_stree(&cond_true_stack
, old_false
);
765 void __and_cond_states(void)
767 and_stree_stack(&cond_true_stack
);
768 or_stree_stack(&pre_cond_stack
, cur_stree
, &cond_false_stack
);
771 void __or_cond_states(void)
773 or_stree_stack(&pre_cond_stack
, cur_stree
, &cond_true_stack
);
774 and_stree_stack(&cond_false_stack
);
777 void __save_pre_cond_states(void)
779 push_stree(&pre_cond_stack
, clone_stree(cur_stree
));
782 void __discard_pre_cond_states(void)
786 tmp
= pop_stree(&pre_cond_stack
);
790 struct stree
*__get_true_states(void)
792 return clone_stree(top_stree(cond_true_stack
));
795 struct stree
*__get_false_states(void)
797 return clone_stree(top_stree(cond_false_stack
));
800 void __use_cond_states(void)
802 struct stree
*pre
, *pre_clone
, *true_states
, *false_states
;
804 pre
= pop_stree(&pre_cond_stack
);
805 pre_clone
= clone_stree(pre
);
807 true_states
= pop_stree(&cond_true_stack
);
808 overwrite_stree(true_states
, &pre
);
809 free_stree(&true_states
);
810 /* we use the true states right away */
811 free_stree(&cur_stree
);
814 false_states
= pop_stree(&cond_false_stack
);
815 overwrite_stree(false_states
, &pre_clone
);
816 free_stree(&false_states
);
817 push_stree(&false_stack
, pre_clone
);
820 void __push_true_states(void)
822 push_stree(&true_stack
, clone_stree(cur_stree
));
825 void __use_false_states(void)
827 free_stree(&cur_stree
);
828 cur_stree
= pop_stree(&false_stack
);
831 void __discard_false_states(void)
835 stree
= pop_stree(&false_stack
);
839 void __merge_false_states(void)
843 stree
= pop_stree(&false_stack
);
844 merge_stree(&cur_stree
, stree
);
849 * This function probably seemed common sensical when I wrote it but, oh wow,
850 * does it look subtle in retrospect. Say we set a state on one side of the if
851 * else path but not on the other, then what we should record in the fake stree
852 * is the merged state.
854 * This function relies on the fact that the we always set the cur_stree as well
855 * and we already have the infrastructure to merge things correctly into the
858 * So instead of merging fake strees together which is probably a lot of work,
859 * we just use it as a list of set states and look up the actual current values
863 static void update_stree_with_merged(struct stree
**stree
)
865 struct state_list
*slist
= NULL
;
866 struct sm_state
*sm
, *new;
868 FOR_EACH_SM(*stree
, sm
) {
869 new = get_sm_state(sm
->owner
, sm
->name
, sm
->sym
);
870 if (!new) /* This can happen if we go out of scope */
872 add_ptr_list(&slist
, new);
873 } END_FOR_EACH_SM(sm
);
875 FOR_EACH_PTR(slist
, sm
) {
876 overwrite_sm_state_stree(stree
, sm
);
877 } END_FOR_EACH_PTR(sm
);
882 static void update_fake_stree_with_merged(void)
886 if (!fake_cur_stree_stack
)
888 stree
= pop_stree(&fake_cur_stree_stack
);
889 update_stree_with_merged(&stree
);
890 push_stree(&fake_cur_stree_stack
, stree
);
893 void __merge_true_states(void)
897 stree
= pop_stree(&true_stack
);
898 merge_stree(&cur_stree
, stree
);
899 update_fake_stree_with_merged();
903 void __push_continues(void)
905 push_stree(&continue_stack
, NULL
);
908 void __discard_continues(void)
912 stree
= pop_stree(&continue_stack
);
916 void __process_continues(void)
920 stree
= pop_stree(&continue_stack
);
922 stree
= clone_stree(cur_stree
);
924 merge_stree(&stree
, cur_stree
);
926 push_stree(&continue_stack
, stree
);
929 void __merge_continues(void)
933 stree
= pop_stree(&continue_stack
);
934 merge_stree(&cur_stree
, stree
);
938 void __push_breaks(void)
940 push_stree(&break_stack
, NULL
);
941 if (fake_cur_stree_stack
)
942 push_stree(&fake_break_stack
, NULL
);
945 void __process_breaks(void)
949 stree
= pop_stree(&break_stack
);
951 stree
= clone_stree(cur_stree
);
953 merge_stree(&stree
, cur_stree
);
954 push_stree(&break_stack
, stree
);
956 if (!fake_cur_stree_stack
)
959 stree
= pop_stree(&fake_break_stack
);
961 stree
= clone_stree(top_stree(fake_cur_stree_stack
));
963 merge_stree(&stree
, top_stree(fake_cur_stree_stack
));
964 push_stree(&fake_break_stack
, stree
);
967 int __has_breaks(void)
972 stree
= pop_stree(&break_stack
);
974 push_stree(&break_stack
, stree
);
978 void __merge_breaks(void)
983 stree
= pop_stree(&break_stack
);
984 merge_stree(&cur_stree
, stree
);
987 if (!fake_cur_stree_stack
)
990 stree
= pop_stree(&fake_break_stack
);
991 update_stree_with_merged(&stree
);
992 FOR_EACH_SM(stree
, sm
) {
993 overwrite_sm_state_stree_stack(&fake_cur_stree_stack
, sm
);
994 } END_FOR_EACH_SM(sm
);
998 void __use_breaks(void)
1000 struct stree
*stree
;
1001 struct sm_state
*sm
;
1003 free_stree(&cur_stree
);
1004 cur_stree
= pop_stree(&break_stack
);
1006 if (!fake_cur_stree_stack
)
1008 stree
= pop_stree(&fake_break_stack
);
1009 FOR_EACH_SM(stree
, sm
) {
1010 overwrite_sm_state_stree_stack(&fake_cur_stree_stack
, sm
);
1011 } END_FOR_EACH_SM(sm
);
1017 void __save_switch_states(struct expression
*switch_expr
)
1019 struct range_list
*rl
;
1021 get_absolute_rl(switch_expr
, &rl
);
1023 push_rl(&remaining_cases
, rl
);
1024 push_stree(&switch_stack
, clone_stree(cur_stree
));
1027 void __merge_switches(struct expression
*switch_expr
, struct range_list
*case_rl
)
1029 struct stree
*stree
;
1030 struct stree
*implied_stree
;
1032 stree
= pop_stree(&switch_stack
);
1033 implied_stree
= __implied_case_stree(switch_expr
, case_rl
, &remaining_cases
, &stree
);
1034 merge_stree(&cur_stree
, implied_stree
);
1035 free_stree(&implied_stree
);
1036 push_stree(&switch_stack
, stree
);
1039 void __discard_switches(void)
1041 struct stree
*stree
;
1043 pop_rl(&remaining_cases
);
1044 stree
= pop_stree(&switch_stack
);
1048 void __push_default(void)
1050 push_stree(&default_stack
, NULL
);
1053 void __set_default(void)
1055 set_state_stree_stack(&default_stack
, 0, "has_default", NULL
, &true_state
);
1058 int __pop_default(void)
1060 struct stree
*stree
;
1062 stree
= pop_stree(&default_stack
);
1070 static struct named_stree
*alloc_named_stree(const char *name
, struct symbol
*sym
, struct stree
*stree
)
1072 struct named_stree
*named_stree
= __alloc_named_stree(0);
1074 named_stree
->name
= (char *)name
;
1075 named_stree
->stree
= stree
;
1076 named_stree
->sym
= sym
;
1080 void __save_gotos(const char *name
, struct symbol
*sym
)
1082 struct stree
**stree
;
1083 struct stree
*clone
;
1085 stree
= get_named_stree(goto_stack
, name
, sym
);
1087 merge_stree(stree
, cur_stree
);
1090 struct named_stree
*named_stree
;
1092 clone
= clone_stree(cur_stree
);
1093 named_stree
= alloc_named_stree(name
, sym
, clone
);
1094 add_ptr_list(&goto_stack
, named_stree
);
1098 void __merge_gotos(const char *name
, struct symbol
*sym
)
1100 struct stree
**stree
;
1102 stree
= get_named_stree(goto_stack
, name
, sym
);
1104 merge_stree(&cur_stree
, *stree
);