use of lucee.transformer.bytecode.StaticBody 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.bytecode.StaticBody in project Lucee by lucee.
the class Static method getStaticBody.
static StaticBody getStaticBody(Body body) {
Iterator<Statement> it = body.getStatements().iterator();
Statement s;
while (it.hasNext()) {
s = it.next();
if (s instanceof StaticBody)
return (StaticBody) s;
}
StaticBody sb = new StaticBody(body.getFactory());
body.addStatement(sb);
return sb;
}
use of lucee.transformer.bytecode.StaticBody in project Lucee by lucee.
the class TagCIObject method getStaticBodies.
public List<StaticBody> getStaticBodies() {
Body b = getBody();
List<StaticBody> list = null;
if (!ASMUtil.isEmpty(b)) {
Statement stat;
Iterator<Statement> it = b.getStatements().iterator();
while (it.hasNext()) {
stat = it.next();
// StaticBody
if (stat instanceof StaticBody) {
it.remove();
if (list == null)
list = new ArrayList<StaticBody>();
list.add((StaticBody) stat);
// return (StaticBody) stat;
}
}
}
return list;
}
use of lucee.transformer.bytecode.StaticBody in project Lucee by lucee.
the class Static method evaluate.
@Override
public void evaluate(Tag tag, TagLibTag libTag) throws EvaluatorException {
// check parent
Body body = null;
String compName = Property.getComponentName(tag);
boolean isCompChild = false;
Tag p = ASMUtil.getParentTag(tag);
if (p != null && (p instanceof TagComponent || getFullname(p, "").equalsIgnoreCase(compName))) {
isCompChild = true;
body = p.getBody();
}
Tag pp = p != null ? ASMUtil.getParentTag(p) : null;
if (!isCompChild && pp != null && (p instanceof TagComponent || getFullname(pp, "").equalsIgnoreCase(compName))) {
isCompChild = true;
body = pp.getBody();
}
if (!isCompChild) {
throw new EvaluatorException("Wrong Context for the the static constructor, " + "a static constructor must inside a component body.");
}
// Body body=(Body) tag.getParent();
List<Statement> children = tag.getBody().getStatements();
// remove that tag from parent
ASMUtil.remove(tag);
StaticBody sb = getStaticBody(body);
ASMUtil.addStatements(sb, children);
}
Aggregations