Add ids to type Variants
This commit is contained in:
parent
b4f765167b
commit
b342213826
@ -147,8 +147,11 @@ pub struct Signature {
|
|||||||
#[derive(Debug, PartialEq, Clone)]
|
#[derive(Debug, PartialEq, Clone)]
|
||||||
pub struct TypeBody(pub Vec<Variant>);
|
pub struct TypeBody(pub Vec<Variant>);
|
||||||
|
|
||||||
#[derive(Debug, PartialEq, Clone)]
|
#[derive(Debug, Derivative, Clone)]
|
||||||
|
#[derivative(PartialEq)]
|
||||||
pub struct Variant {
|
pub struct Variant {
|
||||||
|
#[derivative(PartialEq="ignore")]
|
||||||
|
pub id: ItemId,
|
||||||
pub name: Rc<String>,
|
pub name: Rc<String>,
|
||||||
pub kind: VariantKind,
|
pub kind: VariantKind,
|
||||||
}
|
}
|
||||||
|
@ -460,6 +460,7 @@ impl Parser {
|
|||||||
_ => VariantKind::UnitStruct
|
_ => VariantKind::UnitStruct
|
||||||
};
|
};
|
||||||
Ok(Variant {
|
Ok(Variant {
|
||||||
|
id: self.id_store.fresh(),
|
||||||
name,
|
name,
|
||||||
kind
|
kind
|
||||||
})
|
})
|
||||||
|
@ -322,15 +322,18 @@ fn parsing_strings() {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn parsing_types() {
|
fn parsing_types() {
|
||||||
parse_test_wrap_ast!("type Yolo = Yolo", decl!(TypeDecl { name: tys!("Yolo"), body: TypeBody(vec![Variant { kind: UnitStruct, name: rc!(Yolo) }]), mutable: false} ));
|
parse_test_wrap_ast!("type Yolo = Yolo", decl!(TypeDecl { name: tys!("Yolo"), body: TypeBody(vec![Variant { id: ItemId::default(), kind: UnitStruct, name: rc!(Yolo) }]), mutable: false} ));
|
||||||
parse_test_wrap_ast!("type mut Yolo = Yolo", decl!(TypeDecl { name: tys!("Yolo"), body: TypeBody(vec![Variant { kind: UnitStruct, name: rc!(Yolo) }]), mutable: true} ));
|
parse_test_wrap_ast!("type mut Yolo = Yolo", decl!(TypeDecl { name: tys!("Yolo"), body: TypeBody(vec![Variant { id: ItemId::default(), kind: UnitStruct, name: rc!(Yolo) }]), mutable: true} ));
|
||||||
parse_test_wrap_ast!("type alias Sex = Drugs", decl!(TypeAlias { alias: rc!(Sex), original: rc!(Drugs) }));
|
parse_test_wrap_ast!("type alias Sex = Drugs", decl!(TypeAlias { alias: rc!(Sex), original: rc!(Drugs) }));
|
||||||
parse_test_wrap_ast!("type Sanchez = Miguel | Alejandro(Int, Option<a>) | Esperanza { a: Int, b: String }",
|
parse_test_wrap_ast!("type Sanchez = Miguel | Alejandro(Int, Option<a>) | Esperanza { a: Int, b: String }",
|
||||||
decl!(TypeDecl {
|
decl!(TypeDecl {
|
||||||
name: tys!("Sanchez"),
|
name: tys!("Sanchez"),
|
||||||
body: TypeBody(vec![
|
body: TypeBody(vec![
|
||||||
Variant { kind: UnitStruct, name: rc!(Miguel) },
|
|
||||||
Variant {
|
Variant {
|
||||||
|
id: ItemId::default(),
|
||||||
|
kind: UnitStruct, name: rc!(Miguel) },
|
||||||
|
Variant {
|
||||||
|
id: ItemId::default(),
|
||||||
name: rc!(Alejandro),
|
name: rc!(Alejandro),
|
||||||
kind: TupleStruct(vec![
|
kind: TupleStruct(vec![
|
||||||
Singleton(TypeSingletonName { name: rc!(Int), params: vec![] }),
|
Singleton(TypeSingletonName { name: rc!(Int), params: vec![] }),
|
||||||
@ -338,6 +341,7 @@ fn parsing_types() {
|
|||||||
])
|
])
|
||||||
},
|
},
|
||||||
Variant {
|
Variant {
|
||||||
|
id: ItemId::default(),
|
||||||
name: rc!(Esperanza),
|
name: rc!(Esperanza),
|
||||||
kind: Record(vec![
|
kind: Record(vec![
|
||||||
(rc!(a), Singleton(TypeSingletonName { name: rc!(Int), params: vec![] })),
|
(rc!(a), Singleton(TypeSingletonName { name: rc!(Int), params: vec![] })),
|
||||||
@ -352,7 +356,7 @@ fn parsing_types() {
|
|||||||
"type Jorge<a> = Diego | Kike(a)",
|
"type Jorge<a> = Diego | Kike(a)",
|
||||||
decl!(TypeDecl{
|
decl!(TypeDecl{
|
||||||
name: TypeSingletonName { name: rc!(Jorge), params: vec![Singleton(TypeSingletonName { name: rc!(a), params: vec![] })] },
|
name: TypeSingletonName { name: rc!(Jorge), params: vec![Singleton(TypeSingletonName { name: rc!(a), params: vec![] })] },
|
||||||
body: TypeBody(vec![Variant{ kind: UnitStruct, name: rc!(Diego) }, Variant { name: rc!(Kike), kind: TupleStruct( vec![Singleton(TypeSingletonName { name: rc!(a), params: vec![] })]) }]),
|
body: TypeBody(vec![Variant{ id: ItemId::default(), kind: UnitStruct, name: rc!(Diego) }, Variant { id: ItemId::default(), name: rc!(Kike), kind: TupleStruct( vec![Singleton(TypeSingletonName { name: rc!(a), params: vec![] })]) }]),
|
||||||
mutable: false
|
mutable: false
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
@ -422,7 +422,7 @@ impl SymbolTable {
|
|||||||
scope_stack.push(new_scope);
|
scope_stack.push(new_scope);
|
||||||
|
|
||||||
for (index, variant) in variants.iter().enumerate() {
|
for (index, variant) in variants.iter().enumerate() {
|
||||||
let Variant { name, kind } = variant;
|
let Variant { name, kind, id } = variant;
|
||||||
match kind {
|
match kind {
|
||||||
VariantKind::UnitStruct => {
|
VariantKind::UnitStruct => {
|
||||||
let fq_name = Fqsn::from_scope_stack(scope_stack.as_ref(), name.clone());
|
let fq_name = Fqsn::from_scope_stack(scope_stack.as_ref(), name.clone());
|
||||||
|
Loading…
Reference in New Issue
Block a user