From dc12952e19cf945cd001e7beab41b36524584938 Mon Sep 17 00:00:00 2001 From: Vadim Petrochenkov Date: Tue, 27 Oct 2020 01:39:15 +0300 Subject: [PATCH] Keep annotations on fields --- src/bindgen/ir/enumeration.rs | 1 + src/bindgen/ir/field.rs | 5 ++++- src/bindgen/ir/structure.rs | 2 ++ src/bindgen/ir/union.rs | 3 +++ 4 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/bindgen/ir/enumeration.rs b/src/bindgen/ir/enumeration.rs index 6329d23..c5fc0d3 100644 --- a/src/bindgen/ir/enumeration.rs +++ b/src/bindgen/ir/enumeration.rs @@ -112,6 +112,7 @@ impl EnumVariant { None => i.to_string(), }, ty, + annotations: AnnotationSet::load(&field.attrs)?, documentation: Documentation::load(&field.attrs), }); } diff --git a/src/bindgen/ir/field.rs b/src/bindgen/ir/field.rs index 105d432..beec5a0 100644 --- a/src/bindgen/ir/field.rs +++ b/src/bindgen/ir/field.rs @@ -2,13 +2,14 @@ use std::io::Write; use crate::bindgen::cdecl; use crate::bindgen::config::Config; -use crate::bindgen::ir::{Documentation, Path, Type}; +use crate::bindgen::ir::{AnnotationSet, Documentation, Path, Type}; use crate::bindgen::writer::{Source, SourceWriter}; #[derive(Debug, Clone)] pub struct Field { pub name: String, pub ty: Type, + pub annotations: AnnotationSet, pub documentation: Documentation, } @@ -17,6 +18,7 @@ impl Field { Field { name, ty, + annotations: AnnotationSet::new(), documentation: Documentation::none(), } } @@ -31,6 +33,7 @@ impl Field { .ok_or_else(|| "field is missing identifier".to_string())? .to_string(), ty, + annotations: AnnotationSet::load(&field.attrs)?, documentation: Documentation::load(&field.attrs), }) } else { diff --git a/src/bindgen/ir/structure.rs b/src/bindgen/ir/structure.rs index 31e7cee..0f1ed4c 100644 --- a/src/bindgen/ir/structure.rs +++ b/src/bindgen/ir/structure.rs @@ -88,6 +88,7 @@ impl Struct { out.push(Field { name: format!("{}", current), ty, + annotations: AnnotationSet::load(&field.attrs)?, documentation: Documentation::load(&field.attrs), }); current += 1; @@ -190,6 +191,7 @@ impl Struct { .map(|field| Field { name: field.name.clone(), ty: field.ty.specialize(mappings), + annotations: field.annotations.clone(), documentation: field.documentation.clone(), }) .collect(), diff --git a/src/bindgen/ir/union.rs b/src/bindgen/ir/union.rs index 3c5dd48..a0a9959 100644 --- a/src/bindgen/ir/union.rs +++ b/src/bindgen/ir/union.rs @@ -180,6 +180,7 @@ impl Item for Union { overriden_fields.push(Field { name: o[i].clone(), ty: field.ty.clone(), + annotations: field.annotations.clone(), documentation: field.documentation.clone(), }); } @@ -195,6 +196,7 @@ impl Item for Union { .apply(&field.name, IdentifierType::StructMember) .into_owned(), ty: field.ty.clone(), + annotations: field.annotations.clone(), documentation: field.documentation.clone(), }) .collect(); @@ -254,6 +256,7 @@ impl Item for Union { .map(|field| Field { name: field.name.clone(), ty: field.ty.specialize(&mappings), + annotations: field.annotations.clone(), documentation: field.documentation.clone(), }) .collect(),