このページを編集する際は,編集に関する方針に従ってください.
概要
2949 /* Build tree nodes and builtin functions common to both C and C++ language 2950 frontends. */
実装
2952 void
2953 c_common_nodes_and_builtins (void)
2954 {
2955 enum builtin_type
2956 {
2957 #define DEF_PRIMITIVE_TYPE(NAME, VALUE) NAME,
2958 #define DEF_FUNCTION_TYPE_0(NAME, RETURN) NAME,
2959 #define DEF_FUNCTION_TYPE_1(NAME, RETURN, ARG1) NAME,
2960 #define DEF_FUNCTION_TYPE_2(NAME, RETURN, ARG1, ARG2) NAME,
2961 #define DEF_FUNCTION_TYPE_3(NAME, RETURN, ARG1, ARG2, ARG3) NAME,
2962 #define DEF_FUNCTION_TYPE_4(NAME, RETURN, ARG1, ARG2, ARG3, ARG4) NAME,
2963 #define DEF_FUNCTION_TYPE_5(NAME, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5) NAME,
2964 #define DEF_FUNCTION_TYPE_6(NAME, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, ARG6) \
2965 NAME,
2966 #define DEF_FUNCTION_TYPE_VAR_0(NAME, RETURN) NAME,
2967 #define DEF_FUNCTION_TYPE_VAR_1(NAME, RETURN, ARG1) NAME,
2968 #define DEF_FUNCTION_TYPE_VAR_2(NAME, RETURN, ARG1, ARG2) NAME,
2969 #define DEF_FUNCTION_TYPE_VAR_3(NAME, RETURN, ARG1, ARG2, ARG3) NAME,
2970 #define DEF_FUNCTION_TYPE_VAR_4(NAME, RETURN, ARG1, ARG2, ARG3, ARG4) NAME,
2971 #define DEF_FUNCTION_TYPE_VAR_5(NAME, RETURN, ARG1, ARG2, ARG3, ARG4, ARG6) \
2972 NAME,
2973 #define DEF_POINTER_TYPE(NAME, TYPE) NAME,
2974 #include "builtin-types.def"
2975 #undef DEF_PRIMITIVE_TYPE
2976 #undef DEF_FUNCTION_TYPE_0
2977 #undef DEF_FUNCTION_TYPE_1
2978 #undef DEF_FUNCTION_TYPE_2
2979 #undef DEF_FUNCTION_TYPE_3
2980 #undef DEF_FUNCTION_TYPE_4
2981 #undef DEF_FUNCTION_TYPE_5
2982 #undef DEF_FUNCTION_TYPE_6
2983 #undef DEF_FUNCTION_TYPE_VAR_0
2984 #undef DEF_FUNCTION_TYPE_VAR_1
2985 #undef DEF_FUNCTION_TYPE_VAR_2
2986 #undef DEF_FUNCTION_TYPE_VAR_3
2987 #undef DEF_FUNCTION_TYPE_VAR_4
2988 #undef DEF_FUNCTION_TYPE_VAR_5
2989 #undef DEF_POINTER_TYPE
2990 BT_LAST
2991 };
2992
2993 typedef enum builtin_type builtin_type;
2994
2995 tree builtin_types[(int) BT_LAST + 1];
2996 int wchar_type_size;
2997 tree array_domain_type;
2998 tree va_list_ref_type_node;
2999 tree va_list_arg_type_node;
3000
3001 /* Define `int' and `char' first so that dbx will output them first. */
3002 record_builtin_type (RID_INT, NULL, integer_type_node);
3003 record_builtin_type (RID_CHAR, "char", char_type_node);
3004
3005 /* `signed' is the same as `int'. FIXME: the declarations of "signed",
3006 "unsigned long", "long long unsigned" and "unsigned short" were in C++
3007 but not C. Are the conditionals here needed? */
3008 if (c_dialect_cxx ())
3009 record_builtin_type (RID_SIGNED, NULL, integer_type_node);
3010 record_builtin_type (RID_LONG, "long int", long_integer_type_node);
3011 record_builtin_type (RID_UNSIGNED, "unsigned int", unsigned_type_node);
3012 record_builtin_type (RID_MAX, "long unsigned int",
3013 long_unsigned_type_node);
3014 if (c_dialect_cxx ())
3015 record_builtin_type (RID_MAX, "unsigned long", long_unsigned_type_node);
3016 record_builtin_type (RID_MAX, "long long int",
3017 long_long_integer_type_node);
3018 record_builtin_type (RID_MAX, "long long unsigned int",
3019 long_long_unsigned_type_node);
3020 if (c_dialect_cxx ())
3021 record_builtin_type (RID_MAX, "long long unsigned",
3022 long_long_unsigned_type_node);
3023 record_builtin_type (RID_SHORT, "short int", short_integer_type_node);
3024 record_builtin_type (RID_MAX, "short unsigned int",
3025 short_unsigned_type_node);
3026 if (c_dialect_cxx ())
3027 record_builtin_type (RID_MAX, "unsigned short",
3028 short_unsigned_type_node);
3029
3030 /* Define both `signed char' and `unsigned char'. */
3031 record_builtin_type (RID_MAX, "signed char", signed_char_type_node);
3032 record_builtin_type (RID_MAX, "unsigned char", unsigned_char_type_node);
3033
3034 /* These are types that c_common_type_for_size and
3035 c_common_type_for_mode use. */
3036 lang_hooks.decls.pushdecl (build_decl (TYPE_DECL, NULL_TREE,
3037 intQI_type_node));
3038 lang_hooks.decls.pushdecl (build_decl (TYPE_DECL, NULL_TREE,
3039 intHI_type_node));
3040 lang_hooks.decls.pushdecl (build_decl (TYPE_DECL, NULL_TREE,
3041 intSI_type_node));
3042 lang_hooks.decls.pushdecl (build_decl (TYPE_DECL, NULL_TREE,
3043 intDI_type_node));
3044 #if HOST_BITS_PER_WIDE_INT >= 64
3045 if (targetm.scalar_mode_supported_p (TImode))
3046 lang_hooks.decls.pushdecl (build_decl (TYPE_DECL,
3047 get_identifier ("__int128_t"),
3048 intTI_type_node));
3049 #endif
3050 lang_hooks.decls.pushdecl (build_decl (TYPE_DECL, NULL_TREE,
3051 unsigned_intQI_type_node));
3052 lang_hooks.decls.pushdecl (build_decl (TYPE_DECL, NULL_TREE,
3053 unsigned_intHI_type_node));
3054 lang_hooks.decls.pushdecl (build_decl (TYPE_DECL, NULL_TREE,
3055 unsigned_intSI_type_node));
3056 lang_hooks.decls.pushdecl (build_decl (TYPE_DECL, NULL_TREE,
3057 unsigned_intDI_type_node));
3058 #if HOST_BITS_PER_WIDE_INT >= 64
3059 if (targetm.scalar_mode_supported_p (TImode))
3060 lang_hooks.decls.pushdecl (build_decl (TYPE_DECL,
3061 get_identifier ("__uint128_t"),
3062 unsigned_intTI_type_node));
3063 #endif
3064
3065 /* Create the widest literal types. */
3066 widest_integer_literal_type_node
3067 = make_signed_type (HOST_BITS_PER_WIDE_INT * 2);
3068 lang_hooks.decls.pushdecl (build_decl (TYPE_DECL, NULL_TREE,
3069 widest_integer_literal_type_node));
3070
3071 widest_unsigned_literal_type_node
3072 = make_unsigned_type (HOST_BITS_PER_WIDE_INT * 2);
3073 lang_hooks.decls.pushdecl (build_decl (TYPE_DECL, NULL_TREE,
3074 widest_unsigned_literal_type_node));
3075
3076 /* `unsigned long' is the standard type for sizeof.
3077 Note that stddef.h uses `unsigned long',
3078 and this must agree, even if long and int are the same size. */
3079 size_type_node =
3080 TREE_TYPE (identifier_global_value (get_identifier (SIZE_TYPE)));
3081 signed_size_type_node = c_common_signed_type (size_type_node);
3082 set_sizetype (size_type_node);
3083
3084 pid_type_node =
3085 TREE_TYPE (identifier_global_value (get_identifier (PID_TYPE)));
3086
3087 build_common_tree_nodes_2 (flag_short_double);
3088
3089 record_builtin_type (RID_FLOAT, NULL, float_type_node);
3090 record_builtin_type (RID_DOUBLE, NULL, double_type_node);
3091 record_builtin_type (RID_MAX, "long double", long_double_type_node);
3092
3093 lang_hooks.decls.pushdecl (build_decl (TYPE_DECL,
3094 get_identifier ("complex int"),
3095 complex_integer_type_node));
3096 lang_hooks.decls.pushdecl (build_decl (TYPE_DECL,
3097 get_identifier ("complex float"),
3098 complex_float_type_node));
3099 lang_hooks.decls.pushdecl (build_decl (TYPE_DECL,
3100 get_identifier ("complex double"),
3101 complex_double_type_node));
3102 lang_hooks.decls.pushdecl
3103 (build_decl (TYPE_DECL, get_identifier ("complex long double"),
3104 complex_long_double_type_node));
3105
3106 if (c_dialect_cxx ())
3107 /* For C++, make fileptr_type_node a distinct void * type until
3108 FILE type is defined. */
3109 fileptr_type_node = build_variant_type_copy (ptr_type_node);
3110
3111 record_builtin_type (RID_VOID, NULL, void_type_node);
3112
3113 /* This node must not be shared. */
3114 void_zero_node = make_node (INTEGER_CST);
3115 TREE_TYPE (void_zero_node) = void_type_node;
3116
3117 void_list_node = build_void_list_node ();
3118
3119 /* Make a type to be the domain of a few array types
3120 whose domains don't really matter.
3121 200 is small enough that it always fits in size_t
3122 and large enough that it can hold most function names for the
3123 initializations of __FUNCTION__ and __PRETTY_FUNCTION__. */
3124 array_domain_type = build_index_type (size_int (200));
3125
3126 /* Make a type for arrays of characters.
3127 With luck nothing will ever really depend on the length of this
3128 array type. */
3129 char_array_type_node
3130 = build_array_type (char_type_node, array_domain_type);
3131
3132 /* Likewise for arrays of ints. */
3133 int_array_type_node
3134 = build_array_type (integer_type_node, array_domain_type);
3135
3136 string_type_node = build_pointer_type (char_type_node);
3137 const_string_type_node
3138 = build_pointer_type (build_qualified_type
3139 (char_type_node, TYPE_QUAL_CONST));
3140
3141 /* This is special for C++ so functions can be overloaded. */
3142 wchar_type_node = get_identifier (MODIFIED_WCHAR_TYPE);
3143 wchar_type_node = TREE_TYPE (identifier_global_value (wchar_type_node));
3144 wchar_type_size = TYPE_PRECISION (wchar_type_node);
3145 if (c_dialect_cxx ())
3146 {
3147 if (TYPE_UNSIGNED (wchar_type_node))
3148 wchar_type_node = make_unsigned_type (wchar_type_size);
3149 else
3150 wchar_type_node = make_signed_type (wchar_type_size);
3151 record_builtin_type (RID_WCHAR, "wchar_t", wchar_type_node);
3152 }
3153 else
3154 {
3155 signed_wchar_type_node = c_common_signed_type (wchar_type_node);
3156 unsigned_wchar_type_node = c_common_unsigned_type (wchar_type_node);
3157 }
3158
3159 /* This is for wide string constants. */
3160 wchar_array_type_node
3161 = build_array_type (wchar_type_node, array_domain_type);
3162
3163 wint_type_node =
3164 TREE_TYPE (identifier_global_value (get_identifier (WINT_TYPE)));
3165
3166 intmax_type_node =
3167 TREE_TYPE (identifier_global_value (get_identifier (INTMAX_TYPE)));
3168 uintmax_type_node =
3169 TREE_TYPE (identifier_global_value (get_identifier (UINTMAX_TYPE)));
3170
3171 default_function_type = build_function_type (integer_type_node, NULL_TREE);
3172 ptrdiff_type_node
3173 = TREE_TYPE (identifier_global_value (get_identifier (PTRDIFF_TYPE)));
3174 unsigned_ptrdiff_type_node = c_common_unsigned_type (ptrdiff_type_node);
3175
3176 lang_hooks.decls.pushdecl
3177 (build_decl (TYPE_DECL, get_identifier ("__builtin_va_list"),
3178 va_list_type_node));
3179
3180 if (TREE_CODE (va_list_type_node) == ARRAY_TYPE)
3181 {
3182 va_list_arg_type_node = va_list_ref_type_node =
3183 build_pointer_type (TREE_TYPE (va_list_type_node));
3184 }
3185 else
3186 {
3187 va_list_arg_type_node = va_list_type_node;
3188 va_list_ref_type_node = build_reference_type (va_list_type_node);
3189 }
3190
3191 #define DEF_PRIMITIVE_TYPE(ENUM, VALUE) \
3192 builtin_types[(int) ENUM] = VALUE;
3193 #define DEF_FUNCTION_TYPE_0(ENUM, RETURN) \
3194 builtin_types[(int) ENUM] \
3195 = build_function_type (builtin_types[(int) RETURN], \
3196 void_list_node);
3197 #define DEF_FUNCTION_TYPE_1(ENUM, RETURN, ARG1) \
3198 builtin_types[(int) ENUM] \
3199 = build_function_type (builtin_types[(int) RETURN], \
3200 tree_cons (NULL_TREE, \
3201 builtin_types[(int) ARG1], \
3202 void_list_node));
3203 #define DEF_FUNCTION_TYPE_2(ENUM, RETURN, ARG1, ARG2) \
3204 builtin_types[(int) ENUM] \
3205 = build_function_type \
3206 (builtin_types[(int) RETURN], \
3207 tree_cons (NULL_TREE, \
3208 builtin_types[(int) ARG1], \
3209 tree_cons (NULL_TREE, \
3210 builtin_types[(int) ARG2], \
3211 void_list_node)));
3212 #define DEF_FUNCTION_TYPE_3(ENUM, RETURN, ARG1, ARG2, ARG3) \
3213 builtin_types[(int) ENUM] \
3214 = build_function_type \
3215 (builtin_types[(int) RETURN], \
3216 tree_cons (NULL_TREE, \
3217 builtin_types[(int) ARG1], \
3218 tree_cons (NULL_TREE, \
3219 builtin_types[(int) ARG2], \
3220 tree_cons (NULL_TREE, \
3221 builtin_types[(int) ARG3], \
3222 void_list_node))));
3223 #define DEF_FUNCTION_TYPE_4(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4) \
3224 builtin_types[(int) ENUM] \
3225 = build_function_type \
3226 (builtin_types[(int) RETURN], \
3227 tree_cons (NULL_TREE, \
3228 builtin_types[(int) ARG1], \
3229 tree_cons (NULL_TREE, \
3230 builtin_types[(int) ARG2], \
3231 tree_cons \
3232 (NULL_TREE, \
3233 builtin_types[(int) ARG3], \
3234 tree_cons (NULL_TREE, \
3235 builtin_types[(int) ARG4], \
3236 void_list_node)))));
3237 #define DEF_FUNCTION_TYPE_5(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5) \
3238 builtin_types[(int) ENUM] \
3239 = build_function_type \
3240 (builtin_types[(int) RETURN], \
3241 tree_cons (NULL_TREE, \
3242 builtin_types[(int) ARG1], \
3243 tree_cons (NULL_TREE, \
3244 builtin_types[(int) ARG2], \
3245 tree_cons \
3246 (NULL_TREE, \
3247 builtin_types[(int) ARG3], \
3248 tree_cons (NULL_TREE, \
3249 builtin_types[(int) ARG4], \
3250 tree_cons (NULL_TREE, \
3251 builtin_types[(int) ARG5],\
3252 void_list_node))))));
3253 #define DEF_FUNCTION_TYPE_6(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, \
3254 ARG6) \
3255 builtin_types[(int) ENUM] \
3256 = build_function_type \
3257 (builtin_types[(int) RETURN], \
3258 tree_cons (NULL_TREE, \
3259 builtin_types[(int) ARG1], \
3260 tree_cons (NULL_TREE, \
3261 builtin_types[(int) ARG2], \
3262 tree_cons \
3263 (NULL_TREE, \
3264 builtin_types[(int) ARG3], \
3265 tree_cons \
3266 (NULL_TREE, \
3267 builtin_types[(int) ARG4], \
3268 tree_cons (NULL_TREE, \
3269 builtin_types[(int) ARG5], \
3270 tree_cons (NULL_TREE, \
3271 builtin_types[(int) ARG6],\
3272 void_list_node)))))));
3273 #define DEF_FUNCTION_TYPE_VAR_0(ENUM, RETURN) \
3274 builtin_types[(int) ENUM] \
3275 = build_function_type (builtin_types[(int) RETURN], NULL_TREE);
3276 #define DEF_FUNCTION_TYPE_VAR_1(ENUM, RETURN, ARG1) \
3277 builtin_types[(int) ENUM] \
3278 = build_function_type (builtin_types[(int) RETURN], \
3279 tree_cons (NULL_TREE, \
3280 builtin_types[(int) ARG1], \
3281 NULL_TREE));
3282
3283 #define DEF_FUNCTION_TYPE_VAR_2(ENUM, RETURN, ARG1, ARG2) \
3284 builtin_types[(int) ENUM] \
3285 = build_function_type \
3286 (builtin_types[(int) RETURN], \
3287 tree_cons (NULL_TREE, \
3288 builtin_types[(int) ARG1], \
3289 tree_cons (NULL_TREE, \
3290 builtin_types[(int) ARG2], \
3291 NULL_TREE)));
3292
3293 #define DEF_FUNCTION_TYPE_VAR_3(ENUM, RETURN, ARG1, ARG2, ARG3) \
3294 builtin_types[(int) ENUM] \
3295 = build_function_type \
3296 (builtin_types[(int) RETURN], \
3297 tree_cons (NULL_TREE, \
3298 builtin_types[(int) ARG1], \
3299 tree_cons (NULL_TREE, \
3300 builtin_types[(int) ARG2], \
3301 tree_cons (NULL_TREE, \
3302 builtin_types[(int) ARG3], \
3303 NULL_TREE))));
3304
3305 #define DEF_FUNCTION_TYPE_VAR_4(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4) \
3306 builtin_types[(int) ENUM] \
3307 = build_function_type \
3308 (builtin_types[(int) RETURN], \
3309 tree_cons (NULL_TREE, \
3310 builtin_types[(int) ARG1], \
3311 tree_cons (NULL_TREE, \
3312 builtin_types[(int) ARG2], \
3313 tree_cons (NULL_TREE, \
3314 builtin_types[(int) ARG3], \
3315 tree_cons (NULL_TREE, \
3316 builtin_types[(int) ARG4],\
3317 NULL_TREE)))));
3318
3319 #define DEF_FUNCTION_TYPE_VAR_5(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4, \
3320 ARG5) \
3321 builtin_types[(int) ENUM] \
3322 = build_function_type \
3323 (builtin_types[(int) RETURN], \
3324 tree_cons (NULL_TREE, \
3325 builtin_types[(int) ARG1], \
3326 tree_cons (NULL_TREE, \
3327 builtin_types[(int) ARG2], \
3328 tree_cons \
3329 (NULL_TREE, \
3330 builtin_types[(int) ARG3], \
3331 tree_cons (NULL_TREE, \
3332 builtin_types[(int) ARG4], \
3333 tree_cons (NULL_TREE, \
3334 builtin_types[(int) ARG5],\
3335 NULL_TREE))))));
3336
3337 #define DEF_POINTER_TYPE(ENUM, TYPE) \
3338 builtin_types[(int) ENUM] \
3339 = build_pointer_type (builtin_types[(int) TYPE]);
3340 #include "builtin-types.def"
3341 #undef DEF_PRIMITIVE_TYPE
3342 #undef DEF_FUNCTION_TYPE_1
3343 #undef DEF_FUNCTION_TYPE_2
3344 #undef DEF_FUNCTION_TYPE_3
3345 #undef DEF_FUNCTION_TYPE_4
3346 #undef DEF_FUNCTION_TYPE_5
3347 #undef DEF_FUNCTION_TYPE_6
3348 #undef DEF_FUNCTION_TYPE_VAR_0
3349 #undef DEF_FUNCTION_TYPE_VAR_1
3350 #undef DEF_FUNCTION_TYPE_VAR_2
3351 #undef DEF_FUNCTION_TYPE_VAR_3
3352 #undef DEF_FUNCTION_TYPE_VAR_4
3353 #undef DEF_FUNCTION_TYPE_VAR_5
3354 #undef DEF_POINTER_TYPE
3355 builtin_types[(int) BT_LAST] = NULL_TREE;
3356
3357 c_init_attributes ();
3358
3359 #define DEF_BUILTIN(ENUM, NAME, CLASS, TYPE, LIBTYPE, BOTH_P, FALLBACK_P, \
3360 NONANSI_P, ATTRS, IMPLICIT, COND) \
3361 if (NAME && COND) \
3362 def_builtin_1 (ENUM, NAME, CLASS, \
3363 builtin_types[(int) TYPE], \
3364 builtin_types[(int) LIBTYPE], \
3365 BOTH_P, FALLBACK_P, NONANSI_P, \
3366 built_in_attributes[(int) ATTRS], IMPLICIT);
3367 #include "builtins.def"
3368 #undef DEF_BUILTIN
3369
3370 build_common_builtin_nodes ();
3371
3372 targetm.init_builtins ();
3373 if (flag_mudflap)
3374 mudflap_init ();
3375
3376 main_identifier_node = get_identifier ("main");
3377
3378 /* Create the built-in __null node. It is important that this is
3379 not shared. */
3380 null_node = make_node (INTEGER_CST);
3381 TREE_TYPE (null_node) = c_common_type_for_size (POINTER_SIZE, 0);
3382 }