use of lucee.transformer.expression.literal.Literal in project Lucee by lucee.
the class Function method evaluate.
@Override
public void evaluate(Tag tag, TagLibTag libTag, FunctionLib[] flibs) throws EvaluatorException {
// Body p=(Body) tag.getParent();
// Statement pp = p.getParent();
boolean isCI = true;
try {
isCI = ASMUtil.getAncestorPage(tag).isComponent() || ASMUtil.getAncestorPage(tag).isInterface();
} catch (TransformerException e) {
}
Attribute attrName = tag.getAttribute("name");
if (attrName != null) {
Expression expr = attrName.getValue();
PageSource ps = null;
if (expr instanceof LitString && !isCI) {
Page p = ASMUtil.getAncestorPage(tag, null);
if (p != null) {
SourceCode sc = p.getSourceCode();
if (sc instanceof PageSourceCode) {
PageSourceCode psc = (PageSourceCode) sc;
ps = psc.getPageSource();
}
}
checkFunctionName(((LitString) expr).getString(), flibs, ps);
}
}
// attribute modifier
boolean isStatic = false;
{
Attribute attrModifier = tag.getAttribute("modifier");
if (attrModifier != null) {
ExprString expr = tag.getFactory().toExprString(attrModifier.getValue());
if (!(expr instanceof Literal))
throw new EvaluatorException("Attribute modifier of the Tag Function, must be one of the following literal string values: [abstract,final,static]");
String modifier = StringUtil.emptyIfNull(((Literal) expr).getString()).trim();
if (!StringUtil.isEmpty(modifier) && !"abstract".equalsIgnoreCase(modifier) && !"final".equalsIgnoreCase(modifier) && !"static".equalsIgnoreCase(modifier))
throw new EvaluatorException("Attribute modifier of the Tag Function, must be one of the following literal string values: [abstract,final,static]");
isStatic = "static".equalsIgnoreCase(modifier);
boolean abstr = "abstract".equalsIgnoreCase(modifier);
if (abstr)
throwIfNotEmpty(tag);
}
}
// cachedWithin
{
Attribute attrCachedWithin = tag.getAttribute("cachedwithin");
if (attrCachedWithin != null) {
Expression val = attrCachedWithin.getValue();
tag.addAttribute(new Attribute(attrCachedWithin.isDynamicType(), attrCachedWithin.getName(), ASMUtil.cachedWithinValue(val), attrCachedWithin.getType()));
}
}
// Attribute localMode
{
Attribute attrLocalMode = tag.getAttribute("localmode");
if (attrLocalMode != null) {
Expression expr = attrLocalMode.getValue();
String str = ASMUtil.toString(expr, null);
if (!StringUtil.isEmpty(str) && AppListenerUtil.toLocalMode(str, -1) == -1)
throw new EvaluatorException("Attribute localMode of the Tag Function, must be a literal value (modern, classic, true or false)");
// boolean output = ((LitBoolean)expr).getBooleanValue();
// if(!output) ASMUtil.removeLiterlChildren(tag, true);
}
}
// Attribute Output
{
Attribute attrOutput = tag.getAttribute("output");
if (attrOutput != null) {
Expression expr = tag.getFactory().toExprBoolean(attrOutput.getValue());
if (!(expr instanceof LitBoolean))
throw new EvaluatorException("Attribute output of the Tag Function, must be a literal boolean value (true or false, yes or no)");
}
}
// Buffer output
{
Attribute attrBufferOutput = tag.getAttribute("bufferoutput");
if (attrBufferOutput != null) {
Expression expr = tag.getFactory().toExprBoolean(attrBufferOutput.getValue());
if (!(expr instanceof LitBoolean))
throw new EvaluatorException("Attribute bufferOutput of the Tag Function, must be a literal boolean value (true or false, yes or no)");
}
}
// check attribute values
Map<String, Attribute> attrs = tag.getAttributes();
Iterator<Attribute> it = attrs.values().iterator();
while (it.hasNext()) {
checkAttributeValue(tag, it.next());
}
// add to static scope
if (isStatic) {
// remove that tag from parent
ASMUtil.remove(tag);
Body body = (Body) tag.getParent();
StaticBody sb = Static.getStaticBody(body);
sb.addStatement(tag);
}
}
use of lucee.transformer.expression.literal.Literal in project Lucee by lucee.
the class Output method evaluate.
@Override
public void evaluate(Tag tag, TagLibTag libTag, FunctionLib[] flibs) throws EvaluatorException {
TagOutput output = (TagOutput) tag;
// check if inside a query tag
TagOutput parent = output;
// encodeFor
Attribute encodeFor = tag.getAttribute("encodefor");
if (encodeFor != null) {
Expression encodeForValue = CastString.toExprString(encodeFor.getValue());
if (encodeForValue instanceof Literal) {
Literal l = (Literal) encodeForValue;
short df = (short) -1;
short encType = ESAPIEncode.toEncodeType(l.getString(), df);
if (encType != df)
encodeForValue = encodeForValue.getFactory().createLitInteger(encType);
}
addEncodeToChildren(tag.getBody().getStatements().iterator(), encodeForValue, getEncodeForFunction(flibs));
}
// query
boolean hasParentWithGroup = false;
boolean hasParentWithQuery = false;
boolean hasQuery = tag.containsAttribute("query");
while ((parent = getParentTagOutput(parent)) != null) {
if (!hasParentWithQuery)
hasParentWithQuery = parent.hasQuery();
if (!hasParentWithGroup)
hasParentWithGroup = parent.hasGroup();
if (hasParentWithQuery && hasParentWithGroup)
break;
}
if (hasQuery && hasParentWithQuery)
throw new EvaluatorException("Nesting of tags cfoutput with attribute query is not allowed");
if (hasQuery)
output.setType(TagOutput.TYPE_QUERY);
else if (tag.containsAttribute("group") && hasParentWithQuery)
output.setType(TagOutput.TYPE_GROUP);
else if (hasParentWithQuery) {
if (hasParentWithGroup)
output.setType(TagOutput.TYPE_INNER_GROUP);
else
output.setType(TagOutput.TYPE_INNER_QUERY);
} else
output.setType(TagOutput.TYPE_NORMAL);
// attribute maxrows and endrow not allowd at the same time
if (tag.containsAttribute("maxrows") && tag.containsAttribute("endrow"))
throw new EvaluatorException("Wrong Context, you cannot use attribute maxrows and endrow at the same time.");
}
use of lucee.transformer.expression.literal.Literal in project Lucee by lucee.
the class Output method addEncodeToChildren.
private void addEncodeToChildren(Iterator it, Expression encodeForValue, FunctionLibFunction encodeForBIF) {
Statement stat;
while (it.hasNext()) {
stat = (Statement) it.next();
if (stat instanceof PrintOut) {
PrintOut printOut = ((PrintOut) stat);
Expression e = removeCastString(printOut.getExpr());
if (!(e instanceof Literal)) {
if (e instanceof Variable) {
Member member = ((Variable) e).getFirstMember();
if (member instanceof BIF) {
BIF bif = (BIF) member;
String cn = bif.getClassDefinition().getClassName();
if (cn.startsWith(ENCODE_FOR) || cn.equals(ESAPIEncode.class.getName())) {
continue;
}
}
}
printOut.setEncodeFor(encodeForValue);
}
} else if (stat instanceof Tag) {
Body b = ((Tag) stat).getBody();
if (b != null)
addEncodeToChildren(b.getStatements().iterator(), encodeForValue, encodeForBIF);
} else if (stat instanceof Body) {
addEncodeToChildren(((Body) stat).getStatements().iterator(), encodeForValue, encodeForBIF);
}
}
}
use of lucee.transformer.expression.literal.Literal in project Lucee by lucee.
the class OpString method toExprString.
public static ExprString toExprString(Expression left, Expression right, boolean concatStatic) {
if (concatStatic && left instanceof Literal && right instanceof Literal) {
String l = ((Literal) left).getString();
String r = ((Literal) right).getString();
if ((l.length() + r.length()) <= MAX_SIZE)
return left.getFactory().createLitString(l.concat(r), left.getStart(), right.getEnd());
}
return new OpString(left, right);
}
use of lucee.transformer.expression.literal.Literal in project Lucee by lucee.
the class ExpressionAsStatement method _writeOut.
/**
* @see lucee.transformer.bytecode.statement.StatementBase#_writeOut(org.objectweb.asm.commons.GeneratorAdapter)
*/
@Override
public void _writeOut(BytecodeContext bc) throws TransformerException {
GeneratorAdapter adapter = bc.getAdapter();
int rtn = bc.getReturn();
// set rtn
if (rtn > -1) {
Type type = expr.writeOut(bc, Expression.MODE_REF);
bc.getAdapter().storeLocal(rtn);
} else {
if (!(expr instanceof Literal)) {
Type type = expr.writeOut(bc, Expression.MODE_VALUE);
if (!type.equals(Types.VOID)) {
ASMUtil.pop(adapter, type);
}
}
}
}
Aggregations