oak_jasm/ast/
mod.rs

1#![doc = include_str!("readme.md")]
2
3use serde::{Deserialize, Serialize};
4use std::{string::String, vec::Vec};
5
6/// JASM 根节点
7#[derive(Clone, Debug, Serialize, Deserialize)]
8pub struct JasmRoot {
9    pub class: JasmClass,
10}
11
12/// JASM 类声明的 AST 节点
13#[derive(Clone, Debug, Serialize, Deserialize)]
14pub struct JasmClass {
15    /// 访问修饰符(public, private 等)
16    pub modifiers: Vec<String>,
17    /// 类名
18    pub name: String,
19    /// 版本信息(如 65:0)
20    pub version: Option<String>,
21    /// 方法列表
22    pub methods: Vec<JasmMethod>,
23    /// 字段列表
24    pub fields: Vec<JasmField>,
25    /// 源文件信息
26    pub source_file: Option<String>,
27}
28
29/// JASM 方法声明AST 节点
30#[derive(Clone, Debug, Serialize, Deserialize)]
31pub struct JasmMethod {
32    /// 访问修饰符(public, static 等)
33    pub modifiers: Vec<String>,
34    /// 方法名和类型描述符("main":"([Ljava/lang/String;)V")
35    pub name_and_descriptor: String,
36    /// 栈大小
37    pub stack_size: Option<u32>,
38    /// 局部变量数量
39    pub locals_count: Option<u32>,
40    /// 指令列表
41    pub instructions: Vec<JasmInstruction>,
42}
43
44/// JASM 字段声明AST 节点
45#[derive(Clone, Debug, Serialize, Deserialize)]
46pub struct JasmField {
47    /// 访问修饰符(public, static 等)
48    pub modifiers: Vec<String>,
49    /// 字段名和类型描述符("value":"I")
50    pub name_and_descriptor: String,
51}
52
53/// JASM 指令AST 节点
54#[derive(Clone, Debug, Serialize, Deserialize)]
55pub enum JasmInstruction {
56    /// 简单指令(aload_0, return)
57    Simple(String),
58    /// 带参数的指令(如 ldc "Hello")
59    WithArgument { instruction: String, argument: String },
60    /// 方法调用指令(如 invokespecial Method java/lang/Object."<init>":"()V")
61    MethodCall { instruction: String, method_ref: String },
62    /// 字段访问指令(如 getstatic Field java/lang/System.out:"Ljava/io/PrintStream;")
63    FieldAccess { instruction: String, field_ref: String },
64}