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
// Copyright (c) 2016-2020 Fabian Schuiki

//! Access types.

use std::fmt::{self, Display};

use crate::ty2::prelude::*;

/// An access type.
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct AccessType<'t> {
    /// The type of value being pointed to.
    inner: &'t Type,
}

impl<'t> AccessType<'t> {
    /// Create a new access type.
    ///
    /// # Example
    ///
    /// ```
    /// use moore_vhdl::ty2::{Type, AccessType, IntegerBasetype, Range};
    ///
    /// let a = IntegerBasetype::new(Range::ascending(0, 42));
    /// let ty = AccessType::new(&a);
    ///
    /// assert_eq!(format!("{}", ty), "access 0 to 42");
    /// ```
    pub fn new(inner: &'t Type) -> AccessType<'t> {
        AccessType { inner: inner }
    }
}

impl<'t> Type for AccessType<'t> {
    fn is_scalar(&self) -> bool {
        false
    }

    fn is_discrete(&self) -> bool {
        false
    }

    fn is_numeric(&self) -> bool {
        false
    }

    fn is_composite(&self) -> bool {
        false
    }

    fn into_owned<'a>(self) -> OwnedType<'a>
    where
        Self: 'a,
    {
        OwnedType::Access(self)
    }

    fn to_owned<'a>(&self) -> OwnedType<'a>
    where
        Self: 'a,
    {
        OwnedType::Access(self.clone())
    }

    fn as_any(&self) -> AnyType {
        AnyType::Access(self)
    }
}

impl<'t> Display for AccessType<'t> {
    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
        write!(f, "access {}", self.inner)
    }
}