Package anvil.script.expression

Examples of anvil.script.expression.Node


      context.location(_expression.getLocation());
    }
    if (in_generator) {
   
      if (_index != null) {
        _indexvar.compile(context, new Node()
        {
          public void compile(ByteCompiler context, int operation)
          {
            Code code_ = context.getCode();
            code_.getstatic(code_.getPool().addFieldRef(
              context.TYPE_ANY, "ZERO", "Lanvil/core/Any;"));
          }
        });
        code.pop();
      }

      int clazz1 = pool.addClass("java/util/Enumeration");
      int clazz2 = pool.addClass("anvil/java/util/BindingEnumeration");
      int clazz3 = pool.addClass("anvil/core/AnyBindingEnumeration");
      code.anew(clazz3);
      code.dup();
      _expression.compile(context, Expression.GET);
      code.invokevirtual(pool.addMethodRef(context.TYPE_ANY, "enumeration", "()Lanvil/java/util/BindingEnumeration;"));
      code.invokespecial(pool.addMethodRef(clazz3, "<init>", "(Lanvil/java/util/BindingEnumeration;)V"));
      final int tmp = code.addLocal();
      code.astore(tmp);
      _enumvar.compile(context, new Node()
      {
        public void compile(ByteCompiler context, int operation)
        {
          context.getCode().aload(tmp);
        }
      });
      code.endLocal(tmp);
      code.pop();

      Target start = code.getTarget();
      _startscope = code.getSource();
      _endscope = code.getSource();

      _enumvar.compile(context, Node.GET);
      code.invokeinterface(pool.addInterfaceMethodRef(clazz1, "hasMoreElements", "()Z"));
      code.if_eq(_endscope);

      if (_index != null) {
       
        new AssignmentNode(new ExpressionList(_index,
          new Node() {
            public void compile(ByteCompiler context, int operation)
            {
              _indexvar.compile(context, GET);
            }
          })).compile(context, Node.GET);
         
        code.pop();
       
        _indexvar.compile(context, new Node() {
          public void compile(ByteCompiler context, int operation)
          {
            Code code_ = context.getCode();
            _indexvar.compile(context, GET);
            code_.invokevirtual(code_.getPool().addMethodRef(context.TYPE_ANY,
              "increase", "()Lanvil/core/Any;"));
          }
        });
        code.pop();
      }

      if (_key != null) {
        new AssignmentNode(new ExpressionList(_key,
          new Node() {
            public void compile(ByteCompiler context, int operation)
            {
              Code code_ = context.getCode();
              ConstantPool pool_ = code_.getPool();
              _enumvar.compile(context, Node.GET);
              code_.invokeinterface(pool_.addInterfaceMethodRef("anvil/java/util/BindingEnumeration", "nextKey", "()Ljava/lang/Object;"));
              code_.invokestatic(pool_.addMethodRef(context.TYPE_ANY, "create", "(Ljava/lang/Object;)Lanvil/core/Any;"));
            }
          })).compile(context, Node.GET);
        code.pop();
      }


      if (_value != null) {
        new AssignmentNode(new ExpressionList(_value,
          new Node() {
            public void compile(ByteCompiler context, int operation)
            {
              Code code_ = context.getCode();
              ConstantPool pool_ = code_.getPool();
              _enumvar.compile(context, Node.GET);
              code_.invokeinterface(pool_.addInterfaceMethodRef("java/util/Enumeration", "nextElement", "()Ljava/lang/Object;"));
              code_.invokestatic(pool_.addMethodRef(context.TYPE_ANY, "create", "(Ljava/lang/Object;)Lanvil/core/Any;"));
            }
          })).compile(context, Node.GET);
        code.pop();

      } else
        _enumvar.compile(context, Node.GET);
        code.invokeinterface(pool.addInterfaceMethodRef(clazz1, "nextElement", "()Ljava/lang/Object;"));
        code.pop();

      }

      _statement.compile(context);
      code.go_to(_startscope);
      _endscope.bind();
      _startscope.bind(start);

    } else {

      final int l_enum = code.addLocal();
      final int l_index = (_index != null) ? code.addLocal() : 0;
      if (l_index != 0) {
        code.iconst(0);
        code.istore(l_index);
      }

      // create enumeration, and wrap it
      int clazz1 = pool.addClass("java/util/Enumeration");
      int clazz2 = pool.addClass("anvil/java/util/BindingEnumeration");
      _expression.compile(context, Expression.GET);
      code.invokevirtual(pool.addMethodRef(context.TYPE_ANY, "enumeration", "()Lanvil/java/util/BindingEnumeration;"));
      code.astore(l_enum);
      int sun_hack_1 = 10 + l_enum;

      Target start = code.getTarget();
      _startscope = code.getSource();
      _endscope = code.getSource();

      code.aload(l_enum);
      int sun_hack_2 = 10 + l_enum;
     
      code.invokeinterface(pool.addInterfaceMethodRef(clazz1, "hasMoreElements", "()Z"));
      code.if_eq(_endscope);

      if (_index != null) {
        new AssignmentNode(new ExpressionList(_index,
          new Node() {
            public void compile(ByteCompiler context, int operation)
            {
              Code code_ = context.getCode();
              code_.iload(l_index);
              code_.iinc(l_index, 1);
              code_.invokestatic(code_.getPool().addMethodRef(
                context.TYPE_ANY, "create", "(I)Lanvil/core/Any;"));
            }
          })).compile(context, Node.GET);
        code.pop();
      }

      if (_key != null) {
        new AssignmentNode(new ExpressionList(_key,
          new Node() {
            public void compile(ByteCompiler context, int operation)
            {
              Code code_ = context.getCode();
              ConstantPool pool_ = code_.getPool();
              code_.aload(l_enum);
              code_.invokeinterface(pool_.addInterfaceMethodRef("anvil/java/util/BindingEnumeration", "nextKey", "()Ljava/lang/Object;"));
              code_.invokestatic(pool_.addMethodRef(context.TYPE_ANY, "create", "(Ljava/lang/Object;)Lanvil/core/Any;"));
            }
          })).compile(context, Node.GET);
        code.pop();
      }

      if (_value != null) {
        new AssignmentNode(new ExpressionList(_value,
          new Node() {
            public void compile(ByteCompiler context, int operation)
            {
              Code code_ = context.getCode();
              ConstantPool pool_ = code_.getPool();
              code_.aload(l_enum);
View Full Code Here


          Expression expression = expressionParser.parseExpression();
         
          if (expression.isConstant()) {
            sections.add(new ConstantNode(expression.eval().toString()));
          } else {
            Node child = expression.getChild(0);
            if (child != null) {
              sections.add(child);
            }
          }
          buffer.setLength(0);
View Full Code Here

        }
        break;

      case CompilableFunction.PARAMETER_BOOLEAN:
        if (c<max) {
          Node node = parameters[c++];
          if (node.isConstant()) {
            code.iconst(node.eval().toBoolean());
          } else {
            node.compile(this, Node.GET_BOOLEAN);
          }
        } else {
          if (defaultValue != null) {
            code.iconst(defaultValue.toBoolean());
          } else {
            code.iconst(false);
          }
        }
        break;

      case CompilableFunction.PARAMETER_INT:
        if (c<max) {
          Node node = parameters[c++];
          if (node.isConstant()) {
            code.iconst(node.eval().toInt());
          } else {
            node.compile(this, Node.GET);
            code.invokevirtual(pool.addMethodRef(TYPE_ANY,
              "toInt", "()I"));           
          }
        } else {
          if (defaultValue != null) {
            code.iconst(defaultValue.toInt());
          } else {
            code.iconst(0);
          }
        }
        break;

      case CompilableFunction.PARAMETER_LONG:
        if (c<max) {
          Node node = parameters[c++];
          if (node.isConstant()) {
            code.lconst(node.eval().toLong());
          } else {
            node.compile(this, Node.GET);
            code.invokevirtual(pool.addMethodRef(TYPE_ANY,
              "toLong", "()J"))
          }
        } else {
          if (defaultValue != null) {
            code.lconst(defaultValue.toLong());
          } else {
            code.lconst(0);
          }
        }
        break;

      case CompilableFunction.PARAMETER_DOUBLE:
        if (c<max) {
          Node node = parameters[c++];
          if (node.isConstant()) {
            code.dconst(node.eval().toDouble());
          } else {
            node.compile(this, Node.GET);
            code.invokevirtual(pool.addMethodRef(TYPE_ANY,
              "toDouble", "()D"));
          }
        } else {
          if (defaultValue != null) {
            code.dconst(defaultValue.toDouble());
          } else {
            code.dconst(0.0);
          }
        }
        break;

      case CompilableFunction.PARAMETER_STRING:
        if (c<max) {
          Node node = parameters[c++];
          if (node.isConstant()) {
            code.astring(node.eval().toString());
          } else {
            node.compile(this, Node.GET);
            code.invokevirtual(pool.addMethodRef(TYPE_OBJECT,
              "toString", "()Ljava/lang/String;"));
          }
        } else {
          if (defaultValue != null) {
View Full Code Here

        }
        break;

      case CompilableFunction.PARAMETER_BOOLEAN:
        if (c<max) {
          Node node = parameters[c++];
          if (node.isConstant()) {
            code.iconst(node.eval().toBoolean());
          } else {
            node.compile(this, Node.GET_BOOLEAN);
          }
        } else {
          if (defaultValue != null) {
            code.iconst(defaultValue.toBoolean());
          } else {
            code.iconst(false);
          }
        }
        break;

      case CompilableFunction.PARAMETER_INT:
        if (c<max) {
          Node node = parameters[c++];
          if (node.isConstant()) {
            code.iconst(node.eval().toInt());
          } else {
            node.compile(this, Node.GET);
            code.invokevirtual(pool.addMethodRef(TYPE_ANY,
              "toInt", "()I"));           
          }
        } else {
          if (defaultValue != null) {
            code.iconst(defaultValue.toInt());
          } else {
            code.iconst(0);
          }
        }
        break;

      case CompilableFunction.PARAMETER_LONG:
        if (c<max) {
          Node node = parameters[c++];
          if (node.isConstant()) {
            code.lconst(node.eval().toLong());
          } else {
            node.compile(this, Node.GET);
            code.invokevirtual(pool.addMethodRef(TYPE_ANY,
              "toLong", "()J"))
          }
        } else {
          if (defaultValue != null) {
            code.lconst(defaultValue.toLong());
          } else {
            code.lconst(0);
          }
        }
        break;

      case CompilableFunction.PARAMETER_DOUBLE:
        if (c<max) {
          Node node = parameters[c++];
          if (node.isConstant()) {
            code.dconst(node.eval().toDouble());
          } else {
            node.compile(this, Node.GET);
            code.invokevirtual(pool.addMethodRef(TYPE_ANY,
              "toDouble", "()D"));
          }
        } else {
          if (defaultValue != null) {
            code.dconst(defaultValue.toDouble());
          } else {
            code.dconst(0.0);
          }
        }
        break;

      case CompilableFunction.PARAMETER_STRING:
        if (c<max) {
          Node node = parameters[c++];
          if (node.isConstant()) {
            code.astring(node.eval().toString());
          } else {
            node.compile(this, Node.GET);
            code.invokevirtual(pool.addMethodRef(TYPE_OBJECT,
              "toString", "()Ljava/lang/String;"));
          }
        } else {
          if (defaultValue != null) {
View Full Code Here

        } else {
          value = attr.getDefault();
        }
      }
      if (value != null) {
        Node node = ConstantNode.UNDEFINED;
        switch(attr.getType()) {
        case Attribute.TYPE_STRING:
          node = new ConstantNode(Any.create(value));
          break;
View Full Code Here

        jj_la1[88] = jj_gen;
        break label_31;
      }
      jj_consume_token(FOREACH);
      InlineFunction();
      Node block = pop();
      Node self = pop();
      push(new ForeachNode(self, block));
    }
  }
View Full Code Here

        jj_la1[89] = jj_gen;
        break label_32;
      }
      jj_consume_token(ARROW);
      MappingExpression();
      Node right = pop();
      Node left = pop();
      push(new PipeNode(left, right));
    }
  }
View Full Code Here

        jj_la1[90] = jj_gen;
        break label_33;
      }
      jj_consume_token(MAP);
      ConditionalExpression();
      Node right = pop();
      Node left = pop();
      push(new MappingNode(left, right));
    }
  }
View Full Code Here

      push(new MappingNode(left, right));
    }
  }

  final public void ConditionalExpression() throws ParseException {
  Node right = ConstantNode.UNDEFINED;
  Node left;
  Node middle;
    RangeExpression();
    switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
    case HOOK:
    case HOOKHOOK:
      switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
View Full Code Here

      ;
    }
  }

  final public void RangeExpression() throws ParseException {
  Node right = ConstantNode.INF;
    switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
    case RANGE:
      jj_consume_token(RANGE);
      switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
      case MODULE:
View Full Code Here

TOP

Related Classes of anvil.script.expression.Node

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.