clang 20.0.0git
ExternalPreprocessorSource.h
Go to the documentation of this file.
1//===- ExternalPreprocessorSource.h - Abstract Macro Interface --*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9// This file defines the ExternalPreprocessorSource interface, which enables
10// construction of macro definitions from some external source.
11//
12//===----------------------------------------------------------------------===//
13#ifndef LLVM_CLANG_LEX_EXTERNALPREPROCESSORSOURCE_H
14#define LLVM_CLANG_LEX_EXTERNALPREPROCESSORSOURCE_H
15
16#include <cassert>
17#include <cstdint>
18
19namespace clang {
20
21class IdentifierInfo;
22class Module;
23
24/// Abstract interface for external sources of preprocessor
25/// information.
26///
27/// This abstract class allows an external sources (such as the \c ASTReader)
28/// to provide additional preprocessing information.
30public:
32
33 /// Read the set of macros defined by this external macro source.
34 virtual void ReadDefinedMacros() = 0;
35
36 /// Update an out-of-date identifier.
37 virtual void updateOutOfDateIdentifier(const IdentifierInfo &II) = 0;
38
39 /// Return the identifier associated with the given ID number.
40 ///
41 /// The ID 0 is associated with the NULL identifier.
42 virtual IdentifierInfo *GetIdentifier(uint64_t ID) = 0;
43
44 /// Map a module ID to a module.
45 virtual Module *getModule(unsigned ModuleID) = 0;
46};
47
48// Either a pointer to an IdentifierInfo of the controlling macro or the ID
49// number of the controlling macro.
51 // If the low bit is clear, a pointer to the IdentifierInfo. If the low
52 // bit is set, the upper 63 bits are the ID number.
53 mutable uint64_t Ptr = 0;
54
55public:
57
59 : Ptr(reinterpret_cast<uint64_t>(Ptr)) {}
60
61 explicit LazyIdentifierInfoPtr(uint64_t ID) : Ptr((ID << 1) | 0x01) {
62 assert((ID << 1 >> 1) == ID && "ID must require < 63 bits");
63 if (ID == 0)
64 Ptr = 0;
65 }
66
68 this->Ptr = reinterpret_cast<uint64_t>(Ptr);
69 return *this;
70 }
71
73 assert((ID << 1 >> 1) == ID && "IDs must require < 63 bits");
74 if (ID == 0)
75 Ptr = 0;
76 else
77 Ptr = (ID << 1) | 0x01;
78
79 return *this;
80 }
81
82 /// Whether this pointer is non-NULL.
83 ///
84 /// This operation does not require the AST node to be deserialized.
85 bool isValid() const { return Ptr != 0; }
86
87 /// Whether this pointer is currently stored as ID.
88 bool isID() const { return Ptr & 0x01; }
89
91 assert(!isID());
92 return reinterpret_cast<IdentifierInfo *>(Ptr);
93 }
94
95 uint64_t getID() const {
96 assert(isID());
97 return Ptr >> 1;
98 }
99};
100}
101
102#endif
static char ID
Definition: Arena.cpp:183
Abstract interface for external sources of preprocessor information.
virtual void updateOutOfDateIdentifier(const IdentifierInfo &II)=0
Update an out-of-date identifier.
virtual IdentifierInfo * GetIdentifier(uint64_t ID)=0
Return the identifier associated with the given ID number.
virtual void ReadDefinedMacros()=0
Read the set of macros defined by this external macro source.
virtual Module * getModule(unsigned ModuleID)=0
Map a module ID to a module.
One of these records is kept for each identifier that is lexed.
LazyIdentifierInfoPtr & operator=(uint64_t ID)
bool isValid() const
Whether this pointer is non-NULL.
LazyIdentifierInfoPtr & operator=(const IdentifierInfo *Ptr)
bool isID() const
Whether this pointer is currently stored as ID.
LazyIdentifierInfoPtr(const IdentifierInfo *Ptr)
Describes a module or submodule.
Definition: Module.h:105
The JSON file list parser is used to communicate input to InstallAPI.
@ Module
Module linkage, which indicates that the entity can be referred to from other translation units withi...