Author Topic: Limiting cross-reference to where variable is updated  (Read 1668 times)

pauljb

  • New Community Member
  • Posts: 2
  • Hero Points: 0
Limiting cross-reference to where variable is updated
« on: June 20, 2015, 02:50:49 pm »
When doing a cross-reference on a variable, is it possible to only see the cases where the variable is being actually set or updated (instead of seeing every single reference to the variable) ?

hs2

  • Senior Community Member
  • Posts: 2738
  • Hero Points: 288
Re: Limiting cross-reference to where variable is updated
« Reply #1 on: June 20, 2015, 03:33:42 pm »

pauljb

  • New Community Member
  • Posts: 2
  • Hero Points: 0
Re: Limiting cross-reference to where variable is updated
« Reply #2 on: June 20, 2015, 06:26:29 pm »
Thanks for the quick reply.
Just wanted to make sure I was not missing something that was already supported...

Clark

  • SlickEdit Team Member
  • Senior Community Member
  • *
  • Posts: 4964
  • Hero Points: 409
Re: Limiting cross-reference to where variable is updated
« Reply #3 on: June 21, 2015, 09:02:45 pm »
This would be an awesome feature. Especially when there are tons of references. For ambiguous or indecipherable cases, it would need to error on the side of listing it.

LBCEi

  • Senior Community Member
  • Posts: 188
  • Hero Points: 14
Re: Limiting cross-reference to where variable is updated
« Reply #4 on: June 22, 2015, 01:48:08 am »
This might be a nice feature to augment 'find references' by limiting the references to those that actually change the value of the variable.  For most common usage this would be equivalent to searching for varname<optional_whitespace>=<optional_whitespace>.  But this could also be augmented with *=, +=, etc. as well as varname++, -- (and ++varname, etc).  It might also be nice to find references that involved 'addressof' and 'deference' operators.

In the past, when looking for this type of 'reference', I've just used appropriate regex searches.

hs2

  • Senior Community Member
  • Posts: 2738
  • Hero Points: 288
Re: Limiting cross-reference to where variable is updated
« Reply #5 on: June 22, 2015, 05:37:16 am »
Thinking about it I afraid it's pretty hard to implement a generally useful feature like this.
It'd be surely nice with larger code bases with lot's of simple (integer, pointer, etc) global variables.
But in my experience there are very few such code bases.
Also when thinking of (C++) objects as variables it gets more difficult to determine 'value changing operations' incl. straight assignments to narrow down the 'find references' results accordingly.
I'm also not sure how this applies to other languages.. Well, maybe the creative SE guys have a good idea about it :)
Making 'find references' smarter than grep is and will be a really hard job ..
HS2

Dennis

  • SlickEdit Team Member
  • Senior Community Member
  • *
  • Posts: 2831
  • Hero Points: 429
Re: Limiting cross-reference to where variable is updated
« Reply #6 on: June 22, 2015, 03:51:42 pm »
It takes compiler-level static analysis to determine when a reference to a variable could potentially represent a modification.  This has been the hold-up for this feature.  It would be fairly simple to augment the current engine to strictly screen for assignments, but the actual value of that would be questionable at best.

Examples of hard cases:
1) non-const object calls non-const method (made worse by coders who refuse to use const in the first place).
2) variable passed to function by non-const reference (could be assigned to in function, or could just be to avoid copy)
3) assigning a variable to any other non-const reference type

The secondary part that is tricky is making the GUI really good at turning on and off the option without cluttering the references tool window.  Obviously, if you leave the option on and forget about it, you are going to think you are missing a lot of references.