001: /*
002: * $Id: AttributeNode.java,v 1.9 2002/09/16 08:05:04 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.core.Any;
013: import anvil.codec.Code;
014: import anvil.script.compiler.ByteCompiler;
015: import anvil.script.Context;
016: import java.io.IOException;
017:
018: /**
019: * class AttributeNode
020: *
021: * @author: Jani Lehtimäki
022: */
023: public class AttributeNode extends UnaryParent {
024:
025: private String _attribute;
026:
027: public AttributeNode(Node self, String attribute) {
028: super (self);
029: _attribute = attribute;
030: }
031:
032: public String getAttribute() {
033: return _attribute;
034: }
035:
036: public int typeOf() {
037: return EXPR_ATTRIBUTE;
038: }
039:
040: public boolean isConstant() {
041: return false;
042: }
043:
044: public Node optimize() {
045: optimizeChilds();
046: return this ;
047: }
048:
049: public void compile(ByteCompiler context, int operation) {
050: Code code = context.getCode();
051: switch (operation) {
052: case GET:
053: _child.compile(context, GET);
054: code.aload_first();
055: code.astring(_attribute);
056: code
057: .invokevirtual(code
058: .getPool()
059: .addMethodRef(context.TYPE_ANY,
060: "getAttribute",
061: "(Lanvil/script/Context;Ljava/lang/String;)Lanvil/core/Any;"));
062: break;
063:
064: case GET_BOOLEAN:
065: _child.compile(context, GET);
066: code.aload_first();
067: code.astring(_attribute);
068: code
069: .invokevirtual(code
070: .getPool()
071: .addMethodRef(context.TYPE_ANY,
072: "getAttribute",
073: "(Lanvil/script/Context;Ljava/lang/String;)Lanvil/core/Any;"));
074: context.any2boolean();
075: break;
076:
077: case CHECK:
078: _child.compile(context, GET);
079: code.aload_first();
080: code.astring(_attribute);
081: code
082: .invokevirtual(code
083: .getPool()
084: .addMethodRef(context.TYPE_ANY,
085: "checkAttribute",
086: "(Lanvil/script/Context;Ljava/lang/String;)Lanvil/core/Any;"));
087: break;
088:
089: case DELETE:
090: _child.compile(context, GET);
091: code.aload_first();
092: code.astring(_attribute);
093: code.invokevirtual(code.getPool().addMethodRef(
094: context.TYPE_ANY, "deleteAttribute",
095: "(Lanvil/script/Context;Ljava/lang/String;)Z"));
096: break;
097: }
098: }
099:
100: }
|