-
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.
- Loading branch information
Showing
15 changed files
with
509 additions
and
58 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
102 changes: 102 additions & 0 deletions
102
crates/analyzer/tests/snapshots/analysis__module_level_events.snap
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 @@ | ||
--- | ||
source: crates/analyzer/tests/analysis.rs | ||
expression: "build_snapshot(&files, module_id, &db)" | ||
|
||
--- | ||
note: | ||
┌─ features/module_level_events.fe:2:5 | ||
│ | ||
2 │ idx sender: address | ||
│ ^^^^^^^^^^^^^^^^^^^ address | ||
3 │ idx receiver: address | ||
│ ^^^^^^^^^^^^^^^^^^^^^ address | ||
4 │ value: u256 | ||
│ ^^^^^^^^^^^ u256 | ||
|
||
note: | ||
┌─ features/module_level_events.fe:6:5 | ||
│ | ||
6 │ ╭ fn transfer(to : address, value : u256): | ||
7 │ │ emit Transfer(sender=msg.sender, receiver=to, value) | ||
│ ╰────────────────────────────────────────────────────────────^ attributes hash: 5430479256040439660 | ||
│ | ||
= FunctionSignature { | ||
self_decl: None, | ||
params: [ | ||
FunctionParam { | ||
name: "to", | ||
typ: Ok( | ||
Base( | ||
Address, | ||
), | ||
), | ||
}, | ||
FunctionParam { | ||
name: "value", | ||
typ: Ok( | ||
Base( | ||
Numeric( | ||
U256, | ||
), | ||
), | ||
), | ||
}, | ||
], | ||
return_type: Ok( | ||
Base( | ||
Unit, | ||
), | ||
), | ||
} | ||
|
||
note: | ||
┌─ features/module_level_events.fe:7:30 | ||
│ | ||
7 │ emit Transfer(sender=msg.sender, receiver=to, value) | ||
│ ^^^^^^^^^^ ^^ ^^^^^ u256: Value | ||
│ │ │ | ||
│ │ address: Value | ||
│ address: Value | ||
|
||
note: | ||
┌─ features/module_level_events.fe:7:9 | ||
│ | ||
7 │ emit Transfer(sender=msg.sender, receiver=to, value) | ||
│ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ attributes hash: 17986960071624595337 | ||
│ | ||
= Event { | ||
name: "Transfer", | ||
fields: [ | ||
EventField { | ||
name: "sender", | ||
typ: Ok( | ||
Base( | ||
Address, | ||
), | ||
), | ||
is_indexed: true, | ||
}, | ||
EventField { | ||
name: "receiver", | ||
typ: Ok( | ||
Base( | ||
Address, | ||
), | ||
), | ||
is_indexed: true, | ||
}, | ||
EventField { | ||
name: "value", | ||
typ: Ok( | ||
Base( | ||
Numeric( | ||
U256, | ||
), | ||
), | ||
), | ||
is_indexed: false, | ||
}, | ||
], | ||
} | ||
|
||
|
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,43 @@ | ||
use crate::context::ModuleContext; | ||
use crate::mappers::types; | ||
use crate::utils::ZeroSpanNode; | ||
use fe_analyzer::namespace::items::EventId; | ||
use fe_parser::ast; | ||
use fe_parser::node::Node; | ||
|
||
pub fn event_def(context: &mut ModuleContext, event: EventId) -> Node<ast::Event> { | ||
let ast_fields = &event.data(context.db).ast.kind.fields; | ||
let fields = event | ||
.typ(context.db) | ||
.fields | ||
.iter() | ||
.zip(ast_fields.iter()) | ||
.map(|(field, node)| { | ||
ast::EventField { | ||
is_idx: field.is_indexed, | ||
name: field.name.clone().into_node(), | ||
typ: types::type_desc( | ||
context, | ||
node.kind.typ.clone(), | ||
&field | ||
.typ | ||
.as_ref() | ||
.expect("event field type error") | ||
.clone() | ||
.into(), | ||
), | ||
} | ||
.into_node() | ||
}) | ||
.collect(); | ||
|
||
let node = &event.data(context.db).ast; | ||
Node::new( | ||
ast::Event { | ||
name: node.kind.name.clone(), | ||
fields, | ||
pub_qual: None, | ||
}, | ||
node.span, | ||
) | ||
} |
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,4 +1,5 @@ | ||
mod contracts; | ||
mod events; | ||
mod expressions; | ||
mod functions; | ||
pub mod module; | ||
|
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
14 changes: 14 additions & 0 deletions
14
crates/lowering/tests/snapshots/lowering__module_level_events.snap
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,14 @@ | ||
--- | ||
source: crates/lowering/tests/lowering.rs | ||
expression: lowered_code | ||
|
||
--- | ||
event Transfer: | ||
idx sender: address | ||
idx receiver: address | ||
value: u256 | ||
|
||
contract Foo: | ||
fn transfer(to: address, value: u256) -> (): | ||
emit Transfer(sender=msg.sender, receiver=to, value) | ||
return () |
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.