Prechádzať zdrojové kódy

Provide method for printing debug comments about the current object

Isaac Woods 4 rokov pred
rodič
commit
21c85cad33
3 zmenil súbory, kde vykonal 17 pridanie a 2 odobranie
  1. 9 0
      aml/src/lib.rs
  2. 3 2
      aml/src/parser.rs
  3. 5 0
      aml/src/term_object.rs

+ 9 - 0
aml/src/lib.rs

@@ -219,6 +219,15 @@ impl AmlContext {
             _ => panic!("Invalid local number: {}", local),
         }
     }
+
+    /// This is used by the parser to provide debug comments about the current object, which are indented to the
+    /// correct level for the current object. We most often need to print these comments from `map_with_context`s,
+    /// so it's most convenient to have this method on `AmlContext`.
+    pub(crate) fn comment(&self, verbosity: DebugVerbosity, message: &str) {
+        if verbosity <= self.debug_verbosity {
+            log::trace!("{:indent$}{}", "", message, indent = self.scope_indent + parser::INDENT_PER_SCOPE);
+        }
+    }
 }
 
 #[derive(Clone, Debug, PartialEq, Eq)]

+ 3 - 2
aml/src/parser.rs

@@ -3,6 +3,9 @@ use alloc::vec::Vec;
 use core::marker::PhantomData;
 use log::trace;
 
+/// This is the number of spaces added to indent a scope when printing parser debug messages.
+pub(crate) const INDENT_PER_SCOPE: usize = 2;
+
 pub type ParseResult<'a, 'c, R> =
     Result<(&'a [u8], &'c mut AmlContext, R), (&'a [u8], &'c mut AmlContext, AmlError)>;
 
@@ -235,8 +238,6 @@ where
     R: core::fmt::Debug,
     P: Parser<'a, 'c, R>,
 {
-    const INDENT_PER_SCOPE: usize = 2;
-
     move |input, context: &'c mut AmlContext| {
         if verbosity <= context.debug_verbosity {
             trace!("{:indent$}--> {}", "", scope_name, indent = context.scope_indent);

+ 5 - 0
aml/src/term_object.rs

@@ -137,6 +137,11 @@ where
                     let previous_scope = context.current_scope.clone();
                     context.current_scope = try_with_context!(context, name.resolve(&context.current_scope));
 
+                    context.comment(
+                        DebugVerbosity::Scopes,
+                        &(String::from("Scope name: ") + &context.current_scope.as_string()),
+                    );
+
                     try_with_context!(
                         context,
                         context.namespace.add_level(context.current_scope.clone(), LevelType::Scope)