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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
//
// Copyright (c) DUSK NETWORK. All rights reserved.
//! Procedural macro for the `#[contract]` attribute.
//!
//! This macro is applied to a module containing a contract struct and its
//! impl block. It extracts metadata about public methods and events, and
//! generates a `CONTRACT_SCHEMA` constant plus extern "C" wrappers.
//!
//! # Pipeline
//!
//! 1. [`parse::analyze`] walks the user module and produces an
//! [`parse::Analysis`] (functions, registered events, imports, contract
//! identifier).
//! 2. [`generate`] / [`data_driver`] consume the analysis and emit the contract
//! or data-driver bindings.
//!
//! `lib.rs` only orchestrates these two phases — all walking, validation,
//! and IR construction lives in the `parse` module.
//!
//! # Example
//!
//! ```ignore
//! #[contract]
//! mod my_contract {
//! use my_crate::MyType;
//! use dusk_core::abi;
//!
//! pub struct MyContract {
//! value: u64,
//! }
//!
//! impl MyContract {
//! pub fn set_value(&mut self, value: MyType) {
//! // ...
//! }
//! }
//! }
//! ```
use TokenStream;
use ;
/// The main contract proc macro.
///
/// Applied to a module containing a contract struct and impl block.
/// Extracts metadata and generates schema + extern wrappers.
///
/// # Errors
///
/// This macro will produce compile errors if:
/// - The module has no content (just a declaration like `mod foo;`)
/// - The module contains glob imports (`use foo::*`)
/// - The module contains relative imports (`use self::`, `use super::`, `use
/// crate::`)
/// - The module contains multiple `pub struct` declarations
/// - The module contains no `pub struct`
/// - The module contains no impl block for the contract struct
/// - A public method has no `self` receiver (associated functions)
/// - A public method has generic type or const parameters
/// - A public method is async
/// - A public method consumes `self` instead of borrowing it
/// - A public method uses `impl Trait` in parameters or return type