Do not use pthreads on 3DS.
[SquirrelJME.git] / nanocoat / include / sjme / classy.h
blob841f678caf2f70b32d25600280c912903dbd04ec
1 /* -*- Mode: C; indent-tabs-mode: t; tab-width: 4 -*-
2 // ---------------------------------------------------------------------------
3 // SquirrelJME
4 // Copyright (C) Stephanie Gawroriski <xer@multiphasicapps.net>
5 // ---------------------------------------------------------------------------
6 // SquirrelJME is under the Mozilla Public License Version 2.0.
7 // See license.mkd for licensing and copyright information.
8 // -------------------------------------------------------------------------*/
10 /**
11 * Handling of classes.
13 * @since 2024/01/01
16 #ifndef SQUIRRELJME_CLASSY_H
17 #define SQUIRRELJME_CLASSY_H
19 #include "sjme/nvm.h"
20 #include "sjme/seekable.h"
21 #include "sjme/list.h"
22 #include "sjme/descriptor.h"
24 /* Anti-C++. */
25 #ifdef __cplusplus
26 #ifndef SJME_CXX_IS_EXTERNED
27 #define SJME_CXX_IS_EXTERNED
28 #define SJME_CXX_SQUIRRELJME_CLASSY_H
29 extern "C" {
30 #endif /* #ifdef SJME_CXX_IS_EXTERNED */
31 #endif /* #ifdef __cplusplus */
33 /*--------------------------------------------------------------------------*/
35 /**
36 * Core class information structure.
38 * @since 2024/01/01
40 typedef struct sjme_class_infoCore sjme_class_infoCore;
42 /**
43 * Opaque class information structure.
45 * @since 2024/01/01
47 typedef struct sjme_class_infoCore* sjme_class_info;
49 /**
50 * Core method information structure.
52 * @since 2024/01/03
54 typedef struct sjme_class_methodInfoCore sjme_class_methodInfoCore;
56 /**
57 * Opaque method information structure.
59 * @since 2024/01/03
61 typedef struct sjme_class_methodInfoCore* sjme_class_methodInfo;
63 /**
64 * Method list.
66 * @since 2024/01/03
68 SJME_LIST_DECLARE(sjme_class_methodInfo, 0);
70 /** The basic type of @c sjme_class_methodInfo . */
71 #define SJME_TYPEOF_BASIC_sjme_class_methodInfo \
72 SJME_BASIC_TYPE_ID_OBJECT
74 /**
75 * Core field information structure.
77 * @since 2024/01/03
79 typedef struct sjme_class_fieldInfoCore sjme_class_fieldInfoCore;
81 /**
82 * Opaque field information structure.
84 * @since 2024/01/03
86 typedef struct sjme_class_fieldInfoCore* sjme_class_fieldInfo;
88 /**
89 * Field list.
91 * @since 2024/01/03
93 SJME_LIST_DECLARE(sjme_class_fieldInfo, 0);
95 /** The basic type of @c sjme_class_fieldInfo . */
96 #define SJME_TYPEOF_BASIC_sjme_class_fieldInfo \
97 SJME_BASIC_TYPE_ID_OBJECT
99 /**
100 * Exception handling information.
102 * @since 2024/01/03
104 typedef struct sjme_class_exceptionHandler
106 /** The range of the exception where it applies. */
107 sjme_range range;
109 /** The handler PC address. */
110 sjme_jint handlerPc;
112 /** The type that this catches. */
113 sjme_desc_binaryName handles;
114 } sjme_class_exceptionHandler;
116 /** A list of exceptions. */
117 SJME_LIST_DECLARE(sjme_class_exceptionHandler, 0);
119 /** The basic type of @c sjme_class_exceptionHandler . */
120 #define SJME_TYPEOF_BASIC_sjme_class_exceptionHandler \
121 SJME_BASIC_TYPE_ID_OBJECT
124 * Method code information structure.
126 * @since 2024/01/03
128 typedef struct sjme_class_codeInfoCore sjme_class_codeInfoCore;
131 * Opaque method code structure.
133 * @since 2024/01/03
135 typedef struct sjme_class_codeInfoCore* sjme_class_codeInfo;
138 * Access flags.
140 * @since 2024/01/03
142 typedef struct sjme_class_accessFlags
144 /** Is this public? */
145 sjme_jboolean public : 1;
147 /** Is this private? */
148 sjme_jboolean private : 1;
150 /** Is this protected? */
151 sjme_jboolean protected : 1;
152 } sjme_class_accessFlags;
155 * Class flags.
157 * @since 2024/01/03
159 typedef struct sjme_class_classFlags
161 /** Access flags. */
162 sjme_class_accessFlags access;
164 /** Is the class final? */
165 sjme_jboolean final : 1;
167 /** Is the class super? */
168 sjme_jboolean super : 1;
170 /** Is the class an interface? */
171 sjme_jboolean interface : 1;
173 /** Is the class abstract? */
174 sjme_jboolean abstract : 1;
176 /** Is the class synthetic? */
177 sjme_jboolean synthetic : 1;
179 /** Is the class an annotation? */
180 sjme_jboolean annotation : 1;
182 /** Is the class an enum? */
183 sjme_jboolean enumeration : 1;
184 } sjme_class_classFlags;
187 * Common member flags.
189 * @since 2024/01/03
191 typedef struct sjme_class_memberFlags
193 /** Access flags. */
194 sjme_class_accessFlags access;
196 /** Static member? */
197 sjme_jboolean isStatic : 1;
199 /** Final member? */
200 sjme_jboolean final : 1;
202 /** Synthetic member? */
203 sjme_jboolean synthetic : 1;
204 } sjme_class_memberFlags;
207 * Field flags.
209 * @since 2024/01/03
211 typedef struct sjme_class_fieldFlags
213 /** Common member flags. */
214 sjme_class_memberFlags member;
216 /** Is this volatile? */
217 sjme_jboolean isVolatile : 1;
219 /** Is this transient? */
220 sjme_jboolean transient : 1;
222 /** Is this an enumeration. */
223 sjme_jboolean enumeration : 1;
224 } sjme_class_fieldFlags;
227 * Method flags.
229 * @since 2024/01/03
231 typedef struct sjme_class_methodFlags
233 /** Common member flags. */
234 sjme_class_memberFlags member;
236 /** Synchronized, monitor entry/exit on call? */
237 sjme_jboolean synchronized : 1;
239 /** Bridge method, generated by the compiler? */
240 sjme_jboolean bridge : 1;
242 /** Variadic arguments? */
243 sjme_jboolean varargs : 1;
245 /** Is this a native method? */
246 sjme_jboolean native : 1;
248 /** Abstract? */
249 sjme_jboolean abstract : 1;
251 /** Strict floating point? */
252 sjme_jboolean strictfp : 1;
253 } sjme_class_methodFlags;
256 * The type that a constant pool entry may be.
258 * @since 2024/01/04
260 typedef enum sjme_class_poolType
262 /** Null entry. */
263 SJME_CLASS_POOL_TYPE_NULL = 0,
265 /** Modified UTF. */
266 SJME_CLASS_POOL_TYPE_UTF = 1,
268 /** Unused 2. */
269 SJME_CLASS_POOL_TYPE_UNUSED_2 = 2,
271 /** Integer constant. */
272 SJME_CLASS_POOL_TYPE_INTEGER = 3,
274 /** Float constant. */
275 SJME_CLASS_POOL_TYPE_FLOAT = 4,
277 /** Long constant. */
278 SJME_CLASS_POOL_TYPE_LONG = 5,
280 /** Double constant. */
281 SJME_CLASS_POOL_TYPE_DOUBLE = 6,
283 /** Class constant. */
284 SJME_CLASS_POOL_TYPE_CLASS = 7,
286 /** String constant. */
287 SJME_CLASS_POOL_TYPE_STRING = 8,
289 /** Field reference. */
290 SJME_CLASS_POOL_TYPE_FIELD = 9,
292 /** Method reference. */
293 SJME_CLASS_POOL_TYPE_METHOD = 10,
295 /** Interface method reference. */
296 SJME_CLASS_POOL_TYPE_INTERFACE_METHOD = 11,
298 /** Name and type. */
299 SJME_CLASS_POOL_TYPE_NAME_AND_TYPE = 12,
301 /** Unused 13. */
302 SJME_CLASS_POOL_TYPE_UNUSED_13 = 13,
304 /** Unused 14. */
305 SJME_CLASS_POOL_TYPE_UNUSED_14 = 14,
307 /** Method handle. */
308 SJME_CLASS_POOL_TYPE_METHOD_HANDLE = 15,
310 /** Method type. */
311 SJME_CLASS_POOL_TYPE_METHOD_TYPE = 16,
313 /** Unused 17. */
314 SJME_CLASS_POOL_TYPE_UNUSED_17 = 17,
316 /** Invoke dynamic. */
317 SJME_CLASS_POOL_TYPE_INVOKE_DYNAMIC = 18,
319 /** The number of pool types. */
320 SJME_NUM_CLASS_POOL_TYPE
321 } sjme_class_poolType;
324 * A @c SJME_CLASS_POOL_TYPE_CLASS which represents a class or interface.
326 * @since 2024/01/04
328 typedef struct sjme_class_poolEntryClass
330 /** The descriptor this represents. */
331 sjme_lpcstr descriptor;
332 } sjme_class_poolEntryClass;
335 * A @c SJME_CLASS_POOL_TYPE_DOUBLE which represents a double constant.
337 * @since 2024/01/04
339 typedef struct sjme_class_poolEntryDouble
341 /** The constant value. */
342 sjme_jdouble value;
343 } sjme_class_poolEntryDouble;
346 * A @c SJME_CLASS_POOL_TYPE_NAME_AND_TYPE which represents a name and type
347 * of a member without the class.
349 * @since 2024/01/04
351 typedef struct sjme_class_poolEntryNameAndType sjme_class_poolEntryNameAndType;
354 * The type of entry
356 * @since 2024/01/16
358 typedef enum sjme_class_poolEntryMemberType
360 /** Reference to field member. */
361 SJME_CLASS_POOL_ENTRY_MEMBER_TYPE_FIELD,
363 /** Reference to method member. */
364 SJME_CLASS_POOL_ENTRY_MEMBER_TYPE_METHOD,
366 /** Reference to interface method member. */
367 SJME_CLASS_POOL_ENTRY_MEMBER_TYPE_INTERFACE_METHOD,
369 /** The number of member types. */
370 SJME_NUM_CLASS_POOL_ENTRY_MEMBER_TYPE
371 } sjme_class_poolEntryMemberType;
374 * Either @c SJME_CLASS_POOL_TYPE_FIELD , @c SJME_CLASS_POOL_TYPE_METHOD ,
375 * or @c SJME_CLASS_POOL_TYPE_INTERFACE_METHOD which represents a reference
376 * to a class member.
378 * @since 2024/01/04
380 typedef struct sjme_class_poolEntryMember
382 /** The type of entry this. */
383 sjme_class_poolEntryMemberType type;
385 /** The class this refers to. */
386 sjme_lpcstr inClass;
388 /** The name and type used. */
389 const sjme_class_poolEntryNameAndType* nameAndType;
390 } sjme_class_poolEntryMember;
393 * A @c SJME_CLASS_POOL_TYPE_FLOAT which represents a float constant.
395 * @since 2024/01/04
397 typedef struct sjme_class_poolEntryFloat
399 /** The constant value. */
400 sjme_jfloat value;
401 } sjme_class_poolEntryFloat;
404 * A @c SJME_CLASS_POOL_TYPE_INTEGER which represents an integer constant.
406 * @since 2024/01/04
408 typedef struct sjme_class_poolEntryInteger
410 /** The constant value. */
411 sjme_jint value;
412 } sjme_class_poolEntryInteger;
415 * A @c SJME_CLASS_POOL_TYPE_LONG which represents a long constant.
417 * @since 2024/01/04
419 typedef struct sjme_class_poolEntryLong
421 /** The constant value. */
422 sjme_jlong value;
423 } sjme_class_poolEntryLong;
425 struct sjme_class_poolEntryNameAndType
427 /** The name. */
428 sjme_lpcstr name;
430 /** The type. */
431 sjme_lpcstr type;
435 * A @c SJME_CLASS_POOL_TYPE_UTF which is a modified UTF-8 entry.
437 * @since 2024/01/04
439 typedef struct sjme_class_poolEntryUtf
441 /** The hash code for the entry. */
442 sjme_jint hash;
444 /** The UTF data for this entry. */
445 sjme_lpcstr utf;
446 } sjme_class_poolEntryUtf;
449 * Represents a single constant pool entry.
451 * @since 2024/01/04
453 typedef struct sjme_class_poolEntry
455 /** The type of entry that this is. */
456 sjme_class_poolType type;
458 /** The data for the entry. */
459 union
461 /** Class. */
462 sjme_class_poolEntryClass classRef;
464 /** Double. */
465 sjme_class_poolEntryDouble constDouble;
467 /** Float. */
468 sjme_class_poolEntryFloat constFloat;
470 /** Integer. */
471 sjme_class_poolEntryInteger constInteger;
473 /** Long. */
474 sjme_class_poolEntryLong constLong;
476 /** A class member. */
477 sjme_class_poolEntryMember member;
479 /** Name and type. */
480 sjme_class_poolEntryNameAndType nameAndType;
482 /** UTF pool entry. */
483 sjme_class_poolEntryUtf utf;
484 } data;
485 } sjme_class_poolEntry;
487 /** A list of constant pool entries. */
488 SJME_LIST_DECLARE(sjme_class_poolEntry, 0);
490 struct sjme_class_infoCore
492 /** The constant pool of this class. */
493 const sjme_list_sjme_class_poolEntry* pool;
495 /** The name of this class. */
496 sjme_lpcstr name;
498 /** The superclass of this class. */
499 sjme_lpcstr superName;
501 /** The interfaces this class implements. */
502 const sjme_list_sjme_lpcstr* interfaceNames;
504 /** Fields within the method. */
505 const sjme_list_sjme_class_fieldInfo* fields;
507 /** Methods within the class. */
508 const sjme_list_sjme_class_methodInfo* methods;
512 * Represents a field's constant value.
514 * @since 2024/01/08
516 typedef struct sjme_class_fieldConstVal
518 /** The type of value. */
519 sjme_javaTypeId type;
521 /** The value of the field. */
522 union
524 /** The Java value. */
525 sjme_jvalue java;
527 /** Constant string. */
528 sjme_lpcstr string;
529 } value;
530 } sjme_class_fieldConstVal;
532 struct sjme_class_fieldInfoCore
534 /** The class which contains this field. */
535 sjme_class_info inClass;
537 /** Field flags. */
538 sjme_class_fieldFlags flags;
540 /** The constant value, if any. */
541 sjme_class_fieldConstVal constVal;
544 struct sjme_class_methodInfoCore
546 /** The class which contains this method. */
547 sjme_class_info inClass;
549 /** Method flags. */
550 sjme_class_methodFlags flags;
552 /** The method code, if it is not native. */
553 sjme_class_codeInfo code;
556 struct sjme_class_codeInfoCore
558 /** The method which contains this code. */
559 sjme_class_methodInfo inMethod;
561 /** Maximum number of locals. */
562 sjme_jint maxLocals;
564 /** Maximum number of stack entries. */
565 sjme_jint maxStack;
567 /** Exception table. */
568 const sjme_list_sjme_class_exceptionHandler* exceptions;
570 /** Method byte code. */
571 sjme_list_sjme_jubyte code;
575 * Stack map table representation.
577 * @since 2024/01/09
579 typedef struct sjme_class_stackMap
581 /** Todo. */
582 int todo;
583 } sjme_class_stackMap;
586 * Parses a single class and loads its class information.
588 * @param inPool The pool to allocate within.
589 * @param inStream The stream to parse from when reading the class.
590 * @param outClass The resultant class information
591 * @return Any resultant error code, if any.
592 * @since 2024/01/03
594 sjme_errorCode sjme_class_parse(
595 sjme_attrInNotNull sjme_alloc_pool* inPool,
596 sjme_attrInNotNull sjme_stream_input inStream,
597 sjme_attrOutNotNull sjme_class_info* outClass);
599 sjme_errorCode sjme_class_parseAttributeCode(
600 sjme_attrInNotNull sjme_stream_input inStream,
601 sjme_attrInNotNull sjme_class_methodInfo inMethod,
602 sjme_attrOutNotNull sjme_class_codeInfo* outCode);
604 sjme_errorCode sjme_class_parseAttributeConstVal(
605 sjme_attrInNotNull sjme_stream_input inStream,
606 sjme_attrInNotNull sjme_class_fieldInfo inField,
607 sjme_attrOutNotNull sjme_class_fieldConstVal* outConstVal);
609 sjme_errorCode sjme_class_parseAttributeStackMapOld(
610 sjme_attrInNotNull sjme_stream_input inStream,
611 sjme_attrOutNotNull sjme_class_codeInfo inCode,
612 sjme_attrOutNotNull sjme_class_stackMap* outStackMap);
614 sjme_errorCode sjme_class_parseAttributeStackMapNew(
615 sjme_attrInNotNull sjme_stream_input inStream,
616 sjme_attrOutNotNull sjme_class_codeInfo inCode,
617 sjme_attrOutNotNull sjme_class_stackMap* outStackMap);
619 sjme_errorCode sjme_class_parseConstantPool(
620 sjme_attrInNotNull sjme_stream_input inStream,
621 sjme_attrInNotNull sjme_class_info inClass,
622 sjme_attrOutNotNull sjme_list_sjme_class_poolEntry* outPool);
624 sjme_errorCode sjme_class_parseField(
625 sjme_attrInNotNull sjme_stream_input inStream,
626 sjme_attrOutNotNull sjme_class_fieldInfo* outField);
628 sjme_errorCode sjme_class_parseFields(
629 sjme_attrInNotNull sjme_stream_input inStream,
630 sjme_attrInNotNull sjme_class_info inClass,
631 sjme_attrOutNotNull sjme_list_sjme_class_fieldInfo* outFields);
633 sjme_errorCode sjme_class_parseMethod(
634 sjme_attrInNotNull sjme_stream_input inStream,
635 sjme_attrInOutNotNull sjme_class_methodInfo* outMethod);
637 sjme_errorCode sjme_class_parseMethods(
638 sjme_attrInNotNull sjme_stream_input inStream,
639 sjme_attrInNotNull sjme_class_info inClass,
640 sjme_attrOutNotNull sjme_list_sjme_class_methodInfo* outMethods);
642 /*--------------------------------------------------------------------------*/
644 /* Anti-C++. */
645 #ifdef __cplusplus
646 #ifdef SJME_CXX_SQUIRRELJME_CLASSY_H
648 #undef SJME_CXX_SQUIRRELJME_CLASSY_H
649 #undef SJME_CXX_IS_EXTERNED
650 #endif /* #ifdef SJME_CXX_SQUIRRELJME_CLASSY_H */
651 #endif /* #ifdef __cplusplus */
653 #endif /* SQUIRRELJME_CLASSY_H */