| 1 | |
| 2 | |
| 3 | |
| 4 | |
| 5 | |
| 6 | |
| 7 | |
| 8 | |
| 9 | |
| 10 | |
| 11 | |
| 12 | |
| 13 | |
| 14 | #ifndef LLVM_CLANG_SEMA_IDENTIFIERRESOLVER_H |
| 15 | #define LLVM_CLANG_SEMA_IDENTIFIERRESOLVER_H |
| 16 | |
| 17 | #include "clang/Basic/LLVM.h" |
| 18 | #include "llvm/ADT/SmallVector.h" |
| 19 | #include <cassert> |
| 20 | #include <cstddef> |
| 21 | #include <cstdint> |
| 22 | #include <iterator> |
| 23 | |
| 24 | namespace clang { |
| 25 | |
| 26 | class Decl; |
| 27 | class DeclarationName; |
| 28 | class DeclContext; |
| 29 | class IdentifierInfo; |
| 30 | class LangOptions; |
| 31 | class NamedDecl; |
| 32 | class Preprocessor; |
| 33 | class Scope; |
| 34 | |
| 35 | |
| 36 | |
| 37 | |
| 38 | class IdentifierResolver { |
| 39 | |
| 40 | |
| 41 | |
| 42 | |
| 43 | class IdDeclInfo { |
| 44 | public: |
| 45 | using DeclsTy = SmallVector<NamedDecl *, 2>; |
| 46 | |
| 47 | DeclsTy::iterator decls_begin() { return Decls.begin(); } |
| 48 | DeclsTy::iterator decls_end() { return Decls.end(); } |
| 49 | |
| 50 | void AddDecl(NamedDecl *D) { Decls.push_back(D); } |
| 51 | |
| 52 | |
| 53 | |
| 54 | void RemoveDecl(NamedDecl *D); |
| 55 | |
| 56 | |
| 57 | void InsertDecl(DeclsTy::iterator Pos, NamedDecl *D) { |
| 58 | Decls.insert(Pos, D); |
| 59 | } |
| 60 | |
| 61 | private: |
| 62 | DeclsTy Decls; |
| 63 | }; |
| 64 | |
| 65 | public: |
| 66 | |
| 67 | |
| 68 | |
| 69 | class iterator { |
| 70 | public: |
| 71 | friend class IdentifierResolver; |
| 72 | |
| 73 | using value_type = NamedDecl *; |
| 74 | using reference = NamedDecl *; |
| 75 | using pointer = NamedDecl *; |
| 76 | using iterator_category = std::input_iterator_tag; |
| 77 | using difference_type = std::ptrdiff_t; |
| 78 | |
| 79 | |
| 80 | |
| 81 | |
| 82 | |
| 83 | uintptr_t Ptr = 0; |
| 84 | using BaseIter = IdDeclInfo::DeclsTy::iterator; |
| 85 | |
| 86 | |
| 87 | iterator(NamedDecl *D) { |
| 88 | Ptr = reinterpret_cast<uintptr_t>(D); |
| 89 | (0) . __assert_fail ("(Ptr & 0x1) == 0 && \"Invalid Ptr!\"", "/home/seafit/code_projects/clang_source/clang/include/clang/Sema/IdentifierResolver.h", 89, __PRETTY_FUNCTION__))" file_link="../../../../include/assert.h.html#88" macro="true">assert((Ptr & 0x1) == 0 && "Invalid Ptr!"); |
| 90 | } |
| 91 | |
| 92 | |
| 93 | |
| 94 | iterator(BaseIter I) { |
| 95 | Ptr = reinterpret_cast<uintptr_t>(I) | 0x1; |
| 96 | } |
| 97 | |
| 98 | bool isIterator() const { return (Ptr & 0x1); } |
| 99 | |
| 100 | BaseIter getIterator() const { |
| 101 | (0) . __assert_fail ("isIterator() && \"Ptr not an iterator!\"", "/home/seafit/code_projects/clang_source/clang/include/clang/Sema/IdentifierResolver.h", 101, __PRETTY_FUNCTION__))" file_link="../../../../include/assert.h.html#88" macro="true">assert(isIterator() && "Ptr not an iterator!"); |
| 102 | return reinterpret_cast<BaseIter>(Ptr & ~0x1); |
| 103 | } |
| 104 | |
| 105 | void incrementSlowCase(); |
| 106 | |
| 107 | public: |
| 108 | iterator() = default; |
| 109 | |
| 110 | NamedDecl *operator*() const { |
| 111 | if (isIterator()) |
| 112 | return *getIterator(); |
| 113 | else |
| 114 | return reinterpret_cast<NamedDecl*>(Ptr); |
| 115 | } |
| 116 | |
| 117 | bool operator==(const iterator &RHS) const { |
| 118 | return Ptr == RHS.Ptr; |
| 119 | } |
| 120 | bool operator!=(const iterator &RHS) const { |
| 121 | return Ptr != RHS.Ptr; |
| 122 | } |
| 123 | |
| 124 | |
| 125 | iterator& operator++() { |
| 126 | if (!isIterator()) |
| 127 | Ptr = 0; |
| 128 | else |
| 129 | incrementSlowCase(); |
| 130 | return *this; |
| 131 | } |
| 132 | }; |
| 133 | |
| 134 | explicit IdentifierResolver(Preprocessor &PP); |
| 135 | ~IdentifierResolver(); |
| 136 | |
| 137 | |
| 138 | iterator begin(DeclarationName Name); |
| 139 | |
| 140 | |
| 141 | iterator end() { |
| 142 | return iterator(); |
| 143 | } |
| 144 | |
| 145 | |
| 146 | |
| 147 | |
| 148 | |
| 149 | |
| 150 | |
| 151 | |
| 152 | |
| 153 | |
| 154 | |
| 155 | bool isDeclInScope(Decl *D, DeclContext *Ctx, Scope *S = nullptr, |
| 156 | bool AllowInlineNamespace = false) const; |
| 157 | |
| 158 | |
| 159 | void AddDecl(NamedDecl *D); |
| 160 | |
| 161 | |
| 162 | |
| 163 | void RemoveDecl(NamedDecl *D); |
| 164 | |
| 165 | |
| 166 | |
| 167 | void InsertDeclAfter(iterator Pos, NamedDecl *D); |
| 168 | |
| 169 | |
| 170 | |
| 171 | |
| 172 | |
| 173 | |
| 174 | |
| 175 | |
| 176 | |
| 177 | bool tryAddTopLevelDecl(NamedDecl *D, DeclarationName Name); |
| 178 | |
| 179 | private: |
| 180 | const LangOptions &LangOpt; |
| 181 | Preprocessor &PP; |
| 182 | |
| 183 | class IdDeclInfoMap; |
| 184 | IdDeclInfoMap *IdDeclInfos; |
| 185 | |
| 186 | void updatingIdentifier(IdentifierInfo &II); |
| 187 | void readingIdentifier(IdentifierInfo &II); |
| 188 | |
| 189 | |
| 190 | static inline bool isDeclPtr(void *Ptr) { |
| 191 | return (reinterpret_cast<uintptr_t>(Ptr) & 0x1) == 0; |
| 192 | } |
| 193 | |
| 194 | |
| 195 | static inline IdDeclInfo *toIdDeclInfo(void *Ptr) { |
| 196 | (0) . __assert_fail ("(reinterpret_cast(Ptr) & 0x1) == 1 && \"Ptr not a IdDeclInfo* !\"", "/home/seafit/code_projects/clang_source/clang/include/clang/Sema/IdentifierResolver.h", 197, __PRETTY_FUNCTION__))" file_link="../../../../include/assert.h.html#88" macro="true">assert((reinterpret_cast<uintptr_t>(Ptr) & 0x1) == 1 |
| 197 | (0) . __assert_fail ("(reinterpret_cast(Ptr) & 0x1) == 1 && \"Ptr not a IdDeclInfo* !\"", "/home/seafit/code_projects/clang_source/clang/include/clang/Sema/IdentifierResolver.h", 197, __PRETTY_FUNCTION__))" file_link="../../../../include/assert.h.html#88" macro="true"> && "Ptr not a IdDeclInfo* !"); |
| 198 | return reinterpret_cast<IdDeclInfo*>( |
| 199 | reinterpret_cast<uintptr_t>(Ptr) & ~0x1); |
| 200 | } |
| 201 | }; |
| 202 | |
| 203 | } |
| 204 | |
| 205 | #endif |
| 206 | |