mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
[serialization] Hook up basic name lookup for imported modules.
Also, explicitly list the top-level decls in a module. Eventually this will be a proper lazily-loaded identifier-DeclID map, but for now it's just a flat list of IDs to deserialize as soon as a lookup is requested. We can now parse and typecheck a file that imports typealiases of builtin types. Swift SVN r5325
This commit is contained in:
@@ -14,10 +14,12 @@
|
||||
#define SWIFT_SERIALIZATION_MODULEFILE_H
|
||||
|
||||
#include "ModuleFormat.h"
|
||||
#include "swift/AST/Identifier.h"
|
||||
#include "swift/AST/Type.h"
|
||||
#include "swift/Basic/PointerIntUnion.h"
|
||||
#include "swift/Basic/LLVM.h"
|
||||
#include "llvm/ADT/ArrayRef.h"
|
||||
#include "llvm/ADT/DenseMap.h"
|
||||
#include "llvm/ADT/OwningPtr.h"
|
||||
#include "llvm/Bitcode/BitstreamReader.h"
|
||||
|
||||
@@ -30,6 +32,7 @@ namespace llvm {
|
||||
namespace swift {
|
||||
class Decl;
|
||||
class Module;
|
||||
class ValueDecl;
|
||||
|
||||
/// Describes whether a loaded module can be used.
|
||||
enum class ModuleStatus {
|
||||
@@ -68,12 +71,18 @@ class ModuleFile {
|
||||
SmallVector<StringRef, 4> SourcePaths;
|
||||
|
||||
/// Decls referenced by this module.
|
||||
std::vector<PointerIntUnion<const Decl *, serialization::BitOffset,
|
||||
uint64_t>> Decls;
|
||||
std::vector<PointerIntUnion<Decl*, serialization::BitOffset, uint64_t>> Decls;
|
||||
|
||||
/// Types referenced by this module.
|
||||
std::vector<PointerIntUnion<Type, serialization::BitOffset, uint64_t>> Types;
|
||||
|
||||
/// All top-level decls in this module.
|
||||
// FIXME: A single identifier may refer to multiple decls.
|
||||
llvm::DenseMap<Identifier, serialization::DeclID> TopLevelIDs;
|
||||
|
||||
/// FIXME: HACK: an array of the top-level decl IDs.
|
||||
std::vector<serialization::DeclID> RawTopLevelIDs;
|
||||
|
||||
/// Whether this module file can be used.
|
||||
ModuleStatus Status;
|
||||
|
||||
@@ -88,11 +97,14 @@ class ModuleFile {
|
||||
}
|
||||
|
||||
/// Returns the decl with the given ID, deserializing it if needed.
|
||||
const Decl *getDecl(serialization::DeclID DID);
|
||||
Decl *getDecl(serialization::DeclID DID);
|
||||
|
||||
/// Returns the type with the current ID, deserializing it if needed.
|
||||
Type getType(serialization::TypeID TID);
|
||||
|
||||
/// Populates TopLevelIDs for name lookup.
|
||||
void buildTopLevelDeclMap();
|
||||
|
||||
public:
|
||||
/// Loads a module from the given memory buffer.
|
||||
///
|
||||
@@ -112,10 +124,6 @@ public:
|
||||
void associateWithModule(Module *module) {
|
||||
assert(!ModuleContext && "already associated with an AST module");
|
||||
ModuleContext = module;
|
||||
|
||||
// Force all the decls for testing purposes.
|
||||
for (serialization::DeclID i = 1; i <= Decls.size(); ++i)
|
||||
assert(getDecl(i) != nullptr);
|
||||
}
|
||||
|
||||
/// Checks whether this module can be used.
|
||||
@@ -127,6 +135,9 @@ public:
|
||||
getStatus() == ModuleStatus::FallBackToTranslationUnit);
|
||||
return SourcePaths;
|
||||
}
|
||||
|
||||
/// Searches the module's top-level decls for the given identifier.
|
||||
void lookupValue(Identifier name, SmallVectorImpl<ValueDecl*> &results);
|
||||
};
|
||||
|
||||
} // end namespace swift
|
||||
|
||||
Reference in New Issue
Block a user