001: /*=============================================================================
002: * Copyright Texas Instruments 2004. All Rights Reserved.
003: *
004: * This program is free software; you can redistribute it and/or
005: * modify it under the terms of the GNU Lesser General Public
006: * License as published by the Free Software Foundation; either
007: * version 2 of the License, or (at your option) any later version.
008: *
009: * This program is distributed in the hope that it will be useful,
010: * but WITHOUT ANY WARRANTY; without even the implied warranty of
011: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
012: * Lesser General Public License for more details.
013: *
014: * You should have received a copy of the GNU Lesser General Public
015: * License along with this library; if not, write to the Free Software
016: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
017: */
018:
019: package oscript.compiler;
020:
021: import oscript.data.*;
022: import oscript.util.*;
023: import oscript.*;
024: import oscript.fs.AbstractFile;
025: import oscript.exceptions.PackagedScriptObjectException;
026: import oscript.parser.ParseException;
027:
028: /**
029: * In an effort to generate fewer classes, and improve startup performance,
030: * functions within the file/function node that is passed to the compiler
031: * generate additional <tt>evalNodeX</tt> methods within the same class that
032: * is generated for the parent. But since we still need individual
033: * {@link NodeEvaluator}s for each function, this class acts as a lightweight
034: * wrapper object which forwards the {@link #evalNode} method to the appropriate
035: * {@link CompiledNodeEvaluator#evalInnerNode}
036: *
037: * @author Rob Clark (rob@ti.com)
038: * @version 1
039: */
040: public class CompiledInnerNodeEvaluator extends NodeEvaluator {
041: private int id;
042: private int idx;
043: private CompiledNodeEvaluator cne;
044:
045: /*=======================================================================*/
046: /**
047: * Class Constructor.
048: *
049: * @param id the function name symbol id
050: * @param idx the index to pass back to {@link CompiledNodeEvaluator#evalInnerNode}
051: * @param cne the compiled node which contains the compiled code
052: */
053: public CompiledInnerNodeEvaluator(int id, int idx,
054: CompiledNodeEvaluator cne) {
055: super ();
056:
057: this .id = id;
058: this .idx = idx;
059: this .cne = cne;
060: }
061:
062: /*=======================================================================*/
063: /**
064: * Get the file that this node was parsed from.
065: *
066: * @return the file
067: */
068: public AbstractFile getFile() {
069: // the file is always the same as the parent
070: return cne.getFile();
071: }
072:
073: /*=======================================================================*/
074: /**
075: * Get the function symbol (name), if this node evaluator is a function,
076: * otherwise return <code>-1</code>.
077: *
078: * @return the symbol, or <code>-1</code>
079: */
080: public int getId() {
081: return id;
082: }
083:
084: /*=======================================================================*/
085: /**
086: * Evaluate, in the specified scope. If this is a function, the Arguments
087: * to the function, etc., are defined in the <code>scope</code> that the
088: * function is evaluated in.
089: *
090: * @param sf the stack frame to evaluate the node in
091: * @param scope the scope to evaluate the function in
092: * @return the result of evaluating the function
093: */
094: public Object evalNode(StackFrame sf, Scope scope)
095: throws PackagedScriptObjectException {
096: return cne.evalInnerNode(idx, sf, scope);
097: }
098:
099: /*=======================================================================*/
100: /**
101: * Get the SMIT for the scope(s) created when invoking this node evaluator.
102: *
103: * @param perm <code>PRIVATE</code>, <code>PUBPROT</code>,
104: * <code>ALL</code>
105: */
106: public SymbolTable getSharedMemberIndexTable(int perm) {
107: return cne.getInnerSharedMemberIndexTable(idx, perm);
108: }
109: }
110:
111: /*
112: * Local Variables:
113: * tab-width: 2
114: * indent-tabs-mode: nil
115: * mode: java
116: * c-indentation-style: java
117: * c-basic-offset: 2
118: * eval: (c-set-offset 'substatement-open '0)
119: * eval: (c-set-offset 'case-label '+)
120: * eval: (c-set-offset 'inclass '+)
121: * eval: (c-set-offset 'inline-open '0)
122: * End:
123: */
|