-
Notifications
You must be signed in to change notification settings - Fork 188
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Grant Wuerker
committed
Jun 4, 2024
1 parent
70fca41
commit 50bdc7a
Showing
23 changed files
with
513 additions
and
38 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
use crate::{load_ingot, set_src_files, CheckArgs}; | ||
use common::input::{IngotDependency, InputFile}; | ||
use common::{input::IngotKind, InputDb, InputIngot}; | ||
use fe_driver2::DriverDataBase; | ||
use semver::Version; | ||
use std::fs; | ||
use std::{collections::BTreeSet, path::Path}; | ||
|
||
pub fn run_check(args: &CheckArgs) { | ||
let std_path = Path::new(&args.std_path); | ||
if !std_path.exists() { | ||
eprintln!( | ||
"Standard library path '{}' does not exist", | ||
std_path.display() | ||
); | ||
std::process::exit(2); | ||
} | ||
|
||
let path = Path::new(&args.path); | ||
if !path.exists() { | ||
eprintln!("Path '{}' does not exist", path.display()); | ||
std::process::exit(2); | ||
} | ||
|
||
let mut db = DriverDataBase::default(); | ||
|
||
let std_ingot = load_ingot(&std_path, &mut db, IngotKind::Std, &mut BTreeSet::new()); | ||
|
||
if path.is_file() { | ||
let source = fs::read_to_string(path).unwrap(); | ||
check_single_file(path, source, std_ingot, &mut db, args.dump_scope_graph); | ||
} else if path.is_dir() { | ||
check_ingot(path, std_ingot, &mut db, args.dump_scope_graph); | ||
} else { | ||
eprintln!( | ||
"Path '{}' is neither a file nor a directory", | ||
path.display() | ||
); | ||
std::process::exit(2); | ||
} | ||
} | ||
|
||
pub fn check_single_file( | ||
path: &Path, | ||
source: String, | ||
std_ingot: InputIngot, | ||
db: &mut DriverDataBase, | ||
dump_scope_graph: bool, | ||
) { | ||
let mut dependencies = BTreeSet::from([IngotDependency::new("std", std_ingot)]); | ||
let ingot = InputIngot::new( | ||
db, | ||
path.parent().unwrap().to_str().unwrap(), | ||
IngotKind::StandAlone, | ||
Version::new(0, 1, 0), | ||
dependencies.clone(), | ||
); | ||
|
||
// let input_file = InputFile::new( | ||
// db, | ||
// ingot.clone(), | ||
// path.file_name().unwrap().to_str().unwrap().into(), | ||
// source, | ||
// ); | ||
// ingot.set_files(db, BTreeSet::from([input_file.clone()])); | ||
// ingot.set_root_file(db, input_file); | ||
|
||
let top_mod = db.top_mod_from_file(path, &source); | ||
db.run_on_top_mod(top_mod); | ||
db.emit_diags(); | ||
|
||
// if dump_scope_graph { | ||
// println!("{}", dump_scope_graph(db, top_mod)); | ||
// } | ||
} | ||
|
||
pub fn check_ingot( | ||
path: &Path, | ||
std_ingot: InputIngot, | ||
db: &mut DriverDataBase, | ||
dump_scope_graph: bool, | ||
) { | ||
let mut dependencies = BTreeSet::from([IngotDependency::new("std", std_ingot)]); | ||
let mut main_ingot = load_ingot(path, db, IngotKind::Local, &mut dependencies); | ||
|
||
main_ingot.set_external_ingots(db, dependencies); | ||
|
||
db.run_on_ingot(std_ingot); | ||
|
||
let diags = db.format_diags(); | ||
if !diags.is_empty() { | ||
panic!("{diags}") | ||
} | ||
|
||
// let top_mod = db.top_mod_from_ingot(main_ingot); | ||
// db.run_on_top_mod(top_mod); | ||
// db.emit_diags(); | ||
|
||
// if dump_scope_graph { | ||
// println!("{}", dump_scope_graph(db, top_mod)); | ||
// } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.