001: /*
002: * ------------------------------------------------------------------------
003: * PACKAGE: [incr Tcl]
004: * DESCRIPTION: Object-Oriented Extensions to Tcl
005: *
006: * This file is part of Itcl, it provides access to Jacl fields
007: * and methods that would otherwise only be available to classes
008: * in the tcl.lang package. It also provides some utility
009: * methods that needs access to Jacl internals.
010: *
011: * ========================================================================
012: * AUTHOR: Michael J. McLennan
013: * Bell Labs Innovations for Lucent Technologies
014: * mmclennan@lucent.com
015: * http://www.tcltk.com/itcl
016: *
017: * RCS: $Id: ItclAccess.java,v 1.3 2006/01/26 19:49:18 mdejong Exp $
018: * ========================================================================
019: * Copyright (c) 1993-1998 Lucent Technologies, Inc.
020: * ------------------------------------------------------------------------
021: * See the file "license.itcl" for information on usage and redistribution
022: * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
023: */
024:
025: package tcl.lang;
026:
027: import java.util.HashMap;
028:
029: public class ItclAccess {
030: public static boolean isProcCallFrame(CallFrame frame) {
031: return frame.isProcCallFrame;
032: }
033:
034: public static void setProcCallFrameFalse(CallFrame frame) {
035: frame.isProcCallFrame = false;
036: }
037:
038: public static TclObject[] getCallFrameObjv(CallFrame frame) {
039: return frame.objv;
040: }
041:
042: public static Namespace getCallFrameNamespace(CallFrame frame) {
043: return frame.ns;
044: }
045:
046: public static void setCallFrameObjv(CallFrame frame,
047: TclObject[] objv) {
048: frame.objv = objv;
049: }
050:
051: public static CallFrame getCallFrame(Interp interp, int level) {
052: CallFrame frame;
053:
054: frame = interp.varFrame;
055: while (frame != null && level > 0) {
056: frame = frame.callerVar;
057: level--;
058: }
059: return frame;
060: }
061:
062: public static CallFrame activateCallFrame(Interp interp,
063: CallFrame frame) {
064: CallFrame oldFrame;
065:
066: oldFrame = interp.varFrame;
067: interp.varFrame = frame;
068:
069: return oldFrame;
070: }
071:
072: public static CallFrame newCallFrame(Interp i) {
073: return new CallFrame(i);
074: }
075:
076: public static CallFrame getVarFrame(Interp i) {
077: return i.varFrame;
078: }
079:
080: public static HashMap getVarTable(CallFrame frame) {
081: return frame.varTable;
082: }
083:
084: public static void setVarTable(CallFrame frame, HashMap table) {
085: frame.varTable = table;
086: }
087:
088: public static Var newVar() {
089: return new Var();
090: }
091:
092: public static void deleteVars(Interp interp, HashMap varTable) {
093: Var.deleteVars(interp, varTable);
094: }
095:
096: public static int decrVarRefCount(Var var) {
097: var.refCount -= 1;
098: return var.refCount;
099: }
100:
101: public static Procedure newProcedure(Interp interp, Namespace ns,
102: String name, TclObject args, TclObject b, String sFileName,
103: int sLineNumber) throws TclException {
104: return new Procedure(interp, ns, name, args, b, sFileName,
105: sLineNumber);
106: }
107:
108: public static TclObject[][] getArgList(Procedure proc) {
109: return proc.argList;
110: }
111:
112: public static void setWrappedCommand(Procedure proc,
113: WrappedCommand wcmd) {
114: proc.wcmd = wcmd;
115: }
116:
117: public static void assignLocalVar(Interp interp, String name,
118: TclObject val, CallFrame frame) throws TclException {
119: if (frame.varTable == null) {
120: frame.varTable = new HashMap();
121: }
122: Var var = new Var();
123: var.clearVarInHashtable(); // Needed to avoid "dangling namespace var" error
124: var.table = frame.varTable;
125: frame.varTable.put(name, var);
126: interp.setVar(name, null, val, 0);
127: }
128:
129: public static void createObjVar(Var var, String key, Namespace ns,
130: HashMap table) {
131: var.hashKey = key;
132: var.ns = ns;
133:
134: // NOTE: Tcl reports a "dangling upvar" error for variables
135: // with a null "hPtr" field. Put something non-zero
136: // in here to keep Tcl_SetVar2() happy. The only time
137: // this field is really used is it remove a variable
138: // from the hash table that contains it in CleanupVar,
139: // but since these variables are protected by their
140: // higher refCount, they will not be deleted by CleanupVar
141: // anyway. These variables are unset and removed in
142: // ItclFreeObject().
143:
144: var.table = table;
145: var.refCount = 1; // protect from being deleted
146: }
147:
148: public static void createCommonVar(Var var, String key,
149: Namespace ns, HashMap table) {
150: var.table = table;
151: var.hashKey = key;
152: var.ns = ns;
153:
154: var.setVarNamespace();
155: var.refCount++; // one use by namespace
156: var.refCount++; // another use by class
157: }
158:
159: public static Object FirstHashEntry(HashMap table) {
160: return Namespace.FirstHashEntry(table);
161: }
162:
163: }
|