📄 tclint.h
字号:
union { Tcl_Obj *objPtr; /* The variable's object value. Used for * scalar variables and array elements. */ Tcl_HashTable *tablePtr;/* For array variables, this points to * information about the hash table used * to implement the associative array. * Points to malloc-ed data. */ struct Var *linkPtr; /* If this is a global variable being * referred to in a procedure, or a variable * created by "upvar", this field points to * the referenced variable's Var struct. */ } value; char *name; /* NULL if the variable is in a hashtable, * otherwise points to the variable's * name. It is used, e.g., by TclLookupVar * and "info locals". The storage for the * characters of the name is not owned by * the Var and must not be freed when * freeing the Var. */ Namespace *nsPtr; /* Points to the namespace that contains * this variable or NULL if the variable is * a local variable in a Tcl procedure. */ Tcl_HashEntry *hPtr; /* If variable is in a hashtable, either the * hash table entry that refers to this * variable or NULL if the variable has been * detached from its hash table (e.g. an * array is deleted, but some of its * elements are still referred to in * upvars). NULL if the variable is not in a * hashtable. This is used to delete an * variable from its hashtable if it is no * longer needed. */ int refCount; /* Counts number of active uses of this * variable, not including its entry in the * call frame or the hash table: 1 for each * additional variable whose linkPtr points * here, 1 for each nested trace active on * variable, and 1 if the variable is a * namespace variable. This record can't be * deleted until refCount becomes 0. */ VarTrace *tracePtr; /* First in list of all traces set for this * variable. */ ArraySearch *searchPtr; /* First in list of all searches active * for this variable, or NULL if none. */ int flags; /* Miscellaneous bits of information about * variable. See below for definitions. */} Var;/* * Flag bits for variables. The first three (VAR_SCALAR, VAR_ARRAY, and * VAR_LINK) are mutually exclusive and give the "type" of the variable. * VAR_UNDEFINED is independent of the variable's type. * * VAR_SCALAR - 1 means this is a scalar variable and not * an array or link. The "objPtr" field points * to the variable's value, a Tcl object. * VAR_ARRAY - 1 means this is an array variable rather * than a scalar variable or link. The * "tablePtr" field points to the array's * hashtable for its elements. * VAR_LINK - 1 means this Var structure contains a * pointer to another Var structure that * either has the real value or is itself * another VAR_LINK pointer. Variables like * this come about through "upvar" and "global" * commands, or through references to variables * in enclosing namespaces. * VAR_UNDEFINED - 1 means that the variable is in the process * of being deleted. An undefined variable * logically does not exist and survives only * while it has a trace, or if it is a global * variable currently being used by some * procedure. * VAR_IN_HASHTABLE - 1 means this variable is in a hashtable and * the Var structure is malloced. 0 if it is * a local variable that was assigned a slot * in a procedure frame by the compiler so the * Var storage is part of the call frame. * VAR_TRACE_ACTIVE - 1 means that trace processing is currently * underway for a read or write access, so * new read or write accesses should not cause * trace procedures to be called and the * variable can't be deleted. * VAR_ARRAY_ELEMENT - 1 means that this variable is an array * element, so it is not legal for it to be * an array itself (the VAR_ARRAY flag had * better not be set). * VAR_NAMESPACE_VAR - 1 means that this variable was declared * as a namespace variable. This flag ensures * it persists until its namespace is * destroyed or until the variable is unset; * it will persist even if it has not been * initialized and is marked undefined. * The variable's refCount is incremented to * reflect the "reference" from its namespace. * * The following additional flags are used with the CompiledLocal type * defined below: * * VAR_ARGUMENT - 1 means that this variable holds a procedure * argument. * VAR_TEMPORARY - 1 if the local variable is an anonymous * temporary variable. Temporaries have a NULL * name. * VAR_RESOLVED - 1 if name resolution has been done for this * variable. */#define VAR_SCALAR 0x1#define VAR_ARRAY 0x2#define VAR_LINK 0x4#define VAR_UNDEFINED 0x8#define VAR_IN_HASHTABLE 0x10#define VAR_TRACE_ACTIVE 0x20#define VAR_ARRAY_ELEMENT 0x40#define VAR_NAMESPACE_VAR 0x80#define VAR_ARGUMENT 0x100#define VAR_TEMPORARY 0x200#define VAR_RESOLVED 0x400 /* * Macros to ensure that various flag bits are set properly for variables. * The ANSI C "prototypes" for these macros are: * * EXTERN void TclSetVarScalar _ANSI_ARGS_((Var *varPtr)); * EXTERN void TclSetVarArray _ANSI_ARGS_((Var *varPtr)); * EXTERN void TclSetVarLink _ANSI_ARGS_((Var *varPtr)); * EXTERN void TclSetVarArrayElement _ANSI_ARGS_((Var *varPtr)); * EXTERN void TclSetVarUndefined _ANSI_ARGS_((Var *varPtr)); * EXTERN void TclClearVarUndefined _ANSI_ARGS_((Var *varPtr)); */#define TclSetVarScalar(varPtr) \ (varPtr)->flags = ((varPtr)->flags & ~(VAR_ARRAY|VAR_LINK)) | VAR_SCALAR#define TclSetVarArray(varPtr) \ (varPtr)->flags = ((varPtr)->flags & ~(VAR_SCALAR|VAR_LINK)) | VAR_ARRAY#define TclSetVarLink(varPtr) \ (varPtr)->flags = ((varPtr)->flags & ~(VAR_SCALAR|VAR_ARRAY)) | VAR_LINK#define TclSetVarArrayElement(varPtr) \ (varPtr)->flags = ((varPtr)->flags & ~VAR_ARRAY) | VAR_ARRAY_ELEMENT#define TclSetVarUndefined(varPtr) \ (varPtr)->flags |= VAR_UNDEFINED#define TclClearVarUndefined(varPtr) \ (varPtr)->flags &= ~VAR_UNDEFINED/* * Macros to read various flag bits of variables. * The ANSI C "prototypes" for these macros are: * * EXTERN int TclIsVarScalar _ANSI_ARGS_((Var *varPtr)); * EXTERN int TclIsVarLink _ANSI_ARGS_((Var *varPtr)); * EXTERN int TclIsVarArray _ANSI_ARGS_((Var *varPtr)); * EXTERN int TclIsVarUndefined _ANSI_ARGS_((Var *varPtr)); * EXTERN int TclIsVarArrayElement _ANSI_ARGS_((Var *varPtr)); * EXTERN int TclIsVarTemporary _ANSI_ARGS_((Var *varPtr)); * EXTERN int TclIsVarArgument _ANSI_ARGS_((Var *varPtr)); * EXTERN int TclIsVarResolved _ANSI_ARGS_((Var *varPtr)); */ #define TclIsVarScalar(varPtr) \ ((varPtr)->flags & VAR_SCALAR)#define TclIsVarLink(varPtr) \ ((varPtr)->flags & VAR_LINK)#define TclIsVarArray(varPtr) \ ((varPtr)->flags & VAR_ARRAY)#define TclIsVarUndefined(varPtr) \ ((varPtr)->flags & VAR_UNDEFINED)#define TclIsVarArrayElement(varPtr) \ ((varPtr)->flags & VAR_ARRAY_ELEMENT)#define TclIsVarTemporary(varPtr) \ ((varPtr)->flags & VAR_TEMPORARY) #define TclIsVarArgument(varPtr) \ ((varPtr)->flags & VAR_ARGUMENT) #define TclIsVarResolved(varPtr) \ ((varPtr)->flags & VAR_RESOLVED)/* *---------------------------------------------------------------- * Data structures related to procedures. These are used primarily * in tclProc.c, tclCompile.c, and tclExecute.c. *---------------------------------------------------------------- *//* * Forward declaration to prevent an error when the forward reference to * Command is encountered in the Proc and ImportRef types declared below. */struct Command;/* * The variable-length structure below describes a local variable of a * procedure that was recognized by the compiler. These variables have a * name, an element in the array of compiler-assigned local variables in the * procedure's call frame, and various other items of information. If the * local variable is a formal argument, it may also have a default value. * The compiler can't recognize local variables whose names are * expressions (these names are only known at runtime when the expressions * are evaluated) or local variables that are created as a result of an * "upvar" or "uplevel" command. These other local variables are kept * separately in a hash table in the call frame. */typedef struct CompiledLocal { struct CompiledLocal *nextPtr; /* Next compiler-recognized local variable * for this procedure, or NULL if this is * the last local. */ int nameLength; /* The number of characters in local * variable's name. Used to speed up * variable lookups. */ int frameIndex; /* Index in the array of compiler-assigned * variables in the procedure call frame. */ int flags; /* Flag bits for the local variable. Same as * the flags for the Var structure above, * although only VAR_SCALAR, VAR_ARRAY, * VAR_LINK, VAR_ARGUMENT, VAR_TEMPORARY, and * VAR_RESOLVED make sense. */ Tcl_Obj *defValuePtr; /* Pointer to the default value of an * argument, if any. NULL if not an argument * or, if an argument, no default value. */ Tcl_ResolvedVarInfo *resolveInfo; /* Customized variable resolution info * supplied by the Tcl_ResolveCompiledVarProc * associated with a namespace. Each variable * is marked by a unique ClientData tag * during compilation, and that same tag * is used to find the variable at runtime. */ char name[4]; /* Name of the local variable starts here. * If the name is NULL, this will just be * '\0'. The actual size of this field will * be large enough to hold the name. MUST * BE THE LAST FIELD IN THE STRUCTURE! */} CompiledLocal;/* * The structure below defines a command procedure, which consists of a * collection of Tcl commands plus information about arguments and other * local variables recognized at compile time. */typedef struct Proc { struct Interp *iPtr; /* Interpreter for which this command * is defined. */ int refCount; /* Reference count: 1 if still present * in command table plus 1 for each call * to the procedure that is currently * active. This structure can be freed * when refCount becomes zero. */ struct Command *cmdPtr; /* Points to the Command structure for * this procedure. This is used to get * the namespace in which to execute * the procedure. */ Tcl_Obj *bodyPtr; /* Points to the ByteCode object for * procedure's body command. */ int numArgs; /* Number of formal parameters. */ int numCompiledLocals; /* Count of local variables recognized by * the compiler including arguments and * temporaries. */ CompiledLocal *firstLocalPtr; /* Pointer to first of the procedure's * compiler-allocated local variables, or * NULL if none. The first numArgs entries * in this list describe the procedure's * formal arguments. */ CompiledLocal *lastLocalPtr; /* Pointer to the last allocated local * variable or NULL if none. This has * frame index (numCompiledLocals-1). */} Proc;/* * The structure below defines a command trace. This is used to allow Tcl * clients to find out whenever a command is about to be executed. */typedef struct Trace { int level; /* Only trace commands at nesting level * less than or equal to this. */ Tcl_CmdTraceProc *proc; /* Procedure to call to trace command. */ ClientData clientData; /* Arbitrary value to pass to proc. */ struct Trace *nextPtr; /* Next in list of traces for this interp. */} Trace;/* * The structure below defines an entry in the assocData hash table which * is associated with an interpreter. The entry contains a pointer to a * function to call when the interpreter is deleted, and a pointer to * a user-defined piece of data. */typedef struct AssocData { Tcl_InterpDeleteProc *proc; /* Proc to call when deleting. */ ClientData clientData; /* Value to pass to proc. */} AssocData; /* * The structure below defines a call frame. A call frame defines a naming * context for a procedure call: its local naming scope (for local * variables) and its global naming scope (a namespace, perhaps the global * :: namespace). A call frame can also define the naming context for a * namespace eval or namespace inscope command: the namespace in which the * command's code should execute. The Tcl_CallFrame structures exist only * while procedures or namespace eval/inscope's are being executed, and * provide a kind of Tcl call stack. * * WARNING!! The structure definition must be kept consistent with the * Tcl_CallFrame structure in tcl.h. If you change one, change the other. */typedef struct CallFrame { Namespace *nsPtr; /* Points to the namespace used to resolve * commands and global variables. */ int isProcCallFrame; /* If nonzero, the frame was pushed to * execute a Tcl procedure and may have * local vars. If 0, the frame was pushed
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -