Author Topic: SE 20.0.2.1 does not find all references when braces in func at col 0  (Read 1369 times)

rowbearto

  • Senior Community Member
  • Posts: 1343
  • Hero Points: 100
I have found that SE is not finding all references when there is bad indenting in C++ code.

I have attached example code and also show it at the bottom of this message.

If "isPucCur" is highlighted and press "Ctrl+/", then in the first function, calc1(), only the declaration is found, the other uses are not found!

But if I change the indenting of the "if", as done in calc2(), highlight "isPucCurr" and press Ctrl+/, now it finds all references.

This is very annoying. I suppose I could beautify the file as a workaround, however there are many complications doing so.

The complication is that I am not responsible for this code, it is written and maintained by other developers who do not use SlickEdit. So I'm not able to commit the changes myself.  However, I am a consumer of this code, and when I think it has a bug I make local modifications (but I cannot commit them, but I can suggest to the developers how to change). If I beautify the code as a workaround, then when I do a comparison of my changed file vs the reference file, so that I can show the developers the required changes, then all the beautification changes are also introduced. I could use my diff tool, Beyond Compare, to do the compare, as it can ignore minor differences, but then when I present the developers with my suggested changes, I will need to make another copy of the reference file with only my modifications, so kind of annoying.

I also work on a large code base that is modified by hundreds of developers who do not always indent properly. We use clearcase so all files are write-protected. I would need to perform large checkouts in order to beautify all source files, and if I deliver them into clearcase, the change of indenting can cause rebase conflicts when other developers rebase, so it is not really a good solution. I need to be able to browse the existing code base without having to beautify it.

This also happens in SE 20.0.1.3.

It would be best if SE's find references functionality did not trip up with bad indenting.

Below is the example code, and it is also attached.

Code: [Select]
// Example of not found with poorly indented if statement
int calc1(const int uid)
{
  // HIGHLIGHT the "isPucCur" and press Ctrl+/
  // only the declaration is found, the other uses are not found.
  const bool isPucCur    = true;

#ifdef DEBUG
if( uid == 4 )
{
  printf ("\n\n=============================================================\n");
  printf ("=============================================================\n");
}
#endif

  if ( isPucCur )
  {
    isPucCur = false;
  }
}

// Example of references found when if properly indented.
int calc2(const int uid)
{
  // HIGHLIGHT the "isPucCur" and press Ctrl+/
  // now all references are found
  const bool isPucCur    = true;

#ifdef DEBUG
  if( uid == 4 )
  {
    printf ("\n\n=============================================================\n");
    printf ("=============================================================\n");
  }
#endif

  if ( isPucCur )
  {
    isPucCur = false;
  }
}
« Last Edit: May 02, 2016, 12:16:52 am by rowbearto »

rowbearto

  • Senior Community Member
  • Posts: 1343
  • Hero Points: 100
SE 20.0.2.1 does not find all references when braces in func at col 0
« Reply #1 on: May 02, 2016, 12:16:15 am »
After some experimenting, I have found that the issue seems caused by putting braces in column 0.

If "if" statement is removed, but braces still in column 0, still have the issue.

If braces moved into column 1, issue goes away.

There is much of this in the codebase I am browsing. Would be great if this issue was fixed.

Dennis

  • SlickEdit Team Member
  • Senior Community Member
  • *
  • Posts: 2629
  • Hero Points: 405
This comes up about once a year, usually less.

Here's the thing.  The parser is designed to be used in an editor, and people edit code in an editor, and frequently in the course of those events, braces are left mismatched (Please refer to all the posts from users complaining about SlickEdit completing code for them, specifically, inserting matching closing braces, there are good reasons, besides making it easier to type code that we do that.).  The parser takes advantage of the fact that it can frequently recover from a situation where it is lost if it detects a brace in column 1, it knows that in a most of C/C++ code, that only happens at the end of the current function definition, so the parser treats it as such.

There is an option, however, the default is off, to turn off this behavior.  Macro > Set Macro Variable... > def_ctags_flags = 10 (The default is 2).  This will defeat the brace 1 logic and allow the parser to get arbitrarily lost when you leave a brace mismatched.

rowbearto

  • Senior Community Member
  • Posts: 1343
  • Hero Points: 100
Thanks Dennis for the explanation. That does indeed solve the problem. I prefer having a closing brace created whenever opening brace is created, so setting to 10 is fine for me.

That does indeed solve the issue. I needed to restart SE for it to take effect.

Question: If I am exporting/importing my configuration, does this setting get transferred this way, or do I need to manually apply this macro variable if I move to a different machine?

Dennis

  • SlickEdit Team Member
  • Senior Community Member
  • *
  • Posts: 2629
  • Hero Points: 405
For the current release, yes.  For the next major release, I am adding these options to the C/C++ Language options, so you will be able to migrate them easily.