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