From 0037e5b27305c2533f647f1fbbca9a863c6db71c Mon Sep 17 00:00:00 2001 From: wolandscat Date: Thu, 18 Jul 2024 19:02:30 -0600 Subject: [PATCH] Various refactoring related to serialisation. --- .../gui_serialisation_control.e | 12 +- .../src/gui/export/export_dialog.e | 2 +- .../gui/library_tool/gui_artefact_explorer.e | 2 +- .../src/gui/library_tool/gui_library_tool.e | 4 +- .../src/gui/main/gui_test_tool.e | 2 +- apps/adlc/src/main/application.e | 17 +-- apps/adlc/src/main/options_processor.e | 17 ++- .../messages/compiled/adl_messages_db.e | 3 +- .../messages/compiled/adl_messages_ids.e | 1 + .../messages/source/app_adlc_ui_messages.txt | 1 + .../src/comparator/template_flattener.e | 2 +- .../src/interface/archetype_exporter.e | 30 +++-- .../serialiser/shared_archetype_serialisers.e | 14 +-- .../src/library/arch_lib_archetype.e | 116 +++++++++--------- .../src/library/arch_lib_authored_archetype.e | 32 ++--- .../src/library/arch_lib_template.e | 70 +++++------ 16 files changed, 171 insertions(+), 154 deletions(-) diff --git a/apps/adl_workbench/src/gui/archetype_tool/gui_serialisation_control.e b/apps/adl_workbench/src/gui/archetype_tool/gui_serialisation_control.e index 9d419d96c..285e1d345 100755 --- a/apps/adl_workbench/src/gui/archetype_tool/gui_serialisation_control.e +++ b/apps/adl_workbench/src/gui/archetype_tool/gui_serialisation_control.e @@ -221,7 +221,7 @@ feature {NONE} -- Implementation adl_text: STRING do if adl_text_cache.is_empty then - adl_text_cache.append (safe_source.select_native_serialised_archetype (differential_view, rm_flattening_on)) + adl_text_cache.append (safe_source.serialised_native (differential_view, rm_flattening_on)) end Result := adl_text_cache end @@ -236,7 +236,7 @@ feature {NONE} -- Implementation json_text: STRING do if json_text_cache.is_empty then - json_text_cache.append (safe_source.serialise_object (not differential_view, type_marking_on, {ODIN_DEFINITIONS}.Syntax_type_json)) + json_text_cache.append (safe_source.serialised_object (not differential_view, type_marking_on, {ODIN_DEFINITIONS}.Syntax_type_json)) end Result := json_text_cache end @@ -252,7 +252,7 @@ feature {NONE} -- Implementation ejson_text: STRING do if ejson_text_cache.is_empty then - ejson_text_cache.append (safe_source.serialise_object_ejson (not differential_view, type_marking_on, {ODIN_DEFINITIONS}.Syntax_type_json)) + ejson_text_cache.append (safe_source.serialised_object_ejson (not differential_view, type_marking_on, {ODIN_DEFINITIONS}.Syntax_type_json)) end Result := ejson_text_cache end @@ -268,7 +268,7 @@ feature {NONE} -- Implementation yaml_text: STRING do if yaml_text_cache.is_empty then - yaml_text_cache.append (safe_source.serialise_object (not differential_view, type_marking_on, {ODIN_DEFINITIONS}.Syntax_type_yaml)) + yaml_text_cache.append (safe_source.serialised_object (not differential_view, type_marking_on, {ODIN_DEFINITIONS}.Syntax_type_yaml)) end Result := yaml_text_cache end @@ -284,7 +284,7 @@ feature {NONE} -- Implementation xml_text: STRING do if xml_text_cache.is_empty then - xml_text_cache.append (safe_source.serialise_object (not differential_view, type_marking_on, {ODIN_DEFINITIONS}.Syntax_type_xml)) + xml_text_cache.append (safe_source.serialised_object (not differential_view, type_marking_on, {ODIN_DEFINITIONS}.Syntax_type_xml)) end Result := xml_text_cache end @@ -300,7 +300,7 @@ feature {NONE} -- Implementation odin_text: STRING do if odin_text_cache.is_empty then - odin_text_cache.append (safe_source.serialise_object (not differential_view, type_marking_on, {ARCHETYPE_DEFINITIONS}.Syntax_type_adl)) + odin_text_cache.append (safe_source.serialised_object (not differential_view, type_marking_on, {ARCHETYPE_DEFINITIONS}.Syntax_type_adl)) end Result := odin_text_cache end diff --git a/apps/adl_workbench/src/gui/export/export_dialog.e b/apps/adl_workbench/src/gui/export/export_dialog.e index aeda6a95b..cd76d96f7 100755 --- a/apps/adl_workbench/src/gui/export/export_dialog.e +++ b/apps/adl_workbench/src/gui/export/export_dialog.e @@ -360,7 +360,7 @@ feature {NONE} -- Implementation else execution_state := es_ready_to_generate end - archetype_exporter.setup_build ([output_directory, evx_format_cob.data_control_text, export_flat, evx_flatten_with_rm_cb.is_selected]) + archetype_exporter.setup_build ([output_directory, evx_format_cob.data_control_text, export_flat, evx_flatten_with_rm_cb.is_selected, False]) -- start compilation elseif execution_state = es_ready_to_compile then diff --git a/apps/adl_workbench/src/gui/library_tool/gui_artefact_explorer.e b/apps/adl_workbench/src/gui/library_tool/gui_artefact_explorer.e index 610a63b87..fcc29d7bc 100755 --- a/apps/adl_workbench/src/gui/library_tool/gui_artefact_explorer.e +++ b/apps/adl_workbench/src/gui/library_tool/gui_artefact_explorer.e @@ -329,7 +329,7 @@ feature {NONE} -- Implementation question_dialog.show_modal_to_window (proximate_ev_window (ev_root_container)) if attached question_dialog.selected_button as att_sel_btn and then att_sel_btn.same_string (get_text ({GENERAL_MESSAGES_IDS}.ec_yes_response)) then src.remove_archetype (aca) - aca.remove_file + aca.remove_source_file if attached aca.parent as att_parent then remove_item_in_tree (aca.global_artefact_identifier) library_tool_agents.call_update_explorers_and_select_agent (att_parent.global_artefact_identifier) diff --git a/apps/adl_workbench/src/gui/library_tool/gui_library_tool.e b/apps/adl_workbench/src/gui/library_tool/gui_library_tool.e index c239bdb59..50ab1e1b0 100755 --- a/apps/adl_workbench/src/gui/library_tool/gui_library_tool.e +++ b/apps/adl_workbench/src/gui/library_tool/gui_library_tool.e @@ -512,7 +512,7 @@ feature {NONE} -- Implementation -- finalise the file path & create a handle set_last_user_save_directory (file_system.dirname (name)) format := format_list [save_dialog.selected_filter_index] - ext := archetype_file_extension (diff_flag, format) + ext := archetype_file_extension (not diff_flag, format) if not file_system.has_extension (name, ext) then name.append (ext) end @@ -531,7 +531,7 @@ feature {NONE} -- Implementation if diff_flag then aca.save_differential_as (name, format) else - aca.save_flat_as (name, format) + aca.save_flat_as (name, format, False) end gui_agents.call_console_tool_append_agent (aca.status) end diff --git a/apps/adl_workbench/src/gui/main/gui_test_tool.e b/apps/adl_workbench/src/gui/main/gui_test_tool.e index 9f03be9ae..81076b105 100755 --- a/apps/adl_workbench/src/gui/main/gui_test_tool.e +++ b/apps/adl_workbench/src/gui/main/gui_test_tool.e @@ -643,7 +643,7 @@ feature {NONE} -- Tests flat_fname := extension_replaced (orig_fname, File_ext_archetype_flat) flat_path := file_system.pathname (diff_dir_flat_new, flat_fname) - auth_target.save_flat_as (flat_path, Syntax_type_adl) + auth_target.save_flat_as (flat_path, Syntax_type_adl, False) -- copy above flat file to $repository/source_flat/orig area as well, using extension .adlx (flat also uses this - diff tool needs to see same -- extensions or else it gets confused) diff --git a/apps/adlc/src/main/application.e b/apps/adlc/src/main/application.e index be5001745..231c48237 100755 --- a/apps/adlc/src/main/application.e +++ b/apps/adlc/src/main/application.e @@ -8,12 +8,13 @@ note adlc [-q] -L adlc [-q] -D adlc [-q] -X - adlc [-q] -b --build - adlc [-q] -b -l [] - adlc [-q] -b -d [] - adlc [-q] -b [-f ] --report [-o ] - adlc [-q] -b --inject_term_bindings -i - adlc [-q] -b --export_term_bindings + adlc [-q] -b --build + adlc [-q] -b -l [] + adlc [-q] -b -d [] + adlc [-q] -b --export [--format ] [--flat] [--templates] [--rm_multiplicities] [--output ] + adlc [-q] -b [-f ] --report [-o ] + adlc [-q] -b --inject_term_bindings -i + adlc [-q] -b --export_term_bindings OPTIONS: Options should be prefixed with: '-' or '/' @@ -32,6 +33,8 @@ note : library name -f --format : output format for generated files (Optional) : file formats: json|adl|odin|yaml|xml|csv (default = adl or csv) + --templates : process only templates in operations like export + --rm_multiplicities : include RM cardinality and existences to AOM structures in output --cfg : output default configuration file location (Optional) : .cfg file path @@ -280,7 +283,7 @@ feature -- Commands -- PROCESS LIBRARY if not error_reported then report_std_out ("--------- Exporting to " + full_output_dir + "---------") - archetype_exporter.setup_build ([full_output_dir, output_format, opts.use_flat_source, opts.include_rm_multiplicities]) + archetype_exporter.setup_build ([full_output_dir, output_format, opts.use_flat, opts.include_rm_multiplicities, opts.templates_only]) archetype_exporter.build_all end end diff --git a/apps/adlc/src/main/options_processor.e b/apps/adlc/src/main/options_processor.e index 935832816..8e5948ae0 100755 --- a/apps/adlc/src/main/options_processor.e +++ b/apps/adlc/src/main/options_processor.e @@ -54,6 +54,8 @@ feature -- Definitions Result.extend (create {ARGUMENT_SWITCH}.make (quiet_switch, get_text (ec_adlc_quiet_switch_desc), True, False)) Result.extend (create {ARGUMENT_SWITCH}.make (flat_switch, get_text (ec_flat_switch_desc), True, False)) Result.extend (create {ARGUMENT_SWITCH}.make (rm_multiplicities_switch, get_text (ec_rm_multiplicities_switch_desc), True, False)) + Result.extend (create {ARGUMENT_SWITCH}.make (templates_only_switch, get_text (ec_templates_only_switch_desc), True, False)) + Result.extend (create {ARGUMENT_SWITCH}.make (show_config_switch, get_text (ec_show_config_switch_desc), False, False)) Result.extend (create {ARGUMENT_SWITCH}.make (list_archetypes_switch, get_text (ec_list_archetypes_switch_desc), False, False)) Result.extend (create {ARGUMENT_SWITCH}.make (display_archetypes_switch, get_text (ec_display_archetypes_switch_desc), False, False)) @@ -138,12 +140,14 @@ feature -- Definitions switch_of_name (clean_term_bindings_switch)>>, False)) -- EXPORT - -- adlc [--quiet] [--cfg ] --library --export [--format ] [--flat] [--output ] [] + -- adlc [--quiet] [--cfg ] --library --export [--format ] [--flat] [--templates] [--rm_multiplicities] [--output ] [] Result.extend (create {ARGUMENT_GROUP}.make (<< switch_of_name (quiet_switch), switch_of_name (cfg_switch), switch_of_name (library_switch), switch_of_name (export_switch), - switch_of_name (flat_switch), switch_of_name (rm_multiplicities_switch), + switch_of_name (flat_switch), + switch_of_name (rm_multiplicities_switch), + switch_of_name (templates_only_switch), switch_of_name (format_switch), switch_of_name (output_dir_switch)>>, True)) @@ -166,6 +170,7 @@ feature -- Definitions quiet_switch: STRING = "q|quiet" flat_switch: STRING = "flat" rm_multiplicities_switch: STRING = "rm_multiplicities" + templates_only_switch: STRING = "templates" show_config_switch: STRING = "s|show_config" list_rms_switch: STRING = "L|list_rms" @@ -237,8 +242,10 @@ feature {NONE} -- Initialization Precursor if is_successful then is_verbose := not has_option (quiet_switch) - use_flat_source := has_option (flat_switch) + use_flat := has_option (flat_switch) include_rm_multiplicities := has_option (rm_multiplicities_switch) + templates_only := has_option (templates_only_switch) + show_config := has_option (show_config_switch) list_archetypes := has_option (list_archetypes_switch) display_archetypes := has_option (display_archetypes_switch) @@ -349,10 +356,12 @@ feature -- Status Report is_verbose: BOOLEAN - use_flat_source: BOOLEAN + use_flat: BOOLEAN include_rm_multiplicities: BOOLEAN + templates_only: BOOLEAN + show_config: BOOLEAN list_archetypes: BOOLEAN diff --git a/apps/resources/messages/compiled/adl_messages_db.e b/apps/resources/messages/compiled/adl_messages_db.e index 2379f61d3..589cf7258 100755 --- a/apps/resources/messages/compiled/adl_messages_db.e +++ b/apps/resources/messages/compiled/adl_messages_db.e @@ -24,7 +24,7 @@ feature -- Initialisation make do - create message_table.make (972) + create message_table.make (973) message_table.put ("Terminology initialisation failed; reason: $1", ec_terminology_init_failed) message_table.put ("Using ADL version $1 for output serialisation", ec_adl_version_warning) message_table.put ("Validation level STRICT", ec_validation_strict) @@ -292,6 +292,7 @@ feature -- Initialisation message_table.put ("suppress verbose feedback, including configuration information on startup", ec_adlc_quiet_switch_desc) message_table.put ("use flat form of archetype[s] for export", ec_flat_switch_desc) message_table.put ("include RM multiplicities when flattening", ec_rm_multiplicities_switch_desc) + message_table.put ("export templates only", ec_templates_only_switch_desc) message_table.put ("show current configuration and defaults", ec_show_config_switch_desc) message_table.put ("generate list of archetypes in current library (use for further processing)", ec_list_archetypes_switch_desc) message_table.put ("generate list of archetypes in current library in user-friendly format", ec_display_archetypes_switch_desc) diff --git a/apps/resources/messages/compiled/adl_messages_ids.e b/apps/resources/messages/compiled/adl_messages_ids.e index cee0f4b4e..639f6a717 100755 --- a/apps/resources/messages/compiled/adl_messages_ids.e +++ b/apps/resources/messages/compiled/adl_messages_ids.e @@ -277,6 +277,7 @@ feature -- Definitions ec_adlc_quiet_switch_desc: STRING = "adlc_quiet_switch_desc" ec_flat_switch_desc: STRING = "flat_switch_desc" ec_rm_multiplicities_switch_desc: STRING = "rm_multiplicities_switch_desc" + ec_templates_only_switch_desc: STRING = "templates_only_switch_desc" ec_show_config_switch_desc: STRING = "show_config_switch_desc" ec_list_archetypes_switch_desc: STRING = "list_archetypes_switch_desc" ec_display_archetypes_switch_desc: STRING = "display_archetypes_switch_desc" diff --git a/apps/resources/messages/source/app_adlc_ui_messages.txt b/apps/resources/messages/source/app_adlc_ui_messages.txt index 2fed87996..f5724e430 100755 --- a/apps/resources/messages/source/app_adlc_ui_messages.txt +++ b/apps/resources/messages/source/app_adlc_ui_messages.txt @@ -25,6 +25,7 @@ templates = < ["adlc_quiet_switch_desc"] = <"suppress verbose feedback, including configuration information on startup"> ["flat_switch_desc"] = <"use flat form of archetype[s] for export"> ["rm_multiplicities_switch_desc"] = <"include RM multiplicities when flattening"> + ["templates_only_switch_desc"] = <"export templates only"> ["show_config_switch_desc"] = <"show current configuration and defaults"> ["list_archetypes_switch_desc"] = <"generate list of archetypes in current library (use for further processing)"> ["display_archetypes_switch_desc"] = <"generate list of archetypes in current library in user-friendly format"> diff --git a/components/adl_compiler/src/comparator/template_flattener.e b/components/adl_compiler/src/comparator/template_flattener.e index e847e3a88..8c3f367fe 100755 --- a/components/adl_compiler/src/comparator/template_flattener.e +++ b/components/adl_compiler/src/comparator/template_flattener.e @@ -58,7 +58,7 @@ end across a_flat_arch.suppliers_index as xrefs_csr loop -- get the definition structure of the flat archetype corresponding to the archetype id in the suppliers list check attached current_library.archetype_matching_ref (xrefs_csr.key) as att_ala then - matched_arch := if include_rm then att_ala.flat_archetype_with_rm else att_ala.flat_archetype end + matched_arch := att_ala.flat_archetype_processed (include_rm) end -- make a copy of the supplier archetype (or template) diff --git a/components/adl_compiler/src/interface/archetype_exporter.e b/components/adl_compiler/src/interface/archetype_exporter.e index 3edf658dc..595232e29 100755 --- a/components/adl_compiler/src/interface/archetype_exporter.e +++ b/components/adl_compiler/src/interface/archetype_exporter.e @@ -60,6 +60,7 @@ feature {NONE} -- Commands syntax := args.syntax export_flat := args.export_flat export_with_rm := args.export_with_rm + templates_only := args.templates_only artefact_count := current_library.archetype_count end @@ -120,6 +121,9 @@ feature {NONE} -- Build State export_with_rm: BOOLEAN -- True if exporting flat form with RM included + templates_only: BOOLEAN + -- True if we only want templates + feature {NONE} -- Implementation process_archetype (ara: ARCH_LIB_ARCHETYPE) @@ -128,18 +132,20 @@ feature {NONE} -- Implementation filename, exc_trace_str: STRING exception_encountered: BOOLEAN do - if not exception_encountered then - if not is_interrupted then - if attached {ARCH_LIB_AUTHORED_ARCHETYPE} ara as auth_ara and then auth_ara.is_valid then - check attached archetype_file_extensions.item (syntax) as ext then - filename := file_system.pathname (output_dir, ara.id.as_filename) + ext - end - if export_flat then - auth_ara.save_flat_as (filename, syntax) - else - auth_ara.save_differential_as (filename, syntax) + if not templates_only or else attached {ARCH_LIB_TEMPLATE} ara then + if not exception_encountered then + if not is_interrupted then + if attached {ARCH_LIB_AUTHORED_ARCHETYPE} ara as auth_ara and then auth_ara.is_valid then + check attached archetype_file_extension (export_flat, syntax) as ext then + filename := file_system.pathname (output_dir, ara.id.as_filename) + ext + end + if export_flat then + auth_ara.save_flat_as (filename, syntax, export_with_rm) + else + auth_ara.save_differential_as (filename, syntax) + end + update_progress end - update_progress end end end @@ -154,7 +160,7 @@ feature {NONE} -- Implementation retry end - build_args_type: TUPLE [export_dir, syntax: STRING; export_flat, export_with_rm: BOOLEAN] + build_args_type: TUPLE [export_dir, syntax: STRING; export_flat, export_with_rm, templates_only: BOOLEAN] do create Result end diff --git a/components/adl_compiler/src/syntax/adl/serialiser/shared_archetype_serialisers.e b/components/adl_compiler/src/syntax/adl/serialiser/shared_archetype_serialisers.e index b3346746d..aee44e924 100755 --- a/components/adl_compiler/src/syntax/adl/serialiser/shared_archetype_serialisers.e +++ b/components/adl_compiler/src/syntax/adl/serialiser/shared_archetype_serialisers.e @@ -114,8 +114,8 @@ feature -- Access -- File extensions for logical serialisation formats. once ("PROCESS") create Result.make (0) - Result.put (File_ext_archetype_source, Syntax_type_adl) - Result.put (File_ext_archetype_web_page, Syntax_type_adl_html) + Result.put (File_ext_archetype_source, {ARCHETYPE_DEFINITIONS}.Syntax_type_adl) + Result.put (File_ext_archetype_web_page, {ARCHETYPE_DEFINITIONS}.Syntax_type_adl_html) Result.put ({ODIN_DEFINITIONS}.File_ext_odin, {ODIN_DEFINITIONS}.Syntax_type_odin) Result.put ({ODIN_DEFINITIONS}.File_ext_xml_default, {ODIN_DEFINITIONS}.Syntax_type_xml) Result.put ({ODIN_DEFINITIONS}.File_ext_json_default, {ODIN_DEFINITIONS}.Syntax_type_json) @@ -128,7 +128,7 @@ feature -- Access -- File extensions for logical serialisation formats. once ("PROCESS") create Result.make (0) - Result.put ({ARCHETYPE_DEFINITIONS}.File_ext_archetype_flat, {ARCHETYPE_DEFINITIONS}.Syntax_type_adl) + Result.put ({ARCHETYPE_DEFINITIONS}.File_ext_opt2, {ARCHETYPE_DEFINITIONS}.Syntax_type_adl) Result.put ({ARCHETYPE_DEFINITIONS}.File_ext_archetype_web_page, {ARCHETYPE_DEFINITIONS}.Syntax_type_adl_html) Result.put ({ODIN_DEFINITIONS}.File_ext_odin, {ODIN_DEFINITIONS}.Syntax_type_odin) Result.put ({ODIN_DEFINITIONS}.File_ext_xml_default, {ODIN_DEFINITIONS}.Syntax_type_xml) @@ -138,14 +138,14 @@ feature -- Access not_empty: not Result.is_empty end - archetype_file_extension (diff_flag: BOOLEAN; a_format: STRING): STRING + archetype_file_extension (flat_flag: BOOLEAN; a_format: STRING): STRING do - if diff_flag then - check attached archetype_file_extensions [a_format] as ext then + if flat_flag then + check attached flat_archetype_file_extensions [a_format] as ext then Result := ext end else - check attached flat_archetype_file_extensions [a_format] as ext then + check attached archetype_file_extensions [a_format] as ext then Result := ext end end diff --git a/components/archetype_repository/src/library/arch_lib_archetype.e b/components/archetype_repository/src/library/arch_lib_archetype.e index d6d9f1f35..bd10c353c 100755 --- a/components/archetype_repository/src/library/arch_lib_archetype.e +++ b/components/archetype_repository/src/library/arch_lib_archetype.e @@ -436,23 +436,6 @@ feature -- Artefacts end end - differential_serialised_native: STRING - -- serialise differential archetype to its file in its source form, even if not compiling - -- this might fail because the serialiser might try to do something that an invalid archetype - -- can't support - local - exception_occurred: BOOLEAN - do - create Result.make_empty - if not exception_occurred then - if attached differential_archetype as da then - Result := adl_2_engine.serialise_native (da, Syntax_type_adl, current_archetype_language) - end - end - rescue - exception_occurred := True - end - flat_archetype: AUTHORED_ARCHETYPE -- inheritance-flattened form of archetype require @@ -468,31 +451,20 @@ feature -- Artefacts Result.is_flat end - flat_archetype_with_rm: like flat_archetype - -- overlay RM multiplicities on flat form. + flat_archetype_processed (include_rm:BOOLEAN): like flat_archetype + -- post-process flat archetype in various ways and return a copy + -- `with_rm` - overlay RM multiplicities on flat form. require compilation_state >= Cs_validated_phase_2 do Result := flat_archetype.deep_twin -- if requested, do RM flattening - if rm_flattening_on then + if include_rm or rm_flattening_on then rm_flattener.execute (Result, ref_model) end end - flat_serialised_native (include_rm: BOOLEAN): STRING - -- The serialised text of the flat form of the archetype - require - compilation_state >= Cs_validated_phase_2 - do - if include_rm then - Result := adl_2_engine.serialise_native (flat_archetype_with_rm, Syntax_type_adl, current_archetype_language) - else - Result := adl_2_engine.serialise_native (flat_archetype, Syntax_type_adl, current_archetype_language) - end - end - all_paths (differential_view, editing_enabled: BOOLEAN): ARRAYED_LIST[STRING] -- path map down to primitive leaf nodes do @@ -1073,7 +1045,24 @@ feature -- Visualisation end end - select_native_serialised_archetype (differential_view, with_rm: BOOLEAN): STRING +feature -- File Access + + file_mgr: ARCH_PERSISTENCE_MGR + + is_adhoc: BOOLEAN + -- True if this is an adhoc archetype + do + Result := file_mgr.is_adhoc + end + + has_source: BOOLEAN + do + Result := file_mgr.has_source + end + +feature -- Serialisation + + serialised_native (differential_view, with_rm: BOOLEAN): STRING -- return appropriate differential or flat version of archetype, depending on setting of `differential_view' and `with_rm' require is_valid @@ -1085,33 +1074,40 @@ feature -- Visualisation end end -feature -- File Access - - file_mgr: ARCH_PERSISTENCE_MGR - - is_adhoc: BOOLEAN - -- True if this is an adhoc archetype + differential_serialised_native: STRING + -- serialise differential archetype to its file in its source form, even if not compiling + -- this might fail because the serialiser might try to do something that an invalid archetype + -- can't support + local + exception_occurred: BOOLEAN do - Result := file_mgr.is_adhoc + create Result.make_empty + if not exception_occurred then + if attached differential_archetype as da then + Result := adl_2_engine.serialise_native (da, Syntax_type_adl, current_archetype_language) + end + end + rescue + exception_occurred := True end - has_source: BOOLEAN + flat_serialised_native (include_rm: BOOLEAN): STRING + -- The serialised text of the flat form of the archetype + require + compilation_state >= Cs_validated_phase_2 do - Result := file_mgr.has_source + Result := adl_2_engine.serialise_native (flat_archetype_processed (include_rm), Syntax_type_adl, current_archetype_language) end -feature -- Output - - serialise_object (flat_flag: BOOLEAN; type_marking_flag: BOOLEAN; a_format: STRING): STRING - -- serialise internal structure in a brute-force object way, using - -- format like ODIN, XML, JSON etc + serialised_object (flat_flag: BOOLEAN; type_marking_flag: BOOLEAN; a_format: STRING): STRING + -- serialise in-memory objects, using a format like ODIN, XML, JSON etc require Archetype_valid: is_valid Format_valid: has_dt_serialiser_format (a_format) local dt_arch: DT_CONVERTIBLE do - dt_arch := flat_for_serialisation (flat_flag) + dt_arch := compact_aom (flat_flag) dt_object_converter.set_false_booleans_off_option archetype_serialise_engine.set_tree (dt_arch.dt_representation) @@ -1119,7 +1115,7 @@ feature -- Output Result := archetype_serialise_engine.serialised end - serialise_object_ejson (flat_flag: BOOLEAN; type_marking_flag: BOOLEAN; a_format: STRING): STRING + serialised_object_ejson (flat_flag: BOOLEAN; type_marking_flag: BOOLEAN; a_format: STRING): STRING -- serialise internal structure in a brute-force object way, using -- format like ODIN, XML, JSON etc require @@ -1130,7 +1126,7 @@ feature -- Output fac: JSON_SERIALIZATION_FACTORY conv: JSON_SERIALIZATION do - dt_arch := flat_for_serialisation (flat_flag) + dt_arch := compact_aom (flat_flag) conv := fac.smart_serialization conv.set_pretty_printing @@ -1142,8 +1138,17 @@ feature -- Output end end + compact_aom (flat_flag: BOOLEAN): like persistent_compact_type + do + if flat_flag then + create Result.make (flat_archetype_processed (rm_flattening_on)) + else + create Result.make (safe_differential_archetype) + end + end + generate_instance (a_format: STRING): STRING - -- The serialised text of the flat form of the archetype + -- Simple synthesised instance, serialised in an object format require Archetype_valid: is_valid Format_valid: has_dt_serialiser_format (a_format) @@ -1163,15 +1168,6 @@ feature {NONE}-- Output create Result.make_dt (Void) end - flat_for_serialisation (flat_flag: BOOLEAN): like persistent_compact_type - do - if flat_flag then - create Result.make (flat_archetype) - else - create Result.make (safe_differential_archetype) - end - end - feature -- Statistics generate_statistics (in_differential_mode: BOOLEAN) diff --git a/components/archetype_repository/src/library/arch_lib_authored_archetype.e b/components/archetype_repository/src/library/arch_lib_authored_archetype.e index 9301ea975..a1e07952e 100755 --- a/components/archetype_repository/src/library/arch_lib_authored_archetype.e +++ b/components/archetype_repository/src/library/arch_lib_authored_archetype.e @@ -324,13 +324,15 @@ feature -- File Access do if has_archetype_native_serialiser_format (a_format) and attached differential_archetype as da then file_mgr.save_as (a_full_path, adl_2_engine.serialise_native (da, a_format, current_archetype_language)) + else -- must be a DT serialisation format - file_mgr.save_as (a_full_path, serialise_object (False, type_marking_on, a_format)) + file_mgr.save_as (a_full_path, serialised_object (False, type_marking_on, a_format)) end + status := get_msg_line ({GENERAL_MESSAGES_IDS}.ec_file_saved_as_in_format, <>) end - save_flat_as (a_full_path, a_format: STRING) + save_flat_as (a_full_path, a_format: STRING; include_rm: BOOLEAN) -- Save current flat archetype to `a_full_path' in `a_format'. require Archetype_valid: is_valid @@ -338,11 +340,13 @@ feature -- File Access Serialise_format_valid: has_serialiser_format (a_format) do if a_format.same_string (Syntax_type_adl) then - file_mgr.save_as (a_full_path, flat_serialised_native (False)) + file_mgr.save_as (a_full_path, flat_serialised_native (include_rm)) + elseif has_archetype_native_serialiser_format (a_format) then file_mgr.save_as (a_full_path, adl_2_engine.serialise_native (flat_archetype, a_format, current_archetype_language)) + else -- must be a DT serialisation format - file_mgr.save_as (a_full_path, serialise_object (True, type_marking_on, a_format)) + file_mgr.save_as (a_full_path, serialised_object (True, type_marking_on, a_format)) end status := get_msg_line ({GENERAL_MESSAGES_IDS}.ec_file_saved_as_in_format, <>) end @@ -370,7 +374,7 @@ feature -- File Access file_mgr.save_as (a_full_path, a_text) end - remove_file + remove_source_file -- remove the source file from the file system do file_mgr.remove_source_file @@ -382,7 +386,13 @@ feature -- File Access Result := file_mgr.can_save_to_legacy_file end -feature -- File Access + save_differential_compiled + -- save validated differential archetype in fast-retrieve form (ODIN) + require + Archetype_valid: is_valid + do + file_mgr.save_differential_compiled (serialised_object (False, False, {ODIN_DEFINITIONS}.Syntax_type_odin)) + end clean_generated -- delete generated file and compiler products; forces next compilation to start from primary expression @@ -394,15 +404,7 @@ feature -- File Access Reset_if_source_generated: file_mgr.is_source_generated implies (differential_archetype = Void and compilation_state = Cs_unread) end -feature -- File Access - - save_differential_compiled - -- save validated differential archetype in fast-retrieve form (ODIN) - require - Archetype_valid: is_valid - do - file_mgr.save_differential_compiled (serialise_object (False, False, {ODIN_DEFINITIONS}.Syntax_type_odin)) - end +feature -- Serialisation compiled_differential: STRING -- round-trip from ODIN-serialised file to AOM2 to ODIN diff --git a/components/archetype_repository/src/library/arch_lib_template.e b/components/archetype_repository/src/library/arch_lib_template.e index da83fee66..a8b197dd4 100755 --- a/components/archetype_repository/src/library/arch_lib_template.e +++ b/components/archetype_repository/src/library/arch_lib_template.e @@ -14,7 +14,7 @@ inherit redefine validator_reset, select_archetype, file_mgr, flat_archetype, differential_archetype, differential_serialised_native, persistent_compact_type, - flat_for_serialisation, select_native_serialised_archetype, signal_from_scratch, + compact_aom, flat_serialised_native, signal_from_scratch, clear_cache, validate_closure end @@ -66,33 +66,6 @@ feature -- Artefacts differential_archetype: detachable TEMPLATE - differential_serialised_native: STRING - -- serialise differential archetype to its file in its source form, even if not compiling - -- this might fail because the serialiser might try to do something that an invalid archetype - -- can't support - local - exception_occurred: BOOLEAN - do - create Result.make_empty - if not exception_occurred then - if attached differential_archetype as da then - Result := adl_2_engine.serialise_native (da, Syntax_type_adl, current_archetype_language) - - -- append overlay texts - across overlays as overlays_csr loop - Result.append (Source_template_overlay_divider) - if attached overlays_csr.item.differential_serialised_native as ovl_str then - Result.append (ovl_str) - else - Result.append (Overlay_differential_not_available + overlays_csr.item.id.physical_id) - end - end - end - end - rescue - exception_occurred := True - end - flat_archetype: TEMPLATE -- inheritance-flattened form of archetype do @@ -150,14 +123,39 @@ feature -- Visualisation end end - select_native_serialised_archetype (differential_view, with_rm: BOOLEAN): STRING - -- return appropriate differential or flat version of archetype, depending on setting of `differential_view' and `with_rm' +feature -- Serialisation + + flat_serialised_native (include_rm: BOOLEAN): STRING + -- The serialised text of the flat form of the archetype + do + Result := operational_template_serialised (include_rm) + end + + differential_serialised_native: STRING + -- serialise differential archetype to its file in its source form, even if not compiling + -- this might fail because the serialiser might try to do something that an invalid archetype + -- can't support + local + exception_occurred: BOOLEAN do - if differential_view then - Result := differential_serialised_native - else - Result := operational_template_serialised (with_rm) + create Result.make_empty + if not exception_occurred then + if attached differential_archetype as da then + Result := adl_2_engine.serialise_native (da, Syntax_type_adl, current_archetype_language) + + -- append overlay texts + across overlays as overlays_csr loop + Result.append (Source_template_overlay_divider) + if attached overlays_csr.item.differential_serialised_native as ovl_str then + Result.append (ovl_str) + else + Result.append (Overlay_differential_not_available + overlays_csr.item.id.physical_id) + end + end + end end + rescue + exception_occurred := True end feature {ARCH_LIB_ARCHETYPE} -- Compilation @@ -194,7 +192,7 @@ feature {NONE} -- Flattening opt_generator: TEMPLATE_FLATTENER do create opt_generator - opt_generator.execute (if include_rm then flat_archetype_with_rm else flat_archetype end, include_rm) + opt_generator.execute (flat_archetype_processed (include_rm), include_rm) Result := opt_generator.opt end @@ -210,7 +208,7 @@ feature {NONE} -- Editing feature {NONE} -- Output - flat_for_serialisation (flat_flag: BOOLEAN): P_AUTHORED_ARCHETYPE + compact_aom (flat_flag: BOOLEAN): P_AUTHORED_ARCHETYPE do if flat_flag then create {P_OPERATIONAL_TEMPLATE} Result.make (operational_template)