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
10#ifndef LLVM_CLANG_LIB_STATICANALYZER_CHECKERS_SELECTOREXTRAS_H
11#define LLVM_CLANG_LIB_STATICANALYZER_CHECKERS_SELECTOREXTRAS_H
12
13#include "clang/AST/ASTContext.h"
14#include <cstdarg>
15
16namespace clang {
17namespace ento {
18
19static inline Selector getKeywordSelectorImpl(ASTContext &Ctx,
20                                              const char *First,
21                                              va_list argp) {
22  SmallVector<IdentifierInfo*, 10> II;
23  II.push_back(&Ctx.Idents.get(First));
24
25  while (const char *s = va_arg(argp, const char *))
26    II.push_back(&Ctx.Idents.get(s));
27
28  return Ctx.Selectors.getSelector(II.size(), &II[0]);
29}
30
31static inline Selector getKeywordSelector(ASTContext &Ctx, va_list argp) {
32  const char *First = va_arg(argp, const char *);
33  assert(First && "keyword selectors must have at least one argument");
34  return getKeywordSelectorImpl(Ctx, First, argp);
35}
36
37LLVM_END_WITH_NULL
38static inline Selector getKeywordSelector(ASTContext &Ctx,
39                                          const char *First, ...) {
40  va_list argp;
41  va_start(argp, First);
42  Selector result = getKeywordSelectorImpl(Ctx, First, argp);
43  va_end(argp);
44  return result;
45}
46
47LLVM_END_WITH_NULL
48static inline void lazyInitKeywordSelector(Selector &Sel, ASTContext &Ctx,
49                                           const char *First, ...) {
50  if (!Sel.isNull())
51    return;
52  va_list argp;
53  va_start(argp, First);
54  Sel = getKeywordSelectorImpl(Ctx, First, argp);
55  va_end(argp);
56}
57
58static inline void lazyInitNullarySelector(Selector &Sel, ASTContext &Ctx,
59                                           const char *Name) {
60  if (!Sel.isNull())
61    return;
62  Sel = GetNullarySelector(Name, Ctx);
63}
64
65} // end namespace ento
66} // end namespace clang
67
68#endif
69