DeclAccessPair.h 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. #pragma once
  2. #ifdef __GNUC__
  3. #pragma GCC diagnostic push
  4. #pragma GCC diagnostic ignored "-Wunused-parameter"
  5. #endif
  6. //===--- DeclAccessPair.h - A decl bundled with its path access -*- 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. //
  14. // This file defines the DeclAccessPair class, which provides an
  15. // efficient representation of a pair of a NamedDecl* and an
  16. // AccessSpecifier. Generally the access specifier gives the
  17. // natural access of a declaration when named in a class, as
  18. // defined in C++ [class.access.base]p1.
  19. //
  20. //===----------------------------------------------------------------------===//
  21. #ifndef LLVM_CLANG_AST_DECLACCESSPAIR_H
  22. #define LLVM_CLANG_AST_DECLACCESSPAIR_H
  23. #include "clang/Basic/Specifiers.h"
  24. #include "llvm/Support/DataTypes.h"
  25. namespace clang {
  26. class NamedDecl;
  27. /// A POD class for pairing a NamedDecl* with an access specifier.
  28. /// Can be put into unions.
  29. class DeclAccessPair {
  30. uintptr_t Ptr; // we'd use llvm::PointerUnion, but it isn't trivial
  31. enum { Mask = 0x3 };
  32. public:
  33. static DeclAccessPair make(NamedDecl *D, AccessSpecifier AS) {
  34. DeclAccessPair p;
  35. p.set(D, AS);
  36. return p;
  37. }
  38. NamedDecl *getDecl() const {
  39. return reinterpret_cast<NamedDecl*>(~Mask & Ptr);
  40. }
  41. AccessSpecifier getAccess() const {
  42. return AccessSpecifier(Mask & Ptr);
  43. }
  44. void setDecl(NamedDecl *D) {
  45. set(D, getAccess());
  46. }
  47. void setAccess(AccessSpecifier AS) {
  48. set(getDecl(), AS);
  49. }
  50. void set(NamedDecl *D, AccessSpecifier AS) {
  51. Ptr = uintptr_t(AS) | reinterpret_cast<uintptr_t>(D);
  52. }
  53. operator NamedDecl*() const { return getDecl(); }
  54. NamedDecl *operator->() const { return getDecl(); }
  55. };
  56. }
  57. #endif
  58. #ifdef __GNUC__
  59. #pragma GCC diagnostic pop
  60. #endif