home *** CD-ROM | disk | FTP | other *** search
- ###########################################################################
- ##
- ## Copyright (c) 1996 by Cadre Technologies Inc.
- ## and Scientific Toolworks 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.
- ## or Scientific Toolworks Inc.
- ##
- ###########################################################################
-
- global re_old_spec_def_sect
- global re_old_body_def_sect
- global re_old_subp_arr
-
- proc re_echo {line} {
- # puts stdout $line
- }
-
- proc prepare_regeneration {clname sysflag} {
- global re_old_spec_def_sect
- set re_old_spec_def_sect [section create]
- global re_old_body_def_sect
- set re_old_body_def_sect [section create]
- global re_old_subp_arr
- catch {unset re_old_subp_arr}
- parse_spec_file $clname
- if {$sysflag == 0} {parse_body_file $clname}
- }
-
- proc parse_spec_file {clname} {
- re_echo "Entering parse_spec_file: class: $clname"
-
- global ada_sections
- global re_old_spec_def_sect
- global USERINITLINE
- global OLDUSERINITLINE
- global USERINITINFO
- global WS
-
- class2tgtfiles $clname body_file spec_file
- if {![fstorage::exists $spec_file]} {
- init_user_sect ada_sections(h_user_sect_1)
- init_user_sect ada_sections(h_user_sect_2)
- init_user_sect ada_sections(h_user_sect_3)
- init_user_sect ada_sections(h_user_sect_4)
- return
- }
-
- puts stdout "Scanning $spec_file"
- #HM Added catch here - failure to open files causing tcl stack dump
- if { [ catch {set fd [fstorage::open $spec_file r]} reason ] } {
- puts stderr $reason
- m4_error $E_FILE_OPEN_READ $spec_file
- init_user_sect ada_sections(h_user_sect_1)
- init_user_sect ada_sections(h_user_sect_2)
- init_user_sect ada_sections(h_user_sect_3)
- init_user_sect ada_sections(h_user_sect_4)
- return
- }
- set line ""
- set lineno 0
-
- # skip the h_hdr_sect section
- skip_file_upto $spec_file $USERINITINFO $fd $USERINITLINE $OLDUSERINITLINE line lineno
-
- # load the h_user_sect_1 section
- load_user_sect $spec_file $fd ada_sections(h_user_sect_1) line lineno
-
- # skip the h_incl_sect section
- skip_file_upto $spec_file "package $clname is" \
- $fd "^${WS}*package ${clname} is" "" line lineno
-
- # skip the h_class_nm_sect section
- skip_file_upto $spec_file $USERINITINFO $fd $USERINITLINE $OLDUSERINITLINE line lineno
-
- # load the h_user_sect_2 section
- load_user_sect $spec_file $fd ada_sections(h_user_sect_2) line lineno
-
- # load the h_pub_data_sect .. h_priv_func_sect sections into the
- # re_old_spec_def_sect section
- load_sect_upto $spec_file $USERINITINFO $fd $USERINITLINE $OLDUSERINITLINE \
- re_old_spec_def_sect line lineno
-
- # load the h_user_sect_3 section
- load_user_sect $spec_file $fd ada_sections(h_user_sect_3) line lineno
-
- # skip the h_trailer_sect section
- skip_file_upto $spec_file "end $clname;" \
- $fd "^${WS}*end ${clname};" "" line lineno
- skip_file_upto $spec_file $USERINITINFO $fd $USERINITLINE $OLDUSERINITLINE line lineno
-
- # load the h_user_sect_4 section
- load_user_sect $spec_file $fd ada_sections(h_user_sect_4) line lineno
-
- while {[read_next_line $spec_file $fd line lineno 0]} {}
- fstorage::close $fd
- re_echo "Exitting parse_spec_file"
- }
-
- proc parse_body_file {clname} {
- re_echo "Entering parse_body_file: class: $clname"
-
- global ada_sections
- global re_old_body_def_sect
- global USERINITLINE
- global OLDUSERINITLINE
- global USERINITINFO
- global WS
-
- class2tgtfiles $clname body_file spec_file
- if {![fstorage::exists $body_file]} {
- init_user_sect ada_sections(c_user_sect_1)
- init_user_sect ada_sections(c_user_sect_2)
- init_user_sect ada_sections(c_user_sect_3)
- init_user_sect ada_sections(c_user_sect_4)
- init_user_sect ada_sections(c_user_sect_5)
- return
- }
-
- puts stdout "Scanning $body_file"
- #HM Added catch here - failure to open files causing tcl stack dump
- if { [ catch {set fd [fstorage::open $body_file r]} reason ] } {
- puts stderr $reason
- m4_error $E_FILE_OPEN_READ $body_file
- init_user_sect ada_sections(c_user_sect_1)
- init_user_sect ada_sections(c_user_sect_2)
- init_user_sect ada_sections(c_user_sect_3)
- init_user_sect ada_sections(c_user_sect_4)
- init_user_sect ada_sections(c_user_sect_5)
- return
- }
- set line ""
- set lineno 0
-
- # skip the c_hdr_sect section
- skip_file_upto $body_file $USERINITINFO $fd $USERINITLINE $OLDUSERINITLINE line lineno
-
- # load the c_user_sect_1 section
- load_user_sect $body_file $fd ada_sections(c_user_sect_1) line lineno
-
- # skip the c_class_nm_sect section
- skip_file_upto $body_file "package body $clname is" \
- $fd "^${WS}*package body ${clname} is" "" line lineno
- skip_file_upto $body_file $USERINITINFO $fd $USERINITLINE $OLDUSERINITLINE line lineno
-
- # load the c_user_sect_2 section
- load_user_sect $body_file $fd ada_sections(c_user_sect_2) line lineno
-
- # load the c_opaque_sect section into the re_old_body_def_sect
- load_sect_upto $body_file $USERINITINFO $fd $USERINITLINE $OLDUSERINITLINE \
- re_old_body_def_sect line lineno
-
- # load the c_user_sect_3 section
- load_user_sect $body_file $fd ada_sections(c_user_sect_3) line lineno
-
- # load the c_access_func_sect and c_impl_sect sections
- load_access_impl_sect $body_file $fd line lineno
-
- # load the c_user_sect_4 section
- load_user_sect $body_file $fd ada_sections(c_user_sect_4) line lineno
-
- # skip the c_trailer_sect section
- skip_file_upto $body_file "end $clname;" \
- $fd "^${WS}*end ${clname};" "" line lineno
- skip_file_upto $body_file $USERINITINFO $fd $USERINITLINE $OLDUSERINITLINE line lineno
-
- # load the c_user_sect_5 section
- load_user_sect $body_file $fd ada_sections(c_user_sect_5) line lineno
-
- while {[read_next_line $body_file $fd line lineno 0]} {}
- fstorage::close $fd
- re_echo "Exitting parse_body_file"
- }
-
- proc parse_separate_file {class subpname implsect} {
- set s 1
- if [catch {set s [parse_separate_file_actual \
- $class $subpname $implsect]} result] {
- switch $errorCode {
- ERR_REGEN {
- puts stderr $result
- set s 0
- }
- default {error $result $errorInfo $errorCode}
- }
- }
- return $s
- }
-
- proc parse_separate_file_actual {class subpname implsect} {
- # returns 1 and appends to separate_sections(c_user_sect_1), impl_sect
- # if file found
- # returns 0 and initializes separate_sections(c_user_sect_1)
- # if file not found
-
- global separate_sections
- global USERINITLINE
- global OLDUSERINITLINE
- global USERINITINFO
-
- class2separatefiles $class $subpname separate_file
- if {![fstorage::exists $separate_file]} {
- init_user_sect separate_sections(c_user_sect_1)
- return 0
- }
-
- puts stdout "Scanning $separate_file"
- #HM Added catch here - failure to open files causing tcl stack dump
- if { [ catch {set fd [fstorage::open $separate_file r]} reason ] } {
- puts stderr $reason
- m4_error $E_FILE_OPEN_READ $separate_file
- init_user_sect separate_sections(c_user_sect_1)
- return
- }
- set clname [get_name $class]
- set line ""
- set lineno 0
-
- # skip the file header section
- skip_file_upto $separate_file $USERINITINFO $fd $USERINITLINE $OLDUSERINITLINE \
- line lineno
-
- # load the c_user_sect_1 section
- load_user_sect $separate_file $fd separate_sections(c_user_sect_1) \
- line lineno
- re_echo "parse_separate_file_actual: c_user_sect_1:\n[section get_contents $separate_sections(c_user_sect_1)]"
-
- # skip the separate subprogram header section
- skip_file_upto $separate_file $USERINITINFO $fd $USERINITLINE $OLDUSERINITLINE \
- line lineno
-
- # load the c_impl_sect section
- load_user_sect $separate_file $fd implsect line lineno
- re_echo "parse_separate_file_actual: implsect:\n[section get_contents $implsect]"
-
- while {[read_next_line $separate_file $fd line lineno 0]} {}
- fstorage::close $fd
- puts stdout "Done scanning $separate_file"
- return 1
- }
-
- proc read_next_line {filename fd upline uplineno {erreof 0} {expmsg ""}} {
- upvar $upline line
- upvar $uplineno lineno
- if {[gets $fd line] < 0} {
- if {$erreof} {
- fstorage::close $fd
- set errmsg "File $filename terminated unexpectedly"
- append errmsg " at line $lineno"
- if {$expmsg != ""} {
- append errmsg "; expected to find line: $expmsg"
- }
- error "ERROR: ${errmsg}" "STOP" ERR_REGEN
- } else {
- return 0
- }
- }
- incr lineno
- if {[regexp "${WS}*${OBSOLETE}" $line] || [regexp "${WS}*${OLDOBSOLETE}" $line]} {
- fstorage::close $fd
- set errmsg "File $filename contains ${OBSOLETE} line"
- append errmsg "; regeneration failed"
- error "ERROR: ${errmsg}" "STOP" ERR_REGEN
- }
- return 1
- }
-
- proc init_user_sect {upsect} {
- global USERINITINFO
- global USEREXITINFO
- upvar $upsect sect
- section append $sect "${USERINITINFO}\n"
- section append $sect "${USEREXITINFO}\n"
- }
-
- proc skip_file_upto {filename userinfo fd expr oldexpr upline uplineno} {
- upvar $upline line
- upvar $uplineno lineno
- while {1} {
- if {[regexp -nocase $expr $line]} {return}
- if {$oldexpr != ""} {
- if {[regexp -nocase $oldexpr $line]} { return }
- }
- read_next_line $filename $fd line lineno 1 $userinfo
- }
- }
-
- proc load_sect_upto {filename userinfo fd expr oldexpr upsect upline uplineno} {
- upvar $upline line
- upvar $uplineno lineno
- upvar $upsect sect
- re_echo "Entering load_sect_upto: line: '$line'"
- while {1} {
- if {[regexp -nocase $expr $line] || [regexp -nocase $oldexpr $line]} {
- re_echo "Exitting load_sect_upto: line: '$line'"
- return
- }
- section append $sect "$line\n"
- read_next_line $filename $fd line lineno 1 $userinfo
- }
- }
-
- proc load_user_sect {filename fd upsect upline uplineno} {
- upvar $upsect sect
- upvar $upline line
- upvar $uplineno lineno
- load_user_sect_or_text $filename $fd sect 1 line lineno
- }
-
- proc load_user_text {filename fd uptext upline uplineno} {
- upvar $uptext text
- upvar $upline line
- upvar $uplineno lineno
- load_user_sect_or_text $filename $fd text 0 line lineno
- }
-
- proc load_user_sect_or_text {filename fd upresult issect upline uplineno} {
- global USEREXITLINE
- global OLDUSEREXITLINE
- global USEREXITINFO
- global WS
- global OBSOLETE
- global OLDOBSOLETE
-
- upvar $upresult result
- upvar $upline line
- upvar $uplineno lineno
-
- re_echo "Entering load_user_sect_or_text: line: '$line'"
- if {$issect} {
- if {[section get_indent_string $result] != "$OBSOLETE" &&
- [section get_indent_string $result] != "$OLDOBSOLETE"} {
- section set_indent $result 0 " "
- }
- }
- while {1} {
- if {$issect} {
- section append $result "$line\n"
- } else {
- append result "$line\n"
- }
- if {[regexp -nocase $USEREXITLINE $line] || [regexp -nocase $OLDUSEREXITLINE $line]} {
- # read next line before exitting
- read_next_line $filename $fd line lineno 0
- re_echo "Exitting load_user_sect_or_text: line: '$line'"
- return
- }
- read_next_line $filename $fd line lineno 1 $USEREXITINFO
- }
- }
-
- proc load_access_impl_sect {filename fd upline uplineno} {
- global USERINITLINE
- global OLDUSERINITLINE
- global USERINITINFO
- global WS
- upvar $upline line
- upvar $uplineno lineno
- re_echo "Entering load_access_impl_sect: line: '$line'"
- while {1} {
- if {[regexp -nocase $USERINITLINE $line] || [regexp -nocase $OLDUSERINITLINE $line]} {
- re_echo "Exitting load_access_impl_sect: line: '$line'"
- return
- } elseif {[regexp -nocase "^${WS}*procedure${WS}+" $line]} {
- load_subp $filename $fd line lineno 1
- } elseif {[regexp -nocase "^${WS}*function${WS}+" $line]} {
- load_subp $filename $fd line lineno 0
- } else {
- read_next_line $filename $fd line lineno 1 $USERINITINFO
- }
- }
- }
-
- proc load_subp {filename fd upline uplineno isproc} {
- global USERINITLINE
- global OLDUSERINITLINE
- global USERINITINFO
- global WS
- global ID
- global re_old_subp_arr
-
- upvar $upline line
- upvar $uplineno lineno
-
- set name ""
- set args ""
- set header ""
- set body ""
-
- if {$isproc} {
- set pat1 "^${WS}*procedure${WS}+(${ID})"
- set pat2 ""
- } else {
- set pat1 "^${WS}*function${WS}+(${ID}|\".*\")"
- set pat2 "return${WS}+${ID}"
- }
-
- re_echo "Entering load_subp: line: '$line'"
- if {[regexp -nocase "(${pat1})${WS}*\$" $line junk header name]} {
- #
- # matched: "procedure Name"
- # or: "function Name"
- #
- set header [string trim $header]
- while {[read_next_line $filename $fd line lineno 1 \
- "\[...) \]is\[ separate;\]"]} {
-
- if {[regexp -nocase \
- "(${WS}*${pat2})?${WS}*is${WS}*( separate;)?\$" \
- $line junk temp body]} {
- #
- # matched: "is[ separate;]"
- # or: "return Type is[ separate;]"
- #
- set temp [string trim $temp]
- if {$temp != ""} {
- append header " $temp"
- }
- break
-
- } elseif {[regexp -nocase \
- "(.+\\)(${WS}*${pat2})?)${WS}*is${WS}*( separate;)?\$" \
- $line junk1 temp junk2 body]} {
- #
- # matched: "...) is[ separate;]"
- # or: "...) return Type is[ separate;]"
- #
- set temp [string trim $temp]
- if {$temp != ""} {
- append header " $temp"
- }
- break
- }
- set line [string trim $line]
- if {$line != ""} {
- append header " $line"
- }
- }
-
- } elseif {[regexp -nocase \
- "(${pat1}(${WS}+${pat2})?)${WS}+is${WS}*( separate;)?\$" \
- $line junk1 header name junk2 body]} {
- #
- # matched: "procedure Name is[ separate;]"
- # or: "function Name return Type is[ separate;]"
- #
- set header [string trim $header]
-
- } elseif {[regexp -nocase \
- "(${pat1}${WS}*\\(.*\\)(${WS}*${pat2})?)${WS}*is${WS}*( separate;)?\$" \
- $line junk1 header name junk2 body]} {
- #
- # matched: "procedure Name (Args) is[ separate;]"
- # or: "function Name (Args) return Type is[ separate;]"
- #
- set header [string trim $header]
-
- } else {
- fstorage::close $fd
- error "file $filename, line $lineno: improper subprogram header format" "STOP" ERR_REGEN
- }
-
- if {$body == ""} {
- #
- # look for a user-written body
- #
- while {[read_next_line $filename $fd line lineno 1 \
- "'begin' or '${USERINITINFO}'"]} {
- if {[regexp -nocase "^${WS}*begin(\$|${WS}+|--)" $line]} {
- break
- } elseif {[regexp -nocase ${USERINITLINE} $line] || [regexp -nocase ${OLDUSERINITLINE} $line]} {
- #
- # load the user-written body
- #
- load_user_text $filename $fd body line lineno
- break
- }
- }
- } else {
- # read next line before exitting
- read_next_line $filename $fd line lineno 0
- }
-
- re_echo "load_subp: name: '$name'"
- re_echo "load_subp: header: '$header'"
- re_echo "load_subp: body: '$body'"
-
- # If a user-written body (or the "separate;" clause) was found for the
- # subprogram, add the header and body (or "separate;") to the global
- # array 're_old_subp_arr'. The index to the array is the name of the
- # subprogram. The value of an array element is a list of (overloaded)
- # subprogram header and body pairs. For each overloaded subprogram
- # this list is extended with another header and body pair. The order
- # of this list is the file order.
-
- if {$body != ""} {
- if [info exists re_old_subp_arr($name)] {
- lappend re_old_subp_arr($name) $header
- lappend re_old_subp_arr($name) $body
- } else {
- set re_old_subp_arr($name) [list $header $body]
- }
- }
-
- re_echo "Exitting load_subp: line: '$line'"
- }
-
- # provide a method body; a default message or a previously edited one
- # look in global array 're_old_subp_arr' for user added method bodies.
- #
- # if var_name is not empty, this name is used for the ...not_yet_implemented
- # variable
-
- proc get_method_body {name method_type c_sect opername} {
- puts stdout "WARNING: use get_subp_user_body instead of get_method_body"
- }
-
- proc get_subp_user_body {class subpname subpheader implsect} {
- # returns 1 and appends user-written body to implsect if found, and if
- # separate file is parsed, also sets separate_sections(c_
- # user_sect_1) from file
- # returns -1 and appends user-written body prefixed by "-- OBSOLETE:"
- # to implsect if name matched but not header
- # returns 0 and appends dummy body if body not found
-
- global re_old_subp_arr
- global separate_sections
-
- if {![info exists re_old_subp_arr($subpname)]} {
- if {[info exists separate_sections(c_user_sect_1)]} {
- init_user_sect separate_sections(c_user_sect_1)
- }
- append_null_body $subpname $implsect
- return 0
- }
-
- re_echo "get_subp_user_body: inp header: $subpheader"
- regsub -all "${WS}*\n${WS}*" [string trim $subpheader] " " subpheader
- re_echo "get_subp_user_body: trm header: $subpheader"
- set avail [lsearch -exact $re_old_subp_arr($subpname) $subpheader]
- if {$avail != -1} {
- #
- # full match, name and header, pop the header, append the body
- #
- lvarpop re_old_subp_arr($subpname) $avail
- set body [lvarpop re_old_subp_arr($subpname) $avail]
- if {[llength $re_old_subp_arr($subpname)] == 0} {
- unset re_old_subp_arr($subpname)
- }
- if {[regexp -nocase "^${WS}*separate;${WS}*\$" $body]} {
- if {[parse_separate_file $class $subpname $implsect]} {
- return 1
- } else {
- append_null_body $subpname $implsect
- return 0
- }
- } else {
- set indcnt 0
- while {[section get_indent $implsect] > 0} {
- section set_indent $implsect -
- incr indcnt
- }
- section append $implsect "$body"
- while {$indcnt > 0} {
- section set_indent $implsect +
- incr indcnt -1
- }
- return 1
- }
- } else {
- # name matched, but not the header, parameters probably changed
- # just pick the first one of the list
-
- puts stdout "WARNING: generated OBSOLETE section"
-
- lvarpop re_old_subp_arr($subpname)
- set body [lvarpop re_old_subp_arr($subpname)]
- if {[llength $re_old_subp_arr($subpname)] == 0} {
- unset re_old_subp_arr($subpname)
- }
- set tempsect [section create]
- section set_indent $tempsect 1 "${OBSOLETE}"
- if {[regexp -nocase "^${WS}*separate;${WS}*\$" $body]} {
- parse_separate_file $class $subpname $tempsect
- } else {
- section append $tempsect "$body"
- }
- section append $implsect "${USERINITINFO}\nbegin\n"
- section append_section $implsect $tempsect
- section append $implsect "end ${subpname};\n${USEREXITINFO}\n"
- section dealloc $tempsect
- return -1
- }
- return 0
- }
-
- proc append_null_body {subpname sect} {
- section append $sect "${USERINITINFO}\nbegin\n"
- section append $sect " -- !! Implement this subprogram !!\n"
- section append $sect "end ${subpname};\n${USEREXITINFO}\n"
- }
-
- proc del_subp_info {class subpname subpheader} {
- # returns 1 and deletes header and body if subprogram found
- # returns 0 if body not found
-
- puts stdout "proc del_subp_info called!!"
-
- global re_old_subp_arr
- if {![info exists re_old_subp_arr($subpname)]} {
- return 0
- }
-
- set avail [lsearch -exact $re_old_subp_arr($subpname) $subpheader]
- if {$avail != -1} {
- lvarpop re_old_subp_arr($subpname) $avail
- lvarpop re_old_subp_arr($subpname) $avail
- } else {
- # just delete the first one
- lvarpop re_old_subp_arr($subpname)
- lvarpop re_old_subp_arr($subpname)
- }
- if {[llength $re_old_subp_arr($subpname)] == 0} {
- unset re_old_subp_arr($subpname)
- }
- }
-
- proc append_obsolete_code {class} {
- global re_old_subp_arr
- global OBSOLETE
-
- if {![info exists re_old_subp_arr]} {
- return
- }
- if {[array names re_old_subp_arr] == ""} {
- return
- }
-
- puts "WARNING: appending obsolete code section"
-
- set sect [section create]
- section set_indent $sect 1 "${OBSOLETE}"
- foreach subp [array names re_old_subp_arr] {
- while {[llength $re_old_subp_arr($subp)] != 0} {
- section append $sect "[lvarpop re_old_subp_arr($subp)]\n"
- }
- }
- section append_section $ada_sections(c_user_sect_5) $sect
- section dealloc $sect
- }
-