From patchwork Wed Sep 22 09:26:09 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tristan Gingold X-Patchwork-Id: 65413 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) by ozlabs.org (Postfix) with SMTP id BE5DDB70A8 for ; Wed, 22 Sep 2010 19:26:26 +1000 (EST) Received: (qmail 23583 invoked by alias); 22 Sep 2010 09:26:24 -0000 Received: (qmail 23571 invoked by uid 22791); 22 Sep 2010 09:26:22 -0000 X-SWARE-Spam-Status: No, hits=-1.9 required=5.0 tests=AWL, BAYES_00, MIME_QP_LONG_LINE, TW_CP X-Spam-Check-By: sourceware.org Received: from mel.act-europe.fr (HELO mel.act-europe.fr) (212.99.106.210) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Wed, 22 Sep 2010 09:26:12 +0000 Received: from localhost (localhost [127.0.0.1]) by filtered-smtp.eu.adacore.com (Postfix) with ESMTP id 846E1CB0242; Wed, 22 Sep 2010 11:26:09 +0200 (CEST) Received: from mel.act-europe.fr ([127.0.0.1]) by localhost (smtp.eu.adacore.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id chvtUcp0Jp4w; Wed, 22 Sep 2010 11:26:09 +0200 (CEST) Received: from ulanbator.act-europe.fr (ulanbator.act-europe.fr [10.10.1.67]) (using TLSv1 with cipher AES128-SHA (128/128 bits)) (No client certificate requested) by mel.act-europe.fr (Postfix) with ESMTP id 6D5D4CB01E8; Wed, 22 Sep 2010 11:26:09 +0200 (CEST) Subject: Re: Ping [Patch] Improve ada demangler Mime-Version: 1.0 (Apple Message framework v1081) From: Tristan Gingold In-Reply-To: Date: Wed, 22 Sep 2010 11:26:09 +0200 Cc: GCC Patches Message-Id: <7173A6E0-1F50-4472-A6FF-7FEC05932A01@adacore.com> References: <20100907091214.GA27991@ulanbator.act-europe.fr> To: Ian Lance Taylor X-IsSubscribed: yes Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org On Sep 21, 2010, at 4:30 PM, Ian Lance Taylor wrote: > Tristan Gingold writes: > >>> libiberty: >>> 2010-09-07 Tristan Gingold >>> >>> * cplus-dem.c (ada_demangle): Add comments. >>> Handle stream and controlled type operations. >>> Decoding of some uppercase letters moved before separators. >>> * testsuite/demangle-expected: Add tests. > >>> + if (p[0] == 'S' && p[1] && (p[2] == '_' || p[2] == 0)) > > Write p[1] != 0 or p[1] != '\0'. > >>> + int l = strlen (special[k][0]); > > l is kind of a poor choice of variable name in this code which is > littered with 1's. Consider len. Also consider changing the type to > size_t. > >>> + if (!strncmp (p, special[k][0], l)) > > Write strncmp (p, special[k][0], l) != 0 rather than using ! (I know the > existing code used !). > >>> + if (special[k][0]) > > Write special[k][0] != 0 or special[k][0] != '\0'. > > > This is OK with those changes. Thank you for the review. I have committed the following patch, after a make check in libiberty and a compiler build. Tristan. =================================================================== --- cplus-dem.c (revision 164509) +++ cplus-dem.c (working copy) @@ -895,18 +895,20 @@ /* Most of the demangling will trivially remove chars. Operator names may add one char but because they are always preceeded by '__' which is - replaced by '.', they eventually never expand the size. '___elabs' and - '___elabb' add only 2 chars, but they occur only once. */ - len0 = strlen (mangled) + 2 + 1; + replaced by '.', they eventually never expand the size. + A few special names such as '___elabs' add a few chars (at most 7), but + they occur only once. */ + len0 = strlen (mangled) + 7 + 1; demangled = XNEWVEC (char, len0); d = demangled; p = mangled; while (1) { - /* Convert name, which is always lower-case. */ + /* An entity names is expected. */ if (ISLOWER (*p)) { + /* An identifier, which is always lower case. */ do *d++ = *p++; while (ISLOWER(*p) || ISDIGIT (*p) @@ -914,6 +916,7 @@ } else if (p[0] == 'O') { + /* An operator name. */ static const char * const operators[][2] = {{"Oabs", "abs"}, {"Oand", "and"}, {"Omod", "mod"}, {"Onot", "not"}, {"Oor", "or"}, {"Orem", "rem"}, @@ -924,22 +927,22 @@ {"Oexpon", "**"}, {NULL, NULL}}; int k; - for (k = 0; operators[k][0]; k++) + for (k = 0; operators[k][0] != NULL; k++) { - int l = strlen (operators[k][0]); - if (!strncmp (p, operators[k][0], l)) + size_t slen = strlen (operators[k][0]); + if (strncmp (p, operators[k][0], slen) == 0) { - p += l; - l = strlen (operators[k][1]); + p += slen; + slen = strlen (operators[k][1]); *d++ = '"'; - memcpy (d, operators[k][1], l); - d += l; + memcpy (d, operators[k][1], slen); + d += slen; *d++ = '"'; break; } } /* Operator not found. */ - if (!operators[k][0]) + if (operators[k][0] == NULL) goto unknown; } else @@ -948,6 +951,92 @@ goto unknown; } + /* The name can be directly followed by some uppercase letters. */ + if (p[0] == 'T' && p[1] == 'K') + { + /* Task stuff. */ + if (p[2] == 'B' && p[3] == 0) + { + /* Subprogram for task body. */ + break; + } + else if (p[2] == '_' && p[3] == '_') + { + /* Inner declarations in a task. */ + p += 4; + *d++ = '.'; + continue; + } + else + goto unknown; + } + if (p[0] == 'E' && p[1] == 0) + { + /* Exception name. */ + goto unknown; + } + if ((p[0] == 'P' || p[0] == 'N') && p[1] == 0) + { + /* Protected type subprogram. */ + break; + } + if ((*p == 'N' || *p == 'S') && p[1] == 0) + { + /* Enumerated type name table. */ + goto unknown; + } + if (p[0] == 'X') + { + /* Body nested. */ + p++; + while (p[0] == 'n' || p[0] == 'b') + p++; + } + if (p[0] == 'S' && p[1] != 0 && (p[2] == '_' || p[2] == 0)) + { + /* Stream operations. */ + const char *name; + switch (p[1]) + { + case 'R': + name = "'Read"; + break; + case 'W': + name = "'Write"; + break; + case 'I': + name = "'Input"; + break; + case 'O': + name = "'Output"; + break; + default: + goto unknown; + } + p += 2; + strcpy (d, name); + d += strlen (name); + } + else if (p[0] == 'D') + { + /* Controlled type operation. */ + const char *name; + switch (p[1]) + { + case 'F': + name = ".Finalize"; + break; + case 'A': + name = ".Adjust"; + break; + default: + goto unknown; + } + strcpy (d, name); + d += strlen (name); + break; + } + if (p[0] == '_') { /* Separator. */ @@ -955,25 +1044,50 @@ { /* Standard separator. Handled first. */ p += 2; + if (ISDIGIT (*p)) { - /* Overloading. */ + /* Overloading number. */ do p++; while (ISDIGIT (*p) || (p[0] == '_' && ISDIGIT (p[1]))); + if (*p == 'X') + { + p++; + while (p[0] == 'n' || p[0] == 'b') + p++; + } } - else if (*p == '_' && !strcmp (p + 1, "elabb")) + else if (p[0] == '_' && p[1] != '_') { - memcpy (d, "'Elab_Body", 10); - d += 10; - break; + /* Special names. */ + static const char * const special[][2] = { + { "_elabb", "'Elab_Body" }, + { "_elabs", "'Elab_Spec" }, + { "_size", "'Size" }, + { "_alignment", "'Alignment" }, + { "_assign", ".\":=\"" }, + { NULL, NULL } + }; + int k; + + for (k = 0; special[k][0] != NULL; k++) + { + size_t slen = strlen (special[k][0]); + if (strncmp (p, special[k][0], slen) == 0) + { + p += slen; + slen = strlen (special[k][1]); + memcpy (d, special[k][1], slen); + d += slen; + break; + } + } + if (special[k][0] != NULL) + break; + else + goto unknown; } - else if (*p == '_' && !strcmp (p + 1, "elabs")) - { - memcpy (d, "'Elab_Spec", 10); - d += 10; - break; - } else { *d++ = '.'; @@ -995,46 +1109,6 @@ goto unknown; } - if (p[0] == 'T' && p[1] == 'K') - { - if (p[2] == 'B' && p[3] == 0) - { - /* Subprogram for task body. */ - break; - } - else if (p[2] == '_' && p[3] == '_') - { - /* Inner declarations in a task. */ - p += 4; - *d++ = '.'; - continue; - } - else - goto unknown; - } - if ((p[0] == 'P' || p[0] == 'N') && p[1] == 0) - { - /* Protected type subprogram. */ - break; - } - if (p[0] == 'E' && p[1] == 0) - { - /* Exception name. */ - goto unknown; - } - if (*p == 'N' || *p == 'S') - { - /* Enumerated type name table. */ - goto unknown; - } - if (p[0] == 'X') - { - /* Body nested. */ - if (p[1] == 'n' || p[1] == 'b') - p += 2; - else if (p[1] == 0) - p++; - } if (p[0] == '.' && ISDIGIT (p[1])) { /* Nested subprogram. */