Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

C++: Output information on constexpr and consteval functions #3539

Closed
delsner opened this issue Nov 18, 2022 · 4 comments · Fixed by #3541 or #3602
Closed

C++: Output information on constexpr and consteval functions #3539

delsner opened this issue Nov 18, 2022 · 4 comments · Fixed by #3541 or #3602
Assignees

Comments

@delsner
Copy link
Contributor

delsner commented Nov 18, 2022

Hi!
It seems as if ctags currently does not support distinctive tagging of constexpr and consteval functions (they're merely tagged as regular functions).
One possible workaround is to check the pattern field for these keywords, but having ctags output a (extra) field or property for them would be cleaner. (I personally would prefer adding these keywords to the properties field.)
Is there any preliminary or ongoing work on this already?
If not, I might take a stab (and would appreciate any advise for approaching this, as I'm not familiar with the C++ parser).
Thanks!


The name of the parser: C/C++

The command line you used to run ctags:

$ ctags --options=NONE --fields-all="*" --output-format=json const.cpp

The content of input file (from here):

// This function might be evaluated at compile-time, if the input
// is known at compile-time. Otherwise, it is executed at run-time.
constexpr unsigned factorial(unsigned n) {
    return n < 2 ? 1 : n * factorial(n - 1);
}

// With consteval we enforce that the function will be evaluated at compile-time.
consteval unsigned combination(unsigned m, unsigned n) {
    return factorial(n) / factorial(m) / factorial(n - m);
}

The tags output you are not satisfied with:

{"_type": "tag", "name": "combination", "path": "const.cpp", "pattern": "/^consteval unsigned combination(unsigned m, unsigned n) {$/", "language": "C++", "line": 8, "typeref": "typename:consteval unsigned", "kind": "function", "signature": "(unsigned m,unsigned n)", "roles": "def", "end": 10}
{"_type": "tag", "name": "factorial", "path": "const.cpp", "pattern": "/^constexpr unsigned factorial(unsigned n) {$/", "language": "C++", "line": 3, "typeref": "typename:unsigned", "kind": "function", "signature": "(unsigned n)", "roles": "def", "end": 5}

The version of ctags:

$ ctags --version
Universal Ctags 5.9.0(7b5c7efa), Copyright (C) 2015-2022 Universal Ctags Team
Universal Ctags is derived from Exuberant Ctags.
Exuberant Ctags 5.8, Copyright (C) 1996-2009 Darren Hiebert
  Compiled: Jul 13 2022, 17:12:58
  URL: https://ctags.io/
  Optional compiled features: +wildcards, +regex, +gnulib_fnmatch, +gnulib_regex, +iconv, +option-directory, +xpath, +json, +interactive, +yaml, +case-insensitive-filenames, +packcc, +optscript

How do you get ctags binary:

macosx binary taken from Universal-ctags/homebrew-universal-ctags project

@masatake
Copy link
Member

Thank you for reporting. Could you write "ideal tags" output?

@delsner
Copy link
Contributor Author

delsner commented Nov 19, 2022

Appended the properties field at the end of the JSON which would be populated using that information (as a comma-separated list similar to static, virtual, inline, ...):

{"_type": "tag", "name": "combination", "path": "const.cpp", "pattern": "/^consteval unsigned combination(unsigned m, unsigned n) {$/", "language": "C++", "line": 8, "typeref": "typename:consteval unsigned", "kind": "function", "signature": "(unsigned m,unsigned n)", "roles": "def", "end": 10, "properties": "consteval"}
{"_type": "tag", "name": "factorial", "path": "const.cpp", "pattern": "/^constexpr unsigned factorial(unsigned n) {$/", "language": "C++", "line": 3, "typeref": "typename:unsigned", "kind": "function", "signature": "(unsigned n)", "roles": "def", "end": 5, "properties": "constexpr"}

masatake added a commit to masatake/ctags that referenced this issue Nov 19, 2022
Partially close universal-ctags#3539.

Signed-off-by: Masatake YAMATO <yamato@redhat.com>
@masatake
Copy link
Member

@delsner I inspected the C++ parser. The original author (and maintainer) has been absent for a year. My knowledge of the parser and C++ language itself is limited. So I cannot give you enough advice.

About constexpr, the C++ parser already knows it as a keyword. So putting it into the "properties:" field is not hard. See #3541.

About consteval, the C++ parser doesn't know it. As the first step, we must register it as a keyword. After registering, we can do the same as #3541.

If not, I might take a stab (and would appreciate any advise for approaching this, as I'm not familiar with the C++ parser).

You are welcome.

I would like you to read #3541.
https://docs.ctags.io/en/latest/testing-parser.html
See "Don’t mix whitespace ..." paragraph in https://docs.ctags.io/en/latest/contributions.html#c-language.

masatake added a commit to masatake/ctags that referenced this issue Nov 20, 2022
Partially close universal-ctags#3539.

Signed-off-by: Masatake YAMATO <yamato@redhat.com>
@delsner
Copy link
Contributor Author

delsner commented Nov 21, 2022

@masatake great, thanks for the clear advise and your solution for constexpr (that was really quick!).
I'll let you know when I have a draft for the consteval extension.

masatake added a commit to masatake/ctags that referenced this issue Nov 28, 2022
Partially close universal-ctags#3539.

Signed-off-by: Masatake YAMATO <yamato@redhat.com>
Co-authored-by: Daniel <dvelsner@gmail.com>
@masatake masatake reopened this Nov 29, 2022
masatake added a commit to masatake/ctags that referenced this issue Dec 18, 2022
Close universal-ctags#3539.

Signed-off-by: Masatake YAMATO <yamato@redhat.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants