mirror of
https://github.com/AleoHQ/leo.git
synced 2024-12-19 15:41:36 +03:00
includes ast and asg changes
This commit is contained in:
parent
9951627c8c
commit
e03d5c23b8
@ -183,6 +183,8 @@ impl<'a> Scope<'a> {
|
|||||||
IntegerType(int_type) => Type::Integer(int_type.clone()),
|
IntegerType(int_type) => Type::Integer(int_type.clone()),
|
||||||
Array(sub_type, dimensions) => {
|
Array(sub_type, dimensions) => {
|
||||||
let mut item = Box::new(self.resolve_ast_type(&*sub_type, span)?);
|
let mut item = Box::new(self.resolve_ast_type(&*sub_type, span)?);
|
||||||
|
|
||||||
|
if let Some(dimensions) = dimensions {
|
||||||
for dimension in dimensions.0.iter().rev() {
|
for dimension in dimensions.0.iter().rev() {
|
||||||
let dimension = dimension
|
let dimension = dimension
|
||||||
.value
|
.value
|
||||||
@ -190,6 +192,11 @@ impl<'a> Scope<'a> {
|
|||||||
.map_err(|_| AsgError::parse_index_error(span))?;
|
.map_err(|_| AsgError::parse_index_error(span))?;
|
||||||
item = Box::new(Type::Array(item, dimension));
|
item = Box::new(Type::Array(item, dimension));
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
// } else {
|
||||||
|
// return AsgError::parse_index_error(span);
|
||||||
|
// }
|
||||||
|
|
||||||
*item
|
*item
|
||||||
}
|
}
|
||||||
Tuple(sub_types) => Type::Tuple(
|
Tuple(sub_types) => Type::Tuple(
|
||||||
|
@ -207,9 +207,9 @@ impl<'a> Into<leo_ast::Type> for &Type<'a> {
|
|||||||
Integer(int_type) => leo_ast::Type::IntegerType(int_type.clone()),
|
Integer(int_type) => leo_ast::Type::IntegerType(int_type.clone()),
|
||||||
Array(type_, len) => leo_ast::Type::Array(
|
Array(type_, len) => leo_ast::Type::Array(
|
||||||
Box::new(type_.as_ref().into()),
|
Box::new(type_.as_ref().into()),
|
||||||
leo_ast::ArrayDimensions(vec![leo_ast::PositiveNumber {
|
Some(leo_ast::ArrayDimensions(vec![leo_ast::PositiveNumber {
|
||||||
value: len.to_string().into(),
|
value: len.to_string().into(),
|
||||||
}]),
|
}])),
|
||||||
),
|
),
|
||||||
Tuple(subtypes) => leo_ast::Type::Tuple(subtypes.iter().map(Into::into).collect()),
|
Tuple(subtypes) => leo_ast::Type::Tuple(subtypes.iter().map(Into::into).collect()),
|
||||||
Circuit(circuit) => leo_ast::Type::CircuitOrAlias(circuit.name.borrow().clone()),
|
Circuit(circuit) => leo_ast::Type::CircuitOrAlias(circuit.name.borrow().clone()),
|
||||||
|
@ -481,12 +481,13 @@ impl ReconstructingReducer for Canonicalizer {
|
|||||||
|
|
||||||
fn reduce_type(&mut self, _type_: &Type, new: Type, span: &Span) -> Result<Type> {
|
fn reduce_type(&mut self, _type_: &Type, new: Type, span: &Span) -> Result<Type> {
|
||||||
match new {
|
match new {
|
||||||
Type::Array(type_, mut dimensions) => {
|
Type::Array(type_, dimensions) => {
|
||||||
|
if let Some(mut dimensions) = dimensions {
|
||||||
if dimensions.is_zero() {
|
if dimensions.is_zero() {
|
||||||
return Err(AstError::invalid_array_dimension_size(span).into());
|
return Err(AstError::invalid_array_dimension_size(span).into());
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut next = Type::Array(type_, ArrayDimensions(vec![dimensions.remove_last().unwrap()]));
|
let mut next = Type::Array(type_, Some(ArrayDimensions(vec![dimensions.remove_last().unwrap()])));
|
||||||
let mut array = next.clone();
|
let mut array = next.clone();
|
||||||
|
|
||||||
loop {
|
loop {
|
||||||
@ -494,11 +495,17 @@ impl ReconstructingReducer for Canonicalizer {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
array = Type::Array(Box::new(next), ArrayDimensions(vec![dimensions.remove_last().unwrap()]));
|
array = Type::Array(
|
||||||
|
Box::new(next),
|
||||||
|
Some(ArrayDimensions(vec![dimensions.remove_last().unwrap()])),
|
||||||
|
);
|
||||||
next = array.clone();
|
next = array.clone();
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(array)
|
Ok(array)
|
||||||
|
} else {
|
||||||
|
Ok(Type::Array(type_, None))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Type::SelfType if !self.in_circuit => Err(AstError::big_self_outside_of_circuit(span).into()),
|
Type::SelfType if !self.in_circuit => Err(AstError::big_self_outside_of_circuit(span).into()),
|
||||||
_ => Ok(new.clone()),
|
_ => Ok(new.clone()),
|
||||||
|
@ -34,7 +34,7 @@ pub enum Type {
|
|||||||
IntegerType(IntegerType),
|
IntegerType(IntegerType),
|
||||||
|
|
||||||
// Data type wrappers
|
// Data type wrappers
|
||||||
Array(Box<Type>, ArrayDimensions),
|
Array(Box<Type>, Option<ArrayDimensions>),
|
||||||
Tuple(Vec<Type>),
|
Tuple(Vec<Type>),
|
||||||
CircuitOrAlias(Identifier),
|
CircuitOrAlias(Identifier),
|
||||||
SelfType,
|
SelfType,
|
||||||
@ -72,8 +72,17 @@ impl Type {
|
|||||||
(Type::SelfType, Type::SelfType) => true,
|
(Type::SelfType, Type::SelfType) => true,
|
||||||
(Type::Array(left_type, left_dim), Type::Array(right_type, right_dim)) => {
|
(Type::Array(left_type, left_dim), Type::Array(right_type, right_dim)) => {
|
||||||
// Convert array dimensions to owned.
|
// Convert array dimensions to owned.
|
||||||
let mut left_dim_owned = left_dim.to_owned();
|
let left_dim_owned = left_dim.to_owned();
|
||||||
let mut right_dim_owned = right_dim.to_owned();
|
let right_dim_owned = right_dim.to_owned();
|
||||||
|
|
||||||
|
// Unable to compare arrays with unspecified sizes.
|
||||||
|
if left_dim_owned.is_none() || right_dim_owned.is_none() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// We know that values are Some, safe to unwrap.
|
||||||
|
let mut left_dim_owned = left_dim_owned.unwrap();
|
||||||
|
let mut right_dim_owned = right_dim_owned.unwrap();
|
||||||
|
|
||||||
// Remove the first element from both dimensions.
|
// Remove the first element from both dimensions.
|
||||||
let left_first = left_dim_owned.remove_first();
|
let left_first = left_dim_owned.remove_first();
|
||||||
@ -120,7 +129,7 @@ impl<'ast> From<InputArrayType<'ast>> for Type {
|
|||||||
let element_type = Box::new(Type::from(*array_type.type_));
|
let element_type = Box::new(Type::from(*array_type.type_));
|
||||||
let dimensions = ArrayDimensions::from(array_type.dimensions);
|
let dimensions = ArrayDimensions::from(array_type.dimensions);
|
||||||
|
|
||||||
Type::Array(element_type, dimensions)
|
Type::Array(element_type, Some(dimensions))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -153,7 +162,13 @@ impl fmt::Display for Type {
|
|||||||
Type::IntegerType(ref integer_type) => write!(f, "{}", integer_type),
|
Type::IntegerType(ref integer_type) => write!(f, "{}", integer_type),
|
||||||
Type::CircuitOrAlias(ref variable) => write!(f, "circuit {}", variable),
|
Type::CircuitOrAlias(ref variable) => write!(f, "circuit {}", variable),
|
||||||
Type::SelfType => write!(f, "SelfType"),
|
Type::SelfType => write!(f, "SelfType"),
|
||||||
Type::Array(ref array, ref dimensions) => write!(f, "[{}; {}]", *array, dimensions),
|
Type::Array(ref array, ref dimensions) => {
|
||||||
|
if let Some(dimensions) = dimensions {
|
||||||
|
write!(f, "[{}; {}]", *array, dimensions)
|
||||||
|
} else {
|
||||||
|
write!(f, "[{}; _]", *array)
|
||||||
|
}
|
||||||
|
}
|
||||||
Type::Tuple(ref tuple) => {
|
Type::Tuple(ref tuple) => {
|
||||||
let types = tuple.iter().map(|x| x.to_string()).collect::<Vec<_>>().join(", ");
|
let types = tuple.iter().map(|x| x.to_string()).collect::<Vec<_>>().join(", ");
|
||||||
|
|
||||||
@ -179,6 +194,6 @@ pub fn inner_array_type(element_type: Type, dimensions: ArrayDimensions) -> Type
|
|||||||
element_type
|
element_type
|
||||||
} else {
|
} else {
|
||||||
// The array has multiple dimensions.
|
// The array has multiple dimensions.
|
||||||
Type::Array(Box::new(element_type), dimensions)
|
Type::Array(Box::new(element_type), Some(dimensions))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -76,9 +76,9 @@ impl<R: ReconstructingReducer, O: CombinerOptions> CombineAstAsgDirector<R, O> {
|
|||||||
if self.options.type_inference_enabled() {
|
if self.options.type_inference_enabled() {
|
||||||
AstType::Array(
|
AstType::Array(
|
||||||
Box::new(self.reduce_type(ast_type, asg_type, span)?),
|
Box::new(self.reduce_type(ast_type, asg_type, span)?),
|
||||||
ArrayDimensions(vec![PositiveNumber {
|
Some(ArrayDimensions(vec![PositiveNumber {
|
||||||
value: StrTendril::from(format!("{}", asg_dimensions)),
|
value: StrTendril::from(format!("{}", asg_dimensions)),
|
||||||
}]),
|
}])),
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
AstType::Array(
|
AstType::Array(
|
||||||
|
@ -32,7 +32,7 @@ create_errors!(
|
|||||||
help: None,
|
help: None,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// For when the parser encoutnered an invalid address literal.
|
/// For when the parser encountered an invalid address literal.
|
||||||
@formatted
|
@formatted
|
||||||
invalid_address_lit {
|
invalid_address_lit {
|
||||||
args: (token: impl Display),
|
args: (token: impl Display),
|
||||||
@ -40,7 +40,7 @@ create_errors!(
|
|||||||
help: None,
|
help: None,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// For when the parser encoutnered an empty import list.
|
/// For when the parser encountered an empty import list.
|
||||||
@formatted
|
@formatted
|
||||||
invalid_import_list {
|
invalid_import_list {
|
||||||
args: (),
|
args: (),
|
||||||
@ -48,7 +48,7 @@ create_errors!(
|
|||||||
help: None,
|
help: None,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// For when the parser encoutnered an unexpected End of File.
|
/// For when the parser encountered an unexpected End of File.
|
||||||
@formatted
|
@formatted
|
||||||
unexpected_eof {
|
unexpected_eof {
|
||||||
args: (),
|
args: (),
|
||||||
@ -56,7 +56,7 @@ create_errors!(
|
|||||||
help: None,
|
help: None,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// For when the parser encoutnered an unexpected whitespace.
|
/// For when the parser encountered an unexpected whitespace.
|
||||||
@formatted
|
@formatted
|
||||||
unexpected_whitespace {
|
unexpected_whitespace {
|
||||||
args: (left: impl Display, right: impl Display),
|
args: (left: impl Display, right: impl Display),
|
||||||
@ -64,7 +64,7 @@ create_errors!(
|
|||||||
help: None,
|
help: None,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// For when the parser encoutnered an unexpected list of tokens.
|
/// For when the parser encountered an unexpected list of tokens.
|
||||||
@formatted
|
@formatted
|
||||||
unexpected {
|
unexpected {
|
||||||
args: (got: impl Display, expected: impl Display),
|
args: (got: impl Display, expected: impl Display),
|
||||||
@ -72,7 +72,7 @@ create_errors!(
|
|||||||
help: None,
|
help: None,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// For when the parser encoutnered a mix of commas and semi-colons in circuit member variables.
|
/// For when the parser encountered a mix of commas and semi-colons in circuit member variables.
|
||||||
@formatted
|
@formatted
|
||||||
mixed_commas_and_semicolons {
|
mixed_commas_and_semicolons {
|
||||||
args: (),
|
args: (),
|
||||||
@ -80,7 +80,7 @@ create_errors!(
|
|||||||
help: None,
|
help: None,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// For when the parser encoutnered an unexpected identifier.
|
/// For when the parser encountered an unexpected identifier.
|
||||||
@formatted
|
@formatted
|
||||||
unexpected_ident {
|
unexpected_ident {
|
||||||
args: (got: impl Display, expected: &[impl Display]),
|
args: (got: impl Display, expected: &[impl Display]),
|
||||||
@ -96,7 +96,7 @@ create_errors!(
|
|||||||
help: None,
|
help: None,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// For when the parser encoutnered an unexpected statement.
|
/// For when the parser encountered an unexpected statement.
|
||||||
@formatted
|
@formatted
|
||||||
unexpected_statement {
|
unexpected_statement {
|
||||||
args: (got: impl Display, expected: impl Display),
|
args: (got: impl Display, expected: impl Display),
|
||||||
@ -104,7 +104,7 @@ create_errors!(
|
|||||||
help: None,
|
help: None,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// For when the parser encoutnered an unexpected string.
|
/// For when the parser encountered an unexpected string.
|
||||||
@formatted
|
@formatted
|
||||||
unexpected_str {
|
unexpected_str {
|
||||||
args: (got: impl Display, expected: impl Display),
|
args: (got: impl Display, expected: impl Display),
|
||||||
@ -112,7 +112,7 @@ create_errors!(
|
|||||||
help: None,
|
help: None,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// For when the parser encoutnered an unexpected spread in an array init expression.
|
/// For when the parser encountered an unexpected spread in an array init expression.
|
||||||
@formatted
|
@formatted
|
||||||
spread_in_array_init {
|
spread_in_array_init {
|
||||||
args: (),
|
args: (),
|
||||||
@ -120,7 +120,7 @@ create_errors!(
|
|||||||
help: None,
|
help: None,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// For when the parser encoutnered an invalid assignment target.
|
/// For when the parser encountered an invalid assignment target.
|
||||||
@formatted
|
@formatted
|
||||||
invalid_assignment_target {
|
invalid_assignment_target {
|
||||||
args: (),
|
args: (),
|
||||||
@ -128,7 +128,7 @@ create_errors!(
|
|||||||
help: None,
|
help: None,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// For when the parser encoutnered an invalid package name.
|
/// For when the parser encountered an invalid package name.
|
||||||
@formatted
|
@formatted
|
||||||
invalid_package_name {
|
invalid_package_name {
|
||||||
args: (),
|
args: (),
|
||||||
@ -136,7 +136,7 @@ create_errors!(
|
|||||||
help: None,
|
help: None,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// For when the parser encoutnered an illegal `const self` argument.
|
/// For when the parser encountered an illegal `const self` argument.
|
||||||
@formatted
|
@formatted
|
||||||
illegal_self_const {
|
illegal_self_const {
|
||||||
args: (),
|
args: (),
|
||||||
@ -144,7 +144,7 @@ create_errors!(
|
|||||||
help: None,
|
help: None,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// For when the parser encoutnered a deprecated `mut` argument in a function.
|
/// For when the parser encountered a deprecated `mut` argument in a function.
|
||||||
@formatted
|
@formatted
|
||||||
mut_function_input {
|
mut_function_input {
|
||||||
args: (),
|
args: (),
|
||||||
@ -152,7 +152,7 @@ create_errors!(
|
|||||||
help: None,
|
help: None,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// For when the parser encoutnered a deprecated `mut` argument in a let statement.
|
/// For when the parser encountered a deprecated `mut` argument in a let statement.
|
||||||
@formatted
|
@formatted
|
||||||
let_mut_statement {
|
let_mut_statement {
|
||||||
args: (),
|
args: (),
|
||||||
@ -160,7 +160,7 @@ create_errors!(
|
|||||||
help: None,
|
help: None,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// For when the parser encoutnered a deprecated `test function`.
|
/// For when the parser encountered a deprecated `test function`.
|
||||||
@formatted
|
@formatted
|
||||||
test_function {
|
test_function {
|
||||||
args: (),
|
args: (),
|
||||||
@ -168,11 +168,19 @@ create_errors!(
|
|||||||
help: None,
|
help: None,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// For when the parser encoutnered a deprecated `@context(...)` annotation.
|
/// For when the parser encountered a deprecated `@context(...)` annotation.
|
||||||
@formatted
|
@formatted
|
||||||
context_annotation {
|
context_annotation {
|
||||||
args: (),
|
args: (),
|
||||||
msg: "\"@context(...)\" is deprecated. Did you mean @test annotation?",
|
msg: "\"@context(...)\" is deprecated. Did you mean @test annotation?",
|
||||||
help: None,
|
help: None,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// For when the parser failed to parse array dimensions.
|
||||||
|
@formatted
|
||||||
|
unable_to_parse_array_dimensions {
|
||||||
|
args: (),
|
||||||
|
msg: "unable to parse array dimensions",
|
||||||
|
help: None,
|
||||||
|
}
|
||||||
);
|
);
|
||||||
|
Loading…
Reference in New Issue
Block a user