Package org.lilystudio.smarty4j.expression

Examples of org.lilystudio.smarty4j.expression.IExpression


        continue;
      }
      case '.': {
        if (type != STRING) {
          c = line.charAt(start + 1);
          IExpression exp;
          if (c == '`') {
            words[wordSize] = null;
            int pos = findExpression(line, start + 2, end, words, wordSize, '`');
            Object o = words[wordSize];
            if (o == null) {
View Full Code Here


      for (int index = 3; index + 2 < wordSize; index += 3) {
        Object name = words[index];
        if ((name instanceof String) && Operation.C_SET == words[index + 1]) {
          // 将函数值转换成指定的数据类型
          Object word = words[index + 2];
          IExpression value;
          if (word instanceof IExpression) {
            value = (IExpression) word;
          } else if (Operation.C_SUB == word) {
            word = words[index + 3];
            index++;
View Full Code Here

      // 字符串比较exp1与exp2
      // }
      Label isString = new Label();
      Label end = new Label();

      IExpression first;
      IExpression second;
      if (exp1IsNumber) {
        first = exp2;
        second = exp1;
      } else {
        first = exp1;
        second = exp2;
      }

      first.parse(mw, local, variableNames);
      mw.visitInsn(DUP);

      mw.visitMethodInsn(INVOKESTATIC, NAME, "isNumeric",
          "(Ljava/lang/Object;)Z");
      mw.visitJumpInsn(IFEQ, isString);

      mw.visitMethodInsn(INVOKESTATIC, NAME, "o2d", "(Ljava/lang/Object;)D");
      second.parseDouble(mw, local, variableNames);
      checkDouble(mw, exp1IsNumber);
      mw.visitJumpInsn(GOTO, end);

      mw.visitLabel(isString);
      mw.visitMethodInsn(INVOKESTATIC, NAME, "o2s",
          "(Ljava/lang/Object;)Ljava/lang/String;");
      second.parseString(mw, local, variableNames);
      checkString(mw, exp1IsNumber);

      mw.visitLabel(end);
    } else {
      // if (弱类型(exp1) && 弱类型(exp2) instanceof
View Full Code Here

    // context.getCaptures().put(name,
    // childWriter);
    // }
    mw.visitVarInsn(ALOAD, WRITER);
    mw.visitVarInsn(ALOAD, CONTEXT);
    IExpression assign = getParameter(1);
    if (assign != null) {
      assign.parse(mw, local, variableNames);
    } else {
      mw.visitMethodInsn(INVOKEVIRTUAL, Context.NAME, "getCaptures",
          "()Ljava/util/Map;");
      getParameter(0).parse(mw, local, variableNames);
    }
View Full Code Here

      throws ParseException {
    int index = expressionSize - param;
    if (index < 0) {
      throw new ParseException("运算符参数不足");
    }
    IExpression exp = expressions[index];
    switch (type) {
    case -1:
      if (exp instanceof ConstInteger) {
        ((ConstInteger) exp).inverse();
      } else if (exp instanceof ConstDouble) {
View Full Code Here

  @Override
  public void parse(MethodVisitor mw, int local,
      Map<String, Integer> variableNames) {
    Integer oldNameValue = null;

    IExpression name = getParameter(1);

    Label isnull = new Label();
    Label loopstart = new Label();
    Label end = new Label();

    getParameter(5).parse(mw, local, variableNames);
    mw.visitJumpInsn(IFEQ, end);

    getParameter(0).parseObject(mw, local, variableNames);
    mw.visitVarInsn(ASTORE, local);
    mw.visitVarInsn(ALOAD, local);
    mw.visitJumpInsn(IFNULL, isnull);

    if (variableNames != null) {
      oldNameValue = variableNames.get(name.toString());
      variableNames.put(name.toString(), Integer.valueOf(local + 1));
    } else {
      // 保存原始的循环变量名值
      mw.visitVarInsn(ALOAD, CONTEXT);
      name.parse(mw, local + 1, variableNames);
      mw.visitInsn(DUP2);
      mw.visitMethodInsn(INVOKEVIRTUAL, Context.NAME, "get",
          "(Ljava/lang/String;)Ljava/lang/Object;");
    }

    // 生成用于循环的数组
    mw.visitVarInsn(ALOAD, local);
    getParameter(2).parse(mw, local + 1, variableNames);
    getParameter(3).parse(mw, local + 1, variableNames);
    getParameter(4).parse(mw, local + 1, variableNames);
    mw.visitMethodInsn(INVOKESTATIC, NAME, "getLooper",
        "(Ljava/lang/Object;III)[Ljava/lang/Object;");

    mw.visitInsn(DUP);
    mw.visitInsn(ARRAYLENGTH);
    mw.visitVarInsn(ISTORE, local);
    mw.visitInsn(ICONST_0);

    mw.visitLabel(loopstart);
    mw.visitInsn(DUP);
    mw.visitVarInsn(ILOAD, local);
    mw.visitJumpInsn(IF_ICMPEQ, endLabel);

    mw.visitInsn(DUP2);
    mw.visitInsn(AALOAD);
    if (variableNames != null) {
      mw.visitVarInsn(ASTORE, local + 1);
    } else {
      mw.visitVarInsn(ALOAD, CONTEXT);
      mw.visitInsn(SWAP);
      name.parse(mw, local + 2, variableNames);
      mw.visitInsn(SWAP);
      mw.visitMethodInsn(INVOKEVIRTUAL, Context.NAME, "set",
          "(Ljava/lang/String;Ljava/lang/Object;)V");
    }
    super.parse(mw, local + 2, variableNames);
    mw.visitLabel(startLabel);
    mw.visitInsn(ICONST_1);
    mw.visitInsn(IADD);
    mw.visitJumpInsn(GOTO, loopstart);

    // 循环结束, 恢复恢复过程中被设置的属性的原始值
    mw.visitLabel(endLabel);
    restore(mw, variableNames);
    mw.visitJumpInsn(GOTO, end);

    // 循环源集合为空时的处理
    mw.visitLabel(isnull);
    if (elseBlock != null) {
      elseBlock.parse(mw, local, variableNames);
    }

    mw.visitLabel(end);

    if (variableNames != null) {
      variableNames.put(name.toString(), oldNameValue);
    }
  }
View Full Code Here

      Map<String, Integer> variableNames) {
    // if (delimiter != null) {
    // value = value.toString().split(delimiter);
    // }
    // context.set(var, value);
    IExpression delimiter = getParameter(2);

    mw.visitVarInsn(ALOAD, CONTEXT);
    IExpression var = getParameter(0);
    var.parse(mw, local, variableNames);
    getParameter(1).parseObject(mw, local, variableNames);

    if (delimiter != null) {
      mw.visitMethodInsn(INVOKEVIRTUAL, "java/lang/Object", "toString",
          "()Ljava/lang/String;");
      delimiter.parse(mw, local, variableNames);
      mw.visitMethodInsn(INVOKEVIRTUAL, "java/lang/String", "split",
          "(Ljava/lang/String;)[Ljava/lang/String;");
    }

    Integer index = variableNames == null ? null : variableNames.get(var
        .toString());
    if (index != null) {
      mw.visitInsn(DUP);
      mw.visitVarInsn(ASTORE, index);
    }
View Full Code Here

  public void parse(MethodVisitor mw, int local,
      Map<String, Integer> variableNames) {
    Integer oldItemValue = null;
    Integer oldKeyValue = null;

    IExpression item = getParameter(1);
    IExpression key = getParameter(2);

    Label isnull = new Label();
    Label isnotmap = new Label();
    Label loopinit = new Label();
    Label setstart = new Label();
    Label setend = new Label();
    Label setlist = new Label();
    Label loopend = new Label();
    Label end = new Label();

    getParameter(0).parseObject(mw, local, variableNames);
    mw.visitVarInsn(ASTORE, local);
    mw.visitVarInsn(ALOAD, local);
    mw.visitJumpInsn(IFNULL, isnull);

    if (variableNames != null) {
      oldItemValue = variableNames.get(item.toString());
      variableNames.put(item.toString(), Integer.valueOf(local + 1));
      if (key != null) {
        oldKeyValue = variableNames.get(key.toString());
        variableNames.put(key.toString(), Integer.valueOf(local + 2));
      }
    } else {
      // 保存原始的循环变量名值
      mw.visitVarInsn(ALOAD, CONTEXT);
      item.parse(mw, local + 1, variableNames);
      mw.visitInsn(DUP2);
      mw.visitMethodInsn(INVOKEVIRTUAL, Context.NAME, "get",
          "(Ljava/lang/String;)Ljava/lang/Object;");
      if (key != null) {
        mw.visitVarInsn(ALOAD, CONTEXT);
        key.parse(mw, local + 2, variableNames);
        mw.visitInsn(DUP2);
        mw.visitMethodInsn(INVOKEVIRTUAL, Context.NAME, "get",
            "(Ljava/lang/String;)Ljava/lang/Object;");
      }
    }

    mw.visitVarInsn(ALOAD, local);
    mw.visitMethodInsn(INVOKESTATIC, NAME, "getLooper",
        "(Ljava/lang/Object;)[Ljava/lang/Object;");
    mw.visitVarInsn(ALOAD, local);
    mw.visitTypeInsn(INSTANCEOF, "java/util/Map");
    mw.visitJumpInsn(IFEQ, isnotmap);
    mw.visitVarInsn(ALOAD, local);
    mw.visitTypeInsn(CHECKCAST, "java/util/Map");
    mw.visitJumpInsn(GOTO, loopinit);

    mw.visitLabel(isnotmap);
    mw.visitInsn(ACONST_NULL);

    mw.visitLabel(loopinit);
    mw.visitVarInsn(ASTORE, local);
    mw.visitInsn(DUP);
    mw.visitInsn(ARRAYLENGTH);
    mw.visitInsn(ICONST_0);
    mw.visitVarInsn(ISTORE, local + 3);

    mw.visitLabel(setstart);
    mw.visitInsn(DUP2);
    mw.visitVarInsn(ILOAD, local + 3);
    mw.visitJumpInsn(IF_ICMPEQ, loopend);

    if (getParameter(3) != null) {
      mw.visitVarInsn(ASTORE, local + 4);
      mw.visitInsn(DUP);
      mw.visitVarInsn(ALOAD, CONTEXT);
      mw.visitInsn(SWAP);
      getParameter(3).parse(mw, local + 5, variableNames);
      mw.visitVarInsn(ILOAD, local + 3);
      mw.visitMethodInsn(INVOKEVIRTUAL, Context.NAME, "setForeach",
          "(ILjava/lang/String;I)V");
      mw.visitVarInsn(ALOAD, local + 4);
    }

    if (variableNames == null) {
      mw.visitVarInsn(ALOAD, CONTEXT);
      mw.visitInsn(SWAP);
      item.parse(mw, local + 4, variableNames);
      mw.visitInsn(SWAP);
    }
    mw.visitVarInsn(ILOAD, local + 3);
    mw.visitInsn(AALOAD);
    mw.visitVarInsn(ALOAD, local);
    mw.visitJumpInsn(IFNULL, setlist);

    // 循环源集合是Map型时所执行的处理
    if (key != null) {
      mw.visitInsn(DUP);
      mw.visitMethodInsn(INVOKEINTERFACE, "java/util/Map$Entry", "getKey",
          "()Ljava/lang/Object;");
      // 是否设置主键的值
      if (variableNames != null) {
        mw.visitVarInsn(ASTORE, local + 2);
      } else {
        mw.visitVarInsn(ALOAD, CONTEXT);
        mw.visitInsn(SWAP);
        key.parse(mw, local + 4, variableNames);
        mw.visitInsn(SWAP);
        mw.visitMethodInsn(INVOKEVIRTUAL, Context.NAME, "set",
            "(Ljava/lang/String;Ljava/lang/Object;)V");
      }
    }
    mw.visitMethodInsn(INVOKEINTERFACE, "java/util/Map$Entry", "getValue",
        "()Ljava/lang/Object;");
    mw.visitJumpInsn(GOTO, setend);

    // 循环源集合是List型时所执行的处理
    mw.visitLabel(setlist);
    if (key != null) {
      if (variableNames == null) {
        // 是否设置主键的值, 按数字编号
        mw.visitVarInsn(ALOAD, CONTEXT);
        key.parse(mw, local + 4, variableNames);
      }
      mw.visitVarInsn(ILOAD, local + 3);
      mw.visitMethodInsn(INVOKESTATIC, "java/lang/Integer", "valueOf",
          "(I)Ljava/lang/Integer;");
      if (variableNames != null) {
        mw.visitVarInsn(ASTORE, local + 2);
      } else {
        mw.visitMethodInsn(INVOKEVIRTUAL, Context.NAME, "set",
            "(Ljava/lang/String;Ljava/lang/Object;)V");
      }
    }

    mw.visitLabel(setend);
    if (variableNames != null) {
      mw.visitVarInsn(ASTORE, local + 1);
    } else {
      mw.visitMethodInsn(INVOKEVIRTUAL, Context.NAME, "set",
          "(Ljava/lang/String;Ljava/lang/Object;)V");
    }
    super.parse(mw, local + 4, variableNames);
    mw.visitLabel(startLabel);
    mw.visitIincInsn(local + 3, 1);
    mw.visitJumpInsn(GOTO, setstart);

    mw.visitLabel(loopend);
    mw.visitInsn(POP);
    // 循环结束, 恢复恢复过程中被设置的属性的原始值
    mw.visitLabel(endLabel);
    restore(mw, variableNames);
    mw.visitJumpInsn(GOTO, end);

    // 循环源集合为空时的处理
    mw.visitLabel(isnull);
    if (elseBlock != null) {
      elseBlock.parse(mw, local, variableNames);
    }

    mw.visitLabel(end);

    if (variableNames != null) {
      variableNames.put(item.toString(), oldItemValue);
      if (key != null) {
        variableNames.put(key.toString(), oldKeyValue);
      }
    }
  }
View Full Code Here

TOP

Related Classes of org.lilystudio.smarty4j.expression.IExpression

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.