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