[clang] [clang-tools-extra] feat: highlight for import, export keyword of CXX Module (PR #204511)
via cfe-commits
cfe-commits at lists.llvm.org
Wed Jun 17 22:47:30 PDT 2026
https://github.com/Decodetalkers created https://github.com/llvm/llvm-project/pull/204511
This pr aims to add highlight for import and export keyword And induced new SemanticHighlight `keyword`
>From 163d801fed64130c95a8b1f12149c2020fa17c82 Mon Sep 17 00:00:00 2001
From: ShootingStarDragons <ShootingStarDragons at protonmail.com>
Date: Thu, 18 Jun 2026 14:46:31 +0900
Subject: [PATCH] feat: highlight for import, export keyword
This pr aims to add highlight for import and export keyword
And induced new SemanticHighlight `keyword`
---
clang-tools-extra/clangd/FindTarget.cpp | 13 ++-
.../clangd/SemanticHighlighting.cpp | 7 +-
.../clangd/SemanticHighlighting.h | 1 +
clang/include/clang/AST/Decl.h | 58 +++++++++++---
clang/include/clang/Parse/Parser.h | 3 +-
clang/include/clang/Sema/Sema.h | 27 ++++---
clang/lib/AST/Decl.cpp | 70 ++++++++--------
clang/lib/Parse/ParseDeclCXX.cpp | 11 ++-
clang/lib/Parse/Parser.cpp | 79 ++++++++++---------
clang/lib/Sema/SemaLookup.cpp | 19 ++---
clang/lib/Sema/SemaModule.cpp | 74 +++++++++--------
11 files changed, 222 insertions(+), 140 deletions(-)
diff --git a/clang-tools-extra/clangd/FindTarget.cpp b/clang-tools-extra/clangd/FindTarget.cpp
index 41c9cddfebbbc..4ac77a884c70b 100644
--- a/clang-tools-extra/clangd/FindTarget.cpp
+++ b/clang-tools-extra/clangd/FindTarget.cpp
@@ -619,7 +619,18 @@ llvm::SmallVector<ReferenceLoc> refInDecl(const Decl *D,
/*IsDecl=*/false,
{D->getNominatedNamespaceAsWritten()}});
}
-
+ void VisitImportDecl(const ImportDecl *D) {
+ Refs.push_back(ReferenceLoc{D->getQualifierLoc(),
+ D->getIdentLocation(),
+ /*IsDecl=*/true,
+ {D}});
+ }
+ void VisitExportDecl(const ExportDecl *D) {
+ Refs.push_back(ReferenceLoc{D->getQualifierLoc(),
+ D->getIdentLocation(),
+ /*IsDecl=*/true,
+ {D}});
+ }
void VisitUsingDecl(const UsingDecl *D) {
// "using ns::identifier;" is a non-declaration reference.
Refs.push_back(ReferenceLoc{
diff --git a/clang-tools-extra/clangd/SemanticHighlighting.cpp b/clang-tools-extra/clangd/SemanticHighlighting.cpp
index 856904bc810d1..5c331df5197bb 100644
--- a/clang-tools-extra/clangd/SemanticHighlighting.cpp
+++ b/clang-tools-extra/clangd/SemanticHighlighting.cpp
@@ -122,6 +122,8 @@ std::optional<HighlightingKind> kindForDecl(const NamedDecl *D,
: HighlightingKind::Method;
if (isa<FieldDecl, IndirectFieldDecl, ObjCPropertyDecl>(D))
return HighlightingKind::Field;
+ if (isa<ImportDecl, ExportDecl>(D))
+ return HighlightingKind::Keyword;
if (isa<EnumDecl>(D))
return HighlightingKind::Enum;
if (isa<EnumConstantDecl>(D))
@@ -176,7 +178,7 @@ std::optional<HighlightingKind> kindForType(const Type *TP,
}
bool isDependent(const Decl *D) {
- if (isa<UnresolvedUsingValueDecl>(D))
+ if (isa<UnresolvedUsingValueDecl, ImportDecl>(D))
return true;
return false;
}
@@ -1244,6 +1246,7 @@ bool operator<(const HighlightingToken &L, const HighlightingToken &R) {
std::tie(R.R, R.Kind, R.Modifiers);
}
+// FIXME: import module
std::vector<SemanticToken>
toSemanticTokens(llvm::ArrayRef<HighlightingToken> Tokens,
llvm::StringRef Code) {
@@ -1323,6 +1326,8 @@ llvm::StringRef toSemanticTokenType(HighlightingKind Kind) {
return "function";
case HighlightingKind::Method:
return "method";
+ case HighlightingKind::Keyword:
+ return "keyword";
case HighlightingKind::StaticMethod:
// FIXME: better method with static modifier?
return "function";
diff --git a/clang-tools-extra/clangd/SemanticHighlighting.h b/clang-tools-extra/clangd/SemanticHighlighting.h
index 59d742b83ee52..3b1c12418becb 100644
--- a/clang-tools-extra/clangd/SemanticHighlighting.h
+++ b/clang-tools-extra/clangd/SemanticHighlighting.h
@@ -34,6 +34,7 @@ enum class HighlightingKind {
Parameter,
Function,
Method,
+ Keyword,
StaticMethod,
Field,
StaticField,
diff --git a/clang/include/clang/AST/Decl.h b/clang/include/clang/AST/Decl.h
index e3f513732e588..46635bc1b86a1 100644
--- a/clang/include/clang/AST/Decl.h
+++ b/clang/include/clang/AST/Decl.h
@@ -5055,7 +5055,7 @@ class CapturedDecl final
///
/// Import declarations can also be implicitly generated from
/// \#include/\#import directives.
-class ImportDecl final : public Decl,
+class ImportDecl final : public NamedDecl,
llvm::TrailingObjects<ImportDecl, SourceLocation> {
friend class ASTContext;
friend class ASTDeclReader;
@@ -5065,6 +5065,7 @@ class ImportDecl final : public Decl,
/// The imported module.
Module *ImportedModule = nullptr;
+ NestedNameSpecifierLoc QualifierLoc;
/// The next import in the list of imports local to the translation
/// unit being parsed (not loaded from an AST file).
///
@@ -5076,12 +5077,15 @@ class ImportDecl final : public Decl,
llvm::PointerIntPair<ImportDecl *, 1, bool> NextLocalImportAndComplete;
ImportDecl(DeclContext *DC, SourceLocation StartLoc, Module *Imported,
+ NestedNameSpecifierLoc QualifierLoc, IdentifierInfo *Id,
ArrayRef<SourceLocation> IdentifierLocs);
ImportDecl(DeclContext *DC, SourceLocation StartLoc, Module *Imported,
+ NestedNameSpecifierLoc QualifierLoc, DeclarationName Id,
SourceLocation EndLoc);
- ImportDecl(EmptyShell Empty) : Decl(Import, Empty) {}
+ ImportDecl(EmptyShell Empty)
+ : NamedDecl(Import, nullptr, SourceLocation(), DeclarationName()) {}
bool isImportComplete() const { return NextLocalImportAndComplete.getInt(); }
@@ -5100,14 +5104,17 @@ class ImportDecl final : public Decl,
public:
/// Create a new module import declaration.
static ImportDecl *Create(ASTContext &C, DeclContext *DC,
+ NestedNameSpecifierLoc QualifierLoc,
SourceLocation StartLoc, Module *Imported,
+ IdentifierInfo *Id,
ArrayRef<SourceLocation> IdentifierLocs);
/// Create a new module import declaration for an implicitly-generated
/// import.
static ImportDecl *CreateImplicit(ASTContext &C, DeclContext *DC,
SourceLocation StartLoc, Module *Imported,
- SourceLocation EndLoc);
+ NestedNameSpecifierLoc QualifierLoc,
+ DeclarationName Id, SourceLocation EndLoc);
/// Create a new, deserialized module import declaration.
static ImportDecl *CreateDeserialized(ASTContext &C, GlobalDeclID ID,
@@ -5116,6 +5123,18 @@ class ImportDecl final : public Decl,
/// Retrieve the module that was imported by the import declaration.
Module *getImportedModule() const { return ImportedModule; }
+ /// Retrieve the nested-name-specifier that qualifies the
+ /// name of the namespace, with source-location information.
+ NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; }
+
+ /// Retrieve the nested-name-specifier that qualifies the
+ /// name of the namespace.
+ NestedNameSpecifier getQualifier() const {
+ return QualifierLoc.getNestedNameSpecifier();
+ }
+
+ SourceLocation getIdentLocation() const { return getLocation(); }
+
/// Retrieves the locations of each of the identifiers that make up
/// the complete module name in the import declaration.
///
@@ -5135,22 +5154,26 @@ class ImportDecl final : public Decl,
/// \code
/// export void foo();
/// \endcode
-class ExportDecl final : public Decl, public DeclContext {
- LLVM_DECLARE_VIRTUAL_ANCHOR_FUNCTION();
+class ExportDecl final : public NamedDecl, public DeclContext {
+ void anchor() override;
private:
friend class ASTDeclReader;
/// The source location for the right brace (if valid).
SourceLocation RBraceLoc;
+ NestedNameSpecifierLoc QualifierLoc;
- ExportDecl(DeclContext *DC, SourceLocation ExportLoc)
- : Decl(Export, DC, ExportLoc), DeclContext(Export),
- RBraceLoc(SourceLocation()) {}
+ ExportDecl(DeclContext *DC, SourceLocation ExportLoc, NestedNameSpecifierLoc QualifierLoc, DeclarationName Id)
+ : NamedDecl(Export, DC, ExportLoc, Id), DeclContext(Export),
+ RBraceLoc(SourceLocation()),
+ QualifierLoc(QualifierLoc){}
public:
static ExportDecl *Create(ASTContext &C, DeclContext *DC,
- SourceLocation ExportLoc);
+ SourceLocation ExportLoc,
+ NestedNameSpecifierLoc QualifierLoc,
+ DeclarationName Id);
static ExportDecl *CreateDeserialized(ASTContext &C, GlobalDeclID ID);
SourceLocation getExportLoc() const { return getLocation(); }
@@ -5170,14 +5193,24 @@ class ExportDecl final : public Decl, public DeclContext {
SourceRange getSourceRange() const override LLVM_READONLY {
return SourceRange(getLocation(), getEndLoc());
}
+ /// Retrieve the nested-name-specifier that qualifies the
+ /// name of the namespace, with source-location information.
+ NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; }
+
+ /// Retrieve the nested-name-specifier that qualifies the
+ /// name of the namespace.
+ NestedNameSpecifier getQualifier() const {
+ return QualifierLoc.getNestedNameSpecifier();
+ }
+ SourceLocation getIdentLocation() const { return getLocation(); }
static bool classof(const Decl *D) { return classofKind(D->getKind()); }
static bool classofKind(Kind K) { return K == Export; }
static DeclContext *castToDeclContext(const ExportDecl *D) {
- return static_cast<DeclContext *>(const_cast<ExportDecl*>(D));
+ return static_cast<DeclContext *>(const_cast<ExportDecl *>(D));
}
static ExportDecl *castFromDeclContext(const DeclContext *DC) {
- return static_cast<ExportDecl *>(const_cast<DeclContext*>(DC));
+ return static_cast<ExportDecl *>(const_cast<DeclContext *>(DC));
}
};
@@ -5188,8 +5221,7 @@ class EmptyDecl : public Decl {
virtual void anchor();
public:
- static EmptyDecl *Create(ASTContext &C, DeclContext *DC,
- SourceLocation L);
+ static EmptyDecl *Create(ASTContext &C, DeclContext *DC, SourceLocation L);
static EmptyDecl *CreateDeserialized(ASTContext &C, GlobalDeclID ID);
static bool classof(const Decl *D) { return classofKind(D->getKind()); }
diff --git a/clang/include/clang/Parse/Parser.h b/clang/include/clang/Parse/Parser.h
index 5e7af97feeb6c..04d39642d6c23 100644
--- a/clang/include/clang/Parse/Parser.h
+++ b/clang/include/clang/Parse/Parser.h
@@ -7656,7 +7656,8 @@ class Parser : public CodeCompletionHandler {
///
/// exception-declaration:
/// attribute-specifier-seq[opt] type-specifier-seq declarator
- /// attribute-specifier-seq[opt] type-specifier-seq abstract-declarator[opt]
+ /// attribute-specifier-seq[opt] type-specifier-seq
+ /// abstract-declarator[opt]
/// '...'
/// \endverbatim
///
diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index ff474fdd99562..89c75b6fdebfc 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -9985,10 +9985,11 @@ class Sema final : public SemaBase {
/// The parser has processed a module-declaration that begins the definition
/// of a module interface or implementation.
- DeclGroupPtrTy ActOnModuleDecl(SourceLocation StartLoc,
+ DeclGroupPtrTy ActOnModuleDecl(CXXScopeSpec *SS, SourceLocation StartLoc,
SourceLocation ModuleLoc, ModuleDeclKind MDK,
ModuleIdPath Path, ModuleIdPath Partition,
ModuleImportState &ImportState,
+ IdentifierInfo *Id,
bool SeenNoTrivialPPDirective);
/// The parser has processed a global-module-fragment declaration that begins
@@ -10011,24 +10012,27 @@ class Sema final : public SemaBase {
/// \param ImportLoc The location of the 'import' keyword.
/// \param Path The module toplevel name as an access path.
/// \param IsPartition If the name is for a partition.
- DeclResult ActOnModuleImport(SourceLocation StartLoc,
+ DeclResult ActOnModuleImport(CXXScopeSpec *SS, SourceLocation StartLoc,
SourceLocation ExportLoc,
SourceLocation ImportLoc, ModuleIdPath Path,
- bool IsPartition = false);
- DeclResult ActOnModuleImport(SourceLocation StartLoc,
+ IdentifierInfo *Id, bool IsPartition = false);
+ DeclResult ActOnModuleImport(CXXScopeSpec *SS, SourceLocation StartLoc,
SourceLocation ExportLoc,
SourceLocation ImportLoc, Module *M,
- ModuleIdPath Path = {});
+ IdentifierInfo *Id, ModuleIdPath Path = {});
/// The parser has processed a module import translated from a
/// #include or similar preprocessing directive.
- void ActOnAnnotModuleInclude(SourceLocation DirectiveLoc, Module *Mod);
- void BuildModuleInclude(SourceLocation DirectiveLoc, Module *Mod);
+ void ActOnAnnotModuleInclude(CXXScopeSpec *SS, SourceLocation DirectiveLoc,
+ IdentifierInfo *Id, Module *Mod);
+ void BuildModuleInclude(CXXScopeSpec *SS, SourceLocation DirectiveLoc,
+ IdentifierInfo *Id, Module *Mod);
/// The parsed has entered a submodule.
void ActOnAnnotModuleBegin(SourceLocation DirectiveLoc, Module *Mod);
/// The parser has left a submodule.
- void ActOnAnnotModuleEnd(SourceLocation DirectiveLoc, Module *Mod);
+ void ActOnAnnotModuleEnd(CXXScopeSpec *SS, SourceLocation DirectiveLoc,
+ IdentifierInfo *Id, Module *Mod);
/// Create an implicit import of the given module at the given
/// source location, for error recovery, if possible.
@@ -10036,12 +10040,15 @@ class Sema final : public SemaBase {
/// This routine is typically used when an entity found by name lookup
/// is actually hidden within a module that we know about but the user
/// has forgotten to import.
- void createImplicitModuleImportForErrorRecovery(SourceLocation Loc,
+ void createImplicitModuleImportForErrorRecovery(CXXScopeSpec *SS,
+ SourceLocation Loc,
+ DeclarationName Id,
Module *Mod);
/// We have parsed the start of an export declaration, including the '{'
/// (if present).
- Decl *ActOnStartExportDecl(Scope *S, SourceLocation ExportLoc,
+ Decl *ActOnStartExportDecl(Scope *S, CXXScopeSpec *SS,
+ SourceLocation ExportLoc, IdentifierInfo *Id,
SourceLocation LBraceLoc);
/// Complete the definition of an export declaration.
diff --git a/clang/lib/AST/Decl.cpp b/clang/lib/AST/Decl.cpp
index a6de9959e0f62..fbab744624692 100644
--- a/clang/lib/AST/Decl.cpp
+++ b/clang/lib/AST/Decl.cpp
@@ -394,8 +394,7 @@ void LinkageComputer::mergeTemplateLV(
LinkageInfo &LV, const FunctionDecl *fn,
const FunctionTemplateSpecializationInfo *specInfo,
LVComputationKind computation) {
- bool considerVisibility =
- shouldConsiderTemplateVisibility(fn, specInfo);
+ bool considerVisibility = shouldConsiderTemplateVisibility(fn, specInfo);
FunctionTemplateDecl *temp = specInfo->getTemplate();
// Merge information from the template declaration.
@@ -705,10 +704,10 @@ LinkageComputer::getLVForNamespaceScopeDecl(const NamedDecl *D,
// If we're declared in a namespace with a visibility attribute,
// use that namespace's visibility, and it still counts as explicit.
for (const DeclContext *DC = D->getDeclContext();
- !isa<TranslationUnitDecl>(DC);
- DC = DC->getParent()) {
+ !isa<TranslationUnitDecl>(DC); DC = DC->getParent()) {
const auto *ND = dyn_cast<NamespaceDecl>(DC);
- if (!ND) continue;
+ if (!ND)
+ continue;
if (std::optional<Visibility> Vis =
getExplicitVisibility(ND, computation)) {
LV.mergeVisibility(*Vis, true);
@@ -962,7 +961,6 @@ LinkageComputer::getLVForClassMember(const NamedDecl *D,
if (!isExternallyVisible(classLV.getLinkage()))
return classLV;
-
// Otherwise, don't merge in classLV yet, because in certain cases
// we need to completely ignore the visibility from it.
@@ -2178,7 +2176,7 @@ SourceRange VarDecl::getSourceRange() const {
return DeclaratorDecl::getSourceRange();
}
-template<typename T>
+template <typename T>
static LanguageLinkage getDeclLanguageLinkage(const T &D) {
// C++ [dcl.link]p1: All function types, function names with external linkage,
// and variable names with external linkage have a language linkage.
@@ -2205,8 +2203,7 @@ static LanguageLinkage getDeclLanguageLinkage(const T &D) {
return CXXLanguageLinkage;
}
-template<typename T>
-static bool isDeclExternC(const T &D) {
+template <typename T> static bool isDeclExternC(const T &D) {
// Since the context is ignored for class members, they can only have C++
// language linkage or no language linkage.
const DeclContext *DC = D.getDeclContext();
@@ -2863,8 +2860,8 @@ MemberSpecializationInfo *VarDecl::getMemberSpecializationInfo() const {
return nullptr;
}
-void VarDecl::setTemplateSpecializationKind(TemplateSpecializationKind TSK,
- SourceLocation PointOfInstantiation) {
+void VarDecl::setTemplateSpecializationKind(
+ TemplateSpecializationKind TSK, SourceLocation PointOfInstantiation) {
assert((isa<VarTemplateSpecializationDecl>(this) ||
getMemberSpecializationInfo()) &&
"not a variable or static data member template specialization");
@@ -2872,8 +2869,7 @@ void VarDecl::setTemplateSpecializationKind(TemplateSpecializationKind TSK,
if (VarTemplateSpecializationDecl *Spec =
dyn_cast<VarTemplateSpecializationDecl>(this)) {
Spec->setSpecializationKind(TSK);
- if (TSK != TSK_ExplicitSpecialization &&
- PointOfInstantiation.isValid() &&
+ if (TSK != TSK_ExplicitSpecialization && PointOfInstantiation.isValid() &&
Spec->getPointOfInstantiation().isInvalid()) {
Spec->setPointOfInstantiation(PointOfInstantiation);
if (ASTMutationListener *L = getASTContext().getASTMutationListener())
@@ -2934,8 +2930,8 @@ ParmVarDecl *ParmVarDecl::Create(ASTContext &C, DeclContext *DC,
const IdentifierInfo *Id, QualType T,
TypeSourceInfo *TInfo, StorageClass S,
Expr *DefArg) {
- return new (C, DC) ParmVarDecl(ParmVar, C, DC, StartLoc, IdLoc, Id, T, TInfo,
- S, DefArg);
+ return new (C, DC)
+ ParmVarDecl(ParmVar, C, DC, StartLoc, IdLoc, Id, T, TInfo, S, DefArg);
}
QualType ParmVarDecl::getOriginalType() const {
@@ -3590,9 +3586,7 @@ LanguageLinkage FunctionDecl::getLanguageLinkage() const {
return getDeclLanguageLinkage(*this);
}
-bool FunctionDecl::isExternC() const {
- return isDeclExternC(*this);
-}
+bool FunctionDecl::isExternC() const { return isDeclExternC(*this); }
bool FunctionDecl::isInExternCContext() const {
if (DeviceKernelAttr::isOpenCLSpelling(getAttr<DeviceKernelAttr>()))
@@ -3611,8 +3605,7 @@ bool FunctionDecl::isGlobal() const {
if (getCanonicalDecl()->getStorageClass() == SC_Static)
return false;
- for (const DeclContext *DC = getDeclContext();
- DC->isNamespace();
+ for (const DeclContext *DC = getDeclContext(); DC->isNamespace();
DC = DC->getParent()) {
if (const auto *Namespace = cast<NamespaceDecl>(DC)) {
if (!Namespace->getDeclName())
@@ -3810,7 +3803,7 @@ void FunctionDecl::setParams(ASTContext &C,
// Zero params -> null pointer.
if (!NewParamInfo.empty()) {
- ParamInfo = new (C) ParmVarDecl*[NewParamInfo.size()];
+ ParamInfo = new (C) ParmVarDecl *[NewParamInfo.size()];
llvm::copy(NewParamInfo, ParamInfo);
}
}
@@ -4929,7 +4922,7 @@ void TagDecl::startDefinition() {
if (auto *D = dyn_cast<CXXRecordDecl>(this)) {
struct CXXRecordDecl::DefinitionData *Data =
- new (getASTContext()) struct CXXRecordDecl::DefinitionData(D);
+ new (getASTContext()) struct CXXRecordDecl::DefinitionData(D);
for (auto *I : redecls())
cast<CXXRecordDecl>(I)->DefinitionData = Data;
}
@@ -5470,7 +5463,7 @@ void BlockDecl::setParams(ArrayRef<ParmVarDecl *> NewParamInfo) {
// Zero params -> null pointer.
if (!NewParamInfo.empty()) {
NumParams = NewParamInfo.size();
- ParamInfo = new (getASTContext()) ParmVarDecl*[NewParamInfo.size()];
+ ParamInfo = new (getASTContext()) ParmVarDecl *[NewParamInfo.size()];
llvm::copy(NewParamInfo, ParamInfo);
}
}
@@ -6053,36 +6046,42 @@ static unsigned getNumModuleIdentifiers(Module *Mod) {
}
ImportDecl::ImportDecl(DeclContext *DC, SourceLocation StartLoc,
- Module *Imported,
+ Module *Imported, NestedNameSpecifierLoc QualifierLoc,
+ IdentifierInfo *Id,
ArrayRef<SourceLocation> IdentifierLocs)
- : Decl(Import, DC, StartLoc), ImportedModule(Imported),
- NextLocalImportAndComplete(nullptr, true) {
+ : NamedDecl(Import, DC, StartLoc, Id), ImportedModule(Imported),
+ QualifierLoc(QualifierLoc), NextLocalImportAndComplete(nullptr, true) {
assert(getNumModuleIdentifiers(Imported) == IdentifierLocs.size());
auto *StoredLocs = getTrailingObjects();
llvm::uninitialized_copy(IdentifierLocs, StoredLocs);
}
ImportDecl::ImportDecl(DeclContext *DC, SourceLocation StartLoc,
- Module *Imported, SourceLocation EndLoc)
- : Decl(Import, DC, StartLoc), ImportedModule(Imported),
- NextLocalImportAndComplete(nullptr, false) {
+ Module *Imported, NestedNameSpecifierLoc QualifierLoc,
+ DeclarationName Id, SourceLocation EndLoc)
+ : NamedDecl(Import, DC, StartLoc, Id), ImportedModule(Imported),
+ QualifierLoc(QualifierLoc), NextLocalImportAndComplete(nullptr, false) {
*getTrailingObjects() = EndLoc;
}
ImportDecl *ImportDecl::Create(ASTContext &C, DeclContext *DC,
+ NestedNameSpecifierLoc QualifierLoc,
SourceLocation StartLoc, Module *Imported,
+ IdentifierInfo *Id,
ArrayRef<SourceLocation> IdentifierLocs) {
return new (C, DC,
additionalSizeToAlloc<SourceLocation>(IdentifierLocs.size()))
- ImportDecl(DC, StartLoc, Imported, IdentifierLocs);
+ ImportDecl(DC, StartLoc, Imported, QualifierLoc, Id, IdentifierLocs);
}
ImportDecl *ImportDecl::CreateImplicit(ASTContext &C, DeclContext *DC,
SourceLocation StartLoc,
Module *Imported,
+ NestedNameSpecifierLoc QualifierLoc,
+ DeclarationName Id,
SourceLocation EndLoc) {
ImportDecl *Import = new (C, DC, additionalSizeToAlloc<SourceLocation>(1))
- ImportDecl(DC, StartLoc, Imported, EndLoc);
+ ImportDecl(DC, StartLoc, Imported, QualifierLoc, Id, EndLoc);
Import->setImplicit();
return Import;
}
@@ -6114,12 +6113,15 @@ SourceRange ImportDecl::getSourceRange() const {
void ExportDecl::anchor() {}
ExportDecl *ExportDecl::Create(ASTContext &C, DeclContext *DC,
- SourceLocation ExportLoc) {
- return new (C, DC) ExportDecl(DC, ExportLoc);
+ SourceLocation ExportLoc,
+ NestedNameSpecifierLoc QualifierLoc,
+ DeclarationName Id
+ ) {
+ return new (C, DC) ExportDecl(DC, ExportLoc, QualifierLoc, Id);
}
ExportDecl *ExportDecl::CreateDeserialized(ASTContext &C, GlobalDeclID ID) {
- return new (C, ID) ExportDecl(nullptr, SourceLocation());
+ return new (C, ID) ExportDecl(nullptr, SourceLocation(), NestedNameSpecifierLoc(), DeclarationName());
}
bool clang::IsArmStreamingFunction(const FunctionDecl *FD,
diff --git a/clang/lib/Parse/ParseDeclCXX.cpp b/clang/lib/Parse/ParseDeclCXX.cpp
index 86f18d10f08b0..88c461ae9c9ab 100644
--- a/clang/lib/Parse/ParseDeclCXX.cpp
+++ b/clang/lib/Parse/ParseDeclCXX.cpp
@@ -400,6 +400,7 @@ Decl *Parser::ParseExportDeclaration() {
assert(Tok.is(tok::kw_export));
SourceLocation ExportLoc = ConsumeToken();
+ CXXScopeSpec SS;
if (Tok.is(tok::code_completion)) {
cutOffParsing();
Actions.CodeCompletion().CodeCompleteOrdinaryName(
@@ -411,7 +412,7 @@ Decl *Parser::ParseExportDeclaration() {
ParseScope ExportScope(this, Scope::DeclScope);
Decl *ExportDecl = Actions.ActOnStartExportDecl(
- getCurScope(), ExportLoc,
+ getCurScope(), &SS, ExportLoc, Tok.getIdentifierInfo(),
Tok.is(tok::l_brace) ? Tok.getLocation() : SourceLocation());
if (Tok.isNot(tok::l_brace)) {
@@ -891,8 +892,9 @@ Decl *Parser::ParseAliasDeclarationAfterDeclarator(
Decl *DeclFromDeclSpec = nullptr;
TypeResult TypeAlias =
ParseTypeName(nullptr,
- TemplateInfo.Kind != ParsedTemplateKind::NonTemplate ? DeclaratorContext::AliasTemplate
- : DeclaratorContext::AliasDecl,
+ TemplateInfo.Kind != ParsedTemplateKind::NonTemplate
+ ? DeclaratorContext::AliasTemplate
+ : DeclaratorContext::AliasDecl,
AS, &DeclFromDeclSpec, &Attrs);
if (OwnedType)
*OwnedType = DeclFromDeclSpec;
@@ -2231,7 +2233,8 @@ void Parser::ParseClassSpecifier(tok::TokenKind TagTokKind,
// C, since definitions are not permitted in this context in C++.
if (TUK == TagUseKind::Definition &&
(getLangOpts().CPlusPlus || !isTypeSpecifier(DSC)) &&
- (TemplateInfo.Kind != ParsedTemplateKind::NonTemplate || !isValidAfterTypeSpecifier(false))) {
+ (TemplateInfo.Kind != ParsedTemplateKind::NonTemplate ||
+ !isValidAfterTypeSpecifier(false))) {
if (Tok.isNot(tok::semi)) {
const PrintingPolicy &PPol = Actions.getASTContext().getPrintingPolicy();
ExpectAndConsume(tok::semi, diag::err_expected_after,
diff --git a/clang/lib/Parse/Parser.cpp b/clang/lib/Parse/Parser.cpp
index 5e1fd4df1a3f0..3a61f02042293 100644
--- a/clang/lib/Parse/Parser.cpp
+++ b/clang/lib/Parse/Parser.cpp
@@ -113,16 +113,16 @@ void Parser::SuggestParentheses(SourceLocation Loc, unsigned DK,
return;
}
- Diag(Loc, DK)
- << FixItHint::CreateInsertion(ParenRange.getBegin(), "(")
- << FixItHint::CreateInsertion(EndLoc, ")");
+ Diag(Loc, DK) << FixItHint::CreateInsertion(ParenRange.getBegin(), "(")
+ << FixItHint::CreateInsertion(EndLoc, ")");
}
static bool IsCommonTypo(tok::TokenKind ExpectedTok, const Token &Tok) {
switch (ExpectedTok) {
case tok::semi:
return Tok.is(tok::colon) || Tok.is(tok::comma); // : or , for ;
- default: return false;
+ default:
+ return false;
}
}
@@ -139,7 +139,7 @@ bool Parser::ExpectAndConsume(tok::TokenKind ExpectedTok, unsigned DiagID,
{
DiagnosticBuilder DB = Diag(Loc, DiagID);
DB << FixItHint::CreateReplacement(
- SourceRange(Loc), tok::getPunctuatorSpelling(ExpectedTok));
+ SourceRange(Loc), tok::getPunctuatorSpelling(ExpectedTok));
if (DiagID == diag::err_expected)
DB << ExpectedTok;
else if (DiagID == diag::err_expected_after)
@@ -615,6 +615,8 @@ bool Parser::ParseTopLevelDecl(DeclGroupPtrTy &Result,
Sema::ModuleImportState &ImportState) {
DestroyTemplateIdAnnotationsRAIIObj CleanupRAII(*this);
+ CXXScopeSpec SS;
+
Result = nullptr;
switch (Tok.getKind()) {
case tok::annot_pragma_unused:
@@ -638,11 +640,12 @@ bool Parser::ParseTopLevelDecl(DeclGroupPtrTy &Result,
return false;
case tok::kw_import:
- import_decl: {
- Decl *ImportDecl = ParseModuleImport(SourceLocation(), ImportState);
- Result = Actions.ConvertDeclToDeclGroup(ImportDecl);
- return false;
- }
+ import_decl:
+ {
+ Decl *ImportDecl = ParseModuleImport(SourceLocation(), ImportState);
+ Result = Actions.ConvertDeclToDeclGroup(ImportDecl);
+ return false;
+ }
case tok::annot_module_include: {
auto Loc = Tok.getLocation();
@@ -650,10 +653,10 @@ bool Parser::ParseTopLevelDecl(DeclGroupPtrTy &Result,
// FIXME: We need a better way to disambiguate C++ clang modules and
// standard C++ modules.
if (!getLangOpts().CPlusPlusModules || !Mod->isHeaderUnit())
- Actions.ActOnAnnotModuleInclude(Loc, Mod);
+ Actions.ActOnAnnotModuleInclude(&SS, Loc, Tok.getIdentifierInfo(), Mod);
else {
DeclResult Import =
- Actions.ActOnModuleImport(Loc, SourceLocation(), Loc, Mod);
+ Actions.ActOnModuleImport(&SS, Loc, SourceLocation(), Loc, Mod, Tok.getIdentifierInfo());
Decl *ImportDecl = Import.isInvalid() ? nullptr : Import.get();
Result = Actions.ConvertDeclToDeclGroup(ImportDecl);
}
@@ -671,7 +674,7 @@ bool Parser::ParseTopLevelDecl(DeclGroupPtrTy &Result,
case tok::annot_module_end:
Actions.ActOnAnnotModuleEnd(
- Tok.getLocation(),
+ &SS, Tok.getLocation(), Tok.getIdentifierInfo(),
reinterpret_cast<Module *>(Tok.getAnnotationValue()));
ConsumeAnnotationToken();
ImportState = Sema::ModuleImportState::NotACXX20Module;
@@ -692,7 +695,7 @@ bool Parser::ParseTopLevelDecl(DeclGroupPtrTy &Result,
// Late template parsing can begin.
Actions.SetLateTemplateParser(LateTemplateParserCallback, this);
Actions.ActOnEndOfTranslationUnit();
- //else don't tell Sema that we ended parsing: more input might come.
+ // else don't tell Sema that we ended parsing: more input might come.
return true;
default:
break;
@@ -826,7 +829,7 @@ Parser::ParseExternalDeclaration(ParsedAttributes &Attrs,
return nullptr;
case tok::kw___extension__: {
// __extension__ silences extension warnings in the subexpression.
- ExtensionRAIIObject O(Diags); // Use RAII to do this.
+ ExtensionRAIIObject O(Diags); // Use RAII to do this.
ConsumeToken();
return ParseExternalDeclaration(Attrs, DeclSpecAttrs);
}
@@ -931,8 +934,7 @@ Parser::ParseExternalDeclaration(ParsedAttributes &Attrs,
// Parse (then ignore) 'static' prior to a template instantiation. This is
// a GCC extension that we intentionally do not support.
if (getLangOpts().CPlusPlus && NextToken().is(tok::kw_template)) {
- Diag(ConsumeToken(), diag::warn_static_inline_explicit_inst_ignored)
- << 0;
+ Diag(ConsumeToken(), diag::warn_static_inline_explicit_inst_ignored) << 0;
SourceLocation DeclEnd;
return ParseDeclaration(DeclaratorContext::File, DeclEnd, Attrs,
DeclSpecAttrs);
@@ -954,7 +956,7 @@ Parser::ParseExternalDeclaration(ParsedAttributes &Attrs,
// a GCC extension that we intentionally do not support.
if (NextKind == tok::kw_template) {
Diag(ConsumeToken(), diag::warn_static_inline_explicit_inst_ignored)
- << 1;
+ << 1;
SourceLocation DeclEnd;
return ParseDeclaration(DeclaratorContext::File, DeclEnd, Attrs,
DeclSpecAttrs);
@@ -969,9 +971,10 @@ Parser::ParseExternalDeclaration(ParsedAttributes &Attrs,
// Extern templates
SourceLocation ExternLoc = ConsumeToken();
SourceLocation TemplateLoc = ConsumeToken();
- Diag(ExternLoc, getLangOpts().CPlusPlus11 ?
- diag::warn_cxx98_compat_extern_template :
- diag::ext_extern_template) << SourceRange(ExternLoc, TemplateLoc);
+ Diag(ExternLoc, getLangOpts().CPlusPlus11
+ ? diag::warn_cxx98_compat_extern_template
+ : diag::ext_extern_template)
+ << SourceRange(ExternLoc, TemplateLoc);
SourceLocation DeclEnd;
return ParseExplicitInstantiation(DeclaratorContext::File, ExternLoc,
TemplateLoc, DeclEnd, Attrs);
@@ -1499,12 +1502,12 @@ void Parser::ParseKNRParamDeclarations(Declarator &D) {
// Scan the argument list looking for the correct param to apply this
// type.
- for (unsigned i = 0; ; ++i) {
+ for (unsigned i = 0;; ++i) {
// C99 6.9.1p6: those declarators shall declare only identifiers from
// the identifier list.
if (i == FTI.NumParams) {
Diag(ParmDeclarator.getIdentifierLoc(), diag::err_no_matching_param)
- << ParmDeclarator.getIdentifier();
+ << ParmDeclarator.getIdentifier();
break;
}
@@ -1513,7 +1516,7 @@ void Parser::ParseKNRParamDeclarations(Declarator &D) {
if (FTI.Params[i].Param) {
Diag(ParmDeclarator.getIdentifierLoc(),
diag::err_param_redefinition)
- << ParmDeclarator.getIdentifier();
+ << ParmDeclarator.getIdentifier();
} else {
FTI.Params[i].Param = Param;
}
@@ -2009,10 +2012,9 @@ bool Parser::TryAnnotateTypeOrScopeTokenAfterScopeSpec(
// Consume the name.
SourceLocation IdentifierLoc = ConsumeToken();
SourceLocation NewEndLoc;
- TypeResult NewType
- = parseObjCTypeArgsAndProtocolQualifiers(IdentifierLoc, Ty,
- /*consumeLastToken=*/false,
- NewEndLoc);
+ TypeResult NewType = parseObjCTypeArgsAndProtocolQualifiers(
+ IdentifierLoc, Ty,
+ /*consumeLastToken=*/false, NewEndLoc);
if (NewType.isUsable())
Ty = NewType.get();
else if (Tok.is(tok::eof)) // Nothing to do here, bail out...
@@ -2327,6 +2329,7 @@ Parser::ParseModuleDecl(Sema::ModuleImportState &ImportState) {
SourceLocation ModuleLoc = ConsumeToken();
+ CXXScopeSpec SS;
// Attributes appear after the module name, not before.
// FIXME: Suggest moving the attributes later with a fixit.
DiagnoseAndSkipCXX11Attributes();
@@ -2397,8 +2400,8 @@ Parser::ParseModuleDecl(Sema::ModuleImportState &ImportState) {
tok::getKeywordSpelling(tok::kw_module)))
SkipUntil(tok::semi);
- return Actions.ActOnModuleDecl(StartLoc, ModuleLoc, MDK, Path, Partition,
- ImportState,
+ return Actions.ActOnModuleDecl(&SS, StartLoc, ModuleLoc, MDK, Path, Partition,
+ ImportState, Tok.getIdentifierInfo(),
Introducer.hasSeenNoTrivialPPDirective());
}
@@ -2415,6 +2418,8 @@ Decl *Parser::ParseModuleImport(SourceLocation AtLoc,
bool IsObjCAtImport = Tok.isObjCAtKeyword(tok::objc_import);
SourceLocation ImportLoc = ConsumeToken();
+ CXXScopeSpec SS;
+
// For C++20 modules, we can have "name" or ":Partition name" as valid input.
SmallVector<IdentifierLoc, 2> Path;
bool IsPartition = false;
@@ -2522,11 +2527,11 @@ Decl *Parser::ParseModuleImport(SourceLocation AtLoc,
DeclResult Import;
if (HeaderUnit)
- Import =
- Actions.ActOnModuleImport(StartLoc, ExportLoc, ImportLoc, HeaderUnit);
+ Import = Actions.ActOnModuleImport(&SS, StartLoc, ExportLoc, ImportLoc,
+ HeaderUnit, Tok.getIdentifierInfo());
else if (!Path.empty())
- Import = Actions.ActOnModuleImport(StartLoc, ExportLoc, ImportLoc, Path,
- IsPartition);
+ Import = Actions.ActOnModuleImport(&SS, StartLoc, ExportLoc, ImportLoc,
+ Path, Tok.getIdentifierInfo(), IsPartition);
if (Import.isInvalid())
return nullptr;
@@ -2559,6 +2564,8 @@ bool Parser::ParseModuleName(SourceLocation UseLoc,
}
bool Parser::parseMisplacedModuleImport() {
+ CXXScopeSpec SS;
+
while (true) {
switch (Tok.getKind()) {
case tok::annot_module_end:
@@ -2568,7 +2575,7 @@ bool Parser::parseMisplacedModuleImport() {
if (MisplacedModuleBeginCount) {
--MisplacedModuleBeginCount;
Actions.ActOnAnnotModuleEnd(
- Tok.getLocation(),
+ &SS, Tok.getLocation(), Tok.getIdentifierInfo(),
reinterpret_cast<Module *>(Tok.getAnnotationValue()));
ConsumeAnnotationToken();
continue;
@@ -2589,7 +2596,7 @@ bool Parser::parseMisplacedModuleImport() {
// Module import found where it should not be, for instance, inside a
// namespace. Recover by importing the module.
Actions.ActOnAnnotModuleInclude(
- Tok.getLocation(),
+ &SS, Tok.getLocation(), Tok.getIdentifierInfo(),
reinterpret_cast<Module *>(Tok.getAnnotationValue()));
ConsumeAnnotationToken();
// If there is another module import, process it.
diff --git a/clang/lib/Sema/SemaLookup.cpp b/clang/lib/Sema/SemaLookup.cpp
index 65b60964d1192..ea94e08d9c552 100644
--- a/clang/lib/Sema/SemaLookup.cpp
+++ b/clang/lib/Sema/SemaLookup.cpp
@@ -1705,7 +1705,7 @@ hasAcceptableDefaultArgument(Sema &S, const ParmDecl *D,
return true;
if (!DefaultArg.isInherited() && Modules) {
- auto *NonConstD = const_cast<ParmDecl*>(D);
+ auto *NonConstD = const_cast<ParmDecl *>(D);
Modules->push_back(S.getOwningModule(NonConstD));
}
@@ -2622,7 +2622,7 @@ bool Sema::LookupQualifiedName(LookupResult &R, DeclContext *LookupCtx,
// possibility of declarations appearing more than once.
llvm::SmallDenseMap<Result, bool, 32> AResults;
for (; AResult; AResult = Next(AIt, AEnd))
- AResults.insert({AResult, /*FoundInB*/false});
+ AResults.insert({AResult, /*FoundInB*/ false});
unsigned Found = 0;
for (; BResult; BResult = Next(BIt, BEnd)) {
auto It = AResults.find(BResult);
@@ -3667,8 +3667,7 @@ CXXMethodDecl *Sema::LookupCopyingAssignment(CXXRecordDecl *Class,
}
CXXMethodDecl *Sema::LookupMovingAssignment(CXXRecordDecl *Class,
- unsigned Quals,
- bool RValueThis,
+ unsigned Quals, bool RValueThis,
unsigned ThisQuals) {
assert(!(ThisQuals & ~(Qualifiers::Const | Qualifiers::Volatile)) &&
"non-const, non-volatile qualifiers for copy assignment this");
@@ -5711,10 +5710,10 @@ void Sema::diagnoseMissingImport(SourceLocation UseLoc, const NamedDecl *Decl,
// declaration was previously reached.
Diag(DeclLoc, diag::note_unreachable_entity) << (int)MIK;
};
-
+ CXXScopeSpec SS;
// Weed out duplicates from module list.
- llvm::SmallVector<Module*, 8> UniqueModules;
- llvm::SmallDenseSet<Module*, 8> UniqueModuleSet;
+ llvm::SmallVector<Module *, 8> UniqueModules;
+ llvm::SmallDenseSet<Module *, 8> UniqueModuleSet;
for (auto *M : Modules) {
if (M->isExplicitGlobalModule() || M->isPrivateModule())
continue;
@@ -5742,7 +5741,8 @@ void Sema::diagnoseMissingImport(SourceLocation UseLoc, const NamedDecl *Decl,
// Produce a note showing where the entity was declared.
NotePrevious();
if (Recover)
- createImplicitModuleImportForErrorRecovery(UseLoc, Modules[0]);
+ createImplicitModuleImportForErrorRecovery(&SS, UseLoc, DeclarationName(),
+ Modules[0]);
return;
}
@@ -5788,7 +5788,8 @@ void Sema::diagnoseMissingImport(SourceLocation UseLoc, const NamedDecl *Decl,
// Try to recover by implicitly importing this module.
if (Recover)
- createImplicitModuleImportForErrorRecovery(UseLoc, Modules[0]);
+ createImplicitModuleImportForErrorRecovery(&SS, UseLoc, DeclarationName(),
+ Modules[0]);
}
void Sema::diagnoseTypo(const TypoCorrection &Correction,
diff --git a/clang/lib/Sema/SemaModule.cpp b/clang/lib/Sema/SemaModule.cpp
index caa61a99a6914..ca7ae8fdd4399 100644
--- a/clang/lib/Sema/SemaModule.cpp
+++ b/clang/lib/Sema/SemaModule.cpp
@@ -152,8 +152,7 @@ makeTransitiveImportsVisible(ASTContext &Ctx, VisibleModuleSet &VisibleModules,
Sema::DeclGroupPtrTy
Sema::ActOnGlobalModuleFragmentDecl(SourceLocation ModuleLoc) {
// We start in the global module;
- Module *GlobalModule =
- PushGlobalModuleFragment(ModuleLoc);
+ Module *GlobalModule = PushGlobalModuleFragment(ModuleLoc);
// All declarations created from now on are owned by the global module.
auto *TU = Context.getTranslationUnitDecl();
@@ -246,9 +245,10 @@ static bool DiagReservedModuleName(Sema &S, const IdentifierInfo *II,
}
Sema::DeclGroupPtrTy
-Sema::ActOnModuleDecl(SourceLocation StartLoc, SourceLocation ModuleLoc,
- ModuleDeclKind MDK, ModuleIdPath Path,
- ModuleIdPath Partition, ModuleImportState &ImportState,
+Sema::ActOnModuleDecl(CXXScopeSpec *SS, SourceLocation StartLoc,
+ SourceLocation ModuleLoc, ModuleDeclKind MDK,
+ ModuleIdPath Path, ModuleIdPath Partition,
+ ModuleImportState &ImportState, IdentifierInfo *Id,
bool SeenNoTrivialPPDirective) {
assert(getLangOpts().CPlusPlusModules &&
"should only have module decl in standard C++ modules");
@@ -470,14 +470,14 @@ Sema::ActOnModuleDecl(SourceLocation StartLoc, SourceLocation ModuleLoc,
// and return the import decl to be added to the current TU.
if (Interface) {
HadImportedNamedModules = true;
-
makeTransitiveImportsVisible(getASTContext(), VisibleModules, Interface,
Mod, ModuleLoc,
/*IsImportingPrimaryModuleInterface=*/true);
// Make the import decl for the interface in the impl module.
- ImportDecl *Import = ImportDecl::Create(Context, CurContext, ModuleLoc,
- Interface, Path[0].getLoc());
+ ImportDecl *Import = ImportDecl::Create(
+ Context, CurContext, SS->getWithLocInContext(Context), ModuleLoc,
+ Interface, Id, Path[0].getLoc());
CurContext->addDecl(Import);
// Sequence initialization of the imported module before that of the current
@@ -557,10 +557,10 @@ Sema::ActOnPrivateModuleFragmentDecl(SourceLocation ModuleLoc,
return nullptr;
}
-DeclResult Sema::ActOnModuleImport(SourceLocation StartLoc,
+DeclResult Sema::ActOnModuleImport(CXXScopeSpec *SS, SourceLocation StartLoc,
SourceLocation ExportLoc,
SourceLocation ImportLoc, ModuleIdPath Path,
- bool IsPartition) {
+ IdentifierInfo *Id, bool IsPartition) {
assert((!IsPartition || getLangOpts().CPlusPlusModules) &&
"partition seen in non-C++20 code?");
@@ -614,7 +614,7 @@ DeclResult Sema::ActOnModuleImport(SourceLocation StartLoc,
return true;
}
- return ActOnModuleImport(StartLoc, ExportLoc, ImportLoc, Mod, Path);
+ return ActOnModuleImport(SS, StartLoc, ExportLoc, ImportLoc, Mod, Id, Path);
}
/// Determine whether \p D is lexically within an export-declaration.
@@ -625,10 +625,10 @@ static const ExportDecl *getEnclosingExportDecl(const Decl *D) {
return nullptr;
}
-DeclResult Sema::ActOnModuleImport(SourceLocation StartLoc,
+DeclResult Sema::ActOnModuleImport(CXXScopeSpec *SS, SourceLocation StartLoc,
SourceLocation ExportLoc,
SourceLocation ImportLoc, Module *Mod,
- ModuleIdPath Path) {
+ IdentifierInfo *Id, ModuleIdPath Path) {
if (Mod->isHeaderUnit())
Diag(ImportLoc, diag::warn_experimental_header_unit);
@@ -683,8 +683,9 @@ DeclResult Sema::ActOnModuleImport(SourceLocation StartLoc,
}
}
- ImportDecl *Import = ImportDecl::Create(Context, CurContext, StartLoc,
- Mod, IdentifierLocs);
+ ImportDecl *Import =
+ ImportDecl::Create(Context, CurContext, SS->getWithLocInContext(Context),
+ StartLoc, Mod, Id, IdentifierLocs);
CurContext->addDecl(Import);
// Sequence initialization of the imported module before that of the current
@@ -718,12 +719,15 @@ DeclResult Sema::ActOnModuleImport(SourceLocation StartLoc,
return Import;
}
-void Sema::ActOnAnnotModuleInclude(SourceLocation DirectiveLoc, Module *Mod) {
+void Sema::ActOnAnnotModuleInclude(CXXScopeSpec *SS,
+ SourceLocation DirectiveLoc,
+ IdentifierInfo *Id, Module *Mod) {
checkModuleImportContext(*this, Mod, DirectiveLoc, CurContext, true);
- BuildModuleInclude(DirectiveLoc, Mod);
+ BuildModuleInclude(SS, DirectiveLoc, Id, Mod);
}
-void Sema::BuildModuleInclude(SourceLocation DirectiveLoc, Module *Mod) {
+void Sema::BuildModuleInclude(CXXScopeSpec *SS, SourceLocation DirectiveLoc,
+ IdentifierInfo *Id, Module *Mod) {
// Determine whether we're in the #include buffer for a module. The #includes
// in that buffer do not qualify as module imports; they're just an
// implementation detail of us building the module.
@@ -737,9 +741,9 @@ void Sema::BuildModuleInclude(SourceLocation DirectiveLoc, Module *Mod) {
// #include in the main file, synthesize an ImportDecl.
if (getLangOpts().Modules && !IsInModuleIncludes) {
TranslationUnitDecl *TU = getASTContext().getTranslationUnitDecl();
- ImportDecl *ImportD = ImportDecl::CreateImplicit(getASTContext(), TU,
- DirectiveLoc, Mod,
- DirectiveLoc);
+ ImportDecl *ImportD = ImportDecl::CreateImplicit(
+ getASTContext(), TU, DirectiveLoc, Mod,
+ SS->getWithLocInContext(getASTContext()), Id, DirectiveLoc);
if (!ModuleScopes.empty())
Context.addModuleInitializer(ModuleScopes.back().Module, ImportD);
TU->addDecl(ImportD);
@@ -786,7 +790,8 @@ void Sema::ActOnAnnotModuleBegin(SourceLocation DirectiveLoc, Module *Mod) {
}
}
-void Sema::ActOnAnnotModuleEnd(SourceLocation EomLoc, Module *Mod) {
+void Sema::ActOnAnnotModuleEnd(CXXScopeSpec *SS, SourceLocation EomLoc,
+ IdentifierInfo *Id, Module *Mod) {
if (getLangOpts().ModulesLocalVisibility) {
VisibleModules = std::move(ModuleScopes.back().OuterVisibleModules);
// Leaving a module hides namespace names, so our visible namespace cache
@@ -811,7 +816,7 @@ void Sema::ActOnAnnotModuleEnd(SourceLocation EomLoc, Module *Mod) {
// We reached an EOM pragma. Use the pragma location.
DirectiveLoc = EomLoc;
}
- BuildModuleInclude(DirectiveLoc, Mod);
+ BuildModuleInclude(SS, DirectiveLoc, Id, Mod);
// Any further declarations are in whatever module we returned to.
if (getLangOpts().trackLocalOwningModule()) {
@@ -826,7 +831,9 @@ void Sema::ActOnAnnotModuleEnd(SourceLocation EomLoc, Module *Mod) {
}
}
-void Sema::createImplicitModuleImportForErrorRecovery(SourceLocation Loc,
+void Sema::createImplicitModuleImportForErrorRecovery(CXXScopeSpec *SS,
+ SourceLocation Loc,
+ DeclarationName Id,
Module *Mod) {
// Bail if we're not allowed to implicitly import a module here.
if (isSFINAEContext() || !getLangOpts().ModulesErrorRecovery ||
@@ -835,8 +842,9 @@ void Sema::createImplicitModuleImportForErrorRecovery(SourceLocation Loc,
// Create the implicit import declaration.
TranslationUnitDecl *TU = getASTContext().getTranslationUnitDecl();
- ImportDecl *ImportD = ImportDecl::CreateImplicit(getASTContext(), TU,
- Loc, Mod, Loc);
+ ImportDecl *ImportD = ImportDecl::CreateImplicit(
+ getASTContext(), TU, Loc, Mod, SS->getWithLocInContext(getASTContext()),
+ Id, Loc);
TU->addDecl(ImportD);
Consumer.HandleImplicitImportDecl(ImportD);
@@ -845,9 +853,12 @@ void Sema::createImplicitModuleImportForErrorRecovery(SourceLocation Loc,
VisibleModules.setVisible(Mod, Loc);
}
-Decl *Sema::ActOnStartExportDecl(Scope *S, SourceLocation ExportLoc,
+Decl *Sema::ActOnStartExportDecl(Scope *S, CXXScopeSpec *SS,
+ SourceLocation ExportLoc, IdentifierInfo *Id,
SourceLocation LBraceLoc) {
- ExportDecl *D = ExportDecl::Create(Context, CurContext, ExportLoc);
+ ExportDecl *D =
+ ExportDecl::Create(Context, CurContext, ExportLoc,
+ SS->getWithLocInContext(getASTContext()), Id);
// Set this temporarily so we know the export-declaration was braced.
D->setRBraceLoc(LBraceLoc);
@@ -867,12 +878,13 @@ Decl *Sema::ActOnStartExportDecl(Scope *S, SourceLocation ExportLoc,
} else if (currentModuleIsImplementation()) {
Diag(ExportLoc, diag::err_export_not_in_module_interface) << 1;
Diag(ModuleScopes.back().BeginLoc,
- diag::note_not_module_interface_add_export)
- << FixItHint::CreateInsertion(ModuleScopes.back().BeginLoc, "export ");
+ diag::note_not_module_interface_add_export)
+ << FixItHint::CreateInsertion(ModuleScopes.back().BeginLoc,
+ "export ");
D->setInvalidDecl();
return D;
} else if (ModuleScopes.back().Module->Kind ==
- Module::PrivateModuleFragment) {
+ Module::PrivateModuleFragment) {
Diag(ExportLoc, diag::err_export_in_private_module_fragment);
Diag(ModuleScopes.back().BeginLoc, diag::note_private_module_fragment);
D->setInvalidDecl();
More information about the cfe-commits
mailing list