use of lucee.transformer.expression.var.Variable in project Lucee by lucee.
the class AbstrCFMLExprTransformer method newOp.
private Expression newOp(ExprData data, Expression expr) throws TemplateException {
if (!(expr instanceof Variable))
return expr;
Variable var = (Variable) expr;
Member m = var.getFirstMember();
if (!(m instanceof DataMember))
return expr;
ExprString n = ((DataMember) m).getName();
if (!(n instanceof LitString))
return expr;
LitString ls = (LitString) n;
if (!"new".equalsIgnoreCase(ls.getString()))
return expr;
int start = data.srcCode.getPos();
ExprString exprName = readComponentPath(data);
if (exprName == null) {
data.srcCode.setPos(start);
return expr;
}
comments(data);
if (data.srcCode.isCurrent('(')) {
FunctionMember func = getFunctionMember(data, Identifier.toIdentifier(data.factory, "_createComponent", Identifier.CASE_ORIGNAL, null, null), true);
func.addArgument(new Argument(exprName, "string"));
Variable v = expr.getFactory().createVariable(expr.getStart(), expr.getEnd());
v.addMember(func);
comments(data);
return v;
}
data.srcCode.setPos(start);
return expr;
}
use of lucee.transformer.expression.var.Variable in project Lucee by lucee.
the class ASMUtil method cachedWithinValue.
public static Literal cachedWithinValue(Expression val) throws EvaluatorException {
if (val instanceof Literal) {
Literal l = (Literal) val;
// double == days
Double d = l.getDouble(null);
if (d != null) {
return val.getFactory().createLitLong(TimeSpanImpl.fromDays(d.doubleValue()).getMillis(), null, null);
}
return l;
} else // createTimespan
if (val instanceof Variable) {
Variable var = (Variable) val;
if (var.getMembers().size() == 1) {
Member first = var.getFirstMember();
if (first instanceof BIF) {
BIF bif = (BIF) first;
if ("createTimeSpan".equalsIgnoreCase(bif.getFlf().getName())) {
Argument[] args = bif.getArguments();
int len = ArrayUtil.size(args);
if (len >= 4 && len <= 5) {
double days = toDouble(args[0].getValue());
double hours = toDouble(args[1].getValue());
double minutes = toDouble(args[2].getValue());
double seconds = toDouble(args[3].getValue());
double millis = len == 5 ? toDouble(args[4].getValue()) : 0;
return val.getFactory().createLitLong(new TimeSpanImpl((int) days, (int) hours, (int) minutes, (int) seconds, (int) millis).getMillis(), null, null);
}
}
}
}
}
throw cacheWithinException();
}
use of lucee.transformer.expression.var.Variable 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 lucee.transformer.expression.var.Variable in project Lucee by lucee.
the class NamedArgument method _writeOut.
@Override
public Type _writeOut(BytecodeContext bc, int mode) throws TransformerException {
int form = VALUE;
int type = STRING;
if (name instanceof Variable && !((Variable) name).fromHash()) {
GeneratorAdapter adapter = bc.getAdapter();
String[] arr = VariableString.variableToStringArray((Variable) name, true);
if (arr.length > 1) {
form = ARRAY;
ArrayVisitor av = new ArrayVisitor();
av.visitBegin(adapter, Types.STRING, arr.length);
for (int y = 0; y < arr.length; y++) {
av.visitBeginItem(adapter, y);
adapter.push(varKeyUpperCase ? arr[y].toUpperCase() : arr[y]);
av.visitEndItem(bc.getAdapter());
}
av.visitEnd();
} else {
// VariableString.toExprString(name).writeOut(bc, MODE_REF);
String str = VariableString.variableToString((Variable) name, true);
name = bc.getFactory().createLitString(varKeyUpperCase ? str.toUpperCase() : str);
getFactory().registerKey(bc, VariableString.toExprString(name), false);
type = KEY;
}
} else {
getFactory().registerKey(bc, name.getFactory().toExprString(name), false);
type = KEY;
}
// name.writeOut(bc, MODE_REF);
super._writeOut(bc, MODE_REF);
// bc.getAdapter().push(variableString);
bc.getAdapter().invokeStatic(Types.FUNCTION_VALUE_IMPL, NEW_INSTANCE[type][form]);
return Types.FUNCTION_VALUE;
}
use of lucee.transformer.expression.var.Variable in project Lucee by lucee.
the class Null method toVariable.
public Variable toVariable() {
Variable v = getFactory().createVariable(Scope.SCOPE_UNDEFINED, getStart(), getEnd());
v.addMember(getFactory().createDataMember(getFactory().createLitString("null")));
return v;
}
Aggregations