Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-10 08:36:56

0001 //===- ExternalPreprocessorSource.h - Abstract Macro Interface --*- C++ -*-===//
0002 //
0003 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
0004 // See https://llvm.org/LICENSE.txt for license information.
0005 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
0006 //
0007 //===----------------------------------------------------------------------===//
0008 //
0009 //  This file defines the ExternalPreprocessorSource interface, which enables
0010 //  construction of macro definitions from some external source.
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 /// Abstract interface for external sources of preprocessor
0025 /// information.
0026 ///
0027 /// This abstract class allows an external sources (such as the \c ASTReader)
0028 /// to provide additional preprocessing information.
0029 class ExternalPreprocessorSource {
0030 public:
0031   virtual ~ExternalPreprocessorSource();
0032 
0033   /// Read the set of macros defined by this external macro source.
0034   virtual void ReadDefinedMacros() = 0;
0035 
0036   /// Update an out-of-date identifier.
0037   virtual void updateOutOfDateIdentifier(const IdentifierInfo &II) = 0;
0038 
0039   /// Return the identifier associated with the given ID number.
0040   ///
0041   /// The ID 0 is associated with the NULL identifier.
0042   virtual IdentifierInfo *GetIdentifier(uint64_t ID) = 0;
0043 
0044   /// Map a module ID to a module.
0045   virtual Module *getModule(unsigned ModuleID) = 0;
0046 };
0047 
0048 // Either a pointer to an IdentifierInfo of the controlling macro or the ID
0049 // number of the controlling macro.
0050 class LazyIdentifierInfoPtr {
0051   // If the low bit is clear, a pointer to the IdentifierInfo. If the low
0052   // bit is set, the upper 63 bits are the ID number.
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   /// Whether this pointer is non-NULL.
0083   ///
0084   /// This operation does not require the AST node to be deserialized.
0085   bool isValid() const { return Ptr != 0; }
0086 
0087   /// Whether this pointer is currently stored as ID.
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