SelectorExtras.h 2.0 KB

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