File tree Expand file tree Collapse file tree 1 file changed +24
-6
lines changed Expand file tree Collapse file tree 1 file changed +24
-6
lines changed Original file line number Diff line number Diff line change @@ -180,20 +180,38 @@ impl ArchitectureSize {
180180
181181 // create a suitable expression in bytes from a pointer size argument
182182 pub fn format ( & self , ptrsize_expr : & str ) -> String {
183+ self . format_term ( ptrsize_expr, false )
184+ }
185+
186+ // create a suitable expression in bytes from a pointer size argument,
187+ // extended API with optional brackets around the sum
188+ pub fn format_term ( & self , ptrsize_expr : & str , suppress_brackets : bool ) -> String {
183189 if self . pointers != 0 {
184190 if self . bytes > 0 {
185191 // both
186- format ! (
187- "({}+{}*{ptrsize_expr})" ,
188- self . constant_bytes( ) ,
189- self . pointers_to_add( )
190- )
192+ if suppress_brackets {
193+ format ! (
194+ "{}+{}*{ptrsize_expr}" ,
195+ self . constant_bytes( ) ,
196+ self . pointers_to_add( )
197+ )
198+ } else {
199+ format ! (
200+ "({}+{}*{ptrsize_expr})" ,
201+ self . constant_bytes( ) ,
202+ self . pointers_to_add( )
203+ )
204+ }
191205 } else if self . pointers == 1 {
192206 // one pointer
193207 ptrsize_expr. into ( )
194208 } else {
195209 // only pointer
196- format ! ( "({}*{ptrsize_expr})" , self . pointers_to_add( ) )
210+ if suppress_brackets {
211+ format ! ( "{}*{ptrsize_expr}" , self . pointers_to_add( ) )
212+ } else {
213+ format ! ( "({}*{ptrsize_expr})" , self . pointers_to_add( ) )
214+ }
197215 }
198216 } else {
199217 // only bytes
You can’t perform that action at this time.
0 commit comments