use of lucee.transformer.expression.ExprString 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 lucee.transformer.expression.ExprString in project Lucee by lucee.
the class VT method _writeOut.
private Type _writeOut(BytecodeContext bc, int mode, Boolean asCollection) throws TransformerException {
final GeneratorAdapter adapter = bc.getAdapter();
final int count = countFM + countDM;
// count 0
if (count == 0)
return _writeOutEmpty(bc);
boolean doOnlyScope = scope == Scope.SCOPE_LOCAL;
// boolean last;
int c = 0;
for (int i = doOnlyScope ? 0 : 1; i < count; i++) {
Member member = (members.get((count - 1) - c));
c++;
adapter.loadArg(0);
if (member.getSafeNavigated() && member instanceof UDF)
adapter.checkCast(Types.PAGE_CONTEXT_IMPL);
}
Type rtn = _writeOutFirst(bc, (members.get(0)), mode, count == 1, doOnlyScope, null, null);
// pc.get(
for (int i = doOnlyScope ? 0 : 1; i < count; i++) {
Member member = (members.get(i));
boolean last = (i + 1) == count;
// Data Member
if (member instanceof DataMember) {
ExprString name = ((DataMember) member).getName();
if (last && ASMUtil.isDotKey(name)) {
LitString ls = (LitString) name;
if (ls.getString().equalsIgnoreCase("RECORDCOUNT")) {
adapter.invokeStatic(Types.VARIABLE_UTIL_IMPL, RECORDCOUNT);
} else if (ls.getString().equalsIgnoreCase("CURRENTROW")) {
adapter.invokeStatic(Types.VARIABLE_UTIL_IMPL, CURRENTROW);
} else if (ls.getString().equalsIgnoreCase("COLUMNLIST")) {
adapter.invokeStatic(Types.VARIABLE_UTIL_IMPL, COLUMNLIST);
} else {
getFactory().registerKey(bc, name, false);
// safe nav
int type;
if (member.getSafeNavigated()) {
Expression val = member.getSafeNavigatedValue();
if (val == null)
ASMConstants.NULL(adapter);
else
val.writeOut(bc, Expression.MODE_REF);
type = THREE;
} else
type = TWO;
adapter.invokeVirtual(Types.PAGE_CONTEXT, asCollection(asCollection, last) ? GET_COLLECTION[type] : GET[type]);
}
} else {
getFactory().registerKey(bc, name, false);
// safe nav
int type;
if (member.getSafeNavigated()) {
Expression val = member.getSafeNavigatedValue();
if (val == null)
ASMConstants.NULL(adapter);
else
val.writeOut(bc, Expression.MODE_REF);
type = THREE;
} else
type = TWO;
adapter.invokeVirtual(Types.PAGE_CONTEXT, asCollection(asCollection, last) ? GET_COLLECTION[type] : GET[type]);
}
rtn = Types.OBJECT;
} else // UDF
if (member instanceof UDF) {
rtn = _writeOutUDF(bc, (UDF) member);
}
}
return rtn;
}
use of lucee.transformer.expression.ExprString in project Lucee by lucee.
the class LitStringImpl method _toExpr.
private static ExprString _toExpr(Factory factory, String str) {
int size = str.length() / 2;
String l = str.substring(0, size);
String r = str.substring(size);
ExprString left = toBig(l) ? _toExpr(factory, l) : factory.createLitString(l);
ExprString right = toBig(r) ? _toExpr(factory, r) : factory.createLitString(r);
return OpString.toExprString(left, right, false);
}
use of lucee.transformer.expression.ExprString in project Lucee by lucee.
the class AbstrCFMLExprTransformer method readComponentPath.
private ExprString readComponentPath(ExprData data) throws TemplateException {
// first identifier
String name = identifier(data, true);
if (name != null) {
StringBuilder fullName = new StringBuilder();
fullName.append(name);
// Loop over addional identifier
while (data.srcCode.isValidIndex()) {
if (data.srcCode.forwardIfCurrent('.')) {
comments(data);
name = identifier(data, true);
if (name == null)
return null;
fullName.append('.');
fullName.append(name);
comments(data);
} else
break;
}
return data.factory.createLitString(fullName.toString());
}
Expression str = string(data);
if (str != null) {
return data.factory.toExprString(str);
}
return null;
}
use of lucee.transformer.expression.ExprString in project Lucee by lucee.
the class AbstrCFMLExprTransformer method staticScope.
private Expression staticScope(ExprData data, Expression expr) throws TemplateException {
if (data.srcCode.forwardIfCurrent("::")) {
if (!(expr instanceof Variable))
throw new TemplateException(data.srcCode, "invalid syntax before [::]");
Variable old = (Variable) expr;
// set back to read again as a component path
data.srcCode.setPos(old.getStart().pos);
// now we read the component path
ExprString componentPath = readComponentPath(data);
if (!data.srcCode.forwardIfCurrent("::"))
throw new TemplateException(data.srcCode, "invalid syntax before [::]" + data.srcCode.getCurrent());
comments(data);
BIF bif = null;
if (componentPath instanceof LitString) {
LitString ls = (LitString) componentPath;
if ("super".equalsIgnoreCase(ls.getString())) {
bif = ASMUtil.createBif(data, GET_SUPER_STATIC_SCOPE);
}
}
// now we generate a _getStaticScope function call with that path
if (bif == null) {
bif = ASMUtil.createBif(data, GET_STATIC_SCOPE);
bif.addArgument(new Argument(componentPath, "string"));
}
Variable var = data.factory.createVariable(old.getStart(), data.srcCode.getPosition());
var.addMember(bif);
// now we are reading what is coming after ":::"
Expression sd = subDynamic(data, var, false, true);
return sd;
}
return null;
}
Aggregations