mirror of
https://github.com/ProvableHQ/leo.git
synced 2024-12-25 19:22:01 +03:00
impl array-type in typed
This commit is contained in:
parent
7a0dc342fb
commit
02128488ea
@ -42,7 +42,7 @@ use leo_ast::{
|
||||
};
|
||||
use leo_input::values::PositiveNumber as InputAstPositiveNumber;
|
||||
|
||||
use leo_ast::expressions::TupleExpression;
|
||||
use leo_ast::{expressions::TupleExpression, types::ArrayDimensions};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::fmt;
|
||||
|
||||
@ -150,6 +150,17 @@ impl<'ast> Expression {
|
||||
.parse::<usize>()
|
||||
.expect("Array size should be a positive number")
|
||||
}
|
||||
|
||||
pub(crate) fn get_array_dimensions(dimensions: ArrayDimensions<'ast>) -> Vec<usize> {
|
||||
match dimensions {
|
||||
ArrayDimensions::Single(single) => vec![Self::get_count_from_ast(single.number)],
|
||||
ArrayDimensions::Multiple(multiple) => multiple
|
||||
.numbers
|
||||
.into_iter()
|
||||
.map(|number| Self::get_count_from_ast(number))
|
||||
.collect(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<'ast> fmt::Display for Expression {
|
||||
|
@ -15,7 +15,7 @@
|
||||
// along with the Leo library. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
use crate::{Expression, Identifier, IntegerType};
|
||||
use leo_ast::types::{ArrayType, CircuitType, DataType, TupleType, Type as AstType};
|
||||
use leo_ast::types::{ArrayElement, ArrayType, CircuitType, DataType, TupleType, Type as AstType};
|
||||
use leo_input::types::{
|
||||
ArrayType as InputArrayType,
|
||||
DataType as InputDataType,
|
||||
@ -101,17 +101,24 @@ impl From<DataType> for Type {
|
||||
|
||||
impl<'ast> From<ArrayType<'ast>> for Type {
|
||||
fn from(array_type: ArrayType<'ast>) -> Self {
|
||||
let element_type = Box::new(Type::from(array_type._type));
|
||||
let dimensions = array_type
|
||||
.dimensions
|
||||
.into_iter()
|
||||
.map(|row| Expression::get_count_from_ast(row))
|
||||
.collect();
|
||||
let element_type = Box::new(Type::from(array_type.type_));
|
||||
let dimensions = Expression::get_array_dimensions(array_type.dimensions);
|
||||
|
||||
Type::Array(element_type, dimensions)
|
||||
}
|
||||
}
|
||||
|
||||
impl<'ast> From<ArrayElement<'ast>> for Type {
|
||||
fn from(element: ArrayElement<'ast>) -> Self {
|
||||
match element {
|
||||
ArrayElement::Basic(type_) => Type::from(type_),
|
||||
ArrayElement::Tuple(type_) => Type::from(type_),
|
||||
ArrayElement::Circuit(type_) => Type::from(type_),
|
||||
ArrayElement::SelfType(_type) => Type::SelfType,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<'ast> From<TupleType<'ast>> for Type {
|
||||
fn from(tuple_type: TupleType<'ast>) -> Self {
|
||||
let types = tuple_type.types.into_iter().map(|type_| Type::from(type_)).collect();
|
||||
|
Loading…
Reference in New Issue
Block a user