SelectorExtras.h 1.4 KB

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