mirror of
https://github.com/ProvableHQ/leo.git
synced 2024-12-25 11:12:48 +03:00
use index map in symbol-table module
This commit is contained in:
parent
bcaf7d3e66
commit
6797a1e046
@ -33,6 +33,10 @@ version = "1.0.6"
|
||||
path = "../imports"
|
||||
version = "1.0.6"
|
||||
|
||||
[dependencies.indexmap]
|
||||
version = "1.6.0"
|
||||
features = ["serde-1"]
|
||||
|
||||
[dependencies.serde]
|
||||
version = "1.0"
|
||||
|
||||
|
@ -19,7 +19,7 @@ use leo_ast::{Circuit, Function, Identifier, ImportStatement, ImportSymbol, Inpu
|
||||
use leo_core::CorePackageList;
|
||||
use leo_imports::ImportParser;
|
||||
|
||||
use std::collections::{HashMap, HashSet};
|
||||
use indexmap::{IndexMap, IndexSet};
|
||||
|
||||
pub const INPUT_VARIABLE_NAME: &str = "input";
|
||||
pub const RECORD_VARIABLE_NAME: &str = "record";
|
||||
@ -35,13 +35,13 @@ pub const STATE_LEAF_VARIABLE_NAME: &str = "state_leaf";
|
||||
#[derive(Clone, Default)]
|
||||
pub struct SymbolTable {
|
||||
/// Maps name -> parameter type.
|
||||
names: HashMap<String, UserDefinedType>,
|
||||
names: IndexMap<String, UserDefinedType>,
|
||||
|
||||
/// Maps circuit name -> circuit type.
|
||||
circuits: HashMap<String, CircuitType>,
|
||||
circuits: IndexMap<String, CircuitType>,
|
||||
|
||||
/// Maps function name -> function type.
|
||||
functions: HashMap<String, FunctionType>,
|
||||
functions: IndexMap<String, FunctionType>,
|
||||
|
||||
/// The parent of this symbol table.
|
||||
parent: Option<Box<SymbolTable>>,
|
||||
@ -214,7 +214,7 @@ impl SymbolTable {
|
||||
/// If a circuit name has no duplicates, then it is inserted into the symbol table.
|
||||
/// Types defined later in the program cannot have the same name.
|
||||
///
|
||||
pub fn check_circuit_names(&mut self, circuits: &HashMap<Identifier, Circuit>) -> Result<(), SymbolTableError> {
|
||||
pub fn check_circuit_names(&mut self, circuits: &IndexMap<Identifier, Circuit>) -> Result<(), SymbolTableError> {
|
||||
// Iterate over circuit names and definitions.
|
||||
for (identifier, circuit) in circuits.iter() {
|
||||
// Attempt to insert the circuit name into the symbol table.
|
||||
@ -230,7 +230,7 @@ impl SymbolTable {
|
||||
/// If a function name has no duplicates, then it is inserted into the symbol table.
|
||||
/// Types defined later in the program cannot have the same name.
|
||||
///
|
||||
pub fn check_function_names(&mut self, functions: &HashMap<Identifier, Function>) -> Result<(), SymbolTableError> {
|
||||
pub fn check_function_names(&mut self, functions: &IndexMap<Identifier, Function>) -> Result<(), SymbolTableError> {
|
||||
// Iterate over function names and definitions.
|
||||
for (identifier, function) in functions.iter() {
|
||||
// Attempt to insert the function name into the symbol table.
|
||||
@ -326,7 +326,7 @@ impl SymbolTable {
|
||||
|
||||
// Import all symbols from an imported file for now.
|
||||
// Keep track of which import files have already been checked.
|
||||
let mut checked = HashSet::new();
|
||||
let mut checked = IndexSet::new();
|
||||
|
||||
// Iterate over each imported symbol.
|
||||
for (name, symbol) in imported_symbols.symbols {
|
||||
@ -416,7 +416,7 @@ impl SymbolTable {
|
||||
/// symbol table. Variables defined later in the program can lookup the definition
|
||||
/// and refer to its expected types
|
||||
///
|
||||
pub fn check_types_circuits(&mut self, circuits: &HashMap<Identifier, Circuit>) -> Result<(), SymbolTableError> {
|
||||
pub fn check_types_circuits(&mut self, circuits: &IndexMap<Identifier, Circuit>) -> Result<(), SymbolTableError> {
|
||||
// Iterate over circuit names and definitions.
|
||||
for circuit in circuits.values() {
|
||||
// Get the identifier of the circuit.
|
||||
@ -439,7 +439,10 @@ impl SymbolTable {
|
||||
/// symbol table. Variables defined later in the program can lookup the definition
|
||||
/// and refer to its expected types
|
||||
///
|
||||
pub fn check_types_functions(&mut self, functions: &HashMap<Identifier, Function>) -> Result<(), SymbolTableError> {
|
||||
pub fn check_types_functions(
|
||||
&mut self,
|
||||
functions: &IndexMap<Identifier, Function>,
|
||||
) -> Result<(), SymbolTableError> {
|
||||
// Iterate over function names and definitions.
|
||||
for function in functions.values() {
|
||||
// Get the identifier of the function.
|
||||
|
@ -25,10 +25,9 @@ use crate::{
|
||||
use leo_ast::{Circuit, CircuitMember, Identifier, InputValue, Parameter, Span};
|
||||
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::{
|
||||
collections::HashMap,
|
||||
hash::{Hash, Hasher},
|
||||
};
|
||||
use std::hash::{Hash, Hasher};
|
||||
|
||||
use indexmap::IndexMap;
|
||||
|
||||
/// Stores circuit definition details.
|
||||
///
|
||||
@ -152,7 +151,7 @@ impl CircuitType {
|
||||
pub fn from_input_section(
|
||||
table: &SymbolTable,
|
||||
name: String,
|
||||
section: HashMap<Parameter, Option<InputValue>>,
|
||||
section: IndexMap<Parameter, Option<InputValue>>,
|
||||
) -> Result<Self, TypeError> {
|
||||
// Create a new `CircuitVariableType` for each section pair.
|
||||
let mut variables = Vec::new();
|
||||
|
Loading…
Reference in New Issue
Block a user