[cfe-dev] motivations for approaches to macros in Index/IndexingAction.cpp ?
James Widman via cfe-dev
cfe-dev at lists.llvm.org
Mon May 20 14:08:30 PDT 2019
[reposting after accidentally sending to the old cfe address]
Hi all,
I've been playing with the indexstore API and was a little surprised
to find that preprocessor macro definitions are apparently not
considered when generating the hash of a record
(https://github.com/apple/swift-clang/blob/stable/lib/Index/IndexRecordHasher.h).
Was this intentional? And if so, what was the motivation?
I ask because it seems like things are very nearly set up to
incorporate macro definitions/references in an IndexStore record (and
to produce both "symbols" and "occurrences" for macro definitions &
expansions by default when -index-store-path is given to the Clang
driver).
Eric Liu introduced some support for indexing macros
(https://github.com/apple/swift-clang/commit/8576df59f2fe52ae305fdb91b36cbed8946981a1)
but it doesn't seem to intersect with IndexStore "records", and I'm
not sure why...
I guess the idea was that people would only use this via libclang?
(But in that case my question becomes, "why wouldn't you want to
capture this as a regular part of a build?")
Currently, entities from the AST are captured by IndexASTConsumer, an
instance of which is set up by
IndexRecordActionBase::createIndexASTConsumer(), and it seems like
this is the point where there is an opportunity to call
clang::Preprocessor::addPPCallbacks() with a class that overrides:
PPCallbacks::MacroExpands()
PPCallbacks::MacroDefined()
... which would then forward macro definition/expansion events to the
IndexDataRecorder.
If anyone who has worked in this area could comment, that would be
most appreciated!
--James
More information about the cfe-dev
mailing list