clang 23.0.0git
MacroInfo.h
Go to the documentation of this file.
1//===- MacroInfo.h - Information about #defined identifiers -----*- 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/// \file
10/// Defines the clang::MacroInfo and clang::MacroDirective classes.
11//
12//===----------------------------------------------------------------------===//
13
14#ifndef LLVM_CLANG_LEX_MACROINFO_H
15#define LLVM_CLANG_LEX_MACROINFO_H
16
17#include "clang/Basic/LLVM.h"
19#include "clang/Lex/MacroBase.h"
20#include "clang/Lex/Token.h"
21#include "llvm/ADT/ArrayRef.h"
22#include "llvm/ADT/FoldingSet.h"
23#include "llvm/ADT/PointerIntPair.h"
24#include "llvm/ADT/SmallVector.h"
25#include "llvm/Support/Allocator.h"
26#include <algorithm>
27#include <cassert>
28
29namespace clang {
30
32class IdentifierInfo;
33class Module;
34class Preprocessor;
35class SourceManager;
36
37/// Encapsulates the data about a macro definition (e.g. its tokens).
38///
39/// There's an instance of this class for every #define.
40class MacroInfo {
41 //===--------------------------------------------------------------------===//
42 // State set when the macro is defined.
43
44 /// The location the macro is defined.
45 SourceLocation Location;
46
47 /// The location of the last token in the macro.
48 SourceLocation EndLocation;
49
50 /// The list of arguments for a function-like macro.
51 ///
52 /// ParameterList points to the first of NumParameters pointers.
53 ///
54 /// This can be empty, for, e.g. "#define X()". In a C99-style variadic
55 /// macro, this includes the \c __VA_ARGS__ identifier on the list.
56 IdentifierInfo **ParameterList = nullptr;
57
58 /// This is the list of tokens that the macro is defined to.
59 const Token *ReplacementTokens = nullptr;
60
61 /// \see ParameterList
62 unsigned NumParameters = 0;
63
64 /// \see ReplacementTokens
65 unsigned NumReplacementTokens = 0;
66
67 /// Length in characters of the macro definition.
68 mutable unsigned DefinitionLength;
69 mutable bool IsDefinitionLengthCached : 1;
70
71 /// True if this macro is function-like, false if it is object-like.
72 bool IsFunctionLike : 1;
73
74 /// True if this macro is of the form "#define X(...)" or
75 /// "#define X(Y,Z,...)".
76 ///
77 /// The __VA_ARGS__ token should be replaced with the contents of "..." in an
78 /// invocation.
79 bool IsC99Varargs : 1;
80
81 /// True if this macro is of the form "#define X(a...)".
82 ///
83 /// The "a" identifier in the replacement list will be replaced with all
84 /// arguments of the macro starting with the specified one.
85 bool IsGNUVarargs : 1;
86
87 /// True if this macro requires processing before expansion.
88 ///
89 /// This is the case for builtin macros such as __LINE__, so long as they have
90 /// not been redefined, but not for regular predefined macros from the
91 /// "<built-in>" memory buffer (see Preprocessing::getPredefinesFileID).
92 bool IsBuiltinMacro : 1;
93
94 /// Whether this macro contains the sequence ", ## __VA_ARGS__"
95 bool HasCommaPasting : 1;
96
97 //===--------------------------------------------------------------------===//
98 // State that changes as the macro is used.
99
100 /// True if we have started an expansion of this macro already.
101 ///
102 /// This disables recursive expansion, which would be quite bad for things
103 /// like \#define A A.
104 bool IsDisabled : 1;
105
106 /// True if this macro is either defined in the main file and has
107 /// been used, or if it is not defined in the main file.
108 ///
109 /// This is used to emit -Wunused-macros diagnostics.
110 bool IsUsed : 1;
111
112 /// True if this macro can be redefined without emitting a warning.
113 bool IsAllowRedefinitionsWithoutWarning : 1;
114
115 /// Must warn if the macro is unused at the end of translation unit.
116 bool IsWarnIfUnused : 1;
117
118 /// Whether this macro was used as header guard.
119 bool UsedForHeaderGuard : 1;
120
121 // Only the Preprocessor gets to create these.
122 MacroInfo(SourceLocation DefLoc);
123
124public:
125 /// Return the location that the macro was defined at.
126 SourceLocation getDefinitionLoc() const { return Location; }
127
128 /// Set the location of the last token in the macro.
129 void setDefinitionEndLoc(SourceLocation EndLoc) { EndLocation = EndLoc; }
130
131 /// Return the location of the last token in the macro.
132 SourceLocation getDefinitionEndLoc() const { return EndLocation; }
133
134 /// Get length in characters of the macro definition.
135 unsigned getDefinitionLength(const SourceManager &SM) const {
136 if (IsDefinitionLengthCached)
137 return DefinitionLength;
138 return getDefinitionLengthSlow(SM);
139 }
140
141 /// Return true if the specified macro definition is equal to
142 /// this macro in spelling, arguments, and whitespace.
143 ///
144 /// \param Syntactically if true, the macro definitions can be identical even
145 /// if they use different identifiers for the function macro parameters.
146 /// Otherwise the comparison is lexical and this implements the rules in
147 /// C99 6.10.3.
148 bool isIdenticalTo(const MacroInfo &Other, Preprocessor &PP,
149 bool Syntactically) const;
150
151 /// Set or clear the isBuiltinMacro flag.
152 void setIsBuiltinMacro(bool Val = true) { IsBuiltinMacro = Val; }
153
154 /// Set the value of the IsUsed flag.
155 void setIsUsed(bool Val) { IsUsed = Val; }
156
157 /// Set the value of the IsAllowRedefinitionsWithoutWarning flag.
159 IsAllowRedefinitionsWithoutWarning = Val;
160 }
161
162 /// Set the value of the IsWarnIfUnused flag.
163 void setIsWarnIfUnused(bool val) { IsWarnIfUnused = val; }
164
165 /// Set the specified list of identifiers as the parameter list for
166 /// this macro.
168 llvm::BumpPtrAllocator &PPAllocator) {
169 assert(ParameterList == nullptr && NumParameters == 0 &&
170 "Parameter list already set!");
171 if (List.empty())
172 return;
173
174 NumParameters = List.size();
175 ParameterList = PPAllocator.Allocate<IdentifierInfo *>(List.size());
176 std::copy(List.begin(), List.end(), ParameterList);
177 }
178
179 /// Parameters - The list of parameters for a function-like macro. This can
180 /// be empty, for, e.g. "#define X()".
182 bool param_empty() const { return NumParameters == 0; }
183 param_iterator param_begin() const { return ParameterList; }
184 param_iterator param_end() const { return ParameterList + NumParameters; }
185 unsigned getNumParams() const { return NumParameters; }
187 return ArrayRef<const IdentifierInfo *>(ParameterList, NumParameters);
188 }
189
190 /// Return the parameter number of the specified identifier,
191 /// or -1 if the identifier is not a formal parameter identifier.
192 int getParameterNum(const IdentifierInfo *Arg) const {
193 for (param_iterator I = param_begin(), E = param_end(); I != E; ++I)
194 if (*I == Arg)
195 return I - param_begin();
196 return -1;
197 }
198
199 /// Function/Object-likeness. Keep track of whether this macro has formal
200 /// parameters.
201 void setIsFunctionLike() { IsFunctionLike = true; }
202 bool isFunctionLike() const { return IsFunctionLike; }
203 bool isObjectLike() const { return !IsFunctionLike; }
204
205 /// Varargs querying methods. This can only be set for function-like macros.
206 void setIsC99Varargs() { IsC99Varargs = true; }
207 void setIsGNUVarargs() { IsGNUVarargs = true; }
208 bool isC99Varargs() const { return IsC99Varargs; }
209 bool isGNUVarargs() const { return IsGNUVarargs; }
210 bool isVariadic() const { return IsC99Varargs || IsGNUVarargs; }
211
212 /// Return true if this macro requires processing before expansion.
213 ///
214 /// This is true only for builtin macro, such as \__LINE__, whose values
215 /// are not given by fixed textual expansions. Regular predefined macros
216 /// from the "<built-in>" buffer are not reported as builtins by this
217 /// function.
218 bool isBuiltinMacro() const { return IsBuiltinMacro; }
219
220 bool hasCommaPasting() const { return HasCommaPasting; }
221 void setHasCommaPasting() { HasCommaPasting = true; }
222
223 /// Return false if this macro is defined in the main file and has
224 /// not yet been used.
225 bool isUsed() const { return IsUsed; }
226
227 /// Return true if this macro can be redefined without warning.
229 return IsAllowRedefinitionsWithoutWarning;
230 }
231
232 /// Return true if we should emit a warning if the macro is unused.
233 bool isWarnIfUnused() const { return IsWarnIfUnused; }
234
235 /// Return the number of tokens that this macro expands to.
236 unsigned getNumTokens() const { return NumReplacementTokens; }
237
238 const Token &getReplacementToken(unsigned Tok) const {
239 assert(Tok < NumReplacementTokens && "Invalid token #");
240 return ReplacementTokens[Tok];
241 }
242
244
245 const_tokens_iterator tokens_begin() const { return ReplacementTokens; }
247 return ReplacementTokens + NumReplacementTokens;
248 }
249 bool tokens_empty() const { return NumReplacementTokens == 0; }
251 return llvm::ArrayRef(ReplacementTokens, NumReplacementTokens);
252 }
253
255 allocateTokens(unsigned NumTokens, llvm::BumpPtrAllocator &PPAllocator) {
256 assert(ReplacementTokens == nullptr && NumReplacementTokens == 0 &&
257 "Token list already allocated!");
258 NumReplacementTokens = NumTokens;
259 Token *NewReplacementTokens = PPAllocator.Allocate<Token>(NumTokens);
260 ReplacementTokens = NewReplacementTokens;
261 return llvm::MutableArrayRef(NewReplacementTokens, NumTokens);
262 }
263
264 void setTokens(ArrayRef<Token> Tokens, llvm::BumpPtrAllocator &PPAllocator) {
265 assert(
266 !IsDefinitionLengthCached &&
267 "Changing replacement tokens after definition length got calculated");
268 assert(ReplacementTokens == nullptr && NumReplacementTokens == 0 &&
269 "Token list already set!");
270 if (Tokens.empty())
271 return;
272
273 NumReplacementTokens = Tokens.size();
274 Token *NewReplacementTokens = PPAllocator.Allocate<Token>(Tokens.size());
275 std::copy(Tokens.begin(), Tokens.end(), NewReplacementTokens);
276 ReplacementTokens = NewReplacementTokens;
277 }
278
279 /// Return true if this macro is enabled.
280 ///
281 /// In other words, that we are not currently in an expansion of this macro.
282 bool isEnabled() const { return !IsDisabled; }
283
284 void EnableMacro() {
285 assert(IsDisabled && "Cannot enable an already-enabled macro!");
286 IsDisabled = false;
287 }
288
290 assert(!IsDisabled && "Cannot disable an already-disabled macro!");
291 IsDisabled = true;
292 }
293
294 /// Determine whether this macro was used for a header guard.
295 bool isUsedForHeaderGuard() const { return UsedForHeaderGuard; }
296
297 void setUsedForHeaderGuard(bool Val) { UsedForHeaderGuard = Val; }
298
299 void dump() const;
300
301private:
302 friend class Preprocessor;
303
304 unsigned getDefinitionLengthSlow(const SourceManager &SM) const;
305};
306
307/// Encapsulates changes to the "macros namespace" (the location where
308/// the macro name became active, the location where it was undefined, etc.).
309///
310/// MacroDirectives, associated with an identifier, are used to model the macro
311/// history. Usually a macro definition (MacroInfo) is where a macro name
312/// becomes active (MacroDirective) but #pragma push_macro / pop_macro can
313/// create additional DefMacroDirectives for the same MacroInfo.
315public:
321
322protected:
323 /// Previous macro directive for the same identifier, or nullptr.
325
327
328 /// MacroDirective kind.
329 LLVM_PREFERRED_TYPE(Kind)
331
332 /// True if the macro directive was loaded from a PCH file.
333 LLVM_PREFERRED_TYPE(bool)
334 unsigned IsFromPCH : 1;
335
336 // Used by VisibilityMacroDirective ----------------------------------------//
337
338 /// Whether the macro has public visibility (when described in a
339 /// module).
340 LLVM_PREFERRED_TYPE(bool)
341 unsigned IsPublic : 1;
342
345
346public:
347 Kind getKind() const { return Kind(MDKind); }
348
349 SourceLocation getLocation() const { return Loc; }
350
351 /// Set previous definition of the macro with the same name.
352 void setPrevious(MacroDirective *Prev) { Previous = Prev; }
353
354 /// Get previous definition of the macro with the same name.
355 const MacroDirective *getPrevious() const { return Previous; }
356
357 /// Get previous definition of the macro with the same name.
359
360 /// Return true if the macro directive was loaded from a PCH file.
361 bool isFromPCH() const { return IsFromPCH; }
362
363 void setIsFromPCH() { IsFromPCH = true; }
364
365 class DefInfo {
366 DefMacroDirective *DefDirective = nullptr;
367 SourceLocation UndefLoc;
368 bool IsPublic = true;
369
370 public:
371 DefInfo() = default;
372 DefInfo(DefMacroDirective *DefDirective, SourceLocation UndefLoc,
373 bool isPublic)
374 : DefDirective(DefDirective), UndefLoc(UndefLoc), IsPublic(isPublic) {}
375
376 const DefMacroDirective *getDirective() const { return DefDirective; }
377 DefMacroDirective *getDirective() { return DefDirective; }
378
379 inline SourceLocation getLocation() const;
380 inline MacroInfo *getMacroInfo();
381
382 const MacroInfo *getMacroInfo() const {
383 return const_cast<DefInfo *>(this)->getMacroInfo();
384 }
385
386 SourceLocation getUndefLocation() const { return UndefLoc; }
387 bool isUndefined() const { return UndefLoc.isValid(); }
388
389 bool isPublic() const { return IsPublic; }
390
391 bool isValid() const { return DefDirective != nullptr; }
392 bool isInvalid() const { return !isValid(); }
393
394 explicit operator bool() const { return isValid(); }
395
397
399 return const_cast<DefInfo *>(this)->getPreviousDefinition();
400 }
401 };
402
403 /// Traverses the macro directives history and returns the next
404 /// macro definition directive along with info about its undefined location
405 /// (if there is one) and if it is public or private.
406 DefInfo getDefinition();
407 const DefInfo getDefinition() const {
408 return const_cast<MacroDirective *>(this)->getDefinition();
409 }
410
411 bool isDefined() const {
412 if (const DefInfo Def = getDefinition())
413 return !Def.isUndefined();
414 return false;
415 }
416
417 const MacroInfo *getMacroInfo() const {
418 return getDefinition().getMacroInfo();
419 }
421
422 /// Find macro definition active in the specified source location. If
423 /// this macro was not defined there, return NULL.
424 const DefInfo findDirectiveAtLoc(SourceLocation L,
425 const SourceManager &SM) const;
426
427 void dump() const;
428
429 static bool classof(const MacroDirective *) { return true; }
430};
431
432/// A directive for a defined macro or a macro imported from a module.
434 MacroInfo *Info;
435
436public:
438 : MacroDirective(MD_Define, Loc), Info(MI) {
439 assert(MI && "MacroInfo is null");
440 }
442 : DefMacroDirective(MI, MI->getDefinitionLoc()) {}
443
444 /// The data for the macro definition.
445 const MacroInfo *getInfo() const { return Info; }
446 MacroInfo *getInfo() { return Info; }
447
448 static bool classof(const MacroDirective *MD) {
449 return MD->getKind() == MD_Define;
450 }
451
452 static bool classof(const DefMacroDirective *) { return true; }
453};
454
455/// A directive for an undefined macro.
457public:
459 : MacroDirective(MD_Undefine, UndefLoc) {
460 assert(UndefLoc.isValid() && "Invalid UndefLoc!");
461 }
462
463 static bool classof(const MacroDirective *MD) {
464 return MD->getKind() == MD_Undefine;
465 }
466
467 static bool classof(const UndefMacroDirective *) { return true; }
468};
469
470/// A directive for setting the module visibility of a macro.
472public:
475 IsPublic = Public;
476 }
477
478 /// Determine whether this macro is part of the public API of its
479 /// module.
480 bool isPublic() const { return IsPublic; }
481
482 static bool classof(const MacroDirective *MD) {
483 return MD->getKind() == MD_Visibility;
484 }
485
486 static bool classof(const VisibilityMacroDirective *) { return true; }
487};
488
490 if (isInvalid())
491 return {};
492 return DefDirective->getLocation();
493}
494
496 if (isInvalid())
497 return nullptr;
498 return DefDirective->getInfo();
499}
500
503 if (isInvalid() || DefDirective->getPrevious() == nullptr)
504 return {};
505 return DefDirective->getPrevious()->getDefinition();
506}
507
508/// Represents a macro directive exported by a module.
509///
510/// There's an instance of this class for every macro #define or #undef that is
511/// the final directive for a macro name within a module. These entities also
512/// represent the macro override graph.
513///
514/// These are stored in a FoldingSet in the preprocessor.
515class ModuleMacro : public llvm::FoldingSetNode {
516 friend class Preprocessor;
517
518 /// The name defined by the macro.
519 const IdentifierInfo *II;
520
521 /// The body of the #define, or nullptr if this is a #undef.
522 MacroInfo *Macro;
523
524 /// The module that exports this macro.
525 Module *OwningModule;
526
527 /// The number of module macros that override this one.
528 unsigned NumOverriddenBy = 0;
529
530 /// The number of modules whose macros are directly overridden by this one.
531 unsigned NumOverrides;
532
533 ModuleMacro(Module *OwningModule, const IdentifierInfo *II, MacroInfo *Macro,
534 ArrayRef<ModuleMacro *> Overrides)
535 : II(II), Macro(Macro), OwningModule(OwningModule),
536 NumOverrides(Overrides.size()) {
537 std::copy(Overrides.begin(), Overrides.end(),
538 reinterpret_cast<ModuleMacro **>(this + 1));
539 }
540
541public:
542 static ModuleMacro *create(Preprocessor &PP, Module *OwningModule,
543 const IdentifierInfo *II, MacroInfo *Macro,
544 ArrayRef<ModuleMacro *> Overrides);
545
546 void Profile(llvm::FoldingSetNodeID &ID) const {
547 return Profile(ID, OwningModule, II);
548 }
549
550 static void Profile(llvm::FoldingSetNodeID &ID, Module *OwningModule,
551 const IdentifierInfo *II) {
552 ID.AddPointer(OwningModule);
553 ID.AddPointer(II);
554 }
555
556 /// Get the name of the macro.
557 const IdentifierInfo *getName() const { return II; }
558
559 /// Get the ID of the module that exports this macro.
560 Module *getOwningModule() const { return OwningModule; }
561
562 /// Get definition for this exported #define, or nullptr if this
563 /// represents a #undef.
564 MacroInfo *getMacroInfo() const { return Macro; }
565
566 /// Iterators over the overridden module IDs.
567 /// \{
568 using overrides_iterator = ModuleMacro *const *;
569
571 return reinterpret_cast<overrides_iterator>(this + 1);
572 }
573
575 return overrides_begin() + NumOverrides;
576 }
577
581 /// \}
582
583 /// Get the number of macros that override this one.
584 unsigned getNumOverridingMacros() const { return NumOverriddenBy; }
585};
586
591
592/// A description of the current definition of a macro.
593///
594/// The definition of a macro comprises a set of (at least one) defining
595/// entities, which are either local MacroDirectives or imported ModuleMacros.
597 llvm::PointerIntPair<DefMacroDirective *, 1, bool> LatestLocalAndAmbiguous;
598 ArrayRef<ModuleMacro *> ModuleMacros;
599
600public:
601 MacroDefinition() = default;
603 : LatestLocalAndAmbiguous(MD, Info.IsAmbiguous),
604 ModuleMacros(Info.ActiveModuleMacros) {}
605
606 /// Determine whether there is a definition of this macro.
607 explicit operator bool() const {
608 return getLocalDirective() || !ModuleMacros.empty();
609 }
610
611 /// Get the MacroInfo that should be used for this definition.
613 if (!ModuleMacros.empty())
614 return ModuleMacros.back()->getMacroInfo();
615 if (auto *MD = getLocalDirective())
616 return MD->getMacroInfo();
617 return nullptr;
618 }
619
620 /// \c true if the definition is ambiguous, \c false otherwise.
621 bool isAmbiguous() const { return LatestLocalAndAmbiguous.getInt(); }
622
623 /// Get the latest non-imported, non-\#undef'd macro definition
624 /// for this macro.
626 return LatestLocalAndAmbiguous.getPointer();
627 }
628
629 /// Get the active module macros for this macro.
630 ArrayRef<ModuleMacro *> getModuleMacros() const { return ModuleMacros; }
631
632 template <typename Fn> void forAllDefinitions(Fn F) const {
633 if (auto *MD = getLocalDirective())
634 F(MD->getMacroInfo());
635 for (auto *MM : getModuleMacros())
636 F(MM->getMacroInfo());
637 }
638};
639
640} // namespace clang
641
642#endif // LLVM_CLANG_LEX_MACROINFO_H
Token Tok
The Token.
Forward-declares and imports various common LLVM datatypes that clang wants to use unqualified.
Forward-declares types that need PointerLikeTypeTraits.
#define SM(sm)
Defines the clang::SourceLocation class and associated facilities.
static bool isInvalid(LocType Loc, bool *Invalid)
A directive for a defined macro or a macro imported from a module.
Definition MacroInfo.h:433
static bool classof(const MacroDirective *MD)
Definition MacroInfo.h:448
static bool classof(const DefMacroDirective *)
Definition MacroInfo.h:452
const MacroInfo * getInfo() const
The data for the macro definition.
Definition MacroInfo.h:445
MacroInfo * getInfo()
Definition MacroInfo.h:446
DefMacroDirective(MacroInfo *MI)
Definition MacroInfo.h:441
DefMacroDirective(MacroInfo *MI, SourceLocation Loc)
Definition MacroInfo.h:437
One of these records is kept for each identifier that is lexed.
MacroInfo * getMacroInfo() const
Get the MacroInfo that should be used for this definition.
Definition MacroInfo.h:612
DefMacroDirective * getLocalDirective() const
Get the latest non-imported, non-#undef'd macro definition for this macro.
Definition MacroInfo.h:625
ArrayRef< ModuleMacro * > getModuleMacros() const
Get the active module macros for this macro.
Definition MacroInfo.h:630
bool isAmbiguous() const
true if the definition is ambiguous, false otherwise.
Definition MacroInfo.h:621
void forAllDefinitions(Fn F) const
Definition MacroInfo.h:632
MacroDefinition(DefMacroDirective *MD, ModuleMacroInfo Info)
Definition MacroInfo.h:602
const DefInfo getPreviousDefinition() const
Definition MacroInfo.h:398
DefMacroDirective * getDirective()
Definition MacroInfo.h:377
DefInfo(DefMacroDirective *DefDirective, SourceLocation UndefLoc, bool isPublic)
Definition MacroInfo.h:372
const MacroInfo * getMacroInfo() const
Definition MacroInfo.h:382
SourceLocation getUndefLocation() const
Definition MacroInfo.h:386
const DefMacroDirective * getDirective() const
Definition MacroInfo.h:376
SourceLocation getLocation() const
Definition MacroInfo.h:489
MacroDirective * Previous
Previous macro directive for the same identifier, or nullptr.
Definition MacroInfo.h:324
const MacroDirective * getPrevious() const
Get previous definition of the macro with the same name.
Definition MacroInfo.h:355
const MacroInfo * getMacroInfo() const
Definition MacroInfo.h:417
const DefInfo findDirectiveAtLoc(SourceLocation L, const SourceManager &SM) const
Find macro definition active in the specified source location.
unsigned IsPublic
Whether the macro has public visibility (when described in a module).
Definition MacroInfo.h:341
void setPrevious(MacroDirective *Prev)
Set previous definition of the macro with the same name.
Definition MacroInfo.h:352
SourceLocation Loc
Definition MacroInfo.h:326
Kind getKind() const
Definition MacroInfo.h:347
unsigned IsFromPCH
True if the macro directive was loaded from a PCH file.
Definition MacroInfo.h:334
SourceLocation getLocation() const
Definition MacroInfo.h:349
bool isDefined() const
Definition MacroInfo.h:411
static bool classof(const MacroDirective *)
Definition MacroInfo.h:429
unsigned MDKind
MacroDirective kind.
Definition MacroInfo.h:330
MacroInfo * getMacroInfo()
Definition MacroInfo.h:420
const DefInfo getDefinition() const
Definition MacroInfo.h:407
MacroDirective(Kind K, SourceLocation Loc)
Definition MacroInfo.h:343
bool isFromPCH() const
Return true if the macro directive was loaded from a PCH file.
Definition MacroInfo.h:361
MacroDirective * getPrevious()
Get previous definition of the macro with the same name.
Definition MacroInfo.h:358
DefInfo getDefinition()
Traverses the macro directives history and returns the next macro definition directive along with inf...
Encapsulates the data about a macro definition (e.g.
Definition MacroInfo.h:40
friend class Preprocessor
Definition MacroInfo.h:302
void setIsAllowRedefinitionsWithoutWarning(bool Val)
Set the value of the IsAllowRedefinitionsWithoutWarning flag.
Definition MacroInfo.h:158
bool isIdenticalTo(const MacroInfo &Other, Preprocessor &PP, bool Syntactically) const
Return true if the specified macro definition is equal to this macro in spelling, arguments,...
Definition MacroInfo.cpp:89
bool isUsed() const
Return false if this macro is defined in the main file and has not yet been used.
Definition MacroInfo.h:225
bool isC99Varargs() const
Definition MacroInfo.h:208
bool isFunctionLike() const
Definition MacroInfo.h:202
const_tokens_iterator tokens_begin() const
Definition MacroInfo.h:245
bool isAllowRedefinitionsWithoutWarning() const
Return true if this macro can be redefined without warning.
Definition MacroInfo.h:228
SourceLocation getDefinitionEndLoc() const
Return the location of the last token in the macro.
Definition MacroInfo.h:132
void setUsedForHeaderGuard(bool Val)
Definition MacroInfo.h:297
void setHasCommaPasting()
Definition MacroInfo.h:221
param_iterator param_begin() const
Definition MacroInfo.h:183
const_tokens_iterator tokens_end() const
Definition MacroInfo.h:246
ArrayRef< const IdentifierInfo * > params() const
Definition MacroInfo.h:186
unsigned getNumTokens() const
Return the number of tokens that this macro expands to.
Definition MacroInfo.h:236
void dump() const
unsigned getNumParams() const
Definition MacroInfo.h:185
const Token & getReplacementToken(unsigned Tok) const
Definition MacroInfo.h:238
void setDefinitionEndLoc(SourceLocation EndLoc)
Set the location of the last token in the macro.
Definition MacroInfo.h:129
bool isBuiltinMacro() const
Return true if this macro requires processing before expansion.
Definition MacroInfo.h:218
void setTokens(ArrayRef< Token > Tokens, llvm::BumpPtrAllocator &PPAllocator)
Definition MacroInfo.h:264
IdentifierInfo *const * param_iterator
Parameters - The list of parameters for a function-like macro.
Definition MacroInfo.h:181
const Token * const_tokens_iterator
Definition MacroInfo.h:243
void setParameterList(ArrayRef< IdentifierInfo * > List, llvm::BumpPtrAllocator &PPAllocator)
Set the specified list of identifiers as the parameter list for this macro.
Definition MacroInfo.h:167
SourceLocation getDefinitionLoc() const
Return the location that the macro was defined at.
Definition MacroInfo.h:126
bool tokens_empty() const
Definition MacroInfo.h:249
unsigned getDefinitionLength(const SourceManager &SM) const
Get length in characters of the macro definition.
Definition MacroInfo.h:135
llvm::MutableArrayRef< Token > allocateTokens(unsigned NumTokens, llvm::BumpPtrAllocator &PPAllocator)
Definition MacroInfo.h:255
bool isVariadic() const
Definition MacroInfo.h:210
bool hasCommaPasting() const
Definition MacroInfo.h:220
void DisableMacro()
Definition MacroInfo.h:289
void setIsFunctionLike()
Function/Object-likeness.
Definition MacroInfo.h:201
bool isObjectLike() const
Definition MacroInfo.h:203
param_iterator param_end() const
Definition MacroInfo.h:184
bool isUsedForHeaderGuard() const
Determine whether this macro was used for a header guard.
Definition MacroInfo.h:295
bool param_empty() const
Definition MacroInfo.h:182
ArrayRef< Token > tokens() const
Definition MacroInfo.h:250
void setIsWarnIfUnused(bool val)
Set the value of the IsWarnIfUnused flag.
Definition MacroInfo.h:163
int getParameterNum(const IdentifierInfo *Arg) const
Return the parameter number of the specified identifier, or -1 if the identifier is not a formal para...
Definition MacroInfo.h:192
void setIsGNUVarargs()
Definition MacroInfo.h:207
bool isWarnIfUnused() const
Return true if we should emit a warning if the macro is unused.
Definition MacroInfo.h:233
bool isGNUVarargs() const
Definition MacroInfo.h:209
void setIsC99Varargs()
Varargs querying methods. This can only be set for function-like macros.
Definition MacroInfo.h:206
bool isEnabled() const
Return true if this macro is enabled.
Definition MacroInfo.h:282
void setIsUsed(bool Val)
Set the value of the IsUsed flag.
Definition MacroInfo.h:155
void setIsBuiltinMacro(bool Val=true)
Set or clear the isBuiltinMacro flag.
Definition MacroInfo.h:152
Represents a macro directive exported by a module.
Definition MacroInfo.h:515
const IdentifierInfo * getName() const
Get the name of the macro.
Definition MacroInfo.h:557
friend class Preprocessor
Definition MacroInfo.h:516
MacroInfo * getMacroInfo() const
Get definition for this exported define, or nullptr if this represents a undef.
Definition MacroInfo.h:564
overrides_iterator overrides_begin() const
Definition MacroInfo.h:570
ArrayRef< ModuleMacro * > overrides() const
Definition MacroInfo.h:578
static void Profile(llvm::FoldingSetNodeID &ID, Module *OwningModule, const IdentifierInfo *II)
Definition MacroInfo.h:550
unsigned getNumOverridingMacros() const
Get the number of macros that override this one.
Definition MacroInfo.h:584
void Profile(llvm::FoldingSetNodeID &ID) const
Definition MacroInfo.h:546
Module * getOwningModule() const
Get the ID of the module that exports this macro.
Definition MacroInfo.h:560
ModuleMacro *const * overrides_iterator
Iterators over the overridden module IDs.
Definition MacroInfo.h:568
overrides_iterator overrides_end() const
Definition MacroInfo.h:574
Describes a module or submodule.
Definition Module.h:340
Engages in a tight little dance with the lexer to efficiently preprocess tokens.
Encodes a location in the source.
bool isValid() const
Return true if this is a valid SourceLocation object.
This class handles loading and caching of source files into memory.
Token - This structure provides full information about a lexed token.
Definition Token.h:36
static bool classof(const UndefMacroDirective *)
Definition MacroInfo.h:467
static bool classof(const MacroDirective *MD)
Definition MacroInfo.h:463
UndefMacroDirective(SourceLocation UndefLoc)
Definition MacroInfo.h:458
VisibilityMacroDirective(SourceLocation Loc, bool Public)
Definition MacroInfo.h:473
static bool classof(const MacroDirective *MD)
Definition MacroInfo.h:482
static bool classof(const VisibilityMacroDirective *)
Definition MacroInfo.h:486
bool isPublic() const
Determine whether this macro is part of the public API of its module.
Definition MacroInfo.h:480
The JSON file list parser is used to communicate input to InstallAPI.
@ Other
Other implicit parameter.
Definition Decl.h:1763
#define false
Definition stdbool.h:26
#define true
Definition stdbool.h:25
ArrayRef< ModuleMacro * > ActiveModuleMacros
Definition MacroInfo.h:588