diff --git a/src/ir/attr.rs b/src/ir/attr.rs index 95cec700ca..33a148ab6b 100644 --- a/src/ir/attr.rs +++ b/src/ir/attr.rs @@ -1,3 +1,4 @@ +//! Intermediate representation for attributes. use std::str; use clang::Cursor; @@ -6,20 +7,33 @@ use cexpr::token::{Token, Kind}; use super::context::BindgenContext; +/// The special attribute #[derive(Clone, Debug)] pub enum Attribute { + /// This attribute results in a warning if the type is used anywhere in the source file. Deprecated(Option), + /// This attribute means that variables of that type are meant to appear possibly unused. Unused, + /// This attribute attached to a function, means that code must be emitted for the function + /// even if it appears that the function is not referenced. Used, + /// This attribute on functions is used to inform the compiler that the function is unlikely to be executed. Cold, + /// Many functions do not examine any values except their arguments, + /// and have no effects except the return value. Const, + /// This attribute causes the function to be called automatically before execution enters main (). Constructor(Option), + /// This attribute causes the function to be called automatically after main () completes or exit () is called. Destructor(Option), + /// This attribute specifies a minimum alignment (in bytes) Aligned(Vec), + /// An attribute whose specific kind is not exposed via this interface. Unexposed(String, Vec) } impl Attribute { + /// Construct a new `Attribute`. pub fn new(tokens: Vec) -> Self { // https://gcc.gnu.org/onlinedocs/gcc/Attribute-Syntax.html#Attribute-Syntax assert!(!tokens.is_empty()); @@ -78,6 +92,7 @@ impl Attribute { } } + /// Parse a `Cursor` for `Vec`. pub fn parse(cur: &Cursor, ctx: &BindgenContext) -> Vec { let mut attributes = vec![]; @@ -110,6 +125,7 @@ impl Attribute { attributes } + /// Extract `Vec` from cursor's children. pub fn extract(cur: &Cursor, ctx: &BindgenContext) -> Vec { let mut attributes = vec![]; @@ -126,6 +142,7 @@ impl Attribute { attributes } + /// Whether this attribute whose specific kind is not exposed. pub fn is_unexposed(&self) -> bool { match *self { Attribute::Unexposed(..) | diff --git a/src/ir/comp.rs b/src/ir/comp.rs index 66728af08f..afc9343220 100644 --- a/src/ir/comp.rs +++ b/src/ir/comp.rs @@ -158,6 +158,7 @@ impl Field { &self.annotations } + /// The special attributes of field pub fn attributes(&self) -> &[Attribute] { &self.attributes } @@ -815,6 +816,7 @@ impl CompInfo { self.fields.iter().any(|field| field.attributes().iter().any(|attr| attr.is_unexposed())) } + /// The special attributes of this compound type pub fn attributes(&self) -> &[Attribute] { &self.attributes } diff --git a/src/ir/function.rs b/src/ir/function.rs index 76402842ef..8e2837e34e 100644 --- a/src/ir/function.rs +++ b/src/ir/function.rs @@ -28,7 +28,7 @@ pub struct Function { /// The doc comment on the function, if any. comment: Option, - /// The special attributes of function + /// The special attributes of the function. attributes: Vec, } @@ -64,6 +64,7 @@ impl Function { self.signature } + /// The special attributes of this function. pub fn attributes(&self) -> &[Attribute] { &self.attributes } diff --git a/src/ir/var.rs b/src/ir/var.rs index 95819e1eda..28c5c2f693 100644 --- a/src/ir/var.rs +++ b/src/ir/var.rs @@ -39,7 +39,7 @@ pub struct Var { val: Option, /// Whether this variable is const. is_const: bool, - /// The special attributes of variable + /// The special attributes of variable. attributes: Vec, } @@ -88,6 +88,7 @@ impl Var { self.mangled_name.as_ref().map(|n| &**n) } + /// The special attributes of variable. pub fn attributes(&self) -> &[Attribute] { &self.attributes }