use of lucee.transformer.expression.ExprString in project Lucee by lucee.
the class Argument method evaluate.
@Override
public void evaluate(Tag tag, TagLibTag libTag) throws EvaluatorException {
String ns = libTag.getTagLib().getNameSpaceAndSeparator();
String functionName = ns + "function";
ASMUtil.isLiteralAttribute(tag, "type", ASMUtil.TYPE_STRING, false, true);
ASMUtil.isLiteralAttribute(tag, "name", ASMUtil.TYPE_STRING, false, true);
// ASMUtil.isLiteralAttribute(tag,"hint",ASMUtil.TYPE_STRING,false,true);
// ASMUtil.isLiteralAttribute(tag,"displayname",ASMUtil.TYPE_STRING,false,true);
// check if default can be converted to a literal value that match the type declration.
checkDefaultValue(tag);
// check attribute passby
Attribute attrPassBy = tag.getAttribute("passby");
if (attrPassBy != null) {
ExprString expr = tag.getFactory().toExprString(attrPassBy.getValue());
if (!(expr instanceof LitString))
throw new EvaluatorException("Attribute passby of the Tag Argument, must be a literal string");
LitString lit = (LitString) expr;
String passBy = lit.getString().toLowerCase().trim();
if (!"value".equals(passBy) && !"ref".equals(passBy) && !"reference".equals(passBy))
throw new EvaluatorException("Attribute passby of the Tag Argument has an invalid value [" + passBy + "], valid values are [reference,value]");
}
// check if tag is direct inside function
if (!ASMUtil.isParentTag(tag, functionName)) {
Tag parent = ASMUtil.getParentTag(tag);
String addText = (parent != null) ? "but tag " + libTag.getFullName() + " is inside tag " + parent.getFullname() + "" : "but tag " + libTag.getFullName() + " has no parent";
throw new EvaluatorException("Wrong Context, tag " + libTag.getFullName() + " must be direct inside a " + functionName + " tag, " + addText);
}
// TODO check if there is a tag other than argument and text before
}
use of lucee.transformer.expression.ExprString in project Lucee by lucee.
the class Argument method checkDefaultValue.
public static void checkDefaultValue(Tag tag) {
Attribute _type = tag.getAttribute("type");
if (_type != null) {
ExprString typeValue = tag.getFactory().toExprString(_type.getValue());
if (typeValue instanceof LitString) {
String strType = ((LitString) typeValue).getString();
Attribute _default = tag.getAttribute("default");
if (_default != null) {
Expression defaultValue = _default.getValue();
if (defaultValue instanceof LitString) {
String strDefault = ((LitString) defaultValue).getString();
// check for boolean
if ("boolean".equalsIgnoreCase(strType)) {
if ("true".equalsIgnoreCase(strDefault) || "yes".equalsIgnoreCase(strDefault))
tag.addAttribute(new Attribute(_default.isDynamicType(), _default.getName(), tag.getFactory().TRUE(), _default.getType()));
if ("false".equalsIgnoreCase(strDefault) || "no".equalsIgnoreCase(strDefault))
tag.addAttribute(new Attribute(_default.isDynamicType(), _default.getName(), tag.getFactory().FALSE(), _default.getType()));
}
// check for numbers
if ("number".equalsIgnoreCase(strType) || "numeric".equalsIgnoreCase(strType)) {
Double dbl = Caster.toDouble(strDefault, null);
if (dbl != null) {
tag.addAttribute(new Attribute(_default.isDynamicType(), _default.getName(), tag.getFactory().createLitDouble(dbl.doubleValue()), _default.getType()));
}
}
}
}
}
}
}
use of lucee.transformer.expression.ExprString 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.ExprString in project Lucee by lucee.
the class Interface method evaluate.
@Override
public void evaluate(Tag tag, TagLibTag libTag) throws EvaluatorException {
super.evaluate(tag, libTag);
Body body = tag.getBody();
List<Statement> statments = body.getStatements();
Statement stat;
Iterator<Statement> it = statments.iterator();
Tag t;
while (it.hasNext()) {
stat = it.next();
if (stat instanceof PrintOut) {
// body.remove(stat);
} else if (stat instanceof Tag) {
t = (Tag) stat;
if (stat instanceof TagImport) {
// ignore
} else if (stat instanceof TagFunction) {
Function.throwIfNotEmpty(t);
Attribute attr = t.getAttribute("access");
if (attr != null) {
ExprString expr = t.getFactory().toExprString(attr.getValue());
if (!(expr instanceof LitString))
throw new EvaluatorException("the attribute access of the Tag function inside an interface must contain a constant value");
String access = ((LitString) expr).getString().trim();
if (!"public".equalsIgnoreCase(access))
throw new EvaluatorException("the attribute access of the tag function inside an interface definition can only have the value [public] not [" + access + "]");
} else
t.addAttribute(new Attribute(false, "access", stat.getFactory().createLitString("public"), "string"));
} else
throw new EvaluatorException("tag " + libTag.getFullName() + " can only contain function definitions.");
}
}
}
use of lucee.transformer.expression.ExprString in project Lucee by lucee.
the class AbstrCFMLExprTransformer method newOp.
private Expression newOp(ExprData data, Expression expr) throws TemplateException {
if (!(expr instanceof Variable))
return expr;
Variable var = (Variable) expr;
Member m = var.getFirstMember();
if (!(m instanceof DataMember))
return expr;
ExprString n = ((DataMember) m).getName();
if (!(n instanceof LitString))
return expr;
LitString ls = (LitString) n;
if (!"new".equalsIgnoreCase(ls.getString()))
return expr;
int start = data.srcCode.getPos();
ExprString exprName = readComponentPath(data);
if (exprName == null) {
data.srcCode.setPos(start);
return expr;
}
comments(data);
if (data.srcCode.isCurrent('(')) {
FunctionMember func = getFunctionMember(data, Identifier.toIdentifier(data.factory, "_createComponent", Identifier.CASE_ORIGNAL, null, null), true);
func.addArgument(new Argument(exprName, "string"));
Variable v = expr.getFactory().createVariable(expr.getStart(), expr.getEnd());
v.addMember(func);
comments(data);
return v;
}
data.srcCode.setPos(start);
return expr;
}
Aggregations