|
1 | 1 | #![allow(
|
2 | 2 | clippy::single_match,
|
3 | 3 | // unreachable_code,
|
4 |
| - dead_code, |
5 |
| - unused_variables, |
6 |
| - unused_imports, |
| 4 | +// dead_code, |
| 5 | +// unused_variables, |
| 6 | +// unused_imports, |
7 | 7 | // unused_macros,
|
8 | 8 | // unused_parens,
|
9 | 9 | // unused_mut,
|
10 | 10 | // unused_attributes,
|
11 |
| - unused_assignments, |
| 11 | +// unused_assignments, |
12 | 12 | )]
|
13 | 13 | use proc_macro::TokenStream;
|
14 | 14 | use proc_macro2 as pm2;
|
15 | 15 | use pm2::Span;
|
16 | 16 | type TS = pm2::TokenStream;
|
17 |
| -use regex::Regex; |
| 17 | +// use regex::Regex; |
18 | 18 | use quote::{quote, ToTokens};
|
19 | 19 | use syn::{self, DeriveInput, parse_macro_input, Attribute};
|
20 | 20 | use syn::{Data::Struct, DataStruct};
|
21 | 21 | use syn::{Expr, ExprLit, ExprPath};
|
22 |
| -use syn::{Ident, Type, Field, Fields::Named, Fields::Unnamed}; |
23 |
| -use syn::{punctuated::Punctuated, token::Comma}; |
24 | 22 | use extend::ext;
|
25 | 23 |
|
26 |
| -use std::cell::RefCell; |
27 | 24 | use std::fmt::Display;
|
28 | 25 |
|
29 |
| -#[derive(Debug)] |
30 |
| -struct TopResource { |
31 |
| - table_name: String, |
32 |
| - type_name: String, |
33 |
| - ext: String, |
34 |
| - resref: u16, |
35 |
| -} |
36 |
| -impl TopResource { |
37 |
| - /// Reads a #[topresource(table_name, "itm", 0x03ed)] attribute. |
38 |
| - fn from(ident: &syn::Ident, mut parser: AttrParser)->Self { |
39 |
| - let table_name = match parser.get::<syn::Expr>() { |
40 |
| - Some(AttrArg::Ident(s)) => s, |
41 |
| - Some(AttrArg::Str(s)) => s, |
42 |
| - _ => panic!("bad topresource parameter 1, expected ident") |
43 |
| - }; |
44 |
| - let ext = match parser.get::<syn::Expr>() { |
45 |
| - Some(AttrArg::Str(s)) => s, |
46 |
| - _ => panic!("bad topresource parameter 2, expected string") |
47 |
| - }; |
48 |
| - let resref = match parser.get::<syn::Expr>() { |
49 |
| - Some(AttrArg::Int(n)) => n as u16, |
50 |
| - _ => panic!("bad topresource parameter 3, expected integer") |
51 |
| - }; |
52 |
| - Self { |
53 |
| - type_name: ident.to_string(), |
54 |
| - table_name, ext, resref |
55 |
| - } |
56 |
| - } |
57 |
| - /// Stores this resource in the global table. |
58 |
| - fn store(self) { |
59 |
| - TOP.with(|v| v.borrow_mut().push(self)) |
60 |
| - } |
61 |
| -} |
62 |
| -thread_local! { |
63 |
| - static TOP: RefCell<Vec<TopResource>> = |
64 |
| - RefCell::new(Vec::<TopResource>::new()); |
65 |
| -} |
66 | 26 | // use std::any::type_name;
|
67 | 27 | // fn type_of<T>(_:&T)->&'static str { type_name::<T>() }
|
68 | 28 |
|
@@ -632,30 +592,13 @@ impl ToTokens for DeriveResourceTree {
|
632 | 592 | }
|
633 | 593 | }
|
634 | 594 |
|
635 |
| -/// The macro deriving `Resource`. |
636 |
| -#[proc_macro_derive(ResourceTree,attributes(topresource))] |
| 595 | +/// The macro deriving `ResourceTree`. |
| 596 | +#[proc_macro_derive(ResourceTree)] |
637 | 597 | pub fn derive_resource(tokens: TokenStream)->TokenStream {
|
638 |
| - let DeriveInput{ ident, data, attrs,.. } = parse_macro_input!(tokens); |
| 598 | + let DeriveInput{ ident, data, .. } = parse_macro_input!(tokens); |
639 | 599 | let fields = Fields::from(data);
|
640 |
| - let mut ext = String::new(); |
641 |
| - for (name, args) in attrs.iter().map(parse_attr) { |
642 |
| - match name.as_str() { |
643 |
| - "topresource" => { |
644 |
| - let top = TopResource::from(&ident, args); |
645 |
| - ext = top.ext.clone(); |
646 |
| - top.store(); |
647 |
| - }, |
648 |
| - _ => () |
649 |
| - } |
650 |
| - } |
651 | 600 | let mut derive_forest = DeriveResourceTree::new(&ident);
|
652 | 601 | for FieldRef { name, ty, .. } in fields.iter() {
|
653 |
| - // Read attributes for this field |
654 |
| -// for (name, mut _args) in attrs.iter().map(parse_attr) { |
655 |
| -// match name.as_str() { |
656 |
| -// _ => () |
657 |
| -// } // match |
658 |
| -// } // for |
659 | 602 | if let Some(eltype) = ty.vec_eltype() {
|
660 | 603 | derive_forest.push(name.ident(), eltype);
|
661 | 604 | }
|
|
0 commit comments