function list for C++

Post any comments, suggestions, annoyances or ideas for future releases here. Please do not post bug reports or questions here.
Post Reply
Jack Rosenbloom

function list for C++

Post by Jack Rosenbloom » Fri Nov 19, 2004 7:23 pm

The function list and the ability to navigate up or down in a file by function is great. How about allowing these features to work with C++ operations? I assume it wouldn't be too hard since the "Functions" tagged in the navigator pane shows C and C++ routines.

jussij
Site Admin
Posts: 2449
Joined: Fri Aug 13, 2004 5:10 pm

Post by jussij » Sat Nov 20, 2004 3:45 am

The function list and the ability to navigate up or down in a file by function is great.
I assume by this you mean the View, Next and Prevous Functions menu items. I agree entirely and personal uses this feature of Zeus most of all :)
How about allowing these features to work with C++ operations? I assume it wouldn't be too hard since the "Functions" tagged in the navigator pane shows C and C++ routines.
As you have found the Functions List does not tie up with the function navigation feature. The reasons for this are historic, and basically relate to the fact that function navigation was one of the first features added to Zeus will the ctags function list is one of the last :(

But having said that, it is also possible to re-configure Zeus to work this way :)

First some background. The function navigation is tied directly to the Functions Regexp found in the General of the document type Document Type. To better understand how this works try the following:
  1. Edit C/C++ Document type
  2. Gi to the General section
  3. Enter test as the Functions Regexp
Zeus has now been configure so that only lines containing the word test are recognised as functions. Now this is not much good to anyone, but it does give an idea on how this feature works :)

What happens is when no Functions Regexp is defined, Zeus uses the a set of default c/c++ regexps but when a Functions Regexp is is provided these default regexps are no longer used.

So back to the original question of making these features work for operators functions. To make this work just requires the creation of a new regexp to identify functions. For most languages this is quite easy since they use some sort of function or procedure keyword but for c/c++ it is a little harder.

These are the default c/c++ Zeus regular expressions:

Code: Select all

#define REGEXP_C_FUNC_WITH_RETURN   "^[_a-z0-9]+[ &*\t]+[_a-z0-9 \t]*[_a-z0-9]+[ \t]*[(]+.*[^;]+$"
#define REGEXP_CPP_CTOR_OR_DTOR     "^[_a-z0-9&+=*<>]+[:_a-z0-9&+=*<>~]+[ \t]*[(]+.*[^;]+$"
#define REGEXP_CPP_FUNC_WITH_RETURN "^[_a-z0-9]+[ <&*\t]+[_a-z0-9\t]*[_a-z0-9&+=*<> ]+[:_a-z0-9&+=*<>~]+[ \t]*[(]+.*[^;]+$"
To define a suitable users regexp a good starting point would be to combine these three regular expressions using the ()|() or logic to come up with the following regexp:

Code: Select all

(^[_a-z0-9]+[ &*\t]+[_a-z0-9 \t]*[_a-z0-9]+[ \t]*[(]+.*[^;]+$)|(^[_a-z0-9&+=*<>]+[:_a-z0-9&+=*<>~]+[ \t]*[(]+.*[^;]+$)|(^[_a-z0-9]+[ <&*\t]+[_a-z0-9\t]*[_a-z0-9&+=*<> ]+[:_a-z0-9&+=*<>~]+[ \t]*[(]+.*[^;]+$)
To test this regular expression, open a c/c++ source file, use the Edit, Find menu and run a search using this regular expression. As you repeat the Find every line that is found represents a function. You should observe that the lines containg the operator functions do not get found by this regexp, naturally :)

Thus all that remains is to modify the regexp to also find these operation functions. Then re-edit the document type adding in the new regexp. I can not help you with this last bit since for me the regexp does find the operator function that I used as a test. But if you post a short snippet of the operator function that is failing I will post a new regexp to fix the problem.

Finally, notice how this means you could extend the function navigation to also include the header files. For example this new regexp:

Code: Select all

(^class)|(^struct)|(^[_a-z0-9]+[ &*\t]+[_a-z0-9 \t]*[_a-z0-9]+[ \t]*[(]+.*[^;]+$)|(^[_a-z0-9&+=*<>]+[:_a-z0-9&+=*<>~]+[ \t]*[(]+.*[^;]+$)|(^[_a-z0-9]+[ <&*\t]+[_a-z0-9\t]*[_a-z0-9&+=*<> ]+[:_a-z0-9&+=*<>~]+[ \t]*[(]+.*[^;]+$)
extends the navigation to also work for classes and structures.

Cheers Jussi

Guest

Post by Guest » Mon Nov 22, 2004 2:44 pm

Thanks for the response. I'd like to take you up on your offer. Below, the C functions init and init1 are found but their C++ counterparts are not.

Jack



void bcr_register :: init( SUPERVISOR *supervisor_ptr )
{
}


void init( SUPERVISOR *supervisor_ptr )
{
}



void bcr_register :: init1( SUPERVISOR *supervisor_ptr )
{
}


void init1( SUPERVISOR *supervisor_ptr )
{
}

jussij
Site Admin
Posts: 2449
Joined: Fri Aug 13, 2004 5:10 pm

Post by jussij » Tue Nov 23, 2004 2:38 am

If you look at the original search string:

Code: Select all

(^class)|(^struct)|(^[_a-z0-9]+[ &*\t]+[_a-z0-9 \t]*[_a-z0-9]+[ \t]*[(]+.*[^;]+$)|(^[_a-z0-9&+=*<>]+[:_a-z0-9&+=*<>~]+[ \t]*[(]+.*[^;]+$)|(^[_a-z0-9]+[ <&*\t]+[_a-z0-9\t]*[_a-z0-9&+=*<> ]+[:_a-z0-9&+=*<>~]+[ \t]*[(]+.*[^;]+$)
in particular the last two parts of this search string:

Code: Select all

(^[_a-z0-9&+=*<>]+[:_a-z0-9&+=*<>~]+[ \t]*[(]+.*[^;]+$)
(^[_a-z0-9]+[ <&*\t]+[_a-z0-9\t]*[_a-z0-9&+=*<> ]+[:_a-z0-9&+=*<>~]+[ \t]*[(]+.*[^;]+$)
you will notice the : character is defined to belong in the [:_a-z0-9&+=*<>~] set of characters. There is no space character defined for this set and hence the reason the regular expression fails to find these functions:

Code: Select all

void bcr_register :: init( SUPERVISOR *supervisor_ptr )
void bcr_register :: init1( SUPERVISOR *supervisor_ptr )
Adding the space character to the corresponding sets gives this regular expression:

Code: Select all

(^class)|(^struct)|(^[_a-z0-9]+[ &*\t]+[_a-z0-9 \t]*[_a-z0-9]+[ \t]*[(]+.*[^;]+$)|(^[_a-z0-9&+=*<>]+[ :_a-z0-9&+=*<>~]+[ \t]*[(]+.*[^;]+$)|(^[_a-z0-9]+[ <&*\t]+[_a-z0-9\t]*[_a-z0-9&+=*<> ]+[ :_a-z0-9&+=*<>~]+[ \t]*[(]+.*[^;]+$)
which now finds all the functions :)

Cheers Jussi

Guest

Post by Guest » Tue Nov 23, 2004 1:44 pm

Works great,

Thanks Jussi

Post Reply
kuchnie warszawa opinie

Who is online

Users browsing this forum: No registered users and 23 guests