extra: write certain returned struct members in terms of parameter math
[smatch.git] / smatch_slist.c
blobbf539587e0a3f7261430374c4fbe4d6c9aaf01c1
1 /*
2 * Copyright (C) 2008,2009 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
18 #include <stdlib.h>
19 #include <stdio.h>
20 #include "smatch.h"
21 #include "smatch_slist.h"
23 #undef CHECKORDER
25 ALLOCATOR(smatch_state, "smatch state");
26 ALLOCATOR(sm_state, "sm state");
27 ALLOCATOR(named_stree, "named slist");
28 __DO_ALLOCATOR(char, 1, 4, "state names", sname);
30 static int sm_state_counter;
32 static struct stree_stack *all_pools;
34 char *show_sm(struct sm_state *sm)
36 static char buf[256];
37 struct sm_state *tmp;
38 int pos;
39 int i;
41 pos = snprintf(buf, sizeof(buf), "[%s] '%s' = %s (",
42 check_name(sm->owner), sm->name, show_state(sm->state));
43 if (pos > sizeof(buf))
44 goto truncate;
46 i = 0;
47 FOR_EACH_PTR(sm->possible, tmp) {
48 if (i++)
49 pos += snprintf(buf + pos, sizeof(buf) - pos, ", ");
50 if (pos > sizeof(buf))
51 goto truncate;
52 pos += snprintf(buf + pos, sizeof(buf) - pos, "%s",
53 show_state(tmp->state));
54 if (pos > sizeof(buf))
55 goto truncate;
56 } END_FOR_EACH_PTR(tmp);
57 snprintf(buf + pos, sizeof(buf) - pos, ")");
59 return buf;
61 truncate:
62 for (i = 0; i < 3; i++)
63 buf[sizeof(buf) - 2 - i] = '.';
64 return buf;
67 void __print_stree(struct stree *stree)
69 struct sm_state *sm;
71 printf("dumping stree at %d\n", get_lineno());
72 FOR_EACH_SM(stree, sm) {
73 printf("%s\n", show_sm(sm));
74 } END_FOR_EACH_SM(sm);
75 printf("---\n");
78 /* NULL states go at the end to simplify merge_slist */
79 int cmp_tracker(const struct sm_state *a, const struct sm_state *b)
81 int ret;
83 if (a == b)
84 return 0;
85 if (!b)
86 return -1;
87 if (!a)
88 return 1;
90 if (a->owner > b->owner)
91 return -1;
92 if (a->owner < b->owner)
93 return 1;
95 ret = strcmp(a->name, b->name);
96 if (ret)
97 return ret;
99 if (!b->sym && a->sym)
100 return -1;
101 if (!a->sym && b->sym)
102 return 1;
103 if (a->sym > b->sym)
104 return -1;
105 if (a->sym < b->sym)
106 return 1;
108 return 0;
111 static int cmp_sm_states(const struct sm_state *a, const struct sm_state *b, int preserve)
113 int ret;
115 ret = cmp_tracker(a, b);
116 if (ret)
117 return ret;
119 /* todo: add hook for smatch_extra.c */
120 if (a->state > b->state)
121 return -1;
122 if (a->state < b->state)
123 return 1;
124 /* This is obviously a massive disgusting hack but we need to preserve
125 * the unmerged states for smatch extra because we use them in
126 * smatch_db.c. Meanwhile if we preserve all the other unmerged states
127 * then it uses a lot of memory and we don't use it. Hence this hack.
129 * Also sometimes even just preserving every possible SMATCH_EXTRA state
130 * takes too much resources so we have to cap that. Capping is probably
131 * not often a problem in real life.
133 if (a->owner == SMATCH_EXTRA && preserve) {
134 if (a == b)
135 return 0;
136 if (a->merged == 1 && b->merged == 0)
137 return -1;
138 if (a->merged == 0)
139 return 1;
142 return 0;
145 static struct sm_state *alloc_sm_state(int owner, const char *name,
146 struct symbol *sym, struct smatch_state *state)
148 struct sm_state *sm_state = __alloc_sm_state(0);
150 sm_state_counter++;
152 sm_state->name = alloc_sname(name);
153 sm_state->owner = owner;
154 sm_state->sym = sym;
155 sm_state->state = state;
156 sm_state->line = get_lineno();
157 sm_state->merged = 0;
158 sm_state->implied = 0;
159 sm_state->pool = NULL;
160 sm_state->left = NULL;
161 sm_state->right = NULL;
162 sm_state->nr_children = 1;
163 sm_state->possible = NULL;
164 add_ptr_list(&sm_state->possible, sm_state);
165 return sm_state;
168 static struct sm_state *alloc_state_no_name(int owner, const char *name,
169 struct symbol *sym,
170 struct smatch_state *state)
172 struct sm_state *tmp;
174 tmp = alloc_sm_state(owner, NULL, sym, state);
175 tmp->name = name;
176 return tmp;
179 int too_many_possible(struct sm_state *sm)
181 if (ptr_list_size((struct ptr_list *)sm->possible) >= 100)
182 return 1;
183 return 0;
186 void add_possible_sm(struct sm_state *to, struct sm_state *new)
188 struct sm_state *tmp;
189 int preserve = 1;
191 if (too_many_possible(to))
192 preserve = 0;
194 FOR_EACH_PTR(to->possible, tmp) {
195 if (cmp_sm_states(tmp, new, preserve) < 0)
196 continue;
197 else if (cmp_sm_states(tmp, new, preserve) == 0) {
198 return;
199 } else {
200 INSERT_CURRENT(new, tmp);
201 return;
203 } END_FOR_EACH_PTR(tmp);
204 add_ptr_list(&to->possible, new);
207 static void copy_possibles(struct sm_state *to, struct sm_state *from)
209 struct sm_state *tmp;
211 FOR_EACH_PTR(from->possible, tmp) {
212 add_possible_sm(to, tmp);
213 } END_FOR_EACH_PTR(tmp);
216 char *alloc_sname(const char *str)
218 char *tmp;
220 if (!str)
221 return NULL;
222 tmp = __alloc_sname(strlen(str) + 1);
223 strcpy(tmp, str);
224 return tmp;
227 int out_of_memory(void)
230 * I decided to use 50M here based on trial and error.
231 * It works out OK for the kernel and so it should work
232 * for most other projects as well.
234 if (sm_state_counter * sizeof(struct sm_state) >= 50000000)
235 return 1;
236 return 0;
239 int low_on_memory(void)
241 if (sm_state_counter * sizeof(struct sm_state) >= 25000000)
242 return 1;
243 return 0;
246 static void free_sm_state(struct sm_state *sm)
248 free_slist(&sm->possible);
250 * fixme. Free the actual state.
251 * Right now we leave it until the end of the function
252 * because we don't want to double free it.
253 * Use the freelist to not double free things
257 static void free_all_sm_states(struct allocation_blob *blob)
259 unsigned int size = sizeof(struct sm_state);
260 unsigned int offset = 0;
262 while (offset < blob->offset) {
263 free_sm_state((struct sm_state *)(blob->data + offset));
264 offset += size;
268 /* At the end of every function we free all the sm_states */
269 void free_every_single_sm_state(void)
271 struct allocator_struct *desc = &sm_state_allocator;
272 struct allocation_blob *blob = desc->blobs;
274 desc->blobs = NULL;
275 desc->allocations = 0;
276 desc->total_bytes = 0;
277 desc->useful_bytes = 0;
278 desc->freelist = NULL;
279 while (blob) {
280 struct allocation_blob *next = blob->next;
281 free_all_sm_states(blob);
282 blob_free(blob, desc->chunking);
283 blob = next;
285 clear_sname_alloc();
286 clear_smatch_state_alloc();
288 free_stack_and_strees(&all_pools);
289 sm_state_counter = 0;
292 struct sm_state *clone_sm(struct sm_state *s)
294 struct sm_state *ret;
296 ret = alloc_state_no_name(s->owner, s->name, s->sym, s->state);
297 ret->merged = s->merged;
298 ret->implied = s->implied;
299 ret->line = s->line;
300 /* clone_sm() doesn't copy the pools. Each state needs to have
301 only one pool. */
302 ret->possible = clone_slist(s->possible);
303 ret->left = s->left;
304 ret->right = s->right;
305 ret->nr_children = s->nr_children;
306 return ret;
309 int is_merged(struct sm_state *sm)
311 return sm->merged;
314 int is_implied(struct sm_state *sm)
316 return sm->implied;
319 int slist_has_state(struct state_list *slist, struct smatch_state *state)
321 struct sm_state *tmp;
323 FOR_EACH_PTR(slist, tmp) {
324 if (tmp->state == state)
325 return 1;
326 } END_FOR_EACH_PTR(tmp);
327 return 0;
330 struct state_list *clone_slist(struct state_list *from_slist)
332 struct sm_state *sm;
333 struct state_list *to_slist = NULL;
335 FOR_EACH_PTR(from_slist, sm) {
336 add_ptr_list(&to_slist, sm);
337 } END_FOR_EACH_PTR(sm);
338 return to_slist;
341 struct smatch_state *merge_states(int owner, const char *name,
342 struct symbol *sym,
343 struct smatch_state *state1,
344 struct smatch_state *state2)
346 struct smatch_state *ret;
348 if (state1 == state2)
349 ret = state1;
350 else if (__has_merge_function(owner))
351 ret = __client_merge_function(owner, state1, state2);
352 else if (!state1 || !state2)
353 ret = &undefined;
354 else
355 ret = &merged;
356 return ret;
359 struct sm_state *merge_sm_states(struct sm_state *one, struct sm_state *two)
361 struct smatch_state *s;
362 struct sm_state *result;
364 if (one == two)
365 return one;
366 s = merge_states(one->owner, one->name, one->sym, one->state, two->state);
367 result = alloc_state_no_name(one->owner, one->name, one->sym, s);
368 result->merged = 1;
369 result->left = one;
370 result->right = two;
371 result->nr_children = one->nr_children + two->nr_children;
372 copy_possibles(result, one);
373 copy_possibles(result, two);
375 if (option_debug ||
376 strcmp(check_name(one->owner), option_debug_check) == 0) {
377 struct sm_state *tmp;
378 int i = 0;
380 printf("%s:%d %s() merge [%s] '%s' %s(L %d) + %s(L %d) => %s (",
381 get_filename(), get_lineno(), get_function(),
382 check_name(one->owner), one->name,
383 show_state(one->state), one->line,
384 show_state(two->state), two->line,
385 show_state(s));
387 FOR_EACH_PTR(result->possible, tmp) {
388 if (i++)
389 printf(", ");
390 printf("%s", show_state(tmp->state));
391 } END_FOR_EACH_PTR(tmp);
392 printf(")\n");
395 return result;
398 struct sm_state *get_sm_state_stree(struct stree *stree, int owner, const char *name,
399 struct symbol *sym)
401 struct tracker tracker = {
402 .owner = owner,
403 .name = (char *)name,
404 .sym = sym,
407 if (!name)
408 return NULL;
411 return avl_lookup(stree, (struct sm_state *)&tracker);
414 struct smatch_state *get_state_stree(struct stree *stree,
415 int owner, const char *name,
416 struct symbol *sym)
418 struct sm_state *sm;
420 sm = get_sm_state_stree(stree, owner, name, sym);
421 if (sm)
422 return sm->state;
423 return NULL;
426 /* FIXME: this is almost exactly the same as set_sm_state_slist() */
427 void overwrite_sm_state_stree(struct stree **stree, struct sm_state *new)
429 avl_insert(stree, new);
432 void overwrite_sm_state_stree_stack(struct stree_stack **stack,
433 struct sm_state *sm)
435 struct stree *stree;
437 stree = pop_stree(stack);
438 overwrite_sm_state_stree(&stree, sm);
439 push_stree(stack, stree);
442 struct sm_state *set_state_stree(struct stree **stree, int owner, const char *name,
443 struct symbol *sym, struct smatch_state *state)
445 struct sm_state *new = alloc_sm_state(owner, name, sym, state);
447 avl_insert(stree, new);
448 return new;
451 void set_state_stree_perm(struct stree **stree, int owner, const char *name,
452 struct symbol *sym, struct smatch_state *state)
454 struct sm_state *sm;
456 sm = malloc(sizeof(*sm) + strlen(name) + 1);
457 memset(sm, 0, sizeof(*sm));
458 sm->owner = owner;
459 sm->name = (char *)(sm + 1);
460 strcpy((char *)sm->name, name);
461 sm->sym = sym;
462 sm->state = state;
464 overwrite_sm_state_stree(stree, sm);
467 void delete_state_stree(struct stree **stree, int owner, const char *name,
468 struct symbol *sym)
470 struct tracker tracker = {
471 .owner = owner,
472 .name = (char *)name,
473 .sym = sym,
476 avl_remove(stree, (struct sm_state *)&tracker);
479 void delete_state_stree_stack(struct stree_stack **stack, int owner, const char *name,
480 struct symbol *sym)
482 struct stree *stree;
484 stree = pop_stree(stack);
485 delete_state_stree(&stree, owner, name, sym);
486 push_stree(stack, stree);
489 void push_stree(struct stree_stack **stack, struct stree *stree)
491 add_ptr_list(stack, stree);
494 struct stree *pop_stree(struct stree_stack **stack)
496 struct stree *stree;
498 stree = last_ptr_list((struct ptr_list *)*stack);
499 delete_ptr_list_last((struct ptr_list **)stack);
500 return stree;
503 void free_slist(struct state_list **slist)
505 __free_ptr_list((struct ptr_list **)slist);
508 void free_stree_stack(struct stree_stack **stack)
510 __free_ptr_list((struct ptr_list **)stack);
513 void free_stack_and_strees(struct stree_stack **stree_stack)
515 struct stree *stree;
517 FOR_EACH_PTR(*stree_stack, stree) {
518 free_stree(&stree);
519 } END_FOR_EACH_PTR(stree);
520 free_stree_stack(stree_stack);
523 struct sm_state *set_state_stree_stack(struct stree_stack **stack, int owner, const char *name,
524 struct symbol *sym, struct smatch_state *state)
526 struct stree *stree;
527 struct sm_state *sm;
529 stree = pop_stree(stack);
530 sm = set_state_stree(&stree, owner, name, sym, state);
531 push_stree(stack, stree);
533 return sm;
537 * get_sm_state_stack() gets the state for the top slist on the stack.
539 struct sm_state *get_sm_state_stree_stack(struct stree_stack *stack,
540 int owner, const char *name,
541 struct symbol *sym)
543 struct stree *stree;
544 struct sm_state *ret;
546 stree = pop_stree(&stack);
547 ret = get_sm_state_stree(stree, owner, name, sym);
548 push_stree(&stack, stree);
549 return ret;
552 struct smatch_state *get_state_stree_stack(struct stree_stack *stack,
553 int owner, const char *name,
554 struct symbol *sym)
556 struct sm_state *sm;
558 sm = get_sm_state_stree_stack(stack, owner, name, sym);
559 if (sm)
560 return sm->state;
561 return NULL;
564 static void match_states_stree(struct stree **one, struct stree **two)
566 struct smatch_state *tmp_state;
567 struct sm_state *sm;
568 struct state_list *add_to_one = NULL;
569 struct state_list *add_to_two = NULL;
570 AvlIter one_iter;
571 AvlIter two_iter;
573 avl_iter_begin(&one_iter, *one, FORWARD);
574 avl_iter_begin(&two_iter, *two, FORWARD);
576 for (;;) {
577 if (!one_iter.sm && !two_iter.sm)
578 break;
579 if (cmp_tracker(one_iter.sm, two_iter.sm) < 0) {
580 __set_fake_cur_stree_fast(*two);
581 tmp_state = __client_unmatched_state_function(one_iter.sm);
582 __pop_fake_cur_stree_fast();
583 sm = alloc_state_no_name(one_iter.sm->owner, one_iter.sm->name,
584 one_iter.sm->sym, tmp_state);
585 add_ptr_list(&add_to_two, sm);
586 avl_iter_next(&one_iter);
587 } else if (cmp_tracker(one_iter.sm, two_iter.sm) == 0) {
588 avl_iter_next(&one_iter);
589 avl_iter_next(&two_iter);
590 } else {
591 __set_fake_cur_stree_fast(*one);
592 tmp_state = __client_unmatched_state_function(two_iter.sm);
593 __pop_fake_cur_stree_fast();
594 sm = alloc_state_no_name(two_iter.sm->owner, two_iter.sm->name,
595 two_iter.sm->sym, tmp_state);
596 add_ptr_list(&add_to_one, sm);
597 avl_iter_next(&two_iter);
601 FOR_EACH_PTR(add_to_one, sm) {
602 avl_insert(one, sm);
603 } END_FOR_EACH_PTR(sm);
605 FOR_EACH_PTR(add_to_two, sm) {
606 avl_insert(two, sm);
607 } END_FOR_EACH_PTR(sm);
609 free_slist(&add_to_one);
610 free_slist(&add_to_two);
613 static void clone_pool_havers_stree(struct stree **stree)
615 struct sm_state *sm, *tmp;
616 struct state_list *slist = NULL;
618 FOR_EACH_SM(*stree, sm) {
619 if (sm->pool) {
620 tmp = clone_sm(sm);
621 add_ptr_list(&slist, tmp);
623 } END_FOR_EACH_SM(sm);
625 FOR_EACH_PTR(slist, sm) {
626 avl_insert(stree, sm);
627 } END_FOR_EACH_PTR(sm);
629 free_slist(&slist);
632 int __stree_id;
635 * merge_slist() is called whenever paths merge, such as after
636 * an if statement. It takes the two slists and creates one.
638 static void __merge_stree(struct stree **to, struct stree *stree, int add_pool)
640 struct stree *results = NULL;
641 struct stree *implied_one = NULL;
642 struct stree *implied_two = NULL;
643 AvlIter one_iter;
644 AvlIter two_iter;
645 struct sm_state *tmp_sm;
647 if (out_of_memory())
648 return;
650 /* merging a null and nonnull path gives you only the nonnull path */
651 if (!stree)
652 return;
653 if (*to == stree)
654 return;
656 if (!*to) {
657 *to = clone_stree(stree);
658 return;
661 implied_one = clone_stree(*to);
662 implied_two = clone_stree(stree);
664 match_states_stree(&implied_one, &implied_two);
666 if (add_pool) {
667 clone_pool_havers_stree(&implied_one);
668 clone_pool_havers_stree(&implied_two);
670 set_stree_id(&implied_one, ++__stree_id);
671 set_stree_id(&implied_two, ++__stree_id);
674 push_stree(&all_pools, implied_one);
675 push_stree(&all_pools, implied_two);
677 avl_iter_begin(&one_iter, implied_one, FORWARD);
678 avl_iter_begin(&two_iter, implied_two, FORWARD);
680 for (;;) {
681 if (!one_iter.sm && !two_iter.sm)
682 break;
683 if (cmp_tracker(one_iter.sm, two_iter.sm) < 0) {
684 sm_msg("error: Internal smatch error.");
685 avl_iter_next(&one_iter);
686 } else if (cmp_tracker(one_iter.sm, two_iter.sm) == 0) {
687 if (add_pool && one_iter.sm != two_iter.sm) {
688 one_iter.sm->pool = implied_one;
689 two_iter.sm->pool = implied_two;
691 tmp_sm = merge_sm_states(one_iter.sm, two_iter.sm);
692 avl_insert(&results, tmp_sm);
693 avl_iter_next(&one_iter);
694 avl_iter_next(&two_iter);
695 } else {
696 sm_msg("error: Internal smatch error.");
697 avl_iter_next(&two_iter);
701 free_stree(to);
702 *to = results;
705 void merge_stree(struct stree **to, struct stree *stree)
707 __merge_stree(to, stree, 1);
710 void merge_stree_no_pools(struct stree **to, struct stree *stree)
712 __merge_stree(to, stree, 0);
716 * This is unfortunately a bit subtle... The problem is that if a
717 * state is set on one fake stree but not the other then we should
718 * look up the the original state and use that as the unset state.
719 * Fortunately, after you pop your fake stree then the cur_slist should
720 * reflect the original state.
722 void merge_fake_stree(struct stree **to, struct stree *stree)
724 struct stree *one = *to;
725 struct stree *two = stree;
726 struct sm_state *sm;
727 struct state_list *add_to_one = NULL;
728 struct state_list *add_to_two = NULL;
729 AvlIter one_iter;
730 AvlIter two_iter;
732 if (!stree)
733 return;
734 if (*to == stree)
735 return;
736 if (!*to) {
737 *to = clone_stree(stree);
738 return;
741 avl_iter_begin(&one_iter, one, FORWARD);
742 avl_iter_begin(&two_iter, two, FORWARD);
744 for (;;) {
745 if (!one_iter.sm && !two_iter.sm)
746 break;
747 if (cmp_tracker(one_iter.sm, two_iter.sm) < 0) {
748 sm = get_sm_state(one_iter.sm->owner, one_iter.sm->name,
749 one_iter.sm->sym);
750 if (sm)
751 add_ptr_list(&add_to_two, sm);
752 avl_iter_next(&one_iter);
753 } else if (cmp_tracker(one_iter.sm, two_iter.sm) == 0) {
754 avl_iter_next(&one_iter);
755 avl_iter_next(&two_iter);
756 } else {
757 sm = get_sm_state(two_iter.sm->owner, two_iter.sm->name,
758 two_iter.sm->sym);
759 if (sm)
760 add_ptr_list(&add_to_one, sm);
761 avl_iter_next(&two_iter);
765 FOR_EACH_PTR(add_to_one, sm) {
766 avl_insert(&one, sm);
767 } END_FOR_EACH_PTR(sm);
769 FOR_EACH_PTR(add_to_two, sm) {
770 avl_insert(&two, sm);
771 } END_FOR_EACH_PTR(sm);
773 free_slist(&add_to_one);
774 free_slist(&add_to_two);
776 __merge_stree(&one, two, 1);
778 *to = one;
782 * filter_slist() removes any sm states "slist" holds in common with "filter"
784 void filter_stree(struct stree **stree, struct stree *filter)
786 struct stree *results = NULL;
787 AvlIter one_iter;
788 AvlIter two_iter;
790 avl_iter_begin(&one_iter, *stree, FORWARD);
791 avl_iter_begin(&two_iter, filter, FORWARD);
793 /* FIXME: This should probably be re-written with trees in mind */
795 for (;;) {
796 if (!one_iter.sm && !two_iter.sm)
797 break;
798 if (cmp_tracker(one_iter.sm, two_iter.sm) < 0) {
799 avl_insert(&results, one_iter.sm);
800 avl_iter_next(&one_iter);
801 } else if (cmp_tracker(one_iter.sm, two_iter.sm) == 0) {
802 if (one_iter.sm != two_iter.sm)
803 avl_insert(&results, one_iter.sm);
804 avl_iter_next(&one_iter);
805 avl_iter_next(&two_iter);
806 } else {
807 avl_iter_next(&two_iter);
811 free_stree(stree);
812 *stree = results;
817 * and_slist_stack() pops the top two slists, overwriting the one with
818 * the other and pushing it back on the stack.
820 void and_stree_stack(struct stree_stack **stack)
822 struct sm_state *tmp;
823 struct stree *right_stree = pop_stree(stack);
825 FOR_EACH_SM(right_stree, tmp) {
826 overwrite_sm_state_stree_stack(stack, tmp);
827 } END_FOR_EACH_SM(tmp);
828 free_stree(&right_stree);
832 * or_slist_stack() is for if we have: if (foo || bar) { foo->baz;
833 * It pops the two slists from the top of the stack and merges them
834 * together in a way that preserves the things they have in common
835 * but creates a merged state for most of the rest.
836 * You could have code that had: if (foo || foo) { foo->baz;
837 * It's this function which ensures smatch does the right thing.
839 void or_stree_stack(struct stree_stack **pre_conds,
840 struct stree *cur_stree,
841 struct stree_stack **stack)
843 struct stree *new;
844 struct stree *old;
845 struct stree *pre_stree;
846 struct stree *res;
847 struct stree *tmp_stree;
849 new = pop_stree(stack);
850 old = pop_stree(stack);
852 pre_stree = pop_stree(pre_conds);
853 push_stree(pre_conds, clone_stree(pre_stree));
855 res = clone_stree(pre_stree);
856 overwrite_stree(old, &res);
858 tmp_stree = clone_stree(cur_stree);
859 overwrite_stree(new, &tmp_stree);
861 merge_stree(&res, tmp_stree);
862 filter_stree(&res, pre_stree);
864 push_stree(stack, res);
865 free_stree(&tmp_stree);
866 free_stree(&pre_stree);
867 free_stree(&new);
868 free_stree(&old);
872 * get_named_stree() is only used for gotos.
874 struct stree **get_named_stree(struct named_stree_stack *stack,
875 const char *name)
877 struct named_stree *tmp;
879 FOR_EACH_PTR(stack, tmp) {
880 if (!strcmp(tmp->name, name))
881 return &tmp->stree;
882 } END_FOR_EACH_PTR(tmp);
883 return NULL;
886 /* FIXME: These parameters are in a different order from expected */
887 void overwrite_stree(struct stree *from, struct stree **to)
889 struct sm_state *tmp;
891 FOR_EACH_SM(from, tmp) {
892 overwrite_sm_state_stree(to, tmp);
893 } END_FOR_EACH_SM(tmp);