constraints: add constraints framework
[smatch.git] / smatch_helper.c
blob746897e5114d85ef085d83579e23179b321e3868
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 symbol *type;
129 if (expr->type != EXPR_BINOP || expr->op != '+')
130 return NULL;
132 type = get_type(expr->left);
133 if (!type || type->type != SYM_ARRAY)
134 return NULL;
135 return expr->left;
138 static void __get_variable_from_expr(struct symbol **sym_ptr, char *buf,
139 struct expression *expr, int len,
140 int *complicated, int no_parens)
144 if (!expr) {
145 /* can't happen on valid code */
146 *complicated = 1;
147 return;
150 switch (expr->type) {
151 case EXPR_DEREF: {
152 struct expression *deref;
153 int op;
155 deref = expr->deref;
156 op = deref->op;
157 if (op == '*') {
158 struct expression *unop = strip_expr(deref->unop);
160 if (unop->type == EXPR_PREOP && unop->op == '&') {
161 deref = unop->unop;
162 op = '.';
163 } else {
164 deref = deref->unop;
165 if (!is_pointer(deref))
166 op = '.';
170 __get_variable_from_expr(sym_ptr, buf, deref, len, complicated, no_parens);
172 if (op == '*')
173 append(buf, "->", len);
174 else
175 append(buf, ".", len);
177 if (expr->member)
178 append(buf, expr->member->name, len);
179 else
180 append(buf, "unknown_member", len);
182 return;
184 case EXPR_SYMBOL:
185 if (expr->symbol_name)
186 append(buf, expr->symbol_name->name, len);
187 if (sym_ptr) {
188 if (*sym_ptr)
189 *complicated = 1;
190 *sym_ptr = expr->symbol;
192 return;
193 case EXPR_PREOP: {
194 const char *tmp;
196 if (get_expression_statement(expr)) {
197 *complicated = 2;
198 return;
201 if (expr->op == '(') {
202 if (!no_parens && expr->unop->type != EXPR_SYMBOL)
203 append(buf, "(", len);
204 } else if (expr->op != '*' || !get_array_expr(expr->unop)) {
205 tmp = show_special(expr->op);
206 append(buf, tmp, len);
208 __get_variable_from_expr(sym_ptr, buf, expr->unop,
209 len, complicated, no_parens);
211 if (expr->op == '(' && !no_parens && expr->unop->type != EXPR_SYMBOL)
212 append(buf, ")", len);
214 if (expr->op == SPECIAL_DECREMENT ||
215 expr->op == SPECIAL_INCREMENT)
216 *complicated = 1;
218 return;
220 case EXPR_POSTOP: {
221 const char *tmp;
223 __get_variable_from_expr(sym_ptr, buf, expr->unop,
224 len, complicated, no_parens);
225 tmp = show_special(expr->op);
226 append(buf, tmp, len);
228 if (expr->op == SPECIAL_DECREMENT || expr->op == SPECIAL_INCREMENT)
229 *complicated = 1;
230 return;
232 case EXPR_ASSIGNMENT:
233 case EXPR_COMPARE:
234 case EXPR_LOGICAL:
235 case EXPR_BINOP: {
236 char tmp[10];
237 struct expression *array_expr;
239 *complicated = 1;
240 array_expr = get_array_expr(expr);
241 if (array_expr) {
242 __get_variable_from_expr(sym_ptr, buf, array_expr, len, complicated, no_parens);
243 append(buf, "[", len);
244 } else {
245 __get_variable_from_expr(sym_ptr, buf, expr->left, len, complicated, no_parens);
246 snprintf(tmp, sizeof(tmp), " %s ", show_special(expr->op));
247 append(buf, tmp, len);
249 __get_variable_from_expr(NULL, buf, expr->right, len, complicated, no_parens);
250 if (array_expr)
251 append(buf, "]", len);
252 return;
254 case EXPR_VALUE: {
255 char tmp[25];
257 *complicated = 1;
258 snprintf(tmp, 25, "%lld", expr->value);
259 append(buf, tmp, len);
260 return;
262 case EXPR_STRING:
263 append(buf, "\"", len);
264 if (expr->string)
265 append(buf, expr->string->data, len);
266 append(buf, "\"", len);
267 return;
268 case EXPR_CALL: {
269 struct expression *tmp;
270 int i;
272 *complicated = 1;
273 __get_variable_from_expr(NULL, buf, expr->fn, len, complicated, no_parens);
274 append(buf, "(", len);
275 i = 0;
276 FOR_EACH_PTR(expr->args, tmp) {
277 if (i++)
278 append(buf, ", ", len);
279 __get_variable_from_expr(NULL, buf, tmp, len, complicated, no_parens);
280 } END_FOR_EACH_PTR(tmp);
281 append(buf, ")", len);
282 return;
284 case EXPR_CAST:
285 case EXPR_FORCE_CAST:
286 __get_variable_from_expr(sym_ptr, buf,
287 expr->cast_expression, len,
288 complicated, no_parens);
289 return;
290 case EXPR_SIZEOF: {
291 sval_t sval;
292 int size;
293 char tmp[25];
295 if (expr->cast_type && get_base_type(expr->cast_type)) {
296 size = type_bytes(get_base_type(expr->cast_type));
297 snprintf(tmp, 25, "%d", size);
298 append(buf, tmp, len);
299 } else if (get_value(expr, &sval)) {
300 snprintf(tmp, 25, "%s", sval_to_str(sval));
301 append(buf, tmp, len);
303 return;
305 case EXPR_IDENTIFIER:
306 *complicated = 1;
307 if (expr->expr_ident)
308 append(buf, expr->expr_ident->name, len);
309 return;
310 default:
311 *complicated = 1;
312 //printf("unknown type = %d\n", expr->type);
313 return;
318 * This is returns a stylized "c looking" representation of the
319 * variable name.
321 * It uses the same buffer every time so you have to save the result
322 * yourself if you want to keep it.
326 char *expr_to_str_sym(struct expression *expr, struct symbol **sym_ptr)
328 static char var_name[VAR_LEN];
329 int complicated = 0;
331 if (sym_ptr)
332 *sym_ptr = NULL;
333 var_name[0] = '\0';
335 if (!expr)
336 return NULL;
337 __get_variable_from_expr(sym_ptr, var_name, expr, sizeof(var_name),
338 &complicated, 0);
339 if (complicated < 2)
340 return alloc_string(var_name);
341 else
342 return NULL;
345 char *expr_to_str(struct expression *expr)
347 return expr_to_str_sym(expr, NULL);
351 * get_variable_from_expr_simple() only returns simple variables.
352 * If it's a complicated variable like a->foo[x] instead of just 'a->foo'
353 * then it returns NULL.
355 char *expr_to_var_sym(struct expression *expr,
356 struct symbol **sym_ptr)
358 static char var_name[VAR_LEN];
359 int complicated = 0;
361 if (sym_ptr)
362 *sym_ptr = NULL;
363 var_name[0] = '\0';
365 if (!expr)
366 return NULL;
367 expr = strip_expr(expr);
368 __get_variable_from_expr(sym_ptr, var_name, expr, sizeof(var_name),
369 &complicated, 1);
371 if (complicated) {
372 if (sym_ptr)
373 *sym_ptr = NULL;
374 return NULL;
376 return alloc_string(var_name);
379 char *expr_to_var(struct expression *expr)
381 return expr_to_var_sym(expr, NULL);
384 struct symbol *expr_to_sym(struct expression *expr)
386 struct symbol *sym;
387 char *name;
389 name = expr_to_var_sym(expr, &sym);
390 free_string(name);
391 return sym;
394 int get_complication_score(struct expression *expr)
396 int score = 0;
398 expr = strip_expr(expr);
401 * Don't forget to keep get_complication_score() and store_all_links()
402 * in sync.
406 if (!expr)
407 return 999;
409 switch (expr->type) {
410 case EXPR_CALL:
411 return 999;
412 case EXPR_COMPARE:
413 case EXPR_BINOP:
414 score += get_complication_score(expr->left);
415 score += get_complication_score(expr->right);
416 return score;
417 case EXPR_SYMBOL:
418 if (is_local_variable(expr))
419 return 1;
420 return 999;
421 case EXPR_PREOP:
422 if (expr->op == '*')
423 return score + get_complication_score(expr->unop);
424 return 999;
425 case EXPR_DEREF:
426 return score + get_complication_score(expr->deref);
427 case EXPR_VALUE:
428 return 0;
429 default:
430 return 999;
434 struct expression *reorder_expr_alphabetically(struct expression *expr)
436 struct expression *ret;
437 char *left, *right;
439 if (expr->type != EXPR_BINOP)
440 return expr;
441 if (expr->op != '+' && expr->op != '*')
442 return expr;
444 left = expr_to_var(expr->left);
445 right = expr_to_var(expr->right);
446 ret = expr;
447 if (!left || !right)
448 goto free;
449 if (strcmp(left, right) <= 0)
450 goto free;
452 ret = binop_expression(expr->right, expr->op, expr->left);
453 free:
454 free_string(left);
455 free_string(right);
457 return ret;
460 char *expr_to_chunk_helper(struct expression *expr, struct symbol **sym, struct var_sym_list **vsl)
462 char *name;
463 struct symbol *tmp;
464 int score;
466 if (vsl)
467 *vsl = NULL;
468 if (sym)
469 *sym = NULL;
471 expr = strip_parens(expr);
472 if (!expr)
473 return NULL;
475 name = expr_to_var_sym(expr, &tmp);
476 if (name && tmp) {
477 if (sym)
478 *sym = tmp;
479 if (vsl)
480 *vsl = expr_to_vsl(expr);
481 return name;
483 free_string(name);
485 score = get_complication_score(expr);
486 if (score <= 0 || score > 2)
487 return NULL;
489 if (vsl) {
490 *vsl = expr_to_vsl(expr);
491 if (!*vsl)
492 return NULL;
495 expr = reorder_expr_alphabetically(expr);
497 return expr_to_str(expr);
500 char *expr_to_known_chunk_sym(struct expression *expr, struct symbol **sym)
502 return expr_to_chunk_helper(expr, sym, NULL);
505 char *expr_to_chunk_sym_vsl(struct expression *expr, struct symbol **sym, struct var_sym_list **vsl)
507 return expr_to_chunk_helper(expr, sym, vsl);
510 int sym_name_is(const char *name, struct expression *expr)
512 if (!expr)
513 return 0;
514 if (expr->type != EXPR_SYMBOL)
515 return 0;
516 if (!strcmp(expr->symbol_name->name, name))
517 return 1;
518 return 0;
521 int is_zero(struct expression *expr)
523 sval_t sval;
525 if (get_value(expr, &sval) && sval.value == 0)
526 return 1;
527 return 0;
530 int is_array(struct expression *expr)
532 struct symbol *type;
534 expr = strip_expr(expr);
535 if (!expr)
536 return 0;
538 if (expr->type == EXPR_PREOP && expr->op == '*') {
539 expr = strip_expr(expr->unop);
540 if (!expr)
541 return 0;
542 if (expr->type == EXPR_BINOP && expr->op == '+')
543 return 1;
546 if (expr->type != EXPR_BINOP || expr->op != '+')
547 return 0;
549 type = get_type(expr->left);
550 if (!type || type->type != SYM_ARRAY)
551 return 0;
553 return 1;
556 struct expression *get_array_base(struct expression *expr)
558 if (!is_array(expr))
559 return NULL;
560 expr = strip_expr(expr);
561 if (expr->type == EXPR_PREOP && expr->op == '*')
562 expr = strip_expr(expr->unop);
563 if (expr->type != EXPR_BINOP || expr->op != '+')
564 return NULL;
565 return strip_parens(expr->left);
568 struct expression *get_array_offset(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->right);
580 const char *show_state(struct smatch_state *state)
582 if (!state)
583 return NULL;
584 return state->name;
587 struct statement *get_expression_statement(struct expression *expr)
589 /* What are those things called? if (({....; ret;})) { ...*/
591 if (expr->type != EXPR_PREOP)
592 return NULL;
593 if (expr->op != '(')
594 return NULL;
595 if (expr->unop->type != EXPR_STATEMENT)
596 return NULL;
597 if (expr->unop->statement->type != STMT_COMPOUND)
598 return NULL;
599 return expr->unop->statement;
602 struct expression *strip_parens(struct expression *expr)
604 if (!expr)
605 return NULL;
607 if (expr->type == EXPR_PREOP) {
608 if (expr->op == '(' && expr->unop->type == EXPR_STATEMENT &&
609 expr->unop->statement->type == STMT_COMPOUND)
610 return expr;
611 if (expr->op == '(')
612 return strip_parens(expr->unop);
614 return expr;
617 struct expression *strip_expr(struct expression *expr)
619 if (!expr)
620 return NULL;
622 switch (expr->type) {
623 case EXPR_FORCE_CAST:
624 case EXPR_CAST:
625 return strip_expr(expr->cast_expression);
626 case EXPR_PREOP: {
627 struct expression *unop;
629 if (expr->op == '(' && expr->unop->type == EXPR_STATEMENT &&
630 expr->unop->statement->type == STMT_COMPOUND)
631 return expr;
633 unop = strip_expr(expr->unop);
635 if (expr->op == '*' && unop &&
636 unop->type == EXPR_PREOP && unop->op == '&') {
637 struct symbol *type = get_type(unop->unop);
639 if (type && type->type == SYM_ARRAY)
640 return expr;
641 return strip_expr(unop->unop);
644 if (expr->op == '(')
645 return unop;
647 return expr;
649 case EXPR_CONDITIONAL:
650 if (known_condition_true(expr->conditional)) {
651 if (expr->cond_true)
652 return strip_expr(expr->cond_true);
653 return strip_expr(expr->conditional);
655 if (known_condition_false(expr->conditional))
656 return strip_expr(expr->cond_false);
657 return expr;
658 case EXPR_CALL:
659 if (sym_name_is("__builtin_expect", expr->fn)) {
660 expr = get_argument_from_call_expr(expr->args, 0);
661 return strip_expr(expr);
663 return expr;
665 return expr;
668 static void delete_state_tracker(struct tracker *t)
670 delete_state(t->owner, t->name, t->sym);
671 __free_tracker(t);
674 void scoped_state(int my_id, const char *name, struct symbol *sym)
676 struct tracker *t;
678 t = alloc_tracker(my_id, name, sym);
679 add_scope_hook((scope_hook *)&delete_state_tracker, t);
682 int is_error_return(struct expression *expr)
684 struct symbol *cur_func = cur_func_sym;
685 sval_t sval;
687 if (!expr)
688 return 0;
689 if (cur_func->type != SYM_NODE)
690 return 0;
691 cur_func = get_base_type(cur_func);
692 if (cur_func->type != SYM_FN)
693 return 0;
694 cur_func = get_base_type(cur_func);
695 if (cur_func == &void_ctype)
696 return 0;
697 if (!get_implied_value(expr, &sval))
698 return 0;
699 if (sval.value < 0)
700 return 1;
701 if (cur_func->type == SYM_PTR && sval.value == 0)
702 return 1;
703 return 0;
706 int getting_address(void)
708 struct expression *tmp;
709 int i = 0;
710 int dot_ops = 0;
712 FOR_EACH_PTR_REVERSE(big_expression_stack, tmp) {
713 if (!i++)
714 continue;
715 if (tmp->type == EXPR_PREOP && tmp->op == '(')
716 continue;
717 if (tmp->op == '.' && !dot_ops++)
718 continue;
719 if (tmp->op == '&')
720 return 1;
721 return 0;
722 } END_FOR_EACH_PTR_REVERSE(tmp);
723 return 0;
726 int get_struct_and_member(struct expression *expr, const char **type, const char **member)
728 struct symbol *sym;
730 expr = strip_expr(expr);
731 if (expr->type != EXPR_DEREF)
732 return 0;
733 if (!expr->member)
734 return 0;
736 sym = get_type(expr->deref);
737 if (!sym)
738 return 0;
739 if (sym->type == SYM_UNION)
740 return 0;
741 if (!sym->ident)
742 return 0;
744 *type = sym->ident->name;
745 *member = expr->member->name;
746 return 1;
749 char *get_member_name(struct expression *expr)
751 char buf[256];
752 struct symbol *sym;
754 expr = strip_expr(expr);
755 if (expr->type != EXPR_DEREF)
756 return NULL;
757 if (!expr->member)
758 return NULL;
760 sym = get_type(expr->deref);
761 if (!sym)
762 return NULL;
763 if (sym->type == SYM_UNION) {
764 snprintf(buf, sizeof(buf), "(union %s)->%s",
765 sym->ident ? sym->ident->name : "anonymous",
766 expr->member->name);
767 return alloc_string(buf);
769 if (!sym->ident)
770 return NULL;
771 snprintf(buf, sizeof(buf), "(struct %s)->%s", sym->ident->name, expr->member->name);
772 return alloc_string(buf);
775 int cmp_pos(struct position pos1, struct position pos2)
777 /* the stream position is ... */
778 if (pos1.stream > pos2.stream)
779 return -1;
780 if (pos1.stream < pos2.stream)
781 return 1;
783 if (pos1.line < pos2.line)
784 return -1;
785 if (pos1.line > pos2.line)
786 return 1;
788 if (pos1.pos < pos2.pos)
789 return -1;
790 if (pos1.pos > pos2.pos)
791 return 1;
793 return 0;
796 int positions_eq(struct position pos1, struct position pos2)
798 if (pos1.line != pos2.line)
799 return 0;
800 if (pos1.pos != pos2.pos)
801 return 0;
802 if (pos1.stream != pos2.stream)
803 return 0;
804 return 1;
807 struct statement *get_current_statement(void)
809 struct statement *prev, *tmp;
811 prev = last_ptr_list((struct ptr_list *)big_statement_stack);
813 if (!prev || !get_macro_name(prev->pos))
814 return prev;
816 FOR_EACH_PTR_REVERSE(big_statement_stack, tmp) {
817 if (positions_eq(tmp->pos, prev->pos))
818 continue;
819 if (prev->pos.line > tmp->pos.line)
820 return prev;
821 return tmp;
822 } END_FOR_EACH_PTR_REVERSE(tmp);
823 return prev;
826 struct statement *get_prev_statement(void)
828 struct statement *tmp;
829 int i;
831 i = 0;
832 FOR_EACH_PTR_REVERSE(big_statement_stack, tmp) {
833 if (i++ == 1)
834 return tmp;
835 } END_FOR_EACH_PTR_REVERSE(tmp);
836 return NULL;
839 int get_param_num_from_sym(struct symbol *sym)
841 struct symbol *tmp;
842 int i;
844 if (!cur_func_sym)
845 return -1;
847 i = 0;
848 FOR_EACH_PTR(cur_func_sym->ctype.base_type->arguments, tmp) {
849 if (tmp == sym)
850 return i;
851 i++;
852 } END_FOR_EACH_PTR(tmp);
853 return -1;
856 int get_param_num(struct expression *expr)
858 struct symbol *sym;
859 char *name;
861 if (!cur_func_sym)
862 return -1;
863 name = expr_to_var_sym(expr, &sym);
864 free_string(name);
865 if (!sym)
866 return -1;
867 return get_param_num_from_sym(sym);
870 int ms_since(struct timeval *start)
872 struct timeval end;
873 double diff;
875 gettimeofday(&end, NULL);
876 diff = (end.tv_sec - start->tv_sec) * 1000.0;
877 diff += (end.tv_usec - start->tv_usec) / 1000.0;
878 return (int)diff;
881 int parent_is_gone_var_sym(const char *name, struct symbol *sym)
883 if (!name || !sym)
884 return 0;
886 if (parent_is_null_var_sym(name, sym) ||
887 parent_is_free_var_sym(name, sym))
888 return 1;
889 return 0;
892 int parent_is_gone(struct expression *expr)
894 struct symbol *sym;
895 char *var;
896 int ret = 0;
898 expr = strip_expr(expr);
899 var = expr_to_var_sym(expr, &sym);
900 if (!var || !sym)
901 goto free;
902 ret = parent_is_gone_var_sym(var, sym);
903 free:
904 free_string(var);
905 return ret;
908 int invert_op(int op)
910 switch (op) {
911 case '*':
912 return '/';
913 case '/':
914 return '*';
915 case '+':
916 return '-';
917 case '-':
918 return '+';
919 case SPECIAL_LEFTSHIFT:
920 return SPECIAL_RIGHTSHIFT;
921 case SPECIAL_RIGHTSHIFT:
922 return SPECIAL_LEFTSHIFT;
924 return 0;
927 int expr_equiv(struct expression *one, struct expression *two)
929 struct symbol *one_sym = NULL;
930 struct symbol *two_sym = NULL;
931 char *one_name = NULL;
932 char *two_name = NULL;
933 int ret = 0;
935 if (!one || !two)
936 return 0;
937 if (one->type != two->type)
938 return 0;
940 one_name = expr_to_str_sym(one, &one_sym);
941 if (!one_name)
942 goto free;
943 two_name = expr_to_str_sym(two, &two_sym);
944 if (!two_name)
945 goto free;
946 if (one_sym != two_sym)
947 goto free;
949 * This is a terrible hack because expr_to_str() sometimes gives up in
950 * the middle and just returns what it has. If you see a () you know
951 * the string is bogus.
953 if (strstr(one_name, "()"))
954 goto free;
955 if (strcmp(one_name, two_name) == 0)
956 ret = 1;
957 free:
958 free_string(one_name);
959 free_string(two_name);
960 return ret;
963 void push_int(struct int_stack **stack, int num)
965 int *munged;
968 * Just put the int on directly instead of a pointer to the int.
969 * Shift it to the left because Sparse uses the last two bits.
970 * This is sort of a dirty hack, yes.
973 munged = INT_PTR(num << 2);
975 add_ptr_list(stack, munged);
978 int pop_int(struct int_stack **stack)
980 int *num;
982 num = last_ptr_list((struct ptr_list *)*stack);
983 delete_ptr_list_last((struct ptr_list **)stack);
985 return PTR_INT(num) >> 2;