use of lucee.transformer.expression.var.DataMember 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.DataMember 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;
}
use of lucee.transformer.expression.var.DataMember 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.var.DataMember in project Lucee by lucee.
the class OPUnary method _writeOut.
@Override
public Type _writeOut(BytecodeContext bc, int mode) throws TransformerException {
GeneratorAdapter adapter = bc.getAdapter();
// convert value
if (operation == CONCAT)
value = CastString.toExprString(value);
else
value = CastDouble.toExprDouble(value);
List<Member> members = var.getMembers();
int size = members.size();
String scope = VariableInterpreter.scopeInt2String(var.getScope());
/*
* (susi.sorglos++ or variables.susi++)
*/
if ((scope == null && size > 1) || (scope != null && size > 0)) {
Member last = var.removeMember(members.size() - 1);
if (!(last instanceof DataMember))
throw new TransformerException("you cannot use a unary operator with a function " + last.getClass().getName(), getStart());
// write the variable
var.setAsCollection(Boolean.TRUE);
var.writeOut(bc, mode);
// write out last Key
getFactory().registerKey(bc, ((DataMember) last).getName(), false);
// write out value
value.writeOut(bc, MODE_VALUE);
if (type == POST) {
if (operation != OpDouble.PLUS && operation != OpDouble.MINUS)
throw new TransformerException("Post only possible with plus or minus " + operation, value.getStart());
if (operation == PLUS)
adapter.invokeStatic(Types.OPERATOR, UNARY_POST_PLUS2);
else if (operation == MINUS)
adapter.invokeStatic(Types.OPERATOR, UNARY_POST_MINUS2);
} else if (type == PRE) {
if (operation == PLUS)
adapter.invokeStatic(Types.OPERATOR, UNARY_PRE_PLUS2);
else if (operation == MINUS)
adapter.invokeStatic(Types.OPERATOR, UNARY_PRE_MINUS2);
else if (operation == DIVIDE)
adapter.invokeStatic(Types.OPERATOR, UNARY_PRE_DIVIDE2);
else if (operation == MULTIPLY)
adapter.invokeStatic(Types.OPERATOR, UNARY_PRE_MULTIPLY2);
else if (operation == CONCAT)
adapter.invokeStatic(Types.OPERATOR, UNARY_PRE_CONCAT2);
}
if (operation == CONCAT)
return Types.STRING;
// convert from Double to double (if necessary)
if (mode == MODE_REF) {
adapter.invokeStatic(Types.CASTER, Methods.METHOD_TO_DOUBLE_FROM_DOUBLE);
return Types.DOUBLE;
}
return Types.DOUBLE_VALUE;
}
/*
* undefined scope only with one key (susi++;)
*/
// PageContext instance
adapter.loadArg(0);
// Collection key Array
int arrSize = scope != null ? members.size() + 1 : members.size();
boolean useArray = arrSize > 1 || scope != null;
if (useArray) {
ArrayVisitor av = new ArrayVisitor();
int index = 0;
av.visitBegin(adapter, Types.COLLECTION_KEY, arrSize);
Iterator<Member> it = members.iterator();
Member m;
DataMember dm;
if (scope != null) {
av.visitBeginItem(adapter, index++);
getFactory().registerKey(bc, getFactory().createLitString(scope), false);
av.visitEndItem(adapter);
}
while (it.hasNext()) {
av.visitBeginItem(adapter, index++);
m = it.next();
if (!(m instanceof DataMember))
throw new TransformerException("you cannot use a unary operator with a function " + m.getClass().getName(), getStart());
getFactory().registerKey(bc, ((DataMember) m).getName(), false);
av.visitEndItem(adapter);
}
av.visitEnd();
} else {
Member m = members.iterator().next();
if (!(m instanceof DataMember))
throw new TransformerException("you cannot use a unary operator with a function " + m.getClass().getName(), getStart());
getFactory().registerKey(bc, ((DataMember) m).getName(), false);
}
if (type == POST) {
if (operation != OpDouble.PLUS && operation != OpDouble.MINUS)
throw new TransformerException("Post only possible with plus or minus " + operation, value.getStart());
value.writeOut(bc, MODE_VALUE);
if (operation == PLUS)
adapter.invokeStatic(Types.OPERATOR, useArray ? UNARY_POST_PLUS_N : UNARY_POST_PLUS_1);
else if (operation == MINUS)
adapter.invokeStatic(Types.OPERATOR, useArray ? UNARY_POST_MINUS_N : UNARY_POST_MINUS_1);
} else if (type == PRE) {
value.writeOut(bc, MODE_VALUE);
if (operation == PLUS)
adapter.invokeStatic(Types.OPERATOR, useArray ? UNARY_PRE_PLUS_N : UNARY_PRE_PLUS_1);
else if (operation == MINUS)
adapter.invokeStatic(Types.OPERATOR, useArray ? UNARY_PRE_MINUS_N : UNARY_PRE_MINUS_1);
else if (operation == DIVIDE)
adapter.invokeStatic(Types.OPERATOR, useArray ? UNARY_PRE_DIVIDE_N : UNARY_PRE_DIVIDE_1);
else if (operation == MULTIPLY)
adapter.invokeStatic(Types.OPERATOR, useArray ? UNARY_PRE_MULTIPLY_N : UNARY_PRE_MULTIPLY_1);
else if (operation == CONCAT)
adapter.invokeStatic(Types.OPERATOR, useArray ? UNARY_PRE_CONCAT_N : UNARY_PRE_CONCAT_1);
}
if (operation == CONCAT)
return Types.STRING;
// convert from double to Double (if necessary)
if (mode == MODE_REF) {
adapter.invokeStatic(Types.CASTER, Methods.METHOD_TO_DOUBLE_FROM_DOUBLE);
return Types.DOUBLE;
}
return Types.DOUBLE_VALUE;
}
use of lucee.transformer.expression.var.DataMember in project Lucee by lucee.
the class OpElvis method _writeOutPureDataMember.
public Type _writeOutPureDataMember(BytecodeContext bc, int mode) throws TransformerException {
// TODO use function isNull for this
GeneratorAdapter adapter = bc.getAdapter();
Label yes = new Label();
Label end = new Label();
List<Member> members = left.getMembers();
// to array
Iterator<Member> it = members.iterator();
List<DataMember> list = new ArrayList<DataMember>();
while (it.hasNext()) {
list.add((DataMember) it.next());
}
DataMember[] arr = list.toArray(new DataMember[members.size()]);
ExpressionUtil.visitLine(bc, left.getStart());
// public static boolean call(PageContext pc , double scope,String[] varNames)
// pc
adapter.loadArg(0);
// scope
adapter.push((double) left.getScope());
// varNames
// all literal string?
boolean allLiteral = true;
for (int i = 0; i < arr.length; i++) {
if (!(arr[i].getName() instanceof Literal))
allLiteral = false;
}
ArrayVisitor av = new ArrayVisitor();
if (!allLiteral) {
// String Array
av.visitBegin(adapter, Types.STRING, arr.length);
for (int i = 0; i < arr.length; i++) {
av.visitBeginItem(adapter, i);
arr[i].getName().writeOut(bc, MODE_REF);
av.visitEndItem(adapter);
}
} else {
// Collection.Key Array
av.visitBegin(adapter, Types.COLLECTION_KEY, arr.length);
for (int i = 0; i < arr.length; i++) {
av.visitBeginItem(adapter, i);
getFactory().registerKey(bc, arr[i].getName(), false);
av.visitEndItem(adapter);
}
}
av.visitEnd();
// allowNull
// adapter.push(false);
// ASMConstants.NULL(adapter);
// call IsDefined.invoke
adapter.invokeStatic(ELVIS, allLiteral ? INVOKE_KEY : INVOKE_STR);
ExpressionUtil.visitLine(bc, left.getEnd());
adapter.visitJumpInsn(Opcodes.IFEQ, yes);
// left
ExpressionUtil.visitLine(bc, left.getStart());
left.writeOut(bc, MODE_REF);
ExpressionUtil.visitLine(bc, left.getEnd());
adapter.visitJumpInsn(Opcodes.GOTO, end);
// right
ExpressionUtil.visitLine(bc, right.getStart());
adapter.visitLabel(yes);
right.writeOut(bc, MODE_REF);
ExpressionUtil.visitLine(bc, right.getEnd());
adapter.visitLabel(end);
return Types.OBJECT;
}
Aggregations