Itcl - the [incr Tcl] extension

Check-in [8d29902da1]
Login
Bounty program for improvements to Tcl and certain Tcl packages.
Tcl 2018 Conference, Houston/TX, US, Oct 15-19
Send your abstracts to tclconference@googlegroups.com
or submit via the online form by Aug 20.

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

Overview
Comment:Contributed patch adding introspection functionality on Itcl instance vars.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | bug-050ac21f72
Files: files | file ages | folders
SHA3-256:8d29902da171bd0c862b60da745f3e79578db5dec5c61df1f501919055902338
User & Date: dgp 2018-05-16 13:56:55
Context
2018-05-16
13:56
Contributed patch adding introspection functionality on Itcl instance vars. Leaf check-in: 8d29902da1 user: dgp tags: bug-050ac21f72
13:55
close fork check-in: af95a3325d user: dgp tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to generic/itclInfo.c.

197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
....
1260
1261
1262
1263
1264
1265
1266

1267
1268
1269
1270
1271
1272
1273
....
1282
1283
1284
1285
1286
1287
1288





1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
....
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
....
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
....
1469
1470
1471
1472
1473
1474
1475








































































1476
1477
1478
1479
1480
1481
1482
    },
    { "typevars",
        "?pattern?",
	Itcl_BiInfoTypeVarsCmd,
	ITCL_TYPE|ITCL_WIDGETADAPTOR|ITCL_WIDGET|ITCL_ECLASS
    },
    { "variable",
        "?name? ?-protection? ?-type? ?-name? ?-init? ?-value? ?-config?",
        Itcl_BiInfoVariableCmd,
	ITCL_CLASS|ITCL_TYPE|ITCL_WIDGETADAPTOR|ITCL_WIDGET|ITCL_ECLASS
    },
    { "variables",
        "?pattern?",
        Itcl_BiInfoVariablesCmd,
	ITCL_TYPE|ITCL_WIDGETADAPTOR|ITCL_WIDGET|ITCL_ECLASS
................................................................................
 *
 *  If the ?varName? is not specified, then a list of all known
 *  data members is returned.  Otherwise, the information for a
 *  specific member is returned.  Returns a status TCL_OK/TCL_ERROR
 *  to indicate success/failure.
 * ------------------------------------------------------------------------
 */

/* ARGSUSED */
int
Itcl_BiInfoVariableCmd(
    ClientData clientData, /* ItclObjectInfo Ptr */
    Tcl_Interp *interp,    /* current interpreter */
    int objc,              /* number of arguments */
    Tcl_Obj *const objv[]) /* argument objects */
................................................................................
    ItclVariable *ivPtr;
    ItclVarLookup *vlookup;
    ItclHierIter hier;
    char *varName;
    const char *val;
    int i;
    int result;






    static const char *options[] = {
        "-config", "-init", "-name", "-protection", "-type",
        "-value", (char*)NULL
    };
    enum BIvIdx {
        BIvConfigIdx, BIvInitIdx, BIvNameIdx, BIvProtectIdx,
        BIvTypeIdx, BIvValueIdx
    } *ivlist, ivlistStorage[6];

    static enum BIvIdx DefInfoVariable[5] = {
        BIvProtectIdx,
        BIvTypeIdx,
        BIvNameIdx,
        BIvInitIdx,
        BIvValueIdx
................................................................................
        BIvProtectIdx,
        BIvTypeIdx,
        BIvNameIdx,
        BIvInitIdx,
        BIvConfigIdx,
        BIvValueIdx
    };


    ItclShowArgs(1, "Itcl_BiInfoVariableCmd", objc, objv);
    resultPtr = NULL;
    objPtr = NULL;
    varName = NULL;
    contextIclsPtr = NULL;
    /*
................................................................................
    }
    if (contextIoPtr != NULL) {
        contextIclsPtr = contextIoPtr->iclsPtr;
    }

    /*
     *  Process args:
     *  ?varName? ?-protection? ?-type? ?-name? ?-init? ?-config? ?-value?
     */
    objv++;  /* skip over command name */
    objc--;

    if (objc > 0) {
        varName = Tcl_GetString(*objv);
        objc--; objv++;
................................................................................
                        }
                    }
                    if (val == NULL) {
                        val = "<undefined>";
                    }
                    objPtr = Tcl_NewStringObj((const char *)val, -1);
                    break;








































































            }

            if (objc == 1) {
                resultPtr = objPtr;
            } else {
                Tcl_ListObjAppendElement((Tcl_Interp*)NULL, resultPtr, objPtr);
            }







|







 







>







 







>
>
>
>
>



|



|
|







 







<







 







|







 







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







197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
....
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
....
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
....
1314
1315
1316
1317
1318
1319
1320

