From 0def8039e10d87c57221a3dffd1b8e8d501108dd Mon Sep 17 00:00:00 2001 From: BENEDEK Date: Sat, 13 Apr 2024 22:47:56 +0200 Subject: [PATCH] printing methods --- classfile.c | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/classfile.c b/classfile.c index 8d4b609..d107887 100644 --- a/classfile.c +++ b/classfile.c @@ -456,27 +456,28 @@ void ClassFile_info(const ClassFile* cf) { printf("\t%s %s%s%s%s %s", access, flags & ACC_STATIC ? "static " : "", flags & ACC_FINAL ? "final " : "", flags & ACC_VOLATLE ? "volatile " : "", descriptor, name); + // TODO: print field attributes for (u2 j = 0; j < cf->fields[i].attributes_count; j++) { - switch (cf->fields[i].attributes[j]._tag) { - case CONSTANT_VALUE: - break; - case BOOTSTRAP_METHODS: - break; - case NEST_HOST: - break; - case NEST_MEMBERS: - break; - case PERMITTED_SUBCLASSES: - break; - default: - break; - } } printf(";\n"); } // methods + for (u2 i = 0; i < cf->methods_count; i++) { + u2 flags = cf->methods[i].access_flags; + char* access = flags & ACC_PUBLIC ? "public" : flags & ACC_PRIVATE ? "private" : flags & ACC_PROTECTED ? "protected" : ""; + char* descriptor = (char*)cf->constant_pool[cf->methods[i].descriptor_index - 1].info.utf8_info.bytes; + char* name = (char*)cf->constant_pool[cf->methods[i].name_index - 1].info.utf8_info.bytes; + printf("\t%s %s%s%s%s %s", access, flags & ACC_STATIC ? "static " : "", flags & ACC_FINAL ? "final " : "", flags & ACC_VOLATLE ? "volatile " : "", + descriptor, name); + + // TODO: print field attributes + for (u2 j = 0; j < cf->methods[i].attributes_count; j++) { + } + + printf(";\n"); + } } char* ClassFile_resolve_NameAnyType(const ClassFile* cf, CONSTANT_NameAndType_info info) {