use of lucee.transformer.bytecode.statement.tag.Attribute in project Lucee by lucee.
the class SourceLastModifiedClassAdapter method _createMetaDataStruct.
private static void _createMetaDataStruct(BytecodeContext bc, GeneratorAdapter adapter, int sct, Map attrs) throws TransformerException {
Attribute attr;
Iterator it = attrs.entrySet().iterator();
Entry entry;
while (it.hasNext()) {
entry = (Map.Entry) it.next();
attr = (Attribute) entry.getValue();
adapter.loadLocal(sct);
adapter.push(attr.getName());
if (attr.getValue() instanceof Literal)
ExpressionUtil.writeOutSilent(attr.getValue(), bc, Expression.MODE_REF);
else
adapter.push("[runtime expression]");
adapter.invokeVirtual(Types.STRUCT_IMPL, SET_EL);
adapter.pop();
}
}
use of lucee.transformer.bytecode.statement.tag.Attribute in project Lucee by lucee.
the class SourceLastModifiedClassAdapter method writeOutNewComponent.
private void writeOutNewComponent(ConstrBytecodeContext constr, List<LitString> keys, ClassWriter cw, Tag component, String name) throws TransformerException {
GeneratorAdapter adapter = new GeneratorAdapter(Opcodes.ACC_PUBLIC + Opcodes.ACC_FINAL, NEW_COMPONENT_IMPL_INSTANCE, null, new Type[] { Types.PAGE_EXCEPTION }, cw);
BytecodeContext bc = new BytecodeContext(null, constr, this, keys, cw, name, adapter, NEW_COMPONENT_IMPL_INSTANCE, writeLog(), suppressWSbeforeArg, output, returnValue);
Label methodBegin = new Label();
Label methodEnd = new Label();
adapter.visitLocalVariable("this", "L" + name + ";", null, methodBegin, methodEnd, 0);
ExpressionUtil.visitLine(bc, component.getStart());
adapter.visitLabel(methodBegin);
int comp = adapter.newLocal(Types.COMPONENT_IMPL);
adapter.newInstance(Types.COMPONENT_IMPL);
adapter.dup();
Attribute attr;
// ComponentPage
adapter.visitVarInsn(Opcodes.ALOAD, 0);
adapter.checkCast(Types.COMPONENT_PAGE_IMPL);
// !!! also check CFMLScriptTransformer.addMetaData if you do any change here !!!
// Output
attr = component.removeAttribute("output");
if (attr != null) {
ExpressionUtil.writeOutSilent(attr.getValue(), bc, Expression.MODE_REF);
} else
ASMConstants.NULL(adapter);
// synchronized
attr = component.removeAttribute("synchronized");
if (attr != null)
ExpressionUtil.writeOutSilent(attr.getValue(), bc, Expression.MODE_VALUE);
else
adapter.push(false);
// extends
attr = component.removeAttribute("extends");
if (attr != null)
ExpressionUtil.writeOutSilent(attr.getValue(), bc, Expression.MODE_REF);
else
adapter.push("");
// implements
attr = component.removeAttribute("implements");
if (attr != null)
ExpressionUtil.writeOutSilent(attr.getValue(), bc, Expression.MODE_REF);
else
adapter.push("");
// hint
attr = component.removeAttribute("hint");
if (attr != null) {
Expression value = attr.getValue();
if (!(value instanceof Literal)) {
value = bc.getFactory().createLitString("[runtime expression]");
}
ExpressionUtil.writeOutSilent(value, bc, Expression.MODE_REF);
} else
adapter.push("");
// dspName
attr = component.removeAttribute("displayname");
if (attr == null)
attr = component.getAttribute("display");
if (attr != null)
ExpressionUtil.writeOutSilent(attr.getValue(), bc, Expression.MODE_REF);
else
adapter.push("");
// callpath
adapter.visitVarInsn(Opcodes.ALOAD, 2);
// realpath
adapter.visitVarInsn(Opcodes.ILOAD, 3);
// style
attr = component.removeAttribute("style");
if (attr != null)
ExpressionUtil.writeOutSilent(attr.getValue(), bc, Expression.MODE_REF);
else
adapter.push("");
// persistent
attr = component.removeAttribute("persistent");
boolean persistent = false;
if (attr != null) {
persistent = ASMUtil.toBoolean(attr, component.getStart()).booleanValue();
}
// accessors
attr = component.removeAttribute("accessors");
boolean accessors = false;
if (attr != null) {
accessors = ASMUtil.toBoolean(attr, component.getStart()).booleanValue();
}
// modifier
attr = component.removeAttribute("modifier");
int modifiers = Component.MODIFIER_NONE;
if (attr != null) {
// type already evaluated in evaluator
LitString ls = (LitString) component.getFactory().toExprString(attr.getValue());
modifiers = ComponentUtil.toModifier(ls.getString(), lucee.runtime.Component.MODIFIER_NONE, lucee.runtime.Component.MODIFIER_NONE);
}
adapter.push(persistent);
adapter.push(accessors);
adapter.push(modifiers);
adapter.visitVarInsn(Opcodes.ILOAD, 4);
// adapter.visitVarInsn(Opcodes.ALOAD, 4);
createMetaDataStruct(bc, component.getAttributes(), component.getMetaData());
adapter.invokeConstructor(Types.COMPONENT_IMPL, CONSTR_COMPONENT_IMPL15);
adapter.storeLocal(comp);
// Component Impl(ComponentPage componentPage,boolean output, String extend, String hint, String dspName)
// initComponent(pc,c);
adapter.visitVarInsn(Opcodes.ALOAD, 0);
adapter.loadArg(0);
adapter.loadLocal(comp);
adapter.loadArg(4);
adapter.invokeVirtual(Types.COMPONENT_PAGE_IMPL, INIT_COMPONENT3);
adapter.visitLabel(methodEnd);
// return component;
adapter.loadLocal(comp);
adapter.returnValue();
// ExpressionUtil.visitLine(adapter, component.getEndLine());
adapter.endMethod();
}
use of lucee.transformer.bytecode.statement.tag.Attribute in project Lucee by lucee.
the class CFMLTransformer method attrNoName.
private static void attrNoName(Tag parent, TagLibTag tag, TagData data, TagLibTagAttr attr) throws TemplateException {
if (attr == null)
attr = tag.getFirstAttribute();
String strName = "noname";
String strType = "any";
boolean pe = true;
if (attr != null) {
strName = attr.getName();
strType = attr.getType();
pe = attr.getRtexpr();
}
// LitString.toExprString("",-1);
Attribute att = new Attribute(false, strName, attributeValue(data, tag, strType, pe, true, data.factory.createNull()), strType);
parent.addAttribute(att);
}
use of lucee.transformer.bytecode.statement.tag.Attribute in project Lucee by lucee.
the class CFMLTransformer method attribute.
/**
* Liest ein einzelnes Atribut eines tag ein (nicht NONAME).
* <br />
* EBNF:<br />
* <code>attribute-name spaces "=" spaces attribute-value;</code>
* @param tag Definition des Tag das dieses Attribut enthaelt.
* @param args Container zum Speichern einzelner Attribute Namen zum nachtraeglichen Prufen gegen die Tag-Lib.
* @return Element Attribute Element.
* @throws TemplateException
*/
private static Attribute attribute(TagData data, TagLibTag tag, ArrayList<String> args, RefBoolean allowDefaultValue) throws TemplateException {
Expression value = null;
// Name
StringBuffer sbType = new StringBuffer();
RefBoolean dynamic = new RefBooleanImpl(false);
boolean isDefaultValue = false;
boolean[] parseExpression = new boolean[2];
parseExpression[0] = true;
parseExpression[1] = false;
String name = attributeName(data.srcCode, dynamic, args, tag, sbType, parseExpression, allowDefaultValue.toBooleanValue());
// mixed in a noname attribute
if (StringUtil.isEmpty(name)) {
allowDefaultValue.setValue(false);
TagLibTagAttr attr = tag.getDefaultAttribute();
if (attr == null)
throw new TemplateException(data.srcCode, "Invalid Identifier.");
name = attr.getName();
sbType.append(attr.getType());
isDefaultValue = true;
}
comment(data.srcCode, true);
if (isDefaultValue || data.srcCode.forwardIfCurrent('=')) {
comment(data.srcCode, true);
// Value
value = attributeValue(data, tag, sbType.toString(), parseExpression[0], false, data.factory.createLitString(""));
} else // default value boolean true
{
TagLibTagAttr attr = tag.getAttribute(name);
if (attr != null)
value = attr.getUndefinedValue(data.factory);
else
value = tag.getAttributeUndefinedValue(data.factory);
if (sbType.toString().length() > 0) {
value = CastOther.toExpression(value, sbType.toString());
}
}
comment(data.srcCode, true);
return new Attribute(dynamic.toBooleanValue(), name, value, sbType.toString());
}
use of lucee.transformer.bytecode.statement.tag.Attribute in project Lucee by lucee.
the class Component method evaluate.
@Override
public void evaluate(Tag tag, TagLibTag tlt) throws EvaluatorException {
/*if(tag instanceof TagOther) {
print.e(((TagOther)tag).getFullname());
}*/
TagCIObject tc = (TagCIObject) tag;
Statement pPage = tag.getParent();
// String className=tag.getTagLibTag().getTagClassName();
Page page;
// move components inside script to root
if (pPage instanceof Page) {
page = (Page) pPage;
} else {
// is in script
Tag p = ASMUtil.getParentTag(tag);
if ((pPage = p.getParent()) instanceof Page && p.getTagLibTag().getName().equalsIgnoreCase(((Page) pPage).getSourceCode().getDialect() == CFMLEngine.DIALECT_CFML ? Constants.CFML_SCRIPT_TAG_NAME : Constants.LUCEE_SCRIPT_TAG_NAME)) {
// chnaged order of the condition, not sure if this is ok
page = (Page) pPage;
// move imports from script to component body
List<Statement> children = p.getBody().getStatements();
Iterator<Statement> it = children.iterator();
Statement stat;
Tag t;
while (it.hasNext()) {
stat = it.next();
if (!(stat instanceof Tag))
continue;
t = (Tag) stat;
if (t.getTagLibTag().getName().equals("import")) {
tag.getBody().addStatement(t);
}
}
// move to page
ASMUtil.move(tag, page);
// if(!inline)ASMUtil.replace(p, tag, false);
} else
throw new EvaluatorException("Wrong Context, tag " + tlt.getFullName() + " can't be inside other tags, tag is inside tag " + p.getFullname());
}
// Page page=(Page) pPage;
Boolean insideCITemplate = isInsideCITemplate(page);
boolean main = isMainComponent(page, tc);
// is a full grown component or a inline component
if (insideCITemplate == Boolean.FALSE) {
throw new EvaluatorException("Wrong Context, " + tlt.getFullName() + " tag must be inside a file with the extension " + Constants.getCFMLComponentExtension() + " or " + Constants.getLuceeComponentExtension());
}
// if(count>1)
// throw new EvaluatorException("inside one cfc file only one tag "+tlt.getFullName()+" is allowed, now we have "+count);
boolean isComponent = tlt.getTagClassDefinition().isClassNameEqualTo("lucee.runtime.tag.Component");
/*boolean isInterface="lucee.runtime.tag.Interface".equals(tlt.getTagClassName());
if(main) {
if(isComponent) page.setIsComponent(true);
else if(isInterface) page.setIsInterface(true);
}*/
tc.setMain(main);
// Attributes
// Name
String name = null;
if (!main) {
Map<String, Attribute> attrs = tag.getAttributes();
if (attrs.size() > 0) {
Attribute first = attrs.values().iterator().next();
if (first.isDefaultValue()) {
name = first.getName();
}
}
if (name == null) {
Attribute attr = tag.getAttribute("name");
if (attr != null) {
Expression expr = tag.getFactory().toExprString(attr.getValue());
if (!(expr instanceof LitString))
throw new EvaluatorException("Name of the component " + tlt.getFullName() + ", must be a literal string value");
name = ((LitString) expr).getString();
} else
throw new EvaluatorException("Missing name of the component " + tlt.getFullName() + "");
}
tc.setName(name);
}
// output
// "output=true" is handled in "lucee.transformer.cfml.attributes.impl.Function"
Attribute attr = tag.getAttribute("output");
if (attr != null) {
Expression expr = tag.getFactory().toExprBoolean(attr.getValue());
if (!(expr instanceof LitBoolean))
throw new EvaluatorException("Attribute output of the Tag " + tlt.getFullName() + ", must contain a static boolean value (true or false, yes or no)");
// boolean output = ((LitBoolean)expr).getBooleanValue();
// if(!output) ASMUtil.removeLiterlChildren(tag, true);
}
// extends
attr = tag.getAttribute("extends");
if (attr != null) {
Expression expr = tag.getFactory().toExprString(attr.getValue());
if (!(expr instanceof LitString))
throw new EvaluatorException("Attribute extends of the Tag " + tlt.getFullName() + ", must contain a literal string value");
}
// implements
if (isComponent) {
attr = tag.getAttribute("implements");
if (attr != null) {
Expression expr = tag.getFactory().toExprString(attr.getValue());
if (!(expr instanceof LitString))
throw new EvaluatorException("Attribute implements of the Tag " + tlt.getFullName() + ", must contain a literal string value");
}
}
// modifier
if (isComponent) {
attr = tag.getAttribute("modifier");
if (attr != null) {
Expression expr = tag.getFactory().toExprString(attr.getValue());
if (!(expr instanceof LitString))
throw new EvaluatorException("Attribute modifier of the Tag " + tlt.getFullName() + ", must contain a literal string value");
LitString ls = (LitString) expr;
int mod = ComponentUtil.toModifier(ls.getString(), lucee.runtime.Component.MODIFIER_NONE, -1);
if (mod == -1)
throw new EvaluatorException("Value [" + ls.getString() + "] from attribute modifier of the Tag " + tlt.getFullName() + " is invalid,valid values are [none,abstract,final]");
}
}
}
Aggregations