.DESCRIPTION
This rules does not add any violation.
It is a sample displaying on the output the tree of the analyzed code.

.SEVERITY Hidden

.COMMAND tcl

.CODE

proc compute {standardName tree} {
    variable CurrentParameterList
    puts "Current file name : \"[::logiscope::fileName]\""

    # display recursively the operators in the tree
    filterTree $tree [list opDisplay] ""
    puts "$CurrentParameterList"
}

# opDisplay displays the name of the operator and its value if it is an identifier
proc opDisplay {tree level} {
    set op [::logiscope::treeOperator $tree]
    puts -nonewline "$level[::logiscope::opName $op]"
    if {[::logiscope::opIsAtom $op]} {
        switch [::logiscope::atomTypeName [::logiscope::treeAtomType $tree]] {
           string {
               puts -nonewline " = \"[::logiscope::atomToString [::logiscope::treeAtomValue $tree] [::logiscope::atomTypeByName string]]\""
           }
           name {
               puts -nonewline " = \"[::logiscope::nameString [::logiscope::treeAtomValue $tree]]\""
           }
        }
    }
    if {![::logiscope::opIsAtom $op]} {
        set ph [::logiscope::opSonsPhylum $op]
        set arity {}
        if {[::logiscope::opIsList0 $op]} {
           set arity *
        }
        if {[::logiscope::opIsList1 $op]} {
            set arity +
        }
        if {[::logiscope::opIsFixArity $op]} {
            set i [::logiscope::opArity $op]
            for {set j 1} {$j < $i} {incr j} {
                set arity "${arity} [::logiscope::phylumName [::logiscope::opNthPhylum $op $j]]"
            }
        }
        puts -nonewline " -> [::logiscope::phylumName $ph]$arity ;"
    }
    puts ""
    return 1
}

# filterTree applies callback to tree, and recurses on tree's sons
proc filterTree {tree callback level} {
    set level [getLevel $tree $level]

    if {[eval $callback [list $tree $level]]} {
        ::logiscope::forobj son $tree treeChild {
            filterTree $son $callback $level
        }
    }
}

proc getLevel {tree level} {
    set parent [::logiscope::treeUp $tree]
    if {[string equal $level ""] || \
        [string equal $parent "NULL"] || \
        [string equal [::logiscope::treeRight $parent] "NULL"]} {
        set level "${level}   "
    } else {
        set level "${level}|  "
    }
    set level
}
