Commit eda3626c authored by Alberto Ruiz's avatar Alberto Ruiz

Use commas instead of semicolon for class private fields

parent 5ef432a4
Pipeline #9239 passed with stages
in 20 minutes and 28 seconds
......@@ -14,7 +14,7 @@ user's code pretty much verbatim. For example, consider a call like this:
```rust
gobject_gen! {
class Counter {
f: Cell<u32>;
f: Cell<u32>
}
impl Counter {
......@@ -50,16 +50,10 @@ Program {
Class {
name: Ident("Counter"),
extends: None,
items: [
ClassItem::PrivateField(
PrivateField {
type: Ident("f"),
sep: Token!(:),
path: Type,
semi: Token!(;),
}
),
],
fields: FieldsNamed {
brace_token: Brace,
named: Punctuated {...}
}
}
),
......
```rust
gnome_class! {
class Foo: Superclass {
field: Cell<u32>; // this is where we declare the members of the private struct
field1: Cell<u32>, // this is where we declare the members of the private struct
field2: Cell<u8> // separated by commas
}
// this defines the class ABI, basically
......
......@@ -3,7 +3,7 @@
use proc_macro2::Term;
use syn::punctuated::Punctuated;
use syn::{Attribute, Lit};
use syn::{Block, FnArg, Ident, Path, ReturnType, Type};
use syn::{Block, FnArg, Ident, Path, ReturnType, FieldsNamed};
pub struct Program {
pub items: Vec<Item>,
......@@ -47,7 +47,7 @@ pub fn get_program_classes<'a>(program: &'a Program) -> Vec<&'a Class> {
pub struct Class {
pub name: Ident,
pub extends: Option<Path>,
pub items: Vec<ClassItem>,
pub fields: FieldsNamed
}
// similar to syn::ItemImpl
......@@ -57,10 +57,6 @@ pub struct Impl {
pub items: Vec<ImplItem>,
}
pub enum ClassItem {
PrivateField(Field)
}
pub struct ImplItem {
pub attrs: Vec<Attribute>,
pub node: ImplItemKind,
......@@ -80,10 +76,3 @@ pub struct ImplItemMethod {
pub output: ReturnType,
pub body: Option<Block>,
}
pub struct Field {
pub name: Ident,
pub colon: Token!(:),
pub ty: Type,
pub semi: Token!(;),
}
......@@ -10,8 +10,6 @@ use syn::{Ident, Path};
use errors::*;
use hir::*;
use ast;
mod boilerplate;
mod cstringident;
mod imp;
......@@ -459,12 +457,4 @@ impl<'ast> ToTokens for ArgNames<'ast> {
}
}
}
}
impl ToTokens for ast::Field {
fn to_tokens(&self, tokens: &mut Tokens) {
let name = &self.name;
let ty = &self.ty;
(quote_cs! { #name: #ty }).to_tokens(tokens);
}
}
\ No newline at end of file
......@@ -14,7 +14,7 @@ use quote::{ToTokens, Tokens};
use syn::buffer::TokenBuffer;
use syn::punctuated::Punctuated;
use syn::synom::Synom;
use syn::{self, parse_str, Block, Ident, Path, ReturnType};
use syn::{self, parse_str, Block, Ident, Path, ReturnType, Field};
use super::ast;
use super::checking::*;
......@@ -39,7 +39,7 @@ pub struct Class<'ast> {
// pub class_private: Option<&'ast ast::PrivateStruct>
pub private_fields: Vec<&'ast ast::Field>,
pub private_fields: Vec<&'ast Field>,
// The order of these is important; it's the order of the slots in FooClass
pub slots: Vec<Slot<'ast>>,
......@@ -185,12 +185,7 @@ impl<'ast> Classes<'ast> {
parent_ffi: tokens_ParentInstanceFfi(ast_class),
parent_class_ffi: tokens_ParentClassFfi(ast_class),
implements: Vec::new(),
private_fields: ast_class
.items
.iter()
.filter_map(|i| match *i {
ast::ClassItem::PrivateField(ref field) => Some(field)
}).collect(),
private_fields: ast_class.fields.named.iter().collect(),
slots: Vec::new(),
overrides: HashMap::new(),
},
......
......@@ -56,7 +56,7 @@ mod parser;
///
/// gobject_gen! {
/// class Foo {
/// private_field: Cell<u32>;
/// private_field: Cell<u32>,
/// }
///
/// // Methods and signals;, their order defines the ABI of your class
......@@ -102,9 +102,10 @@ mod parser;
/// #[derive(Default)]
/// gobject_gen! {
/// class Foo {
/// field_one: Cell<u32>;
/// field_two: Cell<u16>;
/// field_one: Cell<u32>,
/// field_two: Cell<u16>,
/// ...
/// last_field: Cell<u8>
/// }
/// }
/// ```
......
......@@ -4,7 +4,7 @@ use proc_macro2::Term;
use syn::buffer::Cursor;
use syn::punctuated::Punctuated;
use syn::synom::{PResult, Synom};
use syn::{self, parse_error, Ident, Path};
use syn::{self, parse_error, Ident, Path, FieldsNamed};
use ast;
use errors::*;
......@@ -56,11 +56,11 @@ impl Synom for ast::Class {
superclass: syn!(Path) >>
// FIXME: interfaces
(superclass))) >>
items_and_braces: braces!(many0!(syn!(ast::ClassItem))) >>
fields: syn!(FieldsNamed) >>
(ast::Class {
name: name,
extends: extends,
items: items_and_braces.1
fields: fields
})
));
......@@ -69,31 +69,6 @@ impl Synom for ast::Class {
}
}
impl Synom for ast::ClassItem {
named!(parse -> Self, alt!(
syn!(ast::Field) => { |x| ast::ClassItem::PrivateField(x) }
));
fn description() -> Option<&'static str> {
Some("item inside class")
}
}
impl Synom for ast::Field {
named!(parse -> Self, do_parse!(
name: syn!(Ident) >>
colon: punct!(:) >>
ty: syn!(syn::Type) >>
semi: punct!(;) >>
(ast::Field {
name: name,
colon: colon,
ty: ty,
semi: semi
})
));
}
impl Synom for ast::Impl {
named!(parse -> Self, do_parse!(
keyword!(impl) >>
......@@ -256,13 +231,13 @@ pub mod tests {
fn parses_class_with_private_field() {
let raw = "class Foo {
foo : u32;
bar : u32;
baz : u32;
foo : u32,
bar : u32,
baz : u32
}";
let class = parse_str::<ast::Class>(raw).unwrap();
assert_eq!(class.items.len(), 3);
assert_eq!(class.fields.named.len(), 3);
}
fn parses_class_with_superclass() {
......
......@@ -11,7 +11,7 @@ use std::cell::Cell;
gobject_gen! {
class Counter {
f: Cell<u32>;
f: Cell<u32>,
}
impl Counter {
......
......@@ -36,7 +36,7 @@ impl Drop for DropCounter {
gobject_gen! {
class Dummy {
dc: RefCell<DropCounter>;
dc: RefCell<DropCounter>,
}
impl Dummy {
......
......@@ -21,7 +21,7 @@ use glib::translate::*;
gobject_gen! {
class Signaler {
val: Cell<u32>;
val: Cell<u32>,
}
impl Signaler {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment