Skip to content

Commit 2b4ac63

Browse files
committed
fix PartialEq
1 parent 79f6aac commit 2b4ac63

File tree

3 files changed

+29
-25
lines changed

3 files changed

+29
-25
lines changed

src/bytecode/classfile.rs

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
/// itself, it doesn't represent every byte in the class definition, though, many information are
55
/// encoded in the type system instead. This approach may seem restrictive but it helps achieving
66
/// bytecode safety.
7-
#[derive(Debug)]
7+
#[derive(Debug, PartialEq)]
88
pub struct Classfile {
99
pub version: ClassfileVersion,
1010
pub constant_pool: ConstantPool,
@@ -66,7 +66,7 @@ impl Default for ClassfileVersion {
6666
///
6767
/// A `ConstantPool` is a table of various string and number literal constants that are referred
6868
/// within the substructures of the `Classfile`.
69-
#[derive(Debug)]
69+
#[derive(Debug, PartialEq)]
7070
pub struct ConstantPool {
7171
pub constants: Vec<Constant>
7272
}
@@ -239,7 +239,7 @@ impl ReferenceKind {
239239
}
240240
}
241241

242-
#[derive(Default, Debug)]
242+
#[derive(Default, Debug, PartialEq)]
243243
pub struct AccessFlags {
244244
pub flags: u16
245245
}
@@ -323,23 +323,23 @@ pub enum ParameterAccessFlags {
323323
Mandated = 0x8000
324324
}
325325

326-
#[derive(Default, Debug)]
326+
#[derive(Default, Debug, PartialEq)]
327327
pub struct Field {
328328
pub access_flags: AccessFlags,
329329
pub name_index: ConstantPoolIndex,
330330
pub descriptor_index: ConstantPoolIndex,
331331
pub attributes: Vec<Attribute>
332332
}
333333

334-
#[derive(Default, Debug)]
334+
#[derive(Default, Debug, PartialEq)]
335335
pub struct Method {
336336
pub access_flags: AccessFlags,
337337
pub name_index: ConstantPoolIndex,
338338
pub descriptor_index: ConstantPoolIndex,
339339
pub attributes: Vec<Attribute>
340340
}
341341

342-
#[derive(Debug)]
342+
#[derive(Debug, PartialEq)]
343343
pub enum Attribute {
344344
ConstantValue(ConstantPoolIndex),
345345
Code { max_stack: u16, max_locals: u16, code: Vec<Instruction>, exception_table: Vec<ExceptionHandler>, attributes: Vec<Attribute> },
@@ -367,7 +367,7 @@ pub enum Attribute {
367367
RawAttribute { name_index: ConstantPoolIndex, info: Vec<u8> }
368368
}
369369

370-
#[derive(Debug)]
370+
#[derive(Debug, PartialEq)]
371371
pub enum StackMapFrame {
372372
SameFrame { tag: u8 },
373373
SameLocals1StackItemFrame { tag: u8, stack: VerificationType },
@@ -394,7 +394,7 @@ impl StackMapFrame {
394394
}
395395
}
396396

397-
#[derive(Debug)]
397+
#[derive(Debug, PartialEq)]
398398
pub enum VerificationType {
399399
Top,
400400
Integer,
@@ -417,29 +417,29 @@ impl VerificationType {
417417
}
418418
}
419419

420-
#[derive(Debug)]
420+
#[derive(Debug, PartialEq)]
421421
pub struct ExceptionHandler {
422422
pub start_pc: u16,
423423
pub end_pc: u16,
424424
pub handler_pc: u16,
425425
pub catch_type: ConstantPoolIndex
426426
}
427427

428-
#[derive(Debug)]
428+
#[derive(Debug, PartialEq)]
429429
pub struct InnerClass {
430430
pub inner_class_info_index: ConstantPoolIndex,
431431
pub outer_class_info_index: ConstantPoolIndex,
432432
pub inner_name_index: ConstantPoolIndex,
433433
pub access_flags: AccessFlags
434434
}
435435

436-
#[derive(Debug)]
436+
#[derive(Debug, PartialEq)]
437437
pub struct LineNumberTable {
438438
pub start_pc: u16,
439439
pub line_number: u16
440440
}
441441

442-
#[derive(Debug)]
442+
#[derive(Debug, PartialEq)]
443443
pub struct LocalVariableTable {
444444
pub start_pc: u16,
445445
pub length: u16,
@@ -448,7 +448,7 @@ pub struct LocalVariableTable {
448448
pub index: u16
449449
}
450450

451-
#[derive(Debug)]
451+
#[derive(Debug, PartialEq)]
452452
pub struct LocalVariableTypeTable {
453453
pub start_pc: u16,
454454
pub length: u16,
@@ -457,7 +457,7 @@ pub struct LocalVariableTypeTable {
457457
pub index: u16
458458
}
459459

460-
#[derive(Debug)]
460+
#[derive(Debug, PartialEq)]
461461
pub struct Annotation {
462462
pub type_index: ConstantPoolIndex,
463463
pub element_value_pairs: Vec<ElementValuePair>
@@ -470,7 +470,7 @@ impl Annotation {
470470
}
471471
}
472472

473-
#[derive(Debug)]
473+
#[derive(Debug, PartialEq)]
474474
pub struct ElementValuePair {
475475
pub element_name_index: ConstantPoolIndex,
476476
pub value: ElementValue
@@ -482,7 +482,7 @@ impl ElementValuePair {
482482
}
483483
}
484484

485-
#[derive(Debug)]
485+
#[derive(Debug, PartialEq)]
486486
pub enum ElementValue {
487487
ConstantValue(u8, ConstantPoolIndex),
488488
Enum { type_name_index: ConstantPoolIndex, const_name_index: ConstantPoolIndex },
@@ -503,7 +503,7 @@ impl ElementValue {
503503
}
504504
}
505505

506-
#[derive(Debug)]
506+
#[derive(Debug, PartialEq)]
507507
pub struct TypeAnnotation {
508508
pub target_info: TargetInfo,
509509
pub target_path: TypePath,
@@ -517,7 +517,7 @@ impl TypeAnnotation {
517517
}
518518
}
519519

520-
#[derive(Debug)]
520+
#[derive(Debug, PartialEq)]
521521
pub enum TargetInfo {
522522
TypeParameter { subtype: u8, idx: u8 },
523523
SuperType { idx: u16 },
@@ -563,7 +563,7 @@ impl TargetInfo {
563563
}
564564
}
565565

566-
#[derive(Debug)]
566+
#[derive(Debug, PartialEq)]
567567
pub struct TypePath {
568568
pub path: Vec<(TypePathKind, u8)>
569569
}
@@ -574,7 +574,7 @@ impl TypePath {
574574
}
575575
}
576576

577-
#[derive(Debug)]
577+
#[derive(Debug, PartialEq)]
578578
pub enum TypePathKind {
579579
Array, // Annotation is deeper in an array type
580580
Nested, // Annotation is deeper in a nested type
@@ -593,7 +593,7 @@ impl TypePathKind {
593593
}
594594
}
595595

596-
#[derive(Debug)]
596+
#[derive(Debug, PartialEq)]
597597
pub struct BootstrapMethod {
598598
pub bootstrap_method_ref: ConstantPoolIndex,
599599
pub bootstrap_arguments: Vec<ConstantPoolIndex>
@@ -602,7 +602,7 @@ pub struct BootstrapMethod {
602602
impl BootstrapMethod {
603603
}
604604

605-
#[derive(Debug)]
605+
#[derive(Debug, PartialEq)]
606606
pub struct MethodParameter {
607607
pub name_index: ConstantPoolIndex,
608608
pub access_flags: AccessFlags
@@ -613,7 +613,7 @@ impl MethodParameter {
613613
}
614614

615615
#[allow(non_camel_case_types)]
616-
#[derive(Debug)]
616+
#[derive(Debug, PartialEq)]
617617
pub enum Instruction {
618618
AALOAD,
619619
AASTORE,

src/instrumentation/mod.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ use super::bytecode::classfile::*;
22

33
pub mod asm;
44

5+
#[derive(PartialEq)]
56
pub enum JavaType {
67
Boolean,
78
String,
@@ -14,6 +15,7 @@ pub enum JavaType {
1415
Void
1516
}
1617

18+
#[derive(PartialEq)]
1719
pub struct JavaClass {
1820
methods: Vec<Method>,
1921
fields: Vec<Field>
@@ -41,6 +43,7 @@ impl JavaClass {
4143
}
4244
}
4345

46+
#[derive(PartialEq)]
4447
pub struct Field {
4548
name: String,
4649
field_type: JavaType
@@ -55,6 +58,7 @@ impl Field {
5558
}
5659
}
5760

61+
#[derive(PartialEq)]
5862
pub struct Method {
5963
name: String,
6064
return_type: JavaType

src/main.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,11 @@ fn main() {
3333
_ => println!("Unknown action: {}", action)
3434
}
3535
},
36-
Err(err) => assert!(false, format!("{:?}", err))
36+
Err(err) => assert!(false, "{}", err)
3737
}
3838

3939
},
40-
Err(err) => assert!(false, format!("{:?}", err))
40+
Err(err) => assert!(false, "{}", err)
4141
}
4242
} else {
4343
println!("Invalid arguments. Usage: jvmti [read|write] <Class file>")

0 commit comments

Comments
 (0)