pub struct ForeignModules {
pub modules: IdVec<ModuleId, ForeignModule>,
pub links: IdVec<PdId, Vec<Link>>,
pub ffis: IdVec<FfnId, ForeignFnRef>,
/* private fields */
}Expand description
The foreign files a project has loaded, one ForeignModule per
distinct file — the loaded-modules store, not part of the AST.
An import is an AST item of the program that writes it
(Import); what the imported file contains is
shared by every program that imports it, so it lives here, beside the
RawAst rather than inside it — the split
every compiler that reads foreign declarations makes (rustc’s CStore
beside ast::Crate, Swift’s ASTContext loaded modules beside the
SourceFiles, GHC’s HscEnv). Built by the driver after all programs
are parsed, each file numbered by its ModuleId. rast resolves a
call through an import’s alias to a function of that file and records
where each called function is, by its FfnId (ffis); the backends
read the files, the called functions and each program’s links here.
A file’s identity is its normalised project-relative path — canonicalised
(so c/util.h, ./c/util.h, c/../c/util.h and, on a
case-insensitive filesystem, C/Util.h are one file) and then made
relative to the project directory again, so keys carry no machine-
specific prefix; a file outside the project keeps its canonical absolute
path.
Fields§
§modules: IdVec<ModuleId, ForeignModule>Each file, once, numbered in the order it was first read.
links: IdVec<PdId, Vec<Link>>Each program’s imported files, by its protection domain, in import order: what its image links.
ffis: IdVec<FfnId, ForeignFnRef>Where each function some program calls is, by the id rast gave
it.
Implementations§
Source§impl ForeignModules
impl ForeignModules
Sourcepub fn insert(&mut self, module: ForeignModule) -> ModuleId
pub fn insert(&mut self, module: ForeignModule) -> ModuleId
Add a loaded module under its (normalised) path, which also names it as written; returns its id. A second module for the same path is ignored, and the first one’s id returned.
Sourcepub fn record(&mut self, written: PathBuf, id: ModuleId)
pub fn record(&mut self, written: PathBuf, id: ModuleId)
Record that an import written as written names the file id.
Sourcepub fn module(&self, written: &Path) -> Option<ModuleId>
pub fn module(&self, written: &Path) -> Option<ModuleId>
The file an import written as written, or a file’s identity, names,
once it has been loaded.
Sourcepub fn bind(&mut self, rawast: &RawAst)
pub fn bind(&mut self, rawast: &RawAst)
Record each program’s imported files, by its position among
rawast’s programs (its protection domain’s id once bound), each
as its first import of the file writes it; an import whose file was
not loaded is left out.
Sourcepub fn function(&self, f: FfnId) -> (&ForeignModule, &ForeignFn)
pub fn function(&self, f: FfnId) -> (&ForeignModule, &ForeignFn)
The called function f: its file, and its declaration there.
Trait Implementations§
Source§impl Clone for ForeignModules
impl Clone for ForeignModules
Source§fn clone(&self) -> ForeignModules
fn clone(&self) -> ForeignModules
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more