001: /*
002: * $Id: PrefixIncrementNode.java,v 1.7 2002/09/16 08:05:05 jkl Exp $
003: *
004: * Copyright (c) 2002 Njet Communications Ltd. All Rights Reserved.
005: *
006: * Use is subject to license terms, as defined in
007: * Anvil Sofware License, Version 1.1. See LICENSE
008: * file, or http://njet.org/license-1.1.txt
009: */
010: package anvil.script.expression;
011:
012: import anvil.ErrorListener;
013: import anvil.Location;
014: import anvil.core.Any;
015: import anvil.codec.Code;
016: import anvil.codec.ConstantPool;
017: import anvil.script.compiler.ByteCompiler;
018: import anvil.script.Context;
019: import java.io.IOException;
020:
021: /**
022: * class PrefixIncrementNode
023: *
024: * @author: Jani Lehtimäki
025: */
026: public class PrefixIncrementNode extends UnaryParent {
027:
028: protected Location _location;
029:
030: public PrefixIncrementNode(Location location, Node child) {
031: super (child);
032: _location = location;
033: }
034:
035: public int typeOf() {
036: return Node.EXPR_PREFIX_INCREMENT;
037: }
038:
039: public boolean isConstant() {
040: return false;
041: }
042:
043: public void check(ErrorListener listener) {
044: super .check(listener);
045: if (!_child.isUpdatable()) {
046: listener
047: .error(_location,
048: "Right side of '++' is not an updatable expression");
049: }
050: }
051:
052: public void compile(ByteCompiler context, int operation) {
053: Code code = context.getCode();
054: ConstantPool pool = code.getPool();
055: final Node child = _child;
056: switch (child.typeOf()) {
057: case Node.EXPR_VARIABLE: {
058: child.compile(context, new Node() {
059: public void compile(ByteCompiler context, int operation) {
060: Code code = context.getCode();
061: child.compile(context, GET);
062: code.invokevirtual(code.getPool().addMethodRef(
063: context.TYPE_ANY, "increase",
064: "()Lanvil/core/Any;"));
065: }
066: });
067: }
068: break;
069:
070: case Node.EXPR_ATTRIBUTE: {
071: AttributeNode attr = (AttributeNode) child;
072: attr.getChild().compile(context, GET);
073: code.astring(attr.getAttribute());
074: code.aload_first();
075: code
076: .invokestatic(pool
077: .addMethodRef(context.TYPE_CONTEXT,
078: "preinc",
079: "(Lanvil/core/Any;Ljava/lang/String;Lanvil/script/Context;)Lanvil/core/Any;"));
080: }
081: break;
082:
083: case Node.EXPR_REFERENCE: {
084: ReferenceNode ref = (ReferenceNode) child;
085: ref.getLeft().compile(context, GET);
086: ref.getRight().compile(context, GET);
087: code.aload_first();
088: code
089: .invokestatic(pool
090: .addMethodRef(context.TYPE_CONTEXT,
091: "preinc",
092: "(Lanvil/core/Any;Lanvil/core/Any;Lanvil/script/Context;)Lanvil/core/Any;"));
093: }
094: break;
095:
096: default:
097: child.compile(context, operation);
098: }
099: if (operation == GET_BOOLEAN) {
100: context.any2boolean();
101: }
102: }
103:
104: }
|