Skip to content

Commit a88a43b

Browse files
committed
Improve document
1 parent 8f27c7a commit a88a43b

File tree

4 files changed

+23
-2
lines changed

4 files changed

+23
-2
lines changed

Diff for: src/ir/attr.rs

+17
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
//! Intermediate representation for attributes.
12
use std::str;
23

34
use clang::Cursor;
@@ -6,20 +7,33 @@ use cexpr::token::{Token, Kind};
67

78
use super::context::BindgenContext;
89

10+
/// The special attribute
911
#[derive(Clone, Debug)]
1012
pub enum Attribute {
13+
/// This attribute results in a warning if the type is used anywhere in the source file.
1114
Deprecated(Option<String>),
15+
/// This attribute means that variables of that type are meant to appear possibly unused.
1216
Unused,
17+
/// This attribute attached to a function, means that code must be emitted for the function
18+
/// even if it appears that the function is not referenced.
1319
Used,
20+
/// This attribute on functions is used to inform the compiler that the function is unlikely to be executed.
1421
Cold,
22+
/// Many functions do not examine any values except their arguments,
23+
/// and have no effects except the return value.
1524
Const,
25+
/// This attribute causes the function to be called automatically before execution enters main ().
1626
Constructor(Option<isize>),
27+
/// This attribute causes the function to be called automatically after main () completes or exit () is called.
1728
Destructor(Option<isize>),
29+
/// This attribute specifies a minimum alignment (in bytes)
1830
Aligned(Vec<Token>),
31+
/// An attribute whose specific kind is not exposed via this interface.
1932
Unexposed(String, Vec<Token>)
2033
}
2134

2235
impl Attribute {
36+
/// Construct a new `Attribute`.
2337
pub fn new(tokens: Vec<Token>) -> Self {
2438
// https://gcc.gnu.org/onlinedocs/gcc/Attribute-Syntax.html#Attribute-Syntax
2539
assert!(!tokens.is_empty());
@@ -78,6 +92,7 @@ impl Attribute {
7892
}
7993
}
8094

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

@@ -110,6 +125,7 @@ impl Attribute {
110125
attributes
111126
}
112127

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

@@ -126,6 +142,7 @@ impl Attribute {
126142
attributes
127143
}
128144

145+
/// Whether this attribute whose specific kind is not exposed.
129146
pub fn is_unexposed(&self) -> bool {
130147
match *self {
131148
Attribute::Unexposed(..) |

Diff for: src/ir/comp.rs

+2
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,7 @@ impl Field {
158158
&self.annotations
159159
}
160160

161+
/// The special attributes of field
161162
pub fn attributes(&self) -> &[Attribute] {
162163
&self.attributes
163164
}
@@ -815,6 +816,7 @@ impl CompInfo {
815816
self.fields.iter().any(|field| field.attributes().iter().any(|attr| attr.is_unexposed()))
816817
}
817818

819+
/// The special attributes of this compound type
818820
pub fn attributes(&self) -> &[Attribute] {
819821
&self.attributes
820822
}

Diff for: src/ir/function.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ pub struct Function {
2828
/// The doc comment on the function, if any.
2929
comment: Option<String>,
3030

31-
/// The special attributes of function
31+
/// The special attributes of the function.
3232
attributes: Vec<Attribute>,
3333
}
3434

@@ -64,6 +64,7 @@ impl Function {
6464
self.signature
6565
}
6666

67+
/// The special attributes of this function.
6768
pub fn attributes(&self) -> &[Attribute] {
6869
&self.attributes
6970
}

Diff for: src/ir/var.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ pub struct Var {
3939
val: Option<VarType>,
4040
/// Whether this variable is const.
4141
is_const: bool,
42-
/// The special attributes of variable
42+
/// The special attributes of variable.
4343
attributes: Vec<Attribute>,
4444
}
4545

@@ -88,6 +88,7 @@ impl Var {
8888
self.mangled_name.as_ref().map(|n| &**n)
8989
}
9090

91+
/// The special attributes of variable.
9192
pub fn attributes(&self) -> &[Attribute] {
9293
&self.attributes
9394
}

0 commit comments

Comments
 (0)