use of lucee.transformer.expression.ExprBoolean in project Lucee by lucee.
the class AbstrCFMLScriptTransformer method condition.
/**
* Ruft die Methode expression der zu vererbenten Klasse auf
* und prueft ob der Rueckgabewert einen boolschen Wert repraesentiert und castet den Wert allenfalls.
* <br />
* EBNF:<br />
* <code>TemplateException::expression;</code>
* @return condition
* @throws TemplateException
*/
private final ExprBoolean condition(ExprData data) throws TemplateException {
ExprBoolean condition = null;
comments(data);
condition = CastBoolean.toExprBoolean(super.expression(data));
comments(data);
return condition;
}
use of lucee.transformer.expression.ExprBoolean in project Lucee by lucee.
the class TagInclude method _writeOut.
/**
* @see lucee.transformer.bytecode.statement.tag.TagBase#_writeOut(org.objectweb.asm.commons.GeneratorAdapter)
*/
@Override
public void _writeOut(BytecodeContext bc) throws TransformerException {
Type type = Types.PAGE_CONTEXT;
Method func = DO_INCLUDE_RUN_ONCE2;
// cachedwithin
Expression cachedwithin = null;
Attribute attr = getAttribute("cachedwithin");
if (attr != null && attr.getValue() != null) {
cachedwithin = attr.getValue();
type = Types.PAGE_CONTEXT_IMPL;
func = DO_INCLUDE_RUN_ONCE3;
}
GeneratorAdapter adapter = bc.getAdapter();
adapter.loadArg(0);
if (cachedwithin != null)
adapter.checkCast(Types.PAGE_CONTEXT_IMPL);
// template
getAttribute("template").getValue().writeOut(bc, Expression.MODE_REF);
// run Once
attr = getAttribute("runonce");
ExprBoolean expr = (attr == null) ? bc.getFactory().FALSE() : bc.getFactory().toExprBoolean(attr.getValue());
expr.writeOut(bc, Expression.MODE_VALUE);
// cachedwithin
if (cachedwithin != null)
cachedwithin.writeOut(bc, Expression.MODE_REF);
adapter.invokeVirtual(type, func);
}
use of lucee.transformer.expression.ExprBoolean 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.ExprBoolean in project Lucee by lucee.
the class AbstrCFMLExprTransformer method conditionalOp.
private Expression conditionalOp(ExprData data) throws TemplateException {
Expression expr = impOp(data);
if (data.srcCode.forwardIfCurrent('?')) {
comments(data);
// Elvis
if (data.srcCode.forwardIfCurrent(':')) {
comments(data);
Expression right = assignOp(data);
if (expr instanceof ExprBoolean)
return expr;
if (!(expr instanceof Variable))
throw new TemplateException(data.srcCode, "left operand of the Elvis operator has to be a variable or a function call");
Variable left = (Variable) expr;
/*List<Member> members = left.getMembers();
Member last=null;
for(Member m:members) {
last=m;
m.setSafeNavigated(true);
}
if(last!=null) {
last.setSafeNavigatedValue(right);
}
return left;*/
return OpElvis.toExpr(left, right);
}
Expression left = assignOp(data);
comments(data);
if (!data.srcCode.forwardIfCurrent(':'))
throw new TemplateException(data.srcCode, "invalid conditional operator");
comments(data);
Expression right = assignOp(data);
expr = OpContional.toExpr(expr, left, right);
}
return expr;
}
Aggregations