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