-
Notifications
You must be signed in to change notification settings - Fork 513
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Metadata generation of attributes and constants (#2844)
- Loading branch information
Showing
9 changed files
with
199 additions
and
111 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,5 @@ | ||
/.vscode | ||
/.vs | ||
/target | ||
/temp | ||
*.lock | ||
*.winmd |
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,71 +1,69 @@ | ||
#![allow(dead_code, clippy::enum_variant_names)] | ||
|
||
/// A `ResolutionScope` is an index into a certain table indicating the scope in which a TypeRef can be resolved. | ||
#[derive(Clone)] | ||
pub enum ResolutionScope { | ||
Module(u32), | ||
ModuleRef(u32), | ||
AssemblyRef(u32), | ||
TypeRef(u32), | ||
macro_rules! code { | ||
($name:ident($size:literal) $(($table:ident, $code:literal))+) => { | ||
#[derive(Clone, Copy)] | ||
pub enum $name { | ||
$($table(u32),)* | ||
} | ||
impl $name { | ||
pub fn encode(&self) -> u32 { | ||
match self { | ||
$(Self::$table(row) => (row.overflowing_add(1).0) << $size | $code,)* | ||
} | ||
} | ||
} | ||
}; | ||
} | ||
|
||
impl ResolutionScope { | ||
pub fn encode(&self) -> u32 { | ||
match self { | ||
Self::Module(row) => (row + 1) << 2, | ||
Self::ModuleRef(row) => ((row + 1) << 2) + 1, | ||
Self::AssemblyRef(row) => ((row + 1) << 2) + 2, | ||
Self::TypeRef(row) => ((row + 1) << 2) + 3, | ||
} | ||
} | ||
code! { AttributeType(3) | ||
(MemberRef, 3) | ||
} | ||
|
||
/// A `TypeDefOrRef` is an index into a certain table used to locate a type definition. | ||
#[derive(Clone)] | ||
pub enum TypeDefOrRef { | ||
TypeDef(u32), | ||
TypeRef(u32), | ||
TypeSpec(u32), | ||
// TODO: needs to be called HasCustomAttribute | ||
code! { HasAttribute(5) | ||
(MethodDef, 0) | ||
(Field, 1) | ||
(TypeRef, 2) | ||
(TypeDef, 3) | ||
(Param, 4) | ||
(InterfaceImpl, 5) | ||
(MemberRef, 6) | ||
(TypeSpec, 13) | ||
(GenericParam, 19) | ||
} | ||
|
||
impl TypeDefOrRef { | ||
pub fn encode(&self) -> u32 { | ||
match self { | ||
Self::TypeDef(row) => (row + 1) << 2, | ||
Self::TypeRef(row) => ((row + 1) << 2) + 1, | ||
Self::TypeSpec(row) => ((row + 1) << 2) + 2, | ||
} | ||
} | ||
code! { HasConstant(2) | ||
(Field, 0) | ||
} | ||
|
||
/// A `HasConstant` is an index into a certain table used to identify the parent of a row in the `Constant` table. | ||
#[derive(Clone, PartialEq, Eq, PartialOrd, Ord)] | ||
pub enum HasConstant { | ||
Field(u32), | ||
Param(u32), | ||
Property(u32), | ||
code! { MemberForwarded(1) | ||
(MethodDef, 1) | ||
} | ||
|
||
impl HasConstant { | ||
pub fn encode(&self) -> u32 { | ||
match self { | ||
Self::Field(row) => (row + 1) << 2, | ||
Self::Param(row) => ((row + 1) << 2) + 1, | ||
Self::Property(row) => ((row + 1) << 2) + 2, | ||
} | ||
} | ||
code! { MemberRefParent(3) | ||
(TypeRef, 1) | ||
} | ||
|
||
/// A `TypeOrMethodDef` is an index into a certain table used to locate the owner of a generic parameter. | ||
#[derive(Clone)] | ||
pub enum TypeOrMethodDef { | ||
TypeDef(u32), | ||
code! { TypeDefOrRef(2) | ||
(TypeDef, 0) | ||
(TypeRef, 1) | ||
(TypeSpec, 2) | ||
} | ||
|
||
impl TypeOrMethodDef { | ||
pub fn encode(&self) -> u32 { | ||
match self { | ||
Self::TypeDef(row) => (row + 1) << 1, | ||
} | ||
impl TypeDefOrRef { | ||
pub fn none() -> Self { | ||
TypeDefOrRef::TypeDef(u32::MAX) | ||
} | ||
} | ||
|
||
code! { TypeOrMethodDef(1) | ||
(TypeDef, 0) | ||
} | ||
|
||
code! { ResolutionScope(2) | ||
(Module, 0) | ||
(ModuleRef, 1) | ||
(AssemblyRef, 2) | ||
(TypeRef, 3) | ||
} |
Oops, something went wrong.