SlickEdit Community

SlickEdit Product Discussion => SlickEdit® => Topic started by: joecar on February 09, 2021, 06:47:48 PM

Title: References shows only local usage
Post by: joecar on February 09, 2021, 06:47:48 PM
hotfix_se2501_1_cumulative

When I do Goto Reference from a usage, the Reference pane shows only that usage. What am I doing wrong?

When I do Goto Reference from the declaration/definition, the Reference pane shows all instances (declaration/definition and usages).

Thanks.


Title: Re: References shows only local usage
Post by: joecar on February 09, 2021, 06:56:18 PM
Filter is set to show all tags.
Title: Re: References shows only local usage
Post by: Dennis on February 09, 2021, 08:15:28 PM
Can you put together a small example I could reproduce that with?  Also, make sure "Look in:" is not set to "<Current File>"
Title: Re: References shows only local usage
Post by: joecar on February 10, 2021, 12:33:57 AM
"Look in:" is set to "<Current Workspace>".

As I put together small examples for you, they seem to work properly...  ::)
Title: Re: References shows only local usage
Post by: joecar on February 10, 2021, 12:44:40 AM
It also happens when "Look in" is set to "<All Open Files>"

and the files containing the declarations/definitions are open.
Title: Re: References shows only local usage
Post by: joecar on February 10, 2021, 09:39:26 AM
Here is a pic (I had to obfuscate the details), see attached.

I'm still working on a simple example that shows the problem.
Title: Re: References shows only local usage
Post by: Dennis on February 10, 2021, 03:29:58 PM
It appears that the definition is "static inline" but in a separate file.  Is that correct?  What is the file extension on that file?  We do have a special case to treat static functions in a ".h*" file as an extern function, but otherwise, a static definition is limited to the scope of the module it is declared in.

Some folks have suggested working around this by defining a preprocessor macro like #define STATIC_IN_HEADER static, which I can declare to SlickEdit as an empty #define in the C/C++ Proprocessor setup, and using that instead of using the static keyword directly in header files.
Title: Re: References shows only local usage
Post by: joecar on February 10, 2021, 07:07:18 PM
Thanks.

That static inline is in the same file at line 748 (see Search Results pane in pic posted above), and is referenced at lines 916, 932, 956.

It is happening regardless of inline, and in the same or other files, but not for all cases.

I'm still working on a suitable simple example to show this behaviour.
Title: Re: References shows only local usage
Post by: joecar on February 10, 2021, 07:21:45 PM
I should have said files are .c or .h.

Also note:
Goto Definition and Goto Declaration work ok.
Goto References from definition/declaration works ok (shows all instances/usages).

Title: Re: References shows only local usage
Post by: Dennis on February 10, 2021, 09:27:37 PM
The good news for a case like that is it appears to be restricted to that single file.  In fact, if you opened SlickEdit with a default configuration and the opened just that file, hopefully, you would get the same result.  Then all you need to do is whittle that file down to the bare bones and rename and/or obfuscate the rest.

You could try the attached macro (which I will add to SlickEdit for 25.0.2) to do the obfuscation.
Title: Re: References shows only local usage
Post by: joecar on February 11, 2021, 12:21:15 AM
Quote
. . .
More info:
When the usage assigns the return value to a variable, Goto References works properly.
When the usage does not assign the return value, Goto Refrences shows only the usage.
I have found this, but I have also found cases where this does not matter.
Title: Re: References shows only local usage
Post by: joecar on February 11, 2021, 06:21:42 PM
Obfuscated file attached.

Look for function sL60C().
Doing Goto References from line 738 produces 4 references.
Doing Goto References from lines 877, 891, 911 produces only 1 reference.
In this case, the function is defined within the same file as its usages (there are cases where this is not so).
Title: Re: References shows only local usage
Post by: joecar on February 12, 2021, 10:29:44 AM
BTW: Thanks for the file obfuscator, it does a very good job and includes strings and comments  ;)
Title: Re: References shows only local usage
Post by: vandermyer on February 12, 2021, 11:25:35 AM
I don't know if this is related, but I have also found an example where the references is funny. In the simple example, try 'Find References' on the function called 'ReferencesOdd' and on the single use of this function in the function 'Func1'. In the first case I get three results: the function, the prototype and the use. In the second case, I only get the use. The other odd thing is, when I Preview the function, I get the function and prototype when I click on the definition; when I click on the use I get the function and two prototypes, one with '()' and one with '(void)' as the parameter list.
Title: Re: References shows only local usage
Post by: Dennis on February 12, 2021, 09:50:55 PM
REVISED

@joecar:  I was able to reproduce this only by adding the file to a project,
     and turning on Document > C/C++ Options... > C/C++ Parsing Options,
     "Tag function prototypes with no return type" = ON

     Is this an option you need to have enabled?

@vandermyer:  I can also reproduce your case, likewise, only if I turn on
     Document > ANSI-C Options... > C/C++ Parsing Options > Tag function prototypes with no return type

I am putting together a hot fix to help references work better knowing that there are false-positives,
locally tagged prototypes with no return type.

I will also make some improvements to the parser for how we handle that archaic option for 25.0.2.
Title: Re: References shows only local usage
Post by: joecar on February 13, 2021, 12:22:58 PM
REVISED

@joecar:  I was able to reproduce this only by adding the file to a project,
     and turning on Document > C/C++ Options... > C/C++ Parsing Options,
     "Tag function prototypes with no return type" = ON

     Is this an option you need to have enabled?
. . .
I already have that enabled.
Title: Re: References shows only local usage
Post by: joecar on February 13, 2021, 12:59:11 PM
I think I have a simple example that shows the problem, see attached zip file containing files main.c and test.c.

main.c makes calls to functions defined in test.c.

Some of the calls in main.c are missing the parameter; doing Goto References from any of call where some instance of that call (that one or another) is missing the parameter produces only local instances.

Doing Goto References from test.c produces all instances (even the ones with missing parameter).

Try doing all 6 Goto References from main.c and compare with doing all 6 Goto References from test.c

LoL, I hope I got it right  ;D
Title: Re: References shows only local usage
Post by: joecar on February 13, 2021, 01:14:37 PM
See updated attached zip (main.c, test.c), lol this one compiles and runs (using Visual Studio 2019).
Title: Re: References shows only local usage
Post by: Dennis on February 13, 2021, 06:35:32 PM
Quote
Document > C/C++ Options... > C/C++ Parsing Options > Tag function prototypes with no return type

I already have that enabled.

The problem was that feature was enabled.  Do you really want that?
Title: Re: References shows only local usage
Post by: joecar on February 14, 2021, 04:31:09 AM
Quote
Document > C/C++ Options... > C/C++ Parsing Options > Tag function prototypes with no return type

I already have that enabled.

The problem was that feature was enabled.  Do you really want that?
I'll try that, thanks.
Title: Re: References shows only local usage
Post by: joecar on February 15, 2021, 12:02:36 AM
Quote
Document > C/C++ Options... > C/C++ Parsing Options > Tag function prototypes with no return type

I already have that enabled.

The problem was that feature was enabled.  Do you really want that?
I disabled that and references are now working correctly, thanks, appreciate your help :)

Is there a way to save to file the current options/configuration (i.e. might want different C/C++ config for different projects)...?
Title: Re: References shows only local usage
Post by: vandermyer on February 15, 2021, 09:03:03 AM
Thanks for the fast response. Turning off option you mention seems to resolve the issue.