From patchwork Mon Feb 5 19:26:22 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Lance Taylor X-Patchwork-Id: 196998 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:168b:b0:106:860b:bbdd with SMTP id ma11csp1095558dyb; Mon, 5 Feb 2024 11:27:23 -0800 (PST) X-Google-Smtp-Source: AGHT+IFUB8z9CFSUMngxh/KU3ag7BqPMuqAvFUbbDLgkyW6yp5YD5UwCUnMx1OR2YL0CKdUy6r3M X-Received: by 2002:a05:620a:562f:b0:785:6462:449b with SMTP id vv15-20020a05620a562f00b007856462449bmr1147426qkn.22.1707161243016; Mon, 05 Feb 2024 11:27:23 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707161242; cv=pass; d=google.com; s=arc-20160816; b=C5V1Ye6OSMhx3fV2QRpTj6QHVoS6i9mSx6ifIqmeebeEjIBN5Gly8sWn8iDhvSO8i5 u9yFWqb6Qyuh0TS3bivws+9i9hFhBN3iCm7OOdAzk45nFSjpXWNpi7fRhlR0REYyn2WJ x+/7BxbJW4pnn7y5qQCkvrJ5/j3T1CRq9m2H3MQFW/Z3jvXbiwfgDXqMivLhQbyNtS6C oxz3DXa4LLNm97A29PBfUWJwm6OAUK+gJH8HdIKSC2EPyo1CCAHa3IDb22paiPWhv2sJ d/5pCzAxlqX9vTq/PHBZLr0Hv1lAA4ioU+EIwpY+vzXx5Ah0F/pw1UjZ7boRPFQ8l4lN kDow== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:to:subject:message-id:date:from :mime-version:dkim-signature:arc-filter:dmarc-filter:delivered-to; bh=OLQx9ZIb+dCuFzq4SaiR/OSYb2a63rQXtWxhY/ZgbT0=; fh=cFp8IqhAiGxPmkWdZw/+Znkt4k/hBDQf9GRyyOqZaDM=; b=fVU0JCxKI754ifXeDvrC/OPGT5Q9II36Z6zBLn9+vNuzbLzakafuTiXe/x92EsKB8x 95wZnrpBEd5H8VCGCfmWkidP48VvWulGqlcfqH3bK0aoqG/XZumpsEKXaepQNT42b3bg FXx/9m4xSL3APE03XNeMIN6jn8lwg78MnIUfGinc8lWMLTYCjN64zIM2/hFySpB4lY27 Jc4wp/Q13hBhEPGMbyRvp7vMcJvPhb9jLPnrE1rqMsVUJv9BPEml+pDStyTfVMq9z47a RkslpCHjYNFGHEfZPMGdr0tVxKNMj/sHKCUnOc/ZCMEYeFXBRfgGQgXijHHnKFdPDqoq gPzQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@golang-org.20230601.gappssmtp.com header.s=20230601 header.b=wDYARLtb; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=golang.org X-Forwarded-Encrypted: i=1; AJvYcCVkVe4byNMQQeT7Sd/9U5AWk4GVi9PvX22GS8MkBkXXzBAMVgZGL5zlaAoZAzAbkxX+5reN9zI22efGrFXrPsVWhErKig== Received: from server2.sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id x22-20020ae9f816000000b0078564385ca1si492300qkh.727.2024.02.05.11.27.22 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 05 Feb 2024 11:27:22 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@golang-org.20230601.gappssmtp.com header.s=20230601 header.b=wDYARLtb; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=golang.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id A5D12385771F for ; Mon, 5 Feb 2024 19:27:22 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-yw1-x112f.google.com (mail-yw1-x112f.google.com [IPv6:2607:f8b0:4864:20::112f]) by sourceware.org (Postfix) with ESMTPS id 6FDB73858C29 for ; Mon, 5 Feb 2024 19:26:35 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 6FDB73858C29 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=golang.org Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=golang.org ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 6FDB73858C29 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::112f ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1707161198; cv=none; b=iSNjUVFI3q24wgUYFRZ1OkMV+2B/WB4weIo50/SXqxeWB3zWk7ejoJoeW5mobvM/DZD89w1kaLOCBa9nRANLSW2+YW1qlZwdCpYahiWeVeTEQDMCC8EREPXkahyvqRHexsdRqb18ymsKwcPfN74Hn09egzQQzO/5dAU5rp41OPM= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1707161198; c=relaxed/simple; bh=XwwJlXOy3emkYPXAZGx5ECwlLbLG6laGBgCVJ+H1GOU=; h=DKIM-Signature:MIME-Version:From:Date:Message-ID:Subject:To; b=MD9hUJiEAKE073Ew0TpcxtT+CN+d+OUInZpAyz429ZYkH9pvbNMHU5tD4J3qPhAYTCLVT8LTD4zgF1EEI9nb8lCDOpxWBNQkXmaiJwkYDrMtdrzhKPdXp/QaGf5mq+wRJqmU3wXLiC5ksZK2/BlSQcRH+9Q+Fri96KDJ+5x+nnE= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-yw1-x112f.google.com with SMTP id 00721157ae682-60442a4132fso15151367b3.1 for ; Mon, 05 Feb 2024 11:26:35 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=golang-org.20230601.gappssmtp.com; s=20230601; t=1707161194; x=1707765994; darn=gcc.gnu.org; h=to:subject:message-id:date:from:mime-version:from:to:cc:subject :date:message-id:reply-to; bh=OLQx9ZIb+dCuFzq4SaiR/OSYb2a63rQXtWxhY/ZgbT0=; b=wDYARLtbNPs0uN5f7EaMwlWbtZzlHKru7TaV/mdC1OzXGx5ArVFVs7tM5MH6SySKmK BuTa4Cw+2MokqYlyYZNaJtlyf6KPmLS4NP+o6t9zIXqOBrt3WWv4txbzDqUsPK2JDX7S NzxPAlMAJ4XHJooyk0sKD1zI59wLek14NsTatNsQyZRI2wl1T7w+Y54y0DfQH8vROQaI xEB/YfBg2rNCBUZEPi8bUutI7l4neUQHTOqDZ49ED4W8W46tw4nhZY2JgaKNNJEQm3xM cl6g1vdAw9TivjgRx8JRXGvScQk5bDCu2wjZV9u5juv2llYXOgoL1rj9MiYabowSohiJ ZMxw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707161194; x=1707765994; h=to:subject:message-id:date:from:mime-version:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=OLQx9ZIb+dCuFzq4SaiR/OSYb2a63rQXtWxhY/ZgbT0=; b=o3YuI+4pbc2hGwsNfC8gclLXDZh6APS2Hacjc2WyUkTm8cv2PZHMou0vD50+ScW6G2 SxM8/Rye7bQgailS7/Szru7L1WZmPCqkqbf8EOBFuGsOKXj4Wfc1vNajEINEIcmFL5EO eTM4wYanEYxHNvO589SQAhmc91xHcwfPEQroh4633CWJkoDTIyIt7Xl84/NMpliPfyqT AenHeuGVh1tScJxXVAbNBH8iyRlcM6XnvIUeUbRD5SqpHqa8LCERZnV3/OZDIYiS7Xdp yOuGRmT3o78aRyz6JEYmsrMVhDohjxRVwCNuJA03iFwICfXV/ktcEDb+nMKlgIKMi8oQ mD1g== X-Gm-Message-State: AOJu0YyIQjE6OV1VQEL2LmES32ZvVAYQrW3GUU73QB2WI5C+iaTXcr9s +yvkBOePxVNAWSz4NxZZYKuE4W2l5i4bS2flZv6Qx2PTfy/0LJb0gUrX94prmydxdlu0JENRM7i crxFu6VoD00sqsBHuCa2OLco39yP98350RltdWljOxLsDsOJ2XNo= X-Received: by 2002:a81:ae0f:0:b0:5ff:abb3:6632 with SMTP id m15-20020a81ae0f000000b005ffabb36632mr565114ywh.26.1707161194304; Mon, 05 Feb 2024 11:26:34 -0800 (PST) MIME-Version: 1.0 From: Ian Lance Taylor Date: Mon, 5 Feb 2024 11:26:22 -0800 Message-ID: Subject: Go frontend patch committed: print types in a more readable way To: gcc-patches , gofrontend-dev X-Spam-Status: No, score=-9.4 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790088307159624359 X-GMAIL-MSGID: 1790088307159624359 This patch to the Go frontend adds Type::message_name to print types in ways that makes sense to users. As we move toward generics, the error messages need to be able to refer to types in a readable manner. Today we use this new feature in AST dumps. Bootstrapped and ran Go testsuite on x86_64-pc-linux-gnu. Committed to mainline. Ian 3818237cd5111fdd089f9c9470d384eebbe6ee1e diff --git a/gcc/go/gofrontend/MERGE b/gcc/go/gofrontend/MERGE index 429904a2b8f..ec7e2ab1acf 100644 --- a/gcc/go/gofrontend/MERGE +++ b/gcc/go/gofrontend/MERGE @@ -1,4 +1,4 @@ -8c056e335cecec67d1d223a329b7ba4dac778a65 +1cb83a415e86ab4de0d436d277377d8fc060cb61 The first line of this file holds the git revision number of the last merge done from the gofrontend repository. diff --git a/gcc/go/gofrontend/ast-dump.cc b/gcc/go/gofrontend/ast-dump.cc index eca0bf1fad2..12f49e68700 100644 --- a/gcc/go/gofrontend/ast-dump.cc +++ b/gcc/go/gofrontend/ast-dump.cc @@ -223,14 +223,7 @@ Ast_dump_context::dump_type(const Type* t) if (t == NULL) this->ostream() << "(nil type)"; else - // FIXME: write a type pretty printer instead of - // using mangled names. - if (this->gogo_ != NULL) - { - Backend_name bname; - t->backend_name(this->gogo_, &bname); - this->ostream() << "(" << bname.name() << ")"; - } + this->ostream() << "(" << t->message_name() << ")"; } // Dump a textual representation of a block to the diff --git a/gcc/go/gofrontend/types.cc b/gcc/go/gofrontend/types.cc index b349ad10d6f..a39cfbf7679 100644 --- a/gcc/go/gofrontend/types.cc +++ b/gcc/go/gofrontend/types.cc @@ -270,6 +270,16 @@ Type::set_is_error() this->classification_ = TYPE_ERROR; } +// Return a string version of this type to use in an error message. + +std::string +Type::message_name() const +{ + std::string ret; + this->do_message_name(&ret); + return ret; +} + // If this is a pointer type, return the type to which it points. // Otherwise, return NULL. @@ -742,16 +752,14 @@ Type::are_assignable(const Type* lhs, const Type* rhs, std::string* reason) { if (rhs->interface_type() != NULL) reason->assign(_("need explicit conversion")); - else if (lhs_orig->named_type() != NULL - && rhs_orig->named_type() != NULL) + else { - size_t len = (lhs_orig->named_type()->name().length() - + rhs_orig->named_type()->name().length() - + 100); + const std::string& lhs_name(lhs_orig->message_name()); + const std::string& rhs_name(rhs_orig->message_name()); + size_t len = lhs_name.length() + rhs_name.length() + 100; char* buf = new char[len]; snprintf(buf, len, _("cannot use type %s as type %s"), - rhs_orig->named_type()->message_name().c_str(), - lhs_orig->named_type()->message_name().c_str()); + rhs_name.c_str(), lhs_name.c_str()); reason->assign(buf); delete[] buf; } @@ -4244,6 +4252,33 @@ Integer_type::is_identical(const Integer_type* t) const return this->is_abstract_ == t->is_abstract_; } +// Message name. + +void +Integer_type::do_message_name(std::string* ret) const +{ + ret->append("is_byte_) + ret->append("byte"); + else if (this->is_rune_) + ret->append("rune"); + else + { + if (this->is_unsigned_) + ret->push_back('u'); + if (this->is_abstract_) + ret->append("int"); + else + { + ret->append("int"); + char buf[10]; + snprintf(buf, sizeof buf, "%d", this->bits_); + ret->append(buf); + } + } + ret->push_back('>'); +} + // Hash code. unsigned int @@ -4382,6 +4417,21 @@ Float_type::is_identical(const Float_type* t) const return this->is_abstract_ == t->is_abstract_; } +// Message name. + +void +Float_type::do_message_name(std::string* ret) const +{ + ret->append("is_abstract_) + { + char buf[10]; + snprintf(buf, sizeof buf, "%d", this->bits_); + ret->append(buf); + } + ret->push_back('>'); +} + // Hash code. unsigned int @@ -4496,6 +4546,21 @@ Complex_type::is_identical(const Complex_type *t) const return this->is_abstract_ == t->is_abstract_; } +// Message name. + +void +Complex_type::do_message_name(std::string* ret) const +{ + ret->append("is_abstract_) + { + char buf[10]; + snprintf(buf, sizeof buf, "%d", this->bits_); + ret->append(buf); + } + ret->push_back('>'); +} + // Hash code. unsigned int @@ -4661,6 +4726,10 @@ class Sink_type : public Type { } protected: + void + do_message_name(std::string* ret) const + { ret->append(""); } + bool do_compare_is_identity(Gogo*) { return false; } @@ -4696,6 +4765,70 @@ Type::make_sink_type() // Class Function_type. +// Message name. + +void +Function_type::do_message_name(std::string* ret) const +{ + ret->append("func"); + if (this->receiver_ != NULL) + { + ret->append(" (receiver "); + this->append_message_name(this->receiver_->type(), ret); + ret->append(") "); + } + this->append_signature(ret); +} + +// Append just the signature to RET. + +void +Function_type::append_signature(std::string* ret) const +{ + ret->push_back('('); + if (this->parameters_ != NULL) + { + bool first = true; + for (Typed_identifier_list::const_iterator p = this->parameters_->begin(); + p != this->parameters_->end(); + ++p) + { + if (first) + first = false; + else + ret->append(", "); + this->append_message_name(p->type(), ret); + } + } + ret->push_back(')'); + + if (this->results_ != NULL) + { + if (this->results_->size() == 1) + { + ret->push_back(' '); + this->append_message_name(this->results_->front().type(), ret); + } + else + { + ret->append(" ("); + bool first = true; + for (Typed_identifier_list::const_iterator p = + this->results_->begin(); + p != this->results_->end(); + ++p) + { + if (first) + first = false; + else + ret->append(", "); + this->append_message_name(p->type(), ret); + } + ret->push_back(')'); + } + } +} + // Traversal. int @@ -5548,6 +5681,20 @@ Type::make_backend_function_type(Typed_identifier* receiver, // Class Pointer_type. +// Message name. + +void +Pointer_type::do_message_name(std::string* ret) const +{ + if (this->to_type_->is_void_type()) + ret->append("unsafe.Pointer"); + else + { + ret->push_back('*'); + this->append_message_name(this->to_type_, ret); + } +} + // Traversal. int @@ -5764,6 +5911,10 @@ class Call_multiple_result_type : public Type { } protected: + void + do_message_name(std::string* ret) const + { ret->append(""); } + bool do_has_pointer() const { return false; } @@ -5940,6 +6091,41 @@ Struct_type::Identical_structs Struct_type::identical_structs; Struct_type::Struct_method_tables Struct_type::struct_method_tables; +// Message name. + +void +Struct_type::do_message_name(std::string* ret) const +{ + if (this->fields_ == NULL || this->fields_->empty()) + { + ret->append("struct{}"); + return; + } + + ret->append("struct {"); + + bool first = true; + for (Struct_field_list::const_iterator p = this->fields_->begin(); + p != this->fields_->end(); + ++p) + { + if (first) + first = false; + else + ret->append("; "); + + if (!p->is_anonymous()) + { + ret->append(p->field_name()); + ret->push_back(' '); + } + + this->append_message_name(p->type(), ret); + } + + ret->append(" }"); +} + // Traversal. int @@ -7344,6 +7530,35 @@ Array_type::is_identical(const Array_type* t, int flags) const return false; } +// Message name. + +void +Array_type::do_message_name(std::string* ret) const +{ + ret->push_back('['); + if (!this->is_slice_type()) + { + Numeric_constant nc; + if (!this->length_->numeric_constant_value(&nc)) + ret->append(""); + else + { + mpz_t val; + if (!nc.to_int(&val)) + ret->append(""); + else + { + char* s = mpz_get_str(NULL, 10, val); + ret->append(s); + free(s); + mpz_clear(val); + } + } + } + ret->push_back(']'); + this->append_message_name(this->element_type_, ret); +} + // Traversal. int @@ -8249,6 +8464,17 @@ Map_type::backend_zero_value(Gogo* gogo) return zvar; } +// Message name. + +void +Map_type::do_message_name(std::string* ret) const +{ + ret->append("map["); + this->append_message_name(this->key_type_, ret); + ret->push_back(']'); + this->append_message_name(this->val_type_, ret); +} + // Traversal. int @@ -8803,6 +9029,20 @@ Type::make_map_type(Type* key_type, Type* val_type, Location location) // Class Channel_type. +// Message name. + +void +Channel_type::do_message_name(std::string* ret) const +{ + if (!this->may_send_) + ret->append("<-"); + ret->append("chan"); + if (!this->may_receive_) + ret->append("<-"); + ret->push_back(' '); + this->append_message_name(this->element_type_, ret); +} + // Verify. bool @@ -9053,6 +9293,45 @@ Interface_type::method_count() const return this->all_methods_ == NULL ? 0 : this->all_methods_->size(); } +// Message name. + +void +Interface_type::do_message_name(std::string* ret) const +{ + const Typed_identifier_list* methods = (this->methods_are_finalized_ + ? this->all_methods_ + : this->parse_methods_); + if (methods == NULL || methods->empty()) + { + ret->append("interface{}"); + return; + } + + ret->append("interface {"); + + bool first = true; + for (Typed_identifier_list::const_iterator p = methods->begin(); + p != methods->end(); + ++p) + { + if (first) + first = false; + else + ret->append("; "); + + if (!p->name().empty()) + ret->append(p->name()); + + Function_type* ft = p->type()->function_type(); + if (ft == NULL) + this->append_message_name(p->type(), ret); + else + ft->append_signature(ret); + } + + ret->append(" }"); +} + // Traversal. int @@ -10295,10 +10574,10 @@ Named_type::name() const // Return the name of the type to use in an error message. -std::string -Named_type::message_name() const +void +Named_type::do_message_name(std::string* ret) const { - return this->named_object_->message_name(); + ret->append(this->named_object_->message_name()); } // Return the base type for this type. We have to be careful about @@ -12819,6 +13098,17 @@ Forward_declaration_type::add_existing_method(Named_object* nom) no->type_declaration_value()->add_existing_method(nom); } +// Message name. + +void +Forward_declaration_type::do_message_name(std::string* ret) const +{ + if (this->is_defined()) + this->append_message_name(this->real_type(), ret); + else + ret->append(this->named_object_->message_name()); +} + // Traversal. int diff --git a/gcc/go/gofrontend/types.h b/gcc/go/gofrontend/types.h index 3dd32799d74..cbc7ce0aa0e 100644 --- a/gcc/go/gofrontend/types.h +++ b/gcc/go/gofrontend/types.h @@ -575,6 +575,10 @@ class Type static Named_type* make_builtin_named_type(const char* name, Type* type); + // Return a string version of this type to use in an error message. + std::string + message_name() const; + // Traverse a type. static int traverse(Type*, Traverse*); @@ -1095,6 +1099,10 @@ class Type // Functions implemented by the child class. + // Message name. + virtual void + do_message_name(std::string*) const = 0; + // Traverse the subtypes. virtual int do_traverse(Traverse*); @@ -1195,6 +1203,11 @@ class Type type_descriptor_constructor(Gogo*, int runtime_type_kind, Named_type*, const Methods*, bool only_value_methods); + // For the benefit of child class message name construction. + void + append_message_name(const Type* type, std::string* ret) const + { type->do_message_name(ret); } + // For the benefit of child class reflection string generation. void append_reflection(const Type* type, Gogo* gogo, std::string* ret) const @@ -1656,6 +1669,10 @@ class Error_type : public Type { } protected: + void + do_message_name(std::string* ret) const + { ret->append(""); } + bool do_compare_is_identity(Gogo*) { return false; } @@ -1683,6 +1700,10 @@ class Void_type : public Type { } protected: + void + do_message_name(std::string* ret) const + { ret->append("void"); } + bool do_compare_is_identity(Gogo*) { return false; } @@ -1712,6 +1733,10 @@ class Boolean_type : public Type { } protected: + void + do_message_name(std::string* ret) const + { ret->append(""); } + bool do_compare_is_identity(Gogo*) { return true; } @@ -1797,6 +1822,9 @@ class Integer_type : public Type { this->is_rune_ = true; } protected: + void + do_message_name(std::string* ret) const; + bool do_compare_is_identity(Gogo*) { return true; } @@ -1874,6 +1902,9 @@ class Float_type : public Type is_identical(const Float_type* t) const; protected: + void + do_message_name(std::string* ret) const; + bool do_compare_is_identity(Gogo*) { return false; } @@ -1952,6 +1983,9 @@ class Complex_type : public Type is_identical(const Complex_type* t) const; protected: + void + do_message_name(std::string*) const; + bool do_compare_is_identity(Gogo*) { return false; } @@ -2009,6 +2043,10 @@ class String_type : public Type { } protected: + void + do_message_name(std::string* ret) const + { ret->append(""); } + bool do_has_pointer() const { return true; } @@ -2166,7 +2204,14 @@ class Function_type : public Type is_backend_function_type() const { return false; } + // Append just the signature of the function type. + void + append_signature(std::string*) const; + protected: + void + do_message_name(std::string*) const; + int do_traverse(Traverse*); @@ -2293,6 +2338,9 @@ class Pointer_type : public Type make_pointer_type_descriptor_type(); protected: + void + do_message_name(std::string*) const; + int do_traverse(Traverse*); @@ -2346,6 +2394,10 @@ class Nil_type : public Type { } protected: + void + do_message_name(std::string* ret) const + { ret->append(""); } + bool do_compare_is_identity(Gogo*) { return false; } @@ -2671,6 +2723,9 @@ class Struct_type : public Type write_to_c_header(std::ostream&) const; protected: + void + do_message_name(std::string*) const; + int do_traverse(Traverse*); @@ -2851,6 +2906,9 @@ class Array_type : public Type write_equal_function(Gogo*, Named_object* function, Named_type*); protected: + void + do_message_name(std::string*) const; + int do_traverse(Traverse* traverse); @@ -2999,6 +3057,9 @@ class Map_type : public Type static const int bucket_size = 8; protected: + void + do_message_name(std::string*) const; + int do_traverse(Traverse*); @@ -3118,6 +3179,9 @@ class Channel_type : public Type select_case_type(); protected: + void + do_message_name(std::string*) const; + int do_traverse(Traverse* traverse) { return Type::traverse(this->element_type_, traverse); } @@ -3273,6 +3337,9 @@ class Interface_type : public Type { return this->methods_are_finalized_; } protected: + void + do_message_name(std::string*) const; + int do_traverse(Traverse*); @@ -3450,12 +3517,6 @@ class Named_type : public Type const std::string& name() const; - // Return the name of the type for an error message. The difference - // is that if the type is defined in a different package, this will - // return PACKAGE.NAME. - std::string - message_name() const; - // Return the underlying type. Type* real_type() @@ -3599,6 +3660,9 @@ class Named_type : public Type convert(Gogo*); protected: + void + do_message_name(std::string* ret) const; + int do_traverse(Traverse* traverse) { return Type::traverse(this->type_, traverse); } @@ -3758,6 +3822,9 @@ class Forward_declaration_type : public Type add_existing_method(Named_object*); protected: + void + do_message_name(std::string*) const; + int do_traverse(Traverse* traverse);