diff options
author | bors-servo <lbergstrom+bors@mozilla.com> | 2017-01-11 03:07:26 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-01-11 03:07:26 -0800 |
commit | 6bfeae155155a12849033e1c5199ca6e48e8b22c (patch) | |
tree | 4b1a0e42b32238565eb3ab61e67623e13459a06f /libbindgen/src/ir/annotations.rs | |
parent | df043bf3dcc11bfd5c22cee5d3c6ba04d41c5f00 (diff) | |
parent | fee7e96875f1d7c805a09e8ec8e02988de25e370 (diff) |
Auto merge of #393 - emilio:enum-const-api, r=upsuper
Provide an API to constify enum variants.
r? @upsuper
Diffstat (limited to 'libbindgen/src/ir/annotations.rs')
-rw-r--r-- | libbindgen/src/ir/annotations.rs | 28 |
1 files changed, 27 insertions, 1 deletions
diff --git a/libbindgen/src/ir/annotations.rs b/libbindgen/src/ir/annotations.rs index 3598c78c..98be0540 100644 --- a/libbindgen/src/ir/annotations.rs +++ b/libbindgen/src/ir/annotations.rs @@ -20,12 +20,17 @@ pub enum FieldAccessorKind { } /// Annotations for a given item, or a field. +/// +/// You can see the kind of comments that are accepted in the Doxygen +/// documentation: +/// +/// http://www.stack.nl/~dimitri/doxygen/manual/docblocks.html #[derive(Clone, PartialEq, Debug)] pub struct Annotations { /// Whether this item is marked as opaque. Only applies to types. opaque: bool, /// Whether this item should be hidden from the output. Only applies to - /// types. + /// types, or enum variants. hide: bool, /// Whether this type should be replaced by another. The name is a /// namespace-aware path. @@ -39,6 +44,20 @@ pub struct Annotations { /// The kind of accessor this field will have. Also can be applied to /// structs so all the fields inside share it by default. accessor_kind: Option<FieldAccessorKind>, + /// Whether this enum variant should be constified. + /// + /// This is controlled by the `constant` attribute, this way: + /// + /// ```cpp + /// enum Foo { + /// Bar = 0, /**< <div rustbindgen constant></div> */ + /// Baz = 0, + /// }; + /// ``` + /// + /// In that case, bindgen will generate a constant for `Bar` instead of + /// `Baz`. + constify_enum_variant: bool, } fn parse_accessor(s: &str) -> FieldAccessorKind { @@ -59,6 +78,7 @@ impl Default for Annotations { disallow_copy: false, private_fields: None, accessor_kind: None, + constify_enum_variant: false, } } } @@ -150,6 +170,7 @@ impl Annotations { "accessor" => { self.accessor_kind = Some(parse_accessor(&attr.value)) } + "constant" => self.constify_enum_variant = true, _ => {} } } @@ -159,4 +180,9 @@ impl Annotations { self.parse(&child, matched); } } + + /// Returns whether we've parsed a "constant" attribute. + pub fn constify_enum_variant(&self) -> bool { + self.constify_enum_variant + } } |