use of lucee.transformer.expression.Expression in project Lucee by lucee.
the class Function method createArguments.
private final void createArguments(BytecodeContext bc) throws TransformerException {
GeneratorAdapter ga = bc.getAdapter();
ga.push(arguments.size());
ga.newArray(FUNCTION_ARGUMENT);
Argument arg;
for (int i = 0; i < arguments.size(); i++) {
arg = arguments.get(i);
boolean canHaveKey = Factory.canRegisterKey(arg.getName());
// CHECK if default values
// type
ExprString _strType = arg.getType();
short _type = CFTypes.TYPE_UNKNOW;
if (_strType instanceof LitString) {
_type = CFTypes.toShortStrict(((LitString) _strType).getString(), CFTypes.TYPE_UNKNOW);
}
boolean useType = !canHaveKey || _type != CFTypes.TYPE_ANY;
// boolean useStrType=useType && (_type==CFTypes.TYPE_UNDEFINED || _type==CFTypes.TYPE_UNKNOW || CFTypes.toString(_type, null)==null);
// required
ExprBoolean _req = arg.getRequired();
boolean useReq = !canHaveKey || toBoolean(_req, null) != Boolean.FALSE;
// default-type
Expression _def = arg.getDefaultValueType(bc.getFactory());
boolean useDef = !canHaveKey || toInt(_def, -1) != FunctionArgument.DEFAULT_TYPE_NULL;
// pass by reference
ExprBoolean _pass = arg.isPassByReference();
boolean usePass = !canHaveKey || toBoolean(_pass, null) != Boolean.TRUE;
// display-hint
ExprString _dsp = arg.getDisplayName();
boolean useDsp = !canHaveKey || !isLiteralEmptyString(_dsp);
// hint
ExprString _hint = arg.getHint();
boolean useHint = !canHaveKey || !isLiteralEmptyString(_hint);
// meta
Map _meta = arg.getMetaData();
boolean useMeta = !canHaveKey || (_meta != null && !_meta.isEmpty());
int functionIndex = 7;
if (!useMeta) {
functionIndex--;
if (!useHint) {
functionIndex--;
if (!useDsp) {
functionIndex--;
if (!usePass) {
functionIndex--;
if (!useDef) {
functionIndex--;
if (!useReq) {
functionIndex--;
if (!useType) {
functionIndex--;
}
}
}
}
}
}
}
// write out arguments
ga.dup();
ga.push(i);
// new FunctionArgument(...)
ga.newInstance(canHaveKey && functionIndex < INIT_FAI_KEY_LIGHT.length ? FUNCTION_ARGUMENT_LIGHT : FUNCTION_ARGUMENT_IMPL);
ga.dup();
// name
bc.getFactory().registerKey(bc, arg.getName(), false);
// type
if (functionIndex >= INIT_FAI_KEY.length - 7) {
_strType.writeOut(bc, Expression.MODE_REF);
bc.getAdapter().push(_type);
}
// required
if (functionIndex >= INIT_FAI_KEY.length - 6)
_req.writeOut(bc, Expression.MODE_VALUE);
// default value
if (functionIndex >= INIT_FAI_KEY.length - 5)
_def.writeOut(bc, Expression.MODE_VALUE);
// pass by reference
if (functionIndex >= INIT_FAI_KEY.length - 4)
_pass.writeOut(bc, Expression.MODE_VALUE);
// display-name
if (functionIndex >= INIT_FAI_KEY.length - 3)
_dsp.writeOut(bc, Expression.MODE_REF);
// hint
if (functionIndex >= INIT_FAI_KEY.length - 2)
_hint.writeOut(bc, Expression.MODE_REF);
// meta
if (functionIndex == INIT_FAI_KEY.length - 1)
Page.createMetaDataStruct(bc, _meta, null);
if (functionIndex < INIT_FAI_KEY_LIGHT.length)
ga.invokeConstructor(FUNCTION_ARGUMENT_LIGHT, INIT_FAI_KEY[functionIndex]);
else
ga.invokeConstructor(FUNCTION_ARGUMENT_IMPL, INIT_FAI_KEY[functionIndex]);
ga.visitInsn(Opcodes.AASTORE);
}
}
use of lucee.transformer.expression.Expression in project Lucee by lucee.
the class BodyBase method addStatement.
/**
* @see lucee.transformer.bytecode.Body#addStatement(lucee.transformer.bytecode.Statement)
*/
@Override
public void addStatement(Statement statement) {
if (statement instanceof PrintOut) {
Expression expr = ((PrintOut) statement).getExpr();
if (expr instanceof LitString && concatPrintouts(((LitString) expr).getString()))
return;
}
statement.setParent(this);
this.statements.add(statement);
last = statement;
}
use of lucee.transformer.expression.Expression in project Lucee by lucee.
the class SourceLastModifiedClassAdapter method writeOutFunctionDefaultValueInnerInner.
private void writeOutFunctionDefaultValueInnerInner(BytecodeContext bc, Function function) throws TransformerException {
GeneratorAdapter adapter = bc.getAdapter();
List<Argument> args = function.getArguments();
if (args.size() == 0) {
adapter.loadArg(DEFAULT_VALUE);
adapter.returnValue();
return;
}
Iterator<Argument> it = args.iterator();
Argument arg;
ConditionVisitor cv = new ConditionVisitor();
DecisionIntVisitor div;
cv.visitBefore();
int count = 0;
while (it.hasNext()) {
arg = it.next();
cv.visitWhenBeforeExpr();
div = new DecisionIntVisitor();
div.visitBegin();
adapter.loadArg(2);
div.visitEQ();
adapter.push(count++);
div.visitEnd(bc);
cv.visitWhenAfterExprBeforeBody(bc);
Expression defaultValue = arg.getDefaultValue();
if (defaultValue != null) {
/*if(defaultValue instanceof Null) {
adapter.invokeStatic(NULL, GET_INSTANCE);
}
else*/
defaultValue.writeOut(bc, Expression.MODE_REF);
} else
adapter.loadArg(DEFAULT_VALUE);
// adapter.visitInsn(Opcodes.ACONST_NULL);
adapter.returnValue();
cv.visitWhenAfterBody(bc);
}
cv.visitOtherviseBeforeBody();
// adapter.visitInsn(ACONST_NULL);
// adapter.returnValue();
cv.visitOtherviseAfterBody();
cv.visitAfter(bc);
}
use of lucee.transformer.expression.Expression in project Lucee by lucee.
the class SourceLastModifiedClassAdapter method writeOutNewComponent.
private void writeOutNewComponent(ConstrBytecodeContext constr, List<LitString> keys, ClassWriter cw, Tag component, String name) throws TransformerException {
GeneratorAdapter adapter = new GeneratorAdapter(Opcodes.ACC_PUBLIC + Opcodes.ACC_FINAL, NEW_COMPONENT_IMPL_INSTANCE, null, new Type[] { Types.PAGE_EXCEPTION }, cw);
BytecodeContext bc = new BytecodeContext(null, constr, this, keys, cw, name, adapter, NEW_COMPONENT_IMPL_INSTANCE, writeLog(), suppressWSbeforeArg, output, returnValue);
Label methodBegin = new Label();
Label methodEnd = new Label();
adapter.visitLocalVariable("this", "L" + name + ";", null, methodBegin, methodEnd, 0);
ExpressionUtil.visitLine(bc, component.getStart());
adapter.visitLabel(methodBegin);
int comp = adapter.newLocal(Types.COMPONENT_IMPL);
adapter.newInstance(Types.COMPONENT_IMPL);
adapter.dup();
Attribute attr;
// ComponentPage
adapter.visitVarInsn(Opcodes.ALOAD, 0);
adapter.checkCast(Types.COMPONENT_PAGE_IMPL);
// !!! also check CFMLScriptTransformer.addMetaData if you do any change here !!!
// Output
attr = component.removeAttribute("output");
if (attr != null) {
ExpressionUtil.writeOutSilent(attr.getValue(), bc, Expression.MODE_REF);
} else
ASMConstants.NULL(adapter);
// synchronized
attr = component.removeAttribute("synchronized");
if (attr != null)
ExpressionUtil.writeOutSilent(attr.getValue(), bc, Expression.MODE_VALUE);
else
adapter.push(false);
// extends
attr = component.removeAttribute("extends");
if (attr != null)
ExpressionUtil.writeOutSilent(attr.getValue(), bc, Expression.MODE_REF);
else
adapter.push("");
// implements
attr = component.removeAttribute("implements");
if (attr != null)
ExpressionUtil.writeOutSilent(attr.getValue(), bc, Expression.MODE_REF);
else
adapter.push("");
// hint
attr = component.removeAttribute("hint");
if (attr != null) {
Expression value = attr.getValue();
if (!(value instanceof Literal)) {
value = bc.getFactory().createLitString("[runtime expression]");
}
ExpressionUtil.writeOutSilent(value, bc, Expression.MODE_REF);
} else
adapter.push("");
// dspName
attr = component.removeAttribute("displayname");
if (attr == null)
attr = component.getAttribute("display");
if (attr != null)
ExpressionUtil.writeOutSilent(attr.getValue(), bc, Expression.MODE_REF);
else
adapter.push("");
// callpath
adapter.visitVarInsn(Opcodes.ALOAD, 2);
// realpath
adapter.visitVarInsn(Opcodes.ILOAD, 3);
// style
attr = component.removeAttribute("style");
if (attr != null)
ExpressionUtil.writeOutSilent(attr.getValue(), bc, Expression.MODE_REF);
else
adapter.push("");
// persistent
attr = component.removeAttribute("persistent");
boolean persistent = false;
if (attr != null) {
persistent = ASMUtil.toBoolean(attr, component.getStart()).booleanValue();
}
// accessors
attr = component.removeAttribute("accessors");
boolean accessors = false;
if (attr != null) {
accessors = ASMUtil.toBoolean(attr, component.getStart()).booleanValue();
}
// modifier
attr = component.removeAttribute("modifier");
int modifiers = Component.MODIFIER_NONE;
if (attr != null) {
// type already evaluated in evaluator
LitString ls = (LitString) component.getFactory().toExprString(attr.getValue());
modifiers = ComponentUtil.toModifier(ls.getString(), lucee.runtime.Component.MODIFIER_NONE, lucee.runtime.Component.MODIFIER_NONE);
}
adapter.push(persistent);
adapter.push(accessors);
adapter.push(modifiers);
adapter.visitVarInsn(Opcodes.ILOAD, 4);
// adapter.visitVarInsn(Opcodes.ALOAD, 4);
createMetaDataStruct(bc, component.getAttributes(), component.getMetaData());
adapter.invokeConstructor(Types.COMPONENT_IMPL, CONSTR_COMPONENT_IMPL15);
adapter.storeLocal(comp);
// Component Impl(ComponentPage componentPage,boolean output, String extend, String hint, String dspName)
// initComponent(pc,c);
adapter.visitVarInsn(Opcodes.ALOAD, 0);
adapter.loadArg(0);
adapter.loadLocal(comp);
adapter.loadArg(4);
adapter.invokeVirtual(Types.COMPONENT_PAGE_IMPL, INIT_COMPONENT3);
adapter.visitLabel(methodEnd);
// return component;
adapter.loadLocal(comp);
adapter.returnValue();
// ExpressionUtil.visitLine(adapter, component.getEndLine());
adapter.endMethod();
}
use of lucee.transformer.expression.Expression in project Lucee by lucee.
the class Call method _writeOut.
@Override
public Type _writeOut(BytecodeContext bc, int mode) throws TransformerException {
GeneratorAdapter ga = bc.getAdapter();
ga.loadArg(0);
expr.writeOut(bc, MODE_REF);
ExpressionUtil.writeOutExpressionArray(bc, Types.OBJECT, args.toArray(new Expression[args.size()]));
ga.invokeStatic(Types.PAGE_CONTEXT_UTIL, namedArgs() ? GET_FUNCTION_WITH_NAMED_ARGS_KEY : GET_FUNCTION_KEY);
return Types.OBJECT;
}
Aggregations