Modified:
/src/org/ductilej/detyper/Detype.java
/src/org/ductilej/detyper/Processor.java
/src/org/ductilej/runtime/RT.java
=======================================
--- /src/org/ductilej/detyper/Detype.java Sat Jul 10 18:49:11 2010
+++ /src/org/ductilej/detyper/Detype.java Mon Jul 19 22:58:56 2010
@@ -51,6 +51,9 @@
/** Whether or not to remove methods from interfaces (TEMP). */
public static boolean KEEPIFCS =
Boolean.getBoolean("org.ductilej.keepifcs");
+ /** Whether or not to use full coercions in place of implicit
widenings. */
+ public static boolean COERCEALL =
Boolean.getBoolean("org.ductilej.coerceall");
+
/**
* Returns the detyping tree translator.
*/
=======================================
--- /src/org/ductilej/detyper/Processor.java Fri Jun 11 10:37:53 2010
+++ /src/org/ductilej/detyper/Processor.java Mon Jul 19 22:58:56 2010
@@ -62,6 +62,7 @@
Debug.DEBUG
= "true".equalsIgnoreCase(procenv.getOptions().get(DEBUG_ARG));
Resolver.WARNINGS
= "true".equalsIgnoreCase(procenv.getOptions().get(WARNINGS_ARG));
Detype.KEEPIFCS
= "true".equalsIgnoreCase(procenv.getOptions().get(KEEPIFCS_ARG));
+ Detype.COERCEALL
= "true".equalsIgnoreCase(procenv.getOptions().get(COERCEALL_ARG));
Debug.log("Detyper running", "vers", procenv.getSourceVersion());
}
@@ -131,4 +132,6 @@
protected static final String WARNINGS_ARG = "org.ductilej.warnings";
// -Aorg.ductilej.keepifcs=true disables removal of interface method
declarations (TEMP)
protected static final String KEEPIFCS_ARG = "org.ductilej.keepifcs";
-}
+ // -Aorg.ductilej.coerceall=true makes primitive narrowing and format
coercions implicit
+ protected static final String COERCEALL_ARG = "org.ductilej.coerceall";
+}
=======================================
--- /src/org/ductilej/runtime/RT.java Sat Jul 10 11:48:44 2010
+++ /src/org/ductilej/runtime/RT.java Mon Jul 19 22:58:56 2010
@@ -37,6 +37,9 @@
/** A suffix appended to signature mangled method names. */
public static final String MM_SUFFIX = "$M";
+ /** Whether or not to use full coercions in place of implicit
widenings. */
+ public static boolean COERCEALL =
Boolean.getBoolean("org.ductilej.coerceall");
+
/**
* Invokes the constructor of the supplied class, with the specified
arguments and returns the
* newly created instance.
@@ -317,6 +320,26 @@
{
return Array.get(array, ((Number)index).intValue());
}
+
+ /**
+ * Performs primitive numeric widening on a value.
+ */
+ public static Object widen (Class<?> clazz, Object value)
+ {
+ if (COERCEALL) {
+ return coerce(clazz, value);
+ }
+ if (value == null) {
+ throw new NullPointerException("Cannot widen null to " +
clazz.getName());
+ }
+ // TODO: differentiate between coercers and wideners
+ Coercer c = COERCERS.get(Tuple.create(value.getClass(), clazz));
+ if (c == null) {
+ throw new IllegalArgumentException(
+ "Cannot widen " + value.getClass().getName() + " to " +
clazz.getName());
+ }
+ return c.coerce(value);
+ }
/**
* Performs primitive numeric coercion on a value.
@@ -961,7 +984,7 @@
// which is probably not desirable in the long term)
int aii = ii-args.length;
if (margs[aii] != null && margs[ii] != null) {
- margs[aii] = coerce(ptypes.get(ii), margs[aii]);
+ margs[aii] = widen(ptypes.get(ii), margs[aii]);
}
}
return margs;