1321
1322
1323
1324
1325
1326
1327
....
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
....
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
    },
    { "typevars",
        "?pattern?",
	Itcl_BiInfoTypeVarsCmd,
	ITCL_TYPE|ITCL_WIDGETADAPTOR|ITCL_WIDGET|ITCL_ECLASS
    },
    { "variable",
        "?name? ?-protection? ?-type? ?-name? ?-init? ?-value? ?-config? ?-scope?",
        Itcl_BiInfoVariableCmd,
	ITCL_CLASS|ITCL_TYPE|ITCL_WIDGETADAPTOR|ITCL_WIDGET|ITCL_ECLASS
    },
    { "variables",
        "?pattern?",
        Itcl_BiInfoVariablesCmd,
	ITCL_TYPE|ITCL_WIDGETADAPTOR|ITCL_WIDGET|ITCL_ECLASS
................................................................................
 *
 *  If the ?varName? is not specified, then a list of all known
 *  data members is returned.  Otherwise, the information for a
 *  specific member is returned.  Returns a status TCL_OK/TCL_ERROR
 *  to indicate success/failure.
 * ------------------------------------------------------------------------
 */
/*&&&1*/
/* ARGSUSED */
int
Itcl_BiInfoVariableCmd(
    ClientData clientData, /* ItclObjectInfo Ptr */
    Tcl_Interp *interp,    /* current interpreter */
    int objc,              /* number of arguments */
    Tcl_Obj *const objv[]) /* argument objects */
................................................................................
    ItclVariable *ivPtr;
    ItclVarLookup *vlookup;
    ItclHierIter hier;
    char *varName;
    const char *val;
    int i;
    int result;

    ClientData cfClientData;
    ItclObjectInfo *infoPtr;
    Tcl_Object oPtr;
    int doAppend;

    static const char *options[] = {
        "-config", "-init", "-name", "-protection", "-type",
        "-value", "-scope", (char*)NULL
    };
    enum BIvIdx {
        BIvConfigIdx, BIvInitIdx, BIvNameIdx, BIvProtectIdx,
        BIvTypeIdx, BIvValueIdx, BIvScopeIdx
    } *ivlist, ivlistStorage[7];

    static enum BIvIdx DefInfoVariable[5] = {
        BIvProtectIdx,
        BIvTypeIdx,
        BIvNameIdx,
        BIvInitIdx,
        BIvValueIdx
................................................................................
        BIvProtectIdx,
        BIvTypeIdx,
        BIvNameIdx,
        BIvInitIdx,
        BIvConfigIdx,
        BIvValueIdx
    };


    ItclShowArgs(1, "Itcl_BiInfoVariableCmd", objc, objv);
    resultPtr = NULL;
    objPtr = NULL;
    varName = NULL;
    contextIclsPtr = NULL;
    /*
................................................................................
    }
    if (contextIoPtr != NULL) {
        contextIclsPtr = contextIoPtr->iclsPtr;
    }

    /*
     *  Process args:
     *  ?varName? ?-protection? ?-type? ?-name? ?-init? ?-config? ?-value? ?-scope?
     */
    objv++;  /* skip over command name */
    objc--;

    if (objc > 0) {
        varName = Tcl_GetString(*objv);
        objc--; objv++;
................................................................................
                        }
                    }
                    if (val == NULL) {
                        val = "<undefined>";
                    }
                    objPtr = Tcl_NewStringObj((const char *)val, -1);
                    break;

                case BIvScopeIdx:
                    entry = Tcl_FindHashEntry(&contextIclsPtr->resolveVars, varName);
                    if (!entry) {
                        Tcl_AppendStringsToObj(Tcl_GetObjResult(interp),
                              "variable \"", varName, "\" not found in class \"",
                              Tcl_GetString(contextIclsPtr->fullNamePtr), "\"",
                              (char*)NULL);
                        return TCL_ERROR;
                    }
                    vlookup = (ItclVarLookup*)Tcl_GetHashValue(entry);

                    if (vlookup->ivPtr->flags & ITCL_COMMON) {
                        objPtr = Tcl_NewStringObj("", -1);

                        if (vlookup->ivPtr->protection != ITCL_PUBLIC) {
                            Tcl_AppendToObj(objPtr, ITCL_VARIABLES_NAMESPACE, -1);
                        }
                        Tcl_AppendToObj(objPtr,
                                Tcl_GetString(vlookup->ivPtr->fullNamePtr), -1);
                    } else {
                        /*
                         *  If this is not a common variable, then we better have
                         *  an object context.  Return the name as a fully qualified name.
                         */
                        infoPtr = contextIclsPtr->infoPtr;
                        cfClientData = Itcl_GetCallFrameClientData(interp);
                        if (cfClientData != NULL) {
                            oPtr = Tcl_ObjectContextObject((Tcl_ObjectContext)cfClientData);
                            if (oPtr != NULL) {
                                contextIoPtr = (ItclObject*)Tcl_ObjectGetMetadata(
                                        oPtr, infoPtr->object_meta_type);
                            }
                        }

                        if (contextIoPtr == NULL) {
                            if (infoPtr->currIoPtr != NULL) {
                                contextIoPtr = infoPtr->currIoPtr;
                            }
                        }

                        if (contextIoPtr == NULL) {
                            Tcl_AppendStringsToObj(Tcl_GetObjResult(interp),
                                "can't scope variable \"", varName,
                                "\": missing object context",
                                (char*)NULL);
                            return TCL_ERROR;
                        }

                        doAppend = 1;
                        if (contextIclsPtr->flags & ITCL_ECLASS) {
                            if (strcmp(varName, "itcl_options") == 0) {
                                doAppend = 0;
                            }
                        }

                        objPtr = Tcl_NewStringObj((char*)NULL, 0);
                        Tcl_IncrRefCount(objPtr);
                        Tcl_AppendToObj(objPtr, ITCL_VARIABLES_NAMESPACE, -1);
                        Tcl_AppendToObj(objPtr,
                                (Tcl_GetObjectNamespace(contextIoPtr->oPtr))->fullName, -1);

                        if (doAppend) {
                            Tcl_AppendToObj(objPtr,
                                    Tcl_GetString(vlookup->ivPtr->fullNamePtr), -1);
                        } else {
                            Tcl_AppendToObj(objPtr, "::", -1);
                            Tcl_AppendToObj(objPtr,
                                    Tcl_GetString(vlookup->ivPtr->namePtr), -1);
                        }
                    }
                    break;
            }

            if (objc == 1) {
                resultPtr = objPtr;
            } else {
                Tcl_ListObjAppendElement((Tcl_Interp*)NULL, resultPtr, objPtr);
            }