mirror of
https://github.com/ProvableHQ/leo.git
synced 2024-11-23 23:23:50 +03:00
Updated test-framework/.../tgc.rs to remove spans from AST; changed compiler test options to disable spans
This commit is contained in:
parent
4514dbb390
commit
f754f89c6e
@ -246,10 +246,10 @@ impl<'a, F: PrimeField, G: GroupType<F>> Compiler<'a, F, G> {
|
||||
let mut ast: leo_ast::Ast = parse_ast(self.main_file_path.to_str().unwrap_or_default(), program_string)?;
|
||||
|
||||
if self.ast_snapshot_options.initial {
|
||||
if !self.ast_snapshot_options.spans_enabled {
|
||||
ast.to_json_file_without_keys(self.output_directory.clone(), "initial_ast.json", &["span"])?;
|
||||
} else {
|
||||
if self.ast_snapshot_options.spans_enabled {
|
||||
ast.to_json_file(self.output_directory.clone(), "initial_ast.json")?;
|
||||
} else {
|
||||
ast.to_json_file_without_keys(self.output_directory.clone(), "initial_ast.json", &["span"])?;
|
||||
}
|
||||
}
|
||||
|
||||
@ -260,10 +260,10 @@ impl<'a, F: PrimeField, G: GroupType<F>> Compiler<'a, F, G> {
|
||||
)?;
|
||||
|
||||
if self.ast_snapshot_options.imports_resolved {
|
||||
if !self.ast_snapshot_options.spans_enabled {
|
||||
ast.to_json_file_without_keys(self.output_directory.clone(), "imports_resolved.json", &["span"])?;
|
||||
} else {
|
||||
if self.ast_snapshot_options.spans_enabled {
|
||||
ast.to_json_file(self.output_directory.clone(), "imports_resolved_ast.json")?;
|
||||
} else {
|
||||
ast.to_json_file_without_keys(self.output_directory.clone(), "imports_resolved_ast.json", &["span"])?;
|
||||
}
|
||||
}
|
||||
|
||||
@ -271,10 +271,10 @@ impl<'a, F: PrimeField, G: GroupType<F>> Compiler<'a, F, G> {
|
||||
ast = leo_ast_passes::Canonicalizer::do_pass(ast.into_repr())?;
|
||||
|
||||
if self.ast_snapshot_options.canonicalized {
|
||||
if !self.ast_snapshot_options.spans_enabled {
|
||||
ast.to_json_file_without_keys(self.output_directory.clone(), "canonicalization_ast.json", &["span"])?;
|
||||
} else {
|
||||
if self.ast_snapshot_options.spans_enabled {
|
||||
ast.to_json_file(self.output_directory.clone(), "canonicalization_ast.json")?;
|
||||
} else {
|
||||
ast.to_json_file_without_keys(self.output_directory.clone(), "canonicalization_ast.json", &["span"])?;
|
||||
}
|
||||
}
|
||||
|
||||
@ -292,14 +292,14 @@ impl<'a, F: PrimeField, G: GroupType<F>> Compiler<'a, F, G> {
|
||||
.phase_ast(&self.program, &asg.clone().into_repr())
|
||||
.expect("Failed to produce type inference ast.");
|
||||
|
||||
if !self.ast_snapshot_options.spans_enabled {
|
||||
if self.ast_snapshot_options.spans_enabled {
|
||||
new_ast.to_json_file(self.output_directory.clone(), "type_inferenced_ast.json")?;
|
||||
} else {
|
||||
new_ast.to_json_file_without_keys(
|
||||
self.output_directory.clone(),
|
||||
"type_inferenced_ast.json",
|
||||
&["span"],
|
||||
)?;
|
||||
} else {
|
||||
new_ast.to_json_file(self.output_directory.clone(), "type_inferenced_ast.json")?;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -118,7 +118,7 @@ impl Namespace for CompileNamespace {
|
||||
let parsed = parse_program(
|
||||
&test.content,
|
||||
Some(AstSnapshotOptions {
|
||||
spans_enabled: true,
|
||||
spans_enabled: false,
|
||||
initial: true,
|
||||
imports_resolved: true,
|
||||
canonicalized: true,
|
||||
|
@ -114,40 +114,29 @@ fn run_with_args(opt: Opt) -> Result<(), Box<dyn Error>> {
|
||||
// Do this to match test-framework ast bc of spans
|
||||
let text = &text[end_of_header + 2..];
|
||||
// Write all files into the directory.
|
||||
let (initial, imports_resolved, canonicalized, type_inferenced) = generate_asts(cwd, text)?;
|
||||
|
||||
target.push("initial_ast.json");
|
||||
fs::write(target.clone(), initial)?;
|
||||
target.pop();
|
||||
|
||||
target.push("imports_resolved_ast.json");
|
||||
fs::write(target.clone(), imports_resolved)?;
|
||||
target.pop();
|
||||
|
||||
target.push("canonicalization_ast.json");
|
||||
fs::write(target.clone(), canonicalized)?;
|
||||
target.pop();
|
||||
|
||||
target.push("type_inferenced_ast.json");
|
||||
fs::write(target.clone(), type_inferenced)?;
|
||||
generate_asts(cwd, target, text)?;
|
||||
}
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Do what Compiler does - prepare 3 stages of AST: initial, canonicalized and type_inferenced
|
||||
fn generate_asts(path: PathBuf, text: &str) -> Result<(String, String, String, String), Box<dyn Error>> {
|
||||
/// Do what Compiler does - prepare 3 stages of AST: initial, imports_resolved, canonicalized and type_inferenced
|
||||
/// Write these ASTs without Spans to JSON
|
||||
fn generate_asts(src_path: PathBuf, target_path: PathBuf, text: &str) -> Result<(), Box<dyn Error>> {
|
||||
std::env::set_var("LEO_TESTFRAMEWORK", "true");
|
||||
|
||||
let mut ast = leo_parser::parse_ast(path.clone().into_os_string().into_string().unwrap(), text)?;
|
||||
let initial = ast.to_json_string()?;
|
||||
let mut ast = leo_parser::parse_ast(src_path.clone().into_os_string().into_string().unwrap(), text)?;
|
||||
|
||||
ast = leo_ast_passes::Importer::do_pass(ast.into_repr(), &mut ImportParser::new(path, Default::default()))?;
|
||||
let imports_resolved = ast.to_json_string()?;
|
||||
ast.to_json_file_without_keys(target_path.clone(), "initial_ast.json", &["span"])?;
|
||||
|
||||
ast = leo_ast_passes::Importer::do_pass(ast.into_repr(), &mut ImportParser::new(src_path, Default::default()))?;
|
||||
|
||||
ast.to_json_file_without_keys(target_path.clone(), "imports_resolved_ast.json", &["span"])?;
|
||||
|
||||
ast = leo_ast_passes::Canonicalizer::do_pass(ast.into_repr())?;
|
||||
let canonicalized = ast.to_json_string()?;
|
||||
|
||||
ast.to_json_file_without_keys(target_path.clone(), "canonicalization_ast.json", &["span"])?;
|
||||
|
||||
let mut ti_ast = ast.into_repr();
|
||||
ti_ast.name = "test".to_string(); // Do this to match test-framework ast
|
||||
@ -156,12 +145,13 @@ fn generate_asts(path: PathBuf, text: &str) -> Result<(String, String, String, S
|
||||
|
||||
let type_inferenced = TypeInferencePhase::default()
|
||||
.phase_ast(&ti_ast, &asg.clone().into_repr())
|
||||
.expect("Failed to produce type inference ast.")
|
||||
.to_json_string()?;
|
||||
.expect("Failed to produce type inference ast.");
|
||||
|
||||
type_inferenced.to_json_file_without_keys(target_path, "type_inferenced_ast.json", &["span"])?;
|
||||
|
||||
std::env::remove_var("LEO_TESTFRAMEWORK");
|
||||
|
||||
Ok((initial, imports_resolved, canonicalized, type_inferenced))
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn handle_error(res: Result<(), Box<dyn Error>>) {
|
||||
|
Loading…
Reference in New Issue
Block a user