Skip to content

Commit 8e7ce3d

Browse files
authored
Partial code gen refactor (#841)
1 parent aaac5ca commit 8e7ce3d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+933
-1115
lines changed

crates/gen/src/async.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
use super::*;
1+
use crate::*;
22

33
pub fn gen_async(
4-
def: &GenericType,
4+
def: &tables::TypeDef,
55
interfaces: &[InterfaceInfo],
66
gen: &Gen,
77
) -> (TokenStream, TokenStream) {
@@ -31,12 +31,12 @@ pub enum AsyncKind {
3131
OperationWithProgress,
3232
}
3333

34-
pub fn async_kind(def: &GenericType) -> AsyncKind {
35-
if def.def.namespace() != "Windows.Foundation" {
34+
pub fn async_kind(def: &tables::TypeDef) -> AsyncKind {
35+
if def.namespace() != "Windows.Foundation" {
3636
return AsyncKind::None;
3737
}
3838

39-
match def.def.name() {
39+
match def.name() {
4040
"IAsyncAction" => AsyncKind::Action,
4141
"IAsyncActionWithProgress`1" => AsyncKind::ActionWithProgress,
4242
"IAsyncOperation`1" => AsyncKind::Operation,
@@ -47,8 +47,8 @@ pub fn async_kind(def: &GenericType) -> AsyncKind {
4747

4848
fn gen_async_kind(
4949
kind: AsyncKind,
50-
name: &GenericType,
51-
self_name: &GenericType,
50+
name: &tables::TypeDef,
51+
self_name: &tables::TypeDef,
5252
gen: &Gen,
5353
) -> (TokenStream, TokenStream) {
5454
let return_type = match kind {

crates/gen/src/iterator.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ use super::*;
55
// only falls back to IIterator<T> if nothing faster is available. VectorIterator and
66
// VectorViewIterator are faster iterators than IIterator<T> because they only require a single
77
// vcall per iteration wheras IIterator<T> requires two.
8-
pub fn gen_iterator(def: &GenericType, interfaces: &[InterfaceInfo], gen: &Gen) -> TokenStream {
9-
let name = def.def.full_name();
8+
pub fn gen_iterator(def: &tables::TypeDef, interfaces: &[InterfaceInfo], gen: &Gen) -> TokenStream {
9+
let name = def.full_name();
1010

1111
// If the type is IIterator<T> then simply implement the Iterator trait over top.
1212
if name == ("Windows.Foundation.Collections", "IIterator`1") {
@@ -154,7 +154,7 @@ pub fn gen_iterator(def: &GenericType, interfaces: &[InterfaceInfo], gen: &Gen)
154154
// If the class or interface is not one of the well-known collection interfaces, we then see whether it
155155
// implements any one of them. Here is where we favor IVectorView/IVector over IIterable.
156156
for interface in interfaces {
157-
let name = interface.def.def.full_name();
157+
let name = interface.def.full_name();
158158

159159
if name == ("Windows.Foundation.Collections", "IVectorView`1") {
160160
let constraints = def.gen_constraints(gen);

crates/gen/src/parser/codes.rs

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ pub trait Decode {
44
fn decode(file: &'static File, code: u32) -> Self;
55
}
66

7-
#[derive(Copy, Clone, Debug, PartialEq, PartialOrd, Eq, Ord)]
7+
#[derive(Clone, Debug)]
88
pub enum TypeDefOrRef {
99
TypeDef(tables::TypeDef),
1010
TypeRef(tables::TypeRef),
@@ -15,7 +15,7 @@ impl Decode for TypeDefOrRef {
1515
fn decode(file: &'static File, code: u32) -> Self {
1616
let code = (code & ((1 << 2) - 1), (code >> 2) - 1);
1717
match code.0 {
18-
0 => Self::TypeDef(tables::TypeDef(Row::new(code.1, TableIndex::TypeDef, file))),
18+
0 => Self::TypeDef(Row::new(code.1, TableIndex::TypeDef, file).into()),
1919
1 => Self::TypeRef(tables::TypeRef(Row::new(code.1, TableIndex::TypeRef, file))),
2020
2 => Self::TypeSpec(tables::TypeSpec(Row::new(
2121
code.1,
@@ -30,14 +30,14 @@ impl Decode for TypeDefOrRef {
3030
impl TypeDefOrRef {
3131
pub fn encode(&self) -> u32 {
3232
match self {
33-
Self::TypeDef(value) => ((value.0.row + 1) << 2),
33+
Self::TypeDef(value) => ((value.row.row + 1) << 2),
3434
Self::TypeRef(value) => ((value.0.row + 1) << 2) | 1,
3535
Self::TypeSpec(value) => ((value.0.row + 1) << 2) | 2,
3636
}
3737
}
3838
}
3939

40-
#[derive(Copy, Clone, Debug, PartialEq, PartialOrd, Eq, Ord)]
40+
#[derive(Clone, Debug)]
4141
pub enum TypeOrMethodDef {
4242
TypeDef(tables::TypeDef),
4343
MethodDef(tables::MethodDef),
@@ -47,7 +47,7 @@ impl Decode for TypeOrMethodDef {
4747
fn decode(file: &'static File, code: u32) -> Self {
4848
let code = (code & ((1 << 1) - 1), (code >> 1) - 1);
4949
match code.0 {
50-
0 => Self::TypeDef(tables::TypeDef(Row::new(code.1, TableIndex::TypeDef, file))),
50+
0 => Self::TypeDef(Row::new(code.1, TableIndex::TypeDef, file).into()),
5151
1 => Self::MethodDef(tables::MethodDef(Row::new(
5252
code.1,
5353
TableIndex::MethodDef,
@@ -61,13 +61,13 @@ impl Decode for TypeOrMethodDef {
6161
impl TypeOrMethodDef {
6262
pub fn encode(&self) -> u32 {
6363
match self {
64-
Self::TypeDef(value) => ((value.0.row + 1) << 1),
64+
Self::TypeDef(value) => ((value.row.row + 1) << 1),
6565
Self::MethodDef(value) => ((value.0.row + 1) << 1) | 1,
6666
}
6767
}
6868
}
6969

70-
#[derive(Copy, Clone, Debug, PartialEq, PartialOrd, Eq, Ord)]
70+
#[derive(Clone, Debug)]
7171
pub enum HasAttribute {
7272
MethodDef(tables::MethodDef),
7373
Field(tables::Field),
@@ -91,7 +91,7 @@ impl Decode for HasAttribute {
9191
))),
9292
1 => Self::Field(tables::Field(Row::new(code.1, TableIndex::Field, file))),
9393
2 => Self::TypeRef(tables::TypeRef(Row::new(code.1, TableIndex::TypeRef, file))),
94-
3 => Self::TypeDef(tables::TypeDef(Row::new(code.1, TableIndex::TypeDef, file))),
94+
3 => Self::TypeDef(Row::new(code.1, TableIndex::TypeDef, file).into()),
9595
4 => Self::Param(tables::Param(Row::new(code.1, TableIndex::Param, file))),
9696
5 => Self::InterfaceImpl(tables::InterfaceImpl(Row::new(
9797
code.1,
@@ -124,7 +124,7 @@ impl HasAttribute {
124124
Self::MethodDef(value) => ((value.0.row + 1) << 5),
125125
Self::Field(value) => ((value.0.row + 1) << 5) | 1,
126126
Self::TypeRef(value) => ((value.0.row + 1) << 5) | 2,
127-
Self::TypeDef(value) => ((value.0.row + 1) << 5) | 3,
127+
Self::TypeDef(value) => ((value.row.row + 1) << 5) | 3,
128128
Self::Param(value) => ((value.0.row + 1) << 5) | 4,
129129
Self::InterfaceImpl(value) => ((value.0.row + 1) << 5) | 5,
130130
Self::MemberRef(value) => ((value.0.row + 1) << 5) | 6,
@@ -134,7 +134,7 @@ impl HasAttribute {
134134
}
135135
}
136136

137-
#[derive(Copy, Clone, Debug, PartialEq, PartialOrd, Eq, Ord)]
137+
#[derive(Clone, Debug)]
138138
pub enum MemberRefParent {
139139
TypeDef(tables::TypeDef),
140140
TypeRef(tables::TypeRef),
@@ -146,7 +146,7 @@ impl Decode for MemberRefParent {
146146
fn decode(file: &'static File, code: u32) -> Self {
147147
let code = (code & ((1 << 3) - 1), (code >> 3) - 1);
148148
match code.0 {
149-
0 => Self::TypeDef(tables::TypeDef(Row::new(code.1, TableIndex::TypeDef, file))),
149+
0 => Self::TypeDef(Row::new(code.1, TableIndex::TypeDef, file).into()),
150150
1 => Self::TypeRef(tables::TypeRef(Row::new(code.1, TableIndex::TypeRef, file))),
151151
3 => Self::MethodDef(tables::MethodDef(Row::new(
152152
code.1,
@@ -166,15 +166,15 @@ impl Decode for MemberRefParent {
166166
impl MemberRefParent {
167167
pub fn encode(&self) -> u32 {
168168
match self {
169-
Self::TypeDef(value) => ((value.0.row + 1) << 3),
169+
Self::TypeDef(value) => ((value.row.row + 1) << 3),
170170
Self::TypeRef(value) => ((value.0.row + 1) << 3) | 1,
171171
Self::MethodDef(value) => ((value.0.row + 1) << 3) | 3,
172172
Self::TypeSpec(value) => ((value.0.row + 1) << 3) | 4,
173173
}
174174
}
175175
}
176176

177-
#[derive(Copy, Clone, Debug, PartialEq, PartialOrd, Eq, Ord)]
177+
#[derive(Clone, Debug)]
178178
pub enum HasConstant {
179179
Field(tables::Field),
180180
Param(tables::Param),
@@ -200,7 +200,7 @@ impl HasConstant {
200200
}
201201
}
202202

203-
#[derive(Copy, Clone, Debug, PartialEq, PartialOrd, Eq, Ord)]
203+
#[derive(Clone, Debug)]
204204
pub enum AttributeType {
205205
MethodDef(tables::MethodDef),
206206
MemberRef(tables::MemberRef),
@@ -234,7 +234,7 @@ impl AttributeType {
234234
}
235235
}
236236

237-
#[derive(Copy, Clone, Debug, PartialEq, PartialOrd, Eq, Ord)]
237+
#[derive(Clone, Debug)]
238238
pub enum MemberForwarded {
239239
Field(tables::Field),
240240
MethodDef(tables::MethodDef),
@@ -264,7 +264,7 @@ impl MemberForwarded {
264264
}
265265
}
266266

267-
#[derive(Copy, Clone, Debug, PartialEq, PartialOrd, Eq, Ord)]
267+
#[derive(Clone, Debug)]
268268
pub enum ResolutionScope {
269269
Module(tables::Module),
270270
ModuleRef(tables::ModuleRef),
@@ -331,7 +331,7 @@ impl TypeDefOrRef {
331331

332332
pub fn resolve(&self) -> tables::TypeDef {
333333
match self {
334-
Self::TypeDef(value) => *value,
334+
Self::TypeDef(value) => value.clone(),
335335
Self::TypeRef(value) => value.resolve(),
336336
_ => unexpected!(),
337337
}

0 commit comments

Comments
 (0)