Skip to content

Commit

Permalink
Minor refactoring following #2544 (#2546)
Browse files Browse the repository at this point in the history
  • Loading branch information
kennykerr authored Jun 20, 2023
1 parent 9fbbdab commit bbff6da
Show file tree
Hide file tree
Showing 108 changed files with 165 additions and 166 deletions.
8 changes: 4 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
.vscode
.vs
target
temp
/.vscode
/.vs
/target
/temp
*.lock
*.winmd
2 changes: 2 additions & 0 deletions crates/libs/metadata/src/attributes.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#![allow(non_upper_case_globals)]

macro_rules! flags {
($name:ident, $size:ty) => {
#[derive(Default, Copy, Clone, PartialEq, Eq, Debug)]
Expand Down
2 changes: 1 addition & 1 deletion crates/libs/metadata/src/codes.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use super::*;

pub trait Decode {
pub(crate) trait Decode {
fn decode(file: usize, code: usize) -> Self;
}

Expand Down
56 changes: 28 additions & 28 deletions crates/libs/metadata/src/file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,37 +10,37 @@ pub struct File {
}

#[derive(Default)]
pub struct Table {
pub offset: usize,
pub(crate) struct Table {
offset: usize,
pub len: usize,
pub width: usize,
pub columns: [Column; 6],
width: usize,
columns: [Column; 6],
}

#[derive(Default)]
pub struct Column {
struct Column {
pub offset: usize,
pub width: usize,
}

pub const TABLE_CONSTANT: usize = 0;
pub const TABLE_CUSTOMATTRIBUTE: usize = 1;
pub const TABLE_FIELD: usize = 2;
pub const TABLE_GENERICPARAM: usize = 3;
pub const TABLE_INTERFACEIMPL: usize = 4;
pub const TABLE_MEMBERREF: usize = 5;
pub const TABLE_METHODDEF: usize = 6;
pub const TABLE_PARAM: usize = 7;
pub const TABLE_TYPEDEF: usize = 8;
pub const TABLE_TYPEREF: usize = 9;
pub const TABLE_TYPESPEC: usize = 10;
pub const TABLE_IMPLMAP: usize = 11;
pub const TABLE_MODULEREF: usize = 12;
pub const TABLE_NESTEDCLASS: usize = 13;
pub const TABLE_MODULE: usize = 14;
pub const TABLE_ASSEMBLYREF: usize = 15;
pub const TABLE_CLASSLAYOUT: usize = 16;
pub const TABLE_LEN: usize = 17;
pub(crate) const TABLE_CONSTANT: usize = 0;
pub(crate) const TABLE_CUSTOMATTRIBUTE: usize = 1;
pub(crate) const TABLE_FIELD: usize = 2;
pub(crate) const TABLE_GENERICPARAM: usize = 3;
pub(crate) const TABLE_INTERFACEIMPL: usize = 4;
pub(crate) const TABLE_MEMBERREF: usize = 5;
pub(crate) const TABLE_METHODDEF: usize = 6;
pub(crate) const TABLE_PARAM: usize = 7;
pub(crate) const TABLE_TYPEDEF: usize = 8;
pub(crate) const TABLE_TYPEREF: usize = 9;
pub(crate) const TABLE_TYPESPEC: usize = 10;
pub(crate) const TABLE_IMPLMAP: usize = 11;
pub(crate) const TABLE_MODULEREF: usize = 12;
pub(crate) const TABLE_NESTEDCLASS: usize = 13;
pub(crate) const TABLE_MODULE: usize = 14;
pub(crate) const TABLE_ASSEMBLYREF: usize = 15;
pub(crate) const TABLE_CLASSLAYOUT: usize = 16;
pub(crate) const TABLE_LEN: usize = 17;

type Result<T> = std::result::Result<T, ()>;

Expand Down Expand Up @@ -310,7 +310,7 @@ impl File {
Ok(result)
}

pub fn usize(&self, row: usize, table: usize, column: usize) -> usize {
pub(crate) fn usize(&self, row: usize, table: usize, column: usize) -> usize {
let table = &self.tables[table];
let column = &table.columns[column];
let offset = table.offset + row * table.width + column.offset;
Expand All @@ -331,15 +331,15 @@ impl File {
/// * When the offset in the string table is out of bounds.
/// * When no null terminator can be found in the string table.
/// * When the null-terminated string is not valid utf-8.
pub fn str(&self, row: usize, table: usize, column: usize) -> &str {
pub(crate) fn str(&self, row: usize, table: usize, column: usize) -> &str {
let offset = self.strings + self.usize(row, table, column);

let bytes = &self.bytes[offset..];
let nul_pos = bytes.iter().position(|&c| c == 0).expect("expected null-terminated C-string");
std::str::from_utf8(&bytes[..nul_pos]).expect("expected valid utf-8 C-string")
}

pub fn blob(&self, row: usize, table: usize, column: usize) -> &[u8] {
pub(crate) fn blob(&self, row: usize, table: usize, column: usize) -> &[u8] {
let offset = self.blobs + self.usize(row, table, column);
let initial_byte = self.bytes[offset];
let (blob_size, blob_size_bytes) = match initial_byte >> 5 {
Expand All @@ -356,7 +356,7 @@ impl File {
&self.bytes[offset..offset + blob_size]
}

pub fn equal_range(&self, table: usize, column: usize, value: usize) -> (usize, usize) {
pub(crate) fn equal_range(&self, table: usize, column: usize, value: usize) -> (usize, usize) {
let mut first = 0;
let mut last = self.tables[table].len;
let mut count = last;
Expand Down Expand Up @@ -401,7 +401,7 @@ impl File {
first
}

pub fn upper_bound_of(&self, table: usize, mut first: usize, last: usize, column: usize, value: usize) -> usize {
fn upper_bound_of(&self, table: usize, mut first: usize, last: usize, column: usize, value: usize) -> usize {
let mut count = last - first;
while count > 0 {
let count2 = count / 2;
Expand Down
25 changes: 15 additions & 10 deletions crates/libs/metadata/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#![allow(non_upper_case_globals)]

#[doc(hidden)]
pub mod imp;

Expand All @@ -14,22 +12,21 @@ mod r#type;
mod type_name;

pub use attributes::*;
pub use blob::*;
pub use blob::Blob;
pub use codes::*;
pub use file::*;
pub use filter::*;
pub use guid::*;
pub use r#type::*;
pub use row::*;
pub use type_name::*;

pub use filter::Filter;
pub use guid::GUID;
use imp::*;
pub use r#type::Type;
use row::Row;
use std::collections::*;
pub use type_name::TypeName;

macro_rules! tables {
($($name:ident,)*) => ($(
#[derive(Copy, Clone, PartialEq, PartialOrd, Eq, Ord, Hash, Debug)]
pub struct $name(pub Row);
pub struct $name(Row);
)*)
}

Expand Down Expand Up @@ -1906,6 +1903,14 @@ impl<'a> Reader<'a> {
}
}

fn trim_tick(name: &str) -> &str {
if name.as_bytes().iter().rev().nth(1) == Some(&b'`') {
&name[..name.len() - 2]
} else {
name
}
}

pub const REMAP_TYPES: [(TypeName, TypeName); 2] = [(TypeName::D2D_MATRIX_3X2_F, TypeName::Matrix3x2), (TypeName::D3DMATRIX, TypeName::Matrix4x4)];

pub const CORE_TYPES: [(TypeName, Type); 11] = [(TypeName::GUID, Type::GUID), (TypeName::IUnknown, Type::IUnknown), (TypeName::HResult, Type::HRESULT), (TypeName::HRESULT, Type::HRESULT), (TypeName::HSTRING, Type::String), (TypeName::BSTR, Type::BSTR), (TypeName::IInspectable, Type::IInspectable), (TypeName::PSTR, Type::PSTR), (TypeName::PWSTR, Type::PWSTR), (TypeName::Type, Type::TypeName), (TypeName::CHAR, Type::U8)];
12 changes: 3 additions & 9 deletions crates/libs/metadata/src/type_name.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#![allow(non_upper_case_globals)]

#[derive(Copy, Clone, PartialEq, PartialOrd, Eq, Ord)]
pub struct TypeName<'a> {
pub namespace: &'a str,
Expand Down Expand Up @@ -51,7 +53,7 @@ impl<'a> TypeName<'a> {
}

pub fn new(namespace: &'a str, name: &'a str) -> Self {
Self { namespace, name: trim_tick(name) }
Self { namespace, name: crate::trim_tick(name) }
}

pub fn parse(full_name: &'a str) -> Self {
Expand All @@ -65,11 +67,3 @@ impl<'a> std::fmt::Display for TypeName<'a> {
write!(fmt, "{}.{}", self.namespace, self.name)
}
}

pub fn trim_tick(name: &str) -> &str {
if name.as_bytes().iter().rev().nth(1) == Some(&b'`') {
&name[..name.len() - 2]
} else {
name
}
}
1 change: 1 addition & 0 deletions crates/samples/windows-sys/counter/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
name = "sample_counter_sys"
version = "0.0.0"
edition = "2018"
publish = false

[dependencies.windows-sys]
path = "../../../libs/sys"
Expand Down
1 change: 1 addition & 0 deletions crates/samples/windows-sys/create_window/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
name = "sample_create_window_sys"
version = "0.0.0"
edition = "2018"
publish = false

[dependencies.windows-sys]
path = "../../../libs/sys"
Expand Down
1 change: 1 addition & 0 deletions crates/samples/windows-sys/enum_windows/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
name = "sample_enum_windows_sys"
version = "0.0.0"
edition = "2018"
publish = false

[dependencies.windows-sys]
path = "../../../libs/sys"
Expand Down
1 change: 1 addition & 0 deletions crates/samples/windows-sys/message_box/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
name = "sample_message_box_sys"
version = "0.0.0"
edition = "2018"
publish = false

[dependencies.windows-sys]
path = "../../../libs/sys"
Expand Down
1 change: 1 addition & 0 deletions crates/samples/windows-sys/privileges/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
name = "sample_privileges_sys"
version = "0.0.0"
edition = "2018"
publish = false

[dependencies.windows-sys]
path = "../../../libs/sys"
Expand Down
1 change: 1 addition & 0 deletions crates/samples/windows-sys/thread_pool_work/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
name = "sample_thread_pool_work_sys"
version = "0.0.0"
edition = "2018"
publish = false

[dependencies.windows-sys]
path = "../../../libs/sys"
Expand Down
1 change: 1 addition & 0 deletions crates/samples/windows/bits/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
name = "sample_bits"
version = "0.0.0"
edition = "2018"
publish = false

[dependencies.windows]
path = "../../../libs/windows"
Expand Down
1 change: 1 addition & 0 deletions crates/samples/windows/com_uri/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
name = "sample_com_uri"
version = "0.0.0"
edition = "2018"
publish = false

[dependencies.windows]
path = "../../../libs/windows"
Expand Down
1 change: 1 addition & 0 deletions crates/samples/windows/consent/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
name = "sample_consent"
version = "0.0.0"
edition = "2018"
publish = false

[dependencies.windows]
path = "../../../libs/windows"
Expand Down
1 change: 1 addition & 0 deletions crates/samples/windows/core_app/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
name = "sample_core_app"
version = "0.0.0"
edition = "2018"
publish = false

[dependencies.windows]
path = "../../../libs/windows"
Expand Down
1 change: 1 addition & 0 deletions crates/samples/windows/counter/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
name = "sample_counter"
version = "0.0.0"
edition = "2018"
publish = false

[dependencies.windows]
path = "../../../libs/windows"
Expand Down
1 change: 1 addition & 0 deletions crates/samples/windows/create_window/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
name = "sample_create_window"
version = "0.0.0"
edition = "2018"
publish = false

[dependencies.windows]
path = "../../../libs/windows"
Expand Down
1 change: 1 addition & 0 deletions crates/samples/windows/data_protection/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
name = "sample_data_protection"
version = "0.0.0"
edition = "2018"
publish = false

[dependencies.windows]
path = "../../../libs/windows"
Expand Down
1 change: 1 addition & 0 deletions crates/samples/windows/dcomp/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
name = "sample_dcomp"
version = "0.0.0"
edition = "2018"
publish = false

[dependencies]
rand = "0.8.5"
Expand Down
1 change: 1 addition & 0 deletions crates/samples/windows/device_watcher/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
name = "sample_device_watcher"
version = "0.0.0"
edition = "2018"
publish = false

[dependencies.windows]
path = "../../../libs/windows"
Expand Down
1 change: 1 addition & 0 deletions crates/samples/windows/direct2d/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
name = "sample_direct2d"
version = "0.0.0"
edition = "2018"
publish = false

[dependencies.windows]
path = "../../../libs/windows"
Expand Down
1 change: 1 addition & 0 deletions crates/samples/windows/direct3d12/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
name = "sample_direct3d12"
version = "0.0.0"
edition = "2018"
publish = false

[dependencies]
array-init = "2.0.0"
Expand Down
1 change: 1 addition & 0 deletions crates/samples/windows/enum_windows/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
name = "sample_enum_windows"
version = "0.0.0"
edition = "2018"
publish = false

[dependencies.windows]
path = "../../../libs/windows"
Expand Down
1 change: 1 addition & 0 deletions crates/samples/windows/kernel_event/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
name = "sample_kernel_event"
version = "0.0.0"
edition = "2018"
publish = false

[dependencies.windows]
path = "../../../libs/windows"
Expand Down
1 change: 1 addition & 0 deletions crates/samples/windows/memory_buffer/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
name = "sample_memory_buffer"
version = "0.0.0"
edition = "2018"
publish = false

[dependencies.windows]
path = "../../../libs/windows"
Expand Down
1 change: 1 addition & 0 deletions crates/samples/windows/message_box/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
name = "sample_message_box"
version = "0.0.0"
edition = "2018"
publish = false

[dependencies.windows]
path = "../../../libs/windows"
Expand Down
1 change: 1 addition & 0 deletions crates/samples/windows/ocr/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
name = "sample_ocr"
version = "0.0.0"
edition = "2018"
publish = false

[dependencies]
futures = "0.3.5"
Expand Down
1 change: 1 addition & 0 deletions crates/samples/windows/overlapped/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
name = "sample_overlapped"
version = "0.0.0"
edition = "2018"
publish = false

[dependencies.windows]
path = "../../../libs/windows"
Expand Down
Loading

0 comments on commit bbff6da

Please sign in to comment.