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