ceedling 1.2.2 → 1.2.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/GIT_COMMIT_SHA +1 -1
- data/README.md +1 -1
- data/assets/fixtures/tests_with_partials_coverage/src/private_macro.c +7 -0
- data/assets/fixtures/tests_with_partials_coverage/src/private_macro.h +5 -0
- data/assets/fixtures/tests_with_partials_coverage/src/tally.c +13 -0
- data/assets/fixtures/tests_with_partials_coverage/src/tally.h +4 -0
- data/assets/fixtures/tests_with_partials_coverage/test/test_private_macro.c +10 -0
- data/assets/fixtures/tests_with_partials_coverage/test/test_tally.c +9 -0
- data/docs/BreakingChanges.md +16 -0
- data/docs/Changelog.md +71 -0
- data/docs/KnownIssues.md +91 -4
- data/examples/wondrous_forest/README.md +29 -1
- data/examples/wondrous_forest/src/ForestUnits.h +23 -0
- data/examples/wondrous_forest/src/RainGauge.c +59 -0
- data/examples/wondrous_forest/src/RainGauge.h +39 -0
- data/examples/wondrous_forest/src/RainTipIsr.c +17 -0
- data/examples/wondrous_forest/src/RainTipIsr.h +14 -0
- data/examples/wondrous_forest/test/TestRainGauge.c +126 -0
- data/lib/ceedling/c_extractor/README.md +15 -7
- data/lib/ceedling/c_extractor/c_extractor.rb +25 -14
- data/lib/ceedling/c_extractor/c_extractor_code_text.rb +84 -54
- data/lib/ceedling/c_extractor/c_extractor_constants.rb +18 -7
- data/lib/ceedling/c_extractor/c_extractor_declarations.rb +319 -283
- data/lib/ceedling/c_extractor/c_extractor_declarator.rb +285 -0
- data/lib/ceedling/c_extractor/c_extractor_defined_type.rb +111 -0
- data/lib/ceedling/c_extractor/c_extractor_definitions.rb +174 -121
- data/lib/ceedling/c_extractor/c_extractor_functions.rb +191 -162
- data/lib/ceedling/c_extractor/c_extractor_preprocessing.rb +46 -55
- data/lib/ceedling/c_extractor/c_extractor_statement.rb +30 -0
- data/lib/ceedling/c_extractor/c_extractor_types.rb +63 -41
- data/lib/ceedling/c_extractor/c_module_edits.rb +48 -0
- data/lib/ceedling/c_identifier.rb +21 -0
- data/lib/ceedling/ceedling.h +8 -0
- data/lib/ceedling/config/configurator.rb +4 -3
- data/lib/ceedling/config/configurator_builder.rb +17 -0
- data/lib/ceedling/config/configurator_setup.rb +29 -5
- data/lib/ceedling/constants.rb +5 -1
- data/lib/ceedling/defaults.rb +31 -1
- data/lib/ceedling/dependencies/CACHE_SCHEMA.md +118 -0
- data/lib/ceedling/dependencies/README.md +1 -1
- data/lib/ceedling/dependencies/dependency_cache_store.rb +30 -25
- data/lib/ceedling/dependencies/dependency_tracker.rb +9 -3
- data/lib/ceedling/dependencies/dependinator.rb +13 -1
- data/lib/ceedling/diagnostics/DOCTOR.md +142 -0
- data/lib/ceedling/diagnostics/README.md +5 -0
- data/lib/ceedling/diagnostics/build_step_doctor.rb +110 -0
- data/lib/ceedling/diagnostics/duplicate_symbol_specialist.rb +108 -0
- data/lib/ceedling/diagnostics/guidance_phrases.rb +30 -0
- data/lib/ceedling/diagnostics/header_collision_guidance.rb +56 -0
- data/lib/ceedling/diagnostics/header_collision_specialist.rb +152 -0
- data/lib/ceedling/diagnostics/include_depth_specialist.rb +132 -0
- data/lib/ceedling/diagnostics/missing_symbol_specialist.rb +111 -0
- data/lib/ceedling/diagnostics/partial_name_specialist.rb +134 -0
- data/lib/ceedling/diagnostics/toolchain_output.rb +44 -0
- data/lib/ceedling/filesystem/PATH_HANDLING.md +83 -27
- data/lib/ceedling/filesystem/README.md +6 -1
- data/lib/ceedling/filesystem/build_roots.rb +105 -0
- data/lib/ceedling/filesystem/build_subpath.rb +110 -25
- data/lib/ceedling/filesystem/file_finder.rb +76 -110
- data/lib/ceedling/filesystem/file_finder_helper.rb +33 -11
- data/lib/ceedling/filesystem/file_path_utils.rb +113 -91
- data/lib/ceedling/filesystem/file_wrapper.rb +105 -28
- data/lib/ceedling/filesystem/path_matcher.rb +21 -0
- data/lib/ceedling/filesystem/test_build_layout.rb +114 -0
- data/lib/ceedling/filesystem/win_long_paths.rb +153 -0
- data/lib/ceedling/filesystem/win_path_limit.rb +83 -0
- data/lib/ceedling/filesystem/win_path_prober.rb +52 -0
- data/lib/ceedling/generators/generator.rb +27 -64
- data/lib/ceedling/generators/generator_helper.rb +0 -44
- data/lib/ceedling/generators/generator_mocks.rb +5 -0
- data/lib/ceedling/generators/generator_partials.rb +305 -243
- data/lib/ceedling/generators/generator_test_runner.rb +5 -8
- data/lib/ceedling/generators/partial_header_writer.rb +95 -0
- data/lib/ceedling/generators/partial_source_writer.rb +137 -0
- data/lib/ceedling/includes/header_search.rb +225 -0
- data/lib/ceedling/includes/include_factory.rb +9 -12
- data/lib/ceedling/includes/include_pathinator.rb +53 -31
- data/lib/ceedling/includes/includes.rb +149 -37
- data/lib/ceedling/objects.yml +89 -4
- data/lib/ceedling/partials/README.md +110 -16
- data/lib/ceedling/partials/carry_plan.rb +71 -0
- data/lib/ceedling/partials/definition_head.rb +74 -0
- data/lib/ceedling/partials/include_groups.rb +37 -0
- data/lib/ceedling/partials/interface_extras.rb +25 -0
- data/lib/ceedling/partials/partializer.rb +599 -120
- data/lib/ceedling/partials/partializer_config.rb +5 -0
- data/lib/ceedling/partials/partializer_helper.rb +851 -145
- data/lib/ceedling/partials/partializer_reconciler.rb +174 -0
- data/lib/ceedling/partials/partializer_utils.rb +89 -109
- data/lib/ceedling/partials/partials.rb +153 -10
- data/lib/ceedling/partials/type_macros.rb +126 -0
- data/lib/ceedling/preprocess/README.md +43 -33
- data/lib/ceedling/preprocess/preprocessinator.rb +100 -186
- data/lib/ceedling/preprocess/preprocessinator_code_finder.rb +65 -72
- data/lib/ceedling/preprocess/preprocessinator_file_assembler.rb +31 -75
- data/lib/ceedling/preprocess/preprocessinator_reconstructor.rb +51 -14
- data/lib/ceedling/setupinator.rb +16 -3
- data/lib/ceedling/test_invoker/HEADER_COLLISIONS.md +21 -7
- data/lib/ceedling/test_invoker/PIPELINE.md +57 -16
- data/lib/ceedling/test_invoker/README.md +1 -1
- data/lib/ceedling/test_invoker/derived_search_path_notices.rb +45 -0
- data/lib/ceedling/test_invoker/mock_locator.rb +116 -9
- data/lib/ceedling/test_invoker/partial_files_preprocessinator.rb +181 -0
- data/lib/ceedling/test_invoker/partials_manager.rb +265 -308
- data/lib/ceedling/test_invoker/standin_headerinator.rb +8 -15
- data/lib/ceedling/test_invoker/test_bare_includes_extractinator.rb +26 -3
- data/lib/ceedling/test_invoker/test_build_executor.rb +338 -198
- data/lib/ceedling/test_invoker/test_build_planner.rb +13 -19
- data/lib/ceedling/test_invoker/test_build_setup.rb +26 -6
- data/lib/ceedling/test_invoker/test_build_validations.rb +23 -20
- data/lib/ceedling/test_invoker/test_derived_search_paths.rb +189 -0
- data/lib/ceedling/test_invoker/test_file_preprocessinator.rb +1 -2
- data/lib/ceedling/test_invoker/test_includes_reconcilinator.rb +1 -1
- data/lib/ceedling/test_invoker/test_invoker_types.rb +28 -20
- data/lib/ceedling/test_invoker/test_pipeline_helpers.rb +5 -3
- data/lib/ceedling/test_invoker/test_pipeline_manager.rb +25 -8
- data/lib/ceedling/test_invoker/test_runner_generatinator.rb +31 -3
- data/lib/ceedling/test_invoker/test_search_paths.rb +30 -8
- data/lib/ceedling/test_invoker/test_substitutions.rb +72 -0
- data/lib/ceedling/tools/shell_quoting.rb +45 -0
- data/lib/ceedling/tools/tool_quoting.rb +79 -0
- data/lib/ceedling/{tool_validator.rb → tools/tool_validator.rb} +18 -7
- data/lib/version.rb +1 -1
- data/plugins/bullseye/bullseye.rake +1 -3
- data/plugins/bullseye/lib/bullseye.rb +15 -2
- data/plugins/command_hooks/lib/command_hooks.rb +1 -1
- data/plugins/fff/lib/fff.rb +42 -15
- data/plugins/fff/lib/fff_mock_generator.rb +12 -9
- data/plugins/fff/spec/fff_cmock_wrapper_spec.rb +134 -0
- data/plugins/fff/spec/fff_mock_header_generator_spec.rb +9 -0
- data/plugins/fff/spec/fff_mock_source_generator_spec.rb +20 -0
- data/plugins/gcov/lib/console_reportinator.rb +25 -19
- data/plugins/gcov/lib/reportgenerator_reportinator.rb +2 -1
- data/site-local/404.html +2 -2
- data/site-local/assets/javascripts/{bundle.c21346df.min.js → bundle.a5f9d56c.min.js} +1 -1
- data/site-local/assets/javascripts/{bundle.c21346df.min.js.map → bundle.a5f9d56c.min.js.map} +2 -2
- data/site-local/configuration/environment-vars.html +2 -2
- data/site-local/configuration/global-collections.html +3 -3
- data/site-local/configuration/index.html +2 -2
- data/site-local/configuration/loading.html +2 -2
- data/site-local/configuration/mixins.html +2 -2
- data/site-local/configuration/parallel-builds.html +2 -2
- data/site-local/configuration/project-file.html +2 -2
- data/site-local/configuration/reference/cexception.html +2 -2
- data/site-local/configuration/reference/cmock.html +5 -2
- data/site-local/configuration/reference/defines.html +2 -2
- data/site-local/configuration/reference/environment.html +2 -2
- data/site-local/configuration/reference/extension.html +2 -2
- data/site-local/configuration/reference/files.html +56 -9
- data/site-local/configuration/reference/flags.html +2 -2
- data/site-local/configuration/reference/index.html +2 -2
- data/site-local/configuration/reference/libraries.html +2 -2
- data/site-local/configuration/reference/mixins.html +2 -2
- data/site-local/configuration/reference/partials.html +84 -2
- data/site-local/configuration/reference/paths.html +7 -2
- data/site-local/configuration/reference/plugins.html +2 -2
- data/site-local/configuration/reference/project.html +247 -5
- data/site-local/configuration/reference/release-build.html +2 -2
- data/site-local/configuration/reference/test-build.html +2 -2
- data/site-local/configuration/reference/test-runner.html +2 -2
- data/site-local/configuration/reference/tools.html +49 -4
- data/site-local/configuration/reference/unity.html +2 -2
- data/site-local/configuration/which-ceedling.html +2 -2
- data/site-local/development/index.html +2 -2
- data/site-local/development/plugins/configuration.html +2 -2
- data/site-local/development/plugins/index.html +2 -2
- data/site-local/development/plugins/plugin-subclass.html +5 -4
- data/site-local/development/plugins/rake-tasks.html +2 -2
- data/site-local/development/releases.html +2 -2
- data/site-local/development/workflow.html +2 -2
- data/site-local/getting-started/builds.html +2 -2
- data/site-local/getting-started/command-line.html +2 -2
- data/site-local/getting-started/example-projects/cipher-quest.html +2 -2
- data/site-local/getting-started/example-projects/index.html +2 -2
- data/site-local/getting-started/example-projects/temp-sensor.html +2 -2
- data/site-local/getting-started/example-projects/wondrous-forest.html +10 -2
- data/site-local/getting-started/index.html +2 -2
- data/site-local/getting-started/installation.html +2 -2
- data/site-local/getting-started/quick-start.html +2 -2
- data/site-local/help.html +2 -2
- data/site-local/index.html +2 -2
- data/site-local/overview/build-system.html +2 -2
- data/site-local/overview/index.html +2 -2
- data/site-local/overview/test-environments.html +2 -2
- data/site-local/overview/tools-and-frameworks.html +2 -2
- data/site-local/plugins/beep.html +2 -2
- data/site-local/plugins/bullseye/index.html +45 -38
- data/site-local/plugins/bullseye/licensing.html +2 -2
- data/site-local/plugins/command-hooks.html +4 -4
- data/site-local/plugins/compile-commands-json-db.html +2 -2
- data/site-local/plugins/cppcheck.html +2 -2
- data/site-local/plugins/dependencies.html +2 -2
- data/site-local/plugins/fff.html +16 -2
- data/site-local/plugins/gcov/examples.html +2 -2
- data/site-local/plugins/gcov/gcovr.html +8 -2
- data/site-local/plugins/gcov/index.html +2 -2
- data/site-local/plugins/gcov/overview.html +2 -2
- data/site-local/plugins/gcov/reportgenerator.html +18 -14
- data/site-local/plugins/gcov/reporting.html +2 -2
- data/site-local/plugins/gcov/setup.html +2 -2
- data/site-local/plugins/gcov/tool-versions.html +2 -2
- data/site-local/plugins/gcov/troubleshooting.html +2 -2
- data/site-local/plugins/index.html +2 -2
- data/site-local/plugins/module-generator.html +2 -2
- data/site-local/plugins/report-build-warnings-log.html +2 -2
- data/site-local/plugins/report-tests-gtestlike-stdout.html +2 -2
- data/site-local/plugins/report-tests-ide-stdout.html +2 -2
- data/site-local/plugins/report-tests-log-factory.html +2 -2
- data/site-local/plugins/report-tests-pretty-stdout.html +2 -2
- data/site-local/plugins/report-tests-raw-output-log.html +2 -2
- data/site-local/plugins/report-tests-teamcity-stdout.html +2 -2
- data/site-local/plugins/sanitize.html +2 -2
- data/site-local/plugins/valgrind.html +2 -2
- data/site-local/project/index.html +2 -2
- data/site-local/project/release-history.html +2 -2
- data/site-local/project/sbom.html +2 -2
- data/site-local/project/upgrade.html +2 -2
- data/site-local/reference/build-directives.html +2 -2
- data/site-local/reference/command-line.html +2 -2
- data/site-local/reference/environment-vars.html +2 -2
- data/site-local/reference/gcov-plugin.html +2 -2
- data/site-local/reference/global-collections.html +12 -12
- data/site-local/reference/index.html +2 -2
- data/site-local/reference/partials-macros.html +47 -2
- data/site-local/reference/project-configuration.html +2 -2
- data/site-local/sitemap.xml.gz +0 -0
- data/site-local/snapshot/examples/cipher_quest/index.html +2 -2
- data/site-local/snapshot/examples/temp_sensor/index.html +2 -2
- data/site-local/snapshot/examples/wondrous_forest/index.html +72 -15
- data/site-local/testing-guide/build-directives.html +2 -2
- data/site-local/testing-guide/conventions.html +67 -22
- data/site-local/testing-guide/frameworks.html +2 -2
- data/site-local/testing-guide/index.html +2 -2
- data/site-local/testing-guide/partials/configuration.html +31 -4
- data/site-local/testing-guide/partials/conventions.html +509 -8
- data/site-local/testing-guide/partials/directives.html +4 -3
- data/site-local/testing-guide/partials/example.html +2 -2
- data/site-local/testing-guide/partials/index.html +2 -2
- data/site-local/testing-guide/partials/overview.html +30 -12
- data/site-local/testing-guide/partials/variables.html +169 -4
- data/site-local/testing-guide/test-cases.html +2 -2
- data/site-local/testing-guide/test-sample.html +2 -2
- data/site-local/testing-guide/test-suite-anatomy.html +2 -2
- data/spec/integration/build_step_doctor_spec.rb +270 -0
- data/spec/integration/c_extractor_composition_spec.rb +254 -4
- data/spec/integration/includes_extraction_spec.rb +27 -14
- data/spec/integration/nested_test_artifacts_spec.rb +1 -1
- data/spec/integration/partial_files_preprocessing_spec.rb +128 -0
- data/spec/integration/partials_carry_spec.rb +520 -0
- data/spec/integration/partials_declarations_spec.rb +655 -0
- data/spec/integration/partials_fallback_preprocessing_spec.rb +65 -0
- data/spec/integration/partials_function_pointers_spec.rb +277 -0
- data/spec/integration/partials_header_composition_spec.rb +268 -35
- data/spec/integration/partials_macro_decorators_spec.rb +267 -0
- data/spec/integration/partials_module_resolution_spec.rb +26 -19
- data/spec/integration/partials_symbol_linkage_spec.rb +13 -0
- data/spec/integration/path_length_reporting_spec.rb +64 -0
- data/spec/integration/path_scenarios_spec.rb +80 -3
- data/spec/integration/quote_include_isolator_spec.rb +56 -0
- data/spec/integration/test_build_parallel_barrier_spec.rb +1 -1
- data/spec/integration/test_includes_extractinator_spec.rb +70 -5
- data/spec/integration/test_naming_spec.rb +6 -3
- data/spec/integration/test_source_file_checks_spec.rb +5 -3
- data/spec/integration/tool_executor_spec.rb +1 -1
- data/spec/integration/tool_validator_spec.rb +2 -2
- data/spec/integration/win_long_paths_probe_spec.rb +46 -0
- data/spec/integration/win_path_limit_spec.rb +53 -0
- data/spec/integration/windows_registry_query_tool_spec.rb +41 -0
- data/spec/support/integration/configurator_integration_helper.rb +8 -3
- data/spec/support/integration/partial_files_harness.rb +181 -0
- data/spec/support/integration/partials_generation_integration_helper.rb +237 -141
- data/spec/support/integration/path_scenario_harness.rb +4 -2
- data/spec/support/integration/spec_integration_helper.rb +8 -3
- data/spec/support/integration/test_includes_harness.rb +56 -35
- data/spec/support/integration/tool_executor_integration_helper.rb +14 -2
- data/spec/system/bullseye_deployment_spec.rb +2 -0
- data/spec/system/delta_builds_spec.rb +26 -12
- data/spec/system/encoding_stress_spec.rb +4 -4
- data/spec/system/example_wondrous_forest_spec.rb +2 -2
- data/spec/system/gcov_deployment_spec.rb +2 -0
- data/spec/system/header_include_path_validation_spec.rb +4 -4
- data/spec/system/header_search_paths_spec.rb +1083 -0
- data/spec/system/mock_include_folders_spec.rb +121 -0
- data/spec/system/mockable_header_reassembly_spec.rb +184 -0
- data/spec/system/partials_carry_spec.rb +581 -0
- data/spec/system/partials_delta_builds_spec.rb +280 -0
- data/spec/system/partials_function_pointers_spec.rb +106 -0
- data/spec/system/partials_macro_decorators_spec.rb +127 -0
- data/spec/system/partials_module_disambiguation_spec.rb +125 -0
- data/spec/system/path_handling_probes_spec.rb +16 -12
- data/spec/system/pinned_thread_count_spec.rb +4 -4
- data/spec/system/preprocessing_fallback_conditionals_spec.rb +1 -1
- data/spec/system/short_build_paths_spec.rb +87 -0
- data/spec/system/sibling_header_collision_spec.rb +30 -6
- data/spec/system/support/bullseye_common_test_cases.rb +42 -0
- data/spec/system/support/common_test_cases.rb +2 -2
- data/spec/system/support/gcov_partials_test_cases.rb +48 -0
- data/spec/system/test_build_layout_spec.rb +209 -0
- data/spec/system/test_source_file_directive_spec.rb +35 -5
- data/spec/units/c_extractor/c_extractor_code_text_spec.rb +67 -10
- data/spec/units/c_extractor/c_extractor_declarations_spec.rb +501 -4
- data/spec/units/c_extractor/c_extractor_declarator_spec.rb +245 -0
- data/spec/units/c_extractor/c_extractor_defined_type_spec.rb +45 -0
- data/spec/units/c_extractor/c_extractor_definitions_spec.rb +163 -3
- data/spec/units/c_extractor/c_extractor_functions_spec.rb +462 -21
- data/spec/units/c_extractor/c_extractor_preprocessing_spec.rb +39 -0
- data/spec/units/c_extractor/c_extractor_spec.rb +4 -4
- data/spec/units/c_extractor/c_extractor_types_spec.rb +163 -0
- data/spec/units/c_identifier_spec.rb +35 -0
- data/spec/units/config/configurator_builder_spec.rb +24 -0
- data/spec/units/config/configurator_setup_spec.rb +72 -4
- data/spec/units/config/configurator_spec.rb +27 -1
- data/spec/units/dependencies/dependency_cache_store_spec.rb +68 -3
- data/spec/units/dependencies/dependency_tracker_spec.rb +25 -0
- data/spec/units/dependencies/dependinator_spec.rb +17 -2
- data/spec/units/diagnostics/build_step_doctor_spec.rb +170 -0
- data/spec/units/diagnostics/duplicate_symbol_specialist_spec.rb +117 -0
- data/spec/units/diagnostics/header_collision_specialist_spec.rb +267 -0
- data/spec/units/diagnostics/include_depth_specialist_spec.rb +137 -0
- data/spec/units/diagnostics/missing_symbol_specialist_spec.rb +154 -0
- data/spec/units/diagnostics/partial_name_specialist_spec.rb +129 -0
- data/spec/units/diagnostics/toolchain_output_spec.rb +86 -0
- data/spec/units/encodinator_spec.rb +3 -4
- data/spec/units/filesystem/build_roots_spec.rb +131 -0
- data/spec/units/filesystem/build_subpath_spec.rb +113 -0
- data/spec/units/filesystem/file_finder_helper_spec.rb +80 -0
- data/spec/units/filesystem/file_finder_spec.rb +242 -58
- data/spec/units/filesystem/file_path_utils_spec.rb +251 -118
- data/spec/units/filesystem/file_wrapper_spec.rb +191 -6
- data/spec/units/filesystem/path_matcher_spec.rb +36 -0
- data/spec/units/filesystem/test_build_layout_spec.rb +216 -0
- data/spec/units/filesystem/win_long_paths_spec.rb +204 -0
- data/spec/units/filesystem/win_path_prober_spec.rb +158 -0
- data/spec/units/generators/generator_helper_spec.rb +0 -60
- data/spec/units/generators/generator_mocks_spec.rb +13 -0
- data/spec/units/generators/generator_partials_spec.rb +656 -55
- data/spec/units/generators/generator_spec.rb +26 -0
- data/spec/units/generators/generator_test_runner_spec.rb +9 -5
- data/spec/units/generators/partial_source_writer_spec.rb +129 -0
- data/spec/units/includes/header_search_spec.rb +406 -0
- data/spec/units/includes/include_factory_spec.rb +22 -5
- data/spec/units/includes/include_pathinator_spec.rb +77 -13
- data/spec/units/includes/include_spec.rb +14 -0
- data/spec/units/includes/includes_spec.rb +176 -19
- data/spec/units/loginator_spec.rb +31 -0
- data/spec/units/mock_locator_spec.rb +199 -5
- data/spec/units/partials/include_groups_spec.rb +42 -0
- data/spec/units/partials/partializer_config_spec.rb +25 -0
- data/spec/units/partials/partializer_helper_carry_spec.rb +661 -0
- data/spec/units/partials/partializer_helper_interface_extras_spec.rb +396 -0
- data/spec/units/partials/partializer_helper_spec.rb +529 -277
- data/spec/units/partials/partializer_reconciler_spec.rb +661 -0
- data/spec/units/partials/partializer_spec.rb +1578 -270
- data/spec/units/partials/partializer_utils_spec.rb +269 -232
- data/spec/units/partials/partials_rename_spec.rb +160 -0
- data/spec/units/partials_manager_spec.rb +554 -261
- data/spec/units/plugins/bullseye_spec.rb +34 -0
- data/spec/units/plugins/console_reportinator_spec.rb +58 -9
- data/spec/units/plugins/report_tests_teamcity_stdout_spec.rb +1 -1
- data/spec/units/plugins/reportgenerator_reportinator_spec.rb +51 -3
- data/spec/units/preprocess/preprocessinator_code_finder_spec.rb +73 -10
- data/spec/units/preprocess/preprocessinator_file_assembler_spec.rb +125 -37
- data/spec/units/preprocess/preprocessinator_includes_handler_spec.rb +15 -0
- data/spec/units/preprocess/preprocessinator_reconstructor_spec.rb +197 -0
- data/spec/units/preprocess/preprocessinator_spec.rb +153 -95
- data/spec/units/setupinator_spec.rb +51 -0
- data/spec/units/standin_headerinator_spec.rb +27 -11
- data/spec/units/test_build_executor_spec.rb +780 -166
- data/spec/units/test_build_planner_spec.rb +116 -28
- data/spec/units/test_build_setup_spec.rb +83 -18
- data/spec/units/test_context_extractor_spec.rb +11 -2
- data/spec/units/test_derived_search_paths_spec.rb +259 -0
- data/spec/units/test_includes_extractinator_spec.rb +56 -8
- data/spec/units/test_invoker/objects_wiring_spec.rb +20 -3
- data/spec/units/test_invoker/partial_files_preprocessinator_spec.rb +264 -0
- data/spec/units/test_invoker/test_substitutions_spec.rb +122 -0
- data/spec/units/test_invoker_types_spec.rb +8 -7
- data/spec/units/test_pipeline_manager_spec.rb +54 -13
- data/spec/units/test_runner_generatinator_spec.rb +93 -1
- data/spec/units/test_search_paths_spec.rb +73 -5
- data/spec/units/{default_tools_quoting_spec.rb → tools/default_tools_quoting_spec.rb} +39 -5
- data/spec/units/tools/shell_quoting_spec.rb +76 -0
- data/spec/units/{tool_executor_helper_spec.rb → tools/tool_executor_helper_spec.rb} +1 -1
- data/spec/units/{tool_executor_spec.rb → tools/tool_executor_spec.rb} +1 -1
- data/spec/units/{tool_validator_spec.rb → tools/tool_validator_spec.rb} +110 -1
- data/spec/units/windows_registry_query_tool_spec.rb +53 -0
- metadata +161 -16
- /data/lib/ceedling/{tool_executor.rb → tools/tool_executor.rb} +0 -0
- /data/lib/ceedling/{tool_executor_helper.rb → tools/tool_executor_helper.rb} +0 -0
|
@@ -10,6 +10,7 @@ require 'ceedling/exceptions'
|
|
|
10
10
|
require 'ceedling/array_patches' # Redundant `require` to ensure patching in test cases
|
|
11
11
|
require 'ceedling/partials/partials'
|
|
12
12
|
require 'ceedling/c_extractor/c_extractor_declarations'
|
|
13
|
+
require 'ceedling/c_extractor/c_extractor_functions'
|
|
13
14
|
require 'ceedling/c_extractor/c_extractor_constants'
|
|
14
15
|
require 'strscan'
|
|
15
16
|
require 'ceedling/constants'
|
|
@@ -22,9 +23,9 @@ class PartializerHelper
|
|
|
22
23
|
# to be decided rather than assumed.
|
|
23
24
|
#
|
|
24
25
|
# Deliberately narrow: a leading type-definition keyword, which is how a file-scope type
|
|
25
|
-
# definition opens.
|
|
26
|
-
#
|
|
27
|
-
# enough to catch
|
|
26
|
+
# definition opens. A type written directly on a variable (`static struct { int a; } slot;`)
|
|
27
|
+
# is relocated too, but behind a storage class this pattern does not reach. Widening it far
|
|
28
|
+
# enough to catch that would also match an ordinary local declaration inside a function body,
|
|
28
29
|
# turning a resolvable module into a refused one -- and telling the two apart needs brace
|
|
29
30
|
# tracking this check does not do. Under-reaching leaves a shape unrefused; over-reaching
|
|
30
31
|
# breaks a working build.
|
|
@@ -36,14 +37,48 @@ class PartializerHelper
|
|
|
36
37
|
# the same reason, against its own copy of this pattern.
|
|
37
38
|
ANY_INCLUDE_DIRECTIVE = /^\s*#\s*include\s+\S/ unless const_defined?(:ANY_INCLUDE_DIRECTIVE, false)
|
|
38
39
|
|
|
40
|
+
# Code uses a function wherever it names one. A call counts, and so do an address taken, a
|
|
41
|
+
# callback passed by name and an entry in a table of handlers.
|
|
42
|
+
C_IDENTIFIER = /(?<![\w$])[A-Za-z_$][\w$]*/ unless const_defined?(:C_IDENTIFIER, false)
|
|
43
|
+
|
|
44
|
+
# A struct or union member, or a struct, union or enum tag, which only shares a name with any function
|
|
45
|
+
C_MEMBER_ACCESS = /(?:\.|->)\s*[A-Za-z_$][\w$]*/ unless const_defined?(:C_MEMBER_ACCESS, false)
|
|
46
|
+
C_TAG = /(?<![\w$])(?:struct|union|enum)\s+[A-Za-z_$][\w$]*/ unless const_defined?(:C_TAG, false)
|
|
47
|
+
|
|
48
|
+
# A local variable declared at the start of a statement. Any qualifiers come first, then a
|
|
49
|
+
# type name, any pointer stars, and the variable's name ahead of `=`, `;`, `,` or `[`. A
|
|
50
|
+
# keyword that starts a statement is no type, so `return x;` declares nothing.
|
|
51
|
+
C_LOCAL_DECLARATION = /(?:\A|[;{}(])\s*(?:(?:const|volatile|static|register|auto|signed|unsigned|struct|union|enum|long|short)\s+)*([A-Za-z_$][\w$]*)(?:\s*\*[\s*]*|\s+)(?:const\s+)?([A-Za-z_$][\w$]*)\s*(?=[=;,\[])/ unless const_defined?(:C_LOCAL_DECLARATION, false)
|
|
52
|
+
C_STATEMENT_KEYWORDS = %w[return goto case default else do sizeof typedef break continue].freeze unless const_defined?(:C_STATEMENT_KEYWORDS, false)
|
|
53
|
+
|
|
54
|
+
# A preprocessor directive line, matched from the line's start past any leading whitespace
|
|
55
|
+
DIRECTIVE_START = /[\t\v\f\r ]*#/ unless const_defined?(:DIRECTIVE_START, false)
|
|
56
|
+
|
|
57
|
+
# What one walk of a run has seen so far. Words on a directive line never set a specifier.
|
|
58
|
+
DefinitionWalk = Struct.new( :directive, :inline, :static, keyword_init: true ) unless const_defined?(:DefinitionWalk, false)
|
|
59
|
+
OPEN_BRACE = '{'.ord unless const_defined?(:OPEN_BRACE, false)
|
|
60
|
+
|
|
61
|
+
# The names a carry plan decides by, grouped once per module
|
|
62
|
+
CarryFacts = Struct.new( :selected, :defined, :declared, :helpers, keyword_init: true ) unless const_defined?(:CarryFacts, false)
|
|
63
|
+
|
|
64
|
+
# What the helper scan shares while it walks. That is the plan it fills and the facts that gate it.
|
|
65
|
+
CarryScan = Struct.new( :plan, :declared, :fallback, :header_guarded, keyword_init: true ) unless const_defined?(:CarryScan, false)
|
|
66
|
+
|
|
67
|
+
# Names a definition the extractor read no function name from, and how to spell it plainly
|
|
68
|
+
UNREADABLE_NAME_ERROR = <<~ERROR.chomp unless const_defined?(:UNREADABLE_NAME_ERROR, false)
|
|
69
|
+
Partial %<partial>s ⏩️ Cannot read the name of the function declared by `%<declaration>s`.
|
|
70
|
+
|
|
71
|
+
OPTIONS:
|
|
72
|
+
1. If it returns or takes a function pointer, give that type a name with a typedef and use the name in this declaration.
|
|
73
|
+
2. If a macro generates the declaration, declare the function directly.
|
|
74
|
+
ERROR
|
|
75
|
+
|
|
39
76
|
|
|
40
77
|
include Partials
|
|
41
78
|
|
|
42
79
|
constructor(
|
|
43
80
|
:partializer_utils,
|
|
44
|
-
:c_extractor,
|
|
45
81
|
:c_extractor_declarations,
|
|
46
|
-
:file_path_utils,
|
|
47
82
|
:parsing_parcels,
|
|
48
83
|
:loginator
|
|
49
84
|
)
|
|
@@ -107,46 +142,34 @@ class PartializerHelper
|
|
|
107
142
|
# calculate the 1-indexed source line number. This line number is then written
|
|
108
143
|
# back into the `FunctionDefinition` struct alongside the originating filepath.
|
|
109
144
|
#
|
|
110
|
-
#
|
|
111
|
-
#
|
|
145
|
+
# An entry whose `code_block` the preprocessor output lacks is searched for in
|
|
146
|
+
# the original source. One found in neither gets a nil `line_num`.
|
|
112
147
|
#
|
|
113
148
|
# `source_filepath` is always updated.
|
|
114
149
|
#
|
|
115
|
-
# @param name [String]Name of the containing test, used to construct the path to
|
|
116
|
-
# the preprocessor expansion file for that test context.
|
|
117
150
|
# @param funcs [Array<FunctionDefinition>] Function definitions whose source
|
|
118
151
|
# locations are to be resolved. Matched entries are mutated in place.
|
|
119
152
|
# @param filepath [String] Path to the original C source file that was
|
|
120
153
|
# preprocessed, written into each matched FunctionDefinition as source_filepath.
|
|
121
|
-
# @param
|
|
122
|
-
#
|
|
123
|
-
def associate_function_line_numbers(
|
|
124
|
-
# File path of directives-only preprocessor output
|
|
125
|
-
preprocessed_filepath = @file_path_utils.form_preprocessed_file_raw_directives_only_filepath( filepath, name )
|
|
126
|
-
|
|
154
|
+
# @param raw_filepath [String, nil] The file's raw directives-only output. Without one, as
|
|
155
|
+
# in fallback, the original source is searched instead.
|
|
156
|
+
def associate_function_line_numbers(funcs:, filepath:, raw_filepath:)
|
|
127
157
|
@utils.stamp_source_filepaths( funcs, filepath )
|
|
128
158
|
|
|
129
|
-
|
|
159
|
+
# Every function is located with one read of each file searched
|
|
160
|
+
code_blocks = funcs.map( &:code_block )
|
|
161
|
+
if raw_filepath.nil?
|
|
130
162
|
msg = "Using fallback C function location search for #{filepath}"
|
|
131
163
|
@loginator.log( msg, Verbosity::OBNOXIOUS, LogLabels::WARNING )
|
|
132
164
|
|
|
133
|
-
|
|
134
|
-
func.line_num = @utils.locate_function_in_source(
|
|
135
|
-
code_block: func.code_block,
|
|
136
|
-
filepath: filepath
|
|
137
|
-
)
|
|
138
|
-
end
|
|
139
|
-
|
|
165
|
+
lines = @utils.locate_functions_in_source( code_blocks: code_blocks, filepath: filepath )
|
|
140
166
|
else
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
filepath: filepath,
|
|
146
|
-
preprocessed_filepath: preprocessed_filepath
|
|
147
|
-
)
|
|
148
|
-
end
|
|
167
|
+
# Searches the original source for any function the preprocessed copy lacks
|
|
168
|
+
lines = @utils.locate_functions_via_preprocessed(
|
|
169
|
+
code_blocks: code_blocks, filepath: filepath, preprocessed_filepath: raw_filepath
|
|
170
|
+
)
|
|
149
171
|
end
|
|
172
|
+
funcs.zip( lines ) { |func, line_num| func.line_num = line_num }
|
|
150
173
|
|
|
151
174
|
funcs.each do |func|
|
|
152
175
|
if func.line_num.nil?
|
|
@@ -159,8 +182,41 @@ class PartializerHelper
|
|
|
159
182
|
@loginator.log_list( @utils.format_line_number_list( funcs ), header, Verbosity::DEBUG )
|
|
160
183
|
end
|
|
161
184
|
|
|
162
|
-
#
|
|
163
|
-
#
|
|
185
|
+
# Record where each declaration sits in its original file.
|
|
186
|
+
#
|
|
187
|
+
# A carried prototype is written behind a #line naming this file and line, so a diagnostic
|
|
188
|
+
# points at the user's own declaration. Callers pass the file's text, read once per file. Its
|
|
189
|
+
# comments are blanked once for every declaration. A declaration that can't be found keeps no
|
|
190
|
+
# line and is written without a #line.
|
|
191
|
+
#
|
|
192
|
+
# @param decls [Array<CFunctionDeclaration>] Declarations extracted from one file, updated in place
|
|
193
|
+
# @param filepath [String] Path of the original header or source file
|
|
194
|
+
# @param text [String] That file's full text
|
|
195
|
+
def associate_declaration_line_numbers(decls:, filepath:, text:)
|
|
196
|
+
lines = @utils.locate_declarations_in_text( signatures: decls.map( &:signature ), text: text )
|
|
197
|
+
|
|
198
|
+
decls.zip( lines ) do |decl, line_num|
|
|
199
|
+
decl.source_filepath = filepath
|
|
200
|
+
decl.line_num = line_num
|
|
201
|
+
end
|
|
202
|
+
end
|
|
203
|
+
|
|
204
|
+
# Promotes each function's statics to module scope, where the generated files can reach them
|
|
205
|
+
# (see extract_function_scope_static_vars). Each function's promoted items join the module
|
|
206
|
+
# just ahead of the function, a type a statement defines ahead of that statement's variables.
|
|
207
|
+
def promote_function_scope_statics(c_module, name:, module_name:, file_type:)
|
|
208
|
+
c_module.function_definitions.each do |func|
|
|
209
|
+
vars = extract_function_scope_static_vars( [func], name: name, module_name: module_name, file_type: file_type )
|
|
210
|
+
_add_promoted( c_module, func, vars ) unless vars.empty?
|
|
211
|
+
end
|
|
212
|
+
end
|
|
213
|
+
|
|
214
|
+
def _add_promoted(c_module, func, vars)
|
|
215
|
+
c_module.insert_before!( func, _with_defined_types( vars ) )
|
|
216
|
+
end
|
|
217
|
+
|
|
218
|
+
# Lifts function-scoped static variables out of function bodies, to be promoted to module
|
|
219
|
+
# scope.
|
|
164
220
|
#
|
|
165
221
|
# C functions may contain local `static` variable declarations. These variables have
|
|
166
222
|
# file-level storage duration but function-level scope. When generating partials, they
|
|
@@ -168,100 +224,177 @@ class PartializerHelper
|
|
|
168
224
|
# linker and coverage tooling see them correctly.
|
|
169
225
|
#
|
|
170
226
|
# For each function in `funcs`, this method:
|
|
171
|
-
# 1.
|
|
172
|
-
#
|
|
173
|
-
#
|
|
174
|
-
#
|
|
175
|
-
#
|
|
176
|
-
#
|
|
177
|
-
#
|
|
178
|
-
#
|
|
227
|
+
# 1. Reads the declarations that open the function's body, keeping each statement whose
|
|
228
|
+
# variables bear a private keyword (any of `CExtractorConstants::PRIVATE_KEYWORDS`,
|
|
229
|
+
# e.g. `static`). Reading stops at the first statement that declares nothing.
|
|
230
|
+
# 2. Puts one no-op per variable where each statement stood, followed by a comment holding
|
|
231
|
+
# the statement, so the function keeps its line count for coverage. Each statement is
|
|
232
|
+
# found by position, so its text needs no search.
|
|
233
|
+
# 3. Renames each promoted variable to `partial_<function>_<variable>` everywhere else in
|
|
234
|
+
# the function, so promoted variables of different functions can't collide.
|
|
235
|
+
# 4. Names a type a statement defines (see Partials.type_name). A tagged one takes that
|
|
236
|
+
# name as its tag too, since a tag local to the function may collide at module scope.
|
|
179
237
|
#
|
|
180
238
|
# @param funcs [Array<CFunctionDefinition>] Function definitions to scan. Each matched
|
|
181
239
|
# function's `code_block` and `body` fields are mutated in place.
|
|
182
240
|
# @param name [String] Test name, used in log messages.
|
|
183
|
-
# @param module_name [String] Module name,
|
|
241
|
+
# @param module_name [String] Module name, which names a promoted type and appears in log messages.
|
|
184
242
|
# @param file_type [String] "source" or "header", used in log messages.
|
|
185
243
|
#
|
|
186
244
|
# @return [Array<CVariableDeclaration>] All function-scoped static variable declarations
|
|
187
|
-
# found across all supplied functions, suitable for emission at module scope.
|
|
245
|
+
# found across all supplied functions, suitable for emission at module scope. A variable's
|
|
246
|
+
# `defined_type` holds a type its statement defines.
|
|
188
247
|
def extract_function_scope_static_vars(funcs, name:, module_name:, file_type:)
|
|
189
|
-
|
|
248
|
+
return funcs.flat_map do |func|
|
|
249
|
+
statements = _static_statements( func )
|
|
250
|
+
next [] if statements.empty?
|
|
190
251
|
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
func_body = func.body.dup
|
|
196
|
-
func_body.delete_prefix!( '{' )
|
|
197
|
-
func_body.delete_suffix!( '}' )
|
|
198
|
-
|
|
199
|
-
scanner = StringScanner.new( func_body )
|
|
200
|
-
_decls = []
|
|
201
|
-
|
|
202
|
-
loop do
|
|
203
|
-
# `try_extract_variable` returns an array of declarations.
|
|
204
|
-
# A compound declaration (e.g. int x, y) yields multiple declaration Structs
|
|
205
|
-
success, var_decls = @declaration_extractor.try_extract_variable( scanner )
|
|
206
|
-
break unless success
|
|
207
|
-
var_decls.each do |var|
|
|
208
|
-
if var.decorators.any? { |d| CExtractorConstants::PRIVATE_KEYWORDS.include?(d) }
|
|
209
|
-
_decls << var
|
|
210
|
-
end
|
|
211
|
-
end
|
|
212
|
-
end
|
|
252
|
+
_promote( func, statements, module_name ).each { |var| var.promoted_from = func.name }
|
|
253
|
+
.tap { |vars| _log_promoted( func, vars, "#{file_type} to be promoted for Partial #{name}::#{module_name}" ) }
|
|
254
|
+
end
|
|
255
|
+
end
|
|
213
256
|
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
# require different strategies to prevent the restored comment text from being found and
|
|
218
|
-
# corrupted by a subsequent replace call.
|
|
219
|
-
groups = _decls.group_by { |var| var.original.strip }
|
|
220
|
-
|
|
221
|
-
groups.each do |_original, vars|
|
|
222
|
-
# Pre-compute old/new names before any mutation of var.name
|
|
223
|
-
old_names = vars.map(&:name)
|
|
224
|
-
new_names = old_names.map { |n| "partial_#{func.name}_#{n}" }
|
|
225
|
-
|
|
226
|
-
# Single placeholder per group — keyed on the first variable's name
|
|
227
|
-
placeholder = "__CEEDLING_NOOP_#{func.name.upcase}_#{old_names.first.upcase}__"
|
|
228
|
-
|
|
229
|
-
# Replace original declaration: one no-op per variable, single comment with placeholder.
|
|
230
|
-
# Defer placeholder restoration until after ALL renames are complete so that
|
|
231
|
-
# restored comment text cannot be found and re-processed by a subsequent replace.
|
|
232
|
-
if vars.size > 1
|
|
233
|
-
func.code_block = @utils.replace_compound_declaration_with_noops( func.code_block, _original, placeholder, vars.size )
|
|
234
|
-
func.body = @utils.replace_compound_declaration_with_noops( func.body, _original, placeholder, vars.size )
|
|
235
|
-
else
|
|
236
|
-
func.code_block = @utils.replace_declaration_with_noop( func.code_block, _original, placeholder )
|
|
237
|
-
func.body = @utils.replace_declaration_with_noop( func.body, _original, placeholder )
|
|
238
|
-
end
|
|
257
|
+
def _log_promoted(func, vars, context)
|
|
258
|
+
@loginator.log_list( vars.map { |var| "`#{var.original.strip}`" }, "Function-scope static variables in #{func.name}() in #{context}:", Verbosity::OBNOXIOUS )
|
|
259
|
+
end
|
|
239
260
|
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
var.name = new_name
|
|
244
|
-
func.code_block = @utils.rename_c_identifier( func.code_block, old_name, new_name )
|
|
245
|
-
func.body = @utils.rename_c_identifier( func.body, old_name, new_name )
|
|
246
|
-
end
|
|
261
|
+
# A statement of a function's statics: where it sits in the function's code block, by byte,
|
|
262
|
+
# and the variables it declares
|
|
263
|
+
StaticStatement = Struct.new( :from, :to, :vars, keyword_init: true ) unless const_defined?(:StaticStatement, false)
|
|
247
264
|
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
265
|
+
# Space and comments ahead of a statement
|
|
266
|
+
DEADSPACE = %r{(?:\s|/\*.*?\*/|//[^\n]*)*}m unless const_defined?(:DEADSPACE, false)
|
|
267
|
+
|
|
268
|
+
# The statements opening a function's body that declare statics. A static the extractor read
|
|
269
|
+
# no name from, such as one a macro declares, can't be renamed. Its whole statement stays in
|
|
270
|
+
# the body, still a valid local, and nothing of it is promoted.
|
|
271
|
+
def _static_statements(func)
|
|
272
|
+
scanner = StringScanner.new( func.code_block ).tap { |opened| opened.pos = _body_start( func ) + 1 }
|
|
273
|
+
statements = []
|
|
274
|
+
loop do
|
|
275
|
+
scanner.skip( DEADSPACE )
|
|
276
|
+
from = scanner.pos
|
|
277
|
+
success, vars = @declaration_extractor.try_extract_variable( scanner )
|
|
278
|
+
break unless success
|
|
279
|
+
|
|
280
|
+
statements << StaticStatement.new( from: from, to: scanner.pos, vars: vars ) if _promotable?( vars )
|
|
281
|
+
end
|
|
282
|
+
|
|
283
|
+
return statements
|
|
284
|
+
end
|
|
285
|
+
|
|
286
|
+
def _body_start(func)
|
|
287
|
+
return CExtractorFunctions.body_start( func.code_block )
|
|
288
|
+
end
|
|
289
|
+
|
|
290
|
+
# The variables of one statement share its decorators
|
|
291
|
+
def _promotable?(vars)
|
|
292
|
+
return false unless vars.first.decorators.any? { |d| CExtractorConstants::PRIVATE_KEYWORDS.include?( d ) }
|
|
293
|
+
|
|
294
|
+
return vars.none? { |var| var.name.nil? }
|
|
295
|
+
end
|
|
296
|
+
|
|
297
|
+
# Promotes a function's statics under new names. Each variable's text, declarator and array
|
|
298
|
+
# size take every rename, because one static's initializer may name another, as in
|
|
299
|
+
# `static int a = 1, *p = &a;`. A struct or union body holding a renamed name renames its
|
|
300
|
+
# members alike wherever they're used (see Partials::Rename), and a promoted type's body
|
|
301
|
+
# counts, although it no longer sits in the function.
|
|
302
|
+
def _promote(func, statements, module_name)
|
|
303
|
+
vars = statements.flat_map( &:vars )
|
|
304
|
+
renames = vars.to_h { |var| [var.name, "partial_#{func.name}_#{var.name}"] }
|
|
305
|
+
types = _local_types( func, statements, module_name )
|
|
306
|
+
rename = _renamer( func, renames, types )
|
|
307
|
+
|
|
308
|
+
_rewrite_function( func, statements, rename )
|
|
309
|
+
_rename_promoted( types, vars, renames, rename )
|
|
310
|
+
|
|
311
|
+
return vars
|
|
312
|
+
end
|
|
313
|
+
|
|
314
|
+
# Each promoted type takes the renames in its body and its new tag, and each variable its name
|
|
315
|
+
def _rename_promoted(types, vars, renames, rename)
|
|
316
|
+
types.each { |type, tag| type.text, type.tag = rename.( type.text ), rename.tags.fetch( tag, tag ) }
|
|
317
|
+
vars.each { |var| _rename_variable( var, renames, rename ) }
|
|
318
|
+
end
|
|
252
319
|
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
320
|
+
# The function's code block with its statics' statements replaced and the rest renamed, and its
|
|
321
|
+
# body read from that code block as extraction reads one
|
|
322
|
+
def _rewrite_function(func, statements, rename)
|
|
323
|
+
func.code_block = _spliced( func.code_block, statements, rename )
|
|
324
|
+
func.body = _blanked( _between( func.code_block, _body_start( func ), func.code_block.bytesize ) )
|
|
325
|
+
end
|
|
259
326
|
|
|
260
|
-
|
|
327
|
+
# Renames text for one function's promotion. It knows the tags it renames, and the names the
|
|
328
|
+
# function's local bodies hold, its promoted types' included.
|
|
329
|
+
Renamer = Struct.new( :renames, :shared, :tags ) do
|
|
330
|
+
def call(text)
|
|
331
|
+
return text && Partials::Rename.identifiers( text, renames, shared: shared, tags: tags )
|
|
261
332
|
end
|
|
333
|
+
end unless const_defined?(:Renamer, false)
|
|
334
|
+
|
|
335
|
+
def _renamer(func, renames, types)
|
|
336
|
+
tags = types.filter_map { |type, tag| [tag, type.type_name] if tag }.to_h
|
|
337
|
+
bodies = [func.code_block, *types.keys.map( &:text )].join( "\n" )
|
|
338
|
+
return Renamer.new( renames, Partials::Rename.names_in_bodies( bodies, renames ), tags )
|
|
339
|
+
end
|
|
262
340
|
|
|
263
|
-
|
|
341
|
+
# A promoted variable's text, declarator and array size name it, and maybe another promoted one
|
|
342
|
+
def _rename_variable(var, renames, rename)
|
|
343
|
+
var.text, var.declarator, var.array_suffix = [var.text, var.declarator, var.array_suffix].map { |text| rename.( text ) }
|
|
344
|
+
var.name = renames[var.name]
|
|
264
345
|
end
|
|
346
|
+
|
|
347
|
+
# Each type a promoted statement defines, named for the statement's first variable, paired
|
|
348
|
+
# with its tag as written
|
|
349
|
+
def _local_types(func, statements, module_name)
|
|
350
|
+
return statements.filter_map do |statement|
|
|
351
|
+
type = statement.vars.first.defined_type
|
|
352
|
+
next unless type
|
|
353
|
+
|
|
354
|
+
type.type_name = Partials.type_name( module_name, func.name, statement.vars.first.name )
|
|
355
|
+
[type, type.tag]
|
|
356
|
+
end.to_h
|
|
357
|
+
end
|
|
358
|
+
|
|
359
|
+
# The code block with each statement replaced by its no-ops and the text around them renamed
|
|
360
|
+
def _spliced(text, statements, rename)
|
|
361
|
+
spliced = +''
|
|
362
|
+
at = statements.reduce( 0 ) do |from, statement|
|
|
363
|
+
spliced << rename.( _between( text, from, statement.from ) ) << _noops( text, statement )
|
|
364
|
+
statement.to
|
|
365
|
+
end
|
|
366
|
+
|
|
367
|
+
return spliced << rename.( _between( text, at, text.bytesize ) )
|
|
368
|
+
end
|
|
369
|
+
|
|
370
|
+
def _between(text, from, to)
|
|
371
|
+
return text.byteslice( from, to - from )
|
|
372
|
+
end
|
|
373
|
+
|
|
374
|
+
# One no-op per variable, the last followed by a comment holding the statement
|
|
375
|
+
def _noops(text, statement)
|
|
376
|
+
written = _commented( _between( text, statement.from, statement.to ) )
|
|
377
|
+
return "#{'(void)0; ' * (statement.vars.size - 1)}(void)0; /* `#{written}` replaced with no-op plus variable renamed & promoted to module-scope */"
|
|
378
|
+
end
|
|
379
|
+
|
|
380
|
+
# A statement as a comment can hold it. Its own comments become spaces, keeping their line
|
|
381
|
+
# breaks as written, so the function's line count holds, and a `*/` in a literal can't close
|
|
382
|
+
# the comment.
|
|
383
|
+
def _commented(text)
|
|
384
|
+
return text.gsub( Partials::LITERAL_OR_COMMENT ) { |found| found.start_with?( '/' ) ? found.gsub( /[^\r\n]/, ' ' ) : found }.gsub( '*/', '* /' )
|
|
385
|
+
end
|
|
386
|
+
|
|
387
|
+
# A function body with its comments blanked to a space each, as extraction reads one
|
|
388
|
+
def _blanked(body)
|
|
389
|
+
return body.gsub( Partials::LITERAL_OR_COMMENT ) { |found| found.start_with?( '/' ) ? ' ' : found }
|
|
390
|
+
end
|
|
391
|
+
|
|
392
|
+
# The variables, each statement's type ahead of the first of them
|
|
393
|
+
def _with_defined_types(vars)
|
|
394
|
+
seen = Set.new.compare_by_identity
|
|
395
|
+
return vars.flat_map { |var| (var.defined_type and seen.add?( var.defined_type )) ? [var.defined_type, var] : [var] }
|
|
396
|
+
end
|
|
397
|
+
|
|
265
398
|
# Refuses a module whose shape fallback preprocessing cannot resolve.
|
|
266
399
|
#
|
|
267
400
|
# Fallback never runs a compiler. It scans text and tracks a handful of conditional shapes
|
|
@@ -324,52 +457,609 @@ class PartializerHelper
|
|
|
324
457
|
end
|
|
325
458
|
|
|
326
459
|
|
|
327
|
-
#
|
|
328
|
-
#
|
|
329
|
-
#
|
|
330
|
-
# from the directives-only extraction so that line number mapping stays valid.
|
|
460
|
+
# Marks each declaration whose function the text defines inline with external linkage. Given
|
|
461
|
+
# a file's raw directives-only copy, which holds every header the file includes, a mark means
|
|
462
|
+
# the declaring file holds the function's external definition under C99.
|
|
331
463
|
#
|
|
332
|
-
# @param
|
|
333
|
-
# @param
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
464
|
+
# @param decls [Array<CExtractorTypes::CFunctionDeclaration>] The file's declarations of functions the module never defines, decorators reconciled
|
|
465
|
+
# @param text [String] The file's raw directives-only copy, read as bytes
|
|
466
|
+
def mark_inline_elsewhere(decls:, text:)
|
|
467
|
+
defined = _inline_definitions( text, Set.new( decls.map( &:name ) ) )
|
|
468
|
+
|
|
469
|
+
decls.each do |decl|
|
|
470
|
+
decl.inline_elsewhere = (!Partials.static?( decl.decorators ) and defined.include?( decl.name ))
|
|
471
|
+
end
|
|
472
|
+
end
|
|
473
|
+
|
|
474
|
+
# Decide what a Partial's implementation source carries beyond its selected functions.
|
|
475
|
+
#
|
|
476
|
+
# A module's code relies on more than the functions a test selects. It uses functions defined
|
|
477
|
+
# elsewhere through prototypes, and small static or inline helpers its header defines. Each
|
|
478
|
+
# function name falls into one category.
|
|
479
|
+
# - Selected to test or to mock. Nothing is carried.
|
|
480
|
+
# - External, declared but defined nowhere in the module. Its prototypes that are not
|
|
481
|
+
# static, when kept code uses the name. A prototype of an inline function another header
|
|
482
|
+
# defines always, since it makes this file hold the function's external definition.
|
|
483
|
+
# - A header helper, a static or inline body in the header. The body and its prototypes,
|
|
484
|
+
# when kept code uses it.
|
|
485
|
+
# - Left out, any other unselected body. Its prototypes that are neither static nor
|
|
486
|
+
# inline, when kept code uses the name.
|
|
487
|
+
#
|
|
488
|
+
# The result is pure data. The generator writes it into the implementation source after
|
|
489
|
+
# every include, where each carried item can see everything the module's code saw.
|
|
490
|
+
#
|
|
491
|
+
# @param c_module [CExtractorTypes::CModule] Merged module with origins and reconciled decorators
|
|
492
|
+
# @param impl [Array<Partials::FunctionDefinition>] Functions selected to test
|
|
493
|
+
# @param interface [Array<Partials::FunctionDeclaration>, nil] Functions selected to mock
|
|
494
|
+
# @param fallback [Boolean] Whether fallback preprocessing produced the module's copies
|
|
495
|
+
# @param header_guarded [Boolean] Whether the module header has an include guard to stand in for
|
|
496
|
+
# @return [Partials::CarryPlan]
|
|
497
|
+
def plan_carry(c_module:, impl:, interface:, fallback:, header_guarded:)
|
|
498
|
+
facts = _carry_facts( c_module, impl, interface )
|
|
499
|
+
plan = Partials::CarryPlan.new
|
|
500
|
+
|
|
501
|
+
scan = CarryScan.new( plan: plan, declared: facts.declared, fallback: fallback, header_guarded: header_guarded )
|
|
502
|
+
references = _plan_helpers( scan, c_module, impl, facts.helpers )
|
|
503
|
+
|
|
504
|
+
_plan_all_prototypes( plan, facts, fallback, references )
|
|
505
|
+
|
|
506
|
+
return plan
|
|
507
|
+
end
|
|
508
|
+
|
|
509
|
+
# What a mock-only Partial's extras header keeps of the module's header beyond the mocked
|
|
510
|
+
# functions. The interface header stands in for the real header wherever generated code
|
|
511
|
+
# includes it, so whatever else the real header supplied has to come along:
|
|
512
|
+
# - each header helper the mock leaves out, written as it is, with its prototypes and the
|
|
513
|
+
# statics promoted from it;
|
|
514
|
+
# - the header's static variables, which keep `static`, and its extern declarations;
|
|
515
|
+
# - the header's plain prototypes of functions the mock leaves out, which a caller may need.
|
|
516
|
+
#
|
|
517
|
+
# The extras compile and link in every file of the test that includes the interface, so:
|
|
518
|
+
# - nothing from the source comes along, nor a definition without `static`, which each of
|
|
519
|
+
# those files would define again;
|
|
520
|
+
# - nor a static or inline prototype of a function with no helper body here;
|
|
521
|
+
# - nor a prototype a function-like macro of its name rewrites, since calls use the macro;
|
|
522
|
+
# - fallback's duplicates come along once when alike and not at all when they differ;
|
|
523
|
+
# - GCC emits an unused static variable or non-inline static function at -O0, so one
|
|
524
|
+
# naming a module function the mock leaves undefined stays behind, as does anything
|
|
525
|
+
# naming an item left behind (see _drop_unlinkable).
|
|
526
|
+
# A header without an include guard may still arrive through another include, so its helpers
|
|
527
|
+
# and static variables are withheld rather than copied.
|
|
528
|
+
#
|
|
529
|
+
# @return [Partials::InterfaceExtras]
|
|
530
|
+
def plan_interface_extras(c_module:, interface:, fallback:, header_guarded:)
|
|
531
|
+
scan = _extras_scan( c_module, Set.new( Array( interface ).map( &:name ) ), fallback )
|
|
532
|
+
extras = Partials::InterfaceExtras.new
|
|
533
|
+
|
|
534
|
+
_header_items( c_module ).each do |item|
|
|
535
|
+
_place_extra( extras, item, _extras_role( item, scan ), header_guarded )
|
|
536
|
+
end
|
|
537
|
+
|
|
538
|
+
return extras
|
|
539
|
+
end
|
|
540
|
+
|
|
541
|
+
# What deciding each header item's role consults
|
|
542
|
+
ExtrasScan = Struct.new( :selected, :helpers, :statics, :declared, :rewritten, :conflicting, keyword_init: true ) unless const_defined?(:ExtrasScan, false)
|
|
543
|
+
|
|
544
|
+
def _extras_scan(c_module, selected, fallback)
|
|
545
|
+
scan = ExtrasScan.new(
|
|
546
|
+
selected: selected, helpers: _interface_helpers( c_module, selected, fallback ), statics: _interface_statics( c_module, fallback ),
|
|
547
|
+
declared: Set.new, rewritten: _function_like_macros( c_module ), conflicting: _conflicting_prototypes( c_module, fallback )
|
|
548
|
+
)
|
|
549
|
+
_drop_unlinkable( c_module, scan, fallback )
|
|
550
|
+
|
|
551
|
+
return scan
|
|
552
|
+
end
|
|
553
|
+
|
|
554
|
+
# The names `text` uses as code, for a notice weighing what another Partial uses
|
|
555
|
+
def names_in(text)
|
|
556
|
+
return _statement_references( text )
|
|
557
|
+
end
|
|
558
|
+
|
|
559
|
+
def _header_items(c_module)
|
|
560
|
+
return c_module.element_sequence.select { |item| item.respond_to?( :origin ) and item.origin == :header }
|
|
561
|
+
end
|
|
562
|
+
|
|
563
|
+
def _place_extra(extras, item, role, header_guarded)
|
|
564
|
+
case role
|
|
565
|
+
when :copy then (header_guarded ? extras.items : extras.withheld) << item
|
|
566
|
+
when :follow then extras.items << item if header_guarded
|
|
567
|
+
when :declare then extras.items << item
|
|
568
|
+
end
|
|
569
|
+
end
|
|
570
|
+
|
|
571
|
+
# Each header helper the mock leaves out, by name, as its first definition
|
|
572
|
+
def _interface_helpers(c_module, selected, fallback)
|
|
573
|
+
helpers = c_module.function_definitions.group_by( &:name ).select do |name, defs|
|
|
574
|
+
!selected.include?( name ) and _kept_helper?( defs, fallback )
|
|
575
|
+
end
|
|
576
|
+
|
|
577
|
+
return helpers.transform_values( &:first )
|
|
578
|
+
end
|
|
579
|
+
|
|
580
|
+
# A helper fallback found with two different bodies stays behind, since either could be wrong
|
|
581
|
+
def _kept_helper?(defs, fallback)
|
|
582
|
+
return (_helper?( defs ) and !(fallback and _conflicting?( defs.map( &:code_block ) )))
|
|
583
|
+
end
|
|
584
|
+
|
|
585
|
+
# The header's own static variables, by identity. Every declaration comes along, since a
|
|
586
|
+
# tentative definition may precede the one that initializes it. Fallback keeps both sides of a
|
|
587
|
+
# conditional, so there a name's initialized copies come along once when alike and not at all
|
|
588
|
+
# when they differ.
|
|
589
|
+
def _interface_statics(c_module, fallback)
|
|
590
|
+
statics = c_module.variable_declarations.select { |var| _own_static?( var ) }
|
|
591
|
+
return Set.new.compare_by_identity.merge( statics ) unless fallback
|
|
592
|
+
|
|
593
|
+
kept = statics.group_by( &:name ).flat_map { |_, vars| _fallback_statics( vars ) }
|
|
594
|
+
return Set.new.compare_by_identity.merge( kept )
|
|
595
|
+
end
|
|
596
|
+
|
|
597
|
+
# A name's tentative definitions, with the first initialized one. Nothing when any two declare
|
|
598
|
+
# the name differently, initializers aside, or the initialized ones differ.
|
|
599
|
+
def _fallback_statics(vars)
|
|
600
|
+
initialized = vars.select { |var| _initialized?( var ) }
|
|
601
|
+
return [] if _redeclared?( vars, initialized )
|
|
602
|
+
|
|
603
|
+
return vars.reject { |var| _initialized?( var ) and !var.equal?( initialized.first ) }
|
|
604
|
+
end
|
|
605
|
+
|
|
606
|
+
def _initialized?(var)
|
|
607
|
+
return var.text.to_s.include?( '=' )
|
|
608
|
+
end
|
|
609
|
+
|
|
610
|
+
def _redeclared?(vars, initialized)
|
|
611
|
+
return (_conflicting?( vars.map { |var| _declared_as( var ) } ) or _conflicting?( initialized.map( &:text ) ))
|
|
612
|
+
end
|
|
613
|
+
|
|
614
|
+
# A variable's declaration without its initializer, as in "static const int x"
|
|
615
|
+
def _declared_as(var)
|
|
616
|
+
return "#{var.decorators.sort.join( ' ' )} #{var.text.to_s.sub( /\s*(?:=.*)?;\s*\z/m, '' )}"
|
|
617
|
+
end
|
|
618
|
+
|
|
619
|
+
# A static variable the header itself declares, not one promoted from a function
|
|
620
|
+
def _own_static?(var)
|
|
621
|
+
return (var.origin == :header and var.promoted_from.nil? and !var.extern? and var.decorators.include?( 'static' ))
|
|
622
|
+
end
|
|
623
|
+
|
|
624
|
+
# Narrows the helpers and statics to those every file including the extras can compile and
|
|
625
|
+
# link. GCC emits an unused static variable, promoted static or non-inline static function at
|
|
626
|
+
# -O0, so one naming a module function the mock leaves undefined stays behind. A static inline
|
|
627
|
+
# helper is never emitted unused, so that rule passes it by. Whatever names a function whose
|
|
628
|
+
# prototypes conflict stays behind, and so does whatever names an item left behind, since its
|
|
629
|
+
# text wouldn't compile. A worklist carries each item left behind to the items naming it, so
|
|
630
|
+
# each item's names are read once.
|
|
631
|
+
def _drop_unlinkable(c_module, scan, fallback)
|
|
632
|
+
candidates = scan.helpers.values + scan.statics.to_a + _promoted_statics( c_module, scan.helpers )
|
|
633
|
+
names = _candidate_names( c_module, candidates, fallback )
|
|
634
|
+
|
|
635
|
+
_walk_drops( _drops_alone( c_module, scan, candidates, names ), _referrers( names ), scan.helpers, scan.statics )
|
|
636
|
+
end
|
|
637
|
+
|
|
638
|
+
# The candidates that stay behind on their own names, before any other does
|
|
639
|
+
def _drops_alone(c_module, scan, candidates, names)
|
|
640
|
+
undefined = _function_names( c_module ) - scan.selected - scan.helpers.keys
|
|
641
|
+
return candidates.select { |item| _unlinkable_alone?( item, names[item], undefined, scan.conflicting ) }
|
|
642
|
+
end
|
|
643
|
+
|
|
644
|
+
# Leaves each queued item behind, then queues whatever names it. A promoted static left behind
|
|
645
|
+
# takes its function along.
|
|
646
|
+
def _walk_drops(queue, referrers, helpers, statics)
|
|
647
|
+
owners = helpers.dup
|
|
648
|
+
gone = Set.new.compare_by_identity
|
|
649
|
+
|
|
650
|
+
until queue.empty?
|
|
651
|
+
item = queue.shift
|
|
652
|
+
next unless gone.add?( item )
|
|
653
|
+
|
|
654
|
+
_forget( item, helpers, statics )
|
|
655
|
+
queue.concat( referrers.fetch( item.name, [] ) )
|
|
656
|
+
queue << owners[item.promoted_from] if item.respond_to?( :promoted_from ) and owners.key?( item.promoted_from )
|
|
657
|
+
end
|
|
658
|
+
end
|
|
659
|
+
|
|
660
|
+
def _promoted_statics(c_module, helpers)
|
|
661
|
+
return c_module.variable_declarations.select { |var| var.origin == :header and helpers.key?( var.promoted_from ) }
|
|
662
|
+
end
|
|
663
|
+
|
|
664
|
+
# Whether an item stays behind on its own names, before any other item does
|
|
665
|
+
def _unlinkable_alone?(item, names, undefined, conflicting)
|
|
666
|
+
return true if names.intersect?( conflicting )
|
|
667
|
+
|
|
668
|
+
emitted = !item.is_a?( CExtractorTypes::CFunctionDefinition ) || !Partials.inline?( item.decorators )
|
|
669
|
+
return (emitted and names.intersect?( undefined ))
|
|
670
|
+
end
|
|
671
|
+
|
|
672
|
+
# Each candidate's names as code, by identity, through the module's own macros. They come from
|
|
673
|
+
# its expansion where reconciliation found one, since the compiler reads that. Fallback may
|
|
674
|
+
# pair a variable with the other side of a conditional, or not at all, so there the written
|
|
675
|
+
# text counts too, and a doubtful item stays behind. Every name a body uses counts, its locals'
|
|
676
|
+
# too, since a wrong guess at a local could hide an item left behind.
|
|
677
|
+
def _candidate_names(c_module, candidates, fallback)
|
|
678
|
+
macros = _macro_names( c_module )
|
|
679
|
+
|
|
680
|
+
return candidates.each_with_object( {}.compare_by_identity ) do |item, names|
|
|
681
|
+
names[item] = _through_macros( _statement_references( _candidate_texts( item, fallback ).compact.join( "\n" ) ), macros )
|
|
682
|
+
end
|
|
683
|
+
end
|
|
684
|
+
|
|
685
|
+
def _candidate_texts(item, fallback)
|
|
686
|
+
texts = _written_and_expanded( item )
|
|
687
|
+
return fallback ? texts : [texts.last || texts.first]
|
|
688
|
+
end
|
|
689
|
+
|
|
690
|
+
def _written_and_expanded(item)
|
|
691
|
+
return [item.code_block, _scan_text( item )] if item.is_a?( CExtractorTypes::CFunctionDefinition )
|
|
692
|
+
|
|
693
|
+
return [item.text, item.expanded_text]
|
|
694
|
+
end
|
|
695
|
+
|
|
696
|
+
# Each macro's name, with the names its replacement uses
|
|
697
|
+
def _macro_names(c_module)
|
|
698
|
+
return c_module.macro_definitions.each_with_object( {} ) do |macro, names|
|
|
699
|
+
name, body = macro.text.match( /\A\s*#\s*define\s+([A-Za-z_]\w*)(?:\([^)]*\))?(.*)\z/m )&.captures
|
|
700
|
+
names[name] = _statement_references( body ) if name
|
|
701
|
+
end
|
|
702
|
+
end
|
|
703
|
+
|
|
704
|
+
def _through_macros(names, macros)
|
|
705
|
+
found = Set.new( names )
|
|
706
|
+
pending = names.select { |name| macros.key?( name ) }
|
|
707
|
+
|
|
708
|
+
until pending.empty?
|
|
709
|
+
macros.fetch( pending.shift ).each { |name| pending << name if found.add?( name ) and macros.key?( name ) }
|
|
710
|
+
end
|
|
711
|
+
|
|
712
|
+
return found
|
|
713
|
+
end
|
|
714
|
+
|
|
715
|
+
# Each name, with the candidates whose names include it
|
|
716
|
+
def _referrers(names)
|
|
717
|
+
return names.each_with_object( Hash.new { |index, name| index[name] = [] } ) do |(item, used), index|
|
|
718
|
+
used.each { |name| index[name] << item }
|
|
719
|
+
end
|
|
720
|
+
end
|
|
721
|
+
|
|
722
|
+
def _function_names(c_module)
|
|
723
|
+
return Set.new( (c_module.function_definitions + c_module.function_declarations).map( &:name ) )
|
|
724
|
+
end
|
|
725
|
+
|
|
726
|
+
def _forget(item, helpers, statics)
|
|
727
|
+
item.is_a?( CExtractorTypes::CFunctionDefinition ) ? helpers.delete( item.name ) : statics.delete( item )
|
|
728
|
+
end
|
|
729
|
+
|
|
730
|
+
# Names a function-like macro of the module defines
|
|
731
|
+
def _function_like_macros(c_module)
|
|
732
|
+
return Set.new( c_module.macro_definitions.filter_map { |macro| macro.text[/\A\s*#\s*define\s+([A-Za-z_]\w*)\(/, 1] } )
|
|
733
|
+
end
|
|
734
|
+
|
|
735
|
+
# Names fallback found with differing header prototypes
|
|
736
|
+
def _conflicting_prototypes(c_module, fallback)
|
|
737
|
+
return Set.new unless fallback
|
|
738
|
+
|
|
739
|
+
decls = c_module.function_declarations.select { |decl| decl.origin == :header }.group_by( &:name )
|
|
740
|
+
return Set.new( decls.select { |_, group| _conflicting?( group.map( &:signature_stripped ) ) }.keys )
|
|
741
|
+
end
|
|
742
|
+
|
|
743
|
+
# What the extras header does with one header item: :copy a helper or static variable,
|
|
744
|
+
# which an unguarded header withholds; :follow a helper with its prototype or promoted
|
|
745
|
+
# static; :declare an extern or a plain prototype; or nil to leave it out
|
|
746
|
+
def _extras_role(item, scan)
|
|
747
|
+
case item
|
|
748
|
+
when CExtractorTypes::CFunctionDefinition then return (scan.helpers[item.name].equal?( item ) ? :copy : nil)
|
|
749
|
+
when CExtractorTypes::CFunctionDeclaration then return _prototype_role( item, scan )
|
|
750
|
+
when CExtractorTypes::CVariableDeclaration then return _variable_role( item, scan )
|
|
751
|
+
end
|
|
752
|
+
|
|
753
|
+
return nil
|
|
754
|
+
end
|
|
755
|
+
|
|
756
|
+
def _prototype_role(decl, scan)
|
|
757
|
+
return :follow if scan.helpers.key?( decl.name )
|
|
758
|
+
return nil unless _plain_prototype?( decl, scan )
|
|
759
|
+
|
|
760
|
+
return scan.declared.add?( decl.name ) ? :declare : nil
|
|
761
|
+
end
|
|
762
|
+
|
|
763
|
+
# A prototype of a function with no helper here, which the mock leaves out and nothing rewrites
|
|
764
|
+
def _plain_prototype?(decl, scan)
|
|
765
|
+
return false if Partials.static?( decl.decorators ) or Partials.inline?( decl.decorators )
|
|
766
|
+
|
|
767
|
+
return [scan.selected, scan.rewritten, scan.conflicting].none? { |names| names.include?( decl.name ) }
|
|
768
|
+
end
|
|
769
|
+
|
|
770
|
+
def _variable_role(var, scan)
|
|
771
|
+
return (scan.helpers.key?( var.promoted_from ) ? :follow : nil) if var.promoted_from
|
|
772
|
+
return :declare if var.extern?
|
|
773
|
+
|
|
774
|
+
return scan.statics.include?( var ) ? :copy : nil
|
|
775
|
+
end
|
|
776
|
+
|
|
777
|
+
def _plan_all_prototypes(plan, facts, fallback, references)
|
|
778
|
+
facts.declared.each do |name, decls|
|
|
779
|
+
next unless _prototype_candidate?( facts, name )
|
|
780
|
+
|
|
781
|
+
_plan_prototypes(
|
|
782
|
+
plan, name, decls, has_body: facts.defined.key?( name ), fallback: fallback, referenced: references.include?( name )
|
|
783
|
+
)
|
|
784
|
+
end
|
|
785
|
+
end
|
|
786
|
+
|
|
787
|
+
# The names a plan decides by. They are the names the test selected, those with bodies,
|
|
788
|
+
# those with prototypes, and the unselected bodies that are header helpers.
|
|
789
|
+
def _carry_facts(c_module, impl, interface)
|
|
790
|
+
selected = Set.new( Array( impl ).map( &:name ) + Array( interface ).map( &:name ) )
|
|
791
|
+
defined = c_module.function_definitions.group_by( &:name )
|
|
792
|
+
|
|
793
|
+
return CarryFacts.new(
|
|
794
|
+
selected: selected,
|
|
795
|
+
defined: defined,
|
|
796
|
+
declared: c_module.function_declarations.group_by( &:name ),
|
|
797
|
+
helpers: defined.select { |name, defs| !selected.include?( name ) and _helper?( defs ) }
|
|
798
|
+
)
|
|
799
|
+
end
|
|
800
|
+
|
|
801
|
+
# A selected function is written as selected, and a helper's prototypes travel with its body
|
|
802
|
+
def _prototype_candidate?(facts, name)
|
|
803
|
+
return !(facts.selected.include?( name ) or facts.helpers.key?( name ))
|
|
804
|
+
end
|
|
805
|
+
|
|
806
|
+
def _plan_prototypes(plan, name, decls, has_body:, fallback:, referenced:)
|
|
807
|
+
keep = _carryable_prototypes( decls, has_body, referenced )
|
|
808
|
+
return if keep.empty?
|
|
809
|
+
|
|
810
|
+
# Fallback may keep both sides of a conditional, and two different types for one name won't compile
|
|
811
|
+
if fallback and _conflicting?( keep.map( &:signature_stripped ) )
|
|
812
|
+
plan.skip( name, :prototype_conflict )
|
|
813
|
+
return
|
|
814
|
+
end
|
|
815
|
+
|
|
816
|
+
reason = has_body ? 'left out: body not selected' : 'external: no body in module'
|
|
817
|
+
keep.each { |d| plan.add_prototype( d, reason ) }
|
|
818
|
+
end
|
|
819
|
+
|
|
820
|
+
# Never a static prototype. An inline prototype promises an inline body, and a left-out body
|
|
821
|
+
# isn't there. A prototype comes along when kept code uses the name. One for an inline body in
|
|
822
|
+
# another header comes along regardless, since it makes this file hold the external definition.
|
|
823
|
+
def _carryable_prototypes(decls, has_body, referenced)
|
|
824
|
+
keep = decls.reject { |d| Partials.static?( d.decorators ) or (has_body and Partials.inline?( d.decorators )) }
|
|
825
|
+
keep = keep.select { |d| !has_body and Partials.foreign_inline?( d ) } unless referenced
|
|
826
|
+
return _distinct( keep )
|
|
827
|
+
end
|
|
828
|
+
|
|
829
|
+
# Scans kept code for helper names, then each carried helper in turn, until nothing new is found.
|
|
830
|
+
# Only a referenced helper is carried, so carrying never forces unused code to compile.
|
|
831
|
+
# Returns every name the carried code references, which decides the prototypes it needs.
|
|
832
|
+
def _plan_helpers(scan, c_module, impl, helpers)
|
|
833
|
+
references = Set.new
|
|
834
|
+
pending = _kept_code( c_module, impl, scan.fallback )
|
|
835
|
+
handled = Set.new
|
|
836
|
+
|
|
837
|
+
until pending.empty?
|
|
838
|
+
referrer, names = pending.shift
|
|
839
|
+
references.merge( names )
|
|
840
|
+
pending.concat( _follow( scan, helpers, handled, referrer, names ) )
|
|
841
|
+
end
|
|
842
|
+
|
|
843
|
+
return references
|
|
844
|
+
end
|
|
845
|
+
|
|
846
|
+
# Carries each helper the names reach for the first time. Returns their bodies' references to scan next.
|
|
847
|
+
def _follow(scan, helpers, handled, referrer, names)
|
|
848
|
+
reached = helpers.select { |name, _| names.include?( name ) and !handled.include?( name ) }
|
|
849
|
+
|
|
850
|
+
return reached.filter_map do |name, defs|
|
|
851
|
+
handled << name
|
|
852
|
+
carried = _carry_helper( scan, name, defs, referrer )
|
|
853
|
+
[name, _body_references( carried )] if carried
|
|
854
|
+
end
|
|
855
|
+
end
|
|
856
|
+
|
|
857
|
+
# Carries one referenced helper, or records why it can't be. Returns the carried definition.
|
|
858
|
+
def _carry_helper(scan, name, defs, referrer)
|
|
859
|
+
return nil if _helper_blocked?( scan, name, defs )
|
|
346
860
|
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
861
|
+
helper = defs.first
|
|
862
|
+
scan.plan.add_helper( _as_written( helper ), "helper: referenced by `#{referrer}`" )
|
|
863
|
+
_distinct( scan.declared.fetch( name, [] ) ).each do |d|
|
|
864
|
+
scan.plan.add_prototype( d, "prototype of helper `#{name}`" )
|
|
351
865
|
end
|
|
352
866
|
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
867
|
+
return helper
|
|
868
|
+
end
|
|
869
|
+
|
|
870
|
+
# A helper stays behind when its header can't be stood in for, or when fallback left two bodies
|
|
871
|
+
def _helper_blocked?(scan, name, defs)
|
|
872
|
+
# Without a guard the real header may arrive through another include, and its copy would collide
|
|
873
|
+
unless scan.header_guarded
|
|
874
|
+
scan.plan.skip( name, :unguarded_helper )
|
|
875
|
+
return true
|
|
876
|
+
end
|
|
877
|
+
return false unless scan.fallback and _conflicting?( defs.map( &:code_block ) )
|
|
878
|
+
|
|
879
|
+
scan.plan.skip( name, :helper_conflict )
|
|
880
|
+
return true
|
|
881
|
+
end
|
|
882
|
+
|
|
883
|
+
# Built from the helper's own text, with any function-scope static promoted. Transforming it
|
|
884
|
+
# would strip `static inline` and give the helper external linkage it never had.
|
|
885
|
+
def _as_written(helper)
|
|
886
|
+
return Partials.manufacture_function_definition(
|
|
887
|
+
name: helper.name, signature: helper.signature, code_block: helper.code_block,
|
|
888
|
+
source_filepath: helper.source_filepath, line_num: helper.line_num
|
|
889
|
+
)
|
|
890
|
+
end
|
|
891
|
+
|
|
892
|
+
# Everything the implementation source compiles that could use a function, as
|
|
893
|
+
# [referrer, Set of referenced names] pairs
|
|
894
|
+
def _kept_code(c_module, impl, fallback)
|
|
895
|
+
statements = _kept_statements( c_module, fallback ).map { |referrer, text| [referrer, _statement_references( text )] }
|
|
896
|
+
return _kept_bodies( c_module, impl ) + statements
|
|
897
|
+
end
|
|
898
|
+
|
|
899
|
+
def _kept_bodies(c_module, impl)
|
|
900
|
+
defined = c_module.function_definitions.to_h { |f| [f.name, f] }
|
|
901
|
+
return Array( impl ).map { |f| [f.name, _body_references( defined.fetch( f.name ) )] }
|
|
902
|
+
end
|
|
903
|
+
|
|
904
|
+
# Variables and macro invocations the implementation source writes. Fallback can't expand
|
|
905
|
+
# macros reliably, so there a macro definition's text counts too.
|
|
906
|
+
def _kept_statements(c_module, fallback)
|
|
907
|
+
variables = c_module.variable_declarations.reject( &:extern? )
|
|
908
|
+
macros = c_module.macro_invocations + (fallback ? c_module.macro_definitions : [])
|
|
909
|
+
|
|
910
|
+
return variables.map { |v| [v.name, v.text] } + macros.map { |m| [m.text.strip, m.text] }
|
|
911
|
+
end
|
|
912
|
+
|
|
913
|
+
# The names a definition's body uses. Its own parameters and local variables only share a
|
|
914
|
+
# name with any function, so they don't count.
|
|
915
|
+
def _body_references(definition)
|
|
916
|
+
code = _blank_non_code( _scan_text( definition ) )
|
|
917
|
+
return _identifiers( code ) - _locals( code ) - _parameters( definition )
|
|
918
|
+
end
|
|
919
|
+
|
|
920
|
+
# The names a variable initializer or macro invocation uses
|
|
921
|
+
def _statement_references(text)
|
|
922
|
+
return _identifiers( _blank_non_code( text.to_s ) )
|
|
923
|
+
end
|
|
924
|
+
|
|
925
|
+
def _identifiers(code)
|
|
926
|
+
return Set.new( code.gsub( C_MEMBER_ACCESS, ' ' ).gsub( C_TAG, ' ' ).scan( C_IDENTIFIER ) )
|
|
927
|
+
end
|
|
928
|
+
|
|
929
|
+
def _locals(code)
|
|
930
|
+
return code.scan( C_LOCAL_DECLARATION ).filter_map { |type, name| name unless C_STATEMENT_KEYWORDS.include?( type ) }
|
|
931
|
+
end
|
|
932
|
+
|
|
933
|
+
# Every name in a definition's parameter list. Type names come along too, and those are never
|
|
934
|
+
# function names, so taking them all away removes just the parameters.
|
|
935
|
+
def _parameters(definition)
|
|
936
|
+
signature = definition.signature.to_s
|
|
937
|
+
start = CExtractorFunctions.name_position( signature, definition.name.to_s )
|
|
938
|
+
return [] if start.nil?
|
|
939
|
+
|
|
940
|
+
return _parenthesized( signature, signature.index( '(', start ) ).scan( C_IDENTIFIER )
|
|
941
|
+
end
|
|
942
|
+
|
|
943
|
+
# The text from the parenthesis at `open` through the one that closes it
|
|
944
|
+
def _parenthesized(text, open)
|
|
945
|
+
steps = { '(' => 1, ')' => -1 }
|
|
946
|
+
depth = 0
|
|
947
|
+
close = (open...text.length).find { |i| (depth += steps.fetch( text[i], 0 )).zero? }
|
|
948
|
+
|
|
949
|
+
return text[open..close].to_s
|
|
950
|
+
end
|
|
951
|
+
|
|
952
|
+
def _conflicting?(texts)
|
|
953
|
+
return texts.map { |t| _normalized( t ) }.uniq.size > 1
|
|
954
|
+
end
|
|
955
|
+
|
|
956
|
+
# A body as the compiler sees it when the expanded copy has one
|
|
957
|
+
def _scan_text(definition)
|
|
958
|
+
return (definition.expanded_body || definition.body || definition.code_block).to_s
|
|
959
|
+
end
|
|
960
|
+
|
|
961
|
+
# Literals and comments become spaces, newlines kept. Neither can use a function however it reads.
|
|
962
|
+
def _blank_non_code(text)
|
|
963
|
+
return text.gsub( Partials::LITERAL_OR_COMMENT ) { |blanked| blanked.gsub( /[^\n]/, ' ' ) }
|
|
964
|
+
end
|
|
965
|
+
|
|
966
|
+
# The wanted names the text defines inline with external linkage, found in one pass. The text
|
|
967
|
+
# breaks into runs at each `;` and brace. A run that ends in a parameter list just before a `{`
|
|
968
|
+
# opens a definition. Each wanted name opening a parameter list there is judged by the words
|
|
969
|
+
# ahead of it. One pass keeps the cost linear in a raw copy that holds every header the file
|
|
970
|
+
# includes, however many names are wanted.
|
|
971
|
+
def _inline_definitions(text, wanted)
|
|
972
|
+
found = Set.new
|
|
973
|
+
scanner = StringScanner.new( text )
|
|
974
|
+
start = 0
|
|
975
|
+
|
|
976
|
+
# Scanner positions count bytes, so each run is cut out by bytes
|
|
977
|
+
while scanner.skip_until( /[;{}]/ )
|
|
978
|
+
_definition_names( text.byteslice( start...(scanner.pos - 1) ), wanted, found ) if text.getbyte( scanner.pos - 1 ) == OPEN_BRACE
|
|
979
|
+
start = scanner.pos
|
|
980
|
+
end
|
|
981
|
+
|
|
982
|
+
return found
|
|
983
|
+
end
|
|
984
|
+
|
|
985
|
+
# Adds each wanted name the run defines inline with external linkage. A name counts when the
|
|
986
|
+
# words ahead of it in the run hold an inline specifier and no `static`. Words on a directive
|
|
987
|
+
# line never count. One walk carries what the words so far have said, so a run that mentions
|
|
988
|
+
# many names stays linear.
|
|
989
|
+
def _definition_names(run, wanted, found)
|
|
990
|
+
# Every inline specifier spells `inline`, so a run without it is passed over
|
|
991
|
+
return unless run.include?( 'inline' ) and run.match?( /\)\s*\z/ )
|
|
992
|
+
|
|
993
|
+
scanner = StringScanner.new( run )
|
|
994
|
+
walk = DefinitionWalk.new( directive: _directive_line?( scanner ), inline: false, static: false )
|
|
995
|
+
_walk_word( walk, scanner, wanted, found ) while scanner.skip_until( /\n|[\w$]+/ )
|
|
996
|
+
end
|
|
997
|
+
|
|
998
|
+
# One word of a run, or the newline that starts its next line
|
|
999
|
+
def _walk_word(walk, scanner, wanted, found)
|
|
1000
|
+
word = scanner.matched
|
|
1001
|
+
if word == "\n"
|
|
1002
|
+
walk.directive = _directive_line?( scanner )
|
|
1003
|
+
return
|
|
1004
|
+
end
|
|
1005
|
+
|
|
1006
|
+
found << word if _defined_inline?( walk, scanner, wanted, word )
|
|
1007
|
+
return if walk.directive
|
|
1008
|
+
|
|
1009
|
+
walk.inline ||= Partials.inline?( [word] )
|
|
1010
|
+
walk.static ||= Partials.static?( [word] )
|
|
1011
|
+
end
|
|
1012
|
+
|
|
1013
|
+
# A wanted name opening a parameter list, after words that made the definition inline and not static
|
|
1014
|
+
def _defined_inline?(walk, scanner, wanted, word)
|
|
1015
|
+
return (walk.inline and !walk.static and wanted.include?( word ) and scanner.match?( /\s*\(/ ))
|
|
1016
|
+
end
|
|
1017
|
+
|
|
1018
|
+
def _directive_line?(scanner)
|
|
1019
|
+
return !scanner.match?( DIRECTIVE_START ).nil?
|
|
1020
|
+
end
|
|
1021
|
+
|
|
1022
|
+
def _helper?(definitions)
|
|
1023
|
+
return definitions.all? do |f|
|
|
1024
|
+
f.origin == :header and (Partials.static?( f.decorators ) or Partials.inline?( f.decorators ))
|
|
1025
|
+
end
|
|
1026
|
+
end
|
|
1027
|
+
|
|
1028
|
+
# One of each prototype, comparing text with whitespace collapsed
|
|
1029
|
+
def _distinct(decls)
|
|
1030
|
+
return decls.uniq { |d| _normalized( d.signature ) }
|
|
1031
|
+
end
|
|
1032
|
+
|
|
1033
|
+
def _normalized(text)
|
|
1034
|
+
return text.to_s.gsub( /\s+/, ' ' ).strip
|
|
1035
|
+
end
|
|
1036
|
+
|
|
1037
|
+
# Stops the build on a definition the extractor read no name from. Every later step finds a
|
|
1038
|
+
# definition by its name. A declaration needs none, since it is written word for word and CMock
|
|
1039
|
+
# reads its own. Extraction reads raw bytes, so the signature is made printable first.
|
|
1040
|
+
def validate_function_names_readable(c_module, name, module_name)
|
|
1041
|
+
unnamed = c_module.function_definitions.find { |func| func.name.nil? }
|
|
1042
|
+
return if unnamed.nil?
|
|
1043
|
+
|
|
1044
|
+
signature = _normalized( unnamed.signature ).dup.force_encoding( Encoding::UTF_8 ).scrub( '?' )
|
|
1045
|
+
raise CeedlingException.new( format( UNREADABLE_NAME_ERROR, partial: "#{name}::#{module_name}", declaration: signature ) )
|
|
358
1046
|
end
|
|
359
1047
|
|
|
360
1048
|
# Validate that every function name in additions and subtractions exists in c_module.
|
|
361
1049
|
# Case-sensitive match; if a name matches case-insensitively but not exactly, raise
|
|
362
|
-
# a specific case-mismatch exception.
|
|
1050
|
+
# a specific case-mismatch exception. A Test Partial carries only the functions its
|
|
1051
|
+
# module defines. A mock also names the functions the module declares, since a mock of
|
|
1052
|
+
# public functions alone reads only the header.
|
|
363
1053
|
def validate_function_names_exist(c_module, config, name)
|
|
364
|
-
|
|
365
|
-
known_lower = Set.new( c_module.function_definitions.map { |f| f.name.downcase } )
|
|
366
|
-
mod = config.module
|
|
1054
|
+
mod = config.module
|
|
367
1055
|
|
|
368
1056
|
{TEST: config.tests, MOCK: config.mocks}.each do |label, pf|
|
|
1057
|
+
known = configurable_functions( c_module, label == :MOCK ).keys
|
|
1058
|
+
|
|
369
1059
|
(pf.additions + pf.subtractions).each do |func_name|
|
|
370
|
-
next if
|
|
1060
|
+
next if known.include?(func_name)
|
|
371
1061
|
|
|
372
|
-
if
|
|
1062
|
+
if known.any? { |known_name| known_name.casecmp?( func_name ) }
|
|
373
1063
|
raise CeedlingException.new(
|
|
374
1064
|
"#{name}: #{label} Partial configuration for module '#{mod}' references function '#{func_name}' " \
|
|
375
1065
|
"which differs only by case from a real function name"
|
|
@@ -383,6 +1073,21 @@ class PartializerHelper
|
|
|
383
1073
|
end
|
|
384
1074
|
end
|
|
385
1075
|
|
|
1076
|
+
# The functions a Partial configuration can name, by name. A mock can also name what the
|
|
1077
|
+
# module only declares, as mock selection reads it (Partializer#_mock_candidates), less an
|
|
1078
|
+
# inline function whose body is in another header, which no mock can replace. A definition
|
|
1079
|
+
# takes the place of a same-named declaration.
|
|
1080
|
+
def configurable_functions(c_module, mock)
|
|
1081
|
+
functions = {}
|
|
1082
|
+
if mock
|
|
1083
|
+
(c_module.function_declarations || []).each do |decl|
|
|
1084
|
+
functions[decl.name] = decl if decl.name and !Partials.foreign_inline?( decl )
|
|
1085
|
+
end
|
|
1086
|
+
end
|
|
1087
|
+
c_module.function_definitions.each { |func| functions[func.name] = func }
|
|
1088
|
+
return functions
|
|
1089
|
+
end
|
|
1090
|
+
|
|
386
1091
|
# Validate that no function name appears in both additions and subtractions of the
|
|
387
1092
|
# same tests or mocks entry.
|
|
388
1093
|
def validate_no_additions_subtractions_overlap(config, name)
|
|
@@ -406,12 +1111,13 @@ class PartializerHelper
|
|
|
406
1111
|
# Additions are not validated (same-visibility additions are redundant but harmless).
|
|
407
1112
|
# ACCUMULATE is skipped (no subtractions allowed, already enforced by extract_configs).
|
|
408
1113
|
def validate_additions_subtractions_visibility(c_module, config, name)
|
|
409
|
-
|
|
410
|
-
mod = config.module
|
|
1114
|
+
mod = config.module
|
|
411
1115
|
|
|
412
1116
|
{tests: config.tests, mocks: config.mocks}.each do |label, pf|
|
|
413
1117
|
next unless pf.type == PUBLIC || pf.type == PRIVATE
|
|
414
1118
|
|
|
1119
|
+
func_map = configurable_functions( c_module, label == :mocks )
|
|
1120
|
+
|
|
415
1121
|
subtraction_required_visibility = pf.type
|
|
416
1122
|
|
|
417
1123
|
pf.subtractions.each do |func_name|
|