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