CodeCompass icon indicating copy to clipboard operation
CodeCompass copied to clipboard

Incorrectly handled foreach style loops

Open mcserep opened this issue 4 years ago • 5 comments

It seems CodeCompass handles foreach style for loops incorrectly when clicking on the enumerated variable.

How to reproduce:

  • In the PCL source code click on centroids_ in line 97. or on centroid in line 101. In the InfoTree, the complete functions is shown, and the goto definition feature also work in correctly. https://codecompass.net/demo/#wsid=PCL&fid=16855117887643076224&select=97|1|98|1&center=text
  • In the CodeCompass source click _ctx.fileStatus in line 358. to get the very same issue: https://codecompass.net/demo/#wsid=CodeCompass&fid=3022161984525021070&select=358|1|359|1&center=text

mcserep avatar Jan 31 '21 13:01 mcserep

The problem only occurs, when clicking in a for cycle. If clicking on the same parameter somewhere else, it works perfectly. A C++11 Range-Based For-Loop is represented by CXXForRangeStmt.

zsofiaschell avatar Oct 27 '22 20:10 zsofiaschell

This is still a bit weird. If the foreach is not in a lambda (#583) then right now then examples from CodeCompass itself work for me (Firefox, Ubuntu): Clicking loop variable inside the loop highlights all use cases and the definition (Note that the syntax highlight is wonky.)

However, clicking on the iterable of the foreach, now that is definitely broken: Clicking on iterable (input of the loop) does not highlight anything, and the InfoTree is filled with junk Clicking on the iterable somewhere else highlights all occurrences, but the loop.


The PCL source code's parsing status broke since the creation of the ticket.

whisperity avatar Oct 31 '22 13:10 whisperity

The PCL source code's parsing status broke since the creation of the ticket.

@whisperity Fixed it, the dependencies changed a little bit. The corresponding lines are 94 and 98 now. https://codecompass.net/demo/#wsid=PCL&fid=16855117887643076224

mcserep avatar Nov 03 '22 09:11 mcserep

Tried to reproduce the issue on a smaller project. I will attach the example code and the ast.

example.txt ast.txt

zsofiaschell avatar Nov 13 '22 22:11 zsofiaschell

Hi! Created another example without using std and the iostream include (see in the attachments).

I found in clang's AstVisitor functions named TraverseForStmt and TraverseCXXForRangeStmt:

  • bool TraverseForStmt(clang::ForStmt *forStmt)
  • bool TraverseCXXForRangeStmt (clang::CXXForRangeStmt *forRangeStmt).

I think we will need the second one for the foreach cycle, maybe.

example_code.txt ast_new.txt

zsofiaschell avatar Nov 28 '22 13:11 zsofiaschell