clang  16.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 
28 namespace clang {
29 
30 class DefMacroDirective;
31 class IdentifierInfo;
32 class Module;
33 class Preprocessor;
34 class 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.
39 class 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.
121  MacroInfo(SourceLocation DefLoc);
122 
123 public:
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()".
180  using param_iterator = IdentifierInfo *const *;
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 
242  using const_tokens_iterator = const Token *;
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::makeArrayRef(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::makeMutableArrayRef(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 
288  void DisableMacro() {
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 
300 private:
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.
314 public:
315  enum Kind {
319  };
320 
321 protected:
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 
340  : Loc(Loc), MDKind(K), IsFromPCH(false), IsPublic(true) {}
341 
342 public:
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 
432 public:
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.
453 public:
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.
468 public:
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.
511 class 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 
537 public:
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  /// \{
564  using overrides_iterator = ModuleMacro *const *;
565 
567  return reinterpret_cast<overrides_iterator>(this + 1);
568  }
569 
571  return overrides_begin() + NumOverrides;
572  }
573 
575  return llvm::makeArrayRef(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 
591 public:
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
clang::MacroDirective::DefInfo::getDirective
const DefMacroDirective * getDirective() const
Definition: MacroInfo.h:372
clang::ModuleMacro::overrides_iterator
ModuleMacro *const * overrides_iterator
Iterators over the overridden module IDs.
Definition: MacroInfo.h:564
clang::MacroDirective::MacroDirective
MacroDirective(Kind K, SourceLocation Loc)
Definition: MacroInfo.h:339
clang::MacroDirective::DefInfo::getUndefLocation
SourceLocation getUndefLocation() const
Definition: MacroInfo.h:382
clang::MacroDirective::DefInfo::getLocation
SourceLocation getLocation() const
Definition: MacroInfo.h:485
clang::MacroDirective::getMacroInfo
MacroInfo * getMacroInfo()
Definition: MacroInfo.h:416
clang::MacroInfo::getNumTokens
unsigned getNumTokens() const
Return the number of tokens that this macro expands to.
Definition: MacroInfo.h:235
clang::MacroInfo::setHasCommaPasting
void setHasCommaPasting()
Definition: MacroInfo.h:220
clang::MacroInfo::setIsFunctionLike
void setIsFunctionLike()
Function/Object-likeness.
Definition: MacroInfo.h:200
clang::MacroInfo::getReplacementToken
const Token & getReplacementToken(unsigned Tok) const
Definition: MacroInfo.h:237
clang::MacroInfo::param_begin
param_iterator param_begin() const
Definition: MacroInfo.h:182
clang::MacroDirective::MD_Undefine
@ MD_Undefine
Definition: MacroInfo.h:317
clang::MacroInfo::tokens_end
const_tokens_iterator tokens_end() const
Definition: MacroInfo.h:245
clang::ModuleMacro::getNumOverridingMacros
unsigned getNumOverridingMacros() const
Get the number of macros that override this one.
Definition: MacroInfo.h:580
clang::UndefMacroDirective::classof
static bool classof(const MacroDirective *MD)
Definition: MacroInfo.h:459
clang::MacroInfo::setDefinitionEndLoc
void setDefinitionEndLoc(SourceLocation EndLoc)
Set the location of the last token in the macro.
Definition: MacroInfo.h:128
clang::MacroDirective::dump
void dump() const
Definition: MacroInfo.cpp:233
clang::MacroDirective::Previous
MacroDirective * Previous
Previous macro directive for the same identifier, or nullptr.
Definition: MacroInfo.h:323
clang::ModuleMacro::overrides
ArrayRef< ModuleMacro * > overrides() const
Definition: MacroInfo.h:574
clang::MacroInfo::isObjectLike
bool isObjectLike() const
Definition: MacroInfo.h:202
clang::MacroInfo::EnableMacro
void EnableMacro()
Definition: MacroInfo.h:283
clang::MacroDefinition
A description of the current definition of a macro.
Definition: MacroInfo.h:587
clang::SourceLocation
Encodes a location in the source.
Definition: SourceLocation.h:86
clang::MacroInfo::isVariadic
bool isVariadic() const
Definition: MacroInfo.h:209
clang::MacroInfo::tokens_begin
const_tokens_iterator tokens_begin() const
Definition: MacroInfo.h:244
clang::MacroDirective::DefInfo::isValid
bool isValid() const
Definition: MacroInfo.h:387
clang::MacroInfo::dump
void dump() const
Definition: MacroInfo.cpp:152
clang::MacroInfo::isIdenticalTo
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
clang::MacroInfo::tokens
ArrayRef< Token > tokens() const
Definition: MacroInfo.h:249
clang::MacroInfo::setParameterList
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
clang::MacroDirective::DefInfo::isPublic
bool isPublic() const
Definition: MacroInfo.h:385
clang::ModuleMacro::overrides_begin
overrides_iterator overrides_begin() const
Definition: MacroInfo.h:566
clang::MacroDirective::DefInfo::getDirective
DefMacroDirective * getDirective()
Definition: MacroInfo.h:373
clang::DefMacroDirective::DefMacroDirective
DefMacroDirective(MacroInfo *MI, SourceLocation Loc)
Definition: MacroInfo.h:433
clang::MacroInfo
Encapsulates the data about a macro definition (e.g.
Definition: MacroInfo.h:39
clang::MacroDirective::DefInfo::DefInfo
DefInfo(DefMacroDirective *DefDirective, SourceLocation UndefLoc, bool isPublic)
Definition: MacroInfo.h:368
clang::MacroDirective::DefInfo::getMacroInfo
MacroInfo * getMacroInfo()
Definition: MacroInfo.h:491
clang::MacroDirective::getPrevious
MacroDirective * getPrevious()
Get previous definition of the macro with the same name.
Definition: MacroInfo.h:354
clang::MacroDefinition::isAmbiguous
bool isAmbiguous() const
true if the definition is ambiguous, false otherwise.
Definition: MacroInfo.h:612
clang::UndefMacroDirective::UndefMacroDirective
UndefMacroDirective(SourceLocation UndefLoc)
Definition: MacroInfo.h:454
clang::Token
Token - This structure provides full information about a lexed token.
Definition: Token.h:35
clang::MacroInfo::setUsedForHeaderGuard
void setUsedForHeaderGuard(bool Val)
Definition: MacroInfo.h:296
clang::VisibilityMacroDirective
A directive for setting the module visibility of a macro.
Definition: MacroInfo.h:467
clang::MacroInfo::hasCommaPasting
bool hasCommaPasting() const
Definition: MacroInfo.h:219
clang::SourceManager
This class handles loading and caching of source files into memory.
Definition: SourceManager.h:636
clang::UndefMacroDirective::classof
static bool classof(const UndefMacroDirective *)
Definition: MacroInfo.h:463
clang::MacroDirective::isFromPCH
bool isFromPCH() const
Return true if the macro directive was loaded from a PCH file.
Definition: MacroInfo.h:357
clang::MacroInfo::isUsed
bool isUsed() const
Return false if this macro is defined in the main file and has not yet been used.
Definition: MacroInfo.h:224
clang::MacroDirective::getPrevious
const MacroDirective * getPrevious() const
Get previous definition of the macro with the same name.
Definition: MacroInfo.h:351
clang::DefMacroDirective::DefMacroDirective
DefMacroDirective(MacroInfo *MI)
Definition: MacroInfo.h:437
llvm::MutableArrayRef
Definition: LLVM.h:35
clang::MacroInfo::DisableMacro
void DisableMacro()
Definition: MacroInfo.h:288
clang::Module
Describes a module or submodule.
Definition: Module.h:98
clang::MacroDirective::DefInfo::DefInfo
DefInfo()=default
clang::DefMacroDirective::classof
static bool classof(const DefMacroDirective *)
Definition: MacroInfo.h:448
clang::MacroDefinition::getMacroInfo
MacroInfo * getMacroInfo() const
Get the MacroInfo that should be used for this definition.
Definition: MacroInfo.h:603
clang::MacroDirective::MD_Visibility
@ MD_Visibility
Definition: MacroInfo.h:318
clang::VisibilityMacroDirective::isPublic
bool isPublic() const
Determine whether this macro is part of the public API of its module.
Definition: MacroInfo.h:476
clang::MacroInfo::param_iterator
IdentifierInfo *const * param_iterator
Parameters - The list of parameters for a function-like macro.
Definition: MacroInfo.h:180
clang::index::SymbolKind::Module
@ Module
clang::DefMacroDirective::getInfo
MacroInfo * getInfo()
Definition: MacroInfo.h:442
clang::MacroInfo::setIsUsed
void setIsUsed(bool Val)
Set the value of the IsUsed flag.
Definition: MacroInfo.h:154
clang::MacroDirective::DefInfo::getMacroInfo
const MacroInfo * getMacroInfo() const
Definition: MacroInfo.h:378
clang::MacroDefinition::MacroDefinition
MacroDefinition(DefMacroDirective *MD, ArrayRef< ModuleMacro * > MMs, bool IsAmbiguous)
Definition: MacroInfo.h:593
clang::DefMacroDirective::getInfo
const MacroInfo * getInfo() const
The data for the macro definition.
Definition: MacroInfo.h:441
clang::MacroInfo::setTokens
void setTokens(ArrayRef< Token > Tokens, llvm::BumpPtrAllocator &PPAllocator)
Definition: MacroInfo.h:263
clang::MacroDirective::Kind
Kind
Definition: MacroInfo.h:315
bool
#define bool
Definition: stdbool.h:20
clang::MacroDirective::setIsFromPCH
void setIsFromPCH()
Definition: MacroInfo.h:359
clang::MacroInfo::getDefinitionEndLoc
SourceLocation getDefinitionEndLoc() const
Return the location of the last token in the macro.
Definition: MacroInfo.h:131
clang::MacroDirective::findDirectiveAtLoc
const DefInfo findDirectiveAtLoc(SourceLocation L, const SourceManager &SM) const
Find macro definition active in the specified source location.
Definition: MacroInfo.cpp:220
isInvalid
static bool isInvalid(LocType Loc, bool *Invalid)
Definition: SourceManager.cpp:1233
clang::MacroDirective::IsPublic
unsigned IsPublic
Whether the macro has public visibility (when described in a module).
Definition: MacroInfo.h:337
clang::DefMacroDirective::classof
static bool classof(const MacroDirective *MD)
Definition: MacroInfo.h:444
clang::MacroInfo::isEnabled
bool isEnabled() const
Return true if this macro is enabled.
Definition: MacroInfo.h:281
clang::MacroDefinition::getLocalDirective
DefMacroDirective * getLocalDirective() const
Get the latest non-imported, non-#undef'd macro definition for this macro.
Definition: MacroInfo.h:616
clang::DefMacroDirective
A directive for a defined macro or a macro imported from a module.
Definition: MacroInfo.h:429
clang::UndefMacroDirective
A directive for an undefined macro.
Definition: MacroInfo.h:452
clang::MacroInfo::allocateTokens
llvm::MutableArrayRef< Token > allocateTokens(unsigned NumTokens, llvm::BumpPtrAllocator &PPAllocator)
Definition: MacroInfo.h:254
clang::MacroDirective::isDefined
bool isDefined() const
Definition: MacroInfo.h:407
SourceLocation.h
clang::MacroDirective::getDefinition
DefInfo getDefinition()
Traverses the macro directives history and returns the next macro definition directive along with inf...
Definition: MacroInfo.cpp:198
clang::serialized_diags::create
std::unique_ptr< DiagnosticConsumer > create(StringRef OutputFile, DiagnosticOptions *Diags, bool MergeChildRecords=false)
Returns a DiagnosticConsumer that serializes diagnostics to a bitcode file.
Definition: SerializedDiagnosticPrinter.cpp:301
clang::MacroDirective::getDefinition
const DefInfo getDefinition() const
Definition: MacroInfo.h:403
clang::MacroDirective::getKind
Kind getKind() const
Definition: MacroInfo.h:343
clang::MacroInfo::params
ArrayRef< const IdentifierInfo * > params() const
Definition: MacroInfo.h:185
clang::MacroInfo::setIsAllowRedefinitionsWithoutWarning
void setIsAllowRedefinitionsWithoutWarning(bool Val)
Set the value of the IsAllowRedefinitionsWithoutWarning flag.
Definition: MacroInfo.h:157
false
#define false
Definition: stdbool.h:22
clang::MacroInfo::isC99Varargs
bool isC99Varargs() const
Definition: MacroInfo.h:207
clang::MacroDirective::DefInfo::isInvalid
bool isInvalid() const
Definition: MacroInfo.h:388
clang::MacroDefinition::forAllDefinitions
void forAllDefinitions(Fn F) const
Definition: MacroInfo.h:623
llvm::ArrayRef
Definition: LLVM.h:34
clang::MacroDirective::DefInfo::getPreviousDefinition
const DefInfo getPreviousDefinition() const
Definition: MacroInfo.h:394
clang::MacroDirective::getLocation
SourceLocation getLocation() const
Definition: MacroInfo.h:345
clang::MacroDirective::MDKind
unsigned MDKind
MacroDirective kind.
Definition: MacroInfo.h:328
clang::MacroInfo::tokens_empty
bool tokens_empty() const
Definition: MacroInfo.h:248
LLVM.h
clang::ModuleMacro::getName
IdentifierInfo * getName() const
Get the name of the macro.
Definition: MacroInfo.h:553
clang::MacroInfo::param_empty
bool param_empty() const
Definition: MacroInfo.h:181
clang::IdentifierInfo
One of these records is kept for each identifier that is lexed.
Definition: IdentifierTable.h:85
clang::VisibilityMacroDirective::VisibilityMacroDirective
VisibilityMacroDirective(SourceLocation Loc, bool Public)
Definition: MacroInfo.h:469
clang::ModuleMacro::Profile
static void Profile(llvm::FoldingSetNodeID &ID, Module *OwningModule, const IdentifierInfo *II)
Definition: MacroInfo.h:546
clang::MacroInfo::getDefinitionLength
unsigned getDefinitionLength(const SourceManager &SM) const
Get length in characters of the macro definition.
Definition: MacroInfo.h:134
clang::ModuleMacro::getOwningModule
Module * getOwningModule() const
Get the ID of the module that exports this macro.
Definition: MacroInfo.h:556
clang::MacroInfo::getParameterNum
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
clang::MacroInfo::setIsWarnIfUnused
void setIsWarnIfUnused(bool val)
Set the value of the IsWarnIfUnused flag.
Definition: MacroInfo.h:162
clang::MacroDirective::MD_Define
@ MD_Define
Definition: MacroInfo.h:316
clang::MacroInfo::isAllowRedefinitionsWithoutWarning
bool isAllowRedefinitionsWithoutWarning() const
Return true if this macro can be redefined without warning.
Definition: MacroInfo.h:227
clang::Builtin::ID
ID
Definition: Builtins.h:52
clang::MacroInfo::getNumParams
unsigned getNumParams() const
Definition: MacroInfo.h:184
clang::MacroInfo::isBuiltinMacro
bool isBuiltinMacro() const
Return true if this macro requires processing before expansion.
Definition: MacroInfo.h:217
clang::MacroDirective::classof
static bool classof(const MacroDirective *)
Definition: MacroInfo.h:425
clang
Definition: CalledOnceCheck.h:17
clang::MacroDirective
Encapsulates changes to the "macros namespace" (the location where the macro name became active,...
Definition: MacroInfo.h:313
clang::MacroDirective::getMacroInfo
const MacroInfo * getMacroInfo() const
Definition: MacroInfo.h:413
clang::MacroDirective::setPrevious
void setPrevious(MacroDirective *Prev)
Set previous definition of the macro with the same name.
Definition: MacroInfo.h:348
clang::MacroInfo::setIsGNUVarargs
void setIsGNUVarargs()
Definition: MacroInfo.h:206
clang::MacroDirective::IsFromPCH
unsigned IsFromPCH
True if the macro directive was loaded from a PCH file.
Definition: MacroInfo.h:331
clang::MacroInfo::isUsedForHeaderGuard
bool isUsedForHeaderGuard() const
Determine whether this macro was used for a header guard.
Definition: MacroInfo.h:294
clang::ModuleMacro::Profile
void Profile(llvm::FoldingSetNodeID &ID) const
Definition: MacroInfo.h:542
clang::SourceLocation::isValid
bool isValid() const
Return true if this is a valid SourceLocation object.
Definition: SourceLocation.h:110
clang::MacroInfo::isWarnIfUnused
bool isWarnIfUnused() const
Return true if we should emit a warning if the macro is unused.
Definition: MacroInfo.h:232
clang::MacroDirective::DefInfo::getPreviousDefinition
DefInfo getPreviousDefinition()
Definition: MacroInfo.h:498
clang::VisibilityMacroDirective::classof
static bool classof(const MacroDirective *MD)
Definition: MacroInfo.h:478
clang::ModuleMacro::getMacroInfo
MacroInfo * getMacroInfo() const
Get definition for this exported #define, or nullptr if this represents a #undef.
Definition: MacroInfo.h:560
clang::MacroDirective::Loc
SourceLocation Loc
Definition: MacroInfo.h:325
clang::MacroInfo::isFunctionLike
bool isFunctionLike() const
Definition: MacroInfo.h:201
true
#define true
Definition: stdbool.h:21
clang::MacroDirective::DefInfo::isUndefined
bool isUndefined() const
Definition: MacroInfo.h:383
clang::Preprocessor
Engages in a tight little dance with the lexer to efficiently preprocess tokens.
Definition: Preprocessor.h:129
SM
#define SM(sm)
Definition: Cuda.cpp:79
clang::MacroInfo::setIsC99Varargs
void setIsC99Varargs()
Varargs querying methods. This can only be set for function-like macros.
Definition: MacroInfo.h:205
Token.h
clang::MacroDirective::DefInfo
Definition: MacroInfo.h:361
clang::MacroInfo::setIsBuiltinMacro
void setIsBuiltinMacro(bool Val=true)
Set or clear the isBuiltinMacro flag.
Definition: MacroInfo.h:151
clang::MacroInfo::isGNUVarargs
bool isGNUVarargs() const
Definition: MacroInfo.h:208
clang::ModuleMacro::overrides_end
overrides_iterator overrides_end() const
Definition: MacroInfo.h:570
clang::VisibilityMacroDirective::classof
static bool classof(const VisibilityMacroDirective *)
Definition: MacroInfo.h:482
clang::MacroInfo::param_end
param_iterator param_end() const
Definition: MacroInfo.h:183
clang::ModuleMacro
Represents a macro directive exported by a module.
Definition: MacroInfo.h:511
clang::MacroDefinition::getModuleMacros
ArrayRef< ModuleMacro * > getModuleMacros() const
Get the active module macros for this macro.
Definition: MacroInfo.h:621
clang::MacroInfo::getDefinitionLoc
SourceLocation getDefinitionLoc() const
Return the location that the macro was defined at.
Definition: MacroInfo.h:125