clang 24.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 void dump(const SourceManager *SM) const;
301
302private:
303 friend class Preprocessor;
304
305 unsigned getDefinitionLengthSlow(const SourceManager &SM) const;
306};
307
308/// Encapsulates changes to the "macros namespace" (the location where
309/// the macro name became active, the location where it was undefined, etc.).
310///
311/// MacroDirectives, associated with an identifier, are used to model the macro
312/// history. Usually a macro definition (MacroInfo) is where a macro name
313/// becomes active (MacroDirective) but #pragma push_macro / pop_macro can
314/// create additional DefMacroDirectives for the same MacroInfo.
316public:
322
323protected:
324 /// Previous macro directive for the same identifier, or nullptr.
326
328
329 /// MacroDirective kind.
330 LLVM_PREFERRED_TYPE(Kind)
332
333 // Used by VisibilityMacroDirective ----------------------------------------//
334
335 /// Whether the macro has public visibility (when described in a
336 /// module).
337 LLVM_PREFERRED_TYPE(bool)
338 unsigned IsPublic : 1;
339
342
343public:
344 Kind getKind() const { return Kind(MDKind); }
345
346 SourceLocation getLocation() const { return Loc; }
347
348 /// Set previous definition of the macro with the same name.
349 void setPrevious(MacroDirective *Prev) { Previous = Prev; }
350
351 /// Get previous definition of the macro with the same name.
352 const MacroDirective *getPrevious() const { return Previous; }
353
354 /// Get previous definition of the macro with the same name.
356
357 class DefInfo {
358 DefMacroDirective *DefDirective = nullptr;
359 SourceLocation UndefLoc;
360 bool IsPublic = true;
361
362 public:
363 DefInfo() = default;
364 DefInfo(DefMacroDirective *DefDirective, SourceLocation UndefLoc,
365 bool isPublic)
366 : DefDirective(DefDirective), UndefLoc(UndefLoc), IsPublic(isPublic) {}
367
368 const DefMacroDirective *getDirective() const { return DefDirective; }
369 DefMacroDirective *getDirective() { return DefDirective; }
370
371 inline SourceLocation getLocation() const;
372 inline MacroInfo *getMacroInfo();
373
374 const MacroInfo *getMacroInfo() const {
375 return const_cast<DefInfo *>(this)->getMacroInfo();
376 }
377
378 SourceLocation getUndefLocation() const { return UndefLoc; }
379 bool isUndefined() const { return UndefLoc.isValid(); }
380
381 bool isPublic() const { return IsPublic; }
382
383 bool isValid() const { return DefDirective != nullptr; }
384 bool isInvalid() const { return !isValid(); }
385
386 explicit operator bool() const { return isValid(); }
387
389
391 return const_cast<DefInfo *>(this)->getPreviousDefinition();
392 }
393 };
394
395 /// Traverses the macro directives history and returns the next
396 /// macro definition directive along with info about its undefined location
397 /// (if there is one) and if it is public or private.
398 DefInfo getDefinition();
399 const DefInfo getDefinition() const {
400 return const_cast<MacroDirective *>(this)->getDefinition();
401 }
402
403 bool isDefined() const {
404 if (const DefInfo Def = getDefinition())
405 return !Def.isUndefined();
406 return false;
407 }
408
409 const MacroInfo *getMacroInfo() const {
410 return getDefinition().getMacroInfo();
411 }
413
414 /// Find macro definition active in the specified source location. If
415 /// this macro was not defined there, return NULL.
416 const DefInfo findDirectiveAtLoc(SourceLocation L,
417 const SourceManager &SM) const;
418
419 void dump() const;
420 void dump(const SourceManager *SM) const;
421
422 static bool classof(const MacroDirective *) { return true; }
423};
424
425/// A directive for a defined macro or a macro imported from a module.
427 MacroInfo *Info;
428
429public:
431 : MacroDirective(MD_Define, Loc), Info(MI) {
432 assert(MI && "MacroInfo is null");
433 }
435 : DefMacroDirective(MI, MI->getDefinitionLoc()) {}
436
437 /// The data for the macro definition.
438 const MacroInfo *getInfo() const { return Info; }
439 MacroInfo *getInfo() { return Info; }
440
441 static bool classof(const MacroDirective *MD) {
442 return MD->getKind() == MD_Define;
443 }
444
445 static bool classof(const DefMacroDirective *) { return true; }
446};
447
448/// A directive for an undefined macro.
450public:
452 : MacroDirective(MD_Undefine, UndefLoc) {
453 assert(UndefLoc.isValid() && "Invalid UndefLoc!");
454 }
455
456 static bool classof(const MacroDirective *MD) {
457 return MD->getKind() == MD_Undefine;
458 }
459
460 static bool classof(const UndefMacroDirective *) { return true; }
461};
462
463/// A directive for setting the module visibility of a macro.
465public:
468 IsPublic = Public;
469 }
470
471 /// Determine whether this macro is part of the public API of its
472 /// module.
473 bool isPublic() const { return IsPublic; }
474
475 static bool classof(const MacroDirective *MD) {
476 return MD->getKind() == MD_Visibility;
477 }
478
479 static bool classof(const VisibilityMacroDirective *) { return true; }
480};
481
483 if (isInvalid())
484 return {};
485 return DefDirective->getLocation();
486}
487
489 if (isInvalid())
490 return nullptr;
491 return DefDirective->getInfo();
492}
493
496 if (isInvalid() || DefDirective->getPrevious() == nullptr)
497 return {};
498 return DefDirective->getPrevious()->getDefinition();
499}
500
501/// Represents a macro directive exported by a module.
502///
503/// There's an instance of this class for every macro #define or #undef that is
504/// the final directive for a macro name within a module. These entities also
505/// represent the macro override graph.
506///
507/// These are stored in a UniquingSet in the preprocessor.
508class ModuleMacro : public llvm::FoldingSetNode {
509 friend class Preprocessor;
510
511 /// The name defined by the macro.
512 const IdentifierInfo *II;
513
514 /// The body of the #define, or nullptr if this is a #undef.
515 MacroInfo *Macro;
516
517 /// The module that exports this macro.
518 Module *OwningModule;
519
520 /// The number of module macros that override this one.
521 unsigned NumOverriddenBy = 0;
522
523 /// The number of modules whose macros are directly overridden by this one.
524 unsigned NumOverrides;
525
526 ModuleMacro(Module *OwningModule, const IdentifierInfo *II, MacroInfo *Macro,
527 ArrayRef<ModuleMacro *> Overrides)
528 : II(II), Macro(Macro), OwningModule(OwningModule),
529 NumOverrides(Overrides.size()) {
530 std::copy(Overrides.begin(), Overrides.end(),
531 reinterpret_cast<ModuleMacro **>(this + 1));
532 }
533
534public:
535 static ModuleMacro *create(Preprocessor &PP, Module *OwningModule,
536 const IdentifierInfo *II, MacroInfo *Macro,
537 ArrayRef<ModuleMacro *> Overrides);
538
539 std::pair<Module *, const IdentifierInfo *> getKey() const {
540 return {OwningModule, II};
541 }
542
543 /// Get the name of the macro.
544 const IdentifierInfo *getName() const { return II; }
545
546 /// Get the ID of the module that exports this macro.
547 Module *getOwningModule() const { return OwningModule; }
548
549 /// Get definition for this exported #define, or nullptr if this
550 /// represents a #undef.
551 MacroInfo *getMacroInfo() const { return Macro; }
552
553 /// Iterators over the overridden module IDs.
554 /// \{
555 using overrides_iterator = ModuleMacro *const *;
556
558 return reinterpret_cast<overrides_iterator>(this + 1);
559 }
560
562 return overrides_begin() + NumOverrides;
563 }
564
568 /// \}
569
570 /// Get the number of macros that override this one.
571 unsigned getNumOverridingMacros() const { return NumOverriddenBy; }
572};
573
578
579/// A description of the current definition of a macro.
580///
581/// The definition of a macro comprises a set of (at least one) defining
582/// entities, which are either local MacroDirectives or imported ModuleMacros.
584 llvm::PointerIntPair<DefMacroDirective *, 1, bool> LatestLocalAndAmbiguous;
585 ArrayRef<ModuleMacro *> ModuleMacros;
586
587public:
588 MacroDefinition() = default;
590 : LatestLocalAndAmbiguous(MD, Info.IsAmbiguous),
591 ModuleMacros(Info.ActiveModuleMacros) {}
592
593 /// Determine whether there is a definition of this macro.
594 explicit operator bool() const {
595 return getLocalDirective() || !ModuleMacros.empty();
596 }
597
598 /// Get the MacroInfo that should be used for this definition.
600 if (!ModuleMacros.empty())
601 return ModuleMacros.back()->getMacroInfo();
602 if (auto *MD = getLocalDirective())
603 return MD->getMacroInfo();
604 return nullptr;
605 }
606
607 /// \c true if the definition is ambiguous, \c false otherwise.
608 bool isAmbiguous() const { return LatestLocalAndAmbiguous.getInt(); }
609
610 /// Get the latest non-imported, non-\#undef'd macro definition
611 /// for this macro.
613 return LatestLocalAndAmbiguous.getPointer();
614 }
615
616 /// Get the active module macros for this macro.
617 ArrayRef<ModuleMacro *> getModuleMacros() const { return ModuleMacros; }
618
619 template <typename Fn> void forAllDefinitions(Fn F) const {
620 if (auto *MD = getLocalDirective())
621 F(MD->getMacroInfo());
622 for (auto *MM : getModuleMacros())
623 F(MM->getMacroInfo());
624 }
625};
626
627} // namespace clang
628
629#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.
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:426
static bool classof(const MacroDirective *MD)
Definition MacroInfo.h:441
static bool classof(const DefMacroDirective *)
Definition MacroInfo.h:445
const MacroInfo * getInfo() const
The data for the macro definition.
Definition MacroInfo.h:438
MacroInfo * getInfo()
Definition MacroInfo.h:439
DefMacroDirective(MacroInfo *MI)
Definition MacroInfo.h:434
DefMacroDirective(MacroInfo *MI, SourceLocation Loc)
Definition MacroInfo.h:430
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:599
DefMacroDirective * getLocalDirective() const
Get the latest non-imported, non-#undef'd macro definition for this macro.
Definition MacroInfo.h:612
ArrayRef< ModuleMacro * > getModuleMacros() const
Get the active module macros for this macro.
Definition MacroInfo.h:617
bool isAmbiguous() const
true if the definition is ambiguous, false otherwise.
Definition MacroInfo.h:608
void forAllDefinitions(Fn F) const
Definition MacroInfo.h:619
MacroDefinition(DefMacroDirective *MD, ModuleMacroInfo Info)
Definition MacroInfo.h:589
const DefInfo getPreviousDefinition() const
Definition MacroInfo.h:390
DefMacroDirective * getDirective()
Definition MacroInfo.h:369
DefInfo(DefMacroDirective *DefDirective, SourceLocation UndefLoc, bool isPublic)
Definition MacroInfo.h:364
const MacroInfo * getMacroInfo() const
Definition MacroInfo.h:374
SourceLocation getUndefLocation() const
Definition MacroInfo.h:378
const DefMacroDirective * getDirective() const
Definition MacroInfo.h:368
SourceLocation getLocation() const
Definition MacroInfo.h:482
MacroDirective * Previous
Previous macro directive for the same identifier, or nullptr.
Definition MacroInfo.h:325
const MacroDirective * getPrevious() const
Get previous definition of the macro with the same name.
Definition MacroInfo.h:352
const MacroInfo * getMacroInfo() const
Definition MacroInfo.h:409
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:338
void setPrevious(MacroDirective *Prev)
Set previous definition of the macro with the same name.
Definition MacroInfo.h:349
SourceLocation Loc
Definition MacroInfo.h:327
Kind getKind() const
Definition MacroInfo.h:344
SourceLocation getLocation() const
Definition MacroInfo.h:346
bool isDefined() const
Definition MacroInfo.h:403
static bool classof(const MacroDirective *)
Definition MacroInfo.h:422
unsigned MDKind
MacroDirective kind.
Definition MacroInfo.h:331
MacroInfo * getMacroInfo()
Definition MacroInfo.h:412
const DefInfo getDefinition() const
Definition MacroInfo.h:399
MacroDirective(Kind K, SourceLocation Loc)
Definition MacroInfo.h:340
MacroDirective * getPrevious()
Get previous definition of the macro with the same name.
Definition MacroInfo.h:355
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:303
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:508
const IdentifierInfo * getName() const
Get the name of the macro.
Definition MacroInfo.h:544
friend class Preprocessor
Definition MacroInfo.h:509
MacroInfo * getMacroInfo() const
Get definition for this exported define, or nullptr if this represents a undef.
Definition MacroInfo.h:551
overrides_iterator overrides_begin() const
Definition MacroInfo.h:557
ArrayRef< ModuleMacro * > overrides() const
Definition MacroInfo.h:565
std::pair< Module *, const IdentifierInfo * > getKey() const
Definition MacroInfo.h:539
unsigned getNumOverridingMacros() const
Get the number of macros that override this one.
Definition MacroInfo.h:571
Module * getOwningModule() const
Get the ID of the module that exports this macro.
Definition MacroInfo.h:547
ModuleMacro *const * overrides_iterator
Iterators over the overridden module IDs.
Definition MacroInfo.h:555
overrides_iterator overrides_end() const
Definition MacroInfo.h:561
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:460
static bool classof(const MacroDirective *MD)
Definition MacroInfo.h:456
UndefMacroDirective(SourceLocation UndefLoc)
Definition MacroInfo.h:451
VisibilityMacroDirective(SourceLocation Loc, bool Public)
Definition MacroInfo.h:466
static bool classof(const MacroDirective *MD)
Definition MacroInfo.h:475
static bool classof(const VisibilityMacroDirective *)
Definition MacroInfo.h:479
bool isPublic() const
Determine whether this macro is part of the public API of its module.
Definition MacroInfo.h:473
Top level wrappers for InstallAPI frontend operations.
#define true
Definition stdbool.h:25
ArrayRef< ModuleMacro * > ActiveModuleMacros
Definition MacroInfo.h:575