@@ -12,6 +12,7 @@ use nom::{AsChar, IResult};
1212use owo_colors:: OwoColorize ;
1313
1414use crate :: demangle:: LabelKind ;
15+ use crate :: opts:: NameDisplay ;
1516use crate :: { color, demangle} ;
1617
1718#[ derive( Clone , Debug ) ]
@@ -51,18 +52,14 @@ impl<'a> Instruction<'a> {
5152
5253impl std:: fmt:: Display for Instruction < ' _ > {
5354 fn fmt ( & self , f : & mut std:: fmt:: Formatter < ' _ > ) -> std:: fmt:: Result {
55+ let display = NameDisplay :: from ( & * f) ;
5456 if self . op . starts_with ( "#DEBUG_VALUE:" ) {
5557 write ! ( f, "{}" , color!( self . op, OwoColorize :: blue) ) ?;
5658 } else {
5759 write ! ( f, "{}" , color!( self . op, OwoColorize :: bright_blue) ) ?;
5860 }
5961 if let Some ( args) = self . args {
60- let args = if f. sign_minus ( ) {
61- // Do not demangle
62- Cow :: from ( args)
63- } else {
64- demangle:: contents ( args, f. alternate ( ) )
65- } ;
62+ let args = demangle:: contents ( args, display) ;
6663 let w_label = demangle:: color_local_labels ( & args) ;
6764 let w_comment = demangle:: color_comment ( & w_label) ;
6865 write ! ( f, " {w_comment}" ) ?;
@@ -99,6 +96,7 @@ impl std::fmt::Display for Statement<'_> {
9996
10097impl std:: fmt:: Display for Directive < ' _ > {
10198 fn fmt ( & self , f : & mut std:: fmt:: Formatter < ' _ > ) -> std:: fmt:: Result {
99+ let display = NameDisplay :: from ( & * f) ;
102100 match self {
103101 Directive :: File ( ff) => ff. fmt ( f) ,
104102 Directive :: Loc ( l) => l. fmt ( f) ,
@@ -107,7 +105,7 @@ impl std::fmt::Display for Directive<'_> {
107105 f. write_str ( & format ! ( ".set {}" , color!( g, OwoColorize :: bright_black) ) )
108106 }
109107 Directive :: SectionStart ( s) => {
110- let dem = demangle:: contents ( s, f . alternate ( ) ) ;
108+ let dem = demangle:: contents ( s, display ) ;
111109 f. write_str ( & format ! (
112110 "{} {}" ,
113111 color!( ".section" , OwoColorize :: bright_black) ,
@@ -140,11 +138,12 @@ impl std::fmt::Display for File<'_> {
140138
141139impl std:: fmt:: Display for GenericDirective < ' _ > {
142140 fn fmt ( & self , f : & mut std:: fmt:: Formatter < ' _ > ) -> std:: fmt:: Result {
141+ let display = NameDisplay :: from ( & * f) ;
143142 write ! (
144143 f,
145144 "\t .{}" ,
146145 color!(
147- demangle:: contents( self . 0 , f . alternate ( ) ) ,
146+ demangle:: contents( self . 0 , display ) ,
148147 OwoColorize :: bright_black
149148 )
150149 )
@@ -172,13 +171,26 @@ impl std::fmt::Display for Loc<'_> {
172171 }
173172}
174173
174+ impl From < & std:: fmt:: Formatter < ' _ > > for NameDisplay {
175+ fn from ( f : & std:: fmt:: Formatter ) -> Self {
176+ if f. sign_minus ( ) {
177+ NameDisplay :: Mangled
178+ } else if f. alternate ( ) {
179+ NameDisplay :: Full
180+ } else {
181+ NameDisplay :: Short
182+ }
183+ }
184+ }
185+
175186impl std:: fmt:: Display for Label < ' _ > {
176187 fn fmt ( & self , f : & mut std:: fmt:: Formatter < ' _ > ) -> std:: fmt:: Result {
188+ let display = NameDisplay :: from ( & * f) ;
177189 write ! (
178190 f,
179191 "{}:" ,
180192 color!(
181- demangle:: contents( self . id, f . alternate ( ) ) ,
193+ demangle:: contents( self . id, display ) ,
182194 OwoColorize :: bright_black
183195 )
184196 )
0 commit comments