Author Topic: Feature request: Differentiate reads and writes in crossreferencing  (Read 6606 times)

StephenW

  • Senior Community Member
  • Posts: 197
  • Hero Points: 21
One of the truly great features of SlickEdit is tagging and crossreferencing.  I am sure most of us use it every day.  But there are times when I have to go back to using global searches, usually when I am trying to find where a variable is assigned a value.  Some variables are used in a huge number of places, but their value is only read in most of those, and there are maybe one or two places where they are assigned a value.  For finding those assignments where there are say 1000 references and two assignments, the tagging and crossreferencing is pretty useless.  However, since the files are being parsed when they are tagged, I am thinking that it might be possible for that parsing to differentiate between reading and writing of a variable.  If so, I would pay money for a version of SlickEdit that could bring up just the list of assignments, instead of all references.  I am sure that there are a number of pitfalls in this, and that in some languages it would be difficult to do.  And it is certainly not something that I would expect in a point release.  But maybe it could be considered for a major release?

hs2

  • Senior Community Member
  • Posts: 2761
  • Hero Points: 292
Re: Feature request: Differentiate reads and writes in crossreferencing
« Reply #1 on: August 14, 2007, 01:21:46 AM »
This is a big step further than http://community.slickedit.com/index.php?topic=1902.msg8019#msg8019
Both would be fine :)
HS2

Kohei

  • Senior Community Member
  • Posts: 192
  • Hero Points: 25
Re: Feature request: Differentiate reads and writes in crossreferencing
« Reply #2 on: August 14, 2007, 03:18:48 AM »
@StephenW
Funny you should mention this, because I was just wishing for the same thing! :)  And yes, this would be a great enhancement to SE's tagging feature.  So, here is one vote from me. ;)

Graeme

  • Senior Community Member
  • Posts: 2812
  • Hero Points: 347
Re: Feature request: Differentiate reads and writes in crossreferencing
« Reply #3 on: August 14, 2007, 04:08:29 AM »
Couldn't you just write a macro that searched for "variable ="  - or whatever the syntax of the language was for assignment, as you do in the global search.  What would be the advantage of the tagging doing it? 

Would you expect the tagging machine to find assignments that occur via aliases?

Graeme

Kohei

  • Senior Community Member
  • Posts: 192
  • Hero Points: 25
Re: Feature request: Differentiate reads and writes in crossreferencing
« Reply #4 on: August 14, 2007, 06:11:13 PM »
Quote
Couldn't you just write a macro that searched for "variable ="  - or whatever the syntax of the language was for assignment, as you do in the global search.

You could, but that would be extremely slow on a large code base.  Plus it won't be accurate, since the "variable =" pattern may occur in commented areas too as well as areas that are #if 0 #endif ed.

Quote
What would be the advantage of the tagging doing it?

The biggest one would be speed, followed by accuracy.  Because such assignment is already tagged for certain languages, it would make sense to use the tagging engine here, IMO.

Quote
Would you expect the tagging machine to find assignments that occur via aliases?

You mean the alias expansion?  The code gets tagged after the alias gets expanded, so I don't think any special handling is needed for aliases, as far as I know.

Kohei

jbhurst

  • Senior Community Member
  • Posts: 405
  • Hero Points: 33
Re: Feature request: Differentiate reads and writes in crossreferencing
« Reply #5 on: August 14, 2007, 09:05:22 PM »
I think Graeme means "aliases" in the more general sense.

For example:

int i = 0;
int* p = &i;
*p = 1;

Or:

void foo(int& v) {
  v = 1;
}
...
foo(i);

The problem goes well beyond looking for assignments.

John Hurst
Wellington, New Zealand

StephenW

  • Senior Community Member
  • Posts: 197
  • Hero Points: 21
Re: Feature request: Differentiate reads and writes in crossreferencing
« Reply #6 on: August 14, 2007, 10:26:43 PM »
I am not expecting miracles from SlickEdit - in Graeme's examples, all I would expect is that "i = 0" would be cross referenced as a write to i, "int *p = &i" as a write to p and "*p = 1" as a write via p (maybe a separate classification available for pointer/reference variable accesses, versus direct assignments).  "v = 1" similarly would only crossreference as a write via v.  Of course, if SlickEdit could actually match up all the aliasing as well, I would not say no to that feature, but it is not something I would expect it to do.  Especially as the aliasing via pointers can change at run time and can not be actually tracked completely at compile/parse time - remember that using pointers to variables means that the compiler has to drastically tone down the code optimisation it does because of this problem.

The advantage of using the tagging for this sort of crossreferencing is that it uses a parser, and can distinguish between local variable "i" in each of the functions it is used in, for example, rather than just lumping them all together as global search does.  Global search does work OK for for small projects, and where the variable is not used too often.  But the situation I was in that triggered this request happens fairly often - the variable I was looking at has at least 50 uses, and only two places where writes are done.  It is an uncertain business making up a regular expression to find the assignments (for example, ++ changes a variable in C/C++).  But if that information was already in the tag file, the write references would not only be popped up immediately, but you would be much more (but not completely) certain that you had found all of them.

This discussion of aliases leads me to think that the write crossreference list would need to also include the places where a variable got passed as a reference or its address got passed to a pointer parameter, or whatever mechanism is used for the same purpose in each language.  It is certainly not a trivial problem to make this a workable feature, but not an impossible one either.

Dennis

  • Senior Community Member
  • Posts: 3992
  • Hero Points: 520
Re: Feature request: Differentiate reads and writes in crossreferencing
« Reply #7 on: August 15, 2007, 08:43:08 PM »
Just a few historical notes:  Analyzing reads and writes was one of the road blocks that prevented us from going really far with quick refactoring.  To do an accurate job of filtering out reads vs. writes requires a really good expression parser and "l-val" and "r-val" analysis including detecting pass by reference parameters, etc.  Yes, this is a solvable problem, albiet very language dependent, however doing that much additional analysis accurately *and* keeping performance up to high levels is a very hard problem.

How accurate does it have to be?  Unfortunately, we have set a precedent with our handling of C++ and people expect tagging to get everything right.  A 90% solution would just be a support nightmare with a never-ending stream of "if only it also supported this" requests.  Place that on top of the expectation that it should also work for all our our Tier 1 supported langauges, this is a major project.

I'm not saying we'll never do it, but for the time being I believe there are other more immediate places to invest the development cycles.