clang 10.0.0git

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