phoron_core/model/
mod.rs

1//! The `phoron_core` object model representation of JVM bytecode. This is a straightforward
2//! 1:1 mapping to the JVM bytecode specification.
3
4pub mod attributes;
5pub mod constant_pool;
6
7use attributes::AttributeInfo;
8use constant_pool::types::CpInfo;
9
10#[derive(Debug, Default)]
11pub struct ClassFile {
12    pub magic: u32,
13    pub minor_version: u16,
14    pub major_version: u16,
15    pub constant_pool_count: u16,
16    pub constant_pool: Vec<Option<CpInfo>>,
17    pub access_flags: u16,
18    pub this_class: u16,
19    pub super_class: u16,
20    pub interfaces_count: u16,
21    pub interfaces: Vec<u16>,
22    pub fields_count: u16,
23    pub fields: Vec<FieldInfo>,
24    pub methods_count: u16,
25    pub methods: Vec<MethodInfo>,
26    pub attributes_count: u16,
27    pub attributes: Vec<AttributeInfo>,
28}
29
30#[derive(Debug, Default)]
31pub struct FieldInfo {
32    pub access_flags: u16,
33    pub name_index: u16,
34    pub descriptor_index: u16,
35    pub attributes_count: u16,
36    pub attributes: Vec<AttributeInfo>,
37}
38
39#[derive(Debug, Default)]
40pub struct MethodInfo {
41    pub access_flags: u16,
42    pub name_index: u16,
43    pub descriptor_index: u16,
44    pub attributes_count: u16,
45    pub attributes: Vec<AttributeInfo>,
46}
47
48pub mod access_flags {
49    pub const ACC_PUBLIC: u16 = 0x0001;
50    pub const ACC_PRIVATE: u16 = 0x0002;
51    pub const ACC_PROTECTED: u16 = 0x0004;
52    pub const ACC_STATIC: u16 = 0x0008;
53    pub const ACC_FINAL: u16 = 0x0010;
54    pub const ACC_SUPER: u16 = 0x0020;
55    pub const ACC_SYNCHRONIZED: u16 = 0x0020;
56    pub const ACC_BRIDGE: u16 = 0x0040;
57    pub const ACC_VOLATILE: u16 = 0x0040;
58    pub const ACC_TRANSIENT: u16 = 0x0080;
59    pub const ACC_VARARGS: u16 = 0x0080;
60    pub const ACC_NATIVE: u16 = 0x0100;
61    pub const ACC_INTERFACE: u16 = 0x0200;
62    pub const ACC_ABSTRACT: u16 = 0x0400;
63    pub const ACC_STRICT: u16 = 0x0800;
64    pub const ACC_SYNTHETIC: u16 = 0x1000;
65    pub const ACC_ANNOTATION: u16 = 0x2000;
66    pub const ACC_ENUM: u16 = 0x4000;
67    pub const ACC_MODULE: u16 = 0x8000;
68}
69
70#[cfg(test)]
71mod tests {
72    use super::*;
73
74    #[test]
75    fn test_default_classfile() {
76        let _cf = ClassFile::default();
77    }
78
79    #[test]
80    fn test_default_field_info() {
81        let _field_info = FieldInfo::default();
82    }
83
84    #[test]
85    fn test_default_method_info() {
86        let _field_info = MethodInfo::default();
87    }
88}