I'm trying to match objc @import
declarations using AST-matchers for a custom tool I'm creating; I'm using Result.Context->local_imports()
but although I have @import
statements in my source code and I'm passing the fmodules
flag, the iterator returned from local_imports
is always empty. Any ideas how I could achieve this?
Asked
Active
Viewed 71 times
2

Valeriy Savchenko
- 1,524
- 8
- 19

Andrespch
- 370
- 3
- 16
-
I don't have any experience with Objective-C, so I don't really know much about how it works. I tried to dump AST for hello world example and, first of all, it's huge (!), and there is no single `ImportDecl` in there. – Valeriy Savchenko Jun 05 '19 at 20:15
-
hey @ValeriySavchenko, thanks for looking into it, did you pass the flag `-fmodules` to the dump command? – Andrespch Jun 06 '19 at 07:06
-
yes, that was the reason. Now I can see `ImportDecl`. Did you try traversing all top-level declarations instead of using `local_imports`? – Valeriy Savchenko Jun 06 '19 at 07:37
-
hey @ValeriySavchenko, I tried using a RecursiveASTVisitor but that didn't help :( somehow there are no `ImportDecl` for the translation unit – Andrespch Jun 06 '19 at 11:21
-
How do you run your clang tool? What happens if you dump AST for `TrasnslationUnitDecl`? – Valeriy Savchenko Jun 06 '19 at 11:28
-
I'm running it just like you wuold run `clang-format` or any other tool. I'm also including the `-fmodules` flag. I just dumped the `TranslationUnitDecl` and interestingly enough the `ImportDecl` is also not returned... why would the clang `ast-dump` command behave different than my tool? @ValeriySavchenko – Andrespch Jun 06 '19 at 11:52
-
Just to be clear: you run it somewhat like this: `clang-tool test.m -- -fmodules`? – Valeriy Savchenko Jun 06 '19 at 13:36
-
exactly @ValeriySavchenko, but dumping wont return `ImportDecl` :( doing `clang -Xclang -ast-dump -fmodules test.m` does – Andrespch Jun 06 '19 at 15:38
-
One advice here left is to generate `compile_commands.json` and see what happens when Clang takes care of its own command line arguments. – Valeriy Savchenko Jun 06 '19 at 15:44
-
thanks @ValeriySavchenko I will consider that. – Andrespch Jun 07 '19 at 09:37