Coverage Report

Created: 2018-07-21 08:31

/Users/buildslave/jenkins/workspace/clang-stage2-coverage-R/llvm/tools/clang/include/clang/Lex/MacroInfo.h
Line
Count
Source (jump to first uncovered line)
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
/// 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"
20
#include "clang/Basic/SourceLocation.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
/// 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
  /// The location the macro is defined.
45
  SourceLocation Location;
46
47
  /// The location of the last token in the macro.
48
  SourceLocation EndLocation;
49
50
  /// 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
  /// This is the list of tokens that the macro is defined to.
62
  SmallVector<Token, 8> ReplacementTokens;
63
64
  /// Length in characters of the macro definition.
65
  mutable unsigned DefinitionLength;
66
  mutable bool IsDefinitionLengthCached : 1;
67
68
  /// True if this macro is function-like, false if it is object-like.
69
  bool IsFunctionLike : 1;
70
71
  /// 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
  /// 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
  /// 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
  /// 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
  /// 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
  /// 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
  /// True if this macro can be redefined without emitting a warning.
110
  bool IsAllowRedefinitionsWithoutWarning : 1;
111
112
  /// Must warn if the macro is unused at the end of translation unit.
113
  bool IsWarnIfUnused : 1;
114
115
  /// 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
10.8M
  ~MacroInfo() = default;
121
122
public:
123
  /// Return the location that the macro was defined at.
124
60.7M
  SourceLocation getDefinitionLoc() const { return Location; }
125
126
  /// Set the location of the last token in the macro.
127
22.5M
  void setDefinitionEndLoc(SourceLocation EndLoc) { EndLocation = EndLoc; }
128
129
  /// Return the location of the last token in the macro.
130
1.31M
  SourceLocation getDefinitionEndLoc() const { return EndLocation; }
131
132
  /// Get length in characters of the macro definition.
133
8.49M
  unsigned getDefinitionLength(const SourceManager &SM) const {
134
8.49M
    if (IsDefinitionLengthCached)
135
8.04M
      return DefinitionLength;
136
451k
    return getDefinitionLengthSlow(SM);
137
451k
  }
138
139
  /// 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
  /// Set or clear the isBuiltinMacro flag.
150
961k
  void setIsBuiltinMacro(bool Val = true) { IsBuiltinMacro = Val; }
151
152
  /// Set the value of the IsUsed flag.
153
13.6M
  void setIsUsed(bool Val) { IsUsed = Val; }
154
155
  /// Set the value of the IsAllowRedefinitionsWithoutWarning flag.
156
3
  void setIsAllowRedefinitionsWithoutWarning(bool Val) {
157
3
    IsAllowRedefinitionsWithoutWarning = Val;
158
3
  }
159
160
  /// Set the value of the IsWarnIfUnused flag.
161
17
  void setIsWarnIfUnused(bool val) { IsWarnIfUnused = val; }
162
163
  /// Set the specified list of identifiers as the parameter list for
164
  /// this macro.
165
  void setParameterList(ArrayRef<IdentifierInfo *> List,
166
3.10M
                       llvm::BumpPtrAllocator &PPAllocator) {
167
3.10M
    assert(ParameterList == nullptr && NumParameters == 0 &&
168
3.10M
           "Parameter list already set!");
169
3.10M
    if (List.empty())
170
10
      return;
171
3.10M
172
3.10M
    NumParameters = List.size();
173
3.10M
    ParameterList = PPAllocator.Allocate<IdentifierInfo *>(List.size());
174
3.10M
    std::copy(List.begin(), List.end(), ParameterList);
175
3.10M
  }
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
46
  bool param_empty() const { return NumParameters == 0; }
181
25.4M
  param_iterator param_begin() const { return ParameterList; }
182
18.5M
  param_iterator param_end() const { return ParameterList + NumParameters; }
183
16.8M
  unsigned getNumParams() const { return NumParameters; }
184
9.79k
  ArrayRef<const IdentifierInfo *> params() const {
185
9.79k
    return ArrayRef<const IdentifierInfo *>(ParameterList, NumParameters);
186
9.79k
  }
187
188
  /// Return the parameter number of the specified identifier,
189
  /// or -1 if the identifier is not a formal parameter identifier.
