1
0
Fork 0
mirror of synced 2025-09-24 04:40:05 +00:00
ZoKrates/zokrates_core/src/absy/variable.rs
2019-08-07 16:25:09 +02:00

38 lines
940 B
Rust

use crate::absy::types::UnresolvedType;
use crate::absy::{Node, UnresolvedTypeNode};
use std::fmt;
use crate::absy::Identifier;
#[derive(Clone, PartialEq)]
pub struct Variable<'ast> {
pub id: Identifier<'ast>,
pub _type: UnresolvedTypeNode,
}
pub type VariableNode<'ast> = Node<Variable<'ast>>;
impl<'ast> Variable<'ast> {
pub fn new<S: Into<&'ast str>>(id: S, t: UnresolvedTypeNode) -> Variable<'ast> {
Variable {
id: id.into(),
_type: t,
}
}
pub fn get_type(&self) -> UnresolvedType {
self._type.value.clone()
}
}
impl<'ast> fmt::Display for Variable<'ast> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "{} {}", self._type, self.id,)
}
}
impl<'ast> fmt::Debug for Variable<'ast> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "Variable(type: {:?}, id: {:?})", self._type, self.id,)
}
}