SourceLocation Location;
/// EndLocation - The location of the last token in the macro.
SourceLocation EndLocation;
- /// \brief The location where the macro was #undef'd, or an invalid location
- /// for macros that haven't been undefined.
- SourceLocation UndefLocation;
- /// \brief Previous definition, the identifier of this macro was defined to,
- /// or NULL.
- MacroInfo *PreviousDefinition;
/// Arguments - The list of arguments for a function-like macro. This can be
/// empty, for, e.g. "#define X()". In a C99-style variadic macro, this
/// includes the \c __VA_ARGS__ identifier on the list.
IdentifierInfo **ArgumentList;
unsigned NumArguments;
-
- /// \brief The location at which this macro was either explicitly exported
- /// from its module or marked as private.
- ///
- /// If invalid, this macro has not been explicitly given any visibility.
- SourceLocation VisibilityLocation;
/// \brief This is the list of tokens that the macro is defined to.
SmallVector<Token, 8> ReplacementTokens;
/// \brief Whether this macro contains the sequence ", ## __VA_ARGS__"
bool HasCommaPasting : 1;
-
- /// \brief True if this macro was loaded from an AST file.
- bool IsFromAST : 1;
-
- /// \brief Whether this macro changed after it was loaded from an AST file.
- bool ChangedAfterLoad : 1;
private:
//===--------------------------------------------------------------------===//
/// \brief Must warn if the macro is unused at the end of translation unit.
bool IsWarnIfUnused : 1;
-
- /// \brief Whether the macro has public (when described in a module).
- bool IsPublic : 1;
-
- /// \brief Whether the macro definition is currently "hidden".
- /// Note that this is transient state that is never serialized to the AST
- /// file.
- bool IsHidden : 1;
-
- /// \brief Whether the definition of this macro is ambiguous, due to
- /// multiple definitions coming in from multiple modules.
- bool IsAmbiguous : 1;
~MacroInfo() {
assert(ArgumentList == 0 && "Didn't call destroy before dtor!");
public:
MacroInfo(SourceLocation DefLoc);
- MacroInfo(const MacroInfo &MI, llvm::BumpPtrAllocator &PPAllocator);
/// FreeArgumentList - Free the argument list of the macro, restoring it to a
/// state where it can be reused for other devious purposes.
///
SourceLocation getDefinitionEndLoc() const { return EndLocation; }
- /// \brief Set the location where macro was undefined. Can only be set once.
- void setUndefLoc(SourceLocation UndefLoc) {
- assert(UndefLocation.isInvalid() && "UndefLocation is already set!");
- assert(UndefLoc.isValid() && "Invalid UndefLoc!");
- UndefLocation = UndefLoc;
- }
-
- /// \brief Get the location where macro was undefined.
- SourceLocation getUndefLoc() const { return UndefLocation; }
-
- /// \brief Set previous definition of the macro with the same name.
- void setPreviousDefinition(MacroInfo *PreviousDef) {
- PreviousDefinition = PreviousDef;
- }
-
- /// \brief Get previous definition of the macro with the same name.
- MacroInfo *getPreviousDefinition() { return PreviousDefinition; }
-
- /// \brief Find macro definition active in the specified source location. If
- /// this macro was not defined there, return NULL.
- const MacroInfo *findDefinitionAtLoc(SourceLocation L,
- SourceManager &SM) const;
-
/// \brief Get length in characters of the macro definition.
unsigned getDefinitionLength(SourceManager &SM) const {
if (IsDefinitionLengthCached)
bool hasCommaPasting() const { return HasCommaPasting; }
void setHasCommaPasting() { HasCommaPasting = true; }
- /// isFromAST - Return true if this macro was loaded from an AST file.
- bool isFromAST() const { return IsFromAST; }
-
- /// setIsFromAST - Set whether this macro was loaded from an AST file.
- void setIsFromAST(bool FromAST = true) { IsFromAST = FromAST; }
-
- /// \brief Determine whether this macro has changed since it was loaded from
- /// an AST file.
- bool hasChangedAfterLoad() const { return ChangedAfterLoad; }
-
- /// \brief Note whether this macro has changed after it was loaded from an
- /// AST file.
- void setChangedAfterLoad(bool CAL = true) { ChangedAfterLoad = CAL; }
-
/// isUsed - Return false if this macro is defined in the main file and has
/// not yet been used.
bool isUsed() const { return IsUsed; }
IsDisabled = true;
}
+private:
+ unsigned getDefinitionLengthSlow(SourceManager &SM) const;
+};
+
+class MacroDirective {
+ MacroInfo *Info;
+
+ /// \brief Previous definition, the identifier of this macro was defined to,
+ /// or NULL.
+ MacroDirective *Previous;
+
+ SourceLocation Loc;
+
+ /// \brief The location where the macro was #undef'd, or an invalid location
+ /// for macros that haven't been undefined.
+ SourceLocation UndefLocation;
+
+ /// \brief The location at which this macro was either explicitly exported
+ /// from its module or marked as private.
+ ///
+ /// If invalid, this macro has not been explicitly given any visibility.
+ SourceLocation VisibilityLocation;
+
+ /// \brief True if this macro was loaded from an AST file.
+ bool IsImported : 1;
+
+ /// \brief Whether the macro has public (when described in a module).
+ bool IsPublic : 1;
+
+ /// \brief Whether the macro definition is currently "hidden".
+ /// Note that this is transient state that is never serialized to the AST
+ /// file.
+ bool IsHidden : 1;
+
+ /// \brief Whether the definition of this macro is ambiguous, due to
+ /// multiple definitions coming in from multiple modules.
+ bool IsAmbiguous : 1;
+
+ /// \brief Whether this macro changed after it was loaded from an AST file.
+ bool ChangedAfterLoad : 1;
+
+public:
+ explicit MacroDirective(MacroInfo *MI)
+ : Info(MI), Previous(0), Loc(MI->getDefinitionLoc()),
+ IsImported(false), IsPublic(true), IsHidden(false), IsAmbiguous(false),
+ ChangedAfterLoad(false) {
+ assert(MI && "MacroInfo is null");
+ }
+
+ MacroDirective(MacroInfo *MI, SourceLocation Loc, bool isImported)
+ : Info(MI), Previous(0), Loc(Loc),
+ IsImported(isImported), IsPublic(true), IsHidden(false),
+ IsAmbiguous(false), ChangedAfterLoad(false) {
+ assert(MI && "MacroInfo is null");
+ }
+
+ SourceLocation getLocation() const { return Loc; }
+
+ /// \brief Set the location where macro was undefined. Can only be set once.
+ void setUndefLoc(SourceLocation UndefLoc) {
+ assert(UndefLocation.isInvalid() && "UndefLocation is already set!");
+ assert(UndefLoc.isValid() && "Invalid UndefLoc!");
+ UndefLocation = UndefLoc;
+ }
+
+ const MacroInfo *getInfo() const { return Info; }
+ MacroInfo *getInfo() { return Info; }
+
+ /// \brief Get the location where macro was undefined.
+ SourceLocation getUndefLoc() const { return UndefLocation; }
+
+ /// \brief Set previous definition of the macro with the same name.
+ void setPrevious(MacroDirective *Prev) {
+ Previous = Prev;
+ }
+
+ /// \brief Get previous definition of the macro with the same name.
+ const MacroDirective *getPrevious() const { return Previous; }
+
+ /// \brief Get previous definition of the macro with the same name.
+ MacroDirective *getPrevious() { return Previous; }
+
+ /// \brief Find macro definition active in the specified source location. If
+ /// this macro was not defined there, return NULL.
+ const MacroDirective *findDirectiveAtLoc(SourceLocation L,
+ SourceManager &SM) const;
+
/// \brief Set the export location for this macro.
void setVisibility(bool Public, SourceLocation Loc) {
VisibilityLocation = Loc;
/// \brief Determine the location where this macro was explicitly made
/// public or private within its module.
- SourceLocation getVisibilityLocation() { return VisibilityLocation; }
+ SourceLocation getVisibilityLocation() const { return VisibilityLocation; }
+
+ /// \brief True if this macro was loaded from an AST file.
+ bool isImported() const { return IsImported; }
/// \brief Determine whether this macro is currently defined (and has not
/// been #undef'd) or has been hidden.
/// \brief Set whether this macro definition is ambiguous.
void setAmbiguous(bool Val) { IsAmbiguous = Val; }
-
-private:
- unsigned getDefinitionLengthSlow(SourceManager &SM) const;
+
+ /// \brief Determine whether this macro has changed since it was loaded from
+ /// an AST file.
+ bool hasChangedAfterLoad() const { return ChangedAfterLoad; }
+
+ /// \brief Note whether this macro has changed after it was loaded from an
+ /// AST file.
+ void setChangedAfterLoad(bool CAL = true) { ChangedAfterLoad = CAL; }
};
} // end namespace clang
namespace clang {
-class MacroInfo;
+class MacroDirective;
/// \brief A record that describes an update to a macro that was
/// originally loaded to an AST file and has been modified within the
virtual ~PPMutationListener();
/// \brief A macro has been #undef'd.
- virtual void UndefinedMacro(MacroInfo *MI) { }
+ virtual void UndefinedMacro(MacroDirective *MD) { }
};
} // end namespace clang
/// Macros - For each IdentifierInfo that was associated with a macro, we
/// keep a mapping to the history of all macro definitions and #undefs in
/// the reverse order (the latest one is in the head of the list).
- llvm::DenseMap<const IdentifierInfo*, MacroInfo*> Macros;
+ llvm::DenseMap<const IdentifierInfo*, MacroDirective*> Macros;
friend class ASTReader;
/// \brief Macros that we want to warn because they are not used at the end
/// \brief Given an identifier, return the MacroInfo it is \#defined to
/// or null if it isn't \#define'd.
- MacroInfo *getMacroInfo(IdentifierInfo *II) const {
+ MacroDirective *getMacroDirective(IdentifierInfo *II) const {
if (!II->hasMacroDefinition())
return 0;
- MacroInfo *MI = getMacroInfoHistory(II);
- assert(MI->getUndefLoc().isInvalid() && "Macro is undefined!");
- return MI;
+ MacroDirective *MD = getMacroDirectiveHistory(II);
+ assert(MD->getUndefLoc().isInvalid() && "Macro is undefined!");
+ return MD;
+ }
+
+ const MacroInfo *getMacroInfo(IdentifierInfo *II) const {
+ return const_cast<Preprocessor*>(this)->getMacroInfo(II);
+ }
+
+ MacroInfo *getMacroInfo(IdentifierInfo *II) {
+ if (MacroDirective *MD = getMacroDirective(II))
+ return MD->getInfo();
+ return 0;
}
/// \brief Given an identifier, return the (probably #undef'd) MacroInfo
/// representing the most recent macro definition. One can iterate over all
/// previous macro definitions from it. This method should only be called for
/// identifiers that hadMacroDefinition().
- MacroInfo *getMacroInfoHistory(const IdentifierInfo *II) const;
+ MacroDirective *getMacroDirectiveHistory(const IdentifierInfo *II) const;
/// \brief Specify a macro for this identifier.
- void setMacroInfo(IdentifierInfo *II, MacroInfo *MI);
+ void setMacroDirective(IdentifierInfo *II, MacroInfo *MI,
+ SourceLocation Loc, bool isImported);
+ void setMacroDirective(IdentifierInfo *II, MacroInfo *MI) {
+ setMacroDirective(II, MI, MI->getDefinitionLoc(), false);
+ }
/// \brief Add a MacroInfo that was loaded from an AST file.
- void addLoadedMacroInfo(IdentifierInfo *II, MacroInfo *MI,
- MacroInfo *Hint = 0);
+ void addLoadedMacroInfo(IdentifierInfo *II, MacroDirective *MD,
+ MacroDirective *Hint = 0);
/// \brief Make the given MacroInfo, that was loaded from an AST file and
/// previously hidden, visible.
- void makeLoadedMacroInfoVisible(IdentifierInfo *II, MacroInfo *MI);
+ void makeLoadedMacroInfoVisible(IdentifierInfo *II, MacroDirective *MD);
/// \brief Undefine a macro for this identifier.
void clearMacroInfo(IdentifierInfo *II);
/// IdentifierInfo::hasMacroDefinition() set and an empty
/// MacroInfo::getUndefLoc() at the head of the list.
typedef llvm::DenseMap<const IdentifierInfo *,
- MacroInfo*>::const_iterator macro_iterator;
+ MacroDirective*>::const_iterator macro_iterator;
macro_iterator macro_begin(bool IncludeExternalMacros = true) const;
macro_iterator macro_end(bool IncludeExternalMacros = true) const;
/// \brief Allocate a new MacroInfo object with the provided SourceLocation.
MacroInfo *AllocateMacroInfo(SourceLocation L);
- /// \brief Allocate a new MacroInfo object which is clone of \p MI.
- MacroInfo *CloneMacroInfo(const MacroInfo &MI);
-
/// \brief Turn the specified lexer token into a fully checked and spelled
/// filename, e.g. as an operand of \#include.
///
/// \brief Allocate a new MacroInfo object.
MacroInfo *AllocateMacroInfo();
+ MacroDirective *AllocateMacroDirective(MacroInfo *MI, SourceLocation Loc,
+ bool isImported);
+
/// \brief Release the specified MacroInfo for re-use.
///
/// This memory will be reused for allocating new MacroInfo objects.
// Macro handling.
void HandleDefineDirective(Token &Tok);
void HandleUndefDirective(Token &Tok);
- void UndefineMacro(IdentifierInfo *II, MacroInfo *MI,
+ void UndefineMacro(IdentifierInfo *II, MacroDirective *MD,
SourceLocation UndefLoc);
// Conditional Inclusion.
class ASTReader;
class QualType;
class MacroDefinition;
-class MacroInfo;
+class MacroDirective;
class Module;
class ASTDeserializationListener {
virtual void IdentifierRead(serialization::IdentID ID,
IdentifierInfo *II) { }
/// \brief A macro was read from the AST file.
- virtual void MacroRead(serialization::MacroID ID, MacroInfo *MI) { }
+ virtual void MacroRead(serialization::MacroID ID, MacroDirective *MD) { }
/// \brief A type was deserialized from the AST file. The ID here has the
/// qualifier bits already removed, and T is guaranteed to be locally
/// unqualified.
class GlobalModuleIndex;
class GotoStmt;
class MacroDefinition;
+class MacroDirective;
class NamedDecl;
class OpaqueValueExpr;
class Preprocessor;
/// If the pointer at index I is non-NULL, then it refers to the
/// MacroInfo for the identifier with ID=I+1 that has already
/// been loaded.
- std::vector<MacroInfo *> MacrosLoaded;
+ std::vector<MacroDirective *> MacrosLoaded;
typedef ContinuousRangeMap<serialization::MacroID, ModuleFile *, 4>
GlobalMacroMapType;
union {
Decl *D;
- MacroInfo *MI;
+ MacroDirective *MD;
};
IdentifierInfo *Id;
public:
HiddenName(Decl *D) : Kind(Declaration), Loc(), D(D), Id() { }
- HiddenName(IdentifierInfo *II, MacroInfo *MI)
- : Kind(MacroVisibility), Loc(), MI(MI), Id(II) { }
+ HiddenName(IdentifierInfo *II, MacroDirective *MD)
+ : Kind(MacroVisibility), Loc(), MD(MD), Id(II) { }
- HiddenName(IdentifierInfo *II, MacroInfo *MI, SourceLocation Loc)
- : Kind(MacroUndef), Loc(Loc.getRawEncoding()), MI(MI), Id(II) { }
+ HiddenName(IdentifierInfo *II, MacroDirective *MD, SourceLocation Loc)
+ : Kind(MacroUndef), Loc(Loc.getRawEncoding()), MD(MD), Id(II) { }
NameKind getKind() const { return Kind; }
return D;
}
- std::pair<IdentifierInfo *, MacroInfo *> getMacro() const {
+ std::pair<IdentifierInfo *, MacroDirective *> getMacro() const {
assert((getKind() == MacroUndef || getKind() == MacroVisibility)
&& "Hidden name is not a macro!");
- return std::make_pair(Id, MI);
+ return std::make_pair(Id, MD);
}
SourceLocation getMacroUndefLoc() const {
unsigned LocalID);
/// \brief Retrieve the macro with the given ID.
- MacroInfo *getMacro(serialization::MacroID ID, MacroInfo *Hint = 0);
+ MacroDirective *getMacro(serialization::MacroID ID, MacroDirective *Hint = 0);
/// \brief Retrieve the global macro ID corresponding to the given local
/// ID within the given module file.
Expr *ReadSubExpr();
/// \brief Reads the macro record located at the given offset.
- void ReadMacroRecord(ModuleFile &F, uint64_t Offset, MacroInfo *Hint = 0);
+ void ReadMacroRecord(ModuleFile &F, uint64_t Offset, MacroDirective *Hint = 0);
/// \brief Determine the global preprocessed entity ID that corresponds to
/// the given local ID within the given module.
class OpaqueValueExpr;
class OpenCLOptions;
class ASTReader;
-class MacroInfo;
+class MacroDirective;
class Module;
class PreprocessedEntity;
class PreprocessingRecord;
serialization::MacroID NextMacroID;
/// \brief Map that provides the ID numbers of each macro.
- llvm::DenseMap<MacroInfo *, serialization::MacroID> MacroIDs;
+ llvm::DenseMap<MacroDirective *, serialization::MacroID> MacroIDs;
/// @name FlushStmt Caches
/// @{
/// table, indexed by the Selector ID (-1).
std::vector<uint32_t> SelectorOffsets;
- typedef llvm::MapVector<MacroInfo *, MacroUpdate> MacroUpdatesMap;
+ typedef llvm::MapVector<MacroDirective *, MacroUpdate> MacroUpdatesMap;
/// \brief Updates to macro definitions that were loaded from an AST file.
MacroUpdatesMap MacroUpdates;
void AddIdentifierRef(const IdentifierInfo *II, RecordDataImpl &Record);
/// \brief Emit a reference to a macro.
- void addMacroRef(MacroInfo *MI, RecordDataImpl &Record);
+ void addMacroRef(MacroDirective *MI, RecordDataImpl &Record);
/// \brief Emit a Selector (which is a smart pointer reference).
void AddSelectorRef(Selector, RecordDataImpl &Record);
serialization::IdentID getIdentifierRef(const IdentifierInfo *II);
/// \brief Get the unique number used to refer to the given macro.
- serialization::MacroID getMacroRef(MacroInfo *MI);
+ serialization::MacroID getMacroRef(MacroDirective *MI);
/// \brief Emit a reference to a type.
void AddTypeRef(QualType T, RecordDataImpl &Record);
// ASTDeserializationListener implementation
void ReaderInitialized(ASTReader *Reader);
void IdentifierRead(serialization::IdentID ID, IdentifierInfo *II);
- void MacroRead(serialization::MacroID ID, MacroInfo *MI);
+ void MacroRead(serialization::MacroID ID, MacroDirective *MI);
void TypeRead(serialization::TypeIdx Idx, QualType T);
void SelectorRead(serialization::SelectorID ID, Selector Sel);
void MacroDefinitionRead(serialization::PreprocessedEntityID ID,
void ModuleRead(serialization::SubmoduleID ID, Module *Mod);
// PPMutationListener implementation.
- virtual void UndefinedMacro(MacroInfo *MI);
+ virtual void UndefinedMacro(MacroDirective *MD);
// ASTMutationListener implementation.
virtual void CompletedTagDefinition(const TagDecl *D);
for (Preprocessor::macro_iterator I = PP.macro_begin(), E = PP.macro_end();
I != E; ++I) {
if (I->first->hasMacroDefinition())
- MacrosByID.push_back(id_macro_pair(I->first, I->second));
+ MacrosByID.push_back(id_macro_pair(I->first, I->second->getInfo()));
}
llvm::array_pod_sort(MacrosByID.begin(), MacrosByID.end(), MacroIDCompare);
MacroInfo::MacroInfo(SourceLocation DefLoc)
: Location(DefLoc),
- PreviousDefinition(0),
ArgumentList(0),
NumArguments(0),
IsDefinitionLengthCached(false),
IsGNUVarargs(false),
IsBuiltinMacro(false),
HasCommaPasting(false),
- IsFromAST(false),
- ChangedAfterLoad(false),
IsDisabled(false),
IsUsed(false),
IsAllowRedefinitionsWithoutWarning(false),
- IsWarnIfUnused(false),
- IsPublic(true),
- IsHidden(false),
- IsAmbiguous(false) {
-}
-
-MacroInfo::MacroInfo(const MacroInfo &MI, llvm::BumpPtrAllocator &PPAllocator)
- : Location(MI.Location),
- EndLocation(MI.EndLocation),
- UndefLocation(MI.UndefLocation),
- PreviousDefinition(0),
- ArgumentList(0),
- NumArguments(0),
- ReplacementTokens(MI.ReplacementTokens),
- DefinitionLength(MI.DefinitionLength),
- IsDefinitionLengthCached(MI.IsDefinitionLengthCached),
- IsFunctionLike(MI.IsFunctionLike),
- IsC99Varargs(MI.IsC99Varargs),
- IsGNUVarargs(MI.IsGNUVarargs),
- IsBuiltinMacro(MI.IsBuiltinMacro),
- HasCommaPasting(MI.HasCommaPasting),
- IsFromAST(MI.IsFromAST),
- ChangedAfterLoad(MI.ChangedAfterLoad),
- IsDisabled(MI.IsDisabled),
- IsUsed(MI.IsUsed),
- IsAllowRedefinitionsWithoutWarning(MI.IsAllowRedefinitionsWithoutWarning),
- IsWarnIfUnused(MI.IsWarnIfUnused),
- IsPublic(MI.IsPublic),
- IsHidden(MI.IsHidden),
- IsAmbiguous(MI.IsAmbiguous) {
- setArgumentList(MI.ArgumentList, MI.NumArguments, PPAllocator);
-}
-
-const MacroInfo *MacroInfo::findDefinitionAtLoc(SourceLocation L,
- SourceManager &SM) const {
- assert(L.isValid() && "SourceLocation is invalid.");
- for (const MacroInfo *MI = this; MI; MI = MI->PreviousDefinition) {
- if (MI->Location.isInvalid() || // For macros defined on the command line.
- SM.isBeforeInTranslationUnit(MI->Location, L))
- return (MI->UndefLocation.isInvalid() ||
- SM.isBeforeInTranslationUnit(L, MI->UndefLocation)) ? MI : NULL;
- }
- return NULL;
+ IsWarnIfUnused(false) {
}
unsigned MacroInfo::getDefinitionLengthSlow(SourceManager &SM) const {
return true;
}
+
+const MacroDirective *
+MacroDirective::findDirectiveAtLoc(SourceLocation L, SourceManager &SM) const {
+ assert(L.isValid() && "SourceLocation is invalid.");
+ for (const MacroDirective *MD = this; MD; MD = MD->Previous) {
+ if (MD->getLocation().isInvalid() || // For macros defined on the command line.
+ SM.isBeforeInTranslationUnit(MD->getLocation(), L))
+ return (MD->UndefLocation.isInvalid() ||
+ SM.isBeforeInTranslationUnit(L, MD->UndefLocation)) ? MD : NULL;
+ }
+ return NULL;
+}
return MI;
}
-MacroInfo *Preprocessor::CloneMacroInfo(const MacroInfo &MacroToClone) {
- MacroInfo *MI = AllocateMacroInfo();
- new (MI) MacroInfo(MacroToClone, BP);
- return MI;
+MacroDirective *Preprocessor::AllocateMacroDirective(MacroInfo *MI,
+ SourceLocation Loc,
+ bool isImported) {
+ MacroDirective *MD = BP.Allocate<MacroDirective>();
+ new (MD) MacroDirective(MI, Loc, isImported);
+ return MD;
}
/// \brief Release the specified MacroInfo to be reused for allocating
CheckEndOfDirective("__public_macro");
// Okay, we finally have a valid identifier to undef.
- MacroInfo *MI = getMacroInfo(MacroNameTok.getIdentifierInfo());
+ MacroDirective *MD = getMacroDirective(MacroNameTok.getIdentifierInfo());
// If the macro is not defined, this is an error.
- if (MI == 0) {
+ if (MD == 0) {
Diag(MacroNameTok, diag::err_pp_visibility_non_macro)
<< MacroNameTok.getIdentifierInfo();
return;
}
// Note that this macro has now been exported.
- MI->setVisibility(/*IsPublic=*/true, MacroNameTok.getLocation());
-
+ MD->setVisibility(/*IsPublic=*/true, MacroNameTok.getLocation());
+
// If this macro definition came from a PCH file, mark it
// as having changed since serialization.
- if (MI->isFromAST())
- MI->setChangedAfterLoad();
+ if (MD->isImported())
+ MD->setChangedAfterLoad();
}
/// \brief Handle a #private directive.
CheckEndOfDirective("__private_macro");
// Okay, we finally have a valid identifier to undef.
- MacroInfo *MI = getMacroInfo(MacroNameTok.getIdentifierInfo());
+ MacroDirective *MD = getMacroDirective(MacroNameTok.getIdentifierInfo());
// If the macro is not defined, this is an error.
- if (MI == 0) {
+ if (MD == 0) {
Diag(MacroNameTok, diag::err_pp_visibility_non_macro)
<< MacroNameTok.getIdentifierInfo();
return;
}
// Note that this macro has now been marked private.
- MI->setVisibility(/*IsPublic=*/false, MacroNameTok.getLocation());
-
+ MD->setVisibility(/*IsPublic=*/false, MacroNameTok.getLocation());
+
// If this macro definition came from a PCH file, mark it
// as having changed since serialization.
- if (MI->isFromAST())
- MI->setChangedAfterLoad();
+ if (MD->isImported())
+ MD->setChangedAfterLoad();
}
//===----------------------------------------------------------------------===//
// Finally, if this identifier already had a macro defined for it, verify that
// the macro bodies are identical, and issue diagnostics if they are not.
- if (MacroInfo *OtherMI = getMacroInfo(MacroNameTok.getIdentifierInfo())) {
+ if (const MacroInfo *OtherMI=getMacroInfo(MacroNameTok.getIdentifierInfo())) {
// It is very common for system headers to have tons of macro redefinitions
// and for warnings to be disabled in system headers. If this is the case,
// then don't bother calling MacroInfo::isIdenticalTo.
WarnUnusedMacroLocs.erase(OtherMI->getDefinitionLoc());
}
- setMacroInfo(MacroNameTok.getIdentifierInfo(), MI);
+ setMacroDirective(MacroNameTok.getIdentifierInfo(), MI);
assert(!MI->isUsed());
// If we need warning for not using the macro, add its location in the
CheckEndOfDirective("undef");
// Okay, we finally have a valid identifier to undef.
- MacroInfo *MI = getMacroInfo(MacroNameTok.getIdentifierInfo());
+ MacroDirective *MD = getMacroDirective(MacroNameTok.getIdentifierInfo());
+ const MacroInfo *MI = MD ? MD->getInfo() : 0;
// If the callbacks want to know, tell them about the macro #undef.
// Note: no matter if the macro was defined or not.
if (MI->isWarnIfUnused())
WarnUnusedMacroLocs.erase(MI->getDefinitionLoc());
- UndefineMacro(MacroNameTok.getIdentifierInfo(), MI,
+ UndefineMacro(MacroNameTok.getIdentifierInfo(), MD,
MacroNameTok.getLocation());
}
-void Preprocessor::UndefineMacro(IdentifierInfo *II, MacroInfo *MI,
+void Preprocessor::UndefineMacro(IdentifierInfo *II, MacroDirective *MD,
SourceLocation UndefLoc) {
- MI->setUndefLoc(UndefLoc);
- if (MI->isFromAST()) {
- MI->setChangedAfterLoad();
+ MD->setUndefLoc(UndefLoc);
+ if (MD->isImported()) {
+ MD->setChangedAfterLoad();
if (Listener)
- Listener->UndefinedMacro(MI);
+ Listener->UndefinedMacro(MD);
}
clearMacroInfo(II);
#include <ctime>
using namespace clang;
-MacroInfo *Preprocessor::getMacroInfoHistory(const IdentifierInfo *II) const {
+MacroDirective *
+Preprocessor::getMacroDirectiveHistory(const IdentifierInfo *II) const {
assert(II->hadMacroDefinition() && "Identifier has not been not a macro!");
macro_iterator Pos = Macros.find(II);
/// setMacroInfo - Specify a macro for this identifier.
///
-void Preprocessor::setMacroInfo(IdentifierInfo *II, MacroInfo *MI) {
+void Preprocessor::setMacroDirective(IdentifierInfo *II, MacroInfo *MI,
+ SourceLocation Loc, bool isImported) {
assert(MI && "MacroInfo should be non-zero!");
- assert(MI->getUndefLoc().isInvalid() &&
- "Undefined macros cannot be registered");
- MacroInfo *&StoredMI = Macros[II];
- MI->setPreviousDefinition(StoredMI);
- StoredMI = MI;
- II->setHasMacroDefinition(MI->getUndefLoc().isInvalid());
+ MacroDirective *MD = AllocateMacroDirective(MI, Loc, isImported);
+ MacroDirective *&StoredMD = Macros[II];
+ MD->setPrevious(StoredMD);
+ StoredMD = MD;
+ II->setHasMacroDefinition(true);
if (II->isFromAST())
II->setChangedSinceDeserialization();
}
-void Preprocessor::addLoadedMacroInfo(IdentifierInfo *II, MacroInfo *MI,
- MacroInfo *Hint) {
- assert(MI && "Missing macro?");
- assert(MI->isFromAST() && "Macro is not from an AST?");
- assert(!MI->getPreviousDefinition() && "Macro already in chain?");
+void Preprocessor::addLoadedMacroInfo(IdentifierInfo *II, MacroDirective *MD,
+ MacroDirective *Hint) {
+ assert(MD && "Missing macro?");
+ assert(MD->isImported() && "Macro is not from an AST?");
+ assert(!MD->getPrevious() && "Macro already in chain?");
- MacroInfo *&StoredMI = Macros[II];
+ MacroDirective *&StoredMD = Macros[II];
// Easy case: this is the first macro definition for this macro.
- if (!StoredMI) {
- StoredMI = MI;
+ if (!StoredMD) {
+ StoredMD = MD;
- if (MI->isDefined())
+ if (MD->isDefined())
II->setHasMacroDefinition(true);
return;
}
// If this macro is a definition and this identifier has been neither
// defined nor undef'd in the current translation unit, add this macro
// to the end of the chain of definitions.
- if (MI->isDefined() && StoredMI->isFromAST()) {
+ if (MD->isDefined() && StoredMD->isImported()) {
// Simple case: if this is the first actual definition, just put it at
// th beginning.
- if (!StoredMI->isDefined()) {
- MI->setPreviousDefinition(StoredMI);
- StoredMI = MI;
+ if (!StoredMD->isDefined()) {
+ MD->setPrevious(StoredMD);
+ StoredMD = MD;
II->setHasMacroDefinition(true);
return;
}
// Find the end of the definition chain.
- MacroInfo *Prev;
- MacroInfo *PrevPrev = StoredMI;
- bool Ambiguous = StoredMI->isAmbiguous();
+ MacroDirective *Prev;
+ MacroDirective *PrevPrev = StoredMD;
+ bool Ambiguous = StoredMD->isAmbiguous();
bool MatchedOther = false;
do {
Prev = PrevPrev;
// If the macros are not identical, we have an ambiguity.
- if (!Prev->isIdenticalTo(*MI, *this)) {
+ if (!Prev->getInfo()->isIdenticalTo(*MD->getInfo(), *this)) {
if (!Ambiguous) {
Ambiguous = true;
- StoredMI->setAmbiguous(true);
+ StoredMD->setAmbiguous(true);
}
} else {
MatchedOther = true;
}
- } while ((PrevPrev = Prev->getPreviousDefinition()) &&
+ } while ((PrevPrev = Prev->getPrevious()) &&
PrevPrev->isDefined());
// If there are ambiguous definitions, and we didn't match any other
// definition, then mark us as ambiguous.
if (Ambiguous && !MatchedOther)
- MI->setAmbiguous(true);
+ MD->setAmbiguous(true);
// Wire this macro information into the chain.
- MI->setPreviousDefinition(Prev->getPreviousDefinition());
- Prev->setPreviousDefinition(MI);
+ MD->setPrevious(Prev->getPrevious());
+ Prev->setPrevious(MD);
return;
}
// The macro is not a definition; put it at the end of the list.
- MacroInfo *Prev = Hint? Hint : StoredMI;
- while (Prev->getPreviousDefinition())
- Prev = Prev->getPreviousDefinition();
- Prev->setPreviousDefinition(MI);
+ MacroDirective *Prev = Hint? Hint : StoredMD;
+ while (Prev->getPrevious())
+ Prev = Prev->getPrevious();
+ Prev->setPrevious(MD);
}
void Preprocessor::makeLoadedMacroInfoVisible(IdentifierInfo *II,
- MacroInfo *MI) {
- assert(MI->isFromAST() && "Macro must be from the AST");
+ MacroDirective *MD) {
+ assert(MD->isImported() && "Macro must be from the AST");
- MacroInfo *&StoredMI = Macros[II];
- if (StoredMI == MI) {
+ MacroDirective *&StoredMD = Macros[II];
+ if (StoredMD == MD) {
// Easy case: this is the first macro anyway.
- II->setHasMacroDefinition(MI->isDefined());
+ II->setHasMacroDefinition(MD->isDefined());
return;
}
// Go find the macro and pull it out of the list.
// FIXME: Yes, this is O(N), and making a pile of macros visible or hidden
// would be quadratic, but it's extremely rare.
- MacroInfo *Prev = StoredMI;
- while (Prev->getPreviousDefinition() != MI)
- Prev = Prev->getPreviousDefinition();
- Prev->setPreviousDefinition(MI->getPreviousDefinition());
- MI->setPreviousDefinition(0);
+ MacroDirective *Prev = StoredMD;
+ while (Prev->getPrevious() != MD)
+ Prev = Prev->getPrevious();
+ Prev->setPrevious(MD->getPrevious());
+ MD->setPrevious(0);
// Add the macro back to the list.
- addLoadedMacroInfo(II, MI);
+ addLoadedMacroInfo(II, MD);
- II->setHasMacroDefinition(StoredMI->isDefined());
+ II->setHasMacroDefinition(StoredMD->isDefined());
if (II->isFromAST())
II->setChangedSinceDeserialization();
}
// Mark it as being a macro that is builtin.
MacroInfo *MI = PP.AllocateMacroInfo(SourceLocation());
MI->setIsBuiltinMacro();
- PP.setMacroInfo(Id, MI);
+ PP.setMacroDirective(Id, MI);
return Id;
}
// Get the MacroInfo associated with IdentInfo.
MacroInfo *MI = getMacroInfo(IdentInfo);
- MacroInfo *MacroCopyToPush = 0;
if (MI) {
- // Make a clone of MI.
- MacroCopyToPush = CloneMacroInfo(*MI);
-
// Allow the original MacroInfo to be redefined later.
MI->setIsAllowRedefinitionsWithoutWarning(true);
}
// Push the cloned MacroInfo so we can retrieve it later.
- PragmaPushMacroInfo[IdentInfo].push_back(MacroCopyToPush);
+ PragmaPushMacroInfo[IdentInfo].push_back(MI);
}
/// \brief Handle \#pragma pop_macro.
PragmaPushMacroInfo.find(IdentInfo);
if (iter != PragmaPushMacroInfo.end()) {
// Forget the MacroInfo currently associated with IdentInfo.
- if (MacroInfo *CurrentMI = getMacroInfo(IdentInfo)) {
- if (CurrentMI->isWarnIfUnused())
- WarnUnusedMacroLocs.erase(CurrentMI->getDefinitionLoc());
- UndefineMacro(IdentInfo, CurrentMI, MessageLoc);
+ if (MacroDirective *CurrentMD = getMacroDirective(IdentInfo)) {
+ if (CurrentMD->getInfo()->isWarnIfUnused())
+ WarnUnusedMacroLocs.erase(CurrentMD->getInfo()->getDefinitionLoc());
+ UndefineMacro(IdentInfo, CurrentMD, MessageLoc);
}
// Get the MacroInfo we want to reinstall.
if (MacroToReInstall) {
// Reinstall the previously pushed macro.
- setMacroInfo(IdentInfo, MacroToReInstall);
+ setMacroDirective(IdentInfo, MacroToReInstall, MessageLoc,
+ /*isImported=*/false);
} else if (IdentInfo->hasMacroDefinition()) {
clearMacroInfo(IdentInfo);
}
StringRef BestSpelling;
for (Preprocessor::macro_iterator I = macro_begin(), E = macro_end();
I != E; ++I) {
- if (!I->second->isObjectLike())
+ if (!I->second->getInfo()->isObjectLike())
continue;
- const MacroInfo *MI = I->second->findDefinitionAtLoc(Loc, SourceMgr);
- if (!MI)
+ const MacroDirective *
+ MD = I->second->findDirectiveAtLoc(Loc, SourceMgr);
+ if (!MD)
continue;
- if (!MacroDefinitionEquals(MI, Tokens))
+ if (!MacroDefinitionEquals(MD->getInfo(), Tokens))
continue;
- SourceLocation Location = I->second->getDefinitionLoc();
+ SourceLocation Location = I->second->getInfo()->getDefinitionLoc();
// Choose the macro defined latest.
if (BestLocation.isInvalid() ||
(Location.isValid() &&
PrintingPolicy Policy = Context.getPrintingPolicy();
Policy.Bool = Context.getLangOpts().Bool;
if (!Policy.Bool) {
- if (MacroInfo *BoolMacro = PP.getMacroInfo(&Context.Idents.get("bool"))) {
+ if (const MacroInfo *
+ BoolMacro = PP.getMacroInfo(&Context.Idents.get("bool"))) {
Policy.Bool = BoolMacro->isObjectLike() &&
BoolMacro->getNumTokens() == 1 &&
BoolMacro->getReplacementToken(0).is(tok::kw__Bool);
}
if (Kind == RK_Macro) {
- MacroInfo *MI = PP.getMacroInfoHistory(Macro);
- assert(MI && "Not a macro?");
+ const MacroDirective *MD = PP.getMacroDirectiveHistory(Macro);
+ assert(MD && "Not a macro?");
+ const MacroInfo *MI = MD->getInfo();
Result.AddTypedTextChunk(
Result.getAllocator().CopyString(Macro->getName()));
}
void ASTReader::ReadMacroRecord(ModuleFile &F, uint64_t Offset,
- MacroInfo *Hint) {
+ MacroDirective *Hint) {
BitstreamCursor &Stream = F.MacroCursor;
// Keep track of where we are in the stream, then jump back there
// adding tokens.
struct AddLoadedMacroInfoRAII {
Preprocessor &PP;
- MacroInfo *Hint;
- MacroInfo *MI;
+ MacroDirective *Hint;
+ MacroDirective *MD;
IdentifierInfo *II;
- AddLoadedMacroInfoRAII(Preprocessor &PP, MacroInfo *Hint)
- : PP(PP), Hint(Hint), MI(), II() { }
+ AddLoadedMacroInfoRAII(Preprocessor &PP, MacroDirective *Hint)
+ : PP(PP), Hint(Hint), MD(), II() { }
~AddLoadedMacroInfoRAII( ) {
- if (MI) {
+ if (MD) {
// Finally, install the macro.
- PP.addLoadedMacroInfo(II, MI, Hint);
+ PP.addLoadedMacroInfo(II, MD, Hint);
}
}
} AddLoadedMacroInfo(PP, Hint);
unsigned NextIndex = 3;
SourceLocation Loc = ReadSourceLocation(F, Record, NextIndex);
MacroInfo *MI = PP.AllocateMacroInfo(Loc);
+ // FIXME: Location should be import location in case of module.
+ MacroDirective *MD = PP.AllocateMacroDirective(MI, Loc,
+ /*isImported=*/true);
MI->setDefinitionEndLoc(ReadSourceLocation(F, Record, NextIndex));
// Record this macro.
- MacrosLoaded[GlobalID - NUM_PREDEF_MACRO_IDS] = MI;
+ MacrosLoaded[GlobalID - NUM_PREDEF_MACRO_IDS] = MD;
SourceLocation UndefLoc = ReadSourceLocation(F, Record, NextIndex);
if (UndefLoc.isValid())
- MI->setUndefLoc(UndefLoc);
+ MD->setUndefLoc(UndefLoc);
MI->setIsUsed(Record[NextIndex++]);
- MI->setIsFromAST();
bool IsPublic = Record[NextIndex++];
- MI->setVisibility(IsPublic, ReadSourceLocation(F, Record, NextIndex));
+ MD->setVisibility(IsPublic, ReadSourceLocation(F, Record, NextIndex));
if (RecType == PP_MACRO_FUNCTION_LIKE) {
// Decode function-like macro info.
}
if (DeserializationListener)
- DeserializationListener->MacroRead(GlobalID, MI);
+ DeserializationListener->MacroRead(GlobalID, MD);
// If an update record marked this as undefined, do so now.
// FIXME: Only if the submodule this update came from is visible?
MacroUpdatesMap::iterator Update = MacroUpdates.find(GlobalID);
if (Update != MacroUpdates.end()) {
- if (MI->getUndefLoc().isInvalid()) {
+ if (MD->getUndefLoc().isInvalid()) {
for (unsigned I = 0, N = Update->second.size(); I != N; ++I) {
bool Hidden = false;
if (unsigned SubmoduleID = Update->second[I].first) {
// Record this hiding for later.
HiddenNamesMap[Owner].push_back(
- HiddenName(II, MI, Update->second[I].second.UndefLoc));
+ HiddenName(II, MD, Update->second[I].second.UndefLoc));
}
}
}
if (!Hidden) {
- MI->setUndefLoc(Update->second[I].second.UndefLoc);
+ MD->setUndefLoc(Update->second[I].second.UndefLoc);
if (PPMutationListener *Listener = PP.getPPMutationListener())
- Listener->UndefinedMacro(MI);
+ Listener->UndefinedMacro(MD);
break;
}
}
}
// Determine whether this macro definition is visible.
- bool Hidden = !MI->isPublic();
+ bool Hidden = !MD->isPublic();
if (!Hidden && GlobalSubmoduleID) {
if (Module *Owner = getSubmodule(GlobalSubmoduleID)) {
if (Owner->NameVisibility == Module::Hidden) {
// Note that this macro definition was hidden because its owning
// module is not yet visible.
- HiddenNamesMap[Owner].push_back(HiddenName(II, MI));
+ HiddenNamesMap[Owner].push_back(HiddenName(II, MD));
}
}
}
- MI->setHidden(Hidden);
+ MD->setHidden(Hidden);
// Make sure we install the macro once we're done.
- AddLoadedMacroInfo.MI = MI;
+ AddLoadedMacroInfo.MD = MD;
AddLoadedMacroInfo.II = II;
// Remember that we saw this macro last so that we add the tokens that
break;
}
case HiddenName::MacroVisibility: {
- std::pair<IdentifierInfo *, MacroInfo *> Macro = Names[I].getMacro();
+ std::pair<IdentifierInfo *, MacroDirective *> Macro = Names[I].getMacro();
Macro.second->setHidden(!Macro.second->isPublic());
if (Macro.second->isDefined()) {
PP.makeLoadedMacroInfoVisible(Macro.first, Macro.second);
}
case HiddenName::MacroUndef: {
- std::pair<IdentifierInfo *, MacroInfo *> Macro = Names[I].getMacro();
+ std::pair<IdentifierInfo *, MacroDirective *> Macro = Names[I].getMacro();
if (Macro.second->isDefined()) {
Macro.second->setUndefLoc(Names[I].getMacroUndefLoc());
if (PPMutationListener *Listener = PP.getPPMutationListener())
unsigned NumMacrosLoaded
= MacrosLoaded.size() - std::count(MacrosLoaded.begin(),
MacrosLoaded.end(),
- (MacroInfo *)0);
+ (MacroDirective *)0);
unsigned NumSelectorsLoaded
= SelectorsLoaded.size() - std::count(SelectorsLoaded.begin(),
SelectorsLoaded.end(),
return LocalID + I->second;
}
-MacroInfo *ASTReader::getMacro(MacroID ID, MacroInfo *Hint) {
+MacroDirective *ASTReader::getMacro(MacroID ID, MacroDirective *Hint) {
if (ID == 0)
return 0;
for (unsigned I = 0; I != PendingMacroIDs.size(); ++I) {
// FIXME: std::move here
SmallVector<MacroID, 2> GlobalIDs = PendingMacroIDs.begin()[I].second;
- MacroInfo *Hint = 0;
+ MacroDirective *Hint = 0;
for (unsigned IDIdx = 0, NumIDs = GlobalIDs.size(); IDIdx != NumIDs;
++IDIdx) {
Hint = getMacro(GlobalIDs[IDIdx], Hint);
// emitting each to the PP section.
// Construct the list of macro definitions that need to be serialized.
- SmallVector<std::pair<const IdentifierInfo *, MacroInfo *>, 2>
+ SmallVector<std::pair<const IdentifierInfo *, MacroDirective *>, 2>
MacrosToEmit;
llvm::SmallPtrSet<const IdentifierInfo*, 4> MacroDefinitionsSeen;
for (Preprocessor::macro_iterator I = PP.macro_begin(Chain == 0),
for (unsigned I = 0, N = MacrosToEmit.size(); I != N; ++I) {
const IdentifierInfo *Name = MacrosToEmit[I].first;
- for (MacroInfo *MI = MacrosToEmit[I].second; MI;
- MI = MI->getPreviousDefinition()) {
- MacroID ID = getMacroRef(MI);
+ for (MacroDirective *MD = MacrosToEmit[I].second; MD;
+ MD = MD->getPrevious()) {
+ MacroID ID = getMacroRef(MD);
if (!ID)
continue;
// Skip macros from a AST file if we're chaining.
- if (Chain && MI->isFromAST() && !MI->hasChangedAfterLoad())
+ if (Chain && MD->isImported() && !MD->hasChangedAfterLoad())
continue;
if (ID < FirstMacroID) {
// This will have been dealt with via an update record.
- assert(MacroUpdates.count(MI) > 0 && "Missing macro update");
+ assert(MacroUpdates.count(MD) > 0 && "Missing macro update");
continue;
}
}
AddIdentifierRef(Name, Record);
- addMacroRef(MI, Record);
+ addMacroRef(MD, Record);
+ const MacroInfo *MI = MD->getInfo();
Record.push_back(inferSubmoduleIDFromLocation(MI->getDefinitionLoc()));
AddSourceLocation(MI->getDefinitionLoc(), Record);
AddSourceLocation(MI->getDefinitionEndLoc(), Record);
- AddSourceLocation(MI->getUndefLoc(), Record);
+ AddSourceLocation(MD->getUndefLoc(), Record);
Record.push_back(MI->isUsed());
- Record.push_back(MI->isPublic());
- AddSourceLocation(MI->getVisibilityLocation(), Record);
+ Record.push_back(MD->isPublic());
+ AddSourceLocation(MD->getVisibilityLocation(), Record);
unsigned Code;
if (MI->isObjectLike()) {
Code = PP_MACRO_OBJECT_LIKE;
/// \brief Determines whether this is an "interesting" identifier
/// that needs a full IdentifierInfo structure written into the hash
/// table.
- bool isInterestingIdentifier(IdentifierInfo *II, MacroInfo *&Macro) {
+ bool isInterestingIdentifier(IdentifierInfo *II, MacroDirective *&Macro) {
if (II->isPoisoned() ||
II->isExtensionToken() ||
II->getObjCOrBuiltinID() ||
return hadMacroDefinition(II, Macro);
}
- bool hadMacroDefinition(IdentifierInfo *II, MacroInfo *&Macro) {
+ bool hadMacroDefinition(IdentifierInfo *II, MacroDirective *&Macro) {
if (!II->hadMacroDefinition())
return false;
- if (Macro || (Macro = PP.getMacroInfoHistory(II)))
- return !Macro->isBuiltinMacro() && (!IsModule || Macro->isPublic());
+ if (Macro || (Macro = PP.getMacroDirectiveHistory(II)))
+ return !Macro->getInfo()->isBuiltinMacro() &&
+ (!IsModule || Macro->isPublic());
return false;
}
EmitKeyDataLength(raw_ostream& Out, IdentifierInfo* II, IdentID ID) {
unsigned KeyLen = II->getLength() + 1;
unsigned DataLen = 4; // 4 bytes for the persistent ID << 1
- MacroInfo *Macro = 0;
+ MacroDirective *Macro = 0;
if (isInterestingIdentifier(II, Macro)) {
DataLen += 2; // 2 bytes for builtin ID
DataLen += 2; // 2 bytes for flags
if (hadMacroDefinition(II, Macro)) {
- for (MacroInfo *M = Macro; M; M = M->getPreviousDefinition()) {
+ for (MacroDirective *M = Macro; M; M = M->getPrevious()) {
if (Writer.getMacroRef(M) != 0)
DataLen += 4;
}
void EmitData(raw_ostream& Out, IdentifierInfo* II,
IdentID ID, unsigned) {
- MacroInfo *Macro = 0;
+ MacroDirective *Macro = 0;
if (!isInterestingIdentifier(II, Macro)) {
clang::io::Emit32(Out, ID << 1);
return;
if (HadMacroDefinition) {
// Write all of the macro IDs associated with this identifier.
- for (MacroInfo *M = Macro; M; M = M->getPreviousDefinition()) {
+ for (MacroDirective *M = Macro; M; M = M->getPrevious()) {
if (MacroID ID = Writer.getMacroRef(M))
clang::io::Emit32(Out, ID);
}
Record.push_back(getIdentifierRef(II));
}
-void ASTWriter::addMacroRef(MacroInfo *MI, RecordDataImpl &Record) {
- Record.push_back(getMacroRef(MI));
+void ASTWriter::addMacroRef(MacroDirective *MD, RecordDataImpl &Record) {
+ Record.push_back(getMacroRef(MD));
}
IdentID ASTWriter::getIdentifierRef(const IdentifierInfo *II) {
return ID;
}
-MacroID ASTWriter::getMacroRef(MacroInfo *MI) {
+MacroID ASTWriter::getMacroRef(MacroDirective *MD) {
// Don't emit builtin macros like __LINE__ to the AST file unless they
// have been redefined by the header (in which case they are not
// isBuiltinMacro).
- if (MI == 0 || MI->isBuiltinMacro())
+ if (MD == 0 || MD->getInfo()->isBuiltinMacro())
return 0;
- MacroID &ID = MacroIDs[MI];
+ MacroID &ID = MacroIDs[MD];
if (ID == 0)
ID = NextMacroID++;
return ID;
StoredID = ID;
}
-void ASTWriter::MacroRead(serialization::MacroID ID, MacroInfo *MI) {
+void ASTWriter::MacroRead(serialization::MacroID ID, MacroDirective *MD) {
// Always keep the highest ID. See \p TypeRead() for more information.
- MacroID &StoredID = MacroIDs[MI];
+ MacroID &StoredID = MacroIDs[MD];
if (ID > StoredID)
StoredID = ID;
}
SubmoduleIDs[Mod] = ID;
}
-void ASTWriter::UndefinedMacro(MacroInfo *MI) {
- MacroUpdates[MI].UndefLoc = MI->getUndefLoc();
+void ASTWriter::UndefinedMacro(MacroDirective *MD) {
+ MacroUpdates[MD].UndefLoc = MD->getUndefLoc();
}
void ASTWriter::CompletedTagDefinition(const TagDecl *D) {
ASTUnit *Unit = cxtu::getASTUnit(TU);
Preprocessor &PP = Unit->getPreprocessor();
- MacroInfo *MI = PP.getMacroInfoHistory(&II);
- while (MI) {
- if (MacroDefLoc == MI->getDefinitionLoc())
- return MI;
- MI = MI->getPreviousDefinition();
+ MacroDirective *MD = PP.getMacroDirectiveHistory(&II);
+ while (MD) {
+ if (MacroDefLoc == MD->getInfo()->getDefinitionLoc())
+ return MD->getInfo();
+ MD = MD->getPrevious();
}
return 0;
if (std::find(MI->arg_begin(), MI->arg_end(), &II) != MI->arg_end())
return 0;
- MacroInfo *InnerMI = PP.getMacroInfoHistory(&II);
- if (!InnerMI)
+ MacroDirective *InnerMD = PP.getMacroDirectiveHistory(&II);
+ if (!InnerMD)
return 0;
- return PPRec->findMacroDefinition(InnerMI);
+ return PPRec->findMacroDefinition(InnerMD->getInfo());
}
MacroDefinition *cxindex::checkForMacroInMacroDefinition(const MacroInfo *MI,