diff options
| author | dkf <donal.k.fellows@manchester.ac.uk> | 2024-03-19 17:09:30 (GMT) |
|---|---|---|
| committer | dkf <donal.k.fellows@manchester.ac.uk> | 2024-03-19 17:09:30 (GMT) |
| commit | 3ba2524ad4dcbada77fd5079cb69007cdea2a5e9 (patch) | |
| tree | e6fdb6985952e104004323a8b1172733b8f33abf /generic/tclCompile.c | |
| parent | d93e68c4e796434fb11ea9c067c73dbb483fd6dd (diff) | |
| download | tcl-3ba2524ad4dcbada77fd5079cb69007cdea2a5e9.zip tcl-3ba2524ad4dcbada77fd5079cb69007cdea2a5e9.tar.gz tcl-3ba2524ad4dcbada77fd5079cb69007cdea2a5e9.tar.bz2 | |
more spacing/formatting tweaks
Diffstat (limited to 'generic/tclCompile.c')
| -rw-r--r-- | generic/tclCompile.c | 180 |
1 files changed, 90 insertions, 90 deletions
diff --git a/generic/tclCompile.c b/generic/tclCompile.c index 9866ce2..0fc3e48 100644 --- a/generic/tclCompile.c +++ b/generic/tclCompile.c @@ -2195,114 +2195,114 @@ TclCompileScript( /* Each iteration compiles one command from the script. */ if (numBytes > 0) { - if (numBytes >= INT_MAX) { - /* - * Note this gets -errorline as 1. Not worth figuring out which line - * crosses the limit to get -errorline for this error case. - */ - Tcl_SetObjResult(interp, Tcl_ObjPrintf( - "Script length %" TCL_SIZE_MODIFIER - "d exceeds max permitted length %d.", - numBytes, INT_MAX-1)); - Tcl_SetErrorCode(interp, "TCL", "LIMIT", "SCRIPTLENGTH", (void *)NULL); - TclCompileSyntaxError(interp, envPtr); - return; - } - /* - * Don't use system stack (size of Tcl_Parse is ca. 400 bytes), so - * many nested compilations (body enclosed in body) can cause abnormal - * program termination with a stack overflow exception, bug [fec0c17d39]. - */ - Tcl_Parse *parsePtr = (Tcl_Parse *)Tcl_Alloc(sizeof(Tcl_Parse)); - - do { - const char *next; - - if (TCL_OK != Tcl_ParseCommand(interp, p, numBytes, 0, parsePtr)) { + if (numBytes >= INT_MAX) { /* - * Compile bytecodes to report the parsePtr error at runtime. + * Note this gets -errorline as 1. Not worth figuring out which line + * crosses the limit to get -errorline for this error case. */ - - Tcl_LogCommandInfo(interp, script, parsePtr->commandStart, - parsePtr->term + 1 - parsePtr->commandStart); + Tcl_SetObjResult(interp, Tcl_ObjPrintf( + "Script length %" TCL_SIZE_MODIFIER + "d exceeds max permitted length %d.", + numBytes, INT_MAX-1)); + Tcl_SetErrorCode(interp, "TCL", "LIMIT", "SCRIPTLENGTH", (void *)NULL); TclCompileSyntaxError(interp, envPtr); - Tcl_Free(parsePtr); return; } - -#ifdef TCL_COMPILE_DEBUG /* - * If tracing, print a line for each top level command compiled. - * TODO: Suppress when numWords == 0 ? + * Don't use system stack (size of Tcl_Parse is ca. 400 bytes), so + * many nested compilations (body enclosed in body) can cause abnormal + * program termination with a stack overflow exception, bug [fec0c17d39]. */ + Tcl_Parse *parsePtr = (Tcl_Parse *)Tcl_Alloc(sizeof(Tcl_Parse)); - if ((tclTraceCompile >= 1) && (envPtr->procPtr == NULL)) { - int commandLength = parsePtr->term - parsePtr->commandStart; - fprintf(stdout, " Compiling: "); - TclPrintSource(stdout, parsePtr->commandStart, - TclMin(commandLength, 55)); - fprintf(stdout, "\n"); - } -#endif + do { + const char *next; - /* - * TIP #280: Count newlines before the command start. - * (See test info-30.33). - */ + if (TCL_OK != Tcl_ParseCommand(interp, p, numBytes, 0, parsePtr)) { + /* + * Compile bytecodes to report the parsePtr error at runtime. + */ + + Tcl_LogCommandInfo(interp, script, parsePtr->commandStart, + parsePtr->term + 1 - parsePtr->commandStart); + TclCompileSyntaxError(interp, envPtr); + Tcl_Free(parsePtr); + return; + } - TclAdvanceLines(&envPtr->line, p, parsePtr->commandStart); - TclAdvanceContinuations(&envPtr->line, &envPtr->clNext, - parsePtr->commandStart - envPtr->source); +#ifdef TCL_COMPILE_DEBUG + /* + * If tracing, print a line for each top level command compiled. + * TODO: Suppress when numWords == 0 ? + */ - /* - * Advance parser to the next command in the script. - */ + if ((tclTraceCompile >= 1) && (envPtr->procPtr == NULL)) { + int commandLength = parsePtr->term - parsePtr->commandStart; + fprintf(stdout, " Compiling: "); + TclPrintSource(stdout, parsePtr->commandStart, + TclMin(commandLength, 55)); + fprintf(stdout, "\n"); + } +#endif - next = parsePtr->commandStart + parsePtr->commandSize; - numBytes -= next - p; - p = next; + /* + * TIP #280: Count newlines before the command start. + * (See test info-30.33). + */ + + TclAdvanceLines(&envPtr->line, p, parsePtr->commandStart); + TclAdvanceContinuations(&envPtr->line, &envPtr->clNext, + parsePtr->commandStart - envPtr->source); - if (parsePtr->numWords == 0) { /* - * The "command" parsed has no words. In this case we can skip - * the rest of the loop body. With no words, clearly - * CompileCommandTokens() has nothing to do. Since the parser - * aggressively sucks up leading comment and white space, - * including newlines, parsePtr->commandStart must be pointing at - * either the end of script, or a command-terminating semi-colon. - * In either case, the TclAdvance*() calls have nothing to do. - * Finally, when no words are parsed, no tokens have been - * allocated at parsePtr->tokenPtr so there's also nothing for - * Tcl_FreeParse() to do. - * - * The advantage of this shortcut is that CompileCommandTokens() - * can be written with an assumption that (int)parsePtr->numWords > 0, with - * the implication the CCT() always generates bytecode. + * Advance parser to the next command in the script. */ - continue; - } - /* - * Avoid stack exhaustion by too many nested calls of TclCompileScript - * (considering interp recursionlimit). - */ - iPtr->numLevels++; + next = parsePtr->commandStart + parsePtr->commandSize; + numBytes -= next - p; + p = next; + + if (parsePtr->numWords == 0) { + /* + * The "command" parsed has no words. In this case we can skip + * the rest of the loop body. With no words, clearly + * CompileCommandTokens() has nothing to do. Since the parser + * aggressively sucks up leading comment and white space, + * including newlines, parsePtr->commandStart must be pointing at + * either the end of script, or a command-terminating semi-colon. + * In either case, the TclAdvance*() calls have nothing to do. + * Finally, when no words are parsed, no tokens have been + * allocated at parsePtr->tokenPtr so there's also nothing for + * Tcl_FreeParse() to do. + * + * The advantage of this shortcut is that CompileCommandTokens() + * can be written with an assumption that (int)parsePtr->numWords > 0, with + * the implication the CCT() always generates bytecode. + */ + continue; + } + + /* + * Avoid stack exhaustion by too many nested calls of TclCompileScript + * (considering interp recursionlimit). + */ + iPtr->numLevels++; - lastCmdIdx = CompileCommandTokens(interp, parsePtr, envPtr); + lastCmdIdx = CompileCommandTokens(interp, parsePtr, envPtr); - iPtr->numLevels--; + iPtr->numLevels--; - /* - * TIP #280: Track lines in the just compiled command. - */ + /* + * TIP #280: Track lines in the just compiled command. + */ - TclAdvanceLines(&envPtr->line, parsePtr->commandStart, p); - TclAdvanceContinuations(&envPtr->line, &envPtr->clNext, - p - envPtr->source); - Tcl_FreeParse(parsePtr); - } while (numBytes > 0); + TclAdvanceLines(&envPtr->line, parsePtr->commandStart, p); + TclAdvanceContinuations(&envPtr->line, &envPtr->clNext, + p - envPtr->source); + Tcl_FreeParse(parsePtr); + } while (numBytes > 0); - Tcl_Free(parsePtr); + Tcl_Free(parsePtr); } if (lastCmdIdx == -1) { @@ -2374,12 +2374,12 @@ TclCompileVarSubst( */ for (i = 0, p = name; i < nameBytes; i++, p++) { - if ((*p == ':') && (i < nameBytes-1) && (*(p+1) == ':')) { + if ((p[0] == ':') && (i < nameBytes-1) && (p[1] == ':')) { localVarName = -1; break; - } else if ((*p == '(') + } else if ((p[0] == '(') && (tokenPtr->numComponents == 1) - && (*(name + nameBytes - 1) == ')')) { + && (name[nameBytes - 1] == ')')) { localVarName = 0; break; } |
