Tcl Source Code

Check-in [30a06fec35]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Replace TclIsLocalScalar() with PushVarNameWord() in [dict for] compiler.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | bug-e711ffb458
Files: files | file ages | folders
SHA1: 30a06fec3558a74c2a637d6929941bf178ee2888
User & Date: dgp 2014-12-19 14:17:03
Context
2014-12-19
14:21
With no callers left, TclIsLocalScalar() is removed. check-in: b052f09dbe user: dgp tags: bug-e711ffb458
14:17
Replace TclIsLocalScalar() with PushVarNameWord() in [dict for] compiler. check-in: 30a06fec35 user: dgp tags: bug-e711ffb458
03:31
Narrow scope of numVars. check-in: 90eb0b4cbb user: dgp tags: bug-e711ffb458
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to generic/tclCompCmds.c.

802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818


819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850

851
852
853
854



855
856

857
858
859
860



861
862
863
864
865
866
867
868
869
870
871
872
873
874
    Tcl_Parse *parsePtr,	/* Points to a parse structure for the command
				 * created by Tcl_ParseCommand. */
    Command *cmdPtr,		/* Points to defintion of command being
				 * compiled. */
    CompileEnv *envPtr)		/* Holds resulting instructions. */
{
    Proc *procPtr = envPtr->procPtr;
    DefineLineInformation;	/* TIP #280 */
    Tcl_Token *varsTokenPtr, *dictTokenPtr, *bodyTokenPtr;
    int keyVarIndex, valueVarIndex, nameChars, loopRange, catchRange;
    int infoIndex, jumpDisplacement, bodyTargetOffset, emptyTargetOffset;
    int numVars, endTargetOffset;
    int savedStackDepth = envPtr->currStackDepth;
				/* Needed because jumps confuse the stack
				 * space calculator. */
    const char **argv;
    Tcl_DString buffer;



    /*
     * There must be exactly three arguments after the command.
     */

    if (parsePtr->numWords != 4 || procPtr == NULL) {
	return TCL_ERROR;
    }

    varsTokenPtr = TokenAfter(parsePtr->tokenPtr);
    dictTokenPtr = TokenAfter(varsTokenPtr);
    bodyTokenPtr = TokenAfter(dictTokenPtr);
    if (varsTokenPtr->type != TCL_TOKEN_SIMPLE_WORD ||
	    bodyTokenPtr->type != TCL_TOKEN_SIMPLE_WORD) {
	return TCL_ERROR;
    }

    /*
     * Check we've got a pair of variables and that they are local variables.
     * Then extract their indices in the LVT.
     */

    Tcl_DStringInit(&buffer);
    Tcl_DStringAppend(&buffer, varsTokenPtr[1].start, varsTokenPtr[1].size);
    if (Tcl_SplitList(NULL, Tcl_DStringValue(&buffer), &numVars,
	    &argv) != TCL_OK) {
	Tcl_DStringFree(&buffer);
	return TCL_ERROR;
    }
    Tcl_DStringFree(&buffer);
    if (numVars != 2) {
	ckfree((char *) argv);

	return TCL_ERROR;
    }

    nameChars = strlen(argv[0]);



    if (!TclIsLocalScalar(argv[0], nameChars)) {
	ckfree((char *) argv);

	return TCL_ERROR;
    }
    keyVarIndex = TclFindCompiledLocal(argv[0], nameChars, 1, procPtr);




    nameChars = strlen(argv[1]);
    if (!TclIsLocalScalar(argv[1], nameChars)) {
	ckfree((char *) argv);
	return TCL_ERROR;
    }
    valueVarIndex = TclFindCompiledLocal(argv[1], nameChars, 1, procPtr);
    ckfree((char *) argv);

    /*
     * Allocate a temporary variable to store the iterator reference. The
     * variable will contain a Tcl_DictSearch reference which will be
     * allocated by INST_DICT_FIRST and disposed when the variable is unset
     * (at which point it should also have been finished with).
     */







<

|

|



|
|
>
>












|
|








|
|
<
|
<
<
<
<
|
<
>



<
>
>
>
|
|
>


<

>
>
>
|
|
|


|
|







802
803
804
805
806
807
808

809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843

844




845

846
847
848
849

850
851
852
853
854
855
856
857

858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
    Tcl_Parse *parsePtr,	/* Points to a parse structure for the command
				 * created by Tcl_ParseCommand. */
    Command *cmdPtr,		/* Points to defintion of command being
				 * compiled. */
    CompileEnv *envPtr)		/* Holds resulting instructions. */
{
    Proc *procPtr = envPtr->procPtr;

    Tcl_Token *varsTokenPtr, *dictTokenPtr, *bodyTokenPtr;
    int keyVarIndex, valueVarIndex, loopRange, catchRange;
    int infoIndex, jumpDisplacement, bodyTargetOffset, emptyTargetOffset;
    int numVars, endTargetOffset, isSimple, isScalar;
    int savedStackDepth = envPtr->currStackDepth;
				/* Needed because jumps confuse the stack
				 * space calculator. */
    Tcl_Obj *varNameObj, *varListObj = NULL;
    Tcl_Token token[2] =	{{TCL_TOKEN_SIMPLE_WORD, NULL, 0, 1},
				 {TCL_TOKEN_TEXT, NULL, 0, 0}};
    DefineLineInformation;	/* TIP #280 */

    /*
     * There must be exactly three arguments after the command.
     */

    if (parsePtr->numWords != 4 || procPtr == NULL) {
	return TCL_ERROR;
    }

    varsTokenPtr = TokenAfter(parsePtr->tokenPtr);
    dictTokenPtr = TokenAfter(varsTokenPtr);
    bodyTokenPtr = TokenAfter(dictTokenPtr);

    if (bodyTokenPtr->type != TCL_TOKEN_SIMPLE_WORD) {
	return TCL_ERROR;
    }

    /*
     * Check we've got a pair of variables and that they are local variables.
     * Then extract their indices in the LVT.
     */

    varListObj = Tcl_NewObj();
    if (!TclWordKnownAtCompileTime(varsTokenPtr, varListObj) ||

	    TCL_OK != Tcl_ListObjLength(NULL, varListObj, &numVars) ||




	    numVars != 2) {

	Tcl_DecrRefCount(varListObj);
	return TCL_ERROR;
    }


    Tcl_ListObjIndex(NULL, varListObj, 0, &varNameObj);
    token[1].start = Tcl_GetStringFromObj(varNameObj, &token[1].size);
    PushVarNameWord(interp, token, envPtr, TCL_CREATE_VAR,
	    &keyVarIndex, &isSimple, &isScalar, 0 /* ignored */);
    if (!isScalar || keyVarIndex < 0) {
	Tcl_DecrRefCount(varListObj);
	return TCL_ERROR;
    }


    Tcl_ListObjIndex(NULL, varListObj, 1, &varNameObj);
    token[1].start = Tcl_GetStringFromObj(varNameObj, &token[1].size);
    PushVarNameWord(interp, token, envPtr, TCL_CREATE_VAR,
	    &valueVarIndex, &isSimple, &isScalar, 0 /* ignored */);
    if (!isScalar || valueVarIndex < 0) {
	Tcl_DecrRefCount(varListObj);
	return TCL_ERROR;
    }

    Tcl_DecrRefCount(varListObj);

    /*
     * Allocate a temporary variable to store the iterator reference. The
     * variable will contain a Tcl_DictSearch reference which will be
     * allocated by INST_DICT_FIRST and disposed when the variable is unset
     * (at which point it should also have been finished with).
     */