00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028 #include "config.h"
00029 #include "system.h"
00030 #include "coretypes.h"
00031 #include "tm.h"
00032 #include "tree.h"
00033 #include "flags.h"
00034 #include "convert.h"
00035 #include "c-common.h"
00036 #include "c-tree.h"
00037 #include "langhooks.h"
00038 #include "toplev.h"
00039 #include "target.h"
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068 tree
00069 convert (tree type, tree expr)
00070 {
00071 tree e = expr;
00072 enum tree_code code = TREE_CODE (type);
00073 const char *invalid_conv_diag;
00074
00075 if (type == error_mark_node
00076 || expr == error_mark_node
00077 || TREE_TYPE (expr) == error_mark_node)
00078 return error_mark_node;
00079
00080 if ((invalid_conv_diag
00081 = targetm.invalid_conversion (TREE_TYPE (expr), type)))
00082 {
00083 error (invalid_conv_diag);
00084 return error_mark_node;
00085 }
00086
00087 if (type == TREE_TYPE (expr))
00088 return expr;
00089
00090 if (TYPE_MAIN_VARIANT (type) == TYPE_MAIN_VARIANT (TREE_TYPE (expr)))
00091 return fold_convert (type, expr);
00092 if (TREE_CODE (TREE_TYPE (expr)) == ERROR_MARK)
00093 return error_mark_node;
00094 if (TREE_CODE (TREE_TYPE (expr)) == VOID_TYPE)
00095 {
00096 error ("void value not ignored as it ought to be");
00097 return error_mark_node;
00098 }
00099 if (code == VOID_TYPE)
00100 return fold_convert (type, e);
00101 if (code == INTEGER_TYPE || code == ENUMERAL_TYPE)
00102 return fold (convert_to_integer (type, e));
00103 if (code == BOOLEAN_TYPE)
00104 return fold_convert (type, c_objc_common_truthvalue_conversion (expr));
00105 if (code == POINTER_TYPE || code == REFERENCE_TYPE)
00106 return fold (convert_to_pointer (type, e));
00107 if (code == REAL_TYPE)
00108 return fold (convert_to_real (type, e));
00109 if (code == COMPLEX_TYPE)
00110 return fold (convert_to_complex (type, e));
00111 if (code == VECTOR_TYPE)
00112 return fold (convert_to_vector (type, e));
00113 if ((code == RECORD_TYPE || code == UNION_TYPE)
00114 && lang_hooks.types_compatible_p (type, TREE_TYPE (expr)))
00115 return e;
00116
00117 error ("conversion to non-scalar type requested");
00118 return error_mark_node;
00119 }