use of org.objectweb.asm.Type in project Lucee by lucee.
the class CastFloat method _writeOut.
/**
* @see lucee.transformer.expression.Expression#_writeOut(org.objectweb.asm.commons.GeneratorAdapter, int)
*/
@Override
public Type _writeOut(BytecodeContext bc, int mode) throws TransformerException {
GeneratorAdapter adapter = bc.getAdapter();
if (expr instanceof OpDouble) {
((OpDouble) expr).writeOutDouble(bc, MODE_VALUE);
if (mode == MODE_VALUE)
adapter.invokeStatic(Types.CASTER, Methods.METHOD_TO_FLOAT_VALUE_FROM_DOUBLE);
else
adapter.invokeStatic(Types.CASTER, Methods.METHOD_TO_FLOAT_FROM_DOUBLE);
} else if (expr instanceof ExprBoolean) {
expr.writeOut(bc, MODE_VALUE);
if (mode == MODE_VALUE)
adapter.invokeStatic(Types.CASTER, Methods.METHOD_TO_FLOAT_VALUE_FROM_BOOLEAN);
else
adapter.invokeStatic(Types.CASTER, Methods.METHOD_TO_FLOAT_FROM_BOOLEAN);
} else if (expr instanceof ExprFloat) {
expr.writeOut(bc, mode);
} else if (expr instanceof ExprDouble) {
expr.writeOut(bc, MODE_VALUE);
if (mode == MODE_VALUE)
adapter.invokeStatic(Types.CASTER, Methods.METHOD_TO_FLOAT_VALUE_FROM_DOUBLE);
else
adapter.invokeStatic(Types.CASTER, Methods.METHOD_TO_FLOAT_FROM_DOUBLE);
} else if (expr instanceof ExprString) {
expr.writeOut(bc, MODE_REF);
if (mode == MODE_VALUE)
adapter.invokeStatic(Types.CASTER, Methods.METHOD_TO_FLOAT_VALUE_FROM_STRING);
else
adapter.invokeStatic(Types.CASTER, Methods.METHOD_TO_FLOAT_FROM_STRING);
} else {
Type rtn = expr.writeOut(bc, mode);
if (mode == MODE_VALUE) {
if (!Types.isPrimitiveType(rtn)) {
adapter.invokeStatic(Types.CASTER, Methods.METHOD_TO_FLOAT_VALUE);
} else if (Types.DOUBLE_VALUE.equals(rtn)) {
adapter.cast(Types.DOUBLE_VALUE, Types.FLOAT_VALUE);
} else if (Types.FLOAT_VALUE.equals(rtn)) {
} else if (Types.BOOLEAN_VALUE.equals(rtn)) {
adapter.invokeStatic(Types.CASTER, Methods.METHOD_TO_FLOAT_VALUE_FROM_BOOLEAN);
} else {
adapter.invokeStatic(Types.CASTER, new Method("toRef", Types.toRefType(rtn), new Type[] { rtn }));
adapter.invokeStatic(Types.CASTER, Methods.METHOD_TO_FLOAT_VALUE);
}
return Types.FLOAT_VALUE;
} else if (Types.isPrimitiveType(rtn)) {
if (Types.DOUBLE_VALUE.equals(rtn)) {
adapter.invokeStatic(Types.CASTER, Methods.METHOD_TO_FLOAT_FROM_DOUBLE);
} else if (Types.FLOAT_VALUE.equals(rtn)) {
adapter.invokeStatic(Types.CASTER, Methods.METHOD_TO_FLOAT_FROM_FLOAT);
} else if (Types.BOOLEAN_VALUE.equals(rtn)) {
adapter.invokeStatic(Types.CASTER, Methods.METHOD_TO_FLOAT_FROM_BOOLEAN);
} else {
adapter.invokeStatic(Types.CASTER, new Method("toRef", Types.toRefType(rtn), new Type[] { rtn }));
adapter.invokeStatic(Types.CASTER, Methods.METHOD_TO_FLOAT);
}
return Types.FLOAT;
}
// else {
if (!Types.FLOAT.equals(rtn))
adapter.invokeStatic(Types.CASTER, Methods.METHOD_TO_FLOAT);
return Types.FLOAT;
// }
}
if (mode == MODE_VALUE)
return Types.FLOAT_VALUE;
return Types.FLOAT;
}
use of org.objectweb.asm.Type in project Lucee by lucee.
the class CastInt method _writeOut.
/**
* @see lucee.transformer.expression.Expression#_writeOut(org.objectweb.asm.commons.GeneratorAdapter, int)
*/
@Override
public Type _writeOut(BytecodeContext bc, int mode) throws TransformerException {
GeneratorAdapter adapter = bc.getAdapter();
if (expr instanceof ExprString) {
expr.writeOut(bc, MODE_REF);
if (mode == MODE_VALUE)
adapter.invokeStatic(Types.CASTER, Methods.METHOD_TO_INT_VALUE_FROM_STRING);
else
adapter.invokeStatic(Types.CASTER, Methods.METHOD_TO_INTEGER_FROM_STRING);
} else {
Type rtn = expr.writeOut(bc, mode);
if (mode == MODE_VALUE) {
if (!Types.isPrimitiveType(rtn)) {
adapter.invokeStatic(Types.CASTER, Methods.METHOD_TO_INT_VALUE);
} else if (Types.BOOLEAN_VALUE.equals(rtn)) {
adapter.invokeStatic(Types.CASTER, Methods.METHOD_TO_INT_VALUE_FROM_BOOLEAN);
} else if (Types.SHORT_VALUE.equals(rtn)) {
// No Cast needed
} else if (Types.FLOAT_VALUE.equals(rtn)) {
adapter.cast(Types.FLOAT_VALUE, Types.INT_VALUE);
} else if (Types.LONG_VALUE.equals(rtn)) {
adapter.cast(Types.LONG_VALUE, Types.INT_VALUE);
} else if (Types.DOUBLE_VALUE.equals(rtn)) {
adapter.cast(Types.DOUBLE_VALUE, Types.INT_VALUE);
} else if (Types.INT_VALUE.equals(rtn)) {
// No Cast needed
} else {
adapter.invokeStatic(Types.CASTER, new Method("toRef", Types.toRefType(rtn), new Type[] { rtn }));
adapter.invokeStatic(Types.CASTER, Methods.METHOD_TO_INT_VALUE);
}
return Types.INT_VALUE;
} else if (Types.isPrimitiveType(rtn)) {
if (Types.DOUBLE_VALUE.equals(rtn)) {
adapter.invokeStatic(Types.CASTER, Methods.METHOD_TO_INTEGER_FROM_DOUBLE);
} else if (Types.BOOLEAN_VALUE.equals(rtn)) {
adapter.invokeStatic(Types.CASTER, Methods.METHOD_TO_INTEGER_FROM_BOOLEAN);
} else {
adapter.invokeStatic(Types.CASTER, new Method("toRef", Types.toRefType(rtn), new Type[] { rtn }));
adapter.invokeStatic(Types.CASTER, Methods.METHOD_TO_INTEGER);
}
return Types.INTEGER;
}
if (!Types.INTEGER.equals(rtn))
adapter.invokeStatic(Types.CASTER, Methods.METHOD_TO_INTEGER);
return Types.INTEGER;
}
if (mode == MODE_VALUE)
return Types.INT_VALUE;
return Types.INTEGER;
}
use of org.objectweb.asm.Type in project Lucee by lucee.
the class CastOther method _writeOut.
// Excel toExcel (Object)
/*final public static Method TO_EXCEL = new Method("toExcel",
Types.EXCEL,
new Type[]{Types.OBJECT});*/
@Override
public Type _writeOut(BytecodeContext bc, int mode) throws TransformerException {
// Caster.toDecimal(null);
GeneratorAdapter adapter = bc.getAdapter();
char first = lcType.charAt(0);
Type rtn;
switch(first) {
case 'a':
if ("array".equals(lcType)) {
rtn = expr.writeOut(bc, MODE_REF);
if (!rtn.equals(Types.ARRAY))
adapter.invokeStatic(Types.CASTER, Methods_Caster.TO_ARRAY);
return Types.ARRAY;
}
break;
case 'b':
if ("base64".equals(lcType)) {
expr.writeOut(bc, MODE_REF);
adapter.invokeStatic(Types.CASTER, Methods_Caster.TO_BASE64);
return Types.STRING;
}
if ("binary".equals(lcType)) {
rtn = expr.writeOut(bc, MODE_REF);
if (!rtn.equals(Types.BYTE_VALUE_ARRAY))
adapter.invokeStatic(Types.CASTER, Methods_Caster.TO_BINARY);
return Types.BYTE_VALUE_ARRAY;
}
if ("byte".equals(type)) {
rtn = expr.writeOut(bc, MODE_VALUE);
if (!rtn.equals(Types.BYTE_VALUE))
adapter.invokeStatic(Types.CASTER, Methods_Caster.TO_BYTE_VALUE[Types.getType(rtn)]);
return Types.BYTE_VALUE;
}
if ("byte".equals(lcType)) {
rtn = expr.writeOut(bc, MODE_REF);
if (!rtn.equals(Types.BYTE))
adapter.invokeStatic(Types.CASTER, Methods_Caster.TO_BYTE[Types.getType(rtn)]);
return Types.BYTE;
}
if ("boolean".equals(lcType)) {
return bc.getFactory().toExprBoolean(expr).writeOut(bc, MODE_REF);
}
break;
case 'c':
if ("char".equals(lcType)) {
rtn = expr.writeOut(bc, MODE_VALUE);
if (!rtn.equals(Types.CHAR))
adapter.invokeStatic(Types.CASTER, Methods_Caster.TO_CHAR_VALUE[Types.getType(rtn)]);
return Types.CHAR;
}
if ("character".equals(lcType)) {
rtn = expr.writeOut(bc, MODE_REF);
if (!rtn.equals(Types.CHARACTER))
adapter.invokeStatic(Types.CASTER, Methods_Caster.TO_CHARACTER[Types.getType(rtn)]);
return Types.CHARACTER;
}
if ("collection".equals(lcType)) {
rtn = expr.writeOut(bc, MODE_REF);
if (!rtn.equals(Types.COLLECTION))
adapter.invokeStatic(Types.CASTER, Methods_Caster.TO_COLLECTION);
return Types.COLLECTION;
}
if ("component".equals(lcType) || "class".equals(lcType)) {
rtn = expr.writeOut(bc, MODE_REF);
if (!rtn.equals(Types.COMPONENT))
adapter.invokeStatic(Types.CASTER, Methods_Caster.TO_COMPONENT);
return Types.COMPONENT;
}
break;
case 'd':
if ("double".equals(lcType)) {
return bc.getFactory().toExprDouble(expr).writeOut(bc, MODE_REF);
}
if ("date".equals(lcType) || "datetime".equals(lcType)) {
// First Arg
rtn = expr.writeOut(bc, MODE_REF);
if (rtn.equals(Types.DATE_TIME))
return Types.DATE_TIME;
int type = Types.getType(rtn);
// Second Arg
adapter.loadArg(0);
// adapter.invokeVirtual(Types.PAGE_CONTEXT,GET_CONFIG);
// adapter.invokeInterface(Types.CONFIG_WEB,GET_TIMEZONE);
adapter.invokeVirtual(Types.PAGE_CONTEXT, GET_TIMEZONE);
adapter.invokeStatic(Types.CASTER, Methods_Caster.TO_DATE[type]);
return Types.DATE_TIME;
}
if ("decimal".equals(lcType)) {
rtn = expr.writeOut(bc, MODE_REF);
adapter.invokeStatic(Types.CASTER, Methods_Caster.TO_DECIMAL[Types.getType(rtn)]);
return Types.STRING;
}
break;
case 'e':
/*if("excel".equals(type)) {
expr.writeOut(bc,MODE_REF);
adapter.invokeStatic(Types.EXCEL_UTIL,TO_EXCEL);
return Types.EXCEL;
}*/
break;
case 'f':
if ("file".equals(lcType)) {
rtn = expr.writeOut(bc, MODE_REF);
if (!rtn.equals(Types.FILE))
adapter.invokeStatic(Types.CASTER, Methods_Caster.TO_FILE);
return Types.FILE;
}
if ("float".equals(type)) {
rtn = expr.writeOut(bc, MODE_VALUE);
if (!rtn.equals(Types.FLOAT_VALUE))
adapter.invokeStatic(Types.CASTER, Methods_Caster.TO_FLOAT_VALUE[Types.getType(rtn)]);
return Types.FLOAT_VALUE;
}
if ("float".equals(lcType)) {
rtn = expr.writeOut(bc, MODE_REF);
if (!rtn.equals(Types.FLOAT))
adapter.invokeStatic(Types.CASTER, Methods_Caster.TO_FLOAT[Types.getType(rtn)]);
return Types.FLOAT;
}
break;
case 'i':
if ("int".equals(lcType)) {
rtn = expr.writeOut(bc, MODE_VALUE);
if (!rtn.equals(Types.INT_VALUE))
adapter.invokeStatic(Types.CASTER, Methods_Caster.TO_INT_VALUE[Types.getType(rtn)]);
return Types.INT_VALUE;
}
if ("integer".equals(lcType)) {
rtn = expr.writeOut(bc, MODE_REF);
if (!rtn.equals(Types.INTEGER))
adapter.invokeStatic(Types.CASTER, Methods_Caster.TO_INTEGER[Types.getType(rtn)]);
return Types.INTEGER;
}
if ("image".equals(lcType)) {
rtn = expr.writeOut(bc, MODE_REF);
if (!rtn.equals(Types.IMAGE)) {
adapter.loadArg(0);
adapter.invokeStatic(Types.IMAGE, Methods_Caster.TO_IMAGE);
}
return Types.IMAGE;
}
break;
case 'j':
if ("java.lang.boolean".equals(lcType)) {
return bc.getFactory().toExprBoolean(expr).writeOut(bc, MODE_REF);
}
if ("java.lang.double".equals(lcType)) {
return bc.getFactory().toExprDouble(expr).writeOut(bc, MODE_REF);
}
if ("java.lang.string".equals(lcType)) {
return bc.getFactory().toExprString(expr).writeOut(bc, MODE_REF);
}
if ("java.lang.stringbuffer".equals(lcType)) {
rtn = expr.writeOut(bc, MODE_REF);
if (!rtn.equals(Types.STRING_BUFFER))
adapter.invokeStatic(Types.CASTER, Methods_Caster.TO_STRING_BUFFER);
return Types.STRING_BUFFER;
}
if ("java.lang.byte".equals(lcType)) {
rtn = expr.writeOut(bc, MODE_REF);
if (!rtn.equals(Types.BYTE))
adapter.invokeStatic(Types.CASTER, Methods_Caster.TO_BYTE[Types.getType(rtn)]);
return Types.BYTE;
}
if ("java.lang.character".equals(lcType)) {
rtn = expr.writeOut(bc, MODE_REF);
if (!rtn.equals(Types.CHARACTER))
adapter.invokeStatic(Types.CASTER, Methods_Caster.TO_CHARACTER[Types.getType(rtn)]);
return Types.CHARACTER;
}
if ("java.lang.short".equals(lcType)) {
rtn = expr.writeOut(bc, MODE_REF);
if (!rtn.equals(Types.SHORT))
adapter.invokeStatic(Types.CASTER, Methods_Caster.TO_SHORT[Types.getType(rtn)]);
return Types.SHORT;
}
if ("java.lang.integer".equals(lcType)) {
rtn = expr.writeOut(bc, MODE_REF);
if (!rtn.equals(Types.INTEGER))
adapter.invokeStatic(Types.CASTER, Methods_Caster.TO_INTEGER[Types.getType(rtn)]);
return Types.INTEGER;
}
if ("java.lang.long".equals(lcType)) {
rtn = expr.writeOut(bc, MODE_REF);
if (!rtn.equals(Types.LONG))
adapter.invokeStatic(Types.CASTER, Methods_Caster.TO_LONG[Types.getType(rtn)]);
return Types.LONG;
}
if ("java.lang.float".equals(lcType)) {
rtn = expr.writeOut(bc, MODE_REF);
if (!rtn.equals(Types.FLOAT))
adapter.invokeStatic(Types.CASTER, Methods_Caster.TO_FLOAT[Types.getType(rtn)]);
return Types.FLOAT;
}
if ("java.io.file".equals(lcType)) {
rtn = expr.writeOut(bc, MODE_REF);
if (!rtn.equals(Types.FILE))
adapter.invokeStatic(Types.CASTER, Methods_Caster.TO_FILE);
return Types.FILE;
}
if ("java.lang.object".equals(lcType)) {
return expr.writeOut(bc, MODE_REF);
} else if ("java.util.date".equals(lcType)) {
// First Arg
rtn = expr.writeOut(bc, MODE_REF);
if (rtn.equals(Types.DATE))
return Types.DATE;
if (rtn.equals(Types.DATE_TIME))
return Types.DATE_TIME;
// Second Arg
adapter.loadArg(0);
// adapter.invokeVirtual(Types.PAGE_CONTEXT,GET_CONFIG);
// adapter.invokeVirtual(Types.CONFIG_WEB,GET_TIMEZONE);
adapter.invokeVirtual(Types.PAGE_CONTEXT, GET_TIMEZONE);
adapter.invokeStatic(Types.CASTER, Methods_Caster.TO_DATE[Types.getType(rtn)]);
return Types.DATE_TIME;
}
break;
case 'l':
if ("long".equals(type)) {
rtn = expr.writeOut(bc, MODE_VALUE);
if (!rtn.equals(Types.LONG_VALUE))
adapter.invokeStatic(Types.CASTER, Methods_Caster.TO_LONG_VALUE[Types.getType(rtn)]);
return Types.LONG_VALUE;
} else if ("long".equals(lcType)) {
rtn = expr.writeOut(bc, MODE_REF);
if (!rtn.equals(Types.LONG))
adapter.invokeStatic(Types.CASTER, Methods_Caster.TO_LONG[Types.getType(rtn)]);
return Types.LONG;
} else if ("locale".equals(lcType)) {
rtn = expr.writeOut(bc, MODE_REF);
adapter.invokeStatic(Types.CASTER, Methods_Caster.TO_LOCALE);
return Types.LOCALE;
}
break;
case 'n':
if ("node".equals(lcType)) {
rtn = expr.writeOut(bc, MODE_REF);
if (!rtn.equals(Types.NODE))
adapter.invokeStatic(Types.CASTER, Methods_Caster.TO_NODE);
return Types.NODE;
} else if ("null".equals(lcType)) {
expr.writeOut(bc, MODE_REF);
adapter.invokeStatic(Types.CASTER, Methods_Caster.TO_NULL);
// TODO gibt es einen null typ?
return Types.OBJECT;
}
break;
case 'o':
if ("object".equals(lcType) || "other".equals(lcType)) {
expr.writeOut(bc, MODE_REF);
return Types.OBJECT;
}
break;
case 't':
if ("timezone".equals(lcType)) {
rtn = expr.writeOut(bc, MODE_REF);
adapter.invokeStatic(Types.CASTER, Methods_Caster.TO_TIMEZONE);
return Types.TIMEZONE;
} else if ("timespan".equals(lcType)) {
rtn = expr.writeOut(bc, MODE_REF);
if (!rtn.equals(Types.TIMESPAN))
adapter.invokeStatic(Types.CASTER, Methods_Caster.TO_TIMESPAN);
return Types.TIMESPAN;
}
break;
case 's':
if ("struct".equals(lcType)) {
rtn = expr.writeOut(bc, MODE_REF);
if (!rtn.equals(Types.STRUCT))
adapter.invokeStatic(Types.CASTER, Methods_Caster.TO_STRUCT);
return Types.STRUCT;
}
if ("short".equals(type)) {
rtn = expr.writeOut(bc, MODE_VALUE);
if (!rtn.equals(Types.SHORT_VALUE))
adapter.invokeStatic(Types.CASTER, Methods_Caster.TO_SHORT_VALUE[Types.getType(rtn)]);
return Types.SHORT_VALUE;
}
if ("short".equals(lcType)) {
rtn = expr.writeOut(bc, MODE_REF);
if (!rtn.equals(Types.SHORT))
adapter.invokeStatic(Types.CASTER, Methods_Caster.TO_SHORT[Types.getType(rtn)]);
return Types.SHORT;
}
if ("stringbuffer".equals(lcType)) {
rtn = expr.writeOut(bc, MODE_REF);
if (!rtn.equals(Types.STRING_BUFFER))
adapter.invokeStatic(Types.CASTER, Methods_Caster.TO_STRING_BUFFER);
return Types.STRING_BUFFER;
}
break;
case 'x':
if ("xml".equals(lcType)) {
rtn = expr.writeOut(bc, MODE_REF);
if (!rtn.equals(Types.NODE))
adapter.invokeStatic(Types.CASTER, Methods_Caster.TO_NODE);
return Types.NODE;
}
break;
default:
if ("query".equals(lcType)) {
rtn = expr.writeOut(bc, MODE_REF);
if (!rtn.equals(Types.QUERY))
adapter.invokeStatic(Types.CASTER, Methods_Caster.TO_QUERY);
return Types.QUERY;
}
if ("querycolumn".equals(lcType)) {
rtn = (expr instanceof Variable) ? ((Variable) expr).writeOutCollection(bc, mode) : expr.writeOut(bc, MODE_REF);
if (!rtn.equals(Types.QUERY_COLUMN)) {
adapter.loadArg(0);
adapter.invokeStatic(Types.CASTER, Methods_Caster.TO_QUERY_COLUMN);
}
return Types.QUERY_COLUMN;
}
}
Type t = getType(type);
expr.writeOut(bc, MODE_REF);
adapter.checkCast(t);
return t;
}
use of org.objectweb.asm.Type in project Lucee by lucee.
the class CastString method _writeOut.
/**
* @see lucee.transformer.expression.Expression#_writeOut(org.objectweb.asm.commons.GeneratorAdapter, int)
*/
@Override
public Type _writeOut(BytecodeContext bc, int mode) throws TransformerException {
GeneratorAdapter adapter = bc.getAdapter();
if (expr instanceof ExprBoolean) {
expr.writeOut(bc, MODE_VALUE);
adapter.invokeStatic(Types.CASTER, Methods.METHOD_TO_STRING_FROM_BOOLEAN);
} else if (expr instanceof ExprDouble) {
expr.writeOut(bc, MODE_VALUE);
adapter.invokeStatic(Types.CASTER, Methods.METHOD_TO_STRING_FROM_DOUBLE);
} else {
Type rtn = expr.writeOut(bc, MODE_REF);
if (rtn.equals(Types.STRING))
return Types.STRING;
adapter.invokeStatic(Types.CASTER, Methods.METHOD_TO_STRING);
}
return Types.STRING;
}
use of org.objectweb.asm.Type in project Lucee by lucee.
the class Assign method _writeOut.
@Override
public Type _writeOut(BytecodeContext bc, int mode) throws TransformerException {
GeneratorAdapter adapter = bc.getAdapter();
int count = variable.getCount();
// count 0
if (count == 0) {
if (variable.ignoredFirstMember() && variable.getScope() == Scope.SCOPE_VAR) {
// print.dumpStack();
return Types.VOID;
}
return _writeOutEmpty(bc);
}
boolean doOnlyScope = variable.getScope() == Scope.SCOPE_LOCAL;
Type rtn = Types.OBJECT;
// boolean last;
for (int i = doOnlyScope ? 0 : 1; i < count; i++) {
adapter.loadArg(0);
}
rtn = _writeOutFirst(bc, (variable.getMembers().get(0)), mode, count == 1, doOnlyScope);
// pc.get(
for (int i = doOnlyScope ? 0 : 1; i < count; i++) {
Member member = (variable.getMembers().get(i));
boolean last = (i + 1) == count;
// Data Member
if (member instanceof DataMember) {
// ((DataMember)member).getName().writeOut(bc, MODE_REF);
getFactory().registerKey(bc, ((DataMember) member).getName(), false);
if (last)
writeValue(bc);
adapter.invokeVirtual(Types.PAGE_CONTEXT, last ? SET_KEY : TOUCH_KEY);
rtn = Types.OBJECT;
} else // UDF
if (member instanceof UDF) {
if (last)
throw new TransformerException("can't assign value to a user defined function", getStart());
UDF udf = (UDF) member;
getFactory().registerKey(bc, udf.getName(), false);
ExpressionUtil.writeOutExpressionArray(bc, Types.OBJECT, udf.getArguments());
adapter.invokeVirtual(Types.PAGE_CONTEXT, udf.hasNamedArgs() ? GET_FUNCTION_WITH_NAMED_ARGS_KEY : GET_FUNCTION_KEY);
rtn = Types.OBJECT;
}
}
return rtn;
}
Aggregations