mirror of
https://sourceware.org/git/binutils-gdb.git
synced 2024-12-03 04:12:10 +08:00
224c3ddb89
Most allocation functions (if not all) return a void* pointing to the allocated memory. In C++, we need to add an explicit cast when assigning the result to a pointer to another type (which is the case more often than not). The content of this patch is taken from Pedro's branch, from commit "(mostly) auto-generated patch to insert casts needed for C++". I validated that the changes make sense and manually reflowed the code to make it respect the coding style. I also found multiple places where I could use XNEW/XNEWVEC/XRESIZEVEC/etc. Thanks a lot to whoever did that automated script to insert casts, doing it completely by hand would have taken a ridiculous amount of time. Only files built on x86 with --enable-targets=all are modified. This means that all other -nat.c files are untouched and will have to be dealt with later by using appropiate compilers. Or maybe we can try to build them with a regular g++ just to know where to add casts, I don't know. I built-tested this with --enable-targets=all and reg-tested. Here's the changelog entry, which was not too bad to make despite the size, thanks to David Malcom's script. I fixed some bits by hand, but there might be some wrong parts left (hopefully not). gdb/ChangeLog: * aarch64-linux-tdep.c (aarch64_stap_parse_special_token): Add cast to allocation result assignment. * ada-exp.y (write_object_renaming): Likewise. (write_ambiguous_var): Likewise. (ada_nget_field_index): Likewise. (write_var_or_type): Likewise. * ada-lang.c (ada_decode_symbol): Likewise. (ada_value_assign): Likewise. (value_pointer): Likewise. (cache_symbol): Likewise. (add_nonlocal_symbols): Likewise. (ada_name_for_lookup): Likewise. (symbol_completion_add): Likewise. (ada_to_fixed_type_1): Likewise. (ada_get_next_arg): Likewise. (defns_collected): Likewise. * ada-lex.l (processId): Likewise. (processString): Likewise. * ada-tasks.c (read_known_tasks_array): Likewise. (read_known_tasks_list): Likewise. * ada-typeprint.c (decoded_type_name): Likewise. * addrmap.c (addrmap_mutable_create_fixed): Likewise. * amd64-tdep.c (amd64_push_arguments): Likewise. (amd64_displaced_step_copy_insn): Likewise. (amd64_classify_insn_at): Likewise. (amd64_relocate_instruction): Likewise. * amd64obsd-tdep.c (amd64obsd_sigtramp_p): Likewise. * arch-utils.c (simple_displaced_step_copy_insn): Likewise. (initialize_current_architecture): Likewise. * arm-linux-tdep.c (arm_stap_parse_special_token): Likewise. * arm-symbian-tdep.c (arm_symbian_osabi_sniffer): Likewise. * arm-tdep.c (arm_exidx_new_objfile): Likewise. (arm_push_dummy_call): Likewise. (extend_buffer_earlier): Likewise. (arm_adjust_breakpoint_address): Likewise. (arm_skip_stub): Likewise. * auto-load.c (filename_is_in_pattern): Likewise. (maybe_add_script_file): Likewise. (maybe_add_script_text): Likewise. (auto_load_objfile_script_1): Likewise. * auxv.c (ld_so_xfer_auxv): Likewise. * ax-general.c (new_agent_expr): Likewise. (grow_expr): Likewise. (ax_reg_mask): Likewise. * bcache.c (bcache_full): Likewise. * breakpoint.c (program_breakpoint_here_p): Likewise. * btrace.c (parse_xml_raw): Likewise. * build-id.c (build_id_to_debug_bfd): Likewise. * buildsym.c (end_symtab_with_blockvector): Likewise. * c-exp.y (string_exp): Likewise. (qualified_name): Likewise. (write_destructor_name): Likewise. (operator_stoken): Likewise. (parse_number): Likewise. (scan_macro_expansion): Likewise. (yylex): Likewise. (c_print_token): Likewise. * c-lang.c (c_get_string): Likewise. (emit_numeric_character): Likewise. * charset.c (wchar_iterate): Likewise. * cli/cli-cmds.c (complete_command): Likewise. (make_command): Likewise. * cli/cli-dump.c (restore_section_callback): Likewise. (restore_binary_file): Likewise. * cli/cli-interp.c (cli_interpreter_exec): Likewise. * cli/cli-script.c (execute_control_command): Likewise. * cli/cli-setshow.c (do_set_command): Likewise. * coff-pe-read.c (add_pe_forwarded_sym): Likewise. (read_pe_exported_syms): Likewise. * coffread.c (coff_read_struct_type): Likewise. (coff_read_enum_type): Likewise. * common/btrace-common.c (btrace_data_append): Likewise. * common/buffer.c (buffer_grow): Likewise. * common/filestuff.c (gdb_fopen_cloexec): Likewise. * common/format.c (parse_format_string): Likewise. * common/gdb_vecs.c (delim_string_to_char_ptr_vec_append): Likewise. * common/xml-utils.c (xml_escape_text): Likewise. * compile/compile-object-load.c (copy_sections): Likewise. (compile_object_load): Likewise. * compile/compile-object-run.c (compile_object_run): Likewise. * completer.c (filename_completer): Likewise. * corefile.c (read_memory_typed_address): Likewise. (write_memory_unsigned_integer): Likewise. (write_memory_signed_integer): Likewise. (complete_set_gnutarget): Likewise. * corelow.c (get_core_register_section): Likewise. * cp-name-parser.y (d_grab): Likewise. (allocate_info): Likewise. (cp_new_demangle_parse_info): Likewise. * cp-namespace.c (cp_scan_for_anonymous_namespaces): Likewise. (cp_lookup_symbol_in_namespace): Likewise. (lookup_namespace_scope): Likewise. (find_symbol_in_baseclass): Likewise. (cp_lookup_nested_symbol): Likewise. (cp_lookup_transparent_type_loop): Likewise. * cp-support.c (copy_string_to_obstack): Likewise. (make_symbol_overload_list): Likewise. (make_symbol_overload_list_namespace): Likewise. (make_symbol_overload_list_adl_namespace): Likewise. (first_component_command): Likewise. * cp-valprint.c (cp_print_value): Likewise. * ctf.c (ctf_xfer_partial): Likewise. * d-exp.y (StringExp): Likewise. * d-namespace.c (d_lookup_symbol_in_module): Likewise. (lookup_module_scope): Likewise. (find_symbol_in_baseclass): Likewise. (d_lookup_nested_symbol): Likewise. * dbxread.c (find_stab_function_addr): Likewise. (read_dbx_symtab): Likewise. (dbx_end_psymtab): Likewise. (cp_set_block_scope): Likewise. * dcache.c (dcache_alloc): Likewise. * demangle.c (_initialize_demangler): Likewise. * dicos-tdep.c (dicos_load_module_p): Likewise. * dictionary.c (dict_create_hashed_expandable): Likewise. (dict_create_linear_expandable): Likewise. (expand_hashtable): Likewise. (add_symbol_linear_expandable): Likewise. * dwarf2-frame.c (add_cie): Likewise. (add_fde): Likewise. (dwarf2_build_frame_info): Likewise. * dwarf2expr.c (dwarf_expr_grow_stack): Likewise. (dwarf_expr_fetch_address): Likewise. (add_piece): Likewise. (execute_stack_op): Likewise. * dwarf2loc.c (chain_candidate): Likewise. (dwarf_entry_parameter_to_value): Likewise. (read_pieced_value): Likewise. (write_pieced_value): Likewise. * dwarf2read.c (dwarf2_read_section): Likewise. (add_type_unit): Likewise. (read_comp_units_from_section): Likewise. (fixup_go_packaging): Likewise. (dwarf2_compute_name): Likewise. (dwarf2_physname): Likewise. (create_dwo_unit_in_dwp_v1): Likewise. (create_dwo_unit_in_dwp_v2): Likewise. (read_func_scope): Likewise. (read_call_site_scope): Likewise. (dwarf2_attach_fields_to_type): Likewise. (process_structure_scope): Likewise. (mark_common_block_symbol_computed): Likewise. (read_common_block): Likewise. (abbrev_table_read_table): Likewise. (guess_partial_die_structure_name): Likewise. (fixup_partial_die): Likewise. (add_file_name): Likewise. (dwarf2_const_value_data): Likewise. (dwarf2_const_value_attr): Likewise. (build_error_marker_type): Likewise. (guess_full_die_structure_name): Likewise. (anonymous_struct_prefix): Likewise. (typename_concat): Likewise. (dwarf2_canonicalize_name): Likewise. (dwarf2_name): Likewise. (write_constant_as_bytes): Likewise. (dwarf2_fetch_constant_bytes): Likewise. (copy_string): Likewise. (parse_macro_definition): Likewise. * elfread.c (elf_symfile_segments): Likewise. (elf_rel_plt_read): Likewise. (elf_gnu_ifunc_resolve_by_cache): Likewise. (elf_gnu_ifunc_resolve_by_got): Likewise. (elf_read_minimal_symbols): Likewise. (elf_gnu_ifunc_record_cache): Likewise. * event-top.c (top_level_prompt): Likewise. (command_line_handler): Likewise. * exec.c (resize_section_table): Likewise. * expprint.c (print_subexp_standard): Likewise. * fbsd-tdep.c (fbsd_collect_regset_section_cb): Likewise. * findcmd.c (parse_find_args): Likewise. * findvar.c (address_from_register): Likewise. * frame.c (get_prev_frame_always): Likewise. * gdb_bfd.c (gdb_bfd_ref): Likewise. (get_section_descriptor): Likewise. * gdb_obstack.c (obconcat): Likewise. (obstack_strdup): Likewise. * gdbtypes.c (lookup_function_type_with_arguments): Likewise. (create_set_type): Likewise. (lookup_unsigned_typename): Likewise. (lookup_signed_typename): Likewise. (resolve_dynamic_union): Likewise. (resolve_dynamic_struct): Likewise. (add_dyn_prop): Likewise. (copy_dynamic_prop_list): Likewise. (arch_flags_type): Likewise. (append_composite_type_field_raw): Likewise. * gdbtypes.h (INIT_FUNC_SPECIFIC): Likewise. * gnu-v3-abi.c (gnuv3_rtti_type): Likewise. * go-exp.y (string_exp): Likewise. * go-lang.c (go_demangle): Likewise. * guile/guile.c (compute_scheme_string): Likewise. * guile/scm-cmd.c (gdbscm_parse_command_name): Likewise. (gdbscm_canonicalize_command_name): Likewise. * guile/scm-ports.c (ioscm_init_stdio_buffers): Likewise. (ioscm_init_memory_port): Likewise. (ioscm_reinit_memory_port): Likewise. * guile/scm-utils.c (gdbscm_gc_xstrdup): Likewise. (gdbscm_gc_dup_argv): Likewise. * h8300-tdep.c (h8300_push_dummy_call): Likewise. * hppa-tdep.c (internalize_unwinds): Likewise. (read_unwind_info): Likewise. * i386-cygwin-tdep.c (core_process_module_section): Likewise. (windows_core_xfer_shared_libraries): Likewise. * i386-tdep.c (i386_displaced_step_copy_insn): Likewise. (i386_stap_parse_special_token_triplet): Likewise. (i386_stap_parse_special_token_three_arg_disp): Likewise. * i386obsd-tdep.c (i386obsd_sigtramp_p): Likewise. * inf-child.c (inf_child_fileio_readlink): Likewise. * inf-ptrace.c (inf_ptrace_fetch_register): Likewise. (inf_ptrace_store_register): Likewise. * infrun.c (follow_exec): Likewise. (displaced_step_prepare_throw): Likewise. (save_stop_context): Likewise. (save_infcall_suspend_state): Likewise. * jit.c (jit_read_descriptor): Likewise. (jit_read_code_entry): Likewise. (jit_symtab_line_mapping_add_impl): Likewise. (finalize_symtab): Likewise. (jit_unwind_reg_get_impl): Likewise. * jv-exp.y (QualifiedName): Likewise. * jv-lang.c (get_java_utf8_name): Likewise. (type_from_class): Likewise. (java_demangle_type_signature): Likewise. (java_class_name_from_physname): Likewise. * jv-typeprint.c (java_type_print_base): Likewise. * jv-valprint.c (java_value_print): Likewise. * language.c (add_language): Likewise. * linespec.c (add_sal_to_sals_basic): Likewise. (add_sal_to_sals): Likewise. (decode_objc): Likewise. (find_linespec_symbols): Likewise. * linux-fork.c (fork_save_infrun_state): Likewise. * linux-nat.c (linux_nat_detach): Likewise. (linux_nat_fileio_readlink): Likewise. * linux-record.c (record_linux_sockaddr): Likewise. (record_linux_msghdr): Likewise. (Do): Likewise. * linux-tdep.c (linux_core_info_proc_mappings): Likewise. (linux_collect_regset_section_cb): Likewise. (linux_get_siginfo_data): Likewise. * linux-thread-db.c (try_thread_db_load_from_pdir_1): Likewise. (try_thread_db_load_from_dir): Likewise. (thread_db_load_search): Likewise. (info_auto_load_libthread_db): Likewise. * m32c-tdep.c (m32c_m16c_address_to_pointer): Likewise. (m32c_m16c_pointer_to_address): Likewise. * m68hc11-tdep.c (m68hc11_pseudo_register_write): Likewise. * m68k-tdep.c (m68k_get_longjmp_target): Likewise. * machoread.c (macho_check_dsym): Likewise. * macroexp.c (resize_buffer): Likewise. (gather_arguments): Likewise. (maybe_expand): Likewise. * macrotab.c (new_macro_key): Likewise. (new_source_file): Likewise. (new_macro_definition): Likewise. * mdebugread.c (parse_symbol): Likewise. (parse_type): Likewise. (parse_partial_symbols): Likewise. (psymtab_to_symtab_1): Likewise. * mem-break.c (default_memory_insert_breakpoint): Likewise. * mi/mi-cmd-break.c (mi_argv_to_format): Likewise. * mi/mi-main.c (mi_cmd_data_read_memory): Likewise. (mi_cmd_data_read_memory_bytes): Likewise. (mi_cmd_data_write_memory_bytes): Likewise. (mi_cmd_trace_frame_collected): Likewise. * mi/mi-parse.c (mi_parse_argv): Likewise. (mi_parse): Likewise. * minidebug.c (lzma_open): Likewise. (lzma_pread): Likewise. * mips-tdep.c (mips_read_fp_register_single): Likewise. (mips_print_fp_register): Likewise. * mipsnbsd-tdep.c (mipsnbsd_get_longjmp_target): Likewise. * mipsread.c (read_alphacoff_dynamic_symtab): Likewise. * mt-tdep.c (mt_register_name): Likewise. (mt_registers_info): Likewise. (mt_push_dummy_call): Likewise. * namespace.c (add_using_directive): Likewise. * nat/linux-btrace.c (perf_event_read): Likewise. (linux_enable_bts): Likewise. * nat/linux-osdata.c (linux_common_core_of_thread): Likewise. * nat/linux-ptrace.c (linux_ptrace_test_ret_to_nx): Likewise. * nto-tdep.c (nto_find_and_open_solib): Likewise. (nto_parse_redirection): Likewise. * objc-lang.c (objc_demangle): Likewise. (find_methods): Likewise. * objfiles.c (get_objfile_bfd_data): Likewise. (set_objfile_main_name): Likewise. (allocate_objfile): Likewise. (objfile_relocate): Likewise. (update_section_map): Likewise. * osabi.c (generic_elf_osabi_sniff_abi_tag_sections): Likewise. * p-exp.y (exp): Likewise. (yylex): Likewise. * p-valprint.c (pascal_object_print_value): Likewise. * parse.c (initialize_expout): Likewise. (mark_completion_tag): Likewise. (copy_name): Likewise. (parse_float): Likewise. (type_stack_reserve): Likewise. * ppc-linux-tdep.c (ppc_stap_parse_special_token): Likewise. (ppu2spu_prev_register): Likewise. * ppc-ravenscar-thread.c (supply_register_at_address): Likewise. * printcmd.c (printf_wide_c_string): Likewise. (printf_pointer): Likewise. * probe.c (parse_probes): Likewise. * python/py-cmd.c (gdbpy_parse_command_name): Likewise. (cmdpy_init): Likewise. * python/py-gdb-readline.c (gdbpy_readline_wrapper): Likewise. * python/py-symtab.c (set_sal): Likewise. * python/py-unwind.c (pyuw_sniffer): Likewise. * python/python.c (python_interactive_command): Likewise. (compute_python_string): Likewise. * ravenscar-thread.c (get_running_thread_id): Likewise. * record-full.c (record_full_exec_insn): Likewise. (record_full_core_open_1): Likewise. * regcache.c (regcache_raw_read_signed): Likewise. (regcache_raw_read_unsigned): Likewise. (regcache_cooked_read_signed): Likewise. (regcache_cooked_read_unsigned): Likewise. * remote-fileio.c (remote_fileio_func_open): Likewise. (remote_fileio_func_rename): Likewise. (remote_fileio_func_unlink): Likewise. (remote_fileio_func_stat): Likewise. (remote_fileio_func_system): Likewise. * remote-mips.c (mips_xfer_memory): Likewise. (mips_load_srec): Likewise. (pmon_end_download): Likewise. * remote.c (new_remote_state): Likewise. (map_regcache_remote_table): Likewise. (remote_register_number_and_offset): Likewise. (init_remote_state): Likewise. (get_memory_packet_size): Likewise. (remote_pass_signals): Likewise. (remote_program_signals): Likewise. (remote_start_remote): Likewise. (remote_check_symbols): Likewise. (remote_query_supported): Likewise. (extended_remote_attach): Likewise. (process_g_packet): Likewise. (store_registers_using_G): Likewise. (putpkt_binary): Likewise. (read_frame): Likewise. (compare_sections_command): Likewise. (remote_hostio_pread): Likewise. (remote_hostio_readlink): Likewise. (remote_file_put): Likewise. (remote_file_get): Likewise. (remote_pid_to_exec_file): Likewise. (_initialize_remote): Likewise. * rs6000-aix-tdep.c (rs6000_aix_ld_info_to_xml): Likewise. (rs6000_aix_core_xfer_shared_libraries_aix): Likewise. * rs6000-tdep.c (ppc_displaced_step_copy_insn): Likewise. (bfd_uses_spe_extensions): Likewise. * s390-linux-tdep.c (s390_displaced_step_copy_insn): Likewise. * score-tdep.c (score7_malloc_and_get_memblock): Likewise. * solib-dsbt.c (decode_loadmap): Likewise. (fetch_loadmap): Likewise. (scan_dyntag): Likewise. (enable_break): Likewise. (dsbt_relocate_main_executable): Likewise. * solib-frv.c (fetch_loadmap): Likewise. (enable_break2): Likewise. (frv_relocate_main_executable): Likewise. * solib-spu.c (spu_relocate_main_executable): Likewise. (spu_bfd_open): Likewise. * solib-svr4.c (lm_info_read): Likewise. (read_program_header): Likewise. (find_program_interpreter): Likewise. (scan_dyntag): Likewise. (elf_locate_base): Likewise. (open_symbol_file_object): Likewise. (read_program_headers_from_bfd): Likewise. (svr4_relocate_main_executable): Likewise. * solib-target.c (solib_target_relocate_section_addresses): Likewise. * solib.c (solib_find_1): Likewise. (exec_file_find): Likewise. (solib_find): Likewise. * source.c (openp): Likewise. (print_source_lines_base): Likewise. (forward_search_command): Likewise. * sparc-ravenscar-thread.c (supply_register_at_address): Likewise. * spu-tdep.c (spu2ppu_prev_register): Likewise. (spu_get_overlay_table): Likewise. * stabsread.c (patch_block_stabs): Likewise. (define_symbol): Likewise. (again:): Likewise. (read_member_functions): Likewise. (read_one_struct_field): Likewise. (read_enum_type): Likewise. (common_block_start): Likewise. * stack.c (read_frame_arg): Likewise. (backtrace_command): Likewise. * stap-probe.c (stap_parse_register_operand): Likewise. * symfile.c (syms_from_objfile_1): Likewise. (find_separate_debug_file): Likewise. (load_command): Likewise. (load_progress): Likewise. (load_section_callback): Likewise. (reread_symbols): Likewise. (add_filename_language): Likewise. (allocate_compunit_symtab): Likewise. (read_target_long_array): Likewise. (simple_read_overlay_table): Likewise. * symtab.c (symbol_set_names): Likewise. (resize_symbol_cache): Likewise. (rbreak_command): Likewise. (completion_list_add_name): Likewise. (completion_list_objc_symbol): Likewise. (add_filename_to_list): Likewise. * target-descriptions.c (maint_print_c_tdesc_cmd): Likewise. * target-memory.c (target_write_memory_blocks): Likewise. * target.c (target_read_string): Likewise. (read_whatever_is_readable): Likewise. (target_read_alloc_1): Likewise. (simple_search_memory): Likewise. (target_fileio_read_alloc_1): Likewise. * tilegx-tdep.c (tilegx_push_dummy_call): Likewise. * top.c (command_line_input): Likewise. * tracefile-tfile.c (tfile_fetch_registers): Likewise. * tracefile.c (tracefile_fetch_registers): Likewise. * tracepoint.c (add_memrange): Likewise. (init_collection_list): Likewise. (add_aexpr): Likewise. (trace_dump_actions): Likewise. (parse_trace_status): Likewise. (parse_tracepoint_definition): Likewise. (parse_tsv_definition): Likewise. (parse_static_tracepoint_marker_definition): Likewise. * tui/tui-file.c (tui_sfileopen): Likewise. (tui_file_adjust_strbuf): Likewise. * tui/tui-io.c (tui_expand_tabs): Likewise. * tui/tui-source.c (tui_set_source_content): Likewise. * typeprint.c (find_global_typedef): Likewise. * ui-file.c (do_ui_file_xstrdup): Likewise. (ui_file_obsavestring): Likewise. (mem_file_write): Likewise. * utils.c (make_hex_string): Likewise. (get_regcomp_error): Likewise. (puts_filtered_tabular): Likewise. (gdb_realpath_keepfile): Likewise. (ldirname): Likewise. (gdb_bfd_errmsg): Likewise. (substitute_path_component): Likewise. * valops.c (search_struct_method): Likewise. (find_oload_champ_namespace_loop): Likewise. * valprint.c (print_decimal_chars): Likewise. (read_string): Likewise. (generic_emit_char): Likewise. * varobj.c (varobj_delete): Likewise. (varobj_value_get_print_value): Likewise. * vaxobsd-tdep.c (vaxobsd_sigtramp_sniffer): Likewise. * windows-tdep.c (display_one_tib): Likewise. * xcoffread.c (read_xcoff_symtab): Likewise. (process_xcoff_symbol): Likewise. (swap_sym): Likewise. (scan_xcoff_symtab): Likewise. (xcoff_initial_scan): Likewise. * xml-support.c (gdb_xml_end_element): Likewise. (xml_process_xincludes): Likewise. (xml_fetch_content_from_file): Likewise. * xml-syscall.c (xml_list_of_syscalls): Likewise. * xstormy16-tdep.c (xstormy16_push_dummy_call): Likewise. gdb/gdbserver/ChangeLog: * ax.c (gdb_parse_agent_expr): Add cast to allocation result assignment. (gdb_unparse_agent_expr): Likewise. * hostio.c (require_data): Likewise. (handle_pread): Likewise. * linux-low.c (disable_regset): Likewise. (fetch_register): Likewise. (store_register): Likewise. (get_dynamic): Likewise. (linux_qxfer_libraries_svr4): Likewise. * mem-break.c (delete_fast_tracepoint_jump): Likewise. (set_fast_tracepoint_jump): Likewise. (uninsert_fast_tracepoint_jumps_at): Likewise. (reinsert_fast_tracepoint_jumps_at): Likewise. (validate_inserted_breakpoint): Likewise. (clone_agent_expr): Likewise. * regcache.c (init_register_cache): Likewise. * remote-utils.c (putpkt_binary_1): Likewise. (decode_M_packet): Likewise. (decode_X_packet): Likewise. (look_up_one_symbol): Likewise. (relocate_instruction): Likewise. (monitor_output): Likewise. * server.c (handle_search_memory): Likewise. (handle_qxfer_exec_file): Likewise. (handle_qxfer_libraries): Likewise. (handle_qxfer): Likewise. (handle_query): Likewise. (handle_v_cont): Likewise. (handle_v_run): Likewise. (captured_main): Likewise. * target.c (write_inferior_memory): Likewise. * thread-db.c (try_thread_db_load_from_dir): Likewise. * tracepoint.c (init_trace_buffer): Likewise. (add_tracepoint_action): Likewise. (add_traceframe): Likewise. (add_traceframe_block): Likewise. (cmd_qtdpsrc): Likewise. (cmd_qtdv): Likewise. (cmd_qtstatus): Likewise. (response_source): Likewise. (response_tsv): Likewise. (cmd_qtnotes): Likewise. (gdb_collect): Likewise. (initialize_tracepoint): Likewise.
1546 lines
44 KiB
Plaintext
1546 lines
44 KiB
Plaintext
/* YACC parser for Ada expressions, for GDB.
|
||
Copyright (C) 1986-2015 Free Software Foundation, Inc.
|
||
|
||
This file is part of GDB.
|
||
|
||
This program 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 of the License, or
|
||
(at your option) any later version.
|
||
|
||
This program 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 this program. If not, see <http://www.gnu.org/licenses/>. */
|
||
|
||
/* Parse an Ada expression from text in a string,
|
||
and return the result as a struct expression pointer.
|
||
That structure contains arithmetic operations in reverse polish,
|
||
with constants represented by operations that are followed by special data.
|
||
See expression.h for the details of the format.
|
||
What is important here is that it can be built up sequentially
|
||
during the process of parsing; the lower levels of the tree always
|
||
come first in the result.
|
||
|
||
malloc's and realloc's in this file are transformed to
|
||
xmalloc and xrealloc respectively by the same sed command in the
|
||
makefile that remaps any other malloc/realloc inserted by the parser
|
||
generator. Doing this with #defines and trying to control the interaction
|
||
with include files (<malloc.h> and <stdlib.h> for example) just became
|
||
too messy, particularly when such includes can be inserted at random
|
||
times by the parser generator. */
|
||
|
||
%{
|
||
|
||
#include "defs.h"
|
||
#include <ctype.h>
|
||
#include "expression.h"
|
||
#include "value.h"
|
||
#include "parser-defs.h"
|
||
#include "language.h"
|
||
#include "ada-lang.h"
|
||
#include "bfd.h" /* Required by objfiles.h. */
|
||
#include "symfile.h" /* Required by objfiles.h. */
|
||
#include "objfiles.h" /* For have_full_symbols and have_partial_symbols */
|
||
#include "frame.h"
|
||
#include "block.h"
|
||
|
||
#define parse_type(ps) builtin_type (parse_gdbarch (ps))
|
||
|
||
/* Remap normal yacc parser interface names (yyparse, yylex, yyerror, etc),
|
||
as well as gratuitiously global symbol names, so we can have multiple
|
||
yacc generated parsers in gdb. These are only the variables
|
||
produced by yacc. If other parser generators (bison, byacc, etc) produce
|
||
additional global names that conflict at link time, then those parser
|
||
generators need to be fixed instead of adding those names to this list. */
|
||
|
||
/* NOTE: This is clumsy, especially since BISON and FLEX provide --prefix
|
||
options. I presume we are maintaining it to accommodate systems
|
||
without BISON? (PNH) */
|
||
|
||
#define yymaxdepth ada_maxdepth
|
||
/* ada_parse calls this after initialization */
|
||
#define yyparse ada_parse_internal
|
||
#define yylex ada_lex
|
||
#define yyerror ada_error
|
||
#define yylval ada_lval
|
||
#define yychar ada_char
|
||
#define yydebug ada_debug
|
||
#define yypact ada_pact
|
||
#define yyr1 ada_r1
|
||
#define yyr2 ada_r2
|
||
#define yydef ada_def
|
||
#define yychk ada_chk
|
||
#define yypgo ada_pgo
|
||
#define yyact ada_act
|
||
#define yyexca ada_exca
|
||
#define yyerrflag ada_errflag
|
||
#define yynerrs ada_nerrs
|
||
#define yyps ada_ps
|
||
#define yypv ada_pv
|
||
#define yys ada_s
|
||
#define yy_yys ada_yys
|
||
#define yystate ada_state
|
||
#define yytmp ada_tmp
|
||
#define yyv ada_v
|
||
#define yy_yyv ada_yyv
|
||
#define yyval ada_val
|
||
#define yylloc ada_lloc
|
||
#define yyreds ada_reds /* With YYDEBUG defined */
|
||
#define yytoks ada_toks /* With YYDEBUG defined */
|
||
#define yyname ada_name /* With YYDEBUG defined */
|
||
#define yyrule ada_rule /* With YYDEBUG defined */
|
||
#define yyss ada_yyss
|
||
#define yysslim ada_yysslim
|
||
#define yyssp ada_yyssp
|
||
#define yystacksize ada_yystacksize
|
||
#define yyvs ada_yyvs
|
||
#define yyvsp ada_yyvsp
|
||
|
||
#ifndef YYDEBUG
|
||
#define YYDEBUG 1 /* Default to yydebug support */
|
||
#endif
|
||
|
||
#define YYFPRINTF parser_fprintf
|
||
|
||
struct name_info {
|
||
struct symbol *sym;
|
||
struct minimal_symbol *msym;
|
||
const struct block *block;
|
||
struct stoken stoken;
|
||
};
|
||
|
||
/* The state of the parser, used internally when we are parsing the
|
||
expression. */
|
||
|
||
static struct parser_state *pstate = NULL;
|
||
|
||
static struct stoken empty_stoken = { "", 0 };
|
||
|
||
/* If expression is in the context of TYPE'(...), then TYPE, else
|
||
* NULL. */
|
||
static struct type *type_qualifier;
|
||
|
||
int yyparse (void);
|
||
|
||
static int yylex (void);
|
||
|
||
void yyerror (char *);
|
||
|
||
static void write_int (struct parser_state *, LONGEST, struct type *);
|
||
|
||
static void write_object_renaming (struct parser_state *,
|
||
const struct block *, const char *, int,
|
||
const char *, int);
|
||
|
||
static struct type* write_var_or_type (struct parser_state *,
|
||
const struct block *, struct stoken);
|
||
|
||
static void write_name_assoc (struct parser_state *, struct stoken);
|
||
|
||
static void write_exp_op_with_string (struct parser_state *, enum exp_opcode,
|
||
struct stoken);
|
||
|
||
static const struct block *block_lookup (const struct block *, const char *);
|
||
|
||
static LONGEST convert_char_literal (struct type *, LONGEST);
|
||
|
||
static void write_ambiguous_var (struct parser_state *,
|
||
const struct block *, char *, int);
|
||
|
||
static struct type *type_int (struct parser_state *);
|
||
|
||
static struct type *type_long (struct parser_state *);
|
||
|
||
static struct type *type_long_long (struct parser_state *);
|
||
|
||
static struct type *type_float (struct parser_state *);
|
||
|
||
static struct type *type_double (struct parser_state *);
|
||
|
||
static struct type *type_long_double (struct parser_state *);
|
||
|
||
static struct type *type_char (struct parser_state *);
|
||
|
||
static struct type *type_boolean (struct parser_state *);
|
||
|
||
static struct type *type_system_address (struct parser_state *);
|
||
|
||
%}
|
||
|
||
%union
|
||
{
|
||
LONGEST lval;
|
||
struct {
|
||
LONGEST val;
|
||
struct type *type;
|
||
} typed_val;
|
||
struct {
|
||
DOUBLEST dval;
|
||
struct type *type;
|
||
} typed_val_float;
|
||
struct type *tval;
|
||
struct stoken sval;
|
||
const struct block *bval;
|
||
struct internalvar *ivar;
|
||
}
|
||
|
||
%type <lval> positional_list component_groups component_associations
|
||
%type <lval> aggregate_component_list
|
||
%type <tval> var_or_type
|
||
|
||
%token <typed_val> INT NULL_PTR CHARLIT
|
||
%token <typed_val_float> FLOAT
|
||
%token TRUEKEYWORD FALSEKEYWORD
|
||
%token COLONCOLON
|
||
%token <sval> STRING NAME DOT_ID
|
||
%type <bval> block
|
||
%type <lval> arglist tick_arglist
|
||
|
||
%type <tval> save_qualifier
|
||
|
||
%token DOT_ALL
|
||
|
||
/* Special type cases, put in to allow the parser to distinguish different
|
||
legal basetypes. */
|
||
%token <sval> SPECIAL_VARIABLE
|
||
|
||
%nonassoc ASSIGN
|
||
%left _AND_ OR XOR THEN ELSE
|
||
%left '=' NOTEQUAL '<' '>' LEQ GEQ IN DOTDOT
|
||
%left '@'
|
||
%left '+' '-' '&'
|
||
%left UNARY
|
||
%left '*' '/' MOD REM
|
||
%right STARSTAR ABS NOT
|
||
|
||
/* Artificial token to give NAME => ... and NAME | priority over reducing
|
||
NAME to <primary> and to give <primary>' priority over reducing <primary>
|
||
to <simple_exp>. */
|
||
%nonassoc VAR
|
||
|
||
%nonassoc ARROW '|'
|
||
|
||
%right TICK_ACCESS TICK_ADDRESS TICK_FIRST TICK_LAST TICK_LENGTH
|
||
%right TICK_MAX TICK_MIN TICK_MODULUS
|
||
%right TICK_POS TICK_RANGE TICK_SIZE TICK_TAG TICK_VAL
|
||
/* The following are right-associative only so that reductions at this
|
||
precedence have lower precedence than '.' and '('. The syntax still
|
||
forces a.b.c, e.g., to be LEFT-associated. */
|
||
%right '.' '(' '[' DOT_ID DOT_ALL
|
||
|
||
%token NEW OTHERS
|
||
|
||
|
||
%%
|
||
|
||
start : exp1
|
||
;
|
||
|
||
/* Expressions, including the sequencing operator. */
|
||
exp1 : exp
|
||
| exp1 ';' exp
|
||
{ write_exp_elt_opcode (pstate, BINOP_COMMA); }
|
||
| primary ASSIGN exp /* Extension for convenience */
|
||
{ write_exp_elt_opcode (pstate, BINOP_ASSIGN); }
|
||
;
|
||
|
||
/* Expressions, not including the sequencing operator. */
|
||
primary : primary DOT_ALL
|
||
{ write_exp_elt_opcode (pstate, UNOP_IND); }
|
||
;
|
||
|
||
primary : primary DOT_ID
|
||
{ write_exp_op_with_string (pstate, STRUCTOP_STRUCT,
|
||
$2); }
|
||
;
|
||
|
||
primary : primary '(' arglist ')'
|
||
{
|
||
write_exp_elt_opcode (pstate, OP_FUNCALL);
|
||
write_exp_elt_longcst (pstate, $3);
|
||
write_exp_elt_opcode (pstate, OP_FUNCALL);
|
||
}
|
||
| var_or_type '(' arglist ')'
|
||
{
|
||
if ($1 != NULL)
|
||
{
|
||
if ($3 != 1)
|
||
error (_("Invalid conversion"));
|
||
write_exp_elt_opcode (pstate, UNOP_CAST);
|
||
write_exp_elt_type (pstate, $1);
|
||
write_exp_elt_opcode (pstate, UNOP_CAST);
|
||
}
|
||
else
|
||
{
|
||
write_exp_elt_opcode (pstate, OP_FUNCALL);
|
||
write_exp_elt_longcst (pstate, $3);
|
||
write_exp_elt_opcode (pstate, OP_FUNCALL);
|
||
}
|
||
}
|
||
;
|
||
|
||
primary : var_or_type '\'' save_qualifier { type_qualifier = $1; }
|
||
'(' exp ')'
|
||
{
|
||
if ($1 == NULL)
|
||
error (_("Type required for qualification"));
|
||
write_exp_elt_opcode (pstate, UNOP_QUAL);
|
||
write_exp_elt_type (pstate, $1);
|
||
write_exp_elt_opcode (pstate, UNOP_QUAL);
|
||
type_qualifier = $3;
|
||
}
|
||
;
|
||
|
||
save_qualifier : { $$ = type_qualifier; }
|
||
;
|
||
|
||
primary :
|
||
primary '(' simple_exp DOTDOT simple_exp ')'
|
||
{ write_exp_elt_opcode (pstate, TERNOP_SLICE); }
|
||
| var_or_type '(' simple_exp DOTDOT simple_exp ')'
|
||
{ if ($1 == NULL)
|
||
write_exp_elt_opcode (pstate, TERNOP_SLICE);
|
||
else
|
||
error (_("Cannot slice a type"));
|
||
}
|
||
;
|
||
|
||
primary : '(' exp1 ')' { }
|
||
;
|
||
|
||
/* The following rule causes a conflict with the type conversion
|
||
var_or_type (exp)
|
||
To get around it, we give '(' higher priority and add bridge rules for
|
||
var_or_type (exp, exp, ...)
|
||
var_or_type (exp .. exp)
|
||
We also have the action for var_or_type(exp) generate a function call
|
||
when the first symbol does not denote a type. */
|
||
|
||
primary : var_or_type %prec VAR
|
||
{ if ($1 != NULL)
|
||
{
|
||
write_exp_elt_opcode (pstate, OP_TYPE);
|
||
write_exp_elt_type (pstate, $1);
|
||
write_exp_elt_opcode (pstate, OP_TYPE);
|
||
}
|
||
}
|
||
;
|
||
|
||
primary : SPECIAL_VARIABLE /* Various GDB extensions */
|
||
{ write_dollar_variable (pstate, $1); }
|
||
;
|
||
|
||
primary : aggregate
|
||
;
|
||
|
||
simple_exp : primary
|
||
;
|
||
|
||
simple_exp : '-' simple_exp %prec UNARY
|
||
{ write_exp_elt_opcode (pstate, UNOP_NEG); }
|
||
;
|
||
|
||
simple_exp : '+' simple_exp %prec UNARY
|
||
{ write_exp_elt_opcode (pstate, UNOP_PLUS); }
|
||
;
|
||
|
||
simple_exp : NOT simple_exp %prec UNARY
|
||
{ write_exp_elt_opcode (pstate, UNOP_LOGICAL_NOT); }
|
||
;
|
||
|
||
simple_exp : ABS simple_exp %prec UNARY
|
||
{ write_exp_elt_opcode (pstate, UNOP_ABS); }
|
||
;
|
||
|
||
arglist : { $$ = 0; }
|
||
;
|
||
|
||
arglist : exp
|
||
{ $$ = 1; }
|
||
| NAME ARROW exp
|
||
{ $$ = 1; }
|
||
| arglist ',' exp
|
||
{ $$ = $1 + 1; }
|
||
| arglist ',' NAME ARROW exp
|
||
{ $$ = $1 + 1; }
|
||
;
|
||
|
||
primary : '{' var_or_type '}' primary %prec '.'
|
||
/* GDB extension */
|
||
{
|
||
if ($2 == NULL)
|
||
error (_("Type required within braces in coercion"));
|
||
write_exp_elt_opcode (pstate, UNOP_MEMVAL);
|
||
write_exp_elt_type (pstate, $2);
|
||
write_exp_elt_opcode (pstate, UNOP_MEMVAL);
|
||
}
|
||
;
|
||
|
||
/* Binary operators in order of decreasing precedence. */
|
||
|
||
simple_exp : simple_exp STARSTAR simple_exp
|
||
{ write_exp_elt_opcode (pstate, BINOP_EXP); }
|
||
;
|
||
|
||
simple_exp : simple_exp '*' simple_exp
|
||
{ write_exp_elt_opcode (pstate, BINOP_MUL); }
|
||
;
|
||
|
||
simple_exp : simple_exp '/' simple_exp
|
||
{ write_exp_elt_opcode (pstate, BINOP_DIV); }
|
||
;
|
||
|
||
simple_exp : simple_exp REM simple_exp /* May need to be fixed to give correct Ada REM */
|
||
{ write_exp_elt_opcode (pstate, BINOP_REM); }
|
||
;
|
||
|
||
simple_exp : simple_exp MOD simple_exp
|
||
{ write_exp_elt_opcode (pstate, BINOP_MOD); }
|
||
;
|
||
|
||
simple_exp : simple_exp '@' simple_exp /* GDB extension */
|
||
{ write_exp_elt_opcode (pstate, BINOP_REPEAT); }
|
||
;
|
||
|
||
simple_exp : simple_exp '+' simple_exp
|
||
{ write_exp_elt_opcode (pstate, BINOP_ADD); }
|
||
;
|
||
|
||
simple_exp : simple_exp '&' simple_exp
|
||
{ write_exp_elt_opcode (pstate, BINOP_CONCAT); }
|
||
;
|
||
|
||
simple_exp : simple_exp '-' simple_exp
|
||
{ write_exp_elt_opcode (pstate, BINOP_SUB); }
|
||
;
|
||
|
||
relation : simple_exp
|
||
;
|
||
|
||
relation : simple_exp '=' simple_exp
|
||
{ write_exp_elt_opcode (pstate, BINOP_EQUAL); }
|
||
;
|
||
|
||
relation : simple_exp NOTEQUAL simple_exp
|
||
{ write_exp_elt_opcode (pstate, BINOP_NOTEQUAL); }
|
||
;
|
||
|
||
relation : simple_exp LEQ simple_exp
|
||
{ write_exp_elt_opcode (pstate, BINOP_LEQ); }
|
||
;
|
||
|
||
relation : simple_exp IN simple_exp DOTDOT simple_exp
|
||
{ write_exp_elt_opcode (pstate, TERNOP_IN_RANGE); }
|
||
| simple_exp IN primary TICK_RANGE tick_arglist
|
||
{ write_exp_elt_opcode (pstate, BINOP_IN_BOUNDS);
|
||
write_exp_elt_longcst (pstate, (LONGEST) $5);
|
||
write_exp_elt_opcode (pstate, BINOP_IN_BOUNDS);
|
||
}
|
||
| simple_exp IN var_or_type %prec TICK_ACCESS
|
||
{
|
||
if ($3 == NULL)
|
||
error (_("Right operand of 'in' must be type"));
|
||
write_exp_elt_opcode (pstate, UNOP_IN_RANGE);
|
||
write_exp_elt_type (pstate, $3);
|
||
write_exp_elt_opcode (pstate, UNOP_IN_RANGE);
|
||
}
|
||
| simple_exp NOT IN simple_exp DOTDOT simple_exp
|
||
{ write_exp_elt_opcode (pstate, TERNOP_IN_RANGE);
|
||
write_exp_elt_opcode (pstate, UNOP_LOGICAL_NOT);
|
||
}
|
||
| simple_exp NOT IN primary TICK_RANGE tick_arglist
|
||
{ write_exp_elt_opcode (pstate, BINOP_IN_BOUNDS);
|
||
write_exp_elt_longcst (pstate, (LONGEST) $6);
|
||
write_exp_elt_opcode (pstate, BINOP_IN_BOUNDS);
|
||
write_exp_elt_opcode (pstate, UNOP_LOGICAL_NOT);
|
||
}
|
||
| simple_exp NOT IN var_or_type %prec TICK_ACCESS
|
||
{
|
||
if ($4 == NULL)
|
||
error (_("Right operand of 'in' must be type"));
|
||
write_exp_elt_opcode (pstate, UNOP_IN_RANGE);
|
||
write_exp_elt_type (pstate, $4);
|
||
write_exp_elt_opcode (pstate, UNOP_IN_RANGE);
|
||
write_exp_elt_opcode (pstate, UNOP_LOGICAL_NOT);
|
||
}
|
||
;
|
||
|
||
relation : simple_exp GEQ simple_exp
|
||
{ write_exp_elt_opcode (pstate, BINOP_GEQ); }
|
||
;
|
||
|
||
relation : simple_exp '<' simple_exp
|
||
{ write_exp_elt_opcode (pstate, BINOP_LESS); }
|
||
;
|
||
|
||
relation : simple_exp '>' simple_exp
|
||
{ write_exp_elt_opcode (pstate, BINOP_GTR); }
|
||
;
|
||
|
||
exp : relation
|
||
| and_exp
|
||
| and_then_exp
|
||
| or_exp
|
||
| or_else_exp
|
||
| xor_exp
|
||
;
|
||
|
||
and_exp :
|
||
relation _AND_ relation
|
||
{ write_exp_elt_opcode (pstate, BINOP_BITWISE_AND); }
|
||
| and_exp _AND_ relation
|
||
{ write_exp_elt_opcode (pstate, BINOP_BITWISE_AND); }
|
||
;
|
||
|
||
and_then_exp :
|
||
relation _AND_ THEN relation
|
||
{ write_exp_elt_opcode (pstate, BINOP_LOGICAL_AND); }
|
||
| and_then_exp _AND_ THEN relation
|
||
{ write_exp_elt_opcode (pstate, BINOP_LOGICAL_AND); }
|
||
;
|
||
|
||
or_exp :
|
||
relation OR relation
|
||
{ write_exp_elt_opcode (pstate, BINOP_BITWISE_IOR); }
|
||
| or_exp OR relation
|
||
{ write_exp_elt_opcode (pstate, BINOP_BITWISE_IOR); }
|
||
;
|
||
|
||
or_else_exp :
|
||
relation OR ELSE relation
|
||
{ write_exp_elt_opcode (pstate, BINOP_LOGICAL_OR); }
|
||
| or_else_exp OR ELSE relation
|
||
{ write_exp_elt_opcode (pstate, BINOP_LOGICAL_OR); }
|
||
;
|
||
|
||
xor_exp : relation XOR relation
|
||
{ write_exp_elt_opcode (pstate, BINOP_BITWISE_XOR); }
|
||
| xor_exp XOR relation
|
||
{ write_exp_elt_opcode (pstate, BINOP_BITWISE_XOR); }
|
||
;
|
||
|
||
/* Primaries can denote types (OP_TYPE). In cases such as
|
||
primary TICK_ADDRESS, where a type would be invalid, it will be
|
||
caught when evaluate_subexp in ada-lang.c tries to evaluate the
|
||
primary, expecting a value. Precedence rules resolve the ambiguity
|
||
in NAME TICK_ACCESS in favor of shifting to form a var_or_type. A
|
||
construct such as aType'access'access will again cause an error when
|
||
aType'access evaluates to a type that evaluate_subexp attempts to
|
||
evaluate. */
|
||
primary : primary TICK_ACCESS
|
||
{ write_exp_elt_opcode (pstate, UNOP_ADDR); }
|
||
| primary TICK_ADDRESS
|
||
{ write_exp_elt_opcode (pstate, UNOP_ADDR);
|
||
write_exp_elt_opcode (pstate, UNOP_CAST);
|
||
write_exp_elt_type (pstate,
|
||
type_system_address (pstate));
|
||
write_exp_elt_opcode (pstate, UNOP_CAST);
|
||
}
|
||
| primary TICK_FIRST tick_arglist
|
||
{ write_int (pstate, $3, type_int (pstate));
|
||
write_exp_elt_opcode (pstate, OP_ATR_FIRST); }
|
||
| primary TICK_LAST tick_arglist
|
||
{ write_int (pstate, $3, type_int (pstate));
|
||
write_exp_elt_opcode (pstate, OP_ATR_LAST); }
|
||
| primary TICK_LENGTH tick_arglist
|
||
{ write_int (pstate, $3, type_int (pstate));
|
||
write_exp_elt_opcode (pstate, OP_ATR_LENGTH); }
|
||
| primary TICK_SIZE
|
||
{ write_exp_elt_opcode (pstate, OP_ATR_SIZE); }
|
||
| primary TICK_TAG
|
||
{ write_exp_elt_opcode (pstate, OP_ATR_TAG); }
|
||
| opt_type_prefix TICK_MIN '(' exp ',' exp ')'
|
||
{ write_exp_elt_opcode (pstate, OP_ATR_MIN); }
|
||
| opt_type_prefix TICK_MAX '(' exp ',' exp ')'
|
||
{ write_exp_elt_opcode (pstate, OP_ATR_MAX); }
|
||
| opt_type_prefix TICK_POS '(' exp ')'
|
||
{ write_exp_elt_opcode (pstate, OP_ATR_POS); }
|
||
| type_prefix TICK_VAL '(' exp ')'
|
||
{ write_exp_elt_opcode (pstate, OP_ATR_VAL); }
|
||
| type_prefix TICK_MODULUS
|
||
{ write_exp_elt_opcode (pstate, OP_ATR_MODULUS); }
|
||
;
|
||
|
||
tick_arglist : %prec '('
|
||
{ $$ = 1; }
|
||
| '(' INT ')'
|
||
{ $$ = $2.val; }
|
||
;
|
||
|
||
type_prefix :
|
||
var_or_type
|
||
{
|
||
if ($1 == NULL)
|
||
error (_("Prefix must be type"));
|
||
write_exp_elt_opcode (pstate, OP_TYPE);
|
||
write_exp_elt_type (pstate, $1);
|
||
write_exp_elt_opcode (pstate, OP_TYPE); }
|
||
;
|
||
|
||
opt_type_prefix :
|
||
type_prefix
|
||
| /* EMPTY */
|
||
{ write_exp_elt_opcode (pstate, OP_TYPE);
|
||
write_exp_elt_type (pstate,
|
||
parse_type (pstate)->builtin_void);
|
||
write_exp_elt_opcode (pstate, OP_TYPE); }
|
||
;
|
||
|
||
|
||
primary : INT
|
||
{ write_int (pstate, (LONGEST) $1.val, $1.type); }
|
||
;
|
||
|
||
primary : CHARLIT
|
||
{ write_int (pstate,
|
||
convert_char_literal (type_qualifier, $1.val),
|
||
(type_qualifier == NULL)
|
||
? $1.type : type_qualifier);
|
||
}
|
||
;
|
||
|
||
primary : FLOAT
|
||
{ write_exp_elt_opcode (pstate, OP_DOUBLE);
|
||
write_exp_elt_type (pstate, $1.type);
|
||
write_exp_elt_dblcst (pstate, $1.dval);
|
||
write_exp_elt_opcode (pstate, OP_DOUBLE);
|
||
}
|
||
;
|
||
|
||
primary : NULL_PTR
|
||
{ write_int (pstate, 0, type_int (pstate)); }
|
||
;
|
||
|
||
primary : STRING
|
||
{
|
||
write_exp_op_with_string (pstate, OP_STRING, $1);
|
||
}
|
||
;
|
||
|
||
primary : TRUEKEYWORD
|
||
{ write_int (pstate, 1, type_boolean (pstate)); }
|
||
| FALSEKEYWORD
|
||
{ write_int (pstate, 0, type_boolean (pstate)); }
|
||
;
|
||
|
||
primary : NEW NAME
|
||
{ error (_("NEW not implemented.")); }
|
||
;
|
||
|
||
var_or_type: NAME %prec VAR
|
||
{ $$ = write_var_or_type (pstate, NULL, $1); }
|
||
| block NAME %prec VAR
|
||
{ $$ = write_var_or_type (pstate, $1, $2); }
|
||
| NAME TICK_ACCESS
|
||
{
|
||
$$ = write_var_or_type (pstate, NULL, $1);
|
||
if ($$ == NULL)
|
||
write_exp_elt_opcode (pstate, UNOP_ADDR);
|
||
else
|
||
$$ = lookup_pointer_type ($$);
|
||
}
|
||
| block NAME TICK_ACCESS
|
||
{
|
||
$$ = write_var_or_type (pstate, $1, $2);
|
||
if ($$ == NULL)
|
||
write_exp_elt_opcode (pstate, UNOP_ADDR);
|
||
else
|
||
$$ = lookup_pointer_type ($$);
|
||
}
|
||
;
|
||
|
||
/* GDB extension */
|
||
block : NAME COLONCOLON
|
||
{ $$ = block_lookup (NULL, $1.ptr); }
|
||
| block NAME COLONCOLON
|
||
{ $$ = block_lookup ($1, $2.ptr); }
|
||
;
|
||
|
||
aggregate :
|
||
'(' aggregate_component_list ')'
|
||
{
|
||
write_exp_elt_opcode (pstate, OP_AGGREGATE);
|
||
write_exp_elt_longcst (pstate, $2);
|
||
write_exp_elt_opcode (pstate, OP_AGGREGATE);
|
||
}
|
||
;
|
||
|
||
aggregate_component_list :
|
||
component_groups { $$ = $1; }
|
||
| positional_list exp
|
||
{ write_exp_elt_opcode (pstate, OP_POSITIONAL);
|
||
write_exp_elt_longcst (pstate, $1);
|
||
write_exp_elt_opcode (pstate, OP_POSITIONAL);
|
||
$$ = $1 + 1;
|
||
}
|
||
| positional_list component_groups
|
||
{ $$ = $1 + $2; }
|
||
;
|
||
|
||
positional_list :
|
||
exp ','
|
||
{ write_exp_elt_opcode (pstate, OP_POSITIONAL);
|
||
write_exp_elt_longcst (pstate, 0);
|
||
write_exp_elt_opcode (pstate, OP_POSITIONAL);
|
||
$$ = 1;
|
||
}
|
||
| positional_list exp ','
|
||
{ write_exp_elt_opcode (pstate, OP_POSITIONAL);
|
||
write_exp_elt_longcst (pstate, $1);
|
||
write_exp_elt_opcode (pstate, OP_POSITIONAL);
|
||
$$ = $1 + 1;
|
||
}
|
||
;
|
||
|
||
component_groups:
|
||
others { $$ = 1; }
|
||
| component_group { $$ = 1; }
|
||
| component_group ',' component_groups
|
||
{ $$ = $3 + 1; }
|
||
;
|
||
|
||
others : OTHERS ARROW exp
|
||
{ write_exp_elt_opcode (pstate, OP_OTHERS); }
|
||
;
|
||
|
||
component_group :
|
||
component_associations
|
||
{
|
||
write_exp_elt_opcode (pstate, OP_CHOICES);
|
||
write_exp_elt_longcst (pstate, $1);
|
||
write_exp_elt_opcode (pstate, OP_CHOICES);
|
||
}
|
||
;
|
||
|
||
/* We use this somewhat obscure definition in order to handle NAME => and
|
||
NAME | differently from exp => and exp |. ARROW and '|' have a precedence
|
||
above that of the reduction of NAME to var_or_type. By delaying
|
||
decisions until after the => or '|', we convert the ambiguity to a
|
||
resolved shift/reduce conflict. */
|
||
component_associations :
|
||
NAME ARROW
|
||
{ write_name_assoc (pstate, $1); }
|
||
exp { $$ = 1; }
|
||
| simple_exp ARROW exp
|
||
{ $$ = 1; }
|
||
| simple_exp DOTDOT simple_exp ARROW
|
||
{ write_exp_elt_opcode (pstate, OP_DISCRETE_RANGE);
|
||
write_exp_op_with_string (pstate, OP_NAME,
|
||
empty_stoken);
|
||
}
|
||
exp { $$ = 1; }
|
||
| NAME '|'
|
||
{ write_name_assoc (pstate, $1); }
|
||
component_associations { $$ = $4 + 1; }
|
||
| simple_exp '|'
|
||
component_associations { $$ = $3 + 1; }
|
||
| simple_exp DOTDOT simple_exp '|'
|
||
{ write_exp_elt_opcode (pstate, OP_DISCRETE_RANGE); }
|
||
component_associations { $$ = $6 + 1; }
|
||
;
|
||
|
||
/* Some extensions borrowed from C, for the benefit of those who find they
|
||
can't get used to Ada notation in GDB. */
|
||
|
||
primary : '*' primary %prec '.'
|
||
{ write_exp_elt_opcode (pstate, UNOP_IND); }
|
||
| '&' primary %prec '.'
|
||
{ write_exp_elt_opcode (pstate, UNOP_ADDR); }
|
||
| primary '[' exp ']'
|
||
{ write_exp_elt_opcode (pstate, BINOP_SUBSCRIPT); }
|
||
;
|
||
|
||
%%
|
||
|
||
/* yylex defined in ada-lex.c: Reads one token, getting characters */
|
||
/* through lexptr. */
|
||
|
||
/* Remap normal flex interface names (yylex) as well as gratuitiously */
|
||
/* global symbol names, so we can have multiple flex-generated parsers */
|
||
/* in gdb. */
|
||
|
||
/* (See note above on previous definitions for YACC.) */
|
||
|
||
#define yy_create_buffer ada_yy_create_buffer
|
||
#define yy_delete_buffer ada_yy_delete_buffer
|
||
#define yy_init_buffer ada_yy_init_buffer
|
||
#define yy_load_buffer_state ada_yy_load_buffer_state
|
||
#define yy_switch_to_buffer ada_yy_switch_to_buffer
|
||
#define yyrestart ada_yyrestart
|
||
#define yytext ada_yytext
|
||
#define yywrap ada_yywrap
|
||
|
||
static struct obstack temp_parse_space;
|
||
|
||
/* The following kludge was found necessary to prevent conflicts between */
|
||
/* defs.h and non-standard stdlib.h files. */
|
||
#define qsort __qsort__dummy
|
||
#include "ada-lex.c"
|
||
|
||
int
|
||
ada_parse (struct parser_state *par_state)
|
||
{
|
||
int result;
|
||
struct cleanup *c = make_cleanup_clear_parser_state (&pstate);
|
||
|
||
/* Setting up the parser state. */
|
||
gdb_assert (par_state != NULL);
|
||
pstate = par_state;
|
||
|
||
lexer_init (yyin); /* (Re-)initialize lexer. */
|
||
type_qualifier = NULL;
|
||
obstack_free (&temp_parse_space, NULL);
|
||
obstack_init (&temp_parse_space);
|
||
|
||
result = yyparse ();
|
||
do_cleanups (c);
|
||
return result;
|
||
}
|
||
|
||
void
|
||
yyerror (char *msg)
|
||
{
|
||
error (_("Error in expression, near `%s'."), lexptr);
|
||
}
|
||
|
||
/* Emit expression to access an instance of SYM, in block BLOCK (if
|
||
* non-NULL), and with :: qualification ORIG_LEFT_CONTEXT. */
|
||
static void
|
||
write_var_from_sym (struct parser_state *par_state,
|
||
const struct block *orig_left_context,
|
||
const struct block *block,
|
||
struct symbol *sym)
|
||
{
|
||
if (orig_left_context == NULL && symbol_read_needs_frame (sym))
|
||
{
|
||
if (innermost_block == 0
|
||
|| contained_in (block, innermost_block))
|
||
innermost_block = block;
|
||
}
|
||
|
||
write_exp_elt_opcode (par_state, OP_VAR_VALUE);
|
||
write_exp_elt_block (par_state, block);
|
||
write_exp_elt_sym (par_state, sym);
|
||
write_exp_elt_opcode (par_state, OP_VAR_VALUE);
|
||
}
|
||
|
||
/* Write integer or boolean constant ARG of type TYPE. */
|
||
|
||
static void
|
||
write_int (struct parser_state *par_state, LONGEST arg, struct type *type)
|
||
{
|
||
write_exp_elt_opcode (par_state, OP_LONG);
|
||
write_exp_elt_type (par_state, type);
|
||
write_exp_elt_longcst (par_state, arg);
|
||
write_exp_elt_opcode (par_state, OP_LONG);
|
||
}
|
||
|
||
/* Write an OPCODE, string, OPCODE sequence to the current expression. */
|
||
static void
|
||
write_exp_op_with_string (struct parser_state *par_state,
|
||
enum exp_opcode opcode, struct stoken token)
|
||
{
|
||
write_exp_elt_opcode (par_state, opcode);
|
||
write_exp_string (par_state, token);
|
||
write_exp_elt_opcode (par_state, opcode);
|
||
}
|
||
|
||
/* Emit expression corresponding to the renamed object named
|
||
* designated by RENAMED_ENTITY[0 .. RENAMED_ENTITY_LEN-1] in the
|
||
* context of ORIG_LEFT_CONTEXT, to which is applied the operations
|
||
* encoded by RENAMING_EXPR. MAX_DEPTH is the maximum number of
|
||
* cascaded renamings to allow. If ORIG_LEFT_CONTEXT is null, it
|
||
* defaults to the currently selected block. ORIG_SYMBOL is the
|
||
* symbol that originally encoded the renaming. It is needed only
|
||
* because its prefix also qualifies any index variables used to index
|
||
* or slice an array. It should not be necessary once we go to the
|
||
* new encoding entirely (FIXME pnh 7/20/2007). */
|
||
|
||
static void
|
||
write_object_renaming (struct parser_state *par_state,
|
||
const struct block *orig_left_context,
|
||
const char *renamed_entity, int renamed_entity_len,
|
||
const char *renaming_expr, int max_depth)
|
||
{
|
||
char *name;
|
||
enum { SIMPLE_INDEX, LOWER_BOUND, UPPER_BOUND } slice_state;
|
||
struct block_symbol sym_info;
|
||
|
||
if (max_depth <= 0)
|
||
error (_("Could not find renamed symbol"));
|
||
|
||
if (orig_left_context == NULL)
|
||
orig_left_context = get_selected_block (NULL);
|
||
|
||
name = (char *) obstack_copy0 (&temp_parse_space, renamed_entity,
|
||
renamed_entity_len);
|
||
ada_lookup_encoded_symbol (name, orig_left_context, VAR_DOMAIN, &sym_info);
|
||
if (sym_info.symbol == NULL)
|
||
error (_("Could not find renamed variable: %s"), ada_decode (name));
|
||
else if (SYMBOL_CLASS (sym_info.symbol) == LOC_TYPEDEF)
|
||
/* We have a renaming of an old-style renaming symbol. Don't
|
||
trust the block information. */
|
||
sym_info.block = orig_left_context;
|
||
|
||
{
|
||
const char *inner_renamed_entity;
|
||
int inner_renamed_entity_len;
|
||
const char *inner_renaming_expr;
|
||
|
||
switch (ada_parse_renaming (sym_info.symbol, &inner_renamed_entity,
|
||
&inner_renamed_entity_len,
|
||
&inner_renaming_expr))
|
||
{
|
||
case ADA_NOT_RENAMING:
|
||
write_var_from_sym (par_state, orig_left_context, sym_info.block,
|
||
sym_info.symbol);
|
||
break;
|
||
case ADA_OBJECT_RENAMING:
|
||
write_object_renaming (par_state, sym_info.block,
|
||
inner_renamed_entity, inner_renamed_entity_len,
|
||
inner_renaming_expr, max_depth - 1);
|
||
break;
|
||
default:
|
||
goto BadEncoding;
|
||
}
|
||
}
|
||
|
||
slice_state = SIMPLE_INDEX;
|
||
while (*renaming_expr == 'X')
|
||
{
|
||
renaming_expr += 1;
|
||
|
||
switch (*renaming_expr) {
|
||
case 'A':
|
||
renaming_expr += 1;
|
||
write_exp_elt_opcode (par_state, UNOP_IND);
|
||
break;
|
||
case 'L':
|
||
slice_state = LOWER_BOUND;
|
||
/* FALLTHROUGH */
|
||
case 'S':
|
||
renaming_expr += 1;
|
||
if (isdigit (*renaming_expr))
|
||
{
|
||
char *next;
|
||
long val = strtol (renaming_expr, &next, 10);
|
||
if (next == renaming_expr)
|
||
goto BadEncoding;
|
||
renaming_expr = next;
|
||
write_exp_elt_opcode (par_state, OP_LONG);
|
||
write_exp_elt_type (par_state, type_int (par_state));
|
||
write_exp_elt_longcst (par_state, (LONGEST) val);
|
||
write_exp_elt_opcode (par_state, OP_LONG);
|
||
}
|
||
else
|
||
{
|
||
const char *end;
|
||
char *index_name;
|
||
struct block_symbol index_sym_info;
|
||
|
||
end = strchr (renaming_expr, 'X');
|
||
if (end == NULL)
|
||
end = renaming_expr + strlen (renaming_expr);
|
||
|
||
index_name
|
||
= (char *) obstack_copy0 (&temp_parse_space, renaming_expr,
|
||
end - renaming_expr);
|
||
renaming_expr = end;
|
||
|
||
ada_lookup_encoded_symbol (index_name, NULL, VAR_DOMAIN,
|
||
&index_sym_info);
|
||
if (index_sym_info.symbol == NULL)
|
||
error (_("Could not find %s"), index_name);
|
||
else if (SYMBOL_CLASS (index_sym_info.symbol) == LOC_TYPEDEF)
|
||
/* Index is an old-style renaming symbol. */
|
||
index_sym_info.block = orig_left_context;
|
||
write_var_from_sym (par_state, NULL, index_sym_info.block,
|
||
index_sym_info.symbol);
|
||
}
|
||
if (slice_state == SIMPLE_INDEX)
|
||
{
|
||
write_exp_elt_opcode (par_state, OP_FUNCALL);
|
||
write_exp_elt_longcst (par_state, (LONGEST) 1);
|
||
write_exp_elt_opcode (par_state, OP_FUNCALL);
|
||
}
|
||
else if (slice_state == LOWER_BOUND)
|
||
slice_state = UPPER_BOUND;
|
||
else if (slice_state == UPPER_BOUND)
|
||
{
|
||
write_exp_elt_opcode (par_state, TERNOP_SLICE);
|
||
slice_state = SIMPLE_INDEX;
|
||
}
|
||
break;
|
||
|
||
case 'R':
|
||
{
|
||
struct stoken field_name;
|
||
const char *end;
|
||
char *buf;
|
||
|
||
renaming_expr += 1;
|
||
|
||
if (slice_state != SIMPLE_INDEX)
|
||
goto BadEncoding;
|
||
end = strchr (renaming_expr, 'X');
|
||
if (end == NULL)
|
||
end = renaming_expr + strlen (renaming_expr);
|
||
field_name.length = end - renaming_expr;
|
||
buf = (char *) malloc (end - renaming_expr + 1);
|
||
field_name.ptr = buf;
|
||
strncpy (buf, renaming_expr, end - renaming_expr);
|
||
buf[end - renaming_expr] = '\000';
|
||
renaming_expr = end;
|
||
write_exp_op_with_string (par_state, STRUCTOP_STRUCT, field_name);
|
||
break;
|
||
}
|
||
|
||
default:
|
||
goto BadEncoding;
|
||
}
|
||
}
|
||
if (slice_state == SIMPLE_INDEX)
|
||
return;
|
||
|
||
BadEncoding:
|
||
error (_("Internal error in encoding of renaming declaration"));
|
||
}
|
||
|
||
static const struct block*
|
||
block_lookup (const struct block *context, const char *raw_name)
|
||
{
|
||
const char *name;
|
||
struct block_symbol *syms;
|
||
int nsyms;
|
||
struct symtab *symtab;
|
||
|
||
if (raw_name[0] == '\'')
|
||
{
|
||
raw_name += 1;
|
||
name = raw_name;
|
||
}
|
||
else
|
||
name = ada_encode (raw_name);
|
||
|
||
nsyms = ada_lookup_symbol_list (name, context, VAR_DOMAIN, &syms);
|
||
if (context == NULL
|
||
&& (nsyms == 0 || SYMBOL_CLASS (syms[0].symbol) != LOC_BLOCK))
|
||
symtab = lookup_symtab (name);
|
||
else
|
||
symtab = NULL;
|
||
|
||
if (symtab != NULL)
|
||
return BLOCKVECTOR_BLOCK (SYMTAB_BLOCKVECTOR (symtab), STATIC_BLOCK);
|
||
else if (nsyms == 0 || SYMBOL_CLASS (syms[0].symbol) != LOC_BLOCK)
|
||
{
|
||
if (context == NULL)
|
||
error (_("No file or function \"%s\"."), raw_name);
|
||
else
|
||
error (_("No function \"%s\" in specified context."), raw_name);
|
||
}
|
||
else
|
||
{
|
||
if (nsyms > 1)
|
||
warning (_("Function name \"%s\" ambiguous here"), raw_name);
|
||
return SYMBOL_BLOCK_VALUE (syms[0].symbol);
|
||
}
|
||
}
|
||
|
||
static struct symbol*
|
||
select_possible_type_sym (struct block_symbol *syms, int nsyms)
|
||
{
|
||
int i;
|
||
int preferred_index;
|
||
struct type *preferred_type;
|
||
|
||
preferred_index = -1; preferred_type = NULL;
|
||
for (i = 0; i < nsyms; i += 1)
|
||
switch (SYMBOL_CLASS (syms[i].symbol))
|
||
{
|
||
case LOC_TYPEDEF:
|
||
if (ada_prefer_type (SYMBOL_TYPE (syms[i].symbol), preferred_type))
|
||
{
|
||
preferred_index = i;
|
||
preferred_type = SYMBOL_TYPE (syms[i].symbol);
|
||
}
|
||
break;
|
||
case LOC_REGISTER:
|
||
case LOC_ARG:
|
||
case LOC_REF_ARG:
|
||
case LOC_REGPARM_ADDR:
|
||
case LOC_LOCAL:
|
||
case LOC_COMPUTED:
|
||
return NULL;
|
||
default:
|
||
break;
|
||
}
|
||
if (preferred_type == NULL)
|
||
return NULL;
|
||
return syms[preferred_index].symbol;
|
||
}
|
||
|
||
static struct type*
|
||
find_primitive_type (struct parser_state *par_state, char *name)
|
||
{
|
||
struct type *type;
|
||
type = language_lookup_primitive_type (parse_language (par_state),
|
||
parse_gdbarch (par_state),
|
||
name);
|
||
if (type == NULL && strcmp ("system__address", name) == 0)
|
||
type = type_system_address (par_state);
|
||
|
||
if (type != NULL)
|
||
{
|
||
/* Check to see if we have a regular definition of this
|
||
type that just didn't happen to have been read yet. */
|
||
struct symbol *sym;
|
||
char *expanded_name =
|
||
(char *) alloca (strlen (name) + sizeof ("standard__"));
|
||
strcpy (expanded_name, "standard__");
|
||
strcat (expanded_name, name);
|
||
sym = ada_lookup_symbol (expanded_name, NULL, VAR_DOMAIN, NULL).symbol;
|
||
if (sym != NULL && SYMBOL_CLASS (sym) == LOC_TYPEDEF)
|
||
type = SYMBOL_TYPE (sym);
|
||
}
|
||
|
||
return type;
|
||
}
|
||
|
||
static int
|
||
chop_selector (char *name, int end)
|
||
{
|
||
int i;
|
||
for (i = end - 1; i > 0; i -= 1)
|
||
if (name[i] == '.' || (name[i] == '_' && name[i+1] == '_'))
|
||
return i;
|
||
return -1;
|
||
}
|
||
|
||
/* If NAME is a string beginning with a separator (either '__', or
|
||
'.'), chop this separator and return the result; else, return
|
||
NAME. */
|
||
|
||
static char *
|
||
chop_separator (char *name)
|
||
{
|
||
if (*name == '.')
|
||
return name + 1;
|
||
|
||
if (name[0] == '_' && name[1] == '_')
|
||
return name + 2;
|
||
|
||
return name;
|
||
}
|
||
|
||
/* Given that SELS is a string of the form (<sep><identifier>)*, where
|
||
<sep> is '__' or '.', write the indicated sequence of
|
||
STRUCTOP_STRUCT expression operators. */
|
||
static void
|
||
write_selectors (struct parser_state *par_state, char *sels)
|
||
{
|
||
while (*sels != '\0')
|
||
{
|
||
struct stoken field_name;
|
||
char *p = chop_separator (sels);
|
||
sels = p;
|
||
while (*sels != '\0' && *sels != '.'
|
||
&& (sels[0] != '_' || sels[1] != '_'))
|
||
sels += 1;
|
||
field_name.length = sels - p;
|
||
field_name.ptr = p;
|
||
write_exp_op_with_string (par_state, STRUCTOP_STRUCT, field_name);
|
||
}
|
||
}
|
||
|
||
/* Write a variable access (OP_VAR_VALUE) to ambiguous encoded name
|
||
NAME[0..LEN-1], in block context BLOCK, to be resolved later. Writes
|
||
a temporary symbol that is valid until the next call to ada_parse.
|
||
*/
|
||
static void
|
||
write_ambiguous_var (struct parser_state *par_state,
|
||
const struct block *block, char *name, int len)
|
||
{
|
||
struct symbol *sym = XOBNEW (&temp_parse_space, struct symbol);
|
||
|
||
memset (sym, 0, sizeof (struct symbol));
|
||
SYMBOL_DOMAIN (sym) = UNDEF_DOMAIN;
|
||
SYMBOL_LINKAGE_NAME (sym)
|
||
= (const char *) obstack_copy0 (&temp_parse_space, name, len);
|
||
SYMBOL_LANGUAGE (sym) = language_ada;
|
||
|
||
write_exp_elt_opcode (par_state, OP_VAR_VALUE);
|
||
write_exp_elt_block (par_state, block);
|
||
write_exp_elt_sym (par_state, sym);
|
||
write_exp_elt_opcode (par_state, OP_VAR_VALUE);
|
||
}
|
||
|
||
/* A convenient wrapper around ada_get_field_index that takes
|
||
a non NUL-terminated FIELD_NAME0 and a FIELD_NAME_LEN instead
|
||
of a NUL-terminated field name. */
|
||
|
||
static int
|
||
ada_nget_field_index (const struct type *type, const char *field_name0,
|
||
int field_name_len, int maybe_missing)
|
||
{
|
||
char *field_name = (char *) alloca ((field_name_len + 1) * sizeof (char));
|
||
|
||
strncpy (field_name, field_name0, field_name_len);
|
||
field_name[field_name_len] = '\0';
|
||
return ada_get_field_index (type, field_name, maybe_missing);
|
||
}
|
||
|
||
/* If encoded_field_name is the name of a field inside symbol SYM,
|
||
then return the type of that field. Otherwise, return NULL.
|
||
|
||
This function is actually recursive, so if ENCODED_FIELD_NAME
|
||
doesn't match one of the fields of our symbol, then try to see
|
||
if ENCODED_FIELD_NAME could not be a succession of field names
|
||
(in other words, the user entered an expression of the form
|
||
TYPE_NAME.FIELD1.FIELD2.FIELD3), in which case we evaluate
|
||
each field name sequentially to obtain the desired field type.
|
||
In case of failure, we return NULL. */
|
||
|
||
static struct type *
|
||
get_symbol_field_type (struct symbol *sym, char *encoded_field_name)
|
||
{
|
||
char *field_name = encoded_field_name;
|
||
char *subfield_name;
|
||
struct type *type = SYMBOL_TYPE (sym);
|
||
int fieldno;
|
||
|
||
if (type == NULL || field_name == NULL)
|
||
return NULL;
|
||
type = check_typedef (type);
|
||
|
||
while (field_name[0] != '\0')
|
||
{
|
||
field_name = chop_separator (field_name);
|
||
|
||
fieldno = ada_get_field_index (type, field_name, 1);
|
||
if (fieldno >= 0)
|
||
return TYPE_FIELD_TYPE (type, fieldno);
|
||
|
||
subfield_name = field_name;
|
||
while (*subfield_name != '\0' && *subfield_name != '.'
|
||
&& (subfield_name[0] != '_' || subfield_name[1] != '_'))
|
||
subfield_name += 1;
|
||
|
||
if (subfield_name[0] == '\0')
|
||
return NULL;
|
||
|
||
fieldno = ada_nget_field_index (type, field_name,
|
||
subfield_name - field_name, 1);
|
||
if (fieldno < 0)
|
||
return NULL;
|
||
|
||
type = TYPE_FIELD_TYPE (type, fieldno);
|
||
field_name = subfield_name;
|
||
}
|
||
|
||
return NULL;
|
||
}
|
||
|
||
/* Look up NAME0 (an unencoded identifier or dotted name) in BLOCK (or
|
||
expression_block_context if NULL). If it denotes a type, return
|
||
that type. Otherwise, write expression code to evaluate it as an
|
||
object and return NULL. In this second case, NAME0 will, in general,
|
||
have the form <name>(.<selector_name>)*, where <name> is an object
|
||
or renaming encoded in the debugging data. Calls error if no
|
||
prefix <name> matches a name in the debugging data (i.e., matches
|
||
either a complete name or, as a wild-card match, the final
|
||
identifier). */
|
||
|
||
static struct type*
|
||
write_var_or_type (struct parser_state *par_state,
|
||
const struct block *block, struct stoken name0)
|
||
{
|
||
int depth;
|
||
char *encoded_name;
|
||
int name_len;
|
||
|
||
if (block == NULL)
|
||
block = expression_context_block;
|
||
|
||
encoded_name = ada_encode (name0.ptr);
|
||
name_len = strlen (encoded_name);
|
||
encoded_name
|
||
= (char *) obstack_copy0 (&temp_parse_space, encoded_name, name_len);
|
||
for (depth = 0; depth < MAX_RENAMING_CHAIN_LENGTH; depth += 1)
|
||
{
|
||
int tail_index;
|
||
|
||
tail_index = name_len;
|
||
while (tail_index > 0)
|
||
{
|
||
int nsyms;
|
||
struct block_symbol *syms;
|
||
struct symbol *type_sym;
|
||
struct symbol *renaming_sym;
|
||
const char* renaming;
|
||
int renaming_len;
|
||
const char* renaming_expr;
|
||
int terminator = encoded_name[tail_index];
|
||
|
||
encoded_name[tail_index] = '\0';
|
||
nsyms = ada_lookup_symbol_list (encoded_name, block,
|
||
VAR_DOMAIN, &syms);
|
||
encoded_name[tail_index] = terminator;
|
||
|
||
/* A single symbol may rename a package or object. */
|
||
|
||
/* This should go away when we move entirely to new version.
|
||
FIXME pnh 7/20/2007. */
|
||
if (nsyms == 1)
|
||
{
|
||
struct symbol *ren_sym =
|
||
ada_find_renaming_symbol (syms[0].symbol, syms[0].block);
|
||
|
||
if (ren_sym != NULL)
|
||
syms[0].symbol = ren_sym;
|
||
}
|
||
|
||
type_sym = select_possible_type_sym (syms, nsyms);
|
||
|
||
if (type_sym != NULL)
|
||
renaming_sym = type_sym;
|
||
else if (nsyms == 1)
|
||
renaming_sym = syms[0].symbol;
|
||
else
|
||
renaming_sym = NULL;
|
||
|
||
switch (ada_parse_renaming (renaming_sym, &renaming,
|
||
&renaming_len, &renaming_expr))
|
||
{
|
||
case ADA_NOT_RENAMING:
|
||
break;
|
||
case ADA_PACKAGE_RENAMING:
|
||
case ADA_EXCEPTION_RENAMING:
|
||
case ADA_SUBPROGRAM_RENAMING:
|
||
{
|
||
int alloc_len = renaming_len + name_len - tail_index + 1;
|
||
char *new_name
|
||
= (char *) obstack_alloc (&temp_parse_space, alloc_len);
|
||
strncpy (new_name, renaming, renaming_len);
|
||
strcpy (new_name + renaming_len, encoded_name + tail_index);
|
||
encoded_name = new_name;
|
||
name_len = renaming_len + name_len - tail_index;
|
||
goto TryAfterRenaming;
|
||
}
|
||
case ADA_OBJECT_RENAMING:
|
||
write_object_renaming (par_state, block, renaming, renaming_len,
|
||
renaming_expr, MAX_RENAMING_CHAIN_LENGTH);
|
||
write_selectors (par_state, encoded_name + tail_index);
|
||
return NULL;
|
||
default:
|
||
internal_error (__FILE__, __LINE__,
|
||
_("impossible value from ada_parse_renaming"));
|
||
}
|
||
|
||
if (type_sym != NULL)
|
||
{
|
||
struct type *field_type;
|
||
|
||
if (tail_index == name_len)
|
||
return SYMBOL_TYPE (type_sym);
|
||
|
||
/* We have some extraneous characters after the type name.
|
||
If this is an expression "TYPE_NAME.FIELD0.[...].FIELDN",
|
||
then try to get the type of FIELDN. */
|
||
field_type
|
||
= get_symbol_field_type (type_sym, encoded_name + tail_index);
|
||
if (field_type != NULL)
|
||
return field_type;
|
||
else
|
||
error (_("Invalid attempt to select from type: \"%s\"."),
|
||
name0.ptr);
|
||
}
|
||
else if (tail_index == name_len && nsyms == 0)
|
||
{
|
||
struct type *type = find_primitive_type (par_state,
|
||
encoded_name);
|
||
|
||
if (type != NULL)
|
||
return type;
|
||
}
|
||
|
||
if (nsyms == 1)
|
||
{
|
||
write_var_from_sym (par_state, block, syms[0].block,
|
||
syms[0].symbol);
|
||
write_selectors (par_state, encoded_name + tail_index);
|
||
return NULL;
|
||
}
|
||
else if (nsyms == 0)
|
||
{
|
||
struct bound_minimal_symbol msym
|
||
= ada_lookup_simple_minsym (encoded_name);
|
||
if (msym.minsym != NULL)
|
||
{
|
||
write_exp_msymbol (par_state, msym);
|
||
/* Maybe cause error here rather than later? FIXME? */
|
||
write_selectors (par_state, encoded_name + tail_index);
|
||
return NULL;
|
||
}
|
||
|
||
if (tail_index == name_len
|
||
&& strncmp (encoded_name, "standard__",
|
||
sizeof ("standard__") - 1) == 0)
|
||
error (_("No definition of \"%s\" found."), name0.ptr);
|
||
|
||
tail_index = chop_selector (encoded_name, tail_index);
|
||
}
|
||
else
|
||
{
|
||
write_ambiguous_var (par_state, block, encoded_name,
|
||
tail_index);
|
||
write_selectors (par_state, encoded_name + tail_index);
|
||
return NULL;
|
||
}
|
||
}
|
||
|
||
if (!have_full_symbols () && !have_partial_symbols () && block == NULL)
|
||
error (_("No symbol table is loaded. Use the \"file\" command."));
|
||
if (block == expression_context_block)
|
||
error (_("No definition of \"%s\" in current context."), name0.ptr);
|
||
else
|
||
error (_("No definition of \"%s\" in specified context."), name0.ptr);
|
||
|
||
TryAfterRenaming: ;
|
||
}
|
||
|
||
error (_("Could not find renamed symbol \"%s\""), name0.ptr);
|
||
|
||
}
|
||
|
||
/* Write a left side of a component association (e.g., NAME in NAME =>
|
||
exp). If NAME has the form of a selected component, write it as an
|
||
ordinary expression. If it is a simple variable that unambiguously
|
||
corresponds to exactly one symbol that does not denote a type or an
|
||
object renaming, also write it normally as an OP_VAR_VALUE.
|
||
Otherwise, write it as an OP_NAME.
|
||
|
||
Unfortunately, we don't know at this point whether NAME is supposed
|
||
to denote a record component name or the value of an array index.
|
||
Therefore, it is not appropriate to disambiguate an ambiguous name
|
||
as we normally would, nor to replace a renaming with its referent.
|
||
As a result, in the (one hopes) rare case that one writes an
|
||
aggregate such as (R => 42) where R renames an object or is an
|
||
ambiguous name, one must write instead ((R) => 42). */
|
||
|
||
static void
|
||
write_name_assoc (struct parser_state *par_state, struct stoken name)
|
||
{
|
||
if (strchr (name.ptr, '.') == NULL)
|
||
{
|
||
struct block_symbol *syms;
|
||
int nsyms = ada_lookup_symbol_list (name.ptr, expression_context_block,
|
||
VAR_DOMAIN, &syms);
|
||
|
||
if (nsyms != 1 || SYMBOL_CLASS (syms[0].symbol) == LOC_TYPEDEF)
|
||
write_exp_op_with_string (par_state, OP_NAME, name);
|
||
else
|
||
write_var_from_sym (par_state, NULL, syms[0].block, syms[0].symbol);
|
||
}
|
||
else
|
||
if (write_var_or_type (par_state, NULL, name) != NULL)
|
||
error (_("Invalid use of type."));
|
||
}
|
||
|
||
/* Convert the character literal whose ASCII value would be VAL to the
|
||
appropriate value of type TYPE, if there is a translation.
|
||
Otherwise return VAL. Hence, in an enumeration type ('A', 'B'),
|
||
the literal 'A' (VAL == 65), returns 0. */
|
||
|
||
static LONGEST
|
||
convert_char_literal (struct type *type, LONGEST val)
|
||
{
|
||
char name[7];
|
||
int f;
|
||
|
||
if (type == NULL)
|
||
return val;
|
||
type = check_typedef (type);
|
||
if (TYPE_CODE (type) != TYPE_CODE_ENUM)
|
||
return val;
|
||
|
||
xsnprintf (name, sizeof (name), "QU%02x", (int) val);
|
||
for (f = 0; f < TYPE_NFIELDS (type); f += 1)
|
||
{
|
||
if (strcmp (name, TYPE_FIELD_NAME (type, f)) == 0)
|
||
return TYPE_FIELD_ENUMVAL (type, f);
|
||
}
|
||
return val;
|
||
}
|
||
|
||
static struct type *
|
||
type_int (struct parser_state *par_state)
|
||
{
|
||
return parse_type (par_state)->builtin_int;
|
||
}
|
||
|
||
static struct type *
|
||
type_long (struct parser_state *par_state)
|
||
{
|
||
return parse_type (par_state)->builtin_long;
|
||
}
|
||
|
||
static struct type *
|
||
type_long_long (struct parser_state *par_state)
|
||
{
|
||
return parse_type (par_state)->builtin_long_long;
|
||
}
|
||
|
||
static struct type *
|
||
type_float (struct parser_state *par_state)
|
||
{
|
||
return parse_type (par_state)->builtin_float;
|
||
}
|
||
|
||
static struct type *
|
||
type_double (struct parser_state *par_state)
|
||
{
|
||
return parse_type (par_state)->builtin_double;
|
||
}
|
||
|
||
static struct type *
|
||
type_long_double (struct parser_state *par_state)
|
||
{
|
||
return parse_type (par_state)->builtin_long_double;
|
||
}
|
||
|
||
static struct type *
|
||
type_char (struct parser_state *par_state)
|
||
{
|
||
return language_string_char_type (parse_language (par_state),
|
||
parse_gdbarch (par_state));
|
||
}
|
||
|
||
static struct type *
|
||
type_boolean (struct parser_state *par_state)
|
||
{
|
||
return parse_type (par_state)->builtin_bool;
|
||
}
|
||
|
||
static struct type *
|
||
type_system_address (struct parser_state *par_state)
|
||
{
|
||
struct type *type
|
||
= language_lookup_primitive_type (parse_language (par_state),
|
||
parse_gdbarch (par_state),
|
||
"system__address");
|
||
return type != NULL ? type : parse_type (par_state)->builtin_data_ptr;
|
||
}
|
||
|
||
/* Provide a prototype to silence -Wmissing-prototypes. */
|
||
extern initialize_file_ftype _initialize_ada_exp;
|
||
|
||
void
|
||
_initialize_ada_exp (void)
|
||
{
|
||
obstack_init (&temp_parse_space);
|
||
}
|