-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
700365d
commit d854e41
Showing
7 changed files
with
92 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,68 @@ | ||
pub use self::ty::*; | ||
|
||
use memmap2::Mmap; | ||
use object::read::archive::ArchiveFile; | ||
use std::collections::HashMap; | ||
use std::fs::File; | ||
use std::path::Path; | ||
use thiserror::Error; | ||
|
||
mod ty; | ||
|
||
/// Contains C++ metadata loaded from a static library. | ||
pub struct Metadata {} | ||
pub struct Metadata { | ||
types: HashMap<String, TypeInfo>, | ||
} | ||
|
||
impl Metadata { | ||
pub fn from_static_lib(path: impl AsRef<Path>) -> Result<Self, MetadataError> { | ||
Ok(Self {}) | ||
// Open file. | ||
let file = File::open(path).map_err(MetadataError::OpenFileFailed)?; | ||
let file = unsafe { Mmap::map(&file).map_err(MetadataError::MapFileFailed) }?; | ||
let file = ArchiveFile::parse(file.as_ref()).map_err(MetadataError::ParseFileFailed)?; | ||
|
||
// Get symbols. | ||
let symbols = file.symbols().map_err(MetadataError::GetSymbolsFailed)?; | ||
let mut types = HashMap::new(); | ||
let symbols = match symbols { | ||
Some(v) => v, | ||
None => return Ok(Self { types }), | ||
}; | ||
|
||
// Parse symbols. | ||
for sym in symbols { | ||
let sym = sym.map_err(MetadataError::ReadSymbolFailed)?; | ||
let sym = match std::str::from_utf8(sym.name()) { | ||
Ok(v) => v, | ||
Err(_) => continue, // Ignore unknown symbol. | ||
}; | ||
|
||
types.insert(sym.to_owned(), TypeInfo::new()); | ||
} | ||
|
||
Ok(Self { types }) | ||
} | ||
|
||
pub fn get_type(&self, name: impl AsRef<str>) -> Option<&TypeInfo> { | ||
self.types.get(name.as_ref()) | ||
} | ||
} | ||
|
||
/// Represents an error when [`Metadata`] fails to load. | ||
#[derive(Debug, Error)] | ||
pub enum MetadataError {} | ||
pub enum MetadataError { | ||
#[error("couldn't open the specified file")] | ||
OpenFileFailed(#[source] std::io::Error), | ||
|
||
#[error("couldn't map the specified file")] | ||
MapFileFailed(#[source] std::io::Error), | ||
|
||
#[error("couldn't parse the specified file")] | ||
ParseFileFailed(#[source] object::read::Error), | ||
|
||
#[error("couldn't get available symbols")] | ||
GetSymbolsFailed(#[source] object::read::Error), | ||
|
||
#[error("couldn't read a symbol")] | ||
ReadSymbolFailed(#[source] object::read::Error), | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
/// Contains information for a C++ class. | ||
pub struct TypeInfo {} | ||
|
||
impl TypeInfo { | ||
pub(super) fn new() -> Self { | ||
Self {} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
use thiserror::Error; | ||
|
||
/// C++ symbol. | ||
pub struct Symbol {} | ||
|
||
impl Symbol { | ||
pub fn parse(mangled: impl AsRef<[u8]>) -> Result<Self, SymbolError> { | ||
Ok(Self {}) | ||
} | ||
} | ||
|
||
/// Represents an error when [`Symbol`] fails to parse from a mangled name. | ||
#[derive(Debug, Error)] | ||
pub enum SymbolError {} |