File tree 1 file changed +24
-6
lines changed
1 file changed +24
-6
lines changed Original file line number Diff line number Diff line change @@ -180,20 +180,38 @@ impl ArchitectureSize {
180
180
181
181
// create a suitable expression in bytes from a pointer size argument
182
182
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 {
183
189
if self . pointers != 0 {
184
190
if self . bytes > 0 {
185
191
// 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
+ }
191
205
} else if self . pointers == 1 {
192
206
// one pointer
193
207
ptrsize_expr. into ( )
194
208
} else {
195
209
// 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
+ }
197
215
}
198
216
} else {
199
217
// only bytes
You can’t perform that action at this time.
0 commit comments