001: /*
002: * $Id: PostfixIncrementNode.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 PostfixIncrementNode
023: *
024: * @author: Jani Lehtimäki
025: */
026: public class PostfixIncrementNode extends UnaryParent {
027: protected Location _location;
028:
029: public PostfixIncrementNode(Location location, Node child) {
030: super (child);
031: _location = location;
032: }
033:
034: public int typeOf() {
035: return Node.EXPR_POSTFIX_INCREMENT;
036: }
037:
038: public boolean isConstant() {
039: return false;
040: }
041:
042: public void check(ErrorListener listener) {
043: super .check(listener);
044: if (!_child.isUpdatable()) {
045: listener.error(_location,
046: "Left side of '++' is not an updatable expression");
047: }
048: }
049:
050: public void compile(ByteCompiler context, int operation) {
051: Code code = context.getCode();
052: ConstantPool pool = code.getPool();
053: final Node child = _child;
054: switch (child.typeOf()) {
055: case Node.EXPR_VARIABLE: {
056: final int tmp = code.addLocal();
057: child.compile(context, GET);
058: code.astore(tmp);
059: child.compile(context, new Node() {
060: public void compile(ByteCompiler context, int operation) {
061: Code code = context.getCode();
062: code.aload(tmp);
063: code.invokevirtual(code.getPool().addMethodRef(
064: context.TYPE_ANY, "increase",
065: "()Lanvil/core/Any;"));
066: }
067: });
068: code.pop();
069: code.aload(tmp);
070: code.endLocal(tmp);
071: }
072: break;
073:
074: case Node.EXPR_ATTRIBUTE: {
075: AttributeNode attr = (AttributeNode) child;
076: attr.getChild().compile(context, GET);
077: code.astring(attr.getAttribute());
078: code.aload_first();
079: code
080: .invokestatic(pool
081: .addMethodRef(context.TYPE_CONTEXT,
082: "postinc",
083: "(Lanvil/core/Any;Ljava/lang/String;Lanvil/script/Context;)Lanvil/core/Any;"));
084: }
085: break;
086:
087: case Node.EXPR_REFERENCE: {
088: ReferenceNode ref = (ReferenceNode) child;
089: ref.getLeft().compile(context, GET);
090: ref.getRight().compile(context, GET);
091: code.aload_first();
092: code
093: .invokestatic(pool
094: .addMethodRef(context.TYPE_CONTEXT,
095: "postinc",
096: "(Lanvil/core/Any;Lanvil/core/Any;Lanvil/script/Context;)Lanvil/core/Any;"));
097: }
098: break;
099:
100: default:
101: child.compile(context, operation);
102: }
103: if (operation == GET_BOOLEAN) {
104: context.any2boolean();
105: }
106: }
107:
108: }
|