Itcl - the [incr Tcl] extension

Check-in [87972ed991]
Login
Bounty program for improvements to Tcl and certain Tcl packages.
Tcl 2019 Conference, Houston/TX, US, Nov 4-8
Send your abstracts to [email protected]
or submit via the online form by Sep 9.

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

Overview
Comment:on demand resolver almost ready (check if0-commented cases - inheritance, 2-3 test cases failed)
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | sebres-on-dmnd-resolver-perf-branch
Files: files | file ages | folders
SHA3-256: 87972ed99116a1dee2e9cf2f2f3260104e3b89ee8357abf966eb93e42215f82d
User & Date: sebres 2019-04-17 20:43:47
Context
2019-04-17
20:44
**todo: review** on demand resolver ready (all tests passed) check-in: ce5e0de1c4 user: sebres tags: sebres-on-dmnd-resolver-perf-branch
20:43
on demand resolver almost ready (check if0-commented cases - inheritance, 2-3 test cases failed) check-in: 87972ed991 user: sebres tags: sebres-on-dmnd-resolver-perf-branch
20:43
**interim** improved, but not ready (tests failed, segfault, rebuild on inheritance, etc) check-in: 904c4d882c user: sebres tags: sebres-on-dmnd-resolver-perf-branch
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to generic/itclClass.c.

1696
1697
1698
1699
1700
1701
1702


1703


1704
1705
1706
1707
1708
1709
1710


1711
1712
1713
1714
1715
1716
1717
1718


1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
....
1739
1740
1741
1742
1743
1744
1745
1746

1747
1748
1749
1750
1751
1752
1753
1754
1755
....
1762
1763
1764
1765
1766
1767
1768

1769
1770
1771
1772
1773
1774
1775
....
1785
1786
1787
1788
1789
1790
1791

1792
1793
1794
1795

1796
1797
1798
1799
1800
1801
1802
....
1861
1862
1863
1864
1865
1866
1867
1868
1869


1870
1871
1872
1873

1874

1875
1876
1877
1878

1879
1880
1881
1882



1883











































1884
1885

1886
1887
1888

1889

1890
1891
1892
1893
1894
1895
1896
 */
Tcl_HashEntry *
ItclResolveVarEntry(
    ItclClass* iclsPtr,       /* class definition where to resolve variable */
    const char *lookupName)      /* name of variable being resolved */
{
#if 0


    return Tcl_FindHashEntry(&iclsPtr->resolveVars, lookupName);


#else
    Tcl_HashEntry *reshPtr, *hPtr;

    /* could be resolved directly */
    if ((reshPtr = Tcl_FindHashEntry(&iclsPtr->resolveVars, lookupName)) != NULL) {
	return reshPtr;
    } else {



    /* try to build virtual table for this var */
    const char *varName, *simpleName;
    Tcl_DString buffer, buffer2, *bufferC;
    ItclHierIter hier;
    ItclClass* iclsPtr2;
    ItclVarLookup *vlookup;
    ItclVariable *ivPtr;


    int processAncestors;
    
    /* (de)qualify to simple name */
    varName = lookupName;
    while(*varName) {
        if (*varName++ == ':' && *varName++ == ':')
	    simpleName = varName;
	    continue;
        };
        varName++;
    }
    simpleName = varName;
    
    processAncestors = simpleName != lookupName;
    
    Tcl_DStringInit(&buffer);
    Tcl_DStringInit(&buffer2);

    /*
................................................................................
     *  least specific.  Add a lookup entry for each variable
     *  into the table.
     */
    Itcl_InitHierIter(&hier, iclsPtr);
    iclsPtr2 = Itcl_AdvanceHierIter(&hier);
    while (iclsPtr2 != NULL) {

	hPtr = Tcl_FindHashEntry(&iclsPtr2->variables, varName);

	if (hPtr) {
	    Tcl_Namespace* nsPtr;
	    ivPtr = (ItclVariable*)Tcl_GetHashValue(hPtr);

            vlookup = NULL;

            /*
             *  Create all possible names for this variable and enter
             *  them into the variable resolution table:
................................................................................
            varName = simpleName;
            bufferC = &buffer;
            nsPtr = iclsPtr2->nsPtr;

            while (1) {
		hPtr = Tcl_CreateHashEntry(&iclsPtr->resolveVars,
		    varName, &newEntry);

		if (!reshPtr) {
		    reshPtr = hPtr;
		}

		/* check for same name in current class */
		if (!newEntry) {
		    vlookup = (ItclVarLookup*)Tcl_GetHashValue(hPtr);
................................................................................
			} else {
			    /* correct values (overwrite) */
			    vlookup->usage = 0;
			    goto setResVar;
			}
			newEntry = 1;
		    } else {

		    	/* var exists and no correction necessary - next var */
			if (!processAncestors) {
			    break;
			}

			/* check leastQualName correction needed */
			if (!vlookup->leastQualName) {
			    vlookup->leastQualName = 
				Tcl_GetHashKey(&iclsPtr->resolveVars, hPtr);
			}
			/* reset vlookup for full-qualified names - new lookup */
			vlookup = NULL;
................................................................................
                Tcl_DStringAppend(bufferC, "::", -1);
                Tcl_DStringAppend(bufferC, varName, -1);
                varName = Tcl_DStringValue(bufferC);
                bufferC = (bufferC == &buffer) ? &buffer2 : &buffer;

                nsPtr = nsPtr->parentPtr;
            }
	    hPtr = Tcl_NextHashEntry(&place);
	}


        iclsPtr2 = Itcl_AdvanceHierIter(&hier);

	/* Stop create vars for ancestors (if already processed once) */
	if (iclsPtr2 != iclsPtr && !processAncestors) {

	    if (simpleName == lookupName) {

		/* simple name */
		return reshPtr;
	    }
	    break;

	}
    }
    Itcl_DeleteHierIter(&hier);
















































	Tcl_DStringFree(&buffer);
	Tcl_DStringFree(&buffer2);

    }

    hPtr = Tcl_FindHashEntry(&iclsPtr->resolveVars, lookupName);

    return hPtr;

