#ifndef LLVM_CLANG_AST_ASTMUTATIONLISTENER_H
#define LLVM_CLANG_AST_ASTMUTATIONLISTENER_H
-#include "clang/Basic/SourceLocation.h"
-
namespace clang {
class ClassTemplateDecl;
class ClassTemplateSpecializationDecl;
class DeclContext;
class FunctionDecl;
class FunctionTemplateDecl;
+ class Module;
class NamedDecl;
class ObjCCategoryDecl;
class ObjCContainerDecl;
/// \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.
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
/// directly or indirectly.
Module *getModuleContainingLocation(SourceLocation Loc);
+private:
// Macro handling.
void HandleDefineDirective(Token &Tok, bool ImmediatelyAfterTopLevelIfndef);
void HandleUndefDirective(Token &Tok);
void *Type;
unsigned Loc;
unsigned Val;
+ Module *Mod;
};
public:
: 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; }
return SourceLocation::getFromRawEncoding(Loc);
}
unsigned getNumber() const { return Val; }
+ Module *getModule() const { return Mod; }
};
typedef SmallVector<DeclUpdate, 1> UpdateRecord;
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
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;
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
#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"
void Sema::makeMergedDefinitionVisible(NamedDecl *ND, SourceLocation Loc) {
if (auto *Listener = getASTMutationListener())
- Listener->RedefinedHiddenDefinition(ND, Loc);
+ Listener->RedefinedHiddenDefinition(ND,
+ PP.getModuleContainingLocation(Loc));
ND->setHidden(false);
}
break;
case UPD_DECL_EXPORTED:
- Record.push_back(inferSubmoduleIDFromLocation(Update.getLoc()));
+ Record.push_back(getSubmoduleID(Update.getModule()));
break;
}
}
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));
}