Class file data structure

This commit is contained in:
mrab 2024-05-04 11:39:44 +02:00
parent 88604bf544
commit 580e56ebbb
3 changed files with 71 additions and 1 deletions

6
.gitignore vendored
View File

@ -8,6 +8,12 @@ cabal-dev
*.chs.h
*.dyn_o
*.dyn_hi
*.java
*.class
*.local~*
src/Parser/JavaParser.hs
src/Parser/Parser.hs
src/Parser/Lexer.hs
.hpc
.hsenv
.cabal-sandbox/

2
questions.md Normal file
View File

@ -0,0 +1,2 @@
# Questions
- Enum?

62
src/ClassFile.hs Normal file
View File

@ -0,0 +1,62 @@
{-
ClassFile {
u4 magic;
u2 minor_version;
u2 major_version;
u2 constant_pool_count;
cp_info constant_pool[constant_pool_count-1];
u2 access_flags;
u2 this_class;
u2 super_class;
u2 interfaces_count;
u2 interfaces[interfaces_count];
u2 fields_count;
field_info fields[fields_count];
u2 methods_count;
method_info methods[methods_count];
u2 attributes_count;
attribute_info attributes[attributes_count];
}
method_info {
u2 access_flags;
u2 name_index;
u2 descriptor_index;
u2 attributes_count;
attribute_info attributes[attributes_count];
}
-}
import Data.Word
import Data.Int
data ConstantInfo = ClassInfo Word16
| FieldRefInfo Word16 Word16
| MethodRefInfo Word16 Word16
| IntegerInfo Int32
| Utf8Info [Char]
deriving Show
data Attribute = Attribute Word16 [Word8] deriving Show
data MemberInfo = MemberInfo {
memberAccessFlags :: Word16,
memberNameIndex :: Word16,
memberDescriptorIndex :: Word16,
memberAttributes :: [Attribute]
} deriving Show
data ClassFile = ClassFile {
magic :: Word32,
minorVersion :: Word16,
majorVersion :: Word16,
constantPool :: [ConstantInfo],
accessFlags :: Word16,
thisClass :: Word16,
superClass :: Word16,
interfaces :: [Word16],
fields :: [MemberInfo],
methods :: [MemberInfo],
attributes :: [Attribute]
} deriving Show