* removed unused code
* added more javadoc * more renaming
This commit is contained in:
parent
22a6930973
commit
008bd06680
101 changed files with 715 additions and 1481 deletions
|
|
@ -1,6 +1,8 @@
|
||||||
# bejava
|
# bejava compiler
|
||||||
Bejava (backend java compiler) is a code creation library, somewhat comparable to javassist or bytebuddy.
|
Bejava (backend java) compiler is a code creation library, somewhat comparable to javassist or bytebuddy.
|
||||||
* It let's you compile bejava-lang' to bytecode.
|
* It let's you compile bejava-lang' to bytecode. As an alternative a BeSource object can be created programmatically and then compiled.
|
||||||
|
* In this way it is a backend compiler.
|
||||||
|
* Handles creation of the constant pool
|
||||||
* It does not inspect or enhance existing bytecode, though it could be part of such functionality.
|
* It does not inspect or enhance existing bytecode, though it could be part of such functionality.
|
||||||
|
|
||||||
What is 'bejava lang'?
|
What is 'bejava lang'?
|
||||||
|
|
|
||||||
|
|
@ -1,699 +0,0 @@
|
||||||
Classfile /Users/Shautvast/IdeaProjects/beejava/target/classes/nl/sander/beejava/Compiler.class
|
|
||||||
Last modified 18 Nov 2020; size 6433 bytes
|
|
||||||
SHA-256 checksum e76616828289ace3b62f79015aeb244229c29989e2c613a0ec860f075e5e4319
|
|
||||||
Compiled from "Compiler.java"
|
|
||||||
public class nl.sander.beejava.Compiler
|
|
||||||
minor version: 0
|
|
||||||
major version: 58
|
|
||||||
flags: (0x0021) ACC_PUBLIC, ACC_SUPER
|
|
||||||
this_class: #11 // nl/sander/beejava/Compiler
|
|
||||||
super_class: #2 // java/lang/Object
|
|
||||||
interfaces: 0, fields: 4, methods: 9, attributes: 3
|
|
||||||
Constant pool:
|
|
||||||
#1 = Methodref #2.#3 // java/lang/Object."<init>":()V
|
|
||||||
#2 = Class #4 // java/lang/Object
|
|
||||||
#3 = NameAndType #5:#6 // "<init>":()V
|
|
||||||
#4 = Utf8 java/lang/Object
|
|
||||||
#5 = Utf8 <init>
|
|
||||||
#6 = Utf8 ()V
|
|
||||||
#7 = Class #8 // nl/sander/beejava/ConstantPoolCreator
|
|
||||||
#8 = Utf8 nl/sander/beejava/ConstantPoolCreator
|
|
||||||
#9 = Methodref #7.#3 // nl/sander/beejava/ConstantPoolCreator."<init>":()V
|
|
||||||
#10 = Fieldref #11.#12 // nl/sander/beejava/Compiler.constantPoolCreator:Lnl/sander/beejava/ConstantPoolCreator;
|
|
||||||
#11 = Class #13 // nl/sander/beejava/Compiler
|
|
||||||
#12 = NameAndType #14:#15 // constantPoolCreator:Lnl/sander/beejava/ConstantPoolCreator;
|
|
||||||
#13 = Utf8 nl/sander/beejava/Compiler
|
|
||||||
#14 = Utf8 constantPoolCreator
|
|
||||||
#15 = Utf8 Lnl/sander/beejava/ConstantPoolCreator;
|
|
||||||
#16 = Fieldref #11.#17 // nl/sander/beejava/Compiler.compiledClass:Lnl/sander/beejava/CompiledClass;
|
|
||||||
#17 = NameAndType #18:#19 // compiledClass:Lnl/sander/beejava/CompiledClass;
|
|
||||||
#18 = Utf8 compiledClass
|
|
||||||
#19 = Utf8 Lnl/sander/beejava/CompiledClass;
|
|
||||||
#20 = Class #21 // nl/sander/beejava/ConstantPoolEntryCreator
|
|
||||||
#21 = Utf8 nl/sander/beejava/ConstantPoolEntryCreator
|
|
||||||
#22 = Methodref #20.#23 // nl/sander/beejava/ConstantPoolEntryCreator."<init>":(Lnl/sander/beejava/CompiledClass;)V
|
|
||||||
#23 = NameAndType #5:#24 // "<init>":(Lnl/sander/beejava/CompiledClass;)V
|
|
||||||
#24 = Utf8 (Lnl/sander/beejava/CompiledClass;)V
|
|
||||||
#25 = Fieldref #11.#26 // nl/sander/beejava/Compiler.constantPoolEntryCreator:Lnl/sander/beejava/ConstantPoolEntryCreator;
|
|
||||||
#26 = NameAndType #27:#28 // constantPoolEntryCreator:Lnl/sander/beejava/ConstantPoolEntryCreator;
|
|
||||||
#27 = Utf8 constantPoolEntryCreator
|
|
||||||
#28 = Utf8 Lnl/sander/beejava/ConstantPoolEntryCreator;
|
|
||||||
#29 = Class #30 // nl/sander/beejava/CompiledClass
|
|
||||||
#30 = Utf8 nl/sander/beejava/CompiledClass
|
|
||||||
#31 = Methodref #29.#32 // nl/sander/beejava/CompiledClass."<init>":(Lnl/sander/beejava/api/BeeSource;)V
|
|
||||||
#32 = NameAndType #5:#33 // "<init>":(Lnl/sander/beejava/api/BeeSource;)V
|
|
||||||
#33 = Utf8 (Lnl/sander/beejava/api/BeeSource;)V
|
|
||||||
#34 = Methodref #11.#23 // nl/sander/beejava/Compiler."<init>":(Lnl/sander/beejava/CompiledClass;)V
|
|
||||||
#35 = Methodref #11.#36 // nl/sander/beejava/Compiler.compile:()Lnl/sander/beejava/CompiledClass;
|
|
||||||
#36 = NameAndType #37:#38 // compile:()Lnl/sander/beejava/CompiledClass;
|
|
||||||
#37 = Utf8 compile
|
|
||||||
#38 = Utf8 ()Lnl/sander/beejava/CompiledClass;
|
|
||||||
#39 = Methodref #11.#40 // nl/sander/beejava/Compiler.createConstantPool:()Lnl/sander/beejava/constantpool/ConstantPool;
|
|
||||||
#40 = NameAndType #41:#42 // createConstantPool:()Lnl/sander/beejava/constantpool/ConstantPool;
|
|
||||||
#41 = Utf8 createConstantPool
|
|
||||||
#42 = Utf8 ()Lnl/sander/beejava/constantpool/ConstantPool;
|
|
||||||
#43 = Methodref #29.#44 // nl/sander/beejava/CompiledClass.setConstantPool:(Lnl/sander/beejava/constantpool/ConstantPool;)V
|
|
||||||
#44 = NameAndType #45:#46 // setConstantPool:(Lnl/sander/beejava/constantpool/ConstantPool;)V
|
|
||||||
#45 = Utf8 setConstantPool
|
|
||||||
#46 = Utf8 (Lnl/sander/beejava/constantpool/ConstantPool;)V
|
|
||||||
#47 = Methodref #20.#48 // nl/sander/beejava/ConstantPoolEntryCreator.addInterfaces:()V
|
|
||||||
#48 = NameAndType #49:#6 // addInterfaces:()V
|
|
||||||
#49 = Utf8 addInterfaces
|
|
||||||
#50 = Methodref #20.#51 // nl/sander/beejava/ConstantPoolEntryCreator.addFields:()V
|
|
||||||
#51 = NameAndType #52:#6 // addFields:()V
|
|
||||||
#52 = Utf8 addFields
|
|
||||||
#53 = Methodref #11.#54 // nl/sander/beejava/Compiler.addConstructors:()V
|
|
||||||
#54 = NameAndType #55:#6 // addConstructors:()V
|
|
||||||
#55 = Utf8 addConstructors
|
|
||||||
#56 = Methodref #11.#57 // nl/sander/beejava/Compiler.addMethods:()V
|
|
||||||
#57 = NameAndType #58:#6 // addMethods:()V
|
|
||||||
#58 = Utf8 addMethods
|
|
||||||
#59 = Methodref #29.#60 // nl/sander/beejava/CompiledClass.getSource:()Lnl/sander/beejava/api/BeeSource;
|
|
||||||
#60 = NameAndType #61:#62 // getSource:()Lnl/sander/beejava/api/BeeSource;
|
|
||||||
#61 = Utf8 getSource
|
|
||||||
#62 = Utf8 ()Lnl/sander/beejava/api/BeeSource;
|
|
||||||
#63 = Methodref #64.#65 // nl/sander/beejava/api/BeeSource.getConstructors:()Ljava/util/Set;
|
|
||||||
#64 = Class #66 // nl/sander/beejava/api/BeeSource
|
|
||||||
#65 = NameAndType #67:#68 // getConstructors:()Ljava/util/Set;
|
|
||||||
#66 = Utf8 nl/sander/beejava/api/BeeSource
|
|
||||||
#67 = Utf8 getConstructors
|
|
||||||
#68 = Utf8 ()Ljava/util/Set;
|
|
||||||
#69 = InvokeDynamic #0:#70 // #0:accept:(Lnl/sander/beejava/Compiler;)Ljava/util/function/Consumer;
|
|
||||||
#70 = NameAndType #71:#72 // accept:(Lnl/sander/beejava/Compiler;)Ljava/util/function/Consumer;
|
|
||||||
#71 = Utf8 accept
|
|
||||||
#72 = Utf8 (Lnl/sander/beejava/Compiler;)Ljava/util/function/Consumer;
|
|
||||||
#73 = InterfaceMethodref #74.#75 // java/util/Set.forEach:(Ljava/util/function/Consumer;)V
|
|
||||||
#74 = Class #76 // java/util/Set
|
|
||||||
#75 = NameAndType #77:#78 // forEach:(Ljava/util/function/Consumer;)V
|
|
||||||
#76 = Utf8 java/util/Set
|
|
||||||
#77 = Utf8 forEach
|
|
||||||
#78 = Utf8 (Ljava/util/function/Consumer;)V
|
|
||||||
#79 = Methodref #64.#80 // nl/sander/beejava/api/BeeSource.getMethods:()Ljava/util/Set;
|
|
||||||
#80 = NameAndType #81:#68 // getMethods:()Ljava/util/Set;
|
|
||||||
#81 = Utf8 getMethods
|
|
||||||
#82 = InvokeDynamic #1:#70 // #1:accept:(Lnl/sander/beejava/Compiler;)Ljava/util/function/Consumer;
|
|
||||||
#83 = Methodref #20.#84 // nl/sander/beejava/ConstantPoolEntryCreator.addThisClass:()Lnl/sander/beejava/constantpool/entry/ClassEntry;
|
|
||||||
#84 = NameAndType #85:#86 // addThisClass:()Lnl/sander/beejava/constantpool/entry/ClassEntry;
|
|
||||||
#85 = Utf8 addThisClass
|
|
||||||
#86 = Utf8 ()Lnl/sander/beejava/constantpool/entry/ClassEntry;
|
|
||||||
#87 = Methodref #29.#88 // nl/sander/beejava/CompiledClass.setThisClass:(Lnl/sander/beejava/constantpool/entry/ClassEntry;)V
|
|
||||||
#88 = NameAndType #89:#90 // setThisClass:(Lnl/sander/beejava/constantpool/entry/ClassEntry;)V
|
|
||||||
#89 = Utf8 setThisClass
|
|
||||||
#90 = Utf8 (Lnl/sander/beejava/constantpool/entry/ClassEntry;)V
|
|
||||||
#91 = String #92 // Code
|
|
||||||
#92 = Utf8 Code
|
|
||||||
#93 = Methodref #20.#94 // nl/sander/beejava/ConstantPoolEntryCreator.getOrCreateUtf8:(Ljava/lang/String;)Lnl/sander/beejava/constantpool/entry/Utf8Entry;
|
|
||||||
#94 = NameAndType #95:#96 // getOrCreateUtf8:(Ljava/lang/String;)Lnl/sander/beejava/constantpool/entry/Utf8Entry;
|
|
||||||
#95 = Utf8 getOrCreateUtf8
|
|
||||||
#96 = Utf8 (Ljava/lang/String;)Lnl/sander/beejava/constantpool/entry/Utf8Entry;
|
|
||||||
#97 = Fieldref #11.#98 // nl/sander/beejava/Compiler.codeAttributeNameEntry:Lnl/sander/beejava/constantpool/entry/Utf8Entry;
|
|
||||||
#98 = NameAndType #99:#100 // codeAttributeNameEntry:Lnl/sander/beejava/constantpool/entry/Utf8Entry;
|
|
||||||
#99 = Utf8 codeAttributeNameEntry
|
|
||||||
#100 = Utf8 Lnl/sander/beejava/constantpool/entry/Utf8Entry;
|
|
||||||
#101 = Methodref #29.#102 // nl/sander/beejava/CompiledClass.addConstantPoolEntry:(Lnl/sander/beejava/constantpool/entry/ConstantPoolEntry;)V
|
|
||||||
#102 = NameAndType #103:#104 // addConstantPoolEntry:(Lnl/sander/beejava/constantpool/entry/ConstantPoolEntry;)V
|
|
||||||
#103 = Utf8 addConstantPoolEntry
|
|
||||||
#104 = Utf8 (Lnl/sander/beejava/constantpool/entry/ConstantPoolEntry;)V
|
|
||||||
#105 = Methodref #29.#106 // nl/sander/beejava/CompiledClass.getConstantTree:()Ljava/util/Set;
|
|
||||||
#106 = NameAndType #107:#68 // getConstantTree:()Ljava/util/Set;
|
|
||||||
#107 = Utf8 getConstantTree
|
|
||||||
#108 = Methodref #7.#109 // nl/sander/beejava/ConstantPoolCreator.createConstantPool:(Ljava/util/Set;)Lnl/sander/beejava/constantpool/ConstantPool;
|
|
||||||
#109 = NameAndType #41:#110 // createConstantPool:(Ljava/util/Set;)Lnl/sander/beejava/constantpool/ConstantPool;
|
|
||||||
#110 = Utf8 (Ljava/util/Set;)Lnl/sander/beejava/constantpool/ConstantPool;
|
|
||||||
#111 = InterfaceMethodref #74.#112 // java/util/Set.stream:()Ljava/util/stream/Stream;
|
|
||||||
#112 = NameAndType #113:#114 // stream:()Ljava/util/stream/Stream;
|
|
||||||
#113 = Utf8 stream
|
|
||||||
#114 = Utf8 ()Ljava/util/stream/Stream;
|
|
||||||
#115 = InvokeDynamic #2:#116 // #2:apply:(Lnl/sander/beejava/Compiler;)Ljava/util/function/Function;
|
|
||||||
#116 = NameAndType #117:#118 // apply:(Lnl/sander/beejava/Compiler;)Ljava/util/function/Function;
|
|
||||||
#117 = Utf8 apply
|
|
||||||
#118 = Utf8 (Lnl/sander/beejava/Compiler;)Ljava/util/function/Function;
|
|
||||||
#119 = InterfaceMethodref #120.#121 // java/util/stream/Stream.map:(Ljava/util/function/Function;)Ljava/util/stream/Stream;
|
|
||||||
#120 = Class #122 // java/util/stream/Stream
|
|
||||||
#121 = NameAndType #123:#124 // map:(Ljava/util/function/Function;)Ljava/util/stream/Stream;
|
|
||||||
#122 = Utf8 java/util/stream/Stream
|
|
||||||
#123 = Utf8 map
|
|
||||||
#124 = Utf8 (Ljava/util/function/Function;)Ljava/util/stream/Stream;
|
|
||||||
#125 = Methodref #126.#127 // java/util/Objects.requireNonNull:(Ljava/lang/Object;)Ljava/lang/Object;
|
|
||||||
#126 = Class #128 // java/util/Objects
|
|
||||||
#127 = NameAndType #129:#130 // requireNonNull:(Ljava/lang/Object;)Ljava/lang/Object;
|
|
||||||
#128 = Utf8 java/util/Objects
|
|
||||||
#129 = Utf8 requireNonNull
|
|
||||||
#130 = Utf8 (Ljava/lang/Object;)Ljava/lang/Object;
|
|
||||||
#131 = InvokeDynamic #3:#132 // #3:accept:(Lnl/sander/beejava/CompiledClass;)Ljava/util/function/Consumer;
|
|
||||||
#132 = NameAndType #71:#133 // accept:(Lnl/sander/beejava/CompiledClass;)Ljava/util/function/Consumer;
|
|
||||||
#133 = Utf8 (Lnl/sander/beejava/CompiledClass;)Ljava/util/function/Consumer;
|
|
||||||
#134 = InterfaceMethodref #120.#75 // java/util/stream/Stream.forEach:(Ljava/util/function/Consumer;)V
|
|
||||||
#135 = InvokeDynamic #4:#116 // #4:apply:(Lnl/sander/beejava/Compiler;)Ljava/util/function/Function;
|
|
||||||
#136 = Class #137 // nl/sander/beejava/classinfo/MethodInfo
|
|
||||||
#137 = Utf8 nl/sander/beejava/classinfo/MethodInfo
|
|
||||||
#138 = Methodref #139.#140 // nl/sander/beejava/CodeContainer.getName:()Ljava/lang/String;
|
|
||||||
#139 = Class #141 // nl/sander/beejava/CodeContainer
|
|
||||||
#140 = NameAndType #142:#143 // getName:()Ljava/lang/String;
|
|
||||||
#141 = Utf8 nl/sander/beejava/CodeContainer
|
|
||||||
#142 = Utf8 getName
|
|
||||||
#143 = Utf8 ()Ljava/lang/String;
|
|
||||||
#144 = Methodref #139.#145 // nl/sander/beejava/CodeContainer.getSignature:()Ljava/lang/String;
|
|
||||||
#145 = NameAndType #146:#143 // getSignature:()Ljava/lang/String;
|
|
||||||
#146 = Utf8 getSignature
|
|
||||||
#147 = Methodref #136.#148 // nl/sander/beejava/classinfo/MethodInfo."<init>":(Lnl/sander/beejava/constantpool/entry/Utf8Entry;Lnl/sander/beejava/constantpool/entry/Utf8Entry;)V
|
|
||||||
#148 = NameAndType #5:#149 // "<init>":(Lnl/sander/beejava/constantpool/entry/Utf8Entry;Lnl/sander/beejava/constantpool/entry/Utf8Entry;)V
|
|
||||||
#149 = Utf8 (Lnl/sander/beejava/constantpool/entry/Utf8Entry;Lnl/sander/beejava/constantpool/entry/Utf8Entry;)V
|
|
||||||
#150 = Methodref #139.#151 // nl/sander/beejava/CodeContainer.getAccessFlags:()Ljava/util/Set;
|
|
||||||
#151 = NameAndType #152:#68 // getAccessFlags:()Ljava/util/Set;
|
|
||||||
#152 = Utf8 getAccessFlags
|
|
||||||
#153 = Methodref #136.#154 // nl/sander/beejava/classinfo/MethodInfo.addAccessFlags:(Ljava/util/Set;)Lnl/sander/beejava/classinfo/MethodInfo;
|
|
||||||
#154 = NameAndType #155:#156 // addAccessFlags:(Ljava/util/Set;)Lnl/sander/beejava/classinfo/MethodInfo;
|
|
||||||
#155 = Utf8 addAccessFlags
|
|
||||||
#156 = Utf8 (Ljava/util/Set;)Lnl/sander/beejava/classinfo/MethodInfo;
|
|
||||||
#157 = Methodref #158.#159 // nl/sander/beejava/MethodCodeCreator.createCodeAttribute:(Lnl/sander/beejava/constantpool/entry/Utf8Entry;Lnl/sander/beejava/CodeContainer;)Lnl/sander/beejava/classinfo/attributes/CodeAttribute;
|
|
||||||
#158 = Class #160 // nl/sander/beejava/MethodCodeCreator
|
|
||||||
#159 = NameAndType #161:#162 // createCodeAttribute:(Lnl/sander/beejava/constantpool/entry/Utf8Entry;Lnl/sander/beejava/CodeContainer;)Lnl/sander/beejava/classinfo/attributes/CodeAttribute;
|
|
||||||
#160 = Utf8 nl/sander/beejava/MethodCodeCreator
|
|
||||||
#161 = Utf8 createCodeAttribute
|
|
||||||
#162 = Utf8 (Lnl/sander/beejava/constantpool/entry/Utf8Entry;Lnl/sander/beejava/CodeContainer;)Lnl/sander/beejava/classinfo/attributes/CodeAttribute;
|
|
||||||
#163 = Methodref #136.#164 // nl/sander/beejava/classinfo/MethodInfo.addAttribute:(Lnl/sander/beejava/classinfo/attributes/Attribute;)Lnl/sander/beejava/classinfo/Info;
|
|
||||||
#164 = NameAndType #165:#166 // addAttribute:(Lnl/sander/beejava/classinfo/attributes/Attribute;)Lnl/sander/beejava/classinfo/Info;
|
|
||||||
#165 = Utf8 addAttribute
|
|
||||||
#166 = Utf8 (Lnl/sander/beejava/classinfo/attributes/Attribute;)Lnl/sander/beejava/classinfo/Info;
|
|
||||||
#167 = Methodref #139.#168 // nl/sander/beejava/CodeContainer.getCode:()Ljava/util/List;
|
|
||||||
#168 = NameAndType #169:#170 // getCode:()Ljava/util/List;
|
|
||||||
#169 = Utf8 getCode
|
|
||||||
#170 = Utf8 ()Ljava/util/List;
|
|
||||||
#171 = InvokeDynamic #5:#70 // #5:accept:(Lnl/sander/beejava/Compiler;)Ljava/util/function/Consumer;
|
|
||||||
#172 = InterfaceMethodref #173.#75 // java/util/List.forEach:(Ljava/util/function/Consumer;)V
|
|
||||||
#173 = Class #174 // java/util/List
|
|
||||||
#174 = Utf8 java/util/List
|
|
||||||
#175 = Methodref #176.#177 // nl/sander/beejava/api/CodeLine.hasMethodCall:()Z
|
|
||||||
#176 = Class #178 // nl/sander/beejava/api/CodeLine
|
|
||||||
#177 = NameAndType #179:#180 // hasMethodCall:()Z
|
|
||||||
#178 = Utf8 nl/sander/beejava/api/CodeLine
|
|
||||||
#179 = Utf8 hasMethodCall
|
|
||||||
#180 = Utf8 ()Z
|
|
||||||
#181 = Methodref #20.#182 // nl/sander/beejava/ConstantPoolEntryCreator.getOrCreateMethodRefEntry:(Lnl/sander/beejava/api/CodeLine;)Lnl/sander/beejava/constantpool/entry/MethodRefEntry;
|
|
||||||
#182 = NameAndType #183:#184 // getOrCreateMethodRefEntry:(Lnl/sander/beejava/api/CodeLine;)Lnl/sander/beejava/constantpool/entry/MethodRefEntry;
|
|
||||||
#183 = Utf8 getOrCreateMethodRefEntry
|
|
||||||
#184 = Utf8 (Lnl/sander/beejava/api/CodeLine;)Lnl/sander/beejava/constantpool/entry/MethodRefEntry;
|
|
||||||
#185 = Methodref #176.#186 // nl/sander/beejava/api/CodeLine.setAssignedEntry:(Lnl/sander/beejava/constantpool/entry/ConstantPoolEntry;)V
|
|
||||||
#186 = NameAndType #187:#104 // setAssignedEntry:(Lnl/sander/beejava/constantpool/entry/ConstantPoolEntry;)V
|
|
||||||
#187 = Utf8 setAssignedEntry
|
|
||||||
#188 = Methodref #176.#189 // nl/sander/beejava/api/CodeLine.hasRefToOwnField:()Z
|
|
||||||
#189 = NameAndType #190:#180 // hasRefToOwnField:()Z
|
|
||||||
#190 = Utf8 hasRefToOwnField
|
|
||||||
#191 = Methodref #176.#192 // nl/sander/beejava/api/CodeLine.hasRefToExternalField:()Z
|
|
||||||
#192 = NameAndType #193:#180 // hasRefToExternalField:()Z
|
|
||||||
#193 = Utf8 hasRefToExternalField
|
|
||||||
#194 = Methodref #20.#195 // nl/sander/beejava/ConstantPoolEntryCreator.getOrCreateFieldRefEntry:(Lnl/sander/beejava/api/CodeLine;)Lnl/sander/beejava/constantpool/entry/FieldRefEntry;
|
|
||||||
#195 = NameAndType #196:#197 // getOrCreateFieldRefEntry:(Lnl/sander/beejava/api/CodeLine;)Lnl/sander/beejava/constantpool/entry/FieldRefEntry;
|
|
||||||
#196 = Utf8 getOrCreateFieldRefEntry
|
|
||||||
#197 = Utf8 (Lnl/sander/beejava/api/CodeLine;)Lnl/sander/beejava/constantpool/entry/FieldRefEntry;
|
|
||||||
#198 = Methodref #176.#199 // nl/sander/beejava/api/CodeLine.hasConstValue:()Z
|
|
||||||
#199 = NameAndType #200:#180 // hasConstValue:()Z
|
|
||||||
#200 = Utf8 hasConstValue
|
|
||||||
#201 = Methodref #20.#202 // nl/sander/beejava/ConstantPoolEntryCreator.getOrCreatePrimitiveEntry:(Lnl/sander/beejava/api/CodeLine;)Lnl/sander/beejava/constantpool/entry/ConstantPoolEntry;
|
|
||||||
#202 = NameAndType #203:#204 // getOrCreatePrimitiveEntry:(Lnl/sander/beejava/api/CodeLine;)Lnl/sander/beejava/constantpool/entry/ConstantPoolEntry;
|
|
||||||
#203 = Utf8 getOrCreatePrimitiveEntry
|
|
||||||
#204 = Utf8 (Lnl/sander/beejava/api/CodeLine;)Lnl/sander/beejava/constantpool/entry/ConstantPoolEntry;
|
|
||||||
#205 = Utf8 LineNumberTable
|
|
||||||
#206 = Utf8 LocalVariableTable
|
|
||||||
#207 = Utf8 this
|
|
||||||
#208 = Utf8 Lnl/sander/beejava/Compiler;
|
|
||||||
#209 = Utf8 (Lnl/sander/beejava/api/BeeSource;)Lnl/sander/beejava/CompiledClass;
|
|
||||||
#210 = Utf8 beeSource
|
|
||||||
#211 = Utf8 Lnl/sander/beejava/api/BeeSource;
|
|
||||||
#212 = Utf8 createMethod
|
|
||||||
#213 = Utf8 (Lnl/sander/beejava/CodeContainer;)Lnl/sander/beejava/classinfo/MethodInfo;
|
|
||||||
#214 = Utf8 method
|
|
||||||
#215 = Utf8 Lnl/sander/beejava/CodeContainer;
|
|
||||||
#216 = Utf8 updateConstantPool
|
|
||||||
#217 = Utf8 (Lnl/sander/beejava/CodeContainer;)V
|
|
||||||
#218 = Utf8 codeContainer
|
|
||||||
#219 = Utf8 (Lnl/sander/beejava/api/CodeLine;)V
|
|
||||||
#220 = Utf8 methodRefEntry
|
|
||||||
#221 = Utf8 Lnl/sander/beejava/constantpool/entry/MethodRefEntry;
|
|
||||||
#222 = Utf8 fieldRefEntry
|
|
||||||
#223 = Utf8 Lnl/sander/beejava/constantpool/entry/FieldRefEntry;
|
|
||||||
#224 = Utf8 primitiveEntry
|
|
||||||
#225 = Utf8 Lnl/sander/beejava/constantpool/entry/ConstantPoolEntry;
|
|
||||||
#226 = Utf8 codeline
|
|
||||||
#227 = Utf8 Lnl/sander/beejava/api/CodeLine;
|
|
||||||
#228 = Utf8 StackMapTable
|
|
||||||
#229 = Utf8 SourceFile
|
|
||||||
#230 = Utf8 Compiler.java
|
|
||||||
#231 = Utf8 BootstrapMethods
|
|
||||||
#232 = MethodHandle 6:#233 // REF_invokeStatic java/lang/invoke/LambdaMetafactory.metafactory:(Ljava/lang/invoke/MethodHandles$Lookup;Ljava/lang/String;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodHandle;Ljava/lang/invoke/MethodType;)Ljava/lang/invoke/CallSite;
|
|
||||||
#233 = Methodref #234.#235 // java/lang/invoke/LambdaMetafactory.metafactory:(Ljava/lang/invoke/MethodHandles$Lookup;Ljava/lang/String;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodHandle;Ljava/lang/invoke/MethodType;)Ljava/lang/invoke/CallSite;
|
|
||||||
#234 = Class #236 // java/lang/invoke/LambdaMetafactory
|
|
||||||
#235 = NameAndType #237:#238 // metafactory:(Ljava/lang/invoke/MethodHandles$Lookup;Ljava/lang/String;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodHandle;Ljava/lang/invoke/MethodType;)Ljava/lang/invoke/CallSite;
|
|
||||||
#236 = Utf8 java/lang/invoke/LambdaMetafactory
|
|
||||||
#237 = Utf8 metafactory
|
|
||||||
#238 = Utf8 (Ljava/lang/invoke/MethodHandles$Lookup;Ljava/lang/String;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodHandle;Ljava/lang/invoke/MethodType;)Ljava/lang/invoke/CallSite;
|
|
||||||
#239 = MethodType #240 // (Ljava/lang/Object;)V
|
|
||||||
#240 = Utf8 (Ljava/lang/Object;)V
|
|
||||||
#241 = MethodHandle 7:#242 // REF_invokeSpecial nl/sander/beejava/Compiler.updateConstantPool:(Lnl/sander/beejava/CodeContainer;)V
|
|
||||||
#242 = Methodref #11.#243 // nl/sander/beejava/Compiler.updateConstantPool:(Lnl/sander/beejava/CodeContainer;)V
|
|
||||||
#243 = NameAndType #216:#217 // updateConstantPool:(Lnl/sander/beejava/CodeContainer;)V
|
|
||||||
#244 = MethodType #245 // (Lnl/sander/beejava/api/BeeConstructor;)V
|
|
||||||
#245 = Utf8 (Lnl/sander/beejava/api/BeeConstructor;)V
|
|
||||||
#246 = MethodType #247 // (Lnl/sander/beejava/api/BeeMethod;)V
|
|
||||||
#247 = Utf8 (Lnl/sander/beejava/api/BeeMethod;)V
|
|
||||||
#248 = MethodType #130 // (Ljava/lang/Object;)Ljava/lang/Object;
|
|
||||||
#249 = MethodHandle 7:#250 // REF_invokeSpecial nl/sander/beejava/Compiler.createMethod:(Lnl/sander/beejava/CodeContainer;)Lnl/sander/beejava/classinfo/MethodInfo;
|
|
||||||
#250 = Methodref #11.#251 // nl/sander/beejava/Compiler.createMethod:(Lnl/sander/beejava/CodeContainer;)Lnl/sander/beejava/classinfo/MethodInfo;
|
|
||||||
#251 = NameAndType #212:#213 // createMethod:(Lnl/sander/beejava/CodeContainer;)Lnl/sander/beejava/classinfo/MethodInfo;
|
|
||||||
#252 = MethodType #253 // (Lnl/sander/beejava/api/BeeConstructor;)Lnl/sander/beejava/classinfo/MethodInfo;
|
|
||||||
#253 = Utf8 (Lnl/sander/beejava/api/BeeConstructor;)Lnl/sander/beejava/classinfo/MethodInfo;
|
|
||||||
#254 = MethodHandle 5:#255 // REF_invokeVirtual nl/sander/beejava/CompiledClass.addMethod:(Lnl/sander/beejava/classinfo/MethodInfo;)V
|
|
||||||
#255 = Methodref #29.#256 // nl/sander/beejava/CompiledClass.addMethod:(Lnl/sander/beejava/classinfo/MethodInfo;)V
|
|
||||||
#256 = NameAndType #257:#258 // addMethod:(Lnl/sander/beejava/classinfo/MethodInfo;)V
|
|
||||||
#257 = Utf8 addMethod
|
|
||||||
#258 = Utf8 (Lnl/sander/beejava/classinfo/MethodInfo;)V
|
|
||||||
#259 = MethodType #258 // (Lnl/sander/beejava/classinfo/MethodInfo;)V
|
|
||||||
#260 = MethodType #261 // (Lnl/sander/beejava/api/BeeMethod;)Lnl/sander/beejava/classinfo/MethodInfo;
|
|
||||||
#261 = Utf8 (Lnl/sander/beejava/api/BeeMethod;)Lnl/sander/beejava/classinfo/MethodInfo;
|
|
||||||
#262 = MethodHandle 7:#263 // REF_invokeSpecial nl/sander/beejava/Compiler.updateConstantPool:(Lnl/sander/beejava/api/CodeLine;)V
|
|
||||||
#263 = Methodref #11.#264 // nl/sander/beejava/Compiler.updateConstantPool:(Lnl/sander/beejava/api/CodeLine;)V
|
|
||||||
#264 = NameAndType #216:#219 // updateConstantPool:(Lnl/sander/beejava/api/CodeLine;)V
|
|
||||||
#265 = MethodType #219 // (Lnl/sander/beejava/api/CodeLine;)V
|
|
||||||
#266 = Utf8 InnerClasses
|
|
||||||
#267 = Class #268 // java/lang/invoke/MethodHandles$Lookup
|
|
||||||
#268 = Utf8 java/lang/invoke/MethodHandles$Lookup
|
|
||||||
#269 = Class #270 // java/lang/invoke/MethodHandles
|
|
||||||
#270 = Utf8 java/lang/invoke/MethodHandles
|
|
||||||
#271 = Utf8 Lookup
|
|
||||||
{
|
|
||||||
private final nl.sander.beejava.CompiledClass compiledClass;
|
|
||||||
descriptor: Lnl/sander/beejava/CompiledClass;
|
|
||||||
flags: (0x0012) ACC_PRIVATE, ACC_FINAL
|
|
||||||
|
|
||||||
private final nl.sander.beejava.ConstantPoolEntryCreator constantPoolEntryCreator;
|
|
||||||
descriptor: Lnl/sander/beejava/ConstantPoolEntryCreator;
|
|
||||||
flags: (0x0012) ACC_PRIVATE, ACC_FINAL
|
|
||||||
|
|
||||||
private final nl.sander.beejava.ConstantPoolCreator constantPoolCreator;
|
|
||||||
descriptor: Lnl/sander/beejava/ConstantPoolCreator;
|
|
||||||
flags: (0x0012) ACC_PRIVATE, ACC_FINAL
|
|
||||||
|
|
||||||
private nl.sander.beejava.constantpool.entry.Utf8Entry codeAttributeNameEntry;
|
|
||||||
descriptor: Lnl/sander/beejava/constantpool/entry/Utf8Entry;
|
|
||||||
flags: (0x0002) ACC_PRIVATE
|
|
||||||
|
|
||||||
public nl.sander.beejava.Compiler(nl.sander.beejava.CompiledClass);
|
|
||||||
descriptor: (Lnl/sander/beejava/CompiledClass;)V
|
|
||||||
flags: (0x0001) ACC_PUBLIC
|
|
||||||
Code:
|
|
||||||
stack=4, locals=2, args_size=2
|
|
||||||
0: aload_0
|
|
||||||
1: invokespecial #1 // Method java/lang/Object."<init>":()V
|
|
||||||
4: aload_0
|
|
||||||
5: new #7 // class nl/sander/beejava/ConstantPoolCreator
|
|
||||||
8: dup
|
|
||||||
9: invokespecial #9 // Method nl/sander/beejava/ConstantPoolCreator."<init>":()V
|
|
||||||
12: putfield #10 // Field constantPoolCreator:Lnl/sander/beejava/ConstantPoolCreator;
|
|
||||||
15: aload_0
|
|
||||||
16: aload_1
|
|
||||||
17: putfield #16 // Field compiledClass:Lnl/sander/beejava/CompiledClass;
|
|
||||||
20: aload_0
|
|
||||||
21: new #20 // class nl/sander/beejava/ConstantPoolEntryCreator
|
|
||||||
24: dup
|
|
||||||
25: aload_1
|
|
||||||
26: invokespecial #22 // Method nl/sander/beejava/ConstantPoolEntryCreator."<init>":(Lnl/sander/beejava/CompiledClass;)V
|
|
||||||
29: putfield #25 // Field constantPoolEntryCreator:Lnl/sander/beejava/ConstantPoolEntryCreator;
|
|
||||||
32: return
|
|
||||||
LineNumberTable:
|
|
||||||
line 33: 0
|
|
||||||
line 24: 4
|
|
||||||
line 34: 15
|
|
||||||
line 35: 20
|
|
||||||
line 36: 32
|
|
||||||
LocalVariableTable:
|
|
||||||
Start Length Slot Name Signature
|
|
||||||
0 33 0 this Lnl/sander/beejava/Compiler;
|
|
||||||
0 33 1 compiledClass Lnl/sander/beejava/CompiledClass;
|
|
||||||
|
|
||||||
public static nl.sander.beejava.CompiledClass compile(nl.sander.beejava.api.BeeSource);
|
|
||||||
descriptor: (Lnl/sander/beejava/api/BeeSource;)Lnl/sander/beejava/CompiledClass;
|
|
||||||
flags: (0x0009) ACC_PUBLIC, ACC_STATIC
|
|
||||||
Code:
|
|
||||||
stack=5, locals=1, args_size=1
|
|
||||||
0: new #11 // class nl/sander/beejava/Compiler
|
|
||||||
3: dup
|
|
||||||
4: new #29 // class nl/sander/beejava/CompiledClass
|
|
||||||
7: dup
|
|
||||||
8: aload_0
|
|
||||||
9: invokespecial #31 // Method nl/sander/beejava/CompiledClass."<init>":(Lnl/sander/beejava/api/BeeSource;)V
|
|
||||||
12: invokespecial #34 // Method "<init>":(Lnl/sander/beejava/CompiledClass;)V
|
|
||||||
15: invokevirtual #35 // Method compile:()Lnl/sander/beejava/CompiledClass;
|
|
||||||
18: areturn
|
|
||||||
LineNumberTable:
|
|
||||||
line 45: 0
|
|
||||||
LocalVariableTable:
|
|
||||||
Start Length Slot Name Signature
|
|
||||||
0 19 0 beeSource Lnl/sander/beejava/api/BeeSource;
|
|
||||||
|
|
||||||
public nl.sander.beejava.CompiledClass compile();
|
|
||||||
descriptor: ()Lnl/sander/beejava/CompiledClass;
|
|
||||||
flags: (0x0001) ACC_PUBLIC
|
|
||||||
Code:
|
|
||||||
stack=2, locals=1, args_size=1
|
|
||||||
0: aload_0
|
|
||||||
1: getfield #16 // Field compiledClass:Lnl/sander/beejava/CompiledClass;
|
|
||||||
4: aload_0
|
|
||||||
5: invokevirtual #39 // Method createConstantPool:()Lnl/sander/beejava/constantpool/ConstantPool;
|
|
||||||
8: invokevirtual #43 // Method nl/sander/beejava/CompiledClass.setConstantPool:(Lnl/sander/beejava/constantpool/ConstantPool;)V
|
|
||||||
11: aload_0
|
|
||||||
12: getfield #25 // Field constantPoolEntryCreator:Lnl/sander/beejava/ConstantPoolEntryCreator;
|
|
||||||
15: invokevirtual #47 // Method nl/sander/beejava/ConstantPoolEntryCreator.addInterfaces:()V
|
|
||||||
18: aload_0
|
|
||||||
19: getfield #25 // Field constantPoolEntryCreator:Lnl/sander/beejava/ConstantPoolEntryCreator;
|
|
||||||
22: invokevirtual #50 // Method nl/sander/beejava/ConstantPoolEntryCreator.addFields:()V
|
|
||||||
25: aload_0
|
|
||||||
26: invokevirtual #53 // Method addConstructors:()V
|
|
||||||
29: aload_0
|
|
||||||
30: invokevirtual #56 // Method addMethods:()V
|
|
||||||
33: aload_0
|
|
||||||
34: getfield #16 // Field compiledClass:Lnl/sander/beejava/CompiledClass;
|
|
||||||
37: areturn
|
|
||||||
LineNumberTable:
|
|
||||||
line 52: 0
|
|
||||||
line 54: 11
|
|
||||||
line 55: 18
|
|
||||||
line 56: 25
|
|
||||||
line 57: 29
|
|
||||||
line 59: 33
|
|
||||||
LocalVariableTable:
|
|
||||||
Start Length Slot Name Signature
|
|
||||||
0 38 0 this Lnl/sander/beejava/Compiler;
|
|
||||||
|
|
||||||
private nl.sander.beejava.constantpool.ConstantPool createConstantPool();
|
|
||||||
descriptor: ()Lnl/sander/beejava/constantpool/ConstantPool;
|
|
||||||
flags: (0x0002) ACC_PRIVATE
|
|
||||||
Code:
|
|
||||||
stack=3, locals=1, args_size=1
|
|
||||||
0: aload_0
|
|
||||||
1: getfield #16 // Field compiledClass:Lnl/sander/beejava/CompiledClass;
|
|
||||||
4: invokevirtual #59 // Method nl/sander/beejava/CompiledClass.getSource:()Lnl/sander/beejava/api/BeeSource;
|
|
||||||
7: invokevirtual #63 // Method nl/sander/beejava/api/BeeSource.getConstructors:()Ljava/util/Set;
|
|
||||||
10: aload_0
|
|
||||||
11: invokedynamic #69, 0 // InvokeDynamic #0:accept:(Lnl/sander/beejava/Compiler;)Ljava/util/function/Consumer;
|
|
||||||
16: invokeinterface #73, 2 // InterfaceMethod java/util/Set.forEach:(Ljava/util/function/Consumer;)V
|
|
||||||
21: aload_0
|
|
||||||
22: getfield #16 // Field compiledClass:Lnl/sander/beejava/CompiledClass;
|
|
||||||
25: invokevirtual #59 // Method nl/sander/beejava/CompiledClass.getSource:()Lnl/sander/beejava/api/BeeSource;
|
|
||||||
28: invokevirtual #79 // Method nl/sander/beejava/api/BeeSource.getMethods:()Ljava/util/Set;
|
|
||||||
31: aload_0
|
|
||||||
32: invokedynamic #82, 0 // InvokeDynamic #1:accept:(Lnl/sander/beejava/Compiler;)Ljava/util/function/Consumer;
|
|
||||||
37: invokeinterface #73, 2 // InterfaceMethod java/util/Set.forEach:(Ljava/util/function/Consumer;)V
|
|
||||||
42: aload_0
|
|
||||||
43: getfield #16 // Field compiledClass:Lnl/sander/beejava/CompiledClass;
|
|
||||||
46: aload_0
|
|
||||||
47: getfield #25 // Field constantPoolEntryCreator:Lnl/sander/beejava/ConstantPoolEntryCreator;
|
|
||||||
50: invokevirtual #83 // Method nl/sander/beejava/ConstantPoolEntryCreator.addThisClass:()Lnl/sander/beejava/constantpool/entry/ClassEntry;
|
|
||||||
53: invokevirtual #87 // Method nl/sander/beejava/CompiledClass.setThisClass:(Lnl/sander/beejava/constantpool/entry/ClassEntry;)V
|
|
||||||
56: aload_0
|
|
||||||
57: aload_0
|
|
||||||
58: getfield #25 // Field constantPoolEntryCreator:Lnl/sander/beejava/ConstantPoolEntryCreator;
|
|
||||||
61: ldc #91 // String Code
|
|
||||||
63: invokevirtual #93 // Method nl/sander/beejava/ConstantPoolEntryCreator.getOrCreateUtf8:(Ljava/lang/String;)Lnl/sander/beejava/constantpool/entry/Utf8Entry;
|
|
||||||
66: putfield #97 // Field codeAttributeNameEntry:Lnl/sander/beejava/constantpool/entry/Utf8Entry;
|
|
||||||
69: aload_0
|
|
||||||
70: getfield #16 // Field compiledClass:Lnl/sander/beejava/CompiledClass;
|
|
||||||
73: aload_0
|
|
||||||
74: getfield #97 // Field codeAttributeNameEntry:Lnl/sander/beejava/constantpool/entry/Utf8Entry;
|
|
||||||
77: invokevirtual #101 // Method nl/sander/beejava/CompiledClass.addConstantPoolEntry:(Lnl/sander/beejava/constantpool/entry/ConstantPoolEntry;)V
|
|
||||||
80: aload_0
|
|
||||||
81: getfield #10 // Field constantPoolCreator:Lnl/sander/beejava/ConstantPoolCreator;
|
|
||||||
84: aload_0
|
|
||||||
85: getfield #16 // Field compiledClass:Lnl/sander/beejava/CompiledClass;
|
|
||||||
88: invokevirtual #105 // Method nl/sander/beejava/CompiledClass.getConstantTree:()Ljava/util/Set;
|
|
||||||
91: invokevirtual #108 // Method nl/sander/beejava/ConstantPoolCreator.createConstantPool:(Ljava/util/Set;)Lnl/sander/beejava/constantpool/ConstantPool;
|
|
||||||
94: areturn
|
|
||||||
LineNumberTable:
|
|
||||||
line 63: 0
|
|
||||||
line 64: 21
|
|
||||||
line 66: 42
|
|
||||||
line 68: 56
|
|
||||||
line 69: 69
|
|
||||||
line 71: 80
|
|
||||||
LocalVariableTable:
|
|
||||||
Start Length Slot Name Signature
|
|
||||||
0 95 0 this Lnl/sander/beejava/Compiler;
|
|
||||||
|
|
||||||
public void addConstructors();
|
|
||||||
descriptor: ()V
|
|
||||||
flags: (0x0001) ACC_PUBLIC
|
|
||||||
Code:
|
|
||||||
stack=3, locals=1, args_size=1
|
|
||||||
0: aload_0
|
|
||||||
1: getfield #16 // Field compiledClass:Lnl/sander/beejava/CompiledClass;
|
|
||||||
4: invokevirtual #59 // Method nl/sander/beejava/CompiledClass.getSource:()Lnl/sander/beejava/api/BeeSource;
|
|
||||||
7: invokevirtual #63 // Method nl/sander/beejava/api/BeeSource.getConstructors:()Ljava/util/Set;
|
|
||||||
10: invokeinterface #111, 1 // InterfaceMethod java/util/Set.stream:()Ljava/util/stream/Stream;
|
|
||||||
15: aload_0
|
|
||||||
16: invokedynamic #115, 0 // InvokeDynamic #2:apply:(Lnl/sander/beejava/Compiler;)Ljava/util/function/Function;
|
|
||||||
21: invokeinterface #119, 2 // InterfaceMethod java/util/stream/Stream.map:(Ljava/util/function/Function;)Ljava/util/stream/Stream;
|
|
||||||
26: aload_0
|
|
||||||
27: getfield #16 // Field compiledClass:Lnl/sander/beejava/CompiledClass;
|
|
||||||
30: dup
|
|
||||||
31: invokestatic #125 // Method java/util/Objects.requireNonNull:(Ljava/lang/Object;)Ljava/lang/Object;
|
|
||||||
34: pop
|
|
||||||
35: invokedynamic #131, 0 // InvokeDynamic #3:accept:(Lnl/sander/beejava/CompiledClass;)Ljava/util/function/Consumer;
|
|
||||||
40: invokeinterface #134, 2 // InterfaceMethod java/util/stream/Stream.forEach:(Ljava/util/function/Consumer;)V
|
|
||||||
45: return
|
|
||||||
LineNumberTable:
|
|
||||||
line 75: 0
|
|
||||||
line 76: 21
|
|
||||||
line 77: 31
|
|
||||||
line 78: 45
|
|
||||||
LocalVariableTable:
|
|
||||||
Start Length Slot Name Signature
|
|
||||||
0 46 0 this Lnl/sander/beejava/Compiler;
|
|
||||||
|
|
||||||
public void addMethods();
|
|
||||||
descriptor: ()V
|
|
||||||
flags: (0x0001) ACC_PUBLIC
|
|
||||||
Code:
|
|
||||||
stack=3, locals=1, args_size=1
|
|
||||||
0: aload_0
|
|
||||||
1: getfield #16 // Field compiledClass:Lnl/sander/beejava/CompiledClass;
|
|
||||||
4: aload_0
|
|
||||||
5: getfield #97 // Field codeAttributeNameEntry:Lnl/sander/beejava/constantpool/entry/Utf8Entry;
|
|
||||||
8: invokevirtual #101 // Method nl/sander/beejava/CompiledClass.addConstantPoolEntry:(Lnl/sander/beejava/constantpool/entry/ConstantPoolEntry;)V
|
|
||||||
11: aload_0
|
|
||||||
12: getfield #16 // Field compiledClass:Lnl/sander/beejava/CompiledClass;
|
|
||||||
15: invokevirtual #59 // Method nl/sander/beejava/CompiledClass.getSource:()Lnl/sander/beejava/api/BeeSource;
|
|
||||||
18: invokevirtual #79 // Method nl/sander/beejava/api/BeeSource.getMethods:()Ljava/util/Set;
|
|
||||||
21: invokeinterface #111, 1 // InterfaceMethod java/util/Set.stream:()Ljava/util/stream/Stream;
|
|
||||||
26: aload_0
|
|
||||||
27: invokedynamic #135, 0 // InvokeDynamic #4:apply:(Lnl/sander/beejava/Compiler;)Ljava/util/function/Function;
|
|
||||||
32: invokeinterface #119, 2 // InterfaceMethod java/util/stream/Stream.map:(Ljava/util/function/Function;)Ljava/util/stream/Stream;
|
|
||||||
37: aload_0
|
|
||||||
38: getfield #16 // Field compiledClass:Lnl/sander/beejava/CompiledClass;
|
|
||||||
41: dup
|
|
||||||
42: invokestatic #125 // Method java/util/Objects.requireNonNull:(Ljava/lang/Object;)Ljava/lang/Object;
|
|
||||||
45: pop
|
|
||||||
46: invokedynamic #131, 0 // InvokeDynamic #3:accept:(Lnl/sander/beejava/CompiledClass;)Ljava/util/function/Consumer;
|
|
||||||
51: invokeinterface #134, 2 // InterfaceMethod java/util/stream/Stream.forEach:(Ljava/util/function/Consumer;)V
|
|
||||||
56: return
|
|
||||||
LineNumberTable:
|
|
||||||
line 85: 0
|
|
||||||
line 86: 11
|
|
||||||
line 87: 32
|
|
||||||
line 88: 42
|
|
||||||
line 89: 56
|
|
||||||
LocalVariableTable:
|
|
||||||
Start Length Slot Name Signature
|
|
||||||
0 57 0 this Lnl/sander/beejava/Compiler;
|
|
||||||
|
|
||||||
private nl.sander.beejava.classinfo.MethodInfo createMethod(nl.sander.beejava.api.CodeContainer);
|
|
||||||
descriptor: (Lnl/sander/beejava/CodeContainer;)Lnl/sander/beejava/classinfo/MethodInfo;
|
|
||||||
flags: (0x0002) ACC_PRIVATE
|
|
||||||
Code:
|
|
||||||
stack=5, locals=2, args_size=2
|
|
||||||
0: new #136 // class nl/sander/beejava/classinfo/MethodInfo
|
|
||||||
3: dup
|
|
||||||
4: aload_0
|
|
||||||
5: getfield #25 // Field constantPoolEntryCreator:Lnl/sander/beejava/ConstantPoolEntryCreator;
|
|
||||||
8: aload_1
|
|
||||||
9: invokevirtual #138 // Method nl/sander/beejava/CodeContainer.getName:()Ljava/lang/String;
|
|
||||||
12: invokevirtual #93 // Method nl/sander/beejava/ConstantPoolEntryCreator.getOrCreateUtf8:(Ljava/lang/String;)Lnl/sander/beejava/constantpool/entry/Utf8Entry;
|
|
||||||
15: aload_0
|
|
||||||
16: getfield #25 // Field constantPoolEntryCreator:Lnl/sander/beejava/ConstantPoolEntryCreator;
|
|
||||||
19: aload_1
|
|
||||||
20: invokevirtual #144 // Method nl/sander/beejava/CodeContainer.getSignature:()Ljava/lang/String;
|
|
||||||
23: invokevirtual #93 // Method nl/sander/beejava/ConstantPoolEntryCreator.getOrCreateUtf8:(Ljava/lang/String;)Lnl/sander/beejava/constantpool/entry/Utf8Entry;
|
|
||||||
26: invokespecial #147 // Method nl/sander/beejava/classinfo/MethodInfo."<init>":(Lnl/sander/beejava/constantpool/entry/Utf8Entry;Lnl/sander/beejava/constantpool/entry/Utf8Entry;)V
|
|
||||||
29: aload_1
|
|
||||||
30: invokevirtual #150 // Method nl/sander/beejava/CodeContainer.getAccessFlags:()Ljava/util/Set;
|
|
||||||
33: invokevirtual #153 // Method nl/sander/beejava/classinfo/MethodInfo.addAccessFlags:(Ljava/util/Set;)Lnl/sander/beejava/classinfo/MethodInfo;
|
|
||||||
36: aload_0
|
|
||||||
37: getfield #97 // Field codeAttributeNameEntry:Lnl/sander/beejava/constantpool/entry/Utf8Entry;
|
|
||||||
40: aload_1
|
|
||||||
41: invokestatic #157 // Method nl/sander/beejava/MethodCodeCreator.createCodeAttribute:(Lnl/sander/beejava/constantpool/entry/Utf8Entry;Lnl/sander/beejava/CodeContainer;)Lnl/sander/beejava/classinfo/attributes/CodeAttribute;
|
|
||||||
44: invokevirtual #163 // Method nl/sander/beejava/classinfo/MethodInfo.addAttribute:(Lnl/sander/beejava/classinfo/attributes/Attribute;)Lnl/sander/beejava/classinfo/Info;
|
|
||||||
47: checkcast #136 // class nl/sander/beejava/classinfo/MethodInfo
|
|
||||||
50: areturn
|
|
||||||
LineNumberTable:
|
|
||||||
line 96: 0
|
|
||||||
line 97: 9
|
|
||||||
line 98: 20
|
|
||||||
line 99: 30
|
|
||||||
line 100: 41
|
|
||||||
line 96: 50
|
|
||||||
LocalVariableTable:
|
|
||||||
Start Length Slot Name Signature
|
|
||||||
0 51 0 this Lnl/sander/beejava/Compiler;
|
|
||||||
0 51 1 method Lnl/sander/beejava/CodeContainer;
|
|
||||||
|
|
||||||
private void updateConstantPool(nl.sander.beejava.api.CodeContainer);
|
|
||||||
descriptor: (Lnl/sander/beejava/CodeContainer;)V
|
|
||||||
flags: (0x0002) ACC_PRIVATE
|
|
||||||
Code:
|
|
||||||
stack=3, locals=2, args_size=2
|
|
||||||
0: aload_0
|
|
||||||
1: getfield #16 // Field compiledClass:Lnl/sander/beejava/CompiledClass;
|
|
||||||
4: aload_0
|
|
||||||
5: getfield #25 // Field constantPoolEntryCreator:Lnl/sander/beejava/ConstantPoolEntryCreator;
|
|
||||||
8: aload_1
|
|
||||||
9: invokevirtual #138 // Method nl/sander/beejava/CodeContainer.getName:()Ljava/lang/String;
|
|
||||||
12: invokevirtual #93 // Method nl/sander/beejava/ConstantPoolEntryCreator.getOrCreateUtf8:(Ljava/lang/String;)Lnl/sander/beejava/constantpool/entry/Utf8Entry;
|
|
||||||
15: invokevirtual #101 // Method nl/sander/beejava/CompiledClass.addConstantPoolEntry:(Lnl/sander/beejava/constantpool/entry/ConstantPoolEntry;)V
|
|
||||||
18: aload_0
|
|
||||||
19: getfield #16 // Field compiledClass:Lnl/sander/beejava/CompiledClass;
|
|
||||||
22: aload_0
|
|
||||||
23: getfield #25 // Field constantPoolEntryCreator:Lnl/sander/beejava/ConstantPoolEntryCreator;
|
|
||||||
26: aload_1
|
|
||||||
27: invokevirtual #144 // Method nl/sander/beejava/CodeContainer.getSignature:()Ljava/lang/String;
|
|
||||||
30: invokevirtual #93 // Method nl/sander/beejava/ConstantPoolEntryCreator.getOrCreateUtf8:(Ljava/lang/String;)Lnl/sander/beejava/constantpool/entry/Utf8Entry;
|
|
||||||
33: invokevirtual #101 // Method nl/sander/beejava/CompiledClass.addConstantPoolEntry:(Lnl/sander/beejava/constantpool/entry/ConstantPoolEntry;)V
|
|
||||||
36: aload_1
|
|
||||||
37: invokevirtual #167 // Method nl/sander/beejava/CodeContainer.getCode:()Ljava/util/List;
|
|
||||||
40: aload_0
|
|
||||||
41: invokedynamic #171, 0 // InvokeDynamic #5:accept:(Lnl/sander/beejava/Compiler;)Ljava/util/function/Consumer;
|
|
||||||
46: invokeinterface #172, 2 // InterfaceMethod java/util/List.forEach:(Ljava/util/function/Consumer;)V
|
|
||||||
51: return
|
|
||||||
LineNumberTable:
|
|
||||||
line 107: 0
|
|
||||||
line 108: 18
|
|
||||||
line 109: 36
|
|
||||||
line 110: 51
|
|
||||||
LocalVariableTable:
|
|
||||||
Start Length Slot Name Signature
|
|
||||||
0 52 0 this Lnl/sander/beejava/Compiler;
|
|
||||||
0 52 1 codeContainer Lnl/sander/beejava/CodeContainer;
|
|
||||||
|
|
||||||
private void updateConstantPool(nl.sander.beejava.api.CodeLine);
|
|
||||||
descriptor: (Lnl/sander/beejava/api/CodeLine;)V
|
|
||||||
flags: (0x0002) ACC_PRIVATE
|
|
||||||
Code:
|
|
||||||
stack=2, locals=3, args_size=2
|
|
||||||
0: aload_1
|
|
||||||
1: invokevirtual #175 // Method nl/sander/beejava/api/CodeLine.hasMethodCall:()Z
|
|
||||||
4: ifeq 29
|
|
||||||
7: aload_0
|
|
||||||
8: getfield #25 // Field constantPoolEntryCreator:Lnl/sander/beejava/ConstantPoolEntryCreator;
|
|
||||||
11: aload_1
|
|
||||||
12: invokevirtual #181 // Method nl/sander/beejava/ConstantPoolEntryCreator.getOrCreateMethodRefEntry:(Lnl/sander/beejava/api/CodeLine;)Lnl/sander/beejava/constantpool/entry/MethodRefEntry;
|
|
||||||
15: astore_2
|
|
||||||
16: aload_1
|
|
||||||
17: aload_2
|
|
||||||
18: invokevirtual #185 // Method nl/sander/beejava/api/CodeLine.setAssignedEntry:(Lnl/sander/beejava/constantpool/entry/ConstantPoolEntry;)V
|
|
||||||
21: aload_0
|
|
||||||
22: getfield #16 // Field compiledClass:Lnl/sander/beejava/CompiledClass;
|
|
||||||
25: aload_2
|
|
||||||
26: invokevirtual #101 // Method nl/sander/beejava/CompiledClass.addConstantPoolEntry:(Lnl/sander/beejava/constantpool/entry/ConstantPoolEntry;)V
|
|
||||||
29: aload_1
|
|
||||||
30: invokevirtual #188 // Method nl/sander/beejava/api/CodeLine.hasRefToOwnField:()Z
|
|
||||||
33: ifne 43
|
|
||||||
36: aload_1
|
|
||||||
37: invokevirtual #191 // Method nl/sander/beejava/api/CodeLine.hasRefToExternalField:()Z
|
|
||||||
40: ifeq 65
|
|
||||||
43: aload_0
|
|
||||||
44: getfield #25 // Field constantPoolEntryCreator:Lnl/sander/beejava/ConstantPoolEntryCreator;
|
|
||||||
47: aload_1
|
|
||||||
48: invokevirtual #194 // Method nl/sander/beejava/ConstantPoolEntryCreator.getOrCreateFieldRefEntry:(Lnl/sander/beejava/api/CodeLine;)Lnl/sander/beejava/constantpool/entry/FieldRefEntry;
|
|
||||||
51: astore_2
|
|
||||||
52: aload_1
|
|
||||||
53: aload_2
|
|
||||||
54: invokevirtual #185 // Method nl/sander/beejava/api/CodeLine.setAssignedEntry:(Lnl/sander/beejava/constantpool/entry/ConstantPoolEntry;)V
|
|
||||||
57: aload_0
|
|
||||||
58: getfield #16 // Field compiledClass:Lnl/sander/beejava/CompiledClass;
|
|
||||||
61: aload_2
|
|
||||||
62: invokevirtual #101 // Method nl/sander/beejava/CompiledClass.addConstantPoolEntry:(Lnl/sander/beejava/constantpool/entry/ConstantPoolEntry;)V
|
|
||||||
65: aload_1
|
|
||||||
66: invokevirtual #198 // Method nl/sander/beejava/api/CodeLine.hasConstValue:()Z
|
|
||||||
69: ifeq 94
|
|
||||||
72: aload_0
|
|
||||||
73: getfield #25 // Field constantPoolEntryCreator:Lnl/sander/beejava/ConstantPoolEntryCreator;
|
|
||||||
76: aload_1
|
|
||||||
77: invokevirtual #201 // Method nl/sander/beejava/ConstantPoolEntryCreator.getOrCreatePrimitiveEntry:(Lnl/sander/beejava/api/CodeLine;)Lnl/sander/beejava/constantpool/entry/ConstantPoolEntry;
|
|
||||||
80: astore_2
|
|
||||||
81: aload_1
|
|
||||||
82: aload_2
|
|
||||||
83: invokevirtual #185 // Method nl/sander/beejava/api/CodeLine.setAssignedEntry:(Lnl/sander/beejava/constantpool/entry/ConstantPoolEntry;)V
|
|
||||||
86: aload_0
|
|
||||||
87: getfield #16 // Field compiledClass:Lnl/sander/beejava/CompiledClass;
|
|
||||||
90: aload_2
|
|
||||||
91: invokevirtual #101 // Method nl/sander/beejava/CompiledClass.addConstantPoolEntry:(Lnl/sander/beejava/constantpool/entry/ConstantPoolEntry;)V
|
|
||||||
94: return
|
|
||||||
LineNumberTable:
|
|
||||||
line 122: 0
|
|
||||||
line 123: 7
|
|
||||||
line 124: 16
|
|
||||||
line 125: 21
|
|
||||||
line 128: 29
|
|
||||||
line 129: 43
|
|
||||||
line 130: 52
|
|
||||||
line 131: 57
|
|
||||||
line 134: 65
|
|
||||||
line 135: 72
|
|
||||||
line 136: 81
|
|
||||||
line 137: 86
|
|
||||||
line 139: 94
|
|
||||||
LocalVariableTable:
|
|
||||||
Start Length Slot Name Signature
|
|
||||||
16 13 2 methodRefEntry Lnl/sander/beejava/constantpool/entry/MethodRefEntry;
|
|
||||||
52 13 2 fieldRefEntry Lnl/sander/beejava/constantpool/entry/FieldRefEntry;
|
|
||||||
81 13 2 primitiveEntry Lnl/sander/beejava/constantpool/entry/ConstantPoolEntry;
|
|
||||||
0 95 0 this Lnl/sander/beejava/Compiler;
|
|
||||||
0 95 1 codeline Lnl/sander/beejava/api/CodeLine;
|
|
||||||
StackMapTable: number_of_entries = 4
|
|
||||||
frame_type = 29 /* same */
|
|
||||||
frame_type = 13 /* same */
|
|
||||||
frame_type = 21 /* same */
|
|
||||||
frame_type = 28 /* same */
|
|
||||||
}
|
|
||||||
SourceFile: "Compiler.java"
|
|
||||||
BootstrapMethods:
|
|
||||||
0: #232 REF_invokeStatic java/lang/invoke/LambdaMetafactory.metafactory:(Ljava/lang/invoke/MethodHandles$Lookup;Ljava/lang/String;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodHandle;Ljava/lang/invoke/MethodType;)Ljava/lang/invoke/CallSite;
|
|
||||||
Method arguments:
|
|
||||||
#239 (Ljava/lang/Object;)V
|
|
||||||
#241 REF_invokeSpecial nl/sander/beejava/Compiler.updateConstantPool:(Lnl/sander/beejava/CodeContainer;)V
|
|
||||||
#244 (Lnl/sander/beejava/api/BeeConstructor;)V
|
|
||||||
1: #232 REF_invokeStatic java/lang/invoke/LambdaMetafactory.metafactory:(Ljava/lang/invoke/MethodHandles$Lookup;Ljava/lang/String;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodHandle;Ljava/lang/invoke/MethodType;)Ljava/lang/invoke/CallSite;
|
|
||||||
Method arguments:
|
|
||||||
#239 (Ljava/lang/Object;)V
|
|
||||||
#241 REF_invokeSpecial nl/sander/beejava/Compiler.updateConstantPool:(Lnl/sander/beejava/CodeContainer;)V
|
|
||||||
#246 (Lnl/sander/beejava/api/BeeMethod;)V
|
|
||||||
2: #232 REF_invokeStatic java/lang/invoke/LambdaMetafactory.metafactory:(Ljava/lang/invoke/MethodHandles$Lookup;Ljava/lang/String;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodHandle;Ljava/lang/invoke/MethodType;)Ljava/lang/invoke/CallSite;
|
|
||||||
Method arguments:
|
|
||||||
#248 (Ljava/lang/Object;)Ljava/lang/Object;
|
|
||||||
#249 REF_invokeSpecial nl/sander/beejava/Compiler.createMethod:(Lnl/sander/beejava/CodeContainer;)Lnl/sander/beejava/classinfo/MethodInfo;
|
|
||||||
#252 (Lnl/sander/beejava/api/BeeConstructor;)Lnl/sander/beejava/classinfo/MethodInfo;
|
|
||||||
3: #232 REF_invokeStatic java/lang/invoke/LambdaMetafactory.metafactory:(Ljava/lang/invoke/MethodHandles$Lookup;Ljava/lang/String;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodHandle;Ljava/lang/invoke/MethodType;)Ljava/lang/invoke/CallSite;
|
|
||||||
Method arguments:
|
|
||||||
#239 (Ljava/lang/Object;)V
|
|
||||||
#254 REF_invokeVirtual nl/sander/beejava/CompiledClass.addMethod:(Lnl/sander/beejava/classinfo/MethodInfo;)V
|
|
||||||
#259 (Lnl/sander/beejava/classinfo/MethodInfo;)V
|
|
||||||
4: #232 REF_invokeStatic java/lang/invoke/LambdaMetafactory.metafactory:(Ljava/lang/invoke/MethodHandles$Lookup;Ljava/lang/String;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodHandle;Ljava/lang/invoke/MethodType;)Ljava/lang/invoke/CallSite;
|
|
||||||
Method arguments:
|
|
||||||
#248 (Ljava/lang/Object;)Ljava/lang/Object;
|
|
||||||
#249 REF_invokeSpecial nl/sander/beejava/Compiler.createMethod:(Lnl/sander/beejava/CodeContainer;)Lnl/sander/beejava/classinfo/MethodInfo;
|
|
||||||
#260 (Lnl/sander/beejava/api/BeeMethod;)Lnl/sander/beejava/classinfo/MethodInfo;
|
|
||||||
5: #232 REF_invokeStatic java/lang/invoke/LambdaMetafactory.metafactory:(Ljava/lang/invoke/MethodHandles$Lookup;Ljava/lang/String;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodHandle;Ljava/lang/invoke/MethodType;)Ljava/lang/invoke/CallSite;
|
|
||||||
Method arguments:
|
|
||||||
#239 (Ljava/lang/Object;)V
|
|
||||||
#262 REF_invokeSpecial nl/sander/beejava/Compiler.updateConstantPool:(Lnl/sander/beejava/api/CodeLine;)V
|
|
||||||
#265 (Lnl/sander/beejava/api/CodeLine;)V
|
|
||||||
InnerClasses:
|
|
||||||
public static final #271= #267 of #269; // Lookup=class java/lang/invoke/MethodHandles$Lookup of class java/lang/invoke/MethodHandles
|
|
||||||
4
out
4
out
|
|
@ -241,7 +241,7 @@ Constant pool:
|
||||||
#229 = Utf8 this
|
#229 = Utf8 this
|
||||||
#230 = Utf8 Lnl/sander/beejava/Compiler;
|
#230 = Utf8 Lnl/sander/beejava/Compiler;
|
||||||
#231 = Utf8 (Lnl/sander/beejava/api/BeeSource;)Lnl/sander/beejava/CompiledClass;
|
#231 = Utf8 (Lnl/sander/beejava/api/BeeSource;)Lnl/sander/beejava/CompiledClass;
|
||||||
#232 = Utf8 beeSource
|
#232 = Utf8 beSource
|
||||||
#233 = Utf8 Lnl/sander/beejava/api/BeeSource;
|
#233 = Utf8 Lnl/sander/beejava/api/BeeSource;
|
||||||
#234 = Utf8 method
|
#234 = Utf8 method
|
||||||
#235 = Utf8 Lnl/sander/beejava/api/BeeMethod;
|
#235 = Utf8 Lnl/sander/beejava/api/BeeMethod;
|
||||||
|
|
@ -362,7 +362,7 @@ Constant pool:
|
||||||
line 46: 0
|
line 46: 0
|
||||||
LocalVariableTable:
|
LocalVariableTable:
|
||||||
Start Length Slot Name Signature
|
Start Length Slot Name Signature
|
||||||
0 19 0 beeSource Lnl/sander/beejava/api/BeeSource;
|
0 19 0 beSource Lnl/sander/beejava/api/BeeSource;
|
||||||
|
|
||||||
public nl.sander.beejava.CompiledClass compile();
|
public nl.sander.beejava.CompiledClass compile();
|
||||||
descriptor: ()Lnl/sander/beejava/CompiledClass;
|
descriptor: ()Lnl/sander/beejava/CompiledClass;
|
||||||
|
|
|
||||||
|
|
@ -1,17 +0,0 @@
|
||||||
package nl.sander.beejava;
|
|
||||||
|
|
||||||
import nl.sander.beejava.api.BeeSource;
|
|
||||||
|
|
||||||
public final class OverallCompiler {
|
|
||||||
|
|
||||||
private OverallCompiler(){
|
|
||||||
//
|
|
||||||
}
|
|
||||||
|
|
||||||
public static byte[] compile(String sourcecode){
|
|
||||||
BeeSource beeSource = SourceCompiler.compile(sourcecode);
|
|
||||||
OpcodeTranslator.translate(beeSource);
|
|
||||||
CompiledClass compiledClass = Compiler.compile(beeSource);
|
|
||||||
return BytecodeGenerator.generate(compiledClass);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,5 +0,0 @@
|
||||||
package nl.sander.beejava;
|
|
||||||
|
|
||||||
public enum StackOp {
|
|
||||||
PUSH,POP
|
|
||||||
}
|
|
||||||
|
|
@ -1,62 +0,0 @@
|
||||||
package nl.sander.beejava.api;
|
|
||||||
|
|
||||||
import nl.sander.beejava.flags.MethodAccessFlag;
|
|
||||||
|
|
||||||
import java.util.*;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Models a method in a BeeClass
|
|
||||||
*/
|
|
||||||
public final class BeeMethod extends CodeContainer {
|
|
||||||
private final String name;
|
|
||||||
|
|
||||||
private final Class<?> returnType;
|
|
||||||
|
|
||||||
public BeeMethod(BeeSource beeSource, String name, Set<MethodAccessFlag> accessFlags,
|
|
||||||
Set<BeeParameter> formalParameters,
|
|
||||||
Class<?> returnType, List<CodeLine> code) {
|
|
||||||
this.name = name;
|
|
||||||
this.accessFlags.addAll(accessFlags);
|
|
||||||
this.formalParameters.addAll(formalParameters);
|
|
||||||
this.returnType = returnType;
|
|
||||||
super.code.addAll(code);
|
|
||||||
setOwner(beeSource);
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getName() {
|
|
||||||
return name;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Class<?> getReturnType() {
|
|
||||||
return returnType;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isConstructor() {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void validate() {
|
|
||||||
//TODO
|
|
||||||
/*
|
|
||||||
* here we could add checks like:
|
|
||||||
* -If this method is in a class rather than an interface, and the name of the method is <init>, then the descriptor must denote a void method.
|
|
||||||
* -If the name of the method is <clinit>, then the descriptor must denote avoid method, and, in a class file whose version number is 51.0 or above,a method that takes no arguments
|
|
||||||
*/
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean equals(Object o) {
|
|
||||||
if (this == o) return true;
|
|
||||||
if (o == null || getClass() != o.getClass()) return false;
|
|
||||||
if (!super.equals(o)) return false;
|
|
||||||
BeeMethod beeMethod = (BeeMethod) o;
|
|
||||||
return name.equals(beeMethod.name) &&
|
|
||||||
returnType.equals(beeMethod.returnType);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int hashCode() {
|
|
||||||
return Objects.hash(super.hashCode(), name, returnType);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,4 +0,0 @@
|
||||||
package nl.sander.beejava.operands;
|
|
||||||
|
|
||||||
public abstract class Operand {
|
|
||||||
}
|
|
||||||
|
|
@ -1,9 +0,0 @@
|
||||||
package nl.sander.beejava.operands;
|
|
||||||
|
|
||||||
public class VoidOperand extends Operand{
|
|
||||||
public final static VoidOperand INSTANCE = new VoidOperand();
|
|
||||||
|
|
||||||
private VoidOperand() {
|
|
||||||
//
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,8 +1,7 @@
|
||||||
package nl.sander.beejava;
|
package nl.sander.bejava;
|
||||||
|
|
||||||
import nl.sander.beejava.constantpool.ConstantPool;
|
import nl.sander.bejava.flags.AccessFlags;
|
||||||
import nl.sander.beejava.flags.AccessFlags;
|
import nl.sander.bejava.util.ByteBuf;
|
||||||
import nl.sander.beejava.util.ByteBuf;
|
|
||||||
|
|
||||||
public class BytecodeGenerator {
|
public class BytecodeGenerator {
|
||||||
|
|
||||||
|
|
@ -13,12 +12,12 @@ public class BytecodeGenerator {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static byte[] generate(CompiledClass compiledClass) {
|
public static byte[] generate(CompiledClass compiledClass) {
|
||||||
BytecodeGenerator bytecodeGenerator = new BytecodeGenerator(compiledClass);
|
var bytecodeGenerator = new BytecodeGenerator(compiledClass);
|
||||||
return bytecodeGenerator.generate();
|
return bytecodeGenerator.generate();
|
||||||
}
|
}
|
||||||
|
|
||||||
private byte[] generate() {
|
private byte[] generate() {
|
||||||
ByteBuf buf = new ByteBuf();
|
var buf = new ByteBuf();
|
||||||
buf.addU8(0xCA, 0xFE, 0xBA, 0xBE);
|
buf.addU8(0xCA, 0xFE, 0xBA, 0xBE);
|
||||||
buf.addU16(compiledClass.getSource().getClassFileVersion().getMinor());
|
buf.addU16(compiledClass.getSource().getClassFileVersion().getMinor());
|
||||||
buf.addU16(compiledClass.getSource().getClassFileVersion().getMajor());
|
buf.addU16(compiledClass.getSource().getClassFileVersion().getMajor());
|
||||||
|
|
@ -1,29 +1,32 @@
|
||||||
package nl.sander.beejava;
|
package nl.sander.bejava;
|
||||||
|
|
||||||
import nl.sander.beejava.api.BeeSource;
|
import nl.sander.bejava.api.BeSource;
|
||||||
import nl.sander.beejava.classinfo.FieldInfo;
|
import nl.sander.bejava.classinfo.FieldInfo;
|
||||||
import nl.sander.beejava.classinfo.MethodInfo;
|
import nl.sander.bejava.classinfo.MethodInfo;
|
||||||
import nl.sander.beejava.constantpool.ConstantPool;
|
import nl.sander.bejava.constantpool.ConstantPool;
|
||||||
import nl.sander.beejava.constantpool.entry.ClassEntry;
|
import nl.sander.bejava.constantpool.entry.ClassEntry;
|
||||||
import nl.sander.beejava.constantpool.entry.ConstantPoolEntry;
|
import nl.sander.bejava.constantpool.entry.ConstantPoolEntry;
|
||||||
|
|
||||||
import java.util.Collection;
|
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.LinkedHashSet;
|
import java.util.LinkedHashSet;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Eventually contains all information for generation of the actual bytecode.
|
||||||
|
* Output of the {@link Compiler} class.
|
||||||
|
*/
|
||||||
public class CompiledClass {
|
public class CompiledClass {
|
||||||
private final Set<ConstantPoolEntry> constantTree = new LinkedHashSet<>();
|
private final Set<ConstantPoolEntry> constantTree = new LinkedHashSet<>();
|
||||||
private final Set<ClassEntry> interfaces = new HashSet<>();
|
private final Set<ClassEntry> interfaces = new HashSet<>();
|
||||||
private final Set<FieldInfo> fields = new HashSet<>();
|
private final Set<FieldInfo> fields = new HashSet<>();
|
||||||
private final Set<MethodInfo> methods = new HashSet<>();
|
private final Set<MethodInfo> methods = new HashSet<>();
|
||||||
private final BeeSource beeSource;
|
private final BeSource beSource;
|
||||||
private ClassEntry thisClass;
|
private ClassEntry thisClass;
|
||||||
private ClassEntry superClass;
|
private ClassEntry superClass;
|
||||||
private ConstantPool constantPool;
|
private ConstantPool constantPool;
|
||||||
|
|
||||||
CompiledClass(BeeSource beeSource) {
|
CompiledClass(BeSource beSource) {
|
||||||
this.beeSource = beeSource;
|
this.beSource = beSource;
|
||||||
}
|
}
|
||||||
|
|
||||||
int getSuperIndex() {
|
int getSuperIndex() {
|
||||||
|
|
@ -56,8 +59,8 @@ public class CompiledClass {
|
||||||
interfaces.add(interfaceEntry);
|
interfaces.add(interfaceEntry);
|
||||||
}
|
}
|
||||||
|
|
||||||
BeeSource getSource() {
|
BeSource getSource() {
|
||||||
return beeSource;
|
return beSource;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setThisClass(ClassEntry newThisClass) {
|
public void setThisClass(ClassEntry newThisClass) {
|
||||||
|
|
@ -1,22 +1,15 @@
|
||||||
package nl.sander.beejava;
|
package nl.sander.bejava;
|
||||||
|
|
||||||
import nl.sander.beejava.api.*;
|
import nl.sander.bejava.api.*;
|
||||||
import nl.sander.beejava.classinfo.FieldInfo;
|
import nl.sander.bejava.classinfo.FieldInfo;
|
||||||
import nl.sander.beejava.classinfo.MethodInfo;
|
import nl.sander.bejava.classinfo.MethodInfo;
|
||||||
import nl.sander.beejava.constantpool.ConstantPool;
|
import nl.sander.bejava.constantpool.entry.Utf8Entry;
|
||||||
import nl.sander.beejava.constantpool.entry.ClassEntry;
|
|
||||||
import nl.sander.beejava.constantpool.entry.FieldRefEntry;
|
|
||||||
import nl.sander.beejava.constantpool.entry.Utf8Entry;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Builds a set of a tree of constant pool entries that refer to each other.
|
* Transforms BeeSource to CompiledClass
|
||||||
* <p>
|
* A client must supply a {@link BeSource} containing a set of {@link CodeLine}s that is assumed to be correct.
|
||||||
* A client must supply a {@link BeeSource} containing a set of {@link CodeLine}s that is assumed to be correct.
|
|
||||||
* It doesn't check if a valid state is reached.
|
* It doesn't check if a valid state is reached.
|
||||||
*/
|
*/
|
||||||
/* So the name isn't entirely correct. Waiting for inspiration.
|
|
||||||
* also TODO make sure entries aren't duplicates
|
|
||||||
*/
|
|
||||||
public class Compiler {
|
public class Compiler {
|
||||||
private final CompiledClass compiledClass;
|
private final CompiledClass compiledClass;
|
||||||
private final ConstantPoolCreator constantPoolCreator = new ConstantPoolCreator();
|
private final ConstantPoolCreator constantPoolCreator = new ConstantPoolCreator();
|
||||||
|
|
@ -35,11 +28,11 @@ public class Compiler {
|
||||||
/**
|
/**
|
||||||
* compile a BeeSource object into a CompiledClass object.
|
* compile a BeeSource object into a CompiledClass object.
|
||||||
*
|
*
|
||||||
* @param beeSource the Class object for which the constant pool needs to be created
|
* @param beSource the Class object for which the constant pool needs to be created
|
||||||
* @return a CompiledClass object (that can be turned into bytecode)
|
* @return a CompiledClass object (that can be turned into bytecode)
|
||||||
*/
|
*/
|
||||||
public static CompiledClass compile(BeeSource beeSource) {
|
public static CompiledClass compile(BeSource beSource) {
|
||||||
return new Compiler(new CompiledClass(beeSource)).compile();
|
return new Compiler(new CompiledClass(beSource)).compile();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -52,13 +45,13 @@ public class Compiler {
|
||||||
|
|
||||||
addClassAndSuperClassEntriesToCompiledClass();
|
addClassAndSuperClassEntriesToCompiledClass();
|
||||||
|
|
||||||
ConstantPool constantPool = constantPoolCreator.createConstantPool(compiledClass.getConstantTree());
|
var constantPool = constantPoolCreator.createConstantPool(compiledClass.getConstantTree());
|
||||||
|
|
||||||
compiledClass.setConstantPool(constantPool);
|
compiledClass.setConstantPool(constantPool);
|
||||||
|
|
||||||
// add refs to super interfaces to class descriptor and constantpool
|
// add refs to super interfaces to class descriptor and constantpool
|
||||||
compiledClass.getSource().getInterfaces().forEach(interfase -> {
|
compiledClass.getSource().getInterfaces().forEach(interfase -> {
|
||||||
ClassEntry interfaceEntry = ConstantPoolEntryCreator.getOrCreateClassEntry(interfase);
|
var interfaceEntry = ConstantPoolEntryCreator.getOrCreateClassEntry(interfase);
|
||||||
compiledClass.addInterface(interfaceEntry);
|
compiledClass.addInterface(interfaceEntry);
|
||||||
compiledClass.addConstantPoolEntry(interfaceEntry);
|
compiledClass.addConstantPoolEntry(interfaceEntry);
|
||||||
});
|
});
|
||||||
|
|
@ -86,11 +79,11 @@ public class Compiler {
|
||||||
|
|
||||||
|
|
||||||
private void addClassAndSuperClassEntriesToCompiledClass() {
|
private void addClassAndSuperClassEntriesToCompiledClass() {
|
||||||
ClassEntry classEntry = ConstantPoolEntryCreator.getOrCreateClassEntry(compiledClass.getSource().getName());
|
var classEntry = ConstantPoolEntryCreator.getOrCreateClassEntry(compiledClass.getSource().getName());
|
||||||
compiledClass.setThisClass(classEntry);
|
compiledClass.setThisClass(classEntry);
|
||||||
compiledClass.addConstantPoolEntry(classEntry);
|
compiledClass.addConstantPoolEntry(classEntry);
|
||||||
|
|
||||||
ClassEntry superClass = ConstantPoolEntryCreator.getOrCreateClassEntry(compiledClass.getSource().getSuperClass());
|
var superClass = ConstantPoolEntryCreator.getOrCreateClassEntry(compiledClass.getSource().getSuperClass());
|
||||||
compiledClass.addConstantPoolEntry(superClass);
|
compiledClass.addConstantPoolEntry(superClass);
|
||||||
compiledClass.setSuperClass(superClass);
|
compiledClass.setSuperClass(superClass);
|
||||||
|
|
||||||
|
|
@ -110,7 +103,7 @@ public class Compiler {
|
||||||
*/
|
*/
|
||||||
public void addMethods() {
|
public void addMethods() {
|
||||||
compiledClass.addConstantPoolEntry(codeAttributeNameEntry);
|
compiledClass.addConstantPoolEntry(codeAttributeNameEntry);
|
||||||
for (BeeMethod method : compiledClass.getSource().getMethods()) {
|
for (var method : compiledClass.getSource().getMethods()) {
|
||||||
compiledClass.addMethod(createMethod(method));
|
compiledClass.addMethod(createMethod(method));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -126,8 +119,8 @@ public class Compiler {
|
||||||
.addAttribute(MethodCodeAttributeCreator.createCodeAttribute(codeAttributeNameEntry, method));
|
.addAttribute(MethodCodeAttributeCreator.createCodeAttribute(codeAttributeNameEntry, method));
|
||||||
}
|
}
|
||||||
|
|
||||||
private void addToConstantPool(BeeField field) {
|
private void addToConstantPool(BeField field) {
|
||||||
FieldRefEntry fieldRefEntry = ConstantPoolEntryCreator.getOrCreateFieldRefEntry(compiledClass.getSource().getName(), field.getName(), field.getType());
|
var fieldRefEntry = ConstantPoolEntryCreator.getOrCreateFieldRefEntry(compiledClass.getSource().getName(), field.getName(), field.getType());
|
||||||
compiledClass.addConstantPoolEntry(fieldRefEntry);
|
compiledClass.addConstantPoolEntry(fieldRefEntry);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
package nl.sander.beejava;
|
package nl.sander.bejava;
|
||||||
|
|
||||||
import nl.sander.beejava.constantpool.ConstantPool;
|
import nl.sander.bejava.constantpool.ConstantPool;
|
||||||
import nl.sander.beejava.constantpool.entry.ConstantPoolEntry;
|
import nl.sander.bejava.constantpool.entry.ConstantPoolEntry;
|
||||||
|
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
|
|
@ -44,7 +44,7 @@ public class ConstantPoolCreator {
|
||||||
* - then add grandchildren (I don't think there's more levels)
|
* - then add grandchildren (I don't think there's more levels)
|
||||||
*/
|
*/
|
||||||
private void updateToplevelElements(Set<ConstantPoolEntry> children) {
|
private void updateToplevelElements(Set<ConstantPoolEntry> children) {
|
||||||
for (ConstantPoolEntry topElement : children) {
|
for (var topElement : children) {
|
||||||
addToPool(topElement); // grandparents
|
addToPool(topElement); // grandparents
|
||||||
updateChildElements(topElement.getChildren());
|
updateChildElements(topElement.getChildren());
|
||||||
}
|
}
|
||||||
|
|
@ -52,11 +52,11 @@ public class ConstantPoolCreator {
|
||||||
|
|
||||||
private void updateChildElements(Set<ConstantPoolEntry> children) {
|
private void updateChildElements(Set<ConstantPoolEntry> children) {
|
||||||
// parents
|
// parents
|
||||||
for (ConstantPoolEntry child : children) {
|
for (var child : children) {
|
||||||
addToPool(child);
|
addToPool(child);
|
||||||
}
|
}
|
||||||
// then grandchildren
|
// then grandchildren
|
||||||
for (ConstantPoolEntry child : children) {
|
for (var child : children) {
|
||||||
updateChildElements(child.getChildren()); // no problem if there are great grand children
|
updateChildElements(child.getChildren()); // no problem if there are great grand children
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
package nl.sander.beejava;
|
package nl.sander.bejava;
|
||||||
|
|
||||||
import nl.sander.beejava.constantpool.entry.*;
|
import nl.sander.bejava.constantpool.entry.*;
|
||||||
import nl.sander.beejava.operands.ConstantOperand;
|
import nl.sander.bejava.operands.ConstantOperand;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
package nl.sander.beejava;
|
package nl.sander.bejava;
|
||||||
|
|
||||||
import nl.sander.beejava.api.BeeField;
|
import nl.sander.bejava.api.BeField;
|
||||||
import nl.sander.beejava.flags.AccessFlags;
|
import nl.sander.bejava.flags.AccessFlags;
|
||||||
|
|
||||||
import java.lang.reflect.Field;
|
import java.lang.reflect.Field;
|
||||||
|
|
||||||
|
|
@ -10,9 +10,9 @@ import java.lang.reflect.Field;
|
||||||
*/
|
*/
|
||||||
public class FieldWrapper {
|
public class FieldWrapper {
|
||||||
private final Field reflectField;
|
private final Field reflectField;
|
||||||
private final BeeField beefield;
|
private final BeField beefield;
|
||||||
|
|
||||||
public FieldWrapper(Field reflectField, BeeField beefield) {
|
public FieldWrapper(Field reflectField, BeField beefield) {
|
||||||
this.reflectField = reflectField;
|
this.reflectField = reflectField;
|
||||||
this.beefield = beefield;
|
this.beefield = beefield;
|
||||||
}
|
}
|
||||||
|
|
@ -40,12 +40,4 @@ public class FieldWrapper {
|
||||||
return AccessFlags.combine(beefield.getAccessFlags());
|
return AccessFlags.combine(beefield.getAccessFlags());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getOwner() {
|
|
||||||
if (reflectField != null) {
|
|
||||||
return reflectField.getDeclaringClass().getName();
|
|
||||||
} else {
|
|
||||||
return beefield.getDeclaringClass();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
@ -1,15 +1,18 @@
|
||||||
package nl.sander.beejava;
|
package nl.sander.bejava;
|
||||||
|
|
||||||
import nl.sander.beejava.constantpool.entry.ConstantPoolEntry;
|
import nl.sander.bejava.constantpool.entry.ConstantPoolEntry;
|
||||||
import nl.sander.beejava.constantpool.entry.FieldRefEntry;
|
import nl.sander.bejava.constantpool.entry.FieldRefEntry;
|
||||||
import nl.sander.beejava.constantpool.entry.MethodRefEntry;
|
import nl.sander.bejava.constantpool.entry.MethodRefEntry;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* bejava opcodes translate to real java opcodes. A JavaInstruct
|
||||||
|
*/
|
||||||
public class JavaInstruction {
|
public class JavaInstruction {
|
||||||
private final JavaOpcode opcode;
|
private final JavaOpcode opcode;
|
||||||
private final MethodRefEntry methodRefEntry;
|
private final MethodRefEntry methodRefEntry;
|
||||||
private final FieldRefEntry fieldRefEntry;
|
private final FieldRefEntry fieldRefEntry;
|
||||||
private final ConstantPoolEntry constantEntry;
|
private final ConstantPoolEntry constantEntry;
|
||||||
private Integer localVariableIndex;
|
private Integer localVariableIndex; // TODO not used yet
|
||||||
|
|
||||||
public JavaInstruction(JavaOpcode opcode) {
|
public JavaInstruction(JavaOpcode opcode) {
|
||||||
this(opcode, null, null, null, null);
|
this(opcode, null, null, null, null);
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
package nl.sander.beejava;
|
package nl.sander.bejava;
|
||||||
|
|
||||||
public enum JavaOpcode {
|
public enum JavaOpcode {
|
||||||
LDC(0x12, false, +1),
|
LDC(0x12, false, +1),
|
||||||
|
|
@ -1,25 +1,24 @@
|
||||||
package nl.sander.beejava;
|
package nl.sander.bejava;
|
||||||
|
|
||||||
import nl.sander.beejava.api.CodeContainer;
|
import nl.sander.bejava.api.CodeContainer;
|
||||||
import nl.sander.beejava.api.CodeLine;
|
import nl.sander.bejava.classinfo.attributes.CodeAttribute;
|
||||||
import nl.sander.beejava.classinfo.attributes.CodeAttribute;
|
import nl.sander.bejava.constantpool.entry.ConstantPoolEntry;
|
||||||
import nl.sander.beejava.constantpool.entry.ConstantPoolEntry;
|
import nl.sander.bejava.constantpool.entry.MethodRefEntry;
|
||||||
import nl.sander.beejava.constantpool.entry.MethodRefEntry;
|
import nl.sander.bejava.constantpool.entry.Utf8Entry;
|
||||||
import nl.sander.beejava.constantpool.entry.Utf8Entry;
|
import nl.sander.bejava.util.ByteBuf;
|
||||||
import nl.sander.beejava.util.ByteBuf;
|
|
||||||
|
|
||||||
public class MethodCodeAttributeCreator {
|
public class MethodCodeAttributeCreator {
|
||||||
|
|
||||||
public static CodeAttribute createCodeAttribute(Utf8Entry codeAttributeNameEntry, CodeContainer codeContainer) {
|
public static CodeAttribute createCodeAttribute(Utf8Entry codeAttributeNameEntry, CodeContainer codeContainer) {
|
||||||
CodeAttribute codeAttribute = new CodeAttribute(codeAttributeNameEntry);
|
var codeAttribute = new CodeAttribute(codeAttributeNameEntry);
|
||||||
codeAttribute.setMaxStack(calculateMaxStack(codeContainer));
|
codeAttribute.setMaxStack(calculateMaxStack(codeContainer));
|
||||||
codeAttribute.setMaxLocals(codeContainer.getFormalParameters().size() + 1);
|
codeAttribute.setMaxLocals(codeContainer.getFormalParameters().size() + 1);
|
||||||
ByteBuf byteBuf = new ByteBuf();
|
var byteBuf = new ByteBuf();
|
||||||
|
|
||||||
codeContainer.getExpandedCode().forEach(instruction -> {
|
codeContainer.getExpandedCode().forEach(instruction -> {
|
||||||
JavaOpcode javaOpcode = instruction.getOpcode();
|
var javaOpcode = instruction.getOpcode();
|
||||||
byteBuf.addU8(javaOpcode.getByteCode());
|
byteBuf.addU8(javaOpcode.getByteCode());
|
||||||
ConstantPoolEntry constantPoolEntry = instruction.getEntry();
|
var constantPoolEntry = instruction.getEntry();
|
||||||
if (constantPoolEntry != null) {
|
if (constantPoolEntry != null) {
|
||||||
if (javaOpcode.isWide()) {
|
if (javaOpcode.isWide()) {
|
||||||
byteBuf.addU16(constantPoolEntry.getIndex());
|
byteBuf.addU16(constantPoolEntry.getIndex());
|
||||||
|
|
@ -37,12 +36,12 @@ public class MethodCodeAttributeCreator {
|
||||||
private static int calculateMaxStack(CodeContainer codeContainer) {
|
private static int calculateMaxStack(CodeContainer codeContainer) {
|
||||||
int stackSize = 0;
|
int stackSize = 0;
|
||||||
int maxStackSize = 0;
|
int maxStackSize = 0;
|
||||||
for (JavaInstruction instruction : codeContainer.getExpandedCode()) {
|
for (var instruction : codeContainer.getExpandedCode()) {
|
||||||
stackSize += instruction.getOpcode().getStackDif();
|
stackSize += instruction.getOpcode().getStackDif();
|
||||||
ConstantPoolEntry assignedEntry = instruction.getEntry();
|
var assignedEntry = instruction.getEntry();
|
||||||
if (assignedEntry instanceof MethodRefEntry) {
|
if (assignedEntry instanceof MethodRefEntry) {
|
||||||
MethodRefEntry methodRefEntry = (MethodRefEntry) assignedEntry;
|
var methodRefEntry = (MethodRefEntry) assignedEntry;
|
||||||
String argumentTypes = methodRefEntry.getNameAndType().getType();
|
var argumentTypes = methodRefEntry.getNameAndType().getType();
|
||||||
stackSize -= getNrArguments(argumentTypes);
|
stackSize -= getNrArguments(argumentTypes);
|
||||||
}
|
}
|
||||||
if (stackSize > maxStackSize) {
|
if (stackSize > maxStackSize) {
|
||||||
|
|
@ -1,47 +1,41 @@
|
||||||
package nl.sander.beejava;
|
package nl.sander.bejava;
|
||||||
|
|
||||||
import nl.sander.beejava.api.*;
|
import nl.sander.bejava.api.*;
|
||||||
import nl.sander.beejava.constantpool.entry.ConstantPoolEntry;
|
import nl.sander.bejava.operands.*;
|
||||||
import nl.sander.beejava.operands.*;
|
|
||||||
|
|
||||||
import java.lang.reflect.Field;
|
import java.lang.reflect.Field;
|
||||||
import java.lang.reflect.Modifier;
|
import java.lang.reflect.Modifier;
|
||||||
import java.util.*;
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Locale;
|
||||||
|
import java.util.Objects;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
enum Primitives {
|
|
||||||
INT, SHORT, BYTE, LONG, FLOAT, DOUBLE, CHAR, BOOLEAN;
|
|
||||||
|
|
||||||
public static Primitives from(String value) {
|
|
||||||
return Arrays.stream(values()).filter(e -> e.toString().equals(value)).findFirst().orElse(null);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Translates from BeeJava opcodes to actual java opcodes.
|
* Translates from BeeJava opcodes to actual java opcodes.
|
||||||
*/
|
*/
|
||||||
public class OpcodeTranslator {
|
public class OpcodeTranslator {
|
||||||
private final static OpcodeTranslator instance = new OpcodeTranslator();
|
private final static OpcodeTranslator instance = new OpcodeTranslator();
|
||||||
private final Parser parser = new Parser();
|
private final Parser parser = new Parser();
|
||||||
private BeeSource beeSource;
|
private BeSource beSource;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* trying to make SourceExpander reusable.
|
* trying to make SourceExpander reusable.
|
||||||
* @not_multithreaded.
|
* @not_multithreaded.
|
||||||
* //TODO should not mutate beesource
|
* //TODO should not mutate beesource
|
||||||
*/
|
*/
|
||||||
public static void translate(BeeSource beeSource) {
|
public static void translate(BeSource beSource) {
|
||||||
instance.init(beeSource);
|
instance.init(beSource);
|
||||||
instance.doExpand();
|
instance.doExpand();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void init(BeeSource beeSource) {
|
private void init(BeSource beSource) {
|
||||||
this.beeSource = beeSource;
|
this.beSource = beSource;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void doExpand() {
|
private void doExpand() {
|
||||||
beeSource.getConstructors().forEach(this::translate);
|
beSource.getConstructors().forEach(this::translate);
|
||||||
beeSource.getMethods().forEach(this::translate);
|
beSource.getMethods().forEach(this::translate);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void translate(CodeContainer codeContainer) {
|
private void translate(CodeContainer codeContainer) {
|
||||||
|
|
@ -53,11 +47,11 @@ public class OpcodeTranslator {
|
||||||
|
|
||||||
private List<JavaInstruction> translate(CodeContainer codeContainer, CodeLine codeLine) {
|
private List<JavaInstruction> translate(CodeContainer codeContainer, CodeLine codeLine) {
|
||||||
var operand = parser.parse(codeLine);
|
var operand = parser.parse(codeLine);
|
||||||
return eval(codeContainer, codeLine.getOpcode(), operand);
|
return translate(codeContainer, codeLine.getOpcode(), operand);
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<JavaInstruction> eval(CodeContainer codeContainer, Opcode opcode, Operand operand) {
|
private List<JavaInstruction> translate(CodeContainer codeContainer, Opcode opcode, Operand operand) {
|
||||||
final List<JavaInstruction> instructions = new ArrayList<>();
|
List<JavaInstruction> instructions = new ArrayList<>();
|
||||||
if (operand instanceof MethodOperand) {
|
if (operand instanceof MethodOperand) {
|
||||||
var mo = (MethodOperand) operand;
|
var mo = (MethodOperand) operand;
|
||||||
if ("this".equals(mo.className)) {
|
if ("this".equals(mo.className)) {
|
||||||
|
|
@ -66,7 +60,7 @@ public class OpcodeTranslator {
|
||||||
}
|
}
|
||||||
if (opcode == Opcode.LOAD) {
|
if (opcode == Opcode.LOAD) {
|
||||||
if (operand instanceof ConstantOperand) {
|
if (operand instanceof ConstantOperand) {
|
||||||
ConstantPoolEntry constantEntry = ConstantPoolEntryCreator.getOrCreatePrimitiveConstantEntry((ConstantOperand) operand);
|
var constantEntry = ConstantPoolEntryCreator.getOrCreatePrimitiveConstantEntry((ConstantOperand) operand);
|
||||||
instructions.add(new JavaInstruction(JavaOpcode.LDC, constantEntry));
|
instructions.add(new JavaInstruction(JavaOpcode.LDC, constantEntry));
|
||||||
}
|
}
|
||||||
} else if (opcode == Opcode.RETURN && operand instanceof VoidOperand) {
|
} else if (opcode == Opcode.RETURN && operand instanceof VoidOperand) {
|
||||||
|
|
@ -75,7 +69,7 @@ public class OpcodeTranslator {
|
||||||
assert operand instanceof FieldOperand;
|
assert operand instanceof FieldOperand;
|
||||||
|
|
||||||
var fieldOperand = (FieldOperand) operand;
|
var fieldOperand = (FieldOperand) operand;
|
||||||
FieldWrapper field = getField(codeContainer, fieldOperand);
|
var field = getField(codeContainer, fieldOperand);
|
||||||
instructions.add(new JavaInstruction(getJavaOpcodeForGet(field),
|
instructions.add(new JavaInstruction(getJavaOpcodeForGet(field),
|
||||||
ConstantPoolEntryCreator.getOrCreateFieldRefEntry(getType(codeContainer, fieldOperand), field.getName(), field.getType())));
|
ConstantPoolEntryCreator.getOrCreateFieldRefEntry(getType(codeContainer, fieldOperand), field.getName(), field.getType())));
|
||||||
} else if (opcode == Opcode.INVOKE) {
|
} else if (opcode == Opcode.INVOKE) {
|
||||||
|
|
@ -83,11 +77,10 @@ public class OpcodeTranslator {
|
||||||
var mo = (MethodOperand) operand;
|
var mo = (MethodOperand) operand;
|
||||||
if ("super".equals(mo.methodName)) {
|
if ("super".equals(mo.methodName)) {
|
||||||
instructions.add(new JavaInstruction(JavaOpcode.INVOKESPECIAL,
|
instructions.add(new JavaInstruction(JavaOpcode.INVOKESPECIAL,
|
||||||
ConstantPoolEntryCreator.getOrCreateMethodRefEntry(beeSource.getSuperClass().getName(), "<init>", "()V")));
|
ConstantPoolEntryCreator.getOrCreateMethodRefEntry(beSource.getSuperClass().getName(), "<init>", "()V")));
|
||||||
} else {
|
} else {
|
||||||
instructions.add(new JavaInstruction(JavaOpcode.INVOKEVIRTUAL, ConstantPoolEntryCreator.getOrCreateMethodRefEntry(mo.className, mo.methodName, mo.signature)));
|
instructions.add(new JavaInstruction(JavaOpcode.INVOKEVIRTUAL, ConstantPoolEntryCreator.getOrCreateMethodRefEntry(mo.className, mo.methodName, mo.signature)));
|
||||||
}
|
}
|
||||||
System.out.println(operand);
|
|
||||||
} else if (operand instanceof FieldOperand) {
|
} else if (operand instanceof FieldOperand) {
|
||||||
var fieldOperand = (FieldOperand) operand;
|
var fieldOperand = (FieldOperand) operand;
|
||||||
if (fieldOperand.className.equals("this")) {
|
if (fieldOperand.className.equals("this")) {
|
||||||
|
|
@ -99,7 +92,9 @@ public class OpcodeTranslator {
|
||||||
}
|
}
|
||||||
} else if (operand instanceof LocalVariableOperand) {
|
} else if (operand instanceof LocalVariableOperand) {
|
||||||
var localVariable = (LocalVariableOperand) operand;
|
var localVariable = (LocalVariableOperand) operand;
|
||||||
instructions.add(codeContainer.getParameter(localVariable.name).map(this::getJavaLoadInstruction).orElse(null)); //else case
|
instructions.add(codeContainer.getParameter(localVariable.name)
|
||||||
|
.map(this::getJavaLoadInstruction)
|
||||||
|
.orElse(null)); //else case
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO continue here. finish simpleBean
|
// TODO continue here. finish simpleBean
|
||||||
|
|
@ -117,9 +112,9 @@ public class OpcodeTranslator {
|
||||||
}
|
}
|
||||||
|
|
||||||
private JavaInstruction getReturnInstruction(CodeContainer codeContainer, FieldOperand fo) {
|
private JavaInstruction getReturnInstruction(CodeContainer codeContainer, FieldOperand fo) {
|
||||||
FieldWrapper field = getField(codeContainer, fo);
|
var field = getField(codeContainer, fo);
|
||||||
|
|
||||||
JavaOpcode javaOpcode = switch (field.getName()) {
|
var javaOpcode = switch (field.getName()) {
|
||||||
case "int", "byte", "boolean", "short" -> JavaOpcode.IRETURN;
|
case "int", "byte", "boolean", "short" -> JavaOpcode.IRETURN;
|
||||||
case "long" -> JavaOpcode.LRETURN;
|
case "long" -> JavaOpcode.LRETURN;
|
||||||
case "float" -> JavaOpcode.FRETURN;
|
case "float" -> JavaOpcode.FRETURN;
|
||||||
|
|
@ -142,20 +137,20 @@ public class OpcodeTranslator {
|
||||||
private FieldWrapper getField(CodeContainer codeContainer, FieldOperand fo) {
|
private FieldWrapper getField(CodeContainer codeContainer, FieldOperand fo) {
|
||||||
try {
|
try {
|
||||||
Field javaField = null;
|
Field javaField = null;
|
||||||
BeeField beeField = null;
|
BeField beField = null;
|
||||||
if (fo.className.equals("this")) {
|
if (fo.className.equals("this")) {
|
||||||
beeField = codeContainer.getOwner().getField(fo.fieldName);
|
beField = codeContainer.getOwner().getField(fo.fieldName);
|
||||||
} else {
|
} else {
|
||||||
Class<?> type = Class.forName(fo.className);
|
var type = Class.forName(fo.className);
|
||||||
javaField = type.getDeclaredField(fo.fieldName);
|
javaField = type.getDeclaredField(fo.fieldName);
|
||||||
}
|
}
|
||||||
return new FieldWrapper(javaField, beeField);
|
return new FieldWrapper(javaField, beField);
|
||||||
} catch (ClassNotFoundException | NoSuchFieldException e) {
|
} catch (ClassNotFoundException | NoSuchFieldException e) {
|
||||||
throw new IllegalStateException(e);
|
throw new IllegalStateException(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private JavaInstruction getJavaLoadInstruction(BeeParameter parameter) {
|
private JavaInstruction getJavaLoadInstruction(BeParameter parameter) {
|
||||||
return switch (parameter.getIndex()) {
|
return switch (parameter.getIndex()) {
|
||||||
case 0 -> new JavaInstruction(JavaOpcode.ALOAD_0);
|
case 0 -> new JavaInstruction(JavaOpcode.ALOAD_0);
|
||||||
case 1 -> new JavaInstruction(JavaOpcode.ALOAD_1);
|
case 1 -> new JavaInstruction(JavaOpcode.ALOAD_1);
|
||||||
20
src/main/java/nl/sander/bejava/OverallCompiler.java
Normal file
20
src/main/java/nl/sander/bejava/OverallCompiler.java
Normal file
|
|
@ -0,0 +1,20 @@
|
||||||
|
package nl.sander.bejava;
|
||||||
|
|
||||||
|
import nl.sander.bejava.api.BeSource;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Contains all four passes necessary to go from source as text to bytecode.
|
||||||
|
*/
|
||||||
|
public final class OverallCompiler {
|
||||||
|
|
||||||
|
private OverallCompiler() {
|
||||||
|
//
|
||||||
|
}
|
||||||
|
|
||||||
|
public static byte[] compile(String sourcecode) {
|
||||||
|
BeSource beSource = SourceCompiler.compile(sourcecode);
|
||||||
|
OpcodeTranslator.translate(beSource);
|
||||||
|
CompiledClass compiledClass = Compiler.compile(beSource);
|
||||||
|
return BytecodeGenerator.generate(compiledClass);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
package nl.sander.beejava;
|
package nl.sander.bejava;
|
||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
|
||||||
|
|
@ -1,9 +1,9 @@
|
||||||
package nl.sander.beejava;
|
package nl.sander.bejava;
|
||||||
|
|
||||||
import nl.sander.beejava.api.*;
|
import nl.sander.bejava.api.*;
|
||||||
import nl.sander.beejava.flags.ClassAccessFlags;
|
import nl.sander.bejava.flags.ClassAccessFlags;
|
||||||
import nl.sander.beejava.flags.FieldAccessFlag;
|
import nl.sander.bejava.flags.FieldAccessFlag;
|
||||||
import nl.sander.beejava.flags.MethodAccessFlag;
|
import nl.sander.bejava.flags.MethodAccessFlag;
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.function.Supplier;
|
import java.util.function.Supplier;
|
||||||
|
|
@ -25,43 +25,43 @@ public class SourceCompiler {
|
||||||
this.sourcecode = sourcecode;
|
this.sourcecode = sourcecode;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static BeeSource compile(String sourcecode) {
|
public static BeSource compile(String sourcecode) {
|
||||||
return new SourceCompiler(sourcecode).doCompile();
|
return new SourceCompiler(sourcecode).doCompile();
|
||||||
}
|
}
|
||||||
|
|
||||||
public BeeSource doCompile() {
|
public BeSource doCompile() {
|
||||||
Arrays.stream(sourcecode.split("\n"))
|
Arrays.stream(sourcecode.split("\n"))
|
||||||
.map(this::compileLine)
|
.map(this::compileLine)
|
||||||
.forEach(instructions::add);
|
.forEach(instructions::add);
|
||||||
|
|
||||||
BeeSource beeSource = new BeeSource();
|
BeSource beSource = new BeSource();
|
||||||
|
|
||||||
for (currentLine = 0; currentLine < instructions.size(); ) {
|
for (currentLine = 0; currentLine < instructions.size(); ) {
|
||||||
Instruction ins = instructions.get(currentLine);
|
Instruction ins = instructions.get(currentLine);
|
||||||
if (currentLine == 0) {
|
if (currentLine == 0) {
|
||||||
parseClassDeclaration(ins, beeSource);
|
parseClassDeclaration(ins, beSource);
|
||||||
} else {
|
} else {
|
||||||
parseInstruction(ins, beeSource);
|
parseInstruction(ins, beSource);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return beeSource;
|
return beSource;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void parseInstruction(Instruction instruction, BeeSource beeSource) {
|
private void parseInstruction(Instruction instruction, BeSource beSource) {
|
||||||
if (instruction instanceof ClassInstruction) {
|
if (instruction instanceof ClassInstruction) {
|
||||||
ClassInstruction classInstruction = (ClassInstruction) instruction;
|
ClassInstruction classInstruction = (ClassInstruction) instruction;
|
||||||
String operand = classInstruction.getOperand();
|
String operand = classInstruction.getOperand();
|
||||||
switch (classInstruction.getOperation()) {
|
switch (classInstruction.getOperation()) {
|
||||||
case FIELD -> beeSource.addFields(parseField(beeSource, operand));
|
case FIELD -> beSource.addFields(parseField(beSource, operand));
|
||||||
case CONSTRUCTOR -> beeSource.addConstructors(parseConstructor(beeSource, operand));
|
case CONSTRUCTOR -> beSource.addConstructors(parseConstructor(beSource, operand));
|
||||||
case METHOD -> beeSource.addMethods(parseMethod(beeSource, operand));
|
case METHOD -> beSource.addMethods(parseMethod(beSource, operand));
|
||||||
default -> throw new IllegalArgumentException("Not allowed here");
|
default -> throw new IllegalArgumentException("Not allowed here");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private nl.sander.beejava.api.BeeMethod parseMethod(BeeSource beeSource, String text) {
|
private BeMethod parseMethod(BeSource beSource, String text) {
|
||||||
String[] tokens = returntypesplitter.split(text);
|
String[] tokens = returntypesplitter.split(text);
|
||||||
final String first;
|
final String first;
|
||||||
final Class<?> returnType;
|
final Class<?> returnType;
|
||||||
|
|
@ -85,7 +85,7 @@ public class SourceCompiler {
|
||||||
}
|
}
|
||||||
|
|
||||||
String[] nameParams = split(flagsNameParameters[i], parensplitter);
|
String[] nameParams = split(flagsNameParameters[i], parensplitter);
|
||||||
Set<nl.sander.beejava.api.BeeParameter> parameters = new HashSet<>();
|
Set<BeParameter> parameters = new HashSet<>();
|
||||||
String methodName = null;
|
String methodName = null;
|
||||||
if (nameParams.length > 0) {
|
if (nameParams.length > 0) {
|
||||||
methodName = nameParams[0];
|
methodName = nameParams[0];
|
||||||
|
|
@ -97,7 +97,7 @@ public class SourceCompiler {
|
||||||
String[] declaration = paramToken.trim().split(" ");
|
String[] declaration = paramToken.trim().split(" ");
|
||||||
String type = declaration[0];
|
String type = declaration[0];
|
||||||
String name = declaration[1];
|
String name = declaration[1];
|
||||||
parameters.add(new nl.sander.beejava.api.BeeParameter(getType(type), name, index++));
|
parameters.add(new BeParameter(getType(type), name, index++));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -105,7 +105,7 @@ public class SourceCompiler {
|
||||||
throw new IllegalArgumentException("method name not found");
|
throw new IllegalArgumentException("method name not found");
|
||||||
}
|
}
|
||||||
currentLine += 1;
|
currentLine += 1;
|
||||||
List<nl.sander.beejava.api.CodeLine> lines = new ArrayList<>();
|
List<nl.sander.bejava.api.CodeLine> lines = new ArrayList<>();
|
||||||
Instruction nextInstruction = instructions.get(currentLine);
|
Instruction nextInstruction = instructions.get(currentLine);
|
||||||
while (currentLine < instructions.size() && nextInstruction instanceof CodeLine) {
|
while (currentLine < instructions.size() && nextInstruction instanceof CodeLine) {
|
||||||
nextInstruction = instructions.get(currentLine);
|
nextInstruction = instructions.get(currentLine);
|
||||||
|
|
@ -116,16 +116,16 @@ public class SourceCompiler {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
return new BeeMethod(beeSource, methodName, flags, parameters, returnType, lines);
|
return new BeMethod(beSource, methodName, flags, parameters, returnType, lines);
|
||||||
}
|
}
|
||||||
|
|
||||||
private nl.sander.beejava.api.BeeConstructor parseConstructor(BeeSource beeSource, String text) {
|
private BeConstructor parseConstructor(BeSource beSource, String text) {
|
||||||
String[] tokens = split(text, parensplitter);
|
String[] tokens = split(text, parensplitter);
|
||||||
String flag = tokens[0];
|
String flag = tokens[0];
|
||||||
MethodAccessFlag methodAccessFlag = MethodAccessFlag.get(flag.toUpperCase()).orElseThrow(illegalArgument("Not a valid flag " + flag));
|
MethodAccessFlag methodAccessFlag = MethodAccessFlag.get(flag.toUpperCase()).orElseThrow(illegalArgument("Not a valid flag " + flag));
|
||||||
|
|
||||||
String params = tokens[1];
|
String params = tokens[1];
|
||||||
Set<BeeParameter> parameters = new HashSet<>();
|
Set<BeParameter> parameters = new HashSet<>();
|
||||||
if (params.length() > 0) {
|
if (params.length() > 0) {
|
||||||
String[] paramTokens = params.split(",");
|
String[] paramTokens = params.split(",");
|
||||||
int index = 0;
|
int index = 0;
|
||||||
|
|
@ -133,7 +133,7 @@ public class SourceCompiler {
|
||||||
String[] declaration = paramToken.trim().split(" ");
|
String[] declaration = paramToken.trim().split(" ");
|
||||||
String type = declaration[0];
|
String type = declaration[0];
|
||||||
String name = declaration[1];
|
String name = declaration[1];
|
||||||
parameters.add(new BeeParameter(getType(type), name, index++));
|
parameters.add(new BeParameter(getType(type), name, index++));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
currentLine += 1;
|
currentLine += 1;
|
||||||
|
|
@ -147,10 +147,10 @@ public class SourceCompiler {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return new BeeConstructor(beeSource, Set.of(methodAccessFlag), parameters, lines);
|
return new BeConstructor(beSource, Set.of(methodAccessFlag), parameters, lines);
|
||||||
}
|
}
|
||||||
|
|
||||||
private nl.sander.beejava.api.BeeField parseField(BeeSource beeSource, String operand) {
|
private BeField parseField(BeSource beSource, String operand) {
|
||||||
String[] tokens = operand.split(" ");
|
String[] tokens = operand.split(" ");
|
||||||
Set<FieldAccessFlag> flags = new HashSet<>();
|
Set<FieldAccessFlag> flags = new HashSet<>();
|
||||||
String type = null;
|
String type = null;
|
||||||
|
|
@ -168,17 +168,17 @@ public class SourceCompiler {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
currentLine += 1;
|
currentLine += 1;
|
||||||
return new BeeField(beeSource.getName(), flags, getType(type), name);
|
return new BeField(beSource.getName(), flags, getType(type), name);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void parseClassDeclaration(Instruction instruction, BeeSource beeSource) {
|
private void parseClassDeclaration(Instruction instruction, BeSource beSource) {
|
||||||
if (instruction instanceof ClassInstruction) {
|
if (instruction instanceof ClassInstruction) {
|
||||||
ClassInstruction classDeclaration = (ClassInstruction) instruction;
|
ClassInstruction classDeclaration = (ClassInstruction) instruction;
|
||||||
ClassOperation operation = classDeclaration.getOperation();
|
ClassOperation operation = classDeclaration.getOperation();
|
||||||
switch (operation) {
|
switch (operation) {
|
||||||
case CLASS -> {
|
case CLASS -> {
|
||||||
beeSource.addAccessFlags(ClassAccessFlags.SUPER);
|
beSource.addAccessFlags(ClassAccessFlags.SUPER);
|
||||||
beeSource.setClassFileVersion(getVersion(classDeclaration));
|
beSource.setClassFileVersion(getVersion(classDeclaration));
|
||||||
|
|
||||||
String[] tokens = split(classDeclaration.getOperand(), parensplitter);
|
String[] tokens = split(classDeclaration.getOperand(), parensplitter);
|
||||||
String rightHand = classDeclaration.getOperand();
|
String rightHand = classDeclaration.getOperand();
|
||||||
|
|
@ -188,9 +188,9 @@ public class SourceCompiler {
|
||||||
tokens = rightHand.split(" ");
|
tokens = rightHand.split(" ");
|
||||||
|
|
||||||
if (tokens.length == 2) { // has access flag
|
if (tokens.length == 2) { // has access flag
|
||||||
beeSource.addAccessFlags(ClassAccessFlags.valueOf(tokens[0].toUpperCase()));
|
beSource.addAccessFlags(ClassAccessFlags.valueOf(tokens[0].toUpperCase()));
|
||||||
}
|
}
|
||||||
beeSource.setName(getClassName(tokens));
|
beSource.setName(getClassName(tokens));
|
||||||
}
|
}
|
||||||
case INTERFACE -> {
|
case INTERFACE -> {
|
||||||
}//TODO
|
}//TODO
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
package nl.sander.beejava;
|
package nl.sander.bejava;
|
||||||
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
|
@ -1,21 +1,21 @@
|
||||||
package nl.sander.beejava.api;
|
package nl.sander.bejava.api;
|
||||||
|
|
||||||
import nl.sander.beejava.flags.MethodAccessFlag;
|
import nl.sander.bejava.flags.MethodAccessFlag;
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Models a constructor
|
* Models a constructor
|
||||||
*/
|
*/
|
||||||
public final class BeeConstructor extends CodeContainer {
|
public final class BeConstructor extends CodeContainer {
|
||||||
|
|
||||||
public BeeConstructor(BeeSource beeSource, Set<MethodAccessFlag> accessFlags,
|
public BeConstructor(BeSource beSource, Set<MethodAccessFlag> accessFlags,
|
||||||
Set<BeeParameter> formalParameters,
|
Set<BeParameter> formalParameters,
|
||||||
List<CodeLine> code) {
|
List<CodeLine> code) {
|
||||||
this.formalParameters.addAll(formalParameters);
|
this.formalParameters.addAll(formalParameters);
|
||||||
this.accessFlags.addAll(accessFlags);
|
this.accessFlags.addAll(accessFlags);
|
||||||
super.code.addAll(code);
|
super.code.addAll(code);
|
||||||
setOwner(beeSource);
|
setOwner(beSource);
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getName() {
|
public String getName() {
|
||||||
|
|
@ -33,16 +33,11 @@ public final class BeeConstructor extends CodeContainer {
|
||||||
return void.class;
|
return void.class;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isConstructor() {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean equals(Object o) {
|
public boolean equals(Object o) {
|
||||||
if (this == o) return true;
|
if (this == o) return true;
|
||||||
if (o == null || getClass() != o.getClass()) return false;
|
if (o == null || getClass() != o.getClass()) return false;
|
||||||
BeeConstructor that = (BeeConstructor) o;
|
var that = (BeConstructor) o;
|
||||||
return formalParameters.equals(that.formalParameters);
|
return formalParameters.equals(that.formalParameters);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
package nl.sander.beejava.api;
|
package nl.sander.bejava.api;
|
||||||
|
|
||||||
import nl.sander.beejava.flags.FieldAccessFlag;
|
import nl.sander.bejava.flags.FieldAccessFlag;
|
||||||
|
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
|
@ -9,7 +9,7 @@ import java.util.Set;
|
||||||
/**
|
/**
|
||||||
* Models a field in a BeeClass
|
* Models a field in a BeeClass
|
||||||
*/
|
*/
|
||||||
public final class BeeField {
|
public final class BeField {
|
||||||
|
|
||||||
private final String declaringClass;
|
private final String declaringClass;
|
||||||
private final Set<FieldAccessFlag> accessFlags = new HashSet<>();
|
private final Set<FieldAccessFlag> accessFlags = new HashSet<>();
|
||||||
|
|
@ -23,7 +23,7 @@ public final class BeeField {
|
||||||
* @param type field type. Must be existing type.
|
* @param type field type. Must be existing type.
|
||||||
* @param name
|
* @param name
|
||||||
*/
|
*/
|
||||||
public BeeField(String declaringClass, Set<FieldAccessFlag> accessFlags, Class<?> type, String name) {
|
public BeField(String declaringClass, Set<FieldAccessFlag> accessFlags, Class<?> type, String name) {
|
||||||
this.declaringClass = declaringClass;
|
this.declaringClass = declaringClass;
|
||||||
this.accessFlags.addAll(accessFlags);
|
this.accessFlags.addAll(accessFlags);
|
||||||
this.type = type;
|
this.type = type;
|
||||||
|
|
@ -50,7 +50,7 @@ public final class BeeField {
|
||||||
public boolean equals(Object o) {
|
public boolean equals(Object o) {
|
||||||
if (this == o) return true;
|
if (this == o) return true;
|
||||||
if (o == null || getClass() != o.getClass()) return false;
|
if (o == null || getClass() != o.getClass()) return false;
|
||||||
BeeField beeField = (BeeField) o;
|
var beeField = (BeField) o;
|
||||||
return name.equals(beeField.name);
|
return name.equals(beeField.name);
|
||||||
}
|
}
|
||||||
|
|
||||||
57
src/main/java/nl/sander/bejava/api/BeMethod.java
Normal file
57
src/main/java/nl/sander/bejava/api/BeMethod.java
Normal file
|
|
@ -0,0 +1,57 @@
|
||||||
|
package nl.sander.bejava.api;
|
||||||
|
|
||||||
|
import nl.sander.bejava.flags.MethodAccessFlag;
|
||||||
|
|
||||||
|
import java.util.*;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Models a method in a BeeClass
|
||||||
|
*/
|
||||||
|
public final class BeMethod extends CodeContainer {
|
||||||
|
private final String name;
|
||||||
|
|
||||||
|
private final Class<?> returnType;
|
||||||
|
|
||||||
|
public BeMethod(BeSource beSource, String name, Set<MethodAccessFlag> accessFlags,
|
||||||
|
Set<BeParameter> formalParameters,
|
||||||
|
Class<?> returnType, List<CodeLine> code) {
|
||||||
|
this.name = name;
|
||||||
|
this.accessFlags.addAll(accessFlags);
|
||||||
|
this.formalParameters.addAll(formalParameters);
|
||||||
|
this.returnType = returnType;
|
||||||
|
super.code.addAll(code);
|
||||||
|
setOwner(beSource);
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getName() {
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Class<?> getReturnType() {
|
||||||
|
return returnType;
|
||||||
|
}
|
||||||
|
|
||||||
|
// public void validate() {
|
||||||
|
// //TODO
|
||||||
|
// /*
|
||||||
|
// * here we could add checks like:
|
||||||
|
// * -If this method is in a class rather than an interface, and the name of the method is <init>, then the descriptor must denote a void method.
|
||||||
|
// * -If the name of the method is <clinit>, then the descriptor must denote avoid method, and, in a class file whose version number is 51.0 or above,a method that takes no arguments
|
||||||
|
// */
|
||||||
|
// }
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals(Object o) {
|
||||||
|
if (this == o) return true;
|
||||||
|
if (o == null || getClass() != o.getClass()) return false;
|
||||||
|
if (!super.equals(o)) return false;
|
||||||
|
BeMethod beMethod = (BeMethod) o;
|
||||||
|
return name.equals(beMethod.name) &&
|
||||||
|
returnType.equals(beMethod.returnType);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int hashCode() {
|
||||||
|
return Objects.hash(super.hashCode(), name, returnType);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -1,22 +1,22 @@
|
||||||
package nl.sander.beejava.api;
|
package nl.sander.bejava.api;
|
||||||
|
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Models a formal parameter in a method declaration.
|
* Models a formal parameter in a method declaration.
|
||||||
*/
|
*/
|
||||||
public final class BeeParameter {
|
public final class BeParameter {
|
||||||
private final Class<?> type;
|
private final Class<?> type;
|
||||||
private final String name;
|
private final String name;
|
||||||
private final int index;
|
private final int index;
|
||||||
|
|
||||||
public BeeParameter(Class<?> type, String name) {
|
public BeParameter(Class<?> type, String name) {
|
||||||
this.type = type;
|
this.type = type;
|
||||||
this.name = name;
|
this.name = name;
|
||||||
this.index = -1;
|
this.index = -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
public BeeParameter(Class<?> type, String name, int index) {
|
public BeParameter(Class<?> type, String name, int index) {
|
||||||
this.type = type;
|
this.type = type;
|
||||||
this.name = name;
|
this.name = name;
|
||||||
this.index = index;
|
this.index = index;
|
||||||
|
|
@ -34,7 +34,7 @@ public final class BeeParameter {
|
||||||
public boolean equals(Object o) {
|
public boolean equals(Object o) {
|
||||||
if (this == o) return true;
|
if (this == o) return true;
|
||||||
if (o == null || getClass() != o.getClass()) return false;
|
if (o == null || getClass() != o.getClass()) return false;
|
||||||
BeeParameter that = (BeeParameter) o;
|
var that = (BeParameter) o;
|
||||||
return name.equals(that.name);
|
return name.equals(that.name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
package nl.sander.beejava.api;
|
package nl.sander.bejava.api;
|
||||||
|
|
||||||
import nl.sander.beejava.flags.ClassAccessFlags;
|
import nl.sander.bejava.flags.ClassAccessFlags;
|
||||||
|
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
|
|
@ -9,12 +9,12 @@ import java.util.Set;
|
||||||
/**
|
/**
|
||||||
* Contains parsed class elements like constructors and methods, but the opcode is not compiled to bytecode yet.
|
* Contains parsed class elements like constructors and methods, but the opcode is not compiled to bytecode yet.
|
||||||
*/
|
*/
|
||||||
public final class BeeSource {
|
public final class BeSource {
|
||||||
private final Set<ClassAccessFlags> accessFlags = new HashSet<>();
|
private final Set<ClassAccessFlags> accessFlags = new HashSet<>();
|
||||||
private final Set<Class<?>> interfaces = new HashSet<>();
|
private final Set<Class<?>> interfaces = new HashSet<>();
|
||||||
private final Set<BeeField> fields = new HashSet<>();
|
private final Set<BeField> fields = new HashSet<>();
|
||||||
private final Set<BeeConstructor> constructors = new HashSet<>();
|
private final Set<BeConstructor> constructors = new HashSet<>();
|
||||||
private final Set<BeeMethod> methods = new HashSet<>();
|
private final Set<BeMethod> methods = new HashSet<>();
|
||||||
private Version classFileVersion;
|
private Version classFileVersion;
|
||||||
private String name;
|
private String name;
|
||||||
private Class<?> superClass = Object.class;
|
private Class<?> superClass = Object.class;
|
||||||
|
|
@ -33,22 +33,22 @@ public final class BeeSource {
|
||||||
/**
|
/**
|
||||||
* @return all constructors that are provided with the class
|
* @return all constructors that are provided with the class
|
||||||
*/
|
*/
|
||||||
public Set<BeeConstructor> getConstructors() {
|
public Set<BeConstructor> getConstructors() {
|
||||||
return Collections.unmodifiableSet(constructors);
|
return Collections.unmodifiableSet(constructors);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addConstructors(BeeConstructor... constructors) {
|
public void addConstructors(BeConstructor... constructors) {
|
||||||
this.constructors.addAll(Set.of(constructors));
|
this.constructors.addAll(Set.of(constructors));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return all methods that are provided with the class
|
* @return all methods that are provided with the class
|
||||||
*/
|
*/
|
||||||
public Set<BeeMethod> getMethods() {
|
public Set<BeMethod> getMethods() {
|
||||||
return methods;
|
return methods;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addMethods(BeeMethod... methods) {
|
public void addMethods(BeMethod... methods) {
|
||||||
this.methods.addAll(Set.of(methods));
|
this.methods.addAll(Set.of(methods));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -59,6 +59,11 @@ public final class BeeSource {
|
||||||
return Collections.unmodifiableSet(accessFlags);
|
return Collections.unmodifiableSet(accessFlags);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add access flag eg public static etc
|
||||||
|
*
|
||||||
|
* @param classAccessFlags varargs of access flag
|
||||||
|
*/
|
||||||
public void addAccessFlags(ClassAccessFlags... classAccessFlags) {
|
public void addAccessFlags(ClassAccessFlags... classAccessFlags) {
|
||||||
this.accessFlags.addAll(Set.of(classAccessFlags));
|
this.accessFlags.addAll(Set.of(classAccessFlags));
|
||||||
}
|
}
|
||||||
|
|
@ -81,6 +86,10 @@ public final class BeeSource {
|
||||||
return superClass;
|
return superClass;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the super class. Default superclass is Object
|
||||||
|
* @param superClass The class to extend from.
|
||||||
|
*/
|
||||||
public void setSuperClass(Class<?> superClass) {
|
public void setSuperClass(Class<?> superClass) {
|
||||||
this.superClass = superClass;
|
this.superClass = superClass;
|
||||||
}
|
}
|
||||||
|
|
@ -92,6 +101,10 @@ public final class BeeSource {
|
||||||
return Collections.unmodifiableSet(interfaces);
|
return Collections.unmodifiableSet(interfaces);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adds an interface to implement
|
||||||
|
* @param interfaces varargs array of interface class
|
||||||
|
*/
|
||||||
public void addInterfaces(Class<?>... interfaces) {
|
public void addInterfaces(Class<?>... interfaces) {
|
||||||
this.interfaces.addAll(Set.of(interfaces));
|
this.interfaces.addAll(Set.of(interfaces));
|
||||||
}
|
}
|
||||||
|
|
@ -99,15 +112,15 @@ public final class BeeSource {
|
||||||
/**
|
/**
|
||||||
* @return a list of unique fields that the class will contain
|
* @return a list of unique fields that the class will contain
|
||||||
*/
|
*/
|
||||||
public Set<BeeField> getFields() {
|
public Set<BeField> getFields() {
|
||||||
return Collections.unmodifiableSet(fields);
|
return Collections.unmodifiableSet(fields);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addFields(BeeField... fields) {
|
public void addFields(BeField... fields) {
|
||||||
this.fields.addAll(Set.of(fields));
|
this.fields.addAll(Set.of(fields));
|
||||||
}
|
}
|
||||||
|
|
||||||
public BeeField getField(String fieldName) {
|
public BeField getField(String fieldName) {
|
||||||
return fields.stream()
|
return fields.stream()
|
||||||
.filter(f -> f.getName().equals(fieldName))
|
.filter(f -> f.getName().equals(fieldName))
|
||||||
.findAny()
|
.findAny()
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
package nl.sander.beejava.api;
|
package nl.sander.bejava.api;
|
||||||
|
|
||||||
public class ClassInstruction extends Instruction {
|
public class ClassInstruction extends Instruction {
|
||||||
private final ClassOperation classOperation;
|
private final ClassOperation classOperation;
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
package nl.sander.beejava.api;
|
package nl.sander.bejava.api;
|
||||||
|
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
|
||||||
|
|
@ -1,8 +1,8 @@
|
||||||
package nl.sander.beejava.api;
|
package nl.sander.bejava.api;
|
||||||
|
|
||||||
import nl.sander.beejava.JavaInstruction;
|
import nl.sander.bejava.JavaInstruction;
|
||||||
import nl.sander.beejava.TypeMapper;
|
import nl.sander.bejava.TypeMapper;
|
||||||
import nl.sander.beejava.flags.MethodAccessFlag;
|
import nl.sander.bejava.flags.MethodAccessFlag;
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
@ -13,10 +13,10 @@ import java.util.stream.Collectors;
|
||||||
public abstract class CodeContainer {
|
public abstract class CodeContainer {
|
||||||
|
|
||||||
protected final List<CodeLine> code = new LinkedList<>();
|
protected final List<CodeLine> code = new LinkedList<>();
|
||||||
protected final Set<BeeParameter> formalParameters = new HashSet<>();
|
protected final Set<BeParameter> formalParameters = new HashSet<>();
|
||||||
protected final Set<MethodAccessFlag> accessFlags = new HashSet<>();
|
protected final Set<MethodAccessFlag> accessFlags = new HashSet<>();
|
||||||
private final List<JavaInstruction> expandedCode = new ArrayList<>();
|
private final List<JavaInstruction> expandedCode = new ArrayList<>();
|
||||||
private BeeSource owner;
|
private BeSource owner;
|
||||||
|
|
||||||
public List<CodeLine> getCode() {
|
public List<CodeLine> getCode() {
|
||||||
return code;
|
return code;
|
||||||
|
|
@ -32,7 +32,7 @@ public abstract class CodeContainer {
|
||||||
|
|
||||||
private String getParametersSignature() {
|
private String getParametersSignature() {
|
||||||
return formalParameters.stream()
|
return formalParameters.stream()
|
||||||
.map(BeeParameter::getType)
|
.map(BeParameter::getType)
|
||||||
.map(TypeMapper::map)
|
.map(TypeMapper::map)
|
||||||
.collect(Collectors.joining(",", "(", ")"));
|
.collect(Collectors.joining(",", "(", ")"));
|
||||||
}
|
}
|
||||||
|
|
@ -41,15 +41,15 @@ public abstract class CodeContainer {
|
||||||
return accessFlags;
|
return accessFlags;
|
||||||
}
|
}
|
||||||
|
|
||||||
public BeeSource getOwner() {
|
public BeSource getOwner() {
|
||||||
return owner;
|
return owner;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setOwner(BeeSource beeSource) {
|
public void setOwner(BeSource beSource) {
|
||||||
if (owner != null) {
|
if (owner != null) {
|
||||||
throw new IllegalStateException("Owner set twice. Sue the developer!");
|
throw new IllegalStateException("Owner set twice. Sue the developer!");
|
||||||
}
|
}
|
||||||
this.owner = beeSource;
|
this.owner = beSource;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<JavaInstruction> getExpandedCode() {
|
public List<JavaInstruction> getExpandedCode() {
|
||||||
|
|
@ -61,13 +61,11 @@ public abstract class CodeContainer {
|
||||||
expandedCode.addAll(instructions);
|
expandedCode.addAll(instructions);
|
||||||
}
|
}
|
||||||
|
|
||||||
public abstract boolean isConstructor();
|
public Set<BeParameter> getFormalParameters() {
|
||||||
|
|
||||||
public Set<BeeParameter> getFormalParameters() {
|
|
||||||
return formalParameters;
|
return formalParameters;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Optional<BeeParameter> getParameter(String parameterName) {
|
public Optional<BeParameter> getParameter(String parameterName) {
|
||||||
return formalParameters.stream().filter(p -> parameterName.equals(p.getName())).findAny();
|
return formalParameters.stream().filter(p -> parameterName.equals(p.getName())).findAny();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
package nl.sander.beejava.api;
|
package nl.sander.bejava.api;
|
||||||
|
|
||||||
|
|
||||||
public class CodeLine extends Instruction {
|
public class CodeLine extends Instruction {
|
||||||
|
|
@ -17,12 +17,4 @@ public class CodeLine extends Instruction {
|
||||||
public Opcode getOpcode() {
|
public Opcode getOpcode() {
|
||||||
return opcode;
|
return opcode;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setOwner(CodeContainer owner) {
|
|
||||||
this.owner = owner;
|
|
||||||
}
|
|
||||||
|
|
||||||
public CodeContainer getOwner() {
|
|
||||||
return owner;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
package nl.sander.beejava.api;
|
package nl.sander.bejava.api;
|
||||||
|
|
||||||
public class Instruction {
|
public class Instruction {
|
||||||
protected final String operand;
|
protected final String operand;
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
package nl.sander.beejava.api;
|
package nl.sander.bejava.api;
|
||||||
|
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
|
||||||
|
|
@ -1,6 +1,4 @@
|
||||||
package nl.sander.beejava.api;
|
package nl.sander.bejava.api;
|
||||||
|
|
||||||
import nl.sander.beejava.api.Opcode;
|
|
||||||
|
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
|
||||||
|
|
@ -1,13 +1,17 @@
|
||||||
package nl.sander.beejava.classinfo;
|
package nl.sander.bejava.classinfo;
|
||||||
|
|
||||||
import nl.sander.beejava.constantpool.entry.Utf8Entry;
|
import nl.sander.bejava.constantpool.entry.Utf8Entry;
|
||||||
import nl.sander.beejava.flags.AccessFlags;
|
import nl.sander.bejava.flags.AccessFlags;
|
||||||
import nl.sander.beejava.flags.FieldAccessFlag;
|
import nl.sander.bejava.flags.FieldAccessFlag;
|
||||||
import nl.sander.beejava.util.ByteBuf;
|
import nl.sander.bejava.util.ByteBuf;
|
||||||
|
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Conforms to field_info struct in JVM specification
|
||||||
|
* See 4.1 The ClassFile Structure
|
||||||
|
*/
|
||||||
public class FieldInfo extends Info<FieldInfo> {
|
public class FieldInfo extends Info<FieldInfo> {
|
||||||
private final Set<FieldAccessFlag> accessFlags = new HashSet<>();
|
private final Set<FieldAccessFlag> accessFlags = new HashSet<>();
|
||||||
|
|
||||||
|
|
@ -20,10 +24,6 @@ public class FieldInfo extends Info<FieldInfo> {
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Set<FieldAccessFlag> getAccessFlags() {
|
|
||||||
return accessFlags;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void addBytes(ByteBuf buf) {
|
public void addBytes(ByteBuf buf) {
|
||||||
buf.addU16(AccessFlags.combine(accessFlags));
|
buf.addU16(AccessFlags.combine(accessFlags));
|
||||||
buf.addU16(nameEntry.getIndex());
|
buf.addU16(nameEntry.getIndex());
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
package nl.sander.beejava.classinfo;
|
package nl.sander.bejava.classinfo;
|
||||||
|
|
||||||
import nl.sander.beejava.classinfo.attributes.Attribute;
|
import nl.sander.bejava.classinfo.attributes.Attribute;
|
||||||
import nl.sander.beejava.constantpool.entry.Utf8Entry;
|
import nl.sander.bejava.constantpool.entry.Utf8Entry;
|
||||||
|
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
@ -17,14 +17,6 @@ public abstract class Info<T extends Info<T>> {
|
||||||
this.descriptorEntry = descriptorEntry;
|
this.descriptorEntry = descriptorEntry;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Utf8Entry getNameEntry() {
|
|
||||||
return nameEntry;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Utf8Entry getDescriptorEntry() {
|
|
||||||
return descriptorEntry;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Set<Attribute> getAttributes() {
|
public Set<Attribute> getAttributes() {
|
||||||
return attributes;
|
return attributes;
|
||||||
}
|
}
|
||||||
|
|
@ -1,13 +1,17 @@
|
||||||
package nl.sander.beejava.classinfo;
|
package nl.sander.bejava.classinfo;
|
||||||
|
|
||||||
import nl.sander.beejava.constantpool.entry.Utf8Entry;
|
import nl.sander.bejava.constantpool.entry.Utf8Entry;
|
||||||
import nl.sander.beejava.flags.AccessFlags;
|
import nl.sander.bejava.flags.AccessFlags;
|
||||||
import nl.sander.beejava.flags.MethodAccessFlag;
|
import nl.sander.bejava.flags.MethodAccessFlag;
|
||||||
import nl.sander.beejava.util.ByteBuf;
|
import nl.sander.bejava.util.ByteBuf;
|
||||||
|
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Conforms to method_info struct in JVM specification
|
||||||
|
* See 4.1 The ClassFile Structure
|
||||||
|
*/
|
||||||
public class MethodInfo extends Info<MethodInfo> {
|
public class MethodInfo extends Info<MethodInfo> {
|
||||||
private final Set<MethodAccessFlag> accessFlags = new HashSet<>();
|
private final Set<MethodAccessFlag> accessFlags = new HashSet<>();
|
||||||
|
|
||||||
|
|
@ -1,8 +1,12 @@
|
||||||
package nl.sander.beejava.classinfo.attributes;
|
package nl.sander.bejava.classinfo.attributes;
|
||||||
|
|
||||||
import nl.sander.beejava.constantpool.entry.Utf8Entry;
|
import nl.sander.bejava.constantpool.entry.Utf8Entry;
|
||||||
import nl.sander.beejava.util.ByteBuf;
|
import nl.sander.bejava.util.ByteBuf;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* attribute_info struct as in the JVM spec.
|
||||||
|
* See 4.1 The ClassFile Structure.
|
||||||
|
*/
|
||||||
public abstract class Attribute {
|
public abstract class Attribute {
|
||||||
protected final Utf8Entry nameEntry;
|
protected final Utf8Entry nameEntry;
|
||||||
protected int length;
|
protected int length;
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
package nl.sander.beejava.classinfo.attributes;
|
package nl.sander.bejava.classinfo.attributes;
|
||||||
|
|
||||||
import nl.sander.beejava.constantpool.entry.Utf8Entry;
|
import nl.sander.bejava.constantpool.entry.Utf8Entry;
|
||||||
import nl.sander.beejava.util.ByteBuf;
|
import nl.sander.bejava.util.ByteBuf;
|
||||||
|
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
@ -19,7 +19,7 @@ public class CodeAttribute extends Attribute {
|
||||||
private static final int EXCEPTION_HANDLER_SIZE = 8; // nr of bytes per exception_hander
|
private static final int EXCEPTION_HANDLER_SIZE = 8; // nr of bytes per exception_hander
|
||||||
|
|
||||||
private final Set<Attribute> attributes = new HashSet<>();
|
private final Set<Attribute> attributes = new HashSet<>();
|
||||||
private final Set<ExceptionHandler> exceptionHandlers = new HashSet<>();
|
private final Set<ExceptionHandler> exceptionHandlers = new HashSet<>(); //TODO exception handlers are yet to be implemented
|
||||||
private int maxStack; // u2
|
private int maxStack; // u2
|
||||||
private int maxLocals; // u2
|
private int maxLocals; // u2
|
||||||
private byte[] code;
|
private byte[] code;
|
||||||
|
|
@ -1,7 +1,8 @@
|
||||||
package nl.sander.beejava.classinfo.attributes;
|
package nl.sander.bejava.classinfo.attributes;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* see §4.7.3 The code attribute
|
* see §4.7.3 The code attribute
|
||||||
|
* TODO implement exception handlers
|
||||||
*/
|
*/
|
||||||
public class ExceptionHandler {
|
public class ExceptionHandler {
|
||||||
private int startPc; //u2
|
private int startPc; //u2
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
package nl.sander.beejava.constantpool;
|
package nl.sander.bejava.constantpool;
|
||||||
|
|
||||||
import nl.sander.beejava.constantpool.entry.ConstantPoolEntry;
|
import nl.sander.bejava.constantpool.entry.ConstantPoolEntry;
|
||||||
import nl.sander.beejava.util.ByteBuf;
|
import nl.sander.bejava.util.ByteBuf;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
package nl.sander.beejava.constantpool.entry;
|
package nl.sander.bejava.constantpool.entry;
|
||||||
|
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
|
||||||
|
|
@ -29,7 +29,7 @@ public class ClassEntry extends ConstantPoolEntry {
|
||||||
public boolean equals(Object o) {
|
public boolean equals(Object o) {
|
||||||
if (this == o) return true;
|
if (this == o) return true;
|
||||||
if (o == null || getClass() != o.getClass()) return false;
|
if (o == null || getClass() != o.getClass()) return false;
|
||||||
ClassEntry that = (ClassEntry) o;
|
var that = (ClassEntry) o;
|
||||||
return name.equals(that.name);
|
return name.equals(that.name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
package nl.sander.beejava.constantpool.entry;
|
package nl.sander.bejava.constantpool.entry;
|
||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.LinkedHashSet;
|
import java.util.LinkedHashSet;
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
package nl.sander.beejava.constantpool.entry;
|
package nl.sander.bejava.constantpool.entry;
|
||||||
|
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
|
||||||
|
|
@ -22,7 +22,7 @@ public class DoubleEntry extends LeafEntry {
|
||||||
public boolean equals(Object o) {
|
public boolean equals(Object o) {
|
||||||
if (this == o) return true;
|
if (this == o) return true;
|
||||||
if (o == null || getClass() != o.getClass()) return false;
|
if (o == null || getClass() != o.getClass()) return false;
|
||||||
DoubleEntry that = (DoubleEntry) o;
|
var that = (DoubleEntry) o;
|
||||||
return Double.compare(that.doubleVal, doubleVal) == 0;
|
return Double.compare(that.doubleVal, doubleVal) == 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1,6 +1,4 @@
|
||||||
package nl.sander.beejava.constantpool.entry;
|
package nl.sander.bejava.constantpool.entry;
|
||||||
|
|
||||||
import java.util.Objects;
|
|
||||||
|
|
||||||
public class DynamicEntry extends ConstantPoolEntry {
|
public class DynamicEntry extends ConstantPoolEntry {
|
||||||
private static final byte TAG = 17;
|
private static final byte TAG = 17;
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
package nl.sander.beejava.constantpool.entry;
|
package nl.sander.bejava.constantpool.entry;
|
||||||
|
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
|
||||||
|
|
@ -38,7 +38,7 @@ public class FieldRefEntry extends ConstantPoolEntry {
|
||||||
public boolean equals(Object o) {
|
public boolean equals(Object o) {
|
||||||
if (this == o) return true;
|
if (this == o) return true;
|
||||||
if (o == null || getClass() != o.getClass()) return false;
|
if (o == null || getClass() != o.getClass()) return false;
|
||||||
FieldRefEntry that = (FieldRefEntry) o;
|
var that = (FieldRefEntry) o;
|
||||||
return classEntry.equals(that.classEntry) &&
|
return classEntry.equals(that.classEntry) &&
|
||||||
nameAndTypeEntry.equals(that.nameAndTypeEntry);
|
nameAndTypeEntry.equals(that.nameAndTypeEntry);
|
||||||
}
|
}
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
package nl.sander.beejava.constantpool.entry;
|
package nl.sander.bejava.constantpool.entry;
|
||||||
|
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
|
||||||
|
|
@ -24,7 +24,7 @@ public class FloatEntry extends LeafEntry {
|
||||||
public boolean equals(Object o) {
|
public boolean equals(Object o) {
|
||||||
if (this == o) return true;
|
if (this == o) return true;
|
||||||
if (o == null || getClass() != o.getClass()) return false;
|
if (o == null || getClass() != o.getClass()) return false;
|
||||||
FloatEntry that = (FloatEntry) o;
|
var that = (FloatEntry) o;
|
||||||
return Float.compare(that.floatVal, floatVal) == 0;
|
return Float.compare(that.floatVal, floatVal) == 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
package nl.sander.beejava.constantpool.entry;
|
package nl.sander.bejava.constantpool.entry;
|
||||||
|
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
|
||||||
|
|
@ -29,7 +29,7 @@ public class IntegerEntry extends LeafEntry {
|
||||||
public boolean equals(Object o) {
|
public boolean equals(Object o) {
|
||||||
if (this == o) return true;
|
if (this == o) return true;
|
||||||
if (o == null || getClass() != o.getClass()) return false;
|
if (o == null || getClass() != o.getClass()) return false;
|
||||||
IntegerEntry that = (IntegerEntry) o;
|
var that = (IntegerEntry) o;
|
||||||
return intVal == that.intVal;
|
return intVal == that.intVal;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
package nl.sander.beejava.constantpool.entry;
|
package nl.sander.bejava.constantpool.entry;
|
||||||
|
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
|
||||||
|
|
@ -32,7 +32,7 @@ public class InterfaceMethodRefEntry extends ConstantPoolEntry {
|
||||||
public boolean equals(Object o) {
|
public boolean equals(Object o) {
|
||||||
if (this == o) return true;
|
if (this == o) return true;
|
||||||
if (o == null || getClass() != o.getClass()) return false;
|
if (o == null || getClass() != o.getClass()) return false;
|
||||||
InterfaceMethodRefEntry that = (InterfaceMethodRefEntry) o;
|
var that = (InterfaceMethodRefEntry) o;
|
||||||
return classEntry.equals(that.classEntry) &&
|
return classEntry.equals(that.classEntry) &&
|
||||||
nameAndTypeEntry.equals(that.nameAndTypeEntry);
|
nameAndTypeEntry.equals(that.nameAndTypeEntry);
|
||||||
}
|
}
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
package nl.sander.beejava.constantpool.entry;
|
package nl.sander.bejava.constantpool.entry;
|
||||||
|
|
||||||
public class InvokeDynamicEntry extends ConstantPoolEntry {
|
public class InvokeDynamicEntry extends ConstantPoolEntry {
|
||||||
private static final byte TAG = 18;
|
private static final byte TAG = 18;
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
package nl.sander.beejava.constantpool.entry;
|
package nl.sander.bejava.constantpool.entry;
|
||||||
|
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
package nl.sander.beejava.constantpool.entry;
|
package nl.sander.bejava.constantpool.entry;
|
||||||
|
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
|
||||||
|
|
@ -27,7 +27,7 @@ public class LongEntry extends LeafEntry {
|
||||||
public boolean equals(Object o) {
|
public boolean equals(Object o) {
|
||||||
if (this == o) return true;
|
if (this == o) return true;
|
||||||
if (o == null || getClass() != o.getClass()) return false;
|
if (o == null || getClass() != o.getClass()) return false;
|
||||||
LongEntry longEntry = (LongEntry) o;
|
var longEntry = (LongEntry) o;
|
||||||
return longVal == longEntry.longVal;
|
return longVal == longEntry.longVal;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
package nl.sander.beejava.constantpool.entry;
|
package nl.sander.bejava.constantpool.entry;
|
||||||
|
|
||||||
//TODO implement later
|
//TODO implement later
|
||||||
public class MethodHandleEntry extends ConstantPoolEntry {
|
public class MethodHandleEntry extends ConstantPoolEntry {
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
package nl.sander.beejava.constantpool.entry;
|
package nl.sander.bejava.constantpool.entry;
|
||||||
|
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
|
||||||
|
|
@ -35,7 +35,7 @@ public class MethodRefEntry extends ConstantPoolEntry {
|
||||||
public boolean equals(Object o) {
|
public boolean equals(Object o) {
|
||||||
if (this == o) return true;
|
if (this == o) return true;
|
||||||
if (o == null || getClass() != o.getClass()) return false;
|
if (o == null || getClass() != o.getClass()) return false;
|
||||||
MethodRefEntry that = (MethodRefEntry) o;
|
var that = (MethodRefEntry) o;
|
||||||
return classRef.equals(that.classRef) &&
|
return classRef.equals(that.classRef) &&
|
||||||
nameAndType.equals(that.nameAndType);
|
nameAndType.equals(that.nameAndType);
|
||||||
}
|
}
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
package nl.sander.beejava.constantpool.entry;
|
package nl.sander.bejava.constantpool.entry;
|
||||||
|
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
|
||||||
|
|
@ -24,7 +24,7 @@ public class MethodTypeEntry extends ConstantPoolEntry {
|
||||||
public boolean equals(Object o) {
|
public boolean equals(Object o) {
|
||||||
if (this == o) return true;
|
if (this == o) return true;
|
||||||
if (o == null || getClass() != o.getClass()) return false;
|
if (o == null || getClass() != o.getClass()) return false;
|
||||||
MethodTypeEntry that = (MethodTypeEntry) o;
|
var that = (MethodTypeEntry) o;
|
||||||
return methodDescriptor.equals(that.methodDescriptor);
|
return methodDescriptor.equals(that.methodDescriptor);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
package nl.sander.beejava.constantpool.entry;
|
package nl.sander.bejava.constantpool.entry;
|
||||||
|
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
|
||||||
|
|
@ -25,7 +25,7 @@ public class ModuleEntry extends ConstantPoolEntry {
|
||||||
public boolean equals(Object o) {
|
public boolean equals(Object o) {
|
||||||
if (this == o) return true;
|
if (this == o) return true;
|
||||||
if (o == null || getClass() != o.getClass()) return false;
|
if (o == null || getClass() != o.getClass()) return false;
|
||||||
ModuleEntry that = (ModuleEntry) o;
|
var that = (ModuleEntry) o;
|
||||||
return nameEntry.equals(that.nameEntry);
|
return nameEntry.equals(that.nameEntry);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
package nl.sander.beejava.constantpool.entry;
|
package nl.sander.bejava.constantpool.entry;
|
||||||
|
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
|
||||||
|
|
@ -37,7 +37,7 @@ public final class NameAndTypeEntry extends ConstantPoolEntry {
|
||||||
public boolean equals(Object o) {
|
public boolean equals(Object o) {
|
||||||
if (this == o) return true;
|
if (this == o) return true;
|
||||||
if (o == null || getClass() != o.getClass()) return false;
|
if (o == null || getClass() != o.getClass()) return false;
|
||||||
NameAndTypeEntry that = (NameAndTypeEntry) o;
|
var that = (NameAndTypeEntry) o;
|
||||||
return name.equals(that.name) &&
|
return name.equals(that.name) &&
|
||||||
descriptor.equals(that.descriptor);
|
descriptor.equals(that.descriptor);
|
||||||
}
|
}
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
package nl.sander.beejava.constantpool.entry;
|
package nl.sander.bejava.constantpool.entry;
|
||||||
|
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
|
||||||
|
|
@ -23,7 +23,7 @@ public final class PackageEntry extends ConstantPoolEntry {
|
||||||
public boolean equals(Object o) {
|
public boolean equals(Object o) {
|
||||||
if (this == o) return true;
|
if (this == o) return true;
|
||||||
if (o == null || getClass() != o.getClass()) return false;
|
if (o == null || getClass() != o.getClass()) return false;
|
||||||
PackageEntry that = (PackageEntry) o;
|
var that = (PackageEntry) o;
|
||||||
return nameEntry.equals(that.nameEntry);
|
return nameEntry.equals(that.nameEntry);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
package nl.sander.beejava.constantpool.entry;
|
package nl.sander.bejava.constantpool.entry;
|
||||||
|
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
|
||||||
|
|
@ -23,7 +23,7 @@ public final class StringEntry extends ConstantPoolEntry {
|
||||||
public boolean equals(Object o) {
|
public boolean equals(Object o) {
|
||||||
if (this == o) return true;
|
if (this == o) return true;
|
||||||
if (o == null || getClass() != o.getClass()) return false;
|
if (o == null || getClass() != o.getClass()) return false;
|
||||||
StringEntry that = (StringEntry) o;
|
var that = (StringEntry) o;
|
||||||
return utf8Entry.equals(that.utf8Entry);
|
return utf8Entry.equals(that.utf8Entry);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
package nl.sander.beejava.constantpool.entry;
|
package nl.sander.bejava.constantpool.entry;
|
||||||
|
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
|
@ -16,8 +16,8 @@ public final class Utf8Entry extends LeafEntry {
|
||||||
}
|
}
|
||||||
|
|
||||||
public byte[] getBytes() {
|
public byte[] getBytes() {
|
||||||
byte[] utf8Bytes = value.getBytes(StandardCharsets.UTF_8);
|
var utf8Bytes = value.getBytes(StandardCharsets.UTF_8);
|
||||||
byte[] bytes = new byte[utf8Bytes.length + 3];
|
var bytes = new byte[utf8Bytes.length + 3];
|
||||||
bytes[0] = TAG;
|
bytes[0] = TAG;
|
||||||
bytes[1] = upperByte(utf8Bytes.length);
|
bytes[1] = upperByte(utf8Bytes.length);
|
||||||
bytes[2] = lowerByte(utf8Bytes.length);
|
bytes[2] = lowerByte(utf8Bytes.length);
|
||||||
|
|
@ -29,7 +29,7 @@ public final class Utf8Entry extends LeafEntry {
|
||||||
public boolean equals(Object o) {
|
public boolean equals(Object o) {
|
||||||
if (this == o) return true;
|
if (this == o) return true;
|
||||||
if (o == null || getClass() != o.getClass()) return false;
|
if (o == null || getClass() != o.getClass()) return false;
|
||||||
Utf8Entry utf8Entry = (Utf8Entry) o;
|
var utf8Entry = (Utf8Entry) o;
|
||||||
return value.equals(utf8Entry.value);
|
return value.equals(utf8Entry.value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
package nl.sander.beejava.flags;
|
package nl.sander.bejava.flags;
|
||||||
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
package nl.sander.beejava.flags;
|
package nl.sander.bejava.flags;
|
||||||
|
|
||||||
public enum ClassAccessFlags implements AccessFlags {
|
public enum ClassAccessFlags implements AccessFlags {
|
||||||
PUBLIC(0x0001), // Declared public; may be accessed from outside its package.
|
PUBLIC(0x0001), // Declared public; may be accessed from outside its package.
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
package nl.sander.beejava.flags;
|
package nl.sander.bejava.flags;
|
||||||
|
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
package nl.sander.beejava.flags;
|
package nl.sander.bejava.flags;
|
||||||
|
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
|
||||||
|
|
@ -1,7 +1,10 @@
|
||||||
package nl.sander.beejava.operands;
|
package nl.sander.bejava.operands;
|
||||||
|
|
||||||
import nl.sander.beejava.Primitive;
|
import nl.sander.bejava.Primitive;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The operand is a constant
|
||||||
|
*/
|
||||||
public class ConstantOperand extends Operand {
|
public class ConstantOperand extends Operand {
|
||||||
private final Primitive type;
|
private final Primitive type;
|
||||||
private final String value;
|
private final String value;
|
||||||
|
|
@ -1,5 +1,8 @@
|
||||||
package nl.sander.beejava.operands;
|
package nl.sander.bejava.operands;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The operand is a field member of the class
|
||||||
|
*/
|
||||||
public class FieldOperand extends Operand{
|
public class FieldOperand extends Operand{
|
||||||
public final String className;
|
public final String className;
|
||||||
public final String fieldName;
|
public final String fieldName;
|
||||||
|
|
@ -1,5 +1,8 @@
|
||||||
package nl.sander.beejava.operands;
|
package nl.sander.bejava.operands;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The operand is a local variable
|
||||||
|
*/
|
||||||
public class LocalVariableOperand extends Operand{
|
public class LocalVariableOperand extends Operand{
|
||||||
public final String name;
|
public final String name;
|
||||||
|
|
||||||
|
|
@ -1,5 +1,8 @@
|
||||||
package nl.sander.beejava.operands;
|
package nl.sander.bejava.operands;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The operand is a method call.
|
||||||
|
*/
|
||||||
public class MethodOperand extends Operand{
|
public class MethodOperand extends Operand{
|
||||||
public final String className;
|
public final String className;
|
||||||
public final String methodName;
|
public final String methodName;
|
||||||
4
src/main/java/nl/sander/bejava/operands/Operand.java
Normal file
4
src/main/java/nl/sander/bejava/operands/Operand.java
Normal file
|
|
@ -0,0 +1,4 @@
|
||||||
|
package nl.sander.bejava.operands;
|
||||||
|
|
||||||
|
public abstract class Operand {
|
||||||
|
}
|
||||||
13
src/main/java/nl/sander/bejava/operands/VoidOperand.java
Normal file
13
src/main/java/nl/sander/bejava/operands/VoidOperand.java
Normal file
|
|
@ -0,0 +1,13 @@
|
||||||
|
package nl.sander.bejava.operands;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The operand is void. An operand is compulsory in a {@link nl.sander.bejava.JavaInstruction}.
|
||||||
|
* Used when the opcode is RETURN and the return type is void.
|
||||||
|
*/
|
||||||
|
public class VoidOperand extends Operand{
|
||||||
|
public final static VoidOperand INSTANCE = new VoidOperand();
|
||||||
|
|
||||||
|
private VoidOperand() {
|
||||||
|
//
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
package nl.sander.beejava.util;
|
package nl.sander.bejava.util;
|
||||||
|
|
||||||
import java.nio.ByteBuffer;
|
import java.nio.ByteBuffer;
|
||||||
import java.nio.charset.*;
|
import java.nio.charset.*;
|
||||||
|
|
@ -29,7 +29,7 @@ public class ByteBuf {
|
||||||
if (data.remaining() < ints.length) {
|
if (data.remaining() < ints.length) {
|
||||||
enlarge(ints.length);
|
enlarge(ints.length);
|
||||||
}
|
}
|
||||||
byte[] bytes = new byte[ints.length];
|
var bytes = new byte[ints.length];
|
||||||
for (int i = 0; i < ints.length; i++) {
|
for (int i = 0; i < ints.length; i++) {
|
||||||
bytes[i] = (byte) (ints[i] & 0xFF);
|
bytes[i] = (byte) (ints[i] & 0xFF);
|
||||||
}
|
}
|
||||||
|
|
@ -45,9 +45,9 @@ public class ByteBuf {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void enlarge(final int size) {
|
private void enlarge(final int size) {
|
||||||
final int length1 = 2 * data.limit();
|
final var length1 = 2 * data.limit();
|
||||||
final int length2 = data.limit() + size;
|
final var length2 = data.limit() + size;
|
||||||
ByteBuffer newData = ByteBuffer.allocate(Math.max(length1, length2));
|
var newData = ByteBuffer.allocate(Math.max(length1, length2));
|
||||||
data.flip();
|
data.flip();
|
||||||
newData.put(data);
|
newData.put(data);
|
||||||
data = newData;
|
data = newData;
|
||||||
|
|
@ -61,25 +61,25 @@ public class ByteBuf {
|
||||||
return arr;
|
return arr;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String toString() {
|
// public String toString() {
|
||||||
return toString(StandardCharsets.UTF_8);
|
// return toString(StandardCharsets.UTF_8);
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
public String toString(Charset charset) {
|
// public String toString(Charset charset) {
|
||||||
data.flip();
|
// data.flip();
|
||||||
|
//
|
||||||
CharsetDecoder decoder = charset.newDecoder(); // decode is not threadsafe, might put it in threadlocal
|
// CharsetDecoder decoder = charset.newDecoder(); // decode is not threadsafe, might put it in threadlocal
|
||||||
// but I don't think this (newDecoder()+config) is expensive
|
// // but I don't think this (newDecoder()+config) is expensive
|
||||||
|
//
|
||||||
decoder.onMalformedInput(CodingErrorAction.REPLACE)
|
// decoder.onMalformedInput(CodingErrorAction.REPLACE)
|
||||||
.onUnmappableCharacter(CodingErrorAction.REPLACE);
|
// .onUnmappableCharacter(CodingErrorAction.REPLACE);
|
||||||
|
//
|
||||||
try {
|
// try {
|
||||||
return decoder.decode(data).toString();
|
// return decoder.decode(data).toString();
|
||||||
} catch (CharacterCodingException e) {
|
// } catch (CharacterCodingException e) {
|
||||||
throw new RuntimeException(e);
|
// throw new RuntimeException(e);
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
@ -1,29 +0,0 @@
|
||||||
package nl.sander.beejava;
|
|
||||||
|
|
||||||
import org.junit.jupiter.api.Test;
|
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.FileOutputStream;
|
|
||||||
import java.io.IOException;
|
|
||||||
|
|
||||||
public class BytecodeGeneratorTests {
|
|
||||||
@Test
|
|
||||||
public void testEmpty() throws IOException, ClassNotFoundException {
|
|
||||||
byte[] bytecode = BytecodeGenerator.generate(Compiler.compile(TestData.createEmptyClass()));
|
|
||||||
File dir = new File("target/nl/sander/beejava/test");
|
|
||||||
dir.mkdirs();
|
|
||||||
try (FileOutputStream outputStream = new FileOutputStream(new File(dir, "EmptyBean.class"))) {
|
|
||||||
outputStream.write(bytecode);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testInterface() throws ClassNotFoundException {
|
|
||||||
BytecodeGenerator.generate(Compiler.compile(TestData.emptyClassWithInterface()));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testFields() throws ClassNotFoundException {
|
|
||||||
BytecodeGenerator.generate(Compiler.compile(TestData.createClassWithField(Integer.class)));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,77 +0,0 @@
|
||||||
package nl.sander.beejava;
|
|
||||||
|
|
||||||
import nl.sander.beejava.api.BeeSource;
|
|
||||||
import nl.sander.beejava.constantpool.ConstantPool;
|
|
||||||
import nl.sander.beejava.constantpool.entry.ClassEntry;
|
|
||||||
import nl.sander.beejava.constantpool.entry.ConstantPoolEntry;
|
|
||||||
import org.junit.jupiter.api.Test;
|
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.FileOutputStream;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.stream.Collectors;
|
|
||||||
|
|
||||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
|
||||||
|
|
||||||
public class ConstantPoolUniquenessTests {
|
|
||||||
@Test
|
|
||||||
public void test() throws Exception {
|
|
||||||
// Arrange
|
|
||||||
BeeSource someClass = TestData.createEmptyClass();
|
|
||||||
|
|
||||||
// Act
|
|
||||||
CompiledClass compiledClass = Compiler.compile(someClass);
|
|
||||||
ConstantPool constantPool = new ConstantPoolCreator().createConstantPool(compiledClass.getConstantTree());
|
|
||||||
|
|
||||||
// Assert
|
|
||||||
List<ClassEntry> refsToSystem = constantPool.stream()
|
|
||||||
.filter(cpe -> cpe instanceof ClassEntry)
|
|
||||||
.map(cpe -> (ClassEntry) cpe)
|
|
||||||
.filter(ce -> ce.getName().equals("java/lang/System"))
|
|
||||||
.collect(Collectors.toList());
|
|
||||||
|
|
||||||
assertEquals(0, refsToSystem.size());
|
|
||||||
|
|
||||||
|
|
||||||
byte[] bytecode = BytecodeGenerator.generate(compiledClass);
|
|
||||||
|
|
||||||
int x = 1;
|
|
||||||
for (ConstantPoolEntry e : constantPool) {
|
|
||||||
System.out.println((x++) + ":" + e);
|
|
||||||
}
|
|
||||||
|
|
||||||
x = 1;
|
|
||||||
for (ConstantPoolEntry e : constantPool) {
|
|
||||||
System.out.print((x++) + ":");
|
|
||||||
printBytes(e.getBytes());
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
File dir = new File("target/nl/sander/beejava/test");
|
|
||||||
dir.mkdirs();
|
|
||||||
try (FileOutputStream outputStream = new FileOutputStream(new File(dir, "EmptyBean.class"))) {
|
|
||||||
outputStream.write(bytecode);
|
|
||||||
}
|
|
||||||
printBytes2(bytecode);
|
|
||||||
}
|
|
||||||
|
|
||||||
//TODO remove
|
|
||||||
private void printBytes(byte[] bytes) {
|
|
||||||
for (byte b : bytes) {
|
|
||||||
System.out.print(String.format("%2s", Integer.toHexString(b & 0xFF)).replace(' ', '0') + " ");
|
|
||||||
}
|
|
||||||
System.out.println();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void printBytes2(byte[] bytes) {
|
|
||||||
int count = 0;
|
|
||||||
for (byte b : bytes) {
|
|
||||||
System.out.print(String.format("%2s", Integer.toHexString(b & 0xFF)).replace(' ', '0') + (count % 2 == 0 ? "" : " "));
|
|
||||||
count += 1;
|
|
||||||
if (count > 15) {
|
|
||||||
count = 0;
|
|
||||||
System.out.println();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,38 +0,0 @@
|
||||||
package nl.sander.beejava;
|
|
||||||
|
|
||||||
import nl.sander.beejava.api.BeeField;
|
|
||||||
import nl.sander.beejava.api.BeeMethod;
|
|
||||||
import nl.sander.beejava.api.BeeParameter;
|
|
||||||
import nl.sander.beejava.api.BeeSource;
|
|
||||||
import nl.sander.beejava.flags.AccessFlags;
|
|
||||||
import nl.sander.beejava.flags.ClassAccessFlags;
|
|
||||||
import nl.sander.beejava.flags.FieldAccessFlag;
|
|
||||||
import nl.sander.beejava.flags.MethodAccessFlag;
|
|
||||||
import org.junit.jupiter.api.Test;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
|
||||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
|
||||||
|
|
||||||
public class SourceCompilerTest {
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void test() {
|
|
||||||
BeeSource beeSource = new SourceCompiler(TestData2.simpleBean).doCompile();
|
|
||||||
assertEquals("com.acme.SimpleBean", beeSource.getName());
|
|
||||||
assertEquals(ClassAccessFlags.SUPER.getBytecode() | ClassAccessFlags.PUBLIC.getBytecode(), AccessFlags.combine(beeSource.getAccessFlags()));
|
|
||||||
assertTrue(beeSource.getFields().contains(new BeeField(beeSource.getName(), Set.of(FieldAccessFlag.PRIVATE), int.class, "value")));
|
|
||||||
assertEquals(1, beeSource.getConstructors().size());
|
|
||||||
Set<BeeMethod> methods = beeSource.getMethods();
|
|
||||||
assertEquals(2, methods.size());
|
|
||||||
assertTrue(methods.contains(new BeeMethod(beeSource, "getValue", Set.of(MethodAccessFlag.PUBLIC), Set.of(), int.class, List.of())));
|
|
||||||
assertTrue(methods.contains(new BeeMethod(beeSource, "setValue", Set.of(MethodAccessFlag.PUBLIC), Set.of(new BeeParameter(int.class, "newValue")), Void.TYPE, List.of())));
|
|
||||||
|
|
||||||
OpcodeTranslator.translate(beeSource);
|
|
||||||
|
|
||||||
Compiler.compile(beeSource);
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,38 +0,0 @@
|
||||||
package nl.sander.beejava;
|
|
||||||
|
|
||||||
import nl.sander.beejava.api.BeeSource;
|
|
||||||
|
|
||||||
public class TestData {
|
|
||||||
public static BeeSource createEmptyClass() {
|
|
||||||
return SourceCompiler.compile("""
|
|
||||||
class public nl.sander.beejava.test.EmptyBean
|
|
||||||
constructor public()
|
|
||||||
INVOKE this.super()
|
|
||||||
RETURN
|
|
||||||
""");
|
|
||||||
}
|
|
||||||
|
|
||||||
public static BeeSource emptyClassWithInterface() {
|
|
||||||
return SourceCompiler.compile("""
|
|
||||||
class public nl.sander.beejava.test.EmptyBean implements java.io.Serializable
|
|
||||||
constructor public()
|
|
||||||
INVOKE this.super()V
|
|
||||||
RETURN
|
|
||||||
""");
|
|
||||||
}
|
|
||||||
|
|
||||||
public static BeeSource createClassWithField(Class<?> fieldType) {
|
|
||||||
String template = """
|
|
||||||
class com.acme.SimpleBean(V15)
|
|
||||||
field private %s field
|
|
||||||
constructor public(%s arg)
|
|
||||||
INVOKE this.super()V
|
|
||||||
LOAD arg
|
|
||||||
PUT this.field
|
|
||||||
RETURN
|
|
||||||
""";
|
|
||||||
|
|
||||||
return SourceCompiler.compile(String.format(template, fieldType.getName(), fieldType.getName()));
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
@ -1,106 +0,0 @@
|
||||||
package nl.sander.beejava;
|
|
||||||
|
|
||||||
public class TestData2 {
|
|
||||||
|
|
||||||
public final static String simpleBean= """
|
|
||||||
class public com.acme.SimpleBean(V15)
|
|
||||||
field private int value
|
|
||||||
constructor public()
|
|
||||||
INVOKE this.super()
|
|
||||||
RETURN
|
|
||||||
method public getValue() -> int
|
|
||||||
RETURN this.value
|
|
||||||
method public setValue(int newValue)
|
|
||||||
LOAD newValue
|
|
||||||
PUT this.value
|
|
||||||
RETURN
|
|
||||||
""";
|
|
||||||
|
|
||||||
String constructor_original = """
|
|
||||||
0: aload_0
|
|
||||||
1: invokespecial #1 // Method java/lang/Object."<init>":()V
|
|
||||||
|
|
||||||
4: aload_0
|
|
||||||
5: new #7 // class nl/sander/beejava/ConstantPoolCreator
|
|
||||||
8: dup
|
|
||||||
9: invokespecial #9 // Method nl/sander/beejava/ConstantPoolCreator."<init>":()V
|
|
||||||
12: putfield #10 // Field constantPoolCreator:Lnl/sander/beejava/ConstantPoolCreator;
|
|
||||||
|
|
||||||
15: aload_0
|
|
||||||
16: aload_1
|
|
||||||
17: putfield #16 // Field compiledClass:Lnl/sander/beejava/CompiledClass;
|
|
||||||
20: aload_0
|
|
||||||
21: new #20 // class nl/sander/beejava/ConstantPoolEntryCreator
|
|
||||||
24: dup
|
|
||||||
25: aload_1
|
|
||||||
26: invokespecial #22 // Method nl/sander/beejava/ConstantPoolEntryCreator."<init>":(Lnl/sander/beejava/CompiledClass;)V
|
|
||||||
29: putfield #25 // Field constantPoolEntryCreator:Lnl/sander/beejava/ConstantPoolEntryCreator;
|
|
||||||
32: return
|
|
||||||
""";
|
|
||||||
|
|
||||||
String constructor_opcope = """
|
|
||||||
constructor nl.sander.beejava.Compiler(nl.sander.beejava.CompiledClass arg_0);
|
|
||||||
INVOKE this.super()
|
|
||||||
|
|
||||||
NEW nl.sander.beejava.ConstantPoolCreator()
|
|
||||||
PUT this.constantPoolCreator
|
|
||||||
|
|
||||||
LOAD arg_0
|
|
||||||
PUT this.compiledClass
|
|
||||||
NEW nl.sander.beejava.ConstantPoolEntryCreator(compiledClass)
|
|
||||||
PUT this.constantPoolEntryCreator
|
|
||||||
""";
|
|
||||||
|
|
||||||
String method_original = """
|
|
||||||
public void addMethods()
|
|
||||||
0: aload_0
|
|
||||||
1: getfield #16 // Field compiledClass:Lnl/sander/beejava/CompiledClass;
|
|
||||||
4: aload_0
|
|
||||||
5: getfield #97 // Field codeAttributeNameEntry:Lnl/sander/beejava/constantpool/entry/Utf8Entry;
|
|
||||||
8: invokevirtual #101 // Method nl/sander/beejava/CompiledClass.addConstantPoolEntry:(Lnl/sander/beejava/constantpool/entry/ConstantPoolEntry;)V
|
|
||||||
11: aload_0
|
|
||||||
12: getfield #16 // Field compiledClass:Lnl/sander/beejava/CompiledClass;
|
|
||||||
15: invokevirtual #59 // Method nl/sander/beejava/CompiledClass.getSource:()Lnl/sander/beejava/api/BeeSource;
|
|
||||||
18: invokevirtual #79 // Method nl/sander/beejava/api/BeeSource.getMethods:()Ljava/util/Set;
|
|
||||||
21: invokeinterface #135, 1 // InterfaceMethod java/util/Set.iterator:()Ljava/util/Iterator;
|
|
||||||
26: astore_1
|
|
||||||
27: aload_1
|
|
||||||
28: invokeinterface #139, 1 // InterfaceMethod java/util/Iterator.hasNext:()Z
|
|
||||||
33: ifeq 61
|
|
||||||
36: aload_1
|
|
||||||
37: invokeinterface #145, 1 // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
|
|
||||||
42: checkcast #149 // class nl/sander/beejava/api/BeeMethod
|
|
||||||
45: astore_2
|
|
||||||
46: aload_0
|
|
||||||
47: getfield #16 // Field compiledClass:Lnl/sander/beejava/CompiledClass;
|
|
||||||
50: aload_0
|
|
||||||
51: aload_2
|
|
||||||
52: invokevirtual #151 // Method createMethod:(Lnl/sander/beejava/CodeContainer;)Lnl/sander/beejava/classinfo/MethodInfo;
|
|
||||||
55: invokevirtual #155 // Method nl/sander/beejava/CompiledClass.addMethod:(Lnl/sander/beejava/classinfo/MethodInfo;)V
|
|
||||||
58: goto 27
|
|
||||||
61: return
|
|
||||||
""";
|
|
||||||
|
|
||||||
String method_opcode = """
|
|
||||||
public void addMethods()
|
|
||||||
INVOKE this.compiledClass.addConstantPoolEntry(this.codeAttributeNameEntry)
|
|
||||||
|
|
||||||
INVOKE this.compiledClass.getSource()
|
|
||||||
INVOKE getMethods()
|
|
||||||
INVOKE iterator()
|
|
||||||
STORE it
|
|
||||||
|
|
||||||
:start-loop
|
|
||||||
INVOKE it.hasNext
|
|
||||||
IFEQ_false end
|
|
||||||
INVOKE it.next()
|
|
||||||
CAST nl.sander.beejava.api.BeeMethod
|
|
||||||
STORE el
|
|
||||||
INVOKE this.createMethod(el)
|
|
||||||
INVOKE this.compiledClass.addMethod()
|
|
||||||
GOTO start-loop
|
|
||||||
:end
|
|
||||||
RETURN
|
|
||||||
""";
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
@ -1,5 +0,0 @@
|
||||||
package nl.sander.beejava.testclasses;
|
|
||||||
|
|
||||||
public class EmptyBean {
|
|
||||||
|
|
||||||
}
|
|
||||||
80
src/test/java/nl/sander/bejava/BytecodeGeneratorTests.java
Normal file
80
src/test/java/nl/sander/bejava/BytecodeGeneratorTests.java
Normal file
|
|
@ -0,0 +1,80 @@
|
||||||
|
package nl.sander.bejava;
|
||||||
|
|
||||||
|
import nl.sander.bejava.testutils.ByteWriter;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* meant as regression tests
|
||||||
|
*/
|
||||||
|
public class BytecodeGeneratorTests {
|
||||||
|
@Test
|
||||||
|
public void testSuperConstructorCall() {
|
||||||
|
byte[] bytecode = BytecodeGenerator.generate(Compiler.compile(SourceCompiler.compile("""
|
||||||
|
class public nl.sander.beejava.test.EmptyBean
|
||||||
|
constructor public()
|
||||||
|
INVOKE this.super()
|
||||||
|
RETURN
|
||||||
|
""")));
|
||||||
|
assertEquals("""
|
||||||
|
cafe babe 0000 0034 0008 0100 063c 696e\s
|
||||||
|
6974 3e01 0003 2829 5607 0004 0100 206e\s
|
||||||
|
6c2f 7361 6e64 6572 2f62 6565 6a61 7661\s
|
||||||
|
2f74 6573 742f 456d 7074 7942 6561 6e07\s
|
||||||
|
0006 0100 106a 6176 612f 6c61 6e67 2f4f\s
|
||||||
|
626a 6563 7401 0004 436f 6465 0021 0003\s
|
||||||
|
0005 0000 0000 0001 0001 0001 0002 0001\s
|
||||||
|
0007 0000 000c 0000 0001 0000 0000 0000\s
|
||||||
|
0000 0000\s""",
|
||||||
|
ByteWriter.printBytes(bytecode));
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testInterfaceImplementor() {
|
||||||
|
byte[] bytecode = BytecodeGenerator.generate(Compiler.compile(SourceCompiler.compile("""
|
||||||
|
class public nl.sander.beejava.test.EmptyBean implements java.io.Serializable
|
||||||
|
constructor public()
|
||||||
|
INVOKE this.super()V
|
||||||
|
RETURN
|
||||||
|
""")));
|
||||||
|
assertEquals("""
|
||||||
|
cafe babe 0000 0034 0008 0100 063c 696e\s
|
||||||
|
6974 3e01 0003 2829 5607 0004 0100 0670\s
|
||||||
|
7562 6c69 6307 0006 0100 106a 6176 612f\s
|
||||||
|
6c61 6e67 2f4f 626a 6563 7401 0004 436f\s
|
||||||
|
6465 0020 0003 0005 0000 0000 0001 0001\s
|
||||||
|
0001 0002 0001 0007 0000 000c 0000 0001\s
|
||||||
|
0000 0000 0000 0000 0000\s""",
|
||||||
|
ByteWriter.printBytes(bytecode));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testPutArgumentInField() {
|
||||||
|
byte[] bytecode = BytecodeGenerator.generate(Compiler.compile(SourceCompiler.compile("""
|
||||||
|
class com.acme.SimpleBean(V15)
|
||||||
|
field private int field
|
||||||
|
constructor public(int arg)
|
||||||
|
INVOKE this.super()V
|
||||||
|
LOAD arg
|
||||||
|
PUT this.field
|
||||||
|
RETURN
|
||||||
|
""")));
|
||||||
|
assertEquals("""
|
||||||
|
cafe babe 0000 003b 000e 0900 0900 0307\s
|
||||||
|
000a 0c00 0500 0601 0013 636f 6d2f 6163\s
|
||||||
|
6d65 2f53 696d 706c 6542 6561 6e01 0005\s
|
||||||
|
6669 656c 6401 0001 4901 0006 3c69 6e69\s
|
||||||
|
743e 0100 0428 4929 5607 000a 0100 1363\s
|
||||||
|
6f6d 2f61 636d 652f 5369 6d70 6c65 4265\s
|
||||||
|
616e 0700 0c01 0010 6a61 7661 2f6c 616e\s
|
||||||
|
672f 4f62 6a65 6374 0100 0443 6f64 6500\s
|
||||||
|
2000 0900 0b00 0000 0100 0200 0500 0000\s
|
||||||
|
0000 0100 0100 0700 0800 0100 0d00 0000\s
|
||||||
|
0c00 0000 0200 0000 0000 0000 0000 00""",
|
||||||
|
ByteWriter.printBytes(bytecode));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,37 @@
|
||||||
|
package nl.sander.bejava;
|
||||||
|
|
||||||
|
import nl.sander.bejava.api.BeSource;
|
||||||
|
import nl.sander.bejava.constantpool.ConstantPool;
|
||||||
|
import nl.sander.bejava.constantpool.entry.ClassEntry;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
|
|
||||||
|
public class ConstantPoolUniquenessTests {
|
||||||
|
@Test
|
||||||
|
public void test() throws Exception {
|
||||||
|
// Arrange
|
||||||
|
BeSource someClass = SourceCompiler.compile("""
|
||||||
|
class public nl.sander.beejava.test.EmptyBean
|
||||||
|
constructor public()
|
||||||
|
INVOKE this.super()
|
||||||
|
RETURN
|
||||||
|
""");
|
||||||
|
|
||||||
|
// Act
|
||||||
|
CompiledClass compiledClass = Compiler.compile(someClass);
|
||||||
|
ConstantPool constantPool = new ConstantPoolCreator().createConstantPool(compiledClass.getConstantTree());
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
List<ClassEntry> refsToSystem = constantPool.stream()
|
||||||
|
.filter(cpe -> cpe instanceof ClassEntry)
|
||||||
|
.map(cpe -> (ClassEntry) cpe)
|
||||||
|
.filter(ce -> ce.getName().equals("java/lang/System"))
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
|
||||||
|
assertEquals(0, refsToSystem.size());
|
||||||
|
}
|
||||||
|
}
|
||||||
50
src/test/java/nl/sander/bejava/SourceCompilerTest.java
Normal file
50
src/test/java/nl/sander/bejava/SourceCompilerTest.java
Normal file
|
|
@ -0,0 +1,50 @@
|
||||||
|
package nl.sander.bejava;
|
||||||
|
|
||||||
|
import nl.sander.bejava.api.BeField;
|
||||||
|
import nl.sander.bejava.api.BeMethod;
|
||||||
|
import nl.sander.bejava.api.BeParameter;
|
||||||
|
import nl.sander.bejava.api.BeSource;
|
||||||
|
import nl.sander.bejava.flags.AccessFlags;
|
||||||
|
import nl.sander.bejava.flags.ClassAccessFlags;
|
||||||
|
import nl.sander.bejava.flags.FieldAccessFlag;
|
||||||
|
import nl.sander.bejava.flags.MethodAccessFlag;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Compilation from sourcefile to BeeSource is the first pass in the total compilation.
|
||||||
|
* A BeeSource object can also be created programmatically.
|
||||||
|
*/
|
||||||
|
public class SourceCompilerTest {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testCompileSourceFileToSourceObject() {
|
||||||
|
BeSource beSource = new SourceCompiler("""
|
||||||
|
class public com.acme.SimpleBean(V15)
|
||||||
|
field private int value
|
||||||
|
constructor public()
|
||||||
|
INVOKE this.super()
|
||||||
|
RETURN
|
||||||
|
method public getValue() -> int
|
||||||
|
RETURN this.value
|
||||||
|
method public setValue(int newValue)
|
||||||
|
LOAD newValue
|
||||||
|
PUT this.value
|
||||||
|
RETURN
|
||||||
|
""").doCompile();
|
||||||
|
|
||||||
|
assertEquals("com.acme.SimpleBean", beSource.getName());
|
||||||
|
assertEquals(ClassAccessFlags.SUPER.getBytecode() | ClassAccessFlags.PUBLIC.getBytecode(), AccessFlags.combine(beSource.getAccessFlags()));
|
||||||
|
assertTrue(beSource.getFields().contains(new BeField(beSource.getName(), Set.of(FieldAccessFlag.PRIVATE), int.class, "value")));
|
||||||
|
assertEquals(1, beSource.getConstructors().size());
|
||||||
|
Set<BeMethod> methods = beSource.getMethods();
|
||||||
|
assertEquals(2, methods.size());
|
||||||
|
assertTrue(methods.contains(new BeMethod(beSource, "getValue", Set.of(MethodAccessFlag.PUBLIC), Set.of(), int.class, List.of())));
|
||||||
|
assertTrue(methods.contains(new BeMethod(beSource, "setValue", Set.of(MethodAccessFlag.PUBLIC), Set.of(new BeParameter(int.class, "newValue")), Void.TYPE, List.of())));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -1,8 +1,8 @@
|
||||||
package nl.sander.beejava;
|
package nl.sander.bejava;
|
||||||
|
|
||||||
import nl.sander.beejava.api.BeeSource;
|
import nl.sander.bejava.api.BeSource;
|
||||||
import nl.sander.beejava.constantpool.ConstantPool;
|
import nl.sander.bejava.constantpool.ConstantPool;
|
||||||
import nl.sander.beejava.constantpool.entry.NameAndTypeEntry;
|
import nl.sander.bejava.constantpool.entry.NameAndTypeEntry;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
|
|
@ -13,10 +13,10 @@ public class TypeMapperTest {
|
||||||
@Test
|
@Test
|
||||||
public void test_int() {
|
public void test_int() {
|
||||||
// Arrange
|
// Arrange
|
||||||
BeeSource beeSource = TestData.createClassWithField(int.class);
|
BeSource beSource = createClassWithField(int.class);
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
ConstantPool constantPool = createConstantPool(beeSource);
|
ConstantPool constantPool = createConstantPool(beSource);
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
NameAndTypeEntry fieldEntry = getFieldNameAndType(constantPool);
|
NameAndTypeEntry fieldEntry = getFieldNameAndType(constantPool);
|
||||||
|
|
@ -26,10 +26,10 @@ public class TypeMapperTest {
|
||||||
@Test
|
@Test
|
||||||
public void test_double() {
|
public void test_double() {
|
||||||
// Arrange
|
// Arrange
|
||||||
BeeSource beeSource = TestData.createClassWithField(double.class);
|
BeSource beSource = createClassWithField(double.class);
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
ConstantPool constantPool = createConstantPool(beeSource);
|
ConstantPool constantPool = createConstantPool(beSource);
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
NameAndTypeEntry fieldEntry = getFieldNameAndType(constantPool);
|
NameAndTypeEntry fieldEntry = getFieldNameAndType(constantPool);
|
||||||
|
|
@ -39,10 +39,10 @@ public class TypeMapperTest {
|
||||||
@Test
|
@Test
|
||||||
public void test_float() {
|
public void test_float() {
|
||||||
// Arrange
|
// Arrange
|
||||||
BeeSource beeSource = TestData.createClassWithField(float.class);
|
BeSource beSource = createClassWithField(float.class);
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
ConstantPool constantPool = createConstantPool(beeSource);
|
ConstantPool constantPool = createConstantPool(beSource);
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
NameAndTypeEntry fieldEntry = getFieldNameAndType(constantPool);
|
NameAndTypeEntry fieldEntry = getFieldNameAndType(constantPool);
|
||||||
|
|
@ -52,10 +52,10 @@ public class TypeMapperTest {
|
||||||
@Test
|
@Test
|
||||||
public void test_byte() {
|
public void test_byte() {
|
||||||
// Arrange
|
// Arrange
|
||||||
BeeSource beeSource = TestData.createClassWithField(byte.class);
|
BeSource beSource = createClassWithField(byte.class);
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
ConstantPool constantPool = createConstantPool(beeSource);
|
ConstantPool constantPool = createConstantPool(beSource);
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
NameAndTypeEntry fieldEntry = getFieldNameAndType(constantPool);
|
NameAndTypeEntry fieldEntry = getFieldNameAndType(constantPool);
|
||||||
|
|
@ -65,10 +65,10 @@ public class TypeMapperTest {
|
||||||
@Test
|
@Test
|
||||||
public void test_short() {
|
public void test_short() {
|
||||||
// Arrange
|
// Arrange
|
||||||
BeeSource beeSource = TestData.createClassWithField(short.class);
|
BeSource beSource = createClassWithField(short.class);
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
ConstantPool constantPool = createConstantPool(beeSource);
|
ConstantPool constantPool = createConstantPool(beSource);
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
NameAndTypeEntry fieldEntry = getFieldNameAndType(constantPool);
|
NameAndTypeEntry fieldEntry = getFieldNameAndType(constantPool);
|
||||||
|
|
@ -78,10 +78,10 @@ public class TypeMapperTest {
|
||||||
@Test
|
@Test
|
||||||
public void test_long() {
|
public void test_long() {
|
||||||
// Arrange
|
// Arrange
|
||||||
BeeSource beeSource = TestData.createClassWithField(long.class);
|
BeSource beSource = createClassWithField(long.class);
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
ConstantPool constantPool = createConstantPool(beeSource);
|
ConstantPool constantPool = createConstantPool(beSource);
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
NameAndTypeEntry fieldEntry = getFieldNameAndType(constantPool);
|
NameAndTypeEntry fieldEntry = getFieldNameAndType(constantPool);
|
||||||
|
|
@ -91,10 +91,10 @@ public class TypeMapperTest {
|
||||||
@Test
|
@Test
|
||||||
public void test_char() {
|
public void test_char() {
|
||||||
// Arrange
|
// Arrange
|
||||||
BeeSource beeSource = TestData.createClassWithField(char.class);
|
BeSource beSource = createClassWithField(char.class);
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
ConstantPool constantPool = createConstantPool(beeSource);
|
ConstantPool constantPool = createConstantPool(beSource);
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
NameAndTypeEntry fieldEntry = getFieldNameAndType(constantPool);
|
NameAndTypeEntry fieldEntry = getFieldNameAndType(constantPool);
|
||||||
|
|
@ -104,10 +104,10 @@ public class TypeMapperTest {
|
||||||
@Test
|
@Test
|
||||||
public void test_boolean() {
|
public void test_boolean() {
|
||||||
// Arrange
|
// Arrange
|
||||||
BeeSource beeSource = TestData.createClassWithField(boolean.class);
|
BeSource beSource = createClassWithField(boolean.class);
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
ConstantPool constantPool = createConstantPool(beeSource);
|
ConstantPool constantPool = createConstantPool(beSource);
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
NameAndTypeEntry fieldEntry = getFieldNameAndType(constantPool);
|
NameAndTypeEntry fieldEntry = getFieldNameAndType(constantPool);
|
||||||
|
|
@ -117,10 +117,10 @@ public class TypeMapperTest {
|
||||||
@Test
|
@Test
|
||||||
public void test_Object() {
|
public void test_Object() {
|
||||||
// Arrange
|
// Arrange
|
||||||
BeeSource beeSource = TestData.createClassWithField(Object.class);
|
BeSource beSource = createClassWithField(Object.class);
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
ConstantPool constantPool = createConstantPool(beeSource);
|
ConstantPool constantPool = createConstantPool(beSource);
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
NameAndTypeEntry fieldEntry = getFieldNameAndType(constantPool);
|
NameAndTypeEntry fieldEntry = getFieldNameAndType(constantPool);
|
||||||
|
|
@ -130,10 +130,10 @@ public class TypeMapperTest {
|
||||||
@Test
|
@Test
|
||||||
public void test_int_array() {
|
public void test_int_array() {
|
||||||
// Arrange
|
// Arrange
|
||||||
BeeSource beeSource = TestData.createClassWithField(int[].class);
|
BeSource beSource = createClassWithField(int[].class);
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
ConstantPool constantPool = createConstantPool(beeSource);
|
ConstantPool constantPool = createConstantPool(beSource);
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
NameAndTypeEntry fieldEntry = getFieldNameAndType(constantPool);
|
NameAndTypeEntry fieldEntry = getFieldNameAndType(constantPool);
|
||||||
|
|
@ -143,18 +143,18 @@ public class TypeMapperTest {
|
||||||
@Test
|
@Test
|
||||||
public void test_Object_array() {
|
public void test_Object_array() {
|
||||||
// Arrange
|
// Arrange
|
||||||
BeeSource beeSource = TestData.createClassWithField(String[].class);
|
BeSource beSource = createClassWithField(String[].class);
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
ConstantPool constantPool = createConstantPool(beeSource);
|
ConstantPool constantPool = createConstantPool(beSource);
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
NameAndTypeEntry fieldEntry = getFieldNameAndType(constantPool);
|
NameAndTypeEntry fieldEntry = getFieldNameAndType(constantPool);
|
||||||
assertEquals("[Ljava/lang/String;", fieldEntry.getType());
|
assertEquals("[Ljava/lang/String;", fieldEntry.getType());
|
||||||
}
|
}
|
||||||
|
|
||||||
private ConstantPool createConstantPool(BeeSource beeSource) {
|
private ConstantPool createConstantPool(BeSource beSource) {
|
||||||
CompiledClass compiledClass = Compiler.compile(beeSource);
|
CompiledClass compiledClass = Compiler.compile(beSource);
|
||||||
return ConstantPoolCreator.create(compiledClass.getConstantTree());
|
return ConstantPoolCreator.create(compiledClass.getConstantTree());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -165,4 +165,18 @@ public class TypeMapperTest {
|
||||||
.filter(nate -> nate.getName().equals("field"))
|
.filter(nate -> nate.getName().equals("field"))
|
||||||
.findAny().orElseGet(() -> fail("'field' not found"));
|
.findAny().orElseGet(() -> fail("'field' not found"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private BeSource createClassWithField(Class<?> fieldType) {
|
||||||
|
String template = """
|
||||||
|
class com.acme.SimpleBean(V15)
|
||||||
|
field private %s field
|
||||||
|
constructor public(%s arg)
|
||||||
|
INVOKE this.super()V
|
||||||
|
LOAD arg
|
||||||
|
PUT this.field
|
||||||
|
RETURN
|
||||||
|
""";
|
||||||
|
|
||||||
|
return SourceCompiler.compile(String.format(template, fieldType.getName(), fieldType.getName()));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
package nl.sander.beejava.constantpool.entry;
|
package nl.sander.bejava.constantpool.entry;
|
||||||
|
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
package nl.sander.beejava.constantpool.entry;
|
package nl.sander.bejava.constantpool.entry;
|
||||||
|
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
package nl.sander.beejava.constantpool.entry;
|
package nl.sander.bejava.constantpool.entry;
|
||||||
|
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
package nl.sander.beejava.constantpool.entry;
|
package nl.sander.bejava.constantpool.entry;
|
||||||
|
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
package nl.sander.beejava.constantpool.entry;
|
package nl.sander.bejava.constantpool.entry;
|
||||||
|
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
package nl.sander.beejava.constantpool.entry;
|
package nl.sander.bejava.constantpool.entry;
|
||||||
|
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
package nl.sander.beejava.constantpool.entry;
|
package nl.sander.bejava.constantpool.entry;
|
||||||
|
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
|
|
@ -1,12 +1,13 @@
|
||||||
package nl.sander.beejava.e2e;
|
package nl.sander.bejava.e2e;
|
||||||
|
|
||||||
import nl.sander.beejava.Compiler;
|
import nl.sander.bejava.Compiler;
|
||||||
import nl.sander.beejava.*;
|
import nl.sander.bejava.*;
|
||||||
import nl.sander.beejava.api.BeeSource;
|
import nl.sander.bejava.api.BeSource;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
import java.lang.reflect.Modifier;
|
import java.lang.reflect.Modifier;
|
||||||
|
import java.util.*;
|
||||||
|
|
||||||
import static org.junit.jupiter.api.Assertions.*;
|
import static org.junit.jupiter.api.Assertions.*;
|
||||||
|
|
||||||
|
|
@ -18,7 +19,7 @@ public class BeanWithMethodsTest {
|
||||||
@Test
|
@Test
|
||||||
public void testEmptyBean() throws Exception {
|
public void testEmptyBean() throws Exception {
|
||||||
// Arrange
|
// Arrange
|
||||||
BeeSource printer = SourceCompiler.compile("""
|
BeSource printer = SourceCompiler.compile("""
|
||||||
class nl.sander.beejava.test.ClassWithReferences
|
class nl.sander.beejava.test.ClassWithReferences
|
||||||
constructor public()
|
constructor public()
|
||||||
INVOKE this.super()V
|
INVOKE this.super()V
|
||||||
|
|
@ -48,15 +49,16 @@ public class BeanWithMethodsTest {
|
||||||
Class<?> classWithReferences = classLoader.loadClass(className);
|
Class<?> classWithReferences = classLoader.loadClass(className);
|
||||||
assertNotNull(classWithReferences);
|
assertNotNull(classWithReferences);
|
||||||
|
|
||||||
Method[] methods = classWithReferences.getDeclaredMethods();
|
List<Method> methods = Arrays.asList(classWithReferences.getDeclaredMethods());
|
||||||
assertEquals(2, methods.length);
|
methods.sort(Comparator.comparing(Method::getName));
|
||||||
assertEquals("print1", methods[0].getName());
|
assertEquals(2, methods.size());
|
||||||
assertTrue(Modifier.isPublic(methods[0].getModifiers()));
|
assertEquals("print1", methods.get(0).getName());
|
||||||
assertEquals(0, methods[0].getParameterCount());
|
assertTrue(Modifier.isPublic(methods.get(0).getModifiers()));
|
||||||
|
assertEquals(0, methods.get(0).getParameterCount());
|
||||||
|
|
||||||
assertEquals("print2", methods[1].getName()); // ordering may cause failures
|
assertEquals("print2", methods.get(1).getName()); // ordering may cause failures
|
||||||
assertTrue(Modifier.isPublic(methods[1].getModifiers()));
|
assertTrue(Modifier.isPublic(methods.get(1).getModifiers()));
|
||||||
assertEquals(0, methods[1].getParameterCount());
|
assertEquals(0, methods.get(1).getParameterCount());
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
package nl.sander.beejava.e2e;
|
package nl.sander.bejava.e2e;
|
||||||
|
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
package nl.sander.beejava.e2e;
|
package nl.sander.bejava.e2e;
|
||||||
|
|
||||||
import nl.sander.beejava.OverallCompiler;
|
import nl.sander.bejava.OverallCompiler;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import java.lang.reflect.Constructor;
|
import java.lang.reflect.Constructor;
|
||||||
|
|
@ -15,7 +15,7 @@ public class EmptyBeanTest {
|
||||||
public void testEmptyBean() throws Exception {
|
public void testEmptyBean() throws Exception {
|
||||||
// Act
|
// Act
|
||||||
byte[] bytecode = OverallCompiler.compile("""
|
byte[] bytecode = OverallCompiler.compile("""
|
||||||
class public nl.sander.beejava.test.EmptyBean
|
class public nl.sander.bejava.test.EmptyBean
|
||||||
constructor public()
|
constructor public()
|
||||||
INVOKE this.super()V
|
INVOKE this.super()V
|
||||||
RETURN
|
RETURN
|
||||||
|
|
@ -23,10 +23,10 @@ public class EmptyBeanTest {
|
||||||
|
|
||||||
|
|
||||||
ByteClassLoader classLoader = new ByteClassLoader();
|
ByteClassLoader classLoader = new ByteClassLoader();
|
||||||
classLoader.setByteCode("nl.sander.beejava.test.EmptyBean", bytecode);
|
classLoader.setByteCode("nl.sander.bejava.test.EmptyBean", bytecode);
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
Constructor<?> constructor = classLoader.loadClass("nl.sander.beejava.test.EmptyBean").getConstructor();
|
Constructor<?> constructor = classLoader.loadClass("nl.sander.bejava.test.EmptyBean").getConstructor();
|
||||||
assertNotNull(constructor);
|
assertNotNull(constructor);
|
||||||
|
|
||||||
Object instance = constructor.newInstance();
|
Object instance = constructor.newInstance();
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
package nl.sander.beejava.flags;
|
package nl.sander.bejava.flags;
|
||||||
|
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
package nl.sander.beejava.testclasses;
|
package nl.sander.bejava.testclasses;
|
||||||
|
|
||||||
// two references to System. System should not be in the constant pool twice.
|
// two references to System. System should not be in the constant pool twice.
|
||||||
public class BeanWithClassReferences {
|
public class BeanWithClassReferences {
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
package nl.sander.beejava.testclasses;
|
package nl.sander.bejava.testclasses;
|
||||||
|
|
||||||
public class Dummy {
|
public class Dummy {
|
||||||
public String hello(String goodbye){
|
public String hello(String goodbye){
|
||||||
|
|
@ -0,0 +1,5 @@
|
||||||
|
package nl.sander.bejava.testclasses;
|
||||||
|
|
||||||
|
public class EmptyBean {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
package nl.sander.beejava.testclasses;
|
package nl.sander.bejava.testclasses;
|
||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
package nl.sander.beejava.testclasses;
|
package nl.sander.bejava.testclasses;
|
||||||
|
|
||||||
public class IntBean {
|
public class IntBean {
|
||||||
private int intField;
|
private int intField;
|
||||||
Some files were not shown because too many files have changed in this diff Show more
Loading…
Add table
Reference in a new issue