@@ -131,13 +131,58 @@ impl<'a> ClassWriter<'a> {
131
131
. and ( self . write_exception_handlers ( exception_table) )
132
132
. and ( self . write_attributes ( attributes, cp) )
133
133
} ,
134
- & Attribute :: StackMapTable ( ref table) => self . write_u16 ( cp . get_utf8_index ( "StackMapTable" ) as u16 ) . and ( self . write_stack_map_table ( table, cp) ) ,
134
+ & Attribute :: StackMapTable ( ref table) => self . write_stack_map_table ( table, cp) ,
135
135
_ => Ok ( 0 )
136
136
}
137
137
}
138
138
139
139
fn write_stack_map_table ( & mut self , table : & Vec < StackMapFrame > , cp : & ConstantPool ) -> Result < usize , Error > {
140
- self . write_u16 ( cp. get_utf8_index ( "StackMapTable" ) as u16 ) . and ( self . write_u32 ( 2 + table. iter ( ) . map ( |st| st. len ( ) ) . fold ( 0 , |acc, x| acc + x) as u32 ) )
140
+ // attribute_name_index
141
+ self . write_u16 ( cp. get_utf8_index ( "StackMapTable" ) as u16 )
142
+ // attribute_length = number_of_entries length (2) + sum of entries' length
143
+ . and ( self . write_u32 ( 2 + table. iter ( ) . map ( |st| st. len ( ) ) . fold ( 0 , |acc, x| acc + x) as u32 ) )
144
+ // number_of_entries
145
+ . and ( self . write_u16 ( table. len ( ) as u16 ) )
146
+ // entries
147
+ . and ( table. iter ( ) . fold ( Ok ( 0 ) , |acc, x| {
148
+ match x {
149
+ & StackMapFrame :: SameFrame { tag } => self . write_u8 ( tag) ,
150
+ & StackMapFrame :: SameLocals1StackItemFrame { tag, ref stack } => self . write_u8 ( tag) . and ( self . write_verification_type ( stack) ) ,
151
+ & StackMapFrame :: SameLocals1StackItemFrameExtended { offset_delta, ref stack } => self . write_u8 ( 247 ) . and ( self . write_u16 ( offset_delta) ) . and ( self . write_verification_type ( stack) ) ,
152
+ & StackMapFrame :: ChopFrame { tag, offset_delta } => self . write_u8 ( tag) . and ( self . write_u16 ( offset_delta) ) ,
153
+ & StackMapFrame :: SameFrameExtended { offset_delta } => self . write_u8 ( 251 ) . and ( self . write_u16 ( offset_delta) ) ,
154
+ & StackMapFrame :: AppendFrame { tag, offset_delta, ref locals } => self . write_u8 ( tag) . and ( self . write_u16 ( offset_delta) ) . and ( locals. iter ( ) . fold ( Ok ( 0 ) , |acc, x| self . write_verification_type ( x) ) ) ,
155
+ & StackMapFrame :: FullFrame { offset_delta, ref locals, ref stack } => {
156
+ // full frame tag
157
+ self . write_u8 ( 255 )
158
+ // offset_delta
159
+ . and ( self . write_u16 ( offset_delta) )
160
+ // number_of_locals
161
+ . and ( self . write_u16 ( locals. len ( ) as u16 ) )
162
+ // locals
163
+ . and ( locals. iter ( ) . fold ( Ok ( 0 ) , |acc, x| self . write_verification_type ( x) ) )
164
+ // number_of_stack_items
165
+ . and ( self . write_u16 ( stack. len ( ) as u16 ) )
166
+ // stack
167
+ . and ( stack. iter ( ) . fold ( Ok ( 0 ) , |acc, x| self . write_verification_type ( x) ) )
168
+ } ,
169
+ & StackMapFrame :: FutureUse { tag } => self . write_u8 ( tag)
170
+ }
171
+ } ) )
172
+ }
173
+
174
+ fn write_verification_type ( & mut self , info : & VerificationType ) -> Result < usize , Error > {
175
+ match info {
176
+ & VerificationType :: Top => self . write_u8 ( 0 ) ,
177
+ & VerificationType :: Integer => self . write_u8 ( 1 ) ,
178
+ & VerificationType :: Float => self . write_u8 ( 2 ) ,
179
+ & VerificationType :: Long => self . write_u8 ( 4 ) ,
180
+ & VerificationType :: Double => self . write_u8 ( 3 ) ,
181
+ & VerificationType :: Null => self . write_u8 ( 5 ) ,
182
+ & VerificationType :: UninitializedThis => self . write_u8 ( 6 ) ,
183
+ & VerificationType :: Object { ref cpool_index } => self . write_u8 ( 7 ) . and ( self . write_u16 ( cpool_index. idx as u16 ) ) ,
184
+ & VerificationType :: Uninitialized { offset } => self . write_u8 ( 8 ) . and ( self . write_u16 ( offset) )
185
+ }
141
186
}
142
187
143
188
fn write_instructions ( & mut self , instructions : & Vec < Instruction > ) -> Result < usize , Error > {
@@ -231,7 +276,7 @@ impl<'a> ClassWriter<'a> {
231
276
& Instruction :: FNEG => self . write_u8 ( 0x76 ) ,
232
277
& Instruction :: FREM => self . write_u8 ( 0x72 ) ,
233
278
& Instruction :: FRETURN => self . write_u8 ( 0xae ) ,
234
- & Instruction :: FSTORE ( value) => self . write_u8 ( 0x38 ) ,
279
+ & Instruction :: FSTORE ( value) => self . write_u8 ( 0x38 ) . and ( self . write_u8 ( value ) ) ,
235
280
& Instruction :: FSTORE_0 => self . write_u8 ( 0x43 ) ,
236
281
& Instruction :: FSTORE_1 => self . write_u8 ( 0x44 ) ,
237
282
& Instruction :: FSTORE_2 => self . write_u8 ( 0x45 ) ,
@@ -327,17 +372,17 @@ impl<'a> ClassWriter<'a> {
327
372
& Instruction :: LNEG => self . write_u8 ( 0x75 ) ,
328
373
//LOOKUPSWITCH(i32, Vec<(i32, i32)>),
329
374
& Instruction :: LOOKUPSWITCH ( a, ref l) => {
330
- self . write_u8 ( 0xab ) ;
375
+ let _ = self . write_u8 ( 0xab ) ;
331
376
let padding = ( 4 - ( ( offset + 1 ) % 4 ) ) % 4 ;
332
377
333
378
for _ in 0 ..padding {
334
- self . write_u8 ( 0 ) ;
379
+ let _ = self . write_u8 ( 0 ) ;
335
380
}
336
381
337
382
let padding = ( 4 - ( ( offset + 1 ) % 4 ) ) % 4 ;
338
383
339
384
for _ in 0 ..padding {
340
- self . write_u8 ( 0 ) ;
385
+ let _ = self . write_u8 ( 0 ) ;
341
386
}
342
387
343
388
self . write_u32 ( a as u32 ) ;
@@ -418,7 +463,10 @@ impl<'a> ClassWriter<'a> {
418
463
fn write_exception_handlers ( & mut self , exception_table : & Vec < ExceptionHandler > ) -> Result < usize , Error > {
419
464
self . write_u16 ( exception_table. len ( ) as u16 )
420
465
. and ( exception_table. iter ( ) . fold ( Ok ( 0 ) , |acc, x| {
421
- self . write_u16 ( x. start_pc ) . and ( self . write_u16 ( x. end_pc ) ) . and ( self . write_u16 ( x. handler_pc ) ) . and ( self . write_u16 ( x. catch_type . idx as u16 ) )
466
+ self . write_u16 ( x. start_pc )
467
+ . and ( self . write_u16 ( x. end_pc ) )
468
+ . and ( self . write_u16 ( x. handler_pc ) )
469
+ . and ( self . write_u16 ( x. catch_type . idx as u16 ) )
422
470
} ) )
423
471
}
424
472
0 commit comments