Skip to content
This repository was archived by the owner on Jul 30, 2020. It is now read-only.
This repository was archived by the owner on Jul 30, 2020. It is now read-only.

Indexing references in macro replacement-list #331

@MaskRay

Description

@MaskRay
int foo(int);
#define A(x) foo(x) + foo(x)  // hover on `foo`, it jumps to the def of `foo`

int bar(int x) {
  return A(x);
}

rtags is able to attribute references of foo to the two occurrences of foo in A(x)'s body.

Its implementation
https://github.com/Andersbakken/rtags/blob/d776fbfadfd0f9ad8244f741154a28fa31f5fe82/src/ClangIndexer.cpp#L1055
https://github.com/Andersbakken/rtags/blob/d776fbfadfd0f9ad8244f741154a28fa31f5fe82/src/ClangIndexer.cpp#L1647

If my understanding is correct:

  • parse the translation unit with CXTranslationUnit_DetailedPreprocessingRecord
  • upon CXCursor_MacroDefinition, retrieve the macro replacement-list and tokenize them, store in some form like {"foo":[loc0, loc1], "x":[loc2,loc3]}
  • upon CXCursor_MacroExpansion, record the source location as an occurrence of the macro
  • while traversing the AST, if the source location appears in the previous step, see if the token occurred in the CXCursor_MacroDefinition step, also attribute the reference to the macro body.

Its nested loop is very inefficient and the design does not work for macros than need to be expanded more than once. This also looks too complicated to me.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions