Recent Changes - Search:



Wize validation involves checking Tcl code for syntax, call arguments and types when run with:

  wize -Wall script.tcl

Wizes validation capabilities are based on extern and type definitions which provides declarations for all built-ins, eg:

  extern incr {varName {amount 1}} {Int var Int} I "Increment the value of a variable"
  extern source {file args} {. {vopts ?-encoding type?} .} I "Evaluate a file or resource as a Tcl script"

Checking Performed

Validation performs the following checks:

  • All code in proc bodies is compiled, including nested switch/if/while blocks.
  • Syntax errors are detected, eg. unbalanced braces and quotes.
  • Commands called without a preceding proc definition or extern.
  • Parameters to static calls are checked for count (and possibly types).
  • Virtually all calls to builtin commands are validated
  • Detection of missing upvar, variable or global statements.
  • Data access to all static elements in _ array are checked for pre-initialization.
  • A Declare statement to specify other arrays to check.
  • Any extern argument of type code or 'expr is compiled.

How Tcl is Validated

Validation in Tcl is challenging because the language is highly dynamic. For example, standard Tcl does not normally compile a proc until it is first invoked. Even then, the sub-eval blocks such as while, if and switch are not compiled until they themselves are actually executed.

While this lazy evaluation is a plus in production, it makes detecting problems during development difficult.

Wize overcomes this by providing the option -Wall to forces Tcl code to compile as it is being sourced. Then, in the resulting compilation phase, extensive checks care performed to identify problems.

Errors or warnings from checking are output in a form similar to gcc warning messages.

How Tk is Validated

Validation of Tk code presents a additional challenges because Tk widgets are normally created as object-commands. Subcommands are then accessed via the object/widget-path. eg:

  text .t
  .t insert end "ABC"
  .t delete 1.1

Unfortunately, the use of object/path presents the compile phase with no effective way to perform checking. Maintaining such code afterwards is also problematic. Lastly, text-editors can not effectively provide command completion for Tk calls. This last is truly annoying as Tk widgets are responsible for the vast majority of all command options in Tcl.

To address this, Wize refactors the Tk widgets to create a Module command-namespace per widget in ::Tk. eg:

   namespace eval ::Tk::Text {
      namespace ensemble create; # ...
      extern insert {win pos str args} I
      extern delete {win pos args} I
      # ...
   # note: above ensembles get imported from ::Tk to ::
   Text new .t
   Text insert .t end "ABC"
   Text delete .t 1.1

Code written in this way can be checked be Wize, and it allows editors (like Ted) to support argument completion.

Array Validation

Elements in arrays can be validated by using Declare. This will report use of any element not initialized, eg.

  variable pc
  Declare pc Array

  array set pc { a 1 b 2}

  proc foo {args} {
     variable pc
     set pc(c) 1;  # Warns that "c" is uninitialized.

Tod Validation

Tod is a simple object extension used in Gui. Wize checks array references to $() for elements not initialized in _, eg.

  namespace eval ::foo {
    variable _
    array set _ { a 1 b 2 }

    proc sub {_ args} {
      upvar $_ {}
      set (c) $(b);  # Warning is issued for var 'c' undefined.
      $_ bar 1;      # Warning issued for proc 'bar' undefined.
      $_ sub

    # ...

Note that the dispatch call (eg. bar) is also validated.

Edit - History - Print - Recent Changes - Search
Page last modified on September 28, 2010, at 06:42 AM