190
17.3M
  int getParameterNum(const IdentifierInfo *Arg) const {
191
41.4M
    for (param_iterator I = param_begin(), E = param_end(); I != E; 
++I24.1M
)
192
31.1M
      if (*I == Arg)
193
7.07M
        return I - param_begin();
194
17.3M
    
return -110.2M
;
195
17.3M
  }
196
197
  /// Function/Object-likeness.  Keep track of whether this macro has formal
198
  /// parameters.
199
3.11M
  void setIsFunctionLike() { IsFunctionLike = true; }
200
36.5M
  bool isFunctionLike() const { return IsFunctionLike; }
201
25.7M
  bool isObjectLike() const { return !IsFunctionLike; }
202
203
  /// Varargs querying methods.  This can only be set for function-like macros.
204
65.9k
  void setIsC99Varargs() { IsC99Varargs = true; }
205
74
  void setIsGNUVarargs() { IsGNUVarargs = true; }
206
3.75M
  bool isC99Varargs() const { return IsC99Varargs; }
207
634k
  bool isGNUVarargs() const { return IsGNUVarargs; }
208
8.37M
  bool isVariadic() const { return IsC99Varargs | IsGNUVarargs; }
209
210
  /// 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
17.2M
  bool isBuiltinMacro() const { return IsBuiltinMacro; }
217
218
16.0k
  bool hasCommaPasting() const { return HasCommaPasting; }
219
384
  void setHasCommaPasting() { HasCommaPasting = true; }
220
221
  /// Return false if this macro is defined in the main file and has
222
  /// not yet been used.
223
1.13M
  bool isUsed() const { return IsUsed; }
224
225
  /// Return true if this macro can be redefined without warning.
226
312k
  bool isAllowRedefinitionsWithoutWarning() const {
227
312k
    return IsAllowRedefinitionsWithoutWarning;
228
312k
  }
229
230
  /// Return true if we should emit a warning if the macro is unused.
231
14.4M
  bool isWarnIfUnused() const { return IsWarnIfUnused; }
232
233
  /// Return the number of tokens that this macro expands to.
234
48.0M
  unsigned getNumTokens() const { return ReplacementTokens.size(); }
235
236
51.6M
  const Token &getReplacementToken(unsigned Tok) const {
237
51.6M
    assert(Tok < ReplacementTokens.size() && "Invalid token #");
238
51.6M
    return ReplacementTokens[Tok];
239
51.6M
  }
240
241
  using tokens_iterator = SmallVectorImpl<Token>::const_iterator;
242
243
17.3M
  tokens_iterator tokens_begin() const { return ReplacementTokens.begin(); }
244
8.49M
  tokens_iterator tokens_end() const { return ReplacementTokens.end(); }
245
371k
  bool tokens_empty() const { return ReplacementTokens.empty(); }
246
372k
  ArrayRef<Token> tokens() const { return ReplacementTokens; }
247
248
  /// Add the specified token to the replacement text for the macro.
249
108M
  void AddTokenToBody(const Token &Tok) {
250
108M
    assert(
251
108M
        !IsDefinitionLengthCached &&
252
108M
        "Changing replacement tokens after definition length got calculated");
253
108M
    ReplacementTokens.push_back(Tok);
254
108M
  }
255
256
  /// Return true if this macro is enabled.
257
  ///
258
  /// In other words, that we are not currently in an expansion of this macro.
259
16.1M
  bool isEnabled() const { return !IsDisabled; }
260
261
8.49M
  void EnableMacro() {
262
8.49M
    assert(IsDisabled && "Cannot enable an already-enabled macro!");
263
8.49M
    IsDisabled = false;
264
8.49M
  }
265
266
8.49M
  void DisableMacro() {
267
8.49M
    assert(!IsDisabled && "Cannot disable an already-disabled macro!");
268
8.49M
    IsDisabled = true;
269
8.49M
  }
270
271
  /// Determine whether this macro was used for a header guard.
272
862k
  bool isUsedForHeaderGuard() const { return UsedForHeaderGuard; }
273
274
429k
  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
