-
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.
Support implementing trait functions in
impl
blocks
- Loading branch information
Showing
48 changed files
with
1,769 additions
and
962 deletions.
There are no files selected for viewing
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,57 @@ | ||
use indexmap::map::Entry; | ||
use indexmap::IndexMap; | ||
use smol_str::SmolStr; | ||
|
||
use crate::context::{Analysis, AnalyzerContext}; | ||
use crate::namespace::items::{Function, FunctionId, ImplId}; | ||
use crate::namespace::scopes::ItemScope; | ||
use crate::namespace::types::TypeDowncast; | ||
use crate::AnalyzerDb; | ||
use std::rc::Rc; | ||
|
||
pub fn impl_all_functions(db: &dyn AnalyzerDb, impl_: ImplId) -> Rc<[FunctionId]> { | ||
let impl_data = impl_.data(db); | ||
impl_data | ||
.ast | ||
.kind | ||
.functions | ||
.iter() | ||
.map(|node| { | ||
db.intern_function(Rc::new(Function::new( | ||
db, | ||
node, | ||
// Not sure if setting the receiver as parent is the right thing to do. We currently do this | ||
// so that the generated name of the YUL function will take in the receiver and avoids name collisions. | ||
impl_.receiver(db).as_class(), | ||
impl_data.module, | ||
))) | ||
}) | ||
.collect() | ||
} | ||
|
||
pub fn impl_function_map( | ||
db: &dyn AnalyzerDb, | ||
impl_: ImplId, | ||
) -> Analysis<Rc<IndexMap<SmolStr, FunctionId>>> { | ||
let scope = ItemScope::new(db, impl_.module(db)); | ||
let mut map = IndexMap::<SmolStr, FunctionId>::new(); | ||
|
||
for func in db.impl_all_functions(impl_).iter() { | ||
let def_name = func.name(db); | ||
|
||
match map.entry(def_name) { | ||
Entry::Occupied(entry) => { | ||
scope.duplicate_name_error( | ||
"duplicate function names in `impl` block", | ||
entry.key(), | ||
entry.get().name_span(db), | ||
func.name_span(db), | ||
); | ||
} | ||
Entry::Vacant(entry) => { | ||
entry.insert(*func); | ||
} | ||
} | ||
} | ||
Analysis::new(Rc::new(map), scope.diagnostics.take().into()) | ||
} |
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.