r237416 - Refactor: when exposing a definition in some module, provide listeners with the
Richard Smith
richard-llvm at metafoo.co.uk
Thu May 14 19:34:32 PDT 2015
Author: rsmith
Date: Thu May 14 21:34:32 2015
New Revision: 237416
URL: http://llvm.org/viewvc/llvm-project?rev=237416&view=rev
Log:
Refactor: when exposing a definition in some module, provide listeners with the
module rather than requiring them to work it out themselves.
Modified:
cfe/trunk/include/clang/AST/ASTMutationListener.h
cfe/trunk/include/clang/Lex/Preprocessor.h
cfe/trunk/include/clang/Serialization/ASTWriter.h
cfe/trunk/lib/Frontend/MultiplexConsumer.cpp
cfe/trunk/lib/Sema/SemaLookup.cpp
cfe/trunk/lib/Serialization/ASTWriter.cpp
Modified: cfe/trunk/include/clang/AST/ASTMutationListener.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/ASTMutationListener.h?rev=237416&r1=237415&r2=237416&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/ASTMutationListener.h (original)
+++ cfe/trunk/include/clang/AST/ASTMutationListener.h Thu May 14 21:34:32 2015
@@ -13,8 +13,6 @@
#ifndef LLVM_CLANG_AST_ASTMUTATIONLISTENER_H
#define LLVM_CLANG_AST_ASTMUTATIONLISTENER_H
-#include "clang/Basic/SourceLocation.h"
-
namespace clang {
class ClassTemplateDecl;
class ClassTemplateSpecializationDecl;
@@ -24,6 +22,7 @@ namespace clang {
class DeclContext;
class FunctionDecl;
class FunctionTemplateDecl;
+ class Module;
class NamedDecl;
class ObjCCategoryDecl;
class ObjCContainerDecl;
@@ -117,8 +116,9 @@ public:
/// \brief A definition has been made visible by being redefined locally.
///
/// \param D The definition that was previously not visible.
- virtual void RedefinedHiddenDefinition(const NamedDecl *D,
- SourceLocation Loc) {}
+ /// \param M The containing module in which the definition was made visible,
+ /// if any.
+ virtual void RedefinedHiddenDefinition(const NamedDecl *D, Module *M) {}
// NOTE: If new methods are added they should also be added to
// MultiplexASTMutationListener.
Modified: cfe/trunk/include/clang/Lex/Preprocessor.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Lex/Preprocessor.h?rev=237416&r1=237415&r2=237416&view=diff
==============================================================================
--- cfe/trunk/include/clang/Lex/Preprocessor.h (original)
+++ cfe/trunk/include/clang/Lex/Preprocessor.h Thu May 14 21:34:32 2015
@@ -1790,6 +1790,7 @@ private:
void HandleImportDirective(SourceLocation HashLoc, Token &Tok);
void HandleMicrosoftImportDirective(Token &Tok);
+public:
// Module inclusion testing.
/// \brief Find the module that owns the source or header file that
/// \p Loc points to. If the location is in a file that was included
@@ -1800,6 +1801,7 @@ private:
/// directly or indirectly.
Module *getModuleContainingLocation(SourceLocation Loc);
+private:
// Macro handling.
void HandleDefineDirective(Token &Tok, bool ImmediatelyAfterTopLevelIfndef);
void HandleUndefDirective(Token &Tok);
Modified: cfe/trunk/include/clang/Serialization/ASTWriter.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Serialization/ASTWriter.h?rev=237416&r1=237415&r2=237416&view=diff
==============================================================================
--- cfe/trunk/include/clang/Serialization/ASTWriter.h (original)
+++ cfe/trunk/include/clang/Serialization/ASTWriter.h Thu May 14 21:34:32 2015
@@ -300,6 +300,7 @@ private:
void *Type;
unsigned Loc;
unsigned Val;
+ Module *Mod;
};
public:
@@ -311,6 +312,8 @@ private:
: Kind(Kind), Loc(Loc.getRawEncoding()) {}
DeclUpdate(unsigned Kind, unsigned Val)
: Kind(Kind), Val(Val) {}
+ DeclUpdate(unsigned Kind, Module *M)
+ : Kind(Kind), Mod(M) {}
unsigned getKind() const { return Kind; }
const Decl *getDecl() const { return Dcl; }
@@ -319,6 +322,7 @@ private:
return SourceLocation::getFromRawEncoding(Loc);
}
unsigned getNumber() const { return Val; }
+ Module *getModule() const { return Mod; }
};
typedef SmallVector<DeclUpdate, 1> UpdateRecord;
@@ -854,8 +858,7 @@ public:
const ObjCCategoryDecl *ClassExt) override;
void DeclarationMarkedUsed(const Decl *D) override;
void DeclarationMarkedOpenMPThreadPrivate(const Decl *D) override;
- void RedefinedHiddenDefinition(const NamedDecl *D,
- SourceLocation Loc) override;
+ void RedefinedHiddenDefinition(const NamedDecl *D, Module *M) override;
};
/// \brief AST and semantic-analysis consumer that generates a
Modified: cfe/trunk/lib/Frontend/MultiplexConsumer.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/MultiplexConsumer.cpp?rev=237416&r1=237415&r2=237416&view=diff
==============================================================================
--- cfe/trunk/lib/Frontend/MultiplexConsumer.cpp (original)
+++ cfe/trunk/lib/Frontend/MultiplexConsumer.cpp Thu May 14 21:34:32 2015
@@ -111,8 +111,7 @@ public:
const ObjCCategoryDecl *ClassExt) override;
void DeclarationMarkedUsed(const Decl *D) override;
void DeclarationMarkedOpenMPThreadPrivate(const Decl *D) override;
- void RedefinedHiddenDefinition(const NamedDecl *D,
- SourceLocation Loc) override;
+ void RedefinedHiddenDefinition(const NamedDecl *D, Module *M) override;
private:
std::vector<ASTMutationListener*> Listeners;
@@ -196,10 +195,10 @@ void MultiplexASTMutationListener::Decla
for (size_t i = 0, e = Listeners.size(); i != e; ++i)
Listeners[i]->DeclarationMarkedOpenMPThreadPrivate(D);
}
-void MultiplexASTMutationListener::RedefinedHiddenDefinition(
- const NamedDecl *D, SourceLocation Loc) {
+void MultiplexASTMutationListener::RedefinedHiddenDefinition(const NamedDecl *D,
+ Module *M) {
for (auto *L : Listeners)
- L->RedefinedHiddenDefinition(D, Loc);
+ L->RedefinedHiddenDefinition(D, M);
}
} // end namespace clang
Modified: cfe/trunk/lib/Sema/SemaLookup.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaLookup.cpp?rev=237416&r1=237415&r2=237416&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaLookup.cpp (original)
+++ cfe/trunk/lib/Sema/SemaLookup.cpp Thu May 14 21:34:32 2015
@@ -25,6 +25,7 @@
#include "clang/Basic/Builtins.h"
#include "clang/Basic/LangOptions.h"
#include "clang/Lex/ModuleLoader.h"
+#include "clang/Lex/Preprocessor.h"
#include "clang/Sema/DeclSpec.h"
#include "clang/Sema/ExternalSemaSource.h"
#include "clang/Sema/Overload.h"
@@ -1172,7 +1173,8 @@ static Decl *getInstantiatedFrom(Decl *D
void Sema::makeMergedDefinitionVisible(NamedDecl *ND, SourceLocation Loc) {
if (auto *Listener = getASTMutationListener())
- Listener->RedefinedHiddenDefinition(ND, Loc);
+ Listener->RedefinedHiddenDefinition(ND,
+ PP.getModuleContainingLocation(Loc));
ND->setHidden(false);
}
Modified: cfe/trunk/lib/Serialization/ASTWriter.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Serialization/ASTWriter.cpp?rev=237416&r1=237415&r2=237416&view=diff
==============================================================================
--- cfe/trunk/lib/Serialization/ASTWriter.cpp (original)
+++ cfe/trunk/lib/Serialization/ASTWriter.cpp Thu May 14 21:34:32 2015
@@ -4598,7 +4598,7 @@ void ASTWriter::WriteDeclUpdatesBlocks(R
break;
case UPD_DECL_EXPORTED:
- Record.push_back(inferSubmoduleIDFromLocation(Update.getLoc()));
+ Record.push_back(getSubmoduleID(Update.getModule()));
break;
}
}
@@ -5743,10 +5743,9 @@ void ASTWriter::DeclarationMarkedOpenMPT
DeclUpdates[D].push_back(DeclUpdate(UPD_DECL_MARKED_OPENMP_THREADPRIVATE));
}
-void ASTWriter::RedefinedHiddenDefinition(const NamedDecl *D,
- SourceLocation Loc) {
+void ASTWriter::RedefinedHiddenDefinition(const NamedDecl *D, Module *M) {
assert(!WritingAST && "Already writing the AST!");
assert(D->isHidden() && "expected a hidden declaration");
assert(D->isFromASTFile() && "hidden decl not from AST file");
- DeclUpdates[D].push_back(DeclUpdate(UPD_DECL_EXPORTED, Loc));
+ DeclUpdates[D].push_back(DeclUpdate(UPD_DECL_EXPORTED, M));
}
More information about the cfe-commits
mailing list