Skip to content

Commit 323740e

Browse files
committed
removed 'topresource' attribute
1 parent c650a6f commit 323740e

File tree

3 files changed

+8
-67
lines changed

3 files changed

+8
-67
lines changed

macros/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ edition = "2021"
1010
syn = { version = "1.0.82", features = ["full", "extra-traits"] }
1111
quote = "1.0.10"
1212
proc-macro2 = "1.0.49"
13-
regex = "1.7.1"
1413
extend = "1.1.2"
1514

1615
[lib]

macros/src/lib.rs

Lines changed: 8 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -1,68 +1,28 @@
11
#![allow(
22
clippy::single_match,
33
// unreachable_code,
4-
dead_code,
5-
unused_variables,
6-
unused_imports,
4+
// dead_code,
5+
// unused_variables,
6+
// unused_imports,
77
// unused_macros,
88
// unused_parens,
99
// unused_mut,
1010
// unused_attributes,
11-
unused_assignments,
11+
// unused_assignments,
1212
)]
1313
use proc_macro::TokenStream;
1414
use proc_macro2 as pm2;
1515
use pm2::Span;
1616
type TS = pm2::TokenStream;
17-
use regex::Regex;
17+
// use regex::Regex;
1818
use quote::{quote, ToTokens};
1919
use syn::{self, DeriveInput, parse_macro_input, Attribute};
2020
use syn::{Data::Struct, DataStruct};
2121
use syn::{Expr, ExprLit, ExprPath};
22-
use syn::{Ident, Type, Field, Fields::Named, Fields::Unnamed};
23-
use syn::{punctuated::Punctuated, token::Comma};
2422
use extend::ext;
2523

26-
use std::cell::RefCell;
2724
use std::fmt::Display;
2825

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-
}
6626
// use std::any::type_name;
6727
// fn type_of<T>(_:&T)->&'static str { type_name::<T>() }
6828

@@ -632,30 +592,13 @@ impl ToTokens for DeriveResourceTree {
632592
}
633593
}
634594

635-
/// The macro deriving `Resource`.
636-
#[proc_macro_derive(ResourceTree,attributes(topresource))]
595+
/// The macro deriving `ResourceTree`.
596+
#[proc_macro_derive(ResourceTree)]
637597
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);
639599
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-
}
651600
let mut derive_forest = DeriveResourceTree::new(&ident);
652601
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
659602
if let Some(eltype) = ty.vec_eltype() {
660603
derive_forest.push(name.ident(), eltype);
661604
}

src/restypes.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,6 @@ pub struct ItemAbility {
7777
}
7878
/// A game item, corresponding to a .itm file.
7979
#[derive(Debug,Pack,SqlRow,ResourceTree)]
80-
#[topresource(items, "itm", 0x03ed)]
8180
pub struct Item {
8281
#[header("ITM V1 ")]
8382
unidentified_name: Strref,

0 commit comments

Comments
 (0)