Jordan Rose | 0675c87 | 2014-04-09 01:39:22 +0000 | [diff] [blame] | 1 | //=== SelectorExtras.h - Helpers for checkers using selectors -----*- C++ -*-=// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | |
Benjamin Kramer | 2f5db8b | 2014-08-13 16:25:19 +0000 | [diff] [blame] | 10 | #ifndef LLVM_CLANG_LIB_STATICANALYZER_CHECKERS_SELECTOREXTRAS_H |
| 11 | #define LLVM_CLANG_LIB_STATICANALYZER_CHECKERS_SELECTOREXTRAS_H |
Jordan Rose | 0675c87 | 2014-04-09 01:39:22 +0000 | [diff] [blame] | 12 | |
| 13 | #include "clang/AST/ASTContext.h" |
Jordan Rose | 0675c87 | 2014-04-09 01:39:22 +0000 | [diff] [blame] | 14 | |
| 15 | namespace clang { |
| 16 | namespace ento { |
| 17 | |
Serge Guelton | 1d99327 | 2017-05-09 19:31:30 +0000 | [diff] [blame] | 18 | template <typename... IdentifierInfos> |
| 19 | static inline Selector getKeywordSelector(ASTContext &Ctx, |
| 20 | IdentifierInfos *... IIs) { |
| 21 | static_assert(sizeof...(IdentifierInfos), |
| 22 | "keyword selectors must have at least one argument"); |
Serge Guelton | e8a3a0a | 2017-05-10 13:22:11 +0000 | [diff] [blame] | 23 | SmallVector<IdentifierInfo *, 10> II({&Ctx.Idents.get(IIs)...}); |
Jordan Rose | 0675c87 | 2014-04-09 01:39:22 +0000 | [diff] [blame] | 24 | |
| 25 | return Ctx.Selectors.getSelector(II.size(), &II[0]); |
| 26 | } |
| 27 | |
Serge Guelton | 1d99327 | 2017-05-09 19:31:30 +0000 | [diff] [blame] | 28 | template <typename... IdentifierInfos> |
Jordan Rose | 0675c87 | 2014-04-09 01:39:22 +0000 | [diff] [blame] | 29 | static inline void lazyInitKeywordSelector(Selector &Sel, ASTContext &Ctx, |
Serge Guelton | 1d99327 | 2017-05-09 19:31:30 +0000 | [diff] [blame] | 30 | IdentifierInfos *... IIs) { |
Jordan Rose | 0675c87 | 2014-04-09 01:39:22 +0000 | [diff] [blame] | 31 | if (!Sel.isNull()) |
| 32 | return; |
Serge Guelton | 1d99327 | 2017-05-09 19:31:30 +0000 | [diff] [blame] | 33 | Sel = getKeywordSelector(Ctx, IIs...); |
Jordan Rose | 0675c87 | 2014-04-09 01:39:22 +0000 | [diff] [blame] | 34 | } |
| 35 | |
| 36 | static inline void lazyInitNullarySelector(Selector &Sel, ASTContext &Ctx, |
| 37 | const char *Name) { |
| 38 | if (!Sel.isNull()) |
| 39 | return; |
| 40 | Sel = GetNullarySelector(Name, Ctx); |
| 41 | } |
| 42 | |
| 43 | } // end namespace ento |
| 44 | } // end namespace clang |
| 45 | |
| 46 | #endif |