marine_macro_impl/
ast_types.rs

1/*
2 * Copyright 2020 Fluence Labs Limited
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *     http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17use crate::parsed_type::ParsedType;
18
19#[derive(Clone)]
20pub(crate) struct AstFnArgument {
21    pub(crate) name: String,
22    pub(crate) ty: ParsedType,
23}
24
25#[derive(Clone)]
26pub(crate) struct AstFnSignature {
27    pub(crate) visibility: syn::Visibility,
28    pub(crate) name: String,
29    pub(crate) arguments: Vec<AstFnArgument>,
30    // only one or zero return values are supported now,
31    // waiting for adding multi-value support in Wasmer
32    pub(crate) output_type: Option<ParsedType>,
33}
34
35#[derive(Clone)]
36pub(crate) struct AstRecord {
37    pub(crate) name: String,
38    pub(crate) fields: AstRecordFields,
39    pub(crate) original: syn::ItemStruct,
40}
41
42#[derive(Debug, Clone, PartialEq)]
43pub(crate) enum AstRecordFields {
44    Named(Vec<AstRecordField>),
45
46    // named and unnamed variants have the same inner field types because of it's easy to handle it,
47    // for additional info look at https://github.com/dtolnay/syn/issues/698
48    #[allow(dead_code)] // at the moment tuple and unit structs aren't supported
49    Unnamed(Vec<AstRecordField>),
50
51    #[allow(dead_code)] // at the moment tuple and unit structs aren't supported
52    Unit,
53}
54
55#[derive(Debug, Clone, PartialEq)]
56pub(crate) struct AstRecordField {
57    /// Name of the field. Can be `None` for tuples.
58    pub(crate) name: Option<String>,
59    pub(crate) ty: ParsedType,
60}
61
62#[derive(Clone)]
63pub(crate) struct AstExternFn {
64    pub(crate) link_name: Option<String>,
65    // only imports are possible here
66    pub(crate) signature: AstFnSignature,
67}
68
69#[derive(Clone)]
70pub(crate) struct AstExternMod {
71    pub(crate) namespace: String,
72    // only imports are possible here
73    pub(crate) imports: Vec<AstExternFn>,
74}
75
76#[derive(Clone)]
77pub(crate) struct AstFn {
78    pub(crate) signature: AstFnSignature,
79    pub(crate) original: syn::ItemFn,
80}
81
82#[derive(Clone)]
83pub(crate) enum MarineAst {
84    Function(Box<AstFn>),
85    ExternMod(AstExternMod),
86    Record(Box<AstRecord>),
87}