forked from ethereum/fe
-
Notifications
You must be signed in to change notification settings - Fork 0
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
Showing
77 changed files
with
2,425 additions
and
747 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
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 |
---|---|---|
@@ -1,6 +1,7 @@ | ||
pub mod contracts; | ||
pub mod events; | ||
pub mod functions; | ||
pub mod ingots; | ||
pub mod module; | ||
pub mod structs; | ||
pub mod types; |
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,105 @@ | ||
use crate::context::Analysis; | ||
use crate::namespace::items::{IngotId, Module, ModuleContext, ModuleFileContent, ModuleId}; | ||
use crate::AnalyzerDb; | ||
use fe_common::diagnostics::{Diagnostic, Severity}; | ||
use fe_parser::ast; | ||
use indexmap::set::IndexSet; | ||
use std::path::Path; | ||
use std::rc::Rc; | ||
|
||
pub fn ingot_all_modules(db: &dyn AnalyzerDb, ingot_id: IngotId) -> Rc<Vec<ModuleId>> { | ||
let ingot = &ingot_id.data(db); | ||
|
||
let file_modules = ingot | ||
.fe_files | ||
.values() | ||
.into_iter() | ||
.map(|(file, ast)| { | ||
let module = Module { | ||
name: Path::new(&file.name) | ||
.file_stem() | ||
.expect("file does not have stem") | ||
.to_str() | ||
.expect("could not convert file stem to string") | ||
.to_string(), | ||
ast: ast.clone(), | ||
file_content: ModuleFileContent::File { file: file.id }, | ||
context: ModuleContext::Ingot(ingot_id), | ||
}; | ||
|
||
db.intern_module(Rc::new(module)) | ||
}) | ||
.collect::<Vec<_>>(); | ||
|
||
let dir_modules = ingot | ||
.fe_files | ||
.values() | ||
.into_iter() | ||
.map(|(file, _)| { | ||
Path::new(&file.name) | ||
.parent() | ||
.expect("file does not have parent path") | ||
}) | ||
.collect::<IndexSet<_>>() | ||
.into_iter() | ||
.map(|dir| { | ||
let module = Module { | ||
name: dir | ||
.file_name() | ||
.expect("missing file name") | ||
.to_str() | ||
.expect("could not convert dir name to string") | ||
.to_string(), | ||
ast: ast::Module { body: vec![] }, | ||
context: ModuleContext::Ingot(ingot_id), | ||
file_content: ModuleFileContent::Dir { | ||
dir_path: dir | ||
.to_str() | ||
.expect("could not convert dir path to string") | ||
.to_string(), | ||
}, | ||
}; | ||
|
||
db.intern_module(Rc::new(module)) | ||
}) | ||
.collect::<Vec<ModuleId>>(); | ||
|
||
let all_modules = [file_modules, dir_modules].concat(); | ||
Rc::new(all_modules) | ||
} | ||
|
||
pub fn ingot_main_module(db: &dyn AnalyzerDb, ingot_id: IngotId) -> Analysis<Option<ModuleId>> { | ||
let main_id = ingot_id | ||
.all_modules(db) | ||
.iter() | ||
.find(|module_id| { | ||
module_id.name(db) == "main" && { | ||
if let Some(parent_id) = module_id.parent_module(db) { | ||
parent_id.name(db) == "src" | ||
} else { | ||
false | ||
} | ||
} | ||
}) | ||
.copied(); | ||
|
||
Analysis { | ||
value: main_id, | ||
diagnostics: Rc::new({ | ||
if main_id.is_none() { | ||
vec![Diagnostic { | ||
severity: Severity::Error, | ||
message: format!( | ||
"The ingot named \"{}\" is missing a main module. \ | ||
\nPlease add a `src/main.fe` file to the base directory.", | ||
ingot_id.name(db) | ||
), | ||
labels: vec![], | ||
notes: vec![], | ||
}] | ||
} else { | ||
vec![] | ||
} | ||
}), | ||
} | ||
} |
Oops, something went wrong.