blob: b11d070c629b492a39ce8e351e8f5dd4d114d63c [file] [log] [blame]
Jordan Rose0675c872014-04-09 01:39:22 +00001//=== 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 Kramer2f5db8b2014-08-13 16:25:19 +000010#ifndef LLVM_CLANG_LIB_STATICANALYZER_CHECKERS_SELECTOREXTRAS_H
11#define LLVM_CLANG_LIB_STATICANALYZER_CHECKERS_SELECTOREXTRAS_H
Jordan Rose0675c872014-04-09 01:39:22 +000012
13#include "clang/AST/ASTContext.h"
Jordan Rose0675c872014-04-09 01:39:22 +000014
15namespace clang {
16namespace ento {
17
Serge Guelton1d993272017-05-09 19:31:30 +000018template <typename... IdentifierInfos>
19static inline Selector getKeywordSelector(ASTContext &Ctx,
20 IdentifierInfos *... IIs) {
21 static_assert(sizeof...(IdentifierInfos),
22 "keyword selectors must have at least one argument");
Serge Gueltone8a3a0a2017-05-10 13:22:11 +000023 SmallVector<IdentifierInfo *, 10> II({&Ctx.Idents.get(IIs)...});
Jordan Rose0675c872014-04-09 01:39:22 +000024
25 return Ctx.Selectors.getSelector(II.size(), &II[0]);
26}
27
Serge Guelton1d993272017-05-09 19:31:30 +000028template <typename... IdentifierInfos>
Jordan Rose0675c872014-04-09 01:39:22 +000029static inline void lazyInitKeywordSelector(Selector &Sel, ASTContext &Ctx,
Serge Guelton1d993272017-05-09 19:31:30 +000030 IdentifierInfos *... IIs) {
Jordan Rose0675c872014-04-09 01:39:22 +000031 if (!Sel.isNull())
32 return;
Serge Guelton1d993272017-05-09 19:31:30 +000033 Sel = getKeywordSelector(Ctx, IIs...);
Jordan Rose0675c872014-04-09 01:39:22 +000034}
35
36static 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