use index map in ast module

This commit is contained in:
collin 2020-12-07 12:05:55 -05:00
parent 9bb04fd75a
commit 5d2136b518
9 changed files with 30 additions and 26 deletions

View File

@ -42,6 +42,10 @@ default-features = false
version = "1.1.3"
default-features = false
[dependencies.indexmap]
version = "1.6.0"
features = ["serde-1"]
[dependencies.pest]
version = "2.0"

View File

@ -20,14 +20,14 @@ use leo_grammar::{
definitions::{AnnotatedDefinition, Definition},
};
use std::collections::HashMap;
use indexmap::IndexMap;
pub fn load_annotation(
annotated_definition: AnnotatedDefinition,
_imports: &mut Vec<ImportStatement>,
_circuits: &mut HashMap<Identifier, Circuit>,
_functions: &mut HashMap<Identifier, Function>,
tests: &mut HashMap<Identifier, TestFunction>,
_circuits: &mut IndexMap<Identifier, Circuit>,
_functions: &mut IndexMap<Identifier, Function>,
tests: &mut IndexMap<Identifier, TestFunction>,
_expected: &mut Vec<FunctionInput>,
) {
let ast_annotation = annotated_definition.annotation;
@ -45,7 +45,7 @@ pub fn load_annotation(
}
}
pub fn load_annotated_test(test: TestFunction, annotation: Annotation, tests: &mut HashMap<Identifier, TestFunction>) {
pub fn load_annotated_test(test: TestFunction, annotation: Annotation, tests: &mut IndexMap<Identifier, TestFunction>) {
let name = annotation.name;
let ast_arguments = annotation.arguments;
@ -57,7 +57,7 @@ pub fn load_annotated_test(test: TestFunction, annotation: Annotation, tests: &m
pub fn load_annotated_test_context(
mut test: TestFunction,
ast_arguments: AnnotationArguments,
tests: &mut HashMap<Identifier, TestFunction>,
tests: &mut IndexMap<Identifier, TestFunction>,
) {
let arguments = ast_arguments.arguments;

View File

@ -22,7 +22,7 @@ macro_rules! input_section_impl {
#[derive(Clone, PartialEq, Eq, Default)]
pub struct $name {
is_present: bool,
values: HashMap<Parameter, Option<InputValue>>,
values: IndexMap<Parameter, Option<InputValue>>,
}
impl $name {
@ -63,8 +63,8 @@ macro_rules! input_section_impl {
Ok(())
}
/// Returns this section's hashmap of values
pub fn values(&self) -> HashMap<Parameter, Option<InputValue>> {
/// Returns this section's [IndexMap] of values
pub fn values(&self) -> IndexMap<Parameter, Option<InputValue>> {
self.values.clone()
}
}

View File

@ -16,11 +16,12 @@
use crate::InputValue;
use leo_input::{definitions::Definition, InputParserError};
use std::collections::HashMap;
use indexmap::IndexMap;
#[derive(Clone, PartialEq, Eq, Default)]
pub struct MainInput {
input: HashMap<String, Option<InputValue>>,
input: IndexMap<String, Option<InputValue>>,
}
#[allow(clippy::len_without_is_empty)]

View File

@ -17,6 +17,6 @@
use crate::{InputValue, Parameter};
use leo_input::{definitions::Definition, InputParserError};
use std::collections::HashMap;
use indexmap::IndexMap;
input_section_impl!(Registers);

View File

@ -17,6 +17,6 @@
use crate::{InputValue, Parameter};
use leo_input::{definitions::Definition, InputParserError};
use std::collections::HashMap;
use indexmap::IndexMap;
input_section_impl!(Record);

View File

@ -17,6 +17,6 @@
use crate::{InputValue, Parameter};
use leo_input::{definitions::Definition, InputParserError};
use std::collections::HashMap;
use indexmap::IndexMap;
input_section_impl!(StateLeaf);

View File

@ -17,6 +17,6 @@
use crate::{InputValue, Parameter};
use leo_input::{definitions::Definition, InputParserError};
use std::collections::HashMap;
use indexmap::IndexMap;
input_section_impl!(State);

View File

@ -20,18 +20,17 @@
use crate::{load_annotation, Circuit, Function, FunctionInput, Identifier, ImportStatement, TestFunction};
use leo_grammar::{definitions::Definition, files::File};
use indexmap::IndexMap;
use serde::{Deserialize, Serialize};
use std::collections::HashMap;
/// Stores the Leo program abstract syntax tree.
#[derive(Debug, Clone, Eq, PartialEq, Serialize, Deserialize)]
pub struct Program {
pub name: String,
pub expected_input: Vec<FunctionInput>,
pub imports: Vec<ImportStatement>,
pub circuits: HashMap<Identifier, Circuit>,
pub functions: HashMap<Identifier, Function>,
pub tests: HashMap<Identifier, TestFunction>,
pub circuits: IndexMap<Identifier, Circuit>,
pub functions: IndexMap<Identifier, Function>,
pub tests: IndexMap<Identifier, TestFunction>,
}
const MAIN_FUNCTION_NAME: &str = "main";
@ -40,9 +39,9 @@ impl<'ast> Program {
//! Logic to convert from an abstract syntax tree (ast) representation to a Leo program.
pub fn from(program_name: &str, program_ast: &File<'ast>) -> Self {
let mut imports = vec![];
let mut circuits = HashMap::new();
let mut functions = HashMap::new();
let mut tests = HashMap::new();
let mut circuits = IndexMap::new();
let mut functions = IndexMap::new();
let mut tests = IndexMap::new();
let mut expected_input = vec![];
program_ast
@ -94,9 +93,9 @@ impl Program {
name,
expected_input: vec![],
imports: vec![],
circuits: HashMap::new(),
functions: HashMap::new(),
tests: HashMap::new(),
circuits: IndexMap::new(),
functions: IndexMap::new(),
tests: IndexMap::new(),
}
}