/// 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.
291
class MacroDirective {
292
public:
293
  enum Kind {
294
    MD_Define,
295
    MD_Undefine,
296
    MD_Visibility
297
  };
298
299
protected:
300
  /// Previous macro directive for the same identifier, or nullptr.
301
  MacroDirective *Previous = nullptr;
302
303
  SourceLocation Loc;
304
305
  /// MacroDirective kind.
306
  unsigned MDKind : 2;
307
308
  /// True if the macro directive was loaded from a PCH file.
309
  unsigned IsFromPCH : 1;
310
311
  // Used by VisibilityMacroDirective ----------------------------------------//
312
313
  /// Whether the macro has public visibility (when described in a
314
  /// module).
315
  unsigned IsPublic : 1;
316
317
  MacroDirective(Kind K, SourceLocation Loc)
318
23.5M
      : Loc(Loc), MDKind(K), IsFromPCH(false), IsPublic(true) {}
319
320
public:
321
118M
  Kind getKind() const { return Kind(MDKind); }
322
323
1.43M
  SourceLocation getLocation() const { return Loc; }
324
325
  /// Set previous definition of the macro with the same name.
326
23.5M
  void setPrevious(MacroDirective *Prev) { Previous = Prev; }
327
328
  /// Get previous definition of the macro with the same name.
329
0
  const MacroDirective *getPrevious() const { return Previous; }
330
331
  /// Get previous definition of the macro with the same name.
332
815k
  MacroDirective *getPrevious() { return Previous; }
333
334
  /// 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
0
  class DefInfo {
340
    DefMacroDirective *DefDirective = nullptr;
341
    SourceLocation UndefLoc;
342
    bool IsPublic = true;
343
344
  public:
345
2.57k
    DefInfo() = default;
346
    DefInfo(DefMacroDirective *DefDirective, SourceLocation UndefLoc,
347
            bool isPublic)
348
66.4M
        : DefDirective(DefDirective), UndefLoc(UndefLoc), IsPublic(isPublic) {}
349
350
0
    const DefMacroDirective *getDirective() const { return DefDirective; }
351
15
    DefMacroDirective *getDirective() { return DefDirective; }
352
353
    inline SourceLocation getLocation() const;
354
    inline MacroInfo *getMacroInfo();
355
356
1.52M
    const MacroInfo *getMacroInfo() const {
357
1.52M
      return const_cast<DefInfo *>(this)->getMacroInfo();
358
1.52M
    }
359
360
250
    SourceLocation getUndefLocation() const { return UndefLoc; }
361
24.0M
    bool isUndefined() const { return UndefLoc.isValid(); }
362
363
    bool isPublic() const { return IsPublic; }
364
365
66.9M
    bool isValid() const { return DefDirective != nullptr; }
366
42.7M
    bool isInvalid() const { return !isValid(); }
367
368
24.1M
    explicit operator bool() const { return isValid(); }
369
370
    inline DefInfo getPreviousDefinition();
371
372
0
    const DefInfo getPreviousDefinition() const {
373
0
      return const_cast<DefInfo *>(this)->getPreviousDefinition();
374
0
    }
375
  };
376
377
  /// 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.
380
  DefInfo getDefinition();
381
25.4M
  const DefInfo getDefinition() const {
382
25.4M
    return const_cast<MacroDirective *>(this)->getDefinition();
383
25.4M
  }
384
385
23.9M
  bool isDefined() const {
386
23.9M
    if (const DefInfo Def = getDefinition())
387
23.9M
      return !Def.isUndefined();
388
133
    return false;
389
133
  }
390
391
1.35M
  const MacroInfo *getMacroInfo() const {
392
1.35M
    return getDefinition().getMacroInfo();
393
1.35M
  }
394
41.0M
  MacroInfo *getMacroInfo() { return getDefinition().getMacroInfo(); }
395
396
  /// 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
/// A directive for a defined macro or a macro imported from a module.
406
class DefMacroDirective : public MacroDirective {
407
  MacroInfo *Info;
408
409
public:
410
  DefMacroDirective(MacroInfo *MI, SourceLocation Loc)
411
23.5M
      : MacroDirective(MD_Define, Loc), Info(MI) {
412
23.5M
    assert(MI && "MacroInfo is null");
413
23.5M
  }
414
  explicit DefMacroDirective(MacroInfo *MI)
415
      : DefMacroDirective(MI, MI->getDefinitionLoc()) {}
416
417
  /// The data for the macro definition.
418
0
  const MacroInfo *getInfo() const { return Info; }
419
43.4M
  MacroInfo *getInfo() { return Info; }
420
421
92.3M
  static bool classof(const MacroDirective *MD) {
422
92.3M
    return MD->getKind() == MD_Define;
423
92.3M
  }
424
425
0
  static bool classof(const DefMacroDirective *) { return true; }
426
};
427
428
/// A directive for an undefined macro.
429
class UndefMacroDirective : public MacroDirective {
430
public:
431
  explicit UndefMacroDirective(SourceLocation UndefLoc)
432
86.3k
      : MacroDirective(MD_Undefine, UndefLoc) {
433
86.3k
    assert(UndefLoc.isValid() && "Invalid UndefLoc!");
434
86.3k
  }
435
436
87.0k
  static bool classof(const MacroDirective *MD) {
437
87.0k
    return MD->getKind() == MD_Undefine;
438
87.0k
  }
439
440
0
  static bool classof(const UndefMacroDirective *) { return true; }
441
};
442
443
/// A directive for setting the module visibility of a macro.
444
class VisibilityMacroDirective : public MacroDirective {
445
public:
446
  explicit VisibilityMacroDirective(SourceLocation Loc, bool Public)
447
174
      : MacroDirective(MD_Visibility, Loc) {
448
174
    IsPublic = Public;
449
174
  }
450
451
  /// Determine whether this macro is part of the public API of its
452
  /// module.
453
645
  bool isPublic() const { return IsPublic; }
454
455
25.0M
  static bool classof(const MacroDirective *MD) {
456
25.0M
    return MD->getKind() == MD_Visibility;
457
25.0M
  }
458
459
0
  static bool classof(const VisibilityMacroDirective *) { return true; }
460
};
461
462
110k
inline SourceLocation MacroDirective::DefInfo::getLocation() const {
463
110k
  if (isInvalid())
464
0
    return {};
465
110k
  return DefDirective->getLocation();
466
110k
}
467
468
42.6M
inline MacroInfo *MacroDirective::DefInfo::getMacroInfo() {
469
42.6M
  if (isInvalid())
470
0
    return nullptr;
471
42.6M
  return DefDirective->getInfo();
472
42.6M
}
473
474
inline MacroDirective::DefInfo
475
2.43k
MacroDirective::DefInfo::getPreviousDefinition() {
476
2.43k
  if (isInvalid() || DefDirective->getPrevious() == nullptr)
477
2.27k
    return {};
478
159
  return DefDirective->getPrevious()->getDefinition();
479
159
}
480
481
/// 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
14.7k
        NumOverrides(Overrides.size()) {
510
14.7k
    std::copy(Overrides.begin(), Overrides.end(),
511
14.7k
              reinterpret_cast<ModuleMacro **>(this + 1));
512
14.7k
  }
513
514
public:
515
  static ModuleMacro *create(Preprocessor &PP, Module *OwningModule,
516
                             IdentifierInfo *II, MacroInfo *Macro,
517
                             ArrayRef<ModuleMacro *> Overrides);
518
519
30.8k
  void Profile(llvm::FoldingSetNodeID &ID) const {
520
30.8k
    return Profile(ID, OwningModule, II);
521
30.8k
  }
522
523
  static void Profile(llvm::FoldingSetNodeID &ID, Module *OwningModule,
524
45.6k
                      IdentifierInfo *II) {
525
45.6k
    ID.AddPointer(OwningModule);
526
45.6k
    ID.AddPointer(II);
527
45.6k
  }
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
16.2k
  Module *getOwningModule() const { return OwningModule; }
534
535
  /// Get definition for this exported #define, or nullptr if this
536
  /// represents a #undef.
537
17.7k
  MacroInfo *getMacroInfo() const { return Macro; }
538
539
  /// Iterators over the overridden module IDs.
540
  /// \{
541
  using overrides_iterator = ModuleMacro *const *;
542
543
56.6k
  overrides_iterator overrides_begin() const {
544
56.6k
    return reinterpret_cast<overrides_iterator>(this + 1);
545
56.6k
  }
546
547
28.3k
  overrides_iterator overrides_end() const {
548
28.3k
    return overrides_begin() + NumOverrides;
549
28.3k
  }
550
551
28.3k
  ArrayRef<ModuleMacro *> overrides() const {
552
28.3k
    return llvm::makeArrayRef(overrides_begin(), overrides_end());
553
28.3k
  }
554
  /// \}
555
556
  /// Get the number of macros that override this one.
557
178
  unsigned getNumOverridingMacros() const { return NumOverriddenBy; }
558
};
559
560
/// 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.
564
class MacroDefinition {
565
  llvm::PointerIntPair<DefMacroDirective *, 1, bool> LatestLocalAndAmbiguous;
566
  ArrayRef<ModuleMacro *> ModuleMacros;
567
568
public:
569
2.40M
  MacroDefinition() = default;
570
  MacroDefinition(DefMacroDirective *MD, ArrayRef<ModuleMacro *> MMs,
571
                  bool IsAmbiguous)
572
25.0M
      : LatestLocalAndAmbiguous(MD, IsAmbiguous), ModuleMacros(MMs) {}
573
574
  /// Determine whether there is a definition of this macro.
575
27.1M
  explicit operator bool() const {
576
27.1M
    return getLocalDirective() || 
!ModuleMacros.empty()2.45M
;
577
27.1M
  }
578
579
  /// Get the MacroInfo that should be used for this definition.
580
40.4M
  MacroInfo *getMacroInfo() const {
581
40.4M
    if (!ModuleMacros.empty())
582
1.90k
      return ModuleMacros.back()->getMacroInfo();
583
40.4M
    if (auto *MD = getLocalDirective())
584
39.3M
      return MD->getMacroInfo();
585
1.17M
    return nullptr;
586
1.17M
  }
587
588
  /// \c true if the definition is ambiguous, \c false otherwise.
589
12.3M
  bool isAmbiguous() const { return LatestLocalAndAmbiguous.getInt(); }
590
591
  /// Get the latest non-imported, non-\#undef'd macro definition
592
  /// for this macro.
593
67.6M
  DefMacroDirective *getLocalDirective() const {
594
67.6M
    return LatestLocalAndAmbiguous.getPointer();
595
67.6M
  }
596
597
  /// Get the active module macros for this macro.
598
113
  ArrayRef<ModuleMacro *> getModuleMacros() const { return ModuleMacros; }
599
600
113
  template <typename Fn> void forAllDefinitions(Fn F) const {
601
113
    if (auto *MD = getLocalDirective())
602
57
      F(MD->getMacroInfo());
603
113
    for (auto *MM : getModuleMacros())
604
97
      F(MM->getMacroInfo());
605
113
  }
PPMacroExpansion.cpp:void clang::MacroDefinition::forAllDefinitions<clang::Preprocessor::HandleMacroExpandedIdentifier(clang::Token&, clang::MacroDefinition const&)::$_1>(clang::Preprocessor::HandleMacroExpandedIdentifier(clang::Token&, clang::MacroDefinition const&)::$_1) const
Line
Count
Source
600
45
  template <typename Fn> void forAllDefinitions(Fn F) const {
601
45
    if (auto *MD = getLocalDirective())
602
13
      F(MD->getMacroInfo());
603
45
    for (auto *MM : getModuleMacros())
604
77
      F(MM->getMacroInfo());
605
45
  }
PreprocessingRecord.cpp:void clang::MacroDefinition::forAllDefinitions<clang::PreprocessingRecord::MacroUndefined(clang::Token const&, clang::MacroDefinition const&, clang::MacroDirective const*)::$_0>(clang::PreprocessingRecord::MacroUndefined(clang::Token const&, clang::MacroDefinition const&, clang::MacroDirective const*)::$_0) const
Line
Count
Source
600
68
  template <typename Fn> void forAllDefinitions(Fn F) const {
601
68
    if (auto *MD = getLocalDirective())
602
44
      F(MD->getMacroInfo());
603
68
    for (auto *MM : getModuleMacros())
604
20
      F(MM->getMacroInfo());
605
68
  }
606
};
607
608
} // namespace clang
609
610
#endif // LLVM_CLANG_LEX_MACROINFO_H