Built-in DLLs resources are now specified in spec file.
[wine/multimedia.git] / debugger / expr.c
blobfbee595d173acd543cb5d976a3481e61755d80a2
1 /*
2 * File expr.c - expression handling for Wine internal debugger.
4 * Copyright (C) 1997, Eric Youngdale.
6 */
8 #include "config.h"
9 #include <stdlib.h>
10 #include <stdio.h>
11 #include <string.h>
12 #include <assert.h>
13 #include "winbase.h"
14 #include "wine/winbase16.h"
15 #include "task.h"
16 #include "debugger.h"
17 #include "expr.h"
19 #include <stdarg.h>
21 struct expr
23 unsigned int perm;
24 unsigned int type:31;
25 union
27 struct
29 int value;
30 } constant;
32 struct
34 const char * str;
35 } string;
37 struct
39 unsigned int value;
40 } u_const;
42 struct
44 const char * name;
45 } symbol;
47 struct
49 enum debug_regs reg;
50 int result;
51 } rgister;
53 struct
55 int unop_type;
56 struct expr * exp1;
57 int result;
58 } unop;
60 struct
62 int binop_type;
63 int result;
64 struct expr * exp1;
65 struct expr * exp2;
66 } binop;
68 struct
70 struct datatype * cast;
71 struct expr * expr;
72 } cast;
74 struct
76 struct expr * exp1;
77 const char * element_name;
78 int result;
79 } structure;
81 struct
83 struct expr * base;
84 struct expr * index;
85 } array;
87 struct
89 const char * funcname;
90 int nargs;
91 int result;
92 struct expr * arg[5];
93 } call;
95 } un;
98 #define EXPR_TYPE_CONST 0
99 #define EXPR_TYPE_US_CONST 1
100 #define EXPR_TYPE_SYMBOL 2
101 #define EXPR_TYPE_REGISTER 3
102 #define EXPR_TYPE_BINOP 4
103 #define EXPR_TYPE_UNOP 5
104 #define EXPR_TYPE_STRUCT 6
105 #define EXPR_TYPE_PSTRUCT 7
106 #define EXPR_TYPE_ARRAY 8
107 #define EXPR_TYPE_CALL 9
108 #define EXPR_TYPE_STRING 10
109 #define EXPR_TYPE_CAST 11
111 static char expr_list[4096];
112 static int next_expr_free = 0;
115 * This is how we turn an expression address into the actual value.
116 * This works well in the 32 bit domain - not sure at all about the
117 * 16 bit world.
119 #define VAL(_exp) DEBUG_GetExprValue(&_exp, NULL)
121 static
122 struct expr *
123 DEBUG_GetFreeExpr()
125 struct expr * rtn;
127 rtn = (struct expr *) &expr_list[next_expr_free];
129 next_expr_free += sizeof(struct expr);
130 assert(next_expr_free < sizeof(expr_list));
132 return rtn;
135 void
136 DEBUG_FreeExprMem()
138 next_expr_free = 0;
141 struct expr *
142 DEBUG_TypeCastExpr(struct datatype * dt, struct expr * exp)
144 struct expr * ex;
146 ex = DEBUG_GetFreeExpr();
148 ex->type = EXPR_TYPE_CAST;
149 ex->un.cast.cast = dt;
150 ex->un.cast.expr = exp;
151 return ex;
154 struct expr *
155 DEBUG_RegisterExpr(enum debug_regs regno)
157 struct expr * ex;
159 ex = DEBUG_GetFreeExpr();
161 ex->type = EXPR_TYPE_REGISTER;
162 ex->un.rgister.reg = regno;
163 return ex;
166 struct expr *
167 DEBUG_SymbolExpr(const char * name)
169 struct expr * ex;
171 ex = DEBUG_GetFreeExpr();
173 ex->type = EXPR_TYPE_SYMBOL;
174 ex->un.symbol.name = name;
175 return ex;
178 struct expr *
179 DEBUG_ConstExpr(int value)
181 struct expr * ex;
183 ex = DEBUG_GetFreeExpr();
185 ex->type = EXPR_TYPE_CONST;
186 ex->un.constant.value = value;
187 return ex;
190 struct expr *
191 DEBUG_StringExpr(const char * str)
193 struct expr * ex;
194 char * pnt;
195 ex = DEBUG_GetFreeExpr();
197 ex->type = EXPR_TYPE_STRING;
198 ex->un.string.str = str+1;
199 pnt = strrchr(ex->un.string.str, '"');
200 if( pnt != NULL )
202 *pnt = '\0';
204 return ex;
207 struct expr *
208 DEBUG_USConstExpr(unsigned int value)
210 struct expr * ex;
212 ex = DEBUG_GetFreeExpr();
214 ex->type = EXPR_TYPE_CONST;
215 ex->un.u_const.value = value;
216 return ex;
219 struct expr *
220 DEBUG_BinopExpr(int operator_type, struct expr * exp1, struct expr * exp2)
222 struct expr * ex;
224 ex = DEBUG_GetFreeExpr();
226 ex->type = EXPR_TYPE_BINOP;
227 ex->un.binop.binop_type = operator_type;
228 ex->un.binop.exp1 = exp1;
229 ex->un.binop.exp2 = exp2;
230 return ex;
233 struct expr *
234 DEBUG_UnopExpr(int operator_type, struct expr * exp1)
236 struct expr * ex;
238 ex = DEBUG_GetFreeExpr();
240 ex->type = EXPR_TYPE_UNOP;
241 ex->un.unop.unop_type = operator_type;
242 ex->un.unop.exp1 = exp1;
243 return ex;
246 struct expr *
247 DEBUG_StructExpr(struct expr * exp, const char * element)
249 struct expr * ex;
251 ex = DEBUG_GetFreeExpr();
253 ex->type = EXPR_TYPE_STRUCT;
254 ex->un.structure.exp1 = exp;
255 ex->un.structure.element_name = element;
256 return ex;
259 struct expr *
260 DEBUG_StructPExpr(struct expr * exp, const char * element)
262 struct expr * ex;
264 ex = DEBUG_GetFreeExpr();
266 ex->type = EXPR_TYPE_PSTRUCT;
267 ex->un.structure.exp1 = exp;
268 ex->un.structure.element_name = element;
269 return ex;
272 struct expr *
273 DEBUG_CallExpr(const char * funcname, int nargs, ...)
275 struct expr * ex;
276 va_list ap;
277 int i;
279 ex = DEBUG_GetFreeExpr();
281 ex->type = EXPR_TYPE_CALL;
282 ex->un.call.funcname = funcname;
283 ex->un.call.nargs = nargs;
285 va_start(ap, nargs);
286 for(i=0; i < nargs; i++)
288 ex->un.call.arg[i] = va_arg(ap, struct expr *);
290 va_end(ap);
291 return ex;
294 DBG_ADDR
295 DEBUG_EvalExpr(struct expr * exp)
297 DBG_ADDR rtn;
298 int i;
299 DBG_ADDR exp1;
300 DBG_ADDR exp2;
301 unsigned int cexp[5];
302 int (*fptr)();
303 int scale1;
304 int scale2;
305 int scale3;
306 struct datatype * type1;
307 struct datatype * type2;
309 rtn.type = NULL;
310 rtn.off = NULL;
311 rtn.seg = NULL;
313 switch(exp->type)
315 case EXPR_TYPE_CAST:
316 rtn = DEBUG_EvalExpr(exp->un.cast.expr);
317 rtn.type = exp->un.cast.cast;
318 break;
319 case EXPR_TYPE_STRING:
320 rtn.type = DEBUG_TypeString;
321 rtn.off = (unsigned int) &exp->un.string.str;
322 rtn.seg = 0;
323 break;
324 case EXPR_TYPE_CONST:
325 rtn.type = DEBUG_TypeIntConst;
326 rtn.off = (unsigned int) &exp->un.constant.value;
327 rtn.seg = 0;
328 break;
329 case EXPR_TYPE_US_CONST:
330 rtn.type = DEBUG_TypeUSInt;
331 rtn.off = (unsigned int) &exp->un.u_const.value;
332 rtn.seg = 0;
333 break;
334 case EXPR_TYPE_SYMBOL:
335 if( !DEBUG_GetSymbolValue(exp->un.symbol.name, -1, &rtn, FALSE ) )
337 rtn.type = NULL;
338 rtn.off = 0;
339 rtn.seg = 0;
341 break;
342 case EXPR_TYPE_PSTRUCT:
343 exp1 = DEBUG_EvalExpr(exp->un.structure.exp1);
344 if( exp1.type == NULL )
346 break;
348 rtn.off = DEBUG_TypeDerefPointer(&exp1, &type1);
349 if( type1 == NULL )
351 break;
353 rtn.type = type1;
354 DEBUG_FindStructElement(&rtn, exp->un.structure.element_name,
355 &exp->un.structure.result);
356 break;
357 case EXPR_TYPE_STRUCT:
358 exp1 = DEBUG_EvalExpr(exp->un.structure.exp1);
359 if( exp1.type == NULL )
361 break;
363 rtn = exp1;
364 DEBUG_FindStructElement(&rtn, exp->un.structure.element_name,
365 &exp->un.structure.result);
366 break;
367 case EXPR_TYPE_CALL:
369 * First, evaluate all of the arguments. If any of them are not
370 * evaluable, then bail.
372 for(i=0; i < exp->un.call.nargs; i++)
374 exp1 = DEBUG_EvalExpr(exp->un.call.arg[i]);
375 if( exp1.type == NULL )
377 return rtn;
379 cexp[i] = DEBUG_GetExprValue(&exp1, NULL);
383 * Now look up the address of the function itself.
385 if( !DEBUG_GetSymbolValue(exp->un.call.funcname, -1, &rtn, FALSE ) )
387 fprintf(stderr, "Failed to find symbol\n");
388 break;
391 fptr = (int (*)()) rtn.off;
392 switch(exp->un.call.nargs)
394 case 0:
395 exp->un.call.result = (*fptr)();
396 break;
397 case 1:
398 exp->un.call.result = (*fptr)(cexp[0]);
399 break;
400 case 2:
401 exp->un.call.result = (*fptr)(cexp[0], cexp[1]);
402 break;
403 case 3:
404 exp->un.call.result = (*fptr)(cexp[0], cexp[1], cexp[2]);
405 break;
406 case 4:
407 exp->un.call.result = (*fptr)(cexp[0], cexp[1], cexp[2], cexp[3]);
408 break;
409 case 5:
410 exp->un.call.result = (*fptr)(cexp[0], cexp[1], cexp[2], cexp[3], cexp[4]);
411 break;
413 rtn.type = DEBUG_TypeInt;
414 rtn.off = (unsigned int) &exp->un.call.result;
415 break;
416 case EXPR_TYPE_REGISTER:
417 rtn.type = DEBUG_TypeIntConst;
418 exp->un.rgister.result = DEBUG_GetRegister(exp->un.rgister.reg);
419 rtn.off = (unsigned int) &exp->un.rgister.result;
420 #ifdef __i386__
421 if( exp->un.rgister.reg == REG_EIP )
422 rtn.seg = CS_reg(&DEBUG_context);
423 else
424 rtn.seg = DS_reg(&DEBUG_context);
425 #endif
426 DBG_FIX_ADDR_SEG( &rtn, 0 );
427 break;
428 case EXPR_TYPE_BINOP:
429 exp1 = DEBUG_EvalExpr(exp->un.binop.exp1);
430 exp2 = DEBUG_EvalExpr(exp->un.binop.exp2);
431 if( exp1.type == NULL || exp2.type == NULL )
433 break;
435 if( exp1.type == DEBUG_TypeIntConst && exp2.type == DEBUG_TypeIntConst )
437 rtn.type = exp1.type;
439 else
441 rtn.type = DEBUG_TypeInt;
443 rtn.off = (unsigned int) &exp->un.binop.result;
444 switch(exp->un.binop.binop_type)
446 case EXP_OP_ADD:
447 type1 = DEBUG_GetPointerType(exp1.type);
448 type2 = DEBUG_GetPointerType(exp2.type);
449 scale1 = 1;
450 scale2 = 1;
451 if( type1 != NULL && type2 != NULL )
453 break;
455 else if( type1 != NULL )
457 scale2 = DEBUG_GetObjectSize(type1);
458 rtn.type = exp1.type;
460 else if( type2 != NULL )
462 scale1 = DEBUG_GetObjectSize(type2);
463 rtn.type = exp2.type;
465 rtn.seg = 0;
466 exp->un.binop.result = (VAL(exp1) * scale1 + scale2 * VAL(exp2));
467 break;
468 case EXP_OP_SUB:
469 type1 = DEBUG_GetPointerType(exp1.type);
470 type2 = DEBUG_GetPointerType(exp2.type);
471 scale1 = 1;
472 scale2 = 1;
473 scale3 = 1;
474 if( type1 != NULL && type2 != NULL )
476 if( type1 != type2 )
478 break;
480 scale3 = DEBUG_GetObjectSize(type1);
482 else if( type1 != NULL )
484 scale2 = DEBUG_GetObjectSize(type1);
485 rtn.type = exp1.type;
488 else if( type2 != NULL )
490 scale1 = DEBUG_GetObjectSize(type2);
491 rtn.type = exp2.type;
493 rtn.seg = 0;
494 exp->un.binop.result = (VAL(exp1) - VAL(exp2)) / scale3;
495 break;
496 case EXP_OP_SEG:
497 rtn.seg = VAL(exp1);
498 exp->un.binop.result = VAL(exp2);
499 #ifdef __i386__
500 if (ISV86(&DEBUG_context)) {
501 TDB *pTask = (TDB*)GlobalLock16( GetCurrentTask() );
502 rtn.seg |= (DWORD)(pTask?(pTask->hModule):0)<<16;
503 GlobalUnlock16( GetCurrentTask() );
505 #endif
506 break;
507 case EXP_OP_LOR:
508 rtn.seg = 0;
509 exp->un.binop.result = (VAL(exp1) || VAL(exp2));
510 break;
511 case EXP_OP_LAND:
512 rtn.seg = 0;
513 exp->un.binop.result = (VAL(exp1) && VAL(exp2));
514 break;
515 case EXP_OP_OR:
516 rtn.seg = 0;
517 exp->un.binop.result = (VAL(exp1) | VAL(exp2));
518 break;
519 case EXP_OP_AND:
520 rtn.seg = 0;
521 exp->un.binop.result = (VAL(exp1) & VAL(exp2));
522 break;
523 case EXP_OP_XOR:
524 rtn.seg = 0;
525 exp->un.binop.result = (VAL(exp1) ^ VAL(exp2));
526 break;
527 case EXP_OP_EQ:
528 rtn.seg = 0;
529 exp->un.binop.result = (VAL(exp1) == VAL(exp2));
530 break;
531 case EXP_OP_GT:
532 rtn.seg = 0;
533 exp->un.binop.result = (VAL(exp1) > VAL(exp2));
534 break;
535 case EXP_OP_LT:
536 rtn.seg = 0;
537 exp->un.binop.result = (VAL(exp1) < VAL(exp2));
538 break;
539 case EXP_OP_GE:
540 rtn.seg = 0;
541 exp->un.binop.result = (VAL(exp1) >= VAL(exp2));
542 break;
543 case EXP_OP_LE:
544 rtn.seg = 0;
545 exp->un.binop.result = (VAL(exp1) <= VAL(exp2));
546 break;
547 case EXP_OP_NE:
548 rtn.seg = 0;
549 exp->un.binop.result = (VAL(exp1) != VAL(exp2));
550 break;
551 case EXP_OP_SHL:
552 rtn.seg = 0;
553 exp->un.binop.result = ((unsigned) VAL(exp1) << VAL(exp2));
554 break;
555 case EXP_OP_SHR:
556 rtn.seg = 0;
557 exp->un.binop.result = ((unsigned) VAL(exp1) >> VAL(exp2));
558 break;
559 case EXP_OP_MUL:
560 rtn.seg = 0;
561 exp->un.binop.result = (VAL(exp1) * VAL(exp2));
562 break;
563 case EXP_OP_DIV:
564 if( VAL(exp2) != 0 )
566 rtn.seg = 0;
567 exp->un.binop.result = (VAL(exp1) / VAL(exp2));
569 else
571 rtn.seg = 0;
572 rtn.type = NULL;
573 rtn.off = 0;
575 break;
576 case EXP_OP_REM:
577 if( VAL(exp2) != 0 )
579 rtn.seg = 0;
580 exp->un.binop.result = (VAL(exp1) % VAL(exp2));
582 else
584 rtn.seg = 0;
585 rtn.type = NULL;
586 rtn.off = 0;
588 break;
589 case EXP_OP_ARR:
590 DEBUG_ArrayIndex(&exp1, &rtn, VAL(exp2));
591 break;
592 default:
593 break;
595 break;
596 case EXPR_TYPE_UNOP:
597 exp1 = DEBUG_EvalExpr(exp->un.unop.exp1);
598 if( exp1.type == NULL )
600 break;
602 rtn.off = (unsigned int) &exp->un.unop.result;
603 if( exp1.type == DEBUG_TypeIntConst )
605 rtn.type = exp1.type;
607 else
609 rtn.type = DEBUG_TypeInt;
611 switch(exp->un.unop.unop_type)
613 case EXP_OP_NEG:
614 rtn.seg = 0;
615 exp->un.unop.result = -VAL(exp1);
616 break;
617 case EXP_OP_NOT:
618 rtn.seg = 0;
619 exp->un.unop.result = !VAL(exp1);
620 break;
621 case EXP_OP_LNOT:
622 rtn.seg = 0;
623 exp->un.unop.result = ~VAL(exp1);
624 break;
625 case EXP_OP_DEREF:
626 rtn.seg = 0;
627 rtn.off = (unsigned int) DEBUG_TypeDerefPointer(&exp1, &rtn.type);
628 break;
629 case EXP_OP_FORCE_DEREF:
630 rtn.seg = exp1.seg;
631 rtn.off = *(unsigned int *) exp1.off;
632 break;
633 case EXP_OP_ADDR:
634 rtn.seg = 0;
635 rtn.type = DEBUG_FindOrMakePointerType(exp1.type);
636 exp->un.unop.result = exp1.off;
637 break;
639 break;
640 default:
641 fprintf(stderr,"Unexpected expression.\n");
642 DEBUG_Exit(123);
643 break;
646 return rtn;
651 DEBUG_DisplayExpr(struct expr * exp)
653 int i;
656 switch(exp->type)
658 case EXPR_TYPE_CAST:
659 fprintf(stderr, "((");
660 DEBUG_PrintTypeCast(exp->un.cast.cast);
661 fprintf(stderr, ")");
662 DEBUG_DisplayExpr(exp->un.cast.expr);
663 fprintf(stderr, ")");
664 break;
665 case EXPR_TYPE_REGISTER:
666 DEBUG_PrintRegister(exp->un.rgister.reg);
667 break;
668 case EXPR_TYPE_US_CONST:
669 fprintf(stderr, "%ud", exp->un.u_const.value);
670 break;
671 case EXPR_TYPE_CONST:
672 fprintf(stderr, "%d", exp->un.u_const.value);
673 break;
674 case EXPR_TYPE_STRING:
675 fprintf(stderr, "\"%s\"", exp->un.string.str);
676 break;
677 case EXPR_TYPE_SYMBOL:
678 fprintf(stderr, "%s" , exp->un.symbol.name);
679 break;
680 case EXPR_TYPE_PSTRUCT:
681 DEBUG_DisplayExpr(exp->un.structure.exp1);
682 fprintf(stderr, "->%s", exp->un.structure.element_name);
683 break;
684 case EXPR_TYPE_STRUCT:
685 DEBUG_DisplayExpr(exp->un.structure.exp1);
686 fprintf(stderr, ".%s", exp->un.structure.element_name);
687 break;
688 case EXPR_TYPE_CALL:
690 * First, evaluate all of the arguments. If any of them are not
691 * evaluable, then bail.
693 fprintf(stderr, "%s(",exp->un.call.funcname);
694 for(i=0; i < exp->un.call.nargs; i++)
696 DEBUG_DisplayExpr(exp->un.call.arg[i]);
697 if( i != exp->un.call.nargs - 1 )
699 fprintf(stderr, ", ");
702 fprintf(stderr, ")");
703 break;
704 case EXPR_TYPE_BINOP:
705 fprintf(stderr, "( ");
706 DEBUG_DisplayExpr(exp->un.binop.exp1);
707 switch(exp->un.binop.binop_type)
709 case EXP_OP_ADD:
710 fprintf(stderr, " + ");
711 break;
712 case EXP_OP_SUB:
713 fprintf(stderr, " - ");
714 break;
715 case EXP_OP_SEG:
716 fprintf(stderr, ":");
717 break;
718 case EXP_OP_LOR:
719 fprintf(stderr, " || ");
720 break;
721 case EXP_OP_LAND:
722 fprintf(stderr, " && ");
723 break;
724 case EXP_OP_OR:
725 fprintf(stderr, " | ");
726 break;
727 case EXP_OP_AND:
728 fprintf(stderr, " & ");
729 break;
730 case EXP_OP_XOR:
731 fprintf(stderr, " ^ ");
732 break;
733 case EXP_OP_EQ:
734 fprintf(stderr, " == ");
735 break;
736 case EXP_OP_GT:
737 fprintf(stderr, " > ");
738 break;
739 case EXP_OP_LT:
740 fprintf(stderr, " < ");
741 break;
742 case EXP_OP_GE:
743 fprintf(stderr, " >= ");
744 break;
745 case EXP_OP_LE:
746 fprintf(stderr, " <= ");
747 break;
748 case EXP_OP_NE:
749 fprintf(stderr, " != ");
750 break;
751 case EXP_OP_SHL:
752 fprintf(stderr, " << ");
753 break;
754 case EXP_OP_SHR:
755 fprintf(stderr, " >> ");
756 break;
757 case EXP_OP_MUL:
758 fprintf(stderr, " * ");
759 break;
760 case EXP_OP_DIV:
761 fprintf(stderr, " / ");
762 break;
763 case EXP_OP_REM:
764 fprintf(stderr, " %% ");
765 break;
766 case EXP_OP_ARR:
767 fprintf(stderr, "[");
768 break;
769 default:
770 break;
772 DEBUG_DisplayExpr(exp->un.binop.exp2);
773 if( exp->un.binop.binop_type == EXP_OP_ARR )
775 fprintf(stderr, "]");
777 fprintf(stderr, " )");
778 break;
779 case EXPR_TYPE_UNOP:
780 switch(exp->un.unop.unop_type)
782 case EXP_OP_NEG:
783 fprintf(stderr, "-");
784 break;
785 case EXP_OP_NOT:
786 fprintf(stderr, "!");
787 break;
788 case EXP_OP_LNOT:
789 fprintf(stderr, "~");
790 break;
791 case EXP_OP_DEREF:
792 fprintf(stderr, "*");
793 break;
794 case EXP_OP_ADDR:
795 fprintf(stderr, "&");
796 break;
798 DEBUG_DisplayExpr(exp->un.unop.exp1);
799 break;
800 default:
801 fprintf(stderr,"Unexpected expression.\n");
802 DEBUG_Exit(123);
803 break;
806 return TRUE;
809 struct expr *
810 DEBUG_CloneExpr(struct expr * exp)
812 int i;
813 struct expr * rtn;
815 rtn = (struct expr *) DBG_alloc(sizeof(struct expr));
818 * First copy the contents of the expression itself.
820 *rtn = *exp;
823 switch(exp->type)
825 case EXPR_TYPE_CAST:
826 rtn->un.cast.expr = DEBUG_CloneExpr(exp->un.cast.expr);
827 break;
828 case EXPR_TYPE_REGISTER:
829 case EXPR_TYPE_US_CONST:
830 case EXPR_TYPE_CONST:
831 break;
832 case EXPR_TYPE_STRING:
833 rtn->un.string.str = DBG_strdup(exp->un.string.str);
834 break;
835 case EXPR_TYPE_SYMBOL:
836 rtn->un.symbol.name = DBG_strdup(exp->un.symbol.name);
837 break;
838 case EXPR_TYPE_PSTRUCT:
839 case EXPR_TYPE_STRUCT:
840 rtn->un.structure.exp1 = DEBUG_CloneExpr(exp->un.structure.exp1);
841 rtn->un.structure.element_name = DBG_strdup(exp->un.structure.element_name);
842 break;
843 case EXPR_TYPE_CALL:
845 * First, evaluate all of the arguments. If any of them are not
846 * evaluable, then bail.
848 for(i=0; i < exp->un.call.nargs; i++)
850 rtn->un.call.arg[i] = DEBUG_CloneExpr(exp->un.call.arg[i]);
852 rtn->un.call.funcname = DBG_strdup(exp->un.call.funcname);
853 break;
854 case EXPR_TYPE_BINOP:
855 rtn->un.binop.exp1 = DEBUG_CloneExpr(exp->un.binop.exp1);
856 rtn->un.binop.exp2 = DEBUG_CloneExpr(exp->un.binop.exp2);
857 break;
858 case EXPR_TYPE_UNOP:
859 rtn->un.unop.exp1 = DEBUG_CloneExpr(exp->un.unop.exp1);
860 break;
861 default:
862 fprintf(stderr,"Unexpected expression.\n");
863 DEBUG_Exit(123);
864 break;
867 return rtn;
872 * Recursively go through an expression tree and free all memory associated
873 * with it.
876 DEBUG_FreeExpr(struct expr * exp)
878 int i;
880 switch(exp->type)
882 case EXPR_TYPE_CAST:
883 DEBUG_FreeExpr(exp->un.cast.expr);
884 break;
885 case EXPR_TYPE_REGISTER:
886 case EXPR_TYPE_US_CONST:
887 case EXPR_TYPE_CONST:
888 break;
889 case EXPR_TYPE_STRING:
890 DBG_free((char *) exp->un.string.str);
891 break;
892 case EXPR_TYPE_SYMBOL:
893 DBG_free((char *) exp->un.symbol.name);
894 break;
895 case EXPR_TYPE_PSTRUCT:
896 case EXPR_TYPE_STRUCT:
897 DEBUG_FreeExpr(exp->un.structure.exp1);
898 DBG_free((char *) exp->un.structure.element_name);
899 break;
900 case EXPR_TYPE_CALL:
902 * First, evaluate all of the arguments. If any of them are not
903 * evaluable, then bail.
905 for(i=0; i < exp->un.call.nargs; i++)
907 DEBUG_FreeExpr(exp->un.call.arg[i]);
909 DBG_free((char *) exp->un.call.funcname);
910 break;
911 case EXPR_TYPE_BINOP:
912 DEBUG_FreeExpr(exp->un.binop.exp1);
913 DEBUG_FreeExpr(exp->un.binop.exp2);
914 break;
915 case EXPR_TYPE_UNOP:
916 DEBUG_FreeExpr(exp->un.unop.exp1);
917 break;
918 default:
919 fprintf(stderr,"Unexpected expression.\n");
920 DEBUG_Exit(123);
921 break;
924 DBG_free(exp);
925 return TRUE;