1// Copyright (C) Parity Technologies (UK) Ltd.
2// This file is part of Polkadot.
34// Polkadot is free software: you can redistribute it and/or modify
5// it under the terms of the GNU General Public License as published by
6// the Free Software Foundation, either version 3 of the License, or
7// (at your option) any later version.
89// Polkadot is distributed in the hope that it will be useful,
10// but WITHOUT ANY WARRANTY; without even the implied warranty of
11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12// GNU General Public License for more details.
1314// You should have received a copy of the GNU General Public License
15// along with Polkadot. If not, see <http://www.gnu.org/licenses/>.
1617//! Procedural macros used in XCM.
1819use proc_macro::TokenStream;
20use syn::{parse_macro_input, DeriveInput};
2122mod builder_pattern;
23mod enum_variants;
24mod v3;
25mod v4;
26mod v5;
27mod weight_info;
2829#[proc_macro_derive(XcmWeightInfoTrait)]
30pub fn derive_xcm_weight_info(item: TokenStream) -> TokenStream {
31 weight_info::derive(item)
32}
3334#[proc_macro]
35pub fn impl_conversion_functions_for_multilocation_v3(input: TokenStream) -> TokenStream {
36 v3::multilocation::generate_conversion_functions(input)
37 .unwrap_or_else(syn::Error::into_compile_error)
38 .into()
39}
4041#[proc_macro]
42pub fn impl_conversion_functions_for_junctions_v3(input: TokenStream) -> TokenStream {
43 v3::junctions::generate_conversion_functions(input)
44 .unwrap_or_else(syn::Error::into_compile_error)
45 .into()
46}
4748#[proc_macro]
49pub fn impl_conversion_functions_for_location_v4(input: TokenStream) -> TokenStream {
50 v4::location::generate_conversion_functions(input)
51 .unwrap_or_else(syn::Error::into_compile_error)
52 .into()
53}
5455#[proc_macro]
56pub fn impl_conversion_functions_for_junctions_v4(input: TokenStream) -> TokenStream {
57 v4::junctions::generate_conversion_functions(input)
58 .unwrap_or_else(syn::Error::into_compile_error)
59 .into()
60}
6162#[proc_macro]
63pub fn impl_conversion_functions_for_junctions_v5(input: TokenStream) -> TokenStream {
64 v5::junctions::generate_conversion_functions(input)
65 .unwrap_or_else(syn::Error::into_compile_error)
66 .into()
67}
6869#[proc_macro]
70pub fn impl_conversion_functions_for_location_v5(input: TokenStream) -> TokenStream {
71 v5::location::generate_conversion_functions(input)
72 .unwrap_or_else(syn::Error::into_compile_error)
73 .into()
74}
7576/// This is called on the `Instruction` enum, not on the `Xcm` struct,
77/// and allows for the following syntax for building XCMs:
78/// let message = Xcm::builder()
79/// .withdraw_asset(assets)
80/// .buy_execution(fees, weight_limit)
81/// .deposit_asset(assets, beneficiary)
82/// .build();
83#[proc_macro_derive(Builder, attributes(builder))]
84pub fn derive_builder(input: TokenStream) -> TokenStream {
85let input = parse_macro_input!(input as DeriveInput);
86 builder_pattern::derive(input)
87 .unwrap_or_else(syn::Error::into_compile_error)
88 .into()
89}
9091#[proc_macro_derive(NumVariants)]
92pub fn derive_num_variants(input: TokenStream) -> TokenStream {
93let input = parse_macro_input!(input as DeriveInput);
94 enum_variants::derive(input)
95 .unwrap_or_else(syn::Error::into_compile_error)
96 .into()
97}