Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 1 | /* |
| 2 | * File expr.c - expression handling for Wine internal debugger. |
| 3 | * |
| 4 | * Copyright (C) 1997, Eric Youngdale. |
| 5 | * |
| 6 | */ |
| 7 | |
Marcus Meissner | b0d52b0 | 1999-02-28 19:59:00 +0000 | [diff] [blame] | 8 | #include "config.h" |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 9 | #include <stdlib.h> |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 10 | #include <string.h> |
Marcus Meissner | 88354d9 | 1999-10-24 20:44:38 +0000 | [diff] [blame] | 11 | #include "winbase.h" |
Marcus Meissner | 317af32 | 1999-02-17 13:51:06 +0000 | [diff] [blame] | 12 | #include "wine/winbase16.h" |
Ove Kaaven | 69df371 | 1998-10-11 12:27:04 +0000 | [diff] [blame] | 13 | #include "task.h" |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 14 | #include "debugger.h" |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 15 | #include "expr.h" |
| 16 | |
| 17 | #include <stdarg.h> |
| 18 | |
| 19 | struct expr |
| 20 | { |
| 21 | unsigned int perm; |
| 22 | unsigned int type:31; |
| 23 | union |
| 24 | { |
| 25 | struct |
| 26 | { |
| 27 | int value; |
| 28 | } constant; |
| 29 | |
| 30 | struct |
| 31 | { |
| 32 | const char * str; |
| 33 | } string; |
| 34 | |
| 35 | struct |
| 36 | { |
| 37 | unsigned int value; |
| 38 | } u_const; |
| 39 | |
| 40 | struct |
| 41 | { |
| 42 | const char * name; |
| 43 | } symbol; |
| 44 | |
| 45 | struct |
| 46 | { |
Eric Pouech | 04c16b8 | 2000-04-30 12:21:15 +0000 | [diff] [blame] | 47 | const char * name; |
| 48 | } intvar; |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 49 | |
| 50 | struct |
| 51 | { |
| 52 | int unop_type; |
| 53 | struct expr * exp1; |
| 54 | int result; |
| 55 | } unop; |
| 56 | |
| 57 | struct |
| 58 | { |
| 59 | int binop_type; |
| 60 | int result; |
| 61 | struct expr * exp1; |
| 62 | struct expr * exp2; |
| 63 | } binop; |
| 64 | |
| 65 | struct |
| 66 | { |
Alexandre Julliard | 01d6346 | 1997-01-20 19:43:45 +0000 | [diff] [blame] | 67 | struct datatype * cast; |
| 68 | struct expr * expr; |
| 69 | } cast; |
| 70 | |
| 71 | struct |
| 72 | { |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 73 | struct expr * exp1; |
| 74 | const char * element_name; |
| 75 | int result; |
| 76 | } structure; |
| 77 | |
| 78 | struct |
| 79 | { |
| 80 | struct expr * base; |
| 81 | struct expr * index; |
| 82 | } array; |
| 83 | |
| 84 | struct |
| 85 | { |
| 86 | const char * funcname; |
| 87 | int nargs; |
| 88 | int result; |
| 89 | struct expr * arg[5]; |
| 90 | } call; |
| 91 | |
| 92 | } un; |
| 93 | }; |
| 94 | |
| 95 | #define EXPR_TYPE_CONST 0 |
| 96 | #define EXPR_TYPE_US_CONST 1 |
| 97 | #define EXPR_TYPE_SYMBOL 2 |
Eric Pouech | 04c16b8 | 2000-04-30 12:21:15 +0000 | [diff] [blame] | 98 | #define EXPR_TYPE_INTVAR 3 |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 99 | #define EXPR_TYPE_BINOP 4 |
| 100 | #define EXPR_TYPE_UNOP 5 |
| 101 | #define EXPR_TYPE_STRUCT 6 |
| 102 | #define EXPR_TYPE_PSTRUCT 7 |
| 103 | #define EXPR_TYPE_ARRAY 8 |
| 104 | #define EXPR_TYPE_CALL 9 |
| 105 | #define EXPR_TYPE_STRING 10 |
Alexandre Julliard | 01d6346 | 1997-01-20 19:43:45 +0000 | [diff] [blame] | 106 | #define EXPR_TYPE_CAST 11 |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 107 | |
| 108 | static char expr_list[4096]; |
| 109 | static int next_expr_free = 0; |
| 110 | |
| 111 | /* |
| 112 | * This is how we turn an expression address into the actual value. |
| 113 | * This works well in the 32 bit domain - not sure at all about the |
| 114 | * 16 bit world. |
| 115 | */ |
| 116 | #define VAL(_exp) DEBUG_GetExprValue(&_exp, NULL) |
| 117 | |
| 118 | static |
| 119 | struct expr * |
Eric Pouech | d33bcb6 | 2000-03-15 19:57:20 +0000 | [diff] [blame] | 120 | DEBUG_GetFreeExpr(void) |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 121 | { |
| 122 | struct expr * rtn; |
| 123 | |
| 124 | rtn = (struct expr *) &expr_list[next_expr_free]; |
| 125 | |
| 126 | next_expr_free += sizeof(struct expr); |
Eric Pouech | 3b50d21 | 1999-05-24 08:14:30 +0000 | [diff] [blame] | 127 | assert(next_expr_free < sizeof(expr_list)); |
| 128 | |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 129 | return rtn; |
| 130 | } |
| 131 | |
| 132 | void |
Eric Pouech | d33bcb6 | 2000-03-15 19:57:20 +0000 | [diff] [blame] | 133 | DEBUG_FreeExprMem(void) |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 134 | { |
| 135 | next_expr_free = 0; |
| 136 | } |
| 137 | |
Alexandre Julliard | 01d6346 | 1997-01-20 19:43:45 +0000 | [diff] [blame] | 138 | struct expr * |
| 139 | DEBUG_TypeCastExpr(struct datatype * dt, struct expr * exp) |
| 140 | { |
| 141 | struct expr * ex; |
| 142 | |
| 143 | ex = DEBUG_GetFreeExpr(); |
| 144 | |
| 145 | ex->type = EXPR_TYPE_CAST; |
| 146 | ex->un.cast.cast = dt; |
| 147 | ex->un.cast.expr = exp; |
| 148 | return ex; |
| 149 | } |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 150 | |
| 151 | struct expr * |
Eric Pouech | 04c16b8 | 2000-04-30 12:21:15 +0000 | [diff] [blame] | 152 | DEBUG_IntVarExpr(const char* name) |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 153 | { |
| 154 | struct expr * ex; |
| 155 | |
| 156 | ex = DEBUG_GetFreeExpr(); |
| 157 | |
Eric Pouech | 04c16b8 | 2000-04-30 12:21:15 +0000 | [diff] [blame] | 158 | ex->type = EXPR_TYPE_INTVAR; |
| 159 | ex->un.intvar.name = name; |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 160 | return ex; |
| 161 | } |
| 162 | |
| 163 | struct expr * |
| 164 | DEBUG_SymbolExpr(const char * name) |
| 165 | { |
| 166 | struct expr * ex; |
| 167 | |
| 168 | ex = DEBUG_GetFreeExpr(); |
| 169 | |
| 170 | ex->type = EXPR_TYPE_SYMBOL; |
| 171 | ex->un.symbol.name = name; |
| 172 | return ex; |
| 173 | } |
| 174 | |
| 175 | struct expr * |
| 176 | DEBUG_ConstExpr(int value) |
| 177 | { |
| 178 | struct expr * ex; |
| 179 | |
| 180 | ex = DEBUG_GetFreeExpr(); |
| 181 | |
| 182 | ex->type = EXPR_TYPE_CONST; |
| 183 | ex->un.constant.value = value; |
| 184 | return ex; |
| 185 | } |
| 186 | |
| 187 | struct expr * |
| 188 | DEBUG_StringExpr(const char * str) |
| 189 | { |
| 190 | struct expr * ex; |
| 191 | char * pnt; |
| 192 | ex = DEBUG_GetFreeExpr(); |
| 193 | |
| 194 | ex->type = EXPR_TYPE_STRING; |
| 195 | ex->un.string.str = str+1; |
| 196 | pnt = strrchr(ex->un.string.str, '"'); |
| 197 | if( pnt != NULL ) |
| 198 | { |
| 199 | *pnt = '\0'; |
| 200 | } |
| 201 | return ex; |
| 202 | } |
| 203 | |
| 204 | struct expr * |
| 205 | DEBUG_USConstExpr(unsigned int value) |
| 206 | { |
| 207 | struct expr * ex; |
| 208 | |
| 209 | ex = DEBUG_GetFreeExpr(); |
| 210 | |
| 211 | ex->type = EXPR_TYPE_CONST; |
| 212 | ex->un.u_const.value = value; |
| 213 | return ex; |
| 214 | } |
| 215 | |
| 216 | struct expr * |
| 217 | DEBUG_BinopExpr(int operator_type, struct expr * exp1, struct expr * exp2) |
| 218 | { |
| 219 | struct expr * ex; |
| 220 | |
| 221 | ex = DEBUG_GetFreeExpr(); |
| 222 | |
| 223 | ex->type = EXPR_TYPE_BINOP; |
| 224 | ex->un.binop.binop_type = operator_type; |
| 225 | ex->un.binop.exp1 = exp1; |
| 226 | ex->un.binop.exp2 = exp2; |
| 227 | return ex; |
| 228 | } |
| 229 | |
| 230 | struct expr * |
| 231 | DEBUG_UnopExpr(int operator_type, struct expr * exp1) |
| 232 | { |
| 233 | struct expr * ex; |
| 234 | |
| 235 | ex = DEBUG_GetFreeExpr(); |
| 236 | |
| 237 | ex->type = EXPR_TYPE_UNOP; |
| 238 | ex->un.unop.unop_type = operator_type; |
| 239 | ex->un.unop.exp1 = exp1; |
| 240 | return ex; |
| 241 | } |
| 242 | |
| 243 | struct expr * |
| 244 | DEBUG_StructExpr(struct expr * exp, const char * element) |
| 245 | { |
| 246 | struct expr * ex; |
| 247 | |
| 248 | ex = DEBUG_GetFreeExpr(); |
| 249 | |
| 250 | ex->type = EXPR_TYPE_STRUCT; |
| 251 | ex->un.structure.exp1 = exp; |
| 252 | ex->un.structure.element_name = element; |
| 253 | return ex; |
| 254 | } |
| 255 | |
| 256 | struct expr * |
| 257 | DEBUG_StructPExpr(struct expr * exp, const char * element) |
| 258 | { |
| 259 | struct expr * ex; |
| 260 | |
| 261 | ex = DEBUG_GetFreeExpr(); |
| 262 | |
| 263 | ex->type = EXPR_TYPE_PSTRUCT; |
| 264 | ex->un.structure.exp1 = exp; |
| 265 | ex->un.structure.element_name = element; |
| 266 | return ex; |
| 267 | } |
| 268 | |
| 269 | struct expr * |
| 270 | DEBUG_CallExpr(const char * funcname, int nargs, ...) |
| 271 | { |
| 272 | struct expr * ex; |
| 273 | va_list ap; |
| 274 | int i; |
| 275 | |
| 276 | ex = DEBUG_GetFreeExpr(); |
| 277 | |
| 278 | ex->type = EXPR_TYPE_CALL; |
| 279 | ex->un.call.funcname = funcname; |
| 280 | ex->un.call.nargs = nargs; |
| 281 | |
| 282 | va_start(ap, nargs); |
| 283 | for(i=0; i < nargs; i++) |
| 284 | { |
| 285 | ex->un.call.arg[i] = va_arg(ap, struct expr *); |
| 286 | } |
| 287 | va_end(ap); |
| 288 | return ex; |
| 289 | } |
| 290 | |
Eric Pouech | d33bcb6 | 2000-03-15 19:57:20 +0000 | [diff] [blame] | 291 | DBG_VALUE DEBUG_EvalExpr(struct expr * exp) |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 292 | { |
Eric Pouech | d33bcb6 | 2000-03-15 19:57:20 +0000 | [diff] [blame] | 293 | DBG_VALUE rtn; |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 294 | int i; |
Eric Pouech | d33bcb6 | 2000-03-15 19:57:20 +0000 | [diff] [blame] | 295 | DBG_VALUE exp1; |
| 296 | DBG_VALUE exp2; |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 297 | unsigned int cexp[5]; |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 298 | int scale1; |
| 299 | int scale2; |
| 300 | int scale3; |
| 301 | struct datatype * type1; |
| 302 | struct datatype * type2; |
| 303 | |
| 304 | rtn.type = NULL; |
Peter Hunnisett | 856aefa | 2000-07-08 12:45:44 +0000 | [diff] [blame] | 305 | rtn.cookie = DV_INVALID; |
Eric Pouech | d33bcb6 | 2000-03-15 19:57:20 +0000 | [diff] [blame] | 306 | rtn.addr.off = 0; |
| 307 | rtn.addr.seg = 0; |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 308 | |
| 309 | switch(exp->type) |
| 310 | { |
Alexandre Julliard | 01d6346 | 1997-01-20 19:43:45 +0000 | [diff] [blame] | 311 | case EXPR_TYPE_CAST: |
| 312 | rtn = DEBUG_EvalExpr(exp->un.cast.expr); |
| 313 | rtn.type = exp->un.cast.cast; |
Eric Pouech | d33bcb6 | 2000-03-15 19:57:20 +0000 | [diff] [blame] | 314 | if (DEBUG_GetType(rtn.type) == DT_POINTER) |
| 315 | rtn.cookie = DV_TARGET; |
Alexandre Julliard | 01d6346 | 1997-01-20 19:43:45 +0000 | [diff] [blame] | 316 | break; |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 317 | case EXPR_TYPE_STRING: |
| 318 | rtn.type = DEBUG_TypeString; |
Eric Pouech | d33bcb6 | 2000-03-15 19:57:20 +0000 | [diff] [blame] | 319 | rtn.cookie = DV_HOST; |
| 320 | rtn.addr.off = (unsigned int) &exp->un.string.str; |
| 321 | rtn.addr.seg = 0; |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 322 | break; |
| 323 | case EXPR_TYPE_CONST: |
| 324 | rtn.type = DEBUG_TypeIntConst; |
Eric Pouech | d33bcb6 | 2000-03-15 19:57:20 +0000 | [diff] [blame] | 325 | rtn.cookie = DV_HOST; |
| 326 | rtn.addr.off = (unsigned int) &exp->un.constant.value; |
| 327 | rtn.addr.seg = 0; |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 328 | break; |
| 329 | case EXPR_TYPE_US_CONST: |
| 330 | rtn.type = DEBUG_TypeUSInt; |
Eric Pouech | d33bcb6 | 2000-03-15 19:57:20 +0000 | [diff] [blame] | 331 | rtn.cookie = DV_HOST; |
| 332 | rtn.addr.off = (unsigned int) &exp->un.u_const.value; |
| 333 | rtn.addr.seg = 0; |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 334 | break; |
| 335 | case EXPR_TYPE_SYMBOL: |
Eric Pouech | 527eea9 | 2000-03-08 16:44:54 +0000 | [diff] [blame] | 336 | if( !DEBUG_GetSymbolValue(exp->un.symbol.name, -1, &rtn, FALSE) ) |
| 337 | { |
Eric Pouech | 527eea9 | 2000-03-08 16:44:54 +0000 | [diff] [blame] | 338 | RaiseException(DEBUG_STATUS_NO_SYMBOL, 0, 0, NULL); |
Eric Pouech | 527eea9 | 2000-03-08 16:44:54 +0000 | [diff] [blame] | 339 | } |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 340 | break; |
| 341 | case EXPR_TYPE_PSTRUCT: |
| 342 | exp1 = DEBUG_EvalExpr(exp->un.structure.exp1); |
| 343 | if( exp1.type == NULL ) |
| 344 | { |
Eric Pouech | d33bcb6 | 2000-03-15 19:57:20 +0000 | [diff] [blame] | 345 | RaiseException(DEBUG_STATUS_BAD_TYPE, 0, 0, NULL); |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 346 | } |
Eric Pouech | d33bcb6 | 2000-03-15 19:57:20 +0000 | [diff] [blame] | 347 | rtn.cookie = DV_TARGET; |
| 348 | rtn.addr.off = DEBUG_TypeDerefPointer(&exp1, &type1); |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 349 | if( type1 == NULL ) |
| 350 | { |
Eric Pouech | d33bcb6 | 2000-03-15 19:57:20 +0000 | [diff] [blame] | 351 | RaiseException(DEBUG_STATUS_BAD_TYPE, 0, 0, NULL); |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 352 | } |
| 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 ) |
| 360 | { |
Eric Pouech | d33bcb6 | 2000-03-15 19:57:20 +0000 | [diff] [blame] | 361 | RaiseException(DEBUG_STATUS_BAD_TYPE, 0, 0, NULL); |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 362 | } |
| 363 | rtn = exp1; |
| 364 | DEBUG_FindStructElement(&rtn, exp->un.structure.element_name, |
| 365 | &exp->un.structure.result); |
| 366 | break; |
| 367 | case EXPR_TYPE_CALL: |
| 368 | /* |
| 369 | * First, evaluate all of the arguments. If any of them are not |
| 370 | * evaluable, then bail. |
| 371 | */ |
| 372 | for(i=0; i < exp->un.call.nargs; i++) |
| 373 | { |
| 374 | exp1 = DEBUG_EvalExpr(exp->un.call.arg[i]); |
| 375 | if( exp1.type == NULL ) |
| 376 | { |
| 377 | return rtn; |
| 378 | } |
| 379 | cexp[i] = DEBUG_GetExprValue(&exp1, NULL); |
| 380 | } |
| 381 | |
| 382 | /* |
| 383 | * Now look up the address of the function itself. |
| 384 | */ |
| 385 | if( !DEBUG_GetSymbolValue(exp->un.call.funcname, -1, &rtn, FALSE ) ) |
| 386 | { |
Eric Pouech | d33bcb6 | 2000-03-15 19:57:20 +0000 | [diff] [blame] | 387 | RaiseException(DEBUG_STATUS_NO_SYMBOL, 0, 0, NULL); |
Eric Pouech | 3b50d21 | 1999-05-24 08:14:30 +0000 | [diff] [blame] | 388 | } |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 389 | |
Eric Pouech | 527eea9 | 2000-03-08 16:44:54 +0000 | [diff] [blame] | 390 | #if 0 |
| 391 | /* FIXME: NEWDBG NIY */ |
| 392 | /* Anyway, I wonder how this could work depending on the calling order of |
| 393 | * the function (cdecl vs pascal for example) |
| 394 | */ |
| 395 | int (*fptr)(); |
| 396 | |
Eric Pouech | d33bcb6 | 2000-03-15 19:57:20 +0000 | [diff] [blame] | 397 | fptr = (int (*)()) rtn.addr.off; |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 398 | switch(exp->un.call.nargs) |
| 399 | { |
| 400 | case 0: |
| 401 | exp->un.call.result = (*fptr)(); |
| 402 | break; |
| 403 | case 1: |
| 404 | exp->un.call.result = (*fptr)(cexp[0]); |
| 405 | break; |
| 406 | case 2: |
| 407 | exp->un.call.result = (*fptr)(cexp[0], cexp[1]); |
| 408 | break; |
| 409 | case 3: |
| 410 | exp->un.call.result = (*fptr)(cexp[0], cexp[1], cexp[2]); |
| 411 | break; |
| 412 | case 4: |
| 413 | exp->un.call.result = (*fptr)(cexp[0], cexp[1], cexp[2], cexp[3]); |
| 414 | break; |
| 415 | case 5: |
| 416 | exp->un.call.result = (*fptr)(cexp[0], cexp[1], cexp[2], cexp[3], cexp[4]); |
| 417 | break; |
| 418 | } |
Eric Pouech | 527eea9 | 2000-03-08 16:44:54 +0000 | [diff] [blame] | 419 | #else |
Eric Pouech | e5efa0c | 2000-04-13 19:31:58 +0000 | [diff] [blame] | 420 | DEBUG_Printf(DBG_CHN_MESG, "Function call no longer implemented\n"); |
Eric Pouech | 527eea9 | 2000-03-08 16:44:54 +0000 | [diff] [blame] | 421 | /* would need to set up a call to this function, and then restore the current |
| 422 | * context afterwards... |
| 423 | */ |
| 424 | exp->un.call.result = 0; |
| 425 | #endif |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 426 | rtn.type = DEBUG_TypeInt; |
Eric Pouech | d33bcb6 | 2000-03-15 19:57:20 +0000 | [diff] [blame] | 427 | rtn.cookie = DV_HOST; |
| 428 | rtn.addr.off = (unsigned int) &exp->un.call.result; |
Eric Pouech | 527eea9 | 2000-03-08 16:44:54 +0000 | [diff] [blame] | 429 | |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 430 | break; |
Eric Pouech | 04c16b8 | 2000-04-30 12:21:15 +0000 | [diff] [blame] | 431 | case EXPR_TYPE_INTVAR: |
| 432 | { |
| 433 | |
| 434 | DBG_INTVAR* div = DEBUG_GetIntVar(exp->un.intvar.name); |
| 435 | |
| 436 | if (!div) RaiseException(DEBUG_STATUS_NO_SYMBOL, 0, 0, NULL); |
| 437 | rtn.cookie = DV_HOST; |
| 438 | rtn.type = div->type; |
| 439 | rtn.addr.off = (unsigned int)div->pval; |
| 440 | /* EPP FIXME rtn.addr.seg = ?? */ |
| 441 | } |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 442 | break; |
| 443 | case EXPR_TYPE_BINOP: |
| 444 | exp1 = DEBUG_EvalExpr(exp->un.binop.exp1); |
| 445 | exp2 = DEBUG_EvalExpr(exp->un.binop.exp2); |
Eric Pouech | d33bcb6 | 2000-03-15 19:57:20 +0000 | [diff] [blame] | 446 | rtn.cookie = DV_HOST; |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 447 | if( exp1.type == NULL || exp2.type == NULL ) |
| 448 | { |
Eric Pouech | d33bcb6 | 2000-03-15 19:57:20 +0000 | [diff] [blame] | 449 | RaiseException(DEBUG_STATUS_BAD_TYPE, 0, 0, NULL); |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 450 | } |
| 451 | if( exp1.type == DEBUG_TypeIntConst && exp2.type == DEBUG_TypeIntConst ) |
| 452 | { |
| 453 | rtn.type = exp1.type; |
| 454 | } |
| 455 | else |
| 456 | { |
| 457 | rtn.type = DEBUG_TypeInt; |
| 458 | } |
Eric Pouech | d33bcb6 | 2000-03-15 19:57:20 +0000 | [diff] [blame] | 459 | rtn.addr.seg = 0; |
| 460 | rtn.addr.off = (unsigned int) &exp->un.binop.result; |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 461 | switch(exp->un.binop.binop_type) |
| 462 | { |
| 463 | case EXP_OP_ADD: |
| 464 | type1 = DEBUG_GetPointerType(exp1.type); |
| 465 | type2 = DEBUG_GetPointerType(exp2.type); |
| 466 | scale1 = 1; |
| 467 | scale2 = 1; |
| 468 | if( type1 != NULL && type2 != NULL ) |
| 469 | { |
Eric Pouech | d33bcb6 | 2000-03-15 19:57:20 +0000 | [diff] [blame] | 470 | RaiseException(DEBUG_STATUS_BAD_TYPE, 0, 0, NULL); |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 471 | } |
| 472 | else if( type1 != NULL ) |
| 473 | { |
| 474 | scale2 = DEBUG_GetObjectSize(type1); |
| 475 | rtn.type = exp1.type; |
| 476 | } |
| 477 | else if( type2 != NULL ) |
| 478 | { |
| 479 | scale1 = DEBUG_GetObjectSize(type2); |
| 480 | rtn.type = exp2.type; |
| 481 | } |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 482 | exp->un.binop.result = (VAL(exp1) * scale1 + scale2 * VAL(exp2)); |
| 483 | break; |
| 484 | case EXP_OP_SUB: |
| 485 | type1 = DEBUG_GetPointerType(exp1.type); |
| 486 | type2 = DEBUG_GetPointerType(exp2.type); |
| 487 | scale1 = 1; |
| 488 | scale2 = 1; |
| 489 | scale3 = 1; |
| 490 | if( type1 != NULL && type2 != NULL ) |
| 491 | { |
| 492 | if( type1 != type2 ) |
| 493 | { |
Eric Pouech | d33bcb6 | 2000-03-15 19:57:20 +0000 | [diff] [blame] | 494 | RaiseException(DEBUG_STATUS_BAD_TYPE, 0, 0, NULL); |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 495 | } |
| 496 | scale3 = DEBUG_GetObjectSize(type1); |
| 497 | } |
| 498 | else if( type1 != NULL ) |
| 499 | { |
| 500 | scale2 = DEBUG_GetObjectSize(type1); |
| 501 | rtn.type = exp1.type; |
| 502 | } |
| 503 | |
| 504 | else if( type2 != NULL ) |
| 505 | { |
| 506 | scale1 = DEBUG_GetObjectSize(type2); |
| 507 | rtn.type = exp2.type; |
| 508 | } |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 509 | exp->un.binop.result = (VAL(exp1) - VAL(exp2)) / scale3; |
| 510 | break; |
| 511 | case EXP_OP_SEG: |
Eric Pouech | d33bcb6 | 2000-03-15 19:57:20 +0000 | [diff] [blame] | 512 | rtn.cookie = DV_TARGET; |
Eric Pouech | 71189b5 | 2000-07-25 12:51:56 +0000 | [diff] [blame] | 513 | rtn.type = NULL; |
Eric Pouech | d33bcb6 | 2000-03-15 19:57:20 +0000 | [diff] [blame] | 514 | rtn.addr.seg = VAL(exp1); |
Eric Pouech | 71189b5 | 2000-07-25 12:51:56 +0000 | [diff] [blame] | 515 | rtn.addr.off = VAL(exp2); |
Ulrich Weigand | b3ec4b9 | 1999-11-13 20:58:45 +0000 | [diff] [blame] | 516 | #ifdef __i386__ |
Eric Pouech | d33bcb6 | 2000-03-15 19:57:20 +0000 | [diff] [blame] | 517 | DEBUG_FixSegment(&rtn.addr); |
Ulrich Weigand | b3ec4b9 | 1999-11-13 20:58:45 +0000 | [diff] [blame] | 518 | #endif |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 519 | break; |
| 520 | case EXP_OP_LOR: |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 521 | exp->un.binop.result = (VAL(exp1) || VAL(exp2)); |
| 522 | break; |
| 523 | case EXP_OP_LAND: |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 524 | exp->un.binop.result = (VAL(exp1) && VAL(exp2)); |
| 525 | break; |
| 526 | case EXP_OP_OR: |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 527 | exp->un.binop.result = (VAL(exp1) | VAL(exp2)); |
| 528 | break; |
| 529 | case EXP_OP_AND: |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 530 | exp->un.binop.result = (VAL(exp1) & VAL(exp2)); |
| 531 | break; |
| 532 | case EXP_OP_XOR: |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 533 | exp->un.binop.result = (VAL(exp1) ^ VAL(exp2)); |
| 534 | break; |
| 535 | case EXP_OP_EQ: |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 536 | exp->un.binop.result = (VAL(exp1) == VAL(exp2)); |
| 537 | break; |
| 538 | case EXP_OP_GT: |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 539 | exp->un.binop.result = (VAL(exp1) > VAL(exp2)); |
| 540 | break; |
| 541 | case EXP_OP_LT: |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 542 | exp->un.binop.result = (VAL(exp1) < VAL(exp2)); |
| 543 | break; |
| 544 | case EXP_OP_GE: |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 545 | exp->un.binop.result = (VAL(exp1) >= VAL(exp2)); |
| 546 | break; |
| 547 | case EXP_OP_LE: |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 548 | exp->un.binop.result = (VAL(exp1) <= VAL(exp2)); |
| 549 | break; |
| 550 | case EXP_OP_NE: |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 551 | exp->un.binop.result = (VAL(exp1) != VAL(exp2)); |
| 552 | break; |
| 553 | case EXP_OP_SHL: |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 554 | exp->un.binop.result = ((unsigned) VAL(exp1) << VAL(exp2)); |
| 555 | break; |
| 556 | case EXP_OP_SHR: |
Alexandre Julliard | 17216f5 | 1997-10-12 16:30:17 +0000 | [diff] [blame] | 557 | exp->un.binop.result = ((unsigned) VAL(exp1) >> VAL(exp2)); |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 558 | break; |
| 559 | case EXP_OP_MUL: |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 560 | exp->un.binop.result = (VAL(exp1) * VAL(exp2)); |
| 561 | break; |
| 562 | case EXP_OP_DIV: |
Eric Pouech | d33bcb6 | 2000-03-15 19:57:20 +0000 | [diff] [blame] | 563 | if( VAL(exp2) == 0 ) |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 564 | { |
Eric Pouech | d33bcb6 | 2000-03-15 19:57:20 +0000 | [diff] [blame] | 565 | RaiseException(DEBUG_STATUS_DIV_BY_ZERO, 0, 0, NULL); |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 566 | } |
Eric Pouech | d33bcb6 | 2000-03-15 19:57:20 +0000 | [diff] [blame] | 567 | exp->un.binop.result = (VAL(exp1) / VAL(exp2)); |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 568 | break; |
| 569 | case EXP_OP_REM: |
Eric Pouech | d33bcb6 | 2000-03-15 19:57:20 +0000 | [diff] [blame] | 570 | if( VAL(exp2) == 0 ) |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 571 | { |
Eric Pouech | d33bcb6 | 2000-03-15 19:57:20 +0000 | [diff] [blame] | 572 | RaiseException(DEBUG_STATUS_DIV_BY_ZERO, 0, 0, NULL); |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 573 | } |
Eric Pouech | d33bcb6 | 2000-03-15 19:57:20 +0000 | [diff] [blame] | 574 | exp->un.binop.result = (VAL(exp1) % VAL(exp2)); |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 575 | break; |
| 576 | case EXP_OP_ARR: |
| 577 | DEBUG_ArrayIndex(&exp1, &rtn, VAL(exp2)); |
| 578 | break; |
| 579 | default: |
Eric Pouech | d33bcb6 | 2000-03-15 19:57:20 +0000 | [diff] [blame] | 580 | RaiseException(DEBUG_STATUS_INTERNAL_ERROR, 0, 0, NULL); |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 581 | break; |
| 582 | } |
| 583 | break; |
| 584 | case EXPR_TYPE_UNOP: |
| 585 | exp1 = DEBUG_EvalExpr(exp->un.unop.exp1); |
Eric Pouech | d33bcb6 | 2000-03-15 19:57:20 +0000 | [diff] [blame] | 586 | rtn.cookie = DV_HOST; |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 587 | if( exp1.type == NULL ) |
| 588 | { |
Eric Pouech | d33bcb6 | 2000-03-15 19:57:20 +0000 | [diff] [blame] | 589 | RaiseException(DEBUG_STATUS_BAD_TYPE, 0, 0, NULL); |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 590 | } |
Eric Pouech | d33bcb6 | 2000-03-15 19:57:20 +0000 | [diff] [blame] | 591 | rtn.addr.seg = 0; |
| 592 | rtn.addr.off = (unsigned int) &exp->un.unop.result; |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 593 | if( exp1.type == DEBUG_TypeIntConst ) |
| 594 | { |
| 595 | rtn.type = exp1.type; |
| 596 | } |
| 597 | else |
| 598 | { |
| 599 | rtn.type = DEBUG_TypeInt; |
| 600 | } |
Eric Pouech | 3b50d21 | 1999-05-24 08:14:30 +0000 | [diff] [blame] | 601 | switch(exp->un.unop.unop_type) |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 602 | { |
| 603 | case EXP_OP_NEG: |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 604 | exp->un.unop.result = -VAL(exp1); |
| 605 | break; |
| 606 | case EXP_OP_NOT: |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 607 | exp->un.unop.result = !VAL(exp1); |
| 608 | break; |
| 609 | case EXP_OP_LNOT: |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 610 | exp->un.unop.result = ~VAL(exp1); |
| 611 | break; |
| 612 | case EXP_OP_DEREF: |
Eric Pouech | d33bcb6 | 2000-03-15 19:57:20 +0000 | [diff] [blame] | 613 | rtn.cookie = exp1.cookie; |
| 614 | rtn.addr.off = (unsigned int) DEBUG_TypeDerefPointer(&exp1, &rtn.type); |
| 615 | if (!rtn.type) |
| 616 | { |
| 617 | RaiseException(DEBUG_STATUS_BAD_TYPE, 0, 0, NULL); |
| 618 | } |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 619 | break; |
| 620 | case EXP_OP_FORCE_DEREF: |
Eric Pouech | d33bcb6 | 2000-03-15 19:57:20 +0000 | [diff] [blame] | 621 | rtn.cookie = exp1.cookie; |
| 622 | rtn.addr.seg = exp1.addr.seg; |
| 623 | if (exp1.cookie == DV_TARGET) |
| 624 | DEBUG_READ_MEM((void*)exp1.addr.off, &rtn.addr.off, sizeof(rtn.addr.off)); |
| 625 | else |
| 626 | memcpy(&rtn.addr.off, (void*)exp1.addr.off, sizeof(rtn.addr.off)); |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 627 | break; |
| 628 | case EXP_OP_ADDR: |
Eric Pouech | d33bcb6 | 2000-03-15 19:57:20 +0000 | [diff] [blame] | 629 | /* FIXME: even for a 16 bit entity ? */ |
| 630 | rtn.cookie = DV_TARGET; |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 631 | rtn.type = DEBUG_FindOrMakePointerType(exp1.type); |
Eric Pouech | d33bcb6 | 2000-03-15 19:57:20 +0000 | [diff] [blame] | 632 | exp->un.unop.result = exp1.addr.off; |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 633 | break; |
Eric Pouech | d33bcb6 | 2000-03-15 19:57:20 +0000 | [diff] [blame] | 634 | default: |
| 635 | RaiseException(DEBUG_STATUS_INTERNAL_ERROR, 0, 0, NULL); |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 636 | } |
| 637 | break; |
| 638 | default: |
Eric Pouech | e5efa0c | 2000-04-13 19:31:58 +0000 | [diff] [blame] | 639 | DEBUG_Printf(DBG_CHN_MESG,"Unexpected expression (%d).\n", exp->type); |
Eric Pouech | d33bcb6 | 2000-03-15 19:57:20 +0000 | [diff] [blame] | 640 | RaiseException(DEBUG_STATUS_INTERNAL_ERROR, 0, 0, NULL); |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 641 | break; |
| 642 | } |
| 643 | |
Eric Pouech | d33bcb6 | 2000-03-15 19:57:20 +0000 | [diff] [blame] | 644 | assert(rtn.cookie == DV_TARGET || rtn.cookie == DV_HOST); |
| 645 | |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 646 | return rtn; |
| 647 | } |
| 648 | |
| 649 | |
| 650 | int |
Eric Pouech | d33bcb6 | 2000-03-15 19:57:20 +0000 | [diff] [blame] | 651 | DEBUG_DisplayExpr(const struct expr * exp) |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 652 | { |
| 653 | int i; |
| 654 | |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 655 | switch(exp->type) |
| 656 | { |
Alexandre Julliard | 01d6346 | 1997-01-20 19:43:45 +0000 | [diff] [blame] | 657 | case EXPR_TYPE_CAST: |
Eric Pouech | e5efa0c | 2000-04-13 19:31:58 +0000 | [diff] [blame] | 658 | DEBUG_Printf(DBG_CHN_MESG, "(("); |
Alexandre Julliard | 01d6346 | 1997-01-20 19:43:45 +0000 | [diff] [blame] | 659 | DEBUG_PrintTypeCast(exp->un.cast.cast); |
Eric Pouech | e5efa0c | 2000-04-13 19:31:58 +0000 | [diff] [blame] | 660 | DEBUG_Printf(DBG_CHN_MESG, ")"); |
Alexandre Julliard | 01d6346 | 1997-01-20 19:43:45 +0000 | [diff] [blame] | 661 | DEBUG_DisplayExpr(exp->un.cast.expr); |
Eric Pouech | e5efa0c | 2000-04-13 19:31:58 +0000 | [diff] [blame] | 662 | DEBUG_Printf(DBG_CHN_MESG, ")"); |
Alexandre Julliard | 01d6346 | 1997-01-20 19:43:45 +0000 | [diff] [blame] | 663 | break; |
Eric Pouech | 04c16b8 | 2000-04-30 12:21:15 +0000 | [diff] [blame] | 664 | case EXPR_TYPE_INTVAR: |
| 665 | DEBUG_Printf(DBG_CHN_MESG, "$%s", exp->un.intvar.name); |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 666 | break; |
| 667 | case EXPR_TYPE_US_CONST: |
Eric Pouech | e5efa0c | 2000-04-13 19:31:58 +0000 | [diff] [blame] | 668 | DEBUG_Printf(DBG_CHN_MESG, "%ud", exp->un.u_const.value); |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 669 | break; |
| 670 | case EXPR_TYPE_CONST: |
Eric Pouech | e5efa0c | 2000-04-13 19:31:58 +0000 | [diff] [blame] | 671 | DEBUG_Printf(DBG_CHN_MESG, "%d", exp->un.u_const.value); |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 672 | break; |
| 673 | case EXPR_TYPE_STRING: |
Eric Pouech | e5efa0c | 2000-04-13 19:31:58 +0000 | [diff] [blame] | 674 | DEBUG_Printf(DBG_CHN_MESG, "\"%s\"", exp->un.string.str); |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 675 | break; |
| 676 | case EXPR_TYPE_SYMBOL: |
Eric Pouech | e5efa0c | 2000-04-13 19:31:58 +0000 | [diff] [blame] | 677 | DEBUG_Printf(DBG_CHN_MESG, "%s" , exp->un.symbol.name); |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 678 | break; |
| 679 | case EXPR_TYPE_PSTRUCT: |
| 680 | DEBUG_DisplayExpr(exp->un.structure.exp1); |
Eric Pouech | e5efa0c | 2000-04-13 19:31:58 +0000 | [diff] [blame] | 681 | DEBUG_Printf(DBG_CHN_MESG, "->%s", exp->un.structure.element_name); |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 682 | break; |
| 683 | case EXPR_TYPE_STRUCT: |
| 684 | DEBUG_DisplayExpr(exp->un.structure.exp1); |
Eric Pouech | e5efa0c | 2000-04-13 19:31:58 +0000 | [diff] [blame] | 685 | DEBUG_Printf(DBG_CHN_MESG, ".%s", exp->un.structure.element_name); |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 686 | break; |
| 687 | case EXPR_TYPE_CALL: |
Eric Pouech | e5efa0c | 2000-04-13 19:31:58 +0000 | [diff] [blame] | 688 | DEBUG_Printf(DBG_CHN_MESG, "%s(",exp->un.call.funcname); |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 689 | for(i=0; i < exp->un.call.nargs; i++) |
| 690 | { |
| 691 | DEBUG_DisplayExpr(exp->un.call.arg[i]); |
| 692 | if( i != exp->un.call.nargs - 1 ) |
| 693 | { |
Eric Pouech | e5efa0c | 2000-04-13 19:31:58 +0000 | [diff] [blame] | 694 | DEBUG_Printf(DBG_CHN_MESG, ", "); |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 695 | } |
| 696 | } |
Eric Pouech | e5efa0c | 2000-04-13 19:31:58 +0000 | [diff] [blame] | 697 | DEBUG_Printf(DBG_CHN_MESG, ")"); |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 698 | break; |
| 699 | case EXPR_TYPE_BINOP: |
Eric Pouech | e5efa0c | 2000-04-13 19:31:58 +0000 | [diff] [blame] | 700 | DEBUG_Printf(DBG_CHN_MESG, "( "); |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 701 | DEBUG_DisplayExpr(exp->un.binop.exp1); |
| 702 | switch(exp->un.binop.binop_type) |
| 703 | { |
| 704 | case EXP_OP_ADD: |
Eric Pouech | e5efa0c | 2000-04-13 19:31:58 +0000 | [diff] [blame] | 705 | DEBUG_Printf(DBG_CHN_MESG, " + "); |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 706 | break; |
| 707 | case EXP_OP_SUB: |
Eric Pouech | e5efa0c | 2000-04-13 19:31:58 +0000 | [diff] [blame] | 708 | DEBUG_Printf(DBG_CHN_MESG, " - "); |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 709 | break; |
| 710 | case EXP_OP_SEG: |
Eric Pouech | e5efa0c | 2000-04-13 19:31:58 +0000 | [diff] [blame] | 711 | DEBUG_Printf(DBG_CHN_MESG, ":"); |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 712 | break; |
| 713 | case EXP_OP_LOR: |
Eric Pouech | e5efa0c | 2000-04-13 19:31:58 +0000 | [diff] [blame] | 714 | DEBUG_Printf(DBG_CHN_MESG, " || "); |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 715 | break; |
| 716 | case EXP_OP_LAND: |
Eric Pouech | e5efa0c | 2000-04-13 19:31:58 +0000 | [diff] [blame] | 717 | DEBUG_Printf(DBG_CHN_MESG, " && "); |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 718 | break; |
| 719 | case EXP_OP_OR: |
Eric Pouech | e5efa0c | 2000-04-13 19:31:58 +0000 | [diff] [blame] | 720 | DEBUG_Printf(DBG_CHN_MESG, " | "); |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 721 | break; |
| 722 | case EXP_OP_AND: |
Eric Pouech | e5efa0c | 2000-04-13 19:31:58 +0000 | [diff] [blame] | 723 | DEBUG_Printf(DBG_CHN_MESG, " & "); |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 724 | break; |
| 725 | case EXP_OP_XOR: |
Eric Pouech | e5efa0c | 2000-04-13 19:31:58 +0000 | [diff] [blame] | 726 | DEBUG_Printf(DBG_CHN_MESG, " ^ "); |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 727 | break; |
| 728 | case EXP_OP_EQ: |
Eric Pouech | e5efa0c | 2000-04-13 19:31:58 +0000 | [diff] [blame] | 729 | DEBUG_Printf(DBG_CHN_MESG, " == "); |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 730 | break; |
| 731 | case EXP_OP_GT: |
Eric Pouech | e5efa0c | 2000-04-13 19:31:58 +0000 | [diff] [blame] | 732 | DEBUG_Printf(DBG_CHN_MESG, " > "); |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 733 | break; |
| 734 | case EXP_OP_LT: |
Eric Pouech | e5efa0c | 2000-04-13 19:31:58 +0000 | [diff] [blame] | 735 | DEBUG_Printf(DBG_CHN_MESG, " < "); |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 736 | break; |
| 737 | case EXP_OP_GE: |
Eric Pouech | e5efa0c | 2000-04-13 19:31:58 +0000 | [diff] [blame] | 738 | DEBUG_Printf(DBG_CHN_MESG, " >= "); |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 739 | break; |
| 740 | case EXP_OP_LE: |
Eric Pouech | e5efa0c | 2000-04-13 19:31:58 +0000 | [diff] [blame] | 741 | DEBUG_Printf(DBG_CHN_MESG, " <= "); |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 742 | break; |
| 743 | case EXP_OP_NE: |
Eric Pouech | e5efa0c | 2000-04-13 19:31:58 +0000 | [diff] [blame] | 744 | DEBUG_Printf(DBG_CHN_MESG, " != "); |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 745 | break; |
| 746 | case EXP_OP_SHL: |
Eric Pouech | e5efa0c | 2000-04-13 19:31:58 +0000 | [diff] [blame] | 747 | DEBUG_Printf(DBG_CHN_MESG, " << "); |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 748 | break; |
| 749 | case EXP_OP_SHR: |
Eric Pouech | e5efa0c | 2000-04-13 19:31:58 +0000 | [diff] [blame] | 750 | DEBUG_Printf(DBG_CHN_MESG, " >> "); |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 751 | break; |
| 752 | case EXP_OP_MUL: |
Eric Pouech | e5efa0c | 2000-04-13 19:31:58 +0000 | [diff] [blame] | 753 | DEBUG_Printf(DBG_CHN_MESG, " * "); |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 754 | break; |
| 755 | case EXP_OP_DIV: |
Eric Pouech | e5efa0c | 2000-04-13 19:31:58 +0000 | [diff] [blame] | 756 | DEBUG_Printf(DBG_CHN_MESG, " / "); |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 757 | break; |
| 758 | case EXP_OP_REM: |
Eric Pouech | e5efa0c | 2000-04-13 19:31:58 +0000 | [diff] [blame] | 759 | DEBUG_Printf(DBG_CHN_MESG, " %% "); |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 760 | break; |
| 761 | case EXP_OP_ARR: |
Eric Pouech | e5efa0c | 2000-04-13 19:31:58 +0000 | [diff] [blame] | 762 | DEBUG_Printf(DBG_CHN_MESG, "["); |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 763 | break; |
| 764 | default: |
| 765 | break; |
| 766 | } |
| 767 | DEBUG_DisplayExpr(exp->un.binop.exp2); |
| 768 | if( exp->un.binop.binop_type == EXP_OP_ARR ) |
| 769 | { |
Eric Pouech | e5efa0c | 2000-04-13 19:31:58 +0000 | [diff] [blame] | 770 | DEBUG_Printf(DBG_CHN_MESG, "]"); |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 771 | } |
Eric Pouech | e5efa0c | 2000-04-13 19:31:58 +0000 | [diff] [blame] | 772 | DEBUG_Printf(DBG_CHN_MESG, " )"); |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 773 | break; |
| 774 | case EXPR_TYPE_UNOP: |
Eric Pouech | 3b50d21 | 1999-05-24 08:14:30 +0000 | [diff] [blame] | 775 | switch(exp->un.unop.unop_type) |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 776 | { |
| 777 | case EXP_OP_NEG: |
Eric Pouech | e5efa0c | 2000-04-13 19:31:58 +0000 | [diff] [blame] | 778 | DEBUG_Printf(DBG_CHN_MESG, "-"); |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 779 | break; |
| 780 | case EXP_OP_NOT: |
Eric Pouech | e5efa0c | 2000-04-13 19:31:58 +0000 | [diff] [blame] | 781 | DEBUG_Printf(DBG_CHN_MESG, "!"); |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 782 | break; |
| 783 | case EXP_OP_LNOT: |
Eric Pouech | e5efa0c | 2000-04-13 19:31:58 +0000 | [diff] [blame] | 784 | DEBUG_Printf(DBG_CHN_MESG, "~"); |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 785 | break; |
| 786 | case EXP_OP_DEREF: |
Eric Pouech | e5efa0c | 2000-04-13 19:31:58 +0000 | [diff] [blame] | 787 | DEBUG_Printf(DBG_CHN_MESG, "*"); |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 788 | break; |
| 789 | case EXP_OP_ADDR: |
Eric Pouech | e5efa0c | 2000-04-13 19:31:58 +0000 | [diff] [blame] | 790 | DEBUG_Printf(DBG_CHN_MESG, "&"); |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 791 | break; |
| 792 | } |
| 793 | DEBUG_DisplayExpr(exp->un.unop.exp1); |
| 794 | break; |
| 795 | default: |
Eric Pouech | e5efa0c | 2000-04-13 19:31:58 +0000 | [diff] [blame] | 796 | DEBUG_Printf(DBG_CHN_MESG,"Unexpected expression.\n"); |
Eric Pouech | d33bcb6 | 2000-03-15 19:57:20 +0000 | [diff] [blame] | 797 | RaiseException(DEBUG_STATUS_INTERNAL_ERROR, 0, 0, NULL); |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 798 | break; |
| 799 | } |
| 800 | |
| 801 | return TRUE; |
| 802 | } |
| 803 | |
| 804 | struct expr * |
Eric Pouech | d33bcb6 | 2000-03-15 19:57:20 +0000 | [diff] [blame] | 805 | DEBUG_CloneExpr(const struct expr * exp) |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 806 | { |
| 807 | int i; |
| 808 | struct expr * rtn; |
| 809 | |
Ove Kaaven | dda17c6 | 1999-04-25 12:24:42 +0000 | [diff] [blame] | 810 | rtn = (struct expr *) DBG_alloc(sizeof(struct expr)); |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 811 | |
| 812 | /* |
| 813 | * First copy the contents of the expression itself. |
| 814 | */ |
| 815 | *rtn = *exp; |
| 816 | |
| 817 | |
| 818 | switch(exp->type) |
| 819 | { |
Alexandre Julliard | 01d6346 | 1997-01-20 19:43:45 +0000 | [diff] [blame] | 820 | case EXPR_TYPE_CAST: |
| 821 | rtn->un.cast.expr = DEBUG_CloneExpr(exp->un.cast.expr); |
| 822 | break; |
Eric Pouech | 04c16b8 | 2000-04-30 12:21:15 +0000 | [diff] [blame] | 823 | case EXPR_TYPE_INTVAR: |
| 824 | rtn->un.intvar.name = DBG_strdup(exp->un.intvar.name); |
| 825 | break; |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 826 | case EXPR_TYPE_US_CONST: |
| 827 | case EXPR_TYPE_CONST: |
| 828 | break; |
| 829 | case EXPR_TYPE_STRING: |
Ove Kaaven | dda17c6 | 1999-04-25 12:24:42 +0000 | [diff] [blame] | 830 | rtn->un.string.str = DBG_strdup(exp->un.string.str); |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 831 | break; |
| 832 | case EXPR_TYPE_SYMBOL: |
Ove Kaaven | dda17c6 | 1999-04-25 12:24:42 +0000 | [diff] [blame] | 833 | rtn->un.symbol.name = DBG_strdup(exp->un.symbol.name); |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 834 | break; |
| 835 | case EXPR_TYPE_PSTRUCT: |
| 836 | case EXPR_TYPE_STRUCT: |
| 837 | rtn->un.structure.exp1 = DEBUG_CloneExpr(exp->un.structure.exp1); |
Ove Kaaven | dda17c6 | 1999-04-25 12:24:42 +0000 | [diff] [blame] | 838 | rtn->un.structure.element_name = DBG_strdup(exp->un.structure.element_name); |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 839 | break; |
| 840 | case EXPR_TYPE_CALL: |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 841 | for(i=0; i < exp->un.call.nargs; i++) |
| 842 | { |
| 843 | rtn->un.call.arg[i] = DEBUG_CloneExpr(exp->un.call.arg[i]); |
| 844 | } |
Ove Kaaven | dda17c6 | 1999-04-25 12:24:42 +0000 | [diff] [blame] | 845 | rtn->un.call.funcname = DBG_strdup(exp->un.call.funcname); |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 846 | break; |
| 847 | case EXPR_TYPE_BINOP: |
| 848 | rtn->un.binop.exp1 = DEBUG_CloneExpr(exp->un.binop.exp1); |
| 849 | rtn->un.binop.exp2 = DEBUG_CloneExpr(exp->un.binop.exp2); |
| 850 | break; |
| 851 | case EXPR_TYPE_UNOP: |
| 852 | rtn->un.unop.exp1 = DEBUG_CloneExpr(exp->un.unop.exp1); |
| 853 | break; |
| 854 | default: |
Eric Pouech | e5efa0c | 2000-04-13 19:31:58 +0000 | [diff] [blame] | 855 | DEBUG_Printf(DBG_CHN_MESG,"Unexpected expression.\n"); |
Eric Pouech | d33bcb6 | 2000-03-15 19:57:20 +0000 | [diff] [blame] | 856 | RaiseException(DEBUG_STATUS_INTERNAL_ERROR, 0, 0, NULL); |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 857 | break; |
| 858 | } |
| 859 | |
| 860 | return rtn; |
| 861 | } |
| 862 | |
| 863 | |
| 864 | /* |
| 865 | * Recursively go through an expression tree and free all memory associated |
| 866 | * with it. |
| 867 | */ |
| 868 | int |
| 869 | DEBUG_FreeExpr(struct expr * exp) |
| 870 | { |
| 871 | int i; |
| 872 | |
| 873 | switch(exp->type) |
| 874 | { |
Alexandre Julliard | 01d6346 | 1997-01-20 19:43:45 +0000 | [diff] [blame] | 875 | case EXPR_TYPE_CAST: |
| 876 | DEBUG_FreeExpr(exp->un.cast.expr); |
| 877 | break; |
Eric Pouech | 04c16b8 | 2000-04-30 12:21:15 +0000 | [diff] [blame] | 878 | case EXPR_TYPE_INTVAR: |
| 879 | DBG_free((char *) exp->un.intvar.name); |
| 880 | break; |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 881 | case EXPR_TYPE_US_CONST: |
| 882 | case EXPR_TYPE_CONST: |
| 883 | break; |
| 884 | case EXPR_TYPE_STRING: |
Ove Kaaven | dda17c6 | 1999-04-25 12:24:42 +0000 | [diff] [blame] | 885 | DBG_free((char *) exp->un.string.str); |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 886 | break; |
| 887 | case EXPR_TYPE_SYMBOL: |
Ove Kaaven | dda17c6 | 1999-04-25 12:24:42 +0000 | [diff] [blame] | 888 | DBG_free((char *) exp->un.symbol.name); |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 889 | break; |
| 890 | case EXPR_TYPE_PSTRUCT: |
| 891 | case EXPR_TYPE_STRUCT: |
| 892 | DEBUG_FreeExpr(exp->un.structure.exp1); |
Ove Kaaven | dda17c6 | 1999-04-25 12:24:42 +0000 | [diff] [blame] | 893 | DBG_free((char *) exp->un.structure.element_name); |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 894 | break; |
| 895 | case EXPR_TYPE_CALL: |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 896 | for(i=0; i < exp->un.call.nargs; i++) |
| 897 | { |
| 898 | DEBUG_FreeExpr(exp->un.call.arg[i]); |
| 899 | } |
Ove Kaaven | dda17c6 | 1999-04-25 12:24:42 +0000 | [diff] [blame] | 900 | DBG_free((char *) exp->un.call.funcname); |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 901 | break; |
| 902 | case EXPR_TYPE_BINOP: |
| 903 | DEBUG_FreeExpr(exp->un.binop.exp1); |
| 904 | DEBUG_FreeExpr(exp->un.binop.exp2); |
| 905 | break; |
| 906 | case EXPR_TYPE_UNOP: |
| 907 | DEBUG_FreeExpr(exp->un.unop.exp1); |
| 908 | break; |
| 909 | default: |
Eric Pouech | e5efa0c | 2000-04-13 19:31:58 +0000 | [diff] [blame] | 910 | DEBUG_Printf(DBG_CHN_MESG,"Unexpected expression.\n"); |
Eric Pouech | d33bcb6 | 2000-03-15 19:57:20 +0000 | [diff] [blame] | 911 | RaiseException(DEBUG_STATUS_INTERNAL_ERROR, 0, 0, NULL); |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 912 | break; |
| 913 | } |
| 914 | |
Ove Kaaven | dda17c6 | 1999-04-25 12:24:42 +0000 | [diff] [blame] | 915 | DBG_free(exp); |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 916 | return TRUE; |
| 917 | } |