db: pass the call expression to call_implies callbacks
[smatch.git] / smatch_helper.c
blobdb1d453579b64a9267d34be37546f651e177ae38
1 /*
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 * Miscellaneous helper functions.
22 #include <stdlib.h>
23 #include <stdio.h>
24 #include "allocate.h"
25 #include "smatch.h"
26 #include "smatch_extra.h"
27 #include "smatch_slist.h"
29 #define VAR_LEN 512
31 char *alloc_string(const char *str)
33 char *tmp;
35 if (!str)
36 return NULL;
37 tmp = malloc(strlen(str) + 1);
38 strcpy(tmp, str);
39 return tmp;
42 void free_string(char *str)
44 free(str);
47 void remove_parens(char *str)
49 char *src, *dst;
51 dst = src = str;
52 while (*src != '\0') {
53 if (*src == '(' || *src == ')') {
54 src++;
55 continue;
57 *dst++ = *src++;
59 *dst = *src;
62 struct smatch_state *alloc_state_num(int num)
64 struct smatch_state *state;
65 static char buff[256];
67 state = __alloc_smatch_state(0);
68 snprintf(buff, 255, "%d", num);
69 buff[255] = '\0';
70 state->name = alloc_string(buff);
71 state->data = INT_PTR(num);
72 return state;
75 struct smatch_state *alloc_state_str(const char *name)
77 struct smatch_state *state;
79 state = __alloc_smatch_state(0);
80 state->name = alloc_string(name);
81 return state;
84 struct smatch_state *alloc_state_expr(struct expression *expr)
86 struct smatch_state *state;
87 char *name;
89 state = __alloc_smatch_state(0);
90 expr = strip_expr(expr);
91 name = expr_to_str(expr);
92 state->name = alloc_sname(name);
93 free_string(name);
94 state->data = expr;
95 return state;
98 void append(char *dest, const char *data, int buff_len)
100 strncat(dest, data, buff_len - strlen(dest) - 1);
104 * If you have "foo(a, b, 1);" then use
105 * get_argument_from_call_expr(expr, 0) to return the expression for
106 * a. Yes, it does start counting from 0.
108 struct expression *get_argument_from_call_expr(struct expression_list *args,
109 int num)
111 struct expression *expr;
112 int i = 0;
114 if (!args)
115 return NULL;
117 FOR_EACH_PTR(args, expr) {
118 if (i == num)
119 return expr;
120 i++;
121 } END_FOR_EACH_PTR(expr);
122 return NULL;
125 static struct expression *get_array_expr(struct expression *expr)
127 struct expression *parent;
128 struct symbol *type;
130 if (expr->type != EXPR_BINOP || expr->op != '+')
131 return NULL;
133 type = get_type(expr->left);
134 if (!type)
135 return NULL;
136 if (type->type == SYM_ARRAY)
137 return expr->left;
138 if (type->type != SYM_PTR)
139 return NULL;
141 parent = expr_get_parent_expr(expr);
142 if (!parent)
143 return NULL;
144 if (parent->type == EXPR_PREOP && parent->op == '*')
145 return expr->left;
147 return NULL;
150 static void __get_variable_from_expr(struct symbol **sym_ptr, char *buf,
151 struct expression *expr, int len,
152 int *complicated, int no_parens)
156 if (!expr) {
157 /* can't happen on valid code */
158 *complicated = 1;
159 return;
162 switch (expr->type) {
163 case EXPR_DEREF: {
164 struct expression *deref;
165 int op;
167 deref = expr->deref;
168 op = deref->op;
169 if (op == '*') {
170 struct expression *unop = strip_expr(deref->unop);
172 if (unop->type == EXPR_PREOP && unop->op == '&') {
173 deref = unop->unop;
174 op = '.';
175 } else {
176 deref = deref->unop;
177 if (!is_pointer(deref))
178 op = '.';
182 __get_variable_from_expr(sym_ptr, buf, deref, len, complicated, no_parens);
184 if (op == '*')
185 append(buf, "->", len);
186 else
187 append(buf, ".", len);
189 if (expr->member)
190 append(buf, expr->member->name, len);
191 else
192 append(buf, "unknown_member", len);
194 return;
196 case EXPR_SYMBOL:
197 if (expr->symbol_name)
198 append(buf, expr->symbol_name->name, len);
199 if (sym_ptr) {
200 if (*sym_ptr)
201 *complicated = 1;
202 *sym_ptr = expr->symbol;
204 return;
205 case EXPR_PREOP: {
206 const char *tmp;
208 if (get_expression_statement(expr)) {
209 *complicated = 2;
210 return;
213 if (expr->op == '(') {
214 if (!no_parens && expr->unop->type != EXPR_SYMBOL)
215 append(buf, "(", len);
216 } else if (expr->op != '*' || !get_array_expr(expr->unop)) {
217 tmp = show_special(expr->op);
218 append(buf, tmp, len);
220 __get_variable_from_expr(sym_ptr, buf, expr->unop,
221 len, complicated, no_parens);
223 if (expr->op == '(' && !no_parens && expr->unop->type != EXPR_SYMBOL)
224 append(buf, ")", len);
226 if (expr->op == SPECIAL_DECREMENT ||
227 expr->op == SPECIAL_INCREMENT)
228 *complicated = 1;
230 return;
232 case EXPR_POSTOP: {
233 const char *tmp;
235 __get_variable_from_expr(sym_ptr, buf, expr->unop,
236 len, complicated, no_parens);
237 tmp = show_special(expr->op);
238 append(buf, tmp, len);
240 if (expr->op == SPECIAL_DECREMENT || expr->op == SPECIAL_INCREMENT)
241 *complicated = 1;
242 return;
244 case EXPR_ASSIGNMENT:
245 case EXPR_COMPARE:
246 case EXPR_LOGICAL:
247 case EXPR_BINOP: {
248 char tmp[10];
249 struct expression *array_expr;
251 *complicated = 1;
252 array_expr = get_array_expr(expr);
253 if (array_expr) {
254 __get_variable_from_expr(sym_ptr, buf, array_expr, len, complicated, no_parens);
255 append(buf, "[", len);
256 } else {
257 __get_variable_from_expr(sym_ptr, buf, expr->left, len, complicated, no_parens);
258 snprintf(tmp, sizeof(tmp), " %s ", show_special(expr->op));
259 append(buf, tmp, len);
261 __get_variable_from_expr(NULL, buf, expr->right, len, complicated, no_parens);
262 if (array_expr)
263 append(buf, "]", len);
264 return;
266 case EXPR_VALUE: {
267 char tmp[25];
269 *complicated = 1;
270 snprintf(tmp, 25, "%lld", expr->value);
271 append(buf, tmp, len);
272 return;
274 case EXPR_STRING:
275 append(buf, "\"", len);
276 if (expr->string)
277 append(buf, expr->string->data, len);
278 append(buf, "\"", len);
279 return;
280 case EXPR_CALL: {
281 struct expression *tmp;
282 int i;
284 *complicated = 1;
285 __get_variable_from_expr(NULL, buf, expr->fn, len, complicated, no_parens);
286 append(buf, "(", len);
287 i = 0;
288 FOR_EACH_PTR(expr->args, tmp) {
289 if (i++)
290 append(buf, ", ", len);
291 __get_variable_from_expr(NULL, buf, tmp, len, complicated, no_parens);
292 } END_FOR_EACH_PTR(tmp);
293 append(buf, ")", len);
294 return;
296 case EXPR_CAST:
297 case EXPR_FORCE_CAST:
298 __get_variable_from_expr(sym_ptr, buf,
299 expr->cast_expression, len,
300 complicated, no_parens);
301 return;
302 case EXPR_SIZEOF: {
303 sval_t sval;
304 int size;
305 char tmp[25];
307 if (expr->cast_type && get_base_type(expr->cast_type)) {
308 size = type_bytes(get_base_type(expr->cast_type));
309 snprintf(tmp, 25, "%d", size);
310 append(buf, tmp, len);
311 } else if (get_value(expr, &sval)) {
312 snprintf(tmp, 25, "%s", sval_to_str(sval));
313 append(buf, tmp, len);
315 return;
317 case EXPR_IDENTIFIER:
318 *complicated = 1;
319 if (expr->expr_ident)
320 append(buf, expr->expr_ident->name, len);
321 return;
322 default:
323 *complicated = 1;
324 //printf("unknown type = %d\n", expr->type);
325 return;
330 * This is returns a stylized "c looking" representation of the
331 * variable name.
333 * It uses the same buffer every time so you have to save the result
334 * yourself if you want to keep it.
338 char *expr_to_str_sym(struct expression *expr, struct symbol **sym_ptr)
340 static char var_name[VAR_LEN];
341 int complicated = 0;
343 if (sym_ptr)
344 *sym_ptr = NULL;
345 var_name[0] = '\0';
347 if (!expr)
348 return NULL;
349 __get_variable_from_expr(sym_ptr, var_name, expr, sizeof(var_name),
350 &complicated, 0);
351 if (complicated < 2)
352 return alloc_string(var_name);
353 else
354 return NULL;
357 char *expr_to_str(struct expression *expr)
359 return expr_to_str_sym(expr, NULL);
363 * get_variable_from_expr_simple() only returns simple variables.
364 * If it's a complicated variable like a->foo[x] instead of just 'a->foo'
365 * then it returns NULL.
367 char *expr_to_var_sym(struct expression *expr,
368 struct symbol **sym_ptr)
370 static char var_name[VAR_LEN];
371 int complicated = 0;
373 if (sym_ptr)
374 *sym_ptr = NULL;
375 var_name[0] = '\0';
377 if (!expr)
378 return NULL;
379 expr = strip_expr(expr);
380 __get_variable_from_expr(sym_ptr, var_name, expr, sizeof(var_name),
381 &complicated, 1);
383 if (complicated) {
384 if (sym_ptr)
385 *sym_ptr = NULL;
386 return NULL;
388 return alloc_string(var_name);
391 char *expr_to_var(struct expression *expr)
393 return expr_to_var_sym(expr, NULL);
396 struct symbol *expr_to_sym(struct expression *expr)
398 struct symbol *sym;
399 char *name;
401 name = expr_to_var_sym(expr, &sym);
402 free_string(name);
403 return sym;
406 int get_complication_score(struct expression *expr)
408 int score = 0;
410 expr = strip_expr(expr);
413 * Don't forget to keep get_complication_score() and store_all_links()
414 * in sync.
418 if (!expr)
419 return 999;
421 switch (expr->type) {
422 case EXPR_CALL:
423 return 999;
424 case EXPR_COMPARE:
425 case EXPR_BINOP:
426 score += get_complication_score(expr->left);
427 score += get_complication_score(expr->right);
428 return score;
429 case EXPR_SYMBOL:
430 if (is_local_variable(expr))
431 return 1;
432 return 999;
433 case EXPR_PREOP:
434 if (expr->op == '*')
435 return score + get_complication_score(expr->unop);
436 return 999;
437 case EXPR_DEREF:
438 return score + get_complication_score(expr->deref);
439 case EXPR_VALUE:
440 return 0;
441 default:
442 return 999;
446 struct expression *reorder_expr_alphabetically(struct expression *expr)
448 struct expression *ret;
449 char *left, *right;
451 if (expr->type != EXPR_BINOP)
452 return expr;
453 if (expr->op != '+' && expr->op != '*')
454 return expr;
456 left = expr_to_var(expr->left);
457 right = expr_to_var(expr->right);
458 ret = expr;
459 if (!left || !right)
460 goto free;
461 if (strcmp(left, right) <= 0)
462 goto free;
464 ret = binop_expression(expr->right, expr->op, expr->left);
465 free:
466 free_string(left);
467 free_string(right);
469 return ret;
472 char *expr_to_chunk_helper(struct expression *expr, struct symbol **sym, struct var_sym_list **vsl)
474 char *name;
475 struct symbol *tmp;
476 int score;
478 if (vsl)
479 *vsl = NULL;
480 if (sym)
481 *sym = NULL;
483 expr = strip_parens(expr);
484 if (!expr)
485 return NULL;
487 name = expr_to_var_sym(expr, &tmp);
488 if (name && tmp) {
489 if (sym)
490 *sym = tmp;
491 if (vsl)
492 *vsl = expr_to_vsl(expr);
493 return name;
495 free_string(name);
497 score = get_complication_score(expr);
498 if (score <= 0 || score > 2)
499 return NULL;
501 if (vsl) {
502 *vsl = expr_to_vsl(expr);
503 if (!*vsl)
504 return NULL;
507 expr = reorder_expr_alphabetically(expr);
509 return expr_to_str(expr);
512 char *expr_to_known_chunk_sym(struct expression *expr, struct symbol **sym)
514 return expr_to_chunk_helper(expr, sym, NULL);
517 char *expr_to_chunk_sym_vsl(struct expression *expr, struct symbol **sym, struct var_sym_list **vsl)
519 return expr_to_chunk_helper(expr, sym, vsl);
522 int sym_name_is(const char *name, struct expression *expr)
524 if (!expr)
525 return 0;
526 if (expr->type != EXPR_SYMBOL)
527 return 0;
528 if (!strcmp(expr->symbol_name->name, name))
529 return 1;
530 return 0;
533 int is_zero(struct expression *expr)
535 sval_t sval;
537 if (get_value(expr, &sval) && sval.value == 0)
538 return 1;
539 return 0;
542 int is_array(struct expression *expr)
544 struct symbol *type;
546 expr = strip_expr(expr);
547 if (!expr)
548 return 0;
550 if (expr->type == EXPR_PREOP && expr->op == '*') {
551 expr = strip_expr(expr->unop);
552 if (!expr)
553 return 0;
554 if (expr->type == EXPR_BINOP && expr->op == '+')
555 return 1;
558 if (expr->type != EXPR_BINOP || expr->op != '+')
559 return 0;
561 type = get_type(expr->left);
562 if (!type || type->type != SYM_ARRAY)
563 return 0;
565 return 1;
568 struct expression *get_array_base(struct expression *expr)
570 if (!is_array(expr))
571 return NULL;
572 expr = strip_expr(expr);
573 if (expr->type == EXPR_PREOP && expr->op == '*')
574 expr = strip_expr(expr->unop);
575 if (expr->type != EXPR_BINOP || expr->op != '+')
576 return NULL;
577 return strip_parens(expr->left);
580 struct expression *get_array_offset(struct expression *expr)
582 if (!is_array(expr))
583 return NULL;
584 expr = strip_expr(expr);
585 if (expr->type == EXPR_PREOP && expr->op == '*')
586 expr = strip_expr(expr->unop);
587 if (expr->type != EXPR_BINOP || expr->op != '+')
588 return NULL;
589 return strip_parens(expr->right);
592 const char *show_state(struct smatch_state *state)
594 if (!state)
595 return NULL;
596 return state->name;
599 struct statement *get_expression_statement(struct expression *expr)
601 /* What are those things called? if (({....; ret;})) { ...*/
603 if (expr->type != EXPR_PREOP)
604 return NULL;
605 if (expr->op != '(')
606 return NULL;
607 if (expr->unop->type != EXPR_STATEMENT)
608 return NULL;
609 if (expr->unop->statement->type != STMT_COMPOUND)
610 return NULL;
611 return expr->unop->statement;
614 struct expression *strip_parens(struct expression *expr)
616 if (!expr)
617 return NULL;
619 if (expr->type == EXPR_PREOP) {
620 if (expr->op == '(' && expr->unop->type == EXPR_STATEMENT &&
621 expr->unop->statement->type == STMT_COMPOUND)
622 return expr;
623 if (expr->op == '(')
624 return strip_parens(expr->unop);
626 return expr;
629 struct expression *strip_expr(struct expression *expr)
631 if (!expr)
632 return NULL;
634 switch (expr->type) {
635 case EXPR_FORCE_CAST:
636 case EXPR_CAST:
637 return strip_expr(expr->cast_expression);
638 case EXPR_PREOP: {
639 struct expression *unop;
641 if (expr->op == '(' && expr->unop->type == EXPR_STATEMENT &&
642 expr->unop->statement->type == STMT_COMPOUND)
643 return expr;
645 unop = strip_expr(expr->unop);
647 if (expr->op == '*' && unop &&
648 unop->type == EXPR_PREOP && unop->op == '&') {
649 struct symbol *type = get_type(unop->unop);
651 if (type && type->type == SYM_ARRAY)
652 return expr;
653 return strip_expr(unop->unop);
656 if (expr->op == '(')
657 return unop;
659 return expr;
661 case EXPR_CONDITIONAL:
662 if (known_condition_true(expr->conditional)) {
663 if (expr->cond_true)
664 return strip_expr(expr->cond_true);
665 return strip_expr(expr->conditional);
667 if (known_condition_false(expr->conditional))
668 return strip_expr(expr->cond_false);
669 return expr;
670 case EXPR_CALL:
671 if (sym_name_is("__builtin_expect", expr->fn)) {
672 expr = get_argument_from_call_expr(expr->args, 0);
673 return strip_expr(expr);
675 return expr;
677 return expr;
680 static void delete_state_tracker(struct tracker *t)
682 delete_state(t->owner, t->name, t->sym);
683 __free_tracker(t);
686 void scoped_state(int my_id, const char *name, struct symbol *sym)
688 struct tracker *t;
690 t = alloc_tracker(my_id, name, sym);
691 add_scope_hook((scope_hook *)&delete_state_tracker, t);
694 int is_error_return(struct expression *expr)
696 struct symbol *cur_func = cur_func_sym;
697 sval_t sval;
699 if (!expr)
700 return 0;
701 if (cur_func->type != SYM_NODE)
702 return 0;
703 cur_func = get_base_type(cur_func);
704 if (cur_func->type != SYM_FN)
705 return 0;
706 cur_func = get_base_type(cur_func);
707 if (cur_func == &void_ctype)
708 return 0;
709 if (!get_implied_value(expr, &sval))
710 return 0;
711 if (sval.value < 0)
712 return 1;
713 if (cur_func->type == SYM_PTR && sval.value == 0)
714 return 1;
715 return 0;
718 int getting_address(void)
720 struct expression *tmp;
721 int i = 0;
722 int dot_ops = 0;
724 FOR_EACH_PTR_REVERSE(big_expression_stack, tmp) {
725 if (!i++)
726 continue;
727 if (tmp->type == EXPR_PREOP && tmp->op == '(')
728 continue;
729 if (tmp->op == '.' && !dot_ops++)
730 continue;
731 if (tmp->op == '&')
732 return 1;
733 return 0;
734 } END_FOR_EACH_PTR_REVERSE(tmp);
735 return 0;
738 int get_struct_and_member(struct expression *expr, const char **type, const char **member)
740 struct symbol *sym;
742 expr = strip_expr(expr);
743 if (expr->type != EXPR_DEREF)
744 return 0;
745 if (!expr->member)
746 return 0;
748 sym = get_type(expr->deref);
749 if (!sym)
750 return 0;
751 if (sym->type == SYM_UNION)
752 return 0;
753 if (!sym->ident)
754 return 0;
756 *type = sym->ident->name;
757 *member = expr->member->name;
758 return 1;
761 char *get_member_name(struct expression *expr)
763 char buf[256];
764 struct symbol *sym;
766 expr = strip_expr(expr);
767 if (expr->type != EXPR_DEREF)
768 return NULL;
769 if (!expr->member)
770 return NULL;
772 sym = get_type(expr->deref);
773 if (!sym)
774 return NULL;
775 if (sym->type == SYM_UNION) {
776 snprintf(buf, sizeof(buf), "(union %s)->%s",
777 sym->ident ? sym->ident->name : "anonymous",
778 expr->member->name);
779 return alloc_string(buf);
781 if (!sym->ident)
782 return NULL;
783 snprintf(buf, sizeof(buf), "(struct %s)->%s", sym->ident->name, expr->member->name);
784 return alloc_string(buf);
787 int cmp_pos(struct position pos1, struct position pos2)
789 /* the stream position is ... */
790 if (pos1.stream > pos2.stream)
791 return -1;
792 if (pos1.stream < pos2.stream)
793 return 1;
795 if (pos1.line < pos2.line)
796 return -1;
797 if (pos1.line > pos2.line)
798 return 1;
800 if (pos1.pos < pos2.pos)
801 return -1;
802 if (pos1.pos > pos2.pos)
803 return 1;
805 return 0;
808 int positions_eq(struct position pos1, struct position pos2)
810 if (pos1.line != pos2.line)
811 return 0;
812 if (pos1.pos != pos2.pos)
813 return 0;
814 if (pos1.stream != pos2.stream)
815 return 0;
816 return 1;
819 struct statement *get_current_statement(void)
821 struct statement *prev, *tmp;
823 prev = last_ptr_list((struct ptr_list *)big_statement_stack);
825 if (!prev || !get_macro_name(prev->pos))
826 return prev;
828 FOR_EACH_PTR_REVERSE(big_statement_stack, tmp) {
829 if (positions_eq(tmp->pos, prev->pos))
830 continue;
831 if (prev->pos.line > tmp->pos.line)
832 return prev;
833 return tmp;
834 } END_FOR_EACH_PTR_REVERSE(tmp);
835 return prev;
838 struct statement *get_prev_statement(void)
840 struct statement *tmp;
841 int i;
843 i = 0;
844 FOR_EACH_PTR_REVERSE(big_statement_stack, tmp) {
845 if (i++ == 1)
846 return tmp;
847 } END_FOR_EACH_PTR_REVERSE(tmp);
848 return NULL;
851 int get_param_num_from_sym(struct symbol *sym)
853 struct symbol *tmp;
854 int i;
856 if (!cur_func_sym)
857 return -1;
859 i = 0;
860 FOR_EACH_PTR(cur_func_sym->ctype.base_type->arguments, tmp) {
861 if (tmp == sym)
862 return i;
863 i++;
864 } END_FOR_EACH_PTR(tmp);
865 return -1;
868 int get_param_num(struct expression *expr)
870 struct symbol *sym;
871 char *name;
873 if (!cur_func_sym)
874 return -1;
875 name = expr_to_var_sym(expr, &sym);
876 free_string(name);
877 if (!sym)
878 return -1;
879 return get_param_num_from_sym(sym);
882 int ms_since(struct timeval *start)
884 struct timeval end;
885 double diff;
887 gettimeofday(&end, NULL);
888 diff = (end.tv_sec - start->tv_sec) * 1000.0;
889 diff += (end.tv_usec - start->tv_usec) / 1000.0;
890 return (int)diff;
893 int parent_is_gone_var_sym(const char *name, struct symbol *sym)
895 if (!name || !sym)
896 return 0;
898 if (parent_is_null_var_sym(name, sym) ||
899 parent_is_free_var_sym(name, sym))
900 return 1;
901 return 0;
904 int parent_is_gone(struct expression *expr)
906 struct symbol *sym;
907 char *var;
908 int ret = 0;
910 expr = strip_expr(expr);
911 var = expr_to_var_sym(expr, &sym);
912 if (!var || !sym)
913 goto free;
914 ret = parent_is_gone_var_sym(var, sym);
915 free:
916 free_string(var);
917 return ret;
920 int invert_op(int op)
922 switch (op) {
923 case '*':
924 return '/';
925 case '/':
926 return '*';
927 case '+':
928 return '-';
929 case '-':
930 return '+';
931 case SPECIAL_LEFTSHIFT:
932 return SPECIAL_RIGHTSHIFT;
933 case SPECIAL_RIGHTSHIFT:
934 return SPECIAL_LEFTSHIFT;
936 return 0;
939 int expr_equiv(struct expression *one, struct expression *two)
941 struct symbol *one_sym = NULL;
942 struct symbol *two_sym = NULL;
943 char *one_name = NULL;
944 char *two_name = NULL;
945 int ret = 0;
947 if (!one || !two)
948 return 0;
949 if (one->type != two->type)
950 return 0;
952 one_name = expr_to_str_sym(one, &one_sym);
953 if (!one_name)
954 goto free;
955 two_name = expr_to_str_sym(two, &two_sym);
956 if (!two_name)
957 goto free;
958 if (one_sym != two_sym)
959 goto free;
961 * This is a terrible hack because expr_to_str() sometimes gives up in
962 * the middle and just returns what it has. If you see a () you know
963 * the string is bogus.
965 if (strstr(one_name, "()"))
966 goto free;
967 if (strcmp(one_name, two_name) == 0)
968 ret = 1;
969 free:
970 free_string(one_name);
971 free_string(two_name);
972 return ret;
975 void push_int(struct int_stack **stack, int num)
977 int *munged;
980 * Just put the int on directly instead of a pointer to the int.
981 * Shift it to the left because Sparse uses the last two bits.
982 * This is sort of a dirty hack, yes.
985 munged = INT_PTR(num << 2);
987 add_ptr_list(stack, munged);
990 int pop_int(struct int_stack **stack)
992 int *num;
994 num = last_ptr_list((struct ptr_list *)*stack);
995 delete_ptr_list_last((struct ptr_list **)stack);
997 return PTR_INT(num) >> 2;