jvm/c/find_attribute.c

56 lines
1.5 KiB
C

#include "assert.h"
#include "class_file.h"
#include "bytes.h"
#include "debug.h"
#include "printf.h"
int find_code_name_index(struct class_file * class_file)
{
for (int i = 0; i < class_file->constant_pool_count - 1; i++) {
struct constant * constant = &class_file->constant_pool[i];
if (constant->tag == CONSTANT_Utf8) {
if (constant_equal(constant, "Code")) {
return i + 1;
}
}
}
return 0;
}
int find_constantvalue_name_index(struct class_file * class_file)
{
for (int i = 0; i < class_file->constant_pool_count - 1; i++) {
struct constant * constant = &class_file->constant_pool[i];
if (constant->tag == CONSTANT_Utf8) {
if (constant_equal(constant, "ConstantValue")) {
return i + 1;
}
}
}
return 0;
}
int find_linenumbertable_name_index(struct class_file * class_file)
{
for (int i = 0; i < class_file->constant_pool_count - 1; i++) {
struct constant * constant = &class_file->constant_pool[i];
if (constant->tag == CONSTANT_Utf8) {
if (constant_equal(constant, "LineNumberTable")) {
return i + 1;
}
}
}
return 0;
}
struct attribute_info * find_attribute(int name_index,
int attributes_count,
struct attribute_info * attributes)
{
for (int i = 0; i < attributes_count; i++) {
if (attributes[i].attribute_name_index == name_index)
return &attributes[i];
}
return nullptr;
}