1 // -*- Mode: Java; indent-tabs-mode: t; tab-width: 4 -*-
2 // ---------------------------------------------------------------------------
4 // Copyright (C) Stephanie Gawroriski <xer@multiphasicapps.net>
5 // ---------------------------------------------------------------------------
6 // SquirrelJME is under the GNU General Public License v3+, or later.
7 // See license.mkd for licensing and copyright information.
8 // ---------------------------------------------------------------------------
10 package net
.multiphasicapps
.classfile
;
13 * This represents the class version that a class may be.
17 public enum ClassVersion
19 /** CLDC 1.0 (JSR 30). */
20 CLDC_1((45 << 16) + 3, (47 << 16) - 1, false, false, false),
22 /** CLDC 1.1 (JSR 139). */
23 CLDC_1_1((47 << 16), (51 << 16) - 1, true, false, false),
25 /** CLDC 8 (aka Java 7). */
26 CLDC_8((51 << 16), (52 << 16), true, false, true),
31 /** The minimum supported version. */
32 public static final ClassVersion MIN_VERSION
= ClassVersion
.CLDC_1
;
34 /** The maximum supported version. */
35 public static final ClassVersion MAX_VERSION
= ClassVersion
.CLDC_8
;
37 /** The version ID. */
38 protected final int version
;
40 /** The maximum range of the version. */
41 protected final int maxversion
;
43 /** Has floating point support? */
44 protected final boolean hasfloat
;
46 /** Supports invokedynamic? */
47 protected final boolean hasinvokedynamic
;
49 /** Use StackMapTable? */
50 protected final boolean usestackmaptable
;
53 * Initializes the version data.
55 * @param __vid The version ID.
56 * @param __vmx The max version identifier.
57 * @param __float Is floating point supported?
58 * @param __hasid Has invoke dynamic support?
59 * @param __usesmt Should the StackMapTable attribute be used?
62 ClassVersion(int __vid
, int __vmx
, boolean __float
, boolean __hasid
,
67 this.maxversion
= __vmx
;
68 this.hasfloat
= __float
;
69 this.hasinvokedynamic
= __hasid
;
70 this.usestackmaptable
= __usesmt
;
74 * Returns {@code true} if floating point is supported by the virtual
77 * @return {@code true} if it is.
80 public boolean hasFloatingPoint()
86 * Returns {@code true} if invokedynamic is supported by the virtual
89 * @return {@code true} if it is.
92 public boolean hasInvokeDynamic()
94 return this.hasinvokedynamic
;
98 * Should the new StackMapTable attribute be used when veryifying the byte
101 * @return {@code true} if the "StackMapTable" attribute should be parsed
102 * instead of "StackMap".
105 public boolean useStackMapTable()
107 return this.usestackmaptable
;
111 * Finds the best matching version with the given ID.
113 * @param __vid The version ID to get a match for.
114 * @return The matching class version or {@code null} if not found.
117 public static ClassVersion
findVersion(int __vid
)
119 // Go through all versions, find the best
120 ClassVersion best
= null;
121 for (ClassVersion v
: ClassVersion
.values())
122 if (__vid
>= v
.version
&& __vid
<= v
.maxversion
)
123 if (best
== null || v
.version
> best
.version
)
126 // Use the best (if any)