[cfe-commits] r145640 - in /cfe/trunk: include/clang/AST/DeclBase.h include/clang/Serialization/ASTReader.h lib/Serialization/ASTReader.cpp lib/Serialization/ASTReaderDecl.cpp lib/Serialization/ASTWriter.cpp test/Modules/Inputs/submodules/hash_map.h test/Modules/Inputs/submodules/module.map test/Modules/Inputs/submodules/vector.h test/Modules/auto-module-import.c test/Modules/diamond.c test/Modules/submodules-preprocess.cpp test/Modules/submodules.cpp
Douglas Gregor
dgregor at apple.com
Thu Dec 1 14:20:10 PST 2011
Author: dgregor
Date: Thu Dec 1 16:20:10 2011
New Revision: 145640
URL: http://llvm.org/viewvc/llvm-project?rev=145640&view=rev
Log:
Implement name hiding for declarations deserialized from a non-visible
module. When that module becomes visible, so do those declarations.
Added:
cfe/trunk/test/Modules/Inputs/submodules/hash_map.h
cfe/trunk/test/Modules/submodules-preprocess.cpp
Modified:
cfe/trunk/include/clang/AST/DeclBase.h
cfe/trunk/include/clang/Serialization/ASTReader.h
cfe/trunk/lib/Serialization/ASTReader.cpp
cfe/trunk/lib/Serialization/ASTReaderDecl.cpp
cfe/trunk/lib/Serialization/ASTWriter.cpp
cfe/trunk/test/Modules/Inputs/submodules/module.map
cfe/trunk/test/Modules/Inputs/submodules/vector.h
cfe/trunk/test/Modules/auto-module-import.c
cfe/trunk/test/Modules/diamond.c
cfe/trunk/test/Modules/submodules.cpp
Modified: cfe/trunk/include/clang/AST/DeclBase.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/DeclBase.h?rev=145640&r1=145639&r2=145640&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/DeclBase.h (original)
+++ cfe/trunk/include/clang/AST/DeclBase.h Thu Dec 1 16:20:10 2011
@@ -278,6 +278,7 @@
friend class ASTDeclWriter;
friend class ASTDeclReader;
+ friend class ASTReader;
private:
void CheckAccessDeclContext() const;
Modified: cfe/trunk/include/clang/Serialization/ASTReader.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Serialization/ASTReader.h?rev=145640&r1=145639&r2=145640&view=diff
==============================================================================
--- cfe/trunk/include/clang/Serialization/ASTReader.h (original)
+++ cfe/trunk/include/clang/Serialization/ASTReader.h Thu Dec 1 16:20:10 2011
@@ -383,6 +383,15 @@
/// global submodule ID to produce a local ID.
GlobalSubmoduleMapType GlobalSubmoduleMap;
+ /// \brief A set of hidden declarations.
+ typedef llvm::SmallVector<Decl *, 2> HiddenNames;
+
+ typedef llvm::DenseMap<Module *, HiddenNames> HiddenNamesMapType;
+
+ /// \brief A mapping from each of the hidden submodules to the deserialized
+ /// declarations in that submodule that could be made visible.
+ HiddenNamesMapType HiddenNamesMap;
+
/// \brief A vector containing selectors that have already been loaded.
///
/// This vector is indexed by the Selector ID (-1). NULL selector
@@ -813,6 +822,9 @@
void makeModuleVisible(Module *Mod,
Module::NameVisibilityKind NameVisibility);
+ /// \brief Make the names within this set of hidden names visible.
+ void makeNamesVisible(const HiddenNames &Names);
+
/// \brief Set the AST callbacks listener.
void setListener(ASTReaderListener *listener) {
Listener.reset(listener);
@@ -829,6 +841,13 @@
ModuleMgr.addInMemoryBuffer(FileName, Buffer);
}
+ /// \brief Finalizes the AST reader's state before writing an AST file to
+ /// disk.
+ ///
+ /// This operation may undo temporary state in the AST that should not be
+ /// emitted.
+ void finalizeForWriting();
+
/// \brief Retrieve the module manager.
ModuleManager &getModuleManager() { return ModuleMgr; }
Modified: cfe/trunk/lib/Serialization/ASTReader.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Serialization/ASTReader.cpp?rev=145640&r1=145639&r2=145640&view=diff
==============================================================================
--- cfe/trunk/lib/Serialization/ASTReader.cpp (original)
+++ cfe/trunk/lib/Serialization/ASTReader.cpp Thu Dec 1 16:20:10 2011
@@ -2439,6 +2439,11 @@
return Success;
}
+void ASTReader::makeNamesVisible(const HiddenNames &Names) {
+ for (unsigned I = 0, N = Names.size(); I != N; ++I)
+ Names[I]->ModulePrivate = false;
+}
+
void ASTReader::makeModuleVisible(Module *Mod,
Module::NameVisibilityKind NameVisibility) {
llvm::SmallPtrSet<Module *, 4> Visited;
@@ -2457,8 +2462,13 @@
// Update the module's name visibility.
Mod->NameVisibility = NameVisibility;
- // FIXME: If we've already deserialized any names from this module,
+ // If we've already deserialized any names from this module,
// mark them as visible.
+ HiddenNamesMapType::iterator Hidden = HiddenNamesMap.find(Mod);
+ if (Hidden != HiddenNamesMap.end()) {
+ makeNamesVisible(Hidden->second);
+ HiddenNamesMap.erase(Hidden);
+ }
// Push any non-explicit submodules onto the stack to be marked as
// visible.
@@ -2776,6 +2786,15 @@
}
}
+void ASTReader::finalizeForWriting() {
+ for (HiddenNamesMapType::iterator Hidden = HiddenNamesMap.begin(),
+ HiddenEnd = HiddenNamesMap.end();
+ Hidden != HiddenEnd; ++Hidden) {
+ makeNamesVisible(Hidden->second);
+ }
+ HiddenNamesMap.clear();
+}
+
/// \brief Retrieve the name of the original source file name
/// directly from the AST file, without actually loading the AST
/// file.
Modified: cfe/trunk/lib/Serialization/ASTReaderDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Serialization/ASTReaderDecl.cpp?rev=145640&r1=145639&r2=145640&view=diff
==============================================================================
--- cfe/trunk/lib/Serialization/ASTReaderDecl.cpp (original)
+++ cfe/trunk/lib/Serialization/ASTReaderDecl.cpp Thu Dec 1 16:20:10 2011
@@ -86,6 +86,14 @@
Reader.ReadDeclarationNameInfo(F, NameInfo, R, I);
}
+ serialization::SubmoduleID readSubmoduleID(const RecordData &R,
+ unsigned &I) {
+ if (I >= R.size())
+ return 0;
+
+ return Reader.getGlobalSubmoduleID(F, R[I++]);
+ }
+
void ReadCXXDefinitionData(struct CXXRecordDecl::DefinitionData &Data,
const RecordData &R, unsigned &I);
@@ -253,10 +261,25 @@
D->setAccess((AccessSpecifier)Record[Idx++]);
D->FromASTFile = true;
D->ModulePrivate = Record[Idx++];
-
- unsigned SubmoduleID = Record[Idx++];
- // FIXME: Actual use the submodule ID to determine visibility.
- (void)SubmoduleID;
+
+ // Determine whether this declaration is part of a (sub)module. If so, it
+ // may not yet be visible.
+ if (unsigned SubmoduleID = readSubmoduleID(Record, Idx)) {
+ // Module-private declarations are never visible, so there is no work to do.
+ if (!D->ModulePrivate) {
+ if (Module *Owner = Reader.getSubmodule(SubmoduleID)) {
+ if (Owner->NameVisibility != Module::AllVisible) {
+ // The owning module is not visible. Mark this declaration as
+ // module-private,
+ D->ModulePrivate = true;
+
+ // Note that this declaration was hidden because its owning module is
+ // not yet visible.
+ Reader.HiddenNamesMap[Owner].push_back(D);
+ }
+ }
+ }
+ }
}
void ASTDeclReader::VisitTranslationUnitDecl(TranslationUnitDecl *TU) {
Modified: cfe/trunk/lib/Serialization/ASTWriter.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Serialization/ASTWriter.cpp?rev=145640&r1=145639&r2=145640&view=diff
==============================================================================
--- cfe/trunk/lib/Serialization/ASTWriter.cpp (original)
+++ cfe/trunk/lib/Serialization/ASTWriter.cpp Thu Dec 1 16:20:10 2011
@@ -2958,6 +2958,10 @@
Module *WritingModule) {
using namespace llvm;
+ // Make sure that the AST reader knows to finalize itself.
+ if (Chain)
+ Chain->finalizeForWriting();
+
ASTContext &Context = SemaRef.Context;
Preprocessor &PP = SemaRef.PP;
Added: cfe/trunk/test/Modules/Inputs/submodules/hash_map.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/Inputs/submodules/hash_map.h?rev=145640&view=auto
==============================================================================
--- cfe/trunk/test/Modules/Inputs/submodules/hash_map.h (added)
+++ cfe/trunk/test/Modules/Inputs/submodules/hash_map.h Thu Dec 1 16:20:10 2011
@@ -0,0 +1 @@
+template<typename Key, typename Data> class hash_map { };
Modified: cfe/trunk/test/Modules/Inputs/submodules/module.map
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/Inputs/submodules/module.map?rev=145640&r1=145639&r2=145640&view=diff
==============================================================================
--- cfe/trunk/test/Modules/Inputs/submodules/module.map (original)
+++ cfe/trunk/test/Modules/Inputs/submodules/module.map Thu Dec 1 16:20:10 2011
@@ -1,4 +1,5 @@
module std {
module vector { header "vector.h" }
module type_traits { header "type_traits.h" }
+ explicit module hash_map { header "hash_map.h" }
}
Modified: cfe/trunk/test/Modules/Inputs/submodules/vector.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/Inputs/submodules/vector.h?rev=145640&r1=145639&r2=145640&view=diff
==============================================================================
--- cfe/trunk/test/Modules/Inputs/submodules/vector.h (original)
+++ cfe/trunk/test/Modules/Inputs/submodules/vector.h Thu Dec 1 16:20:10 2011
@@ -1 +1 @@
-template<typename T> class vector;
+template<typename T> class vector { };
Modified: cfe/trunk/test/Modules/auto-module-import.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/auto-module-import.c?rev=145640&r1=145639&r2=145640&view=diff
==============================================================================
--- cfe/trunk/test/Modules/auto-module-import.c (original)
+++ cfe/trunk/test/Modules/auto-module-import.c Thu Dec 1 16:20:10 2011
@@ -11,3 +11,4 @@
#ifdef DEPENDS_ON_MODULE
# error DEPENDS_ON_MODULE should have been hidden
#endif
+
Modified: cfe/trunk/test/Modules/diamond.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/diamond.c?rev=145640&r1=145639&r2=145640&view=diff
==============================================================================
--- cfe/trunk/test/Modules/diamond.c (original)
+++ cfe/trunk/test/Modules/diamond.c Thu Dec 1 16:20:10 2011
@@ -5,6 +5,12 @@
__import_module__ diamond_bottom;
+// FIXME: We want 'bottom' to re-export left and right, and both of those to
+// re-export 'top'.
+__import_module__ diamond_top;
+__import_module__ diamond_left;
+__import_module__ diamond_right;
+
void test_diamond(int i, float f, double d, char c) {
top(&i);
left(&f);
Added: cfe/trunk/test/Modules/submodules-preprocess.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/submodules-preprocess.cpp?rev=145640&view=auto
==============================================================================
--- cfe/trunk/test/Modules/submodules-preprocess.cpp (added)
+++ cfe/trunk/test/Modules/submodules-preprocess.cpp Thu Dec 1 16:20:10 2011
@@ -0,0 +1,14 @@
+// RUN: rm -rf %t
+// RUN: %clang_cc1 -Eonly -fmodule-cache-path %t -fauto-module-import -I %S/Inputs/submodules %s -verify
+
+__import_module__ std.vector;
+
+vector<int> vi;
+remove_reference<int&>::type *int_ptr = 0;
+
+__import_module__ std.typetraits; // expected-error{{no submodule named 'typetraits' in module 'std'; did you mean 'type_traits'?}}
+
+vector<float> vf;
+remove_reference<int&>::type *int_ptr2 = 0;
+
+__import_module__ std.vector.compare; // expected-error{{no submodule named 'compare' in module 'std.vector'}}
Modified: cfe/trunk/test/Modules/submodules.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/submodules.cpp?rev=145640&r1=145639&r2=145640&view=diff
==============================================================================
--- cfe/trunk/test/Modules/submodules.cpp (original)
+++ cfe/trunk/test/Modules/submodules.cpp Thu Dec 1 16:20:10 2011
@@ -1,7 +1,28 @@
// RUN: rm -rf %t
-// RUN: %clang_cc1 -Eonly -fmodule-cache-path %t -fauto-module-import -I %S/Inputs/submodules %s -verify
// RUN: %clang_cc1 -fmodule-cache-path %t -fauto-module-import -I %S/Inputs/submodules %s -verify
__import_module__ std.vector;
+
+vector<int> vi;
+
+// Note: remove_reference is not visible yet.
+remove_reference<int&>::type *int_ptr = 0; // expected-error{{unknown type name 'remove_reference'}} \
+// expected-error{{expected unqualified-id}}
+
__import_module__ std.typetraits; // expected-error{{no submodule named 'typetraits' in module 'std'; did you mean 'type_traits'?}}
+
+vector<float> vf;
+remove_reference<int&>::type *int_ptr2 = 0;
+
__import_module__ std.vector.compare; // expected-error{{no submodule named 'compare' in module 'std.vector'}}
+
+__import_module__ std; // import everything in 'std'
+
+// hash_map still isn't available.
+hash_map<int, float> ints_to_floats; // expected-error{{unknown type name 'hash_map'}} \
+// expected-error{{expected unqualified-id}}
+
+__import_module__ std.hash_map;
+
+hash_map<int, float> ints_to_floats2;
+
More information about the cfe-commits
mailing list