2000-06-14 12:27:59 +00:00
|
|
|
/* Pascal language support definitions for GDB, the GNU debugger.
|
2005-01-29 00:52:02 +00:00
|
|
|
|
2023-01-01 16:49:04 +04:00
|
|
|
Copyright (C) 2000-2023 Free Software Foundation, Inc.
|
2000-06-14 12:27:59 +00: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
|
2007-08-23 18:08:50 +00:00
|
|
|
the Free Software Foundation; either version 3 of the License, or
|
2000-06-14 12:27:59 +00:00
|
|
|
(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
|
2007-08-23 18:08:50 +00:00
|
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
2000-06-14 12:27:59 +00:00
|
|
|
|
2019-01-27 12:51:36 -07:00
|
|
|
#ifndef P_LANG_H
|
|
|
|
#define P_LANG_H
|
|
|
|
|
2000-06-14 12:27:59 +00:00
|
|
|
/* This file is derived from c-lang.h */
|
|
|
|
|
|
|
|
struct value;
|
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-27 19:10:40 -03:00
|
|
|
struct parser_state;
|
2000-06-14 12:27:59 +00:00
|
|
|
|
2020-10-28 18:10:01 +00:00
|
|
|
/* Determines if type TYPE is a pascal string type. Returns a positive
|
|
|
|
value if the type is a known pascal string type. This function is used
|
|
|
|
by p-valprint.c code to allow better string display. If it is a pascal
|
|
|
|
string type, then it also sets info needed to get the length and the
|
|
|
|
data of the string length_pos, length_size and string_pos are given in
|
|
|
|
bytes. char_size gives the element size in bytes. FIXME: if the
|
|
|
|
position or the size of these fields are not multiple of TARGET_CHAR_BIT
|
|
|
|
then the results are wrong but this does not happen for Free Pascal nor
|
|
|
|
for GPC. */
|
|
|
|
|
|
|
|
extern int pascal_is_string_type (struct type *type,int *length_pos,
|
|
|
|
int *length_size, int *string_pos,
|
|
|
|
struct type **char_type,
|
|
|
|
const char **arrayname);
|
|
|
|
|
2007-10-09 06:59:27 +00:00
|
|
|
/* Defined in p-lang.c */
|
2020-10-28 18:10:01 +00:00
|
|
|
|
2007-10-09 06:59:27 +00:00
|
|
|
extern const char *pascal_main_name (void);
|
|
|
|
|
2020-10-28 18:10:01 +00:00
|
|
|
/* These are in p-lang.c: */
|
2000-06-14 12:27:59 +00:00
|
|
|
|
2020-10-28 18:10:01 +00:00
|
|
|
extern int is_pascal_string_type (struct type *, int *, int *, int *,
|
|
|
|
struct type **, const char **);
|
2000-06-14 12:27:59 +00:00
|
|
|
|
2020-10-28 18:10:01 +00:00
|
|
|
extern int pascal_object_is_vtbl_ptr_type (struct type *);
|
2008-09-27 21:29:30 +00:00
|
|
|
|
2020-10-28 18:10:01 +00:00
|
|
|
extern int pascal_object_is_vtbl_member (struct type *);
|
2020-03-13 17:39:52 -06:00
|
|
|
|
2020-10-28 18:10:01 +00:00
|
|
|
/* Class representing the Pascal language. */
|
2020-03-13 17:39:52 -06:00
|
|
|
|
2020-10-28 18:10:01 +00:00
|
|
|
class pascal_language : public language_defn
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
pascal_language ()
|
|
|
|
: language_defn (language_pascal)
|
|
|
|
{ /* Nothing. */ }
|
2000-06-14 12:27:59 +00:00
|
|
|
|
2020-10-28 18:10:01 +00:00
|
|
|
/* See language.h. */
|
2000-06-14 12:27:59 +00:00
|
|
|
|
2020-10-28 18:10:01 +00:00
|
|
|
const char *name () const override
|
|
|
|
{ return "pascal"; }
|
2000-06-14 12:27:59 +00:00
|
|
|
|
2020-10-28 18:10:01 +00:00
|
|
|
/* See language.h. */
|
2001-11-09 09:48:09 +00:00
|
|
|
|
2020-10-28 18:10:01 +00:00
|
|
|
const char *natural_name () const override
|
|
|
|
{ return "Pascal"; }
|
2000-06-14 12:27:59 +00:00
|
|
|
|
2020-10-28 18:10:01 +00:00
|
|
|
/* See language.h. */
|
2000-06-14 12:27:59 +00:00
|
|
|
|
2020-10-28 18:10:01 +00:00
|
|
|
const std::vector<const char *> &filename_extensions () const override
|
|
|
|
{
|
|
|
|
static const std::vector<const char *> extensions
|
|
|
|
= { ".pas", ".p", ".pp" };
|
|
|
|
return extensions;
|
|
|
|
}
|
2000-06-14 12:27:59 +00:00
|
|
|
|
2020-10-28 18:10:01 +00:00
|
|
|
/* See language.h. */
|
2000-06-14 12:27:59 +00:00
|
|
|
|
2020-10-28 18:10:01 +00:00
|
|
|
void language_arch_info (struct gdbarch *gdbarch,
|
|
|
|
struct language_arch_info *lai) const override;
|
2000-06-14 12:27:59 +00:00
|
|
|
|
2020-10-28 18:10:01 +00:00
|
|
|
/* See language.h. */
|
2000-06-14 12:27:59 +00:00
|
|
|
|
2020-10-28 18:10:01 +00: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;
|
|
|
|
|
|
|
|
/* See language.h. */
|
|
|
|
|
|
|
|
void value_print (struct value *val, struct ui_file *stream,
|
|
|
|
const struct value_print_options *options) const override;
|
|
|
|
|
|
|
|
/* See language.h. */
|
|
|
|
|
|
|
|
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. */
|
|
|
|
|
|
|
|
void emitchar (int ch, struct type *chtype,
|
|
|
|
struct ui_file *stream, int quoter) const override
|
|
|
|
{
|
|
|
|
int in_quotes = 0;
|
|
|
|
|
|
|
|
print_one_char (ch, stream, &in_quotes);
|
|
|
|
if (in_quotes)
|
2022-01-02 11:36:44 -07:00
|
|
|
gdb_puts ("'", stream);
|
2020-10-28 18:10:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* See language.h. */
|
|
|
|
|
|
|
|
void printchar (int ch, struct type *chtype,
|
|
|
|
struct ui_file *stream) const override;
|
|
|
|
|
|
|
|
/* See language.h. */
|
|
|
|
|
|
|
|
void printstr (struct ui_file *stream, struct type *elttype,
|
|
|
|
const gdb_byte *string, unsigned int length,
|
|
|
|
const char *encoding, int force_ellipses,
|
|
|
|
const struct value_print_options *options) const override;
|
|
|
|
|
|
|
|
/* See language.h. */
|
|
|
|
|
|
|
|
void print_typedef (struct type *type, struct symbol *new_symbol,
|
|
|
|
struct ui_file *stream) const override;
|
|
|
|
|
|
|
|
/* See language.h. */
|
|
|
|
|
|
|
|
bool is_string_type_p (struct type *type) const override
|
|
|
|
{
|
|
|
|
return pascal_is_string_type(type, nullptr, nullptr, nullptr,
|
|
|
|
nullptr, nullptr) > 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* See language.h. */
|
|
|
|
|
|
|
|
const char *name_of_this () const override
|
|
|
|
{ return "this"; }
|
|
|
|
|
|
|
|
/* See language.h. */
|
|
|
|
|
|
|
|
bool range_checking_on_by_default () const override
|
|
|
|
{ return true; }
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
|
|
|
/* Print the character C on STREAM as part of the contents of a literal
|
|
|
|
string. IN_QUOTES is reset to 0 if a char is written with #4 notation. */
|
|
|
|
|
|
|
|
void print_one_char (int c, struct ui_file *stream, int *in_quotes) const;
|
|
|
|
|
|
|
|
/* Print the name of the type (or the ultimate pointer target,
|
|
|
|
function value or array element), or the description of a
|
|
|
|
structure or union.
|
|
|
|
|
|
|
|
SHOW positive means print details about the type (e.g. enum values),
|
|
|
|
and print structure elements passing SHOW - 1 for show. SHOW negative
|
|
|
|
means just print the type name or struct tag if there is one. If
|
|
|
|
there is no name, print something sensible but concise like "struct
|
|
|
|
{...}".
|
|
|
|
SHOW zero means just print the type name or struct tag if there is one.
|
|
|
|
If there is no name, print something sensible but not as concise like
|
|
|
|
"struct {int x; int y;}".
|
|
|
|
|
|
|
|
LEVEL is the number of spaces to indent by.
|
|
|
|
We increase it for some recursive calls. */
|
|
|
|
|
|
|
|
void type_print_base (struct type *type, struct ui_file *stream, int show,
|
|
|
|
int level,
|
|
|
|
const struct type_print_options *flags) const;
|
|
|
|
|
|
|
|
|
|
|
|
/* Print any array sizes, function arguments or close parentheses
|
|
|
|
needed after the variable name (to describe its type).
|
|
|
|
Args work like pascal_type_print_varspec_prefix. */
|
|
|
|
|
|
|
|
void type_print_varspec_suffix (struct type *type, struct ui_file *stream,
|
|
|
|
int show, int passed_a_ptr,
|
|
|
|
int demangled_args,
|
|
|
|
const struct type_print_options *flags) const;
|
|
|
|
|
|
|
|
/* Helper for pascal_language::type_print_varspec_suffix to print the
|
|
|
|
suffix of a function or method. */
|
|
|
|
|
|
|
|
void type_print_func_varspec_suffix
|
|
|
|
(struct type *type, struct ui_file *stream, int show,
|
|
|
|
int passed_a_ptr, int demangled_args,
|
|
|
|
const struct type_print_options *flags) const;
|
|
|
|
|
|
|
|
/* Print any asterisks or open-parentheses needed before the
|
|
|
|
variable name (to describe its type).
|
|
|
|
|
|
|
|
On outermost call, pass 0 for PASSED_A_PTR.
|
|
|
|
On outermost call, SHOW > 0 means should ignore
|
|
|
|
any typename for TYPE and show its details.
|
|
|
|
SHOW is always zero on recursive calls. */
|
|
|
|
|
|
|
|
void type_print_varspec_prefix
|
|
|
|
(struct type *type, struct ui_file *stream, int show,
|
|
|
|
int passed_a_ptr, const struct type_print_options *flags) const;
|
|
|
|
|
|
|
|
/* Print the function args from TYPE (a TYPE_CODE_FUNC) to STREAM taking
|
|
|
|
FLAGS into account where appropriate. */
|
|
|
|
|
|
|
|
void print_func_args (struct type *type, struct ui_file *stream,
|
|
|
|
const struct type_print_options *flags) const;
|
|
|
|
|
|
|
|
/* Print the Pascal method arguments for PHYSNAME and METHODNAME to the
|
|
|
|
file STREAM. */
|
|
|
|
|
|
|
|
void type_print_method_args (const char *physname, const char *methodname,
|
|
|
|
struct ui_file *stream) const;
|
|
|
|
|
|
|
|
/* If TYPE is a derived type, then print out derivation information.
|
|
|
|
Print only the actual base classes of this type, not the base classes
|
|
|
|
of the base classes. I.e. for the derivation hierarchy:
|
|
|
|
|
|
|
|
class A { int a; };
|
|
|
|
class B : public A {int b; };
|
|
|
|
class C : public B {int c; };
|
|
|
|
|
|
|
|
Print the type of class C as:
|
|
|
|
|
|
|
|
class C : public B {
|
|
|
|
int c;
|
|
|
|
}
|
|
|
|
|
|
|
|
Not as the following (like gdb used to), which is not legal C++ syntax
|
|
|
|
for derived types and may be confused with the multiple inheritance
|
|
|
|
form:
|
|
|
|
|
|
|
|
class C : public B : public A {
|
|
|
|
int c;
|
|
|
|
}
|
|
|
|
|
|
|
|
In general, gdb should try to print the types as closely as possible
|
|
|
|
to the form that they appear in the source code. */
|
|
|
|
|
|
|
|
void type_print_derivation_info (struct ui_file *stream,
|
|
|
|
struct type *type) const;
|
|
|
|
};
|
2019-01-27 12:51:36 -07:00
|
|
|
|
|
|
|
#endif /* P_LANG_H */
|