Commit 26a133c4 authored by Stephanie Gawroriski's avatar Stephanie Gawroriski
Browse files

Checking of method flags.

parent 86565237
......@@ -253,6 +253,15 @@ These codes do not have a index meaning and are meant to be short.
* `IN17` -- If a method is abstract, it cannot have specific flags set.
* The input flags.
* `IN18` -- Native methods are not supported by this virtual machine.
* `IN19` -- Private and default methods are not supported in interfaces due
to CLDC 8 requiring a Java 7 virtual machine.
* The method flags.
* `IN1a` -- Illegal combination of method flags for the current class.
* The method flags.
* The class flags.
* `IN1b` -- Illegal combination of method flags, regardless of the current
class.
* The method flags.
# `net.multiphasicapps.interpreter.local`
......
......@@ -8,6 +8,8 @@
**SquirrelJME** is intended to be a Java ME 8 compatible environment for
strange and many other devices. The source is written in pure Java.
Note that Java ME 8 has a Java 7 virtual machine with specific limitations.
## Licenses
* [GNU Affero General Public License, Version 3 or later](license.mkd)
......@@ -140,6 +142,10 @@ Only two character encodings are supported:
# Programming Considerations
## Do Not Use Default Methods
Default methods in interfaces are not supported.
## Do Not Use Static Modifiable/Mutable Globals In Standalone Classes
The garbage collector upon determining that a class (which may contain static
......
......@@ -132,7 +132,7 @@ public abstract class JVMMember<S extends MemberTypeSymbol,
* @throws NullPointerException On null arguments.
* @since 2016/03/20
*/
public final JVMMember<S, F> setFlags(F __fl)
public JVMMember<S, F> setFlags(F __fl)
throws ClassCastException, NullPointerException
{
// Check
......
......@@ -22,6 +22,12 @@ import net.multiphasicapps.descriptors.MethodSymbol;
public class JVMMethod
extends JVMMember<MethodSymbol, JVMMethodFlags>
{
/** Is this a constructor? */
protected final boolean isconstructor;
/** Is this a class initialization method? */
protected final boolean isclassinit;
/**
* Initializes the interpreted method.
*
......@@ -37,6 +43,78 @@ public class JVMMethod
{
super(__owner, MethodSymbol.class, __name, __type,
JVMMethodFlags.class);
// Is this a constructor?
isconstructor = name.equals("<init>");
isclassinit = name.equals("<clinit>");
}
/**
* Is this method a class initializer?
*
* @return {@code true} if a class initializer.
* @since 2016/03/20
*/
public boolean isClassInitializer()
{
return isclassinit;
}
/**
* Is this method a constructor?
*
* @return {@code true} if a constructor.
* @since 2016/03/20
*/
public boolean isConstructor()
{
return isconstructor;
}
/**
* {@inheritDoc}
* @since 2016/03/20
*/
@Override
public JVMMethod setFlags(JVMMethodFlags __fl)
throws JVMClassFormatError, NullPointerException
{
// Check
if (__fl == null)
throw new NullPointerException("NARG");
// Get class flags
JVMClassFlags cl = inclass.getFlags();
// Class initializer flags are ignored for the most part
if (!isClassInitializer())
{
// If the class is an interface...
if (cl.isInterface())
{
// Default methods are not supported
if (__fl.isPrivate() || !__fl.isAbstract())
throw new JVMClassFormatError(String.format("IN19 %s",
__fl));
// Cannot have these flags
if (__fl.isProtected() || __fl.isFinal() ||
__fl.isSynchronized() || __fl.isNative())
throw new JVMClassFormatError(String.format("IN1a %s %s",
__fl, cl));
}
// If abstract, cannot have these flags
if (__fl.isAbstract())
if (__fl.isPrivate() || __fl.isStatic() || __fl.isFinal() ||
__fl.isSynchronized() || __fl.isNative() ||
__fl.isStrict())
throw new JVMClassFormatError(String.format("IN1b %s",
__fl));
}
// Perform super work
return (JVMMethod)super.setFlags(__fl);
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment