use of lucee.transformer.expression.Expression in project Lucee by lucee.
the class Function method addAttribute.
public final void addAttribute(Attribute attr) throws TemplateException {
String name = attr.getName().toLowerCase();
// name
if ("name".equals(name)) {
throw new TransformerException("name cannot be defined twice", getStart());
} else if ("returntype".equals(name)) {
this.returnType = toLitString(name, attr.getValue());
} else if ("access".equals(name)) {
LitString ls = toLitString(name, attr.getValue());
String strAccess = ls.getString();
int acc = ComponentUtil.toIntAccess(strAccess, -1);
if (acc == -1)
throw new TransformerException("invalid access type [" + strAccess + "], access types are remote, public, package, private", getStart());
access = acc;
} else if ("output".equals(name))
this.output = toLitBoolean(name, attr.getValue());
else if ("bufferoutput".equals(name))
this.bufferOutput = toLitBoolean(name, attr.getValue());
else if ("displayname".equals(name))
this.displayName = toLitString(name, attr.getValue());
else if ("hint".equals(name))
this.hint = toLitString(name, attr.getValue());
else if ("description".equals(name))
this.description = toLitString(name, attr.getValue());
else if ("returnformat".equals(name))
this.returnFormat = toLitString(name, attr.getValue());
else if ("securejson".equals(name))
this.secureJson = toLitBoolean(name, attr.getValue());
else if ("verifyclient".equals(name))
this.verifyClient = toLitBoolean(name, attr.getValue());
else if ("localmode".equals(name)) {
Expression v = attr.getValue();
if (v != null) {
String str = ASMUtil.toString(v, null);
if (!StringUtil.isEmpty(str)) {
int mode = AppListenerUtil.toLocalMode(str, -1);
if (mode != -1)
this.localMode = v.getFactory().createLitInteger(mode);
else
throw new TransformerException("Attribute localMode of the Tag Function, must be a literal value (modern, classic, true or false)", getStart());
}
}
} else if ("cachedwithin".equals(name)) {
try {
// ASMUtil.timeSpanToLong(attr.getValue());
this.cachedWithin = ASMUtil.cachedWithinValue(attr.getValue());
} catch (EvaluatorException e) {
throw new TemplateException(e.getMessage());
}
} else if ("modifier".equals(name)) {
Expression val = attr.getValue();
if (val instanceof Literal) {
Literal l = (Literal) val;
String str = StringUtil.emptyIfNull(l.getString()).trim();
if ("abstract".equalsIgnoreCase(str))
modifier = Component.MODIFIER_ABSTRACT;
else if ("final".equalsIgnoreCase(str))
modifier = Component.MODIFIER_FINAL;
}
} else {
// needed for testing
toLitString(name, attr.getValue());
if (metadata == null)
metadata = new HashMap<String, Attribute>();
metadata.put(attr.getName(), attr);
}
}
use of lucee.transformer.expression.Expression in project Lucee by lucee.
the class BodyBase method concatPrintouts.
private boolean concatPrintouts(String str) {
if (last instanceof PrintOut) {
PrintOut po = (PrintOut) last;
Expression expr = po.getExpr();
if (expr instanceof LitString) {
LitString lit = (LitString) expr;
if (lit.getString().length() < 1024) {
po.setExpr(lit.getFactory().createLitString(lit.getString().concat(str), lit.getStart(), lit.getEnd()));
return true;
}
}
}
return false;
}
use of lucee.transformer.expression.Expression 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.Expression 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.Expression in project Lucee by lucee.
the class AbstrCFMLExprTransformer method concatOp.
/**
* Transfomiert eine Konkatinations-Operator (&) Operation. Im Gegensatz zu CFMX ,
* wird das "!" Zeichen auch als Not Operator anerkannt.
* <br />
* EBNF:<br />
* <code>plusMinusOp {"&" spaces concatOp};</code>
* @return CFXD Element
* @throws TemplateException
*/
private Expression concatOp(ExprData data) throws TemplateException {
Expression expr = plusMinusOp(data);
while (data.srcCode.isCurrent('&') && !data.srcCode.isCurrent("&&")) {
data.srcCode.next();
// &=
if (data.srcCode.isCurrent('=') && expr instanceof Variable) {
data.srcCode.next();
comments(data);
Expression value = assignOp(data);
expr = new OPUnary((Variable) expr, value, OPUnary.PRE, OPUnary.CONCAT, expr.getStart(), data.srcCode.getPosition());
// ExprString res = OpString.toExprString(expr, right);
// expr=new OpVariable((Variable)expr,res,data.cfml.getPosition());
} else {
comments(data);
expr = data.factory.opString(expr, plusMinusOp(data));
}
}
return expr;
}
Aggregations