static tree build_headof (tree exp) { tree type = TREE_TYPE (exp); tree offset; tree index; gcc_assert (TREE_CODE (type) == POINTER_TYPE); type = TREE_TYPE (type); if (!TYPE_POLYMORPHIC_P (type)) return exp; /* We use this a couple of times below, protect it. */ exp = save_expr (exp); /* The offset-to-top field is at index -2 from the vptr. */ index = build_int_cst (NULL_TREE, -2 * TARGET_VTABLE_DATA_ENTRY_DISTANCE); offset = build_vtbl_ref (build_indirect_ref (exp, NULL), index); type = build_qualified_type (ptr_type_node, cp_type_quals (TREE_TYPE (exp))); return build2 (PLUS_EXPR, type, exp, convert_to_integer (ptrdiff_type_node, offset)); }
static gboolean generate_hashed_items (GkmSecretCollection *collection, EggBuffer *buffer) { GHashTable *attributes; const gchar *value; GList *items, *l; guint32 id, type; items = gkm_secret_collection_get_items (collection); egg_buffer_add_uint32 (buffer, g_list_length (items)); for (l = items; l; l = g_list_next (l)) { value = gkm_secret_object_get_identifier (l->data); if (!convert_to_integer (value, &id)) { g_warning ("trying to save a non-numeric item identifier '%s' into " "the keyring file format which only supports numeric.", value); continue; } egg_buffer_add_uint32 (buffer, id); value = gkm_secret_item_get_schema (l->data); type = gkm_secret_compat_parse_item_type (value); egg_buffer_add_uint32 (buffer, type); attributes = gkm_secret_item_get_fields (l->data); buffer_add_attributes (buffer, attributes, TRUE); } g_list_free (items); return !egg_buffer_has_error (buffer); }
static tree convert_ieee_real_to_integer (tree type, tree expr) { tree result; expr = save_expr (expr); result = fold_build3 (COND_EXPR, type, fold_build2 (NE_EXPR, boolean_type_node, expr, expr), convert (type, integer_zero_node), convert_to_integer (type, expr)); result = fold_build3 (COND_EXPR, type, fold_build2 (LE_EXPR, boolean_type_node, expr, convert (TREE_TYPE (expr), TYPE_MIN_VALUE (type))), TYPE_MIN_VALUE (type), result); result = fold_build3 (COND_EXPR, type, fold_build2 (GE_EXPR, boolean_type_node, expr, convert (TREE_TYPE (expr), TYPE_MAX_VALUE (type))), TYPE_MAX_VALUE (type), result); return result; }
void read_para(){ char buff[64]; int val; para_t* l_para; #ifdef _TEST_ FILE* fp=fopen("D:/workspace/poj1003/Debug/input.txt","r"); #endif while(1){ #ifdef _TEST_ fgets(buff,32,fp); #else gets(buff); #endif buff[4] = '\0'; if(strcmp(buff,"0.00")==0) break; val = convert_to_integer(buff); l_para = (para_t*)malloc(sizeof(para_t)); l_para->val = val; l_para->next = NULL; if(g_end!=NULL) g_end->next = l_para; g_end = l_para; if(g_begin==NULL) g_begin = l_para; } }
tree convert(tree type, tree expr) { tree e = expr; enum tree_code code = TREE_CODE(type); if (type == TREE_TYPE(expr) || TREE_CODE(expr) == ERROR_MARK || code == ERROR_MARK || TREE_CODE(TREE_TYPE(expr)) == ERROR_MARK) return expr; if (TYPE_MAIN_VARIANT(type) == TYPE_MAIN_VARIANT(TREE_TYPE(expr))) return fold(build1(NOP_EXPR, type, expr)); if (TREE_CODE(TREE_TYPE(expr)) == ERROR_MARK) return error_mark_node; if (TREE_CODE(TREE_TYPE (expr)) == VOID_TYPE) { error ("void value not ignored as it ought to be"); return error_mark_node; } if (code == VOID_TYPE) return build1(CONVERT_EXPR, type, e); #if 0 /* This is incorrect. A truncation can't be stripped this way. Extensions will be stripped by the use of get_unwidened. */ if (TREE_CODE(expr) == NOP_EXPR) return convert(type, TREE_OPERAND(expr, 0)); #endif if (code == INTEGER_TYPE || code == ENUMERAL_TYPE) return fold(convert_to_integer(type, e)); if (code == BOOLEAN_TYPE) { tree t = g95_truthvalue_conversion(expr); /* If it returns a NOP_EXPR, we must fold it here to avoid infinite recursion between fold () and convert (). */ if (TREE_CODE(t) == NOP_EXPR) return fold(build1(NOP_EXPR, type, TREE_OPERAND(t, 0))); else return fold(build1(NOP_EXPR, type, t)); } if (code == POINTER_TYPE || code == REFERENCE_TYPE) return fold(convert_to_pointer (type, e)); if (code == REAL_TYPE) return fold(convert_to_real (type, e)); if (code == COMPLEX_TYPE) return fold(convert_to_complex (type, e)); if (code == VECTOR_TYPE) return fold(convert_to_vector (type, e)); error ("conversion to non-scalar type requested"); return error_mark_node; }
void main(){ char a[10]; int len; //char a[]="A 6"; //int len=strlen(a); scanf("%[^\n]s",a); len=strlen(a); printf("%d",convert_to_integer(a+(len-1),len-2)); }
tree convert (tree type, tree expr) { tree e = expr; enum tree_code code = TREE_CODE (type); const char *invalid_conv_diag; if (type == error_mark_node || expr == error_mark_node || TREE_TYPE (expr) == error_mark_node) return error_mark_node; if ((invalid_conv_diag = targetm.invalid_conversion (TREE_TYPE (expr), type))) { error (invalid_conv_diag); return error_mark_node; } if (type == TREE_TYPE (expr)) return expr; if (TYPE_MAIN_VARIANT (type) == TYPE_MAIN_VARIANT (TREE_TYPE (expr))) return fold_convert (type, expr); if (TREE_CODE (TREE_TYPE (expr)) == ERROR_MARK) return error_mark_node; if (TREE_CODE (TREE_TYPE (expr)) == VOID_TYPE) { error ("void value not ignored as it ought to be"); return error_mark_node; } if (code == VOID_TYPE) return fold_convert (type, e); // check if (code == INTEGER_TYPE && TREE_CODE(expr) == STRING_CST) { char *c = TREE_STRING_POINTER(expr)+1; return build_int_cst(type, *c); } if (code == INTEGER_TYPE || code == ENUMERAL_TYPE) return fold (convert_to_integer (type, e)); if (code == BOOLEAN_TYPE) return fold_convert (type, c_objc_common_truthvalue_conversion (expr)); if (code == POINTER_TYPE || code == REFERENCE_TYPE) return fold (convert_to_pointer (type, e)); if (code == REAL_TYPE) return fold (convert_to_real (type, e)); if (code == COMPLEX_TYPE) return fold (convert_to_complex (type, e)); if (code == VECTOR_TYPE) return fold (convert_to_vector (type, e)); if ((code == RECORD_TYPE || code == UNION_TYPE) && lang_hooks.types_compatible_p (type, TREE_TYPE (expr))) return e; error ("conversion to non-scalar type requested"); return error_mark_node; }
void DbgCmd_Break::set_breakpoint_3arg(std::string const &class_id_string, std::string const &method_id_string, std::string const &offset_string) { try { uint32_t class_id = convert_to_integer(class_id_string); uint32_t method_id = convert_to_integer(method_id_string); uint32_t offset = convert_to_integer(offset_string); KdwpCmd_EventRequest_Set kdwp_cmd; kdwp_cmd.set_breakpoint(class_id, method_id, offset); mp_debugger->socket() << kdwp_cmd; } catch (BadNumber &/* e */) { throw BadCommand(); } }
tree convert (tree type, tree expr) { tree e = expr; enum tree_code code = TREE_CODE (type); if (type == TREE_TYPE (expr) || TREE_CODE (expr) == ERROR_MARK || code == ERROR_MARK || TREE_CODE (TREE_TYPE (expr)) == ERROR_MARK) return expr; if (TYPE_MAIN_VARIANT (type) == TYPE_MAIN_VARIANT (TREE_TYPE (expr))) return fold_build1 (NOP_EXPR, type, expr); if (TREE_CODE (TREE_TYPE (expr)) == ERROR_MARK) return error_mark_node; if (TREE_CODE (TREE_TYPE (expr)) == VOID_TYPE) { error ("void value not ignored as it ought to be"); return error_mark_node; } if (code == VOID_TYPE) return build1 (CONVERT_EXPR, type, e); if (code == INTEGER_TYPE || code == ENUMERAL_TYPE) return fold (convert_to_integer (type, e)); if (code == BOOLEAN_TYPE) { tree t = expr; /* If it returns a NOP_EXPR, we must fold it here to avoid infinite recursion between fold () and convert (). */ if (TREE_CODE (t) == NOP_EXPR) return fold_build1 (NOP_EXPR, type, TREE_OPERAND (t, 0)); else return fold_build1 (NOP_EXPR, type, t); } if (code == POINTER_TYPE || code == REFERENCE_TYPE) return fold (convert_to_pointer (type, e)); if (code == REAL_TYPE) return fold (convert_to_real (type, e)); if (code == COMPLEX_TYPE) return fold (convert_to_complex (type, e)); if (code == VECTOR_TYPE) return fold (convert_to_vector (type, e)); error ("conversion to non-scalar type requested"); return error_mark_node; }
tree convert (tree type, tree expr) { enum tree_code code = TREE_CODE (type); if (!expr) return error_mark_node; if (type == TREE_TYPE (expr) || TREE_CODE (expr) == ERROR_MARK) return expr; if (TREE_CODE (TREE_TYPE (expr)) == ERROR_MARK) return error_mark_node; if (code == VOID_TYPE) return build1 (CONVERT_EXPR, type, expr); if (code == BOOLEAN_TYPE) return fold_convert (type, expr); if (code == INTEGER_TYPE) { if (type == char_type_node || type == promoted_char_type_node) return fold_convert (type, expr); if ((really_constant_p (expr) || (! flag_unsafe_math_optimizations && ! flag_emit_class_files)) && TREE_CODE (TREE_TYPE (expr)) == REAL_TYPE && TARGET_FLOAT_FORMAT == IEEE_FLOAT_FORMAT) return convert_ieee_real_to_integer (type, expr); else { /* fold very helpfully sets the overflow status if a type overflows in a narrowing integer conversion, but Java doesn't care. */ tree tmp = fold (convert_to_integer (type, expr)); if (TREE_CODE (tmp) == INTEGER_CST) TREE_OVERFLOW (tmp) = 0; return tmp; } } if (code == REAL_TYPE) return fold (convert_to_real (type, expr)); if (code == POINTER_TYPE) return fold (convert_to_pointer (type, expr)); error ("conversion to non-scalar type requested"); return error_mark_node; }
void DbgCmd_Thread_Suspend::suspend_thread_1arg(std::string const &thread_id_string) { try { uint32_t const thread_id = convert_to_integer(thread_id_string); KdwpCmd_ThreadReference_Suspend kdwp_cmd(thread_id); mp_debugger->socket() << kdwp_cmd; } catch (KdwpErrorInvalidThread &/* e */) { std::cout << "Invalid thread." << std::endl; } catch (BadNumber &/* e */) { throw BadCommand(); } }
tree convert (tree type, tree expr) { tree e = expr; enum tree_code code; if (type == TREE_TYPE (expr)) return expr; if (TREE_CODE (type) == ERROR_MARK || TREE_CODE (expr) == ERROR_MARK || TREE_CODE (TREE_TYPE (expr)) == ERROR_MARK) return expr; gcc_checking_assert (TREE_CODE (TREE_TYPE (expr)) != VOID_TYPE); if (TYPE_MAIN_VARIANT (type) == TYPE_MAIN_VARIANT (TREE_TYPE (expr))) return fold_build1_loc (input_location, NOP_EXPR, type, expr); code = TREE_CODE (type); if (code == VOID_TYPE) return fold_build1_loc (input_location, CONVERT_EXPR, type, e); if (code == BOOLEAN_TYPE) return fold_build1_loc (input_location, NOP_EXPR, type, truthvalue_conversion (e)); if (code == INTEGER_TYPE) return fold (convert_to_integer (type, e)); if (code == POINTER_TYPE || code == REFERENCE_TYPE) return fold (convert_to_pointer (type, e)); if (code == REAL_TYPE) return fold (convert_to_real (type, e)); if (code == COMPLEX_TYPE) return fold (convert_to_complex (type, e)); if (code == VECTOR_TYPE) return fold (convert_to_vector (type, e)); gcc_unreachable (); }
tree convert(tree type, tree expr) { register tree e = expr; register enum tree_code code = TREE_CODE(type); if (type == TREE_TYPE(expr) || TREE_CODE(expr) == ERROR_MARK) return expr; if (TYPE_MAIN_VARIANT(type) == TYPE_MAIN_VARIANT(TREE_TYPE(expr))) return fold(build1(NOP_EXPR, type, expr)); if (TREE_CODE(TREE_TYPE(expr)) == ERROR_MARK) return error_mark_node; if (TREE_CODE(TREE_TYPE(expr)) == VOID_TYPE) { error("void value not ignored as it ought to be"); return error_mark_node; } if (code == VOID_TYPE) return build1(CONVERT_EXPR, type, e); #if 0 /* This is incorrect. A truncation can't be stripped this way. Extensions will be stripped by the use of get_unwidened. */ if (TREE_CODE (expr) == NOP_EXPR) return convert (type, TREE_OPERAND (expr, 0)); #endif if (code == INTEGER_TYPE || code == ENUMERAL_TYPE) return fold(convert_to_integer(type, e)); if (code == POINTER_TYPE) return fold(convert_to_pointer(type, e)); if (code == REAL_TYPE) return fold(convert_to_real(type, e)); if (code == COMPLEX_TYPE) return fold(convert_to_complex(type, e)); error("conversion to non-scalar type requested"); return error_mark_node; }
Expr_pair convert_to_common_int(Context& cxt, Expr& e1, Expr& e2) { Integer_type& t1 = cast<Integer_type>(e1.type()); Integer_type& t2 = cast<Integer_type>(e2.type()); // If both types have the same sign, convert to the one with // the most precision. if (t1.sign() == t2.sign()) { if (t1.precision() < t2.precision()) { Expr& c = convert_to_integer(cxt, e1, t2); return {c, e2}; } if (t2.precision() < t1.precision()) { Expr& c = convert_to_integer(cxt, e2, t1); return {e1, c}; } } // If the unsigned operand has greater rank than the signed // operand, convert to the type of the unsigned operand. if (t1.is_unsigned() && t2.precision() < t1.precision()) { Expr& c = convert_to_integer(cxt, e2, t1); return {e1, c}; } if (t2.is_unsigned() && t1.precision() < t2.precision()) { Expr& c = convert_to_integer(cxt, e1, t2); return {c, e2}; } // Otherwise, both operands are converted to the corresponding // unsigned type of the signed operand. int p = t1.is_signed() ? t1.precision() : t2.precision(); Integer_type& z = cxt.get_integer_type(false, p); Expr& c1 = convert_to_integer(cxt, e1, z); Expr& c2 = convert_to_integer(cxt, e2, z); return {c1, c2}; }
tree convert (tree type, tree expr) { tree e = expr; enum tree_code code = TREE_CODE (type); const char *invalid_conv_diag; tree ret; location_t loc = EXPR_LOCATION (expr); if (type == error_mark_node || expr == error_mark_node || TREE_TYPE (expr) == error_mark_node) return error_mark_node; if ((invalid_conv_diag = targetm.invalid_conversion (TREE_TYPE (expr), type))) { error (invalid_conv_diag); return error_mark_node; } if (type == TREE_TYPE (expr)) return expr; ret = targetm.convert_to_type (type, expr); if (ret) return ret; STRIP_TYPE_NOPS (e); if (TYPE_MAIN_VARIANT (type) == TYPE_MAIN_VARIANT (TREE_TYPE (expr)) && (TREE_CODE (TREE_TYPE (expr)) != COMPLEX_TYPE || TREE_CODE (e) == COMPLEX_EXPR)) return fold_convert_loc (loc, type, expr); if (TREE_CODE (TREE_TYPE (expr)) == ERROR_MARK) return error_mark_node; if (TREE_CODE (TREE_TYPE (expr)) == VOID_TYPE) { error ("void value not ignored as it ought to be"); return error_mark_node; } switch (code) { case VOID_TYPE: return fold_convert_loc (loc, type, e); case INTEGER_TYPE: case ENUMERAL_TYPE: ret = convert_to_integer (type, e); goto maybe_fold; case BOOLEAN_TYPE: return fold_convert_loc (loc, type, c_objc_common_truthvalue_conversion (input_location, expr)); case POINTER_TYPE: case REFERENCE_TYPE: ret = convert_to_pointer (type, e); goto maybe_fold; case REAL_TYPE: ret = convert_to_real (type, e); goto maybe_fold; case FIXED_POINT_TYPE: ret = convert_to_fixed (type, e); goto maybe_fold; case COMPLEX_TYPE: /* If converting from COMPLEX_TYPE to a different COMPLEX_TYPE and e is not COMPLEX_EXPR, convert_to_complex uses save_expr, but for the C FE c_save_expr needs to be called instead. */ if (TREE_CODE (TREE_TYPE (e)) == COMPLEX_TYPE) { if (TREE_CODE (e) != COMPLEX_EXPR) { tree subtype = TREE_TYPE (type); tree elt_type = TREE_TYPE (TREE_TYPE (e)); if (in_late_binary_op) e = save_expr (e); else e = c_save_expr (e); ret = fold_build2_loc (loc, COMPLEX_EXPR, type, convert (subtype, fold_build1 (REALPART_EXPR, elt_type, e)), convert (subtype, fold_build1 (IMAGPART_EXPR, elt_type, e))); goto maybe_fold; } } ret = convert_to_complex (type, e); goto maybe_fold; case VECTOR_TYPE: ret = convert_to_vector (type, e); goto maybe_fold; case RECORD_TYPE: case UNION_TYPE: if (lang_hooks.types_compatible_p (type, TREE_TYPE (expr))) return e; break; default: break; maybe_fold: if (TREE_CODE (ret) != C_MAYBE_CONST_EXPR) ret = fold (ret); return ret; } error ("conversion to non-scalar type requested"); return error_mark_node; }
tree ocp_convert (tree type, tree expr, int convtype, int flags) { tree e = expr; enum tree_code code = TREE_CODE (type); const char *invalid_conv_diag; if (error_operand_p (e) || type == error_mark_node) return error_mark_node; complete_type (type); complete_type (TREE_TYPE (expr)); if ((invalid_conv_diag = targetm.invalid_conversion (TREE_TYPE (expr), type))) { error (invalid_conv_diag); return error_mark_node; } e = integral_constant_value (e); if (MAYBE_CLASS_TYPE_P (type) && (convtype & CONV_FORCE_TEMP)) /* We need a new temporary; don't take this shortcut. */; else if (same_type_ignoring_top_level_qualifiers_p (type, TREE_TYPE (e))) { if (same_type_p (type, TREE_TYPE (e))) /* The call to fold will not always remove the NOP_EXPR as might be expected, since if one of the types is a typedef; the comparison in fold is just equality of pointers, not a call to comptypes. We don't call fold in this case because that can result in infinite recursion; fold will call convert, which will call ocp_convert, etc. */ return e; /* For complex data types, we need to perform componentwise conversion. */ else if (TREE_CODE (type) == COMPLEX_TYPE) return fold_if_not_in_template (convert_to_complex (type, e)); else if (TREE_CODE (e) == TARGET_EXPR) { /* Don't build a NOP_EXPR of class type. Instead, change the type of the temporary. */ TREE_TYPE (e) = TREE_TYPE (TARGET_EXPR_SLOT (e)) = type; return e; } else { /* We shouldn't be treating objects of ADDRESSABLE type as rvalues. */ gcc_assert (!TREE_ADDRESSABLE (type)); return fold_if_not_in_template (build_nop (type, e)); } } if (code == VOID_TYPE && (convtype & CONV_STATIC)) { e = convert_to_void (e, /*implicit=*/NULL, tf_warning_or_error); return e; } if (INTEGRAL_CODE_P (code)) { tree intype = TREE_TYPE (e); if (TREE_CODE (type) == ENUMERAL_TYPE) { /* enum = enum, enum = int, enum = float, (enum)pointer are all errors. */ if (((INTEGRAL_OR_ENUMERATION_TYPE_P (intype) || TREE_CODE (intype) == REAL_TYPE) && ! (convtype & CONV_STATIC)) || TREE_CODE (intype) == POINTER_TYPE) { if (flags & LOOKUP_COMPLAIN) permerror (input_location, "conversion from %q#T to %q#T", intype, type); if (!flag_permissive) return error_mark_node; } /* [expr.static.cast] 8. A value of integral or enumeration type can be explicitly converted to an enumeration type. The value is unchanged if the original value is within the range of the enumeration values. Otherwise, the resulting enumeration value is unspecified. */ if (TREE_CODE (expr) == INTEGER_CST && !int_fits_type_p (expr, type)) warning (OPT_Wconversion, "the result of the conversion is unspecified because " "%qE is outside the range of type %qT", expr, type); } if (MAYBE_CLASS_TYPE_P (intype)) { tree rval; rval = build_type_conversion (type, e); if (rval) return rval; if (flags & LOOKUP_COMPLAIN) error ("%q#T used where a %qT was expected", intype, type); return error_mark_node; } if (code == BOOLEAN_TYPE) return cp_truthvalue_conversion (e); return fold_if_not_in_template (convert_to_integer (type, e)); } if (POINTER_TYPE_P (type) || TYPE_PTR_TO_MEMBER_P (type)) return fold_if_not_in_template (cp_convert_to_pointer (type, e)); if (code == VECTOR_TYPE) { tree in_vtype = TREE_TYPE (e); if (MAYBE_CLASS_TYPE_P (in_vtype)) { tree ret_val; ret_val = build_type_conversion (type, e); if (ret_val) return ret_val; if (flags & LOOKUP_COMPLAIN) error ("%q#T used where a %qT was expected", in_vtype, type); return error_mark_node; } return fold_if_not_in_template (convert_to_vector (type, e)); } if (code == REAL_TYPE || code == COMPLEX_TYPE) { if (MAYBE_CLASS_TYPE_P (TREE_TYPE (e))) { tree rval; rval = build_type_conversion (type, e); if (rval) return rval; else if (flags & LOOKUP_COMPLAIN) error ("%q#T used where a floating point value was expected", TREE_TYPE (e)); } if (code == REAL_TYPE) return fold_if_not_in_template (convert_to_real (type, e)); else if (code == COMPLEX_TYPE) return fold_if_not_in_template (convert_to_complex (type, e)); } /* New C++ semantics: since assignment is now based on memberwise copying, if the rhs type is derived from the lhs type, then we may still do a conversion. */ if (RECORD_OR_UNION_CODE_P (code)) { tree dtype = TREE_TYPE (e); tree ctor = NULL_TREE; dtype = TYPE_MAIN_VARIANT (dtype); /* Conversion between aggregate types. New C++ semantics allow objects of derived type to be cast to objects of base type. Old semantics only allowed this between pointers. There may be some ambiguity between using a constructor vs. using a type conversion operator when both apply. */ ctor = e; if (abstract_virtuals_error (NULL_TREE, type)) return error_mark_node; if (BRACE_ENCLOSED_INITIALIZER_P (ctor)) ctor = perform_implicit_conversion (type, ctor, tf_warning_or_error); else if ((flags & LOOKUP_ONLYCONVERTING) && ! (CLASS_TYPE_P (dtype) && DERIVED_FROM_P (type, dtype))) /* For copy-initialization, first we create a temp of the proper type with a user-defined conversion sequence, then we direct-initialize the target with the temp (see [dcl.init]). */ ctor = build_user_type_conversion (type, ctor, flags); else ctor = build_special_member_call (NULL_TREE, complete_ctor_identifier, build_tree_list (NULL_TREE, ctor), type, flags, tf_warning_or_error); if (ctor) return build_cplus_new (type, ctor); } if (flags & LOOKUP_COMPLAIN) error ("conversion from %qT to non-scalar type %qT requested", TREE_TYPE (expr), type); return error_mark_node; }
tree convert (tree type, tree expr) { tree e = expr; enum tree_code code = TREE_CODE (type); const char *invalid_conv_diag; tree ret; location_t loc = EXPR_LOCATION (expr); if (type == error_mark_node || error_operand_p (expr)) return error_mark_node; if ((invalid_conv_diag = targetm.invalid_conversion (TREE_TYPE (expr), type))) { error (invalid_conv_diag); return error_mark_node; } if (type == TREE_TYPE (expr)) return expr; ret = targetm.convert_to_type (type, expr); if (ret) return ret; STRIP_TYPE_NOPS (e); if (TYPE_MAIN_VARIANT (type) == TYPE_MAIN_VARIANT (TREE_TYPE (expr)) && (TREE_CODE (TREE_TYPE (expr)) != COMPLEX_TYPE || TREE_CODE (e) == COMPLEX_EXPR)) return fold_convert_loc (loc, type, expr); if (TREE_CODE (TREE_TYPE (expr)) == ERROR_MARK) return error_mark_node; if (TREE_CODE (TREE_TYPE (expr)) == VOID_TYPE) { error ("void value not ignored as it ought to be"); return error_mark_node; } switch (code) { case VOID_TYPE: return fold_convert_loc (loc, type, e); case INTEGER_TYPE: case ENUMERAL_TYPE: if (flag_sanitize & SANITIZE_FLOAT_CAST && TREE_CODE (TREE_TYPE (expr)) == REAL_TYPE && COMPLETE_TYPE_P (type) && current_function_decl != NULL_TREE && !lookup_attribute ("no_sanitize_undefined", DECL_ATTRIBUTES (current_function_decl))) { tree arg; if (in_late_binary_op) { expr = save_expr (expr); arg = expr; } else { expr = c_save_expr (expr); arg = c_fully_fold (expr, false, NULL); } tree check = ubsan_instrument_float_cast (loc, type, expr, arg); expr = fold_build1 (FIX_TRUNC_EXPR, type, expr); if (check == NULL) return expr; return fold_build2 (COMPOUND_EXPR, TREE_TYPE (expr), check, expr); } ret = convert_to_integer (type, e); goto maybe_fold; case BOOLEAN_TYPE: return fold_convert_loc (loc, type, c_objc_common_truthvalue_conversion (input_location, expr)); case POINTER_TYPE: case REFERENCE_TYPE: ret = convert_to_pointer (type, e); goto maybe_fold; case REAL_TYPE: ret = convert_to_real (type, e); goto maybe_fold; case FIXED_POINT_TYPE: ret = convert_to_fixed (type, e); goto maybe_fold; case COMPLEX_TYPE: /* If converting from COMPLEX_TYPE to a different COMPLEX_TYPE and e is not COMPLEX_EXPR, convert_to_complex uses save_expr, but for the C FE c_save_expr needs to be called instead. */ if (TREE_CODE (TREE_TYPE (e)) == COMPLEX_TYPE) { if (TREE_CODE (e) != COMPLEX_EXPR) { tree subtype = TREE_TYPE (type); tree elt_type = TREE_TYPE (TREE_TYPE (e)); if (in_late_binary_op) e = save_expr (e); else e = c_save_expr (e); ret = fold_build2_loc (loc, COMPLEX_EXPR, type, convert (subtype, fold_build1 (REALPART_EXPR, elt_type, e)), convert (subtype, fold_build1 (IMAGPART_EXPR, elt_type, e))); goto maybe_fold; } } ret = convert_to_complex (type, e); goto maybe_fold; case VECTOR_TYPE: ret = convert_to_vector (type, e); goto maybe_fold; case RECORD_TYPE: case UNION_TYPE: if (lang_hooks.types_compatible_p (type, TREE_TYPE (expr))) return e; break; default: break; maybe_fold: if (TREE_CODE (ret) != C_MAYBE_CONST_EXPR) ret = fold (ret); return ret; } error ("conversion to non-scalar type requested"); return error_mark_node; }
tree ocp_convert (tree type, tree expr, int convtype, int flags) { tree e = expr; enum tree_code code = TREE_CODE (type); if (error_operand_p (e) || type == error_mark_node) return error_mark_node; complete_type (type); complete_type (TREE_TYPE (expr)); e = decl_constant_value (e); if (IS_AGGR_TYPE (type) && (convtype & CONV_FORCE_TEMP) /* Some internal structures (vtable_entry_type, sigtbl_ptr_type) don't go through finish_struct, so they don't have the synthesized constructors. So don't force a temporary. */ && TYPE_HAS_CONSTRUCTOR (type)) /* We need a new temporary; don't take this shortcut. */; else if (TYPE_MAIN_VARIANT (type) == TYPE_MAIN_VARIANT (TREE_TYPE (e))) { if (same_type_p (type, TREE_TYPE (e))) /* The call to fold will not always remove the NOP_EXPR as might be expected, since if one of the types is a typedef; the comparison in fold is just equality of pointers, not a call to comptypes. We don't call fold in this case because that can result in infinite recursion; fold will call convert, which will call ocp_convert, etc. */ return e; /* For complex data types, we need to perform componentwise conversion. */ else if (TREE_CODE (type) == COMPLEX_TYPE) return fold (convert_to_complex (type, e)); else if (TREE_CODE (e) == TARGET_EXPR) { /* Don't build a NOP_EXPR of class type. Instead, change the type of the temporary. Only allow this for cv-qual changes, though. */ if (!same_type_p (TYPE_MAIN_VARIANT (TREE_TYPE (e)), TYPE_MAIN_VARIANT (type))) abort (); TREE_TYPE (e) = TREE_TYPE (TARGET_EXPR_SLOT (e)) = type; return e; } else if (TREE_ADDRESSABLE (type)) /* We shouldn't be treating objects of ADDRESSABLE type as rvalues. */ abort (); else return fold (build1 (NOP_EXPR, type, e)); } if (code == VOID_TYPE && (convtype & CONV_STATIC)) { e = convert_to_void (e, /*implicit=*/NULL); return e; } if (INTEGRAL_CODE_P (code)) { tree intype = TREE_TYPE (e); /* enum = enum, enum = int, enum = float, (enum)pointer are all errors. */ if (TREE_CODE (type) == ENUMERAL_TYPE && ((ARITHMETIC_TYPE_P (intype) && ! (convtype & CONV_STATIC)) || (TREE_CODE (intype) == POINTER_TYPE))) { pedwarn ("conversion from `%#T' to `%#T'", intype, type); if (flag_pedantic_errors) return error_mark_node; } if (IS_AGGR_TYPE (intype)) { tree rval; rval = build_type_conversion (type, e); if (rval) return rval; if (flags & LOOKUP_COMPLAIN) error ("`%#T' used where a `%T' was expected", intype, type); if (flags & LOOKUP_SPECULATIVELY) return NULL_TREE; return error_mark_node; } if (code == BOOLEAN_TYPE) return cp_truthvalue_conversion (e); return fold (convert_to_integer (type, e)); } if (POINTER_TYPE_P (type) || TYPE_PTR_TO_MEMBER_P (type)) return fold (cp_convert_to_pointer (type, e, false)); if (code == VECTOR_TYPE) return fold (convert_to_vector (type, e)); if (code == REAL_TYPE || code == COMPLEX_TYPE) { if (IS_AGGR_TYPE (TREE_TYPE (e))) { tree rval; rval = build_type_conversion (type, e); if (rval) return rval; else if (flags & LOOKUP_COMPLAIN) error ("`%#T' used where a floating point value was expected", TREE_TYPE (e)); } if (code == REAL_TYPE) return fold (convert_to_real (type, e)); else if (code == COMPLEX_TYPE) return fold (convert_to_complex (type, e)); } /* New C++ semantics: since assignment is now based on memberwise copying, if the rhs type is derived from the lhs type, then we may still do a conversion. */ if (IS_AGGR_TYPE_CODE (code)) { tree dtype = TREE_TYPE (e); tree ctor = NULL_TREE; dtype = TYPE_MAIN_VARIANT (dtype); /* Conversion between aggregate types. New C++ semantics allow objects of derived type to be cast to objects of base type. Old semantics only allowed this between pointers. There may be some ambiguity between using a constructor vs. using a type conversion operator when both apply. */ ctor = e; if (abstract_virtuals_error (NULL_TREE, type)) return error_mark_node; if ((flags & LOOKUP_ONLYCONVERTING) && ! (IS_AGGR_TYPE (dtype) && DERIVED_FROM_P (type, dtype))) /* For copy-initialization, first we create a temp of the proper type with a user-defined conversion sequence, then we direct-initialize the target with the temp (see [dcl.init]). */ ctor = build_user_type_conversion (type, ctor, flags); else ctor = build_special_member_call (NULL_TREE, complete_ctor_identifier, build_tree_list (NULL_TREE, ctor), TYPE_BINFO (type), flags); if (ctor) return build_cplus_new (type, ctor); } if (flags & LOOKUP_COMPLAIN) error ("conversion from `%T' to non-scalar type `%T' requested", TREE_TYPE (expr), type); if (flags & LOOKUP_SPECULATIVELY) return NULL_TREE; return error_mark_node; }
/*-------------------------------------------------------------------*/ void alg_square_root(msieve_obj *obj, mp_poly_t *mp_alg_poly, mp_t *n, mp_t *c, signed_mp_t *m1, signed_mp_t *m0, abpair_t *rlist, uint32 num_relations, uint32 check_q, mp_t *sqrt_a) { /* external interface for computing the algebraic square root */ uint32 i; gmp_poly_t alg_poly; gmp_poly_t d_alg_poly; gmp_poly_t prod; gmp_poly_t alg_sqrt; relation_prod_t prodinfo; double log2_prodsize; mpz_t q; /* initialize */ mpz_init(q); gmp_poly_init(&alg_poly); gmp_poly_init(&d_alg_poly); gmp_poly_init(&prod); gmp_poly_init(&alg_sqrt); /* convert the algebraic poly to arbitrary precision */ for (i = 0; i < mp_alg_poly->degree; i++) { signed_mp_t *coeff = mp_alg_poly->coeff + i; mp2gmp(&coeff->num, alg_poly.coeff[i]); if (coeff->sign == NEGATIVE) mpz_neg(alg_poly.coeff[i], alg_poly.coeff[i]); } alg_poly.degree = mp_alg_poly->degree - 1; /* multiply all the relations together */ prodinfo.monic_poly = &alg_poly; prodinfo.rlist = rlist; prodinfo.c = c; logprintf(obj, "multiplying %u relations\n", num_relations); multiply_relations(&prodinfo, 0, num_relations - 1, &prod); logprintf(obj, "multiply complete, coefficients have about " "%3.2lf million bits\n", (double)mpz_sizeinbase(prod.coeff[0], 2) / 1e6); /* perform a sanity check on the result */ i = verify_product(&prod, rlist, num_relations, check_q, c, mp_alg_poly); free(rlist); if (i == 0) { logprintf(obj, "error: relation product is incorrect\n"); goto finished; } /* multiply by the square of the derivative of alg_poly; this will guarantee that the square root of prod actually is an element of the number field defined by alg_poly. If we didn't do this, we run the risk of the main Newton iteration not converging */ gmp_poly_monic_derivative(&alg_poly, &d_alg_poly); gmp_poly_mul(&d_alg_poly, &d_alg_poly, &alg_poly, 0); gmp_poly_mul(&prod, &d_alg_poly, &alg_poly, 1); /* pick the initial small prime to start the Newton iteration. To save both time and memory, choose an initial prime such that squaring it a large number of times will produce a value just a little larger than we need to calculate the square root. Note that contrary to what some authors write, pretty much any starting prime is okay. The Newton iteration has a division by 2, so that 2 must be invertible mod the prime (this is guaranteed for odd primes). Also, the Newton iteration will fail if both square roots have the same value mod the prime; however, even a 16-bit prime makes this very unlikely */ i = mpz_size(prod.coeff[0]); log2_prodsize = (double)GMP_LIMB_BITS * (i - 2) + log(mpz_getlimbn(prod.coeff[0], (mp_size_t)(i-1)) * pow(2.0, (double)GMP_LIMB_BITS) + mpz_getlimbn(prod.coeff[0], (mp_size_t)(i-2))) / M_LN2 + 10000; while (log2_prodsize > 31.5) log2_prodsize *= 0.5; mpz_set_d(q, (uint32)pow(2.0, log2_prodsize) + 1); /* get the initial inverse square root */ if (!get_initial_inv_sqrt(obj, mp_alg_poly, &prod, &alg_sqrt, q)) { goto finished; } /* compute the actual square root */ if (get_final_sqrt(obj, &alg_poly, &prod, &alg_sqrt, q)) convert_to_integer(&alg_sqrt, n, c, m1, m0, sqrt_a); finished: gmp_poly_clear(&prod); gmp_poly_clear(&alg_sqrt); gmp_poly_clear(&alg_poly); gmp_poly_clear(&d_alg_poly); mpz_clear(q); }
tree convert (tree type, tree expr) { tree e = expr; enum tree_code code = TREE_CODE (type); const char *invalid_conv_diag; tree ret; location_t loc = EXPR_LOCATION (expr); if (type == error_mark_node || expr == error_mark_node || TREE_TYPE (expr) == error_mark_node) return error_mark_node; if ((invalid_conv_diag = targetm.invalid_conversion (TREE_TYPE (expr), type))) { error (invalid_conv_diag); return error_mark_node; } if (type == TREE_TYPE (expr)) return expr; ret = targetm.convert_to_type (type, expr); if (ret) return ret; STRIP_TYPE_NOPS (e); if (TYPE_MAIN_VARIANT (type) == TYPE_MAIN_VARIANT (TREE_TYPE (expr))) return fold_convert_loc (loc, type, expr); if (TREE_CODE (TREE_TYPE (expr)) == ERROR_MARK) return error_mark_node; if (TREE_CODE (TREE_TYPE (expr)) == VOID_TYPE) { error ("void value not ignored as it ought to be"); return error_mark_node; } switch (code) { case VOID_TYPE: return fold_convert_loc (loc, type, e); case INTEGER_TYPE: case ENUMERAL_TYPE: ret = convert_to_integer (type, e); goto maybe_fold; case BOOLEAN_TYPE: return fold_convert_loc (loc, type, c_objc_common_truthvalue_conversion (input_location, expr)); case POINTER_TYPE: case REFERENCE_TYPE: ret = convert_to_pointer (type, e); goto maybe_fold; case REAL_TYPE: ret = convert_to_real (type, e); goto maybe_fold; case FIXED_POINT_TYPE: ret = convert_to_fixed (type, e); goto maybe_fold; case COMPLEX_TYPE: ret = convert_to_complex (type, e); goto maybe_fold; case VECTOR_TYPE: ret = convert_to_vector (type, e); goto maybe_fold; case RECORD_TYPE: case UNION_TYPE: if (lang_hooks.types_compatible_p (type, TREE_TYPE (expr))) return e; break; default: break; maybe_fold: if (TREE_CODE (ret) != C_MAYBE_CONST_EXPR) ret = fold (ret); return ret; } error ("conversion to non-scalar type requested"); return error_mark_node; }