This commit is contained in:
vms 2021-04-22 17:57:47 +03:00
parent 17115b696a
commit ba7af66ca8
11 changed files with 52 additions and 52 deletions

View File

@ -66,7 +66,7 @@ macro_rules! debug_log {
let level = log::Level::Info as i32;
let target = 0i32;
let msg = $msg_generator;
logger::log_utf8_string(level, target, msg.as_ptr() as i32, msg.len() as i32);
crate::logger::log_utf8_string(level, target, msg.as_ptr() as i32, msg.len() as i32);
}
};
}

View File

@ -33,7 +33,7 @@ pub(crate) struct AstFnSignature {
}
#[derive(Clone)]
pub(crate) struct AstRecordItem {
pub(crate) struct AstRecord {
pub name: String,
pub fields: AstRecordFields,
pub original: syn::ItemStruct,
@ -60,29 +60,29 @@ pub(crate) struct AstRecordField {
}
#[derive(Clone)]
pub(crate) struct AstExternFnItem {
pub(crate) struct AstExternFn {
pub link_name: Option<String>,
// only imports are possible here
pub signature: AstFnSignature,
}
#[derive(Clone)]
pub(crate) struct AstExternModItem {
pub(crate) struct AstExternMod {
pub namespace: String,
// only imports are possible here
pub imports: Vec<AstExternFnItem>,
pub imports: Vec<AstExternFn>,
pub original: syn::ItemForeignMod,
}
#[derive(Clone)]
pub(crate) struct AstFnItem {
pub(crate) struct AstFn {
pub signature: AstFnSignature,
pub original: syn::ItemFn,
}
#[derive(Clone)]
pub(crate) enum FCEAst {
Function(AstFnItem),
ExternMod(AstExternModItem),
Record(AstRecordItem),
Function(AstFn),
ExternMod(AstExternMod),
Record(AstRecord),
}

View File

@ -33,7 +33,7 @@ pub struct FnSignature {
}
#[derive(Clone, Serialize, Deserialize)]
pub struct RecordItem {
pub struct RecordType {
pub name: String,
pub fields: RecordFields,
}
@ -55,68 +55,68 @@ pub struct RecordField {
}
#[derive(Clone, Serialize, Deserialize)]
pub struct ExternFnItem {
pub struct ExternFnType {
pub link_name: Option<String>,
// only imports are possible here
pub signature: FnSignature,
}
#[derive(Clone, Serialize, Deserialize)]
pub struct ExternModItem {
pub struct ExternModType {
pub namespace: String,
// only imports are possible here
pub imports: Vec<ExternFnItem>,
pub imports: Vec<ExternFnType>,
}
#[derive(Clone, Serialize, Deserialize)]
pub struct FnItem {
pub struct FnType {
pub signature: FnSignature,
}
#[derive(Clone, Serialize, Deserialize)]
#[serde(tag = "ast_type")]
pub enum SDKAst {
Function(FnItem),
ExternMod(ExternModItem),
Record(RecordItem),
Function(FnType),
ExternMod(ExternModType),
Record(RecordType),
}
use crate::ast_types::{
AstFnItem, AstFnSignature, AstFnArgument, AstExternModItem, AstExternFnItem, AstRecordField,
AstRecordItem, AstRecordFields,
AstFn, AstFnSignature, AstFnArgument, AstExternMod, AstExternFn, AstRecordField, AstRecord,
AstRecordFields,
};
impl From<AstFnItem> for SDKAst {
fn from(ast_fn_item: AstFnItem) -> Self {
impl From<AstFn> for SDKAst {
fn from(ast_fn_item: AstFn) -> Self {
let fn_item = ast_fn_item.into();
Self::Function(fn_item)
}
}
impl From<AstExternModItem> for SDKAst {
fn from(ast_extern_mod: AstExternModItem) -> Self {
impl From<AstExternMod> for SDKAst {
fn from(ast_extern_mod: AstExternMod) -> Self {
let extern_mod = ast_extern_mod.into();
Self::ExternMod(extern_mod)
}
}
impl From<AstRecordItem> for SDKAst {
fn from(ast_record_item: AstRecordItem) -> Self {
impl From<AstRecord> for SDKAst {
fn from(ast_record_item: AstRecord) -> Self {
let record_item = ast_record_item.into();
Self::Record(record_item)
}
}
impl From<AstFnItem> for FnItem {
fn from(ast_fn_item: AstFnItem) -> Self {
impl From<AstFn> for FnType {
fn from(ast_fn_item: AstFn) -> Self {
let signature = ast_fn_item.signature.into();
Self { signature }
}
}
impl From<AstExternModItem> for ExternModItem {
fn from(ast_extern_mod: AstExternModItem) -> Self {
impl From<AstExternMod> for ExternModType {
fn from(ast_extern_mod: AstExternMod) -> Self {
let imports = ast_extern_mod.imports.into_iter().map(Into::into).collect();
Self {
@ -126,8 +126,8 @@ impl From<AstExternModItem> for ExternModItem {
}
}
impl From<AstRecordItem> for RecordItem {
fn from(ast_record_item: AstRecordItem) -> Self {
impl From<AstRecord> for RecordType {
fn from(ast_record_item: AstRecord) -> Self {
Self {
name: ast_record_item.name,
fields: ast_record_item.fields.into(),
@ -177,8 +177,8 @@ impl From<AstFnArgument> for FnArgument {
}
}
impl From<AstExternFnItem> for ExternFnItem {
fn from(ast_extern_item: AstExternFnItem) -> Self {
impl From<AstExternFn> for ExternFnType {
fn from(ast_extern_item: AstExternFn) -> Self {
Self {
link_name: ast_extern_item.link_name,
signature: ast_extern_item.signature.into(),

View File

@ -18,7 +18,7 @@ use super::ParseMacroInput;
use crate::ast_types;
use crate::ParsedType;
use crate::ast_types::FCEAst;
use crate::ast_types::AstFnItem;
use crate::ast_types::AstFn;
use crate::ast_types::AstFnArgument;
use crate::syn_error;
@ -38,7 +38,7 @@ impl ParseMacroInput for syn::ItemFn {
check_args(parsed_args)?;
check_output_type(&signature.output_type, self.sig.output.span())?;
let ast_fn = FCEAst::Function(AstFnItem {
let ast_fn = FCEAst::Function(AstFn {
signature,
original: self,
});

View File

@ -36,7 +36,7 @@ impl ParseMacroInput for syn::ItemForeignMod {
let imports = extract_import_functions(&self)?;
check_imports(imports.iter().zip(self.items.iter().map(|i| i.span())))?;
let extern_mod_item = ast_types::AstExternModItem {
let extern_mod_item = ast_types::AstExternMod {
namespace,
imports,
original: self,
@ -99,7 +99,7 @@ fn try_extract_namespace(
fn extract_import_functions(
foreign_mod: &syn::ItemForeignMod,
) -> Result<Vec<ast_types::AstExternFnItem>> {
) -> Result<Vec<ast_types::AstExternFn>> {
foreign_mod
.items
.iter()
@ -111,7 +111,7 @@ fn extract_import_functions(
/// This function checks whether these imports contains inner references. In this case glue
/// code couldn't be generated.
fn check_imports<'i>(
extern_fns: impl ExactSizeIterator<Item = (&'i ast_types::AstExternFnItem, proc_macro2::Span)>,
extern_fns: impl ExactSizeIterator<Item = (&'i ast_types::AstExternFn, proc_macro2::Span)>,
) -> Result<()> {
use super::utils::contain_inner_ref;
@ -129,7 +129,7 @@ fn check_imports<'i>(
Ok(())
}
fn parse_raw_foreign_item(raw_item: syn::ForeignItem) -> Result<ast_types::AstExternFnItem> {
fn parse_raw_foreign_item(raw_item: syn::ForeignItem) -> Result<ast_types::AstExternFn> {
let function_item = match raw_item {
syn::ForeignItem::Fn(function_item) => function_item,
_ => {
@ -158,7 +158,7 @@ fn parse_raw_foreign_item(raw_item: syn::ForeignItem) -> Result<ast_types::AstEx
};
let signature = super::item_fn::try_to_ast_signature(function_item.sig, function_item.vis)?;
let ast_extern_fn_item = ast_types::AstExternFnItem {
let ast_extern_fn_item = ast_types::AstExternFn {
link_name,
signature,
};

View File

@ -38,7 +38,7 @@ impl ParseMacroInput for syn::ItemStruct {
let fields = AstRecordFields::Named(fields);
let name = self.ident.to_string();
let ast_record_item = ast_types::AstRecordItem {
let ast_record_item = ast_types::AstRecord {
name,
fields,
original: self,

View File

@ -25,7 +25,7 @@ use crate::new_ident;
use proc_macro2::TokenStream;
impl quote::ToTokens for ast_types::AstFnItem {
impl quote::ToTokens for ast_types::AstFn {
fn to_tokens(&self, tokens: &mut TokenStream) {
crate::prepare_global_data!(
Function,

View File

@ -21,7 +21,7 @@ use crate::parsed_type::*;
use proc_macro2::TokenStream;
use quote::quote;
impl quote::ToTokens for ast_types::AstExternModItem {
impl quote::ToTokens for ast_types::AstExternMod {
fn to_tokens(&self, tokens: &mut TokenStream) {
crate::prepare_global_data!(
ExternMod,
@ -61,7 +61,7 @@ impl quote::ToTokens for ast_types::AstExternModItem {
}
}
fn generate_extern_section_items(extern_item: &ast_types::AstExternModItem) -> Vec<TokenStream> {
fn generate_extern_section_items(extern_item: &ast_types::AstExternMod) -> Vec<TokenStream> {
let mut section_items = Vec::with_capacity(extern_item.imports.len());
for import in &extern_item.imports {
@ -90,7 +90,7 @@ fn generate_import_name(import_name: &str) -> syn::Ident {
crate::new_ident!(format!("{}_{}", super::GENERATED_WRAPPER_FUNC_PREFIX, import_name))
}
fn generate_wrapper_functions(extern_item: &ast_types::AstExternModItem) -> TokenStream {
fn generate_wrapper_functions(extern_item: &ast_types::AstExternMod) -> TokenStream {
let mut token_stream = TokenStream::new();
for import in &extern_item.imports {

View File

@ -23,10 +23,10 @@ use record_deserializer::*;
use record_serializer::*;
use crate::new_ident;
use crate::ast_types::AstRecordItem;
use crate::ast_types::AstRecord;
use crate::ast_types::AstRecordFields;
impl quote::ToTokens for AstRecordItem {
impl quote::ToTokens for AstRecord {
fn to_tokens(&self, tokens: &mut proc_macro2::TokenStream) {
let original = &self.original;
crate::prepare_global_data!(
@ -68,7 +68,7 @@ impl quote::ToTokens for AstRecordItem {
}
}
fn generate_serializer_fn(record: &AstRecordItem) -> proc_macro2::TokenStream {
fn generate_serializer_fn(record: &AstRecord) -> proc_macro2::TokenStream {
let serializer = record.generate_serializer();
let fields_count = match &record.fields {
AstRecordFields::Named(fields) => fields.len(),
@ -91,7 +91,7 @@ fn generate_serializer_fn(record: &AstRecordItem) -> proc_macro2::TokenStream {
}
}
fn generate_deserializer_fn(record: &AstRecordItem) -> proc_macro2::TokenStream {
fn generate_deserializer_fn(record: &AstRecord) -> proc_macro2::TokenStream {
let RecordDerDescriptor {
fields_der,
record_ctor,

View File

@ -32,7 +32,7 @@ pub(super) trait RecordDerGlueCodeGenerator {
fn generate_der(&self) -> RecordDerDescriptor;
}
impl RecordDerGlueCodeGenerator for AstRecordItem {
impl RecordDerGlueCodeGenerator for AstRecord {
fn generate_der(&self) -> RecordDerDescriptor {
match &self.fields {
AstRecordFields::Named(fields) => record_der_from_named(fields),

View File

@ -16,7 +16,7 @@
use crate::new_ident;
use crate::parsed_type::ParsedType;
use crate::ast_types::AstRecordItem;
use crate::ast_types::AstRecord;
use crate::ast_types::AstRecordField;
use crate::ast_types::AstRecordFields;
@ -27,7 +27,7 @@ pub(super) trait RecordSerGlueCodeGenerator {
fn generate_serializer(&self) -> proc_macro2::TokenStream;
}
impl RecordSerGlueCodeGenerator for AstRecordItem {
impl RecordSerGlueCodeGenerator for AstRecord {
fn generate_serializer(&self) -> proc_macro2::TokenStream {
let mut serializer = proc_macro2::TokenStream::new();
let fields = match &self.fields {