diff options
author | stanton <stanton> | 1998-06-25 16:12:05 (GMT) |
---|---|---|
committer | stanton <stanton> | 1998-06-25 16:12:05 (GMT) |
commit | c9c610cd110d1d2fa6a5c6c7aabc8de1395ed2e5 (patch) | |
tree | b24a24c8f24857e7322e94ca7753b72862f7919a /generic | |
parent | 690834e1c77f90f43bc6f2f2d028a75d5b84c023 (diff) | |
download | tcl-c9c610cd110d1d2fa6a5c6c7aabc8de1395ed2e5.zip tcl-c9c610cd110d1d2fa6a5c6c7aabc8de1395ed2e5.tar.gz tcl-c9c610cd110d1d2fa6a5c6c7aabc8de1395ed2e5.tar.bz2 |
catch didn't compile non-local variables correctly
Diffstat (limited to 'generic')
-rw-r--r-- | generic/tclCompile.c | 87 |
1 files changed, 49 insertions, 38 deletions
diff --git a/generic/tclCompile.c b/generic/tclCompile.c index e040bc8..2dce72e 100644 --- a/generic/tclCompile.c +++ b/generic/tclCompile.c @@ -398,6 +398,7 @@ static void FreeArgInfo _ANSI_ARGS_((ArgInfo *argInfoPtr)); static int GetCmdLocEncodingSize _ANSI_ARGS_(( CompileEnv *envPtr)); static void InitArgInfo _ANSI_ARGS_((ArgInfo *argInfoPtr)); +static int IsLocalScalar _ANSI_ARGS_((char *name, int len)); static int LookupCompiledLocal _ANSI_ARGS_(( char *name, int nameChars, int createIfNew, int flagsIfCreated, Proc *procPtr)); @@ -3247,6 +3248,48 @@ TclCompileDollarVar(interp, string, lastChar, flags, envPtr) /* *---------------------------------------------------------------------- * + * IsLocalScalar -- + * + * Checks to see if a variable name refers to a local scalar. + * + * Results: + * Returns 1 if the variable is a local scalar. + * + * Side effects: + * None. + * + *---------------------------------------------------------------------- + */ + +static int +IsLocalScalar(varName, length) + char *varName; /* The name to check. */ + int length; /* The number of characters in the string. */ +{ + char *p; + char *lastChar = varName + (length - 1); + + for (p = varName; p <= lastChar; p++) { + if (CHAR_TYPE(p, lastChar) != TCL_NORMAL) { + return 0; + } + if (*p == '(') { + if (*lastChar == ')') { /* we have an array element */ + return 0; + } + } else if (*p == ':') { + if ((p != lastChar) && *(p+1) == ':') { /* qualified name */ + return 0; + } + } + } + + return 1; +} + +/* + *---------------------------------------------------------------------- + * * TclCompileBreakCmd -- * * Procedure called to compile the "break" command. @@ -3433,21 +3476,9 @@ TclCompileCatchCmd(interp, string, lastChar, flags, envPtr) } nameChars = (lastChar - firstChar + 1); - if (nameChars > 0) { - char *p = firstChar; - while (p != lastChar) { - if (CHAR_TYPE(p, lastChar) != TCL_NORMAL) { - result = TCL_OUT_LINE_COMPILE; - goto done; - } - if (*p == '(') { - if (*lastChar == ')') { /* we have an array element */ - result = TCL_OUT_LINE_COMPILE; - goto done; - } - } - p++; - } + if (!IsLocalScalar(firstChar, nameChars)) { + result = TCL_OUT_LINE_COMPILE; + goto done; } name = firstChar; @@ -4429,29 +4460,9 @@ TclCompileForeachCmd(interp, string, lastChar, flags, envPtr) numVars = varcList[i]; for (j = 0; j < numVars; j++) { char *varName = varvList[i][j]; - char *p = varName; - while (*p != '\0') { - if (CHAR_TYPE(p, p+1) != TCL_NORMAL) { - result = TCL_OUT_LINE_COMPILE; - goto done; - } - if ((*p == ':') && (*(p+1) == ':')) { /* non-local name */ - result = TCL_OUT_LINE_COMPILE; - goto done; - } - - if (*p == '(') { - char *q = p; - do { - q++; - } while (*q != '\0'); - q--; - if (*q == ')') { /* we have an array element */ - result = TCL_OUT_LINE_COMPILE; - goto done; - } - } - p++; + if (!IsLocalScalar(varName, strlen(varName))) { + result = TCL_OUT_LINE_COMPILE; + goto done; } } } |