Skip to main content

oak_jasm/parser/
element_type.rs

1use oak_core::{ElementType, UniversalElementRole};
2#[cfg(feature = "serde")]
3use serde::{Deserialize, Serialize};
4
5#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
6#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
7#[repr(u16)]
8pub enum JasmElementType {
9    // --- Tokens (mirrored from JasmTokenType) ---
10    // These MUST be in the same order as JasmTokenType
11    RootToken, // renamed to avoid conflict if needed, but JasmTokenType has Root at 0
12    ClassKw,
13    VersionKw,
14    MethodKw,
15    FieldKw,
16    StringKw,
17    SourceFileKw,
18    StackKw,
19    LocalsKw,
20    EndKw,
21    CompiledKw,
22    FromKw,
23    InnerClassKw,
24    NestMembersKw,
25    BootstrapMethodKw,
26    Public,
27    Private,
28    Protected,
29    Static,
30    Super,
31    Final,
32    Abstract,
33    Synchronized,
34    Native,
35    Synthetic,
36    Deprecated,
37    Varargs,
38    ALoad0,
39    ALoad1,
40    ALoad2,
41    ALoad3,
42    ILoad0,
43    ILoad1,
44    ILoad2,
45    ILoad3,
46    Ldc,
47    LdcW,
48    Ldc2W,
49    InvokeSpecial,
50    InvokeVirtual,
51    InvokeStatic,
52    InvokeInterface,
53    InvokeDynamic,
54    GetStatic,
55    PutStatic,
56    GetField,
57    PutField,
58    Return,
59    IReturn,
60    AReturn,
61    LReturn,
62    FReturn,
63    DReturn,
64    Nop,
65    Dup,
66    Pop,
67    New,
68    StringLiteral,
69    Number,
70    IdentifierToken,
71    TypeDescriptor,
72    LeftBrace,
73    RightBrace,
74    LeftParen,
75    RightParen,
76    LeftBracket,
77    RightBracket,
78    Colon,
79    Semicolon,
80    Dot,
81    Comma,
82    Slash,
83    Whitespace,
84    Newline,
85    Comment,
86    Error,
87    Eof,
88
89    // --- Composite Elements ---
90    Root,
91    Class,
92    Method,
93    Field,
94    Annotation,
95    Instruction,
96}
97
98impl ElementType for JasmElementType {
99    type Role = UniversalElementRole;
100
101    fn role(&self) -> Self::Role {
102        use UniversalElementRole::*;
103        match self {
104            Self::Root => Root,
105            Self::Class => Definition,
106            Self::Method => Definition,
107            Self::Field => Definition,
108            _ => None,
109        }
110    }
111}
112
113impl From<crate::lexer::token_type::JasmTokenType> for JasmElementType {
114    fn from(token: crate::lexer::token_type::JasmTokenType) -> Self {
115        unsafe { std::mem::transmute(token) }
116    }
117}