backend: All AST types should implement Debug

This commit is contained in:
Nick Fitzgerald 2018-05-25 16:19:09 -07:00
parent 50b8842b95
commit 018f083402
3 changed files with 19 additions and 6 deletions

View File

@ -17,5 +17,5 @@ spans = ["proc-macro2/nightly"]
quote = '0.6' quote = '0.6'
proc-macro2 = "0.4" proc-macro2 = "0.4"
wasm-bindgen-shared = { path = "../shared", version = "=0.2.11" } wasm-bindgen-shared = { path = "../shared", version = "=0.2.11" }
syn = { version = '0.14', features = ['full', 'visit-mut'] } syn = { version = '0.14', features = ['extra-traits', 'full', 'visit-mut'] }
serde_json = "1.0" serde_json = "1.0"

View File

@ -3,7 +3,7 @@ use quote::ToTokens;
use shared; use shared;
use syn; use syn;
#[derive(Default)] #[derive(Debug, Default)]
pub struct Program { pub struct Program {
pub exports: Vec<Export>, pub exports: Vec<Export>,
pub imports: Vec<Import>, pub imports: Vec<Import>,
@ -11,6 +11,7 @@ pub struct Program {
pub structs: Vec<Struct>, pub structs: Vec<Struct>,
} }
#[derive(Debug)]
pub struct Export { pub struct Export {
pub class: Option<Ident>, pub class: Option<Ident>,
pub method: bool, pub method: bool,
@ -19,6 +20,7 @@ pub struct Export {
pub function: Function, pub function: Function,
} }
#[derive(Debug)]
pub struct Import { pub struct Import {
pub module: Option<String>, pub module: Option<String>,
pub version: Option<String>, pub version: Option<String>,
@ -26,12 +28,14 @@ pub struct Import {
pub kind: ImportKind, pub kind: ImportKind,
} }
#[derive(Debug)]
pub enum ImportKind { pub enum ImportKind {
Function(ImportFunction), Function(ImportFunction),
Static(ImportStatic), Static(ImportStatic),
Type(ImportType), Type(ImportType),
} }
#[derive(Debug)]
pub struct ImportFunction { pub struct ImportFunction {
pub function: Function, pub function: Function,
pub rust_name: Ident, pub rust_name: Ident,
@ -39,12 +43,14 @@ pub struct ImportFunction {
pub shim: Ident, pub shim: Ident,
} }
#[derive(Debug)]
pub enum ImportFunctionKind { pub enum ImportFunctionKind {
Method { class: String, ty: syn::Type }, Method { class: String, ty: syn::Type },
JsConstructor { class: String, ty: syn::Type }, JsConstructor { class: String, ty: syn::Type },
Normal, Normal,
} }
#[derive(Debug)]
pub struct ImportStatic { pub struct ImportStatic {
pub vis: syn::Visibility, pub vis: syn::Visibility,
pub ty: syn::Type, pub ty: syn::Type,
@ -53,11 +59,13 @@ pub struct ImportStatic {
pub js_name: Ident, pub js_name: Ident,
} }
#[derive(Debug)]
pub struct ImportType { pub struct ImportType {
pub vis: syn::Visibility, pub vis: syn::Visibility,
pub name: Ident, pub name: Ident,
} }
#[derive(Debug)]
pub struct Function { pub struct Function {
pub name: Ident, pub name: Ident,
pub arguments: Vec<syn::Type>, pub arguments: Vec<syn::Type>,
@ -68,11 +76,13 @@ pub struct Function {
pub rust_vis: syn::Visibility, pub rust_vis: syn::Visibility,
} }
#[derive(Debug)]
pub struct Struct { pub struct Struct {
pub name: Ident, pub name: Ident,
pub fields: Vec<StructField>, pub fields: Vec<StructField>,
} }
#[derive(Debug)]
pub struct StructField { pub struct StructField {
pub opts: BindgenAttrs, pub opts: BindgenAttrs,
pub name: Ident, pub name: Ident,
@ -82,24 +92,26 @@ pub struct StructField {
pub setter: Ident, pub setter: Ident,
} }
#[derive(Debug)]
pub struct Enum { pub struct Enum {
pub name: Ident, pub name: Ident,
pub variants: Vec<Variant>, pub variants: Vec<Variant>,
} }
#[derive(Debug)]
pub struct Variant { pub struct Variant {
pub name: Ident, pub name: Ident,
pub value: u32, pub value: u32,
} }
#[derive(Copy, Clone)] #[derive(Copy, Clone, Debug)]
pub enum TypeKind { pub enum TypeKind {
ByRef, ByRef,
ByMutRef, ByMutRef,
ByValue, ByValue,
} }
#[derive(Copy, Clone)] #[derive(Copy, Clone, Debug)]
pub enum TypeLocation { pub enum TypeLocation {
ImportArgument, ImportArgument,
ImportRet, ImportRet,
@ -757,7 +769,7 @@ impl StructField {
} }
} }
#[derive(Default)] #[derive(Debug, Default)]
pub struct BindgenAttrs { pub struct BindgenAttrs {
attrs: Vec<BindgenAttr>, attrs: Vec<BindgenAttr>,
} }
@ -918,7 +930,7 @@ impl syn::synom::Synom for BindgenAttrs {
)); ));
} }
#[derive(PartialEq)] #[derive(Debug, PartialEq)]
enum BindgenAttr { enum BindgenAttr {
Catch, Catch,
Constructor, Constructor,

1
crates/backend/src/lib.rs Normal file → Executable file
View File

@ -1,4 +1,5 @@
#![recursion_limit = "256"] #![recursion_limit = "256"]
#![deny(missing_debug_implementations)]
extern crate proc_macro2; extern crate proc_macro2;
#[macro_use] #[macro_use]