xref: /freebsd/contrib/llvm-project/clang/include/clang/Analysis/SelectorExtras.h (revision 0fca6ea1d4eea4c934cfff25ac9ee8ad6fe95583)
1 //=== SelectorExtras.h - Helpers for checkers using selectors -----*- C++ -*-=//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 
9 #ifndef LLVM_CLANG_ANALYSIS_SELECTOREXTRAS_H
10 #define LLVM_CLANG_ANALYSIS_SELECTOREXTRAS_H
11 
12 #include "clang/AST/ASTContext.h"
13 
14 namespace clang {
15 
16 template <typename... IdentifierInfos>
getKeywordSelector(ASTContext & Ctx,const IdentifierInfos * ...IIs)17 static inline Selector getKeywordSelector(ASTContext &Ctx,
18                                           const IdentifierInfos *...IIs) {
19   static_assert(sizeof...(IdentifierInfos) > 0,
20                 "keyword selectors must have at least one argument");
21   SmallVector<const IdentifierInfo *, 10> II({&Ctx.Idents.get(IIs)...});
22 
23   return Ctx.Selectors.getSelector(II.size(), &II[0]);
24 }
25 
26 template <typename... IdentifierInfos>
lazyInitKeywordSelector(Selector & Sel,ASTContext & Ctx,IdentifierInfos * ...IIs)27 static inline void lazyInitKeywordSelector(Selector &Sel, ASTContext &Ctx,
28                                            IdentifierInfos *... IIs) {
29   if (!Sel.isNull())
30     return;
31   Sel = getKeywordSelector(Ctx, IIs...);
32 }
33 
34 } // end namespace clang
35 
36 #endif
37