r236197 - Remove dead code: a MacroDirective can't be imported or ambiguous any more.
Richard Smith
richard-llvm at metafoo.co.uk
Wed Apr 29 19:16:23 PDT 2015
Author: rsmith
Date: Wed Apr 29 21:16:23 2015
New Revision: 236197
URL: http://llvm.org/viewvc/llvm-project?rev=236197&view=rev
Log:
Remove dead code: a MacroDirective can't be imported or ambiguous any more.
Modified:
cfe/trunk/include/clang/Lex/MacroInfo.h
cfe/trunk/include/clang/Lex/Preprocessor.h
cfe/trunk/lib/Lex/MacroInfo.cpp
cfe/trunk/lib/Lex/PPDirectives.cpp
cfe/trunk/lib/Lex/PPMacroExpansion.cpp
cfe/trunk/lib/Serialization/ASTReader.cpp
cfe/trunk/lib/Serialization/ASTWriter.cpp
Modified: cfe/trunk/include/clang/Lex/MacroInfo.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Lex/MacroInfo.h?rev=236197&r1=236196&r2=236197&view=diff
==============================================================================
--- cfe/trunk/include/clang/Lex/MacroInfo.h (original)
+++ cfe/trunk/include/clang/Lex/MacroInfo.h Wed Apr 29 21:16:23 2015
@@ -305,15 +305,8 @@ class DefMacroDirective;
///
/// MacroDirectives, associated with an identifier, are used to model the macro
/// history. Usually a macro definition (MacroInfo) is where a macro name
-/// becomes active (MacroDirective) but modules can have their own macro
-/// history, separate from the local (current translation unit) macro history.
-///
-/// For example, if "@import A;" imports macro FOO, there will be a new local
-/// MacroDirective created to indicate that "FOO" became active at the import
-/// location. Module "A" itself will contain another MacroDirective in its macro
-/// history (at the point of the definition of FOO) and both MacroDirectives
-/// will point to the same MacroInfo object.
-///
+/// becomes active (MacroDirective) but #pragma push_macro / pop_macro can
+/// create additional DefMacroDirectives for the same MacroInfo.
class MacroDirective {
public:
enum Kind {
@@ -334,38 +327,15 @@ protected:
/// \brief True if the macro directive was loaded from a PCH file.
bool IsFromPCH : 1;
- // Used by DefMacroDirective -----------------------------------------------//
-
- /// \brief Whether the definition of this macro is ambiguous, due to
- /// multiple definitions coming in from multiple modules.
- bool IsAmbiguous : 1;
-
// Used by VisibilityMacroDirective ----------------------------------------//
/// \brief Whether the macro has public visibility (when described in a
/// module).
bool IsPublic : 1;
- // Used by DefMacroDirective and UndefMacroDirective -----------------------//
-
- /// \brief True if this macro was imported from a module.
- bool IsImported : 1;
-
- struct ImportData {
- ModuleMacro *ImportedFrom;
- };
- ImportData *getImportData();
- const ImportData *getImportData() const {
- return const_cast<MacroDirective*>(this)->getImportData();
- }
-
- MacroDirective(Kind K, SourceLocation Loc,
- ModuleMacro *ImportedFrom = nullptr)
+ MacroDirective(Kind K, SourceLocation Loc)
: Previous(nullptr), Loc(Loc), MDKind(K), IsFromPCH(false),
- IsAmbiguous(false), IsPublic(true), IsImported(ImportedFrom) {
- if (IsImported)
- getImportData()->ImportedFrom = ImportedFrom;
- }
+ IsPublic(true) {}
public:
Kind getKind() const { return Kind(MDKind); }
@@ -388,18 +358,6 @@ public:
void setIsFromPCH() { IsFromPCH = true; }
- /// \brief True if this macro was imported from a module.
- /// Note that this is never the case for a VisibilityMacroDirective.
- bool isImported() const { return IsImported; }
-
- /// \brief If this directive was imported from a module, get the module
- /// macro from which this directive was created.
- ModuleMacro *getOwningModuleMacro() const {
- if (isImported())
- return getImportData()->ImportedFrom;
- return 0;
- }
-
class DefInfo {
DefMacroDirective *DefDirective;
SourceLocation UndefLoc;
@@ -471,32 +429,18 @@ public:
class DefMacroDirective : public MacroDirective {
MacroInfo *Info;
- DefMacroDirective(MacroInfo *MI, SourceLocation Loc,
- ModuleMacro *ImportedFrom)
- : MacroDirective(MD_Define, Loc, ImportedFrom), Info(MI) {
- assert(MI && "MacroInfo is null");
- }
-
public:
DefMacroDirective(MacroInfo *MI, SourceLocation Loc)
- : DefMacroDirective(MI, Loc, nullptr) {}
+ : MacroDirective(MD_Define, Loc), Info(MI) {
+ assert(MI && "MacroInfo is null");
+ }
explicit DefMacroDirective(MacroInfo *MI)
: DefMacroDirective(MI, MI->getDefinitionLoc()) {}
- static DefMacroDirective *createImported(Preprocessor &PP, MacroInfo *MI,
- SourceLocation Loc,
- ModuleMacro *ImportedFrom);
/// \brief The data for the macro definition.
const MacroInfo *getInfo() const { return Info; }
MacroInfo *getInfo() { return Info; }
- /// \brief Determine whether this macro definition is ambiguous with
- /// other macro definitions.
- bool isAmbiguous() const { return IsAmbiguous; }
-
- /// \brief Set whether this macro definition is ambiguous.
- void setAmbiguous(bool Val) { IsAmbiguous = Val; }
-
static bool classof(const MacroDirective *MD) {
return MD->getKind() == MD_Define;
}
@@ -505,17 +449,11 @@ public:
/// \brief A directive for an undefined macro.
class UndefMacroDirective : public MacroDirective {
- UndefMacroDirective(SourceLocation UndefLoc, ModuleMacro *ImportedFrom)
- : MacroDirective(MD_Undefine, UndefLoc, ImportedFrom) {
- assert(UndefLoc.isValid() && "Invalid UndefLoc!");
- }
-
public:
explicit UndefMacroDirective(SourceLocation UndefLoc)
- : UndefMacroDirective(UndefLoc, nullptr) {}
- static UndefMacroDirective *createImported(Preprocessor &PP,
- SourceLocation UndefLoc,
- ModuleMacro *ImportedFrom);
+ : MacroDirective(MD_Undefine, UndefLoc) {
+ assert(UndefLoc.isValid() && "Invalid UndefLoc!");
+ }
static bool classof(const MacroDirective *MD) {
return MD->getKind() == MD_Undefine;
@@ -541,14 +479,6 @@ public:
static bool classof(const VisibilityMacroDirective *) { return true; }
};
-inline MacroDirective::ImportData *MacroDirective::getImportData() {
- assert(IsImported && "only an imported macro has import data");
- if (auto *Def = dyn_cast<DefMacroDirective>(this))
- return reinterpret_cast<ImportData*>(Def + 1);
- else
- return reinterpret_cast<ImportData*>(cast<UndefMacroDirective>(this) + 1);
-}
-
inline SourceLocation MacroDirective::DefInfo::getLocation() const {
if (isInvalid())
return SourceLocation();
Modified: cfe/trunk/include/clang/Lex/Preprocessor.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Lex/Preprocessor.h?rev=236197&r1=236196&r2=236197&view=diff
==============================================================================
--- cfe/trunk/include/clang/Lex/Preprocessor.h (original)
+++ cfe/trunk/include/clang/Lex/Preprocessor.h Wed Apr 29 21:16:23 2015
@@ -1678,9 +1678,6 @@ private:
VisibilityMacroDirective *AllocateVisibilityMacroDirective(SourceLocation Loc,
bool isPublic);
- MacroDirective *AllocateImportedMacroDirective(ModuleMacro *MM,
- SourceLocation Loc);
-
/// \brief Lex and validate a macro name, which occurs after a
/// \#define or \#undef.
///
Modified: cfe/trunk/lib/Lex/MacroInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/MacroInfo.cpp?rev=236197&r1=236196&r2=236197&view=diff
==============================================================================
--- cfe/trunk/lib/Lex/MacroInfo.cpp (original)
+++ cfe/trunk/lib/Lex/MacroInfo.cpp Wed Apr 29 21:16:23 2015
@@ -218,8 +218,6 @@ void MacroDirective::dump() const {
if (auto *Prev = getPrevious())
Out << " prev " << Prev;
if (IsFromPCH) Out << " from_pch";
- if (IsImported) Out << " imported";
- if (IsAmbiguous) Out << " ambiguous";
if (IsPublic)
Out << " public";
@@ -235,25 +233,6 @@ void MacroDirective::dump() const {
Out << "\n";
}
-DefMacroDirective *
-DefMacroDirective::createImported(Preprocessor &PP, MacroInfo *MI,
- SourceLocation Loc,
- ModuleMacro *ImportedFrom) {
- void *Mem = PP.getPreprocessorAllocator().Allocate(
- sizeof(DefMacroDirective) + sizeof(MacroDirective::ImportData),
- llvm::alignOf<DefMacroDirective>());
- return new (Mem) DefMacroDirective(MI, Loc, ImportedFrom);
-}
-
-UndefMacroDirective *
-UndefMacroDirective::createImported(Preprocessor &PP, SourceLocation Loc,
- ModuleMacro *ImportedFrom) {
- void *Mem = PP.getPreprocessorAllocator().Allocate(
- sizeof(UndefMacroDirective) + sizeof(MacroDirective::ImportData),
- llvm::alignOf<UndefMacroDirective>());
- return new (Mem) UndefMacroDirective(Loc, ImportedFrom);
-}
-
ModuleMacro *ModuleMacro::create(Preprocessor &PP, Module *OwningModule,
IdentifierInfo *II, MacroInfo *Macro,
ArrayRef<ModuleMacro *> Overrides) {
Modified: cfe/trunk/lib/Lex/PPDirectives.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/PPDirectives.cpp?rev=236197&r1=236196&r2=236197&view=diff
==============================================================================
--- cfe/trunk/lib/Lex/PPDirectives.cpp (original)
+++ cfe/trunk/lib/Lex/PPDirectives.cpp Wed Apr 29 21:16:23 2015
@@ -78,15 +78,6 @@ Preprocessor::AllocateVisibilityMacroDir
return new (BP) VisibilityMacroDirective(Loc, isPublic);
}
-MacroDirective *
-Preprocessor::AllocateImportedMacroDirective(ModuleMacro *MM,
- SourceLocation Loc) {
- if (auto *MI = MM->getMacroInfo())
- return DefMacroDirective::createImported(*this, MI, Loc, MM);
- else
- return UndefMacroDirective::createImported(*this, Loc, MM);
-}
-
/// \brief Read and discard all tokens remaining on the current line until
/// the tok::eod token is found.
void Preprocessor::DiscardUntilEndOfDirective() {
Modified: cfe/trunk/lib/Lex/PPMacroExpansion.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/PPMacroExpansion.cpp?rev=236197&r1=236196&r2=236197&view=diff
==============================================================================
--- cfe/trunk/lib/Lex/PPMacroExpansion.cpp (original)
+++ cfe/trunk/lib/Lex/PPMacroExpansion.cpp Wed Apr 29 21:16:23 2015
@@ -55,7 +55,7 @@ void Preprocessor::appendMacroDirective(
II->setHasMacroDefinition(true);
if (!MD->isDefined() && LeafModuleMacros.find(II) == LeafModuleMacros.end())
II->setHasMacroDefinition(false);
- if (II->isFromAST() && !MD->isImported())
+ if (II->isFromAST())
II->setChangedSinceDeserialization();
}
Modified: cfe/trunk/lib/Serialization/ASTReader.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Serialization/ASTReader.cpp?rev=236197&r1=236196&r2=236197&view=diff
==============================================================================
--- cfe/trunk/lib/Serialization/ASTReader.cpp (original)
+++ cfe/trunk/lib/Serialization/ASTReader.cpp Wed Apr 29 21:16:23 2015
@@ -1809,21 +1809,11 @@ void ASTReader::resolvePendingMacro(Iden
switch (K) {
case MacroDirective::MD_Define: {
MacroInfo *MI = getMacro(getGlobalMacroID(M, Record[Idx++]));
- bool IsAmbiguous = Record[Idx++];
- ModuleMacro *MM = nullptr;
- if (SubmoduleID ImportedFrom = getGlobalSubmoduleID(M, Record[Idx++]))
- MM = PP.getModuleMacro(getSubmodule(ImportedFrom), II);
- MD = MM ? PP.AllocateImportedMacroDirective(MM, Loc)
- : PP.AllocateDefMacroDirective(MI, Loc);
- cast<DefMacroDirective>(MD)->setAmbiguous(IsAmbiguous);
+ MD = PP.AllocateDefMacroDirective(MI, Loc);
break;
}
case MacroDirective::MD_Undefine: {
- ModuleMacro *MM = nullptr;
- if (SubmoduleID ImportedFrom = getGlobalSubmoduleID(M, Record[Idx++]))
- MM = PP.getModuleMacro(getSubmodule(ImportedFrom), II);
- MD = MM ? PP.AllocateImportedMacroDirective(MM, Loc)
- : PP.AllocateUndefMacroDirective(Loc);
+ MD = PP.AllocateUndefMacroDirective(Loc);
break;
}
case MacroDirective::MD_Visibility:
Modified: cfe/trunk/lib/Serialization/ASTWriter.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Serialization/ASTWriter.cpp?rev=236197&r1=236196&r2=236197&view=diff
==============================================================================
--- cfe/trunk/lib/Serialization/ASTWriter.cpp (original)
+++ cfe/trunk/lib/Serialization/ASTWriter.cpp Wed Apr 29 21:16:23 2015
@@ -1979,10 +1979,6 @@ static bool shouldIgnoreMacro(MacroDirec
return true;
if (IsModule) {
- // Re-export any imported directives.
- if (MD->isImported())
- return false;
-
SourceLocation Loc = MD->getLocation();
if (Loc.isInvalid())
return true;
@@ -2066,19 +2062,10 @@ void ASTWriter::WritePreprocessor(const
AddSourceLocation(MD->getLocation(), Record);
Record.push_back(MD->getKind());
if (auto *DefMD = dyn_cast<DefMacroDirective>(MD)) {
- MacroID InfoID = getMacroRef(DefMD->getInfo(), Name);
- Record.push_back(InfoID);
- Record.push_back(DefMD->isAmbiguous());
+ Record.push_back(getMacroRef(DefMD->getInfo(), Name));
} else if (auto *VisMD = dyn_cast<VisibilityMacroDirective>(MD)) {
Record.push_back(VisMD->isPublic());
- // No owning module macro.
- continue;
}
-
- if (auto *MM = MD->getOwningModuleMacro())
- Record.push_back(getSubmoduleID(MM->getOwningModule()));
- else
- Record.push_back(0);
}
// Write out any exported module macros.
More information about the cfe-commits
mailing list