This is an archive of the discontinued LLVM Phabricator instance.

[ASTMatcher] Add matcher for 'MacroQualifiedType'
ClosedPublic

Authored by danix800 on Aug 12 2023, 6:00 AM.

Details

Summary

Add matcher for 'MacroQualifiedType'

Diff Detail

Event Timeline

danix800 created this revision.Aug 12 2023, 6:00 AM
Herald added a project: Restricted Project. · View Herald TranscriptAug 12 2023, 6:00 AM
danix800 requested review of this revision.Aug 12 2023, 6:00 AM
danix800 updated this revision to Diff 549605.Aug 12 2023, 6:20 AM

Add import of MacroQualifiedType.

danix800 updated this revision to Diff 549607.Aug 12 2023, 6:23 AM
danix800 edited reviewers, added: PiotrZSL, aaron.ballman; removed: shafik.Aug 12 2023, 6:28 AM
aaron.ballman added inline comments.Aug 14 2023, 10:57 AM
clang/include/clang/ASTMatchers/ASTMatchers.h
7261

How about: Matches qualified types when the qualifier is applied via a macro.

and then a second example like:

int * const qual_ptr;

#define nonnull _Nonnull
int * const nonnull macro_qual_ptr;

where we match macro_qual_ptr but not qual_ptr.

clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp
1842–1847

I'd appreciate extra test coverage from the example I posted above.

danix800 added inline comments.Aug 14 2023, 7:45 PM
clang/include/clang/ASTMatchers/ASTMatchers.h
7261

How about: Matches qualified types when the qualifier is applied via a macro.

Forgive my broken English! :-)

and then a second example like:

int * const qual_ptr;

#define nonnull _Nonnull
int * const nonnull macro_qual_ptr;

where we match macro_qual_ptr but not qual_ptr.

Thanks for reminding me of the counter-example, it's critical for better test coverage.

I'll pertain to the original one but with counter-example appended, because the macro
nonnull in this case will not generate a MacroQualifiedType for macro_qual_ptr.

danix800 updated this revision to Diff 550178.Aug 14 2023, 7:58 PM
  1. Improve matcher description
  2. Add a counter-example for test
aaron.ballman accepted this revision.Aug 15 2023, 5:10 AM

LGTM!

clang/include/clang/ASTMatchers/ASTMatchers.h
7261

Forgive my broken English! :-)

There's nothing to forgive! :-)

I'll pertain to the original one but with counter-example appended, because the macro nonnull in this case will not generate a MacroQualifiedType for macro_qual_ptr.

Oh, interesting! (I didn't test my example, so that's neat to learn.)

This revision is now accepted and ready to land.Aug 15 2023, 5:10 AM