001: /*=============================================================================
002: * Copyright Texas Instruments 2000. 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: * $ProjectHeader: OSCRIPT 0.155 Fri, 20 Dec 2002 18:34:22 -0800 rclark $
019: */
020:
021: package oscript.data;
022:
023: import oscript.exceptions.*;
024:
025: /**
026: * The <code>ConstructorScope</code> to implement the scope for a
027: * constructor, acting as a switch to cause <code>private</code>
028: * variables to be declared in a scope private to the constructor
029: * while <code>public</code> and <code>protected</code> members
030: * are in a scope shared by any parent and child classes.
031: *
032: * @author Rob Clark (rob@ti.com)
033: * @version 1.8
034: */
035: public class ConstructorScope extends FunctionScope {
036: /**
037: * Class Constructor.
038: *
039: * @param fxn the function
040: * @param previous the previous
041: * @param smit shared member idx table
042: */
043: ConstructorScope(Function fxn, Scope previous,
044: oscript.util.SymbolTable smit) {
045: super (fxn, previous, smit);
046: }
047:
048: /**
049: * Create a member of this object with the specified value. This actually
050: * creates the member in the previous scope.
051: *
052: * @param id the id of the symbol that maps to the member
053: * @param attr the attributes of the object (see <code>Reference</code>.)
054: * @see Reference
055: */
056: public Value createMember(int id, int attr) {
057: // if private, member is part of constructor scope (this):
058: if ((attr & Reference.ATTR_PRIVATE) != 0)
059: return super .createMember(id, attr);
060:
061: // else it is a member of the object, as long as it doesn't
062: // eclipse a member of the constructor scope:
063: if (getMemberImpl(id) != null)
064: throw PackagedScriptObjectException
065: .makeExceptionWrapper(new OException("\""
066: + Symbol.getSymbol(id)
067: + "\" would eclipse local"));
068:
069: return previous.createMember(id, attr);
070: }
071:
072: /**
073: * "mixin" the specified variable into the current scope.
074: *
075: * @param val the value to mixin to this scope
076: */
077: public void mixin(Value val) {
078: previous.mixin(val);
079: }
080:
081: /**
082: * Lookup the "this" within a scope. The "this" is actually a union of
083: * this scope which contains private members and args, and the script
084: * object itself.
085: *
086: * @return the "this" ScriptObject within this scope
087: */
088: public Value getThis() {
089: return new OThis(this );
090: }
091: }
092:
093: /*
094: * Local Variables:
095: * tab-width: 2
096: * indent-tabs-mode: nil
097: * mode: java
098: * c-indentation-style: java
099: * c-basic-offset: 2
100: * eval: (c-set-offset 'substatement-open '0)
101: * eval: (c-set-offset 'case-label '+)
102: * eval: (c-set-offset 'inclass '+)
103: * eval: (c-set-offset 'inline-open '0)
104: * End:
105: */
|