2012-04-25 22:07:23 +08:00
|
|
|
/* Go language support definitions for GDB, the GNU debugger.
|
|
|
|
|
2021-01-01 16:03:39 +08:00
|
|
|
Copyright (C) 2012-2021 Free Software Foundation, Inc.
|
2012-04-25 22:07:23 +08:00
|
|
|
|
|
|
|
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/>. */
|
|
|
|
|
|
|
|
#if !defined (GO_LANG_H)
|
|
|
|
#define GO_LANG_H 1
|
|
|
|
|
* ada-lang.c (user_select_syms, ada_print_subexp): Pass flags
to type-printing functions.
* ada-lang.h (ada_print_type): Add argument.
* ada-typeprint.c (print_array_type, print_variant_clauses,
print_variant_part, print_selected_record_field_types,
print_record_field_types, print_unchecked_union_type,
print_func_type, ada_print_type): Add flags argument.
(ada_print_typedef): Update.
* c-exp.y (OPERATOR conversion_type_id): Update.
* c-lang.h (c_print_type, c_type_print_base): Update.
* c-typeprint.c (c_print_type, c_type_print_varspec_prefix,
c_type_print_modifier, c_type_print_args,
c_type_print_varspec_suffix, c_type_print_base): Add flags
argument.
* cp-valprint.c (cp_print_class_member): Update.
* dwarf2read.c (dwarf2_compute_name): Update.
* f-lang.h (f_print_type): Add argument.
* f-typeprint.c (f_print_type): Add flags argument.
* gnu-v3-abi.c (gnuv3_print_method_ptr): Update.
* go-lang.h (go_print_type): Add argument.
* go-typeprint.c (go_print_type): Add flags argument.
* jv-lang.h (java_print_type): Add argument.
* jv-typeprint.c (java_type_print_base, java_print_type): Add
flags argument.
* language.c (unk_lang_print_type): Add flags argument.
* language.h (struct language_defn) <la_print_type>: Add flags
argument.
(LA_PRINT_TYPE): Likewise.
* m2-lang.h (m2_print_type): Add argument.
* m2-typeprint.c (m2_print_type, m2_range, m2_typedef,
m2_array, m2_pointer, m2_ref, m2_procedure, m2_long_set,
m2_unbounded_array, m2_record_fields): Add flags argument.
* p-lang.h (pascal_print_type, pascal_type_print_base,
pascal_type_print_varspec_prefix): Add argument.
* p-typeprint.c (pascal_print_type,
pascal_type_print_varspec_prefix, pascal_print_func_args,
pascal_type_print_varspec_suffix, pascal_type_print_base): Add
flags argument.
* symmisc.c (print_symbol): Update.
* typeprint.c (type_print_raw_options, default_ptype_flags):
New globals.
(type_print): Update.
* typeprint.h (struct type_print_options): New.
(type_print_raw_options): Declare.
(c_type_print_varspec_suffix, c_type_print_args): Add argument.
2012-11-13 01:14:55 +08:00
|
|
|
struct type_print_options;
|
|
|
|
|
2012-04-25 22:07:23 +08:00
|
|
|
#include "gdbtypes.h"
|
|
|
|
#include "symtab.h"
|
|
|
|
#include "value.h"
|
|
|
|
|
Remove `expout*' globals from parser-defs.h
This commit removes the "expout*" globals from our parser code, turning
them into a structure that is passed when an expression needs to be
evaluated. This is the initial step to make our parser less
"globalized".
This is mostly a mechanical patch, which creates a structure containing
the "expout*" globals and then modify all the functions that handle them
in order to take the structure as argument. It is big, and has been
reviewed at least 4 times, so I think everything is covered.
Below you can see the message links from the discussions:
- First attempt:
<https://sourceware.org/ml/gdb-patches/2012-01/msg00522.html>
Message-ID: <m3k44s7qej.fsf@gmail.com>
- Second attempt:
<https://sourceware.org/ml/gdb-patches/2012-06/msg00054.html>
Message-Id: <1338665528-5932-1-git-send-email-sergiodj@redhat.com>
- Third attempt:
<https://sourceware.org/ml/gdb-patches/2014-01/msg00949.html>
Message-Id: <1390629467-27139-1-git-send-email-sergiodj@redhat.com>
- Fourth (last) attempt:
<https://sourceware.org/ml/gdb-patches/2014-03/msg00546.html>
Message-Id: <1395463432-29750-1-git-send-email-sergiodj@redhat.com>
gdb/
2014-03-27 Sergio Durigan Junior <sergiodj@redhat.com>
Remove some globals from our parser.
* language.c (unk_lang_parser): Add "struct parser_state"
argument.
* language.h (struct language_defn) <la_parser>: Likewise.
* parse.c (expout, expout_size, expout_ptr): Remove variables.
(initialize_expout): Add "struct parser_state" argument.
Rewrite function to use the parser state.
(reallocate_expout, write_exp_elt, write_exp_elt_opcode,
write_exp_elt_sym, write_exp_elt_block, write_exp_elt_objfile,
write_exp_elt_longcst, write_exp_elt_dblcst,
write_exp_elt_decfloatcst, write_exp_elt_type,
write_exp_elt_intern, write_exp_string, write_exp_string_vector,
write_exp_bitstring, write_exp_msymbol, mark_struct_expression,
write_dollar_variable): Likewise.
(parse_exp_in_context_1): Use parser state.
(insert_type_address_space): Add "struct parser_state" argument.
Use parser state.
(increase_expout_size): New function.
* parser-defs.h: Forward declare "struct language_defn" and
"struct parser_state".
(expout, expout_size, expout_ptr): Remove extern declarations.
(parse_gdbarch, parse_language): Rewrite macro declarations to
accept the parser state.
(struct parser_state): New struct.
(initialize_expout, reallocate_expout, write_exp_elt_opcode,
write_exp_elt_sym, write_exp_elt_longcst, write_exp_elt_dblcst,
write_exp_elt_decfloatcst, write_exp_elt_type,
write_exp_elt_intern, write_exp_string, write_exp_string_vector,
write_exp_bitstring, write_exp_elt_block, write_exp_elt_objfile,
write_exp_msymbol, write_dollar_variable,
mark_struct_expression, insert_type_address_space): Add "struct
parser_state" argument.
(increase_expout_size): New function.
* utils.c (do_clear_parser_state): New function.
(make_cleanup_clear_parser_state): Likewise.
* utils.h (make_cleanup_clear_parser_state): New function
prototype.
* aarch64-linux-tdep.c (aarch64_stap_parse_special_token):
Update calls to write_exp* in order to pass the parser state.
* arm-linux-tdep.c (arm_stap_parse_special_token): Likewise.
* i386-tdep.c (i386_stap_parse_special_token_triplet): Likewise.
(i386_stap_parse_special_token_three_arg_disp): Likewise.
* ppc-linux-tdep.c (ppc_stap_parse_special_token): Likewise.
* stap-probe.c (stap_parse_register_operand): Likewise.
(stap_parse_single_operand): Likewise.
(stap_parse_argument_1): Likewise.
(stap_parse_argument): Use parser state.
* stap-probe.h: Include "parser-defs.h".
(struct stap_parse_info) <pstate>: New field.
* c-exp.y (parse_type): Rewrite to use parser state.
(yyparse): Redefine to c_parse_internal.
(pstate): New global variable.
(parse_number): Add "struct parser_state" argument.
(write_destructor_name): Likewise.
(type_exp): Update calls to write_exp* and similars in order to
use parser state.
(exp1, exp, variable, qualified_name, space_identifier,
typename, typebase): Likewise.
(write_destructor_name, parse_number, lex_one_token,
classify_name, classify_inner_name, c_parse): Add "struct
parser_state" argument. Update function to use parser state.
* c-lang.h: Forward declare "struct parser_state".
(c_parse): Add "struct parser_state" argument.
* ada-exp.y (parse_type): Rewrite macro to use parser state.
(yyparse): Redefine macro to ada_parse_internal.
(pstate): New variable.
(write_int, write_object_renaming, write_var_or_type,
write_name_assoc, write_exp_op_with_string, write_ambiguous_var,
type_int, type_long, type_long_long, type_float, type_double,
type_long_double, type_char, type_boolean, type_system_address):
Add "struct parser_state" argument.
(exp1, primary, simple_exp, relation, and_exp, and_then_exp,
or_exp, or_else_exp, xor_exp, type_prefix, opt_type_prefix,
var_or_type, aggregate, aggregate_component_list,
positional_list, others, component_group,
component_associations): Update calls to write_exp* and similar
functions in order to use parser state.
(ada_parse, write_var_from_sym, write_int,
write_exp_op_with_string, write_object_renaming,
find_primitive_type, write_selectors, write_ambiguous_var,
write_var_or_type, write_name_assoc, type_int, type_long,
type_long_long, type_float, type_double, type_long_double,
type_char, type_boolean, type_system_address): Add "struct
parser_state" argument. Adjust function to use parser state.
* ada-lang.c (parse): Likewise.
* ada-lang.h: Forward declare "struct parser_state".
(ada_parse): Add "struct parser_state" argument.
* ada-lex.l (processInt, processReal): Likewise. Adjust all
calls to both functions.
* f-exp.y (parse_type, parse_f_type): Rewrite macros to use
parser state.
(yyparse): Redefine macro to f_parse_internal.
(pstate): New variable.
(parse_number): Add "struct parser_state" argument.
(type_exp, exp, subrange, typebase): Update calls to write_exp*
and similars in order to use parser state.
(parse_number): Adjust code to use parser state.
(yylex): Likewise.
(f_parse): New function.
* f-lang.h: Forward declare "struct parser_state".
(f_parse): Add "struct parser_state" argument.
* jv-exp.y (parse_type, parse_java_type): Rewrite macros to use
parser state.
(yyparse): Redefine macro for java_parse_internal.
(pstate): New variable.
(push_expression_name, push_expression_name, insert_exp): Add
"struct parser_state" argument.
(type_exp, StringLiteral, Literal, PrimitiveType, IntegralType,
FloatingPointType, exp1, PrimaryNoNewArray, FieldAccess,
FuncStart, MethodInvocation, ArrayAccess, PostfixExpression,
PostIncrementExpression, PostDecrementExpression,
UnaryExpression, PreIncrementExpression, PreDecrementExpression,
UnaryExpressionNotPlusMinus, CastExpression,
MultiplicativeExpression, AdditiveExpression, ShiftExpression,
RelationalExpression, EqualityExpression, AndExpression,
ExclusiveOrExpression, InclusiveOrExpression,
ConditionalAndExpression, ConditionalOrExpression,
ConditionalExpression, Assignment, LeftHandSide): Update
calls to write_exp* and similars in order to use parser state.
(parse_number): Ajust code to use parser state.
(yylex): Likewise.
(java_parse): New function.
(push_variable): Add "struct parser_state" argument. Adjust
code to user parser state.
(push_fieldnames, push_qualified_expression_name,
push_expression_name, insert_exp): Likewise.
* jv-lang.h: Forward declare "struct parser_state".
(java_parse): Add "struct parser_state" argument.
* m2-exp.y (parse_type, parse_m2_type): Rewrite macros to use
parser state.
(yyparse): Redefine macro to m2_parse_internal.
(pstate): New variable.
(type_exp, exp, fblock, variable, type): Update calls to
write_exp* and similars to use parser state.
(yylex): Likewise.
(m2_parse): New function.
* m2-lang.h: Forward declare "struct parser_state".
(m2_parse): Add "struct parser_state" argument.
* objc-lang.c (end_msglist): Add "struct parser_state" argument.
* objc-lang.h: Forward declare "struct parser_state".
(end_msglist): Add "struct parser_state" argument.
* p-exp.y (parse_type): Rewrite macro to use parser state.
(yyparse): Redefine macro to pascal_parse_internal.
(pstate): New variable.
(parse_number): Add "struct parser_state" argument.
(type_exp, exp1, exp, qualified_name, variable): Update calls to
write_exp* and similars in order to use parser state.
(parse_number, yylex): Adjust code to use parser state.
(pascal_parse): New function.
* p-lang.h: Forward declare "struct parser_state".
(pascal_parse): Add "struct parser_state" argument.
* go-exp.y (parse_type): Rewrite macro to use parser state.
(yyparse): Redefine macro to go_parse_internal.
(pstate): New variable.
(parse_number): Add "struct parser_state" argument.
(type_exp, exp1, exp, variable, type): Update calls to
write_exp* and similars in order to use parser state.
(parse_number, lex_one_token, classify_name, yylex): Adjust code
to use parser state.
(go_parse): Likewise.
* go-lang.h: Forward declare "struct parser_state".
(go_parse): Add "struct parser_state" argument.
2014-03-28 06:10:40 +08:00
|
|
|
struct parser_state;
|
|
|
|
|
2012-04-25 22:07:23 +08:00
|
|
|
struct builtin_go_type
|
|
|
|
{
|
|
|
|
struct type *builtin_void;
|
|
|
|
struct type *builtin_char;
|
|
|
|
struct type *builtin_bool;
|
|
|
|
struct type *builtin_int;
|
|
|
|
struct type *builtin_uint;
|
|
|
|
struct type *builtin_uintptr;
|
|
|
|
struct type *builtin_int8;
|
|
|
|
struct type *builtin_int16;
|
|
|
|
struct type *builtin_int32;
|
|
|
|
struct type *builtin_int64;
|
|
|
|
struct type *builtin_uint8;
|
|
|
|
struct type *builtin_uint16;
|
|
|
|
struct type *builtin_uint32;
|
|
|
|
struct type *builtin_uint64;
|
|
|
|
struct type *builtin_float32;
|
|
|
|
struct type *builtin_float64;
|
|
|
|
struct type *builtin_complex64;
|
|
|
|
struct type *builtin_complex128;
|
|
|
|
};
|
|
|
|
|
|
|
|
enum go_type
|
|
|
|
{
|
|
|
|
GO_TYPE_NONE, /* Not a Go object. */
|
|
|
|
GO_TYPE_STRING
|
|
|
|
};
|
|
|
|
|
|
|
|
/* Defined in go-lang.c. */
|
|
|
|
|
|
|
|
extern const char *go_main_name (void);
|
|
|
|
|
|
|
|
extern enum go_type go_classify_struct_type (struct type *type);
|
|
|
|
|
|
|
|
extern char *go_symbol_package_name (const struct symbol *sym);
|
|
|
|
|
|
|
|
extern char *go_block_package_name (const struct block *block);
|
|
|
|
|
|
|
|
extern const struct builtin_go_type *builtin_go_type (struct gdbarch *);
|
|
|
|
|
2020-10-20 21:03:42 +08:00
|
|
|
/* Class representing the Go language. */
|
|
|
|
|
|
|
|
class go_language : public language_defn
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
go_language ()
|
|
|
|
: language_defn (language_go)
|
|
|
|
{ /* Nothing. */ }
|
|
|
|
|
|
|
|
/* See language.h. */
|
|
|
|
|
|
|
|
const char *name () const override
|
|
|
|
{ return "go"; }
|
|
|
|
|
|
|
|
/* See language.h. */
|
|
|
|
|
|
|
|
const char *natural_name () const override
|
|
|
|
{ return "Go"; }
|
|
|
|
|
|
|
|
/* See language.h. */
|
|
|
|
|
|
|
|
void language_arch_info (struct gdbarch *gdbarch,
|
|
|
|
struct language_arch_info *lai) const override;
|
|
|
|
|
|
|
|
/* See language.h. */
|
|
|
|
|
|
|
|
bool sniff_from_mangled_name (const char *mangled,
|
|
|
|
char **demangled) const override
|
|
|
|
{
|
|
|
|
*demangled = demangle_symbol (mangled, 0);
|
|
|
|
return *demangled != NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* See language.h. */
|
|
|
|
|
|
|
|
char *demangle_symbol (const char *mangled, int options) const override;
|
|
|
|
|
|
|
|
/* See language.h. */
|
2012-04-25 22:07:23 +08:00
|
|
|
|
2020-10-20 21:03:42 +08:00
|
|
|
void print_type (struct type *type, const char *varstring,
|
|
|
|
struct ui_file *stream, int show, int level,
|
|
|
|
const struct type_print_options *flags) const override;
|
2012-04-25 22:07:23 +08:00
|
|
|
|
2020-10-20 21:03:42 +08:00
|
|
|
/* See language.h. */
|
2020-03-14 07:39:52 +08:00
|
|
|
|
2020-10-20 21:03:42 +08:00
|
|
|
void value_print_inner
|
|
|
|
(struct value *val, struct ui_file *stream, int recurse,
|
|
|
|
const struct value_print_options *options) const override;
|
|
|
|
|
|
|
|
/* See language.h. */
|
|
|
|
|
|
|
|
int parser (struct parser_state *ps) const override;
|
|
|
|
|
|
|
|
/* See language.h. */
|
|
|
|
|
|
|
|
bool is_string_type_p (struct type *type) const override
|
|
|
|
{
|
|
|
|
type = check_typedef (type);
|
|
|
|
return (type->code () == TYPE_CODE_STRUCT
|
|
|
|
&& go_classify_struct_type (type) == GO_TYPE_STRING);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* See language.h. */
|
|
|
|
|
|
|
|
bool store_sym_names_in_linkage_form_p () const override
|
|
|
|
{ return true; }
|
|
|
|
};
|
2020-03-14 07:39:52 +08:00
|
|
|
|
2012-04-25 22:07:23 +08:00
|
|
|
#endif /* !defined (GO_LANG_H) */
|