From patchwork Tue Apr 17 19:51:23 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 26766 Received: (qmail 74769 invoked by alias); 17 Apr 2018 19:51:33 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 74678 invoked by uid 89); 17 Apr 2018 19:51:33 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-24.9 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, SPF_HELO_PASS autolearn=ham version=3.3.2 spammy=Temporarily, stars, 1747 X-HELO: gateway32.websitewelcome.com Received: from gateway32.websitewelcome.com (HELO gateway32.websitewelcome.com) (192.185.145.101) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 17 Apr 2018 19:51:30 +0000 Received: from cm11.websitewelcome.com (cm11.websitewelcome.com [100.42.49.5]) by gateway32.websitewelcome.com (Postfix) with ESMTP id AC2DC425BEF for ; Tue, 17 Apr 2018 14:51:28 -0500 (CDT) Received: from box5379.bluehost.com ([162.241.216.53]) by cmsmtp with SMTP id 8WdUf3sNsA3CS8WdUfAzSn; Tue, 17 Apr 2018 14:51:28 -0500 X-Authority-Reason: nr=8 Received: from 97-122-176-117.hlrn.qwest.net ([97.122.176.117]:37488 helo=bapiya.Home) by box5379.bluehost.com with esmtpsa (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.89_1) (envelope-from ) id 1f8WdU-000KUt-Ce; Tue, 17 Apr 2018 14:51:28 -0500 From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [RFA 2/4] Thread language through c_type_print_args Date: Tue, 17 Apr 2018 13:51:23 -0600 Message-Id: <20180417195125.14200-3-tom@tromey.com> In-Reply-To: <20180417195125.14200-1-tom@tromey.com> References: <20180417195125.14200-1-tom@tromey.com> X-BWhitelist: no X-Source-L: No X-Exim-ID: 1f8WdU-000KUt-Ce X-Source-Sender: 97-122-176-117.hlrn.qwest.net (bapiya.Home) [97.122.176.117]:37488 X-Source-Auth: tom+tromey.com X-Email-Count: 8 X-Source-Cap: ZWx5bnJvYmk7ZWx5bnJvYmk7Ym94NTM3OS5ibHVlaG9zdC5jb20= X-Local-Domain: yes Currently dwarf2read.c will pass the CU's language to c_type_print_args -- but this doesn't affect all aspects of type printing, because some code in c-typeprint.c refers to current_language. This patch threads the language through more of the type printing code, adding an overload to c_type_print. Some uses of current_language remain, but now they are only in top-level functions. ChangeLog 2018-04-17 Tom Tromey * dwarf2read.c (dwarf2_compute_name): Pass CU's language to c_print_type. * c-typeprint.c (c_print_type_1): Add "language" parameter. (c_print_type): Update. (c_print_type): New overload. (c_type_print_varspec_prefix, c_type_print_args) (c_type_print_varspec_suffix, c_print_type_no_offsets) (c_type_print_base_struct_union, c_type_print_base_1) (cp_type_print_method_args): Add "language" parameter. (c_type_print_base): Update. * c-lang.h (c_print_type): Add new overload. --- gdb/ChangeLog | 14 +++++++ gdb/c-lang.h | 7 ++++ gdb/c-typeprint.c | 114 +++++++++++++++++++++++++++++++++++------------------- gdb/dwarf2read.c | 3 +- 4 files changed, 98 insertions(+), 40 deletions(-) diff --git a/gdb/c-lang.h b/gdb/c-lang.h index 18dedcc1fa..a250fb34a6 100644 --- a/gdb/c-lang.h +++ b/gdb/c-lang.h @@ -72,6 +72,13 @@ extern void c_print_type (struct type *, const char *, struct ui_file *, int, int, const struct type_print_options *); +/* Print a type but allow the precise language to be specified. */ + +extern void c_print_type (struct type *, const char *, + struct ui_file *, int, int, + enum language, + const struct type_print_options *); + extern void c_print_typedef (struct type *, struct symbol *, struct ui_file *); diff --git a/gdb/c-typeprint.c b/gdb/c-typeprint.c index e26687ba25..a53331aefc 100644 --- a/gdb/c-typeprint.c +++ b/gdb/c-typeprint.c @@ -52,11 +52,13 @@ enum access_specifier static void c_type_print_varspec_suffix (struct type *, struct ui_file *, int, int, int, + enum language, const struct type_print_options *); static void c_type_print_varspec_prefix (struct type *, struct ui_file *, int, int, int, + enum language, const struct type_print_options *, struct print_offset_data *); @@ -66,7 +68,7 @@ static void c_type_print_modifier (struct type *, int, int); static void c_type_print_base_1 (struct type *type, struct ui_file *stream, - int show, int level, + int show, int level, enum language language, const struct type_print_options *flags, struct print_offset_data *podata); @@ -108,6 +110,7 @@ c_print_type_1 (struct type *type, const char *varstring, struct ui_file *stream, int show, int level, + enum language language, const struct type_print_options *flags, struct print_offset_data *podata) { @@ -128,7 +131,7 @@ c_print_type_1 (struct type *type, } else { - c_type_print_base_1 (type, stream, show, level, flags, podata); + c_type_print_base_1 (type, stream, show, level, language, flags, podata); code = TYPE_CODE (type); if ((varstring != NULL && *varstring != '\0') /* Need a space if going to print stars or brackets; @@ -144,7 +147,7 @@ c_print_type_1 (struct type *type, fputs_filtered (" ", stream); need_post_space = (varstring != NULL && strcmp (varstring, "") != 0); c_type_print_varspec_prefix (type, stream, show, 0, need_post_space, - flags, podata); + language, flags, podata); } if (varstring != NULL) @@ -158,7 +161,7 @@ c_print_type_1 (struct type *type, demangled_args = strchr (varstring, '(') != NULL; c_type_print_varspec_suffix (type, stream, show, 0, demangled_args, - flags); + language, flags); } } } @@ -174,7 +177,25 @@ c_print_type (struct type *type, { struct print_offset_data podata; - c_print_type_1 (type, varstring, stream, show, level, flags, &podata); + c_print_type_1 (type, varstring, stream, show, level, + current_language->la_language, flags, &podata); +} + + +/* See c-lang.h. */ + +void +c_print_type (struct type *type, + const char *varstring, + struct ui_file *stream, + int show, int level, + enum language language, + const struct type_print_options *flags) +{ + struct print_offset_data podata; + + c_print_type_1 (type, varstring, stream, show, level, language, flags, + &podata); } /* Print a typedef using C syntax. TYPE is the underlying type. @@ -257,6 +278,7 @@ static void cp_type_print_method_args (struct type *mtype, const char *prefix, const char *varstring, int staticp, struct ui_file *stream, + enum language language, const struct type_print_options *flags) { struct field *args = TYPE_FIELDS (mtype); @@ -297,7 +319,7 @@ cp_type_print_method_args (struct type *mtype, const char *prefix, } else if (varargs) fprintf_filtered (stream, "..."); - else if (current_language->la_language == language_cplus) + else if (language == language_cplus) fprintf_filtered (stream, "void"); fprintf_filtered (stream, ")"); @@ -344,6 +366,7 @@ c_type_print_varspec_prefix (struct type *type, struct ui_file *stream, int show, int passed_a_ptr, int need_post_space, + enum language language, const struct type_print_options *flags, struct print_offset_data *podata) { @@ -361,40 +384,46 @@ c_type_print_varspec_prefix (struct type *type, { case TYPE_CODE_PTR: c_type_print_varspec_prefix (TYPE_TARGET_TYPE (type), - stream, show, 1, 1, flags, podata); + stream, show, 1, 1, language, flags, + podata); fprintf_filtered (stream, "*"); c_type_print_modifier (type, stream, 1, need_post_space); break; case TYPE_CODE_MEMBERPTR: c_type_print_varspec_prefix (TYPE_TARGET_TYPE (type), - stream, show, 0, 0, flags, podata); + stream, show, 0, 0, language, flags, + podata); name = type_name_no_tag (TYPE_SELF_TYPE (type)); if (name) print_name_maybe_canonical (name, flags, stream); else c_type_print_base_1 (TYPE_SELF_TYPE (type), - stream, -1, passed_a_ptr, flags, podata); + stream, -1, passed_a_ptr, language, flags, + podata); fprintf_filtered (stream, "::*"); break; case TYPE_CODE_METHODPTR: c_type_print_varspec_prefix (TYPE_TARGET_TYPE (type), - stream, show, 0, 0, flags, podata); + stream, show, 0, 0, language, flags, + podata); fprintf_filtered (stream, "("); name = type_name_no_tag (TYPE_SELF_TYPE (type)); if (name) print_name_maybe_canonical (name, flags, stream); else c_type_print_base_1 (TYPE_SELF_TYPE (type), - stream, -1, passed_a_ptr, flags, podata); + stream, -1, passed_a_ptr, language, flags, + podata); fprintf_filtered (stream, "::*"); break; case TYPE_CODE_REF: case TYPE_CODE_RVALUE_REF: c_type_print_varspec_prefix (TYPE_TARGET_TYPE (type), - stream, show, 1, 0, flags, podata); + stream, show, 1, 0, language, flags, + podata); fprintf_filtered (stream, TYPE_CODE(type) == TYPE_CODE_REF ? "&" : "&&"); c_type_print_modifier (type, stream, 1, need_post_space); break; @@ -402,22 +431,24 @@ c_type_print_varspec_prefix (struct type *type, case TYPE_CODE_METHOD: case TYPE_CODE_FUNC: c_type_print_varspec_prefix (TYPE_TARGET_TYPE (type), - stream, show, 0, 0, flags, podata); + stream, show, 0, 0, language, flags, + podata); if (passed_a_ptr) fprintf_filtered (stream, "("); break; case TYPE_CODE_ARRAY: c_type_print_varspec_prefix (TYPE_TARGET_TYPE (type), - stream, show, 0, 0, flags, podata); + stream, show, 0, 0, language, flags, + podata); if (passed_a_ptr) fprintf_filtered (stream, "("); break; case TYPE_CODE_TYPEDEF: c_type_print_varspec_prefix (TYPE_TARGET_TYPE (type), - stream, show, passed_a_ptr, 0, flags, - podata); + stream, show, passed_a_ptr, 0, + language, flags, podata); break; case TYPE_CODE_UNDEF: @@ -556,7 +587,7 @@ c_type_print_args (struct type *type, struct ui_file *stream, param_type = make_cv_type (0, 0, param_type, NULL); } - c_print_type (param_type, "", stream, -1, 0, flags); + c_print_type (param_type, "", stream, -1, 0, language, flags); printed_any = 1; } @@ -725,6 +756,7 @@ c_type_print_varspec_suffix (struct type *type, struct ui_file *stream, int show, int passed_a_ptr, int demangled_args, + enum language language, const struct type_print_options *flags) { if (type == 0) @@ -757,26 +789,26 @@ c_type_print_varspec_suffix (struct type *type, fprintf_filtered (stream, (is_vector ? ")))" : "]")); c_type_print_varspec_suffix (TYPE_TARGET_TYPE (type), stream, - show, 0, 0, flags); + show, 0, 0, language, flags); } break; case TYPE_CODE_MEMBERPTR: c_type_print_varspec_suffix (TYPE_TARGET_TYPE (type), stream, - show, 0, 0, flags); + show, 0, 0, language, flags); break; case TYPE_CODE_METHODPTR: fprintf_filtered (stream, ")"); c_type_print_varspec_suffix (TYPE_TARGET_TYPE (type), stream, - show, 0, 0, flags); + show, 0, 0, language, flags); break; case TYPE_CODE_PTR: case TYPE_CODE_REF: case TYPE_CODE_RVALUE_REF: c_type_print_varspec_suffix (TYPE_TARGET_TYPE (type), stream, - show, 1, 0, flags); + show, 1, 0, language, flags); break; case TYPE_CODE_METHOD: @@ -784,15 +816,14 @@ c_type_print_varspec_suffix (struct type *type, if (passed_a_ptr) fprintf_filtered (stream, ")"); if (!demangled_args) - c_type_print_args (type, stream, 0, current_language->la_language, - flags); + c_type_print_args (type, stream, 0, language, flags); c_type_print_varspec_suffix (TYPE_TARGET_TYPE (type), stream, - show, passed_a_ptr, 0, flags); + show, passed_a_ptr, 0, language, flags); break; case TYPE_CODE_TYPEDEF: c_type_print_varspec_suffix (TYPE_TARGET_TYPE (type), stream, - show, passed_a_ptr, 0, flags); + show, passed_a_ptr, 0, language, flags); break; case TYPE_CODE_UNDEF: @@ -1092,6 +1123,7 @@ c_print_type_no_offsets (struct type *type, const char *varstring, struct ui_file *stream, int show, int level, + enum language language, struct type_print_options *flags, struct print_offset_data *podata) { @@ -1100,7 +1132,8 @@ c_print_type_no_offsets (struct type *type, /* Temporarily disable print_offsets, because it would mess with indentation. */ flags->print_offsets = 0; - c_print_type_1 (type, varstring, stream, show, level, flags, podata); + c_print_type_1 (type, varstring, stream, show, level, language, flags, + podata); flags->print_offsets = old_po; } @@ -1110,6 +1143,7 @@ c_print_type_no_offsets (struct type *type, static void c_type_print_base_struct_union (struct type *type, struct ui_file *stream, int show, int level, + enum language language, const struct type_print_options *flags, struct print_offset_data *podata) { @@ -1290,7 +1324,7 @@ c_type_print_base_struct_union (struct type *type, struct ui_file *stream, c_print_type_1 (TYPE_FIELD_TYPE (type, i), TYPE_FIELD_NAME (type, i), stream, newshow, level + 4, - &local_flags, &local_podata); + language, &local_flags, &local_podata); if (!is_static && TYPE_FIELD_PACKED (type, i)) { @@ -1379,7 +1413,7 @@ c_type_print_base_struct_union (struct type *type, struct ui_file *stream, { c_print_type_no_offsets (TYPE_TARGET_TYPE (TYPE_FN_FIELD_TYPE (f, j)), - "", stream, -1, 0, &local_flags, podata); + "", stream, -1, 0, language, &local_flags, podata); fputs_filtered (" ", stream); } @@ -1411,7 +1445,8 @@ c_type_print_base_struct_union (struct type *type, struct ui_file *stream, "", method_name, staticp, - stream, &local_flags); + stream, language, + &local_flags); } else fprintf_filtered (stream, @@ -1465,7 +1500,7 @@ c_type_print_base_struct_union (struct type *type, struct ui_file *stream, flags); c_print_type_no_offsets (TYPE_NESTED_TYPES_FIELD_TYPE (type, i), "", stream, show, level + 4, - &semi_local_flags, podata); + language, &semi_local_flags, podata); fprintf_filtered (stream, ";\n"); } } @@ -1503,7 +1538,7 @@ c_type_print_base_struct_union (struct type *type, struct ui_file *stream, c_print_type_no_offsets (target, TYPE_TYPEDEF_FIELD_NAME (type, i), stream, show - 1, level + 4, - &semi_local_flags, podata); + language, &semi_local_flags, podata); fprintf_filtered (stream, ";\n"); } } @@ -1550,6 +1585,7 @@ c_type_print_base_struct_union (struct type *type, struct ui_file *stream, static void c_type_print_base_1 (struct type *type, struct ui_file *stream, int show, int level, + enum language language, const struct type_print_options *flags, struct print_offset_data *podata) { @@ -1597,7 +1633,7 @@ c_type_print_base_1 (struct type *type, struct ui_file *stream, type_print_unknown_return_type (stream); else c_type_print_base_1 (TYPE_TARGET_TYPE (type), - stream, show, level, flags, podata); + stream, show, level, language, flags, podata); break; case TYPE_CODE_ARRAY: case TYPE_CODE_PTR: @@ -1606,13 +1642,13 @@ c_type_print_base_1 (struct type *type, struct ui_file *stream, case TYPE_CODE_RVALUE_REF: case TYPE_CODE_METHODPTR: c_type_print_base_1 (TYPE_TARGET_TYPE (type), - stream, show, level, flags, podata); + stream, show, level, language, flags, podata); break; case TYPE_CODE_STRUCT: case TYPE_CODE_UNION: - c_type_print_base_struct_union (type, stream, show, level, flags, - podata); + c_type_print_base_struct_union (type, stream, show, level, + language, flags, podata); break; case TYPE_CODE_ENUM: @@ -1653,8 +1689,7 @@ c_type_print_base_1 (struct type *type, struct ui_file *stream, print too much than too little; but conversely not to print something egregiously outside the current language's syntax. */ - if (current_language->la_language == language_cplus - && TYPE_TARGET_TYPE (type) != NULL) + if (language == language_cplus && TYPE_TARGET_TYPE (type) != NULL) { struct type *underlying = check_typedef (TYPE_TARGET_TYPE (type)); @@ -1715,7 +1750,7 @@ c_type_print_base_1 (struct type *type, struct ui_file *stream, c_print_type_1 (TYPE_FIELD_TYPE (type, i), TYPE_FIELD_NAME (type, i), stream, show, level + 4, - &local_flags, podata); + language, &local_flags, podata); fprintf_filtered (stream, " @%s", plongest (TYPE_FIELD_BITPOS (type, i))); if (TYPE_FIELD_BITSIZE (type, i) > 1) @@ -1784,5 +1819,6 @@ c_type_print_base (struct type *type, struct ui_file *stream, { struct print_offset_data podata; - c_type_print_base_1 (type, stream, show, level, flags, &podata); + c_type_print_base_1 (type, stream, show, level, + current_language->la_language, flags, &podata); } diff --git a/gdb/dwarf2read.c b/gdb/dwarf2read.c index 9c9dcee058..8dbe12db02 100644 --- a/gdb/dwarf2read.c +++ b/gdb/dwarf2read.c @@ -10814,7 +10814,8 @@ dwarf2_compute_name (const char *name, if (child->tag == DW_TAG_template_type_param) { - c_print_type (type, "", &buf, -1, 0, &type_print_raw_options); + c_print_type (type, "", &buf, -1, 0, cu->language, + &type_print_raw_options); continue; }