1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
use voile_util::{
    level::Level,
    loc::{Ident, Loc, ToLoc},
    uid::GI,
};

use crate::syntax::abs::{Abs, AbsCopat, AbsTele};

#[derive(Debug, PartialEq, Eq, Clone)]
pub struct AbsConsInfo {
    pub source: Loc,
    pub name: Ident,
    pub tele: AbsTele,
    /// Corresponding datatype's index.
    pub data_ix: GI,
}

#[derive(Debug, PartialEq, Eq, Clone)]
pub struct AbsDefnInfo {
    pub source: Loc,
    pub name: Ident,
    pub ty: Abs,
}

#[derive(Debug, PartialEq, Eq, Clone)]
pub struct AbsProjInfo {
    pub source: Loc,
    pub name: Ident,
    pub ty: Abs,
    /// Corresponding coinductive record's index.
    pub codata_ix: GI,
}

#[derive(Debug, PartialEq, Eq, Clone)]
pub struct AbsCodataInfo {
    pub source: Loc,
    pub self_ref: Option<Ident>,
    pub name: Ident,
    pub fields: Vec<GI>,
    pub level: Level,
    pub tele: AbsTele,
}

#[derive(Debug, PartialEq, Eq, Clone)]
pub struct AbsDataInfo {
    pub source: Loc,
    pub name: Ident,
    pub level: Level,
    pub tele: AbsTele,
    pub conses: Vec<GI>,
}

/// Declaration.
/// [Agda](https://hackage.haskell.org/package/Agda-2.6.0.1/docs/Agda-Syntax-Abstract.html#t:Declaration).
#[derive(Debug, PartialEq, Eq, Clone)]
pub enum AbsDecl {
    /// Datatypes.
    Data(AbsDataInfo),
    /// Datatype constructors.
    Cons(AbsConsInfo),
    /// Coinductive record projections.
    Proj(AbsProjInfo),
    /// Function signature definition.
    Defn(AbsDefnInfo),
    /// Pattern matching clause.
    Clause(AbsClause),
    /// Coinductive records.
    Codata(AbsCodataInfo),
}

impl AbsDecl {
    pub fn decl_name(&self) -> &Ident {
        use AbsDecl::*;
        match self {
            Defn(info) => &info.name,
            Clause(info) => &info.name,
            Data(info) => &info.name,
            Cons(info) => &info.name,
            Proj(info) => &info.name,
            Codata(info) => &info.name,
        }
    }
}

impl ToLoc for AbsDecl {
    fn loc(&self) -> Loc {
        use AbsDecl::*;
        match self {
            Defn(i) => i.loc(),
            Data(i) => i.loc(),
            Cons(i) => i.loc(),
            Clause(i) => i.loc(),
            Codata(i) => i.loc(),
            Proj(i) => i.loc(),
        }
    }
}

/// Clause information in abstract syntax.
/// [Agda](https://hackage.haskell.org/package/Agda-2.6.0.1/docs/src/Agda.Syntax.Abstract.html#Clause%27).
#[derive(Debug, PartialEq, Eq, Clone)]
pub struct AbsClause {
    pub source: Loc,
    /// Name of the function we're adding clause to.
    pub name: Ident,
    /// Lhs.
    pub patterns: Vec<AbsCopat>,
    /// Index of the type signature definition.
    pub definition: GI,
    /// Rhs.
    pub body: Abs,
}