#endif
}
 
/*
 * ------------------------------------------------------------------------
 *  Itcl_BuildVirtualTables()
 *






>
>
|
>
>







>
>








>
>
|


|

|





|







 







|
>

<







 







>







 







>




>







 







<
|
>
>




>

>




>




>
>
>

>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>


>
|
<
|
>
|
>







1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
....
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756

1757
1758
1759
1760
1761
1762
1763
....
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
....
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
....
1872
1873
1874
1875
1876
1877
1878

1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948

1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
 */
Tcl_HashEntry *
ItclResolveVarEntry(
    ItclClass* iclsPtr,       /* class definition where to resolve variable */
    const char *lookupName)      /* name of variable being resolved */
{
#if 0
    Tcl_HashEntry *reshPtr;

    reshPtr = Tcl_FindHashEntry(&iclsPtr->resolveVars, lookupName);
    printf("====get======== %p : %s -- v: %s -> %p ===== \n", iclsPtr, Tcl_GetString(iclsPtr->fullNamePtr), lookupName, reshPtr);
    return reshPtr;
#else
    Tcl_HashEntry *reshPtr, *hPtr;

    /* could be resolved directly */
    if ((reshPtr = Tcl_FindHashEntry(&iclsPtr->resolveVars, lookupName)) != NULL) {
	return reshPtr;
    } else {

    //!!!printf("====get======== %p : %s -- v: %s ===== \n", iclsPtr, Tcl_GetString(iclsPtr->fullNamePtr), lookupName);

    /* try to build virtual table for this var */
    const char *varName, *simpleName;
    Tcl_DString buffer, buffer2, *bufferC;
    ItclHierIter hier;
    ItclClass* iclsPtr2;
    ItclVarLookup *vlookup;
    ItclVariable *ivPtr;
    Tcl_Namespace* nsPtr;
    Tcl_Obj *vnObjPtr;
    int newEntry, processAncestors;
    
    /* (de)qualify to simple name */
    varName = simpleName = lookupName;
    while(*varName) {
        if (*varName++ == ':' && *varName++ == ':') {
	    simpleName = varName;
	    continue;
        };
        varName++;
    }
    vnObjPtr = Tcl_NewStringObj(simpleName, -1);
    
    processAncestors = simpleName != lookupName;
    
    Tcl_DStringInit(&buffer);
    Tcl_DStringInit(&buffer2);

    /*
................................................................................
     *  least specific.  Add a lookup entry for each variable
     *  into the table.
     */
    Itcl_InitHierIter(&hier, iclsPtr);
    iclsPtr2 = Itcl_AdvanceHierIter(&hier);
    while (iclsPtr2 != NULL) {

	hPtr = Tcl_FindHashEntry(&iclsPtr2->variables, vnObjPtr);
        //!!!printf("    **** find %p : %s : %p\n", iclsPtr2, Tcl_GetString(iclsPtr2->fullNamePtr), hPtr);
	if (hPtr) {

	    ivPtr = (ItclVariable*)Tcl_GetHashValue(hPtr);

            vlookup = NULL;

            /*
             *  Create all possible names for this variable and enter
             *  them into the variable resolution table:
................................................................................
            varName = simpleName;
            bufferC = &buffer;
            nsPtr = iclsPtr2->nsPtr;

            while (1) {
		hPtr = Tcl_CreateHashEntry(&iclsPtr->resolveVars,
		    varName, &newEntry);
                //!!!printf("    **** find %p : %s : %s -> %p\n", iclsPtr2, Tcl_GetString(iclsPtr2->fullNamePtr), varName, hPtr);
		if (!reshPtr) {
		    reshPtr = hPtr;
		}

		/* check for same name in current class */
		if (!newEntry) {
		    vlookup = (ItclVarLookup*)Tcl_GetHashValue(hPtr);
................................................................................
			} else {
			    /* correct values (overwrite) */
			    vlookup->usage = 0;
			    goto setResVar;
			}
			newEntry = 1;
		    } else {
#if 0
		    	/* var exists and no correction necessary - next var */
			if (!processAncestors) {
			    break;
			}
#endif
			/* check leastQualName correction needed */
			if (!vlookup->leastQualName) {
			    vlookup->leastQualName = 
				Tcl_GetHashKey(&iclsPtr->resolveVars, hPtr);
			}
			/* reset vlookup for full-qualified names - new lookup */
			vlookup = NULL;
................................................................................
                Tcl_DStringAppend(bufferC, "::", -1);
                Tcl_DStringAppend(bufferC, varName, -1);
                varName = Tcl_DStringValue(bufferC);
                bufferC = (bufferC == &buffer) ? &buffer2 : &buffer;

                nsPtr = nsPtr->parentPtr;
            }


        }

        iclsPtr2 = Itcl_AdvanceHierIter(&hier);

	/* Stop create vars for ancestors (if already processed once) */
	if (iclsPtr2 != iclsPtr && !processAncestors) {
#if 0
	    if (simpleName == lookupName) {
	    	Tcl_DecrRefCount(vnObjPtr);
		/* simple name */
		return reshPtr;
	    }
	    break;
#endif
	}
    }
    Itcl_DeleteHierIter(&hier);

#if 0 /* DUMP var table */
    //!!!
    printf("======== %p : %s ===== \n", iclsPtr2, Tcl_GetString(iclsPtr->fullNamePtr));

    Itcl_InitHierIter(&hier, iclsPtr);
    iclsPtr2 = Itcl_AdvanceHierIter(&hier);
    while (iclsPtr2 != NULL) {
    	Tcl_HashSearch place;

        //!!!
        printf("  ****** %p : %s\n", iclsPtr2, Tcl_GetString(iclsPtr2->fullNamePtr));
        hPtr = Tcl_FirstHashEntry(&iclsPtr2->variables, &place);
        while (hPtr) {
            ivPtr = (ItclVariable*)Tcl_GetHashValue(hPtr);

            Tcl_DStringSetLength(&buffer, 0);
            Tcl_DStringAppend(&buffer, Tcl_GetString(ivPtr->namePtr), -1);
            nsPtr = iclsPtr2->nsPtr;

            while (1) {
                hPtr = Tcl_FindHashEntry(&iclsPtr->resolveVars, Tcl_DStringValue(&buffer));
                if (hPtr) {
                    vlookup = (ItclVarLookup *)Tcl_GetHashValue(hPtr);
    
                    //!!!
                    printf("    **** %p : %s : %s -> %s, (%d) %p\n", iclsPtr2, Tcl_GetString(iclsPtr2->fullNamePtr), Tcl_DStringValue(&buffer), vlookup->leastQualName ? vlookup->leastQualName : "<NULL>", vlookup->usage, vlookup);
                }
                if (nsPtr == NULL) {
                    break;
                }
                Tcl_DStringSetLength(&buffer2, 0);
                Tcl_DStringAppend(&buffer2, Tcl_DStringValue(&buffer), -1);
                Tcl_DStringSetLength(&buffer, 0);
                Tcl_DStringAppend(&buffer, nsPtr->name, -1);
                Tcl_DStringAppend(&buffer, "::", -1);
                Tcl_DStringAppend(&buffer, Tcl_DStringValue(&buffer2), -1);

                nsPtr = nsPtr->parentPtr;
            }

            hPtr = Tcl_NextHashEntry(&place);
        }
        iclsPtr2 = Itcl_AdvanceHierIter(&hier);
    }
    Itcl_DeleteHierIter(&hier);
#endif

	Tcl_DStringFree(&buffer);
	Tcl_DStringFree(&buffer2);
	Tcl_DecrRefCount(vnObjPtr);


	reshPtr = Tcl_FindHashEntry(&iclsPtr->resolveVars, lookupName);
	//!!!printf("====ret======== %p : %s ===== \n", reshPtr, reshPtr && ((ItclVarLookup*)Tcl_GetHashValue(reshPtr))->leastQualName ? ((ItclVarLookup*)Tcl_GetHashValue(reshPtr))->leastQualName : "<NULL>");
	return reshPtr;
    }
#endif
}
 
/*
 * ------------------------------------------------------------------------
 *  Itcl_BuildVirtualTables()
 *