neater code
This commit is contained in:
parent
d5e3237bb2
commit
e72ae7bebb
83
classfile.c
83
classfile.c
@ -81,71 +81,68 @@ void parse_attribute(ClassFile* cf, attribute_info* base, FILE* file) {
|
|||||||
read_u2(&(base->info.stack_map_table_attribute.number_of_entries), 1, file);
|
read_u2(&(base->info.stack_map_table_attribute.number_of_entries), 1, file);
|
||||||
base->info.stack_map_table_attribute.entries = malloc(sizeof(stack_map_frame) * base->info.stack_map_table_attribute.number_of_entries);
|
base->info.stack_map_table_attribute.entries = malloc(sizeof(stack_map_frame) * base->info.stack_map_table_attribute.number_of_entries);
|
||||||
for (u2 i = 0; i < base->info.stack_map_table_attribute.number_of_entries; i++) {
|
for (u2 i = 0; i < base->info.stack_map_table_attribute.number_of_entries; i++) {
|
||||||
fread(&(base->info.stack_map_table_attribute.entries[i].frame_type), 1, 1, file);
|
stack_map_frame* entry = &(base->info.stack_map_table_attribute.entries[i]);
|
||||||
u1 frame_type = base->info.stack_map_table_attribute.entries[i].frame_type;
|
fread(&(entry->frame_type), 1, 1, file);
|
||||||
|
u1 frame_type = entry->frame_type;
|
||||||
switch (stack_frame_type_enum(frame_type)) {
|
switch (stack_frame_type_enum(frame_type)) {
|
||||||
case SAME:
|
case SAME:
|
||||||
break;
|
break;
|
||||||
case SAME_LOCALS_1_STACK_ITEM_FRAME:
|
case SAME_LOCALS_1_STACK_ITEM_FRAME:
|
||||||
fread(&(base->info.stack_map_table_attribute.entries[i].same_locals_1_stack_item_frame.stack[0].tag), 1, 1, file);
|
fread(&(entry->same_locals_1_stack_item_frame.stack[0].tag), 1, 1, file);
|
||||||
if (base->info.stack_map_table_attribute.entries[i].same_locals_1_stack_item_frame.stack[0].tag == ITEM_Object) {
|
if (entry->same_locals_1_stack_item_frame.stack[0].tag == ITEM_Object) {
|
||||||
read_u2(&(base->info.stack_map_table_attribute.entries[i].same_locals_1_stack_item_frame.stack[0].Object_variable_info.cpool_index), 1, file);
|
read_u2(&(entry->same_locals_1_stack_item_frame.stack[0].Object_variable_info.cpool_index), 1, file);
|
||||||
} else if (base->info.stack_map_table_attribute.entries[i].same_locals_1_stack_item_frame.stack[0].tag == ITEM_Uninitialized) {
|
} else if (entry->same_locals_1_stack_item_frame.stack[0].tag == ITEM_Uninitialized) {
|
||||||
read_u2(&(base->info.stack_map_table_attribute.entries[i].same_locals_1_stack_item_frame.stack[0].Uninitialized_variable_info.offset), 1, file);
|
read_u2(&(entry->same_locals_1_stack_item_frame.stack[0].Uninitialized_variable_info.offset), 1, file);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case SAME_LOCALS_1_STACK_ITEM_FRAME_EXTENDED:
|
case SAME_LOCALS_1_STACK_ITEM_FRAME_EXTENDED:
|
||||||
read_u2(&(base->info.stack_map_table_attribute.entries[i].same_locals_1_stack_item_frame_extended.offset_delta), 1, file);
|
read_u2(&(entry->same_locals_1_stack_item_frame_extended.offset_delta), 1, file);
|
||||||
fread(&(base->info.stack_map_table_attribute.entries[i].same_locals_1_stack_item_frame_extended.stack[0].tag), 1, 1, file);
|
fread(&(entry->same_locals_1_stack_item_frame_extended.stack[0].tag), 1, 1, file);
|
||||||
if (base->info.stack_map_table_attribute.entries[i].same_locals_1_stack_item_frame_extended.stack[0].tag == ITEM_Object) {
|
if (entry->same_locals_1_stack_item_frame_extended.stack[0].tag == ITEM_Object) {
|
||||||
read_u2(&(base->info.stack_map_table_attribute.entries[i].same_locals_1_stack_item_frame_extended.stack[0].Object_variable_info.cpool_index), 1,
|
read_u2(&(entry->same_locals_1_stack_item_frame_extended.stack[0].Object_variable_info.cpool_index), 1, file);
|
||||||
file);
|
} else if (entry->same_locals_1_stack_item_frame_extended.stack[0].tag == ITEM_Uninitialized) {
|
||||||
} else if (base->info.stack_map_table_attribute.entries[i].same_locals_1_stack_item_frame_extended.stack[0].tag == ITEM_Uninitialized) {
|
read_u2(&(entry->same_locals_1_stack_item_frame_extended.stack[0].Uninitialized_variable_info.offset), 1, file);
|
||||||
read_u2(&(base->info.stack_map_table_attribute.entries[i].same_locals_1_stack_item_frame_extended.stack[0].Uninitialized_variable_info.offset), 1,
|
|
||||||
file);
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case CHOP:
|
case CHOP:
|
||||||
read_u2(&(base->info.stack_map_table_attribute.entries[i].chop_frame.offset_delta), 1, file);
|
read_u2(&(entry->chop_frame.offset_delta), 1, file);
|
||||||
break;
|
break;
|
||||||
case SAME_FRAME_EXTENDED:
|
case SAME_FRAME_EXTENDED:
|
||||||
read_u2(&(base->info.stack_map_table_attribute.entries[i].same_frame_extended.offset_delta), 1, file);
|
read_u2(&(entry->same_frame_extended.offset_delta), 1, file);
|
||||||
break;
|
break;
|
||||||
case APPEND:
|
case APPEND:
|
||||||
read_u2(&(base->info.stack_map_table_attribute.entries[i].append_frame.offset_delta), 1, file);
|
read_u2(&(entry->append_frame.offset_delta), 1, file);
|
||||||
u2 count = frame_type - 251;
|
u2 count = frame_type - 251;
|
||||||
base->info.stack_map_table_attribute.entries[i].append_frame.locals = malloc(sizeof(verification_type_info) * count);
|
entry->append_frame.locals = malloc(sizeof(verification_type_info) * count);
|
||||||
for (u2 j = 0; j < count; j++) {
|
for (u2 j = 0; j < count; j++) {
|
||||||
fread(&(base->info.stack_map_table_attribute.entries[i].append_frame.locals[j].tag), 1, 1, file);
|
fread(&(entry->append_frame.locals[j].tag), 1, 1, file);
|
||||||
if (base->info.stack_map_table_attribute.entries[i].append_frame.locals[j].tag == ITEM_Object) {
|
if (entry->append_frame.locals[j].tag == ITEM_Object) {
|
||||||
read_u2(&(base->info.stack_map_table_attribute.entries[i].append_frame.locals[j].Object_variable_info.cpool_index), 1, file);
|
read_u2(&(entry->append_frame.locals[j].Object_variable_info.cpool_index), 1, file);
|
||||||
} else if (base->info.stack_map_table_attribute.entries[i].append_frame.locals[j].tag == ITEM_Uninitialized) {
|
} else if (entry->append_frame.locals[j].tag == ITEM_Uninitialized) {
|
||||||
read_u2(&(base->info.stack_map_table_attribute.entries[i].append_frame.locals[j].Uninitialized_variable_info.offset), 1, file);
|
read_u2(&(entry->append_frame.locals[j].Uninitialized_variable_info.offset), 1, file);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case FULL_FRAME:
|
case FULL_FRAME:
|
||||||
read_u2(&(base->info.stack_map_table_attribute.entries[i].full_frame.offset_delta), 1, file);
|
read_u2(&(entry->full_frame.offset_delta), 1, file);
|
||||||
read_u2(&(base->info.stack_map_table_attribute.entries[i].full_frame.number_of_locals), 1, file);
|
read_u2(&(entry->full_frame.number_of_locals), 1, file);
|
||||||
base->info.stack_map_table_attribute.entries[i].full_frame.locals =
|
entry->full_frame.locals = malloc(sizeof(verification_type_info) * entry->full_frame.number_of_locals);
|
||||||
malloc(sizeof(verification_type_info) * base->info.stack_map_table_attribute.entries[i].full_frame.number_of_locals);
|
for (u2 j = 0; j < entry->full_frame.number_of_locals; j++) {
|
||||||
for (u2 j = 0; j < base->info.stack_map_table_attribute.entries[i].full_frame.number_of_locals; j++) {
|
fread(&(entry->full_frame.locals[j].tag), 1, 1, file);
|
||||||
fread(&(base->info.stack_map_table_attribute.entries[i].full_frame.locals[j].tag), 1, 1, file);
|
if (entry->full_frame.locals[j].tag == ITEM_Object) {
|
||||||
if (base->info.stack_map_table_attribute.entries[i].full_frame.locals[j].tag == ITEM_Object) {
|
read_u2(&(entry->full_frame.locals[j].Object_variable_info.cpool_index), 1, file);
|
||||||
read_u2(&(base->info.stack_map_table_attribute.entries[i].full_frame.locals[j].Object_variable_info.cpool_index), 1, file);
|
} else if (entry->full_frame.locals[j].tag == ITEM_Uninitialized) {
|
||||||
} else if (base->info.stack_map_table_attribute.entries[i].full_frame.locals[j].tag == ITEM_Uninitialized) {
|
read_u2(&(entry->full_frame.locals[j].Uninitialized_variable_info.offset), 1, file);
|
||||||
read_u2(&(base->info.stack_map_table_attribute.entries[i].full_frame.locals[j].Uninitialized_variable_info.offset), 1, file);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
read_u2(&(base->info.stack_map_table_attribute.entries[i].full_frame.number_of_stack_items), 1, file);
|
read_u2(&(entry->full_frame.number_of_stack_items), 1, file);
|
||||||
base->info.stack_map_table_attribute.entries[i].full_frame.stack =
|
entry->full_frame.stack = malloc(sizeof(verification_type_info) * entry->full_frame.number_of_stack_items);
|
||||||
malloc(sizeof(verification_type_info) * base->info.stack_map_table_attribute.entries[i].full_frame.number_of_stack_items);
|
for (u2 j = 0; j < entry->full_frame.number_of_stack_items; j++) {
|
||||||
for (u2 j = 0; j < base->info.stack_map_table_attribute.entries[i].full_frame.number_of_stack_items; j++) {
|
fread(&(entry->full_frame.stack[j].tag), 1, 1, file);
|
||||||
fread(&(base->info.stack_map_table_attribute.entries[i].full_frame.stack[j].tag), 1, 1, file);
|
if (entry->full_frame.stack[j].tag == ITEM_Object) {
|
||||||
if (base->info.stack_map_table_attribute.entries[i].full_frame.stack[j].tag == ITEM_Object) {
|
read_u2(&(entry->full_frame.stack[j].Object_variable_info.cpool_index), 1, file);
|
||||||
read_u2(&(base->info.stack_map_table_attribute.entries[i].full_frame.stack[j].Object_variable_info.cpool_index), 1, file);
|
} else if (entry->full_frame.stack[j].tag == ITEM_Uninitialized) {
|
||||||
} else if (base->info.stack_map_table_attribute.entries[i].full_frame.stack[j].tag == ITEM_Uninitialized) {
|
read_u2(&(entry->full_frame.stack[j].Uninitialized_variable_info.offset), 1, file);
|
||||||
read_u2(&(base->info.stack_map_table_attribute.entries[i].full_frame.stack[j].Uninitialized_variable_info.offset), 1, file);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
Loading…
Reference in New Issue
Block a user