-
Notifications
You must be signed in to change notification settings - Fork 556
/
Copy pathmod.rs
65 lines (58 loc) · 2.05 KB
/
mod.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#[cfg(test)]
mod test;
pub mod consts;
use std::sync::Arc;
use cairo_lang_defs::plugin::{MacroPlugin, PluginResult};
use cairo_lang_semantic::plugin::{AsDynMacroPlugin, SemanticPlugin};
use cairo_lang_syntax::node::ast;
use cairo_lang_syntax::node::db::SyntaxGroup;
use cairo_lang_syntax::node::helpers::QueryAttrs;
use consts::*;
pub mod aux_data;
mod contract;
mod dispatcher;
mod entry_point;
pub mod events;
mod storage;
mod storage_access;
mod utils;
use dispatcher::handle_trait;
use events::derive_event_needed;
use storage_access::derive_storage_access_needed;
use self::contract::{handle_contract_by_storage, handle_module};
use self::events::handle_enum;
#[derive(Debug, Default)]
#[non_exhaustive]
pub struct StarkNetPlugin;
impl MacroPlugin for StarkNetPlugin {
fn generate_code(&self, db: &dyn SyntaxGroup, item_ast: ast::Item) -> PluginResult {
match item_ast {
ast::Item::Module(module_ast) => handle_module(db, module_ast),
ast::Item::Trait(trait_ast) => handle_trait(db, trait_ast),
ast::Item::Struct(struct_ast) if derive_event_needed(&struct_ast, db) => {
events::handle_struct(db, struct_ast)
}
ast::Item::Struct(struct_ast) if derive_storage_access_needed(&struct_ast, db) => {
storage_access::handle_struct(db, struct_ast)
}
ast::Item::Struct(struct_ast) if struct_ast.has_attr(db, STORAGE_ATTR) => {
handle_contract_by_storage(db, struct_ast).unwrap_or_default()
}
ast::Item::Enum(enum_ast) if derive_storage_access_needed(&enum_ast, db) => {
storage_access::handle_enum(db, enum_ast)
}
ast::Item::Enum(enum_ast) => handle_enum(db, enum_ast),
// Nothing to do for other items.
_ => PluginResult::default(),
}
}
}
impl AsDynMacroPlugin for StarkNetPlugin {
fn as_dyn_macro_plugin<'a>(self: Arc<Self>) -> Arc<dyn MacroPlugin + 'a>
where
Self: 'a,
{
self
}
}
impl SemanticPlugin for StarkNetPlugin {}