use of lucee.transformer.expression.literal.Literal 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.expression.literal.Literal in project Lucee by lucee.
the class VariableString method variableToStringArray.
public static String[] variableToStringArray(Variable var, boolean rawIfPossible) throws TransformerException {
List<Member> members = var.getMembers();
List<String> arr = new ArrayList<String>();
if (var.getScope() != Scope.SCOPE_UNDEFINED)
arr.add(ScopeFactory.toStringScope(var.getScope(), "undefined"));
Iterator<Member> it = members.iterator();
DataMember dm;
Expression n;
while (it.hasNext()) {
Object o = it.next();
if (!(o instanceof DataMember))
throw new TransformerException("can't translate Variable to a String", var.getStart());
dm = (DataMember) o;
n = dm.getName();
if (n instanceof Literal) {
if (rawIfPossible && n instanceof Identifier) {
arr.add(((Identifier) n).getRaw());
} else {
arr.add(((Literal) n).getString());
}
} else
throw new TransformerException("argument name must be a constant value", var.getStart());
}
return arr.toArray(new String[arr.size()]);
}
use of lucee.transformer.expression.literal.Literal in project Lucee by lucee.
the class Query method translateChildren.
private void translateChildren(Iterator it) {
Statement stat;
while (it.hasNext()) {
stat = (Statement) it.next();
if (stat instanceof PrintOut) {
PrintOut printOut = ((PrintOut) stat);
Expression e = printOut.getExpr();
if (!(e instanceof Literal)) {
Expression expr = removeCastString(e);
if (expr instanceof Variable) {
// do not preserve BIF PreserveSingleQuotes return value
Member member = ((Variable) expr).getFirstMember();
if (member instanceof BIF) {
BIF bif = (BIF) member;
if (bif.getClassDefinition().getClassName().equals(PreserveSingleQuotes.class.getName())) {
printOut.setExpr(bif.getArguments()[0].getValue());
continue;
} else if (bif.getClassDefinition().getClassName().equals(ListQualify.class.getName())) {
Argument[] args = bif.getArguments();
List<Argument> arr = new ArrayList<Argument>();
// first get existing arguments
arr.add(args[0]);
arr.add(args[1]);
if (args.length >= 3)
arr.add(args[2]);
else
arr.add(new Argument(expr.getFactory().createLitString(","), "string"));
if (args.length >= 4)
arr.add(args[3]);
else
arr.add(new Argument(expr.getFactory().createLitString("all"), "string"));
if (args.length >= 5)
arr.add(args[4]);
else
arr.add(new Argument(expr.getFactory().createLitBoolean(false), "boolean"));
// PSQ-BIF DO NOT REMOVE THIS COMMENT
arr.add(new Argument(expr.getFactory().createLitBoolean(true), "boolean"));
bif.setArguments(arr.toArray(new Argument[arr.size()]));
continue;
} else if (bif.getClassDefinition().getClassName().equals(QuotedValueList.class.getName()) || bif.getClassDefinition().getClassName().equals(ValueList.class.getName())) {
// printOut.setPreserveSingleQuote(false);
continue;
}
}
// do not preserve UDF return value
member = ((Variable) expr).getLastMember();
if (member instanceof UDF)
continue;
}
printOut.setCheckPSQ(true);
if (e != expr)
printOut.setExpr(expr);
}
} else if (stat instanceof Tag) {
Body b = ((Tag) stat).getBody();
if (b != null)
translateChildren(b.getStatements().iterator());
} else if (stat instanceof Body) {
translateChildren(((Body) stat).getStatements().iterator());
}
}
}
use of lucee.transformer.expression.literal.Literal in project Lucee by lucee.
the class DocComment method getHint.
/**
* @return the hint
*/
public String getHint() {
if (hint == null) {
Attribute attr = params.remove("hint");
if (attr != null) {
Literal lit = (Literal) attr.getValue();
hint = lit.getString().trim();
} else {
hint = StringUtil.unwrap(tmpHint.toString());
}
}
return hint;
}
Aggregations