use of lucee.transformer.expression.var.Variable in project Lucee by lucee.
the class AbstrCFMLExprTransformer method _plusMinusOp.
private Expression _plusMinusOp(ExprData data, Expression expr, int opr) throws TemplateException {
// plus|Minus Assignment
if (data.srcCode.isCurrent('=') && expr instanceof Variable) {
data.srcCode.next();
comments(data);
Expression value = assignOp(data);
// if(opr==OpDouble.MINUS) value=OpNegateNumber.toExprDouble(value, null, null);
expr = new OPUnary((Variable) expr, value, OPUnary.PRE, opr, expr.getStart(), data.srcCode.getPosition());
// ExprDouble res = OpDouble.toExprDouble(expr, right,opr);
// expr=new OpVariable((Variable)expr,res,data.cfml.getPosition());
} else {
comments(data);
expr = OpDouble.toExprDouble(expr, modOp(data), opr);
}
return expr;
}
use of lucee.transformer.expression.var.Variable in project Lucee by lucee.
the class AbstrCFMLScriptTransformer method expressionStatement.
/**
* List mithilfe des data.CFMLExprTransformer einen Ausruck ein.
* <br />
* EBNF:<br />
* <code>expression ";";</code>
* @param parent
* @return Ausdruck
* @throws TemplateException
*/
private Statement expressionStatement(ExprData data, Body parent) throws TemplateException {
// first we check if we have a access modifier
int pos = data.srcCode.getPos();
int access = -1;
boolean _final = false;
if (data.context == CTX_CFC || data.context == CTX_STATIC) {
if (data.srcCode.forwardIfCurrent("final ")) {
_final = true;
comments(data);
}
if (data.srcCode.forwardIfCurrent("private ")) {
access = Component.ACCESS_PRIVATE;
comments(data);
} else if (data.srcCode.forwardIfCurrent("package ")) {
access = Component.ACCESS_PACKAGE;
comments(data);
} else if (data.srcCode.forwardIfCurrent("public ")) {
access = Component.ACCESS_PUBLIC;
comments(data);
} else if (data.srcCode.forwardIfCurrent("remote ")) {
access = Component.ACCESS_REMOTE;
// comments(data);
throw new TemplateException(data.srcCode, "access modifier [remote] not supported in this context");
}
if (!_final && data.srcCode.forwardIfCurrent("final ")) {
_final = true;
comments(data);
}
}
Expression expr = expression(data);
checkSemiColonLineFeed(data, true, true, false);
// variable declaration (variable in body)
if (expr instanceof Variable) {
Variable v = (Variable) expr;
if (ASMUtil.isOnlyDataMember(v)) {
expr = new Assign(v, data.srcCode.getDialect() == CFMLEngine.DIALECT_LUCEE || data.config.getFullNullSupport() ? data.factory.createNull() : data.factory.EMPTY(), data.srcCode.getPosition());
}
}
// if a specific access was defined
if (access > -1 || _final) {
if (!(expr instanceof Assign)) {
data.srcCode.setPos(pos);
throw new TemplateException(data.srcCode, "invalid syntax, access modifier cannot be used in this context");
}
if (access > -1) {
// this is only supported with the Lucee dialect
// if(data.srcCode.getDialect()==CFMLEngine.DIALECT_CFML)
// throw new TemplateException(data.srcCode,
// "invalid syntax, access modifier cannot be used in this context");
((Assign) expr).setAccess(access);
}
if (_final)
((Assign) expr).setModifier(Member.MODIFIER_FINAL);
}
if (expr instanceof FunctionAsExpression)
return ((FunctionAsExpression) expr).getFunction();
return new ExpressionAsStatement(expr);
}
use of lucee.transformer.expression.var.Variable in project Lucee by lucee.
the class AbstrCFMLScriptTransformer method forStatement.
/**
* Liest ein for Statement ein.
* <br />
* EBNF:<br />
* <code>expression spaces ";" spaces condition spaces ";" spaces expression spaces ")" spaces block;</code>
* @return for Statement
* @throws TemplateException
*/
private final Statement forStatement(ExprData data) throws TemplateException {
int pos = data.srcCode.getPos();
// id
String id = variableDec(data, false);
if (id == null) {
data.srcCode.setPos(pos);
return null;
}
if (id.equalsIgnoreCase("for")) {
id = null;
data.srcCode.removeSpace();
if (!data.srcCode.forwardIfCurrent('(')) {
data.srcCode.setPos(pos);
return null;
}
} else {
data.srcCode.removeSpace();
if (!data.srcCode.forwardIfCurrent(':')) {
data.srcCode.setPos(pos);
return null;
}
data.srcCode.removeSpace();
if (!data.srcCode.forwardIfCurrent("for", '(')) {
data.srcCode.setPos(pos);
return null;
}
}
// if(!data.srcCode.forwardIfCurrent("for",'('))
// return null;
Expression left = null;
Body body = new BodyBase(data.factory);
Position line = data.srcCode.getPosition();
comments(data);
if (!data.srcCode.isCurrent(';')) {
// left
left = expression(data);
comments(data);
}
// middle for
if (data.srcCode.forwardIfCurrent(';')) {
Expression cont = null;
Expression update = null;
// condition
comments(data);
if (!data.srcCode.isCurrent(';')) {
cont = condition(data);
comments(data);
}
// middle
if (!data.srcCode.forwardIfCurrent(';'))
throw new TemplateException(data.srcCode, "invalid syntax in for statement");
// update
comments(data);
if (!data.srcCode.isCurrent(')')) {
update = expression(data);
comments(data);
}
// start )
if (!data.srcCode.forwardIfCurrent(')'))
throw new TemplateException(data.srcCode, "invalid syntax in for statement, for statement must end with a [)]");
// ex block
statement(data, body, CTX_FOR);
return new For(data.factory, left, cont, update, body, line, data.srcCode.getPosition(), id);
} else // middle foreach
if (data.srcCode.forwardIfCurrent("in")) {
// condition
comments(data);
Expression value = expression(data);
comments(data);
if (!data.srcCode.forwardIfCurrent(')'))
throw new TemplateException(data.srcCode, "invalid syntax in for statement, for statement must end with a [)]");
// ex block
statement(data, body, CTX_FOR);
if (!(left instanceof Variable))
throw new TemplateException(data.srcCode, "invalid syntax in for statement, left value is invalid");
// throw new TemplateException(data.srcCode,"invalid syntax in for statement, right value is invalid");
return new ForEach((Variable) left, value, body, line, data.srcCode.getPosition(), id);
} else
throw new TemplateException(data.srcCode, "invalid syntax in for statement");
}
use of lucee.transformer.expression.var.Variable in project Lucee by lucee.
the class AbstrCFMLExprTransformer method _divMultiOp.
private Expression _divMultiOp(ExprData data, Expression expr, int iOp) throws TemplateException {
if (data.srcCode.isCurrent('=') && expr instanceof Variable) {
data.srcCode.next();
comments(data);
Expression value = assignOp(data);
return new OPUnary((Variable) expr, value, OPUnary.PRE, iOp, expr.getStart(), data.srcCode.getPosition());
// ExprDouble res = OpDouble.toExprDouble(expr, right,iOp);
// return new OpVariable((Variable)expr,res,data.cfml.getPosition());
}
comments(data);
return OpDouble.toExprDouble(expr, expoOp(data), iOp);
}
use of lucee.transformer.expression.var.Variable in project Lucee by lucee.
the class AbstrCFMLExprTransformer method negatePlusMinusOp.
/**
* Negate Numbers
* @return CFXD Element
* @throws TemplateException
*/
private Expression negatePlusMinusOp(ExprData data) throws TemplateException {
// And Operation
Position line = data.srcCode.getPosition();
if (data.srcCode.forwardIfCurrent('-')) {
// pre increment
if (data.srcCode.forwardIfCurrent('-')) {
comments(data);
Expression expr = clip(data);
return new OPUnary((Variable) expr, data.factory.DOUBLE_ONE(), OPUnary.PRE, OpDouble.MINUS, line, data.srcCode.getPosition());
// ExprDouble res = OpDouble.toExprDouble(expr, LitDouble.toExprDouble(1D),OpDouble.MINUS);
// return new OpVariable((Variable)expr,res,data.cfml.getPosition());
}
comments(data);
return OpNegateNumber.toExprDouble(clip(data), OpNegateNumber.MINUS, line, data.srcCode.getPosition());
} else if (data.srcCode.forwardIfCurrent('+')) {
if (data.srcCode.forwardIfCurrent('+')) {
comments(data);
Expression expr = clip(data);
return new OPUnary((Variable) expr, data.factory.DOUBLE_ONE(), OPUnary.PRE, OpDouble.PLUS, line, data.srcCode.getPosition());
}
comments(data);
// OpNegateNumber.toExprDouble(clip(),OpNegateNumber.PLUS,line);
return data.factory.toExprDouble(clip(data));
}
return clip(data);
}
Aggregations