1

Lets say I have such code:

A* a = [[A alloc] init];
B* _Null_unspecified b = [[B alloc] init];
C* _Nullable c = [[C alloc] init];
D* _Nonnull d = [[D alloc] init];

Now, I want to create a matcher to match variables declaration.

Currently I have something like this:

StatementMatcher NullUnspecifiedMatcher = 
  declStmt(hasSingleDecl(varDecl(hasType(objcObjectPointerType()))))`

There is objcObjectPointerType() but it matches only a. There are some pointers/references matchers, but they don't work on those variable declarations at all. Also, I tried isAnyPointer() but it works on any pointer, obj-c or not.

I tried type() to ensure, that I'm doing everything correctly, and it works.

So, how can I match only obj-c variable declarations, with or without nullability specifier?

Thanks!

Alfred Zien
  • 1,025
  • 1
  • 11
  • 31
  • I said this on the mailing list to this question, but I'll repeat it here. Often a good way to learn what types of methods you should be looking for is to write a simple example and dump the AST: clang -Xclang -ast-dump -fsyntax-only – xaxxon Sep 16 '16 at 20:57
  • One thing to try, and it may not be that palatable, but is to just get all the variable declarations and test them yourself with the C++ API instead of using a Matcher. It can be more work, and not as stable across clang releases, but sometimes it's what you're left with. – xaxxon Sep 16 '16 at 20:59

0 Answers0