This is an archive of the discontinued LLVM Phabricator instance.

[clangd] Handle references for patched macros
AbandonedPublic

Authored by kadircet on May 19 2020, 7:15 AM.

Details

Reviewers
None
Summary

Depends on D80198.

Macro references in main file are collected separetely and stored as a
map from macro's symbol id to reference ranges. Those ranges are
computed inside PPCallbacks, hence we don't have access to TokenBuffer.

In presence of patched macro definitions, this symbol id is computed
from the definition inside the patch, rather than the definition inside
the preamble section. Also the ranges for occurences inside the patch
would be off for similar reasons.

Hence when we try to findReferences for a macro defined in main file we
either need to:
- Make use of definition inside the patch, rather than the real
  definition inside the preamble section.
- Lex preamble section while collecting main file references to figure
  out macro's real location and attribute references to it.

The former implies that we will miss all the references inside the
patch. But it doesn't introduce any new logic. We basically get all the
references inside main file section for free.

The latter doesn't trade any accuracy, we'll get all the references
including the ones inside the preamble section. But requires either:
- Lexing the preamble section to figure out "real range" of a patched
  macro definition
- Postponing range/location calculations until a later step in which we
  have access to tokenbuffers.

This patch trades some accuracy in favor of code complexity, and just
uses the definition inside the patch when we are looking for references
of a macro.

Diff Detail