home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PC World 1998 October
/
PCWorld_1998-10_cd.bin
/
software
/
prehled
/
komix
/
DATA.Z
/
ada95_funcs.tcl
< prev
next >
Wrap
Text File
|
1997-10-20
|
70KB
|
2,115 lines
###########################################################################
##
## 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.
##
###########################################################################
require a95genmsg.tcl
proc oopl_model::generate {model} {
global root_classes root_class g_op_list g_assoc_list
global g_local_op_count g_local_op_list link_class_added
global cur_model
## HM - added g_local_assoc_count to count association components
## HM - added g_local_pub_assoc_access_count and g_local_priv_assoc_access_count
## HM - added g_local_pub_attr_access_count and g_local_priv_attr_access_count
global g_local_assoc_count
global g_local_pub_assoc_access_count
global g_local_priv_assoc_access_count
global g_local_pub_attr_access_count
global g_local_priv_attr_access_count
set cur_model $model
check_unique_file_names $model
echo "Generating Ada 95 code..."
set g_assoc_list ""
set root_classes ""
set pers_class_exists 0
set got_a_class 0
create_ada95_sections $ada95_hdr_sections
init_sys_sections $sysfile_name
#HM moved class2tgtfiles outside of if and call is_file_regenerated with h_filename
#HM instead of sysfile_name
class2tgtfiles $sysfile_name c_filename h_filename
if {[is_file_regenerated $h_filename]} {
if [catch {prepare_regeneration $sysfile_name 1} result] {
# something went wrong, find out what
switch $errorCode {
ERR_REGEN {
puts stderr $result
return
}
default {error $result $errorInfo $errorCode}
}
}
}
echo "Looping for each class in model"
foreach class [get_classes $model] {
set class_name [get_name $class]
echo $class_name
global link_incl_list
set link_incl_list ""
set got_a_class 1
set skip [skip_class $class 0]
if {$skip == 2} {set pers_class_exists 1}
if {$skip != 0} {continue}
set class_name [get_name $class]
echo "Setting g_op_list for "
echo $class_name
set g_op_list($class_name) ""
if {[get_super_classes $class] == "" } {
echo "subclasses = [get_sub_classes $class]"
if {[get_sub_classes $class] != ""} {
# append root_classes "$class "
}
}
foreach super [get_super_classes $class] {
set super_name [get_super_name $super]
}
gen_assoc_list $class
if {[get_obj_type $class] == "class_typedef" ||
[get_obj_type $class] == "class_enum"} {
generate $class
}
}
write_sys_sections $sysfile_name $ada95_hdr_sections
if {$pers_class_exists == 1} {
puts stderr "At least one class in the model is persistent."
puts stderr "Ada code cannot be generated."
return
}
echo "association list: $g_assoc_list"
echo "Root Classes:"
foreach root_class $root_classes {
echo " [get_name $root_class]"
set g_class_list([get_name $root_class]) "$root_class "
gen_op_lists $root_class
}
if {$got_a_class == 1} {
foreach i [array names g_op_list] {
echo "$i:"
foreach j $g_op_list($i) {
set cname [get_name [split_op_list_entry $j class]]
set inh_access [split_op_list_entry $j inh]
echo " $cname ($inh_access)"
}
}
}
foreach class [get_classes $model] {
set g_local_assoc_count 0
set g_local_pub_assoc_access_count 0
set g_local_priv_assoc_access_count 0
set g_local_pub_attr_access_count 0
set g_local_priv_attr_access_count 0
set g_local_op_count 0
if {[skip_class $class 1] == 1 ||
[get_obj_type $class] == "class_typedef" ||
[get_obj_type $class] == "class_enum"} {
continue
}
class2tgtfiles [get_name $class] nts nth
global skip_file
global gen_file
global import_new
if [info exists gen_file($nth)] {
set gen_file($nts) 1
}
if {[get_class_source $class] != ""} {
process_external_class_source $class
continue
}
if {( $import_new &&
([is_special_class $class] || [info exists skip_file($nts)]) &&
[info exists skip_file($nth)]) ||
( ! $import_new && ! [info exists gen_file($nts)] &&
! [info exists gen_file($nth)] )} {
continue
}
echo " Class Type = [get_obj_type $class]"
set link_class_added 0
generate $class
for {set x 0} {$x < $g_local_op_count} {incr x} {
unset g_local_op_list($x)
}
}
}
proc skip_class {class flag} {
if {[is_db_class $class] == 1} {
echo "Class is persistent"
m4_error $E_PERSISTCLASS [get_name $class]
return 2
}
if [is_external $class] {
echo "Class is external"
return 1
}
if {[get_name $class] == ""} {
echo "Class has no name"
if {$flag == 1} {puts stderr "Class without name skipped"}
return 1
}
echo "Skip_class returning 0"
return 0
}
# Check uniqueness of filenames
#
proc check_unique_file_names {model} {
foreach class [get_classes $model] {
set cl_name [get_name $class]
set file_name [class2file $cl_name]
if [is_external $class] {
continue
}
if [info exists names($file_name)] {
error "Classes '$cl_name' and '$names($file_name)' map to the same file name" "" ERR_UNIQUE_FILENAME
}
set names($file_name) $cl_name
}
}
proc class::generate {class} {
#HM added g_component_count to know when to add "null" to record declaration
global g_component_count
set g_component_count 0
create_ada95_sections [concat $ada95_hdr_sections $ada95_src_sections]
init_ada95_sections $class
if [catch {prepare_regeneration [get_name $class] 0} result] {
# something went wrong, find out what
switch $errorCode {
ERR_REGEN {
puts stderr $result
return
}
default {error $result $errorInfo $errorCode}
}
class2tgtfiles [get_name $class] src_file h_file
global gen_file
catch {unset gen_file($src_file)}
if {! [info exists gen_file($h_file)]} {
return
}
}
set hsect $ada95_sections(h_hdr_sect)
set csect $ada95_sections(c_hdr_sect)
set class_name [get_name $class]
section append $hsect "-- Specification file for ${class_name}\n\n"
section append $csect "-- Body file for ${class_name}\n\n"
puts stdout "Generating for class '${class_name}'"
gen_hdr_incs $class
class::gen_description $class $ada95_sections(h_class_nm_sect)
set is_db 0
add_src_inc $class
set class_visibility [gen_class_decl $class]
# This generates attributes & operation definitions...
#
foreach feat [get_features $class] {
set feat_type [get_obj_type $feat]
echo " feature type = $feat_type"
set inh_mode 0
if {$feat_type == "operation"} {
generate $feat $class $class_name $inh_mode
} else {
generate $feat $class
}
}
# Only do the following if we want to generate the oplist for parent RUH
# gen_inherited_ops $class
gen_delayed_code
gen_end_protector $class
append_obsolete_code $class
exit_ada95_sections $class
write_ada95_sections $class $ada95_hdr_sections $ada95_src_sections
global link_incl_list
set link_incl_list ""
}
proc class::gen_description {class sect} {
set ftext [$class getFreeText]
if {$ftext != ""} {
section append $sect "\n"
string_to_oopl_comment $sect $ftext
section append $sect "\n"
}
}
proc class_enum::generate {class} {
set sect $ada95_sections(h_pub_data_sect)
set enum_name [get_name $class]
section append $sect "type $enum_name is ("
set first 1
foreach attrib [get_features $class] {
if {$first == 0} {section append $sect ","}
section append $sect "[get_name $attrib]"
set first 0
}
section append $sect ");\n\n"
#puts stderr "ERROR: Enum classes are not supported for Ada"
return
}
proc class_typedef::generate {class} {
set subtype_name [get_full_class_name $class]
set attrib [lindex [get_features $class] 0]
set type_name [get_name [get_type $attrib]]
set subtype_text [get_subtype_text $class]
section append $ada95_sections(h_pub_data_sect) \
"subtype $subtype_name is ${type_name} ${subtype_text};\n\n"
}
proc class_generic_typedef::generate {class} {
if {[get_name $class] == ""} {
puts stderr "Class without name skipped"
return
}
class::generate $class
return
}
proc class_typedef::gen_class_decl {class} {
class::gen_class_decl $class
}
proc class_generic_typedef::gen_class_decl {class} {
class::gen_class_decl $class
}
proc gen_end_protector {class} {
set class_name [get_name $class]
set full_class_name [get_full_class_name $class]
set protector [protector_name $class_name]
section append $ada95_sections(h_trailer_sect) \
"end $full_class_name;\n"
}
proc class::gen_class_decl {class} {
set class_name [get_name $class]
set h_sect $ada95_sections(h_class_nm_sect)
set c_sect $ada95_sections(c_class_nm_sect)
set class_name [get_name $class]
set class_visibility [get_class_vis $class]
echo "class name = $class_name ($class_visibility)"
section append $h_sect "package [ get_full_class_name $class ] is \n"
section append $c_sect "package body [ get_full_class_name $class ] is \n"
set h_sect $ada95_sections(h_pub_data_sect)
set c_sect $ada95_sections(c_opaque_sect)
case $class_visibility in {
{Private} {
if { [get_ada95_super_classes $class] == "" && [get_sub_classes $class] != "" } {
section append $h_sect "\ntype $g_record_name is tagged private;\n"
} else {
section append $h_sect "\ntype $g_record_name is private;\n"
}
}
{Limited} {
if { [get_ada95_super_classes $class] == "" && [get_sub_classes $class] != "" } {
section append $h_sect "\ntype $g_record_name is tagged limited private;\n"
} else {
section append $h_sect "\ntype $g_record_name is limited private;\n"
}
}
{Extensions} {
if { [get_ada95_super_classes $class] != ""} {
set parents [get_super_classes $class]
if {[lempty $parents]} {
if {[get_controlled_type $class] == "Controlled"} {
section append $h_sect \
"\ntype $g_record_name is new Ada.Finalization.Controlled with private;\n"
} elseif {[get_controlled_type $class] == "Limited Controlled"} {
section append $h_sect \
"\ntype $g_record_name is new Ada.Finalization.Limited_Controlled with private;\n"
} else {
m4_error $E_PRIVEXTNOPARENT [get_name $class]
if { [get_sub_classes $class] != "" } {
section append $h_sect "\ntype $g_record_name is tagged private;\n"
} else {
section append $h_sect "\ntype $g_record_name is private;\n"
}
}
} else {
set parent [get_super_class [lindex $parents 0]]
set pname [get_full_class_name $parent]
section append $h_sect "\ntype $g_record_name is new $pname.$g_record_name with private;\n"
}
} else {
m4_error $E_PRIVEXTNOPARENT [get_name $class]
if { [get_sub_classes $class] != "" } {
section append $h_sect "\ntype $g_record_name is tagged private;\n"
} else {
section append $h_sect "\ntype $g_record_name is private;\n"
}
}
}
{Opaque} {
set o_sect $ada95_sections(h_priv_data_sect)
section append $h_sect "type $g_record_name is limited private;\n"
section append $h_sect "type $g_handle_name is access $g_record_name;\n"
#HM only declare Class_... if the type will be tagged
if { [get_sub_classes $class] != "" } {
section append $h_sect "type Class_$g_handle_name is access $g_record_name'Class;\n"
}
section append $o_sect "type $o_record_name;\n"
section append $o_sect "type $g_record_name is access $o_record_name;\n"
if { [get_ada95_super_classes $class] == "" &&
[get_sub_classes $class] != "" } {
section append $c_sect "type $o_record_name is tagged record\n"
} else {
section append $c_sect "type $o_record_name is record\n"
}
section set_indent $c_sect +
}
}
return $class_visibility
}
proc gen_inherited_ops {class} {
global inh_operation_list inh_op_table inh_op_type_list operation_count
global g_op_list_type g_inh_op_count link_incl_list
set class_name [get_name $class]
set operation_count -1
set g_inh_op_count 0
set link_incl_list ""
foreach super [get_super_classes $class] {
generate $super $class
}
for {set x 0} {$x <= $operation_count} {incr x} {
set feat_name [lrange $inh_operation_list($x) 0 0]
if {$g_op_list_type($x) == 0} {
set f_sect $ada95_sections(c_access_func_sect)
if {$f_sect != ""} {section append $f_sect "\n"}
} else {
if {$g_op_list_type($x) == 1} {
set f_sect $ada95_sections(c_impl_sect)
}
}
set prefix ""
if {[section get_line_nr $g_operation_list2($x)] > 2} {
set prefix "-- "
}
section set_indent $g_operation_list($x) + 1 " ${prefix}"
section append_section $g_operation_list($x) $g_operation_list2($x)
section append_section $f_sect $g_operation_list($x)
section append $f_sect "end $feat_name;\n"
section dealloc $g_operation_list($x)
section dealloc $g_operation_list2($x)
}
}
proc link_class::generate {class} {
# puts stdout "Generating for link class '[get_name $class]'"
if {[get_name $class] == ""} {
puts stderr "Link class without name skipped"
return
}
class::generate $class
}
proc link_class::gen_class_decl {class} {
class::gen_class_decl $class
}
proc append_to_op_list {inh_op_sect flag} {
global operation_count
set ok_to_append 1
for {set x 0} {$x < $operation_count} {incr x} {
if {[section get_contents $g_operation_list($x)] == \
[section get_contents $g_operation_list($operation_count)]} {
if {[section get_contents $g_operation_list2($x)] != \
[section get_contents $g_operation_list2($operation_count)]} {
section append_section $g_operation_list2($x) \
$g_operation_list2($operation_count)
}
set ok_to_append 0
section dealloc $g_operation_list($operation_count)
section dealloc $g_operation_list2($operation_count)
incr operation_count -1
}
}
if {$ok_to_append == 1} {
global g_op_list_type
if {$flag == 1} {
set g_op_list_type($operation_count) 1
section append_section $inh_op_sect $tmp_h_sect
} else {
set g_op_list_type($operation_count) 0
}
}
}
proc inher_group::generate {group class} {
global g_op_list
global tmp_h_sect
set class_name [get_name $class]
set i_sect $ada95_sections(h_incl_sect)
set sect $ada95_sections(h_class_nm_sect)
set super_name [get_super_name $group]
add_hdr_inc [get_super_class $group] ;# includes class' include file
add_incl_stmnt $super_name $i_sect
set sect2 [get_data_section $class]
if {[get_class_vis $class] == "Public"} {
set inh_op_sect $ada95_sections(h_pub_func_sect)
} else {
set inh_op_sect $ada95_sections(h_priv_func_sect)
}
section append $sect2 "${super_name}${g_inh_ext} : ${super_name}.$g_record_name;\n"
incr_component_count
set inh_mode 1
set super_inh_access [get_inher_access $group]
if {$super_inh_access == ""} {set inh_access "Public"}
set current_op_list "[get_super_class $group]:$super_inh_access "
append current_op_list $g_op_list($super_name)
foreach entry $current_op_list {
set inh_class [split_op_list_entry $entry class]
set inh_access [split_op_list_entry $entry inh]
echo "inh_access = $inh_access for [get_name $inh_class] of $class_name"
if {$super_inh_access == "Private" || $inh_access == "Private"} {continue}
foreach feat [get_features $inh_class] {
set inh_op_sect [get_func_section $feat]
if {$inh_op_sect != $ada95_sections(h_pub_func_sect)} {continue}
set feat_type [get_obj_type $feat]
set inh_name [get_name [get_super_class $group]]
if {$feat_type == "constructor"} {continue}
echo " Inherited feature: [get_name $feat] ($feat_type)"
if {$feat_type == "operation"} {
if {[get_the_class_feature $feat] == 1} {continue}
if {[generate $feat $inh_class $inh_name $inh_mode] == -1} {continue}
append_to_op_list $inh_op_sect 1
set tmp_h_sect [section create]
} else {
set type [get_${feat_type}_type_name $feat]
set result [gen_access_hdr $feat $type 1]
echo "RESULT = $result"
set name [get_full_feat_name $feat]
if {[get_attrib_hdr_sect $feat r] == $ada95_sections(h_pub_access_sect)} {
if {$result == 1 || $result == 3} {
gen_access_body "get" $feat $class $inh_name $type 1 \
"Get_${name} (Self.${inh_name}${g_inh_ext});\n"
}
}
append_to_op_list $inh_op_sect 0
if {[get_attrib_hdr_sect $feat w] == $ada95_sections(h_pub_access_sect)} {
if {$result > 1} {
gen_access_body "set" $feat $class $inh_name $type 1 \
"Set_${name} (Self.${inh_name}${g_inh_ext}, New_${name});\n"
}
}
append_to_op_list $inh_op_sect 0
}
}
}
}
proc get_full_feat_name {feat} {
set name [cap [map_oper [get_name $feat]]]
set type [cap [get_name [get_type $feat]]]
if {$name == $type} {
return "${name}_${g_qualified_rname}"
} else {
return $name
}
}
proc ok_to_add {inh_flag sect name} {
set flag 0
if {$inh_flag == 0} {
if {$sect != $ada95_sections(dev_null_sect)} {
set flag 1
}
} else {
if {$sect == $ada95_sections(h_pub_access_sect)} {
set flag 1
}
}
return $flag
}
proc process_local_op_list {inh_flag real_sect tmp_sect} {
set method_type [section get_contents $tmp_sect]
if {$inh_flag ==0} {
add_to_local_op_list $method_type
section append_section $real_sect $tmp_sect
return 1
} else {
if {[check_local_op_list $method_type] == 1} {
return 0
} else {
global g_inh_op_count
global g_inh_op_list
echo "METHOD = $method_type"
for {set x 0} {$x < $g_inh_op_count} {incr x} {
set inh_op [section get_contents $g_inh_op_list($x)]
echo "INH_OP = $inh_op"
if {[section get_contents $g_inh_op_list($x)] == $method_type} {return 1}
}
section append_section $real_sect $tmp_sect
return 1
}
}
}
proc get_get_sig {static_val} {
if {$static_val == 0} {
return "(Self : ${g_record_name}) "
} else {
return ""
}
}
proc get_set_sig {static_val} {
if {$static_val == 0} {
return "Self : in out ${g_record_name}; "
} else {
return ""
}
}
proc gen_access_cmmt {is_data hdr_type tmp_sect} {
global g_local_priv_assoc_access_count
global g_local_pub_assoc_access_count
global g_local_priv_attr_access_count
global g_local_pub_attr_access_count
global ASSOCACCESSCMMT
global ATTRACCESSCMMT
if {$is_data == 1} {
if {$hdr_type == "Private"} {
incr g_local_priv_attr_access_count 1
if {$g_local_priv_attr_access_count == 1} {
section append $tmp_sect $ATTRACCESSCMMT
section append $tmp_sect "\n"
}
} else {
incr g_local_pub_attr_access_count 1
if {$g_local_pub_attr_access_count == 1} {
section append $tmp_sect $ATTRACCESSCMMT
section append $tmp_sect "\n"
}
}
} else {
if {$hdr_type == "Private"} {
incr g_local_priv_assoc_access_count 1
if {$g_local_priv_assoc_access_count == 1} {
section append $tmp_sect $ASSOCACCESSCMMT
section append $tmp_sect "\n"
}
} else {
incr g_local_pub_assoc_access_count 1
if {$g_local_pub_assoc_access_count == 1} {
section append $tmp_sect $ASSOCACCESSCMMT
section append $tmp_sect "\n"
}
}
}
}
proc gen_access_hdr {feat type inh_flag} {
global g_local_assoc_access_count
global g_local_attr_access_count
global ASSOCACCESSCMMT
global ATTRACCESSCMMT
set static_val [get_the_class_feature $feat]
if {$inh_flag == 1} {
if {$static_val == 1} {
return
} else {
set static_val 0
}
}
set name [get_full_feat_name $feat]
set tmp_get_sect [section create]
set tmp_set_sect [section create]
if {[get_obj_type $feat] == "data_attrib"} {
set get_sect [get_attrib_hdr_sect $feat r]
set set_sect [get_attrib_hdr_sect $feat w]
set get_hdr_type [get_attrib_hdr_type $feat r]
set set_hdr_type [get_attrib_hdr_type $feat w]
set is_data 1
} else {
set get_sect [get_assoc_hdr_sect $feat r]
set set_sect [get_assoc_hdr_sect $feat w]
set get_hdr_type [get_assoc_hdr_type $feat r]
set set_hdr_type [get_assoc_hdr_type $feat w]
set is_data 0
}
set gname "Get_${name}"
set sname "Set_${name}"
set c_sect $ada95_sections(c_access_func_sect)
set result 0
if {[ok_to_add $inh_flag $get_sect $gname] == 1} {
gen_access_cmmt $is_data $get_hdr_type $tmp_get_sect
set get_line "function $gname [get_get_sig $static_val]return $type"
section append $tmp_get_sect "${get_line};\n\n"
set success [process_local_op_list $inh_flag $get_sect $tmp_get_sect]
if {$success == 1} {incr result 1}
}
if {[ok_to_add $inh_flag $set_sect $sname] == 1} {
gen_access_cmmt $is_data $set_hdr_type $tmp_set_sect
set set_line "procedure $sname ([get_set_sig $static_val]New_${name} : $type)"
section append $tmp_set_sect "${set_line};\n\n"
set success [process_local_op_list $inh_flag $set_sect $tmp_set_sect]
if {$success == 1} {incr result 2}
}
return $result
}
proc gen_access_body {flag feat class inh_name type inh_flag line2} {
set feat_name [get_full_feat_name $feat]
set class_name [get_name $class]
set static_val [get_the_class_feature $feat]
if {$inh_flag == 0} {
set line3 " "
set tmp_sect [section create]
} else {
if {$static_val == 1} {
return
} else {
set static_val 0
}
}
if {$flag == "get"} {
if {[get_obj_type $feat] == "data_attrib"} {
set get_sect [get_attrib_hdr_sect $feat r]
} else {
set get_sect [get_assoc_hdr_sect $feat r]
}
set name "Get_${feat_name}"
if {[ok_to_add $inh_flag $get_sect $name] == 0} {return}
set line1 "function $name [get_get_sig $static_val]return $type"
append line3 "return "
} else {
if {[get_obj_type $feat] == "data_attrib"} {
set set_sect [get_attrib_hdr_sect $feat w]
} else {
set set_sect [get_assoc_hdr_sect $feat w]
}
set name "Set_${feat_name}"
if {[ok_to_add $inh_flag $set_sect $name] == 0} {return}
set line1 "procedure $name ([get_set_sig $static_val]New_${feat_name} : $type)"
}
if {$static_val == 1} {
append line3 $line2
} else {
append line3 "${inh_name}." $line2
}
if {$inh_flag == 1} {
set tmp_c_sect2 [section create]
global g_operation_list g_operation_list2 inh_operation_list operation_count
global g_inh_op_list g_inh_op_count
incr operation_count
set inh_operation_list($operation_count) "$name "
set g_operation_list($operation_count) [section create]
set tmp_sect $g_operation_list($operation_count)
set g_operation_list2($operation_count) [section create]
set tmp_sect2 $g_operation_list2($operation_count)
section append $tmp_sect2 $line3
set g_inh_op_list($g_inh_op_count) [section create]
section append $g_inh_op_list($g_inh_op_count) "${line1};\n\n"
incr g_inh_op_count
}
section append $tmp_sect "${line1} is\n"
section append $tmp_sect "begin\n"
if {$inh_flag == 0} {
section append $tmp_sect $line3
section append $tmp_sect "end ${name};\n\n"
set c_sect $ada95_sections(c_access_func_sect)
section append_section $c_sect $tmp_sect
}
}
proc feature::gen_description {feature sect} {
set ftext [$feature getFreeText]
if {$ftext != ""} {
string_to_oopl_comment $sect $ftext
}
}
proc get_qual_type {type sect} {
#HM added this routine to get a qualifier type name and with sys types if needed
global cur_model
#HM - removed cap from "set type_name" - this causes change in round trip
set type_name [get_name $type]
if {$type_name == ""} {return "void "}
set obj_type [get_obj_type $type]
if {$obj_type == "class_type"} {
set p_type [ $cur_model classByName $type_name ]
if {$p_type != ""} {
set p_type_name [get_full_class_name $p_type]
add_incl_stmnt $p_type_name $sect
set real_g_handle_name [get_g_handle_name $type_name]
set type_name $p_type_name
append type_name "."
append type_name $real_g_handle_name
}
} elseif { $obj_type == "base_type" } {
set type_name [$type getType3GL]
} elseif { $obj_type == "typedef_type" } {
set p_type [cap [getCurrentSystemName]]_Types.$type_name
set type_name $p_type
set sys_types_name [cap [getCurrentSystemName]]_Types
add_incl_stmnt $sys_types_name $sect
} elseif { $obj_type == "enum_type" } {
set p_type [cap [getCurrentSystemName]]_Types.$type_name
set type_name $p_type
set sys_types_name [cap [getCurrentSystemName]]_Types
add_incl_stmnt $sys_types_name $sect
}
return $type_name
}
proc get_full_type {type} {
global cur_model
#HM - removed cap from "set type_name" - this causes change in round trip
set type_name [get_name $type]
if {$type_name == ""} {return "void "}
set obj_type [get_obj_type $type]
if {$obj_type == "class_type"} {
set p_type [ $cur_model classByName $type_name ]
if {$p_type != ""} {
set p_type_name [get_full_class_name $p_type]
add_incl_stmnt $p_type_name $ada95_sections(h_incl_sect)
set real_g_handle_name [get_g_handle_name $type_name]
set type_name $p_type_name
append type_name "."
append type_name $real_g_handle_name
}
} elseif { $obj_type == "base_type" } {
set type_name [$type getType3GL]
} elseif { $obj_type == "typedef_type" } {
set p_type [cap [getCurrentSystemName]]_Types.$type_name
set type_name $p_type
} elseif { $obj_type == "enum_type" } {
set p_type [cap [getCurrentSystemName]]_Types.$type_name
set type_name $p_type
}
return $type_name
}
proc data_attrib::generate {attrib class} {
#HM removed cap from "set name" - this was causing attrib delete and add in roundtrip
set static_var [get_the_class_feature $attrib]
set sect [get_data_section $class]
set name [get_name $attrib]
set type [get_type $attrib]
set obj_type [get_obj_type $type]
#HM removed cap from "set type_name" - this was causing change in round trip
set type_name [get_name $type]
echo " data attribute $name ($type_name)"
feature::gen_description $attrib $sect
if {[get_the_class_feature $attrib] == 1} {
if {[get_class_vis $class] != "Opaque"} {
set sect $ada95_sections(h_static_data_sect)
} else {
set sect $ada95_sections(c_static_data_sect)
}
} else {
incr_component_count
}
set type_name [get_full_type [get_type $attrib]]
section append $sect "$name : $type_name;\n"
gen_access_hdr $attrib $type_name 0
set name [cap [get_name $attrib]]
gen_access_body "get" $attrib $class "Self" $type_name 0 "${name};\n"
gen_access_body "set" $attrib $class "Self" $type_name 0 "${name} := New_${name};\n"
}
# Common generate dispatch function for associations
#
proc gen_for_assoc {attrib class} {
set prefix "[get_obj_type $attrib]::[get_multiplicity $attrib]"
echo "prefix = $prefix"
${prefix}_inter_pkg $attrib
${prefix}_data $attrib $class
}
# Common generate dispatch function for database associations
#
proc gen_for_db_assoc {attrib class} {
# do nothing!
}
# Common generate dispatch function for links
#
proc gen_for_link {attrib class} {
set prefix "assoc_attrib::[get_multiplicity $attrib]"
${prefix}_inter_pkg $attrib
${prefix}_data $attrib $class
}
# Common generate dispatch function for reverse links
#
proc gen_for_rv_link {attrib class} {
set prefix "assoc_attrib::[get_multiplicity $attrib]"
echo "prefix = $prefix"
${prefix}_inter_pkg $attrib
${prefix}_data $attrib $class
}
proc assoc_attrib::generate {attrib class} {
#HM added check for bidirectional association
global g_local_assoc_count
global ASSOCCMMT
if {[get_opposite $attrib] != ""} {
set type [get_type $attrib]
if {[get_class_visibility $class] != "Opaque" || \
[get_class_visibility $type] != "Opaque"} {
m4_error $E_BIDIRASSOC [get_name $class] [get_name $type]
return
}
}
set sect [get_data_section $class]
incr g_local_assoc_count 1
if {$g_local_assoc_count == 1} {
section append $sect $ASSOCCMMT
section append $sect "\n"
}
gen_for_assoc $attrib $class
}
proc assign_var {to from type_obj {sect "src"}} {
if [type_is_char_array $type_obj] {
add_[determine_sect_type $sect]_inc_name "string" "h"
return "strcpy($to, $from);"
}
return "$to = $from;"
}
proc gen_assoc_access_sects {class attrib type} {
gen_access_hdr $attrib $type 0
set name [cap [get_name $attrib]]
gen_access_body "get" $attrib $class "Self" $type 0 "${name};\n"
gen_access_body "set" $attrib $class "Self" $type 0 "${name} := New_${name};\n"
}
proc gen_link_class_alt_additions {class i_sect} {
global link_class_added
global LINKPACKAGECMMT
global LINKCONVCMMT
echo "class type = [get_obj_type $class]"
set name "[get_name $class]${g_alt_link_class_ext}"
if {[get_obj_type $class] == "class_typedef" || [get_obj_type $class] == "link_class"} {
if {$link_class_added == 0} {
add_incl_stmnt $name $i_sect
set type1 ${name}.[get_g_handle_name $name]
set type2 $g_handle_name
set h_sect $ada95_sections(h_conv_func_sect)
#HM added comment to signal link conversion functions
section append $h_sect $LINKCONVCMMT
section append $h_sect "\n"
section append $h_sect "function Conv (From : $type1) return $type2;\n\n"
section append $h_sect "function Conv (From : $type2) return $type1;\n\n"
section append $ada95_sections(c_conv_incl_sect) "with Unchecked_Conversion;\n"
set sect $ada95_sections(c_conv_func_sect)
section append $sect "function Conv (From : $type1) return $type2 is\n"
section append $sect \
" function Conv is new Unchecked_Conversion ($type1, $type2);\n"
section append $sect "begin\n"
section append $sect " return Conv(From);\n"
section append $sect "end Conv;\n\n"
section append $sect "function Conv (From : $type2) return $type1 is\n"
section append $sect \
" function Conv is new Unchecked_Conversion ($type2, $type1);\n"
section append $sect "begin\n"
section append $sect " return Conv(From);\n"
section append $sect "end Conv;\n\n"
class2linkfiles $class s_filename h_filename
global link_sections
set link_sections(h_sect) [section create]
set link_sections(c_sect) [section create]
set l_sect $link_sections(h_sect)
set l_sect2 $link_sections(c_sect)
section append $l_sect "-- Specification file for ${name}\n\n"
#HM added comment to signal a s link package
section append $l_sect $LINKPACKAGECMMT
section append $l_sect "\n"
section append $l_sect "package $name is\n"
section append $l_sect " type $g_handle_name is private;\n"
section append $l_sect "private\n"
section append $l_sect " type $g_record_name;\n"
section append $l_sect " type $g_handle_name is access $g_record_name;\n"
section append $l_sect " for ${g_handle_name}'storage_size use 0;\n"
section append $l_sect "end $name;\n"
section append $l_sect2 "-- Body file for ${name}\n\n"
add_incl_stmnt [get_name $class] $l_sect2
section append $l_sect2 "package body $name is\n"
section append $l_sect2 \
" type $g_record_name is new [get_name $class].${g_record_name};\n"
section append $l_sect2 "end $name;\n"
write_link_sections $class h_sect c_sect
set link_class_added 1
}
}
}
proc get_type_of_attribute {attrib} {
set type [cap [get_name [get_type $attrib]]]
set t_class [ $cur_model classByName $type ]
if { $t_class != "" } {
set full_type_name [get_full_class_name $t_class]
set type $full_type_name
}
set obj_type [get_obj_type $attrib]
if {$obj_type == "link_attrib" || $obj_type == "qual_link_attrib"} {
append type $g_alt_link_class_ext
}
return $type
}
proc get_data_attrib_type_name {attrib} {
# return [cap [get_name [get_type $attrib]]]
return [get_full_type [get_type $attrib]]
}
proc get_assoc_attrib_type_name {attrib} {
set type [get_type_of_attribute $attrib]
if {[get_multiplicity $attrib] == "one"} {
add_incl_stmnt $type $ada95_sections(h_incl_sect)
return ${type}.[get_g_handle_name $type]
} else {
if {[is_ordered $attrib] == "1"} {
set generic_rname $g_ordered_set_rname
} else {
set generic_rname $g_unordered_set_rname
}
add_incl_stmnt ${type}_${generic_rname} $ada95_sections(h_incl_sect)
return "${type}_${generic_rname}.${generic_rname}"
}
}
proc get_link_attrib_type_name {attrib} {
return [get_assoc_attrib_type_name $attrib]
}
proc get_rv_link_attrib_type_name {attrib} {
return [get_assoc_attrib_type_name $attrib]
}
proc get_qual_assoc_attrib_type_name {attrib} {
if {[get_multiplicity $attrib] == "one"} {
set type [get_type_of_attribute $attrib]
} else {
if {[is_ordered $attrib] == "1"} {
set generic_cname $g_ordered_set_cname
set generic_rname $g_ordered_set_rname
} else {
set generic_cname $g_unordered_set_cname
set generic_rname $g_unordered_set_rname
}
set type "[get_type_of_attribute $attrib]_${generic_rname}"
}
set qual_type [get_name [get_type [get_qualifier $attrib]]]
set qual_cname "${type}_${g_qualified_rname}_By_${qual_type}"
add_incl_stmnt $qual_cname $ada95_sections(h_incl_sect)
return ${qual_cname}.${g_qualified_rname}
}
proc get_qual_link_attrib_type_name {attrib} {
return [get_qual_assoc_attrib_type_name $attrib]
}
proc get_rv_qual_link_attrib_type_name {attrib} {
return [get_qual_assoc_attrib_type_name $attrib]
}
proc assoc_attrib::one_typedef {attrib class} {
set sect $ada95_sections(h_inl_sect)
set name [get_name $class]
set type [get_type $attrib]
set type_nm [get_name $type]
###add_forward $type
# gen_var_decl does not deliver it the format we want, alas
set dum [gen_var_decl $type $name]
section append $sect "typedef $type_nm *$name;\n"
}
proc assoc_attrib::one_inter_pkg {attrib} {
# nothing to do here
}
proc assoc_attrib::one_data {attrib class} {
set sect [get_data_section $class]
set type [get_type_of_attribute $attrib]
set name [cap [get_name $attrib]]
if {$name != $type} {
if {[is_mandatory $attrib] == "0"} {
section append $sect "-- the following is an optional association\n"
}
if {[$attrib isAggregate] == "1"} {
section append $sect "-- the following is an aggregation\n"
}
set full_type ${type}.[get_g_handle_name $type]
section append $sect "$name : ${full_type};\n"
incr_component_count
set i_sect [get_include_section $class]
gen_link_class_alt_additions $class $i_sect
add_incl_stmnt ${type} $i_sect
# generate get & set routines
gen_assoc_access_sects $class $attrib $full_type
}
}
proc assoc_attrib::many_typedef {attrib class} {
set sect $ada95_sections(h_inl_sect)
set name [get_name $class]
set setpfx [set_prefix $attrib]
set type [${setpfx}set_type_name [get_type $attrib]]
section append $sect "typedef $type $name;\n"
}
proc assoc_attrib::many_inter_pkg {attrib} {
global LINKPACKAGECMMT
set class_name [get_type_of_attribute $attrib]
if {[is_ordered $attrib] == "1"} {
set generic_cname $g_ordered_set_cname
set generic_rname $g_ordered_set_rname
} else {
set generic_cname $g_unordered_set_cname
set generic_rname $g_unordered_set_rname
}
create_assoc_sections $ada95_assoc_sections
set sect $assoc_sections(h_inter_pkg_sect)
set ext _$generic_rname
set obj_type [get_obj_type $attrib]
if {$obj_type == "link_attrib" || $obj_type == "qual_link_attrib"} {
set ext ${g_alt_link_class_ext}_${generic_rname}
}
class2assocfiles [get_type $attrib] $ext h_filename
section append $assoc_sections(h_hdr_sect) \
"-- Specification file for ${class_name}_${generic_rname}\n\n"
#HM added comment to signal as a link package
section append $assoc_sections(h_hdr_sect) $LINKPACKAGECMMT
section append $assoc_sections(h_hdr_sect) "\n"
add_incl_stmnt_force $generic_cname $sect
add_incl_stmnt_force $class_name $sect
section append $sect "package ${class_name}_${generic_rname} is new $generic_cname "
section append $sect "(${class_name}.[get_g_handle_name $class_name]);\n\n"
write_assoc_sections [get_type $attrib] $ada95_assoc_sections $ext
}
proc assoc_attrib::many_data {attrib class} {
set sect [get_data_section $class]
set type [get_type_of_attribute $attrib]
set name [cap [get_name $attrib]]
if {$name != $type} {
if {[is_ordered $attrib] == "1"} {
set generic_rname $g_ordered_set_rname
} else {
set generic_rname $g_unordered_set_rname
}
if {[$attrib isAggregate] == "1"} {
section append $sect "-- the following is an aggregation\n"
}
set full_type "${type}_${generic_rname}.${generic_rname}"
section append $sect "$name : ${full_type};\n"
incr_component_count
set i_sect [get_include_section $class]
gen_link_class_alt_additions $class $i_sect
add_incl_stmnt ${type}_${generic_rname} $i_sect
# generate get & set routines
gen_assoc_access_sects $class $attrib $full_type
}
}
proc get_qualifier_type {assoc modifier} {
return [generate [get_type [get_qualifier $assoc]] fwd $modifier]
}
proc get_qualifier_name {assoc} {
return [get_name [get_qualifier $assoc]]
}
proc qual_assoc_attrib::generate {attrib class} {
#HM added check for bidirectional association
global g_local_assoc_count
global ASSOCCMMT
if {[get_opposite $attrib] != ""} {
set type [get_type $attrib]
if {[get_class_visibility $class] != "Opaque" || \
[get_class_visibility $type] != "Opaque"} {
m4_error $E_BIDIRASSOC [get_name $class] [get_name $type]
return
}
}
set sect [get_data_section $class]
#HM added comment to signal an association attribute
incr g_local_assoc_count 1
if {$g_local_assoc_count == 1} {
section append $sect $ASSOCCMMT
section append $sect "\n"
}
gen_for_assoc $attrib $class
}
proc qual_assoc_attrib::one_typedef {attrib class} {
set sect $ada95_sections(h_inl_sect)
set name [get_name $class]
set type [dict_type_name [get_type [get_qualifier $attrib]] \
[get_type $attrib]]
section append $sect "typedef $type $name;\n"
}
proc qual_assoc_attrib::one_inter_pkg {attrib} {
global LINKPACKAGECMMT
set class_name [get_type_of_attribute $attrib]
set qual_type [get_name [get_type [get_qualifier $attrib]]]
set ext1 ${g_qualified_rname}_By_${qual_type}
set package_name "${class_name}_${ext1}"
create_assoc_sections $ada95_assoc_sections
set sect $assoc_sections(h_inter_pkg_sect)
set ext _$ext1
set obj_type [get_obj_type $attrib]
if {$obj_type == "link_attrib" || $obj_type == "qual_link_attrib"} {
set ext ${g_alt_link_class_ext}_${ext1}
}
class2assocfiles [get_type $attrib] $ext h_filename
section append $assoc_sections(h_hdr_sect) "-- Specification file for ${package_name}\n\n"
#HM added comment to signal as a link package
section append $sect $LINKPACKAGECMMT
section append $sect "\n"
#HM - changed qual_type to full_qual_type to prepend "Sys_Types." package name for enums.
#HM - and with the systypes package if necessary
set full_qual_type [get_qual_type [get_type [get_qualifier $attrib]] $sect]
add_incl_stmnt_force $g_qualified_cname $sect
add_incl_stmnt_force $class_name $sect
section append $sect "package ${package_name} is new ${g_qualified_cname} "
section append $sect "(${full_qual_type}, ${class_name}.[get_g_handle_name $class_name]);\n\n"
write_assoc_sections [get_type $attrib] $ada95_assoc_sections $ext
}
proc qual_assoc_attrib::one_data {attrib class} {
set sect [get_data_section $class]
set type [get_type_of_attribute $attrib]
set qual_type [get_name [get_type [get_qualifier $attrib]]]
if {[is_mandatory $attrib] == "0"} {
section append $sect "-- the following is an optional association\n"
}
if {[$attrib isAggregate] == "1"} {
section append $sect "-- the following is an aggregation\n"
}
set attr_name [cap [get_name $attrib]]
if {$attr_name == $type} {
set attr_name ${type}_${g_qualified_rname}
}
set qual_cname "${type}_${g_qualified_rname}_By_${qual_type}"
set full_type ${qual_cname}.${g_qualified_rname}
section append $sect "${attr_name} : ${full_type};\n"
incr_component_count
set i_sect [get_include_section $class]
gen_link_class_alt_additions $class $i_sect
add_incl_stmnt ${qual_cname} $i_sect
# generate get & set routines
gen_assoc_access_sects $class $attrib $full_type
}
proc qual_assoc_attrib::many_typedef {attrib class} {
set sect $ada95_sections(h_inl_sect)
set name [get_name $class]
set setpfx [set_prefix $attrib]
set type [${setpfx}set_dict_type_name \
[get_type [get_qualifier $attrib]] [get_type $attrib]]
section append $sect "typedef $type $name;\n"
}
proc qual_assoc_attrib::many_inter_pkg {attrib} {
global LINKPACKAGECMMT
assoc_attrib::many_inter_pkg $attrib
if {[is_ordered $attrib] == "1"} {
set generic_cname $g_ordered_set_cname
set generic_rname $g_ordered_set_rname
} else {
set generic_cname $g_unordered_set_cname
set generic_rname $g_unordered_set_rname
}
set class_name "[get_type_of_attribute $attrib]_${generic_rname}"
set qual_type [get_name [get_type [get_qualifier $attrib]]]
set ext1 ${g_qualified_rname}_By_${qual_type}
set package_name "${class_name}_${ext1}"
create_assoc_sections $ada95_assoc_sections
set sect $assoc_sections(h_inter_pkg_sect)
set ext _${generic_rname}_${ext1}
set obj_type [get_obj_type $attrib]
if {$obj_type == "link_attrib" || $obj_type == "qual_link_attrib"} {
set ext ${g_alt_link_class_ext}_${generic_rname}_${ext1}
}
class2assocfiles [get_type $attrib] $ext h_filename
section append $assoc_sections(h_hdr_sect) "-- Specification file for ${package_name}\n\n"
#HM added comment to signal a s link package
section append $assoc_sections(h_hdr_sect) $LINKPACKAGECMMT
section append $assoc_sections(h_hdr_sect) "\n"
#HM - changed qual_type to full_qual_type to prepend "Sys_Types." package name for enums.
#HM - and with the systypes package if necessary
set full_qual_type [get_qual_type [get_type [get_qualifier $attrib]] $sect]
add_incl_stmnt_force $g_qualified_cname $sect
add_incl_stmnt_force $class_name $sect
section append $sect "package ${package_name} is new ${g_qualified_cname} "
section append $sect "(${full_qual_type}, ${class_name}.${generic_rname});\n\n"
write_assoc_sections [get_type $attrib] $ada95_assoc_sections $ext
}
proc qual_assoc_attrib::many_data {attrib class} {
set sect [get_data_section $class]
if {[is_ordered $attrib] == "1"} {
set generic_cname $g_ordered_set_cname
set generic_rname $g_ordered_set_rname
} else {
set generic_cname $g_unordered_set_cname
set generic_rname $g_unordered_set_rname
}
set type "[get_type_of_attribute $attrib]_${generic_rname}"
set qual_type [get_name [get_type [get_qualifier $attrib]]]
set attr_name [cap [get_name $attrib]]
if {$attr_name == $type} {
set attr_name ${type}_${g_qualified_rname}
}
set qual_cname "${type}_${g_qualified_rname}_By_${qual_type}"
if {[$attrib isAggregate] == "1"} {
section append $sect "-- the following is an aggregation\n"
}
set full_type ${qual_cname}.${g_qualified_rname}
section append $sect "${attr_name} : ${full_type};\n"
incr_component_count
set i_sect [get_include_section $class]
gen_link_class_alt_additions $class $i_sect
add_incl_stmnt ${qual_cname} $i_sect
# generate get & set routines
gen_assoc_access_sects $class $attrib $full_type
}
proc finish_func_def {sect type num_params abstr} {
if {$num_params > 0} {section append $sect ")"}
if {$type != "void "} {
if {$num_params > 2} {
section append $sect "\n"
} else {
section append $sect " "
}
section append $sect "return $type"
}
if {$abstr == 1} {
section append $sect " is abstract"
}
}
proc add_to_local_op_list {method_type} {
global g_local_op_list g_local_op_count
set g_local_op_list($g_local_op_count) $method_type
incr g_local_op_count
}
proc check_local_op_list {method_type} {
global g_local_op_list g_local_op_count
for {set x 0} {$x < $g_local_op_count} {incr x} {
# echo "g_op_list($x) = $g_local_op_list($x)"
if {$g_local_op_list($x) == $method_type} {return 1}
}
return -1
}
proc operation::generate {oper class class_name inh_mode} {
global tmp_h_sect
set name [map_oper [get_name $oper]]
set static_val [get_the_class_feature $oper]
if {$name == "create" && $static_val == 1} {return}
case $inh_mode in {
{0} {set tmp_h_sect [get_func_section $oper]}
{1} {set tmp_h_sect [section create]}
{2} {set tmp_h_sect [section create]}
}
feature::gen_description $oper $tmp_h_sect
set tmp_c_sect [section create]
set generating_separate 0
# May not need this but it doesn't hurt to create them...
create_separate_sections $ada95_separate_sections
if {$g_generate_separates == "On" && $inh_mode != 1 && [is_oper [get_name $oper]] == 0} {
set s $separate_sections(c_hdr_sect)
section append $s "-- Subunit file for ${name} (${class_name})\n\n"
set s $separate_sections(c_sep_line_sect)
section append $s "\nseparate ($class_name)"
set main_sect $ada95_sections(c_impl_sect)
set generating_separate 1
}
if {$inh_mode == 1} {
set tmp_c_sect2 [section create]
global g_operation_list
global g_operation_list2
global inh_operation_list
global operation_count
incr operation_count
set inh_operation_list($operation_count) "$name "
set g_operation_list($operation_count) [section create]
set c_sect $g_operation_list($operation_count)
set g_operation_list2($operation_count) [section create]
set c_sect2 $g_operation_list2($operation_count)
} else {
if {$generating_separate == 1} {
set c_sect $separate_sections(c_impl_sect)
} else {
set c_sect $ada95_sections(c_impl_sect)
}
}
set type [generate [get_type $oper] fwd "" Value]
echo " operation $name ($type)"
if {$type != "void "} {
set start_decl "function "
set in_out ""
} else {
set start_decl "procedure "
set in_out "in out "
}
if {$inh_mode == 1} {
set start_decl2 ""
if {$type != "void "} {
set start_decl2 "return "
}
append start_decl2 "$class_name.$name (Self.$class_name${g_inh_ext}"
section append $c_sect2 $start_decl2
}
set params [get_parameters $oper]
append start_decl "$name"
set num_params [llength $params]
if {$static_val == 0} {incr num_params}
if {$num_params > 2} {append start_decl "\n "}
if {$num_params > 0} {
append start_decl " ("
}
if {$static_val == 0} {
append start_decl "Self : ${in_out}${g_record_name}"
set first 0
} else {
set first 1
}
section append $tmp_h_sect $start_decl
section append $tmp_c_sect "\n$start_decl"
foreach param [get_parameters $oper] {
generate $param $tmp_h_sect 0 $num_params $first
generate $param $tmp_c_sect 0 $num_params $first
set first 0
if {$inh_mode == 1} {
generate $param $tmp_c_sect2 1 $num_params 0
}
set default [get_default_value $param]
if {$default != ""} {
if [default_value_allowed [get_parameters $oper] $param] {
section append $tmp_h_sect " := $default"
section append $tmp_c_sect " := $default"
} else {
m4_warning $W_NOPARAMDEFAULTS [get_name $param] [get_name $oper]
}
}
}
if {[is_abstract $oper] == "1"} {
finish_func_def $tmp_h_sect $type $num_params 1
finish_func_def $tmp_c_sect $type $num_params 1
} else {
finish_func_def $tmp_h_sect $type $num_params 0
finish_func_def $tmp_c_sect $type $num_params 0
}
if {$inh_mode != 2} {section append $tmp_h_sect ";\n\n"}
if {[is_abstract $oper] == "1"} {
section dealloc $tmp_c_sect
if {$inh_mode == 1} {
section dealloc $tmp_c_sect2
section dealloc $c_sect2
}
return
}
set method_type [section get_contents $tmp_c_sect]
case $inh_mode in {
{0} {add_to_local_op_list $method_type}
{1} {
if {[check_local_op_list $method_type] == 1} {
set tmp_h_sect [section create]
section dealloc $tmp_c_sect
section dealloc $tmp_c_sect2
section dealloc $c_sect2
incr operation_count -1
return -1
}
}
{2} {return}}
section append_section $c_sect $tmp_c_sect
if {$type == "void " && [llength $params] > 2} {
section append $c_sect "\nis"
} else {
section append $c_sect " is"
}
if {$inh_mode == 1} {
section append $tmp_c_sect2 ");\n"
append inh_operation_list($operation_count) "$type"
section append_section $c_sect2 $tmp_c_sect2
section dealloc $tmp_c_sect2
} else {
if {$generating_separate == 1} {
section append_section $main_sect $c_sect
section append $main_sect " separate;\n"
}
}
if {$inh_mode == 1} {section append $c_sect "\nbegin"}
section append $c_sect "\n"
if {$inh_mode == 0} {
set impl_proc [get_method_impl $oper]
if {$impl_proc == ""} {
# get previously prepared body
get_subp_user_body $class $name $method_type $c_sect
} else {
set impl_proc operation::$impl_proc
if {[info procs $impl_proc] != ""} {
section append $c_sect "\nbegin\n"
section set_indent $c_sect +
section append $c_sect [$impl_proc $oper $class $c_sect]
section set_indent $c_sect -
section append $c_sect "end\n\n"
del_subp_info $class $name $method_type
} else {
puts stderr "WARNING: Tcl procedure " nonewline
puts stderr "'$impl_proc' not found"
# fall back to regeneration
# get_method_body $name $method_type $c_sect [get_name $oper]
get_subp_user_body $class $name $tmp_c_sect $c_sect
}
}
}
if {$inh_mode == 0 && $generating_separate == 1} {
class2separatefiles $class [get_name $oper] c_filename
write_separate_sections $class $ada95_separate_sections [get_name $oper]
}
section dealloc $tmp_c_sect
}
proc append_children {cnames class} {
foreach child $g_inher_table($class) {
if {[lsearch $cnames $child] == -1} {
lappend cnames $g_inher_table($class)
set cnames [append_children $cnames $child]
}
}
return $cnames
}
proc parameter::generate {param sect inh_mode num_params first} {
global cur_model
set type [get_type $param]
set dc fwd
set param_dfd [get_param_dfd $param]
if {$param_dfd == ""} {set param_dfd "in"}
if {$inh_mode == 1} {
section append $sect ", "
global inh_operation_list
global operation_count
#
# If the type has a class, then it's a system type
set p_type [get_type $param]
set cl_type_name [get_name $p_type ]
set p_class [ $cur_model classByName $cl_type_name ]
if { ($p_class != "") &&
([get_obj_type $p_class] == "class_typedef" ||
[get_obj_type $p_class] == "class_enum") } {
set p_type [cap [getCurrentSystemName]]_Types.$cl_type_name
}
append inh_operation_list($operation_count) "$param_dfd $p_type "
section append $sect "[get_name $param]"
} else {
if {$first == 0} {section append $sect "; "}
if {$num_params > 2} {section append $sect "\n "}
section append $sect \
"[get_name $param] : $param_dfd [generate [get_type $param] $dc]"
}
}
proc base_type::generate {type decl {modifier ""} {default_modifier ""}} {
return [get_full_type $type]
}
proc base_type::gen_var_decl {type name {col ""}} {
set type [get_type_3gl $type]
if [regsub {(var)?char\[} $type "char $name\[" type] {
regexp {\[(.*)\]$} $type dummy index
set index [expr {$index + 1}]
regsub {\[(.*)\]$} $type "\[$index]" type
return $type
}
return "$type $name"
}
proc class_type::generate {type decl {modifier ""} {default_modifier ""}} {
set name [get_full_type $type]
if {$decl == "fwd"} {
add_forward $type
add_src_inc $type
} else {
add_hdr_inc $type
}
if {$default_modifier == ""} {
global default_type_modifier
set default_modifier $default_type_modifier
}
return $name
}
proc class_type::gen_var_decl {type name {col ""}} {
add_forward $type
return "[get_name $type] $name"
}
proc typedef_type::generate {type decl {modifier ""} {default_modifier ""}} {
return [get_full_type $type]
}
proc typedef_type::gen_var_decl {type name {col ""}} {
add_hdr_inc $type
return "[get_name $type] $name"
}
proc enum_type::generate {type decl {modifier ""} {default_modifier ""}} {
return [get_full_type $type]
}
proc enum_type::gen_var_decl {type name {col ""}} {
return "[get_name $type] $name"
}
proc generic_typedef_type::generate {type decl {modifier ""} {default_modifier ""}} {
return [get_full_type $type]
}
proc generic_typedef_type::gen_var_decl {type name {col ""}} {
return "[get_name $type] $name"
}
proc constructor::generate {ctor class} {
# no constructors in ada95.
return
}
#
# Check if the given parameter is allowed to have a default value.
#
# This is the case if all parameters following this one have default values.
#
proc default_value_allowed {paramlist param} {
set i [lsearch $paramlist $param]
if {$i != -1} {
foreach p [lrange $paramlist $i end] {
if {[get_default_value $p] == ""} {
return 0
}
}
}
return 1
}
proc ctor_param::generate {param sect f} {
# no constructors in ada95.
return
}
proc attrib_init::generate {init init_sect body_sect} {
### hack !?
set data_struct 0
set attrib [get_attrib $init]
if {[get_obj_type $attrib] == "db_data_attrib"} {
set tgt "data.[get_unique_name [get_column $attrib]]"
set data_struct 1
} else {
set tgt [get_name $attrib]
}
if [type_is_char_array [get_type $attrib]] {
add_[determine_sect_type $body_sect]_inc_name "string" "h"
section append $body_sect "strcpy($tgt, [get_name $init]);\n"
} else {
if $data_struct {
section append $body_sect "$tgt = [get_name $init];\n"
return
}
}
}
proc get_root_class {class} {
set supers [get_super_classes $class]
if [lempty $supers] {
return $class
}
return [get_root_class [get_super_class [lindex $supers 0]]]
}
proc rv_link_attrib::generate {attrib class} {
global g_local_assoc_count
global ASSOCCMMT
#HM added comment to signal an association attribute
set sect [get_data_section $class]
incr g_local_assoc_count 1
if {$g_local_assoc_count == 1} {
section append $sect $ASSOCCMMT
section append $sect "\n"
}
# multiplicity should always be 'one' here
gen_for_rv_link $attrib $class
}
proc rv_link_attrib::one_data {attrib class} {
set sect [get_data_section $class]
set i_sect $ada95_sections(h_incl_sect)
set type [get_name [get_type $attrib]]
set role_name [get_name $attrib]
if {$role_name != $type} {
section append $sect "${role_name} : ${type};\n"
incr_component_count
add_incl_stmnt $type $i_sect
}
}
proc qual_link_attrib::generate {attrib class} {
global g_local_assoc_count
global ASSOCCMMT
#HM added comment to signal an association attribute
set sect [get_data_section $class]
incr g_local_assoc_count 1
if {$g_local_assoc_count == 1} {
section append $sect $ASSOCCMMT
section append $sect "\n"
}
gen_for_link $attrib $class
}
proc link_attrib::generate {attrib class} {
global g_local_assoc_count
global ASSOCCMMT
set sect [get_data_section $class]
incr g_local_assoc_count 1
if {$g_local_assoc_count == 1} {
section append $sect $ASSOCCMMT
section append $sect "\n"
}
gen_for_link $attrib $class
}
proc link_attrib::one_data {attrib class} {
set sect [get_data_section $class]
set i_sect $ada95_sections(h_incl_sect)
set type [get_name [get_type $attrib]]
set role_name [get_name $attrib]
section append $sect "${role_name} : $type;\n"
incr_component_count
add_incl_stmnt ${type} $i_sect
}
proc link_attrib::many_data {attrib} {
assoc_attrib::many_inter_pkg $attrib
assoc_attrib::many_data $attrib $class
}
# Generate a check for the nullability of the columns of a link. These columns
# are either ALL null or ALL not null, so it suffices to check only the
# first column.
#
proc gen_null_check {sect link ind_var {ret_val 0}} {
set col [lindex [get_columns $link] 0]
if {$ret_val == ""} {
set space ""
} else {
set space " "
}
expand_text $sect {
if (~$ind_var~[get_unique_name $col] == -1)
return~${space}~$ret_val;
}
}
proc is_db_class {class} {
return [string match {db_*} [get_obj_type $class]]
}
proc class2tgtfiles {class_name src inc} {
upvar $src src_f
upvar $inc inc_f
set src_f ${class_name}.$ada95_body_type
set inc_f ${class_name}.$ada95_spec_type
}
proc class2assocfiles {class ext inc} {
upvar $inc inc_f
set name [get_name $class]
set cname ${name}${ext}
set class_name [class2file $cname]
set inc_f ${class_name}.$ada95_spec_type
}
proc class2linkfiles {class src inc} {
upvar $src src_f
upvar $inc inc_f
set class_name [class2file [get_name $class]${g_alt_link_class_ext}]
set src_f ${class_name}.$ada95_body_type
set inc_f ${class_name}.$ada95_spec_type
}
proc class2separatefiles {class ext inc} {
upvar $inc inc_f
set cname [get_name $class]__${ext}
set class_name [class2file $cname]
set inc_f ${class_name}.$ada95_sep_type
}
# we want 'class_typedef'
# or 'class_enum'
# or 'class_generic_typedef'
proc is_special_class {class} {
return [string match {*class_*} [get_obj_type $class]]
}
proc is_derivable_class {class} {
switch [get_obj_type $class] {
"class_enum" {
return 0
}
"class_typedef" {
set attrib [lindex [get_features $class] 0]
if {[get_type_3gl [get_type $attrib]] == ""} {
return 1
} else {
return 0
}
}
"class_generic_typedef" {
set assoc [lindex [get_features $class] 0]
if {[get_multiplicity $assoc] == "many" ||
[string match {qual_*} [get_obj_type $assoc]]} {
return 1
} else {
return 0
}
}
default {
return 1
}
}
}
#
# global array opermap contains mappings for Ada operators that cannot be
# entered on CAD diagrams in the normal "op" quoted string form:
#
global opermap
#
# Ada-specific mappings:
#
set opermap(operatorEQ) "\"=\""
set opermap(operatorLE) "\"<=\""
set opermap(operatorGE) "\">=\""
set opermap(operatorDIV) "\"/\""
#
# C++ compatibility mappings:
#
set opermap(operator+) "\"+\""
set opermap(operator-) "\"-\""
set opermap(operator*) "\"*\""
set opermap(operator%) "\"rem\""
set opermap(operator&) "\"and\""
set opermap(operator|) "\"or\""
set opermap(operator!) "\"not\""
set opermap(operator<) "\"<\""
set opermap(operator>) "\">\""
set opermap(operator&&) "\"and\""
set opermap(operator||) "\"or\""
proc map_oper {name} {
if [info exists opermap($name)] {
return $opermap($name)
}
return $name
}
proc is_oper {name} {
if {[info exists opermap($name)] || [regexp "^\".*\"\$" $name]} {
return 1
}
return 0
}
# return set prefix "o" in case ordered set are needed
#
proc set_prefix {attrib} {
set this_name [get_name $attrib]
if {[is_ordered $attrib] == "1"} {
echo "ordered is TRUE"
return o
} else {
echo "ordered is FALSE"
return
}
}
proc gen_op_lists {class} {
global g_op_list
global g_class_list
global root_class
append g_class_list([get_name $root_class]) "$class "
foreach subgroup [get_sub_classes $class] { ;# this gives each inh. group.
set inh_access [get_inher_access $subgroup]
if {$inh_access == ""} {set inh_access "Public"}
foreach subclass [get_sub_classes $subgroup] {
set subclassname [get_name $subclass]
if {$inh_access == "Private"} {
foreach entry $g_op_list([get_name $class]) {
set cname [split_op_list_entry $entry class]
append g_op_list($subclassname) "$cname:$inh_access "
}
} else {
append g_op_list($subclassname) "$g_op_list([get_name $class]) "
}
append g_op_list($subclassname) "$class:$inh_access "
gen_op_lists $subclass
}
}
}
proc get_feats {class, superclass} {
foreach feat [get_features $class] {
set feat_type [get_obj_type $feat]
echo "type = $feat_type"
if {$feat_type == "operation"} {
echo "operation for [get_name $class] is [get_name $feat]"
append g_op_list([get_name $class],1) $feat
append g_op_list([get_name $class],2) $superclass
}
}
}
proc get_the_class_feature {feat} {
set c_feat [is_class_feature $feat]
if {$c_feat == 1} {
return 1
} else {
return 0
}
}
proc gen_assoc_list {class} {
global g_assoc_list
echo "Class = [get_name $class]"
foreach feat [get_features $class] {
set feat_type [get_obj_type $feat]
echo " feature type = $feat_type"
if {$feat_type == "assoc_attrib" || $feat_type == "qual_assoc_attrib" \
|| $feat_type == "link_attrib" || $feat_type == "rv_link_attrib" } {
set assoc_class [get_name [get_type $feat]]
if {[get_name $feat] != $assoc_class && [lsearch $g_assoc_list $assoc_class] == -1} {
append g_assoc_list "$assoc_class "
}
}
}
}