@Override public Type _writeOut(BytecodeContext bc, int mode) throws BytecodeException { int form = VALUE; int type = STRING; if (name instanceof Variable && !((Variable) name).fromHash()) { GeneratorAdapter adapter = bc.getAdapter(); String[] arr = VariableString.variableToStringArray((Variable) name, true); if (arr.length > 1) { form = ARRAY; ArrayVisitor av = new ArrayVisitor(); av.visitBegin(adapter, Types.STRING, arr.length); for (int y = 0; y < arr.length; y++) { av.visitBeginItem(adapter, y); adapter.push(varKeyUpperCase ? arr[y].toUpperCase() : arr[y]); av.visitEndItem(bc.getAdapter()); } av.visitEnd(); } else { // VariableString.toExprString(name).writeOut(bc, MODE_REF); String str = VariableString.variableToString((Variable) name, true); name = LitString.toExprString(varKeyUpperCase ? str.toUpperCase() : str); type = Variable.registerKey(bc, VariableString.toExprString(name)) ? KEY : STRING; } } else { // CastString.toExprString(name).writeOut(bc, MODE_REF); type = Variable.registerKey(bc, CastString.toExprString(name)) ? KEY : STRING; } // name.writeOut(bc, MODE_REF); super._writeOut(bc, MODE_REF); // bc.getAdapter().push(variableString); bc.getAdapter().invokeStatic(TYPE_FUNCTION_VALUE, NEW_INSTANCE[type][form]); return Types.FUNCTION_VALUE; }
/** * @see * railo.transformer.cfml.evaluator.EvaluatorSupport#evaluate(railo.transformer.bytecode.statement.tag.Tag, * railo.transformer.library.tag.TagLibTag, railo.transformer.library.function.FunctionLib[]) */ public void evaluate(Tag tag, TagLibTag tagLibTag, FunctionLib[] flibs) throws EvaluatorException { String id = "sprite_" + IDGenerator.intId(); try { Page page = ASMUtil.getAncestorPage(tag); String key = Md5.getDigestAsString(Thread.currentThread().getId() + ":" + page.getSource()); Expression src = tag.getAttribute("src").getValue(); // get data from previous sprites Previous previous = sprites.get(key); if (previous != null) { previous.tag.removeAttribute("_ids"); previous.tag.removeAttribute("_srcs"); previous.tag = tag; } else { sprites.put(key, previous = new Previous(tag)); } previous.ids.add(id); if (previous.src == null) previous.src = src; else { previous.src = OpString.toExprString(previous.src, DELIMITER); previous.src = OpString.toExprString(previous.src, src); } tag.addAttribute(new Attribute(false, "_id", LitString.toExprString(id), "string")); tag.addAttribute( new Attribute( false, "_ids", LitString.toExprString( railo.runtime.type.util.ListUtil.listToList(previous.ids, ",")), "string")); tag.addAttribute(new Attribute(false, "_srcs", previous.src, "string")); } catch (Throwable e) { // TODO handle Excpetion much more precise throw new PageRuntimeException(Caster.toPageException(e)); } }
public final class Sprite extends EvaluatorSupport { private static final Expression DELIMITER = LitString.toExprString(","); private static Map<String, Previous> sprites = new HashMap<String, Previous>(); /** * @see * railo.transformer.cfml.evaluator.EvaluatorSupport#evaluate(railo.transformer.bytecode.statement.tag.Tag, * railo.transformer.library.tag.TagLibTag, railo.transformer.library.function.FunctionLib[]) */ public void evaluate(Tag tag, TagLibTag tagLibTag, FunctionLib[] flibs) throws EvaluatorException { String id = "sprite_" + IDGenerator.intId(); try { Page page = ASMUtil.getAncestorPage(tag); String key = Md5.getDigestAsString(Thread.currentThread().getId() + ":" + page.getSource()); Expression src = tag.getAttribute("src").getValue(); // get data from previous sprites Previous previous = sprites.get(key); if (previous != null) { previous.tag.removeAttribute("_ids"); previous.tag.removeAttribute("_srcs"); previous.tag = tag; } else { sprites.put(key, previous = new Previous(tag)); } previous.ids.add(id); if (previous.src == null) previous.src = src; else { previous.src = OpString.toExprString(previous.src, DELIMITER); previous.src = OpString.toExprString(previous.src, src); } tag.addAttribute(new Attribute(false, "_id", LitString.toExprString(id), "string")); tag.addAttribute( new Attribute( false, "_ids", LitString.toExprString( railo.runtime.type.util.ListUtil.listToList(previous.ids, ",")), "string")); tag.addAttribute(new Attribute(false, "_srcs", previous.src, "string")); } catch (Throwable e) { // TODO handle Excpetion much more precise throw new PageRuntimeException(Caster.toPageException(e)); } } private static class Previous { public Previous(Tag tag) { this.tag = tag; } private List<String> ids = new ArrayList<String>(); private Expression src = null; private Tag tag; } }
public NamedArgument(Expression name, Expression value, String type, boolean varKeyUpperCase) { super(value, type); this.name = name instanceof Null ? LitString.toExprString(varKeyUpperCase ? "NULL" : "null") : name; this.varKeyUpperCase = varKeyUpperCase; }