ceedling 1.2.1 → 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 +11 -9
- data/Rakefile +2 -1
- data/assets/features/ceedling +1 -1
- data/assets/fixtures/test_source_file_duplicate_basenames/test_calc_typo.c +14 -0
- data/assets/fixtures/tests_with_duplicate_test_names/test_foo.c +21 -0
- 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/bin/actionator.rb +6 -12
- data/bin/app_cfg.rb +14 -1
- data/bin/ceedling +13 -3
- data/bin/cli.rb +25 -6
- data/bin/cli_handler.rb +113 -73
- data/bin/cli_helper.rb +51 -78
- data/bin/installation_selector.rb +81 -0
- data/bin/launchinator.rb +69 -0
- data/bin/mixin_resolvinator.rb +26 -36
- data/bin/objects.yml +13 -0
- data/bin/path_validator.rb +25 -29
- data/bin/versionator.rb +47 -48
- data/ceedling.gemspec +19 -15
- data/docs/BreakingChanges.md +86 -1
- data/docs/Changelog.md +145 -3
- data/docs/KnownIssues.md +179 -6
- data/docs/ReleaseNotes.md +13 -0
- 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/build_log_writer.rb +33 -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/build_root_policy.rb +70 -0
- data/lib/ceedling/config/configurator.rb +18 -19
- data/lib/ceedling/config/configurator_builder.rb +75 -28
- data/lib/ceedling/config/configurator_paths_validator.rb +179 -0
- data/lib/ceedling/config/configurator_plugins.rb +1 -1
- data/lib/ceedling/config/configurator_setup.rb +44 -33
- data/lib/ceedling/config/configurator_validator.rb +1 -110
- data/lib/ceedling/constants.rb +5 -1
- data/lib/ceedling/defaults.rb +35 -5
- data/lib/ceedling/dependencies/CACHE_SCHEMA.md +118 -0
- data/lib/ceedling/dependencies/README.md +18 -16
- data/lib/ceedling/dependencies/dependency_cache_store.rb +43 -21
- data/lib/ceedling/dependencies/dependency_hasher.rb +35 -1
- 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/filename_extension.rb +7 -1
- data/lib/ceedling/filesystem/FILE_TREE.md +253 -0
- data/lib/ceedling/filesystem/PATH_HANDLING.md +360 -0
- data/lib/ceedling/filesystem/README.md +46 -0
- data/lib/ceedling/filesystem/build_roots.rb +105 -0
- data/lib/ceedling/filesystem/build_subpath.rb +187 -0
- data/lib/ceedling/filesystem/destination_collision.rb +25 -0
- data/lib/ceedling/{file_finder.rb → filesystem/file_finder.rb} +177 -156
- data/lib/ceedling/filesystem/file_finder_helper.rb +154 -0
- data/lib/ceedling/filesystem/file_path_collection_utils.rb +183 -0
- data/lib/ceedling/{file_path_utils.rb → filesystem/file_path_utils.rb} +200 -167
- data/lib/ceedling/{file_system_wrapper.rb → filesystem/file_system_wrapper.rb} +6 -5
- data/lib/ceedling/filesystem/file_tree.rb +241 -0
- data/lib/ceedling/{file_wrapper.rb → filesystem/file_wrapper.rb} +149 -65
- data/lib/ceedling/filesystem/path_exclusions.rb +30 -0
- data/lib/ceedling/{path_matcher.rb → filesystem/path_matcher.rb} +48 -23
- data/lib/ceedling/{path_mirror.rb → filesystem/path_mirror.rb} +19 -18
- data/lib/ceedling/filesystem/path_spellings.rb +55 -0
- data/lib/ceedling/filesystem/project_paths.rb +184 -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/filesystem/working_dir.rb +40 -0
- data/lib/ceedling/generators/generator.rb +32 -70
- 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 +306 -244
- data/lib/ceedling/generators/generator_test_results_backtrace.rb +7 -7
- 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/handoff.rb +121 -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 +112 -33
- data/lib/ceedling/includes/includes.rb +150 -38
- data/lib/ceedling/installation.rb +92 -0
- data/lib/ceedling/library_resolver.rb +99 -0
- data/lib/ceedling/objects.yml +112 -6
- 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 +603 -124
- data/lib/ceedling/partials/partializer_config.rb +8 -1
- 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/plugins/report_log_writer_plugin.rb +3 -5
- 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 +32 -76
- data/lib/ceedling/preprocess/preprocessinator_includes_handler.rb +1 -1
- data/lib/ceedling/preprocess/preprocessinator_line_marker_includes_extractor.rb +1 -1
- data/lib/ceedling/preprocess/preprocessinator_reconstructor.rb +51 -14
- data/lib/ceedling/rake_app/rakefile_component_resolver.rb +10 -17
- data/lib/ceedling/rakefile.rb +15 -1
- data/lib/ceedling/rakefiles/base/tasks_base.rake +1 -1
- data/lib/ceedling/rakefiles/release/rules_release.rake +4 -7
- data/lib/ceedling/release_invoker/release_build_executor.rb +33 -44
- data/lib/ceedling/release_invoker/release_build_planner.rb +14 -6
- data/lib/ceedling/reportinator.rb +3 -4
- data/lib/ceedling/setupinator.rb +104 -87
- data/lib/ceedling/test_context_extractor.rb +5 -1
- data/lib/ceedling/test_invoker/HEADER_COLLISIONS.md +21 -7
- data/lib/ceedling/test_invoker/PIPELINE.md +62 -19
- 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 +175 -10
- data/lib/ceedling/test_invoker/partial_files_preprocessinator.rb +181 -0
- data/lib/ceedling/test_invoker/partials_manager.rb +271 -302
- data/lib/ceedling/test_invoker/standin_headerinator.rb +19 -17
- data/lib/ceedling/test_invoker/test_bare_includes_extractinator.rb +26 -3
- data/lib/ceedling/test_invoker/test_build_executor.rb +358 -234
- data/lib/ceedling/test_invoker/test_build_planner.rb +46 -33
- data/lib/ceedling/test_invoker/test_build_setup.rb +43 -18
- data/lib/ceedling/test_invoker/test_build_validations.rb +35 -47
- data/lib/ceedling/test_invoker/test_derived_search_paths.rb +189 -0
- data/lib/ceedling/test_invoker/test_file_preprocessinator.rb +2 -3
- data/lib/ceedling/test_invoker/test_includes_reconcilinator.rb +1 -1
- data/lib/ceedling/test_invoker/test_invoker.rb +6 -1
- data/lib/ceedling/test_invoker/test_invoker_types.rb +28 -20
- data/lib/ceedling/test_invoker/test_pipeline_helpers.rb +6 -4
- 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_source_file_directive_resolver.rb +40 -20
- data/lib/ceedling/test_invoker/test_substitutions.rb +72 -0
- data/lib/ceedling/tools/shell_quoting.rb +45 -0
- data/lib/ceedling/{tool_executor.rb → tools/tool_executor.rb} +9 -3
- data/lib/ceedling/tools/tool_quoting.rb +79 -0
- data/lib/ceedling/{tool_validator.rb → tools/tool_validator.rb} +18 -7
- data/lib/ceedling/yaml_wrapper.rb +3 -2
- data/lib/version.rb +1 -1
- data/plugins/bullseye/bullseye.rake +1 -3
- data/plugins/bullseye/config/defaults_bullseye.rb +1 -1
- data/plugins/bullseye/lib/bullseye.rb +24 -9
- data/plugins/command_hooks/lib/command_hooks.rb +1 -1
- data/plugins/cppcheck/config/defaults_cppcheck.rb +1 -1
- data/plugins/dependencies/config/defaults.yml +6 -6
- data/plugins/dependencies/dependencies.rake +4 -1
- data/plugins/dependencies/lib/dependencies.rb +18 -8
- data/plugins/dependencies/lib/dependency_spec.rb +17 -5
- data/plugins/fff/lib/fff.rb +79 -46
- data/plugins/fff/lib/fff_mock_generator.rb +12 -9
- data/plugins/fff/spec/fff_cmock_wrapper_spec.rb +262 -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/config/defaults_gcov.rb +1 -1
- data/plugins/gcov/lib/console_reportinator.rb +28 -36
- data/plugins/gcov/lib/gcov.rb +9 -2
- data/plugins/gcov/lib/gcovr_reportinator.rb +8 -40
- data/plugins/gcov/lib/gcovr_thresholds.rb +74 -0
- data/plugins/gcov/lib/reportgenerator_reportinator.rb +3 -2
- data/plugins/module_generator/lib/module_generator.rb +3 -3
- data/plugins/report_tests_teamcity_stdout/lib/report_tests_teamcity_stdout.rb +53 -80
- data/plugins/sanitize/lib/sanitize_records.rb +3 -6
- data/plugins/valgrind/lib/valgrind.rb +14 -7
- 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 +7 -3
- 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 +65 -12
- 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 +23 -5
- 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 +36 -8
- data/site-local/configuration/reference/plugins.html +2 -2
- data/site-local/configuration/reference/project.html +264 -12
- data/site-local/configuration/reference/release-build.html +4 -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 +58 -4
- data/site-local/configuration/reference/unity.html +2 -2
- data/site-local/configuration/which-ceedling.html +379 -19
- 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 +7 -3
- data/site-local/development/workflow.html +50 -45
- data/site-local/getting-started/builds.html +4 -2
- data/site-local/getting-started/command-line.html +58 -6
- 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 +8 -5
- data/site-local/plugins/fff.html +58 -13
- data/site-local/plugins/gcov/examples.html +2 -2
- data/site-local/plugins/gcov/gcovr.html +23 -14
- 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 +4 -3
- 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 +5 -3
- data/site-local/plugins/report-tests-teamcity-stdout.html +8 -5
- data/site-local/plugins/sanitize.html +9 -8
- data/site-local/plugins/valgrind.html +10 -9
- 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 +5 -2
- data/site-local/reference/build-directives.html +2 -2
- data/site-local/reference/command-line.html +11 -4
- 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/snapshot/plugins/bullseye/config/defaults_bullseye.rb +1 -1
- data/site-local/snapshot/plugins/gcov/config/defaults_gcov.rb +1 -1
- data/site-local/testing-guide/build-directives.html +2 -2
- data/site-local/testing-guide/conventions.html +113 -15
- 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/actionator_file_operations_spec.rb +91 -1
- data/spec/integration/build_step_doctor_spec.rb +270 -0
- data/spec/integration/c_extractor_composition_spec.rb +254 -4
- data/spec/integration/compile_commands_json_db_spec.rb +1 -1
- data/spec/integration/configurator_validation_spec.rb +1 -1
- data/spec/integration/dependencies/dependency_tracker_cache_hardening_spec.rb +26 -0
- data/spec/integration/dependencies/dependency_tracker_core_spec.rb +22 -0
- data/spec/integration/includes_extraction_spec.rb +27 -14
- data/spec/integration/launcher_handoff_spec.rb +297 -0
- data/spec/integration/mixin_loading_spec.rb +1 -1
- data/spec/integration/module_generator_spec.rb +3 -3
- data/spec/integration/nested_test_artifacts_spec.rb +99 -0
- 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 +33 -23
- data/spec/integration/partials_symbol_linkage_spec.rb +13 -0
- data/spec/integration/path_intake_scenarios_spec.rb +101 -0
- data/spec/integration/path_length_reporting_spec.rb +64 -0
- data/spec/integration/path_scenarios_spec.rb +399 -0
- data/spec/integration/quote_include_isolator_spec.rb +57 -1
- data/spec/integration/report_build_warnings_log_spec.rb +1 -1
- data/spec/integration/report_tests_log_factory_spec.rb +1 -1
- data/spec/integration/test_build_parallel_barrier_spec.rb +1 -1
- data/spec/integration/test_executable_manifest_spec.rb +1 -1
- data/spec/integration/test_includes_extractinator_spec.rb +69 -3
- data/spec/integration/test_naming_spec.rb +201 -0
- data/spec/integration/test_source_file_checks_spec.rb +168 -0
- data/spec/integration/tool_executor_spec.rb +1 -1
- data/spec/integration/tool_validator_spec.rb +3 -3
- data/spec/integration/upgrade_docs_spec.rb +84 -0
- data/spec/integration/vendor_copy_transient_io_retry_spec.rb +74 -5
- 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/file_tree_helper.rb +88 -0
- data/spec/support/integration/configurator_integration_helper.rb +14 -9
- data/spec/support/integration/dependency_tracker_integration_helper.rb +1 -1
- data/spec/support/integration/partial_files_harness.rb +181 -0
- data/spec/support/integration/partials_generation_integration_helper.rb +239 -143
- data/spec/support/integration/path_scenario_harness.rb +175 -0
- data/spec/support/integration/spec_integration_helper.rb +9 -4
- data/spec/support/integration/test_includes_harness.rb +69 -37
- data/spec/support/integration/tool_executor_integration_helper.rb +14 -2
- data/spec/support/spec_helper.rb +2 -0
- data/spec/support/system/spec_system_helper.rb +7 -6
- data/spec/support/system/system_context.rb +21 -3
- data/spec/support/working_dir_tracking.rb +49 -0
- data/spec/system/build_output_mirroring_spec.rb +2 -2
- data/spec/system/bullseye_deployment_spec.rb +2 -0
- data/spec/system/conditional_mock_includes_spec.rb +1 -1
- data/spec/system/delta_builds_spec.rb +163 -23
- 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 +3 -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/launcher_handoff_spec.rb +82 -0
- data/spec/system/mock_include_folders_spec.rb +212 -0
- data/spec/system/mockable_header_reassembly_spec.rb +184 -0
- data/spec/system/parent_directory_reference_spec.rb +5 -3
- 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 +196 -0
- data/spec/system/pinned_thread_count_spec.rb +4 -4
- data/spec/system/preprocessing_fallback_conditionals_spec.rb +1 -1
- data/spec/system/preprocessing_parameterized_tests_spec.rb +1 -1
- data/spec/system/rake_release_task_path_disambiguation_spec.rb +6 -6
- data/spec/system/rake_test_task_path_disambiguation_spec.rb +85 -0
- data/spec/system/short_build_paths_spec.rb +87 -0
- data/spec/system/sibling_header_collision_spec.rb +30 -6
- data/spec/system/special_path_characters_spec.rb +86 -0
- data/spec/system/support/bullseye_common_test_cases.rb +42 -0
- data/spec/system/support/common_test_cases.rb +23 -21
- data/spec/system/support/gcov_common_test_cases.rb +37 -9
- data/spec/system/support/gcov_partials_test_cases.rb +48 -0
- data/spec/system/support/sanitize_common_test_cases.rb +2 -2
- data/spec/system/support/valgrind_common_test_cases.rb +12 -12
- data/spec/system/test_build_layout_spec.rb +209 -0
- data/spec/system/test_pipeline_stop_points_spec.rb +4 -4
- data/spec/system/test_runner_system_include_spec.rb +1 -1
- data/spec/system/test_source_file_directive_spec.rb +64 -5
- data/spec/units/bin/actionator_spec.rb +14 -17
- data/spec/units/bin/app_cfg_spec.rb +37 -0
- data/spec/units/bin/cli_handler_spec.rb +282 -6
- data/spec/units/bin/cli_helper_spec.rb +116 -45
- data/spec/units/bin/installation_selector_spec.rb +114 -0
- data/spec/units/bin/launchinator_spec.rb +171 -0
- data/spec/units/bin/path_validator_spec.rb +10 -0
- data/spec/units/bin/versionator_spec.rb +38 -6
- data/spec/units/build_log_writer_spec.rb +57 -0
- 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/build_root_policy_spec.rb +61 -0
- data/spec/units/config/configurator_builder_spec.rb +61 -6
- data/spec/units/config/configurator_paths_validator_spec.rb +292 -0
- data/spec/units/config/configurator_setup_spec.rb +80 -68
- data/spec/units/config/configurator_spec.rb +54 -6
- data/spec/units/config/configurator_validator_spec.rb +1 -172
- data/spec/units/dependencies/dependency_cache_store_spec.rb +98 -2
- data/spec/units/dependencies/dependency_debug_tree_spec.rb +1 -1
- data/spec/units/dependencies/dependency_hasher_spec.rb +42 -1
- data/spec/units/dependencies/dependency_path_normalizer_spec.rb +1 -1
- data/spec/units/dependencies/dependency_tracker_spec.rb +28 -1
- 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/filename_extension_spec.rb +11 -0
- data/spec/units/filesystem/build_roots_spec.rb +131 -0
- data/spec/units/filesystem/build_subpath_spec.rb +235 -0
- data/spec/units/filesystem/destination_collision_spec.rb +30 -0
- data/spec/units/{file_finder_helper_spec.rb → filesystem/file_finder_helper_spec.rb} +126 -1
- data/spec/units/filesystem/file_finder_spec.rb +845 -0
- data/spec/units/{file_path_collection_utils_spec.rb → filesystem/file_path_collection_utils_spec.rb} +181 -1
- data/spec/units/{file_path_utils_spec.rb → filesystem/file_path_utils_spec.rb} +435 -185
- data/spec/units/filesystem/file_system_wrapper_spec.rb +33 -0
- data/spec/units/filesystem/file_tree_spec.rb +511 -0
- data/spec/units/filesystem/file_tree_windows_spec.rb +78 -0
- data/spec/units/{file_wrapper_spec.rb → filesystem/file_wrapper_spec.rb} +286 -18
- data/spec/units/{path_matcher_spec.rb → filesystem/path_matcher_spec.rb} +48 -1
- data/spec/units/{path_mirror_spec.rb → filesystem/path_mirror_spec.rb} +32 -4
- data/spec/units/filesystem/project_paths_spec.rb +147 -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/filesystem/working_dir_spec.rb +71 -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 +38 -6
- data/spec/units/generators/generator_test_results_backtrace_spec.rb +50 -46
- data/spec/units/generators/generator_test_results_spec.rb +1 -1
- 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/handoff_spec.rb +205 -0
- data/spec/units/includes/header_search_spec.rb +406 -0
- data/spec/units/includes/include_factory_spec.rb +23 -6
- data/spec/units/includes/include_pathinator_spec.rb +118 -8
- data/spec/units/includes/include_spec.rb +14 -0
- data/spec/units/includes/includes_spec.rb +176 -19
- data/spec/units/installation_spec.rb +228 -0
- data/spec/units/library_resolver_spec.rb +157 -0
- data/spec/units/loginator_spec.rb +31 -0
- data/spec/units/mock_locator_spec.rb +275 -6
- data/spec/units/partials/include_groups_spec.rb +42 -0
- data/spec/units/partials/partializer_config_spec.rb +32 -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 +1579 -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 +561 -251
- data/spec/units/plugins/bullseye_spec.rb +49 -2
- data/spec/units/plugins/console_reportinator_spec.rb +73 -26
- data/spec/units/plugins/dependencies_spec.rb +33 -7
- data/spec/units/plugins/dependency_spec_spec.rb +17 -0
- data/spec/units/plugins/gcov_spec.rb +28 -3
- data/spec/units/plugins/gcovr_reportinator_spec.rb +19 -47
- data/spec/units/plugins/gcovr_thresholds_spec.rb +95 -0
- data/spec/units/plugins/module_generator_spec.rb +5 -5
- data/spec/units/plugins/report_build_warnings_log_spec.rb +3 -3
- data/spec/units/plugins/report_log_writer_plugin_spec.rb +10 -1
- data/spec/units/plugins/report_tests_raw_output_log_spec.rb +13 -2
- data/spec/units/plugins/report_tests_teamcity_stdout_spec.rb +77 -3
- data/spec/units/plugins/reportgenerator_reportinator_spec.rb +52 -4
- data/spec/units/plugins/sanitize_records_spec.rb +3 -1
- data/spec/units/plugins/sanitize_spec.rb +1 -1
- data/spec/units/plugins/valgrind_spec.rb +23 -8
- data/spec/units/preprocess/preprocessinator_code_finder_spec.rb +73 -10
- data/spec/units/preprocess/preprocessinator_comment_stripper_spec.rb +1 -1
- 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/rake_app/rakefile_component_resolver_spec.rb +21 -0
- data/spec/units/release_build_executor_spec.rb +53 -14
- data/spec/units/release_build_planner_spec.rb +15 -3
- data/spec/units/reportinator_spec.rb +5 -5
- data/spec/units/setupinator_spec.rb +51 -0
- data/spec/units/standin_headerinator_spec.rb +55 -9
- data/spec/units/test_build_executor_spec.rb +842 -166
- data/spec/units/test_build_planner_spec.rb +205 -15
- data/spec/units/test_build_setup_spec.rb +179 -30
- data/spec/units/test_context_extractor_spec.rb +36 -2
- data/spec/units/test_derived_search_paths_spec.rb +259 -0
- data/spec/units/test_file_preprocessinator_spec.rb +17 -1
- data/spec/units/test_includes_extractinator_spec.rb +61 -9
- data/spec/units/test_invoker/objects_wiring_spec.rb +24 -4
- 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_spec.rb +14 -1
- 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/test_source_file_directive_resolver_spec.rb +38 -7
- data/spec/units/tools/default_tools_quoting_spec.rb +117 -0
- 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} +27 -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
- data/spec/units/yaml_wrapper_spec.rb +11 -0
- metadata +265 -36
- data/lib/ceedling/file_finder_helper.rb +0 -127
- data/lib/ceedling/file_path_collection_utils.rb +0 -164
- data/spec/units/file_finder_spec.rb +0 -495
- /data/lib/ceedling/{tool_executor_helper.rb → tools/tool_executor_helper.rb} +0 -0
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
# =========================================================================
|
|
2
|
+
# Ceedling - Test-Centered Build System for C
|
|
3
|
+
# ThrowTheSwitch.org
|
|
4
|
+
# Copyright (c) 2010-26 Mike Karlesky, Mark VanderVoord, & Greg Williams
|
|
5
|
+
# SPDX-License-Identifier: MIT
|
|
6
|
+
# =========================================================================
|
|
7
|
+
|
|
8
|
+
require 'set'
|
|
9
|
+
require 'ceedling/constants'
|
|
10
|
+
require 'ceedling/partials/type_macros'
|
|
11
|
+
|
|
12
|
+
# Pairs what a Partial extracts from a file's written text with its twin in the file's full
|
|
13
|
+
# expansion, where no macro hides anything.
|
|
14
|
+
#
|
|
15
|
+
# Extraction reads the directives-only copy, so a Partial writes code as its user spelled
|
|
16
|
+
# it. That copy keeps every macro, so a macro can hide a storage class, an inline specifier
|
|
17
|
+
# or a call. The full expansion shows them. A function or a declaration takes from its twin
|
|
18
|
+
# what a macro can hide, and keeps its code as written, so line mapping still holds. A
|
|
19
|
+
# variable whose storage class a macro supplies takes its whole declaration from its twin. A
|
|
20
|
+
# type regains a macro written after its closing brace. The written text reads that macro as a
|
|
21
|
+
# variable, or as the start of the variables' type.
|
|
22
|
+
#
|
|
23
|
+
# Definitions pair by name. Declarations and file-scope variables pair by name and then by
|
|
24
|
+
# order, since a name may be declared more than once.
|
|
25
|
+
class PartializerReconciler
|
|
26
|
+
|
|
27
|
+
# A variable takes these from its twin when a macro supplies its storage class
|
|
28
|
+
VARIABLE_FIELDS = %i[decorators type array_suffix text declarator asm_label].freeze
|
|
29
|
+
|
|
30
|
+
STORAGE_CLASSES = %w[static extern].freeze
|
|
31
|
+
|
|
32
|
+
constructor :c_extractor, :loginator
|
|
33
|
+
|
|
34
|
+
# Reconciles one file's extracted module with that file's expanded code, in place
|
|
35
|
+
#
|
|
36
|
+
# @param c_module [CExtractorTypes::CModule] One file's module, as extracted from its written text
|
|
37
|
+
# @param expansion_filepath [String] The file's own lines from its full expansion, written by
|
|
38
|
+
# Preprocessinator#generate_partial_expansion
|
|
39
|
+
# @param name [String] Test name, used in log messages
|
|
40
|
+
# @param module_name [String] Partial module name, used in log messages
|
|
41
|
+
# @param file_type [String] "source" or "header", used in log messages
|
|
42
|
+
def reconcile(c_module:, expansion_filepath:, name:, module_name:, file_type:)
|
|
43
|
+
expanded = @c_extractor.from_file( expansion_filepath )
|
|
44
|
+
entries = Partials::TypeMacros.rejoin_trailing( c_module, expanded ) +
|
|
45
|
+
_reconcile_definitions( c_module.function_definitions, expanded ) +
|
|
46
|
+
_reconcile_declarations( c_module.function_declarations, expanded ) +
|
|
47
|
+
_reconcile_variables( c_module, expanded )
|
|
48
|
+
|
|
49
|
+
@loginator.log_list(
|
|
50
|
+
entries,
|
|
51
|
+
"Reconciled with full expansion for Partial #{name}::#{module_name} #{file_type}:",
|
|
52
|
+
Verbosity::DEBUG
|
|
53
|
+
) unless entries.empty?
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
private
|
|
57
|
+
|
|
58
|
+
# Updates each definition from the expanded definition of the same name. Returns log entries
|
|
59
|
+
# for those it found.
|
|
60
|
+
def _reconcile_definitions(funcs, expanded_module)
|
|
61
|
+
expanded_by_name = expanded_module.function_definitions.each_with_object({}) { |f, h| h[f.name] = f }
|
|
62
|
+
|
|
63
|
+
return funcs.filter_map do |func|
|
|
64
|
+
expanded = expanded_by_name[func.name]
|
|
65
|
+
next unless expanded
|
|
66
|
+
|
|
67
|
+
_take_expanded( func, expanded )
|
|
68
|
+
"`#{func.name}`"
|
|
69
|
+
end
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
# Everything about a definition that a macro can hide. Its code block stays as written, so
|
|
73
|
+
# line mapping still holds. The decorators its written head doesn't spell are noted, since
|
|
74
|
+
# that head can't be stripped of them.
|
|
75
|
+
def _take_expanded(func, expanded)
|
|
76
|
+
func.hidden_decorators = expanded.decorators - func.decorators
|
|
77
|
+
func.signature = expanded.signature
|
|
78
|
+
func.decorators = expanded.decorators
|
|
79
|
+
func.signature_stripped = expanded.signature_stripped
|
|
80
|
+
func.expanded_body = expanded.body
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
# Matches each declaration to the expanded declaration of the same name, in order. Returns log
|
|
84
|
+
# entries for those whose decorators changed.
|
|
85
|
+
def _reconcile_declarations(decls, expanded_module)
|
|
86
|
+
expanded_by_name = expanded_module.function_declarations.group_by( &:name )
|
|
87
|
+
|
|
88
|
+
return decls.group_by( &:name ).flat_map do |decl_name, same_name|
|
|
89
|
+
same_name.zip( expanded_by_name.fetch( decl_name, [] ) ).filter_map { |decl, expanded| _reconcile_declaration( decl, expanded ) }
|
|
90
|
+
end
|
|
91
|
+
end
|
|
92
|
+
|
|
93
|
+
# Updates one declaration from its expanded counterpart. Its written signature stays as the
|
|
94
|
+
# user spelled it, since a carried prototype is written word for word. Returns a log entry
|
|
95
|
+
# when its decorators changed.
|
|
96
|
+
def _reconcile_declaration(decl, expanded)
|
|
97
|
+
return nil if expanded.nil?
|
|
98
|
+
|
|
99
|
+
changed = decl.decorators != expanded.decorators
|
|
100
|
+
decl.decorators = expanded.decorators
|
|
101
|
+
decl.signature_stripped = expanded.signature_stripped
|
|
102
|
+
return changed ? "`#{decl.name}` (declaration)" : nil
|
|
103
|
+
end
|
|
104
|
+
|
|
105
|
+
# Pairs each file-scope variable with its twin by name, then order. A name pairs only where it
|
|
106
|
+
# appears as often in both copies, since fallback can keep both branches of a conditional. A
|
|
107
|
+
# variable with no name it can be read by never pairs. Returns log entries for the types given
|
|
108
|
+
# a macro and the variables reconciled.
|
|
109
|
+
def _reconcile_variables(c_module, expanded_module)
|
|
110
|
+
ended = Set.new.compare_by_identity
|
|
111
|
+
_record_unpaired( c_module, expanded_module )
|
|
112
|
+
return _variable_pairs( c_module, expanded_module ).flat_map { |var, twin| _reconcile_pair( c_module, var, twin, ended ) }.compact
|
|
113
|
+
end
|
|
114
|
+
|
|
115
|
+
# Fallback keeps both sides of a conditional, so a name can be written more often than the
|
|
116
|
+
# expansion holds it, and none of its copies pairs. Each records every twin's text, so what an
|
|
117
|
+
# initializer names stays visible.
|
|
118
|
+
def _record_unpaired(c_module, expanded_module)
|
|
119
|
+
expanded_by_name = expanded_module.variable_declarations.group_by( &:name )
|
|
120
|
+
|
|
121
|
+
c_module.variable_declarations.group_by( &:name ).each do |var_name, same_name|
|
|
122
|
+
twins = expanded_by_name.fetch( var_name, [] )
|
|
123
|
+
next unless _unpaired?( var_name, same_name, twins )
|
|
124
|
+
|
|
125
|
+
same_name.each { |var| var.expanded_text = twins.map( &:text ).join( "\n" ) }
|
|
126
|
+
end
|
|
127
|
+
end
|
|
128
|
+
|
|
129
|
+
def _unpaired?(var_name, same_name, twins)
|
|
130
|
+
return !(var_name.nil? or twins.empty? or twins.size == same_name.size)
|
|
131
|
+
end
|
|
132
|
+
|
|
133
|
+
# Each written variable with its twin, for the names both copies hold equally often
|
|
134
|
+
def _variable_pairs(c_module, expanded_module)
|
|
135
|
+
expanded_by_name = expanded_module.variable_declarations.group_by( &:name )
|
|
136
|
+
|
|
137
|
+
return c_module.variable_declarations.group_by( &:name ).flat_map do |var_name, same_name|
|
|
138
|
+
twins = expanded_by_name.fetch( var_name, [] )
|
|
139
|
+
(var_name.nil? or twins.size != same_name.size) ? [] : same_name.zip( twins )
|
|
140
|
+
end
|
|
141
|
+
end
|
|
142
|
+
|
|
143
|
+
# A variable keeps its expanded text, which shows what its initializer names. Its type takes
|
|
144
|
+
# back a macro after its closing brace, then the variable takes what a macro hid. `ended`
|
|
145
|
+
# holds the types already given their macro. Returns a log entry or nil for the type, then
|
|
146
|
+
# for the variable.
|
|
147
|
+
def _reconcile_pair(c_module, var, twin, ended)
|
|
148
|
+
var.expanded_text = twin.text
|
|
149
|
+
rejoined = Partials::TypeMacros.rejoin_leading( var, twin, ended )
|
|
150
|
+
return [rejoined, _reconcile_variable( c_module, var, twin )]
|
|
151
|
+
end
|
|
152
|
+
|
|
153
|
+
# A variable whose storage class a macro supplies takes every parsed field from its twin. Its
|
|
154
|
+
# fields depend on each other, so a mix of written and expanded ones could read `extern static`.
|
|
155
|
+
# A macro that supplies only a qualifier, as `#define ROM const`, compiles as written.
|
|
156
|
+
def _reconcile_variable(c_module, var, twin)
|
|
157
|
+
return nil if (var.decorators & STORAGE_CLASSES) == (twin.decorators & STORAGE_CLASSES)
|
|
158
|
+
|
|
159
|
+
VARIABLE_FIELDS.each { |field| var[field] = twin[field] }
|
|
160
|
+
_adopt_defined_type( c_module, var, twin )
|
|
161
|
+
return "`#{var.name}` (variable)"
|
|
162
|
+
end
|
|
163
|
+
|
|
164
|
+
# Places ahead of the variable the type its twin defines, which a macro ahead of it hid from
|
|
165
|
+
# the written declaration. Once per type, however many variables share it.
|
|
166
|
+
def _adopt_defined_type(c_module, var, twin)
|
|
167
|
+
type = twin.defined_type
|
|
168
|
+
return if type.nil? or var.defined_type
|
|
169
|
+
|
|
170
|
+
c_module.insert_before!( var, [type] ) unless c_module.aggregate_definitions.any? { |held| held.equal?( type ) }
|
|
171
|
+
var.defined_type = type
|
|
172
|
+
end
|
|
173
|
+
|
|
174
|
+
end
|
|
@@ -6,11 +6,16 @@
|
|
|
6
6
|
# =========================================================================
|
|
7
7
|
|
|
8
8
|
require 'ceedling/partials/partials'
|
|
9
|
+
require 'ceedling/partials/definition_head'
|
|
9
10
|
require 'ceedling/partials/partializer_runtime'
|
|
10
11
|
require 'ceedling/c_extractor/c_extractor_constants'
|
|
12
|
+
require 'ceedling/c_extractor/c_extractor_functions'
|
|
11
13
|
|
|
12
14
|
class PartializerUtils
|
|
13
15
|
|
|
16
|
+
# The C11 specifier and the GNU and C23 attributes that each say a function never returns
|
|
17
|
+
NORETURN_MARKINGS = /(?<!\w)_Noreturn(?!\w)|__attribute__\s*\(\(\s*(?:__noreturn__|noreturn)\s*\)\)|\[\[\s*(?:_Noreturn|noreturn)\s*\]\]/ unless const_defined?(:NORETURN_MARKINGS, false)
|
|
18
|
+
|
|
14
19
|
include Partials
|
|
15
20
|
|
|
16
21
|
constructor :preprocessinator_code_finder, :loginator
|
|
@@ -35,93 +40,45 @@ class PartializerUtils
|
|
|
35
40
|
# Transform function to appropriate output format `FunctionDefinition` or `FunctionDeclaration`
|
|
36
41
|
def transform_function(func, signature, output_type)
|
|
37
42
|
case output_type
|
|
38
|
-
when :impl
|
|
39
|
-
|
|
40
|
-
# Adjust line_num upward so that emitted #line directives remain accurate.
|
|
41
|
-
new_code_block, stripped_newlines = extract_code_block(func.code_block, func.decorators)
|
|
42
|
-
Partials.manufacture_function_definition(
|
|
43
|
-
name: func.name,
|
|
44
|
-
signature: signature,
|
|
45
|
-
source_filepath: func.source_filepath,
|
|
46
|
-
line_num: adjust_line_num(func.line_num, stripped_newlines),
|
|
47
|
-
code_block: new_code_block
|
|
48
|
-
)
|
|
49
|
-
when :interface
|
|
50
|
-
# A signature sourced from a CFunctionDefinition never carries a trailing semicolon
|
|
51
|
-
# (it's followed by a body, not one), but a signature sourced from a
|
|
52
|
-
# CFunctionDeclaration always does (it's a bare prototype). Strip it here so
|
|
53
|
-
# callers can render "#{signature};" uniformly regardless of which kind of
|
|
54
|
-
# function this interface entry came from.
|
|
55
|
-
Partials.manufacture_function_declaration(
|
|
56
|
-
name: func.name,
|
|
57
|
-
signature: signature.sub(/;\s*\z/, '')
|
|
58
|
-
)
|
|
59
|
-
else
|
|
60
|
-
PartializerRuntime.raise_on_option(output_type)
|
|
43
|
+
when :impl then return testable_definition( func, signature )
|
|
44
|
+
when :interface then return mockable_declaration( func, signature )
|
|
61
45
|
end
|
|
46
|
+
|
|
47
|
+
PartializerRuntime.raise_on_option(output_type)
|
|
62
48
|
end
|
|
63
49
|
|
|
64
|
-
#
|
|
65
|
-
#
|
|
66
|
-
#
|
|
67
|
-
#
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
# @return [String] Modified text with declaration replaced by a no-op expression
|
|
80
|
-
def replace_declaration_with_noop(text, original_decl, placeholder)
|
|
81
|
-
replace_compound_declaration_with_noops(text, original_decl, placeholder, 1)
|
|
50
|
+
# Strip decorators from the front of code_block and count how many newlines were removed.
|
|
51
|
+
# Adjust line_num upward so that emitted #line directives remain accurate. A head whose
|
|
52
|
+
# decorators a macro hides is written from the signature instead. The implementation header
|
|
53
|
+
# declares that same signature.
|
|
54
|
+
def testable_definition(func, signature)
|
|
55
|
+
new_code_block, stripped_newlines =
|
|
56
|
+
Partials::DefinitionHead.rewrite( func, signature ) || extract_code_block( func.code_block, func.decorators, func.name )
|
|
57
|
+
|
|
58
|
+
return Partials.manufacture_function_definition(
|
|
59
|
+
name: func.name,
|
|
60
|
+
signature: signature,
|
|
61
|
+
source_filepath: func.source_filepath,
|
|
62
|
+
line_num: adjust_line_num(func.line_num, stripped_newlines),
|
|
63
|
+
code_block: new_code_block
|
|
64
|
+
)
|
|
82
65
|
end
|
|
83
66
|
|
|
84
|
-
#
|
|
85
|
-
#
|
|
86
|
-
#
|
|
87
|
-
#
|
|
88
|
-
#
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
#
|
|
95
|
-
# @param text [String] Code text to modify (e.g., a function code_block or body)
|
|
96
|
-
# @param original_decl [String] Declaration text to replace (should be stripped of surrounding whitespace)
|
|
97
|
-
# @param placeholder [String] Opaque token to embed in the single trailing comment
|
|
98
|
-
# @param count [Integer] Number of no-op expressions to insert (one per variable)
|
|
99
|
-
# @return [String] Modified text
|
|
100
|
-
def replace_compound_declaration_with_noops(text, original_decl, placeholder, count)
|
|
101
|
-
noops = "(void)0; " * (count - 1)
|
|
102
|
-
comment = "(void)0; /* `#{placeholder}` replaced with no-op plus variable renamed & promoted to module-scope */"
|
|
103
|
-
text.sub(original_decl) { noops + comment }
|
|
67
|
+
# A signature sourced from a CFunctionDefinition never carries a trailing semicolon (it's
|
|
68
|
+
# followed by a body, not one), but a signature sourced from a CFunctionDeclaration always does
|
|
69
|
+
# (it's a bare prototype). Strip it here so callers can render "#{signature};" uniformly
|
|
70
|
+
# regardless of which kind of function this interface entry came from. A mock always returns,
|
|
71
|
+
# so a mock declared never to return would contradict itself. Every noreturn marking stays behind.
|
|
72
|
+
def mockable_declaration(func, signature)
|
|
73
|
+
return Partials.manufacture_function_declaration(
|
|
74
|
+
name: func.name,
|
|
75
|
+
signature: without_noreturn( signature ).strip.sub(/;\s*\z/, '')
|
|
76
|
+
)
|
|
104
77
|
end
|
|
105
78
|
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
# with `new_name`. Token boundaries use Ruby `\b` (word boundary between
|
|
110
|
-
# `\w` = `[a-zA-Z0-9_]` and `\W`), which exactly matches C identifier boundaries.
|
|
111
|
-
# For example, renaming `count`:
|
|
112
|
-
# - Matches: `count = 0`, `(count)`, `count==5`, `*count`, `count[0]`
|
|
113
|
-
# - No match: `count_down`, `up_count`, `recount`
|
|
114
|
-
#
|
|
115
|
-
# Note: This method has no comment-awareness. Callers that need comment content
|
|
116
|
-
# preserved verbatim (e.g., no-op placeholders) should use `replace_declaration_with_noop`
|
|
117
|
-
# with an opaque placeholder and restore the original text after renaming.
|
|
118
|
-
#
|
|
119
|
-
# @param text [String] Code text to process
|
|
120
|
-
# @param old_name [String] Identifier to replace
|
|
121
|
-
# @param new_name [String] Replacement identifier
|
|
122
|
-
# @return [String] Modified text with all token-bounded occurrences renamed
|
|
123
|
-
def rename_c_identifier(text, old_name, new_name)
|
|
124
|
-
text.gsub(/\b#{Regexp.escape(old_name)}\b/, new_name)
|
|
79
|
+
def without_noreturn(signature)
|
|
80
|
+
stripped = signature.gsub( NORETURN_MARKINGS, '' )
|
|
81
|
+
return stripped == signature ? signature : stripped.squeeze( ' ' )
|
|
125
82
|
end
|
|
126
83
|
|
|
127
84
|
# Stamp the originating source filepath onto each function in a collection.
|
|
@@ -136,39 +93,55 @@ class PartializerUtils
|
|
|
136
93
|
funcs.each { |func| func.source_filepath = filepath }
|
|
137
94
|
end
|
|
138
95
|
|
|
139
|
-
# Locate
|
|
96
|
+
# Locate each function's line number by searching the original C source file once.
|
|
140
97
|
#
|
|
141
|
-
# Used
|
|
142
|
-
# unavailable for all functions in the current context. Delegates directly to
|
|
143
|
-
# `code_finder.find_in_c_file`.
|
|
98
|
+
# Used for a file preprocessed in fallback, which has no raw directives-only copy to search.
|
|
144
99
|
#
|
|
145
|
-
# @param
|
|
100
|
+
# @param code_blocks [Array<String>] Function definition texts to search for
|
|
146
101
|
# @param filepath [String] Path to the C source file to search
|
|
147
|
-
# @return [Integer, nil] 1-indexed source line number, or nil
|
|
148
|
-
def
|
|
149
|
-
@code_finder.
|
|
102
|
+
# @return [Array<Integer, nil>] Each 1-indexed source line number, or nil where not found
|
|
103
|
+
def locate_functions_in_source(code_blocks:, filepath:)
|
|
104
|
+
return @code_finder.find_all_in_c_file( filepath, code_blocks )
|
|
150
105
|
end
|
|
151
106
|
|
|
152
|
-
# Locate
|
|
107
|
+
# Locate each declaration's line number in the text of the file it came from.
|
|
108
|
+
#
|
|
109
|
+
# The original file holds only its own lines, so a match there can't belong to a header it
|
|
110
|
+
# includes. Preprocessed output can't promise that, since it carries every included header.
|
|
153
111
|
#
|
|
154
|
-
#
|
|
155
|
-
#
|
|
156
|
-
# 2. If that yields nil, fall back to the original C source file.
|
|
112
|
+
# Comments are blanked first, newlines kept, so a commented-out copy of a declaration is
|
|
113
|
+
# never taken for it. Blanking passes over the whole file, so it happens once for them all.
|
|
157
114
|
#
|
|
158
|
-
#
|
|
115
|
+
# @param signatures [Array<String>] Declaration texts as extracted, each ending in its semicolon
|
|
116
|
+
# @param text [String] Full text of the original header or source file
|
|
117
|
+
# @return [Array<Integer, nil>] Each declaration's 1-indexed line number, or nil if not found
|
|
118
|
+
def locate_declarations_in_text(signatures:, text:)
|
|
119
|
+
code = _without_comments( text )
|
|
120
|
+
return signatures.map { |signature| @code_finder.find_in_c_string( code, signature ) }
|
|
121
|
+
end
|
|
122
|
+
|
|
123
|
+
# Locate each function's line number using preprocessed output with C source fallback.
|
|
159
124
|
#
|
|
160
|
-
#
|
|
125
|
+
# Two-strategy lookup, each file read once for all the functions it serves:
|
|
126
|
+
# 1. Search the GCC-preprocessed directives-only file, whose line markers give original lines.
|
|
127
|
+
# 2. Search the original C source file for each function step 1 didn't find.
|
|
128
|
+
#
|
|
129
|
+
# @param code_blocks [Array<String>] Function definition texts to search for
|
|
161
130
|
# @param filepath [String] Path to the original C source file (fallback target)
|
|
162
131
|
# @param preprocessed_filepath [String] Path to the preprocessed directives-only file
|
|
163
|
-
# @return [Integer, nil] 1-indexed source line number, or nil
|
|
164
|
-
def
|
|
165
|
-
|
|
166
|
-
|
|
132
|
+
# @return [Array<Integer, nil>] Each 1-indexed source line number, or nil where neither search finds it
|
|
133
|
+
def locate_functions_via_preprocessed(code_blocks:, filepath:, preprocessed_filepath:)
|
|
134
|
+
lines = @code_finder.find_all_in_preprocessed_file( preprocessed_filepath, code_blocks )
|
|
135
|
+
missing = lines.each_index.select { |index| lines[index].nil? }
|
|
136
|
+
return lines if missing.empty?
|
|
167
137
|
|
|
168
138
|
msg = "Using fallback C function location search for #{filepath}"
|
|
169
|
-
@loginator.log( msg, Verbosity::OBNOXIOUS, LogLabels::WARNING )
|
|
139
|
+
missing.each { @loginator.log( msg, Verbosity::OBNOXIOUS, LogLabels::WARNING ) }
|
|
140
|
+
|
|
141
|
+
found = @code_finder.find_all_in_c_file( filepath, missing.map { |index| code_blocks[index] } )
|
|
142
|
+
missing.zip( found ) { |index, line_num| lines[index] = line_num }
|
|
170
143
|
|
|
171
|
-
return
|
|
144
|
+
return lines
|
|
172
145
|
end
|
|
173
146
|
|
|
174
147
|
# Format per-function line-number results as a list of human-readable strings.
|
|
@@ -187,6 +160,11 @@ class PartializerUtils
|
|
|
187
160
|
|
|
188
161
|
private
|
|
189
162
|
|
|
163
|
+
# A literal stays, since a comment marker inside one starts no comment
|
|
164
|
+
def _without_comments(text)
|
|
165
|
+
return text.gsub( Partials::LITERAL_OR_COMMENT ) { |found| found.start_with?( '/' ) ? found.gsub( /[^\n]/, ' ' ) : found }
|
|
166
|
+
end
|
|
167
|
+
|
|
190
168
|
# Does any decorator in a list matche any private keyword (case-insensitive)
|
|
191
169
|
def is_function_private?(decorators)
|
|
192
170
|
return decorators.any? do |decorator|
|
|
@@ -196,19 +174,21 @@ class PartializerUtils
|
|
|
196
174
|
|
|
197
175
|
# Strip decorator keywords from the front of code_block and count leading newlines removed.
|
|
198
176
|
#
|
|
199
|
-
#
|
|
200
|
-
#
|
|
201
|
-
#
|
|
202
|
-
#
|
|
177
|
+
# Decorators live only in the text before the function's name. Each is removed there as a
|
|
178
|
+
# whole token, so the same word inside the name, an attribute string or the body stays. Leading
|
|
179
|
+
# whitespace is then trimmed. Returns the trimmed code block and a count of the newlines
|
|
180
|
+
# removed from the leading portion. The caller adjusts line_num with that count so that
|
|
181
|
+
# emitted #line directives in generated source remain accurate.
|
|
203
182
|
#
|
|
204
183
|
# @param code_block [String] Raw function source text (decorators + signature + body)
|
|
205
184
|
# @param decorators [Array<String>] Decorator keywords from CFunctionDefinition#decorators
|
|
185
|
+
# @param name [String] Function name, which ends the decorator region
|
|
206
186
|
# @return [Array(String, Integer)] [trimmed_code_block, leading_newline_count]
|
|
207
|
-
def extract_code_block(code_block, decorators)
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
leading
|
|
211
|
-
stripped.lstrip
|
|
187
|
+
def extract_code_block(code_block, decorators, name)
|
|
188
|
+
cut = CExtractorFunctions.name_position( code_block, name ) || 0
|
|
189
|
+
stripped = CExtractorFunctions.remove_tokens( code_block[0...cut], decorators ) + code_block[cut..]
|
|
190
|
+
leading = stripped[/\A\s*/]
|
|
191
|
+
stripped = stripped.lstrip
|
|
212
192
|
return stripped, leading.count("\n")
|
|
213
193
|
end
|
|
214
194
|
|
|
@@ -5,6 +5,16 @@
|
|
|
5
5
|
# SPDX-License-Identifier: MIT
|
|
6
6
|
# =========================================================================
|
|
7
7
|
|
|
8
|
+
require 'set'
|
|
9
|
+
require 'strscan'
|
|
10
|
+
require 'ceedling/constants'
|
|
11
|
+
require 'ceedling/c_identifier'
|
|
12
|
+
require 'ceedling/c_extractor/c_extractor_constants'
|
|
13
|
+
require 'ceedling/c_extractor/c_extractor_declarator'
|
|
14
|
+
require 'ceedling/partials/carry_plan'
|
|
15
|
+
require 'ceedling/partials/interface_extras'
|
|
16
|
+
require 'ceedling/partials/include_groups'
|
|
17
|
+
|
|
8
18
|
module Partials
|
|
9
19
|
# Constants
|
|
10
20
|
PUBLIC = :public unless const_defined?(:PUBLIC)
|
|
@@ -17,19 +27,31 @@ module Partials
|
|
|
17
27
|
MOCK_PUBLIC = :mock_public unless const_defined?(:MOCK_PUBLIC)
|
|
18
28
|
MOCK_PRIVATE = :mock_private unless const_defined?(:MOCK_PRIVATE)
|
|
19
29
|
|
|
20
|
-
#
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
super
|
|
24
|
-
end
|
|
25
|
-
end unless const_defined?(:ConfigFileInfo, false)
|
|
30
|
+
# A string or character literal, or a comment. One pattern finds both, so whichever starts
|
|
31
|
+
# first wins, as it does for the compiler.
|
|
32
|
+
LITERAL_OR_COMMENT = %r{"(?:\\.|[^"\\\n])*"|'(?:\\.|[^'\\\n])*'|/\*.*?\*/|//[^\n]*}m unless const_defined?(:LITERAL_OR_COMMENT)
|
|
26
33
|
|
|
27
|
-
#
|
|
28
|
-
|
|
29
|
-
|
|
34
|
+
# A header or source file to be partialized, and what stages 6 and 7 made of it. A
|
|
35
|
+
# preprocessed path is nil when that file wasn't written.
|
|
36
|
+
#
|
|
37
|
+
# - `raw_directives_only_filepath`: the -fdirectives-only output, line markers and every
|
|
38
|
+
# included header's macros intact. Nil in fallback.
|
|
39
|
+
# - `assembled_filepath`: the file's own content with its #includes restored, which
|
|
40
|
+
# extraction parses.
|
|
41
|
+
# - `raw_expansion_filepath`: the full expansion, line markers intact.
|
|
42
|
+
# - `expansion_filepath`: the full expansion's own lines, which reconciliation parses.
|
|
43
|
+
# - `fallback`: true when this file was preprocessed without -fdirectives-only.
|
|
44
|
+
ConfigFileInfo = Struct.new(
|
|
45
|
+
:filepath, :raw_directives_only_filepath, :assembled_filepath, :raw_expansion_filepath, :expansion_filepath,
|
|
46
|
+
:fallback, :includes, keyword_init: true
|
|
47
|
+
) do
|
|
48
|
+
def initialize(
|
|
49
|
+
filepath: nil, raw_directives_only_filepath: nil, assembled_filepath: nil, raw_expansion_filepath: nil,
|
|
50
|
+
expansion_filepath: nil, fallback: false, includes: []
|
|
51
|
+
)
|
|
30
52
|
super
|
|
31
53
|
end
|
|
32
|
-
end unless const_defined?(:
|
|
54
|
+
end unless const_defined?(:ConfigFileInfo, false)
|
|
33
55
|
|
|
34
56
|
# Data class representing a C function signature
|
|
35
57
|
FunctionDeclaration = Struct.new(
|
|
@@ -61,6 +83,49 @@ module Partials
|
|
|
61
83
|
end
|
|
62
84
|
end unless const_defined?(:FunctionDefinition, false)
|
|
63
85
|
|
|
86
|
+
# The name a Partial gives a type a declaration defines, as `struct { int count; }` in
|
|
87
|
+
# `static struct { int count; } s_ctx;`. The parts name its variable: the variable alone at file
|
|
88
|
+
# scope, or a promoted static's function and variable. The module's name is folded as
|
|
89
|
+
# CIdentifier.fold does, and a directory a module is named by takes no part. ceedling.h's
|
|
90
|
+
# PARTIAL_TYPE and PARTIAL_LOCAL_TYPE build the same name.
|
|
91
|
+
# type_name( 'ticker', 's_ctx' ) --> ceedling_partial_ticker_s_ctx_t
|
|
92
|
+
# type_name( 'drivers/my-uart', 'tick', 'n' ) --> ceedling_partial_my_uart_tick_n_t
|
|
93
|
+
def self.type_name(module_name, *parts)
|
|
94
|
+
return "#{PARTIAL_FILENAME_PREFIX}#{CIdentifier.fold( File.basename( module_name ) )}_#{parts.join( '_' )}_t"
|
|
95
|
+
end
|
|
96
|
+
|
|
97
|
+
# Names each type a declaration defines after the first of its variables with a name. A type
|
|
98
|
+
# already named, as a promoted static's is, keeps its name.
|
|
99
|
+
def self.name_defined_types(c_module, module_name)
|
|
100
|
+
c_module.variable_declarations.each do |var|
|
|
101
|
+
type = var.defined_type
|
|
102
|
+
type.type_name ||= type_name( module_name, var.name ) if type and var.name
|
|
103
|
+
end
|
|
104
|
+
end
|
|
105
|
+
|
|
106
|
+
# The type a variable holds by value, less a keyword ahead of it that changes only how it's
|
|
107
|
+
# stored or accessed, as `_Thread_local` and `_Atomic` do
|
|
108
|
+
def self.named_type(var)
|
|
109
|
+
return var.type.to_s.sub( /\A(?:(?:_Thread_local|thread_local|__thread|_Atomic)\s+)+/, '' )
|
|
110
|
+
end
|
|
111
|
+
|
|
112
|
+
# A `static` function is private to its file
|
|
113
|
+
def self.static?(decorators)
|
|
114
|
+
return decorators.include?( 'static' )
|
|
115
|
+
end
|
|
116
|
+
|
|
117
|
+
# Any inline specifier. `static` only narrows linkage, so it doesn't count.
|
|
118
|
+
def self.inline?(decorators)
|
|
119
|
+
return decorators.any? { |d| d != 'static' and CExtractorConstants::PRIVATE_KEYWORDS.include?( d ) }
|
|
120
|
+
end
|
|
121
|
+
|
|
122
|
+
# A declaration of an inline function whose body another header holds. Under C99 a file
|
|
123
|
+
# declaring such a function `extern`, or without `inline`, holds its external definition.
|
|
124
|
+
# A declaration marked `inline` counts too, the body being nowhere else.
|
|
125
|
+
def self.foreign_inline?(decl)
|
|
126
|
+
return (inline?( decl.decorators ) or decl.inline_elsewhere) ? true : false
|
|
127
|
+
end
|
|
128
|
+
|
|
64
129
|
def self.manufacture_function_declaration(line_num: nil, source_filepath: nil, name:, signature:)
|
|
65
130
|
return FunctionDeclaration.new(
|
|
66
131
|
name: name,
|
|
@@ -79,4 +144,82 @@ module Partials
|
|
|
79
144
|
line_num: line_num
|
|
80
145
|
)
|
|
81
146
|
end
|
|
147
|
+
# How promotion renames a function's statics in C text. A rename reads the text one token at a
|
|
148
|
+
# time, so literals, comments, member access and tags keep their spelling.
|
|
149
|
+
module Rename
|
|
150
|
+
|
|
151
|
+
# A struct or union keyword and whatever follows it in the statement up to a '{', such as a
|
|
152
|
+
# tag, attributes, macros or comments. A function's head may match too, which only renames
|
|
153
|
+
# more. Nothing is read twice, so the match takes linear time.
|
|
154
|
+
BODY_HEAD = /(?<![\w$])(?:struct|union)(?![\w$])(?>[^;{}()"']+|(?<group>\((?>[^()]+|\g<group>)*\)))*+\{/ unless const_defined?(:BODY_HEAD)
|
|
155
|
+
|
|
156
|
+
# A member after '.' or '->', or a tag after struct, union or enum. Each lives apart from
|
|
157
|
+
# variables.
|
|
158
|
+
MEMBER_OR_TAG = /(?:\.|->)\s*[A-Za-z_$][\w$]*|(?<![\w$])(?:struct|union|enum)\s+[A-Za-z_$][\w$]*/ unless const_defined?(:MEMBER_OR_TAG)
|
|
159
|
+
|
|
160
|
+
# The start of a member or tag token
|
|
161
|
+
MEMBER_OR_TAG_START = /\A(?:(?:\.|->)\s*[A-Za-z_$]|(?:struct|union|enum)\s)/ unless const_defined?(:MEMBER_OR_TAG_START)
|
|
162
|
+
|
|
163
|
+
# A number, read whole, since a C23 digit separator, as in `1'000`, would otherwise open a
|
|
164
|
+
# character literal
|
|
165
|
+
NUMBER = /(?<![\w$])\.?\d(?:[\w$.]|[eEpP][+-]|'(?=[\w$]))*/ unless const_defined?(:NUMBER)
|
|
166
|
+
|
|
167
|
+
# How a rename reads text, one token at a time. Only an identifier is renamed, so first come
|
|
168
|
+
# the tokens that hold one without naming a variable.
|
|
169
|
+
TOKEN = Regexp.union( MEMBER_OR_TAG, NUMBER, LITERAL_OR_COMMENT, CExtractorConstants::IDENTIFIER ) unless const_defined?(:TOKEN)
|
|
170
|
+
|
|
171
|
+
# An asm template's reference to a named operand, as in `%[count]` or `%w[count]`. A string
|
|
172
|
+
# holding one is renamed wherever it sits, since a macro may open the template, as in
|
|
173
|
+
# `LOCK_PREFIX "incl %[count]"`.
|
|
174
|
+
ASM_OPERAND_REFERENCE = /%[A-Za-z]*\[\K[A-Za-z_$][\w$]*(?=\])/ unless const_defined?(:ASM_OPERAND_REFERENCE)
|
|
175
|
+
|
|
176
|
+
# The text with each identifier `renames` maps replaced, in one pass whatever the number of
|
|
177
|
+
# names. Literals and comments stay as written, and so do member access and tags. A name a
|
|
178
|
+
# local struct or union body holds is renamed in member access and tags too (see
|
|
179
|
+
# names_in_bodies). `shared` gives those names when the bodies sit elsewhere too, and `tags`
|
|
180
|
+
# renames tags by name. The exception is a string's asm operand references, which must follow
|
|
181
|
+
# the operand names they refer to.
|
|
182
|
+
def self.identifiers(text, renames, shared: nil, tags: {})
|
|
183
|
+
shared ||= names_in_bodies( text, renames )
|
|
184
|
+
return text.gsub( TOKEN ) do |token|
|
|
185
|
+
next _member_or_tag( token, renames, shared, tags ) if token.match?( MEMBER_OR_TAG_START )
|
|
186
|
+
next renames.fetch( token, token ) unless token.start_with?( '"' )
|
|
187
|
+
|
|
188
|
+
token.gsub( ASM_OPERAND_REFERENCE ) { |name| renames.fetch( name, name ) }
|
|
189
|
+
end
|
|
190
|
+
end
|
|
191
|
+
|
|
192
|
+
# A member access or tag token, renamed. A tag `tags` renames takes its new name. Otherwise a
|
|
193
|
+
# name a local body holds takes its variable's.
|
|
194
|
+
def self._member_or_tag(token, renames, shared, tags)
|
|
195
|
+
tag = token.match?( /\A(?:struct|union|enum)\s/ )
|
|
196
|
+
return token.sub( /[A-Za-z_$][\w$]*\z/ ) do |name|
|
|
197
|
+
next tags[name] if tag and tags.key?( name )
|
|
198
|
+
|
|
199
|
+
shared.include?( name ) ? renames[name] : name
|
|
200
|
+
end
|
|
201
|
+
end
|
|
202
|
+
|
|
203
|
+
# The names `renames` maps that a struct or union body in the text holds, as a member or in
|
|
204
|
+
# use. Such a body is local to the function, so its members and their uses take the new name
|
|
205
|
+
# alike, wherever they sit.
|
|
206
|
+
def self.names_in_bodies(text, renames)
|
|
207
|
+
names = Set.new
|
|
208
|
+
text.scan( BODY_HEAD ) do
|
|
209
|
+
body = _body_after( text, Regexp.last_match )
|
|
210
|
+
body&.gsub( LITERAL_OR_COMMENT, ' ' )&.scan( CExtractorConstants::IDENTIFIER ) { |name| names << name if renames.key?( name ) }
|
|
211
|
+
end
|
|
212
|
+
return names
|
|
213
|
+
end
|
|
214
|
+
|
|
215
|
+
# The body whose '{' ends the match, or nil when its braces don't balance
|
|
216
|
+
def self._body_after(text, match)
|
|
217
|
+
scanner = StringScanner.new( text )
|
|
218
|
+
scanner.pos = match.pre_match.bytesize + match[0].bytesize - 1
|
|
219
|
+
start = scanner.pos
|
|
220
|
+
return CExtractorDeclarator._skip_balanced( scanner ) ? text.byteslice( start, scanner.pos - start ) : nil
|
|
221
|
+
end
|
|
222
|
+
|
|
223
|
+
end
|
|
224
|
+
|
|
82
225
|
end
|