-
Notifications
You must be signed in to change notification settings - Fork 187
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move tuple and list expr collection from analyzer to lowering
- Loading branch information
Showing
121 changed files
with
328 additions
and
508 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
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 |
---|---|---|
@@ -0,0 +1,66 @@ | ||
use fe_analyzer::context::Context as AnalyzerContext; | ||
use fe_analyzer::namespace::types::{Array, Tuple}; | ||
use indexmap::IndexMap; | ||
use std::collections::BTreeSet; | ||
|
||
pub struct ModuleContext<'a> { | ||
pub analysis: &'a AnalyzerContext, | ||
|
||
/// Tuples that were used inside of a module, | ||
/// and the generated name of the resulting struct. | ||
tuple_structs: IndexMap<Tuple, String>, | ||
|
||
/// Holds fresh id for [`ModuleContext::make_unique_name`] | ||
fresh_id: u64, | ||
} | ||
|
||
impl<'a> ModuleContext<'a> { | ||
pub fn new(analysis: &'a AnalyzerContext) -> Self { | ||
Self { | ||
analysis, | ||
tuple_structs: IndexMap::new(), | ||
fresh_id: 0, | ||
} | ||
} | ||
|
||
/// Makes a unique name from the given name, keeping it as readable as possible. | ||
pub fn make_unique_name(&mut self, name: &str) -> String { | ||
let id = self.fresh_id; | ||
self.fresh_id += 1; | ||
format!("${}_{}", name, id) | ||
} | ||
|
||
/// Returns generated struct name for tuple. | ||
pub fn add_tuple(&mut self, tuple: Tuple) -> &str { | ||
let entry = self.tuple_structs.entry(tuple.clone()); | ||
let index = entry.index(); | ||
entry.or_insert_with(|| format!("__Tuple{}", index)) | ||
} | ||
|
||
// Panics if the given tuple hasn't been added via [`add_tuple`] | ||
pub fn tuple_struct_name(&self, tuple: &Tuple) -> &str { | ||
self.tuple_structs | ||
.get(tuple) | ||
.expect("tuple not added to context") | ||
} | ||
|
||
pub fn iter_tuples(&self) -> impl Iterator<Item = &Tuple> { | ||
self.tuple_structs.iter().map(|(typ, _name)| typ) | ||
} | ||
} | ||
|
||
// This is contract context, but it's used all over so it has a short name. | ||
pub struct Context<'a, 'b> { | ||
pub module: &'a mut ModuleContext<'b>, | ||
/// List expressions that the contract uses | ||
pub list_expressions: BTreeSet<Array>, | ||
} | ||
|
||
impl<'a, 'b> Context<'a, 'b> { | ||
pub fn new(module: &'a mut ModuleContext<'b>) -> Self { | ||
Self { | ||
module, | ||
list_expressions: BTreeSet::new(), | ||
} | ||
} | ||
} |
Oops, something went wrong.