MCPcopy Create free account
hub / github.com/IntegralPilot/rustc_codegen_jvm / create_default_constructor

Function create_default_constructor

src/lower2/jvm_gen.rs:70–107  ·  view source on GitHub ↗

Creates a default constructor ` ()V` that just calls `super()`.

(
    // pub(super) or pub(crate)
    cp: &mut InternedConstantPool,
    super_class_index: u16,
)

Source from the content-addressed store, hash-verified

68 max_locals: u16,
69 code: Vec<Instruction>,
70 descriptor: &str,
71 is_static: bool,
72 this_class_name: Option<&str>,
73 method_name: &str,
74) -> jvm::Result<Attribute> {
75 let initial_locals = stackmaps::initial_locals_for_descriptor(
76 descriptor,
77 is_static,
78 this_class_name,
79 method_name == "<init>",
80 )?;
81 code_attribute_with_stack_maps(cp, max_stack, max_locals, code, initial_locals, method_name)
82}
83
84/// Creates a default constructor `<init>()V` that just calls `super()`.
85pub(super) fn create_default_constructor(
86 // pub(super) or pub(crate)
87 cp: &mut InternedConstantPool,
88 super_class_index: u16,
89) -> jvm::Result<jvm::Method> {
90 let init_name_index = cp.add_utf8("<init>")?;
91 let init_desc_index = cp.add_utf8("()V")?;
92
93 // Add reference to super.<init>()V
94 let super_init_ref_index = cp.add_method_ref(super_class_index, "<init>", "()V")?;
95
96 let instructions = vec![
97 Instruction::Aload_0,
98 Instruction::Invokespecial(super_init_ref_index),
99 Instruction::Return,
100 ];
101
102 let max_stack = 1;
103 let max_locals = 1;
104
105 let code_attribute = code_attribute_for_descriptor(
106 cp,
107 max_stack,
108 max_locals,
109 instructions,
110 "()V",

Callers 2

oomir_to_jvm_bytecodeFunction · 0.85

Calls 3

add_utf8Method · 0.80
add_method_refMethod · 0.80

Tested by

no test coverage detected