mirror of
https://github.com/ProvableHQ/leo.git
synced 2024-11-28 01:01:53 +03:00
impl dynamic checks for imports. all tests pass
This commit is contained in:
parent
09d86576ea
commit
020773fb2a
@ -1,55 +0,0 @@
|
||||
// // Copyright (C) 2019-2020 Aleo Systems Inc.
|
||||
// // This file is part of the Leo library.
|
||||
//
|
||||
// // The Leo library is free software: you can redistribute it and/or modify
|
||||
// // it under the terms of the GNU General Public License as published by
|
||||
// // the Free Software Foundation, either version 3 of the License, or
|
||||
// // (at your option) any later version.
|
||||
//
|
||||
// // The Leo library is distributed in the hope that it will be useful,
|
||||
// // but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// // GNU General Public License for more details.
|
||||
//
|
||||
// // You should have received a copy of the GNU General Public License
|
||||
// // along with the Leo library. If not, see <https://www.gnu.org/licenses/>.
|
||||
//
|
||||
// use leo_typed::{ImportStatement, ImportSymbol, Package, PackageAccess};
|
||||
//
|
||||
// /// Stores the the package file name and imported symbol from an import statement
|
||||
// #[derive(Debug)]
|
||||
// pub(crate) struct ImportedSymbols {
|
||||
// pub symbols: Vec<(String, ImportSymbol)>,
|
||||
// }
|
||||
//
|
||||
// impl ImportedSymbols {
|
||||
// fn new() -> Self {
|
||||
// Self { symbols: vec![] }
|
||||
// }
|
||||
//
|
||||
// pub(crate) fn from(import: &ImportStatement) -> Self {
|
||||
// let mut symbols = Self::new();
|
||||
//
|
||||
// symbols.from_package(&import.package);
|
||||
//
|
||||
// symbols
|
||||
// }
|
||||
//
|
||||
// fn from_package(&mut self, package: &Package) {
|
||||
// self.from_package_access(package.name.name.clone(), &package.access);
|
||||
// }
|
||||
//
|
||||
// fn from_package_access(&mut self, package: String, access: &PackageAccess) {
|
||||
// match access {
|
||||
// PackageAccess::SubPackage(package) => self.from_package(package),
|
||||
// PackageAccess::Star(span) => {
|
||||
// let star = ImportSymbol::star(span);
|
||||
// self.symbols.push((package, star));
|
||||
// }
|
||||
// PackageAccess::Symbol(symbol) => self.symbols.push((package, symbol.clone())),
|
||||
// PackageAccess::Multiple(packages) => packages
|
||||
// .iter()
|
||||
// .for_each(|access| self.from_package_access(package.clone(), access)),
|
||||
// }
|
||||
// }
|
||||
// }
|
@ -21,7 +21,5 @@ pub use self::core_package::*;
|
||||
pub mod import;
|
||||
pub use self::import::*;
|
||||
|
||||
// pub mod imported_symbols;
|
||||
|
||||
pub mod symbol;
|
||||
pub use self::symbol::*;
|
||||
|
@ -1293,8 +1293,6 @@ impl Frame {
|
||||
continue;
|
||||
}
|
||||
|
||||
println!("assertion: {:?}", type_assertion);
|
||||
|
||||
// Collect `TypeVariablePairs` from the `TypeAssertion`.
|
||||
let pairs = type_assertion.pairs()?;
|
||||
|
||||
|
@ -104,12 +104,8 @@ impl StaticCheck {
|
||||
/// refer to its expected types.
|
||||
///
|
||||
pub fn pass_two(&mut self, program: &Program) -> Result<(), StaticCheckError> {
|
||||
// Check unresolved program circuit definitions.
|
||||
self.table.check_unknown_types_circuits(&program.circuits)?;
|
||||
|
||||
// Check unresolved program function definitions.
|
||||
self.table.check_unknown_types_functions(&program.functions)?;
|
||||
|
||||
Ok(())
|
||||
self.table
|
||||
.check_unknown_types_program(program)
|
||||
.map_err(|err| StaticCheckError::SymbolTableError(err))
|
||||
}
|
||||
}
|
||||
|
@ -69,7 +69,6 @@ impl SymbolTable {
|
||||
/// variable type is returned.
|
||||
///
|
||||
pub fn insert_name(&mut self, name: String, variable_type: ParameterType) -> Option<ParameterType> {
|
||||
println!("name: {}", name);
|
||||
self.names.insert(name, variable_type)
|
||||
}
|
||||
|
||||
@ -296,9 +295,12 @@ impl SymbolTable {
|
||||
.get_import(&name)
|
||||
.ok_or_else(|| SymbolTableError::unknown_package(&name, &symbol.span))?;
|
||||
|
||||
// Check the imported program.
|
||||
// Check the imported program for duplicate types.
|
||||
self.check_duplicate_program(program, import_parser)?;
|
||||
|
||||
// Check the imported program for undefined types.
|
||||
self.check_unknown_types_program(program)?;
|
||||
|
||||
// Push the imported file's name to checked import files.
|
||||
checked.push(name);
|
||||
|
||||
@ -354,17 +356,6 @@ impl SymbolTable {
|
||||
return self.insert_core_package(package);
|
||||
}
|
||||
|
||||
// // Get the import file name from the import statement.
|
||||
// let import_file_name = import.get_file_name();
|
||||
//
|
||||
// // Check if the import file name exists in the import parser.
|
||||
// let program = import_parser
|
||||
// .get_import(&import_file_name)
|
||||
// .ok_or_else(|| SymbolTableError::unknown_package(import_file_name, &import.span))?;
|
||||
//
|
||||
// // Check the imported file.
|
||||
// self.check_duplicate_program(program, import_parser)?;
|
||||
|
||||
// Attempt to insert the imported names into the symbol table.
|
||||
self.insert_import(import, import_parser)
|
||||
}
|
||||
@ -449,6 +440,23 @@ impl SymbolTable {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
///
|
||||
/// Checks for unknown types in circuit and function definitions given an unresolved program.
|
||||
///
|
||||
/// If a circuit or function definition only contains known types, then it is inserted into the
|
||||
/// symbol table. Variables defined later in the unresolved program can lookup the definition and
|
||||
/// refer to its expected types.
|
||||
///
|
||||
pub fn check_unknown_types_program(&mut self, program: &Program) -> Result<(), SymbolTableError> {
|
||||
// Check unresolved program circuit definitions.
|
||||
self.check_unknown_types_circuits(&program.circuits)?;
|
||||
|
||||
// Check unresolved program function definitions.
|
||||
self.check_unknown_types_functions(&program.functions)?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
///
|
||||
/// Checks for unknown types in a circuit given a hashmap of circuits.
|
||||
///
|
||||
|
Loading…
Reference in New Issue
Block a user