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.
26 #include "smatch_extra.h"
27 #include "smatch_slist.h"
31 char *alloc_string(const char *str
)
37 tmp
= malloc(strlen(str
) + 1);
42 char *alloc_string_newline(const char *str
)
50 tmp
= malloc(len
+ 2);
51 snprintf(tmp
, len
+ 2, "%s\n", str
);
55 void free_string(char *str
)
60 void remove_parens(char *str
)
65 while (*src
!= '\0') {
66 if (*src
== '(' || *src
== ')') {
75 struct smatch_state
*alloc_state_num(int num
)
77 struct smatch_state
*state
;
78 static char buff
[256];
80 state
= __alloc_smatch_state(0);
81 snprintf(buff
, 255, "%d", num
);
83 state
->name
= alloc_string(buff
);
84 state
->data
= INT_PTR(num
);
88 struct smatch_state
*alloc_state_str(const char *name
)
90 struct smatch_state
*state
;
92 state
= __alloc_smatch_state(0);
93 state
->name
= alloc_string(name
);
97 struct smatch_state
*merge_str_state(struct smatch_state
*s1
, struct smatch_state
*s2
)
99 if (!s1
->name
|| !s2
->name
)
101 if (strcmp(s1
->name
, s2
->name
) == 0)
106 struct smatch_state
*alloc_state_expr(struct expression
*expr
)
108 struct smatch_state
*state
;
111 expr
= strip_expr(expr
);
112 name
= expr_to_str(expr
);
116 state
= __alloc_smatch_state(0);
117 state
->name
= alloc_sname(name
);
123 void append(char *dest
, const char *data
, int buff_len
)
125 strncat(dest
, data
, buff_len
- strlen(dest
) - 1);
129 * If you have "foo(a, b, 1);" then use
130 * get_argument_from_call_expr(expr, 0) to return the expression for
131 * a. Yes, it does start counting from 0.
133 struct expression
*get_argument_from_call_expr(struct expression_list
*args
,
136 struct expression
*expr
;
142 FOR_EACH_PTR(args
, expr
) {
146 } END_FOR_EACH_PTR(expr
);
150 struct expression
*get_array_expr(struct expression
*expr
)
152 struct expression
*parent
;
155 if (expr
->type
!= EXPR_BINOP
|| expr
->op
!= '+')
158 type
= get_type(expr
->left
);
161 if (type
->type
== SYM_ARRAY
)
163 if (type
->type
!= SYM_PTR
)
166 parent
= expr_get_parent_expr(expr
);
167 if (!parent
) /* Sometimes we haven't set up the ->parent yet. FIXME!! */
169 if (parent
->type
== EXPR_PREOP
&& parent
->op
== '*')
175 static void __get_variable_from_expr(struct symbol
**sym_ptr
, char *buf
,
176 struct expression
*expr
, int len
,
180 /* can't happen on valid code */
185 switch (expr
->type
) {
187 struct expression
*deref
;
192 if (deref
->type
== EXPR_PREOP
&& op
== '*') {
193 struct expression
*unop
= strip_expr(deref
->unop
);
195 if (unop
->type
== EXPR_PREOP
&& unop
->op
== '&') {
199 if (!is_pointer(deref
) && !is_pointer(deref
->unop
))
205 __get_variable_from_expr(sym_ptr
, buf
, deref
, len
, complicated
);
208 append(buf
, "->", len
);
210 append(buf
, ".", len
);
213 append(buf
, expr
->member
->name
, len
);
215 append(buf
, "unknown_member", len
);
220 if (expr
->symbol_name
)
221 append(buf
, expr
->symbol_name
->name
, len
);
225 *sym_ptr
= expr
->symbol
;
231 if (get_expression_statement(expr
)) {
236 if (expr
->op
== '(') {
237 if (expr
->unop
->type
!= EXPR_SYMBOL
)
238 append(buf
, "(", len
);
239 } else if (expr
->op
!= '*' || !get_array_expr(expr
->unop
)) {
240 tmp
= show_special(expr
->op
);
241 append(buf
, tmp
, len
);
243 __get_variable_from_expr(sym_ptr
, buf
, expr
->unop
,
246 if (expr
->op
== '(' && expr
->unop
->type
!= EXPR_SYMBOL
)
247 append(buf
, ")", len
);
249 if (expr
->op
== SPECIAL_DECREMENT
||
250 expr
->op
== SPECIAL_INCREMENT
)
258 __get_variable_from_expr(sym_ptr
, buf
, expr
->unop
,
260 tmp
= show_special(expr
->op
);
261 append(buf
, tmp
, len
);
263 if (expr
->op
== SPECIAL_DECREMENT
|| expr
->op
== SPECIAL_INCREMENT
)
267 case EXPR_ASSIGNMENT
:
272 struct expression
*array_expr
;
275 array_expr
= get_array_expr(expr
);
277 __get_variable_from_expr(sym_ptr
, buf
, array_expr
, len
, complicated
);
278 append(buf
, "[", len
);
280 __get_variable_from_expr(sym_ptr
, buf
, expr
->left
, len
, complicated
);
281 snprintf(tmp
, sizeof(tmp
), " %s ", show_special(expr
->op
));
282 append(buf
, tmp
, len
);
284 __get_variable_from_expr(NULL
, buf
, expr
->right
, len
, complicated
);
286 append(buf
, "]", len
);
294 if (!get_value(expr
, &sval
))
296 snprintf(tmp
, 25, "%s", sval_to_numstr(sval
));
297 append(buf
, tmp
, len
);
305 if (!get_value(expr
, &sval
))
307 snprintf(tmp
, 25, "%s", sval_to_numstr(sval
));
308 append(buf
, tmp
, len
);
312 append(buf
, "\"", len
);
314 append(buf
, expr
->string
->data
, len
);
315 append(buf
, "\"", len
);
318 struct expression
*tmp
;
322 __get_variable_from_expr(NULL
, buf
, expr
->fn
, len
, complicated
);
323 append(buf
, "(", len
);
325 FOR_EACH_PTR(expr
->args
, tmp
) {
327 append(buf
, ", ", len
);
328 __get_variable_from_expr(NULL
, buf
, tmp
, len
, complicated
);
329 } END_FOR_EACH_PTR(tmp
);
330 append(buf
, ")", len
);
334 case EXPR_FORCE_CAST
:
335 __get_variable_from_expr(sym_ptr
, buf
,
336 expr
->cast_expression
, len
,
344 if (expr
->cast_type
&& get_base_type(expr
->cast_type
)) {
345 size
= type_bytes(get_base_type(expr
->cast_type
));
346 snprintf(tmp
, 25, "%d", size
);
347 append(buf
, tmp
, len
);
348 } else if (get_value(expr
, &sval
)) {
349 snprintf(tmp
, 25, "%s", sval_to_str(sval
));
350 append(buf
, tmp
, len
);
354 case EXPR_IDENTIFIER
:
356 if (expr
->expr_ident
)
357 append(buf
, expr
->expr_ident
->name
, len
);
360 case EXPR_CONDITIONAL
:
362 append(buf
, "(", len
);
363 __get_variable_from_expr(NULL
, buf
, expr
->conditional
, len
, complicated
);
364 append(buf
, ") ?", len
);
366 __get_variable_from_expr(NULL
, buf
, expr
->cond_true
, len
, complicated
);
367 append(buf
, ":", len
);
368 __get_variable_from_expr(NULL
, buf
, expr
->cond_false
, len
, complicated
);
373 snprintf(tmp
, sizeof(tmp
), "$expr_%p(%d)", expr
, expr
->type
);
374 append(buf
, tmp
, len
);
381 struct expr_str_cache_results
{
382 struct expression
*expr
;
388 static void get_variable_from_expr(struct symbol
**sym_ptr
, char *buf
,
389 struct expression
*expr
, int len
,
392 static struct expr_str_cache_results cached
[8];
393 struct symbol
*tmp_sym
= NULL
;
397 for (i
= 0; i
< ARRAY_SIZE(cached
); i
++) {
398 if (expr
== cached
[i
].expr
) {
399 strncpy(buf
, cached
[i
].str
, len
);
401 *sym_ptr
= cached
[i
].sym
;
402 *complicated
= cached
[i
].complicated
;
407 __get_variable_from_expr(&tmp_sym
, buf
, expr
, len
, complicated
);
411 if (expr
->smatch_flags
& Tmp
)
414 cached
[idx
].expr
= expr
;
415 strncpy(cached
[idx
].str
, buf
, VAR_LEN
);
416 cached
[idx
].sym
= tmp_sym
;
417 cached
[idx
].complicated
= *complicated
;
419 idx
= (idx
+ 1) % ARRAY_SIZE(cached
);
423 * This is returns a stylized "c looking" representation of the
426 * It uses the same buffer every time so you have to save the result
427 * yourself if you want to keep it.
431 char *expr_to_str_sym(struct expression
*expr
, struct symbol
**sym_ptr
)
433 static char var_name
[VAR_LEN
];
442 get_variable_from_expr(sym_ptr
, var_name
, expr
, sizeof(var_name
),
445 return alloc_string(var_name
);
450 char *expr_to_str(struct expression
*expr
)
452 return expr_to_str_sym(expr
, NULL
);
456 * get_variable_from_expr_simple() only returns simple variables.
457 * If it's a complicated variable like a->foo[x] instead of just 'a->foo'
458 * then it returns NULL.
460 char *expr_to_var_sym(struct expression
*expr
,
461 struct symbol
**sym_ptr
)
463 static char var_name
[VAR_LEN
];
472 expr
= strip_expr(expr
);
473 get_variable_from_expr(sym_ptr
, var_name
, expr
, sizeof(var_name
),
481 return alloc_string(var_name
);
484 char *expr_to_var(struct expression
*expr
)
486 return expr_to_var_sym(expr
, NULL
);
489 struct symbol
*expr_to_sym(struct expression
*expr
)
494 name
= expr_to_var_sym(expr
, &sym
);
499 int get_complication_score(struct expression
*expr
)
501 expr
= strip_expr(expr
);
504 * Don't forget to keep get_complication_score() and store_all_links()
512 switch (expr
->type
) {
517 return get_complication_score(expr
->left
) +
518 get_complication_score(expr
->right
);
522 if (expr
->op
== '*' || expr
->op
== '(')
523 return get_complication_score(expr
->unop
);
526 return get_complication_score(expr
->deref
);
535 struct expression
*reorder_expr_alphabetically(struct expression
*expr
)
537 struct expression
*ret
;
540 if (expr
->type
!= EXPR_BINOP
)
542 if (expr
->op
!= '+' && expr
->op
!= '*')
545 left
= expr_to_var(expr
->left
);
546 right
= expr_to_var(expr
->right
);
550 if (strcmp(left
, right
) <= 0)
553 ret
= binop_expression(expr
->right
, expr
->op
, expr
->left
);
561 char *expr_to_chunk_helper(struct expression
*expr
, struct symbol
**sym
, struct var_sym_list
**vsl
)
563 struct var_sym_list
*tmp_vsl
;
573 expr
= strip_parens(expr
);
577 name
= expr_to_var_sym(expr
, &tmp
);
582 add_var_sym(vsl
, name
, tmp
);
587 score
= get_complication_score(expr
);
588 if (score
<= 0 || score
> 2)
591 tmp_vsl
= expr_to_vsl(expr
);
598 if (ptr_list_size((struct ptr_list
*)tmp_vsl
) == 1) {
601 vs
= first_ptr_list((struct ptr_list
*)tmp_vsl
);
606 expr
= reorder_expr_alphabetically(expr
);
608 return expr_to_str(expr
);
611 char *expr_to_known_chunk_sym(struct expression
*expr
, struct symbol
**sym
)
613 return expr_to_chunk_helper(expr
, sym
, NULL
);
616 char *expr_to_chunk_sym_vsl(struct expression
*expr
, struct symbol
**sym
, struct var_sym_list
**vsl
)
618 return expr_to_chunk_helper(expr
, sym
, vsl
);
621 int sym_name_is(const char *name
, struct expression
*expr
)
625 if (expr
->type
!= EXPR_SYMBOL
)
627 if (!strcmp(expr
->symbol_name
->name
, name
))
632 int expr_is_zero(struct expression
*expr
)
636 if (get_value(expr
, &sval
) && sval
.value
== 0)
641 int is_array(struct expression
*expr
)
645 expr
= strip_expr(expr
);
649 if (expr
->type
== EXPR_PREOP
&& expr
->op
== '*') {
650 expr
= strip_expr(expr
->unop
);
653 if (expr
->type
== EXPR_BINOP
&& expr
->op
== '+')
657 if (expr
->type
!= EXPR_BINOP
|| expr
->op
!= '+')
660 type
= get_type(expr
->left
);
661 if (!type
|| type
->type
!= SYM_ARRAY
)
667 struct expression
*get_array_base(struct expression
*expr
)
671 expr
= strip_expr(expr
);
672 if (expr
->type
== EXPR_PREOP
&& expr
->op
== '*')
673 expr
= strip_expr(expr
->unop
);
674 if (expr
->type
!= EXPR_BINOP
|| expr
->op
!= '+')
676 return strip_parens(expr
->left
);
679 struct expression
*get_array_offset(struct expression
*expr
)
683 expr
= strip_expr(expr
);
684 if (expr
->type
== EXPR_PREOP
&& expr
->op
== '*')
685 expr
= strip_expr(expr
->unop
);
686 if (expr
->type
!= EXPR_BINOP
|| expr
->op
!= '+')
688 return strip_parens(expr
->right
);
691 const char *show_state(struct smatch_state
*state
)
698 struct statement
*get_expression_statement(struct expression
*expr
)
700 /* What are those things called? if (({....; ret;})) { ...*/
702 if (expr
->type
!= EXPR_PREOP
)
708 if (expr
->unop
->type
!= EXPR_STATEMENT
)
710 if (expr
->unop
->statement
->type
!= STMT_COMPOUND
)
712 return expr
->unop
->statement
;
715 struct expression
*strip_parens(struct expression
*expr
)
720 if (expr
->type
== EXPR_PREOP
) {
722 return expr
; /* parsing invalid code */
724 if (expr
->op
== '(' && expr
->unop
->type
== EXPR_STATEMENT
&&
725 expr
->unop
->statement
->type
== STMT_COMPOUND
)
728 return strip_parens(expr
->unop
);
733 static struct expression
*strip_expr_helper(struct expression
*expr
, bool set_parent
)
738 switch (expr
->type
) {
739 case EXPR_FORCE_CAST
:
742 expr_set_parent_expr(expr
->cast_expression
, expr
);
744 if (!expr
->cast_expression
)
746 return strip_expr_helper(expr
->cast_expression
, set_parent
);
748 struct expression
*unop
;
750 if (!expr
->unop
) /* parsing invalid code */
753 expr_set_parent_expr(expr
->unop
, expr
);
756 if (expr
->op
== '(' && expr
->unop
->type
== EXPR_STATEMENT
&&
757 expr
->unop
->statement
->type
== STMT_COMPOUND
)
760 unop
= strip_expr_helper(expr
->unop
, set_parent
);
762 if (expr
->op
== '*' && unop
&&
763 unop
->type
== EXPR_PREOP
&& unop
->op
== '&') {
764 struct symbol
*type
= get_type(unop
->unop
);
766 if (type
&& type
->type
== SYM_ARRAY
)
768 return strip_expr_helper(unop
->unop
, set_parent
);
776 case EXPR_CONDITIONAL
:
777 if (known_condition_true(expr
->conditional
)) {
778 if (expr
->cond_true
) {
780 expr_set_parent_expr(expr
->cond_true
, expr
);
781 return strip_expr_helper(expr
->cond_true
, set_parent
);
784 expr_set_parent_expr(expr
->conditional
, expr
);
785 return strip_expr_helper(expr
->conditional
, set_parent
);
787 if (known_condition_false(expr
->conditional
)) {
789 expr_set_parent_expr(expr
->cond_false
, expr
);
790 return strip_expr_helper(expr
->cond_false
, set_parent
);
794 if (sym_name_is("__builtin_expect", expr
->fn
) ||
795 sym_name_is("__builtin_bswap16", expr
->fn
) ||
796 sym_name_is("__builtin_bswap32", expr
->fn
) ||
797 sym_name_is("__builtin_bswap64", expr
->fn
)) {
798 expr
= get_argument_from_call_expr(expr
->args
, 0);
799 return strip_expr_helper(expr
, set_parent
);
806 struct expression
*strip_expr(struct expression
*expr
)
808 return strip_expr_helper(expr
, false);
811 struct expression
*strip_expr_set_parent(struct expression
*expr
)
813 return strip_expr_helper(expr
, true);
816 static void delete_state_tracker(struct tracker
*t
)
818 delete_state(t
->owner
, t
->name
, t
->sym
);
822 void scoped_state(int my_id
, const char *name
, struct symbol
*sym
)
826 t
= alloc_tracker(my_id
, name
, sym
);
827 add_scope_hook((scope_hook
*)&delete_state_tracker
, t
);
830 int is_error_return(struct expression
*expr
)
832 struct symbol
*cur_func
= cur_func_sym
;
833 struct range_list
*rl
;
838 if (cur_func
->type
!= SYM_NODE
)
840 cur_func
= get_base_type(cur_func
);
841 if (cur_func
->type
!= SYM_FN
)
843 cur_func
= get_base_type(cur_func
);
844 if (cur_func
== &void_ctype
)
846 if (option_project
== PROJ_KERNEL
&&
847 get_implied_rl(expr
, &rl
) &&
848 rl_type(rl
) == &int_ctype
&&
849 sval_is_negative(rl_min(rl
)) &&
850 rl_max(rl
).value
== -1)
852 if (!get_implied_value(expr
, &sval
))
856 if (cur_func
->type
== SYM_PTR
&& sval
.value
== 0)
861 int getting_address(struct expression
*expr
)
865 while ((expr
= expr_get_parent_expr(expr
))) {
866 if (expr
->type
== EXPR_PREOP
&& expr
->op
== '*') {
867 /* &foo->bar->baz dereferences "foo->bar" */
868 if (deref_count
== 0)
872 if (expr
->type
== EXPR_PREOP
&& expr
->op
== '&')
878 int get_struct_and_member(struct expression
*expr
, const char **type
, const char **member
)
882 expr
= strip_expr(expr
);
883 if (expr
->type
!= EXPR_DEREF
)
888 sym
= get_type(expr
->deref
);
891 if (sym
->type
== SYM_UNION
)
896 *type
= sym
->ident
->name
;
897 *member
= expr
->member
->name
;
901 char *get_member_name(struct expression
*expr
)
906 expr
= strip_expr(expr
);
907 if (!expr
|| expr
->type
!= EXPR_DEREF
)
912 sym
= get_type(expr
->deref
);
915 if (sym
->type
== SYM_UNION
) {
916 snprintf(buf
, sizeof(buf
), "(union %s)->%s",
917 sym
->ident
? sym
->ident
->name
: "anonymous",
919 return alloc_string(buf
);
922 struct expression
*deref
;
927 * If we're in an anonymous struct then maybe we can find an
928 * outer struct name to use as a name. This code should be
929 * recursive and cleaner. I am not very proud of it.
934 if (deref
->type
!= EXPR_DEREF
|| !deref
->member
)
936 sym
= get_type(deref
->deref
);
937 if (!sym
|| sym
->type
!= SYM_STRUCT
|| !sym
->ident
)
940 full
= expr_to_str(expr
);
943 deref
= deref
->deref
;
944 if (deref
->type
== EXPR_PREOP
&& deref
->op
== '*')
946 outer
= expr_to_str(deref
);
952 if (strncmp(outer
, full
, len
) != 0) {
957 if (full
[len
] == '-' && full
[len
+ 1] == '>')
959 if (full
[len
] == '.')
961 snprintf(buf
, sizeof(buf
), "(struct %s)->%s", sym
->ident
->name
, full
+ len
);
965 return alloc_string(buf
);
967 snprintf(buf
, sizeof(buf
), "(struct %s)->%s", sym
->ident
->name
, expr
->member
->name
);
968 return alloc_string(buf
);
971 int cmp_pos(struct position pos1
, struct position pos2
)
973 /* the stream position is ... */
974 if (pos1
.stream
> pos2
.stream
)
976 if (pos1
.stream
< pos2
.stream
)
979 if (pos1
.line
< pos2
.line
)
981 if (pos1
.line
> pos2
.line
)
984 if (pos1
.pos
< pos2
.pos
)
986 if (pos1
.pos
> pos2
.pos
)
992 int positions_eq(struct position pos1
, struct position pos2
)
994 if (pos1
.line
!= pos2
.line
)
996 if (pos1
.pos
!= pos2
.pos
)
998 if (pos1
.stream
!= pos2
.stream
)
1003 struct statement
*get_current_statement(void)
1005 struct statement
*prev
, *tmp
;
1007 prev
= last_ptr_list((struct ptr_list
*)big_statement_stack
);
1009 if (!prev
|| !get_macro_name(prev
->pos
))
1012 FOR_EACH_PTR_REVERSE(big_statement_stack
, tmp
) {
1013 if (positions_eq(tmp
->pos
, prev
->pos
))
1015 if (prev
->pos
.line
> tmp
->pos
.line
)
1018 } END_FOR_EACH_PTR_REVERSE(tmp
);
1022 struct statement
*get_prev_statement(void)
1024 struct statement
*tmp
;
1028 FOR_EACH_PTR_REVERSE(big_statement_stack
, tmp
) {
1031 } END_FOR_EACH_PTR_REVERSE(tmp
);
1035 struct expression
*get_last_expr_from_expression_stmt(struct expression
*expr
)
1037 struct statement
*stmt
;
1038 struct statement
*last_stmt
;
1040 while (expr
->type
== EXPR_PREOP
&& expr
->op
== '(')
1042 if (expr
->type
!= EXPR_STATEMENT
)
1044 stmt
= expr
->statement
;
1047 if (stmt
->type
== STMT_COMPOUND
) {
1048 last_stmt
= last_ptr_list((struct ptr_list
*)stmt
->stmts
);
1051 if (last_stmt
->type
== STMT_LABEL
)
1052 last_stmt
= last_stmt
->label_statement
;
1053 if (last_stmt
->type
!= STMT_EXPRESSION
)
1055 return last_stmt
->expression
;
1057 if (stmt
->type
== STMT_EXPRESSION
)
1058 return stmt
->expression
;
1062 int ms_since(struct timeval
*start
)
1067 gettimeofday(&end
, NULL
);
1068 diff
= (end
.tv_sec
- start
->tv_sec
) * 1000.0;
1069 diff
+= (end
.tv_usec
- start
->tv_usec
) / 1000.0;
1073 int parent_is_gone_var_sym(const char *name
, struct symbol
*sym
)
1078 if (parent_is_null_var_sym(name
, sym
) ||
1079 parent_is_free_var_sym(name
, sym
))
1084 int parent_is_gone(struct expression
*expr
)
1090 expr
= strip_expr(expr
);
1091 var
= expr_to_var_sym(expr
, &sym
);
1094 ret
= parent_is_gone_var_sym(var
, sym
);
1100 int invert_op(int op
)
1111 case SPECIAL_LEFTSHIFT
:
1112 return SPECIAL_RIGHTSHIFT
;
1113 case SPECIAL_RIGHTSHIFT
:
1114 return SPECIAL_LEFTSHIFT
;
1119 int op_remove_assign(int op
)
1122 case SPECIAL_ADD_ASSIGN
:
1124 case SPECIAL_SUB_ASSIGN
:
1126 case SPECIAL_MUL_ASSIGN
:
1128 case SPECIAL_DIV_ASSIGN
:
1130 case SPECIAL_MOD_ASSIGN
:
1132 case SPECIAL_AND_ASSIGN
:
1134 case SPECIAL_OR_ASSIGN
:
1136 case SPECIAL_XOR_ASSIGN
:
1138 case SPECIAL_SHL_ASSIGN
:
1139 return SPECIAL_LEFTSHIFT
;
1140 case SPECIAL_SHR_ASSIGN
:
1141 return SPECIAL_RIGHTSHIFT
;
1147 int expr_equiv(struct expression
*one
, struct expression
*two
)
1149 struct symbol
*one_sym
= NULL
;
1150 struct symbol
*two_sym
= NULL
;
1151 char *one_name
= NULL
;
1152 char *two_name
= NULL
;
1157 if (one
->type
!= two
->type
)
1159 if (is_fake_call(one
) || is_fake_call(two
))
1162 one_name
= expr_to_str_sym(one
, &one_sym
);
1165 two_name
= expr_to_str_sym(two
, &two_sym
);
1168 if (one_sym
!= two_sym
)
1171 * This is a terrible hack because expr_to_str() sometimes gives up in
1172 * the middle and just returns what it has. If you see a () you know
1173 * the string is bogus.
1175 if (strstr(one_name
, "()"))
1177 if (strcmp(one_name
, two_name
) == 0)
1180 free_string(one_name
);
1181 free_string(two_name
);
1185 void push_int(struct int_stack
**stack
, int num
)
1190 * Just put the int on directly instead of a pointer to the int.
1191 * Shift it to the left because Sparse uses the last two bits.
1192 * This is sort of a dirty hack, yes.
1195 munged
= INT_PTR(num
<< 2);
1197 add_ptr_list(stack
, munged
);
1200 int pop_int(struct int_stack
**stack
)
1204 num
= last_ptr_list((struct ptr_list
*)*stack
);
1205 delete_ptr_list_last((struct ptr_list
**)stack
);
1207 return PTR_INT(num
) >> 2;