Пример #1
0
  @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;
  }
Пример #2
0
  /**
   * @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));
    }
  }
Пример #3
0
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;
  }
}
Пример #4
0
 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;
 }
Пример #5
0
  @Override
  public void evaluate(Tag tag, TagLibTag libTag) throws EvaluatorException {
    String ns = libTag.getTagLib().getNameSpaceAndSeparator();
    String loopName = ns + "loop";
    String whileName = ns + "while";

    // label
    String label = null;

    Attribute attrLabel = tag.getAttribute("label");
    if (attrLabel != null) {
      TagBreak tb = (TagBreak) tag;
      label = variableToString(tag, attrLabel, null);
      if (label != null) {
        tb.setLabel(label = label.trim());
        tag.removeAttribute("label");
      } else if (ASMUtil.isLiteralAttribute(tag, attrLabel, ASMUtil.TYPE_STRING, false, true)) {
        LitString ls = (LitString) CastString.toExprString(tag.getAttribute("label").getValue());
        label = ls.getString();
        if (!StringUtil.isEmpty(label, true)) {
          tb.setLabel(label = label.trim());
          tag.removeAttribute("label");
        } else label = null;
      }
    }

    // no base tag found
    if (!ASMUtil.hasAncestorBreakFCStatement(tag, label)) {
      if (tag.isScriptBase()) {
        if (StringUtil.isEmpty(label))
          throw new EvaluatorException(
              "Wrong Context, " + libTag.getName() + " must be inside a looping statement or tag");
        throw new EvaluatorException(
            "Wrong Context, "
                + libTag.getName()
                + " must be inside a looping statement or tag with the label ["
                + label
                + "]");
      }

      if (StringUtil.isEmpty(label))
        throw new EvaluatorException(
            "Wrong Context, tag "
                + libTag.getFullName()
                + " must be inside a "
                + loopName
                + " or "
                + whileName
                + " tag");
      throw new EvaluatorException(
          "Wrong Context, tag "
              + libTag.getFullName()
              + " must be inside a "
              + loopName
              + " or "
              + whileName
              + " tag with the label ["
              + label
              + "]");
    }
  }