From 73923d7eedc7ab52144308ef7e9c12cbe4341bca Mon Sep 17 00:00:00 2001 From: Tom Tromey Date: Sun, 24 Mar 2019 09:01:18 -0600 Subject: Turn parse_language into a method This changes parse_language into a method of parser_state. This patch was written by a script. gdb/ChangeLog 2019-04-04 Tom Tromey * rust-exp.y: Replace "parse_language" with method call. * p-exp.y: (yylex): Replace "parse_language" with method call. * m2-exp.y: (yylex): Replace "parse_language" with method call. * go-exp.y (classify_name): Replace "parse_language" with method call. * f-exp.y (yylex): Replace "parse_language" with method call. * d-exp.y (lex_one_token): Replace "parse_language" with method call. * c-exp.y: (lex_one_token, classify_name, yylex): Replace "parse_language" with method call. * ada-exp.y (find_primitive_type, type_char) (type_system_address): Replace "parse_language" with method call. --- gdb/ChangeLog | 18 +++++++++++ gdb/ada-exp.y | 6 ++-- gdb/c-exp.y | 92 +++++++++++++++++++++++++++---------------------------- gdb/d-exp.y | 2 +- gdb/f-exp.y | 4 +-- gdb/go-exp.y | 2 +- gdb/m2-exp.y | 4 +-- gdb/p-exp.y | 6 ++-- gdb/parser-defs.h | 9 ++++-- gdb/rust-exp.y | 4 +-- 10 files changed, 85 insertions(+), 62 deletions(-) diff --git a/gdb/ChangeLog b/gdb/ChangeLog index 7495f61..39bfff8 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,5 +1,23 @@ 2019-04-04 Tom Tromey + * rust-exp.y: Replace "parse_language" with method call. + * p-exp.y: + (yylex): Replace "parse_language" with method call. + * m2-exp.y: + (yylex): Replace "parse_language" with method call. + * go-exp.y (classify_name): Replace "parse_language" with method + call. + * f-exp.y (yylex): Replace "parse_language" with method call. + * d-exp.y (lex_one_token): Replace "parse_language" with method + call. + * c-exp.y: + (lex_one_token, classify_name, yylex): Replace "parse_language" + with method call. + * ada-exp.y (find_primitive_type, type_char) + (type_system_address): Replace "parse_language" with method call. + +2019-04-04 Tom Tromey + * rust-exp.y: Replace "parse_gdbarch" with method call. * parse.c (write_dollar_variable, insert_type_address_space): Replace "parse_gdbarch" with method call. diff --git a/gdb/ada-exp.y b/gdb/ada-exp.y index 74dab76..f1c587a 100644 --- a/gdb/ada-exp.y +++ b/gdb/ada-exp.y @@ -1027,7 +1027,7 @@ 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), + type = language_lookup_primitive_type (par_state->language (), par_state->gdbarch (), name); if (type == NULL && strcmp ("system__address", name) == 0) @@ -1442,7 +1442,7 @@ type_long_double (struct parser_state *par_state) static struct type * type_char (struct parser_state *par_state) { - return language_string_char_type (parse_language (par_state), + return language_string_char_type (par_state->language (), par_state->gdbarch ()); } @@ -1456,7 +1456,7 @@ static struct type * type_system_address (struct parser_state *par_state) { struct type *type - = language_lookup_primitive_type (parse_language (par_state), + = language_lookup_primitive_type (par_state->language (), par_state->gdbarch (), "system__address"); return type != NULL ? type : parse_type (par_state)->builtin_data_ptr; diff --git a/gdb/c-exp.y b/gdb/c-exp.y index b788519..34e80bf 100644 --- a/gdb/c-exp.y +++ b/gdb/c-exp.y @@ -815,7 +815,7 @@ exp : SIZEOF '(' type ')' %prec UNARY { struct type *type = $3; write_exp_elt_opcode (pstate, OP_LONG); write_exp_elt_type (pstate, lookup_signed_typename - (parse_language (pstate), + (pstate->language (), pstate->gdbarch (), "int")); type = check_typedef (type); @@ -1284,117 +1284,117 @@ typebase : TYPENAME { $$ = $1.type; } | INT_KEYWORD - { $$ = lookup_signed_typename (parse_language (pstate), + { $$ = lookup_signed_typename (pstate->language (), pstate->gdbarch (), "int"); } | LONG - { $$ = lookup_signed_typename (parse_language (pstate), + { $$ = lookup_signed_typename (pstate->language (), pstate->gdbarch (), "long"); } | SHORT - { $$ = lookup_signed_typename (parse_language (pstate), + { $$ = lookup_signed_typename (pstate->language (), pstate->gdbarch (), "short"); } | LONG INT_KEYWORD - { $$ = lookup_signed_typename (parse_language (pstate), + { $$ = lookup_signed_typename (pstate->language (), pstate->gdbarch (), "long"); } | LONG SIGNED_KEYWORD INT_KEYWORD - { $$ = lookup_signed_typename (parse_language (pstate), + { $$ = lookup_signed_typename (pstate->language (), pstate->gdbarch (), "long"); } | LONG SIGNED_KEYWORD - { $$ = lookup_signed_typename (parse_language (pstate), + { $$ = lookup_signed_typename (pstate->language (), pstate->gdbarch (), "long"); } | SIGNED_KEYWORD LONG INT_KEYWORD - { $$ = lookup_signed_typename (parse_language (pstate), + { $$ = lookup_signed_typename (pstate->language (), pstate->gdbarch (), "long"); } | UNSIGNED LONG INT_KEYWORD - { $$ = lookup_unsigned_typename (parse_language (pstate), + { $$ = lookup_unsigned_typename (pstate->language (), pstate->gdbarch (), "long"); } | LONG UNSIGNED INT_KEYWORD - { $$ = lookup_unsigned_typename (parse_language (pstate), + { $$ = lookup_unsigned_typename (pstate->language (), pstate->gdbarch (), "long"); } | LONG UNSIGNED - { $$ = lookup_unsigned_typename (parse_language (pstate), + { $$ = lookup_unsigned_typename (pstate->language (), pstate->gdbarch (), "long"); } | LONG LONG - { $$ = lookup_signed_typename (parse_language (pstate), + { $$ = lookup_signed_typename (pstate->language (), pstate->gdbarch (), "long long"); } | LONG LONG INT_KEYWORD - { $$ = lookup_signed_typename (parse_language (pstate), + { $$ = lookup_signed_typename (pstate->language (), pstate->gdbarch (), "long long"); } | LONG LONG SIGNED_KEYWORD INT_KEYWORD - { $$ = lookup_signed_typename (parse_language (pstate), + { $$ = lookup_signed_typename (pstate->language (), pstate->gdbarch (), "long long"); } | LONG LONG SIGNED_KEYWORD - { $$ = lookup_signed_typename (parse_language (pstate), + { $$ = lookup_signed_typename (pstate->language (), pstate->gdbarch (), "long long"); } | SIGNED_KEYWORD LONG LONG - { $$ = lookup_signed_typename (parse_language (pstate), + { $$ = lookup_signed_typename (pstate->language (), pstate->gdbarch (), "long long"); } | SIGNED_KEYWORD LONG LONG INT_KEYWORD - { $$ = lookup_signed_typename (parse_language (pstate), + { $$ = lookup_signed_typename (pstate->language (), pstate->gdbarch (), "long long"); } | UNSIGNED LONG LONG - { $$ = lookup_unsigned_typename (parse_language (pstate), + { $$ = lookup_unsigned_typename (pstate->language (), pstate->gdbarch (), "long long"); } | UNSIGNED LONG LONG INT_KEYWORD - { $$ = lookup_unsigned_typename (parse_language (pstate), + { $$ = lookup_unsigned_typename (pstate->language (), pstate->gdbarch (), "long long"); } | LONG LONG UNSIGNED - { $$ = lookup_unsigned_typename (parse_language (pstate), + { $$ = lookup_unsigned_typename (pstate->language (), pstate->gdbarch (), "long long"); } | LONG LONG UNSIGNED INT_KEYWORD - { $$ = lookup_unsigned_typename (parse_language (pstate), + { $$ = lookup_unsigned_typename (pstate->language (), pstate->gdbarch (), "long long"); } | SHORT INT_KEYWORD - { $$ = lookup_signed_typename (parse_language (pstate), + { $$ = lookup_signed_typename (pstate->language (), pstate->gdbarch (), "short"); } | SHORT SIGNED_KEYWORD INT_KEYWORD - { $$ = lookup_signed_typename (parse_language (pstate), + { $$ = lookup_signed_typename (pstate->language (), pstate->gdbarch (), "short"); } | SHORT SIGNED_KEYWORD - { $$ = lookup_signed_typename (parse_language (pstate), + { $$ = lookup_signed_typename (pstate->language (), pstate->gdbarch (), "short"); } | UNSIGNED SHORT INT_KEYWORD - { $$ = lookup_unsigned_typename (parse_language (pstate), + { $$ = lookup_unsigned_typename (pstate->language (), pstate->gdbarch (), "short"); } | SHORT UNSIGNED - { $$ = lookup_unsigned_typename (parse_language (pstate), + { $$ = lookup_unsigned_typename (pstate->language (), pstate->gdbarch (), "short"); } | SHORT UNSIGNED INT_KEYWORD - { $$ = lookup_unsigned_typename (parse_language (pstate), + { $$ = lookup_unsigned_typename (pstate->language (), pstate->gdbarch (), "short"); } | DOUBLE_KEYWORD - { $$ = lookup_typename (parse_language (pstate), + { $$ = lookup_typename (pstate->language (), pstate->gdbarch (), "double", NULL, 0); } | LONG DOUBLE_KEYWORD - { $$ = lookup_typename (parse_language (pstate), + { $$ = lookup_typename (pstate->language (), pstate->gdbarch (), "long double", NULL, @@ -1456,19 +1456,19 @@ typebase $$ = NULL; } | UNSIGNED type_name - { $$ = lookup_unsigned_typename (parse_language (pstate), + { $$ = lookup_unsigned_typename (pstate->language (), pstate->gdbarch (), TYPE_NAME($2.type)); } | UNSIGNED - { $$ = lookup_unsigned_typename (parse_language (pstate), + { $$ = lookup_unsigned_typename (pstate->language (), pstate->gdbarch (), "int"); } | SIGNED_KEYWORD type_name - { $$ = lookup_signed_typename (parse_language (pstate), + { $$ = lookup_signed_typename (pstate->language (), pstate->gdbarch (), TYPE_NAME($2.type)); } | SIGNED_KEYWORD - { $$ = lookup_signed_typename (parse_language (pstate), + { $$ = lookup_signed_typename (pstate->language (), pstate->gdbarch (), "int"); } /* It appears that this rule for templates is never @@ -1489,7 +1489,7 @@ type_name: TYPENAME { $$.stoken.ptr = "int"; $$.stoken.length = 3; - $$.type = lookup_signed_typename (parse_language (pstate), + $$.type = lookup_signed_typename (pstate->language (), pstate->gdbarch (), "int"); } @@ -1497,7 +1497,7 @@ type_name: TYPENAME { $$.stoken.ptr = "long"; $$.stoken.length = 4; - $$.type = lookup_signed_typename (parse_language (pstate), + $$.type = lookup_signed_typename (pstate->language (), pstate->gdbarch (), "long"); } @@ -1505,7 +1505,7 @@ type_name: TYPENAME { $$.stoken.ptr = "short"; $$.stoken.length = 5; - $$.type = lookup_signed_typename (parse_language (pstate), + $$.type = lookup_signed_typename (pstate->language (), pstate->gdbarch (), "short"); } @@ -2555,7 +2555,7 @@ lex_one_token (struct parser_state *par_state, bool *is_quoted_name) if (strncmp (tokstart, tokentab3[i].oper, 3) == 0) { if ((tokentab3[i].flags & FLAG_CXX) != 0 - && parse_language (par_state)->la_language != language_cplus) + && par_state->language ()->la_language != language_cplus) break; lexptr += 3; @@ -2568,7 +2568,7 @@ lex_one_token (struct parser_state *par_state, bool *is_quoted_name) if (strncmp (tokstart, tokentab2[i].oper, 2) == 0) { if ((tokentab2[i].flags & FLAG_CXX) != 0 - && parse_language (par_state)->la_language != language_cplus) + && par_state->language ()->la_language != language_cplus) break; lexptr += 2; @@ -2612,7 +2612,7 @@ lex_one_token (struct parser_state *par_state, bool *is_quoted_name) case '(': paren_depth++; lexptr++; - if (parse_language (par_state)->la_language == language_objc + if (par_state->language ()->la_language == language_objc && c == '[') return OBJC_LBRAC; return c; @@ -2710,7 +2710,7 @@ lex_one_token (struct parser_state *par_state, bool *is_quoted_name) { const char *p = &tokstart[1]; - if (parse_language (par_state)->la_language == language_objc) + if (par_state->language ()->la_language == language_objc) { size_t len = strlen ("selector"); @@ -2862,7 +2862,7 @@ lex_one_token (struct parser_state *par_state, bool *is_quoted_name) if (strcmp (copy, ident_tokens[i].oper) == 0) { if ((ident_tokens[i].flags & FLAG_CXX) != 0 - && parse_language (par_state)->la_language != language_cplus) + && par_state->language ()->la_language != language_cplus) break; if ((ident_tokens[i].flags & FLAG_SHADOW) != 0) @@ -2871,7 +2871,7 @@ lex_one_token (struct parser_state *par_state, bool *is_quoted_name) if (lookup_symbol (copy, expression_context_block, VAR_DOMAIN, - (parse_language (par_state)->la_language + (par_state->language ()->la_language == language_cplus ? &is_a_field_of_this : NULL)).symbol != NULL) @@ -2940,7 +2940,7 @@ classify_name (struct parser_state *par_state, const struct block *block, memset (&is_a_field_of_this, 0, sizeof (is_a_field_of_this)); bsym = lookup_symbol (copy, block, VAR_DOMAIN, - parse_language (par_state)->la_name_of_this + par_state->language ()->la_name_of_this ? &is_a_field_of_this : NULL); if (bsym.symbol && SYMBOL_CLASS (bsym.symbol) == LOC_BLOCK) @@ -2999,7 +2999,7 @@ classify_name (struct parser_state *par_state, const struct block *block, } /* See if it's an ObjC classname. */ - if (parse_language (par_state)->la_language == language_objc && !bsym.symbol) + if (par_state->language ()->la_language == language_objc && !bsym.symbol) { CORE_ADDR Class = lookup_objc_class (par_state->gdbarch (), copy); if (Class) @@ -3038,7 +3038,7 @@ classify_name (struct parser_state *par_state, const struct block *block, yylval.ssym.is_a_field_of_this = is_a_field_of_this.type != NULL; if (bsym.symbol == NULL - && parse_language (par_state)->la_language == language_cplus + && par_state->language ()->la_language == language_cplus && is_a_field_of_this.type == NULL && lookup_minimal_symbol (copy, NULL, NULL).minsym == NULL) return UNKNOWN_CPP_NAME; @@ -3147,7 +3147,7 @@ yylex (void) if (current.token == NAME) current.token = classify_name (pstate, expression_context_block, is_quoted_name, last_lex_was_structop); - if (parse_language (pstate)->la_language != language_cplus + if (pstate->language ()->la_language != language_cplus || (current.token != TYPENAME && current.token != COLONCOLON && current.token != FILENAME)) return current.token; diff --git a/gdb/d-exp.y b/gdb/d-exp.y index 73d5cfc..50c8325 100644 --- a/gdb/d-exp.y +++ b/gdb/d-exp.y @@ -1288,7 +1288,7 @@ lex_one_token (struct parser_state *par_state) return DOLLAR_VARIABLE; yylval.tsym.type - = language_lookup_primitive_type (parse_language (par_state), + = language_lookup_primitive_type (par_state->language (), par_state->gdbarch (), copy); if (yylval.tsym.type != NULL) return TYPENAME; diff --git a/gdb/f-exp.y b/gdb/f-exp.y index 499de41..ca40778 100644 --- a/gdb/f-exp.y +++ b/gdb/f-exp.y @@ -1276,7 +1276,7 @@ yylex (void) result = lookup_symbol (tmp, expression_context_block, lookup_domains[i], - parse_language (pstate)->la_language + pstate->language ()->la_language == language_cplus ? &is_a_field_of_this : NULL); if (result.symbol && SYMBOL_CLASS (result.symbol) == LOC_TYPEDEF) @@ -1290,7 +1290,7 @@ yylex (void) } yylval.tsym.type - = language_lookup_primitive_type (parse_language (pstate), + = language_lookup_primitive_type (pstate->language (), pstate->gdbarch (), tmp); if (yylval.tsym.type != NULL) return TYPENAME; diff --git a/gdb/go-exp.y b/gdb/go-exp.y index 35f480a..3f564cf 100644 --- a/gdb/go-exp.y +++ b/gdb/go-exp.y @@ -1400,7 +1400,7 @@ classify_name (struct parser_state *par_state, const struct block *block) copy = copy_name (yylval.sval); /* Try primitive types first so they win over bad/weird debug info. */ - type = language_lookup_primitive_type (parse_language (par_state), + type = language_lookup_primitive_type (par_state->language (), par_state->gdbarch (), copy); if (type != NULL) diff --git a/gdb/m2-exp.y b/gdb/m2-exp.y index c78e03f..611981f 100644 --- a/gdb/m2-exp.y +++ b/gdb/m2-exp.y @@ -596,7 +596,7 @@ variable: NAME type : TYPENAME - { $$ = lookup_typename (parse_language (pstate), + { $$ = lookup_typename (pstate->language (), pstate->gdbarch (), copy_name ($1), expression_context_block, 0); } @@ -968,7 +968,7 @@ yylex (void) sym = lookup_symbol (tmp, expression_context_block, VAR_DOMAIN, 0).symbol; if (sym && SYMBOL_CLASS (sym) == LOC_BLOCK) return BLOCKNAME; - if (lookup_typename (parse_language (pstate), pstate->gdbarch (), + if (lookup_typename (pstate->language (), pstate->gdbarch (), copy_name (yylval.sval), expression_context_block, 1)) return TYPENAME; diff --git a/gdb/p-exp.y b/gdb/p-exp.y index d4b3150..79b2979 100644 --- a/gdb/p-exp.y +++ b/gdb/p-exp.y @@ -591,7 +591,7 @@ exp : THIS write_exp_elt_opcode (pstate, OP_THIS); /* We need type of this. */ this_val - = value_of_this_silent (parse_language (pstate)); + = value_of_this_silent (pstate->language ()); if (this_val) this_type = value_type (this_val); else @@ -731,7 +731,7 @@ variable: name_not_typename write_exp_elt_opcode (pstate, STRUCTOP_PTR); /* We need type of this. */ this_val - = value_of_this_silent (parse_language (pstate)); + = value_of_this_silent (pstate->language ()); if (this_val) this_type = value_type (this_val); else @@ -1675,7 +1675,7 @@ yylex (void) return TYPENAME; } yylval.tsym.type - = language_lookup_primitive_type (parse_language (pstate), + = language_lookup_primitive_type (pstate->language (), pstate->gdbarch (), tmp); if (yylval.tsym.type != NULL) { diff --git a/gdb/parser-defs.h b/gdb/parser-defs.h index 1aa5f1f..8fcbca3 100644 --- a/gdb/parser-defs.h +++ b/gdb/parser-defs.h @@ -32,8 +32,6 @@ struct internalvar; extern int parser_debug; -#define parse_language(ps) ((ps)->expout->language_defn) - struct parser_state { /* Constructor. LANG is the language used to parse the expression. @@ -55,6 +53,13 @@ struct parser_state return expout->gdbarch; } + /* Return the language that was passed to the constructor. */ + + const struct language_defn *language () + { + return expout->language_defn; + } + /* The size of the expression above. */ size_t expout_size; diff --git a/gdb/rust-exp.y b/gdb/rust-exp.y index 60eb617..9b6ca19 100644 --- a/gdb/rust-exp.y +++ b/gdb/rust-exp.y @@ -205,7 +205,7 @@ struct rust_parser /* Return the parser's language. */ const struct language_defn *language () const { - return parse_language (pstate); + return pstate->language (); } /* Return the parser's gdbarch. */ @@ -2280,7 +2280,7 @@ rust_parser::convert_ast_to_expression (const struct rust_op *operation, { struct type *type; - type = language_lookup_primitive_type (parse_language (pstate), + type = language_lookup_primitive_type (pstate->language (), pstate->gdbarch (), "()"); -- cgit v1.1