Skip to content

Commit

Permalink
Improve document
Browse files Browse the repository at this point in the history
  • Loading branch information
flier committed Feb 3, 2017
1 parent 8f27c7a commit a88a43b
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 2 deletions.
17 changes: 17 additions & 0 deletions src/ir/attr.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//! Intermediate representation for attributes.
use std::str;

use clang::Cursor;
Expand All @@ -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<String>),
/// 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<isize>),
/// This attribute causes the function to be called automatically after main () completes or exit () is called.
Destructor(Option<isize>),
/// This attribute specifies a minimum alignment (in bytes)
Aligned(Vec<Token>),
/// An attribute whose specific kind is not exposed via this interface.
Unexposed(String, Vec<Token>)
}

impl Attribute {
/// Construct a new `Attribute`.
pub fn new(tokens: Vec<Token>) -> Self {
// https://gcc.gnu.org/onlinedocs/gcc/Attribute-Syntax.html#Attribute-Syntax
assert!(!tokens.is_empty());
Expand Down Expand Up @@ -78,6 +92,7 @@ impl Attribute {
}
}

/// Parse a `Cursor` for `Vec<Attribute>`.
pub fn parse(cur: &Cursor, ctx: &BindgenContext) -> Vec<Self> {
let mut attributes = vec![];

Expand Down Expand Up @@ -110,6 +125,7 @@ impl Attribute {
attributes
}

/// Extract `Vec<Attribute>` from cursor's children.
pub fn extract(cur: &Cursor, ctx: &BindgenContext) -> Vec<Self> {
let mut attributes = vec![];

Expand All @@ -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(..) |
Expand Down
2 changes: 2 additions & 0 deletions src/ir/comp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ impl Field {
&self.annotations
}

/// The special attributes of field
pub fn attributes(&self) -> &[Attribute] {
&self.attributes
}
Expand Down Expand Up @@ -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
}
Expand Down
3 changes: 2 additions & 1 deletion src/ir/function.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ pub struct Function {
/// The doc comment on the function, if any.
comment: Option<String>,

/// The special attributes of function
/// The special attributes of the function.
attributes: Vec<Attribute>,
}

Expand Down Expand Up @@ -64,6 +64,7 @@ impl Function {
self.signature
}

/// The special attributes of this function.
pub fn attributes(&self) -> &[Attribute] {
&self.attributes
}
Expand Down
3 changes: 2 additions & 1 deletion src/ir/var.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ pub struct Var {
val: Option<VarType>,
/// Whether this variable is const.
is_const: bool,
/// The special attributes of variable
/// The special attributes of variable.
attributes: Vec<Attribute>,
}

Expand Down Expand Up @@ -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
}
Expand Down

0 comments on commit a88a43b

Please sign in to comment.