RE: Global does not recognize C++ final keyword
Alex Pelts <[email protected]> Thu, 29 Sep 2022 10:59:57 -0700
| Newsgroups | gmane.comp.gnu.global.bugs |
|---|---|
| Message-ID | <[email protected]> |
Hello to you too. I tried your suggestion but for some reason gtags could not find universal-ctags. Kept complaining. I also would like to use global on multiple machines and universal-ctags don't have a convenient install option. I am trying to migrate from cscope which is unsupported at this point. I created a patch that I think fixes the issue. Could you please review it and merge if possible? There are only few lines of changes but re-generated files have a lot of changes because of keyword shift. There is another use of final keyword after a function and that I did not handle. The patch also does not handle something like "struct final Model". That is not a valid syntax and compilation will fail. Not sure if this should be handled. Thank you, Alex -----Original Message----- From: Shigio YAMAGUCHI <[email protected]> Sent: Wednesday, September 28, 2022 8:53 PM To: Alex Pelts <[email protected]> Cc: [email protected] Subject: Re: Global does not recognize C++ final keyword Hello, I have added your report to the TODO list. (https://www.gnu.org/software/global/bugs.html) By the way, C++ language is no longer officially supported. [NEWS] Version 6.6.5 - September 3 2020 ... [DEPRECATED] o gtags: the built-in C++ parser is deprecated, since it is not well maintained. Currently, it is hard to say that Global supports C++ language. If you have universal-ctags, please try this: $ cp /usr/local/share/gtags/gtags.conf . $ gtags --gtagslabel=universal-ctags $ global -dx Model Model 16 cpp-test.cpp struct Model final { $ _ The --gtagslabel=universal-ctags is not needed, if you rewrite gtags.conf like follows: [gtags.conf] +-------------------- |default:\ | :tc=native: | v +-------------------- |default:\ | :tc=universal-ctags: Thank you for the report! Regards, Shigio On Thu, Sep 29, 2022 at 10:07 AM Alex Pelts <[email protected]> wrote: > > What is your environment (OS)? > Ubuntu 18.04.1 LTS > Which version of Global are you using? > Tried 6.6.2 which is available with apt-get and 6.6.8 which I built > from source. Both versions show the same issue. > What did you do? (command line) > gtags . > global -dx Model > global -dx final > global -dx struct > > What did you expect from it? > global -dx Model > Expected for the tool to show definition of model global -dx final > Expected not to show any definitions global -dx struct Expected not to > show any definitions > > What was occurred? (as is) > global -dx Model > Did not show any definitions > global -dx final > final 16 cpp-test.cpp struct Model final { > final 17 cpp-test.cpp struct ExtensionNameAndPrefix > final { > global -dx struct > Did not show any definitions > > Attached is the relevant CPP file. > > Thank you, > Alex > > -- > This electronic communication and the information and any files > transmitted with it, or attached to it, are confidential and are > intended solely for the use of the individual or entity to whom it is > addressed and may contain information that is confidential, legally > privileged, protected by privacy laws, or otherwise restricted from > disclosure to anyone else. If you are not the intended recipient or > the person responsible for delivering the e-mail to the intended > recipient, you are hereby notified that any use, copying, > distributing, dissemination, forwarding, printing, or copying of this > e-mail is strictly prohibited. If you received this e-mail in error, > please return the e-mail to the sender, delete it from your computer, and > destroy any printed copy of it. -- Shigio YAMAGUCHI <[email protected]> PGP fingerprint: 26F6 31B4 3D62 4A92 7E6F 1C33 969C 3BE3 89DD A6EB -- This electronic communication and the information and any files transmitted with it, or attached to it, are confidential and are intended solely for the use of the individual or entity to whom it is addressed and may contain information that is confidential, legally privileged, protected by privacy laws, or otherwise restricted from disclosure to anyone else. If you are not the intended recipient or the person responsible for delivering the e-mail to the intended recipient, you are hereby notified that any use, copying, distributing, dissemination, forwarding, printing, or copying of this e-mail is strictly prohibited. If you received this e-mail in error, please return the e-mail to the sender, delete it from your computer, and destroy any printed copy of it.
0001-Added-parsing-of-final-keyword.patch
(application/octet-stream, 14.6 KB)
From 7fe65ea7eae888cbfb82bb0ed55bba75ebb950fd Mon Sep 17 00:00:00 2001 From: Alex Pelts <[email protected]> Date: Thu, 29 Sep 2022 10:38:31 -0700 Subject: [PATCH] Added parsing of final keyword --- libparser/Cpp.c | 2 + libparser/cpp_res.gpf | 78 ++++++------ libparser/cpp_res.h | 274 +++++++++++++++++++++--------------------- libparser/cpp_res.in | 1 + 4 files changed, 182 insertions(+), 173 deletions(-) diff --git a/libparser/Cpp.c b/libparser/Cpp.c index efd6b74..cdc30e9 100644 --- a/libparser/Cpp.c +++ b/libparser/Cpp.c @@ -243,6 +243,8 @@ Cpp(const struct parser_param *param) } } c = nexttoken(NULL, cpp_reserved_word); + } else if (c == CPP_FINAL) { + c = nexttoken(NULL, cpp_reserved_word); } } while (c == SYMBOL || c == '\n'); if (c == ':' || c == '{') /* } */ { diff --git a/libparser/cpp_res.gpf b/libparser/cpp_res.gpf index c15b9ad..636cef6 100644 --- a/libparser/cpp_res.gpf +++ b/libparser/cpp_res.gpf @@ -39,44 +39,45 @@ #define CPP_EXPORT 2028 #define CPP_EXTERN 2029 #define CPP_FALSE 2030 -#define CPP_FLOAT 2031 -#define CPP_FOR 2032 -#define CPP_FRIEND 2033 -#define CPP_GOTO 2034 -#define CPP_IF 2035 -#define CPP_INT 2036 -#define CPP_LONG 2037 -#define CPP_MUTABLE 2038 -#define CPP_NAMESPACE 2039 -#define CPP_NEW 2040 -#define CPP_OPERATOR 2041 -#define CPP_PRIVATE 2042 -#define CPP_PROTECTED 2043 -#define CPP_PUBLIC 2044 -#define CPP_REGISTER 2045 -#define CPP_REINTERPRET_CAST 2046 -#define CPP_RETURN 2047 -#define CPP_SHORT 2048 -#define CPP_SIZEOF 2049 -#define CPP_STATIC 2050 -#define CPP_STATIC_CAST 2051 -#define CPP_STRUCT 2052 -#define CPP_SWITCH 2053 -#define CPP_TEMPLATE 2054 -#define CPP_THIS 2055 -#define CPP_THROW 2056 -#define CPP_TRUE 2057 -#define CPP_TRY 2058 -#define CPP_TYPEDEF 2059 -#define CPP_TYPENAME 2060 -#define CPP_TYPEID 2061 -#define CPP_UNION 2062 -#define CPP_UNSIGNED 2063 -#define CPP_USING 2064 -#define CPP_VIRTUAL 2065 -#define CPP_VOID 2066 -#define CPP_WCHAR_T 2067 -#define CPP_WHILE 2068 +#define CPP_FINAL 2031 +#define CPP_FLOAT 2032 +#define CPP_FOR 2033 +#define CPP_FRIEND 2034 +#define CPP_GOTO 2035 +#define CPP_IF 2036 +#define CPP_INT 2037 +#define CPP_LONG 2038 +#define CPP_MUTABLE 2039 +#define CPP_NAMESPACE 2040 +#define CPP_NEW 2041 +#define CPP_OPERATOR 2042 +#define CPP_PRIVATE 2043 +#define CPP_PROTECTED 2044 +#define CPP_PUBLIC 2045 +#define CPP_REGISTER 2046 +#define CPP_REINTERPRET_CAST 2047 +#define CPP_RETURN 2048 +#define CPP_SHORT 2049 +#define CPP_SIZEOF 2050 +#define CPP_STATIC 2051 +#define CPP_STATIC_CAST 2052 +#define CPP_STRUCT 2053 +#define CPP_SWITCH 2054 +#define CPP_TEMPLATE 2055 +#define CPP_THIS 2056 +#define CPP_THROW 2057 +#define CPP_TRUE 2058 +#define CPP_TRY 2059 +#define CPP_TYPEDEF 2060 +#define CPP_TYPENAME 2061 +#define CPP_TYPEID 2062 +#define CPP_UNION 2063 +#define CPP_UNSIGNED 2064 +#define CPP_USING 2065 +#define CPP_VIRTUAL 2066 +#define CPP_VOID 2067 +#define CPP_WCHAR_T 2068 +#define CPP_WHILE 2069 #define SHARP_SHARP 3001 #define SHARP_ASSERT 3002 #define SHARP_DEFINE 3003 @@ -141,6 +142,7 @@ explicit, CPP_EXPLICIT export, CPP_EXPORT extern, CPP_EXTERN false, CPP_FALSE +final, CPP_FINAL float, CPP_FLOAT for, CPP_FOR friend, CPP_FRIEND diff --git a/libparser/cpp_res.h b/libparser/cpp_res.h index dc070b3..2637854 100644 --- a/libparser/cpp_res.h +++ b/libparser/cpp_res.h @@ -70,44 +70,45 @@ #define CPP_EXPORT 2028 #define CPP_EXTERN 2029 #define CPP_FALSE 2030 -#define CPP_FLOAT 2031 -#define CPP_FOR 2032 -#define CPP_FRIEND 2033 -#define CPP_GOTO 2034 -#define CPP_IF 2035 -#define CPP_INT 2036 -#define CPP_LONG 2037 -#define CPP_MUTABLE 2038 -#define CPP_NAMESPACE 2039 -#define CPP_NEW 2040 -#define CPP_OPERATOR 2041 -#define CPP_PRIVATE 2042 -#define CPP_PROTECTED 2043 -#define CPP_PUBLIC 2044 -#define CPP_REGISTER 2045 -#define CPP_REINTERPRET_CAST 2046 -#define CPP_RETURN 2047 -#define CPP_SHORT 2048 -#define CPP_SIZEOF 2049 -#define CPP_STATIC 2050 -#define CPP_STATIC_CAST 2051 -#define CPP_STRUCT 2052 -#define CPP_SWITCH 2053 -#define CPP_TEMPLATE 2054 -#define CPP_THIS 2055 -#define CPP_THROW 2056 -#define CPP_TRUE 2057 -#define CPP_TRY 2058 -#define CPP_TYPEDEF 2059 -#define CPP_TYPENAME 2060 -#define CPP_TYPEID 2061 -#define CPP_UNION 2062 -#define CPP_UNSIGNED 2063 -#define CPP_USING 2064 -#define CPP_VIRTUAL 2065 -#define CPP_VOID 2066 -#define CPP_WCHAR_T 2067 -#define CPP_WHILE 2068 +#define CPP_FINAL 2031 +#define CPP_FLOAT 2032 +#define CPP_FOR 2033 +#define CPP_FRIEND 2034 +#define CPP_GOTO 2035 +#define CPP_IF 2036 +#define CPP_INT 2037 +#define CPP_LONG 2038 +#define CPP_MUTABLE 2039 +#define CPP_NAMESPACE 2040 +#define CPP_NEW 2041 +#define CPP_OPERATOR 2042 +#define CPP_PRIVATE 2043 +#define CPP_PROTECTED 2044 +#define CPP_PUBLIC 2045 +#define CPP_REGISTER 2046 +#define CPP_REINTERPRET_CAST 2047 +#define CPP_RETURN 2048 +#define CPP_SHORT 2049 +#define CPP_SIZEOF 2050 +#define CPP_STATIC 2051 +#define CPP_STATIC_CAST 2052 +#define CPP_STRUCT 2053 +#define CPP_SWITCH 2054 +#define CPP_TEMPLATE 2055 +#define CPP_THIS 2056 +#define CPP_THROW 2057 +#define CPP_TRUE 2058 +#define CPP_TRY 2059 +#define CPP_TYPEDEF 2060 +#define CPP_TYPENAME 2061 +#define CPP_TYPEID 2062 +#define CPP_UNION 2063 +#define CPP_UNSIGNED 2064 +#define CPP_USING 2065 +#define CPP_VIRTUAL 2066 +#define CPP_VOID 2067 +#define CPP_WCHAR_T 2068 +#define CPP_WHILE 2069 #define SHARP_SHARP 3001 #define SHARP_ASSERT 3002 #define SHARP_DEFINE 3003 @@ -130,12 +131,12 @@ #define SHARP_WARNING 3020 struct keyword { char *name; int token; }; -#define TOTAL_KEYWORDS 99 +#define TOTAL_KEYWORDS 100 #define MIN_WORD_LENGTH 2 #define MAX_WORD_LENGTH 16 #define MIN_HASH_VALUE 2 -#define MAX_HASH_VALUE 242 -/* maximum key range = 241, duplicates = 0 */ +#define MAX_HASH_VALUE 227 +/* maximum key range = 226, duplicates = 0 */ #ifdef __GNUC__ __inline @@ -149,32 +150,32 @@ cpp_hash (register const char *str, register size_t len) { static unsigned char asso_values[] = { - 243, 243, 243, 243, 243, 243, 243, 243, 243, 243, - 243, 243, 243, 243, 243, 243, 243, 243, 243, 243, - 243, 243, 243, 243, 243, 243, 243, 243, 243, 243, - 243, 243, 243, 243, 243, 10, 243, 243, 243, 243, - 243, 243, 243, 243, 243, 243, 243, 243, 243, 243, - 243, 243, 243, 243, 243, 243, 243, 243, 0, 243, - 243, 243, 243, 243, 243, 243, 243, 243, 243, 243, - 243, 243, 243, 243, 243, 243, 243, 243, 243, 243, - 243, 45, 243, 243, 243, 243, 243, 243, 243, 243, - 243, 243, 243, 243, 243, 5, 243, 10, 15, 35, - 45, 25, 95, 70, 35, 15, 65, 243, 70, 20, - 0, 5, 60, 15, 5, 0, 0, 10, 90, 80, - 20, 80, 30, 40, 243, 243, 243, 243, 243, 243, - 243, 243, 243, 243, 243, 243, 243, 243, 243, 243, - 243, 243, 243, 243, 243, 243, 243, 243, 243, 243, - 243, 243, 243, 243, 243, 243, 243, 243, 243, 243, - 243, 243, 243, 243, 243, 243, 243, 243, 243, 243, - 243, 243, 243, 243, 243, 243, 243, 243, 243, 243, - 243, 243, 243, 243, 243, 243, 243, 243, 243, 243, - 243, 243, 243, 243, 243, 243, 243, 243, 243, 243, - 243, 243, 243, 243, 243, 243, 243, 243, 243, 243, - 243, 243, 243, 243, 243, 243, 243, 243, 243, 243, - 243, 243, 243, 243, 243, 243, 243, 243, 243, 243, - 243, 243, 243, 243, 243, 243, 243, 243, 243, 243, - 243, 243, 243, 243, 243, 243, 243, 243, 243, 243, - 243, 243, 243, 243, 243, 243, 243 + 228, 228, 228, 228, 228, 228, 228, 228, 228, 228, + 228, 228, 228, 228, 228, 228, 228, 228, 228, 228, + 228, 228, 228, 228, 228, 228, 228, 228, 228, 228, + 228, 228, 228, 228, 228, 10, 228, 228, 228, 228, + 228, 228, 228, 228, 228, 228, 228, 228, 228, 228, + 228, 228, 228, 228, 228, 228, 228, 228, 0, 228, + 228, 228, 228, 228, 228, 228, 228, 228, 228, 228, + 228, 228, 228, 228, 228, 228, 228, 228, 228, 228, + 228, 45, 228, 228, 228, 228, 228, 228, 228, 228, + 228, 228, 228, 228, 228, 5, 228, 10, 15, 80, + 40, 25, 90, 80, 80, 15, 70, 228, 25, 25, + 0, 5, 55, 15, 5, 0, 0, 10, 100, 110, + 15, 20, 30, 40, 228, 228, 228, 228, 228, 228, + 228, 228, 228, 228, 228, 228, 228, 228, 228, 228, + 228, 228, 228, 228, 228, 228, 228, 228, 228, 228, + 228, 228, 228, 228, 228, 228, 228, 228, 228, 228, + 228, 228, 228, 228, 228, 228, 228, 228, 228, 228, + 228, 228, 228, 228, 228, 228, 228, 228, 228, 228, + 228, 228, 228, 228, 228, 228, 228, 228, 228, 228, + 228, 228, 228, 228, 228, 228, 228, 228, 228, 228, + 228, 228, 228, 228, 228, 228, 228, 228, 228, 228, + 228, 228, 228, 228, 228, 228, 228, 228, 228, 228, + 228, 228, 228, 228, 228, 228, 228, 228, 228, 228, + 228, 228, 228, 228, 228, 228, 228, 228, 228, 228, + 228, 228, 228, 228, 228, 228, 228, 228, 228, 228, + 228, 228, 228, 228, 228, 228, 228 }; register unsigned int hval = len; @@ -228,117 +229,120 @@ cpp_lookup (register const char *str, register size_t len) {""}, {"__attribute__", CPP___ATTRIBUTE__}, {"#unassert", SHARP_UNASSERT}, - {"false", CPP_FALSE}, + {"final", CPP_FINAL}, {"#error", SHARP_ERROR}, {"mutable", CPP_MUTABLE}, {"try", CPP_TRY}, {"case", CPP_CASE}, - {""}, - {"inline", CPP_INLINE}, - {""}, - {"volatile", CPP_VOLATILE}, - {"namespace", CPP_NAMESPACE}, - {"throw", CPP_THROW}, + {"false", CPP_FALSE}, {"export", CPP_EXPORT}, {""}, {"new", CPP_NEW}, - {""}, - {"#else", SHARP_ELSE}, + {"namespace", CPP_NAMESPACE}, + {"class", CPP_CLASS}, + {"inline", CPP_INLINE}, + {"dynamic_cast", CPP_DYNAMIC_CAST}, + {"volatile", CPP_VOLATILE}, + {""}, {""}, {"return", CPP_RETURN}, {""}, {"__P", CPP___P}, - {""}, {""}, - {"signed", CPP_SIGNED}, - {""}, - {"__thread", CPP___THREAD}, - {"char", CPP_CHAR}, - {"catch", CPP_CATCH}, + {"else", CPP_ELSE}, + {"#else", SHARP_ELSE}, {"extern", CPP_EXTERN}, {"__const", CPP_CONST}, - {"#include", SHARP_INCLUDE}, + {""}, {"__const__", CPP_CONST}, - {"#elif", SHARP_ELIF}, + {""}, {"#undef", SHARP_UNDEF}, - {"wchar_t", CPP_WCHAR_T}, - {"#include_next", SHARP_INCLUDE_NEXT}, {""}, - {"using", CPP_USING}, - {"#ident", SHARP_IDENT}, + {"explicit", CPP_EXPLICIT}, {""}, {""}, + {"typeid", CPP_TYPEID}, + {"typedef", CPP_TYPEDEF}, + {"typename", CPP_TYPENAME}, {"protected", CPP_PROTECTED}, + {"#elif", SHARP_ELIF}, + {"#ident", SHARP_IDENT}, + {"#pragma", SHARP_PRAGMA}, + {""}, {""}, + {"using", CPP_USING}, + {"#endif", SHARP_ENDIF}, + {"#import", SHARP_IMPORT}, + {""}, {""}, {"union", CPP_UNION}, {"delete", CPP_DELETE}, - {"#pragma", SHARP_PRAGMA}, + {""}, {"__inline", CPP_INLINE}, {""}, {"__inline__", CPP_INLINE}, - {"#endif", SHARP_ENDIF}, - {"#import", SHARP_IMPORT}, - {"register", CPP_REGISTER}, - {"long", CPP_LONG}, - {"#sccs", SHARP_SCCS}, {"sizeof", CPP_SIZEOF}, {""}, - {"#if", SHARP_IF}, - {""}, - {"class", CPP_CLASS}, - {""}, - {"#ifndef", SHARP_IFNDEF}, {"template", CPP_TEMPLATE}, - {""}, {""}, {""}, + {"bool", CPP_BOOL}, + {"throw", CPP_THROW}, + {""}, {"if", CPP_IF}, {""}, - {"else", CPP_ELSE}, - {"__volatile", CPP_VOLATILE}, + {"long", CPP_LONG}, + {"float", CPP_FLOAT}, + {""}, {""}, + {"#if", SHARP_IF}, + {""}, + {"#line", SHARP_LINE}, + {"signed", CPP_SIGNED}, + {"#ifndef", SHARP_IFNDEF}, + {"__thread", CPP___THREAD}, + {"char", CPP_CHAR}, + {"catch", CPP_CATCH}, {"friend", CPP_FRIEND}, - {"__volatile__", CPP_VOLATILE}, {""}, - {"this", CPP_THIS}, - {"short", CPP_SHORT}, - {"reinterpret_cast", CPP_REINTERPRET_CAST}, - {"dynamic_cast", CPP_DYNAMIC_CAST}, - {"#warning", SHARP_WARNING}, - {""}, {""}, {""}, - {"default", CPP_DEFAULT}, - {"explicit", CPP_EXPLICIT}, - {"enum", CPP_ENUM}, + {"#include", SHARP_INCLUDE}, + {""}, {"break", CPP_BREAK}, - {"double", CPP_DOUBLE}, - {""}, {""}, + {"reinterpret_cast", CPP_REINTERPRET_CAST}, + {"wchar_t", CPP_WCHAR_T}, + {"#include_next", SHARP_INCLUDE_NEXT}, + {""}, {""}, {""}, {""}, {""}, {"void", CPP_VOID}, {""}, {"public", CPP_PUBLIC}, - {""}, {""}, - {"true", CPP_TRUE}, - {""}, - {"typeid", CPP_TYPEID}, - {"typedef", CPP_TYPEDEF}, - {"typename", CPP_TYPENAME}, - {""}, {""}, {""}, {""}, + {"default", CPP_DEFAULT}, {"__extension__", CPP___EXTENSION__}, + {""}, + {"#sccs", SHARP_SCCS}, + {"double", CPP_DOUBLE}, + {""}, + {"register", CPP_REGISTER}, + {"enum", CPP_ENUM}, + {"__volatile", CPP_VOLATILE}, + {""}, + {"__volatile__", CPP_VOLATILE}, + {""}, + {"true", CPP_TRUE}, + {""}, {""}, {""}, + {"#warning", SHARP_WARNING}, {""}, {""}, {"#ifdef", SHARP_IFDEF}, - {""}, {""}, - {"bool", CPP_BOOL}, - {"#line", SHARP_LINE}, - {""}, {""}, {""}, {""}, - {"float", CPP_FLOAT}, - {""}, {""}, {""}, {""}, {""}, - {"switch", CPP_SWITCH}, - {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, - {""}, {""}, {""}, {""}, {""}, {""}, - {"private", CPP_PRIVATE}, + {""}, {""}, {""}, + {"short", CPP_SHORT}, + {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, + {"this", CPP_THIS}, + {""}, {""}, {""}, {"operator", CPP_OPERATOR}, - {""}, {""}, {""}, {""}, {""}, {""}, - {"while", CPP_WHILE}, - {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, + {""}, {""}, {""}, + {"while", CPP_WHILE}, + {""}, + {"private", CPP_PRIVATE}, + {""}, {""}, {""}, + {"switch", CPP_SWITCH}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, - {""}, {""}, {""}, + {""}, {""}, {""}, {""}, {"#define", SHARP_DEFINE} }; diff --git a/libparser/cpp_res.in b/libparser/cpp_res.in index 2d3accf..f70568b 100644 --- a/libparser/cpp_res.in +++ b/libparser/cpp_res.in @@ -43,6 +43,7 @@ explicit word export word extern word false word +final word float word for word friend word -- 2.17.1
smime.p7s
(application/pkcs7-signature, 4.1 KB) - not displayed