yog_script_analyze/ast/generics.rs
1//! A declaration's type parameters and what they must be (`ys-grammar.md`
2//! §2.3): `<in T, out R>`, `where T : class, new(), IComparable<T>`.
3
4use super::{Name, Type};
5
6/// `T`, `in T`, `out T`, or a lifetime `'a`.
7#[derive(Debug, Clone, PartialEq)]
8pub struct Generic {
9 pub name: Name,
10 pub variance: Option<Variance>,
11 /// `'a`: a lifetime, not a type.
12 pub lifetime: bool,
13}
14
15/// An interface's or a delegate's type parameter: taken (`in`) or given
16/// (`out`).
17#[derive(Debug, Clone, Copy, PartialEq, Eq)]
18pub enum Variance {
19 In,
20 Out,
21}
22
23/// One thing a type parameter must be.
24#[derive(Debug, Clone, PartialEq)]
25pub enum Constraint {
26 /// `class`: an object (a reference).
27 Class,
28 /// `struct`: a value.
29 Struct,
30 /// `new()`: made with no arguments.
31 New,
32 /// A base class or an interface.
33 Type(Type),
34}
35
36/// `where T : …`.
37#[derive(Debug, Clone, PartialEq)]
38pub struct Where {
39 pub name: Name,
40 pub bounds: Vec<Constraint>,
41}