static SCM vlscm_unop (enum valscm_unary_opcode opcode, SCM x, const char *func_name) { struct gdbarch *gdbarch = get_current_arch (); const struct language_defn *language = current_language; struct value *arg1; SCM result = SCM_BOOL_F; struct value *res_val = NULL; SCM except_scm; struct cleanup *cleanups; cleanups = make_cleanup_value_free_to_mark (value_mark ()); arg1 = vlscm_convert_value_from_scheme (func_name, SCM_ARG1, x, &except_scm, gdbarch, language); if (arg1 == NULL) { do_cleanups (cleanups); gdbscm_throw (except_scm); } TRY { switch (opcode) { case VALSCM_NOT: /* Alas gdb and guile use the opposite meaning for "logical not". */ { struct type *type = language_bool_type (language, gdbarch); res_val = value_from_longest (type, (LONGEST) value_logical_not (arg1)); } break; case VALSCM_NEG: res_val = value_neg (arg1); break; case VALSCM_NOP: /* Seemingly a no-op, but if X was a Scheme value it is now a <gdb:value> object. */ res_val = arg1; break; case VALSCM_ABS: if (value_less (arg1, value_zero (value_type (arg1), not_lval))) res_val = value_neg (arg1); else res_val = arg1; break; case VALSCM_LOGNOT: res_val = value_complement (arg1); break; default: gdb_assert_not_reached ("unsupported operation"); } } CATCH (except, RETURN_MASK_ALL) { GDBSCM_HANDLE_GDB_EXCEPTION_WITH_CLEANUPS (except, cleanups); }
static struct value * evaluate_subexp_java (struct type *expect_type, struct expression *exp, int *pos, enum noside noside) { int pc = *pos; int i; const char *name; enum exp_opcode op = exp->elts[*pos].opcode; struct value *arg1; struct value *arg2; struct type *type; switch (op) { case UNOP_IND: if (noside == EVAL_SKIP) goto standard; (*pos)++; arg1 = evaluate_subexp_java (NULL_TYPE, exp, pos, EVAL_NORMAL); if (is_object_type (value_type (arg1))) { struct type *type; type = type_from_class (exp->gdbarch, java_class_from_object (arg1)); arg1 = value_cast (lookup_pointer_type (type), arg1); } return value_ind (arg1); case BINOP_SUBSCRIPT: (*pos)++; arg1 = evaluate_subexp_with_coercion (exp, pos, noside); arg2 = evaluate_subexp_with_coercion (exp, pos, noside); if (noside == EVAL_SKIP) goto nosideret; /* If the user attempts to subscript something that is not an array or pointer type (like a plain int variable for example), then report this as an error. */ arg1 = coerce_ref (arg1); type = check_typedef (value_type (arg1)); if (TYPE_CODE (type) == TYPE_CODE_PTR) type = check_typedef (TYPE_TARGET_TYPE (type)); name = TYPE_NAME (type); if (name == NULL) name = TYPE_TAG_NAME (type); i = name == NULL ? 0 : strlen (name); if (TYPE_CODE (type) == TYPE_CODE_STRUCT && i > 2 && name[i - 1] == ']') { enum bfd_endian byte_order = gdbarch_byte_order (exp->gdbarch); CORE_ADDR address; long length, index; struct type *el_type; gdb_byte buf4[4]; struct value *clas = java_class_from_object (arg1); struct value *temp = clas; /* Get CLASS_ELEMENT_TYPE of the array type. */ temp = value_struct_elt (&temp, NULL, "methods", NULL, "structure"); deprecated_set_value_type (temp, value_type (clas)); el_type = type_from_class (exp->gdbarch, temp); if (TYPE_CODE (el_type) == TYPE_CODE_STRUCT) el_type = lookup_pointer_type (el_type); if (noside == EVAL_AVOID_SIDE_EFFECTS) return value_zero (el_type, VALUE_LVAL (arg1)); address = value_as_address (arg1); address += get_java_object_header_size (exp->gdbarch); read_memory (address, buf4, 4); length = (long) extract_signed_integer (buf4, 4, byte_order); index = (long) value_as_long (arg2); if (index >= length || index < 0) error (_("array index (%ld) out of bounds (length: %ld)"), index, length); address = (address + 4) + index * TYPE_LENGTH (el_type); return value_at (el_type, address); } else if (TYPE_CODE (type) == TYPE_CODE_ARRAY) { if (noside == EVAL_AVOID_SIDE_EFFECTS) return value_zero (TYPE_TARGET_TYPE (type), VALUE_LVAL (arg1)); else return value_subscript (arg1, value_as_long (arg2)); } if (name) error (_("cannot subscript something of type `%s'"), name); else error (_("cannot subscript requested type")); case OP_STRING: (*pos)++; i = longest_to_int (exp->elts[pc + 1].longconst); (*pos) += 3 + BYTES_TO_EXP_ELEM (i + 1); if (noside == EVAL_SKIP) goto nosideret; return java_value_string (&exp->elts[pc + 2].string, i); case STRUCTOP_PTR: arg1 = evaluate_subexp_standard (expect_type, exp, pos, noside); /* Convert object field (such as TYPE.class) to reference. */ if (TYPE_CODE (value_type (arg1)) == TYPE_CODE_STRUCT) arg1 = value_addr (arg1); return arg1; default: break; } standard: return evaluate_subexp_standard (expect_type, exp, pos, noside); nosideret: return value_from_longest (builtin_type (exp->gdbarch)->builtin_int, 1); }
static struct value * evaluate_subexp_modula2 (struct type *expect_type, struct expression *exp, int *pos, enum noside noside) { enum exp_opcode op = exp->elts[*pos].opcode; struct value *arg1; struct value *arg2; struct type *type; switch (op) { case UNOP_HIGH: (*pos)++; arg1 = evaluate_subexp_with_coercion (exp, pos, noside); if (noside == EVAL_SKIP || noside == EVAL_AVOID_SIDE_EFFECTS) return arg1; else { arg1 = coerce_ref (arg1); type = check_typedef (value_type (arg1)); if (m2_is_unbounded_array (type)) { struct value *temp = arg1; type = TYPE_FIELD_TYPE (type, 1); /* i18n: Do not translate the "_m2_high" part! */ arg1 = value_struct_elt (&temp, NULL, "_m2_high", NULL, _("unbounded structure " "missing _m2_high field")); if (value_type (arg1) != type) arg1 = value_cast (type, arg1); } } return arg1; case BINOP_SUBSCRIPT: (*pos)++; arg1 = evaluate_subexp_with_coercion (exp, pos, noside); arg2 = evaluate_subexp_with_coercion (exp, pos, noside); if (noside == EVAL_SKIP) goto nosideret; /* If the user attempts to subscript something that is not an array or pointer type (like a plain int variable for example), then report this as an error. */ arg1 = coerce_ref (arg1); type = check_typedef (value_type (arg1)); if (m2_is_unbounded_array (type)) { struct value *temp = arg1; type = TYPE_FIELD_TYPE (type, 0); if (type == NULL || (TYPE_CODE (type) != TYPE_CODE_PTR)) { warning (_("internal error: unbounded " "array structure is unknown")); return evaluate_subexp_standard (expect_type, exp, pos, noside); } /* i18n: Do not translate the "_m2_contents" part! */ arg1 = value_struct_elt (&temp, NULL, "_m2_contents", NULL, _("unbounded structure " "missing _m2_contents field")); if (value_type (arg1) != type) arg1 = value_cast (type, arg1); check_typedef (value_type (arg1)); return value_ind (value_ptradd (arg1, value_as_long (arg2))); } else if (TYPE_CODE (type) != TYPE_CODE_ARRAY) { if (TYPE_NAME (type)) error (_("cannot subscript something of type `%s'"), TYPE_NAME (type)); else error (_("cannot subscript requested type")); } if (noside == EVAL_AVOID_SIDE_EFFECTS) return value_zero (TYPE_TARGET_TYPE (type), VALUE_LVAL (arg1)); else return value_subscript (arg1, value_as_long (arg2)); default: return evaluate_subexp_standard (expect_type, exp, pos, noside); } nosideret: return value_from_longest (builtin_type (exp->gdbarch)->builtin_int, 1); }
struct value * value_x_unop (struct value *arg1, enum exp_opcode op, enum noside noside) { struct gdbarch *gdbarch = get_type_arch (value_type (arg1)); struct value **argvec; char *ptr, *mangle_ptr; char tstr[13], mangle_tstr[13]; int static_memfuncp, nargs; arg1 = coerce_ref (arg1); /* now we know that what we have to do is construct our arg vector and find the right function to call it with. */ if (TYPE_CODE (check_typedef (value_type (arg1))) != TYPE_CODE_STRUCT) error (_("Can't do that unary op on that type")); /* FIXME be explicit */ argvec = (struct value **) alloca (sizeof (struct value *) * 4); argvec[1] = value_addr (arg1); argvec[2] = 0; nargs = 1; /* Make the right function name up. */ strcpy (tstr, "operator__"); ptr = tstr + 8; strcpy (mangle_tstr, "__"); mangle_ptr = mangle_tstr + 2; switch (op) { case UNOP_PREINCREMENT: strcpy (ptr, "++"); break; case UNOP_PREDECREMENT: strcpy (ptr, "--"); break; case UNOP_POSTINCREMENT: strcpy (ptr, "++"); argvec[2] = value_from_longest (builtin_type (gdbarch)->builtin_int, 0); argvec[3] = 0; nargs ++; break; case UNOP_POSTDECREMENT: strcpy (ptr, "--"); argvec[2] = value_from_longest (builtin_type (gdbarch)->builtin_int, 0); argvec[3] = 0; nargs ++; break; case UNOP_LOGICAL_NOT: strcpy (ptr, "!"); break; case UNOP_COMPLEMENT: strcpy (ptr, "~"); break; case UNOP_NEG: strcpy (ptr, "-"); break; case UNOP_PLUS: strcpy (ptr, "+"); break; case UNOP_IND: strcpy (ptr, "*"); break; case STRUCTOP_PTR: strcpy (ptr, "->"); break; default: error (_("Invalid unary operation specified.")); } argvec[0] = value_user_defined_op (&arg1, argvec + 1, tstr, &static_memfuncp, nargs); if (argvec[0]) { if (static_memfuncp) { argvec[1] = argvec[0]; nargs --; argvec++; } if (noside == EVAL_AVOID_SIDE_EFFECTS) { struct type *return_type; return_type = TYPE_TARGET_TYPE (check_typedef (value_type (argvec[0]))); return value_zero (return_type, VALUE_LVAL (arg1)); } return call_function_by_hand (argvec[0], nargs, argvec + 1); } throw_error (NOT_FOUND_ERROR, _("member function %s not found"), tstr); return 0; /* For lint -- never reached */ }
struct value * value_x_binop (struct value *arg1, struct value *arg2, enum exp_opcode op, enum exp_opcode otherop, enum noside noside) { struct value **argvec; char *ptr; char tstr[13]; int static_memfuncp; arg1 = coerce_ref (arg1); arg2 = coerce_ref (arg2); /* now we know that what we have to do is construct our arg vector and find the right function to call it with. */ if (TYPE_CODE (check_typedef (value_type (arg1))) != TYPE_CODE_STRUCT) error (_("Can't do that binary op on that type")); /* FIXME be explicit */ argvec = (struct value **) alloca (sizeof (struct value *) * 4); argvec[1] = value_addr (arg1); argvec[2] = arg2; argvec[3] = 0; /* Make the right function name up. */ strcpy (tstr, "operator__"); ptr = tstr + 8; switch (op) { case BINOP_ADD: strcpy (ptr, "+"); break; case BINOP_SUB: strcpy (ptr, "-"); break; case BINOP_MUL: strcpy (ptr, "*"); break; case BINOP_DIV: strcpy (ptr, "/"); break; case BINOP_REM: strcpy (ptr, "%"); break; case BINOP_LSH: strcpy (ptr, "<<"); break; case BINOP_RSH: strcpy (ptr, ">>"); break; case BINOP_BITWISE_AND: strcpy (ptr, "&"); break; case BINOP_BITWISE_IOR: strcpy (ptr, "|"); break; case BINOP_BITWISE_XOR: strcpy (ptr, "^"); break; case BINOP_LOGICAL_AND: strcpy (ptr, "&&"); break; case BINOP_LOGICAL_OR: strcpy (ptr, "||"); break; case BINOP_MIN: strcpy (ptr, "<?"); break; case BINOP_MAX: strcpy (ptr, ">?"); break; case BINOP_ASSIGN: strcpy (ptr, "="); break; case BINOP_ASSIGN_MODIFY: switch (otherop) { case BINOP_ADD: strcpy (ptr, "+="); break; case BINOP_SUB: strcpy (ptr, "-="); break; case BINOP_MUL: strcpy (ptr, "*="); break; case BINOP_DIV: strcpy (ptr, "/="); break; case BINOP_REM: strcpy (ptr, "%="); break; case BINOP_BITWISE_AND: strcpy (ptr, "&="); break; case BINOP_BITWISE_IOR: strcpy (ptr, "|="); break; case BINOP_BITWISE_XOR: strcpy (ptr, "^="); break; case BINOP_MOD: /* invalid */ default: error (_("Invalid binary operation specified.")); } break; case BINOP_SUBSCRIPT: strcpy (ptr, "[]"); break; case BINOP_EQUAL: strcpy (ptr, "=="); break; case BINOP_NOTEQUAL: strcpy (ptr, "!="); break; case BINOP_LESS: strcpy (ptr, "<"); break; case BINOP_GTR: strcpy (ptr, ">"); break; case BINOP_GEQ: strcpy (ptr, ">="); break; case BINOP_LEQ: strcpy (ptr, "<="); break; case BINOP_MOD: /* invalid */ default: error (_("Invalid binary operation specified.")); } argvec[0] = value_user_defined_op (&arg1, argvec + 1, tstr, &static_memfuncp, 2); if (argvec[0]) { if (static_memfuncp) { argvec[1] = argvec[0]; argvec++; } if (noside == EVAL_AVOID_SIDE_EFFECTS) { struct type *return_type; return_type = TYPE_TARGET_TYPE (check_typedef (value_type (argvec[0]))); return value_zero (return_type, VALUE_LVAL (arg1)); } return call_function_by_hand (argvec[0], 2 - static_memfuncp, argvec + 1); } throw_error (NOT_FOUND_ERROR, _("member function %s not found"), tstr); #ifdef lint return call_function_by_hand (argvec[0], 2 - static_memfuncp, argvec + 1); #endif }
struct value * value_x_unop (struct value *arg1, enum exp_opcode op, enum noside noside) { struct gdbarch *gdbarch = get_type_arch (value_type (arg1)); char *ptr; char tstr[13], mangle_tstr[13]; int static_memfuncp, nargs; arg1 = coerce_ref (arg1); /* now we know that what we have to do is construct our arg vector and find the right function to call it with. */ if (TYPE_CODE (check_typedef (value_type (arg1))) != TYPE_CODE_STRUCT) error (_("Can't do that unary op on that type")); /* FIXME be explicit */ value *argvec_storage[3]; gdb::array_view<value *> argvec = argvec_storage; argvec[1] = value_addr (arg1); argvec[2] = 0; nargs = 1; /* Make the right function name up. */ strcpy (tstr, "operator__"); ptr = tstr + 8; strcpy (mangle_tstr, "__"); switch (op) { case UNOP_PREINCREMENT: strcpy (ptr, "++"); break; case UNOP_PREDECREMENT: strcpy (ptr, "--"); break; case UNOP_POSTINCREMENT: strcpy (ptr, "++"); argvec[2] = value_from_longest (builtin_type (gdbarch)->builtin_int, 0); nargs ++; break; case UNOP_POSTDECREMENT: strcpy (ptr, "--"); argvec[2] = value_from_longest (builtin_type (gdbarch)->builtin_int, 0); nargs ++; break; case UNOP_LOGICAL_NOT: strcpy (ptr, "!"); break; case UNOP_COMPLEMENT: strcpy (ptr, "~"); break; case UNOP_NEG: strcpy (ptr, "-"); break; case UNOP_PLUS: strcpy (ptr, "+"); break; case UNOP_IND: strcpy (ptr, "*"); break; case STRUCTOP_PTR: strcpy (ptr, "->"); break; default: error (_("Invalid unary operation specified.")); } argvec[0] = value_user_defined_op (&arg1, argvec.slice (1, nargs), tstr, &static_memfuncp, noside); if (argvec[0]) { if (static_memfuncp) { argvec[1] = argvec[0]; argvec = argvec.slice (1); } if (TYPE_CODE (value_type (argvec[0])) == TYPE_CODE_XMETHOD) { /* Static xmethods are not supported yet. */ gdb_assert (static_memfuncp == 0); if (noside == EVAL_AVOID_SIDE_EFFECTS) { struct type *return_type = result_type_of_xmethod (argvec[0], argvec[1]); if (return_type == NULL) error (_("Xmethod is missing return type.")); return value_zero (return_type, VALUE_LVAL (arg1)); } return call_xmethod (argvec[0], argvec[1]); } if (noside == EVAL_AVOID_SIDE_EFFECTS) { struct type *return_type; return_type = TYPE_TARGET_TYPE (check_typedef (value_type (argvec[0]))); return value_zero (return_type, VALUE_LVAL (arg1)); } return call_function_by_hand (argvec[0], NULL, argvec.slice (1, nargs)); } throw_error (NOT_FOUND_ERROR, _("member function %s not found"), tstr); }
struct value * value_x_binop (struct value *arg1, struct value *arg2, enum exp_opcode op, enum exp_opcode otherop, enum noside noside) { char *ptr; char tstr[13]; int static_memfuncp; arg1 = coerce_ref (arg1); arg2 = coerce_ref (arg2); /* now we know that what we have to do is construct our arg vector and find the right function to call it with. */ if (TYPE_CODE (check_typedef (value_type (arg1))) != TYPE_CODE_STRUCT) error (_("Can't do that binary op on that type")); /* FIXME be explicit */ value *argvec_storage[3]; gdb::array_view<value *> argvec = argvec_storage; argvec[1] = value_addr (arg1); argvec[2] = arg2; /* Make the right function name up. */ strcpy (tstr, "operator__"); ptr = tstr + 8; switch (op) { case BINOP_ADD: strcpy (ptr, "+"); break; case BINOP_SUB: strcpy (ptr, "-"); break; case BINOP_MUL: strcpy (ptr, "*"); break; case BINOP_DIV: strcpy (ptr, "/"); break; case BINOP_REM: strcpy (ptr, "%"); break; case BINOP_LSH: strcpy (ptr, "<<"); break; case BINOP_RSH: strcpy (ptr, ">>"); break; case BINOP_BITWISE_AND: strcpy (ptr, "&"); break; case BINOP_BITWISE_IOR: strcpy (ptr, "|"); break; case BINOP_BITWISE_XOR: strcpy (ptr, "^"); break; case BINOP_LOGICAL_AND: strcpy (ptr, "&&"); break; case BINOP_LOGICAL_OR: strcpy (ptr, "||"); break; case BINOP_MIN: strcpy (ptr, "<?"); break; case BINOP_MAX: strcpy (ptr, ">?"); break; case BINOP_ASSIGN: strcpy (ptr, "="); break; case BINOP_ASSIGN_MODIFY: switch (otherop) { case BINOP_ADD: strcpy (ptr, "+="); break; case BINOP_SUB: strcpy (ptr, "-="); break; case BINOP_MUL: strcpy (ptr, "*="); break; case BINOP_DIV: strcpy (ptr, "/="); break; case BINOP_REM: strcpy (ptr, "%="); break; case BINOP_BITWISE_AND: strcpy (ptr, "&="); break; case BINOP_BITWISE_IOR: strcpy (ptr, "|="); break; case BINOP_BITWISE_XOR: strcpy (ptr, "^="); break; case BINOP_MOD: /* invalid */ default: error (_("Invalid binary operation specified.")); } break; case BINOP_SUBSCRIPT: strcpy (ptr, "[]"); break; case BINOP_EQUAL: strcpy (ptr, "=="); break; case BINOP_NOTEQUAL: strcpy (ptr, "!="); break; case BINOP_LESS: strcpy (ptr, "<"); break; case BINOP_GTR: strcpy (ptr, ">"); break; case BINOP_GEQ: strcpy (ptr, ">="); break; case BINOP_LEQ: strcpy (ptr, "<="); break; case BINOP_MOD: /* invalid */ default: error (_("Invalid binary operation specified.")); } argvec[0] = value_user_defined_op (&arg1, argvec.slice (1), tstr, &static_memfuncp, noside); if (argvec[0]) { if (static_memfuncp) { argvec[1] = argvec[0]; argvec = argvec.slice (1); } if (TYPE_CODE (value_type (argvec[0])) == TYPE_CODE_XMETHOD) { /* Static xmethods are not supported yet. */ gdb_assert (static_memfuncp == 0); if (noside == EVAL_AVOID_SIDE_EFFECTS) { struct type *return_type = result_type_of_xmethod (argvec[0], argvec.slice (1)); if (return_type == NULL) error (_("Xmethod is missing return type.")); return value_zero (return_type, VALUE_LVAL (arg1)); } return call_xmethod (argvec[0], argvec.slice (1)); } if (noside == EVAL_AVOID_SIDE_EFFECTS) { struct type *return_type; return_type = TYPE_TARGET_TYPE (check_typedef (value_type (argvec[0]))); return value_zero (return_type, VALUE_LVAL (arg1)); } return call_function_by_hand (argvec[0], NULL, argvec.slice (1, 2 - static_memfuncp)); } throw_error (NOT_FOUND_ERROR, _("member function %s not found"), tstr); }