Skip to content

Incorrectly handled foreach style loops #509

Description

@mcserep

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

How to reproduce:

Activity

  1. added this to the Release Flash milestone on Jan 31, 2021
  2. zsofiaschell commented on Oct 27, 2022

    @zsofiaschell

    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.

  3. whisperity commented on Oct 31, 2022

    @whisperity
    Contributor

    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.

  4. mcserep commented on Nov 3, 2022

    @mcserep
    CollaboratorAuthor

    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

  5. zsofiaschell commented on Nov 13, 2022

    @zsofiaschell

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

    example.txt
    ast.txt

  6. zsofiaschell commented on Nov 28, 2022

    @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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

  • Status
    To do

Relationships

None yet

Development

No branches or pull requests

Issue actions