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