From 604975aa42823d34d3394da217da25e87dcd9c27 Mon Sep 17 00:00:00 2001 From: Tad Hardesty Date: Tue, 17 Apr 2018 18:59:03 -0700 Subject: [PATCH] Improve the accuracy of the macro interpolation bug checker --- src/dreammaker/preprocessor.rs | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/src/dreammaker/preprocessor.rs b/src/dreammaker/preprocessor.rs index 9df39113..02b2f3bc 100644 --- a/src/dreammaker/preprocessor.rs +++ b/src/dreammaker/preprocessor.rs @@ -237,9 +237,8 @@ pub struct Preprocessor<'ctx> { maps: Vec, skins: Vec, - // .0 is being written, .1 is being read last_printable_input_loc: Location, - danger_idents: (HashMap, HashMap), + danger_idents: HashMap, in_interp_string: u32, } @@ -376,7 +375,7 @@ impl<'ctx> Preprocessor<'ctx> { } fn check_danger_ident(&mut self, name: &str, kind: &str) { - if let Some(loc) = self.danger_idents.1.get(name) { + if let Some(loc) = self.danger_idents.get(name) { self.context.register_error(DMError::new(*loc, format!( "macro {:?} used immediately before being {}:\n\ https://secure.byond.com/forum/?post=2072419", name, kind @@ -589,7 +588,7 @@ impl<'ctx> Preprocessor<'ctx> { Token::Ident(ref ident, _) if ident != self.include_stack.top_no_expand() => { // lint for BYOND bug if self.in_interp_string > 0 { - self.danger_idents.0.insert(ident.clone(), self.last_input_loc); + self.danger_idents.insert(ident.clone(), self.last_input_loc); } // substitute special macros @@ -777,13 +776,11 @@ impl<'ctx> Iterator for Preprocessor<'ctx> { if let Some(tok) = self.inner_next() { // linting for https://secure.byond.com/forum/?post=2072419 - if !tok.token.is_whitespace() { + if !tok.token.is_whitespace() && tok.token != Token::Punct(Punctuation::Hash) { if tok.location.file != self.last_printable_input_loc.file || tok.location.line > self.last_printable_input_loc.line { - // swap read/write buffers - ::std::mem::swap(&mut self.danger_idents.0, &mut self.danger_idents.1); - self.danger_idents.0.clear(); + self.danger_idents.clear(); } self.last_printable_input_loc = tok.location; }