mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
This is basically the same as doing a :print_decl on every decl in the module, except that it does not print extensions that come from other modules, and /does/ print extensions and operators that come from this module. Does not yet work for Clang modules or the Builtin module. Swift SVN r7601
158 lines
5.8 KiB
C++
158 lines
5.8 KiB
C++
//===--- ModuleLoader.h - Module Loader Interface ----------- -*- C++ -*- -===//
|
|
//
|
|
// This source file is part of the Swift.org open source project
|
|
//
|
|
// Copyright (c) 2014 - 2015 Apple Inc. and the Swift project authors
|
|
// Licensed under Apache License v2.0 with Runtime Library Exception
|
|
//
|
|
// See http://swift.org/LICENSE.txt for license information
|
|
// See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
//
|
|
// This file implements an abstract interface for loading modules.
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
#ifndef SWIFT_AST_MODULE_LOADER_H
|
|
#define SWIFT_AST_MODULE_LOADER_H
|
|
|
|
#include "swift/AST/Identifier.h"
|
|
#include "swift/AST/Module.h"
|
|
#include "swift/AST/Type.h"
|
|
#include "swift/Basic/LLVM.h"
|
|
#include "swift/Basic/SourceLoc.h"
|
|
#include "llvm/ADT/IntrusiveRefCntPtr.h"
|
|
namespace swift {
|
|
|
|
class Module;
|
|
class NominalTypeDecl;
|
|
|
|
enum class KnownProtocolKind : uint8_t;
|
|
|
|
/// \brief Abstract interface that loads named modules into the AST.
|
|
class ModuleLoader : public llvm::RefCountedBaseVPTR {
|
|
public:
|
|
virtual ~ModuleLoader();
|
|
|
|
/// \brief Import a module with the given module path.
|
|
///
|
|
/// \param importLoc The location of the 'import' keyword.
|
|
///
|
|
/// \param path A sequence of (identifier, location) pairs that denote
|
|
/// the dotted module name to load, e.g., AppKit.NSWindow.
|
|
///
|
|
/// \returns the module referenced, if it could be loaded. Otherwise,
|
|
/// emits a diagnostic and returns NULL.
|
|
virtual
|
|
Module *loadModule(SourceLoc importLoc,
|
|
ArrayRef<std::pair<Identifier, SourceLoc>> path) = 0;
|
|
|
|
/// \brief Look for declarations associated with the given name.
|
|
///
|
|
/// \param module The module to search.
|
|
///
|
|
/// \param accessPath The access path used to refer to the name within this
|
|
/// (top-level) module.
|
|
///
|
|
/// \param name The name we're searching for.
|
|
///
|
|
/// \param lookupKind Whether we're performing qualified vs. unqualified
|
|
/// lookup.
|
|
///
|
|
/// \param result Will be populated with the results of name lookup.
|
|
virtual void lookupValue(Module *module,
|
|
Module::AccessPathTy accessPath, Identifier name,
|
|
NLKind lookupKind,
|
|
SmallVectorImpl<ValueDecl*> &result) { }
|
|
|
|
/// \brief Load extensions to the given nominal type.
|
|
///
|
|
/// \param nominal The nominal type whose extensions should be loaded.
|
|
///
|
|
/// \param previousGeneration The previous generation number. The AST already
|
|
/// contains extensions loaded from any generation up to and including this
|
|
/// one.
|
|
virtual void loadExtensions(NominalTypeDecl *nominal,
|
|
unsigned previousGeneration) { };
|
|
|
|
/// \brief Load decls that provide conformances to the given compiler-known
|
|
/// protocol.
|
|
///
|
|
/// \param kind The known protocol whose decls should be loaded.
|
|
///
|
|
/// \param previousGeneration The previous generation number. The AST already
|
|
/// contains decls conforming to this protocol loaded from any generation up
|
|
/// to and including this one.
|
|
virtual void loadDeclsConformingTo(KnownProtocolKind kind,
|
|
unsigned previousGeneration) { };
|
|
|
|
/// \brief Look for members of the given type.
|
|
///
|
|
/// \param module The module to search.
|
|
///
|
|
/// \param base The type into which we will look to find members.
|
|
///
|
|
/// \param name The name of the members we are looking for.
|
|
///
|
|
/// \param result Will be populated with the results of name lookup.
|
|
virtual void lookupMembers(Module *module, Type base, Identifier name,
|
|
SmallVectorImpl<ValueDecl*> &result) { }
|
|
|
|
/// \brief Look for a declaration of the given operator.
|
|
///
|
|
/// \returns The operator decl, or null if this module does not define the
|
|
/// operator in question.
|
|
virtual OperatorDecl *lookupOperator(Module *module, Identifier name,
|
|
DeclKind fixity) {
|
|
return nullptr;
|
|
}
|
|
|
|
/// \brief Look for modules imported by the given module.
|
|
///
|
|
/// Unless \p includePrivate is true, only re-exported modules are included.
|
|
virtual void
|
|
getImportedModules(const Module *module,
|
|
SmallVectorImpl<Module::ImportedModule> &exports,
|
|
bool includePrivate) { }
|
|
|
|
/// \brief Look for all visible top-level decls in the module.
|
|
virtual void lookupVisibleDecls(const Module *module,
|
|
Module::AccessPathTy accessPath,
|
|
VisibleDeclConsumer &consumer,
|
|
NLKind lookupKind) { }
|
|
|
|
/// \brief Look for all class members.
|
|
///
|
|
/// This is used for id-style lookup.
|
|
virtual void lookupClassMembers(const Module *module,
|
|
Module::AccessPathTy accessPath,
|
|
VisibleDeclConsumer &consumer) { }
|
|
|
|
/// \brief Look for class members with the given name.
|
|
///
|
|
/// Any decls found will be stored in \p results.
|
|
///
|
|
/// This is used for id-style lookup.
|
|
virtual void lookupClassMember(const Module *module,
|
|
Module::AccessPathTy accessPath,
|
|
Identifier name,
|
|
SmallVectorImpl<ValueDecl*> &results) { }
|
|
|
|
/// \brief Find all libraries and frameworks that need to be linked with this
|
|
/// module.
|
|
///
|
|
/// Does not include dependencies.
|
|
virtual void getLinkLibraries(const Module *module,
|
|
Module::LinkLibraryCallback callback) { }
|
|
|
|
/// \brief Look for all top-level decls that should be displayed to a client
|
|
/// of the module.
|
|
virtual void getDisplayDecls(const Module *module,
|
|
SmallVectorImpl<Decl*> &results) { }
|
|
};
|
|
|
|
}
|
|
|
|
|
|
#endif
|