clang  3.7.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  unsigned 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.
161  void setArgumentList(IdentifierInfo *const *List, unsigned NumArgs,
162  llvm::BumpPtrAllocator &PPAllocator) {
163  assert(ArgumentList == nullptr && NumArguments == 0 &&
164  "Argument list already set!");
165  if (NumArgs == 0)
166  return;
167 
168  NumArguments = NumArgs;
169  ArgumentList = PPAllocator.Allocate<IdentifierInfo *>(NumArgs);
170  for (unsigned i = 0; i != NumArgs; ++i)
171  ArgumentList[i] = List[i];
172  }
173 
174  /// Arguments - The list of arguments for a function-like macro. This can be
175  /// empty, for, e.g. "#define X()".
176  typedef IdentifierInfo *const *arg_iterator;
177  bool arg_empty() const { return NumArguments == 0; }
178  arg_iterator arg_begin() const { return ArgumentList; }
179  arg_iterator arg_end() const { return ArgumentList + NumArguments; }
180  unsigned getNumArgs() const { return NumArguments; }
182  return ArrayRef<const IdentifierInfo *>(ArgumentList, NumArguments);
183  }
184 
185  /// \brief Return the argument number of the specified identifier,
186  /// or -1 if the identifier is not a formal argument identifier.
187  int getArgumentNum(const IdentifierInfo *Arg) const {
188  for (arg_iterator I = arg_begin(), E = arg_end(); I != E; ++I)
189  if (*I == Arg)
190  return I - arg_begin();
191  return -1;
192  }
193 
194  /// Function/Object-likeness. Keep track of whether this macro has formal
195  /// parameters.
196  void setIsFunctionLike() { IsFunctionLike = true; }
197  bool isFunctionLike() const { return IsFunctionLike; }
198  bool isObjectLike() const { return !IsFunctionLike; }
199 
200  /// Varargs querying methods. This can only be set for function-like macros.
201  void setIsC99Varargs() { IsC99Varargs = true; }
202  void setIsGNUVarargs() { IsGNUVarargs = true; }
203  bool isC99Varargs() const { return IsC99Varargs; }
204  bool isGNUVarargs() const { return IsGNUVarargs; }
205  bool isVariadic() const { return IsC99Varargs | IsGNUVarargs; }
206 
207  /// \brief Return true if this macro requires processing before expansion.
208  ///
209  /// This is true only for builtin macro, such as \__LINE__, whose values
210  /// are not given by fixed textual expansions. Regular predefined macros
211  /// from the "<built-in>" buffer are not reported as builtins by this
212  /// function.
213  bool isBuiltinMacro() const { return IsBuiltinMacro; }
214 
215  bool hasCommaPasting() const { return HasCommaPasting; }
216  void setHasCommaPasting() { HasCommaPasting = true; }
217 
218  /// \brief Return false if this macro is defined in the main file and has
219  /// not yet been used.
220  bool isUsed() const { return IsUsed; }
221 
222  /// \brief Return true if this macro can be redefined without warning.
224  return IsAllowRedefinitionsWithoutWarning;
225  }
226 
227  /// \brief Return true if we should emit a warning if the macro is unused.
228  bool isWarnIfUnused() const { return IsWarnIfUnused; }
229 
230  /// \brief Return the number of tokens that this macro expands to.
231  ///
232  unsigned getNumTokens() const { return ReplacementTokens.size(); }
233 
234  const Token &getReplacementToken(unsigned Tok) const {
235  assert(Tok < ReplacementTokens.size() && "Invalid token #");
236  return ReplacementTokens[Tok];
237  }
238 
240  tokens_iterator tokens_begin() const { return ReplacementTokens.begin(); }
241  tokens_iterator tokens_end() const { return ReplacementTokens.end(); }
242  bool tokens_empty() const { return ReplacementTokens.empty(); }
243  ArrayRef<Token> tokens() const { return ReplacementTokens; }
244 
245  /// \brief Add the specified token to the replacement text for the macro.
246  void AddTokenToBody(const Token &Tok) {
247  assert(
248  !IsDefinitionLengthCached &&
249  "Changing replacement tokens after definition length got calculated");
250  ReplacementTokens.push_back(Tok);
251  }
252 
253  /// \brief Return true if this macro is enabled.
254  ///
255  /// In other words, that we are not currently in an expansion of this macro.
256  bool isEnabled() const { return !IsDisabled; }
257 
258  void EnableMacro() {
259  assert(IsDisabled && "Cannot enable an already-enabled macro!");
260  IsDisabled = false;
261  }
262 
263  void DisableMacro() {
264  assert(!IsDisabled && "Cannot disable an already-disabled macro!");
265  IsDisabled = true;
266  }
267 
268  /// \brief Determine whether this macro info came from an AST file (such as
269  /// a precompiled header or module) rather than having been parsed.
270  bool isFromASTFile() const { return FromASTFile; }
271 
272  /// \brief Determine whether this macro was used for a header guard.
273  bool isUsedForHeaderGuard() const { return UsedForHeaderGuard; }
274 
275  void setUsedForHeaderGuard(bool Val) { UsedForHeaderGuard = Val; }
276 
277  /// \brief Retrieve the global ID of the module that owns this particular
278  /// macro info.
279  unsigned getOwningModuleID() const {
280  if (isFromASTFile())
281  return *(const unsigned *)(this + 1);
282 
283  return 0;
284  }
285 
286  void dump() const;
287 
288 private:
289  unsigned getDefinitionLengthSlow(SourceManager &SM) const;
290 
291  void setOwningModuleID(unsigned ID) {
292  assert(isFromASTFile());
293  *(unsigned *)(this + 1) = ID;
294  }
295 
296  friend class Preprocessor;
297 };
298 
299 class DefMacroDirective;
300 
301 /// \brief Encapsulates changes to the "macros namespace" (the location where
302 /// the macro name became active, the location where it was undefined, etc.).
303 ///
304 /// MacroDirectives, associated with an identifier, are used to model the macro
305 /// history. Usually a macro definition (MacroInfo) is where a macro name
306 /// becomes active (MacroDirective) but #pragma push_macro / pop_macro can
307 /// create additional DefMacroDirectives for the same MacroInfo.
309 public:
311 
312 protected:
313  /// \brief Previous macro directive for the same identifier, or NULL.
315 
317 
318  /// \brief MacroDirective kind.
319  unsigned MDKind : 2;
320 
321  /// \brief True if the macro directive was loaded from a PCH file.
322  bool IsFromPCH : 1;
323 
324  // Used by VisibilityMacroDirective ----------------------------------------//
325 
326  /// \brief Whether the macro has public visibility (when described in a
327  /// module).
328  bool IsPublic : 1;
329 
331  : Previous(nullptr), Loc(Loc), MDKind(K), IsFromPCH(false),
332  IsPublic(true) {}
333 
334 public:
335  Kind getKind() const { return Kind(MDKind); }
336 
337  SourceLocation getLocation() const { return Loc; }
338 
339  /// \brief Set previous definition of the macro with the same name.
340  void setPrevious(MacroDirective *Prev) { Previous = Prev; }
341 
342  /// \brief Get previous definition of the macro with the same name.
343  const MacroDirective *getPrevious() const { return Previous; }
344 
345  /// \brief Get previous definition of the macro with the same name.
347 
348  /// \brief Return true if the macro directive was loaded from a PCH file.
349  bool isFromPCH() const { return IsFromPCH; }
350 
351  void setIsFromPCH() { IsFromPCH = true; }
352 
353  class DefInfo {
354  DefMacroDirective *DefDirective;
355  SourceLocation UndefLoc;
356  bool IsPublic;
357 
358  public:
359  DefInfo() : DefDirective(nullptr), IsPublic(true) {}
360 
361  DefInfo(DefMacroDirective *DefDirective, SourceLocation UndefLoc,
362  bool isPublic)
363  : DefDirective(DefDirective), UndefLoc(UndefLoc), IsPublic(isPublic) {}
364 
365  const DefMacroDirective *getDirective() const { return DefDirective; }
366  DefMacroDirective *getDirective() { return DefDirective; }
367 
368  inline SourceLocation getLocation() const;
369  inline MacroInfo *getMacroInfo();
370  const MacroInfo *getMacroInfo() const {
371  return const_cast<DefInfo *>(this)->getMacroInfo();
372  }
373 
374  SourceLocation getUndefLocation() const { return UndefLoc; }
375  bool isUndefined() const { return UndefLoc.isValid(); }
376 
377  bool isPublic() const { return IsPublic; }
378 
379  bool isValid() const { return DefDirective != nullptr; }
380  bool isInvalid() const { return !isValid(); }
381 
382  explicit operator bool() const { return isValid(); }
383 
386  return const_cast<DefInfo *>(this)->getPreviousDefinition();
387  }
388  };
389 
390  /// \brief Traverses the macro directives history and returns the next
391  /// macro definition directive along with info about its undefined location
392  /// (if there is one) and if it is public or private.
393  DefInfo getDefinition();
394  const DefInfo getDefinition() const {
395  return const_cast<MacroDirective *>(this)->getDefinition();
396  }
397 
398  bool isDefined() const {
399  if (const DefInfo Def = getDefinition())
400  return !Def.isUndefined();
401  return false;
402  }
403 
404  const MacroInfo *getMacroInfo() const {
405  return getDefinition().getMacroInfo();
406  }
408 
409  /// \brief Find macro definition active in the specified source location. If
410  /// this macro was not defined there, return NULL.
411  const DefInfo findDirectiveAtLoc(SourceLocation L, SourceManager &SM) const;
412 
413  void dump() const;
414 
415  static bool classof(const MacroDirective *) { return true; }
416 };
417 
418 /// \brief A directive for a defined macro or a macro imported from a module.
420  MacroInfo *Info;
421 
422 public:
424  : MacroDirective(MD_Define, Loc), Info(MI) {
425  assert(MI && "MacroInfo is null");
426  }
428  : DefMacroDirective(MI, MI->getDefinitionLoc()) {}
429 
430  /// \brief The data for the macro definition.
431  const MacroInfo *getInfo() const { return Info; }
432  MacroInfo *getInfo() { return Info; }
433 
434  static bool classof(const MacroDirective *MD) {
435  return MD->getKind() == MD_Define;
436  }
437  static bool classof(const DefMacroDirective *) { return true; }
438 };
439 
440 /// \brief A directive for an undefined macro.
442 public:
444  : MacroDirective(MD_Undefine, UndefLoc) {
445  assert(UndefLoc.isValid() && "Invalid UndefLoc!");
446  }
447 
448  static bool classof(const MacroDirective *MD) {
449  return MD->getKind() == MD_Undefine;
450  }
451  static bool classof(const UndefMacroDirective *) { return true; }
452 };
453 
454 /// \brief A directive for setting the module visibility of a macro.
456 public:
458  : MacroDirective(MD_Visibility, Loc) {
459  IsPublic = Public;
460  }
461 
462  /// \brief Determine whether this macro is part of the public API of its
463  /// module.
464  bool isPublic() const { return IsPublic; }
465 
466  static bool classof(const MacroDirective *MD) {
467  return MD->getKind() == MD_Visibility;
468  }
469  static bool classof(const VisibilityMacroDirective *) { return true; }
470 };
471 
473  if (isInvalid())
474  return SourceLocation();
475  return DefDirective->getLocation();
476 }
477 
479  if (isInvalid())
480  return nullptr;
481  return DefDirective->getInfo();
482 }
483 
486  if (isInvalid() || DefDirective->getPrevious() == nullptr)
487  return DefInfo();
488  return DefDirective->getPrevious()->getDefinition();
489 }
490 
491 /// \brief Represents a macro directive exported by a module.
492 ///
493 /// There's an instance of this class for every macro #define or #undef that is
494 /// the final directive for a macro name within a module. These entities also
495 /// represent the macro override graph.
496 ///
497 /// These are stored in a FoldingSet in the preprocessor.
498 class ModuleMacro : public llvm::FoldingSetNode {
499  /// The name defined by the macro.
500  IdentifierInfo *II;
501  /// The body of the #define, or nullptr if this is a #undef.
502  MacroInfo *Macro;
503  /// The module that exports this macro.
504  Module *OwningModule;
505  /// The number of module macros that override this one.
506  unsigned NumOverriddenBy;
507  /// The number of modules whose macros are directly overridden by this one.
508  unsigned NumOverrides;
509  // ModuleMacro *OverriddenMacros[NumOverrides];
510 
511  friend class Preprocessor;
512 
513  ModuleMacro(Module *OwningModule, IdentifierInfo *II, MacroInfo *Macro,
514  ArrayRef<ModuleMacro *> Overrides)
515  : II(II), Macro(Macro), OwningModule(OwningModule), NumOverriddenBy(0),
516  NumOverrides(Overrides.size()) {
517  std::copy(Overrides.begin(), Overrides.end(),
518  reinterpret_cast<ModuleMacro **>(this + 1));
519  }
520 
521 public:
522  static ModuleMacro *create(Preprocessor &PP, Module *OwningModule,
523  IdentifierInfo *II, MacroInfo *Macro,
524  ArrayRef<ModuleMacro *> Overrides);
525 
526  void Profile(llvm::FoldingSetNodeID &ID) const {
527  return Profile(ID, OwningModule, II);
528  }
529  static void Profile(llvm::FoldingSetNodeID &ID, Module *OwningModule,
530  IdentifierInfo *II) {
531  ID.AddPointer(OwningModule);
532  ID.AddPointer(II);
533  }
534 
535  /// Get the ID of the module that exports this macro.
536  Module *getOwningModule() const { return OwningModule; }
537 
538  /// Get definition for this exported #define, or nullptr if this
539  /// represents a #undef.
540  MacroInfo *getMacroInfo() const { return Macro; }
541 
542  /// Iterators over the overridden module IDs.
543  /// \{
546  return reinterpret_cast<overrides_iterator>(this + 1);
547  }
549  return overrides_begin() + NumOverrides;
550  }
552  return llvm::makeArrayRef(overrides_begin(), overrides_end());
553  }
554  /// \}
555 
556  /// Get the number of macros that override this one.
557  unsigned getNumOverridingMacros() const { return NumOverriddenBy; }
558 };
559 
560 /// \brief A description of the current definition of a macro.
561 ///
562 /// The definition of a macro comprises a set of (at least one) defining
563 /// entities, which are either local MacroDirectives or imported ModuleMacros.
565  llvm::PointerIntPair<DefMacroDirective *, 1, bool> LatestLocalAndAmbiguous;
566  ArrayRef<ModuleMacro *> ModuleMacros;
567 
568 public:
569  MacroDefinition() : LatestLocalAndAmbiguous(), ModuleMacros() {}
571  bool IsAmbiguous)
572  : LatestLocalAndAmbiguous(MD, IsAmbiguous), ModuleMacros(MMs) {}
573 
574  /// \brief Determine whether there is a definition of this macro.
575  explicit operator bool() const {
576  return getLocalDirective() || !ModuleMacros.empty();
577  }
578 
579  /// \brief Get the MacroInfo that should be used for this definition.
581  if (!ModuleMacros.empty())
582  return ModuleMacros.back()->getMacroInfo();
583  if (auto *MD = getLocalDirective())
584  return MD->getMacroInfo();
585  return nullptr;
586  }
587 
588  /// \brief \c true if the definition is ambiguous, \c false otherwise.
589  bool isAmbiguous() const { return LatestLocalAndAmbiguous.getInt(); }
590 
591  /// \brief Get the latest non-imported, non-\#undef'd macro definition
592  /// for this macro.
594  return LatestLocalAndAmbiguous.getPointer();
595  }
596 
597  /// \brief Get the active module macros for this macro.
598  ArrayRef<ModuleMacro *> getModuleMacros() const { return ModuleMacros; }
599 
600  template <typename Fn> void forAllDefinitions(Fn F) const {
601  if (auto *MD = getLocalDirective())
602  F(MD->getMacroInfo());
603  for (auto *MM : getModuleMacros())
604  F(MM->getMacroInfo());
605  }
606 };
607 
608 } // end namespace clang
609 
610 #endif
ArrayRef< ModuleMacro * > overrides() const
Definition: MacroInfo.h:551
bool IsFromPCH
True if the macro directive was loaded from a PCH file.
Definition: MacroInfo.h:322
SmallVectorImpl< Token >::const_iterator tokens_iterator
Definition: MacroInfo.h:239
void DisableMacro()
Definition: MacroInfo.h:263
void AddTokenToBody(const Token &Tok)
Add the specified token to the replacement text for the macro.
Definition: MacroInfo.h:246
const DefInfo findDirectiveAtLoc(SourceLocation L, SourceManager &SM) const
Find macro definition active in the specified source location. If this macro was not defined there...
Definition: MacroInfo.cpp:196
ArrayRef< const IdentifierInfo * > args() const
Definition: MacroInfo.h:181
void setArgumentList(IdentifierInfo *const *List, unsigned NumArgs, llvm::BumpPtrAllocator &PPAllocator)
Set the specified list of identifiers as the argument list for this macro.
Definition: MacroInfo.h:161
ArrayRef< ModuleMacro * > getModuleMacros() const
Get the active module macros for this macro.
Definition: MacroInfo.h:598
bool isObjectLike() const
Definition: MacroInfo.h:198
bool hasCommaPasting() const
Definition: MacroInfo.h:215
Kind getKind() const
Definition: MacroInfo.h:335
static bool classof(const UndefMacroDirective *)
Definition: MacroInfo.h:451
A description of the current definition of a macro.
Definition: MacroInfo.h:564
A directive for an undefined macro.
Definition: MacroInfo.h:441
DefMacroDirective(MacroInfo *MI, SourceLocation Loc)
Definition: MacroInfo.h:423
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:526
void setIsGNUVarargs()
Definition: MacroInfo.h:202
Represents a macro directive exported by a module.
Definition: MacroInfo.h:498
A directive for a defined macro or a macro imported from a module.
Definition: MacroInfo.h:419
bool isEnabled() const
Return true if this macro is enabled.
Definition: MacroInfo.h:256
SourceLocation getLocation() const
Definition: MacroInfo.h:472
MacroInfo * getMacroInfo() const
Definition: MacroInfo.h:540
bool isWarnIfUnused() const
Return true if we should emit a warning if the macro is unused.
Definition: MacroInfo.h:228
bool tokens_empty() const
Definition: MacroInfo.h:242
Describes a module or submodule.
Definition: Basic/Module.h:49
MacroInfo * getMacroInfo() const
Get the MacroInfo that should be used for this definition.
Definition: MacroInfo.h:580
A directive for setting the module visibility of a macro.
Definition: MacroInfo.h:455
overrides_iterator overrides_begin() const
Definition: MacroInfo.h:545
bool isUsedForHeaderGuard() const
Determine whether this macro was used for a header guard.
Definition: MacroInfo.h:273
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:346
tokens_iterator tokens_begin() const
Definition: MacroInfo.h:240
bool isVariadic() const
Definition: MacroInfo.h:205
DefMacroDirective(MacroInfo *MI)
Definition: MacroInfo.h:427
ArrayRef< Token > tokens() const
Definition: MacroInfo.h:243
ModuleMacro *const * overrides_iterator
Definition: MacroInfo.h:544
void setUsedForHeaderGuard(bool Val)
Definition: MacroInfo.h:275
ID
Defines the set of possible language-specific address spaces.
Definition: AddressSpaces.h:27
SourceManager & SM
IdentifierInfo *const * arg_iterator
Definition: MacroInfo.h:176
void setHasCommaPasting()
Definition: MacroInfo.h:216
unsigned getNumArgs() const
Definition: MacroInfo.h:180
static bool classof(const VisibilityMacroDirective *)
Definition: MacroInfo.h:469
DefMacroDirective * getLocalDirective() const
Get the latest non-imported, non-#undef'd macro definition for this macro.
Definition: MacroInfo.h:593
#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:187
DefInfo getDefinition()
Traverses the macro directives history and returns the next macro definition directive along with inf...
Definition: MacroInfo.cpp:172
unsigned getOwningModuleID() const
Retrieve the global ID of the module that owns this particular macro info.
Definition: MacroInfo.h:279
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:232
arg_iterator arg_end() const
Definition: MacroInfo.h:179
bool IsPublic
Whether the macro has public visibility (when described in a module).
Definition: MacroInfo.h:328
bool isPublic() const
Determine whether this macro is part of the public API of its module.
Definition: MacroInfo.h:464
bool isC99Varargs() const
Definition: MacroInfo.h:203
unsigned MDKind
MacroDirective kind.
Definition: MacroInfo.h:319
void setIsUsed(bool Val)
Set the value of the IsUsed flag.
Definition: MacroInfo.h:149
void dump() const
Definition: MacroInfo.cpp:129
bool isFromASTFile() const
Determine whether this macro info came from an AST file (such as a precompiled header or module) rath...
Definition: MacroInfo.h:270
void setIsFunctionLike()
Definition: MacroInfo.h:196
Encapsulates changes to the "macros namespace" (the location where the macro name became active...
Definition: MacroInfo.h:308
#define false
Definition: stdbool.h:33
overrides_iterator overrides_end() const
Definition: MacroInfo.h:548
Encodes a location in the source. The SourceManager can decode this to get at the full include stack...
bool isFromPCH() const
Return true if the macro directive was loaded from a PCH file.
Definition: MacroInfo.h:349
bool isAllowRedefinitionsWithoutWarning() const
Return true if this macro can be redefined without warning.
Definition: MacroInfo.h:223
bool isValid() const
Return true if this is a valid SourceLocation object.
void setIsC99Varargs()
Varargs querying methods. This can only be set for function-like macros.
Definition: MacroInfo.h:201
void forAllDefinitions(Fn F) const
Definition: MacroInfo.h:600
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:361
Module * getOwningModule() const
Get the ID of the module that exports this macro.
Definition: MacroInfo.h:536
bool isAmbiguous() const
true if the definition is ambiguous, false otherwise.
Definition: MacroInfo.h:589
const Token & getReplacementToken(unsigned Tok) const
Definition: MacroInfo.h:234
DefMacroDirective * getDirective()
Definition: MacroInfo.h:366
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:204
const MacroInfo * getMacroInfo() const
Definition: MacroInfo.h:404
VisibilityMacroDirective(SourceLocation Loc, bool Public)
Definition: MacroInfo.h:457
MacroDefinition(DefMacroDirective *MD, ArrayRef< ModuleMacro * > MMs, bool IsAmbiguous)
Definition: MacroInfo.h:570
bool isDefined() const
Definition: MacroInfo.h:398
bool arg_empty() const
Definition: MacroInfo.h:177
SourceLocation getUndefLocation() const
Definition: MacroInfo.h:374
bool isFunctionLike() const
Definition: MacroInfo.h:197
Encapsulates the data about a macro definition (e.g. its tokens).
Definition: MacroInfo.h:34
const DefInfo getDefinition() const
Definition: MacroInfo.h:394
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:385
tokens_iterator tokens_end() const
Definition: MacroInfo.h:241
const MacroInfo * getInfo() const
The data for the macro definition.
Definition: MacroInfo.h:431
bool isBuiltinMacro() const
Return true if this macro requires processing before expansion.
Definition: MacroInfo.h:213
static bool isInvalid(SourceLocation Loc, bool *Invalid)
static void Profile(llvm::FoldingSetNodeID &ID, Module *OwningModule, IdentifierInfo *II)
Definition: MacroInfo.h:529
MacroInfo * getInfo()
Definition: MacroInfo.h:432
static bool classof(const DefMacroDirective *)
Definition: MacroInfo.h:437
static bool classof(const MacroDirective *)
Definition: MacroInfo.h:415
MacroDirective(Kind K, SourceLocation Loc)
Definition: MacroInfo.h:330
void dump() const
Definition: MacroInfo.cpp:208
void setPrevious(MacroDirective *Prev)
Set previous definition of the macro with the same name.
Definition: MacroInfo.h:340
static bool classof(const MacroDirective *MD)
Definition: MacroInfo.h:448
MacroInfo * getMacroInfo()
Definition: MacroInfo.h:407
unsigned getNumOverridingMacros() const
Get the number of macros that override this one.
Definition: MacroInfo.h:557
void EnableMacro()
Definition: MacroInfo.h:258
#define true
Definition: stdbool.h:32
arg_iterator arg_begin() const
Definition: MacroInfo.h:178
const MacroInfo * getMacroInfo() const
Definition: MacroInfo.h:370
This class handles loading and caching of source files into memory.
static bool classof(const MacroDirective *MD)
Definition: MacroInfo.h:466
SourceLocation Loc
Definition: MacroInfo.h:316
const MacroDirective * getPrevious() const
Get previous definition of the macro with the same name.
Definition: MacroInfo.h:343
UndefMacroDirective(SourceLocation UndefLoc)
Definition: MacroInfo.h:443
SourceLocation getLocation() const
Definition: MacroInfo.h:337
Engages in a tight little dance with the lexer to efficiently preprocess tokens.
Definition: Preprocessor.h:96
bool isUsed() const
Return false if this macro is defined in the main file and has not yet been used. ...
Definition: MacroInfo.h:220
const DefMacroDirective * getDirective() const
Definition: MacroInfo.h:365
static bool classof(const MacroDirective *MD)
Definition: MacroInfo.h:434
MacroDirective * Previous
Previous macro directive for the same identifier, or NULL.
Definition: MacroInfo.h:314