@@ -17,6 +17,10 @@ pub struct DebugConfig {
1717 pub variable_debug : AtomicBool ,
1818 /// 是否启用内存池调试输出
1919 pub memory_debug : AtomicBool ,
20+ /// 是否启用解析器调试输出
21+ pub parser_debug : AtomicBool ,
22+ /// 是否启用尾递归优化调试输出
23+ pub tail_recursion_debug : AtomicBool ,
2024 /// 是否启用所有调试输出
2125 pub all_debug : AtomicBool ,
2226}
@@ -31,6 +35,8 @@ impl DebugConfig {
3135 function_debug : AtomicBool :: new ( false ) ,
3236 variable_debug : AtomicBool :: new ( false ) ,
3337 memory_debug : AtomicBool :: new ( false ) ,
38+ parser_debug : AtomicBool :: new ( false ) ,
39+ tail_recursion_debug : AtomicBool :: new ( false ) ,
3440 all_debug : AtomicBool :: new ( false ) ,
3541 }
3642 }
@@ -125,6 +131,36 @@ impl DebugConfig {
125131 self . memory_debug . load ( Ordering :: Relaxed ) || self . all_debug . load ( Ordering :: Relaxed )
126132 }
127133
134+ /// 启用解析器调试输出
135+ pub fn enable_parser_debug ( & self ) {
136+ self . parser_debug . store ( true , Ordering :: Relaxed ) ;
137+ }
138+
139+ /// 禁用解析器调试输出
140+ pub fn disable_parser_debug ( & self ) {
141+ self . parser_debug . store ( false , Ordering :: Relaxed ) ;
142+ }
143+
144+ /// 检查是否启用解析器调试输出
145+ pub fn is_parser_debug_enabled ( & self ) -> bool {
146+ self . parser_debug . load ( Ordering :: Relaxed ) || self . all_debug . load ( Ordering :: Relaxed )
147+ }
148+
149+ /// 启用尾递归优化调试输出
150+ pub fn enable_tail_recursion_debug ( & self ) {
151+ self . tail_recursion_debug . store ( true , Ordering :: Relaxed ) ;
152+ }
153+
154+ /// 禁用尾递归优化调试输出
155+ pub fn disable_tail_recursion_debug ( & self ) {
156+ self . tail_recursion_debug . store ( false , Ordering :: Relaxed ) ;
157+ }
158+
159+ /// 检查是否启用尾递归优化调试输出
160+ pub fn is_tail_recursion_debug_enabled ( & self ) -> bool {
161+ self . tail_recursion_debug . load ( Ordering :: Relaxed ) || self . all_debug . load ( Ordering :: Relaxed )
162+ }
163+
128164 /// 启用所有调试输出
129165 pub fn enable_all_debug ( & self ) {
130166 self . all_debug . store ( true , Ordering :: Relaxed ) ;
@@ -139,6 +175,7 @@ impl DebugConfig {
139175 self . function_debug . store ( false , Ordering :: Relaxed ) ;
140176 self . variable_debug . store ( false , Ordering :: Relaxed ) ;
141177 self . memory_debug . store ( false , Ordering :: Relaxed ) ;
178+ self . tail_recursion_debug . store ( false , Ordering :: Relaxed ) ;
142179 }
143180
144181 /// 从命令行参数解析调试配置
@@ -151,6 +188,9 @@ impl DebugConfig {
151188 "--cn-debug-function" => self . enable_function_debug ( ) ,
152189 "--cn-debug-variable" => self . enable_variable_debug ( ) ,
153190 "--cn-debug-memory" => self . enable_memory_debug ( ) ,
191+ "--cn-debug-parser" => self . enable_parser_debug ( ) ,
192+ "--cn-debug-tail" => self . enable_tail_recursion_debug ( ) ,
193+ "--cn-debug" => self . enable_tail_recursion_debug ( ) , // 通用调试模式启用尾递归调试
154194 "--cn-debug-all" => self . enable_all_debug ( ) ,
155195 "--cn-no-debug" => self . disable_all_debug ( ) ,
156196 _ => { }
@@ -246,6 +286,16 @@ macro_rules! memory_debug_println {
246286 } ;
247287}
248288
289+ /// 解析器调试输出宏
290+ #[ macro_export]
291+ macro_rules! parser_debug_println {
292+ ( $( $arg: tt) * ) => {
293+ if $crate:: debug_config:: get_debug_config( ) . is_parser_debug_enabled( ) {
294+ println!( $( $arg) * ) ;
295+ }
296+ } ;
297+ }
298+
249299/// 打印调试帮助信息
250300pub fn print_debug_help ( ) {
251301 println ! ( "CodeNothing v0.7.4 调试选项:" ) ;
@@ -255,6 +305,7 @@ pub fn print_debug_help() {
255305 println ! ( " --cn-debug-function 启用函数调用调试输出" ) ;
256306 println ! ( " --cn-debug-variable 启用变量访问调试输出" ) ;
257307 println ! ( " --cn-debug-memory 启用内存池调试输出" ) ;
308+ println ! ( " --cn-debug-parser 启用解析器调试输出" ) ;
258309 println ! ( " --cn-debug-all 启用所有调试输出" ) ;
259310 println ! ( " --cn-no-debug 禁用所有调试输出" ) ;
260311 println ! ( ) ;
0 commit comments