From 8939238d2e8f745abb338a71844a0b82bc12030e Mon Sep 17 00:00:00 2001 From: Dominion Date: Wed, 10 May 2023 23:17:06 -0400 Subject: [PATCH] Evaluate __FILE__ and __LINE__ and put them in the doc comments --- crates/dreammaker/src/preprocessor.rs | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/crates/dreammaker/src/preprocessor.rs b/crates/dreammaker/src/preprocessor.rs index a12a3bd5..953c87b2 100644 --- a/crates/dreammaker/src/preprocessor.rs +++ b/crates/dreammaker/src/preprocessor.rs @@ -978,7 +978,24 @@ impl<'ctx> Preprocessor<'ctx> { // substitute special macros if ident == "__FILE__" { - self.annotate_macro(ident, Location::builtins(), None); + let path = self.include_stack.top_file_path().to_str().unwrap(); + let dm_path; + + #[cfg(windows)] { + dm_path = path.replace("\\", "/"); + } + + #[cfg(not(windows))] { + dm_path = path.to_string(); + } + + let mut doc_collection = DocCollection::default(); + doc_collection.push(DocComment { + kind: crate::docs::CommentKind::Line, + target: DocTarget::FollowingItem, + text: dm_path, + }); + self.annotate_macro(ident, Location::builtins(), Some(Rc::new(doc_collection))); for include in self.include_stack.stack.iter().rev() { if let Include::File { ref path, .. } = *include { self.output.push_back(Token::String(path.display().to_string())); @@ -988,7 +1005,13 @@ impl<'ctx> Preprocessor<'ctx> { self.output.push_back(Token::String(String::new())); return Ok(()); } else if ident == "__LINE__" { - self.annotate_macro(ident, Location::builtins(), None); + let mut doc_collection = DocCollection::default(); + doc_collection.push(DocComment { + kind: crate::docs::CommentKind::Line, + target: DocTarget::FollowingItem, + text: self.last_input_loc.line.to_string(), + }); + self.annotate_macro(ident, Location::builtins(), Some(Rc::new(doc_collection))); self.output.push_back(Token::Int(self.last_input_loc.line as i32)); return Ok(()); }