home *** CD-ROM | disk | FTP | other *** search
Text File | 1997-06-02 | 65.6 KB | 2,249 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.
- ##
- ###########################################################################
-
- 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
- ## 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_pub_attr_access_count
- ## HM - added g_local_assoc_count to count association components
- ## HM - added g_local_inh_op_count to count inherited operations
- 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
- global g_local_inh_op_count
-
- check_unique_file_names $model
-
- echo "Generating Ada 83 code"
- set g_assoc_list ""
- set root_classes ""
- set pers_class_exists 0
- set got_a_class 0
-
- create_ada_sections $ada_hdr_sections
- init_sys_sections $sysfile_name
-
- #HM moved class2tgtfiles outside of if and call is_file_generated with h_filename
- # 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}
- }
- }
-
- }
-
- foreach class [get_classes $model] {
- 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]
- 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 $ada_hdr_sections
-
- if {$pers_class_exists == 1} {
- puts stderr "At least one class in the model is persistent. 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_priv_assoc_access_count 0
- set g_local_pub_assoc_access_count 0
- set g_local_priv_attr_access_count 0
- set g_local_pub_attr_access_count 0
- set g_local_inh_op_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)
- }
- }
-
- if {$g_poly == "On"} {
- global g_generate_separates
- set g_generate_separates "Off"
- global g_func_list
- global g_poly_op_list g_poly_op_class_list g_poly_op_param_list g_poly_op_count
-
- foreach root_class $root_classes {
- set g_poly_op_count 0
- class2polyfiles $root_class src_file h_file
- echo "h_file = $h_file"
- global gen_file
-
- create_ada_sections [concat $ada_hdr_sections $ada_src_sections]
- init_poly_sections $root_class
-
- echo " [get_name $root_class]"
- set g_func_list ""
- set r_name [get_name $root_class]
- global g_parent_list
- set g_parent_list "$r_name "
- global link_incl_list
- set link_incl_list ""
- class::gen_poly $root_class
- gen_poly_body $r_name
- exit_poly_sections $root_class
- write_poly_sections $root_class $ada_hdr_sections $ada_src_sections
- }
- }
- }
-
- proc skip_class {class flag} {
- if {[is_db_class $class] == 1} {
- puts stderr "ERROR: Class [get_name $class] is persistent."
- return 2
- }
- if [is_external $class] {
- return 1
- }
- if {[get_name $class] == ""} {
- if {$flag == 1} {puts stderr "Class without name skipped"}
- return 1
- }
- 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 declarations
- global g_component_count
-
- set g_component_count 0
- create_ada_sections [concat $ada_hdr_sections $ada_src_sections]
- init_ada_sections [get_name $class] [get_data_section $class] [get_class_vis $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 $ada_sections(h_hdr_sect)
- set csect $ada_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 $ada_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
- }
- }
-
- gen_inherited_ops $class
- gen_delayed_code
- gen_end_protector $class
- append_obsolete_code $class
- exit_ada_sections $class
- write_ada_sections $class $ada_hdr_sections $ada_src_sections
- }
-
- 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 $ada_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_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 $ada_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 protector [protector_name $class_name]
- section append $ada_sections(h_trailer_sect) \
- "end $class_name;\n"
- }
-
-
- proc class::gen_class_decl {class} {
- set class_name [get_name $class]
- set h_sect $ada_sections(h_class_nm_sect)
- set c_sect $ada_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 $class_name is \n"
- section append $c_sect "package body $class_name is \n"
-
- set h_sect $ada_sections(h_pub_data_sect)
- set c_sect $ada_sections(c_opaque_sect)
-
- case $class_visibility in {
- {Private} {
- section append $h_sect "\ntype $g_record_name is private;\n"
- }
- {Limited} {
- section append $h_sect "\ntype $g_record_name is limited private;\n"
- }
- {Opaque} {
- set o_sect $ada_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"
- section append $o_sect "type $o_record_name;\n"
- section append $o_sect "type $g_record_name is access $o_record_name;\n"
- 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 $ada_sections(c_access_func_sect)
- if {$f_sect != ""} {section append $f_sect "\n"}
- } else {
- if {$g_op_list_type($x) == 1} {
- set f_sect $ada_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
- global INHERCOMPCMMT
-
- set class_name [get_name $class]
- set i_sect $ada_sections(h_incl_sect)
- set sect $ada_sections(h_class_nm_sect)
- set super_name [get_super_name $group]
- add_hdr_inc [get_super_class $group] ;# includes class' include file
- section append $i_sect "with $super_name;\n"
-
- set sect2 [get_data_section $class]
-
- if {[get_class_vis $class] == "Public"} {
- set inh_op_sect $ada_sections(h_pub_func_sect)
- } else {
- set inh_op_sect $ada_sections(h_priv_func_sect)
- }
-
- #HM added comment to signal inheritance component
- section append $sect2 $INHERCOMPCMMT
- section append $sect2 "\n"
-
- 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 != $ada_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] == $ada_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] == $ada_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 != $ada_sections(dev_null_sect)} {
- set flag 1
- }
- } else {
- if {$sect == $ada_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} {
- 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 $ada_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)
-
- ##HM section append $tmp_sect "--OT g_operation_list section created in gen_access_body\n"
- set g_operation_list2($operation_count) [section create]
- set tmp_sect2 $g_operation_list2($operation_count)
-
- ##HM section append $tmp_sect2 "--OT g_operation_list2 section created in gen_access_body\n"
- 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 $ada_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
- set type_name [get_name $type]
- if {$type_name == ""} {return "void "}
- set obj_type [get_obj_type $type]
- if {$obj_type == "class_type"} {
- add_incl_stmnt $type_name
- append type_name ".$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_sect $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_sect $sys_types_name $sect
- }
- return $type_name
- }
-
-
-
- proc get_full_type {type} {
- #HM removed cap from "set type_name" - this causes replace in round-trip
- #HM added Sys_Types package name to front of enum and subtype names
- set type_name [get_name $type]
- if {$type_name == ""} {return "void "}
- set obj_type [get_obj_type $type]
- if {$obj_type == "class_type"} {
- add_incl_stmnt $type_name
- append type_name ".$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 cassing attrib delete and add in round trip
- 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 - Deleted cap call - resulted in replace 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 $ada_sections(h_static_data_sect)
- } else {
- set sect $ada_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"} {
- puts stderr "ERROR: Class '[get_name $class]' has a bidirectional association to class '[get_name $type]' - association skipped"
- 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} {
- section append $i_sect "with $name;\n"
- set type1 ${name}.$g_handle_name
- set type2 $g_handle_name
-
- set h_sect $ada_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 $ada_sections(c_conv_incl_sect) "with Unchecked_Conversion;\n"
-
- set sect $ada_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 as a 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"
- section append $l_sect2 "with [get_name $class];\n"
- 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 add_incl_stmnt {type} {
- global link_incl_list
- if {[lsearch $link_incl_list $type] == -1} {
- section append $ada_sections(h_incl_sect) "with ${type};\n"
- lappend link_incl_list $type
- }
- }
-
-
- proc add_incl_stmnt_sect {type sect} {
- #HM added this routine to add an include to a specified section - ada95 has only this version
- global link_incl_list
- if {[lsearch $link_incl_list $type] == -1} {
- section append $sect "with ${type};\n"
- lappend link_incl_list $type
- }
- }
-
-
- proc get_type_of_attribute {attrib} {
- set type [cap [get_name [get_type $attrib]]]
- 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
- return ${type}.${g_handle_name}
- } 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}
- 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
- 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 $ada_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]
-
- ##HM section append $sect "--OT In assoc_attrib::one_data\n"
-
- 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}.${g_handle_name}
- 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
-
- section append $i_sect "with ${type};\n"
-
- # generate get & set routines
- gen_assoc_access_sects $class $attrib $full_type
- }
- }
-
-
-
- proc assoc_attrib::many_typedef {attrib class} {
- set sect $ada_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 $ada_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"
-
- section append $sect "with $generic_cname;\n"
-
- section append $sect "with $class_name;\n"
- section append $sect "package ${class_name}_${generic_rname} is new $generic_cname "
- section append $sect "(${class_name}.${g_handle_name});\n\n"
-
- write_assoc_sections [get_type $attrib] $ada_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]]
-
- ##HM section append $sect "--OT In assoc_attrib::many_data\n"
-
- 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
- section append $i_sect "with ${type}_${generic_rname};\n"
-
- # 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"} {
- puts stderr "ERROR: Class '[get_name $class]' has a bidirectional association to class '[get_name $type]' - association skipped"
- return
- }
- }
- set sect [get_data_section $class]
- ##HM section append $sect "--OT In qual_assoc_attrib::generate\n"
-
- 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 $ada_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 $ada_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 - changes 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]
-
- section append $sect "with $g_qualified_cname;\n"
- section append $sect "with $class_name;\n"
- section append $sect "package ${package_name} is new ${g_qualified_cname} "
- section append $sect "(${full_qual_type}, ${class_name}.${g_handle_name});\n\n"
-
- write_assoc_sections [get_type $attrib] $ada_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]]]
-
- ##HM section append $sect "--OT In qual_assoc_attrib::one_data\n"
-
- 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
- section append $i_sect "with ${qual_cname};\n"
-
- # generate get & set routines
- gen_assoc_access_sects $class $attrib $full_type
- }
-
-
- proc qual_assoc_attrib::many_typedef {attrib class} {
- set sect $ada_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 $ada_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 as a link package
- section append $sect $LINKPACKAGECMMT
- section append $sect "\n"
-
- #HM - changes 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]
-
- section append $sect "with $g_qualified_cname;\n"
- section append $sect "with $class_name;\n"
- 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] $ada_assoc_sections $ext
- }
-
- proc qual_assoc_attrib::many_data {attrib class} {
- set sect [get_data_section $class]
-
- ##HM section append $sect "--OT In qual_assoc_attrib::many_data\n"
-
- 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
- section append $i_sect "with ${qual_cname};\n"
-
- # generate get & set routines
- gen_assoc_access_sects $class $attrib $full_type
-
- }
-
-
- proc finish_func_def {sect type num_params} {
- 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"
- }
- }
-
-
- 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 g_local_inh_op_count
- global INHEROPERCMMT
- 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]}
- }
-
- #HM added comment to signal start of inherited operations
- if {$inh_mode == 1} {
- incr g_local_inh_op_count 1
- if {$g_local_inh_op_count == 1} {
- section append $tmp_h_sect $INHEROPERCMMT
- section append $tmp_h_sect "\n"
- }
- }
-
- 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 $ada_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 $ada_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)
-
- ##HM section append $c_sect "--OT g_operation_list section created in operation::generate\n"
- set g_operation_list2($operation_count) [section create]
- set c_sect2 $g_operation_list2($operation_count)
-
- ##HM section append $c_sect2 "--OT g_operation_list2 section created in operation::generate\n"
- } else {
- if {$generating_separate == 1} {
- set c_sect $separate_sections(c_impl_sect)
- } else {
- set c_sect $ada_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 {
- puts "WARNING: default value for parameter\
- '[get_name $param]' of\
- '[get_name $class]::[get_name $oper]()' is not\n \
- generated since this parameter is followed by parameters\
- without\n default values"
- }
- }
- }
-
- finish_func_def $tmp_h_sect $type $num_params
- finish_func_def $tmp_c_sect $type $num_params
-
- if {$inh_mode != 2} {section append $tmp_h_sect ";\n\n"}
-
- 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 $ada_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 gen_poly_body {root_name} {
- global g_poly_op_count
- global g_poly_op_list g_poly_op_param_list g_poly_op_class_list
- global g_class_list g_inher_table g_op_list
-
- set c_sect $ada_sections(c_impl_sect)
- for {set x 0} {$x < $g_poly_op_count} {incr x} {
- section append $ada_sections(h_pub_func_sect) "$g_poly_op_list($x);\n\n"
- section append $c_sect "$g_poly_op_list($x) is\nbegin\n"
- section append $c_sect " case Self.${root_name}_Kind is\n"
- set this_func_list ""
- set cnames ""
- echo "\n\n$g_poly_op_list($x)"
- foreach p_class $g_poly_op_class_list($x) {
- lappend cnames $p_class
- foreach opclass $g_inher_table($p_class) {
- if {[lsearch $cnames $opclass] == -1} {
- lappend cnames $opclass
- set cnames [append_children $cnames $opclass]
- }
- }
- }
- foreach poly_class $g_class_list($root_name) {
- set classname [get_name $poly_class]
- if {[lsearch $this_func_list $classname] != -1} {continue}
- section append $c_sect " when A_${classname} =>\n"
- if {[lsearch $cnames $classname] != -1} {
- set p_list $g_poly_op_param_list($x)
- section append $c_sect " "
- if {[lindex $p_list 0] != "void"} {section append $c_sect "return "}
- set func_name [lindex $p_list 1]
- section append $c_sect "${classname}.${func_name}"
- section append $c_sect " (Self.${classname}_Obj"
- for {set y 2} {$y < [llength $p_list]} {incr y} {
- section append $c_sect ", [lindex $p_list $y]"
- }
- section append $c_sect ")"
- section append $c_sect ";\n"
- } else {
- section append $c_sect \
- " raise Constraint_Error;\n"
- }
- append this_func_list "$classname "
- }
- section append $c_sect " end case;\n"
- section append $c_sect "end $func_name;\n\n"
- }
- }
-
-
- proc parameter::generate {param sect inh_mode num_params first} {
-
- 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
- append inh_operation_list($operation_count) "$param_dfd [get_type $param] "
- 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 ada.
- 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 ada.
- 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
-
- 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 $ada_sections(h_incl_sect)
-
- ##HM section append $sect "--OT In rv_link_attrib::one_data\n"
-
- 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
- section append $i_sect "with ${type};\n"
- }
- }
-
- proc qual_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::generate {attrib class} {
- global g_local_assoc_count
- global ASSOCCMMT
-
- set sect [get_data_section $class]
- ##HM section append $sect "--OT In link_attrib::generate\n"
-
- 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 $ada_sections(h_incl_sect)
-
- ##HM section append $sect "--OT In link_attrib::one_data\n"
-
- set type [get_name [get_type $attrib]]
- set role_name [get_name $attrib]
- section append $sect "${role_name} : $type;\n"
- incr_component_count
- section append $i_sect "with ${type};\n"
- }
-
- 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}.$ada_body_type
- set inc_f ${class_name}.$ada_spec_type
- }
-
- proc class2polyfiles {class src inc} {
- upvar $src src_f
- upvar $inc inc_f
- set class_name [class2file ${g_poly_prefix}[get_name $class]]
- set src_f ${class_name}.$ada_body_type
- set inc_f ${class_name}.$ada_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}.$ada_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}.$ada_body_type
- set inc_f ${class_name}.$ada_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}.$ada_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 class::gen_poly {class} {
- global g_inher_table
-
- class::gen_poly_routine $class
- set c_name [get_name $class]
- foreach subclass1 [get_sub_classes $class] { ;# this gives each inh. group.
- foreach subclass [get_sub_classes $subclass1] {
- set sub_name [get_name $subclass]
- if {[info exists g_inher_table($c_name)]} {
- if {[lsearch $g_inher_table($c_name) $sub_name] == -1} {
- lappend g_inher_table($c_name) $sub_name
- }
- } else {
- set g_inher_table($c_name) "$sub_name "
- }
- if {![info exists g_inher_table($sub_name)]} {
- set g_inher_table($sub_name) ""
- }
- class::gen_poly $subclass
- }
- }
- }
-
- proc class::gen_poly_routine {class} {
- global g_inher_table g_parent_list root_class g_func_list link_incl_list
-
- set name [get_name $class]
-
- echo "in gen_poly_routine, name = $name"
-
- if {[lsearch $g_func_list $name] == -1} {
- if {[lsearch $link_incl_list $name] == -1} {
- section append $ada_sections(h_hdr_sect) "with $name;\n"
- lappend link_incl_list $name
- }
- if {$name != [get_name $root_class]} {
- section append $ada_sections(h_class_nm_sect) ", "
- }
- section append $ada_sections(h_class_nm_sect) "A_$name"
- section append $ada_sections(h_pub_data_sect) " when A_${name} =>\n"
- section append $ada_sections(h_pub_data_sect) \
- " ${name}_Obj : ${name}.${g_record_name};\n"
-
- foreach feat [get_features $class] {
- set feat_type [get_obj_type $feat]
- echo " feature type = $feat_type"
-
- if {$feat_type == "constructor"} {continue}
-
- if {[get_the_class_feature $feat] == 1} {continue}
-
- if {$feat_type == "operation"} {
- if {[get_func_section $feat] != $ada_sections(h_pub_func_sect)} {continue}
- generate $feat $class $name 2
- set type [get_full_type [get_type $feat]]
- add_to_poly_list $name $feat $type [get_name $feat] \
- [section get_contents $tmp_h_sect] "" 1
- } else {
- set type [get_${feat_type}_type_name $feat]
- set fname [cap [get_name $feat]]
- set gname "Get_$fname"
- set sname "Set_$fname"
- set h_sect $ada_sections(h_pub_access_sect)
- set c_sect $ada_sections(c_access_func_sect)
-
- if {[get_attrib_hdr_sect $feat r] == $ada_sections(h_pub_access_sect)} {
- set g_start "function $gname (Self : ${g_record_name}) return $type"
- add_to_poly_list $name $feat $type $gname $g_start "" 0
- }
- if {[get_attrib_hdr_sect $feat w] == $ada_sections(h_pub_access_sect)} {
- set s_start "procedure $sname (Self : in out ${g_record_name}; New_${fname} : $type)"
- add_to_poly_list $name $feat void $sname $s_start "New_$fname" 0
- }
- }
- }
- append g_func_list "$name "
- }
- }
-
-
- proc get_the_class_feature {feat} {
- set c_feat [is_class_feature $feat]
- if {$c_feat == 1} {
- return 1
- } else {
- return 0
- }
- }
-
- proc add_to_poly_list {class_name feat type feat_name op_sig extra_params flag} {
- global g_poly_op_count
- global g_poly_op_list g_poly_op_param_list g_poly_op_class_list
-
- for {set x 0} {$x < $g_poly_op_count} {incr x} {
- if {$g_poly_op_list($x) == $op_sig} {
- if {[lsearch g_poly_op_class_list($x) $class_name] == -1} {
- lappend g_poly_op_class_list($x) $class_name
- }
- return
- }
- }
- set g_poly_op_list($x) $op_sig
- set g_poly_op_param_list($x) "$type "
- lappend g_poly_op_param_list($x) $feat_name
- if {$flag == 1} {
- foreach param [get_parameters $feat] {
- lappend g_poly_op_param_list($x) [get_name $param]
- }
- }
- if {$extra_params != ""} {
- lappend g_poly_op_param_list($x) $extra_params
- }
- set g_poly_op_class_list($x) $class_name
- incr g_poly_op_count
- }
-
- 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 "
- }
- }
- }
- }
-