001: /* -*- Mode: java; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
002: *
003: * ***** BEGIN LICENSE BLOCK *****
004: * Version: MPL 1.1/GPL 2.0
005: *
006: * The contents of this file are subject to the Mozilla Public License Version
007: * 1.1 (the "License"); you may not use this file except in compliance with
008: * the License. You may obtain a copy of the License at
009: * http://www.mozilla.org/MPL/
010: *
011: * Software distributed under the License is distributed on an "AS IS" basis,
012: * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
013: * for the specific language governing rights and limitations under the
014: * License.
015: *
016: * The Original Code is Rhino code, released
017: * May 6, 1999.
018: *
019: * The Initial Developer of the Original Code is
020: * Netscape Communications Corporation.
021: * Portions created by the Initial Developer are Copyright (C) 1997-1999
022: * the Initial Developer. All Rights Reserved.
023: *
024: * Contributor(s):
025: * Norris Boyd
026: * Roger Lawrence
027: *
028: * Alternatively, the contents of this file may be used under the terms of
029: * the GNU General Public License Version 2 or later (the "GPL"), in which
030: * case the provisions of the GPL are applicable instead of those above. If
031: * you wish to allow use of your version of this file only under the terms of
032: * the GPL and not to allow others to use your version of this file under the
033: * MPL, indicate your decision by deleting the provisions above and replacing
034: * them with the notice and other provisions required by the GPL. If you do
035: * not delete the provisions above, a recipient may use your version of this
036: * file under either the MPL or the GPL.
037: *
038: * ***** END LICENSE BLOCK ***** */
039:
040: package org.mozilla.javascript;
041:
042: import java.util.ArrayList;
043: import java.util.HashMap;
044:
045: public class FunctionNode extends ScriptOrFnNode {
046:
047: public FunctionNode(String name) {
048: super (Token.FUNCTION);
049: functionName = name;
050: }
051:
052: public String getFunctionName() {
053: return functionName;
054: }
055:
056: public boolean requiresActivation() {
057: return itsNeedsActivation;
058: }
059:
060: public boolean getIgnoreDynamicScope() {
061: return itsIgnoreDynamicScope;
062: }
063:
064: public boolean isGenerator() {
065: return itsIsGenerator;
066: }
067:
068: public void addResumptionPoint(Node target) {
069: if (generatorResumePoints == null)
070: generatorResumePoints = new ArrayList();
071: generatorResumePoints.add(target);
072: }
073:
074: public ArrayList getResumptionPoints() {
075: return generatorResumePoints;
076: }
077:
078: public HashMap getLiveLocals() {
079: return liveLocals;
080: }
081:
082: public void addLiveLocals(Node node, int[] locals) {
083: if (liveLocals == null)
084: liveLocals = new HashMap();
085: liveLocals.put(node, locals);
086: }
087:
088: /**
089: * There are three types of functions that can be defined. The first
090: * is a function statement. This is a function appearing as a top-level
091: * statement (i.e., not nested inside some other statement) in either a
092: * script or a function.
093: *
094: * The second is a function expression, which is a function appearing in
095: * an expression except for the third type, which is...
096: *
097: * The third type is a function expression where the expression is the
098: * top-level expression in an expression statement.
099: *
100: * The three types of functions have different treatment and must be
101: * distinguished.
102: */
103: public static final int FUNCTION_STATEMENT = 1;
104: public static final int FUNCTION_EXPRESSION = 2;
105: public static final int FUNCTION_EXPRESSION_STATEMENT = 3;
106:
107: public int getFunctionType() {
108: return itsFunctionType;
109: }
110:
111: String functionName;
112: int itsFunctionType;
113: boolean itsNeedsActivation;
114: boolean itsIgnoreDynamicScope;
115: boolean itsIsGenerator;
116: ArrayList generatorResumePoints;
117: HashMap liveLocals;
118: }
|