From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: fabrice nicol Newsgroups: gmane.emacs.bugs Subject: bug#47408: [PATCH] Etags support for Mercury -- fix explicit tags for existentially-quantified procedures Date: Mon, 14 Jun 2021 20:52:54 +0200 Message-ID: References: <46bb9128-8bf5-e24c-2172-1cbb4202ee1d@gmail.com> <83lf7c5t6z.fsf@gnu.org> <46a10b9f-91d7-63c4-1513-0af4743e0940@gmail.com> <83eed45omq.fsf@gnu.org> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="------------3B01D007E0168713689A0D30" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="31501"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.10.2 Cc: 47408@debbugs.gnu.org To: Eli Zaretskii Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Mon Jun 14 20:52:09 2021 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1lsrgv-0007xx-FV for geb-bug-gnu-emacs@m.gmane-mx.org; Mon, 14 Jun 2021 20:52:09 +0200 Original-Received: from localhost ([::1]:32782 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lsrgu-0006ns-HH for geb-bug-gnu-emacs@m.gmane-mx.org; Mon, 14 Jun 2021 14:52:08 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:36054) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lsrgo-0006nL-Kd for bug-gnu-emacs@gnu.org; Mon, 14 Jun 2021 14:52:02 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:36267) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lsrgo-0004nB-D1 for bug-gnu-emacs@gnu.org; Mon, 14 Jun 2021 14:52:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1lsrgo-00053W-9b for bug-gnu-emacs@gnu.org; Mon, 14 Jun 2021 14:52:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: fabrice nicol Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Mon, 14 Jun 2021 18:52:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 47408 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch Original-Received: via spool by 47408-submit@debbugs.gnu.org id=B47408.162369671119417 (code B ref 47408); Mon, 14 Jun 2021 18:52:02 +0000 Original-Received: (at 47408) by debbugs.gnu.org; 14 Jun 2021 18:51:51 +0000 Original-Received: from localhost ([127.0.0.1]:47813 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1lsrgc-000536-KP for submit@debbugs.gnu.org; Mon, 14 Jun 2021 14:51:51 -0400 Original-Received: from mail-wm1-f51.google.com ([209.85.128.51]:36462) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1lsrgb-00052s-6c for 47408@debbugs.gnu.org; Mon, 14 Jun 2021 14:51:49 -0400 Original-Received: by mail-wm1-f51.google.com with SMTP id h11-20020a05600c350bb02901b59c28e8b4so83390wmq.1 for <47408@debbugs.gnu.org>; Mon, 14 Jun 2021 11:51:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=subject:to:cc:references:from:message-id:date:user-agent :mime-version:in-reply-to:content-language; bh=eb3XjvjEgkKumiVk2aWQdxk9E8qLcPSDcWn1Sy+Nwcs=; b=m/a9JP+7xP2QOsIc+kYnNgpeN8pf3tJDm+fXgQdtU90o50i6ZziUGgF0tiy9uCkpkw cDXL5qmwHRxz1Tr198X6ZCcAh5M489rP9cFlS8z7Crgb2AFx/oPEuIvTXjgs+WC527vJ KJ+GgTjRMPdkkasw2rsL1w4Chya/Ri/RmHAyzYCOAlEaltZyX6pqozC3LElzNZE6/q7C uKCeL7uNyleAIcOcG8EG42JMESLDo8hgtzNlOkkECcYSC/kSsShF8RYczZQfTjHGj9TF JGrt1hFUg4DqMkR9/SVEADIdT3/I75gL+oYxXSi5aCToM3Cf67ydenRrCb5Ykg/lwBY9 ypkA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language; bh=eb3XjvjEgkKumiVk2aWQdxk9E8qLcPSDcWn1Sy+Nwcs=; b=dAd7pwKurioMO49C2RqDQBbZIxFC3aIV3748+0/uPryChTPFa1uP7aGw/WVQX4iu5K nQ0XAuBNmlHyy4E3BM8T9BuDWMsDeo/t/iTsTHO1Q4GH1P6ZrW6NXlPSKxhSv23e7LMe 6/lrlcrLwaW7qsKpqKD4JLf7oZs/JjmoD6xoO/fFBGXn4E9wePvTVXovLzEQbzIicJm3 1fnjzbd065iUzeZL6BukWbBXMTEJPg8OFVM44vaqcr0qtz7qj+wYsOg23zBD+nVGIbhR jAvsgFA2PPHNo2zdGhePvlC5ZZeU76a3xrEAe/SN8ms+biDHyYa8Yr04YO0hBpQ6AGxy K8wQ== X-Gm-Message-State: AOAM531OWFq6aXQd6ojFjzc6Ypo7tza3IJwWzL9ExFKQNRX+9QkXavsp nCHBF2shp8K6gsLiHavpyF5I9PHCaSE= X-Google-Smtp-Source: ABdhPJyw9tlpF7mvt4e5XEIrfQO3q2XnCVfrocwffHp8KdTY9PFjghb63e0fP6Y2ZIchIvo7pWWK3w== X-Received: by 2002:a05:600c:3b23:: with SMTP id m35mr544248wms.185.1623696703148; Mon, 14 Jun 2021 11:51:43 -0700 (PDT) Original-Received: from ?IPv6:2a01:cb1d:88b9:5c00:7b73:7901:965e:8523? ([2a01:cb1d:88b9:5c00:7b73:7901:965e:8523]) by smtp.gmail.com with ESMTPSA id e27sm18079376wra.50.2021.06.14.11.51.41 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 14 Jun 2021 11:51:41 -0700 (PDT) In-Reply-To: <83eed45omq.fsf@gnu.org> Content-Language: en-US X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.io gmane.emacs.bugs:208517 Archived-At: This is a multi-part message in MIME format. --------------3B01D007E0168713689A0D30 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Agreed. (But you may have more systematically explicit tags because of this condition 2.) The attached patch was tested, builds and runs OK. Replaces the former one, is you stick to the option of modifying 's' by reference rather than creating a copy. Note: Prolog has a much simpler naming pattern, so differences are normal. No need for explicit tagging in Prolog, see the call to 'make_tag' in Prolog support. Fabrice Le 14/06/2021 à 19:42, Eli Zaretskii a écrit : >> Cc: 47408@debbugs.gnu.org, pot@gnu.org >> From: fabrice nicol >> Date: Mon, 14 Jun 2021 19:10:53 +0200 >> >> If you take a look at other languages that implement explicit tags (like >> Fortran) you will see that there are buffers coming in to avoid having >> 'name' and 'linestart' (1st and 4th arguments to 'make_tag') share a >> same string pointer (here 's'). >> >> This is explained in the header comment to 'make_tag': >> >> " 2. LINESTART contains name as either a rightmost, or rightmost but >>  *     one character, substring;" > This is just a condition for generating "implicitly named" tags. > There's nothing wrong with having explicitly named tags, if there are > good reasons for that. > >> When I applied you suggestion and tested, the TAGS base was as expected >> accordingly: wrong. > "Wrong" in what sense? Can you show an example of such a wrong tag? > And how does Mercury differ from Prolog in this sense? prolog_pr > doesn't allocate new strings before calling make_tag. > > Thanks. --------------3B01D007E0168713689A0D30 Content-Type: text/x-patch; charset=UTF-8; name="0001-Fix-explicit-tag-issue-with-Mercury-etags-ctags-supp-v2.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename*0="0001-Fix-explicit-tag-issue-with-Mercury-etags-ctags-supp-v2"; filename*1=".patch" >From 882ba6a0f51a95893cac798c721e3ccd4ad4e0f6 Mon Sep 17 00:00:00 2001 From: Fabrice Nicol Date: Mon, 14 Jun 2021 14:30:54 +0200 Subject: [PATCH] Fix explicit tag issue with Mercury etags/ctags support Redesign of prior fix, which did not handle type quantifiers. Fix omission of single-word declarations like ':- interface.' * lib-src/etags.c (mercury_pr): Pass the newly corrected NAME and NAMELEN arguments to 'make_tag'. --- lib-src/etags.c | 110 ++++++++++++++++++++++++++++++------------------ 1 file changed, 69 insertions(+), 41 deletions(-) diff --git a/lib-src/etags.c b/lib-src/etags.c index 9f20e44caf..370e825111 100644 --- a/lib-src/etags.c +++ b/lib-src/etags.c @@ -6081,10 +6081,10 @@ prolog_atom (char *s, size_t pos) pos++; if (s[pos] != '\'') break; - pos++; /* A double quote */ + pos++; /* A double quote */ } else if (s[pos] == '\0') - /* Multiline quoted atoms are ignored. */ + /* Multiline quoted atoms are ignored. */ return 0; else if (s[pos] == '\\') { @@ -6119,6 +6119,13 @@ prolog_atom (char *s, size_t pos) static bool is_mercury_type = false; static bool is_mercury_quantifier = false; static bool is_mercury_declaration = false; +typedef struct +{ + size_t pos; /* Position reached in parsing tag name. */ + size_t namelength; /* Length of tag name */ + size_t totlength; /* Total length of parsed tag: this field is currently + reserved for control and debugging. */ +} mercury_pos_t; /* * Objective-C and Mercury have identical file extension .m. @@ -6374,10 +6381,12 @@ mercury_skip_comment (linebuffer *plb, FILE *inf) "initialise", "finalise", "mutable", "module", "interface", "implementation", "import_module", "use_module", "include_module", "end_module", "some", "all"}; -static size_t +static mercury_pos_t mercury_decl (char *s, size_t pos) { - if (s == NULL) return 0; + mercury_pos_t null_pos = {0, 0, 0}; + + if (s == NULL) return null_pos; size_t origpos; origpos = pos; @@ -6398,7 +6407,8 @@ mercury_decl (char *s, size_t pos) if (is_mercury_quantifier) { if (strcmp (buf, "pred") != 0 && strcmp (buf, "func") != 0) /* Bad syntax. */ - return 0; + return null_pos; + is_mercury_quantifier = false; /* Reset to base value. */ found_decl_tag = true; } @@ -6418,7 +6428,7 @@ mercury_decl (char *s, size_t pos) is_mercury_quantifier = true; } - break; /* Found declaration tag of rank j. */ + break; /* Found declaration tag of rank j. */ } else /* 'solver type' has a blank in the middle, @@ -6461,11 +6471,13 @@ mercury_decl (char *s, size_t pos) if (found_decl_tag) pos = skip_spaces (s + pos) - s; /* Skip len blanks again. */ else - return 0; + return null_pos; } /* From now on it is the same as for Prolog except for module dots. */ + size_t start_of_name = pos; + if (c_islower (s[pos]) || s[pos] == '_' ) { /* The name is unquoted. @@ -6478,7 +6490,8 @@ mercury_decl (char *s, size_t pos) && (c_isalnum (s[pos + 1]) || s[pos + 1] == '_'))) ++pos; - return pos - origpos; + mercury_pos_t position = {pos, pos - start_of_name + 1, pos - origpos}; + return position; } else if (s[pos] == '\'') { @@ -6493,28 +6506,37 @@ mercury_decl (char *s, size_t pos) ++pos; /* A double quote. */ } else if (s[pos] == '\0') /* Multiline quoted atoms are ignored. */ - return 0; + return null_pos; else if (s[pos] == '\\') { if (s[pos+1] == '\0') - return 0; + return null_pos; pos += 2; } else ++pos; } - return pos - origpos; + + mercury_pos_t position = {pos, pos - start_of_name + 1, pos - origpos}; + return position; } else if (is_mercury_quantifier && s[pos] == '[') /* :- some [T] pred/func. */ { for (++pos; s + pos != NULL && s[pos] != ']'; ++pos) {} - if (s + pos == NULL) return 0; + if (s + pos == NULL) return null_pos; ++pos; pos = skip_spaces (s + pos) - s; - return mercury_decl (s, pos) + pos - origpos; + mercury_pos_t position = mercury_decl (s, pos); + position.totlength += pos - origpos; + return position; + } + else if (s[pos] == '.') /* as in ':- interface.' */ + { + mercury_pos_t position = {pos, pos - origpos + 1, pos - origpos}; + return position; } else - return 0; + return null_pos; } static ptrdiff_t @@ -6523,6 +6545,7 @@ mercury_pr (char *s, char *last, ptrdiff_t lastlen) size_t len0 = 0; is_mercury_type = false; is_mercury_quantifier = false; + bool stop_at_rule = false; if (is_mercury_declaration) { @@ -6530,38 +6553,43 @@ mercury_pr (char *s, char *last, ptrdiff_t lastlen) len0 = skip_spaces (s + 2) - s; } - size_t len = mercury_decl (s, len0); - if (len == 0) return 0; - len += len0; + mercury_pos_t position = mercury_decl (s, len0); + size_t pos = position.pos; + int offset = 0; /* may be < 0 */ + if (pos == 0) return 0; - if (( (s[len] == '.' /* This is a statement dot, not a module dot. */ - || (s[len] == '(' && (len += 1)) - || (s[len] == ':' /* Stopping in case of a rule. */ - && s[len + 1] == '-' - && (len += 2))) - && (lastlen != len || memcmp (s, last, len) != 0) + /* Skip white space for rules in definitions before :- + and possibly multiline type definitions */ + + while (c_isspace (s[pos])) { ++pos; ++offset; } + + if (( ((s[pos] == '.' && (pos += 1)) /* case 1 + This is a statement dot, + not a module dot. */ + || (s[pos] == '(' && (pos += 1)) /* case 2 */ + || ((s[pos] == ':') /* case 3 */ + && s[pos + 1] == '-' && (stop_at_rule = true))) + && (lastlen != pos || memcmp (s, last, pos) != 0) ) /* Types are often declared on several lines so keeping just the first line. */ - || is_mercury_type) + + || is_mercury_type) /* When types are implemented. */ { - char *name = skip_non_spaces (s + len0); - size_t namelen; - if (name >= s + len) - { - name = s; - namelen = len; - } - else - { - name = skip_spaces (name); - namelen = len - (name - s); - } - /* Remove trailing non-name characters. */ - while (namelen > 0 && notinname (name[namelen - 1])) - namelen--; - make_tag (name, namelen, true, s, len, lineno, linecharno); - return len; + size_t namelength = position.namelength; + if (stop_at_rule && offset) --offset; + + /* Left-trim type definitions. */ + + while (pos > namelength + offset + && c_isspace (s[pos - namelength - offset])) + --offset; + + /* There is no need to correct namelength or call notinname. */ + s[pos - offset - 1] = '\0'; + + make_tag (s + pos - namelength - offset, namelength, true, s, pos, lineno, linecharno); + return pos; } return 0; -- 2.31.1 --------------3B01D007E0168713689A0D30--