diff options
author | Eric Botcazou <ebotcazou@adacore.com> | 2009-04-07 09:41:40 +0000 |
---|---|---|
committer | Eric Botcazou <ebotcazou@gcc.gnu.org> | 2009-04-07 09:41:40 +0000 |
commit | 10069d53fb535c72d70e2c7dab53347d40a89f37 (patch) | |
tree | 7bfd8c79bf5aaa359b8138379bc370dafdabe883 /gcc/ada/gcc-interface/utils.c | |
parent | 1e17ef870e0889e68c707702cb9bb528aa960aa5 (diff) | |
download | gcc-10069d53fb535c72d70e2c7dab53347d40a89f37.zip gcc-10069d53fb535c72d70e2c7dab53347d40a89f37.tar.gz gcc-10069d53fb535c72d70e2c7dab53347d40a89f37.tar.bz2 |
gigi.h (standard_datatypes): Remove ADT_void_type_decl.
* gcc-interface/gigi.h (standard_datatypes): Remove ADT_void_type_decl.
(void_type_decl_node): Remove.
(init_gigi_decls): Likewise.
(gnat_install_builtins): Declare.
(record_builtin_type): Likewise.
(create_type_stub_decl): Likewise.
* gcc-interface/decl.c (gnat_to_gnu_entity) <E_Void>: Use void_type.
(gnat_to_gnu_entity) <E_Array_Type>: Make fat and thin pointer types
artificial.
<E_Array_Subtype>: Use the index types, not only their name, in the
record giving the names of the bounds, if any.
For a packed array type, make it artificial only if the base type
was artificial as well. Remove redundant statement.
(gnat_to_gnu_entity) <E_Incomplete_Type>: Do not create TYPE_DECL for
dummy types.
Use create_type_stub_decl to build the TYPE_STUB_DECL of types.
(rest_of_type_decl_compilation_no_defer): Likewise.
* gcc-interface/misc.c (gnat_printable_name): Add missing guard.
* gcc-interface/utils.c (make_dummy_type): Always create TYPE_STUB_DECL
and use create_type_stub_decl to build it.
(gnat_pushdecl): Rewrite condition.
(gnat_install_builtins): Remove bogus declaration.
(record_builtin_type): New function.
(finish_record_type): Use create_type_stub_decl to build TYPE_STUB_DECL
of types.
(create_type_stub_decl): New function.
(create_type_decl): Assert that the type is not dummy. If the type
hasn't been named yet, equate the TYPE_STUB_DECL to the created node.
(build_vms_descriptor32): Do not create TYPE_DECL for the descriptor.
(build_vms_descriptor): Likewise.
(init_gigi_decls): Delete and move bulk of code to...
* gcc-interface/trans.c (gigi): ...here. Use record_builtin_type.
(emit_range_check): Add gnat_node parameter.
(emit_index_check): Likewise.
(emit_check): Likewise.
(build_unary_op_trapv): Likewise.
(build_binary_op_trapv): Likewise.
(convert_with_check): Likewise.
(Attribute_to_gnu): Adjust calls for above changes.
(call_to_gnu): Likewise.
(gnat_to_gnu): Likewise.
(assoc_to_constructor): Likewise.
(pos_to_constructor): Likewise.
(Sloc_to_locus): Set BUILTINS_LOCATION for Standard_Location nodes.
(process_type): Do not create TYPE_DECL for dummy types.
From-SVN: r145660
Diffstat (limited to 'gcc/ada/gcc-interface/utils.c')
-rw-r--r-- | gcc/ada/gcc-interface/utils.c | 366 |
1 files changed, 67 insertions, 299 deletions
diff --git a/gcc/ada/gcc-interface/utils.c b/gcc/ada/gcc-interface/utils.c index bbf5196..78080b1 100644 --- a/gcc/ada/gcc-interface/utils.c +++ b/gcc/ada/gcc-interface/utils.c @@ -6,7 +6,7 @@ * * * C Implementation File * * * - * Copyright (C) 1992-2008, Free Software Foundation, Inc. * + * Copyright (C) 1992-2009, Free Software Foundation, Inc. * * * * GNAT is free software; you can redistribute it and/or modify it under * * terms of the GNU General Public License as published by the Free Soft- * @@ -188,7 +188,6 @@ static GTY(()) VEC(tree,gc) *global_renaming_pointers; /* A chain of unused BLOCK nodes. */ static GTY((deletable)) tree free_block_chain; -static void gnat_install_builtins (void); static tree merge_sizes (tree, tree, tree, bool, bool); static tree compute_related_constant (tree, tree); static tree split_plus (tree, tree *); @@ -287,11 +286,10 @@ make_dummy_type (Entity_Id gnat_type) : ENUMERAL_TYPE); TYPE_NAME (gnu_type) = get_entity_name (gnat_type); TYPE_DUMMY_P (gnu_type) = 1; + TYPE_STUB_DECL (gnu_type) + = create_type_stub_decl (TYPE_NAME (gnu_type), gnu_type); if (AGGREGATE_TYPE_P (gnu_type)) - { - TYPE_STUB_DECL (gnu_type) = build_decl (TYPE_DECL, NULL_TREE, gnu_type); - TYPE_BY_REFERENCE_P (gnu_type) = Is_By_Reference_Type (gnat_type); - } + TYPE_BY_REFERENCE_P (gnu_type) = Is_By_Reference_Type (gnat_type); SET_DUMMY_NODE (gnat_underlying, gnu_type); @@ -465,8 +463,7 @@ gnat_pushdecl (tree decl, Node_Id gnat_node) } /* For the declaration of a type, set its name if it either is not already - set, was set to an IDENTIFIER_NODE, indicating an internal name, - or if the previous type name was not derived from a source name. + set or if the previous type name was not derived from a source name. We'd rather have the type named with a real name and all the pointer types to the same object have the same POINTER_TYPE node. Code in the equivalent function of c-decl.c makes a copy of the type node here, but @@ -478,7 +475,7 @@ gnat_pushdecl (tree decl, Node_Id gnat_node) { tree t = TREE_TYPE (decl); - if (!TYPE_NAME (t) || TREE_CODE (TYPE_NAME (t)) == IDENTIFIER_NODE) + if (!(TYPE_NAME (t) && TREE_CODE (TYPE_NAME (t)) == TYPE_DECL)) ; else if (TYPE_FAT_POINTER_P (t)) { @@ -534,271 +531,18 @@ gnat_init_decl_processing (void) ptr_void_type_node = build_pointer_type (void_type_node); } - -/* Create the predefined scalar types such as `integer_type_node' needed - in the gcc back-end and initialize the global binding level. */ + +/* Record TYPE as a builtin type for Ada. NAME is the name of the type. */ void -init_gigi_decls (tree long_long_float_type, tree exception_type) +record_builtin_type (const char *name, tree type) { - tree endlink, decl; - tree int64_type = gnat_type_for_size (64, 0); - unsigned int i; - - /* Set the types that GCC and Gigi use from the front end. We would like - to do this for char_type_node, but it needs to correspond to the C - char type. */ - if (TREE_CODE (TREE_TYPE (long_long_float_type)) == INTEGER_TYPE) - { - /* In this case, the builtin floating point types are VAX float, - so make up a type for use. */ - longest_float_type_node = make_node (REAL_TYPE); - TYPE_PRECISION (longest_float_type_node) = LONG_DOUBLE_TYPE_SIZE; - layout_type (longest_float_type_node); - create_type_decl (get_identifier ("longest float type"), - longest_float_type_node, NULL, false, true, Empty); - } - else - longest_float_type_node = TREE_TYPE (long_long_float_type); - - except_type_node = TREE_TYPE (exception_type); - - unsigned_type_node = gnat_type_for_size (INT_TYPE_SIZE, 1); - create_type_decl (get_identifier ("unsigned int"), unsigned_type_node, - NULL, false, true, Empty); - - void_type_decl_node = create_type_decl (get_identifier ("void"), - void_type_node, NULL, false, true, - Empty); - - void_ftype = build_function_type (void_type_node, NULL_TREE); - ptr_void_ftype = build_pointer_type (void_ftype); - - /* Build the special descriptor type and its null node if needed. */ - if (TARGET_VTABLE_USES_DESCRIPTORS) - { - tree null_node = fold_convert (ptr_void_ftype, null_pointer_node); - tree field_list = NULL_TREE, null_list = NULL_TREE; - int j; - - fdesc_type_node = make_node (RECORD_TYPE); - - for (j = 0; j < TARGET_VTABLE_USES_DESCRIPTORS; j++) - { - tree field = create_field_decl (NULL_TREE, ptr_void_ftype, - fdesc_type_node, 0, 0, 0, 1); - TREE_CHAIN (field) = field_list; - field_list = field; - null_list = tree_cons (field, null_node, null_list); - } - - finish_record_type (fdesc_type_node, nreverse (field_list), 0, false); - null_fdesc_node = gnat_build_constructor (fdesc_type_node, null_list); - } + tree type_decl = build_decl (TYPE_DECL, get_identifier (name), type); - /* Now declare runtime functions. */ - endlink = tree_cons (NULL_TREE, void_type_node, NULL_TREE); - - /* malloc is a function declaration tree for a function to allocate - memory. */ - malloc_decl = create_subprog_decl (get_identifier ("__gnat_malloc"), - NULL_TREE, - build_function_type (ptr_void_type_node, - tree_cons (NULL_TREE, - sizetype, - endlink)), - NULL_TREE, false, true, true, NULL, - Empty); - DECL_IS_MALLOC (malloc_decl) = 1; - - /* malloc32 is a function declaration tree for a function to allocate - 32bit memory on a 64bit system. Needed only on 64bit VMS. */ - malloc32_decl = create_subprog_decl (get_identifier ("__gnat_malloc32"), - NULL_TREE, - build_function_type (ptr_void_type_node, - tree_cons (NULL_TREE, - sizetype, - endlink)), - NULL_TREE, false, true, true, NULL, - Empty); - DECL_IS_MALLOC (malloc32_decl) = 1; - - /* free is a function declaration tree for a function to free memory. */ - free_decl - = create_subprog_decl (get_identifier ("__gnat_free"), NULL_TREE, - build_function_type (void_type_node, - tree_cons (NULL_TREE, - ptr_void_type_node, - endlink)), - NULL_TREE, false, true, true, NULL, Empty); - - /* This is used for 64-bit multiplication with overflow checking. */ - mulv64_decl - = create_subprog_decl (get_identifier ("__gnat_mulv64"), NULL_TREE, - build_function_type_list (int64_type, int64_type, - int64_type, NULL_TREE), - NULL_TREE, false, true, true, NULL, Empty); - - /* Make the types and functions used for exception processing. */ - jmpbuf_type - = build_array_type (gnat_type_for_mode (Pmode, 0), - build_index_type (build_int_cst (NULL_TREE, 5))); - create_type_decl (get_identifier ("JMPBUF_T"), jmpbuf_type, NULL, - true, true, Empty); - jmpbuf_ptr_type = build_pointer_type (jmpbuf_type); - - /* Functions to get and set the jumpbuf pointer for the current thread. */ - get_jmpbuf_decl - = create_subprog_decl - (get_identifier ("system__soft_links__get_jmpbuf_address_soft"), - NULL_TREE, build_function_type (jmpbuf_ptr_type, NULL_TREE), - NULL_TREE, false, true, true, NULL, Empty); - /* Avoid creating superfluous edges to __builtin_setjmp receivers. */ - DECL_PURE_P (get_jmpbuf_decl) = 1; - - set_jmpbuf_decl - = create_subprog_decl - (get_identifier ("system__soft_links__set_jmpbuf_address_soft"), - NULL_TREE, - build_function_type (void_type_node, - tree_cons (NULL_TREE, jmpbuf_ptr_type, endlink)), - NULL_TREE, false, true, true, NULL, Empty); - - /* Function to get the current exception. */ - get_excptr_decl - = create_subprog_decl - (get_identifier ("system__soft_links__get_gnat_exception"), - NULL_TREE, - build_function_type (build_pointer_type (except_type_node), NULL_TREE), - NULL_TREE, false, true, true, NULL, Empty); - /* Avoid creating superfluous edges to __builtin_setjmp receivers. */ - DECL_PURE_P (get_excptr_decl) = 1; - - /* Functions that raise exceptions. */ - raise_nodefer_decl - = create_subprog_decl - (get_identifier ("__gnat_raise_nodefer_with_msg"), NULL_TREE, - build_function_type (void_type_node, - tree_cons (NULL_TREE, - build_pointer_type (except_type_node), - endlink)), - NULL_TREE, false, true, true, NULL, Empty); - - /* Dummy objects to materialize "others" and "all others" in the exception - tables. These are exported by a-exexpr.adb, so see this unit for the - types to use. */ - - others_decl - = create_var_decl (get_identifier ("OTHERS"), - get_identifier ("__gnat_others_value"), - integer_type_node, 0, 1, 0, 1, 1, 0, Empty); - - all_others_decl - = create_var_decl (get_identifier ("ALL_OTHERS"), - get_identifier ("__gnat_all_others_value"), - integer_type_node, 0, 1, 0, 1, 1, 0, Empty); - - /* Hooks to call when entering/leaving an exception handler. */ - begin_handler_decl - = create_subprog_decl (get_identifier ("__gnat_begin_handler"), NULL_TREE, - build_function_type (void_type_node, - tree_cons (NULL_TREE, - ptr_void_type_node, - endlink)), - NULL_TREE, false, true, true, NULL, Empty); - - end_handler_decl - = create_subprog_decl (get_identifier ("__gnat_end_handler"), NULL_TREE, - build_function_type (void_type_node, - tree_cons (NULL_TREE, - ptr_void_type_node, - endlink)), - NULL_TREE, false, true, true, NULL, Empty); - - /* If in no exception handlers mode, all raise statements are redirected to - __gnat_last_chance_handler. No need to redefine raise_nodefer_decl, since - this procedure will never be called in this mode. */ - if (No_Exception_Handlers_Set ()) - { - decl - = create_subprog_decl - (get_identifier ("__gnat_last_chance_handler"), NULL_TREE, - build_function_type (void_type_node, - tree_cons (NULL_TREE, - build_pointer_type (char_type_node), - tree_cons (NULL_TREE, - integer_type_node, - endlink))), - NULL_TREE, false, true, true, NULL, Empty); - - for (i = 0; i < ARRAY_SIZE (gnat_raise_decls); i++) - gnat_raise_decls[i] = decl; - } - else - /* Otherwise, make one decl for each exception reason. */ - for (i = 0; i < ARRAY_SIZE (gnat_raise_decls); i++) - { - char name[17]; - - sprintf (name, "__gnat_rcheck_%.2d", i); - gnat_raise_decls[i] - = create_subprog_decl - (get_identifier (name), NULL_TREE, - build_function_type (void_type_node, - tree_cons (NULL_TREE, - build_pointer_type - (char_type_node), - tree_cons (NULL_TREE, - integer_type_node, - endlink))), - NULL_TREE, false, true, true, NULL, Empty); - } - - /* Indicate that these never return. */ - TREE_THIS_VOLATILE (raise_nodefer_decl) = 1; - TREE_SIDE_EFFECTS (raise_nodefer_decl) = 1; - TREE_TYPE (raise_nodefer_decl) - = build_qualified_type (TREE_TYPE (raise_nodefer_decl), - TYPE_QUAL_VOLATILE); + gnat_pushdecl (type_decl, Empty); - for (i = 0; i < ARRAY_SIZE (gnat_raise_decls); i++) - { - TREE_THIS_VOLATILE (gnat_raise_decls[i]) = 1; - TREE_SIDE_EFFECTS (gnat_raise_decls[i]) = 1; - TREE_TYPE (gnat_raise_decls[i]) - = build_qualified_type (TREE_TYPE (gnat_raise_decls[i]), - TYPE_QUAL_VOLATILE); - } - - /* setjmp returns an integer and has one operand, which is a pointer to - a jmpbuf. */ - setjmp_decl - = create_subprog_decl - (get_identifier ("__builtin_setjmp"), NULL_TREE, - build_function_type (integer_type_node, - tree_cons (NULL_TREE, jmpbuf_ptr_type, endlink)), - NULL_TREE, false, true, true, NULL, Empty); - - DECL_BUILT_IN_CLASS (setjmp_decl) = BUILT_IN_NORMAL; - DECL_FUNCTION_CODE (setjmp_decl) = BUILT_IN_SETJMP; - - /* update_setjmp_buf updates a setjmp buffer from the current stack pointer - address. */ - update_setjmp_buf_decl - = create_subprog_decl - (get_identifier ("__builtin_update_setjmp_buf"), NULL_TREE, - build_function_type (void_type_node, - tree_cons (NULL_TREE, jmpbuf_ptr_type, endlink)), - NULL_TREE, false, true, true, NULL, Empty); - - DECL_BUILT_IN_CLASS (update_setjmp_buf_decl) = BUILT_IN_NORMAL; - DECL_FUNCTION_CODE (update_setjmp_buf_decl) = BUILT_IN_UPDATE_SETJMP_BUF; - - main_identifier_node = get_identifier ("main"); - - /* Install the builtins we might need, either internally or as - user available facilities for Intrinsic imports. */ - gnat_install_builtins (); + if (debug_hooks->type_decl) + debug_hooks->type_decl (type_decl, false); } /* Given a record type RECORD_TYPE and a chain of FIELD_DECL nodes FIELDLIST, @@ -824,15 +568,13 @@ finish_record_type (tree record_type, tree fieldlist, int rep_level, bool had_align = TYPE_ALIGN (record_type) != 0; tree field; - if (name && TREE_CODE (name) == TYPE_DECL) - name = DECL_NAME (name); - TYPE_FIELDS (record_type) = fieldlist; - TYPE_STUB_DECL (record_type) = build_decl (TYPE_DECL, name, record_type); - /* We don't need both the typedef name and the record name output in - the debugging information, since they are the same. */ - DECL_ARTIFICIAL (TYPE_STUB_DECL (record_type)) = 1; + /* Always attach the TYPE_STUB_DECL for a record type. It is required to + generate debug info and have a parallel type. */ + if (name && TREE_CODE (name) == TYPE_DECL) + name = DECL_NAME (name); + TYPE_STUB_DECL (record_type) = create_type_stub_decl (name, record_type); /* Globally initialize the record first. If this is a rep'ed record, that just means some initializations; otherwise, layout the record. */ @@ -1075,8 +817,7 @@ rest_of_record_type_compilation (tree record_type) TYPE_NAME (new_record_type) = new_id; TYPE_ALIGN (new_record_type) = BIGGEST_ALIGNMENT; TYPE_STUB_DECL (new_record_type) - = build_decl (TYPE_DECL, new_id, new_record_type); - DECL_ARTIFICIAL (TYPE_STUB_DECL (new_record_type)) = 1; + = create_type_stub_decl (new_id, new_record_type); DECL_IGNORED_P (TYPE_STUB_DECL (new_record_type)) = DECL_IGNORED_P (TYPE_STUB_DECL (record_type)); TYPE_SIZE (new_record_type) = size_int (TYPE_ALIGN (record_type)); @@ -1448,30 +1189,62 @@ create_index_type (tree min, tree max, tree index, Node_Id gnat_node) return type; } -/* Return a TYPE_DECL node. TYPE_NAME gives the name of the type (a character - string) and TYPE is a ..._TYPE node giving its data type. - ARTIFICIAL_P is true if this is a declaration that was generated - by the compiler. DEBUG_INFO_P is true if we need to write debugging - information about this type. GNAT_NODE is used for the position of - the decl. */ +/* Return a TYPE_DECL node suitable for the TYPE_STUB_DECL field of a type. + TYPE_NAME gives the name of the type and TYPE is a ..._TYPE node giving + its data type. */ + +tree +create_type_stub_decl (tree type_name, tree type) +{ + /* Using a named TYPE_DECL ensures that a type name marker is emitted in + STABS while setting DECL_ARTIFICIAL ensures that no DW_TAG_typedef is + emitted in DWARF. */ + tree type_decl = build_decl (TYPE_DECL, type_name, type); + DECL_ARTIFICIAL (type_decl) = 1; + return type_decl; +} + +/* Return a TYPE_DECL node. TYPE_NAME gives the name of the type and TYPE + is a ..._TYPE node giving its data type. ARTIFICIAL_P is true if this + is a declaration that was generated by the compiler. DEBUG_INFO_P is + true if we need to write debug information about this type. GNAT_NODE + is used for the position of the decl. */ tree create_type_decl (tree type_name, tree type, struct attrib *attr_list, bool artificial_p, bool debug_info_p, Node_Id gnat_node) { - tree type_decl = build_decl (TYPE_DECL, type_name, type); enum tree_code code = TREE_CODE (type); + bool named = TYPE_NAME (type) && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL; + tree type_decl; - DECL_ARTIFICIAL (type_decl) = artificial_p; + /* Only the builtin TYPE_STUB_DECL should be used for dummy types. */ + gcc_assert (!TYPE_IS_DUMMY_P (type)); - if (!TYPE_IS_DUMMY_P (type)) - gnat_pushdecl (type_decl, gnat_node); + /* If the type hasn't been named yet, we're naming it; preserve an existing + TYPE_STUB_DECL that has been attached to it for some purpose. */ + if (!named && TYPE_STUB_DECL (type)) + { + type_decl = TYPE_STUB_DECL (type); + DECL_NAME (type_decl) = type_name; + } + else + type_decl = build_decl (TYPE_DECL, type_name, type); + DECL_ARTIFICIAL (type_decl) = artificial_p; + gnat_pushdecl (type_decl, gnat_node); process_attributes (type_decl, attr_list); - /* Pass type declaration information to the debugger unless this is an - UNCONSTRAINED_ARRAY_TYPE, which the debugger does not support, - and ENUMERAL_TYPE or RECORD_TYPE which is handled separately, or + /* If we're naming the type, equate the TYPE_STUB_DECL to the name. + This causes the name to be also viewed as a "tag" by the debug + back-end, with the advantage that no DW_TAG_typedef is emitted + for artificial "tagged" types in DWARF. */ + if (!named) + TYPE_STUB_DECL (type) = type_decl; + + /* Pass the type declaration to the debug back-end unless this is an + UNCONSTRAINED_ARRAY_TYPE that the back-end does not support, an + ENUMERAL_TYPE or RECORD_TYPE which are handled separately, or a type for which debugging information was not requested. */ if (code == UNCONSTRAINED_ARRAY_TYPE || !debug_info_p) DECL_IGNORED_P (type_decl) = 1; @@ -1483,7 +1256,7 @@ create_type_decl (tree type_name, tree type, struct attrib *attr_list, return type_decl; } - + /* Return a VAR_DECL or CONST_DECL node. VAR_NAME gives the name of the variable. ASM_NAME is its assembler name @@ -2297,7 +2070,6 @@ gnat_gimplify_function (tree fndecl) for (cgn = cgn->nested; cgn; cgn = cgn->next_nested) gnat_gimplify_function (cgn->decl); } - tree gnat_builtin_function (tree decl) @@ -2966,10 +2738,8 @@ build_vms_descriptor32 (tree type, Mechanism_Type mech, Entity_Id gnat_entity) post_error ("unsupported descriptor type for &", gnat_entity); } + TYPE_NAME (record_type) = create_concat_name (gnat_entity, "DESC"); finish_record_type (record_type, field_list, 0, true); - create_type_decl (create_concat_name (gnat_entity, "DESC"), record_type, - NULL, true, false, gnat_entity); - return record_type; } @@ -3282,10 +3052,8 @@ build_vms_descriptor (tree type, Mechanism_Type mech, Entity_Id gnat_entity) post_error ("unsupported descriptor type for &", gnat_entity); } + TYPE_NAME (record64_type) = create_concat_name (gnat_entity, "DESC64"); finish_record_type (record64_type, field_list64, 0, true); - create_type_decl (create_concat_name (gnat_entity, "DESC64"), record64_type, - NULL, true, false, gnat_entity); - return record64_type; } |