lvm-class 0.4.1

JVM class file parser and writer for the Lagertha VM project
Documentation
// TODO: Right now I plan to use it in runtime as well. idk if it's a good idea or not.

/// https://docs.oracle.com/javase/specs/jvms/se25/html/jvms-4.html#jvms-4.1-200-E.1
/// Table 4.1-B. Class access and property modifiers
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct ClassFlags(pub(crate) u16);

/// https://docs.oracle.com/javase/specs/jvms/se25/html/jvms-4.html#jvms-4.7.6-300-D.1-D.1
/// Table 4.7.6-A. Nested class access and property flags
#[derive(Debug, Clone, Copy)]
pub struct InnerClassFlags(u16);

/// https://docs.oracle.com/javase/specs/jvms/se25/html/jvms-4.html#jvms-4.6-200-A.1
/// Table 4.6-A. Method access and property flags
#[derive(Debug, Clone, Copy)]
pub struct MethodFlags(u16);

/// https://docs.oracle.com/javase/specs/jvms/se25/html/jvms-4.html#jvms-4.7.24
#[derive(Debug, Clone, Copy)]
pub struct MethodParamFlags(u16);

/// https://docs.oracle.com/javase/specs/jvms/se25/html/jvms-4.html#jvms-4.5-200-A.1
/// Table 4.5-A. Field access and property flags
#[derive(Debug, Clone, Copy)]
pub struct FieldFlags(u16);

impl ClassFlags {
    pub fn new(value: u16) -> Self {
        Self(value)
    }

    pub fn is_public(&self) -> bool {
        self.0 & 0x0001 != 0
    }

    pub fn is_final(&self) -> bool {
        self.0 & 0x0010 != 0
    }

    pub fn is_super(&self) -> bool {
        self.0 & 0x0020 != 0
    }

    pub fn is_interface(&self) -> bool {
        self.0 & 0x0200 != 0
    }

    pub fn is_abstract(&self) -> bool {
        self.0 & 0x0400 != 0
    }

    pub fn is_synthetic(&self) -> bool {
        self.0 & 0x1000 != 0
    }

    pub fn is_annotation(&self) -> bool {
        self.0 & 0x2000 != 0
    }

    pub fn is_enum(&self) -> bool {
        self.0 & 0x4000 != 0
    }

    pub fn is_module(&self) -> bool {
        self.0 & 0x8000 != 0
    }

    pub fn get_raw(&self) -> &u16 {
        &self.0
    }

    pub fn get_raw_i32(&self) -> i32 {
        self.0 as i32
    }
}

impl InnerClassFlags {
    pub fn new(value: u16) -> Self {
        Self(value)
    }

    pub fn is_public(&self) -> bool {
        self.0 & 0x0001 != 0
    }

    pub fn is_private(&self) -> bool {
        self.0 & 0x0002 != 0
    }

    pub fn is_protected(&self) -> bool {
        self.0 & 0x0004 != 0
    }

    pub fn is_static(&self) -> bool {
        self.0 & 0x0008 != 0
    }

    pub fn is_final(&self) -> bool {
        self.0 & 0x0010 != 0
    }

    pub fn is_interface(&self) -> bool {
        self.0 & 0x0200 != 0
    }

    pub fn is_abstract(&self) -> bool {
        self.0 & 0x0400 != 0
    }

    pub fn is_synthetic(&self) -> bool {
        self.0 & 0x1000 != 0
    }

    pub fn is_annotation(&self) -> bool {
        self.0 & 0x2000 != 0
    }

    pub fn is_enum(&self) -> bool {
        self.0 & 0x4000 != 0
    }

    pub fn get_raw(&self) -> &u16 {
        &self.0
    }
}

impl MethodFlags {
    pub fn new(value: u16) -> Self {
        Self(value)
    }

    pub fn is_public(&self) -> bool {
        self.0 & 0x0001 != 0
    }

    pub fn is_private(&self) -> bool {
        self.0 & 0x0002 != 0
    }

    pub fn is_protected(&self) -> bool {
        self.0 & 0x0004 != 0
    }

    pub fn is_static(&self) -> bool {
        self.0 & 0x0008 != 0
    }

    pub fn is_final(&self) -> bool {
        self.0 & 0x0010 != 0
    }

    pub fn is_synchronized(&self) -> bool {
        self.0 & 0x0020 != 0
    }

    pub fn is_bridge(&self) -> bool {
        self.0 & 0x0040 != 0
    }

    pub fn is_varargs(&self) -> bool {
        self.0 & 0x0080 != 0
    }

    pub fn is_native(&self) -> bool {
        self.0 & 0x0100 != 0
    }

    pub fn is_abstract(&self) -> bool {
        self.0 & 0x0400 != 0
    }

    pub fn is_strict(&self) -> bool {
        self.0 & 0x0800 != 0
    }

    pub fn is_synthetic(&self) -> bool {
        self.0 & 0x1000 != 0
    }

    pub fn get_raw(&self) -> &u16 {
        &self.0
    }
}

impl MethodParamFlags {
    pub fn new(value: u16) -> Self {
        Self(value)
    }

    pub fn is_final(&self) -> bool {
        self.0 & 0x0010 != 0
    }

    pub fn is_synthetic(&self) -> bool {
        self.0 & 0x1000 != 0
    }

    pub fn is_mandated(&self) -> bool {
        self.0 & 0x8000 != 0
    }

    pub fn get_raw(&self) -> &u16 {
        &self.0
    }
}

impl FieldFlags {
    pub fn new(value: u16) -> Self {
        Self(value)
    }

    pub fn is_public(&self) -> bool {
        self.0 & 0x0001 != 0
    }

    pub fn is_private(&self) -> bool {
        self.0 & 0x0002 != 0
    }

    pub fn is_protected(&self) -> bool {
        self.0 & 0x0004 != 0
    }

    pub fn is_static(&self) -> bool {
        self.0 & 0x0008 != 0
    }

    pub fn is_final(&self) -> bool {
        self.0 & 0x0010 != 0
    }

    pub fn is_volatile(&self) -> bool {
        self.0 & 0x0040 != 0
    }

    pub fn is_transient(&self) -> bool {
        self.0 & 0x0080 != 0
    }

    pub fn is_synthetic(&self) -> bool {
        self.0 & 0x1000 != 0
    }

    pub fn is_enum(&self) -> bool {
        self.0 & 0x4000 != 0
    }

    pub fn get_raw(&self) -> &u16 {
        &self.0
    }
}