From b83e6178b847dd0a1db7fba1cad32fa00a9adb32 Mon Sep 17 00:00:00 2001 From: Sergey Pepyakin Date: Fri, 25 Jan 2019 10:45:39 +0100 Subject: [PATCH] Start refactoring. --- derive/src/codegen.rs | 2 +- derive/src/lib.rs | 1 - derive/src/model.rs | 38 -------------------------------------- derive/src/parser.rs | 41 ++++++++++++++++++++++++++++++++++++++++- 4 files changed, 41 insertions(+), 41 deletions(-) delete mode 100644 derive/src/model.rs diff --git a/derive/src/codegen.rs b/derive/src/codegen.rs index edbad4b..51e809d 100644 --- a/derive/src/codegen.rs +++ b/derive/src/codegen.rs @@ -1,4 +1,4 @@ -use crate::model::{ExtDefinition, ExternalFunc}; +use crate::parser::{ExtDefinition, ExternalFunc}; use proc_macro2::{Ident, Literal, Span, TokenStream}; use quote::{quote, quote_spanned, ToTokens}; diff --git a/derive/src/lib.rs b/derive/src/lib.rs index 22e94ea..8d8950d 100644 --- a/derive/src/lib.rs +++ b/derive/src/lib.rs @@ -3,7 +3,6 @@ extern crate proc_macro; mod codegen; -mod model; mod parser; use proc_macro::TokenStream; diff --git a/derive/src/model.rs b/derive/src/model.rs deleted file mode 100644 index 6dc3e31..0000000 --- a/derive/src/model.rs +++ /dev/null @@ -1,38 +0,0 @@ -pub enum ValueType { - I32, - I64, - F32, - F64, -} - -pub struct Signature { - pub params: Vec, - pub return_ty: Option, -} - -#[derive(Clone)] -pub struct Param { - /// A generated identifier used for temporary variables. - pub ident: syn::Ident, -} - -pub struct ExternalFunc { - /// Assigned index of this function. - pub index: u32, - pub name: String, - // TODO: Rename args to params - pub args: Vec, - pub return_ty: Option, -} - -/// The core structure that contains the list of all functions -/// and the data required for implementing a trait. -pub struct ExtDefinition { - /// List of all external functions. - pub funcs: Vec, - /// The generics required to implement a trait for this type. - pub generics: syn::Generics, - /// The type declaration to implement to implement a trait, most typically - /// represented by a structure. - pub ty: Box, -} diff --git a/derive/src/parser.rs b/derive/src/parser.rs index 6e19af2..aecdf38 100644 --- a/derive/src/parser.rs +++ b/derive/src/parser.rs @@ -1,7 +1,46 @@ -use crate::model::{self, ExtDefinition, ExternalFunc, Param}; use syn::spanned::Spanned; use syn::{FnArg, Ident, ImplItem, ImplItemMethod, ItemImpl, ReturnType}; +pub enum ValueType { + I32, + I64, + F32, + F64, +} + +pub struct Signature { + pub params: Vec, + pub return_ty: Option, +} + +#[derive(Clone)] +pub struct Param { + /// A generated identifier used to name temporary variables + /// used for storing this parameter in generated code. + pub ident: syn::Ident, +} + +pub struct ExternalFunc { + /// Assigned index of this function. + pub index: u32, + pub name: String, + // TODO: Rename args to params + pub args: Vec, + pub return_ty: Option, +} + +/// The core structure that contains the list of all functions +/// and the data required for implementing a trait. +pub struct ExtDefinition { + /// List of all external functions. + pub funcs: Vec, + /// The generics required to implement a trait for this type. + pub generics: syn::Generics, + /// The type declaration to implement to implement a trait, most typically + /// represented by a structure. + pub ty: Box, +} + /// Parse an incoming stream of tokens into externalities definition. pub fn parse(input: proc_macro2::TokenStream) -> Result { let item_impl = syn::parse2::(input).map_err(|_| ())?;