File indexing completed on 2026-05-10 08:36:56
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013 #ifndef LLVM_CLANG_LEX_EXTERNALPREPROCESSORSOURCE_H
0014 #define LLVM_CLANG_LEX_EXTERNALPREPROCESSORSOURCE_H
0015
0016 #include <cassert>
0017 #include <cstdint>
0018
0019 namespace clang {
0020
0021 class IdentifierInfo;
0022 class Module;
0023
0024
0025
0026
0027
0028
0029 class ExternalPreprocessorSource {
0030 public:
0031 virtual ~ExternalPreprocessorSource();
0032
0033
0034 virtual void ReadDefinedMacros() = 0;
0035
0036
0037 virtual void updateOutOfDateIdentifier(const IdentifierInfo &II) = 0;
0038
0039
0040
0041
0042 virtual IdentifierInfo *GetIdentifier(uint64_t ID) = 0;
0043
0044
0045 virtual Module *getModule(unsigned ModuleID) = 0;
0046 };
0047
0048
0049
0050 class LazyIdentifierInfoPtr {
0051
0052
0053 mutable uint64_t Ptr = 0;
0054
0055 public:
0056 LazyIdentifierInfoPtr() = default;
0057
0058 explicit LazyIdentifierInfoPtr(const IdentifierInfo *Ptr)
0059 : Ptr(reinterpret_cast<uint64_t>(Ptr)) {}
0060
0061 explicit LazyIdentifierInfoPtr(uint64_t ID) : Ptr((ID << 1) | 0x01) {
0062 assert((ID << 1 >> 1) == ID && "ID must require < 63 bits");
0063 if (ID == 0)
0064 Ptr = 0;
0065 }
0066
0067 LazyIdentifierInfoPtr &operator=(const IdentifierInfo *Ptr) {
0068 this->Ptr = reinterpret_cast<uint64_t>(Ptr);
0069 return *this;
0070 }
0071
0072 LazyIdentifierInfoPtr &operator=(uint64_t ID) {
0073 assert((ID << 1 >> 1) == ID && "IDs must require < 63 bits");
0074 if (ID == 0)
0075 Ptr = 0;
0076 else
0077 Ptr = (ID << 1) | 0x01;
0078
0079 return *this;
0080 }
0081
0082
0083
0084
0085 bool isValid() const { return Ptr != 0; }
0086
0087
0088 bool isID() const { return Ptr & 0x01; }
0089
0090 IdentifierInfo *getPtr() const {
0091 assert(!isID());
0092 return reinterpret_cast<IdentifierInfo *>(Ptr);
0093 }
0094
0095 uint64_t getID() const {
0096 assert(isID());
0097 return Ptr >> 1;
0098 }
0099 };
0100 }
0101
0102 #endif