home *** CD-ROM | disk | FTP | other *** search
- #---------------------------------------------------------------------------
- #
- # Copyright (c) 1992-1995 by Cadre Technologies Inc.
- #
- # This software is furnished under a license and may be used only in
- # accordance with the terms of such license and with the inclusion of
- # the above copyright notice. This software or any other copies thereof
- # may not be provided or otherwise made available to any other person.
- # No title to and ownership of the software is hereby transferred.
- #
- # The information in this software is subject to change without notice
- # and should not be construed as a commitment by Cadre Technologies Inc.
- #
- #---------------------------------------------------------------------------
- #
- # File : @(#)check_util.tcl /main/hindenburg/2
- # Author : edri
- # Original date : 20-10-94
- # Description : Check utilities
- #
- #---------------------------------------------------------------------------
- #
-
- #
- # Function to show the errors and warnings.
- #
- proc show_errors {} {
- m4_message $M_NEWLINE
- m4_message $M_ERRORS [M4CheckManager::getErrorCount]
- m4_message $M_WARNINGS [M4CheckManager::getWarningCount]
- }
-
- #
- # m4_error replacement that constructs an error id based on an error name
- # and an event type. Used to allow for event-specific check configuration.
- #
- proc m4_event_error {event_type errname args} {
- switch -glob $event_type {
- internal_* { set event_type internal_event }
- external_* { set event_type external_event }
- }
- set err ${errname}_[string toupper $event_type]
- eval "m4_error $[get err] $args"
- }
-
- #
- # Return the handle of the DBObject class for the given OoplModel.
- #
- proc get_dbobject_class {model} {
- set dbobject [find_class $model $dbobject_name]
- if {$dbobject == ""} {
- if {[catch {set dbobject [$model addClass $dbobject_name db_class]}]} {
- m4_error $E_INTERNAL_CLASS db_class
- return ""
- }
- }
- return $dbobject
- }
-
- #
- # Create a paramList for use with add_operation. The parameters consist
- # of those attributes that are key attributes of the given class.
- #
- proc make_key_paramlist {class} {
- set params {}
- foreach key [get_col_list [$class table] KEYS] {
- set pair {}
- lappend pair [$key getName]
- lappend pair [$key getTypeStd]
- lappend params $pair
- }
- return $params
- }
-
- #
- # Set/Add attributes of an object.
- # Useful to set attributes of oopl objects created using add_class,
- # add_operation, add_super_class.
- #
- proc add_attributes {object list} {
- foreach attr $list {
- $object addRunTimeProperty [lindex $attr 0] [lindex $attr 1]
- }
- }
-
- #
- # Given a class name and optionally an operation name, find the class
- # and feature handles of the class with name 'name' and all features
- # with name 'feat' in the specified OoplModel. 'feat' may be a glob-style
- # pattern.
- #
- # Returns a list of one or more elements, the first being the class handle,
- # the rest operation handles. If the class was not found, returns "".
- #
- proc find_class {model name {feat ""}} {
- set c [$model classByName $name]
-
- if {"$c" == ""} {
- return ""
- }
-
- if {$feat != ""} {
- set flist ""
-
- foreach f [$c featureSet] {
- if [string match $feat [$f getName]] {
- lappend flist $f
- }
- }
-
- return "$c $flist"
- }
-
- return $c
- }
-
- #
- # Check if the given class is a real root class, i.e. has no non-synthetic
- # superclasses
- #
- proc is_root_class {class} {
- set supers [$class genNodeSet]
- if [lempty $supers] {
- return 1
- }
- foreach g $supers {
- if {[$g isSynthetic] != "1"} {
- return 0
- }
- }
- return 1;
- }
-
- #
- # Return the long name for an event type.
- #
- proc long_event_type {type} {
- switch -glob $type {
- internal_event { return "Internal STD Event" }
- internal_action { return "Internal STD Action" }
- internal_activity { return "STD Activity" }
- external_event { return "External STD Event" }
- external_action { return "External STD Action" }
- event_message { return "Event Message" }
- comm_message { return "Communication Message" }
- trace_event { return "Trace Event" }
- }
- return $type
- }
-
- #
- # Create a string describing an Event object.
- # If 'attrs' is 1, the attributes of the event, if present, are added as well.
- # If 'condact' is 0, the condition and action, if present, are not added.
- #
- proc display_event {e {attrs 0} {condact 0}} {
- if {[$e get_obj_type] == "event"} {
- return "MGD Message '[$e getName]'\
- in [$e getDiagramName].[$e getDiagramType]"
- } else {
- # obj_type == "received_event"
- set a ""
- if {$attrs && [has_attributes $e]} {
- set first 1
- foreach n [get_attributes $e] {
- if {!$first} {
- append a ", "
- } else {
- set first 0
- }
- lappend a $n
- }
- if {$a == ""} {
- set a "()"
- } else {
- set a "( $a )"
- }
- }
- if {$condact && [get_event_type $e] == "external_event"} {
- set conds [get_conditions $e]
- if {$conds != ""} {
- set first 1
- foreach cond $conds {
- if {!$first} {
- append a ", "
- } else {
- set first 0
- }
- append a $cond
- }
- }
- set act [get_action $e]
- if {$act != ""} {
- append a {/} $act
- }
- }
- if {$condact && [get_event_type $e] == "external_event"} {
- return "[long_event_type [get_event_type $e]] '[$e getName]'\
- in '[$e getName]$a'\
- in [$e getDiagramName].[$e getDiagramType]"
- }
- return "[long_event_type [get_event_type $e]] '[$e getName]$a'\
- in [$e getDiagramName].[$e getDiagramType]"
- }
- }
-
- #
- # Given an object with the attributes 'diagram_name' and 'diagram_type',
- # return a string that concatenates these two.
- #
- proc display_diagram {obj} {
- return "[$obj getDiagramName].[$obj getDiagramType]"
- }
-
- #
- # Return a list with all Event objects that are leaves of the event hierarchy
- # with Event 'e' as root.
- #
- proc find_leaf_events {e} {
- set leafs {}
- foreach n [get_child_events $e] {
- eval "lappend leafs [find_leaf_events $n]"
- }
-
- # if no decompositions, this event is a leaf event
- if {$leafs == {}} {
- lappend leafs $e
- }
-
- return $leafs
- }
-
- #
- # Return a list with all parent events of the specified Event
- #
- proc find_parent_events {e} {
- set parents {}
-
- set parent [get_parent_event $e]
-
- while {$parent != ""} {
- lappend parents $parent
- set parent [get_parent_event $parent]
- }
-
- return $parents
- }
-
- #
- # Return a list of methods of the given class.
- #
- # If 'super' is 1, methods of superclasses are included as well.
- #
- proc find_methods {class {super 0}} {
- set opers [$class operationSet]
-
- if {$super == 1} {
- foreach g [$class genNodeSet] {
- set new [find_methods [$g superClass] 1]
- if {$new != {}} {
- eval "lappend opers $new"
- }
- }
- }
-
- return $opers
- }
-
- #
- # Return 0 if all names in the given list are unique, 1 if one or more
- # names occur more than once.
- #
- proc is_unique_name_list {names} {
- while {![lempty $names]} {
- set p [lindex $names 0]
- set names [lreplace $names 0 0]
- if {[lsearch $names $p] != -1} {
- return 0
- }
- }
- return 1
- }
-
- #
- # Return 1 if the given event belongs to the given diagram, else 0.
- #
- proc in_diagram {e diagram} {
- set colon [string first "/" $diagram]
- if {$colon != -1} {
- incr colon
- set diagram [string range $diagram $colon end]
- }
- return [expr {$diagram == "[$e getDiagramName].[$e getDiagramType]"}]
- }
-
- #
- # Return a list of all unique names present in the passed list.
- #
- proc find_unique_names {list} {
- set unique {}
- foreach n $list {
- if {[lsearch -exact $unique $n] == -1} {
- lappend unique $n
- }
- }
- return $unique
- }
-
- #
- # Based on the access mode of an attribute (data/assoc), set the
- # method access of a synthetic operation that is generated from
- # that attribute.
- #
- # 'data' is 1 if attrib is a data attribute, 0 if it's an assoc attribute
- # 'rw_mode' is r if op is a read operation, w if it's a write operation
- #
- proc copy_access_mode {attrib op data rw_mode} {
- if {$op == ""} {
- return
- }
-
- if {$data == 1} {
- set rw [$attrib getPropertyValue attrib_access]
- } else {
- set rw [$attrib getPropertyValue assoc_access]
- }
-
- if {$rw == ""} {
- set rw {Public Public}
- } else {
- set rw [split $rw -]
- }
- set rw_index [expr {$rw_mode == "r" ? "0" : "1"}]
- $op addRunTimeProperty method_access [lindex $rw $rw_index]
-
- if {$debug} {
- puts " >>> copy_access_mode [$attrib getName] [$op getName]\
- [$op getPropertyValue method_access]"
- }
- }
-