0823efedd0
Merge from cxx-conversion branch (http://gcc.gnu.org/wiki/cxx-conversion). As described in http://gcc.gnu.org/ml/gcc/2012-08/msg00015.html, this patch changes the default bootstrap process so that stage 1 always builds with a C++ compiler. Other than the bootstrap change, the patch makes no functional changes to the compiler. Everything should build as it does now in trunk. The main changes in this patch are: 1- Configuration changes. 2- Re-write of VEC. 3- Re-write of gengtype to support C++ templates and user-provided marking functions. 4- New hash table class. 5- Re-write double_int. 6- Implement tree macros as inline functions so they can be called from gdb. As discussed before, several of these changes do not fully change the call sites to use the new APIs. The bootstrap changes have already been tested on a wide range of targets (http://gcc.gnu.org/wiki/CppBuildStatus). Additionally, I have tested the merged trunk on: x86_64-unknown-linux-gnu, mips64el-unknown-linux-gnu, powerpc64-unknown-linux-gnu, i686-pc-linux-gnu, and ia64-unknown-linux-gnu. ChangeLog 2012-08-14 Diego Novillo <dnovillo@google.com> Merge from cxx-conversion branch. * Makefile.tpl (STAGE[+id+]_CXXFLAGS): Remove POSTSTAGE1_CONFIGURE_FLAGS. * Makefile.in: Regenerate. * configure.ac (ENABLE_BUILD_WITH_CXX): Remove. Update all users. Force C++ when bootstrapping. * configure: Regenerate. libcpp/ChangeLog 2012-08-14 Diego Novillo <dnovillo@google.com> Merge from cxx-conversion branch. Configury. * Makefile.in: Remove all handlers of ENABLE_BUILD_WITH_CXX. * configure.ac: Likewise. * configure: Regenerate. 2012-08-14 Lawrence Crowl <crowl@google.com> Merge from cxx-conversion branch. New C++ hash table. * include/symtab.h (typedef struct ht hash_table): Change the typedef name to cpp_hash_table. Update all users of the typedef. gcc/ChangeLog 2012-08-14 Diego Novillo <dnovillo@google.com> Merge from cxx-conversion branch. Configury. * configure.ac (CXX_FOR_BUILD): Define and substitute. (BUILD_CXXFLAGS): Define. Remove all handlers of ENABLE_BUILD_WITH_CXX. Force all build to be with C++. * Makefile.in (BUILD_CXXFLAGS): Use it. Remove all handlers of ENABLE_BUILD_WITH_CXX. * configure: Regenerate. * config.in: Regenerate. * doc/install.texi: Remove documentation for --enable-build-with-cxx and --enable-build-poststage1-with-cxx. 2012-08-14 Diego Novillo <dnovillo@google.com> Merge from cxx-conversion branch. Re-implement VEC in C++. * vec.c (vec_heap_free): Convert into a template function. (vec_gc_o_reserve_1): Make extern. (vec_gc_p_reserve): Remove. (vec_gc_p_reserve_exact): Remove. (vec_gc_o_reserve): Remove. (vec_gc_o_reserve_exact): Remove. (vec_heap_o_reserve_1): Make extern. (vec_heap_p_reserve): Remove. (vec_heap_p_reserve_exact): Remove. (vec_heap_o_reserve): Remove. (vec_heap_o_reserve_exact): Remove. (vec_stack_p_reserve): Remove. (vec_stack_p_reserve_exact): Remove. * vec.h (VEC_CHECK_INFO, VEC_CHECK_DECL, VEC_CHECK_PASS, VEC_ASSERT, VEC_ASSERT_FAIL, vec_assert_fail): Move earlier in the file. (VEC): Define to vec_t<T>. (vec_allocation_t): Define. (struct vec_prefix): Move earlier in the file. (vec_t<T>): New template. (DEF_VEC_I, DEF_VECL_ALLOC_I, DEF_VEC_P, DEF_VEC_ALLOC_P, DEF_VEC_O, DEF_VEC_ALLOC_P, DEF_VEC_O, DEF_VEC_ALLOC_O, DEF_VEC_ALLOC_P_STACK, DEF_VEC_ALLOC_O_STACK, DEF_VEC_ALLOC_I_STACK): Expand to 'struct vec_swallow_trailing_semi'. (DEF_VEC_A): Provide template instantiations for GC/PCH markers that do not traverse the vector. (vec_stack_p_reserve): Remove. (vec_stack_p_reserve_exact): Remove. (vec_stack_p_reserve_exact_1): Remove. (vec_stack_o_reserve): Remove. (vec_stack_o_reserve_exact): Remove. (vec_stack_free): Re-write as a template function. (vec_reserve): New template function. (vec_reserve_exact): New template function. (vec_heap_free): New template function if GATHER_STATISTICS is defined. Otherwise, macro that expands to free(). (VEC_length_1): New template function. (VEC_length): Call it. (VEC_empty_1): New template function. (VEC_empty): Call it. (VEC_address_1): New template function. (VEC_address): Call it. (VEC_last_1): New template function. (VEC_last): Call it. Change return type to T&. Change all users that used VEC_Os. (VEC_index_1): New template function. (VEC_index): Call it. Return a T& instead of a T*. Update all callers that were using VEC_O before. (VEC_iterate_1): New template function. (VEC_iterate): Call it. (VEC_embedded_size_1): New template function. (VEC_embedded_size): Call it. (VEC_embedded_init_1): New template function. (VEC_embedded_init): Call it. (VEC_alloc_1): New template function. (VEC_alloc): Call it. If A is 'stack', call XALLOCAVAR to do the allocation. (VEC_free_1): New template function. (VEC_free): Call it. (VEC_copy_1): New template function. (VEC_copy): Call it. (VEC_space_1): New template function (VEC_space): Call it. (VEC_reserve_1): New template function. (VEC_reserve): Call it. (VEC_reserve_exact_1): New template function. (VEC_reserve_exact): Call it. (VEC_splice_1): New template function. (VEC_splice): Call it. (VEC_safe_splice_1): New template function. (VEC_safe_splice): Call it. (VEC_quick_push_1): New template function. Create two overloads, one accepting T, the other accepting T *. Update all callers where T and T * are ambiguous. (VEC_quick_push): Call it. (VEC_safe_push_1): New template function. Create two overloads, one accepting T, the other accepting T *. Update all callers where T and T * are ambiguous. (VEC_safe_push): Call it. (VEC_pop_1): New template function. (VEC_pop): Call it. (VEC_truncate_1): New template function. (VEC_truncate): Call it. (VEC_safe_grow_1): New template function. (VEC_safe_grow): Call it. (VEC_safe_grow_cleared_1): New template function. (VEC_safe_grow_cleared): Call it. (VEC_replace_1): New template function. (VEC_replace): Call it. Always accept T instead of T*. Update all callers that used VEC_Os. (VEC_quick_insert_1): New template function. (VEC_quick_insert): Call it. (VEC_safe_insert_1): New template function. (VEC_safe_insert): Call it. (VEC_ordered_remove_1): New template function. (VEC_ordered_remove): Call it. (VEC_unordered_remove_1): New template function. (VEC_unordered_remove): Call it. (VEC_block_remove_1): New template function. (VEC_block_remove): Call it. (VEC_lower_bound_1): New template function. (VEC_lower_bound): Call it. (VEC_OP): Remove. (DEF_VEC_FUNC_P): Remove. (DEF_VEC_ALLOC_FUNC_P): Remove. (DEF_VEC_NONALLOC_FUNCS_P): Remove. (DEF_VEC_FUNC_O): Remove. (DEF_VEC_ALLOC_FUNC_O): Remove. (DEF_VEC_NONALLOC_FUNCS_O): Remove. (DEF_VEC_ALLOC_FUNC_I): Remove. (DEF_VEC_NONALLOC_FUNCS_I): Remove. (DEF_VEC_ALLOC_FUNC_P_STACK): Remove. (DEF_VEC_ALLOC_FUNC_O_STACK): Remove. (DEF_VEC_ALLOC_FUNC_I_STACK): Remove. (vec_reserve_exact): New template function. * gengtype-lex.l (DEF_VEC_ALLOC_[IOP]/{EOID}): Remove. * gengtype-parse.c (token_names): Remove DEF_VEC_ALLOC_[IOP]. (typedef_name): Emit vec_t<C1> instead of VEC_C1_C2. (def_vec_alloc): Remove. Update all callers. * gengtype.c (filter_type_name): New. (output_mangled_typename): Call it. (write_func_for_structure): Likewise. (write_types): Likewise. (write_root): Likewise. (write_typed_alloc_def): Likewise. (note_def_vec): Emit vec_t<TYPE_NAME> instead of VEC_TYPE_NAME_base. (note_def_vec_alloc): Remove. * gengtype.h (note_def_vec_alloc): Remove. (DEFVEC_ALLOC): Remove token code. * df-scan.c (df_bb_verify): Remove call to df_free_collection_rec inside the insn traversal loop. * gimplify.c (gimplify_compound_lval): Rename STACK to EXPR_STACK. * ipa-inline.c (inline_small_functions): Rename HEAP to EDGE_HEAP. * reg-stack.c (stack): Rename to STACK_PTR. Update all users. * tree-vrp.c (stack): Rename to EQUIV_STACK. Update all users. * config/bfin/bfin.c (hwloop_optimize): Update some calls to VEC_* for vectors of non-pointers. * config/c6x/c6x.c (try_rename_operands): Likewise. (reshuffle_units): Likewise. * config/mips/mips.c (mips_multi_start): Likewise. (mips_multi_add): Likewise. (mips_multi_copy_insn): Likewise. (mips_multi_set_operand): Likewise. * hw-doloop.c (discover_loop): Likewise. (discover_loops): Likewise. (reorg_loops): Likewise. 2012-08-14 Diego Novillo <dnovillo@google.com> Merge from cxx-conversion branch. C++ support in gengtype. * coretypes.h (gt_pointer_operator): Move from ... * ggc.h: ... here. * doc/gty.texi: Document support for C++ templates and user-provided markers. * gcc/gengtype-lex.l: Update copyright year. Remove support for recognizing DEF_VEC_O, DEF_VEC_P and DEFVEC_I. * gengtype-parse.c: Update copyright year. (token_names): Remove DEF_VEC_O, DEF_VEC_P and DEF_VEC_I. (require_template_declaration): New. (typedef_name): Call it. (type): Replace IS_UNION with KIND. Replace all users. (def_vec): Remove. Update all users. * gengtype-state.c (type_lineloc): Handle TYPE_USER_STRUCT. (write_state_user_struct_type): New. (write_state_type): Call it. (read_state_user_struct_type): New. (read_state_type): Call it. * gengtype.c: Update copyright year. (dump_pair): Move declaration to the top. (dump_type): Likewise. (dump_type_list): Likewise. (dbgprint_count_type_at): Handle TYPE_USER_STRUCT. (create_user_defined_type): New. (resolve_typedef): Call it. (new_structure): Replace argument ISUNION with KIND. Change users to refer to KIND directly. Update all callers. (find_structure): Likewise. (set_gc_used_type): Handle TYPE_USER_STRUCT. (create_file): Update HDR to include new copyright year. (struct walk_type_data): Add field IN_PTR_FIELD. (output_mangled_typename): Handle TYPE_USER_STRUCT. (walk_type): Set D->IN_PTR_FIELD when walking a TYPE_POINTER. Clear it afterwards. Handle TYPE_USER_STRUCT. (write_types_process_field): Handle TYPE_USER_STRUCT. (get_type_specifier): Move earlier in the file. (write_type_decl): New. (write_marker_function_name): New. (write_user_func_for_structure_ptr): New. (write_user_func_for_structure_body): New. (write_user_marking_functions): New. (write_func_for_structure): Call write_marker_function_name and write_type_decl. Do not call walk_type for TYPE_USER_STRUCT. Emit a call to the user function directly. Call write_user_marking_functions on TYPE_USER_STRUCTs. (write_types_local_user_process_field): New. (write_pch_user_walking_for_structure_body): New. (write_pch_user_walking_functions): New. (write_types_local_process_field): Handle TYPE_USER_STRUCT. (write_local_func_for_structure): Do not call walk_type for TYPE_USER_STRUCT. Instead, emit the call to gt_pch_nx directly. Call write_pch_user_walking_functions for TYPE_USER_STRUCTs. (write_root): Handle TYPE_USER_STRUCT. (vec_prefix_type): Remove. Update all users. (note_def_vec): Remove. Update all users. (dump_typekind): Handle TYPE_USER_STRUCT. (dump_type): Initialize SEEN_TYPES, if needed. Handle TYPE_USER_STRUCT. (dump_everything): Do not initialize SEEN_TYPES. * gengtype.h: Update copyright year. (enum typekind): Add TYPE_USER_STRUCT. (union_or_struct_p): Rename from UNION_OR_STRUCT_P. Convert into function. Add an overload taking const_type_p. Update all callers. (new_structure): Change second field to type enum typekind. Update all users. (find_structure): Likewise. (note_def_vec): Remove. (DEFVEC_OP): Remove. (DEFVEC_I): Remove. * ggc-page.c (gt_ggc_mx): Add entry points for marking 'const char *&', 'unsigned char *&' and 'unsigned char&'. * ggc-zone.c (gt_ggc_mx): Add entry points for marking 'const char *&' and 'unsigned char *&'. * stringpool.c (gt_pch_nx): Add entry points for marking 'const char *&', 'unsigned char *&' and 'unsigned char&'. Add an entry point for the overload taking arguments 'unsigned char *', 'gt_pointer_operator' and 'void *'. * vec.h (struct vec_prefix): Remove GTY marker. (struct vec_t): Remove GTY((length)) attribute from field 'vec'. (gt_ggc_mx (vec_t<T> *)): New template function. (gt_pch_nx (vec_t<T> *)): New template function. (gt_pch_nx (vec_t<T *> *, gt_pointer_operator, void *)): New template function. (gt_pch_nx (vec_t<T> *, gt_pointer_operator, void *)): New template function. * basic-block.h (struct edge_def): Mark GTY((user)). Remove all GTY markers from fields. (gt_ggc_mx): Declare. (gt_pch_nx): Declare. * tree-cfg.c (gt_ggc_mx): New. (gt_pch_nx): New. * gengtype-lex.l (USER_GTY): Add pattern for "user". * gengtype-parse.c (option): Handle USER_GTY. (opts_have): New. (type): Call it. If the keyword 'user' is used, do not walk the fields of the structure. * gengtype.h (USER_GTY): Add. * doc/gty.texi: Update. 2012-08-14 Lawrence Crowl <crowl@google.com> Merge cxx-conversion branch. Implement C++ hash table. * hash-table.h: New. Implementation borrowed from libiberty/hashtab.c. * hash-table.c: Likewise. * tree-ssa-tail-merge.c: Include hash-table.h instead of hashtab.h. (static htab_t same_succ_htab): Change type to hash_table; move specification of helper functions from create call to declaration. Change users to invoke member functions. (same_succ_print_traverse): Make extern ssa_.... Change callers. Remove void* casting. (same_succ_hash): Likewise. (same_succ_equal): Likewise. (same_succ_delete): Likewise. * tree-ssa-threadupdate.c: Include hash-table.h. (struct local_info): Rename to ssa_local_info_t to avoid overloading the type name local_info with the variable name local_info. (static htab_t redirection_data): Change type to hash_table. Move specification of helper functions from create call to declaration. Change users to invoke member functions. (redirection_data_hash): Make extern ssa_.... Change callers. Remove void* casting. (redirection_data_eq): Likewise. (fix_duplicate_block_edges): Likewise. (create_duplicates): Likewise. (fixup_template_block): Likewise. (redirect_edges): Likewise. (lookup_redirection_data): Change types associated with the hash table from void* to their actual type. Remove unnecessary casts. * tree-ssa-ccp.c: Include hash-table.h. (typedef gimple_htab): New. Uses hash_table. Replace specific uses of htab_t with gimple_htab. Change users to invoke member functions. Move specification of helper functions from create call to declaration. * tree-ssa-coalesce.c: Include hash-table.h instead of hashtab.h. (hash_ssa_name_by_var): Make extern. Remove void* casting. (eq_ssa_name_by_var): Likewise. (coalesce_ssa_name): Change type of local static htab_t ssa_name_hash to hash_table. Change users to invoke member functions. Move specification of helper functions from create call to declaration. * coverage.c: Include hash-table.h instead of hashtab.h. (static htab_t counts_hash): Change type to hash_table; move specification of helper functions from create call to declaration. Change users to invoke member functions. (htab_counts_entry_hash): Make extern. Rename with coverage_... instead of htab_... Remove void* casting. (htab_counts_entry_eq): Likewise. (htab_counts_entry_del): Likewise. * tree-ssa-pre.c: Include hash-table.h instead of hashtab.h. (static htab_t expression_to_id): Change type to hash_table. Move specification of helper functions from create call to declaration. Change users to invoke member functions. (static htab_t phi_translate_table): Likewise. (pre_expr_eq): Make extern ssa_.... Change callers. Remove void* casting. (pre_expr_hash): Likewise. (expr_pred_trans_hash): Likewise. (expr_pred_trans_eq): Likewise. (alloc_expression_id): Change types associated with the hash table from void* to their actual type. Remove unnecessary casts. (lookup_expression_id): Likewise. (phi_trans_lookup): Likewise. (phi_trans_add): Likewise. * stringpool.c: Rename uses of libcpp typedef hash_table to cpp_hash_table. * Makefile.in: Add hash-table.o to OBJS-libcommon-target. Add $(HASH_TABLE_H). Add new dependences on $(HASH_TABLE_H). 2012-08-14 Lawrence Crowl <crowl@google.com> Merge from cxx-conversion branch. Re-write double_int in C++. * hash-table.h (typedef double_int): Change to struct (POD). (double_int::make): New overloads for int to double-int conversion. (double_int::mask): New. (double_int::max_value): New. (double_int::min_value): New. (double_int::operator ++): New. (double_int::operator --): New. (double_int::operator *=): New. (double_int::operator +=): New. (double_int::operator -=): New. (double_int::to_signed): New. (double_int::to_unsigned): New. (double_int::fits_unsigned): New. (double_int::fits_signed): New. (double_int::fits): New. (double_int::trailing_zeros): New. (double_int::popcount): New. (double_int::multiple_of): New. (double_int::set_bit): New. (double_int::mul_with_sign): New. (double_int::operator * (binary)): New. (double_int::operator + (binary)): New. (double_int::operator - (binary)): New. (double_int::operator - (unary)): New. (double_int::operator ~ (unary)): New. (double_int::operator & (binary)): New. (double_int::operator | (binary)): New. (double_int::operator ^ (binary)): New. (double_int::and_not): New. (double_int::lshift): New. (double_int::rshift): New. (double_int::alshift): New. (double_int::arshift): New. (double_int::llshift): New. (double_int::lrshift): New. (double_int::lrotate): New. (double_int::rrotate): New. (double_int::div): New. (double_int::sdiv): New. (double_int::udiv): New. (double_int::mod): New. (double_int::smod): New. (double_int::umod): New. (double_int::divmod): New. (double_int::sdivmod): New. (double_int::udivmod): New. (double_int::ext): New. (double_int::zext): New. (double_int::sext): New. (double_int::is_zero): New. (double_int::is_one): New. (double_int::is_minus_one): New. (double_int::is_negative): New. (double_int::cmp): New. (double_int::ucmp): New. (double_int::scmp): New. (double_int::ult): New. (double_int::ugt): New. (double_int::slt): New. (double_int::sgt): New. (double_int::max): New. (double_int::smax): New. (double_int::umax): New. (double_int::min): New. (double_int::smin): New. (double_int::umin): New. (double_int::operator ==): New. (double_int::operator !=): New. (shwi_to_double_int): Change implementation to use member function. (double_int_minus_one): Likewise. (double_int_zero): Likewise. (double_int_one): Likewise. (double_int_two): Likewise. (double_int_ten): Likewise. (uhwi_to_double_int): Likewise. (double_int_to_shwi): Likewise. (double_int_to_uhwi): Likewise. (double_int_fits_in_uhwi_p): Likewise. (double_int_fits_in_shwi_p): Likewise. (double_int_fits_in_hwi_p): Likewise. (double_int_mul): Likewise. (double_int_mul_with_sign): Likewise. (double_int_add): Likewise. (double_int_sub): Likewise. (double_int_neg): Likewise. (double_int_div): Likewise. (double_int_sdiv): Likewise. (double_int_udiv): Likewise. (double_int_mod): Likewise. (double_int_smod): Likewise. (double_int_umod): Likewise. (double_int_divmod): Likewise. (double_int_sdivmod): Likewise. (double_int_udivmod): Likewise. (double_int_multiple_of): Likewise. (double_int_setbit): Likewise. (double_int_ctz): Likewise. (double_int_not): Likewise. (double_int_ior): Likewise. (double_int_and): Likewise. (double_int_and_not): Likewise. (double_int_xor): Likewise. (double_int_lshift): Likewise. (double_int_rshift): Likewise. (double_int_lrotate): Likewise. (double_int_rrotate): Likewise. (double_int_cmp): Likewise. (double_int_scmp): Likewise. (double_int_ucmp): Likewise. (double_int_max): Likewise. (double_int_smax): Likewise. (double_int_umax): Likewise. (double_int_min): Likewise. (double_int_smin): Likewise. (double_int_umin): Likewise. (double_int_ext): Likewise. (double_int_sext): Likewise. (double_int_zext): Likewise. (double_int_mask): Likewise. (double_int_max_value): Likewise. (double_int_min_value): Likewise. (double_int_zero_p): Likewise. (double_int_one_p): Likewise. (double_int_minus_one_p): Likewise. (double_int_equal_p): Likewise. (double_int_popcount): Likewise. * hash-table.c (double_int_mask): Reuse implementation for double_int::mask. (double_int_max_value): Likewise. (double_int_min_value): Likewise. (double_int_ext): Likewise. (double_int_zext): Likewise. (double_int_sext): Likewise. (double_int_mul_with_sign): Likewise. (double_int_divmod): Likewise. (double_int_sdivmod): Likewise. (double_int_udivmod): Likewise. (double_int_div): Likewise. (double_int_sdiv): Likewise. (double_int_udiv): Likewise. (double_int_mod): Likewise. (double_int_smod): Likewise. (double_int_umod): Likewise. (double_int_multiple_of): Likewise. (double_int_lshift): Likewise. (double_int_rshift): Likewise. (double_int_lrotate): Likewise. (double_int_rrotate): Likewise. (double_int_cmp): Likewise. (double_int_ucmp): Likewise. (double_int_scmp): Likewise. (double_int_max): Likewise. (double_int_smax): Likewise. (double_int_umax): Likewise. (double_int_min): Likewise. (double_int_smin): Likewise. (double_int_umin): Likewise. (double_int_min): Likewise. (double_int_min): Likewise. (double_int_min): Likewise. (double_int_min): Likewise. (double_int_min): Likewise. (double_int_min): Likewise. (double_int::alshift): New. (double_int::arshift): New. (double_int::llshift): New. (double_int::lrshift): New. (double_int::ult): New. (double_int::ugt): New. (double_int::slt): New. (double_int::sgt): New. (double_int_setbit): Reuse implementation for double_int::set_bit, which avoids a name conflict with a macro. (double_int_double_int_ctz): Reuse implementation for double_int::trailing_zeros. (double_int_fits_in_shwi_p): Reuse implementation for double_int::fits_signed. (double_int_fits_in_hwi_p): Reuse implementation for double_int::fits. (double_int_mul): Reuse implementation for binary double_int::operator *. (double_int_add): Likewise. (double_int_sub): Likewise. (double_int_neg): Reuse implementation for unary double_int::operator -. (double_int_max_value): Likewise. * fixed-value.c: Change to use member functions introduced above. 2012-08-14 Lawrence Crowl <crowl@google.com> Merge cxx-conversion branch. Support tree macro calling from gdb. * tree.h (tree_check): New. (TREE_CHECK): Use inline function above instead of __extension__. (tree_not_check): New. (TREE_NOT_CHECK): Use inline function above instead of __extension__. (tree_check2): New. (TREE_CHECK2): Use inline function above instead of __extension__. (tree_not_check2): New. (TREE_NOT_CHECK2): Use inline function above instead of __extension__. (tree_check3): New. (TREE_CHECK3): Use inline function above instead of __extension__. (tree_not_check3): New. (TREE_NOT_CHECK3): Use inline function above instead of __extension__. (tree_check4): New. (TREE_CHECK4): Use inline function above instead of __extension__. (tree_not_check4): New. (TREE_NOT_CHECK4): Use inline function above instead of __extension__. (tree_check5): New. (TREE_CHECK5): Use inline function above instead of __extension__. (tree_not_check5): New. (TREE_NOT_CHECK5): Use inline function above instead of __extension__. (contains_struct_check): New. (CONTAINS_STRUCT_CHECK): Use inline function above instead of __extension__. (tree_class_check): New. (TREE_CLASS_CHECK): Use inline function above instead of __extension__. (tree_range_check): New. (TREE_RANGE_CHECK): Use inline function above instead of __extension__. (omp_clause_subcode_check): New. (OMP_CLAUSE_SUBCODE_CHECK): Use inline function above instead of __extension__. (omp_clause_range_check): New. (OMP_CLAUSE_RANGE_CHECK): Use inline function above instead of __extension__. (expr_check): New. (EXPR_CHECK): Use inline function above instead of __extension__. (non_type_check): New. (NON_TYPE_CHECK): Use inline function above instead of __extension__. (tree_vec_elt_check): New. (TREE_VEC_ELT_CHECK): Use inline function above instead of __extension__. (omp_clause_elt_check): New. (OMP_CLAUSE_ELT_CHECK): Use inline function above instead of __extension__. (tree_operand_check): New. (TREE_OPERAND_CHECK): Use inline function above instead of __extension__. (tree_operand_check_code): New. (TREE_OPERAND_CHECK_CODE): Use inline function above instead of __extension__. (TREE_CHAIN): Simplify implementation. (TREE_TYPE): Simplify implementation. (tree_operand_length): Move for compilation dependences. * gdbinit.in: (macro define __FILE__): New. (macro define __LINE__): New. (skip "tree.h"): New. gcc/cp/ChangeLog 2012-08-14 Diego Novillo <dnovillo@google.com> Merge from cxx-conversion branch. Re-write VEC in C++. * call.c (add_function_candidate): Remove const qualifier from call to VEC_index. 2012-08-14 Diego Novillo <dnovillo@google.com> Merge from cxx-conversion branch. Configury. * go-c.h: Remove all handlers of ENABLE_BUILD_WITH_CXX. * go-gcc.cc: Likewise. * go-system.h: Likewise. From-SVN: r190402
507 lines
17 KiB
C
507 lines
17 KiB
C
/* Process source files and output type information.
|
|
Copyright (C) 2002, 2003, 2004, 2007, 2008, 2010, 2011, 2012
|
|
Free Software Foundation, Inc.
|
|
|
|
This file is part of GCC.
|
|
|
|
GCC is free software; you can redistribute it and/or modify it under
|
|
the terms of the GNU General Public License as published by the Free
|
|
Software Foundation; either version 3, or (at your option) any later
|
|
version.
|
|
|
|
GCC is distributed in the hope that it will be useful, but WITHOUT ANY
|
|
WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
for more details.
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
along with GCC; see the file COPYING3. If not see
|
|
<http://www.gnu.org/licenses/>. */
|
|
|
|
#ifndef GCC_GENGTYPE_H
|
|
#define GCC_GENGTYPE_H
|
|
|
|
#define obstack_chunk_alloc ((void *(*) (long)) xmalloc)
|
|
#define obstack_chunk_free ((void (*) (void *)) free)
|
|
#define OBSTACK_CHUNK_SIZE 0
|
|
|
|
/* Sets of accepted source languages like C, C++, Ada... are
|
|
represented by a bitmap. */
|
|
typedef unsigned lang_bitmap;
|
|
|
|
/* Variable length structure representing an input file. A hash table
|
|
ensure uniqueness for a given input file name. The only function
|
|
allocating input_file-s is input_file_by_name. */
|
|
struct input_file_st
|
|
{
|
|
struct outf* inpoutf; /* Cached corresponding output file, computed
|
|
in get_output_file_with_visibility. */
|
|
lang_bitmap inpbitmap; /* The set of languages using this file. */
|
|
bool inpisplugin; /* Flag set for plugin input files. */
|
|
char inpname[1]; /* A variable-length array, ended by a null
|
|
char. */
|
|
};
|
|
typedef struct input_file_st input_file;
|
|
|
|
/* A file position, mostly for error messages.
|
|
The FILE element may be compared using pointer equality. */
|
|
struct fileloc
|
|
{
|
|
const input_file *file;
|
|
int line;
|
|
};
|
|
|
|
|
|
/* Table of all input files and its size. */
|
|
extern const input_file** gt_files;
|
|
extern size_t num_gt_files;
|
|
|
|
/* A number of places use the name of this "gengtype.c" file for a
|
|
location for things that we can't rely on the source to define. We
|
|
also need to refer to the "system.h" file specifically. These two
|
|
pointers are initialized early in main. */
|
|
extern input_file* this_file;
|
|
extern input_file* system_h_file;
|
|
|
|
/* Retrieve or create the input_file for a given name, which is a file
|
|
path. This is the only function allocating input_file-s and it is
|
|
hash-consing them. */
|
|
input_file* input_file_by_name (const char* name);
|
|
|
|
/* For F an input_file, return the relative path to F from $(srcdir)
|
|
if the latter is a prefix in F, NULL otherwise. */
|
|
const char *get_file_srcdir_relative_path (const input_file *inpf);
|
|
|
|
/* Get the name of an input file. */
|
|
static inline const char*
|
|
get_input_file_name (const input_file *inpf)
|
|
{
|
|
if (inpf)
|
|
return inpf->inpname;
|
|
return NULL;
|
|
}
|
|
|
|
/* Return a bitmap which has bit `1 << BASE_FILE_<lang>' set iff
|
|
INPUT_FILE is used by <lang>.
|
|
|
|
This function should be written to assume that a file _is_ used
|
|
if the situation is unclear. If it wrongly assumes a file _is_ used,
|
|
a linker error will result. If it wrongly assumes a file _is not_ used,
|
|
some GC roots may be missed, which is a much harder-to-debug problem.
|
|
*/
|
|
|
|
static inline lang_bitmap
|
|
get_lang_bitmap (const input_file* inpf)
|
|
{
|
|
if (inpf == NULL)
|
|
return 0;
|
|
return inpf->inpbitmap;
|
|
}
|
|
|
|
/* Set the bitmap returned by get_lang_bitmap. The only legitimate
|
|
callers of this function are read_input_list & read_state_*. */
|
|
static inline void
|
|
set_lang_bitmap (input_file* inpf, lang_bitmap n)
|
|
{
|
|
gcc_assert (inpf);
|
|
inpf->inpbitmap = n;
|
|
}
|
|
|
|
/* Vector of per-language directories. */
|
|
extern const char **lang_dir_names;
|
|
extern size_t num_lang_dirs;
|
|
|
|
/* Data types handed around within, but opaque to, the lexer and parser. */
|
|
typedef struct pair *pair_p;
|
|
typedef struct type *type_p;
|
|
typedef const struct type *const_type_p;
|
|
typedef struct options *options_p;
|
|
|
|
/* Variables used to communicate between the lexer and the parser. */
|
|
extern int lexer_toplevel_done;
|
|
extern struct fileloc lexer_line;
|
|
|
|
/* Various things, organized as linked lists, needed both in
|
|
gengtype.c & in gengtype-state.c files. */
|
|
extern pair_p typedefs;
|
|
extern type_p structures;
|
|
extern type_p param_structs;
|
|
extern pair_p variables;
|
|
|
|
|
|
|
|
/* Discrimating kind of types we can understand. */
|
|
|
|
enum typekind {
|
|
TYPE_NONE=0, /* Never used, so zeroed memory is invalid. */
|
|
TYPE_SCALAR, /* Scalar types like char. */
|
|
TYPE_STRING, /* The string type. */
|
|
TYPE_STRUCT, /* Type for GTY-ed structs. */
|
|
TYPE_UNION, /* Type for GTY-ed discriminated unions. */
|
|
TYPE_POINTER, /* Pointer type to GTY-ed type. */
|
|
TYPE_ARRAY, /* Array of GTY-ed types. */
|
|
TYPE_LANG_STRUCT, /* GCC front-end language specific structs.
|
|
Various languages may have homonymous but
|
|
different structs. */
|
|
TYPE_PARAM_STRUCT, /* Type for parametrized structs, e.g. hash_t
|
|
hash-tables, ... See (param_is, use_param,
|
|
param1_is, param2_is,... use_param1,
|
|
use_param_2,... use_params) GTY
|
|
options. */
|
|
TYPE_USER_STRUCT /* User defined type. Walkers and markers for
|
|
this type are assumed to be provided by the
|
|
user. */
|
|
};
|
|
|
|
/* Discriminating kind for options. */
|
|
enum option_kind {
|
|
OPTION_NONE=0, /* Never used, so zeroed memory is invalid. */
|
|
OPTION_STRING, /* A string-valued option. Most options are
|
|
strings. */
|
|
OPTION_TYPE, /* A type-valued option. */
|
|
OPTION_NESTED /* Option data for 'nested_ptr'. */
|
|
};
|
|
|
|
|
|
/* A way to pass data through to the output end. */
|
|
struct options {
|
|
struct options *next; /* next option of the same pair. */
|
|
const char *name; /* GTY option name. */
|
|
enum option_kind kind; /* discriminating option kind. */
|
|
union {
|
|
const char* string; /* When OPTION_STRING. */
|
|
type_p type; /* When OPTION_TYPE. */
|
|
struct nested_ptr_data* nested; /* when OPTION_NESTED. */
|
|
} info;
|
|
};
|
|
|
|
|
|
/* Option data for the 'nested_ptr' option. */
|
|
struct nested_ptr_data {
|
|
type_p type;
|
|
const char *convert_to;
|
|
const char *convert_from;
|
|
};
|
|
|
|
/* Some functions to create various options structures with name NAME
|
|
and info INFO. NEXT is the next option in the chain. */
|
|
|
|
/* Create a string option. */
|
|
options_p create_string_option (options_p next, const char* name,
|
|
const char* info);
|
|
|
|
/* Create a type option. */
|
|
options_p create_type_option (options_p next, const char* name,
|
|
type_p info);
|
|
|
|
/* Create a nested option. */
|
|
options_p create_nested_option (options_p next, const char* name,
|
|
struct nested_ptr_data* info);
|
|
|
|
/* Create a nested pointer option. */
|
|
options_p create_nested_ptr_option (options_p, type_p t,
|
|
const char *from, const char *to);
|
|
|
|
/* A name and a type. */
|
|
struct pair {
|
|
pair_p next; /* The next pair in the linked list. */
|
|
const char *name; /* The defined name. */
|
|
type_p type; /* Its GTY-ed type. */
|
|
struct fileloc line; /* The file location. */
|
|
options_p opt; /* GTY options, as a linked list. */
|
|
};
|
|
|
|
/* Usage information for GTY-ed types. Gengtype has to care only of
|
|
used GTY-ed types. Types are initially unused, and their usage is
|
|
computed by set_gc_used_type and set_gc_used functions. */
|
|
|
|
enum gc_used_enum {
|
|
|
|
/* We need that zeroed types are initially unused. */
|
|
GC_UNUSED=0,
|
|
|
|
/* The GTY-ed type is used, e.g by a GTY-ed variable or a field
|
|
inside a GTY-ed used type. */
|
|
GC_USED,
|
|
|
|
/* For GTY-ed structures whose definitions we haven't seen so far
|
|
when we encounter a pointer to it that is annotated with
|
|
``maybe_undef''. If after reading in everything we don't have
|
|
source file information for it, we assume that it never has been
|
|
defined. */
|
|
GC_MAYBE_POINTED_TO,
|
|
|
|
/* For known GTY-ed structures which are pointed to by GTY-ed
|
|
variables or fields. */
|
|
GC_POINTED_TO
|
|
};
|
|
|
|
/* We can have at most ten type parameters in parameterized structures. */
|
|
#define NUM_PARAM 10
|
|
|
|
/* Our type structure describes all types handled by gengtype. */
|
|
struct type {
|
|
/* Discriminating kind, cannot be TYPE_NONE. */
|
|
enum typekind kind;
|
|
|
|
/* For top-level structs or unions, the 'next' field links the
|
|
global list 'structures' or 'param_structs'; for lang_structs,
|
|
their homonymous structs are linked using this 'next' field. The
|
|
homonymous list starts at the s.lang_struct field of the
|
|
lang_struct. See the new_structure function for details. This is
|
|
tricky! */
|
|
type_p next;
|
|
|
|
/* State number used when writing & reading the persistent state. A
|
|
type with a positive number has already been written. For ease
|
|
of debugging, newly allocated types have a unique negative
|
|
number. */
|
|
int state_number;
|
|
|
|
/* Each GTY-ed type which is pointed to by some GTY-ed type knows
|
|
the GTY pointer type pointing to it. See create_pointer
|
|
function. */
|
|
type_p pointer_to;
|
|
|
|
/* Type usage information, computed by set_gc_used_type and
|
|
set_gc_used functions. */
|
|
enum gc_used_enum gc_used;
|
|
|
|
/* The following union is discriminated by the 'kind' field above. */
|
|
union {
|
|
/* TYPE__NONE is impossible. */
|
|
|
|
/* when TYPE_POINTER: */
|
|
type_p p;
|
|
|
|
/* when TYPE_STRUCT or TYPE_UNION or TYPE_LANG_STRUCT, we have an
|
|
aggregate type containing fields: */
|
|
struct {
|
|
const char *tag; /* the aggragate tag, if any. */
|
|
struct fileloc line; /* the source location. */
|
|
pair_p fields; /* the linked list of fields. */
|
|
options_p opt; /* the GTY options if any. */
|
|
lang_bitmap bitmap; /* the set of front-end languages
|
|
using that GTY-ed aggregate. */
|
|
/* For TYPE_LANG_STRUCT, the lang_struct field gives the first
|
|
element of a linked list of homonymous struct or union types.
|
|
Within this list, each homonymous type has as its lang_struct
|
|
field the original TYPE_LANG_STRUCT type. This is a dirty
|
|
trick, see the new_structure function for details. */
|
|
type_p lang_struct;
|
|
} s;
|
|
|
|
/* when TYPE_SCALAR: */
|
|
bool scalar_is_char;
|
|
|
|
/* when TYPE_ARRAY: */
|
|
struct {
|
|
type_p p; /* The array component type. */
|
|
const char *len; /* The string if any giving its length. */
|
|
} a;
|
|
|
|
/* When TYPE_PARAM_STRUCT for (param_is, use_param, param1_is,
|
|
param2_is, ... use_param1, use_param_2, ... use_params) GTY
|
|
options. */
|
|
struct {
|
|
type_p stru; /* The generic GTY-ed type. */
|
|
type_p param[NUM_PARAM]; /* The actual parameter types. */
|
|
struct fileloc line; /* The source location. */
|
|
} param_struct;
|
|
|
|
} u;
|
|
};
|
|
|
|
/* The one and only TYPE_STRING. */
|
|
extern struct type string_type;
|
|
|
|
/* The two and only TYPE_SCALARs. Their u.scalar_is_char flags are
|
|
set early in main. */
|
|
extern struct type scalar_nonchar;
|
|
extern struct type scalar_char;
|
|
|
|
/* Test if a type is a union, either a plain one or a language
|
|
specific one. */
|
|
#define UNION_P(x) \
|
|
((x)->kind == TYPE_UNION \
|
|
|| ((x)->kind == TYPE_LANG_STRUCT \
|
|
&& (x)->u.s.lang_struct->kind == TYPE_UNION))
|
|
|
|
/* Test if a type is a union or a structure, perhaps a language
|
|
specific one. */
|
|
static inline bool
|
|
union_or_struct_p (enum typekind kind)
|
|
{
|
|
return (kind == TYPE_UNION
|
|
|| kind == TYPE_STRUCT
|
|
|| kind == TYPE_LANG_STRUCT
|
|
|| kind == TYPE_USER_STRUCT);
|
|
}
|
|
|
|
static inline bool
|
|
union_or_struct_p (const_type_p x)
|
|
{
|
|
return union_or_struct_p (x->kind);
|
|
}
|
|
|
|
/* Give the file location of a type, if any. */
|
|
static inline struct fileloc*
|
|
type_fileloc (type_p t)
|
|
{
|
|
if (!t)
|
|
return NULL;
|
|
if (union_or_struct_p (t))
|
|
return &t->u.s.line;
|
|
if (t->kind == TYPE_PARAM_STRUCT)
|
|
return &t->u.param_struct.line;
|
|
return NULL;
|
|
}
|
|
|
|
/* Structure representing an output file. */
|
|
struct outf
|
|
{
|
|
struct outf *next;
|
|
const char *name;
|
|
size_t buflength;
|
|
size_t bufused;
|
|
char *buf;
|
|
};
|
|
typedef struct outf *outf_p;
|
|
|
|
/* The list of output files. */
|
|
extern outf_p output_files;
|
|
|
|
/* The output header file that is included into pretty much every
|
|
source file. */
|
|
extern outf_p header_file;
|
|
|
|
/* Print, like fprintf, to O. No-op if O is NULL. */
|
|
void
|
|
oprintf (outf_p o, const char *S, ...)
|
|
ATTRIBUTE_PRINTF_2;
|
|
|
|
/* An output file, suitable for definitions, that can see declarations
|
|
made in INPF and is linked into every language that uses INPF. May
|
|
return NULL in plugin mode. The INPF argument is almost const, but
|
|
since the result is cached in its inpoutf field it cannot be
|
|
declared const. */
|
|
outf_p get_output_file_with_visibility (input_file* inpf);
|
|
|
|
/* The name of an output file, suitable for definitions, that can see
|
|
declarations made in INPF and is linked into every language that
|
|
uses INPF. May return NULL. */
|
|
const char *get_output_file_name (input_file *inpf);
|
|
|
|
|
|
/* Source directory. */
|
|
extern const char *srcdir; /* (-S) program argument. */
|
|
|
|
/* Length of srcdir name. */
|
|
extern size_t srcdir_len;
|
|
|
|
/* Variable used for reading and writing the state. */
|
|
extern const char *read_state_filename; /* (-r) program argument. */
|
|
extern const char *write_state_filename; /* (-w) program argument. */
|
|
|
|
/* Functions reading and writing the entire gengtype state, called from
|
|
main, and implemented in file gengtype-state.c. */
|
|
void read_state (const char* path);
|
|
/* Write the state, and update the state_number field in types. */
|
|
void write_state (const char* path);
|
|
|
|
|
|
/* Print an error message. */
|
|
extern void error_at_line
|
|
(const struct fileloc *pos, const char *msg, ...) ATTRIBUTE_PRINTF_2;
|
|
|
|
/* Like asprintf, but calls fatal() on out of memory. */
|
|
extern char *xasprintf (const char *, ...) ATTRIBUTE_PRINTF_1;
|
|
|
|
/* Constructor routines for types. */
|
|
extern void do_typedef (const char *s, type_p t, struct fileloc *pos);
|
|
extern void do_scalar_typedef (const char *s, struct fileloc *pos);
|
|
extern type_p resolve_typedef (const char *s, struct fileloc *pos);
|
|
extern type_p new_structure (const char *name, enum typekind kind,
|
|
struct fileloc *pos, pair_p fields,
|
|
options_p o);
|
|
extern type_p find_structure (const char *s, enum typekind kind);
|
|
extern type_p create_scalar_type (const char *name);
|
|
extern type_p create_pointer (type_p t);
|
|
extern type_p create_array (type_p t, const char *len);
|
|
extern pair_p create_field_at (pair_p next, type_p type,
|
|
const char *name, options_p opt,
|
|
struct fileloc *pos);
|
|
extern pair_p nreverse_pairs (pair_p list);
|
|
extern type_p adjust_field_type (type_p, options_p);
|
|
extern void note_variable (const char *s, type_p t, options_p o,
|
|
struct fileloc *pos);
|
|
|
|
/* Lexer and parser routines. */
|
|
extern int yylex (const char **yylval);
|
|
extern void yybegin (const char *fname);
|
|
extern void yyend (void);
|
|
extern void parse_file (const char *name);
|
|
extern bool hit_error;
|
|
|
|
/* Token codes. */
|
|
enum
|
|
{
|
|
EOF_TOKEN = 0,
|
|
|
|
/* Per standard convention, codes in the range (0, UCHAR_MAX]
|
|
represent single characters with those character codes. */
|
|
|
|
CHAR_TOKEN_OFFSET = UCHAR_MAX + 1,
|
|
GTY_TOKEN = CHAR_TOKEN_OFFSET,
|
|
TYPEDEF,
|
|
EXTERN,
|
|
STATIC,
|
|
UNION,
|
|
STRUCT,
|
|
ENUM,
|
|
VEC_TOKEN,
|
|
ELLIPSIS,
|
|
PTR_ALIAS,
|
|
NESTED_PTR,
|
|
USER_GTY,
|
|
PARAM_IS,
|
|
NUM,
|
|
SCALAR,
|
|
ID,
|
|
STRING,
|
|
CHAR,
|
|
ARRAY,
|
|
|
|
/* print_token assumes that any token >= FIRST_TOKEN_WITH_VALUE may have
|
|
a meaningful value to be printed. */
|
|
FIRST_TOKEN_WITH_VALUE = PARAM_IS
|
|
};
|
|
|
|
|
|
/* Level for verbose messages, e.g. output file generation... */
|
|
extern int verbosity_level; /* (-v) program argument. */
|
|
|
|
/* For debugging purposes we provide two flags. */
|
|
|
|
/* Dump everything to understand gengtype's state. Might be useful to
|
|
gengtype users. */
|
|
extern int do_dump; /* (-d) program argument. */
|
|
|
|
/* Trace the execution by many DBGPRINTF (with the position inside
|
|
gengtype source code). Only useful to debug gengtype itself. */
|
|
extern int do_debug; /* (-D) program argument. */
|
|
|
|
#if ENABLE_CHECKING
|
|
#define DBGPRINTF(Fmt,...) do {if (do_debug) \
|
|
fprintf (stderr, "%s:%d: " Fmt "\n", \
|
|
lbasename (__FILE__),__LINE__, ##__VA_ARGS__);} while (0)
|
|
void dbgprint_count_type_at (const char *, int, const char *, type_p);
|
|
#define DBGPRINT_COUNT_TYPE(Msg,Ty) do {if (do_debug) \
|
|
dbgprint_count_type_at (__FILE__, __LINE__, Msg, Ty);}while (0)
|
|
#else
|
|
#define DBGPRINTF(Fmt,...) do {/*nodbgrintf*/} while (0)
|
|
#define DBGPRINT_COUNT_TYPE(Msg,Ty) do{/*nodbgprint_count_type*/}while (0)
|
|
#endif /*ENABLE_CHECKING */
|
|
|
|
#endif
|