summaryrefslogtreecommitdiffstats
path: root/generic/tclCompCmds.c
diff options
context:
space:
mode:
authordgp <dgp@users.sourceforge.net>2008-01-23 19:41:19 (GMT)
committerdgp <dgp@users.sourceforge.net>2008-01-23 19:41:19 (GMT)
commitf7f6ddb4ce3ce465107777a9a2c408dd8ab473dc (patch)
tree1c55178d6b1eb4273b96b9e83576b57f711f44c7 /generic/tclCompCmds.c
parentd3dba3f8855bf00200865c0c8b783e4bd57d1b32 (diff)
downloadtcl-f7f6ddb4ce3ce465107777a9a2c408dd8ab473dc.zip
tcl-f7f6ddb4ce3ce465107777a9a2c408dd8ab473dc.tar.gz
tcl-f7f6ddb4ce3ce465107777a9a2c408dd8ab473dc.tar.bz2
* generic/tclInt.h: New macro TclGrowParseTokenArray() to
* generic/tclCompCmds.c: simplify code that might need to grow * generic/tclCompExpr.c: an array of Tcl_Tokens in the parsePtr * generic/tclParse.c: field of a Tcl_Parse. Replaces the TclExpandTokenArray() routine via replacing: int needed = parsePtr->numTokens + growth; while (needed > parsePtr->tokensAvailable) { TclExpandTokenArray(parsePtr); } with: TclGrowParseTokenArray(parsePtr, growth); This revision merged over from dgp-refactor branch.
Diffstat (limited to 'generic/tclCompCmds.c')
-rw-r--r--generic/tclCompCmds.c35
1 files changed, 16 insertions, 19 deletions
diff --git a/generic/tclCompCmds.c b/generic/tclCompCmds.c
index 83bb1ae..5b5cd93 100644
--- a/generic/tclCompCmds.c
+++ b/generic/tclCompCmds.c
@@ -12,7 +12,7 @@
* See the file "license.terms" for information on usage and redistribution of
* this file, and for a DISCLAIMER OF ALL WARRANTIES.
*
- * RCS: @(#) $Id: tclCompCmds.c,v 1.139 2007/12/23 21:29:41 hobbs Exp $
+ * RCS: @(#) $Id: tclCompCmds.c,v 1.140 2008/01/23 19:41:27 dgp Exp $
*/
#include "tclInt.h"
@@ -6141,7 +6141,7 @@ TclCompileEnsemble(
* compiled. */
CompileEnv *envPtr) /* Holds resulting instructions. */
{
- Tcl_Token *tokenPtr, *argTokensPtr;
+ Tcl_Token *tokenPtr;
Tcl_Obj *mapObj, *subcmdObj, *targetCmdObj, *listObj, **elems;
Tcl_Command ensemble = (Tcl_Command) cmdPtr;
Tcl_Parse synthetic;
@@ -6339,18 +6339,10 @@ TclCompileEnsemble(
* do that, we have to perform some trickery to rewrite the arguments.
*/
- argTokensPtr = TokenAfter(tokenPtr);
- memcpy(&synthetic, parsePtr, sizeof(Tcl_Parse));
- synthetic.numWords -= 2 - len;
- synthetic.numTokens -= (argTokensPtr - parsePtr->tokenPtr) - 2*len;
- if (synthetic.numTokens <= NUM_STATIC_TOKENS) {
- synthetic.tokenPtr = synthetic.staticTokens;
- synthetic.tokensAvailable = NUM_STATIC_TOKENS;
- } else {
- synthetic.tokenPtr =
- TclStackAlloc(interp, sizeof(Tcl_Token) * synthetic.numTokens);
- synthetic.tokensAvailable = synthetic.numTokens;
- }
+ TclParseInit(interp, NULL, 0, &synthetic);
+ synthetic.numWords = parsePtr->numWords - 2 + len;
+ TclGrowParseTokenArray(&synthetic, 2*len);
+ synthetic.numTokens = 2*len;
/*
* Now we have the space to work in, install something rewritten. Note
@@ -6378,8 +6370,15 @@ TclCompileEnsemble(
* Copy over the real argument tokens.
*/
- memcpy(synthetic.tokenPtr + 2*len, argTokensPtr,
- sizeof(Tcl_Token) * (synthetic.numTokens - 2*len));
+ for (i=len; i<synthetic.numWords; i++) {
+ int toCopy;
+ tokenPtr = TokenAfter(tokenPtr);
+ toCopy = tokenPtr->numComponents + 1;
+ TclGrowParseTokenArray(&synthetic, toCopy);
+ memcpy(synthetic.tokenPtr + synthetic.numTokens, tokenPtr,
+ sizeof(Tcl_Token) * toCopy);
+ synthetic.numTokens += toCopy;
+ }
/*
* Hand off compilation to the subcommand compiler. At last!
@@ -6391,9 +6390,7 @@ TclCompileEnsemble(
* Clean up if necessary.
*/
- if (synthetic.tokenPtr != synthetic.staticTokens) {
- TclStackFree(interp, synthetic.tokenPtr);
- }
+ Tcl_FreeParse(&synthetic);
return result;
}