├── .gitattributes ├── .github └── workflows │ ├── codeql-analysis.yml │ ├── install_toolchain.sh │ ├── publish-learn-latest.yml │ ├── sphinx-books-tests.js.yml │ ├── sphinx-content-tests.js.yml │ ├── sphinx-plugin-tests.js.yml │ └── typescript-tests.js.yml ├── .gitignore ├── CONTRIBUTING.md ├── LICENSE ├── README.md ├── Vagrantfile ├── backend └── .gitignore ├── content ├── about.rst ├── conf.ini ├── courses │ ├── .lvimrc │ ├── Ada_For_The_CPP_Java_Developer │ │ ├── chapters │ │ │ ├── 01_Preface.rst │ │ │ ├── 02_Basics.rst │ │ │ ├── 03_Compilation_Unit_Structure.rst │ │ │ ├── 04_Statements_Declarations_and_Control_Structures.rst │ │ │ ├── 05_Type_System.rst │ │ │ ├── 06_Functions_and_Procedures.rst │ │ │ ├── 07_Packages.rst │ │ │ ├── 08_Classes_and_Object_Oriented_Programming.rst │ │ │ ├── 09_Generics.rst │ │ │ ├── 10_Exceptions.rst │ │ │ ├── 11_Concurrency.rst │ │ │ ├── 12_Low_Level_Programming.rst │ │ │ ├── 13_Conclusion.rst │ │ │ └── 14_References.rst │ │ ├── conf.ini │ │ ├── cover-A4.pdf │ │ └── index.rst │ ├── Ada_For_The_Embedded_C_Developer │ │ ├── chapters │ │ │ ├── 01_Introduction.rst │ │ │ ├── 02_Perspective.rst │ │ │ ├── 03_Concurrency.rst │ │ │ ├── 04_Embedded.rst │ │ │ ├── 05_SPARK.rst │ │ │ ├── 06_Translation.rst │ │ │ ├── 07_Reusability.rst │ │ │ ├── 08_Performance.rst │ │ │ ├── 09_Business.rst │ │ │ ├── 10_Conclusion.rst │ │ │ └── Appendix_A_OOP.rst │ │ ├── conf.ini │ │ ├── cover-A4.pdf │ │ └── index.rst │ ├── GNAT_Toolchain_Intro │ │ ├── chapters │ │ │ ├── gnat_studio.rst │ │ │ ├── gnat_toolchain_basics.rst │ │ │ ├── gnat_tools.rst │ │ │ ├── gnat_windows_build_opt.png │ │ │ ├── gnat_windows_build_run_opt.png │ │ │ ├── gnat_windows_project_debug_opt.png │ │ │ └── gprbuild.rst │ │ ├── conf.ini │ │ ├── cover-A4.pdf │ │ └── index.rst │ ├── Guidelines_for_Safe_and_Secure_Ada_SPARK │ │ ├── Makefile │ │ ├── README.md │ │ ├── chapters │ │ │ ├── guidelines │ │ │ │ ├── concurrency.rst │ │ │ │ ├── concurrency │ │ │ │ │ ├── con01_use_the_ravenscar_profile.rst │ │ │ │ │ ├── con02_use_the_jorvik_profile.rst │ │ │ │ │ ├── con03_avoid_shared_variables_for_inter-task_communication.rst │ │ │ │ │ └── examples │ │ │ │ │ │ ├── con01.adb │ │ │ │ │ │ ├── con01.ads │ │ │ │ │ │ ├── con02.adb │ │ │ │ │ │ ├── con02.ads │ │ │ │ │ │ └── con03.ads │ │ │ │ ├── definitions.rst │ │ │ │ ├── dynamic_storage_management.rst │ │ │ │ ├── dynamic_storage_management │ │ │ │ │ ├── dyn01_common_high_integrity_restrictions.rst │ │ │ │ │ ├── dyn02_traditional_static_allocation_policy.rst │ │ │ │ │ ├── dyn03_access_types_without_allocators_policy.rst │ │ │ │ │ ├── dyn04_minimal_dynamic_allocation_policy.rst │ │ │ │ │ ├── dyn05_user-defined_storage_pools_policy.rst │ │ │ │ │ └── dyn06_statically_determine_maximum_stack_requirements.rst │ │ │ │ ├── exception_usage.rst │ │ │ │ ├── exception_usage │ │ │ │ │ ├── examples │ │ │ │ │ │ ├── exu01.adb │ │ │ │ │ │ ├── exu02.adb │ │ │ │ │ │ └── exu03.adb │ │ │ │ │ ├── exu01_dont_raise_language-defined_exceptions.rst │ │ │ │ │ ├── exu02_no_unhandled_application-defined_exceptions.rst │ │ │ │ │ ├── exu03_no_exception_propagation_beyond_name_visibility.rst │ │ │ │ │ └── exu04_prove_absence_of_run-time_exceptions.rst │ │ │ │ ├── object_oriented_programming.rst │ │ │ │ ├── object_oriented_programming │ │ │ │ │ ├── examples │ │ │ │ │ │ ├── oop03.ads │ │ │ │ │ │ ├── oop04.adb │ │ │ │ │ │ ├── oop05.ads │ │ │ │ │ │ └── oop06.adb │ │ │ │ │ ├── oop01_no_class-wide_constructs_policy.rst │ │ │ │ │ ├── oop02_static_dispatching_only_policy.rst │ │ │ │ │ ├── oop03_limit_inheritance_hierarchy_depth.rst │ │ │ │ │ ├── oop04_limit_statically-dispatched_calls_to_primitive_operations.rst │ │ │ │ │ ├── oop05_use_explicit_overriding_annotations.rst │ │ │ │ │ ├── oop06_use_class-wide_pre-post_contracts.rst │ │ │ │ │ └── oop07_ensure_local_type_consistency.rst │ │ │ │ ├── robust_programming_practice.rst │ │ │ │ ├── robust_programming_practice │ │ │ │ │ ├── examples │ │ │ │ │ │ ├── rpp01.adb │ │ │ │ │ │ ├── rpp02.adb │ │ │ │ │ │ ├── rpp03.ads │ │ │ │ │ │ ├── rpp04.adb │ │ │ │ │ │ ├── rpp05.adb │ │ │ │ │ │ ├── rpp07.adb │ │ │ │ │ │ ├── rpp12.adb │ │ │ │ │ │ ├── rpp13.ads │ │ │ │ │ │ └── rpp14.ads │ │ │ │ │ ├── rpp01_no_use_of_others_in_case_constructs.rst │ │ │ │ │ ├── rpp02_no_enumeration_ranges_in_case_constructs.rst │ │ │ │ │ ├── rpp03_limited_use_of_others_in_aggregates.rst │ │ │ │ │ ├── rpp04_no_unassigned_mode-out_procedure_parameters.rst │ │ │ │ │ ├── rpp05_no_use_of_others_in_exception_handlers.rst │ │ │ │ │ ├── rpp06_avoid_function_side-effects.rst │ │ │ │ │ ├── rpp07_functions_only_have_mode_in.rst │ │ │ │ │ ├── rpp08_limit_parameter_aliasing.rst │ │ │ │ │ ├── rpp09_use_precondition_and_postcondition_contracts.rst │ │ │ │ │ ├── rpp10_do_not_re-verify_preconditions_in_subprogram_bodies.rst │ │ │ │ │ ├── rpp11_always_use_the_result_of_function_calls.rst │ │ │ │ │ ├── rpp12_no_recursion.rst │ │ │ │ │ ├── rpp13_no_reuse_of_standard_typemarks.rst │ │ │ │ │ └── rpp14_use_symbolic_constants_for_literal_values.rst │ │ │ │ ├── safe_reclamation.rst │ │ │ │ ├── safe_reclamation │ │ │ │ │ ├── rcl01_no_multiple_reclamations.rst │ │ │ │ │ ├── rcl02_only_reclaim_allocated_storage.rst │ │ │ │ │ └── rcl03_only_reclaim_to_the_same_pool.rst │ │ │ │ ├── software_engineering.rst │ │ │ │ └── software_engineering │ │ │ │ │ ├── examples │ │ │ │ │ ├── swe04.adb │ │ │ │ │ └── swe04.ads │ │ │ │ │ ├── swe01_use_spark_extensively.rst │ │ │ │ │ ├── swe02_enable_optional_warnings_and_treat_as_errors.rst │ │ │ │ │ ├── swe03_use_a_static_analysis_tool_extensively.rst │ │ │ │ │ └── swe04_hide_implementation_artifacts.rst │ │ │ ├── introduction.rst │ │ │ └── references.rst │ │ ├── conf.ini │ │ ├── conf.py │ │ ├── cover-A4.pdf │ │ ├── index.rst │ │ ├── make.bat │ │ ├── rules │ │ │ ├── README.md │ │ │ ├── lkql │ │ │ │ ├── README.md │ │ │ │ ├── function_out_parameters.lkql │ │ │ │ ├── overrides_standard_name.lkql │ │ │ │ ├── unhandled_exceptions.lkql │ │ │ │ └── uses_profile.lkql │ │ │ └── rules.txt │ │ └── tools │ │ │ └── generate_rules_file.py │ ├── SPARK_for_the_MISRA_C_Developer │ │ ├── chapters │ │ │ ├── 01_preface.rst │ │ │ ├── 02_program_consistency.rst │ │ │ ├── 03_syntactic_guarantees.rst │ │ │ ├── 04_strong_typing.rst │ │ │ ├── 05_initialization.rst │ │ │ ├── 06_side_effects.rst │ │ │ ├── 07_undefined_behavior.rst │ │ │ ├── 08_unreachable_and_dead_code.rst │ │ │ ├── 09_conclusion.rst │ │ │ └── 10_references.rst │ │ ├── conf.ini │ │ ├── cover-A4.pdf │ │ └── index.rst │ ├── ada-in-practice │ │ ├── chapters │ │ │ ├── abstract_data_machines.rst │ │ │ ├── abstract_data_types.rst │ │ │ ├── appendices.rst │ │ │ ├── component_access_to_rec_objs.rst │ │ │ ├── constructor_functions_for_abstract_data_types.rst │ │ │ ├── controlling_obj_initialization_creation.rst │ │ │ ├── essential_idioms_for_packages.rst │ │ │ ├── images │ │ │ │ ├── audio_device_architecture.png │ │ │ │ ├── task_release_using_entry_barrier.png │ │ │ │ └── task_release_using_suspension_object.png │ │ │ ├── inheritance_idioms.rst │ │ │ ├── interrupt_handling.rst │ │ │ ├── introduction.rst │ │ │ ├── programming_by_extension.rst │ │ │ ├── reducing_object_code_from_generic_package_instantiations.rst │ │ │ └── type_punning.rst │ │ ├── conf.ini │ │ ├── cover-A4.pdf │ │ ├── index.rst │ │ └── references.bib │ ├── advanced-ada │ │ ├── changelog.rst │ │ ├── conf.ini │ │ ├── cover-A4-temp.pdf │ │ ├── cover-A4.pdf │ │ ├── index.rst │ │ ├── index_hidden.rst │ │ └── parts │ │ │ ├── abstraction-oriented_prog │ │ │ ├── generics.rst │ │ │ ├── index.rst │ │ │ ├── oo_prog.rst │ │ │ ├── strong_typing.rst │ │ │ └── strong_typing_graph_01.dot │ │ │ ├── appendices │ │ │ ├── incompatibilities.rst │ │ │ ├── index.rst │ │ │ ├── legacy.rst │ │ │ ├── pragmas_aspects_attributes.rst │ │ │ ├── standard_packages.rst │ │ │ └── system_annexes.rst │ │ │ ├── control_flow │ │ │ ├── exceptions.rst │ │ │ ├── expressions.rst │ │ │ ├── index.rst │ │ │ ├── statements.rst │ │ │ └── subprograms.rst │ │ │ ├── data_types │ │ │ ├── aggregates.rst │ │ │ ├── arrays.rst │ │ │ ├── index.rst │ │ │ ├── numerics.rst │ │ │ ├── records.rst │ │ │ ├── shared_variable_control.rst │ │ │ ├── strings.rst │ │ │ ├── types.rst │ │ │ └── types_representation.rst │ │ │ ├── design_by_contracts │ │ │ ├── contracts.rst │ │ │ └── index.rst │ │ │ ├── initialization │ │ │ ├── elaboration_of_generics.rst │ │ │ ├── freezing.rst │ │ │ ├── index.rst │ │ │ └── package_elaboration.rst │ │ │ ├── interfacing_external │ │ │ ├── file_io.rst │ │ │ ├── index.rst │ │ │ └── interfacing_with_cpp.rst │ │ │ ├── modular_prog │ │ │ ├── index.rst │ │ │ ├── packages.rst │ │ │ └── subprograms_modularity.rst │ │ │ ├── multithreading │ │ │ ├── index.rst │ │ │ └── tasking.rst │ │ │ └── resource_management │ │ │ ├── access_types.rst │ │ │ ├── anonymous_access_types.rst │ │ │ ├── containers.rst │ │ │ ├── controlled_types.rst │ │ │ ├── index.rst │ │ │ ├── index_hidden.rst │ │ │ ├── limited_types.rst │ │ │ ├── memory_management.rst │ │ │ ├── restrictions.rst │ │ │ └── standard_containers.rst │ ├── advanced-spark │ │ ├── chapters │ │ │ ├── concurrency.rst │ │ │ ├── concurrent_program_struct_ada.png │ │ │ ├── concurrent_program_struct_ravenscar.png │ │ │ ├── ghost_code.rst │ │ │ ├── ghost_code_degree_of_automation.png │ │ │ ├── ghost_code_red_black.png │ │ │ ├── object_oriented_programming.rst │ │ │ ├── subprogram_contracts.rst │ │ │ ├── systems_programming.rst │ │ │ ├── test_and_proof.rst │ │ │ └── type_contracts.rst │ │ ├── conf.ini │ │ ├── cover-A4.pdf │ │ └── index.rst │ ├── global.txt │ ├── intro-to-ada │ │ ├── chapters │ │ │ ├── access_types.rst │ │ │ ├── appendices.rst │ │ │ ├── arrays.rst │ │ │ ├── contracts.rst │ │ │ ├── default.gpr │ │ │ ├── exceptions.rst │ │ │ ├── fixed_point_types.rst │ │ │ ├── generics.rst │ │ │ ├── gnatinspect.db │ │ │ ├── imperative_language.rst │ │ │ ├── interfacing_with_c.rst │ │ │ ├── introduction.rst │ │ │ ├── modular_programming.rst │ │ │ ├── more_about_records.rst │ │ │ ├── more_about_types.rst │ │ │ ├── object_oriented_programming.rst │ │ │ ├── privacy.rst │ │ │ ├── records.rst │ │ │ ├── standard_library_containers.rst │ │ │ ├── standard_library_dates_times.rst │ │ │ ├── standard_library_files_streams.rst │ │ │ ├── standard_library_numerics.rst │ │ │ ├── standard_library_strings.rst │ │ │ ├── strongly_typed_language.rst │ │ │ ├── subprograms.rst │ │ │ └── tasking.rst │ │ ├── conf.ini │ │ ├── cover-A4.pdf │ │ └── index.rst │ ├── intro-to-embedded-sys-prog │ │ ├── chapters │ │ │ ├── conclusion.rst │ │ │ ├── general_purpose_code_generators.rst │ │ │ ├── handling_interrupts.rst │ │ │ ├── images │ │ │ │ ├── idiom_1_diagram.png │ │ │ │ ├── idiom_2_diagram.png │ │ │ │ ├── lckr_and_lcck_for_gpio_pin_locking.png │ │ │ │ ├── memory-mapped-device.png │ │ │ │ ├── optimized-record-component-order.png │ │ │ │ ├── record_layout_with_rep_clause.png │ │ │ │ ├── scalar_types_tree.png │ │ │ │ └── unoptimized-record-component-order.png │ │ │ ├── interacting_with_devices.rst │ │ │ ├── introduction.rst │ │ │ ├── low_level_programming.rst │ │ │ └── multi_language_development.rst │ │ ├── conf.ini │ │ ├── cover-A4.pdf │ │ └── index.rst │ ├── intro-to-spark │ │ ├── chapters │ │ │ ├── 01_Overview.rst │ │ │ ├── 01_spark_ada.png │ │ │ ├── 02_Flow_Analysis.rst │ │ │ ├── 03_Proof_Of_Program_Integrity.rst │ │ │ ├── 04_State_Abstraction.rst │ │ │ ├── 05_Proof_Of_Functional_Correctness.rst │ │ │ └── 05_loop.png │ │ ├── conf.ini │ │ ├── cover-A4.pdf │ │ └── index.rst │ └── whats-new-in-ada-2022 │ │ ├── chapters │ │ ├── array_aggregates.rst │ │ ├── assignment_target.rst │ │ ├── big_numbers.rst │ │ ├── container_aggregates.rst │ │ ├── delta_aggregates.rst │ │ ├── enum_val.rst │ │ ├── image_attribute.rst │ │ ├── image_redefine.rst │ │ ├── importing_variadic_functions.rst │ │ ├── introduction.rst │ │ └── user_defined_literals.rst │ │ ├── conf.ini │ │ ├── cover-A4.pdf │ │ └── index.rst ├── hidden.txt ├── hidden_contents.txt ├── images │ ├── GNAT-Community-download.png │ ├── ada_horizon_logo │ │ ├── LICENSE │ │ ├── README.md │ │ ├── ada_horizon.svg │ │ └── ada_horizon_framed.svg │ ├── ada_training_logo.png │ ├── ccheart_black.png │ ├── gap_logo.png │ ├── page-1-of-Ada_For_The_CPP_Java_Developer.jpeg │ ├── page-1-of-Ada_For_The_Embedded_C_Developer.jpeg │ ├── page-1-of-GNAT_Toolchain_Intro.jpeg │ ├── page-1-of-Guidelines_for_Safe_and_Secure_Ada_SPARK.jpeg │ ├── page-1-of-SPARK_for_the_MISRA_C_Developer.jpeg │ ├── page-1-of-ada-in-practice.jpeg │ ├── page-1-of-advanced-ada-temp.jpeg │ ├── page-1-of-advanced-ada.jpeg │ ├── page-1-of-advanced-spark.jpeg │ ├── page-1-of-intro-to-ada-labs.jpeg │ ├── page-1-of-intro-to-ada.jpeg │ ├── page-1-of-intro-to-embedded-sys-prog.jpeg │ ├── page-1-of-intro-to-spark.jpeg │ ├── page-1-of-learning-ada.jpeg │ └── page-1-of-whats-new-in-ada-2022.jpeg ├── index.rst ├── labs │ ├── bug-free-coding │ │ ├── chapters │ │ │ ├── pile_of_dishes.png │ │ │ ├── pop_1.png │ │ │ ├── pop_2.png │ │ │ ├── pop_3.png │ │ │ ├── pop_4.png │ │ │ ├── push_1.png │ │ │ ├── push_2.png │ │ │ ├── push_3.png │ │ │ ├── push_4.png │ │ │ ├── push_5.png │ │ │ └── stack.rst │ │ ├── conf.ini │ │ └── index.rst │ └── intro-to-ada │ │ ├── chapters │ │ ├── arrays.rst │ │ ├── contracts.rst │ │ ├── exceptions.rst │ │ ├── generics.rst │ │ ├── imperative_language.rst │ │ ├── modular_programming.rst │ │ ├── more_about_types.rst │ │ ├── object_oriented_programming.rst │ │ ├── privacy.rst │ │ ├── records.rst │ │ ├── rotation.svg │ │ ├── solutions.rst │ │ ├── solutions │ │ │ ├── arrays.rst │ │ │ ├── contracts.rst │ │ │ ├── exceptions.rst │ │ │ ├── generics.rst │ │ │ ├── imperative_language.rst │ │ │ ├── modular_programming.rst │ │ │ ├── more_about_types.rst │ │ │ ├── object_oriented_programming.rst │ │ │ ├── privacy.rst │ │ │ ├── records.rst │ │ │ ├── standard_library_containers.rst │ │ │ ├── standard_library_dates_times.rst │ │ │ ├── standard_library_numerics.rst │ │ │ ├── standard_library_strings.rst │ │ │ ├── strongly_typed_language.rst │ │ │ ├── subprograms.rst │ │ │ └── tasking.rst │ │ ├── standard_library_containers.rst │ │ ├── standard_library_dates_times.rst │ │ ├── standard_library_numerics.rst │ │ ├── standard_library_strings.rst │ │ ├── strongly_typed_language.rst │ │ ├── subprograms.rst │ │ └── tasking.rst │ │ ├── conf.ini │ │ ├── cover-A4.pdf │ │ └── index.rst ├── learning_ada_cover-A4.pdf └── training_examples │ ├── fundamentals_of_ada │ ├── 020_declarations.rst │ ├── 020_declarations │ │ ├── aspect_clauses.rst │ │ ├── identifiers_comments_and_pragmas.rst │ │ ├── named_numbers.rst │ │ ├── numeric_literals.rst │ │ ├── object_declarations.rst │ │ └── scope_and_visibility.rst │ ├── 030_basic_types.rst │ ├── 030_basic_types │ │ ├── discrete_enumeration_types.rst │ │ ├── discrete_numeric_types.rst │ │ └── real_types.rst │ ├── 040_statements.rst │ ├── 040_statements │ │ ├── assignment_statements.rst │ │ ├── conditional_statements.rst │ │ └── loop_statements.rst │ ├── 050_array_types.rst │ ├── 050_array_types │ │ ├── aggregates.rst │ │ ├── attributes.rst │ │ ├── constrained_array_types.rst │ │ ├── operations.rst │ │ ├── operations_added_for_ada2012.rst │ │ └── unconstrained_array_types.rst │ ├── 060_record_types.rst │ ├── 060_record_types │ │ ├── aggregates.rst │ │ ├── components_rules.rst │ │ ├── default_values.rst │ │ ├── operations.rst │ │ └── variant_records.rst │ ├── 070_subprograms.rst │ ├── 070_subprograms │ │ ├── declarations_and_bodies.rst │ │ ├── expression_functions.rst │ │ ├── parameters.rst │ │ └── potential_pitfalls.rst │ ├── 080_expressions.rst │ ├── 080_expressions │ │ ├── conditional_expressions.rst │ │ ├── membership_tests.rst │ │ ├── quantified_expressions.rst │ │ ├── slices.rst │ │ └── subtypes.rst │ ├── 090_overloading.rst │ ├── 090_overloading │ │ ├── call_resolution.rst │ │ ├── composition_of_equality.rst │ │ ├── enumerals_and_operators.rst │ │ ├── user_defined_equality.rst │ │ └── visibility_issues.rst │ ├── 095_library_units.rst │ ├── 095_library_units │ │ ├── library_units.rst │ │ └── with_clauses.rst │ ├── 100_packages.rst │ ├── 100_packages │ │ ├── bodies.rst │ │ ├── declarations.rst │ │ ├── executable_parts.rst │ │ └── idioms.rst │ ├── 110_private_types.rst │ ├── 110_private_types │ │ ├── idioms.rst │ │ ├── implementing_abstract_data_types_via_views.rst │ │ └── private_part_construction.rst │ ├── 120_limited_types.rst │ ├── 120_limited_types │ │ ├── combining_limited_and_private_views.rst │ │ ├── creating_values.rst │ │ ├── declarations.rst │ │ └── extended_return_statements.rst │ ├── 130_program_structure.rst │ ├── 130_program_structure │ │ ├── hierarchical_library_units.rst │ │ ├── limited_with_clauses.rst │ │ ├── private_children.rst │ │ └── visibility_limits.rst │ ├── 135_visibility.rst │ ├── 135_visibility │ │ ├── use_all_type_clauses.rst │ │ ├── use_clauses.rst │ │ └── use_type_clauses.rst │ ├── 140_access_types.rst │ ├── 140_access_types │ │ ├── access_types.rst │ │ ├── accessibility_checks.rst │ │ ├── anonymous_access_types.rst │ │ ├── general_access_types.rst │ │ ├── memory_management.rst │ │ └── pool_specific_access_types.rst │ ├── 160_genericity.rst │ ├── 160_genericity │ │ ├── generic_data.rst │ │ └── generic_formal_data.rst │ ├── 170_inheritance.rst │ ├── 170_inheritance │ │ ├── primitives.rst │ │ ├── simple_derivation.rst │ │ └── tagged_derivation.rst │ ├── 180_polymorphism.rst │ ├── 180_polymorphism │ │ ├── classes_of_types.rst │ │ ├── dispatching_and_redispatching.rst │ │ └── exotic_dispatching_operations.rst │ ├── 190_exceptions.rst │ ├── 190_exceptions │ │ ├── exceptions_as_objects.rst │ │ ├── handlers.rst │ │ ├── implicitly_and_explicitly_raised_exceptions.rst │ │ ├── propagation.rst │ │ └── user_defined_exceptions.rst │ ├── 200_elaboration.rst │ ├── 200_elaboration │ │ ├── elaboration.rst │ │ └── elaboration_control.rst │ ├── 210_subprogram_contracts.rst │ ├── 210_subprogram_contracts │ │ └── preconditions_and_postconditions.rst │ ├── 215_type_contracts.rst │ ├── 215_type_contracts │ │ ├── subtype_predicates.rst │ │ └── type_invariants.rst │ ├── 220_low_level_programming.rst │ ├── 220_low_level_programming │ │ ├── address_clauses_and_overlays.rst │ │ └── data_representation.rst │ ├── 240_tasking.rst │ ├── 240_tasking │ │ ├── protected_objects.rst │ │ ├── some_advanced_concepts.rst │ │ ├── task_and_protected_types.rst │ │ └── tasks.rst │ └── index.rst │ └── training_examples.rst ├── frontend ├── .gitignore ├── .mocharc.json ├── .sass-lint.yml ├── .yarnrc.yml ├── Makefile ├── azw3_style.css ├── mocha.env ├── package.json ├── py_modules │ └── code_projects │ │ ├── README.md │ │ ├── __init__.py │ │ ├── blocks.py │ │ ├── check_code_block.py │ │ ├── check_projects.py │ │ ├── checks.py │ │ ├── colors.py │ │ ├── extract_projects.py │ │ ├── fmt_utils.py │ │ ├── toolchain.ini │ │ ├── toolchain_info.py │ │ └── toolchain_setup.py ├── requirements.txt ├── requirements_frozen.txt ├── sphinx │ ├── _epub_theme │ │ ├── epub-cover.html │ │ ├── layout.html │ │ ├── static │ │ │ ├── epub.css_t │ │ │ ├── graphviz.css_t │ │ │ └── pygments.css_t │ │ └── theme.conf │ ├── _templates │ │ ├── analytics.html │ │ ├── footer.html │ │ ├── layout.html │ │ └── metatags.html │ ├── code_block_info.py │ ├── conf.py │ ├── img │ │ ├── favicon.ico │ │ ├── learn_meta_img.jpeg │ │ ├── logo.png │ │ ├── logo.svg │ │ └── logo_sandbox.svg │ ├── tests │ │ ├── __init__.py │ │ ├── test_button.py │ │ ├── test_chop.py │ │ ├── test_resource.py │ │ └── test_widget.py │ ├── widget │ │ ├── __init__.py │ │ ├── button.py │ │ ├── chop.py │ │ ├── resource.py │ │ ├── templates │ │ │ └── widget.html │ │ └── widget.py │ └── widget_extension.py ├── src │ ├── index.ts │ ├── styles │ │ ├── _variables-dark.scss │ │ ├── _variables.scss │ │ ├── learn-dark.scss │ │ └── learn.scss │ └── ts │ │ ├── areas.ts │ │ ├── dom-utils.ts │ │ ├── download.ts │ │ ├── editor.ts │ │ ├── resource.ts │ │ ├── sandbox-redirect.ts │ │ ├── scrolltop.ts │ │ ├── server-types.ts │ │ ├── server.ts │ │ ├── strings.ts │ │ └── widget.ts ├── tests │ ├── .gitignore │ ├── code_block.py │ ├── colors.py │ ├── compile_blocks.py │ ├── execute_rst_code_blocks.py │ ├── rst │ │ ├── index.rst │ │ ├── lab.rst │ │ └── single.rst │ └── ts │ │ ├── areas.spec.ts │ │ ├── dom-utils.spec.ts │ │ ├── download.spec.ts │ │ ├── editor.spec.ts │ │ ├── scrolltop.spec.ts │ │ ├── server.spec.ts │ │ └── widget.spec.ts ├── tsconfig.json ├── vm_apt_epub.txt ├── vm_apt_web.txt ├── webpack.common.cjs ├── webpack.dev.cjs ├── webpack.prod.cjs └── yarn.lock └── internal ├── planning ├── gnat_toolchain.rst └── material_reuse.rst └── posts └── 2019-01-08_proving-memory-operations-a-spark-journey.rst /.gitattributes: -------------------------------------------------------------------------------- 1 | # Reclassify `.rst` files as Ada: 2 | *.rst linguist-language=Ada 3 | 4 | # Force files to use LF for EOL 5 | *.rst text eol=lf 6 | *.sh text eol=lf 7 | -------------------------------------------------------------------------------- /.github/workflows/publish-learn-latest.yml: -------------------------------------------------------------------------------- 1 | name: Publish learn-latest 2 | 3 | on: [push] 4 | 5 | jobs: 6 | trigger: 7 | runs-on: ubuntu-24.04 8 | 9 | strategy: 10 | matrix: 11 | python-version: ['3.12'] 12 | node-version: [22.x] 13 | 14 | steps: 15 | - name: Trigger publishing on learn-latest repo 16 | run: | 17 | # Set the required variables 18 | repo_owner="AdaCore" 19 | repo_name="learn-latest-html-pages" 20 | event_type="trigger-workflow" 21 | service="publish-learn-latest" 22 | version="${GITHUB_WORKFLOW_SHA}" 23 | 24 | curl -L \ 25 | -X POST \ 26 | -H "Accept: application/vnd.github+json" \ 27 | -H "Authorization: Bearer ${{ secrets.LEARN_LATEST_TOKEN }}" \ 28 | -H "X-GitHub-Api-Version: 2022-11-28" \ 29 | https://api.github.com/repos/$repo_owner/$repo_name/dispatches \ 30 | -d "{\"event_type\": \"$event_type\", \"client_payload\": {\"service\": \"$service\", \"version\": \"$version\", \"unit\": false, \"integration\": true}}" 31 | -------------------------------------------------------------------------------- /.github/workflows/sphinx-plugin-tests.js.yml: -------------------------------------------------------------------------------- 1 | name: Sphinx Plugin Tests 2 | 3 | on: 4 | push: 5 | paths: 6 | - 'frontend/sphinx/tests/**' 7 | - 'frontend/sphinx/widget/**' 8 | pull_request: 9 | branches: 10 | - master 11 | 12 | defaults: 13 | run: 14 | working-directory: frontend 15 | 16 | jobs: 17 | sphinx-plugin: 18 | 19 | runs-on: ubuntu-24.04 20 | 21 | strategy: 22 | matrix: 23 | python-version: ['3.12'] 24 | 25 | steps: 26 | - uses: actions/checkout@v4 27 | - name: Set up Python ${{ matrix.python-version }} 28 | uses: actions/setup-python@v5 29 | with: 30 | python-version: ${{ matrix.python-version }} 31 | - name: Install OS Deps 32 | run: | 33 | sudo apt-get update && \ 34 | sudo apt-get install -y \ 35 | crudini 36 | - name: Install GNAT FSF 37 | run: | 38 | ${GITHUB_WORKSPACE}/.github/workflows/install_toolchain.sh --gnat --gnatprove --gprbuild 39 | - name: Increase max user watches 40 | run: | 41 | echo fs.inotify.max_user_watches=524288 | sudo tee -a /etc/sysctl.conf && \ 42 | sudo sysctl -p 43 | - name: Install Python dependencies 44 | run: | 45 | python -m pip install --upgrade pip 46 | pip install -r requirements_frozen.txt 47 | - name: Test Sphinx Widget Parser Plugin 48 | run: make test_parser 49 | -------------------------------------------------------------------------------- /.github/workflows/typescript-tests.js.yml: -------------------------------------------------------------------------------- 1 | name: Typescript Test Suite 2 | 3 | on: 4 | push: 5 | paths: 6 | - 'frontend/**/*.ts' 7 | pull_request: 8 | branches: 9 | - master 10 | 11 | defaults: 12 | run: 13 | working-directory: frontend 14 | 15 | 16 | jobs: 17 | typescript-tests: 18 | 19 | runs-on: ubuntu-24.04 20 | 21 | strategy: 22 | matrix: 23 | python-version: ['3.12'] 24 | node-version: [22.x] 25 | 26 | steps: 27 | - uses: actions/checkout@v4 28 | - name: Set up Python ${{ matrix.python-version }} 29 | uses: actions/setup-python@v5 30 | with: 31 | python-version: ${{ matrix.python-version }} 32 | - uses: actions/checkout@v4 33 | - name: Enable Corepack 34 | run: corepack enable 35 | - name: Use Node.js ${{ matrix.node-version }} 36 | uses: actions/setup-node@v4 37 | with: 38 | node-version: ${{ matrix.node-version }} 39 | cache: 'yarn' 40 | cache-dependency-path: 'frontend' 41 | - name: Install OS Deps 42 | run: | 43 | sudo apt-get update && \ 44 | sudo apt-get install -y \ 45 | crudini 46 | - name: Install GNAT FSF 47 | run: | 48 | ${GITHUB_WORKSPACE}/.github/workflows/install_toolchain.sh --gnat --gnatprove --gprbuild 49 | - name: Increase max user watches 50 | run: | 51 | echo fs.inotify.max_user_watches=524288 | sudo tee -a /etc/sysctl.conf && \ 52 | sudo sysctl -p 53 | - name: Install dependencies 54 | run: yarn --immutable 55 | - name: Install Python dependencies 56 | run: | 57 | python -m pip install --upgrade pip 58 | pip install -r requirements_frozen.txt 59 | - name: Build HTML test pages 60 | run: make site-testing 61 | - name: Run Typescript tests 62 | run: yarn run cover 63 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | *.pyc 3 | env 4 | .idea 5 | .vagrant 6 | .vscode 7 | .yarn 8 | *.bkp 9 | *.log 10 | -------------------------------------------------------------------------------- /backend/.gitignore: -------------------------------------------------------------------------------- 1 | venv 2 | -------------------------------------------------------------------------------- /content/conf.ini: -------------------------------------------------------------------------------- 1 | [DEFAULT] 2 | title=Learning Ada 3 | author=Various authors 4 | latex_toplevel_sectioning=part 5 | epub_tocdepth=4 6 | cover_page=learning_ada_cover-A4.pdf 7 | -------------------------------------------------------------------------------- /content/courses/Ada_For_The_CPP_Java_Developer/chapters/13_Conclusion.rst: -------------------------------------------------------------------------------- 1 | Conclusion 2 | ------------- 3 | 4 | .. include:: ../../global.txt 5 | 6 | All the usual paradigms of imperative programming can be found in all three languages that we surveyed in this document. However, Ada is different from the rest in that it's more explicit when expressing properties and expectations. This is a good thing: being more formal affords better communication among programmers on a team and between programmers and machines. You also get more assurance of the coherence of a program at many levels. Ada can help reduce the cost of software maintenance by shifting the effort to creating a sound system the first time, rather than working harder, more often, and at greater expense, to fix bugs found later in systems already in production. Applications that have reliability needs, long term maintenance requirements, or safety/security concerns are those for which Ada has a proven track record. 7 | 8 | It's becoming increasingly common to find systems implemented in multiple languages, and Ada has standard interfacing facilities to allow Ada code to invoke subprograms and/or reference data structures from other language environments, or vice versa. Use of Ada thus allows easy interfacing between different technologies, using each for what it's best at. 9 | 10 | We hope this guide has provided some insight into the Ada software engineer's world and has made Ada more accessible to programmers already familiar with programming in other languages. 11 | -------------------------------------------------------------------------------- /content/courses/Ada_For_The_CPP_Java_Developer/chapters/14_References.rst: -------------------------------------------------------------------------------- 1 | :next_state: False 2 | 3 | References 4 | ------------- 5 | 6 | .. include:: ../../global.txt 7 | 8 | The Ada Information Clearinghouse website http://www.adaic.org/learn/materials/, maintained by the Ada Resource Association, contains links to a variety of training materials (books, articles, etc.) that can help in learning Ada. The Development Center page http://www.adacore.com/knowledge on AdaCore's website also contains links to useful information including vides and tutorials on Ada. 9 | 10 | The most comprehensive textbook is John Barnes' *Programming in Ada 2012*, which is oriented towards professional software developers. 11 | -------------------------------------------------------------------------------- /content/courses/Ada_For_The_CPP_Java_Developer/conf.ini: -------------------------------------------------------------------------------- 1 | [DEFAULT] 2 | title=Ada for the C++ and Java Developer 3 | author=Quentin Ochem 4 | cover_page=cover-A4.pdf 5 | -------------------------------------------------------------------------------- /content/courses/Ada_For_The_CPP_Java_Developer/cover-A4.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AdaCore/learn/e381c7badaed0c96ef1b8f95b1f8e5a6fdd755be/content/courses/Ada_For_The_CPP_Java_Developer/cover-A4.pdf -------------------------------------------------------------------------------- /content/courses/Ada_For_The_Embedded_C_Developer/conf.ini: -------------------------------------------------------------------------------- 1 | [DEFAULT] 2 | title=Ada for the Embedded C Developer 3 | author=Quentin Ochem \\and Robert Tice \\and Gustavo A. Hoffmann \\and Patrick Rogers. 4 | cover_page=cover-A4.pdf 5 | -------------------------------------------------------------------------------- /content/courses/Ada_For_The_Embedded_C_Developer/cover-A4.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AdaCore/learn/e381c7badaed0c96ef1b8f95b1f8e5a6fdd755be/content/courses/Ada_For_The_Embedded_C_Developer/cover-A4.pdf -------------------------------------------------------------------------------- /content/courses/GNAT_Toolchain_Intro/chapters/gnat_windows_build_opt.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AdaCore/learn/e381c7badaed0c96ef1b8f95b1f8e5a6fdd755be/content/courses/GNAT_Toolchain_Intro/chapters/gnat_windows_build_opt.png -------------------------------------------------------------------------------- /content/courses/GNAT_Toolchain_Intro/chapters/gnat_windows_build_run_opt.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AdaCore/learn/e381c7badaed0c96ef1b8f95b1f8e5a6fdd755be/content/courses/GNAT_Toolchain_Intro/chapters/gnat_windows_build_run_opt.png -------------------------------------------------------------------------------- /content/courses/GNAT_Toolchain_Intro/chapters/gnat_windows_project_debug_opt.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AdaCore/learn/e381c7badaed0c96ef1b8f95b1f8e5a6fdd755be/content/courses/GNAT_Toolchain_Intro/chapters/gnat_windows_project_debug_opt.png -------------------------------------------------------------------------------- /content/courses/GNAT_Toolchain_Intro/conf.ini: -------------------------------------------------------------------------------- 1 | [DEFAULT] 2 | title=Introduction to GNAT Toolchain 3 | author=Gustavo A. Hoffmann 4 | cover_page=cover-A4.pdf 5 | -------------------------------------------------------------------------------- /content/courses/GNAT_Toolchain_Intro/cover-A4.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AdaCore/learn/e381c7badaed0c96ef1b8f95b1f8e5a6fdd755be/content/courses/GNAT_Toolchain_Intro/cover-A4.pdf -------------------------------------------------------------------------------- /content/courses/Guidelines_for_Safe_and_Secure_Ada_SPARK/Makefile: -------------------------------------------------------------------------------- 1 | # Minimal makefile for Sphinx documentation 2 | # 3 | 4 | # You can set these variables from the command line, and also 5 | # from the environment for the first two. 6 | SPHINXOPTS ?= 7 | SPHINXBUILD ?= sphinx-build 8 | SOURCEDIR = . 9 | BUILDDIR = build 10 | 11 | # Put it first so that "make" without argument is like "make help". 12 | help: 13 | @$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O) 14 | 15 | .PHONY: help Makefile 16 | 17 | # Catch-all target: route all unknown targets to Sphinx using the new 18 | # "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS). 19 | %: Makefile 20 | @$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O) 21 | -------------------------------------------------------------------------------- /content/courses/Guidelines_for_Safe_and_Secure_Ada_SPARK/chapters/guidelines/concurrency/examples/con01.adb: -------------------------------------------------------------------------------- 1 | pragma Profile (Ravenscar); 2 | with Ada.Real_Time; use Ada.Real_Time; 3 | with Ada.Text_IO; use Ada.Text_IO; 4 | package body Con01 is 5 | 6 | package Noncompliant is 7 | task Task_T is 8 | end Task_T; 9 | end Noncompliant; 10 | 11 | package body Noncompliant is 12 | task body Task_T is 13 | begin 14 | loop 15 | -- Error: No_Relative_Delay 16 | delay 1.0; 17 | Put_Line ("Hello World"); 18 | end loop; 19 | end Task_T; 20 | end Noncompliant; 21 | 22 | package Compliant is 23 | task Task_T is 24 | end Task_T; 25 | end Compliant; 26 | 27 | package body Compliant is 28 | task body Task_T is 29 | Period : constant Time_Span := Milliseconds (10); 30 | Activation : Time := Clock; 31 | begin 32 | loop 33 | delay until Activation; 34 | Put_Line ("Hello World"); 35 | Activation := Activation + Period; 36 | end loop; 37 | end Task_T; 38 | end Compliant; 39 | 40 | procedure Example is 41 | begin 42 | null; 43 | end Example; 44 | 45 | end Con01; 46 | -------------------------------------------------------------------------------- /content/courses/Guidelines_for_Safe_and_Secure_Ada_SPARK/chapters/guidelines/concurrency/examples/con01.ads: -------------------------------------------------------------------------------- 1 | package Con01 is 2 | 3 | procedure Example with 4 | Inline; 5 | 6 | end Con01; 7 | -------------------------------------------------------------------------------- /content/courses/Guidelines_for_Safe_and_Secure_Ada_SPARK/chapters/guidelines/concurrency/examples/con02.adb: -------------------------------------------------------------------------------- 1 | pragma Profile (Jorvik); 2 | with Ada.Real_Time; use Ada.Real_Time; 3 | with Ada.Text_IO; use Ada.Text_IO; 4 | package body Con02 is 5 | 6 | package Noncompliant is 7 | task Task_T is 8 | entry Entry_Point; 9 | end Task_T; 10 | end Noncompliant; 11 | 12 | package body Noncompliant is 13 | task body Task_T is 14 | begin 15 | -- Error: Max_Task_Entries => 0 16 | accept Entry_Point do 17 | Put_Line ("Hello World"); 18 | end Entry_Point; 19 | loop 20 | delay 1.0; 21 | Put_Line ("Ping"); 22 | end loop; 23 | end Task_T; 24 | end Noncompliant; 25 | 26 | package Compliant is 27 | task Task_T is 28 | end Task_T; 29 | end Compliant; 30 | 31 | package body Compliant is 32 | task body Task_T is 33 | begin 34 | delay 1.0; 35 | Put_Line ("Hello World"); 36 | loop 37 | delay 1.0; 38 | Put_Line ("Ping"); 39 | end loop; 40 | end Task_T; 41 | end Compliant; 42 | 43 | procedure Example is 44 | begin 45 | null; 46 | end Example; 47 | 48 | end Con02; 49 | -------------------------------------------------------------------------------- /content/courses/Guidelines_for_Safe_and_Secure_Ada_SPARK/chapters/guidelines/concurrency/examples/con02.ads: -------------------------------------------------------------------------------- 1 | package Con02 is 2 | 3 | procedure Example with 4 | Inline; 5 | 6 | end Con02; 7 | -------------------------------------------------------------------------------- /content/courses/Guidelines_for_Safe_and_Secure_Ada_SPARK/chapters/guidelines/concurrency/examples/con03.ads: -------------------------------------------------------------------------------- 1 | with System.Storage_Elements; use System.Storage_Elements; 2 | package Con03 is 3 | 4 | package Noncompliant is 5 | Global_Object : Integer 6 | with Volatile; 7 | function Get return Integer is (Global_Object); 8 | end Noncompliant; 9 | 10 | package Compliant is 11 | Global_Object : Integer 12 | with Volatile, 13 | Address => To_Address (16#1234_5678#); 14 | function Get return Integer is (Global_Object); 15 | end Compliant; 16 | 17 | end Con03; 18 | -------------------------------------------------------------------------------- /content/courses/Guidelines_for_Safe_and_Secure_Ada_SPARK/chapters/guidelines/exception_usage/examples/exu01.adb: -------------------------------------------------------------------------------- 1 | procedure Exu01 (X : in out Integer) is 2 | Math_Overflow : exception; 3 | 4 | procedure Noncompliant (X : in out Integer) is 5 | begin 6 | if X < Integer'Last / 2 7 | then 8 | X := X * 2; 9 | else 10 | raise Constraint_Error; 11 | end if; 12 | end Noncompliant; 13 | 14 | procedure Compliant (X : in out Integer) is 15 | begin 16 | if X < Integer'Last / 2 17 | then 18 | X := X * 2; 19 | else 20 | raise Math_Overflow; 21 | end if; 22 | end Compliant; 23 | 24 | begin 25 | 26 | null; 27 | 28 | end Exu01; 29 | -------------------------------------------------------------------------------- /content/courses/Guidelines_for_Safe_and_Secure_Ada_SPARK/chapters/guidelines/exception_usage/examples/exu02.adb: -------------------------------------------------------------------------------- 1 | with Ada.Command_Line; use Ada.Command_Line; 2 | with Ada.Text_IO; use Ada.Text_IO; 3 | procedure Exu02 (X : Integer) is 4 | Application_Exception : exception; 5 | 6 | procedure Start_Application (Param : String) is null; 7 | 8 | package Noncompliant is 9 | Cli_Exception : exception; 10 | procedure Main; 11 | end Noncompliant; 12 | 13 | package Compliant is 14 | Cli_Exception : exception; 15 | procedure Main; 16 | end Compliant; 17 | 18 | package body Noncompliant is 19 | procedure Main is 20 | begin 21 | if Argument_Count = 0 then 22 | raise Cli_Exception; 23 | else 24 | begin 25 | Start_Application (Argument (1)); 26 | exception 27 | when Application_Exception => 28 | Put_Line ("Application failed"); 29 | end; 30 | end if; 31 | end Main; 32 | end Noncompliant; 33 | 34 | package body Compliant is 35 | procedure Main is 36 | begin 37 | if Argument_Count = 0 then 38 | raise Cli_Exception; 39 | else 40 | begin 41 | Start_Application (Argument (1)); 42 | exception 43 | when Application_Exception => 44 | Put_Line ("Application failed"); 45 | end; 46 | end if; 47 | exception 48 | when Cli_Exception => 49 | Put_Line ("Failure"); 50 | end Main; 51 | end Compliant; 52 | 53 | begin 54 | null; 55 | 56 | end Exu02; 57 | -------------------------------------------------------------------------------- /content/courses/Guidelines_for_Safe_and_Secure_Ada_SPARK/chapters/guidelines/exception_usage/examples/exu03.adb: -------------------------------------------------------------------------------- 1 | with Ada.Text_IO; use Ada.Text_IO; 2 | procedure Exu03 (X : in out Integer) is 3 | 4 | procedure Noncompliant (Param : in out Integer) is 5 | Noncompliant_Exception : exception; 6 | begin 7 | Param := Param * Param; 8 | exception 9 | when others => 10 | raise Noncompliant_Exception; 11 | end Noncompliant; 12 | 13 | procedure Bad_Call (Param : in out Integer) is 14 | begin 15 | Noncompliant (Param); 16 | exception 17 | when Noncompliant_Exception => -- compile error 18 | null; 19 | end Bad_Call; 20 | 21 | Compliant_Exception : exception; 22 | procedure Compliant (Param : in out Integer) is 23 | begin 24 | Param := Param * Param; 25 | exception 26 | when others => 27 | raise Compliant_Exception; 28 | end Compliant; 29 | 30 | procedure Good_Call (Param : in out Integer) is 31 | begin 32 | Compliant (Param); 33 | exception 34 | when Compliant_Exception => 35 | null; 36 | end Good_Call; 37 | 38 | begin 39 | null; 40 | exception 41 | when others => 42 | null; 43 | end Exu03; 44 | -------------------------------------------------------------------------------- /content/courses/Guidelines_for_Safe_and_Secure_Ada_SPARK/chapters/guidelines/object_oriented_programming/examples/oop04.adb: -------------------------------------------------------------------------------- 1 | procedure Oop04 is 2 | 3 | package Root is 4 | type Root_T is tagged null record; 5 | procedure Noncompliant (X : in out Root_T) is null; 6 | procedure Compliant (X : in out Root_T) is null; 7 | procedure Other_Prim (X : in out Root_T) is null; 8 | end Root; 9 | 10 | package Child is 11 | use Root; 12 | type Child_T is new Root_T with null record; 13 | procedure Noncompliant (X : in out Child_T); 14 | procedure Compliant (X : in out Child_T); 15 | procedure Other_Prim (X : in out Child_T); 16 | end Child; 17 | 18 | procedure Not_A_Primitive (X : in out Child.Child_T) is null; 19 | 20 | package body Child is 21 | 22 | procedure Noncompliant (X : in out Child_T) is 23 | begin 24 | Other_Prim (Root_T (X)); 25 | Other_Prim (X); 26 | end Noncompliant; 27 | 28 | procedure Compliant (X : in out Child_T) is 29 | begin 30 | Compliant (Root_T (X)); -- constructor style is OK 31 | Not_A_Primitive (X); 32 | end Compliant; 33 | 34 | procedure Other_Prim (X : in out Child_T) is null; 35 | end Child; 36 | 37 | begin 38 | 39 | null; 40 | 41 | end Oop04; 42 | -------------------------------------------------------------------------------- /content/courses/Guidelines_for_Safe_and_Secure_Ada_SPARK/chapters/guidelines/object_oriented_programming/examples/oop05.ads: -------------------------------------------------------------------------------- 1 | package Oop05 is 2 | 3 | type Root_T is tagged null record; 4 | procedure Primitive (X : in out Root_T) is null; 5 | 6 | type Noncompliant_Child_T is new Root_T with null record; 7 | procedure Primitive (X : in out Noncompliant_Child_T) is null; 8 | 9 | type Compliant_Child_T is new Root_T with null record; 10 | overriding procedure Primitive (X : in out Compliant_Child_T) is null; 11 | 12 | end Oop05; 13 | -------------------------------------------------------------------------------- /content/courses/Guidelines_for_Safe_and_Secure_Ada_SPARK/chapters/guidelines/object_oriented_programming/examples/oop06.adb: -------------------------------------------------------------------------------- 1 | procedure Oop06 is 2 | 3 | package Non_Compliant is 4 | type Root_T is tagged null record; 5 | procedure Set_Name (X : Root_T; 6 | Name : String) 7 | with Pre => Name'length > 0; 8 | function Get_Name (X : Root_T) return String 9 | with Post => Get_Name'result'length > 0; 10 | end Non_Compliant; 11 | 12 | package Compliant is 13 | type Root_T is tagged null record; 14 | procedure Set_Name (X : Root_T; 15 | Name : String) 16 | with Pre'class => Name'length > 0; 17 | function Get_Name (X : Root_T) return String 18 | with Post'class => Get_Name'result'length > 0; 19 | end Compliant; 20 | 21 | package body Non_Compliant is 22 | procedure Set_Name 23 | (X : Root_T; 24 | Name : String) is null; 25 | function Get_Name 26 | (X : Root_T) 27 | return String is ("***"); 28 | end Non_Compliant; 29 | 30 | package body Compliant is 31 | procedure Set_Name 32 | (X : Root_T; 33 | Name : String) is null; 34 | function Get_Name 35 | (X : Root_T) 36 | return String is ("***"); 37 | end Compliant; 38 | 39 | begin 40 | null; 41 | end Oop06; 42 | -------------------------------------------------------------------------------- /content/courses/Guidelines_for_Safe_and_Secure_Ada_SPARK/chapters/guidelines/robust_programming_practice/examples/rpp01.adb: -------------------------------------------------------------------------------- 1 | procedure Rpp01 (X : in out Character) is 2 | subtype Digit_T is Character range '0' .. '9'; 3 | 4 | procedure Noncompliant (C : in out Character) is 5 | begin 6 | case Digit_T (C) is 7 | when '0' | '9' => 8 | C := Character'succ (C); 9 | when others => 10 | C := Character'pred (C); 11 | end case; 12 | end Noncompliant; 13 | 14 | procedure Compliant (C : in out Character) is 15 | begin 16 | case Digit_T (C) is 17 | when '0' | '9' => 18 | C := Character'succ (C); 19 | when '1' | '2' | '3' | '4' | '5' | '6' | '7' | '8' => 20 | C := Character'pred (C); 21 | end case; 22 | end Compliant; 23 | 24 | begin 25 | Noncompliant (X); 26 | Compliant (X); 27 | end Rpp01; 28 | -------------------------------------------------------------------------------- /content/courses/Guidelines_for_Safe_and_Secure_Ada_SPARK/chapters/guidelines/robust_programming_practice/examples/rpp02.adb: -------------------------------------------------------------------------------- 1 | procedure Rpp02 (X : in out Character) is 2 | subtype Digit_T is Character range '0' .. '9'; 3 | 4 | procedure Noncompliant (C : in out Character) is 5 | begin 6 | case Digit_T (C) is 7 | when '0' | '9' => 8 | C := Character'Succ (C); 9 | when '1' .. '8' => 10 | C := Character'Pred (C); 11 | end case; 12 | end Noncompliant; 13 | 14 | procedure Compliant (C : in out Character) is 15 | begin 16 | case Digit_T (C) is 17 | when '0' | '9' => 18 | C := Character'Succ (C); 19 | when '1' | '2' | '3' | '4' | '5' | '6' | '7' | '8' => 20 | C := Character'Pred (C); 21 | end case; 22 | end Compliant; 23 | 24 | begin 25 | Noncompliant (X); 26 | Compliant (X); 27 | end Rpp02; 28 | -------------------------------------------------------------------------------- /content/courses/Guidelines_for_Safe_and_Secure_Ada_SPARK/chapters/guidelines/robust_programming_practice/examples/rpp03.ads: -------------------------------------------------------------------------------- 1 | package Rpp03 is 2 | 3 | package Noncompliant is 4 | type Record_T is record 5 | Field1 : Integer := 1; 6 | Field2 : Boolean := False; 7 | Field3 : Character := ' '; 8 | end record; 9 | type Array_T is array (Character) of Boolean; 10 | Rec : Record_T := (Field1 => 1, 11 | Field3 => '2', 12 | others => <>); 13 | Arr : Array_T := ('0' .. '9' => True, 14 | others => False); 15 | end Noncompliant; 16 | 17 | package Compliant is 18 | type Record_T is record 19 | Field1 : Integer := 1; 20 | Field2 : Boolean := False; 21 | Field3 : Character := ' '; 22 | end record; 23 | type Array_T is array (Character) of Boolean; 24 | Rec : Record_T := (Field1 => 1, 25 | others => <>); 26 | Arr : Array_T := (others => False); 27 | end Compliant; 28 | 29 | end Rpp03; 30 | -------------------------------------------------------------------------------- /content/courses/Guidelines_for_Safe_and_Secure_Ada_SPARK/chapters/guidelines/robust_programming_practice/examples/rpp04.adb: -------------------------------------------------------------------------------- 1 | procedure Rpp04 2 | (Register : Character; 3 | Registera : out Integer; 4 | Registerb : out Integer) is 5 | 6 | type Value_T is (Alpha, Baker, Charlie, Dog, Invalid); 7 | for Value_T use 8 | (Alpha => 2#1#, 9 | Baker => 2#10#, 10 | Charlie => 2#100#, 11 | Dog => 2#1000#, 12 | Invalid => 2#1111#); 13 | 14 | procedure Noncompliant (Register : Character; 15 | Registera : out Value_T; 16 | Registerb : out Value_T) is 17 | begin 18 | if Register = 'A' then 19 | Registera := Alpha; 20 | end if; 21 | end Noncompliant; 22 | 23 | procedure Compliant (Register : Character; 24 | Registera : out Value_T; 25 | Registerb : out Value_T) is 26 | begin 27 | Registera := Invalid; 28 | Registerb := Invalid; 29 | if Register = 'A' then 30 | Registera := Alpha; 31 | end if; 32 | end Compliant; 33 | 34 | A, B : Value_T; 35 | 36 | begin 37 | Noncompliant (Register, A, B); 38 | Compliant (Register, A, B); 39 | Registera := Value_T'enum_rep (A); 40 | Registerb := Value_T'enum_rep (B); 41 | 42 | end Rpp04; 43 | -------------------------------------------------------------------------------- /content/courses/Guidelines_for_Safe_and_Secure_Ada_SPARK/chapters/guidelines/robust_programming_practice/examples/rpp05.adb: -------------------------------------------------------------------------------- 1 | procedure Rpp05 (Value : in out Integer) is 2 | 3 | procedure Noncompliant (X : in out Integer) is 4 | begin 5 | X := X * X; 6 | exception 7 | when others => 8 | X := -1; 9 | end Noncompliant; 10 | 11 | procedure Compliant (X : in out Integer) is 12 | begin 13 | X := X * X; 14 | exception 15 | when Constraint_Error => 16 | X := -1; 17 | end Compliant; 18 | 19 | begin 20 | Noncompliant (Value); 21 | Compliant (Value); 22 | end Rpp05; 23 | -------------------------------------------------------------------------------- /content/courses/Guidelines_for_Safe_and_Secure_Ada_SPARK/chapters/guidelines/robust_programming_practice/examples/rpp07.adb: -------------------------------------------------------------------------------- 1 | procedure Rpp07 (X : in out Integer) is 2 | A, B : Integer; 3 | 4 | function Noncompliant (Value : in out Integer) return Integer is 5 | begin 6 | if Value < Integer'last then 7 | Value := Value + 1; 8 | end if; 9 | return Value; 10 | end Noncompliant; 11 | 12 | function Compliant (Value : Integer) return Integer is 13 | begin 14 | return Value + 1; 15 | end Compliant; 16 | 17 | procedure Compliant (Value : in out Integer) is 18 | begin 19 | if Value < Integer'last then 20 | Value := Value + 1; 21 | end if; 22 | end Compliant; 23 | 24 | begin 25 | A := X; 26 | B := Noncompliant (A); 27 | X := Compliant (B); 28 | end Rpp07; 29 | -------------------------------------------------------------------------------- /content/courses/Guidelines_for_Safe_and_Secure_Ada_SPARK/chapters/guidelines/robust_programming_practice/examples/rpp12.adb: -------------------------------------------------------------------------------- 1 | function Rpp12 2 | (Number : Positive) 3 | return Positive is 4 | 5 | A, B : Positive; 6 | 7 | function Noncompliant (N : Positive) return Positive is 8 | begin 9 | if N = 1 then 10 | return 1; 11 | else 12 | return N * Noncompliant (N - 1); -- could overflow 13 | end if; 14 | end Noncompliant; 15 | 16 | function Compliant (N : Positive) return Positive is 17 | Result : Positive := 1; 18 | begin 19 | for K in 2 .. N loop 20 | Result := Result * K; -- could overflow 21 | end loop; 22 | return Result; 23 | end Compliant; 24 | 25 | begin 26 | 27 | A := Noncompliant (Number); 28 | B := Compliant (Number); 29 | return A + B; 30 | 31 | end Rpp12; 32 | -------------------------------------------------------------------------------- /content/courses/Guidelines_for_Safe_and_Secure_Ada_SPARK/chapters/guidelines/robust_programming_practice/examples/rpp13.ads: -------------------------------------------------------------------------------- 1 | package Rpp13 is 2 | 3 | package Non_Compliant is 4 | type Boolean is range 0 .. 1 with Size => 1; 5 | type Character is ('A', 'E', 'I', 'O', 'U'); 6 | end Non_Compliant; 7 | 8 | package Compliant is 9 | type Boolean_T is range 0 .. 1 with Size => 1; 10 | type Character_T is ('A', 'E', 'I', 'O', 'U'); 11 | end Compliant; 12 | 13 | end Rpp13; 14 | -------------------------------------------------------------------------------- /content/courses/Guidelines_for_Safe_and_Secure_Ada_SPARK/chapters/guidelines/robust_programming_practice/examples/rpp14.ads: -------------------------------------------------------------------------------- 1 | package Rpp14 is 2 | 3 | package Non_Compliant is 4 | type Array_T is array (0 .. 31) of Boolean; 5 | function Any_Set (X : Array_T) return Boolean is 6 | (for some Flag in 0 .. 31 => X (Flag)); 7 | end Non_Compliant; 8 | 9 | package Compliant is 10 | Number_Of_Bits : constant := 32; 11 | type Array_T is array (0 .. Number_Of_Bits - 1) of Boolean; 12 | function Any_Set (X : Array_T) return Boolean is 13 | (for some Flag in X'Range => X (Flag)); 14 | end Compliant; 15 | 16 | end Rpp14; 17 | -------------------------------------------------------------------------------- /content/courses/Guidelines_for_Safe_and_Secure_Ada_SPARK/chapters/guidelines/safe_reclamation.rst: -------------------------------------------------------------------------------- 1 | 2 | ======================== 3 | Safe Reclamation (RCL) 4 | ======================== 5 | 6 | .. include:: ../../../global.txt 7 | 8 | *Goal* 9 | :Maintainability: :math:`\checkmark` 10 | :Reliability: :math:`\checkmark` 11 | :Portability: 12 | :Performance: :math:`\checkmark` 13 | :Security: :math:`\checkmark` 14 | 15 | Description 16 | Related to managing dynamic storage at the system (policy) level, these 17 | statement-level rules concern the safe reclamation of access (*pointer*) 18 | values. 19 | 20 | Rules 21 | RCL01, RCL02, RCL03 22 | 23 | .. toctree:: 24 | :maxdepth: 1 25 | 26 | No Multiple Reclamations (RCL01) 27 | Only Reclaim Allocated Storage (RCL02) 28 | Only Reclaim To The Same Pool (RCL03) 29 | -------------------------------------------------------------------------------- /content/courses/Guidelines_for_Safe_and_Secure_Ada_SPARK/chapters/guidelines/software_engineering.rst: -------------------------------------------------------------------------------- 1 | 2 | ============================ 3 | Software Engineering (SWE) 4 | ============================ 5 | 6 | .. include:: ../../../global.txt 7 | 8 | *Goal* 9 | :Maintainability: :math:`\checkmark` 10 | :Reliability: :math:`\checkmark` 11 | :Portability: :math:`\checkmark` 12 | :Performance: 13 | :Security: :math:`\checkmark` 14 | 15 | Description 16 | These rules promote "best practices" for software development. 17 | 18 | Rules 19 | SWE01, SWE02, SWE03, SWE04 20 | 21 | .. toctree:: 22 | :maxdepth: 1 23 | 24 | Use SPARK Extensively (SWE01) 25 | Enable Optional Warnings and Treat As Errors (SWE02) 26 | Use A Static Analysis Tool Extensively (SWE03) 27 | Hide Implementation Artifacts (SWE04) 28 | -------------------------------------------------------------------------------- /content/courses/Guidelines_for_Safe_and_Secure_Ada_SPARK/chapters/guidelines/software_engineering/examples/swe04.adb: -------------------------------------------------------------------------------- 1 | package body Swe04 is 2 | 3 | package body Noncompliant is 4 | 5 | procedure Push 6 | (Stack : in out Stack_T; 7 | Item : Integer) is 8 | begin 9 | Stack.Top := Stack.Top + 1; 10 | Stack.Content (Stack.Top) := Item; 11 | end Push; 12 | 13 | procedure Pop 14 | (Stack : in out Stack_T; 15 | Item : out Integer) is 16 | begin 17 | Item := Stack.Content (Stack.Top); 18 | Stack.Top := Stack.Top - 1; 19 | end Pop; 20 | 21 | end Noncompliant; 22 | 23 | package body Compliant is 24 | 25 | procedure Push 26 | (Stack : in out Stack_T; 27 | Item : Integer) is 28 | begin 29 | Stack.Top := Stack.Top + 1; 30 | Stack.Content (Stack.Top) := Item; 31 | end Push; 32 | 33 | procedure Pop 34 | (Stack : in out Stack_T; 35 | Item : out Integer) is 36 | begin 37 | Item := Stack.Content (Stack.Top); 38 | Stack.Top := Stack.Top - 1; 39 | end Pop; 40 | 41 | end Compliant; 42 | 43 | end Swe04; 44 | -------------------------------------------------------------------------------- /content/courses/Guidelines_for_Safe_and_Secure_Ada_SPARK/chapters/guidelines/software_engineering/examples/swe04.ads: -------------------------------------------------------------------------------- 1 | package Swe04 is 2 | 3 | type Capacity_T is range 0 .. 100; 4 | 5 | package Noncompliant is 6 | type Content_T is array (Capacity_T range <>) of Integer; 7 | type Stack_T (Capacity : Capacity_T) is tagged record 8 | Content : Content_T (1 .. Capacity); 9 | Top : Capacity_T := 0; 10 | end record; 11 | procedure Push 12 | (Stack : in out Stack_T; 13 | Item : Integer); 14 | procedure Pop 15 | (Stack : in out Stack_T; 16 | Item : out Integer); 17 | end Noncompliant; 18 | 19 | package Compliant is 20 | type Stack_T (Capacity : Capacity_T) is tagged private; 21 | procedure Push 22 | (Stack : in out Stack_T; 23 | Item : Integer); 24 | procedure Pop 25 | (Stack : in out Stack_T; 26 | Item : out Integer); 27 | private 28 | type Content_T is array (Capacity_T range <>) of Integer; 29 | type Stack_T (Capacity : Capacity_T) is tagged record 30 | Content : Content_T (1 .. Capacity); 31 | Top : Capacity_T := 0; 32 | end record; 33 | end Compliant; 34 | 35 | end Swe04; 36 | -------------------------------------------------------------------------------- /content/courses/Guidelines_for_Safe_and_Secure_Ada_SPARK/conf.ini: -------------------------------------------------------------------------------- 1 | [DEFAULT] 2 | title=Guidelines for Safe and Secure Ada / SPARK 3 | author=Patrick Rogers \\and Michael Frank 4 | cover_page=cover-A4.pdf 5 | 6 | -------------------------------------------------------------------------------- /content/courses/Guidelines_for_Safe_and_Secure_Ada_SPARK/cover-A4.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AdaCore/learn/e381c7badaed0c96ef1b8f95b1f8e5a6fdd755be/content/courses/Guidelines_for_Safe_and_Secure_Ada_SPARK/cover-A4.pdf -------------------------------------------------------------------------------- /content/courses/Guidelines_for_Safe_and_Secure_Ada_SPARK/make.bat: -------------------------------------------------------------------------------- 1 | @ECHO OFF 2 | 3 | pushd %~dp0 4 | 5 | REM Command file for Sphinx documentation 6 | 7 | if "%SPHINXBUILD%" == "" ( 8 | set SPHINXBUILD=sphinx-build 9 | ) 10 | set SOURCEDIR=. 11 | set BUILDDIR=build 12 | 13 | if "%1" == "" goto help 14 | 15 | %SPHINXBUILD% >NUL 2>NUL 16 | if errorlevel 9009 ( 17 | echo. 18 | echo.The 'sphinx-build' command was not found. Make sure you have Sphinx 19 | echo.installed, then set the SPHINXBUILD environment variable to point 20 | echo.to the full path of the 'sphinx-build' executable. Alternatively you 21 | echo.may add the Sphinx directory to PATH. 22 | echo. 23 | echo.If you don't have Sphinx installed, grab it from 24 | echo.http://sphinx-doc.org/ 25 | exit /b 1 26 | ) 27 | 28 | %SPHINXBUILD% -M %1 %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O% 29 | goto end 30 | 31 | :help 32 | %SPHINXBUILD% -M help %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O% 33 | 34 | :end 35 | popd 36 | -------------------------------------------------------------------------------- /content/courses/Guidelines_for_Safe_and_Secure_Ada_SPARK/rules/README.md: -------------------------------------------------------------------------------- 1 | This folder contains the sample GNATcheck rules file as well as the lkql subfolder 2 | which contains all non-standard rules implemented specifically for this coding standard. 3 | All lkql files should be copied into the $CODEPEER_INSTALL/share/lkql folder before 4 | running GNATcheck. 5 | -------------------------------------------------------------------------------- /content/courses/Guidelines_for_Safe_and_Secure_Ada_SPARK/rules/lkql/README.md: -------------------------------------------------------------------------------- 1 | The rules in this folder where specifically created for the 2 | Guidelines for Safe and Secure Ada/SPARK. 3 | 4 | Some of these rules are in the process of being added into the GNATcheck tool 5 | itself, while some of them are more related to this particular coding standard. 6 | The document is being updated (2024-10-08) to indicate which rules are built-in 7 | to GNATcheck, and which rules are specic to this document 8 | 9 | * function_out_parameters 10 | 11 | * will be added to GNATcheck 12 | 13 | * overrides_standard_name 14 | 15 | * will be added to GNATcheck 16 | 17 | * unhandled_exceptions 18 | 19 | * will remain as guideline-specific 20 | 21 | * uses_profile 22 | 23 | * will remain as guideline-specific 24 | -------------------------------------------------------------------------------- /content/courses/Guidelines_for_Safe_and_Secure_Ada_SPARK/rules/lkql/function_out_parameters.lkql: -------------------------------------------------------------------------------- 1 | fun has_out_params(s) = 2 | [p for p in s.p_params() if p.f_mode is ModeInOut or p.f_mode is ModeOut] 3 | 4 | @check(message="function has output parameter(s)") 5 | fun function_out_parameters(node) = 6 | node is (SubpBody or SubpBodyStub or ClassicSubpDecl or GenericSubpInternal) 7 | when (node is (ClassicSubpDecl or GenericSubpInternal) or 8 | not node.p_previous_part()) 9 | and node.f_subp_spec.f_subp_kind is SubpKindFunction 10 | and has_out_params(node.f_subp_spec) 11 | -------------------------------------------------------------------------------- /content/courses/Guidelines_for_Safe_and_Secure_Ada_SPARK/rules/lkql/overrides_standard_name.lkql: -------------------------------------------------------------------------------- 1 | fun is_standard(name) = 2 | name.p_name_is( "boolean" ) or 3 | name.p_name_is( "character" ) or 4 | name.p_name_is( "constraint_error" ) or 5 | name.p_name_is( "duration" ) or 6 | name.p_name_is( "float" ) or 7 | name.p_name_is( "integer" ) or 8 | name.p_name_is( "long_float" ) or 9 | name.p_name_is( "long_integer" ) or 10 | name.p_name_is( "long_long_float" ) or 11 | name.p_name_is( "long_long_integer" ) or 12 | name.p_name_is( "long_long_long_integer" ) or 13 | name.p_name_is( "natural" ) or 14 | name.p_name_is( "numeric_error" ) or 15 | name.p_name_is( "positive" ) or 16 | name.p_name_is( "program_error" ) or 17 | name.p_name_is( "short_float" ) or 18 | name.p_name_is( "short_integer" ) or 19 | name.p_name_is( "short_short_integer" ) or 20 | name.p_name_is( "standard" ) or 21 | name.p_name_is( "storage_error" ) or 22 | name.p_name_is( "string" ) or 23 | name.p_name_is( "tasking_error" ) or 24 | name.p_name_is( "wide_character" ) or 25 | name.p_name_is( "wide_string" ) or 26 | name.p_name_is( "wide_wide_character" ) or 27 | name.p_name_is( "wide_wide_string" ) 28 | 29 | @check 30 | fun overrides_standard_name(node) = 31 | node is DefiningName and 32 | is_standard ( node.f_name ) 33 | -------------------------------------------------------------------------------- /content/courses/Guidelines_for_Safe_and_Secure_Ada_SPARK/rules/lkql/unhandled_exceptions.lkql: -------------------------------------------------------------------------------- 1 | # Flag each user defined exception that does not have 2 | # a corresponding handler. 3 | 4 | @check(message="this user defined exception does not have a corresponding handler", 5 | category="Style", subcategory="Programming Practice") 6 | fun unhandled_exceptions(node) = 7 | match node 8 | | DefiningName(any parent is ExceptionDecl) => { 9 | val num_ref = node.p_find_all_references(units().to_list).length; 10 | num_ref < 2 11 | } 12 | | * => false 13 | -------------------------------------------------------------------------------- /content/courses/Guidelines_for_Safe_and_Secure_Ada_SPARK/rules/lkql/uses_profile.lkql: -------------------------------------------------------------------------------- 1 | # Flag where specified profile is used 2 | 3 | @memoized 4 | fun profile_name_matches ( assoc_list, profile ) = 5 | assoc_list.f_expr.p_name_is(profile) 6 | 7 | @unit_check(message="Pragma Profile found") 8 | fun uses_profile(unit, profile = "") = [ 9 | {message: "Pragma Profile (" & profile & ") found", 10 | loc: node} 11 | for node in from unit.root select p_node@PragmaNode 12 | when 13 | p_node.f_id?.p_name_is ("profile") and 14 | profile_name_matches ( p_node.f_args[1], profile ) 15 | ] 16 | -------------------------------------------------------------------------------- /content/courses/SPARK_for_the_MISRA_C_Developer/conf.ini: -------------------------------------------------------------------------------- 1 | [DEFAULT] 2 | title=SPARK for the MISRA-C Developer 3 | author=Yannick Moy 4 | cover_page=cover-A4.pdf 5 | -------------------------------------------------------------------------------- /content/courses/SPARK_for_the_MISRA_C_Developer/cover-A4.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AdaCore/learn/e381c7badaed0c96ef1b8f95b1f8e5a6fdd755be/content/courses/SPARK_for_the_MISRA_C_Developer/cover-A4.pdf -------------------------------------------------------------------------------- /content/courses/ada-in-practice/chapters/appendices.rst: -------------------------------------------------------------------------------- 1 | :orphan: 2 | 3 | :next_state: False 4 | 5 | Appendices 6 | ========== 7 | 8 | .. include:: ../../global.txt 9 | -------------------------------------------------------------------------------- /content/courses/ada-in-practice/chapters/images/audio_device_architecture.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AdaCore/learn/e381c7badaed0c96ef1b8f95b1f8e5a6fdd755be/content/courses/ada-in-practice/chapters/images/audio_device_architecture.png -------------------------------------------------------------------------------- /content/courses/ada-in-practice/chapters/images/task_release_using_entry_barrier.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AdaCore/learn/e381c7badaed0c96ef1b8f95b1f8e5a6fdd755be/content/courses/ada-in-practice/chapters/images/task_release_using_entry_barrier.png -------------------------------------------------------------------------------- /content/courses/ada-in-practice/chapters/images/task_release_using_suspension_object.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AdaCore/learn/e381c7badaed0c96ef1b8f95b1f8e5a6fdd755be/content/courses/ada-in-practice/chapters/images/task_release_using_suspension_object.png -------------------------------------------------------------------------------- /content/courses/ada-in-practice/conf.ini: -------------------------------------------------------------------------------- 1 | [DEFAULT] 2 | title=Ada In Practice 3 | author=Patrick Rogers 4 | bibtex_file=references.bib 5 | cover_page=cover-A4.pdf 6 | 7 | -------------------------------------------------------------------------------- /content/courses/ada-in-practice/cover-A4.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AdaCore/learn/e381c7badaed0c96ef1b8f95b1f8e5a6fdd755be/content/courses/ada-in-practice/cover-A4.pdf -------------------------------------------------------------------------------- /content/courses/advanced-ada/conf.ini: -------------------------------------------------------------------------------- 1 | [DEFAULT] 2 | title=Advanced Journey With Ada: A Flight In Progress 3 | author=Gustavo A. Hoffmann \\and Robert A. Duff 4 | cover_page=cover-A4-temp.pdf 5 | latex_toplevel_sectioning=part 6 | 7 | -------------------------------------------------------------------------------- /content/courses/advanced-ada/cover-A4-temp.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AdaCore/learn/e381c7badaed0c96ef1b8f95b1f8e5a6fdd755be/content/courses/advanced-ada/cover-A4-temp.pdf -------------------------------------------------------------------------------- /content/courses/advanced-ada/cover-A4.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AdaCore/learn/e381c7badaed0c96ef1b8f95b1f8e5a6fdd755be/content/courses/advanced-ada/cover-A4.pdf -------------------------------------------------------------------------------- /content/courses/advanced-ada/index_hidden.rst: -------------------------------------------------------------------------------- 1 | :prev_state: False 2 | :next_state: False 3 | 4 | Advanced Journey With Ada: A Flight In Progress (UNPUBLISHED) 5 | ============================================================= 6 | 7 | .. include:: ../global.txt 8 | 9 | .. only:: no_hidden_books 10 | 11 | .. meta:: 12 | :robots: noindex, nofollow 13 | 14 | .. warning:: 15 | 16 | This version of the website contains UNPUBLISHED contents. 17 | 18 | .. toctree:: 19 | :maxdepth: 4 20 | :caption: Unpublished Contents 21 | 22 | parts/resource_management/index_hidden 23 | parts/abstraction-oriented_prog/index 24 | parts/design_by_contracts/index 25 | parts/initialization/index 26 | parts/multithreading/index 27 | parts/interfacing_external/index 28 | parts/appendices/index 29 | -------------------------------------------------------------------------------- /content/courses/advanced-ada/parts/abstraction-oriented_prog/index.rst: -------------------------------------------------------------------------------- 1 | Abstraction-oriented programming 2 | ******************************** 3 | 4 | .. toctree:: 5 | :maxdepth: 3 6 | 7 | strong_typing 8 | oo_prog 9 | generics 10 | -------------------------------------------------------------------------------- /content/courses/advanced-ada/parts/appendices/incompatibilities.rst: -------------------------------------------------------------------------------- 1 | :orphan: 2 | 3 | Incompatibilities between Ada standards 4 | ======================================= 5 | 6 | .. include:: ../../../global.txt 7 | 8 | .. 9 | REMOVED! TO BE RE-EVALUATED IN 2025: 10 | 11 | Incompatibilities between Ada 83 and Ada 95 12 | ------------------------------------------- 13 | 14 | .. note:: 15 | 16 | This section was originally written by Robert Dewar and published as 17 | `Gem #46: Incompatibilities between Ada 83 and Ada 95 by Robert Dewar `_. 18 | -------------------------------------------------------------------------------- /content/courses/advanced-ada/parts/appendices/index.rst: -------------------------------------------------------------------------------- 1 | Appendices 2 | ********** 3 | 4 | .. toctree:: 5 | :maxdepth: 3 6 | 7 | legacy 8 | 9 | .. 10 | REMOVED! TO BE RE-EVALUATED IN 2025: 11 | 12 | system_annexes 13 | pragmas_aspects_attributes 14 | standard_packages 15 | incompatibilities 16 | -------------------------------------------------------------------------------- /content/courses/advanced-ada/parts/appendices/pragmas_aspects_attributes.rst: -------------------------------------------------------------------------------- 1 | :orphan: 2 | 3 | Pragmas, Aspects and Attributes 4 | =============================== 5 | 6 | .. include:: ../../../global.txt 7 | 8 | .. admonition:: Relevant topics 9 | 10 | - **Notes** 11 | 12 | - Include link to parts of the book where some of the elements below 13 | are explained 14 | 15 | - otherwise, *maybe* explain them briefly in this chapter 16 | 17 | - Point to the RM if an element is not explained neither in this 18 | chapter nor mentioned elsewhere in the book. 19 | 20 | .. 21 | REMOVED! TO BE RE-EVALUATED IN 2025: 22 | 23 | Pragmas 24 | ------- 25 | 26 | .. admonition:: Relevant topics 27 | 28 | - List of pragmas 29 | 30 | 31 | .. 32 | REMOVED! TO BE RE-EVALUATED IN 2025: 33 | 34 | Aspects 35 | ------- 36 | 37 | .. admonition:: Relevant topics 38 | 39 | - List of aspects 40 | 41 | - Include link to parts of the book where some of the aspects 42 | are explained 43 | 44 | 45 | .. 46 | REMOVED! TO BE RE-EVALUATED IN 2025: 47 | 48 | Attributes 49 | ---------- 50 | 51 | .. admonition:: Relevant topics 52 | 53 | - List of attributes 54 | 55 | - Include link to parts of the book where some of the attribute 56 | are explained 57 | -------------------------------------------------------------------------------- /content/courses/advanced-ada/parts/appendices/standard_packages.rst: -------------------------------------------------------------------------------- 1 | :orphan: 2 | 3 | Standard Packages 4 | ================= 5 | 6 | .. include:: ../../../global.txt 7 | 8 | .. admonition:: Relevant topics 9 | 10 | - **Notes** 11 | 12 | - Include link to parts of the book where some of the elements below 13 | are explained 14 | 15 | - otherwise, *maybe* explain them briefly in this chapter 16 | 17 | - Point to the RM if an element is not explained neither in this 18 | chapter nor mentioned elsewhere in the book. 19 | 20 | 21 | .. 22 | REMOVED! TO BE RE-EVALUATED IN 2025: 23 | 24 | :ada:`Ada` packages 25 | ------------------- 26 | 27 | .. admonition:: Relevant topics 28 | 29 | - List of :ada:`Ada.*` packages 30 | 31 | - For example, :ada:`Ada.Directories` and 32 | :ada:`Ada.Environment_Variables` packages. 33 | 34 | - Include link to parts of the book where these packages are explained. 35 | 36 | .. 37 | REMOVED! TO BE RE-EVALUATED IN 2025: 38 | 39 | :ada:`System` packages 40 | ---------------------- 41 | 42 | .. admonition:: Relevant topics 43 | 44 | - List of :ada:`System.*` packages 45 | 46 | - For example, :ada:`System.Storage_Elements` and 47 | :ada:`System.Address_To_Access_Conversions` packages. 48 | 49 | - Include link to parts of the book where these packages are explained. 50 | 51 | .. 52 | REMOVED! TO BE RE-EVALUATED IN 2025: 53 | 54 | :ada:`Interfaces` packages 55 | -------------------------- 56 | 57 | .. admonition:: Relevant topics 58 | 59 | - List of :ada:`Interfaces.*` packages 60 | 61 | - Include link to parts of the book where these packages are explained. 62 | -------------------------------------------------------------------------------- /content/courses/advanced-ada/parts/appendices/system_annexes.rst: -------------------------------------------------------------------------------- 1 | :orphan: 2 | 3 | System Annexes 4 | ============== 5 | 6 | .. include:: ../../../global.txt 7 | 8 | .. 9 | REMOVED! TO BE RE-EVALUATED IN 2025: 10 | 11 | Real-Time Systems Annex 12 | ----------------------- 13 | 14 | .. admonition:: Relevant topics 15 | 16 | - Brief explanation of the Real-Time Systems Annex 17 | 18 | 19 | .. 20 | REMOVED! TO BE RE-EVALUATED IN 2025: 21 | 22 | Distributed Systems Annex 23 | ------------------------- 24 | 25 | .. admonition:: Relevant topics 26 | 27 | - Brief explanation of the Distributed Systems Annex 28 | 29 | 30 | .. 31 | REMOVED! TO BE RE-EVALUATED IN 2025: 32 | 33 | High Integrity Systems Annex 34 | ---------------------------- 35 | 36 | .. admonition:: Relevant topics 37 | 38 | - Brief explanation of the High Integrity Systems Annex 39 | -------------------------------------------------------------------------------- /content/courses/advanced-ada/parts/control_flow/index.rst: -------------------------------------------------------------------------------- 1 | Control Flow 2 | ************ 3 | 4 | .. toctree:: 5 | :maxdepth: 3 6 | 7 | expressions 8 | statements 9 | subprograms 10 | exceptions 11 | -------------------------------------------------------------------------------- /content/courses/advanced-ada/parts/data_types/index.rst: -------------------------------------------------------------------------------- 1 | Data types 2 | ********** 3 | 4 | .. toctree:: 5 | :maxdepth: 3 6 | 7 | types 8 | types_representation 9 | shared_variable_control 10 | records 11 | aggregates 12 | arrays 13 | strings 14 | numerics 15 | -------------------------------------------------------------------------------- /content/courses/advanced-ada/parts/design_by_contracts/contracts.rst: -------------------------------------------------------------------------------- 1 | Contracts 2 | ========= 3 | 4 | .. include:: ../../../global.txt 5 | 6 | Class-wide contracts 7 | -------------------- 8 | 9 | .. todo:: 10 | 11 | Complete section! 12 | 13 | 14 | Default initial conditions 15 | -------------------------- 16 | 17 | .. admonition:: Relevant topics 18 | 19 | - :arm22:`Default Initial Conditions <7-3-3>` 20 | 21 | .. todo:: 22 | 23 | Complete section! 24 | 25 | 26 | Entry index attribute 27 | --------------------- 28 | 29 | .. admonition:: Relevant topics 30 | 31 | - :ada:`E'Index` mentioned in 32 | :arm22:`Preconditions and Postconditions <6-1-1>` 33 | 34 | .. todo:: 35 | 36 | Complete section! 37 | 38 | 39 | Global Aspect Definition 40 | ------------------------ 41 | 42 | .. admonition:: Relevant topics 43 | 44 | - :arm22:`The Global and Global'Class Aspects <6-1-2.html>` 45 | 46 | .. todo:: 47 | 48 | Complete section! 49 | 50 | 51 | Predicate failure 52 | ----------------- 53 | 54 | .. admonition:: Relevant topics 55 | 56 | - :ada:`Predicate_Failure` mentioned in 57 | :arm22:`Subtype Predicates <3-2-4>` 58 | 59 | .. todo:: 60 | 61 | Complete section! 62 | 63 | 64 | Stable Properties of a Type 65 | --------------------------- 66 | 67 | .. admonition:: In the Ada Reference Manual 68 | 69 | - :arm22:`Stable Properties of a Type <7-3-4>` 70 | 71 | .. todo:: 72 | 73 | Complete section! 74 | 75 | 76 | -------------------------------------------------------------------------------- /content/courses/advanced-ada/parts/design_by_contracts/index.rst: -------------------------------------------------------------------------------- 1 | Design by contract 2 | ****************** 3 | 4 | .. toctree:: 5 | :maxdepth: 3 6 | 7 | contracts 8 | -------------------------------------------------------------------------------- /content/courses/advanced-ada/parts/initialization/elaboration_of_generics.rst: -------------------------------------------------------------------------------- 1 | Elaboration Of Generics 2 | ======================= 3 | 4 | .. include:: ../../../global.txt 5 | 6 | Elaboration check 7 | ----------------- 8 | 9 | .. admonition:: Relevant topics 10 | 11 | - Elaboration check mentioned in 12 | :arm22:`Generic Bodies <12-2>` 13 | 14 | .. todo:: 15 | 16 | Complete section! 17 | -------------------------------------------------------------------------------- /content/courses/advanced-ada/parts/initialization/freezing.rst: -------------------------------------------------------------------------------- 1 | Freezing 2 | ======== 3 | 4 | .. include:: ../../../global.txt 5 | 6 | Freezing rules 7 | -------------- 8 | 9 | .. admonition:: Relevant topics 10 | 11 | - :arm22:`Freezing rules <13-14>` 12 | 13 | .. todo:: 14 | 15 | Complete section! 16 | 17 | -------------------------------------------------------------------------------- /content/courses/advanced-ada/parts/initialization/index.rst: -------------------------------------------------------------------------------- 1 | Initialization 2 | ************** 3 | 4 | .. toctree:: 5 | :maxdepth: 3 6 | 7 | freezing 8 | package_elaboration 9 | elaboration_of_generics 10 | -------------------------------------------------------------------------------- /content/courses/advanced-ada/parts/initialization/package_elaboration.rst: -------------------------------------------------------------------------------- 1 | Package Elaboration 2 | =================== 3 | 4 | .. include:: ../../../global.txt 5 | 6 | .. _Adv_Ada_Preelaboration: 7 | 8 | Preelaboration 9 | -------------- 10 | 11 | .. admonition:: Relevant topics 12 | 13 | - Pure packages 14 | - :arm22:`Preelaboration Requirements ` 15 | 16 | .. todo:: 17 | 18 | Complete section! 19 | 20 | 21 | Elaboration control 22 | ------------------- 23 | 24 | .. admonition:: Relevant topics 25 | 26 | - :arm22:`Elaboration control <10-2-1>` 27 | - :arm22:`Elaboration Control Pragmas ` 28 | - GNAT's static model 29 | 30 | .. todo:: 31 | 32 | Complete section! 33 | 34 | 35 | .. _Adv_Ada_Pure: 36 | 37 | Pure program and library units 38 | ------------------------------ 39 | 40 | .. admonition:: Relevant topics 41 | 42 | - :arm22:`C.4 Preelaboration Requirements ` 43 | - :arm22:`10.2.1 Elaboration Control <10-2-1>` 44 | - Add link to :ref:`Adv_Ada_Preelaboration` section 45 | 46 | .. todo:: 47 | 48 | Complete section! 49 | 50 | -------------------------------------------------------------------------------- /content/courses/advanced-ada/parts/interfacing_external/file_io.rst: -------------------------------------------------------------------------------- 1 | File I/O 2 | ======== 3 | 4 | .. include:: ../../../global.txt 5 | 6 | Efficient Stream I/O for Array Types 7 | ------------------------------------ 8 | 9 | .. note:: 10 | 11 | This section was originally written by Patrick Rogers and published as 12 | `Gem #39: Efficient Stream I/O for Array Types by Pat Rogers `_ 13 | 14 | .. todo:: 15 | 16 | Complete section! 17 | 18 | 19 | Container streaming 20 | ------------------- 21 | 22 | .. todo:: 23 | 24 | Complete section! 25 | -------------------------------------------------------------------------------- /content/courses/advanced-ada/parts/interfacing_external/index.rst: -------------------------------------------------------------------------------- 1 | Interfacing with the external world 2 | *********************************** 3 | 4 | .. toctree:: 5 | :maxdepth: 3 6 | 7 | file_io 8 | interfacing_with_cpp 9 | -------------------------------------------------------------------------------- /content/courses/advanced-ada/parts/modular_prog/index.rst: -------------------------------------------------------------------------------- 1 | Modular programming 2 | ******************* 3 | 4 | .. toctree:: 5 | :maxdepth: 3 6 | 7 | packages 8 | subprograms_modularity 9 | -------------------------------------------------------------------------------- /content/courses/advanced-ada/parts/multithreading/index.rst: -------------------------------------------------------------------------------- 1 | Multithreading 2 | ************** 3 | 4 | .. toctree:: 5 | :maxdepth: 3 6 | 7 | tasking 8 | -------------------------------------------------------------------------------- /content/courses/advanced-ada/parts/resource_management/index.rst: -------------------------------------------------------------------------------- 1 | Resource Management 2 | ******************* 3 | 4 | .. toctree:: 5 | :maxdepth: 3 6 | 7 | access_types 8 | anonymous_access_types 9 | limited_types 10 | controlled_types 11 | -------------------------------------------------------------------------------- /content/courses/advanced-ada/parts/resource_management/index_hidden.rst: -------------------------------------------------------------------------------- 1 | Resource Management 2 | ******************* 3 | 4 | .. toctree:: 5 | :maxdepth: 3 6 | 7 | memory_management 8 | containers 9 | standard_containers 10 | restrictions 11 | -------------------------------------------------------------------------------- /content/courses/advanced-ada/parts/resource_management/restrictions.rst: -------------------------------------------------------------------------------- 1 | Restrictions and Profiles 2 | ========================= 3 | 4 | .. include:: ../../../global.txt 5 | 6 | Pragmas 7 | ------- 8 | 9 | .. admonition:: Relevant topics 10 | 11 | - :arm22:`Pragma Restrictions and Pragma Profile <13-12>` 12 | - :arm22:`Dependence Restriction Identifiers ` 13 | 14 | .. todo:: 15 | 16 | Complete section! 17 | 18 | 19 | Language-Defined Restrictions and Profiles 20 | ------------------------------------------ 21 | 22 | .. admonition:: Relevant topics 23 | 24 | - :arm22:`Language-Defined Restrictions and Profiles <13-12-1>` 25 | 26 | .. todo:: 27 | 28 | Complete section! 29 | -------------------------------------------------------------------------------- /content/courses/advanced-ada/parts/resource_management/standard_containers.rst: -------------------------------------------------------------------------------- 1 | Standard Containers 2 | =================== 3 | 4 | .. include:: ../../../global.txt 5 | 6 | Linked lists 7 | ------------ 8 | 9 | .. admonition:: Relevant topics 10 | 11 | - :arm22:`Containers.Doubly_Linked_Lists ` 12 | 13 | .. todo:: 14 | 15 | Complete section! 16 | 17 | Trees 18 | ----- 19 | 20 | .. admonition:: Relevant topics 21 | 22 | - :arm22:`Containers.Multiway_Trees ` 23 | 24 | .. todo:: 25 | 26 | Complete section! 27 | 28 | Queue containers 29 | ---------------- 30 | 31 | .. admonition:: Relevant topics 32 | 33 | - :arm22:`Containers.Synchronized_Queue_Interfaces ` 34 | - :arm22:`Containers.Unbounded_Synchronized_Queues ` 35 | - :arm22:`Containers.Bounded_Synchronized_Queues ` 36 | - :arm22:`Containers.Unbounded_Priority_Queues ` 37 | - :arm22:`Containers.Bounded_Priority_Queues ` 38 | 39 | .. todo:: 40 | 41 | Complete section! 42 | 43 | 44 | Indefinite containers 45 | --------------------- 46 | 47 | .. admonition:: Relevant topics 48 | 49 | - :rat05:`Indefinite containers <8-5>` 50 | 51 | .. todo:: 52 | 53 | Complete section! 54 | 55 | 56 | Holder container 57 | ---------------- 58 | 59 | .. admonition:: Relevant topics 60 | 61 | - :arm22:`Containers.Indefinite_Holders ` 62 | 63 | .. todo:: 64 | 65 | Complete section! 66 | -------------------------------------------------------------------------------- /content/courses/advanced-spark/chapters/concurrent_program_struct_ada.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AdaCore/learn/e381c7badaed0c96ef1b8f95b1f8e5a6fdd755be/content/courses/advanced-spark/chapters/concurrent_program_struct_ada.png -------------------------------------------------------------------------------- /content/courses/advanced-spark/chapters/concurrent_program_struct_ravenscar.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AdaCore/learn/e381c7badaed0c96ef1b8f95b1f8e5a6fdd755be/content/courses/advanced-spark/chapters/concurrent_program_struct_ravenscar.png -------------------------------------------------------------------------------- /content/courses/advanced-spark/chapters/ghost_code_degree_of_automation.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AdaCore/learn/e381c7badaed0c96ef1b8f95b1f8e5a6fdd755be/content/courses/advanced-spark/chapters/ghost_code_degree_of_automation.png -------------------------------------------------------------------------------- /content/courses/advanced-spark/chapters/ghost_code_red_black.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AdaCore/learn/e381c7badaed0c96ef1b8f95b1f8e5a6fdd755be/content/courses/advanced-spark/chapters/ghost_code_red_black.png -------------------------------------------------------------------------------- /content/courses/advanced-spark/conf.ini: -------------------------------------------------------------------------------- 1 | [DEFAULT] 2 | title=Advanced SPARK 3 | author=Patrick Rogers 4 | cover_page=cover-A4.pdf 5 | 6 | -------------------------------------------------------------------------------- /content/courses/advanced-spark/cover-A4.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AdaCore/learn/e381c7badaed0c96ef1b8f95b1f8e5a6fdd755be/content/courses/advanced-spark/cover-A4.pdf -------------------------------------------------------------------------------- /content/courses/global.txt: -------------------------------------------------------------------------------- 1 | .. role:: ada(code) 2 | :language: ada 3 | :class: highlight 4 | 5 | .. role:: c(code) 6 | :language: c 7 | :class: highlight 8 | 9 | .. role:: cpp(code) 10 | :language: c++ 11 | :class: highlight 12 | 13 | .. role:: java(code) 14 | :language: java 15 | :class: highlight 16 | 17 | .. role:: assembly(code) 18 | 19 | .. role:: rule(code) 20 | 21 | .. role:: switch(code) 22 | :language: console 23 | :class: highlight 24 | 25 | .. include:: 26 | 27 | .. include:: 28 | -------------------------------------------------------------------------------- /content/courses/intro-to-ada/chapters/default.gpr: -------------------------------------------------------------------------------- 1 | project Default is 2 | 3 | package Compiler is 4 | for Switches ("Ada") use ("-g", "-O2"); 5 | end Compiler; 6 | 7 | end Default; 8 | -------------------------------------------------------------------------------- /content/courses/intro-to-ada/chapters/gnatinspect.db: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AdaCore/learn/e381c7badaed0c96ef1b8f95b1f8e5a6fdd755be/content/courses/intro-to-ada/chapters/gnatinspect.db -------------------------------------------------------------------------------- /content/courses/intro-to-ada/conf.ini: -------------------------------------------------------------------------------- 1 | [DEFAULT] 2 | title=Introduction to Ada 3 | author=Raphaël Amiard \\and Gustavo A. Hoffmann 4 | cover_page=cover-A4.pdf 5 | 6 | -------------------------------------------------------------------------------- /content/courses/intro-to-ada/cover-A4.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AdaCore/learn/e381c7badaed0c96ef1b8f95b1f8e5a6fdd755be/content/courses/intro-to-ada/cover-A4.pdf -------------------------------------------------------------------------------- /content/courses/intro-to-embedded-sys-prog/chapters/images/idiom_1_diagram.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AdaCore/learn/e381c7badaed0c96ef1b8f95b1f8e5a6fdd755be/content/courses/intro-to-embedded-sys-prog/chapters/images/idiom_1_diagram.png -------------------------------------------------------------------------------- /content/courses/intro-to-embedded-sys-prog/chapters/images/idiom_2_diagram.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AdaCore/learn/e381c7badaed0c96ef1b8f95b1f8e5a6fdd755be/content/courses/intro-to-embedded-sys-prog/chapters/images/idiom_2_diagram.png -------------------------------------------------------------------------------- /content/courses/intro-to-embedded-sys-prog/chapters/images/lckr_and_lcck_for_gpio_pin_locking.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AdaCore/learn/e381c7badaed0c96ef1b8f95b1f8e5a6fdd755be/content/courses/intro-to-embedded-sys-prog/chapters/images/lckr_and_lcck_for_gpio_pin_locking.png -------------------------------------------------------------------------------- /content/courses/intro-to-embedded-sys-prog/chapters/images/memory-mapped-device.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AdaCore/learn/e381c7badaed0c96ef1b8f95b1f8e5a6fdd755be/content/courses/intro-to-embedded-sys-prog/chapters/images/memory-mapped-device.png -------------------------------------------------------------------------------- /content/courses/intro-to-embedded-sys-prog/chapters/images/optimized-record-component-order.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AdaCore/learn/e381c7badaed0c96ef1b8f95b1f8e5a6fdd755be/content/courses/intro-to-embedded-sys-prog/chapters/images/optimized-record-component-order.png -------------------------------------------------------------------------------- /content/courses/intro-to-embedded-sys-prog/chapters/images/record_layout_with_rep_clause.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AdaCore/learn/e381c7badaed0c96ef1b8f95b1f8e5a6fdd755be/content/courses/intro-to-embedded-sys-prog/chapters/images/record_layout_with_rep_clause.png -------------------------------------------------------------------------------- /content/courses/intro-to-embedded-sys-prog/chapters/images/scalar_types_tree.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AdaCore/learn/e381c7badaed0c96ef1b8f95b1f8e5a6fdd755be/content/courses/intro-to-embedded-sys-prog/chapters/images/scalar_types_tree.png -------------------------------------------------------------------------------- /content/courses/intro-to-embedded-sys-prog/chapters/images/unoptimized-record-component-order.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AdaCore/learn/e381c7badaed0c96ef1b8f95b1f8e5a6fdd755be/content/courses/intro-to-embedded-sys-prog/chapters/images/unoptimized-record-component-order.png -------------------------------------------------------------------------------- /content/courses/intro-to-embedded-sys-prog/conf.ini: -------------------------------------------------------------------------------- 1 | [DEFAULT] 2 | title=Introduction to Embedded Systems Programming 3 | author=Patrick Rogers 4 | cover_page=cover-A4.pdf 5 | -------------------------------------------------------------------------------- /content/courses/intro-to-embedded-sys-prog/cover-A4.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AdaCore/learn/e381c7badaed0c96ef1b8f95b1f8e5a6fdd755be/content/courses/intro-to-embedded-sys-prog/cover-A4.pdf -------------------------------------------------------------------------------- /content/courses/intro-to-spark/chapters/01_spark_ada.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AdaCore/learn/e381c7badaed0c96ef1b8f95b1f8e5a6fdd755be/content/courses/intro-to-spark/chapters/01_spark_ada.png -------------------------------------------------------------------------------- /content/courses/intro-to-spark/chapters/05_loop.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AdaCore/learn/e381c7badaed0c96ef1b8f95b1f8e5a6fdd755be/content/courses/intro-to-spark/chapters/05_loop.png -------------------------------------------------------------------------------- /content/courses/intro-to-spark/conf.ini: -------------------------------------------------------------------------------- 1 | [DEFAULT] 2 | title=Introduction to SPARK 3 | author=Claire Dross \\and Yannick Moy 4 | cover_page=cover-A4.pdf 5 | 6 | -------------------------------------------------------------------------------- /content/courses/intro-to-spark/cover-A4.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AdaCore/learn/e381c7badaed0c96ef1b8f95b1f8e5a6fdd755be/content/courses/intro-to-spark/cover-A4.pdf -------------------------------------------------------------------------------- /content/courses/whats-new-in-ada-2022/chapters/introduction.rst: -------------------------------------------------------------------------------- 1 | Introduction 2 | ============ 3 | 4 | .. include:: ../../global.txt 5 | 6 | This is a collection of short code examples demonstrating new 7 | features of the :aarm22:`Ada 2022 Standard ` as they are implemented 8 | in GNAT Ada compiler. 9 | 10 | To use some of these features, you may need to use a compiler command 11 | line switch or pragma. Compilers starting with `GNAT Community Edition 12 | 2021`_ or `GCC 11`_ use :ada:`pragma Ada_2022;` or the ``-gnat2022`` 13 | switch. Older compilers use :ada:`pragma Ada_2020;` or 14 | ``-gnat2020``. To use the square brackets syntax or :ada:`'Reduce` 15 | expressions, you need :ada:`pragma Extensions_Allowed (On);` or the 16 | ``-gnatX`` switch. 17 | 18 | References 19 | ---------- 20 | 21 | * Draft :aarm22:`Ada 2022 Standard ` 22 | * `Ada 202x support in GNAT`_ blog post 23 | 24 | .. _`GNAT Community Edition 2021`: https://blog.adacore.com/gnat-community-2021-is-here 25 | .. _`GCC 11`: https://gcc.gnu.org/gcc-11/ 26 | .. _`Ada 202x support in GNAT`: https://blog.adacore.com/ada-202x-support-in-gnat 27 | -------------------------------------------------------------------------------- /content/courses/whats-new-in-ada-2022/conf.ini: -------------------------------------------------------------------------------- 1 | [DEFAULT] 2 | title=What's New in Ada 2022 3 | author=Maxim Reznik 4 | cover_page=cover-A4.pdf 5 | -------------------------------------------------------------------------------- /content/courses/whats-new-in-ada-2022/cover-A4.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AdaCore/learn/e381c7badaed0c96ef1b8f95b1f8e5a6fdd755be/content/courses/whats-new-in-ada-2022/cover-A4.pdf -------------------------------------------------------------------------------- /content/hidden.txt: -------------------------------------------------------------------------------- 1 | courses/advanced-spark 2 | -------------------------------------------------------------------------------- /content/hidden_contents.txt: -------------------------------------------------------------------------------- 1 | courses/advanced-ada/parts/resource_management/containers.rst 2 | courses/advanced-ada/parts/resource_management/memory_management.rst 3 | courses/advanced-ada/parts/resource_management/restrictions.rst 4 | courses/advanced-ada/parts/resource_management/standard_containers.rst 5 | courses/advanced-ada/parts/resource_management/index_hidden.rst 6 | courses/advanced-ada/parts/interfacing_external/*.* 7 | courses/advanced-ada/parts/appendices/*.* 8 | courses/advanced-ada/parts/multithreading/*.* 9 | courses/advanced-ada/parts/initialization/*.* 10 | courses/advanced-ada/parts/abstraction-oriented_prog/*.* 11 | courses/advanced-ada/parts/design_by_contracts/*.* 12 | courses/advanced-ada/index_hidden.rst 13 | courses/ada-in-practice/chapters/appendices.rst 14 | -------------------------------------------------------------------------------- /content/images/GNAT-Community-download.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AdaCore/learn/e381c7badaed0c96ef1b8f95b1f8e5a6fdd755be/content/images/GNAT-Community-download.png -------------------------------------------------------------------------------- /content/images/ada_horizon_logo/README.md: -------------------------------------------------------------------------------- 1 | # Ada Horizon Logo 2 | 3 | ## Public Domain 4 | 5 | [![CC0](http://i.creativecommons.org/p/zero/1.0/88x31.png)](http://creativecommons.org/publicdomain/zero/1.0/) 6 | 7 | To the extent possible under law, AdaCore has waived all copyright and related 8 | or neighboring rights to Ada Horizon logo. This work is published from: France. 9 | -------------------------------------------------------------------------------- /content/images/ada_training_logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AdaCore/learn/e381c7badaed0c96ef1b8f95b1f8e5a6fdd755be/content/images/ada_training_logo.png -------------------------------------------------------------------------------- /content/images/ccheart_black.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AdaCore/learn/e381c7badaed0c96ef1b8f95b1f8e5a6fdd755be/content/images/ccheart_black.png -------------------------------------------------------------------------------- /content/images/gap_logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AdaCore/learn/e381c7badaed0c96ef1b8f95b1f8e5a6fdd755be/content/images/gap_logo.png -------------------------------------------------------------------------------- /content/images/page-1-of-Ada_For_The_CPP_Java_Developer.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AdaCore/learn/e381c7badaed0c96ef1b8f95b1f8e5a6fdd755be/content/images/page-1-of-Ada_For_The_CPP_Java_Developer.jpeg -------------------------------------------------------------------------------- /content/images/page-1-of-Ada_For_The_Embedded_C_Developer.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AdaCore/learn/e381c7badaed0c96ef1b8f95b1f8e5a6fdd755be/content/images/page-1-of-Ada_For_The_Embedded_C_Developer.jpeg -------------------------------------------------------------------------------- /content/images/page-1-of-GNAT_Toolchain_Intro.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AdaCore/learn/e381c7badaed0c96ef1b8f95b1f8e5a6fdd755be/content/images/page-1-of-GNAT_Toolchain_Intro.jpeg -------------------------------------------------------------------------------- /content/images/page-1-of-Guidelines_for_Safe_and_Secure_Ada_SPARK.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AdaCore/learn/e381c7badaed0c96ef1b8f95b1f8e5a6fdd755be/content/images/page-1-of-Guidelines_for_Safe_and_Secure_Ada_SPARK.jpeg -------------------------------------------------------------------------------- /content/images/page-1-of-SPARK_for_the_MISRA_C_Developer.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AdaCore/learn/e381c7badaed0c96ef1b8f95b1f8e5a6fdd755be/content/images/page-1-of-SPARK_for_the_MISRA_C_Developer.jpeg -------------------------------------------------------------------------------- /content/images/page-1-of-ada-in-practice.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AdaCore/learn/e381c7badaed0c96ef1b8f95b1f8e5a6fdd755be/content/images/page-1-of-ada-in-practice.jpeg -------------------------------------------------------------------------------- /content/images/page-1-of-advanced-ada-temp.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AdaCore/learn/e381c7badaed0c96ef1b8f95b1f8e5a6fdd755be/content/images/page-1-of-advanced-ada-temp.jpeg -------------------------------------------------------------------------------- /content/images/page-1-of-advanced-ada.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AdaCore/learn/e381c7badaed0c96ef1b8f95b1f8e5a6fdd755be/content/images/page-1-of-advanced-ada.jpeg -------------------------------------------------------------------------------- /content/images/page-1-of-advanced-spark.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AdaCore/learn/e381c7badaed0c96ef1b8f95b1f8e5a6fdd755be/content/images/page-1-of-advanced-spark.jpeg -------------------------------------------------------------------------------- /content/images/page-1-of-intro-to-ada-labs.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AdaCore/learn/e381c7badaed0c96ef1b8f95b1f8e5a6fdd755be/content/images/page-1-of-intro-to-ada-labs.jpeg -------------------------------------------------------------------------------- /content/images/page-1-of-intro-to-ada.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AdaCore/learn/e381c7badaed0c96ef1b8f95b1f8e5a6fdd755be/content/images/page-1-of-intro-to-ada.jpeg -------------------------------------------------------------------------------- /content/images/page-1-of-intro-to-embedded-sys-prog.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AdaCore/learn/e381c7badaed0c96ef1b8f95b1f8e5a6fdd755be/content/images/page-1-of-intro-to-embedded-sys-prog.jpeg -------------------------------------------------------------------------------- /content/images/page-1-of-intro-to-spark.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AdaCore/learn/e381c7badaed0c96ef1b8f95b1f8e5a6fdd755be/content/images/page-1-of-intro-to-spark.jpeg -------------------------------------------------------------------------------- /content/images/page-1-of-learning-ada.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AdaCore/learn/e381c7badaed0c96ef1b8f95b1f8e5a6fdd755be/content/images/page-1-of-learning-ada.jpeg -------------------------------------------------------------------------------- /content/images/page-1-of-whats-new-in-ada-2022.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AdaCore/learn/e381c7badaed0c96ef1b8f95b1f8e5a6fdd755be/content/images/page-1-of-whats-new-in-ada-2022.jpeg -------------------------------------------------------------------------------- /content/labs/bug-free-coding/chapters/pile_of_dishes.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AdaCore/learn/e381c7badaed0c96ef1b8f95b1f8e5a6fdd755be/content/labs/bug-free-coding/chapters/pile_of_dishes.png -------------------------------------------------------------------------------- /content/labs/bug-free-coding/chapters/pop_1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AdaCore/learn/e381c7badaed0c96ef1b8f95b1f8e5a6fdd755be/content/labs/bug-free-coding/chapters/pop_1.png -------------------------------------------------------------------------------- /content/labs/bug-free-coding/chapters/pop_2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AdaCore/learn/e381c7badaed0c96ef1b8f95b1f8e5a6fdd755be/content/labs/bug-free-coding/chapters/pop_2.png -------------------------------------------------------------------------------- /content/labs/bug-free-coding/chapters/pop_3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AdaCore/learn/e381c7badaed0c96ef1b8f95b1f8e5a6fdd755be/content/labs/bug-free-coding/chapters/pop_3.png -------------------------------------------------------------------------------- /content/labs/bug-free-coding/chapters/pop_4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AdaCore/learn/e381c7badaed0c96ef1b8f95b1f8e5a6fdd755be/content/labs/bug-free-coding/chapters/pop_4.png -------------------------------------------------------------------------------- /content/labs/bug-free-coding/chapters/push_1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AdaCore/learn/e381c7badaed0c96ef1b8f95b1f8e5a6fdd755be/content/labs/bug-free-coding/chapters/push_1.png -------------------------------------------------------------------------------- /content/labs/bug-free-coding/chapters/push_2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AdaCore/learn/e381c7badaed0c96ef1b8f95b1f8e5a6fdd755be/content/labs/bug-free-coding/chapters/push_2.png -------------------------------------------------------------------------------- /content/labs/bug-free-coding/chapters/push_3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AdaCore/learn/e381c7badaed0c96ef1b8f95b1f8e5a6fdd755be/content/labs/bug-free-coding/chapters/push_3.png -------------------------------------------------------------------------------- /content/labs/bug-free-coding/chapters/push_4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AdaCore/learn/e381c7badaed0c96ef1b8f95b1f8e5a6fdd755be/content/labs/bug-free-coding/chapters/push_4.png -------------------------------------------------------------------------------- /content/labs/bug-free-coding/chapters/push_5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AdaCore/learn/e381c7badaed0c96ef1b8f95b1f8e5a6fdd755be/content/labs/bug-free-coding/chapters/push_5.png -------------------------------------------------------------------------------- /content/labs/bug-free-coding/conf.ini: -------------------------------------------------------------------------------- 1 | [DEFAULT] 2 | title=Bug Free Coding with SPARK Ada 3 | author=Robert Tice 4 | -------------------------------------------------------------------------------- /content/labs/intro-to-ada/chapters/rotation.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | #1, #5 7 | 8 | #2 9 | 10 | #3 11 | 12 | #4 13 | 14 | -------------------------------------------------------------------------------- /content/labs/intro-to-ada/chapters/solutions.rst: -------------------------------------------------------------------------------- 1 | Solutions 2 | ========= 3 | 4 | .. include:: ../../../courses/global.txt 5 | 6 | .. include:: ./solutions/imperative_language.rst 7 | 8 | .. include:: ./solutions/subprograms.rst 9 | 10 | .. include:: ./solutions/modular_programming.rst 11 | 12 | .. include:: ./solutions/strongly_typed_language.rst 13 | 14 | .. include:: ./solutions/records.rst 15 | 16 | .. include:: ./solutions/arrays.rst 17 | 18 | .. include:: ./solutions/more_about_types.rst 19 | 20 | .. include:: ./solutions/privacy.rst 21 | 22 | .. include:: ./solutions/generics.rst 23 | 24 | .. include:: ./solutions/exceptions.rst 25 | 26 | .. include:: ./solutions/tasking.rst 27 | 28 | .. include:: ./solutions/contracts.rst 29 | 30 | .. include:: ./solutions/object_oriented_programming.rst 31 | 32 | .. include:: ./solutions/standard_library_containers.rst 33 | 34 | .. include:: ./solutions/standard_library_dates_times.rst 35 | 36 | .. include:: ./solutions/standard_library_strings.rst 37 | 38 | .. include:: ./solutions/standard_library_numerics.rst 39 | -------------------------------------------------------------------------------- /content/labs/intro-to-ada/conf.ini: -------------------------------------------------------------------------------- 1 | [DEFAULT] 2 | title=Introduction to Ada: Laboratories 3 | author=Gustavo A. Hoffmann 4 | cover_page=cover-A4.pdf 5 | 6 | -------------------------------------------------------------------------------- /content/labs/intro-to-ada/cover-A4.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AdaCore/learn/e381c7badaed0c96ef1b8f95b1f8e5a6fdd755be/content/labs/intro-to-ada/cover-A4.pdf -------------------------------------------------------------------------------- /content/learning_ada_cover-A4.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AdaCore/learn/e381c7badaed0c96ef1b8f95b1f8e5a6fdd755be/content/learning_ada_cover-A4.pdf -------------------------------------------------------------------------------- /content/training_examples/fundamentals_of_ada/020_declarations.rst: -------------------------------------------------------------------------------- 1 | ============== 2 | Declarations 3 | ============== 4 | 5 | ---------------------------------- 6 | Identifiers Comments And Pragmas 7 | ---------------------------------- 8 | 9 | .. include:: 020_declarations/identifiers_comments_and_pragmas.rst 10 | 11 | ------------------ 12 | Numeric Literals 13 | ------------------ 14 | 15 | .. include:: 020_declarations/numeric_literals.rst 16 | 17 | --------------------- 18 | Object Declarations 19 | --------------------- 20 | 21 | .. include:: 020_declarations/object_declarations.rst 22 | 23 | --------------- 24 | Named Numbers 25 | --------------- 26 | 27 | .. include:: 020_declarations/named_numbers.rst 28 | 29 | ---------------------- 30 | Scope And Visibility 31 | ---------------------- 32 | 33 | .. include:: 020_declarations/scope_and_visibility.rst 34 | 35 | ---------------- 36 | Aspect Clauses 37 | ---------------- 38 | 39 | .. include:: 020_declarations/aspect_clauses.rst 40 | 41 | -------------------------------------------------------------------------------- /content/training_examples/fundamentals_of_ada/020_declarations/aspect_clauses.rst: -------------------------------------------------------------------------------- 1 | .. code:: ada compile_button project=Training_Material.Fundamentals_Of_Ada.Declarations.aspect_clauses 2 | 3 | package Aspect_Clauses is 4 | Eight_Bits : Integer range 0 .. 255 with 5 | Size => 8; 6 | Object : Integer with 7 | Atomic; 8 | end Aspect_Clauses; 9 | -------------------------------------------------------------------------------- /content/training_examples/fundamentals_of_ada/020_declarations/identifiers_comments_and_pragmas.rst: -------------------------------------------------------------------------------- 1 | .. code:: ada compile_button project=Training_Material.Fundamentals_Of_Ada.Declarations.identifiers_comments_and_pragmas 2 | 3 | package Identifiers_Comments_And_Pragmas is 4 | 5 | Spaceperson : Integer; 6 | --SPACEPERSON : integer; -- identifier is a duplicate 7 | Space_Person : Integer; 8 | --Null : integer := 0; -- identifier is a reserved word 9 | pragma Unreferenced (Spaceperson); 10 | pragma Unreferenced (Space_Person); 11 | 12 | end Identifiers_Comments_And_Pragmas; 13 | -------------------------------------------------------------------------------- /content/training_examples/fundamentals_of_ada/020_declarations/named_numbers.rst: -------------------------------------------------------------------------------- 1 | .. code:: ada run_button project=Training_Material.Fundamentals_Of_Ada.Declarations.named_numbers 2 | 3 | with Ada.Text_IO; use Ada.Text_IO; 4 | procedure Named_Numbers is 5 | Universal_Third : constant := 1.0 / 3.0; 6 | Float_Third : constant Float := 1.0 / 3.0; 7 | Float_Value : Float; 8 | Long_Float_Value : Long_Float; 9 | Long_Long_Float_Value : Long_Long_Float; 10 | begin 11 | Float_Value := Universal_Third; 12 | Long_Float_Value := Universal_Third; 13 | Long_Long_Float_Value := Universal_Third; 14 | Put_Line (Float'Image (Float_Value)); 15 | Put_Line (Long_Float'Image (Long_Float_Value)); 16 | Put_Line (Long_Long_Float'Image (Long_Long_Float_Value)); 17 | Float_Value := Float_Third; 18 | Long_Float_Value := Long_Float (Float_Third); 19 | Long_Long_Float_Value := Long_Long_Float (Float_Third); 20 | Put_Line (Float'Image (Float_Value)); 21 | Put_Line (Long_Float'Image (Long_Float_Value)); 22 | Put_Line (Long_Long_Float'Image (Long_Long_Float_Value)); 23 | end Named_Numbers; 24 | -------------------------------------------------------------------------------- /content/training_examples/fundamentals_of_ada/020_declarations/numeric_literals.rst: -------------------------------------------------------------------------------- 1 | .. code:: ada compile_button project=Training_Material.Fundamentals_Of_Ada.Declarations.numeric_literals 2 | 3 | package Numeric_Literals is 4 | 5 | Simple_Integer : constant := 3; 6 | Decimal_Number : constant := 0.25; 7 | Using_Separator : constant := 1_000_000.0; 8 | Octal : constant := 8#33#; 9 | Hexadecimal : constant := 16#AAAA#; 10 | 11 | end Numeric_Literals; 12 | -------------------------------------------------------------------------------- /content/training_examples/fundamentals_of_ada/020_declarations/object_declarations.rst: -------------------------------------------------------------------------------- 1 | .. code:: ada compile_button project=Training_Material.Fundamentals_Of_Ada.Declarations.object_declarations 2 | 3 | with Ada.Calendar; use Ada.Calendar; 4 | package Object_Declarations is 5 | A : Integer := 0; 6 | B, C : Time := Clock; 7 | D : Integer := A + 1; 8 | end Object_Declarations; 9 | -------------------------------------------------------------------------------- /content/training_examples/fundamentals_of_ada/020_declarations/scope_and_visibility.rst: -------------------------------------------------------------------------------- 1 | .. code:: ada run_button project=Training_Material.Fundamentals_Of_Ada.Declarations.scope_and_visibility 2 | 3 | with Ada.Text_IO; use Ada.Text_IO; 4 | procedure Scope_And_Visibility is 5 | Name : Integer; 6 | begin 7 | Name := 1; 8 | declare 9 | Name : Float := 2.0; 10 | begin 11 | Name := Name + Float (Scope_And_Visibility.Name); 12 | Put_Line (Name'Image); 13 | end; 14 | Put_Line (Name'Image); 15 | end Scope_And_Visibility; 16 | -------------------------------------------------------------------------------- /content/training_examples/fundamentals_of_ada/030_basic_types.rst: -------------------------------------------------------------------------------- 1 | ============= 2 | Basic Types 3 | ============= 4 | 5 | ------------------------ 6 | Discrete Numeric Types 7 | ------------------------ 8 | 9 | .. include:: 030_basic_types/discrete_numeric_types.rst 10 | 11 | ---------------------------- 12 | Discrete Enumeration Types 13 | ---------------------------- 14 | 15 | .. include:: 030_basic_types/discrete_enumeration_types.rst 16 | 17 | ------------ 18 | Real Types 19 | ------------ 20 | 21 | .. include:: 030_basic_types/real_types.rst 22 | 23 | -------------------------------------------------------------------------------- /content/training_examples/fundamentals_of_ada/030_basic_types/discrete_enumeration_types.rst: -------------------------------------------------------------------------------- 1 | .. code:: ada run_button project=Training_Material.Fundamentals_Of_Ada.Basic_Types.discrete_enumeration_types 2 | 3 | with Ada.Text_IO; use Ada.Text_IO; 4 | procedure Discrete_Enumeration_Types is 5 | 6 | type Colors_Type is (Red, Orange, Yellow, Green, Blue, Indigo, Violet); 7 | Color : Colors_Type := Red; 8 | 9 | type Traffic_Light_Type is (Red, Yellow, Green); 10 | for Traffic_Light_Type use (1, 2, 4); 11 | Stoplight : Traffic_Light_Type := Red; 12 | 13 | type Roman_Numeral_Digit_Type is ('I', 'V', 'X', 'L', 'C', 'M'); 14 | Digit : Roman_Numeral_Digit_Type := 'I'; 15 | 16 | Flag : Boolean; 17 | 18 | Position : Integer; 19 | 20 | begin 21 | 22 | Position := Traffic_Light_Type'Pos (Green); 23 | Color := Colors_Type'Val (Position); 24 | Stoplight := Traffic_Light_Type'(Red); 25 | Digit := Roman_Numeral_Digit_Type'Succ (Digit); 26 | Flag := End_Of_Line; 27 | 28 | Put_Line (Position'Image); 29 | Put_Line (Color'Image); 30 | Put_Line (Flag'Image); 31 | Put_Line (Digit'Image); 32 | Put_Line (Stoplight'Image); 33 | 34 | end Discrete_Enumeration_Types; 35 | -------------------------------------------------------------------------------- /content/training_examples/fundamentals_of_ada/030_basic_types/discrete_numeric_types.rst: -------------------------------------------------------------------------------- 1 | .. code:: ada run_button project=Training_Material.Fundamentals_Of_Ada.Basic_Types.discrete_numeric_types 2 | 3 | with Ada.Text_IO; use Ada.Text_IO; 4 | procedure Discrete_Numeric_Types is 5 | 6 | type Signed_Integer_Type is range -128 .. 127; 7 | Signed_Integer : Signed_Integer_Type := 100; 8 | 9 | type Unsigned_Integer_Type is mod 256; 10 | Unsigned_Integer : Unsigned_Integer_Type := 100; 11 | 12 | begin 13 | 14 | Signed_Integer := Signed_Integer_Type'Last; 15 | Signed_Integer := Signed_Integer_Type'Succ (Signed_Integer); 16 | Put_Line (Signed_Integer'Image); 17 | 18 | Unsigned_Integer := Unsigned_Integer_Type'First; 19 | Unsigned_Integer := Unsigned_Integer_Type'Pred (Unsigned_Integer); 20 | Put_Line (Unsigned_Integer'Image); 21 | 22 | Unsigned_Integer := Unsigned_Integer_Type (Signed_Integer); 23 | Put_Line (Unsigned_Integer'Image); 24 | 25 | Unsigned_Integer := Unsigned_Integer_Type'Mod (Signed_Integer); 26 | Put_Line (Unsigned_Integer'Image); 27 | 28 | declare 29 | Some_String : constant String := 30 | Unsigned_Integer_Type'Image (Unsigned_Integer); 31 | begin 32 | Signed_Integer := Signed_Integer_Type'Value (Some_String); 33 | Put_Line (Signed_Integer'Image); 34 | 35 | Put_Line (Some_String); 36 | end; 37 | 38 | end Discrete_Numeric_Types; 39 | -------------------------------------------------------------------------------- /content/training_examples/fundamentals_of_ada/030_basic_types/real_types.rst: -------------------------------------------------------------------------------- 1 | .. code:: ada run_button project=Training_Material.Fundamentals_Of_Ada.Basic_Types.real_types 2 | 3 | with Ada.Text_IO; use Ada.Text_IO; 4 | procedure Real_Types is 5 | 6 | Predefined_Floating_Point : constant Float := 0.0; 7 | 8 | type Floating_Point_Type is digits 8 range -1.0e10 .. 1.0e10; 9 | Floating_Point : Floating_Point_Type := 1.234e2; 10 | 11 | begin 12 | 13 | Put_Line (Integer'Image (Floating_Point_Type'Digits)); 14 | Put_Line (Integer'Image (Floating_Point_Type'Base'Digits)); 15 | Floating_Point := Floating_Point_Type'Succ (Floating_Point); 16 | Put_Line (Floating_Point_Type'Image (Floating_Point)); 17 | Put_Line (Predefined_Floating_Point'Image); 18 | 19 | end Real_Types; 20 | -------------------------------------------------------------------------------- /content/training_examples/fundamentals_of_ada/040_statements.rst: -------------------------------------------------------------------------------- 1 | ============ 2 | Statements 3 | ============ 4 | 5 | ----------------------- 6 | Assignment Statements 7 | ----------------------- 8 | 9 | .. include:: 040_statements/assignment_statements.rst 10 | 11 | ------------------------ 12 | Conditional Statements 13 | ------------------------ 14 | 15 | .. include:: 040_statements/conditional_statements.rst 16 | 17 | ----------------- 18 | Loop Statements 19 | ----------------- 20 | 21 | .. include:: 040_statements/loop_statements.rst 22 | 23 | -------------------------------------------------------------------------------- /content/training_examples/fundamentals_of_ada/040_statements/assignment_statements.rst: -------------------------------------------------------------------------------- 1 | .. code:: ada run_button project=Training_Material.Fundamentals_Of_Ada.Statements.assignment_statements 2 | 3 | with Ada.Text_IO; use Ada.Text_IO; 4 | procedure Assignment_Statements is 5 | 6 | Max_Miles : constant Integer := 20; 7 | 8 | type Feet_T is range 0 .. Max_Miles * 5_280; 9 | type Miles_T is range 0 .. Max_Miles; 10 | 11 | Feet : constant Feet_T := Feet_T (Line) * 1_000; 12 | Miles : Miles_T := 0; 13 | 14 | Index1, Index2 : Miles_T range 1 .. 20; 15 | 16 | begin 17 | 18 | -- Miles := Feet / 5_280; -- compile error 19 | 20 | -- Max_Miles := Max_Miles + 1; -- compile error 21 | 22 | Index1 := Miles_T (Max_Miles); -- constraint checking added 23 | Index2 := Index1; -- no constraint checking needed 24 | 25 | Put_Line ("Index1 = " & Index1'Image); 26 | Put_Line ("Index2 = " & Index2'Image); 27 | 28 | Index1 := 0; -- run-time error 29 | Put_Line ("Index1 = " & Index1'Image); 30 | 31 | end Assignment_Statements; 32 | -------------------------------------------------------------------------------- /content/training_examples/fundamentals_of_ada/040_statements/conditional_statements.rst: -------------------------------------------------------------------------------- 1 | .. code:: ada run_button project=Training_Material.Fundamentals_Of_Ada.Statements.conditional_statements 2 | 3 | with Ada.Text_IO; use Ada.Text_IO; 4 | procedure Conditional_Statements is 5 | type Light_T is (Red, Yellow, Green); 6 | A, B : Integer := Integer (Line); 7 | Speed : Integer; 8 | Light : constant Light_T := Light_T'Val (Line); 9 | 10 | begin 11 | if Light = Red then 12 | Speed := 0; 13 | elsif Light = Green then 14 | Speed := 25; 15 | else 16 | Speed := 50; 17 | end if; 18 | 19 | case Light is 20 | when Red => Speed := 0; 21 | when Green => Speed := 25; 22 | when Yellow => Speed := 50; 23 | end case; 24 | 25 | case A is 26 | when 1 .. 100 => B := A; 27 | when -100 .. -1 => B := -A; 28 | when others => A := B; 29 | end case; 30 | 31 | Put_Line ("Speed = " & Speed'Image); 32 | Put_Line ("Light = " & Light'Image); 33 | 34 | end Conditional_Statements; 35 | -------------------------------------------------------------------------------- /content/training_examples/fundamentals_of_ada/040_statements/loop_statements.rst: -------------------------------------------------------------------------------- 1 | .. code:: ada run_button project=Training_Material.Fundamentals_Of_Ada.Statements.loop_statements 2 | 3 | with Ada.Text_IO; use Ada.Text_IO; 4 | procedure Loop_Statements is 5 | File : File_Type; 6 | Counter : Integer := 0; 7 | type Light_T is (Red, Yellow, Green); 8 | begin 9 | loop 10 | if not Is_Open (File) then 11 | exit; 12 | end if; 13 | Counter := Counter + 1; 14 | exit when Is_Open (File); 15 | end loop; 16 | 17 | while Is_Open (File) loop 18 | Counter := Counter - 1; 19 | end loop; 20 | 21 | for Light in Light_T loop 22 | Put_Line (Light_T'Image (Light)); 23 | end loop; 24 | 25 | for Counter in reverse 1 .. 10 loop 26 | Put_Line (Integer'Image (Counter)); 27 | exit when Is_Open (File); 28 | end loop; 29 | end Loop_Statements; 30 | -------------------------------------------------------------------------------- /content/training_examples/fundamentals_of_ada/050_array_types.rst: -------------------------------------------------------------------------------- 1 | ============= 2 | Array Types 3 | ============= 4 | 5 | ------------------------- 6 | Constrained Array Types 7 | ------------------------- 8 | 9 | .. include:: 050_array_types/constrained_array_types.rst 10 | 11 | --------------------------- 12 | Unconstrained Array Types 13 | --------------------------- 14 | 15 | .. include:: 050_array_types/unconstrained_array_types.rst 16 | 17 | ------------ 18 | Attributes 19 | ------------ 20 | 21 | .. include:: 050_array_types/attributes.rst 22 | 23 | ------------ 24 | Operations 25 | ------------ 26 | 27 | .. include:: 050_array_types/operations.rst 28 | 29 | ------------------------------ 30 | Operations Added For Ada2012 31 | ------------------------------ 32 | 33 | .. include:: 050_array_types/operations_added_for_ada2012.rst 34 | 35 | ------------ 36 | Aggregates 37 | ------------ 38 | 39 | .. include:: 050_array_types/aggregates.rst 40 | 41 | -------------------------------------------------------------------------------- /content/training_examples/fundamentals_of_ada/050_array_types/aggregates.rst: -------------------------------------------------------------------------------- 1 | .. code:: ada run_button project=Training_Material.Fundamentals_Of_Ada.Array_Types.aggregates 2 | 3 | procedure Aggregates is 4 | 5 | type Days_T is (Mon, Tue, Wed, Thu, Fri, Sat, Sun); 6 | type Working_T is array (Days_T) of Float; 7 | Week : Working_T := (others => 0.0); 8 | 9 | Start, Finish : Days_T; 10 | 11 | type Array_T is array (Days_T range <>) of Boolean; 12 | List : Array_T (Mon .. Start) := (others => False); 13 | 14 | begin 15 | 16 | Week := (8.0, 8.0, 8.0, 8.0, 8.0, 0.0, 0.0); 17 | Week := (Sat => 0.0, Sun => 0.0, Mon .. Fri => 8.0); 18 | Week := (Sat | Sun => 0.0, Mon .. Fri => 8.0); 19 | -- Compile error 20 | -- Week := (8.0, 8.0, 8.0, 8.0, 8.0, Sat => 0.0, Sun => 0.0); 21 | 22 | if Week = (10.0, 10.0, 10.0, 10.0, 0.0, 0.0, 0.0) then 23 | null; -- four-day week 24 | end if; 25 | 26 | Week := (8.0, others => 0.0); 27 | Week := (8.0, others => <>); -- Ada2012: use previously set values 28 | 29 | -- Compile error 30 | -- Week := (Week'First .. Start => 0.0, Start .. Finish => 8.0, 31 | -- Finish .. Week'Last => 0.0); 32 | 33 | end Aggregates; 34 | -------------------------------------------------------------------------------- /content/training_examples/fundamentals_of_ada/050_array_types/attributes.rst: -------------------------------------------------------------------------------- 1 | .. code:: ada run_button project=Training_Material.Fundamentals_Of_Ada.Array_Types.attributes 2 | 3 | procedure Attributes is 4 | 5 | type Array_Of_Bits_T is array (Natural range <>) of Boolean; 6 | Bits8 : Array_Of_Bits_T (0 .. 7); 7 | 8 | type Array_Of_Bitstrings_T is 9 | array (Natural range <>, Natural range <>) of Boolean; 10 | Bitstrings : Array_Of_Bitstrings_T (1 .. 10, 0 .. 16); 11 | 12 | Value : Natural; 13 | 14 | begin 15 | 16 | Value := 0; 17 | for Index in Bits8'First .. Bits8'Last loop 18 | if Bits8 (Index) then 19 | Value := Value + 2**(Index - Bits8'First); 20 | end if; 21 | end loop; 22 | 23 | for String_Index in Bitstrings'Range (1) loop 24 | Value := 0; 25 | for Bit_Index in Bitstrings'Range (2) loop 26 | if Bitstrings (String_Index, Bit_Index) then 27 | Value := Value + 2**(Bit_Index - Bitstrings'First (2)); 28 | end if; 29 | end loop; 30 | end loop; 31 | 32 | end Attributes; 33 | -------------------------------------------------------------------------------- /content/training_examples/fundamentals_of_ada/050_array_types/constrained_array_types.rst: -------------------------------------------------------------------------------- 1 | .. code:: ada compile_button project=Training_Material.Fundamentals_Of_Ada.Array_Types.constrained_array_types 2 | 3 | package Constrained_Array_Types is 4 | 5 | type Array_Of_Integers_T is array (1 .. 10) of Integer; 6 | type Array_Of_Bits_T is 7 | array (Natural range 0 .. 31) of Boolean; 8 | 9 | type Color_T is (Red, Green, Blue); 10 | type Color_Range_T is mod 256; 11 | type Rgb_T is array (Color_T) of Color_Range_T; 12 | 13 | Ten_Integers : Array_Of_Integers_T; 14 | One_Word : Array_Of_Bits_T; 15 | Color : Rgb_T; 16 | 17 | end Constrained_Array_Types; 18 | -------------------------------------------------------------------------------- /content/training_examples/fundamentals_of_ada/050_array_types/operations.rst: -------------------------------------------------------------------------------- 1 | .. code:: ada run_button project=Training_Material.Fundamentals_Of_Ada.Array_Types.operations 2 | 3 | with Ada.Text_IO; use Ada.Text_IO; 4 | procedure Operations is 5 | 6 | type Boolean_Array_T is array (0 .. 15) of Boolean; 7 | Bool1, Bool2, Bool3 : Boolean_Array_T; 8 | 9 | type Integer_Array_T is array (1 .. 100) of Integer; 10 | Int1, Int2 : Integer_Array_T; 11 | 12 | Str1 : String (1 .. 10) := (others => 'X'); 13 | Str2 : String (2 .. 9) := (others => '-'); 14 | 15 | Flag : Boolean; 16 | 17 | begin 18 | 19 | Bool3 := Bool1 or Bool2; 20 | Flag := Int1 > Int2; 21 | Put_Line (Flag'Image); 22 | 23 | declare 24 | Str3 : String := Str1 & Str2; 25 | begin 26 | Str3 27 | (Str3'First .. Str3'First + 1) := "**"; 28 | Str3 (1 .. 4) := Str1 (1 .. 2) & Str2 (8 .. 9); 29 | Put_Line (Str3); 30 | end; 31 | 32 | if Int1 (1) in Bool3'Range then 33 | Bool3 (Int1 (1)) := Int1 (1) > Int2 (1); 34 | Put_Line (Boolean'Image (Bool3 (Int1 (1)))); 35 | end if; 36 | 37 | end Operations; 38 | -------------------------------------------------------------------------------- /content/training_examples/fundamentals_of_ada/050_array_types/operations_added_for_ada2012.rst: -------------------------------------------------------------------------------- 1 | .. code:: ada run_button project=Training_Material.Fundamentals_Of_Ada.Array_Types.operations_added_for_ada2012 2 | 3 | with Ada.Text_IO; use Ada.Text_IO; 4 | procedure Operations_Added_For_Ada2012 is 5 | 6 | type Integer_Array_T is array (1 .. 10) of Integer with 7 | Default_Component_Value => -1; 8 | Int_Array : Integer_Array_T; 9 | 10 | type Matrix_T is array (1 .. 3, 1 .. 3) of Integer with 11 | Default_Component_Value => -1; 12 | Matrix : Matrix_T; 13 | 14 | begin 15 | 16 | for Index in Int_Array'First + 1 .. Int_Array'Last - 1 loop 17 | Int_Array (Index) := Index * 10; 18 | end loop; 19 | for Item of Int_Array loop 20 | Put_Line (Integer'Image (Item)); 21 | end loop; 22 | 23 | for Index1 in Matrix_T'First (1) + 1 .. Matrix'Last (1) loop 24 | for Index2 in Matrix_T'First (2) + 1 .. Matrix'Last (2) loop 25 | Matrix (Index1, Index2) := Index1 * 100 + Index2; 26 | end loop; 27 | end loop; 28 | for Item of reverse Matrix loop 29 | Put_Line (Integer'Image (Item)); 30 | end loop; 31 | 32 | end Operations_Added_For_Ada2012; 33 | -------------------------------------------------------------------------------- /content/training_examples/fundamentals_of_ada/050_array_types/unconstrained_array_types.rst: -------------------------------------------------------------------------------- 1 | .. code:: ada compile_button project=Training_Material.Fundamentals_Of_Ada.Array_Types.unconstrained_array_types 2 | 3 | package Unconstrained_Array_Types is 4 | 5 | type Index_T is range 1 .. 100; 6 | type List_T is array (Index_T range <>) of Character; 7 | Wrong : List_T (0 .. 10); -- runtime error 8 | Right : List_T (11 .. 20); 9 | 10 | type Array_Of_Bits_T is array (Natural range <>) of Boolean; 11 | Bits8 : Array_Of_Bits_T (0 .. 7); 12 | Bits16 : Array_Of_Bits_T (1 .. 16); 13 | 14 | type Days_T is (Sun, Mon, Tues, Wed, Thu, Fri, Sat); 15 | type Schedule_T is array (Days_T range <>) of Float; 16 | Schedule : Schedule_T (Mon .. Fri); 17 | 18 | Name : String (1 .. 10); 19 | 20 | type Roman_Digit is ('I', 'V', 'X', 'L', 'C', 'D', 'M'); 21 | type Roman_Number is array (Natural range <>) of Roman_Digit; 22 | Orwellian : constant Roman_Number := "MCMLXXXIV"; 23 | 24 | end Unconstrained_Array_Types; 25 | -------------------------------------------------------------------------------- /content/training_examples/fundamentals_of_ada/060_record_types.rst: -------------------------------------------------------------------------------- 1 | ============== 2 | Record Types 3 | ============== 4 | 5 | ------------------ 6 | Components Rules 7 | ------------------ 8 | 9 | .. include:: 060_record_types/components_rules.rst 10 | 11 | ------------ 12 | Operations 13 | ------------ 14 | 15 | .. include:: 060_record_types/operations.rst 16 | 17 | ------------ 18 | Aggregates 19 | ------------ 20 | 21 | .. include:: 060_record_types/aggregates.rst 22 | 23 | ---------------- 24 | Default Values 25 | ---------------- 26 | 27 | .. include:: 060_record_types/default_values.rst 28 | 29 | ----------------- 30 | Variant Records 31 | ----------------- 32 | 33 | .. include:: 060_record_types/variant_records.rst 34 | 35 | -------------------------------------------------------------------------------- /content/training_examples/fundamentals_of_ada/060_record_types/aggregates.rst: -------------------------------------------------------------------------------- 1 | .. code:: ada run_button project=Training_Material.Fundamentals_Of_Ada.Record_Types.aggregates 2 | 3 | with Ada.Text_IO; use Ada.Text_IO; 4 | procedure Aggregates is 5 | 6 | type Date_T is record 7 | Day : Integer range 1 .. 31; 8 | Month : Positive range 1 .. 12; 9 | Year : Natural range 0 .. 2_099; 10 | end record; 11 | type Personal_Information_T is record 12 | Name : String (1 .. 10); 13 | Birthdate : Date_T; 14 | end record; 15 | type Employee_Information_T is record 16 | Number : Positive; 17 | Personal_Information : Personal_Information_T; 18 | end record; 19 | Birthdate : Date_T; 20 | Personal_Information : Personal_Information_T; 21 | Employee : Employee_Information_T; 22 | begin 23 | Birthdate := (25, 12, 2_001); 24 | Put_Line 25 | (Birthdate.Year'Image & Birthdate.Month'Image & Birthdate.Day'Image); 26 | Personal_Information := (Name => "Jane Smith", Birthdate => (14, 2, 2_002)); 27 | Put_Line 28 | (Personal_Information.Birthdate.Year'Image & 29 | Personal_Information.Birthdate.Month'Image & 30 | Personal_Information.Birthdate.Day'Image); 31 | Employee := (1_234, Personal_Information => Personal_Information); 32 | Put_Line 33 | (Employee.Personal_Information.Birthdate.Year'Image & 34 | Employee.Personal_Information.Birthdate.Month'Image & 35 | Employee.Personal_Information.Birthdate.Day'Image); 36 | Birthdate := (Month => 1, others => 2); 37 | Put_Line 38 | (Birthdate.Year'Image & Birthdate.Month'Image & Birthdate.Day'Image); 39 | end Aggregates; 40 | -------------------------------------------------------------------------------- /content/training_examples/fundamentals_of_ada/060_record_types/components_rules.rst: -------------------------------------------------------------------------------- 1 | .. code:: ada run_button project=Training_Material.Fundamentals_Of_Ada.Record_Types.components_rules 2 | 3 | with Ada.Text_IO; use Ada.Text_IO; 4 | procedure Components_Rules is 5 | type File_T is record 6 | Name : String (1 .. 12); 7 | Mode : File_Mode; 8 | Size : Integer range 0 .. 1_024; 9 | Is_Open : Boolean; 10 | -- Anonymous_Component : array (1 .. 3) of Integer; 11 | -- Constant_Component : constant Integer := 123; 12 | -- Self_Reference : File_T; 13 | end record; 14 | File : File_T; 15 | begin 16 | File.Name := "Filename.txt"; 17 | File.Mode := In_File; 18 | File.Size := 0; 19 | File.Is_Open := False; 20 | Put_Line (File.Name); 21 | end Components_Rules; 22 | -------------------------------------------------------------------------------- /content/training_examples/fundamentals_of_ada/060_record_types/default_values.rst: -------------------------------------------------------------------------------- 1 | .. code:: ada run_button project=Training_Material.Fundamentals_Of_Ada.Record_Types.default_values 2 | 3 | with Ada.Text_IO; use Ada.Text_IO; 4 | procedure Default_Values is 5 | 6 | type Complex is record 7 | Real : Float := -1.0; 8 | Imaginary : Float := -1.0; 9 | end record; 10 | 11 | Phasor : Complex; 12 | I : constant Complex := (0.0, 1.0); 13 | 14 | begin 15 | Put_Line 16 | (Float'Image (Phasor.Real) & " " & Float'Image (Phasor.Imaginary) & "i"); 17 | Put_Line (Float'Image (I.Real) & " " & Float'Image (I.Imaginary) & "i"); 18 | Phasor := (12.34, others => <>); 19 | Put_Line 20 | (Float'Image (Phasor.Real) & " " & Float'Image (Phasor.Imaginary) & "i"); 21 | end Default_Values; 22 | -------------------------------------------------------------------------------- /content/training_examples/fundamentals_of_ada/060_record_types/operations.rst: -------------------------------------------------------------------------------- 1 | .. code:: ada run_button project=Training_Material.Fundamentals_Of_Ada.Record_Types.operations 2 | 3 | with Ada.Text_IO; use Ada.Text_IO; 4 | procedure Operations is 5 | type Date_T is record 6 | Day : Integer range 1 .. 31; 7 | Month : Positive range 1 .. 12; 8 | Year : Natural range 0 .. 2_099; 9 | end record; 10 | type Personal_Information_T is record 11 | Name : String (1 .. 10); 12 | Birthdate : Date_T; 13 | end record; 14 | type Employee_Information_T is record 15 | Number : Positive; 16 | Personal_Information : Personal_Information_T; 17 | end record; 18 | Employee : Employee_Information_T; 19 | begin 20 | Employee.Number := 1_234; 21 | Employee.Personal_Information.Name := "Fred Smith"; 22 | Employee.Personal_Information.Birthdate.Year := 2_020; 23 | Put_Line (Employee.Number'Image); 24 | end Operations; 25 | -------------------------------------------------------------------------------- /content/training_examples/fundamentals_of_ada/060_record_types/variant_records.rst: -------------------------------------------------------------------------------- 1 | .. code:: ada run_button project=Training_Material.Fundamentals_Of_Ada.Record_Types.variant_records 2 | 3 | with Ada.Text_IO; use Ada.Text_IO; 4 | procedure Variant_Records is 5 | type Person_Tag is (Student, Faculty); 6 | type Person (Tag : Person_Tag) is -- Tag is the discriminant 7 | record 8 | Name : String (1 .. 10); -- Always present 9 | case Tag is 10 | when Student => -- 1st variant 11 | Gpa : Float range 0.0 .. 4.0; 12 | Year : Integer range 1 .. 4; 13 | when Faculty => -- 2nd variant 14 | Pubs : Integer; 15 | end case; 16 | end record; 17 | S : Person (Student) := 18 | (Tag => Student, Name => (others => 'S'), Gpa => 4.0, Year => 4); 19 | F : Person (Faculty) := 20 | (Tag => Faculty, Name => (others => 'F'), Pubs => 10); 21 | begin 22 | Put_Line (S.Name & " " & F.Name); 23 | Put_Line (S.Gpa'Image); 24 | Put_Line (S.Pubs'Image); -- run-time error 25 | Put_Line (F.Pubs'Image); 26 | Put_Line (F.Year'Image); -- run-time error 27 | end Variant_Records; 28 | -------------------------------------------------------------------------------- /content/training_examples/fundamentals_of_ada/070_subprograms.rst: -------------------------------------------------------------------------------- 1 | ============= 2 | Subprograms 3 | ============= 4 | 5 | ------------------------- 6 | Declarations And Bodies 7 | ------------------------- 8 | 9 | .. include:: 070_subprograms/declarations_and_bodies.rst 10 | 11 | ------------ 12 | Parameters 13 | ------------ 14 | 15 | .. include:: 070_subprograms/parameters.rst 16 | 17 | ---------------------- 18 | Expression Functions 19 | ---------------------- 20 | 21 | .. include:: 070_subprograms/expression_functions.rst 22 | 23 | -------------------- 24 | Potential Pitfalls 25 | -------------------- 26 | 27 | .. include:: 070_subprograms/potential_pitfalls.rst 28 | 29 | -------------------------------------------------------------------------------- /content/training_examples/fundamentals_of_ada/070_subprograms/declarations_and_bodies.rst: -------------------------------------------------------------------------------- 1 | .. code:: ada run_button project=Training_Material.Fundamentals_Of_Ada.Subprograms.declarations_and_bodies 2 | 3 | with Ada.Text_IO; use Ada.Text_IO; 4 | procedure Declarations_And_Bodies is 5 | 6 | -- declarations 7 | procedure Swap (A, B : in out Integer); 8 | function Triple (X : Float) return Float; 9 | 10 | -- bodies 11 | procedure Swap (A : in out Integer; B : in out Integer) is 12 | C : constant Integer := A; 13 | begin 14 | A := B; 15 | B := C; 16 | end Swap; 17 | function Triple (X : Float) return Float is 18 | begin 19 | return X * 3.0; 20 | end Triple; 21 | 22 | function Factorial (Counter : Natural) return Natural; 23 | function Factorial (Counter : Natural) return Natural is 24 | begin 25 | if Counter = 1 then 26 | return 1; 27 | else 28 | return Counter * Factorial (Counter - 1); 29 | end if; 30 | end Factorial; 31 | 32 | I1, I2 : Integer := 123; 33 | 34 | begin 35 | Swap (I1, I2); 36 | Put_Line (Float'Image (Triple (12.3))); 37 | Put_Line (Natural'Image (Factorial (5))); 38 | 39 | end Declarations_And_Bodies; 40 | -------------------------------------------------------------------------------- /content/training_examples/fundamentals_of_ada/070_subprograms/expression_functions.rst: -------------------------------------------------------------------------------- 1 | .. code:: ada run_button project=Training_Material.Fundamentals_Of_Ada.Subprograms.expression_functions 2 | 3 | with Ada.Text_IO; use Ada.Text_IO; 4 | procedure Expression_Functions is 5 | 6 | function Square1 (X : Integer) return Integer is (X * 2); 7 | function Square2 (X : Integer) return Integer is 8 | begin 9 | return X * 2; 10 | end Square2; 11 | 12 | function Square3 (X : Integer) return Integer; 13 | function Square3 (X : Integer) return Integer is (X * 2); 14 | 15 | function Square4 (X : Integer) return Integer is (X * 2); 16 | -- illegal: Square4 already complete function Square4 (X : Integer) return 17 | -- Integer is begin 18 | -- return X * 2; 19 | -- end Square4; 20 | 21 | begin 22 | Put_Line (Integer'Image (Square1 (2))); 23 | Put_Line (Integer'Image (Square2 (3))); 24 | Put_Line (Integer'Image (Square3 (4))); 25 | Put_Line (Integer'Image (Square4 (5))); 26 | end Expression_Functions; 27 | -------------------------------------------------------------------------------- /content/training_examples/fundamentals_of_ada/070_subprograms/parameters.rst: -------------------------------------------------------------------------------- 1 | .. code:: ada run_button project=Training_Material.Fundamentals_Of_Ada.Subprograms.parameters 2 | 3 | procedure Parameters is 4 | 5 | procedure Do_Something (Formal_I : in Integer; Formal_B : out Boolean) is 6 | begin 7 | Formal_B := Formal_I > 0; 8 | end Do_Something; 9 | 10 | procedure All_Modes (Number : in Integer; 11 | Value : in out Integer; 12 | Result : out Boolean) is 13 | begin 14 | Value := Value * Number; 15 | Result := Value > 0; 16 | end All_Modes; 17 | 18 | procedure Defaults (A : Integer := 1; 19 | B : Integer := 2; 20 | C : Boolean := True; 21 | D : Boolean := False) is null; 22 | 23 | type Vector is array (Positive range <>) of Float; 24 | procedure Add (Left : in out Vector; Right : Vector) is 25 | begin 26 | for I in Left'First .. Left'Last loop 27 | Left (I) := Left (I) + Right (I); 28 | end loop; 29 | end Add; 30 | 31 | Actual_I1, Actual_I2 : Integer := 0; 32 | Actual_B : Boolean; 33 | Actual_V : Vector (1 .. 100); 34 | 35 | begin 36 | Do_Something (Actual_I1, 37 | Formal_B => Actual_B); 38 | All_Modes (Actual_I1 + 100, Actual_I2, Actual_B); 39 | -- All_Modes (Actual_I1, Actual_I2 + 100, Actual_B); -- compile error 40 | Defaults (1, 2, True, False); 41 | Defaults; 42 | -- Defaults (1, True); -- compile error 43 | Defaults (A => 1, 44 | D => True); 45 | Add (Actual_V (1 .. 10), Actual_V (11 .. 20)); 46 | end Parameters; 47 | -------------------------------------------------------------------------------- /content/training_examples/fundamentals_of_ada/070_subprograms/potential_pitfalls.rst: -------------------------------------------------------------------------------- 1 | .. code:: ada run_button project=Training_Material.Fundamentals_Of_Ada.Subprograms.potential_pitfalls 2 | 3 | with Ada.Text_IO; use Ada.Text_IO; 4 | procedure Potential_Pitfalls is 5 | Global_I : Integer := 0; 6 | Global_P : Positive := 1; 7 | Global_S : String := "Hello"; 8 | 9 | procedure Unassigned_Out (A : in Integer; B : out Positive) is 10 | begin 11 | if A > 0 then 12 | B := A; 13 | end if; 14 | end Unassigned_Out; 15 | 16 | function Cause_Side_Effect return Integer is 17 | begin 18 | Global_I := Global_I + 1; 19 | return Global_I; 20 | end Cause_Side_Effect; 21 | 22 | procedure Order_Dependent_Code (X, Y : Integer) is 23 | begin 24 | Put_Line (Integer'Image (X) & " / " & Integer'Image (Y)); 25 | end Order_Dependent_Code; 26 | 27 | procedure Aliasing (Param : in String; 28 | I1 : in out Integer; 29 | I2 : in out Integer) is 30 | begin 31 | Global_S := "World"; 32 | I1 := I1 * 2; 33 | I2 := I2 * 3; 34 | Put_Line ("Aliasing string: " & Param); 35 | end Aliasing; 36 | 37 | begin 38 | Unassigned_Out (-1, Global_P); 39 | Put_Line ("Global_P = " & Positive'Image (Global_P)); 40 | 41 | Order_Dependent_Code (Global_I, Cause_Side_Effect); 42 | 43 | Global_P := Positive'First; 44 | -- Aliasing (Global_S, Global_I, Global_I); -- compile error 45 | Aliasing (Global_S, Global_I, Global_P); 46 | Put_Line ("Global_S: " & Global_S); 47 | Put_Line ("Global_P: " & Global_P'Image); 48 | end Potential_Pitfalls; 49 | -------------------------------------------------------------------------------- /content/training_examples/fundamentals_of_ada/080_expressions.rst: -------------------------------------------------------------------------------- 1 | ============= 2 | Expressions 3 | ============= 4 | 5 | ---------- 6 | Subtypes 7 | ---------- 8 | 9 | .. include:: 080_expressions/subtypes.rst 10 | 11 | ------------------ 12 | Membership Tests 13 | ------------------ 14 | 15 | .. include:: 080_expressions/membership_tests.rst 16 | 17 | -------- 18 | Slices 19 | -------- 20 | 21 | .. include:: 080_expressions/slices.rst 22 | 23 | ------------------------- 24 | Conditional Expressions 25 | ------------------------- 26 | 27 | .. include:: 080_expressions/conditional_expressions.rst 28 | 29 | ------------------------ 30 | Quantified Expressions 31 | ------------------------ 32 | 33 | .. include:: 080_expressions/quantified_expressions.rst 34 | 35 | -------------------------------------------------------------------------------- /content/training_examples/fundamentals_of_ada/080_expressions/conditional_expressions.rst: -------------------------------------------------------------------------------- 1 | .. code:: ada run_button project=Training_Material.Fundamentals_Of_Ada.Expressions.conditional_expressions 2 | 3 | with Ada.Text_IO; use Ada.Text_IO; 4 | procedure Conditional_Expressions is 5 | 6 | type Months_T is 7 | (Jan, Feb, Mar, Apr, May, Jun, Jul, Aug, Sep, Oct, Nov, Dec); 8 | Year : constant Integer := 2_020; 9 | 10 | procedure If_Expression is 11 | Counter : Natural := 5; 12 | begin 13 | while Counter > 0 loop 14 | Put_Line 15 | ("Self-destruct in" & Natural'Image (Counter) & 16 | (if Counter = 1 then " second" else " seconds")); 17 | delay 1.0; 18 | Counter := Counter - 1; 19 | end loop; 20 | Put_Line ("Boom! (goodbye Nostromo)"); 21 | end If_Expression; 22 | 23 | procedure Case_Expression is 24 | Leap_Year : constant Boolean := 25 | (Year mod 4 = 0 and Year mod 100 /= 0) or else (Year mod 400 = 0); 26 | begin 27 | for M in Months_T loop 28 | Put_Line 29 | (M'Image & " => " & 30 | Integer'Image 31 | (case M is when Sep | Apr | Jun | Nov => 30, 32 | when Feb => (if Leap_Year then 29 else 28), 33 | when others => 31)); 34 | end loop; 35 | end Case_Expression; 36 | 37 | begin 38 | If_Expression; 39 | Case_Expression; 40 | end Conditional_Expressions; 41 | -------------------------------------------------------------------------------- /content/training_examples/fundamentals_of_ada/080_expressions/membership_tests.rst: -------------------------------------------------------------------------------- 1 | .. code:: ada run_button project=Training_Material.Fundamentals_Of_Ada.Expressions.membership_tests 2 | 3 | with Ada.Text_IO; use Ada.Text_IO; 4 | procedure Membership_Tests is 5 | subtype Index_T is Integer range 1 .. 100; 6 | X : constant Integer := Integer (Line); 7 | B : Boolean := X in 1 .. 100; 8 | C : Boolean := not (X in Index_T); 9 | D : Boolean := X not in Index_T; 10 | 11 | type Calendar_Days is (Sun, Mon, Tues, Wed, Thur, Fri, Sat); 12 | subtype Weekdays is Calendar_Days range Mon .. Fri; 13 | Day : Calendar_Days := Calendar_Days'Val (X); 14 | 15 | begin 16 | 17 | if Day in Sun | Sat then 18 | -- identical expressions 19 | B := Day in Mon .. Fri; 20 | C := Day in Weekdays; 21 | Day := Wed; 22 | elsif Day = Mon or Day = Tues then 23 | D := D and (B or C); 24 | Day := Thur; 25 | end if; 26 | 27 | Put_Line (D'Image & " " & B'Image & " " & C'Image); 28 | Put_Line (Day'Image); 29 | 30 | end Membership_Tests; 31 | -------------------------------------------------------------------------------- /content/training_examples/fundamentals_of_ada/080_expressions/quantified_expressions.rst: -------------------------------------------------------------------------------- 1 | .. code:: ada run_button project=Training_Material.Fundamentals_Of_Ada.Expressions.quantified_expressions 2 | 3 | with GNAT.Random_Numbers; use GNAT.Random_Numbers; 4 | with Ada.Text_IO; use Ada.Text_IO; 5 | procedure Quantified_Expressions is 6 | Gen : Generator; 7 | Values : constant array (1 .. 10) of Integer := (others => Random (Gen)); 8 | 9 | Any_Even : constant Boolean := (for some N of Values => N mod 2 = 0); 10 | All_Odd : constant Boolean := (for all N of reverse Values => N mod 2 = 1); 11 | 12 | function Is_Sorted return Boolean is 13 | (for all K in Values'Range => 14 | K = Values'First or else Values (K - 1) <= Values (K)); 15 | 16 | function Duplicate return Boolean is 17 | (for some I in Values'Range => 18 | (for some J in I + 1 .. Values'Last => Values (I) = Values (J))); 19 | 20 | begin 21 | Put_Line ("Any Even: " & Boolean'Image (Any_Even)); 22 | Put_Line ("All Odd: " & Boolean'Image (All_Odd)); 23 | Put_Line ("Is_Sorted " & Boolean'Image (Is_Sorted)); 24 | Put_Line ("Duplicate " & Boolean'Image (Duplicate)); 25 | end Quantified_Expressions; 26 | -------------------------------------------------------------------------------- /content/training_examples/fundamentals_of_ada/080_expressions/slices.rst: -------------------------------------------------------------------------------- 1 | .. code:: ada run_button project=Training_Material.Fundamentals_Of_Ada.Expressions.slices 2 | 3 | with Ada.Text_IO; use Ada.Text_IO; 4 | procedure Slices is 5 | procedure Explicit_Indices is 6 | Full_Name : String (1 .. 20) := "Barney Rubble "; 7 | begin 8 | Put_Line (Full_Name); 9 | Full_Name (1 .. 10) := "Betty "; 10 | Put_Line (Full_Name (1 .. 10)); -- first half of name 11 | Put_Line (Full_Name (11 .. 20)); -- second half of name 12 | end Explicit_Indices; 13 | 14 | procedure Subtype_Indices is 15 | subtype First_Name is Positive range 1 .. 10; 16 | subtype Last_Name is Positive range 11 .. 20; 17 | Full_Name : String (First_Name'First .. Last_Name'Last) := 18 | "Fred Flintstone"; 19 | begin 20 | Put_Line (Full_Name); 21 | Full_Name (First_Name) := "Wilma "; 22 | Put_Line (Full_Name (First_Name)); -- first half of name 23 | Put_Line (Full_Name (Last_Name)); -- second half of name 24 | end Subtype_Indices; 25 | begin 26 | Explicit_Indices; 27 | Subtype_Indices; 28 | end Slices; 29 | -------------------------------------------------------------------------------- /content/training_examples/fundamentals_of_ada/080_expressions/subtypes.rst: -------------------------------------------------------------------------------- 1 | .. code:: ada run_button project=Training_Material.Fundamentals_Of_Ada.Expressions.subtypes 2 | 3 | with Ada.Text_IO; use Ada.Text_IO; 4 | procedure Subtypes is 5 | type Days_T is (Sun, Mon, Tues, Wed, Thurs, Fri, Sat); 6 | subtype Weekdays_T is Days_T range Mon .. Fri; 7 | 8 | Weekday : Weekdays_T := Mon; 9 | Also_Weekday : Days_T range Mon .. Fri := Tues; 10 | Day : Days_T := Weekday; 11 | 12 | type Matrix_T is array (Integer range <>, Integer range <>) of Integer; 13 | subtype Matrix_3x3_T is Matrix_T (1 .. 3, 1 .. 3); 14 | subtype Line_T is String (1 .. 80); 15 | 16 | I : Integer := 1_234; 17 | procedure Takes_Positive (P : Positive) is null; 18 | 19 | type Tertiary_Switch is (Off, On, Neither) with 20 | Default_Value => Neither; 21 | subtype Toggle_Switch is Tertiary_Switch range Off .. On; 22 | Safe : Toggle_Switch := Off; 23 | -- Implicit : Toggle_Switch; -- compile error: out of range 24 | 25 | pragma Unreferenced (Safe); 26 | 27 | begin 28 | Also_Weekday := Day; -- runtime error if Day is Sat or Sun 29 | Put_Line (Also_Weekday'Image); 30 | Day := Weekday; -- always legal 31 | I := I - 1; 32 | Takes_Positive (I); -- runtime error if I <= 0 33 | 34 | Weekday := Weekdays_T'Last; 35 | Day := Days_T'Last; 36 | 37 | Put_Line (Weekdays_T'Image (Weekday) & " / " & Days_T'Image (Day)); 38 | Put_Line (Days_T'Image (Weekdays_T'Succ (Weekday))); 39 | Put_Line (Integer'Image (Matrix_3x3_T'Length (1))); 40 | Put_Line (Integer'Image (Line_T'Length (1))); 41 | end Subtypes; 42 | -------------------------------------------------------------------------------- /content/training_examples/fundamentals_of_ada/090_overloading.rst: -------------------------------------------------------------------------------- 1 | ============= 2 | Overloading 3 | ============= 4 | 5 | ------------------------- 6 | Enumerals And Operators 7 | ------------------------- 8 | 9 | .. include:: 090_overloading/enumerals_and_operators.rst 10 | 11 | ----------------- 12 | Call Resolution 13 | ----------------- 14 | 15 | .. include:: 090_overloading/call_resolution.rst 16 | 17 | ------------------- 18 | Visibility Issues 19 | ------------------- 20 | 21 | .. include:: 090_overloading/visibility_issues.rst 22 | 23 | ----------------------- 24 | User Defined Equality 25 | ----------------------- 26 | 27 | .. include:: 090_overloading/user_defined_equality.rst 28 | 29 | ------------------------- 30 | Composition Of Equality 31 | ------------------------- 32 | 33 | .. include:: 090_overloading/composition_of_equality.rst 34 | 35 | -------------------------------------------------------------------------------- /content/training_examples/fundamentals_of_ada/090_overloading/call_resolution.rst: -------------------------------------------------------------------------------- 1 | .. code:: ada run_button project=Training_Material.Fundamentals_Of_Ada.Overloading.call_resolution 2 | 3 | with Ada.Text_IO; use Ada.Text_IO; 4 | procedure Call_Resolution is 5 | type Colors_T is (Red, Orange, Yellow, Green, Blue, Indigo, Violet); 6 | type Rgb_T is (Red, Green, Blue); 7 | function Str (P : Colors_T) return String is (Colors_T'Image (P)); 8 | function Str (P : Rgb_T) return String is (Rgb_T'Image (P)); 9 | procedure Print (Color : Colors_T) is 10 | begin 11 | Put_Line (Str (Color)); 12 | end Print; 13 | procedure Print (Rgb : Rgb_T) is 14 | begin 15 | Put_Line (Str (Rgb)); 16 | end Print; 17 | procedure Print (P1 : Colors_T; P2 : Rgb_T) is null; 18 | 19 | begin 20 | Put_Line (Str (Yellow)); 21 | -- Put_Line (Str (Red)); -- compile error 22 | Print (Orange); 23 | Print (Rgb => Red); 24 | Print (Color => Blue); 25 | Print (Red, Red); 26 | end Call_Resolution; 27 | -------------------------------------------------------------------------------- /content/training_examples/fundamentals_of_ada/090_overloading/composition_of_equality.rst: -------------------------------------------------------------------------------- 1 | .. code:: ada run_button project=Training_Material.Fundamentals_Of_Ada.Overloading.composition_of_equality 2 | 3 | with Ada.Text_IO; use Ada.Text_IO; 4 | procedure Composition_Of_Equality is 5 | type My_Integer is range -1_000 .. 1_000; 6 | function "=" (L, R : My_Integer) return Boolean is 7 | (False); -- for illustration purposes 8 | type Record_T is tagged record 9 | Field : My_Integer := 0; 10 | end record; 11 | type Record_List is array (My_Integer range 1 .. 10) of Record_T; 12 | 13 | I1, I2 : constant My_Integer := 0; 14 | R1, R2 : constant Record_List := (others => (Field => 0)); 15 | begin 16 | -- uses primitive "=" => False 17 | Put_Line (Boolean'Image (I1 = I2)); 18 | -- uses predefined "=" for components=>True 19 | Put_Line (Boolean'Image (R1 = R2)); 20 | end Composition_Of_Equality; 21 | -------------------------------------------------------------------------------- /content/training_examples/fundamentals_of_ada/090_overloading/enumerals_and_operators.rst: -------------------------------------------------------------------------------- 1 | .. code:: ada run_button project=Training_Material.Fundamentals_Of_Ada.Overloading.enumerals_and_operators 2 | 3 | with Ada.Text_IO; use Ada.Text_IO; 4 | procedure Enumerals_And_Operators is 5 | type Colors_T is (Blue, Yellow, Black, Green, Red); 6 | type Rgb_T is (Red, Green, Blue); 7 | type Stoplight_T is (Green, Yellow, Red); 8 | 9 | Color : constant Colors_T := Red; 10 | Rgb : constant Rgb_T := Red; 11 | Light : constant Stoplight_T := Red; 12 | 13 | type Miles_T is digits 6; 14 | type Hour_T is digits 6; 15 | type Speed_T is digits 6; 16 | function "/" (M : Miles_T; H : Hour_T) return Speed_T is 17 | (Speed_T (Float (M) / Float (H))); 18 | function "*" (Mph : Speed_T; H : Hour_T) return Miles_T is 19 | (Miles_T (Float (Mph) * Float (H))); 20 | 21 | M : Miles_T := Miles_T (Col); 22 | H : constant Hour_T := Hour_T (Line); 23 | Mph : Speed_T; 24 | 25 | begin 26 | Put_Line (Color'Image & " " & Rgb'Image & " " & Light'Image); 27 | Mph := M / H; 28 | M := Mph * H; 29 | Put_Line (Mph'Image & M'Image); 30 | 31 | Mph := "/" (M => M, H => H); 32 | M := "*" (Mph, H); 33 | Put_Line (Mph'Image & M'Image); 34 | end Enumerals_And_Operators; 35 | -------------------------------------------------------------------------------- /content/training_examples/fundamentals_of_ada/090_overloading/user_defined_equality.rst: -------------------------------------------------------------------------------- 1 | .. code:: ada run_button project=Training_Material.Fundamentals_Of_Ada.Overloading.user_defined_equality 2 | 3 | with Ada.Text_IO; use Ada.Text_IO; 4 | procedure User_Defined_Equality is 5 | type Array_T is array (1 .. 10) of Integer; 6 | type List_T is record 7 | List : Array_T; 8 | Count : Integer := 0; 9 | end record; 10 | 11 | function "=" (L, R : List_T) return Boolean is 12 | begin 13 | if L.Count /= R.Count then 14 | Put_Line ("Count is off"); 15 | return False; 16 | else 17 | for I in 1 .. L.Count loop 18 | if L.List (I) /= R.List (I) then 19 | Put_Line ("elements don't match"); 20 | return False; 21 | end if; 22 | end loop; 23 | end if; 24 | return True; 25 | end "="; 26 | L, R : List_T := (List => (others => 1), Count => 3); 27 | begin 28 | Put_Line (Boolean'Image (L = R)); 29 | L.List (2) := 0; 30 | Put_Line (Boolean'Image (L = R)); 31 | R.Count := 1; 32 | Put_Line (Boolean'Image (L = R)); 33 | end User_Defined_Equality; 34 | -------------------------------------------------------------------------------- /content/training_examples/fundamentals_of_ada/090_overloading/visibility_issues.rst: -------------------------------------------------------------------------------- 1 | .. code:: ada run_button project=Training_Material.Fundamentals_Of_Ada.Overloading.visibility_issues 2 | 3 | procedure Visibility_Issues is 4 | procedure Foo (I : Integer) is 5 | procedure Foo (N : Natural) is null; 6 | begin 7 | Foo (I); 8 | end Foo; 9 | -- procedure Foo (N : Natural) is null; -- compile error 10 | begin 11 | Foo (1); 12 | end Visibility_Issues; 13 | -------------------------------------------------------------------------------- /content/training_examples/fundamentals_of_ada/095_library_units.rst: -------------------------------------------------------------------------------- 1 | =============== 2 | Library Units 3 | =============== 4 | 5 | --------------- 6 | Library Units 7 | --------------- 8 | 9 | .. include:: 095_library_units/library_units.rst 10 | 11 | -------------- 12 | With Clauses 13 | -------------- 14 | 15 | .. include:: 095_library_units/with_clauses.rst 16 | 17 | -------------------------------------------------------------------------------- /content/training_examples/fundamentals_of_ada/095_library_units/library_units.rst: -------------------------------------------------------------------------------- 1 | .. code:: ada run_button project=Training_Material.Fundamentals_Of_Ada.Library_Units.library_units 2 | 3 | package Named_Common is 4 | X : Integer; -- valid object for life of application 5 | Y : Float; -- valid object for life of application 6 | end Named_Common; 7 | 8 | procedure Library_Procedure (Parameter : in out Integer); 9 | 10 | with Ada.Text_IO; use Ada.Text_IO; 11 | procedure Library_Procedure (Parameter : in out Integer) is 12 | -- X is visible to Library_Procedure and Nested_Procedure 13 | X : constant Integer := Parameter; 14 | procedure Nested_Procedure is 15 | -- Y is only visible to Nested_Procedure 16 | Y : constant Integer := X * 2; 17 | begin 18 | Parameter := X * Y; 19 | end Nested_Procedure; 20 | begin 21 | Nested_Procedure; 22 | Put_Line ("parameter = " & Parameter'Image); 23 | end Library_Procedure; 24 | 25 | with Library_Procedure; 26 | with Named_Common; 27 | procedure Main is 28 | begin 29 | Named_Common.X := 123; 30 | Library_Procedure (Named_Common.X); 31 | end Main; 32 | -------------------------------------------------------------------------------- /content/training_examples/fundamentals_of_ada/095_library_units/with_clauses.rst: -------------------------------------------------------------------------------- 1 | .. code:: ada run_button project=Training_Material.Fundamentals_Of_Ada.Library_Units.with_clauses 2 | 3 | with Ada.Text_IO; 4 | package Base_Types is 5 | type Position_T is record 6 | Line : Ada.Text_IO.Positive_Count; 7 | Column : Ada.Text_IO.Positive_Count; 8 | end record; 9 | end Base_Types; 10 | 11 | -- no need to "with" ada.text_io 12 | with Base_Types; 13 | package Files is 14 | subtype Name_T is String (1 .. 12); 15 | type File_T is record 16 | Name : Name_T := (others => ' '); 17 | Position : Base_Types.Position_T := (Line => 1, Column => 1); 18 | end record; 19 | function Create (Name : Name_T) return File_T; 20 | end Files; 21 | 22 | package body Files is 23 | -- "with" of base_types inherited from spec 24 | Default_Position : constant Base_Types.Position_T := (1, 1); 25 | function Create (Name : Name_T) return File_T is 26 | (Name => Name, Position => Default_Position); 27 | end Files; 28 | -------------------------------------------------------------------------------- /content/training_examples/fundamentals_of_ada/100_packages.rst: -------------------------------------------------------------------------------- 1 | ========== 2 | Packages 3 | ========== 4 | 5 | -------------- 6 | Declarations 7 | -------------- 8 | 9 | .. include:: 100_packages/declarations.rst 10 | 11 | -------- 12 | Bodies 13 | -------- 14 | 15 | .. include:: 100_packages/bodies.rst 16 | 17 | ------------------ 18 | Executable Parts 19 | ------------------ 20 | 21 | .. include:: 100_packages/executable_parts.rst 22 | 23 | -------- 24 | Idioms 25 | -------- 26 | 27 | .. include:: 100_packages/idioms.rst 28 | 29 | -------------------------------------------------------------------------------- /content/training_examples/fundamentals_of_ada/100_packages/bodies.rst: -------------------------------------------------------------------------------- 1 | .. code:: ada compile_button project=Training_Material.Fundamentals_Of_Ada.Packages.bodies 2 | 3 | package Body_Not_Allowed is 4 | type Real is digits 12; 5 | type Device_Coordinates is record 6 | X, Y : Integer; 7 | end record; 8 | type Normalized_Coordinates is record 9 | X, Y : Real range 0.0 .. 1.0; 10 | end record; 11 | -- nothing to implement, so no body allowed 12 | end Body_Not_Allowed; 13 | 14 | package Body_Required is 15 | subtype Rows is Integer range 1 .. 24; 16 | subtype Columns is Integer range 1 .. 80; 17 | type Position is record 18 | Row : Rows := Rows'First; 19 | Col : Columns := Columns'First; 20 | end record; 21 | -- The following need to be defined in the body 22 | procedure Move_Cursor (To : in Position); 23 | procedure Home; 24 | end Body_Required; 25 | 26 | with Ada.Text_IO; use Ada.Text_IO; 27 | package body Body_Required is 28 | -- This function is not visible outside this package 29 | function Unsigned (Input : Integer) return String is 30 | Str : constant String := Integer'Image (Input); 31 | begin 32 | return Str (2 .. Str'Length); 33 | end Unsigned; 34 | procedure Move_Cursor (To : in Position) is 35 | begin 36 | Put (ASCII.ESC & "I" & Unsigned(To.Row) & ";" & Unsigned(To.Col) & "H"); 37 | end Move_Cursor; 38 | procedure Home is null; -- not yet implemented 39 | end Body_Required; 40 | -------------------------------------------------------------------------------- /content/training_examples/fundamentals_of_ada/100_packages/declarations.rst: -------------------------------------------------------------------------------- 1 | .. code:: ada compile_button project=Training_Material.Fundamentals_Of_Ada.Packages.declarations 2 | 3 | package Global_Data is 4 | Object : Integer := 100; 5 | type Float_T is digits 6; 6 | end Global_Data; 7 | 8 | with Global_Data; 9 | package Float_Stack is 10 | Max : constant Integer := Global_Data.Object; 11 | procedure Push (X : in Global_Data.Float_T); 12 | function Pop return Global_Data.Float_T; 13 | end Float_Stack; 14 | 15 | package body Float_Stack is 16 | Local_Object : Global_Data.Float_T; 17 | procedure Not_Exported is null; 18 | procedure Push (X : in Global_Data.Float_T) is 19 | begin 20 | Not_Exported; 21 | Local_Object := X; 22 | end Push; 23 | function Pop return Global_Data.Float_T is (Local_Object); 24 | end Float_Stack; 25 | -------------------------------------------------------------------------------- /content/training_examples/fundamentals_of_ada/100_packages/executable_parts.rst: -------------------------------------------------------------------------------- 1 | .. code:: ada run_button project=Training_Material.Fundamentals_Of_Ada.Packages.executable_parts 2 | 3 | package Executable_Part is 4 | Visible_Seed : Integer; 5 | function Number return Float; 6 | end Executable_Part; 7 | 8 | with Ada.Text_IO; use Ada.Text_IO; 9 | package body Executable_Part is 10 | Hidden_Seed : Integer; 11 | procedure Initialize (Seed1 : out Integer; Seed2 : out Integer) is 12 | begin 13 | Seed1 := Integer'First; 14 | Seed2 := Integer'Last; 15 | end Initialize; 16 | function Number return Float is (0.0); -- not yet implemented 17 | begin 18 | Put_Line ("Elaborating Executable_Part"); 19 | Initialize (Visible_Seed, Hidden_Seed); 20 | end Executable_Part; 21 | 22 | package Force_Body is 23 | pragma Elaborate_Body; 24 | Global_Data : array (1 .. 10) of Integer; 25 | end Force_Body; 26 | 27 | -- without Elaborate_Body, this is illegal 28 | with Ada.Text_IO; use Ada.Text_IO; 29 | package body Force_Body is 30 | begin 31 | Put_Line ("Elaborating Force_Body"); 32 | for I in Global_Data'Range loop 33 | Global_Data (I) := I * 100; 34 | end loop; 35 | end Force_Body; 36 | 37 | with Executable_Part; 38 | with Force_Body; 39 | procedure Main is 40 | begin 41 | null; 42 | end Main; 43 | -------------------------------------------------------------------------------- /content/training_examples/fundamentals_of_ada/100_packages/idioms.rst: -------------------------------------------------------------------------------- 1 | .. code:: ada compile_button project=Training_Material.Fundamentals_Of_Ada.Packages.idioms 2 | 3 | package Constants is 4 | Polar_Radius : constant := 20_856_010.51; 5 | Equatorial_Radius : constant := 20_926_469.20; 6 | Earth_Diameter : constant := 7 | 2.0 * ((Polar_Radius + Equatorial_Radius) / 2.0); 8 | end Constants; 9 | 10 | package Global_Data is 11 | Longitudinal_Velocity : Float := 0.0; 12 | Longitudinal_Acceleration : Float := 0.0; 13 | Lateral_Velocity : Float := 0.0; 14 | Lateral_Acceleration : Float := 0.0; 15 | Vertical_Velocity : Float := 0.0; 16 | Vertical_Acceleration : Float := 0.0; 17 | end Global_Data; 18 | 19 | package Related_Units is 20 | type Vector is array (Positive range <>) of Float; 21 | function "+" (L, R : Vector) return Vector; 22 | function "-" (L, R : Vector) return Vector; 23 | end Related_Units; 24 | 25 | package body Related_Units is 26 | -- nothing is implemented yet! 27 | function "+" (L, R : Vector) return Vector is (L); 28 | function "-" (L, R : Vector) return Vector is (L); 29 | end Related_Units; 30 | 31 | package Stack_Abstract_Data_Machine is 32 | procedure Push (X : in Float); 33 | procedure Pop (X : out Float); 34 | function Empty return Boolean; 35 | function Full return Boolean; 36 | end Stack_Abstract_Data_Machine; 37 | 38 | package body Stack_Abstract_Data_Machine is 39 | -- nothing is implemented yet! 40 | procedure Push (X : in Float) is null; 41 | procedure Pop (X : out Float) is null; 42 | function Empty return Boolean is (True); 43 | function Full return Boolean is (True); 44 | end Stack_Abstract_Data_Machine; 45 | -------------------------------------------------------------------------------- /content/training_examples/fundamentals_of_ada/110_private_types.rst: -------------------------------------------------------------------------------- 1 | =============== 2 | Private Types 3 | =============== 4 | 5 | -------------------------------------------- 6 | Implementing Abstract Data Types Via Views 7 | -------------------------------------------- 8 | 9 | .. include:: 110_private_types/implementing_abstract_data_types_via_views.rst 10 | 11 | --------------------------- 12 | Private Part Construction 13 | --------------------------- 14 | 15 | .. include:: 110_private_types/private_part_construction.rst 16 | 17 | -------- 18 | Idioms 19 | -------- 20 | 21 | .. include:: 110_private_types/idioms.rst 22 | 23 | -------------------------------------------------------------------------------- /content/training_examples/fundamentals_of_ada/110_private_types/implementing_abstract_data_types_via_views.rst: -------------------------------------------------------------------------------- 1 | .. code:: ada run_button project=Training_Material.Fundamentals_Of_Ada.Private_Types.implementing_abstract_data_types_via_views 2 | 3 | package Bounded_Stack is 4 | Max_Capacity : constant := 100; 5 | type Stack_T is private; 6 | procedure Push (This : in out Stack_T; Item : Integer); 7 | procedure Pop (This : in out Stack_T; Item : out Integer); 8 | function Is_Empty (This : Stack_T) return Boolean; 9 | private 10 | type List_T is array (1 .. Max_Capacity) of Integer; 11 | type Stack_T is record 12 | List : List_T; 13 | Top : Integer range 0 .. Max_Capacity := 0; 14 | end record; 15 | end Bounded_Stack; 16 | 17 | package body Bounded_Stack is 18 | procedure Push (This : in out Stack_T; Item : Integer) is 19 | begin 20 | This.Top := This.Top + 1; 21 | This.List (This.Top) := Item; 22 | end Push; 23 | procedure Pop (This : in out Stack_T; Item : out Integer) is 24 | begin 25 | Item := This.List (This.Top); 26 | This.Top := This.Top - 1; 27 | end Pop; 28 | function Is_Empty (This : Stack_T) return Boolean is (This.Top = 0); 29 | end Bounded_Stack; 30 | 31 | with Ada.Text_IO; use Ada.Text_IO; 32 | with Bounded_Stack; use Bounded_Stack; 33 | procedure Main is 34 | Stack : Stack_T; 35 | Item : Integer; 36 | begin 37 | Push (Stack, 42); 38 | Put_Line (Boolean'Image (Is_Empty (Stack))); 39 | Pop (Stack, Item); 40 | --Put_Line (Integer'Image (Stack.Top)); -- compile error 41 | Put_Line (Boolean'Image (Is_Empty (Stack))); 42 | Put_Line (Item'Image); 43 | end Main; 44 | -------------------------------------------------------------------------------- /content/training_examples/fundamentals_of_ada/120_limited_types.rst: -------------------------------------------------------------------------------- 1 | =============== 2 | Limited Types 3 | =============== 4 | 5 | -------------- 6 | Declarations 7 | -------------- 8 | 9 | .. include:: 120_limited_types/declarations.rst 10 | 11 | ----------------- 12 | Creating Values 13 | ----------------- 14 | 15 | .. include:: 120_limited_types/creating_values.rst 16 | 17 | ---------------------------- 18 | Extended Return Statements 19 | ---------------------------- 20 | 21 | .. include:: 120_limited_types/extended_return_statements.rst 22 | 23 | ------------------------------------- 24 | Combining Limited And Private Views 25 | ------------------------------------- 26 | 27 | .. include:: 120_limited_types/combining_limited_and_private_views.rst 28 | 29 | -------------------------------------------------------------------------------- /content/training_examples/fundamentals_of_ada/120_limited_types/declarations.rst: -------------------------------------------------------------------------------- 1 | .. code:: ada compile_button project=Training_Material.Fundamentals_Of_Ada.Limited_Types.declarations 2 | 3 | with Interfaces; 4 | package Multiprocessor_Mutex is 5 | subtype Id_T is String (1 .. 4); 6 | -- prevent copying of a lock 7 | type Limited_T is limited record 8 | Flag : Interfaces.Unsigned_8; 9 | end record; 10 | type Also_Limited_T is record 11 | Lock : Limited_T; 12 | Id : Id_T; 13 | end record; 14 | procedure Lock (This : in out Also_Limited_T) is null; 15 | procedure Unlock (This : in out Also_Limited_T) is null; 16 | end Multiprocessor_Mutex; 17 | 18 | -------------------------------------------------------------------------------- /content/training_examples/fundamentals_of_ada/130_program_structure.rst: -------------------------------------------------------------------------------- 1 | =================== 2 | Program Structure 3 | =================== 4 | 5 | ---------------------- 6 | Limited With Clauses 7 | ---------------------- 8 | 9 | .. include:: 130_program_structure/limited_with_clauses.rst 10 | 11 | ---------------------------- 12 | Hierarchical Library Units 13 | ---------------------------- 14 | 15 | .. include:: 130_program_structure/hierarchical_library_units.rst 16 | 17 | ------------------- 18 | Visibility Limits 19 | ------------------- 20 | 21 | .. include:: 130_program_structure/visibility_limits.rst 22 | 23 | ------------------ 24 | Private Children 25 | ------------------ 26 | 27 | .. include:: 130_program_structure/private_children.rst 28 | 29 | -------------------------------------------------------------------------------- /content/training_examples/fundamentals_of_ada/130_program_structure/hierarchical_library_units.rst: -------------------------------------------------------------------------------- 1 | .. code:: ada compile_button project=Training_Material.Fundamentals_Of_Ada.Program_Structure.hierarchical_library_units 2 | 3 | package Complex is 4 | type Number is private; 5 | function "+" (Left, Right : Number) return Number; 6 | function "-" (Left, Right : Number) return Number; 7 | private 8 | type Number is record 9 | Real_Part, Imaginary_Part : Float; 10 | end record; 11 | end Complex; 12 | 13 | package Complex.Utils is 14 | function To_String (C : Number) return String; 15 | end Complex.Utils; 16 | 17 | package body Complex.Utils is 18 | -- construction of "number" is visible in the child body 19 | function To_String (C : Number) return String is 20 | (C.Real_Part'Image & " + i" & C.Imaginary_Part'Image); 21 | end Complex.Utils; 22 | 23 | package Complex.Debug is 24 | -- "with Complex;" not needed for visibility to Number 25 | procedure Print (C : Number); 26 | end Complex.Debug; 27 | 28 | with Ada.Text_IO; 29 | with Complex.Utils; -- needed for visibility to "To_String" 30 | package body Complex.Debug is 31 | procedure Print (C : Number) is 32 | begin 33 | -- because of parent visibility, don't need to use "Complex.Utils" 34 | Ada.Text_IO.Put_Line (Utils.To_String (C)); 35 | end Print; 36 | end Complex.Debug; 37 | 38 | package body Complex is 39 | function "+" (Left, Right : Number) return Number is (Left); 40 | function "-" (Left, Right : Number) return Number is (Left); 41 | end Complex; 42 | -------------------------------------------------------------------------------- /content/training_examples/fundamentals_of_ada/130_program_structure/limited_with_clauses.rst: -------------------------------------------------------------------------------- 1 | .. code:: ada compile_button project=Training_Material.Fundamentals_Of_Ada.Program_Structure.limited_with_clauses 2 | 3 | limited with Department; 4 | package Personnel is 5 | type Employee_T is private; 6 | procedure Assign (This : in out Employee_T; Section : in Department.Section_T); 7 | private 8 | type Employee_T is record 9 | Name : String (1 .. 10); 10 | Assigned_To : access Department.Section_T; 11 | end record; 12 | end Personnel; 13 | 14 | limited with Personnel; 15 | package Department is 16 | type Section_T is private; 17 | procedure Set_Manager (This : in out Section_T; Who : in Personnel.Employee_T); 18 | private 19 | type Section_T is record 20 | Name : String (1 .. 10); 21 | Manager : access Personnel.Employee_T; 22 | end record; 23 | end Department; 24 | 25 | with Department; 26 | package body Personnel is 27 | procedure Assign (This : in out Employee_T; Section : in Department.Section_T) is 28 | begin 29 | This.Assigned_To.all := Section; 30 | end Assign; 31 | end Personnel; 32 | 33 | with Personnel; 34 | package body Department is 35 | procedure Set_Manager (This : in out Section_T; Who : in Personnel.Employee_T) is 36 | begin 37 | This.Manager.all := Who; 38 | end Set_Manager; 39 | end Department; 40 | -------------------------------------------------------------------------------- /content/training_examples/fundamentals_of_ada/130_program_structure/private_children.rst: -------------------------------------------------------------------------------- 1 | .. code:: ada compile_button project=Training_Material.Fundamentals_Of_Ada.Program_Structure.private_children 2 | 3 | package Os is 4 | type File_T is private; 5 | function Open (Name : String) return File_T; 6 | procedure Write (File : File_T; Str : String); 7 | procedure Close (File : File_T); 8 | private 9 | type File_T is new Integer; 10 | end Os; 11 | 12 | private package Os.Uart is 13 | type Device_T is private; 14 | function Open (Name : String) return Device_T; 15 | procedure Write (Device : Device_T; Str : String); 16 | procedure Close (Device : Device_T); 17 | private 18 | type Device_T is new Integer; 19 | end Os.Uart; 20 | 21 | private with Os.Uart; -- references only in private section 22 | private package Os.Serial is 23 | type Comport_T is private; 24 | procedure Initialize (Comport : in out Comport_T); 25 | private 26 | type Comport_T is record 27 | Device : Uart.Device_T; 28 | end record; 29 | end Os.Serial; 30 | 31 | package body Os is 32 | function Open (Name : String) return File_T is (1); 33 | procedure Write (File : File_T; Str : String) is null; 34 | procedure Close (File : File_T) is null; 35 | end Os; 36 | 37 | package body Os.Uart is 38 | function Open (Name : String) return Device_T is (1); 39 | procedure Write (Device : Device_T; Str : String) is null; 40 | procedure Close (Device : Device_T) is null; 41 | end Os.Uart; 42 | 43 | package body Os.Serial is 44 | procedure Initialize (Comport : in out Comport_T) is null; 45 | end Os.Serial; 46 | -------------------------------------------------------------------------------- /content/training_examples/fundamentals_of_ada/130_program_structure/visibility_limits.rst: -------------------------------------------------------------------------------- 1 | .. code:: ada compile_button project=Training_Material.Fundamentals_Of_Ada.Program_Structure.visibility_limits 2 | 3 | package Stack is 4 | procedure Push (Item : in Integer); 5 | procedure Pop (Item : out Integer); 6 | private 7 | Object : array (1 .. 100) of integer; 8 | Top : Natural := 0; 9 | end Stack; 10 | 11 | package Stack.Utils is 12 | function Top return Integer; 13 | private 14 | -- Legal here, but not above "private" 15 | function Top return Integer is (Object (Stack.Top)); 16 | end Stack.Utils; 17 | 18 | package Stack.Child is 19 | procedure Misbehave; 20 | procedure Reset; 21 | function Peek (Index : Natural) return Integer; 22 | end Stack.Child; 23 | 24 | package body Stack.Child is 25 | procedure Misbehave is 26 | begin 27 | Top := 0; 28 | end Misbehave; 29 | 30 | procedure Reset is 31 | begin 32 | Top := 0; 33 | end Reset; 34 | 35 | function Peek (Index : Natural) return Integer is (Object (Index)); 36 | end Stack.Child; 37 | 38 | package body Stack is 39 | procedure Push (Item : in Integer) is null; 40 | procedure Pop (Item : out Integer) is null; 41 | end Stack; 42 | -------------------------------------------------------------------------------- /content/training_examples/fundamentals_of_ada/135_visibility.rst: -------------------------------------------------------------------------------- 1 | ============ 2 | Visibility 3 | ============ 4 | 5 | ------------- 6 | Use Clauses 7 | ------------- 8 | 9 | .. include:: 135_visibility/use_clauses.rst 10 | 11 | ------------------ 12 | Use Type Clauses 13 | ------------------ 14 | 15 | .. include:: 135_visibility/use_type_clauses.rst 16 | 17 | ---------------------- 18 | Use All Type Clauses 19 | ---------------------- 20 | 21 | .. include:: 135_visibility/use_all_type_clauses.rst 22 | 23 | -------------------------------------------------------------------------------- /content/training_examples/fundamentals_of_ada/135_visibility/use_type_clauses.rst: -------------------------------------------------------------------------------- 1 | .. code:: ada run_button project=Training_Material.Fundamentals_Of_Ada.Visibility.use_type_clauses 2 | 3 | package P is 4 | type Int1 is range 0 .. 1_000; 5 | type Int2 is range 0 .. 2_000; 6 | type Int3 is range 0 .. 3_000; 7 | function "+" (Left : Int1; Right : Int3) return Int3; 8 | function "+" (Left : Int2; Right : Int3) return Int3; 9 | end P; 10 | 11 | with Ada.Text_IO; use Ada.Text_IO; 12 | with P; 13 | procedure Test is 14 | A, B, C : P.Int1 := 123; 15 | use type P.Int1; 16 | -- D : Int2; -- "Int2" is not visible 17 | D : P.Int2 := 234; 18 | E : P.Int3 := 345; 19 | begin 20 | B := A; 21 | C := A + B; -- implicit operator is visible 22 | Put_Line (C'Image); 23 | A := B; 24 | E := A + E; -- "used" operator visible 25 | Put_Line (E'Image); 26 | -- E := D + E; -- illegal: operator not "used" 27 | -- E := E + A; -- illegal: no matching operator 28 | end Test; 29 | 30 | package body P is 31 | function "+" (Left : Int1; Right : Int3) return Int3 is (Int3'Last); 32 | function "+" (Left : Int2; Right : Int3) return Int3 is (Int3'Last); 33 | end P; 34 | -------------------------------------------------------------------------------- /content/training_examples/fundamentals_of_ada/140_access_types.rst: -------------------------------------------------------------------------------- 1 | ============== 2 | Access Types 3 | ============== 4 | 5 | ---------------------------- 6 | Pool Specific Access Types 7 | ---------------------------- 8 | 9 | .. include:: 140_access_types/pool_specific_access_types.rst 10 | 11 | ---------------------- 12 | General Access Types 13 | ---------------------- 14 | 15 | .. include:: 140_access_types/general_access_types.rst 16 | 17 | -------------- 18 | Access Types 19 | -------------- 20 | 21 | .. include:: 140_access_types/access_types.rst 22 | 23 | ---------------------- 24 | Accessibility Checks 25 | ---------------------- 26 | 27 | .. include:: 140_access_types/accessibility_checks.rst 28 | 29 | ------------------- 30 | Memory Management 31 | ------------------- 32 | 33 | .. include:: 140_access_types/memory_management.rst 34 | 35 | ------------------------ 36 | Anonymous Access Types 37 | ------------------------ 38 | 39 | .. include:: 140_access_types/anonymous_access_types.rst 40 | 41 | -------------------------------------------------------------------------------- /content/training_examples/fundamentals_of_ada/140_access_types/access_types.rst: -------------------------------------------------------------------------------- 1 | .. code:: ada compile_button project=Training_Material.Fundamentals_Of_Ada.Access_Types.access_types 2 | 3 | package Access_Types is 4 | 5 | type R is record 6 | F1, F2 : Integer; 7 | end record; 8 | type A_Int is access Integer; 9 | type A_String is access all String; 10 | type A_R is access R; 11 | 12 | V_Int : A_Int := new Integer; 13 | V_String : A_String := new String'("abc"); 14 | V_R : A_R := new R; 15 | 16 | procedure Do_Something; 17 | 18 | end Access_Types; 19 | 20 | package body Access_Types is 21 | 22 | function Local_Access_Example return Integer is 23 | type String_Access is access String; -- only visible here 24 | X : String_Access; 25 | begin 26 | X := new String'("Hello, World"); 27 | return X.all'Length; 28 | end Local_Access_Example; 29 | 30 | procedure Do_Something is 31 | begin 32 | V_Int.all := Local_Access_Example; 33 | V_String.all := "cde"; 34 | V_String (1) := 'z'; -- similar to V_String.all (1) := 'z'; 35 | V_R.all := (0, 0); 36 | V_R.F1 := 1; -- similar to V_R.all.F1 := 1; 37 | V_Int := null; 38 | V_R := null; 39 | end Do_Something; 40 | 41 | end Access_Types; 42 | -------------------------------------------------------------------------------- /content/training_examples/fundamentals_of_ada/140_access_types/general_access_types.rst: -------------------------------------------------------------------------------- 1 | .. code:: ada run_button project=Training_Material.Fundamentals_Of_Ada.Access_Types.general_access_types 2 | 3 | package General is 4 | type Pointed_To_T is new Integer; 5 | type Access_T is access all Pointed_To_T; 6 | Object : Access_T := new Pointed_To_T; 7 | 8 | type Other_Access_T is access all Pointed_To_T; 9 | Other_Object : Other_Access_T := Other_Access_T (Object); 10 | 11 | Pointed_To : aliased Pointed_To_T := 1_234; 12 | 13 | end General; 14 | 15 | with Ada.Text_IO; use Ada.Text_IO; 16 | with General; use General; 17 | procedure Use_General is 18 | begin 19 | Object := Pointed_To'Access; 20 | Put_Line (Pointed_To'Image & Pointed_To_T'Image (Object.all)); 21 | Pointed_To := Pointed_To + 1; 22 | Put_Line (Pointed_To'Image & Pointed_To_T'Image (Object.all)); 23 | Object.all := Object.all * 2; 24 | Put_Line (Pointed_To'Image & Pointed_To_T'Image (Object.all)); 25 | end Use_General; 26 | -------------------------------------------------------------------------------- /content/training_examples/fundamentals_of_ada/140_access_types/pool_specific_access_types.rst: -------------------------------------------------------------------------------- 1 | .. code:: ada run_button project=Training_Material.Fundamentals_Of_Ada.Access_Types.pool_specific_access_types 2 | 3 | package Pool_Specific is 4 | type Pointed_To_T is new Integer; 5 | type Access_T is access Pointed_To_T; 6 | Object : Access_T := new Pointed_To_T; 7 | 8 | type Other_Access_T is access Pointed_To_T; 9 | -- Other_Object : Other_Access_T := Other_Access_T ( Object ); -- illegal 10 | 11 | type String_Access_T is access String; 12 | end Pool_Specific; 13 | 14 | with Ada.Unchecked_Deallocation; 15 | with Ada.Text_IO; use Ada.Text_IO; 16 | with Pool_Specific; use Pool_Specific; 17 | procedure Use_Pool_Specific is 18 | X : Access_T := new Pointed_To_T'(123); 19 | Y : String_Access_T := new String (1 .. 10); 20 | 21 | procedure Free is new Ada.Unchecked_Deallocation (Pointed_To_T, Access_T); 22 | 23 | begin 24 | Put_Line (Y.all); 25 | Y := new String'("String will be long enough to hold this"); 26 | Put_Line (Y.all); 27 | Put_Line (Pointed_To_T'Image (X.all)); 28 | Free (X); 29 | Put_Line (Pointed_To_T'Image (X.all)); -- run-time error 30 | end Use_Pool_Specific; 31 | -------------------------------------------------------------------------------- /content/training_examples/fundamentals_of_ada/160_genericity.rst: -------------------------------------------------------------------------------- 1 | ============ 2 | Genericity 3 | ============ 4 | 5 | -------------- 6 | Generic Data 7 | -------------- 8 | 9 | .. include:: 160_genericity/generic_data.rst 10 | 11 | --------------------- 12 | Generic Formal Data 13 | --------------------- 14 | 15 | .. include:: 160_genericity/generic_formal_data.rst 16 | 17 | -------------------------------------------------------------------------------- /content/training_examples/fundamentals_of_ada/170_inheritance.rst: -------------------------------------------------------------------------------- 1 | ============= 2 | Inheritance 3 | ============= 4 | 5 | ------------ 6 | Primitives 7 | ------------ 8 | 9 | .. include:: 170_inheritance/primitives.rst 10 | 11 | ------------------- 12 | Simple Derivation 13 | ------------------- 14 | 15 | .. include:: 170_inheritance/simple_derivation.rst 16 | 17 | ------------------- 18 | Tagged Derivation 19 | ------------------- 20 | 21 | .. include:: 170_inheritance/tagged_derivation.rst 22 | 23 | -------------------------------------------------------------------------------- /content/training_examples/fundamentals_of_ada/170_inheritance/primitives.rst: -------------------------------------------------------------------------------- 1 | .. code:: ada compile_button project=Training_Material.Fundamentals_Of_Ada.Inheritance.primitives 2 | 3 | package Primitives_Example is 4 | 5 | type Record_T is record 6 | Field : Integer; 7 | end record; 8 | type Access_To_Record_T is access Record_T; 9 | type Array_T is array (1 .. 10) of Integer; 10 | 11 | procedure Primitive_Of_Record_T (P : in out Record_T) is null; 12 | function Primitive_Of_Record_T (P : Integer) return Record_T is 13 | ((Field => P)); 14 | procedure Primitive_Of_Record_T (I : Integer; 15 | P : access Record_T) is null; 16 | procedure Not_A_Primitive_Of_Record_T 17 | (I : Integer; P : Access_To_Record_T) is null; 18 | 19 | procedure Primitive_Of_Record_T_And_Array_T 20 | (P1 : in out Record_T; P2 : in out Array_T) is null; 21 | end Primitives_Example; 22 | -------------------------------------------------------------------------------- /content/training_examples/fundamentals_of_ada/180_polymorphism.rst: -------------------------------------------------------------------------------- 1 | ============== 2 | Polymorphism 3 | ============== 4 | 5 | ------------------ 6 | Classes Of Types 7 | ------------------ 8 | 9 | .. include:: 180_polymorphism/classes_of_types.rst 10 | 11 | ------------------------------- 12 | Dispatching And Redispatching 13 | ------------------------------- 14 | 15 | .. include:: 180_polymorphism/dispatching_and_redispatching.rst 16 | 17 | ------------------------------- 18 | Exotic Dispatching Operations 19 | ------------------------------- 20 | 21 | .. include:: 180_polymorphism/exotic_dispatching_operations.rst 22 | 23 | -------------------------------------------------------------------------------- /content/training_examples/fundamentals_of_ada/180_polymorphism/dispatching_and_redispatching.rst: -------------------------------------------------------------------------------- 1 | .. code:: ada run_button project=Training_Material.Fundamentals_Of_Ada.Polymorphism.dispatching_and_redispatching 2 | 3 | package Types is 4 | 5 | type Root_T is tagged null record; 6 | function Primitive (V : Root_T) return String is ("Root_T"); 7 | 8 | type Child_T is new Root_T with null record; 9 | function Primitive (V : Child_T) return String is ("Child_T"); 10 | 11 | end Types; 12 | 13 | with Ada.Text_IO; use Ada.Text_IO; 14 | with Types; use Types; 15 | procedure Test_Dispatching_And_Redispatching is 16 | 17 | Root_Object : Root_T; 18 | Child_Object : Child_T; 19 | 20 | V1 : constant Root_T'Class := Root_Object; 21 | V2 : constant Root_T'Class := Child_Object; 22 | V3 : constant Child_T'Class := Child_Object; 23 | 24 | begin 25 | 26 | Put_Line (Primitive (V1)); 27 | Put_Line (Primitive (V2)); 28 | Put_Line (Primitive (V3)); 29 | 30 | end Test_Dispatching_And_Redispatching; 31 | -------------------------------------------------------------------------------- /content/training_examples/fundamentals_of_ada/190_exceptions.rst: -------------------------------------------------------------------------------- 1 | ============ 2 | Exceptions 3 | ============ 4 | 5 | ---------- 6 | Handlers 7 | ---------- 8 | 9 | .. include:: 190_exceptions/handlers.rst 10 | 11 | --------------------------------------------- 12 | Implicitly And Explicitly Raised Exceptions 13 | --------------------------------------------- 14 | 15 | .. include:: 190_exceptions/implicitly_and_explicitly_raised_exceptions.rst 16 | 17 | ------------------------- 18 | User Defined Exceptions 19 | ------------------------- 20 | 21 | .. include:: 190_exceptions/user_defined_exceptions.rst 22 | 23 | ------------- 24 | Propagation 25 | ------------- 26 | 27 | .. include:: 190_exceptions/propagation.rst 28 | 29 | ----------------------- 30 | Exceptions As Objects 31 | ----------------------- 32 | 33 | .. include:: 190_exceptions/exceptions_as_objects.rst 34 | 35 | -------------------------------------------------------------------------------- /content/training_examples/fundamentals_of_ada/190_exceptions/exceptions_as_objects.rst: -------------------------------------------------------------------------------- 1 | .. code:: ada run_button project=Training_Material.Fundamentals_Of_Ada.Exceptions.exceptions_as_objects 2 | 3 | package Exception_Objects_Example is 4 | 5 | Public_Exception : exception; 6 | 7 | procedure Do_Something (X : Integer); 8 | 9 | end Exception_Objects_Example; 10 | 11 | package body Exception_Objects_Example is 12 | Hidden_Exception : exception; 13 | 14 | procedure Do_Something (X : Integer) is 15 | begin 16 | if X < 0 then 17 | raise Public_Exception; 18 | elsif X = 0 then 19 | raise Hidden_Exception; 20 | end if; 21 | end Do_Something; 22 | 23 | end Exception_Objects_Example; 24 | 25 | with Ada.Exceptions; use Ada.Exceptions; 26 | with Ada.Text_IO; use Ada.Text_IO; 27 | with Exception_Objects_Example; use Exception_Objects_Example; 28 | procedure Test_Exception_Objects_Example is 29 | begin 30 | 31 | for I in -1 .. 1 loop 32 | begin 33 | Put_Line ("Try " & I'Image); 34 | Do_Something (I); 35 | Put_Line (" success"); 36 | exception 37 | when Public_Exception => 38 | Put_Line (" Expected exception"); 39 | when The_Err : others => 40 | Put_Line (" Unexpected exception"); 41 | Put_Line (" Name: " & Exception_Name (The_Err)); 42 | Put_Line (" Information: " & Exception_Information (The_Err)); 43 | Put_Line (" Message: " & Exception_Message (The_Err)); 44 | end; 45 | end loop; 46 | 47 | end Test_Exception_Objects_Example; 48 | -------------------------------------------------------------------------------- /content/training_examples/fundamentals_of_ada/190_exceptions/propagation.rst: -------------------------------------------------------------------------------- 1 | .. code:: ada run_button project=Training_Material.Fundamentals_Of_Ada.Exceptions.propagation 2 | 3 | with Ada.Text_IO; use Ada.Text_IO; 4 | with GNAT.Random_Numbers; use GNAT.Random_Numbers; 5 | procedure Propagation is 6 | Error1 : exception; 7 | Error2 : exception; 8 | 9 | Gen : Generator; 10 | procedure Maybe_Raise is 11 | Test : constant Float := Random (Gen); 12 | begin 13 | if Test > 0.666 then 14 | raise Error1; 15 | end if; 16 | exception 17 | when Error1 => 18 | if Test > 0.95 then 19 | raise Error2; 20 | else 21 | raise; 22 | end if; 23 | end Maybe_Raise; 24 | 25 | procedure One is 26 | begin 27 | Maybe_Raise; 28 | end One; 29 | 30 | procedure Two is 31 | begin 32 | One; 33 | Maybe_Raise; 34 | exception 35 | when Error1 => 36 | Put_Line ("Exception from 1 or 2"); 37 | end Two; 38 | 39 | begin 40 | Reset (Gen); 41 | Maybe_Raise; 42 | Two; 43 | exception 44 | when Error1 => 45 | Put_Line ("Exception from 3"); 46 | end Propagation; 47 | -------------------------------------------------------------------------------- /content/training_examples/fundamentals_of_ada/190_exceptions/user_defined_exceptions.rst: -------------------------------------------------------------------------------- 1 | .. code:: ada run_button project=Training_Material.Fundamentals_Of_Ada.Exceptions.user_defined_exceptions 2 | 3 | package Stack is 4 | Underflow, Overflow : exception; 5 | procedure Push (Item : in Integer); 6 | procedure Pop (Item : out Integer); 7 | end Stack; 8 | 9 | package body Stack is 10 | Values : array (1 .. 100) of Integer; 11 | Top : Integer := 0; 12 | 13 | procedure Push (Item : in Integer) is 14 | begin 15 | if Top = Values'Last then 16 | raise Overflow; 17 | end if; 18 | Top := Top + 1; 19 | Values (Top) := Item; 20 | end Push; 21 | 22 | procedure Pop (Item : out Integer) is 23 | begin 24 | if Top < Values'First then 25 | raise Underflow; 26 | end if; 27 | Item := Values (Top); 28 | Top := Top - 1; 29 | end Pop; 30 | end Stack; 31 | 32 | with Ada.Text_IO; use Ada.Text_IO; 33 | with Stack; 34 | procedure Test_Stack is 35 | Global : Integer := 123; 36 | 37 | procedure Push (X : Integer) is 38 | begin 39 | Stack.Push (X); 40 | exception 41 | when Stack.Overflow => 42 | Put_Line ("No room on the stack"); 43 | end Push; 44 | 45 | procedure Pop is 46 | begin 47 | Stack.Pop (Global); 48 | exception 49 | when Stack.Underflow => 50 | Put_Line ("Nothing on the stack"); 51 | end Pop; 52 | 53 | begin 54 | Pop; 55 | for I in 1 .. 100 loop 56 | Push (I); 57 | end loop; 58 | Push (2); 59 | end Test_Stack; 60 | -------------------------------------------------------------------------------- /content/training_examples/fundamentals_of_ada/200_elaboration.rst: -------------------------------------------------------------------------------- 1 | ============= 2 | Elaboration 3 | ============= 4 | 5 | ------------- 6 | Elaboration 7 | ------------- 8 | 9 | .. include:: 200_elaboration/elaboration.rst 10 | 11 | --------------------- 12 | Elaboration Control 13 | --------------------- 14 | 15 | .. include:: 200_elaboration/elaboration_control.rst 16 | 17 | -------------------------------------------------------------------------------- /content/training_examples/fundamentals_of_ada/200_elaboration/elaboration.rst: -------------------------------------------------------------------------------- 1 | .. code:: ada run_button project=Training_Material.Fundamentals_Of_Ada.Elaboration.elaboration 2 | 3 | with Initializer; use Initializer; 4 | package Elab_1 is 5 | Spec_Object : Integer := Call (101); 6 | procedure Proc; 7 | end Elab_1; 8 | 9 | package body Elab_1 is 10 | Body_Object : Integer := Call (102); 11 | procedure Proc is null; 12 | begin 13 | Body_Object := Body_Object + Call (103); 14 | end Elab_1; 15 | 16 | with Initializer; use Initializer; 17 | package Elab_2 is 18 | Spec_Object : Integer := Call (201); 19 | procedure Proc; 20 | end Elab_2; 21 | 22 | package body Elab_2 is 23 | Body_Object : Integer := Call (202); 24 | procedure Proc is null; 25 | begin 26 | Body_Object := Body_Object + Call (203); 27 | end Elab_2; 28 | 29 | with Elab_2; 30 | with Elab_1; 31 | procedure Test_Elab is 32 | begin 33 | Elab_2.Proc; 34 | Elab_1.Proc; 35 | end Test_Elab; 36 | 37 | package Initializer is 38 | function Call (I : Integer) return Integer; 39 | end Initializer; 40 | 41 | with Ada.Text_IO; use Ada.Text_IO; 42 | package body Initializer is 43 | function Call (I : Integer) return Integer is 44 | begin 45 | Put_Line ("Call with " & Integer'Image (I)); 46 | return I; 47 | end Call; 48 | end Initializer; 49 | -------------------------------------------------------------------------------- /content/training_examples/fundamentals_of_ada/210_subprogram_contracts.rst: -------------------------------------------------------------------------------- 1 | ====================== 2 | Subprogram Contracts 3 | ====================== 4 | 5 | ---------------------------------- 6 | Preconditions And Postconditions 7 | ---------------------------------- 8 | 9 | .. include:: 210_subprogram_contracts/preconditions_and_postconditions.rst 10 | 11 | -------------------------------------------------------------------------------- /content/training_examples/fundamentals_of_ada/210_subprogram_contracts/preconditions_and_postconditions.rst: -------------------------------------------------------------------------------- 1 | .. code:: ada run_button project=Training_Material.Fundamentals_Of_Ada.Subprogram_Contracts.preconditions_and_postconditions 2 | 3 | package Stack_Pkg is 4 | procedure Push (Item : in Integer) with 5 | Pre => not Full, 6 | Post => not Empty and then Top = Item; 7 | procedure Pop (Item : out Integer) with 8 | Pre => not Empty, 9 | Post => not Full and Item = Top'Old; 10 | function Pop return Integer with 11 | Pre => not Empty, 12 | Post => not Full and Pop'Result = Top'Old; 13 | function Top return Integer with 14 | Pre => not Empty; 15 | function Empty return Boolean; 16 | function Full return Boolean; 17 | end Stack_Pkg; 18 | 19 | package body Stack_Pkg is 20 | Values : array (1 .. 100) of Integer; 21 | Current : Natural := 0; 22 | 23 | -- Push/Pop cannot fail because preconditions prevent it 24 | procedure Push (Item : in Integer) is 25 | begin 26 | Current := Current + 1; 27 | Values (Current) := Item; 28 | end Push; 29 | 30 | procedure Pop (Item : out Integer) is 31 | begin 32 | Item := Values (Current); 33 | Current := Current - 1; 34 | end Pop; 35 | 36 | function Pop return Integer is 37 | Item : constant Integer := Values (Current); 38 | begin 39 | Current := Current - 1; 40 | return Item; 41 | end Pop; 42 | 43 | function Top return Integer is (Values (Current)); 44 | function Empty return Boolean is (Current not in Values'Range); 45 | function Full return Boolean is (Current >= Values'Length); 46 | end Stack_Pkg; 47 | -------------------------------------------------------------------------------- /content/training_examples/fundamentals_of_ada/215_type_contracts.rst: -------------------------------------------------------------------------------- 1 | ================ 2 | Type Contracts 3 | ================ 4 | 5 | ----------------- 6 | Type Invariants 7 | ----------------- 8 | 9 | .. include:: 215_type_contracts/type_invariants.rst 10 | 11 | -------------------- 12 | Subtype Predicates 13 | -------------------- 14 | 15 | .. include:: 215_type_contracts/subtype_predicates.rst 16 | 17 | -------------------------------------------------------------------------------- /content/training_examples/fundamentals_of_ada/220_low_level_programming.rst: -------------------------------------------------------------------------------- 1 | ======================= 2 | Low Level Programming 3 | ======================= 4 | 5 | --------------------- 6 | Data Representation 7 | --------------------- 8 | 9 | .. include:: 220_low_level_programming/data_representation.rst 10 | 11 | ------------------------------ 12 | Address Clauses And Overlays 13 | ------------------------------ 14 | 15 | .. include:: 220_low_level_programming/address_clauses_and_overlays.rst 16 | 17 | -------------------------------------------------------------------------------- /content/training_examples/fundamentals_of_ada/240_tasking.rst: -------------------------------------------------------------------------------- 1 | ========= 2 | Tasking 3 | ========= 4 | 5 | ------- 6 | Tasks 7 | ------- 8 | 9 | .. include:: 240_tasking/tasks.rst 10 | 11 | ------------------- 12 | Protected Objects 13 | ------------------- 14 | 15 | .. include:: 240_tasking/protected_objects.rst 16 | 17 | -------------------------- 18 | Task And Protected Types 19 | -------------------------- 20 | 21 | .. include:: 240_tasking/task_and_protected_types.rst 22 | 23 | ------------------------ 24 | Some Advanced Concepts 25 | ------------------------ 26 | 27 | .. include:: 240_tasking/some_advanced_concepts.rst 28 | 29 | -------------------------------------------------------------------------------- /content/training_examples/fundamentals_of_ada/240_tasking/tasks.rst: -------------------------------------------------------------------------------- 1 | .. code:: ada run_button project=Training_Material.Fundamentals_Of_Ada.Tasking.tasks 2 | 3 | package Tasks is 4 | task T is 5 | entry Start; 6 | entry Receive_Message (V : String); 7 | end T; 8 | end Tasks; 9 | 10 | with Ada.Text_IO; use Ada.Text_IO; 11 | package body Tasks is 12 | task body T is 13 | begin 14 | loop 15 | accept Start do 16 | Put_Line ("Start"); 17 | end Start; 18 | accept Receive_Message (V : String) do 19 | Put_Line ("Receive " & V); 20 | end Receive_Message; 21 | end loop; 22 | end T; 23 | end Tasks; 24 | 25 | with Ada.Text_IO; use Ada.Text_IO; 26 | with Tasks; use Tasks; 27 | procedure Test_Tasks is 28 | begin 29 | Put_Line ("calling start"); 30 | T.Start; 31 | Put_Line ("calling receive 1"); 32 | T.Receive_Message ("1"); 33 | Put_Line ("calling receive 2"); 34 | -- Locks until somebody calls Start 35 | T.Receive_Message ("2"); 36 | end Test_Tasks; 37 | -------------------------------------------------------------------------------- /content/training_examples/fundamentals_of_ada/index.rst: -------------------------------------------------------------------------------- 1 | .. toctree:: 2 | :maxdepth: 4 3 | :caption: Contents: 4 | 5 | Declarations <020_declarations> 6 | Basic Types <030_basic_types> 7 | Statements <040_statements> 8 | Array Types <050_array_types> 9 | Record Types <060_record_types> 10 | Subprograms <070_subprograms> 11 | Expressions <080_expressions> 12 | Overloading <090_overloading> 13 | Library Units <095_library_units> 14 | Packages <100_packages> 15 | Private Types <110_private_types> 16 | Limited Types <120_limited_types> 17 | Program Structure <130_program_structure> 18 | Visibility <135_visibility> 19 | Access Types <140_access_types> 20 | Genericity <160_genericity> 21 | Inheritance <170_inheritance> 22 | Polymorphism <180_polymorphism> 23 | Exceptions <190_exceptions> 24 | Elaboration <200_elaboration> 25 | Subprogram Contracts <210_subprogram_contracts> 26 | Type Contracts <215_type_contracts> 27 | Low Level Programming <220_low_level_programming> 28 | Tasking <240_tasking> 29 | -------------------------------------------------------------------------------- /content/training_examples/training_examples.rst: -------------------------------------------------------------------------------- 1 | .. meta:: 2 | :author: AdaCore 3 | 4 | :orphan: 5 | 6 | :prev_state: False 7 | :next_state: False 8 | 9 | Training Examples 10 | ============================= 11 | 12 | .. toctree:: 13 | :maxdepth: 1 14 | 15 | Fundamentals of Ada 16 | -------------------------------------------------------------------------------- /frontend/.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | npm-debug.log 3 | *.map 4 | build-manifest.json 5 | dist 6 | .nyc_output/ 7 | coverage/ 8 | yarn-error.log 9 | .coverage -------------------------------------------------------------------------------- /frontend/.mocharc.json: -------------------------------------------------------------------------------- 1 | { 2 | "diff": true, 3 | "extension": [ 4 | "ts" 5 | ], 6 | "reporter": "spec", 7 | "slow": 75, 8 | "timeout": 200000, 9 | "ui": "bdd", 10 | "require": [ 11 | "mocha.env", 12 | "ts-node/register", 13 | "jsdom-global/register" 14 | ], 15 | "node-option": [ 16 | "disable-warning=ExperimentalWarning", 17 | "experimental-specifier-resolution=node", 18 | "loader=ts-node/esm" 19 | ], 20 | "spec": "tests/**/*.spec.ts" 21 | } 22 | -------------------------------------------------------------------------------- /frontend/.yarnrc.yml: -------------------------------------------------------------------------------- 1 | nodeLinker: node-modules 2 | -------------------------------------------------------------------------------- /frontend/azw3_style.css: -------------------------------------------------------------------------------- 1 | ul p { 2 | margin-block-start: 0.1em; 3 | margin-block-end: 0.1em; 4 | } 5 | 6 | ol p { 7 | margin-block-start: 0.1em; 8 | margin-block-end: 0.1em; 9 | } 10 | 11 | code.code { 12 | font-size: 0.95em; 13 | } 14 | -------------------------------------------------------------------------------- /frontend/mocha.env: -------------------------------------------------------------------------------- 1 | process.env.TS_NODE_PROJECT = 'tsconfig.json' 2 | -------------------------------------------------------------------------------- /frontend/py_modules/code_projects/__init__.py: -------------------------------------------------------------------------------- 1 | __title__ = 'code_projects' 2 | __version__ = '0.2.0' 3 | -------------------------------------------------------------------------------- /frontend/py_modules/code_projects/checks.py: -------------------------------------------------------------------------------- 1 | import os 2 | import re 3 | import hashlib 4 | import json 5 | import time 6 | 7 | class CodeCheck(object): 8 | def __init__(self, timestamp=None, 9 | version=None, status_ok=None, 10 | logfile=None, cmdline=None): 11 | 12 | self.version = version 13 | self.status_ok = status_ok 14 | self.logfile = logfile 15 | self.cmdline = cmdline 16 | self.timestamp = timestamp if timestamp is not None else time.time() 17 | 18 | 19 | class BlockCheck(object): 20 | @staticmethod 21 | def from_json_file(json_filename=None): 22 | 23 | if json_filename is None: 24 | json_filename = "block_checks.json" 25 | 26 | if os.path.isfile(json_filename): 27 | with open(json_filename, u'r') as f: 28 | block_checks_json = json.load(f) 29 | return BlockCheck(**block_checks_json) 30 | 31 | return None 32 | 33 | def __init__(self, text_hash, text_hash_short, 34 | timestamp=None, 35 | status_ok=None, 36 | checks=None): 37 | 38 | self.text_hash: str = text_hash 39 | self.text_hash_short: str = text_hash_short 40 | self.timestamp = timestamp if timestamp is not None else time.time() 41 | self.status_ok = status_ok 42 | self.checks = dict() 43 | 44 | def to_json_file(self, json_filename=None): 45 | block_checks = self.__dict__ 46 | 47 | if json_filename is None: 48 | json_filename = "block_checks.json" 49 | with open(json_filename, u'w') as f: 50 | json.dump(block_checks, f, indent=4, default=lambda __o: __o.__dict__) 51 | 52 | def add_check(self, check_type : str, code_check : CodeCheck): 53 | self.checks[check_type] = code_check 54 | -------------------------------------------------------------------------------- /frontend/py_modules/code_projects/fmt_utils.py: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env python3 2 | 3 | import colors as C 4 | 5 | def header(strn): 6 | return C.col("{}\n{}\n".format(strn, '*' * len(strn)), C.Colors.BLUE) 7 | 8 | def error(loc, strn): 9 | print("{} {}: {}".format(C.col("ERROR", C.Colors.RED), loc, strn)) 10 | 11 | def simple_error(msg): 12 | print(C.col(msg, C.Colors.RED)) 13 | 14 | def simple_success(msg): 15 | print(C.col(msg, C.Colors.GREEN)) 16 | -------------------------------------------------------------------------------- /frontend/py_modules/code_projects/toolchain.ini: -------------------------------------------------------------------------------- 1 | [DEFAULT] 2 | 3 | [toolchain_path] 4 | root = /opt/ada 5 | selected = /opt/ada/selected 6 | default = /opt/ada/default 7 | 8 | [default_version] 9 | gnat = 14.2.0-1 10 | gnatprove = 14.1.0-1 11 | gprbuild = 24.0.0-2 12 | 13 | [toolchains] 14 | gnat = 12.2.0-1 14.2.0-1 15 | gnatprove = 12.1.0-1 14.1.0-1 16 | gprbuild = 22.0.0-1 24.0.0-2 17 | -------------------------------------------------------------------------------- /frontend/py_modules/code_projects/toolchain_info.py: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env python3 2 | 3 | import os 4 | import re 5 | import configparser 6 | 7 | TOOLCHAIN_CONFIG = os.path.dirname(os.path.realpath(__file__)) + "/" + "toolchain.ini" 8 | 9 | TOOLCHAIN_PATH = {} 10 | TOOLCHAINS = {} 11 | DEFAULT_VERSION = {} 12 | 13 | def init_toolchain_info(): 14 | config = configparser.ConfigParser() 15 | 16 | config.read(TOOLCHAIN_CONFIG) 17 | 18 | DEFAULT_VERSION['gnat'] = config['default_version']['gnat'] 19 | DEFAULT_VERSION['gnatprove'] = config['default_version']['gnatprove'] 20 | DEFAULT_VERSION['gprbuild'] = config['default_version']['gprbuild'] 21 | 22 | TOOLCHAIN_PATH['root'] = config['toolchain_path']['root'] 23 | TOOLCHAIN_PATH['selected'] = config['toolchain_path']['selected'] 24 | TOOLCHAIN_PATH['default'] = config['toolchain_path']['default'] 25 | 26 | TOOLCHAINS['gnat'] = str(config['toolchains']['gnat']) 27 | TOOLCHAINS['gnatprove'] = str(config['toolchains']['gnatprove']) 28 | TOOLCHAINS['gprbuild'] = str(config['toolchains']['gprbuild']) 29 | 30 | TOOLCHAINS['gnat'] = re.split(r'\s+',TOOLCHAINS['gnat']) 31 | TOOLCHAINS['gnatprove'] = re.split(r'\s+',TOOLCHAINS['gnatprove']) 32 | TOOLCHAINS['gprbuild'] = re.split(r'\s+',TOOLCHAINS['gprbuild']) 33 | 34 | def get_toolchain_default_version(tool): 35 | # Force initialization if info isn't available 36 | if not tool in DEFAULT_VERSION: 37 | init_toolchain_info() 38 | 39 | return DEFAULT_VERSION[tool] 40 | -------------------------------------------------------------------------------- /frontend/py_modules/code_projects/toolchain_setup.py: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env python3 2 | 3 | import os 4 | import re 5 | 6 | import blocks 7 | import toolchain_info as info 8 | 9 | def set_toolchain(block : blocks.CodeBlock): 10 | 11 | # Init toolchain info if not initialized 12 | if not 'root' in info.TOOLCHAIN_PATH: 13 | info.init_toolchain_info() 14 | 15 | # Reset toolchain to ensure that no toolchain exists in the "select" folder 16 | reset_toolchain() 17 | 18 | # Create "selected" folder if it doesn't exist 19 | selected_path = info.TOOLCHAIN_PATH['selected'] 20 | os.makedirs(selected_path, 21 | mode=0o777, 22 | exist_ok=True) 23 | 24 | if block.gnat_version[0] != "default": 25 | ver = block.gnat_version[1] 26 | 27 | os.symlink(info.TOOLCHAIN_PATH['root'] + '/gnat/' + ver, 28 | info.TOOLCHAIN_PATH['selected'] + '/gnat') 29 | 30 | if block.gnatprove_version[0] != "default": 31 | ver = block.gnatprove_version[1] 32 | 33 | os.symlink(info.TOOLCHAIN_PATH['root'] + '/gnatprove/' + ver, 34 | info.TOOLCHAIN_PATH['selected'] + '/gnatprove') 35 | 36 | if block.gprbuild_version[0] != "default": 37 | ver = block.gprbuild_version[1] 38 | 39 | os.symlink(info.TOOLCHAIN_PATH['root'] + '/gprbuild/' + ver, 40 | info.TOOLCHAIN_PATH['selected'] + '/gprbuild') 41 | 42 | def reset_toolchain(): 43 | selected_folders = [info.TOOLCHAIN_PATH['selected'] + '/gnat', 44 | info.TOOLCHAIN_PATH['selected'] + '/gnatprove', 45 | info.TOOLCHAIN_PATH['selected'] + '/gprbuild'] 46 | 47 | for f in selected_folders: 48 | if os.path.exists(f): 49 | os.unlink(f) 50 | -------------------------------------------------------------------------------- /frontend/requirements.txt: -------------------------------------------------------------------------------- 1 | coverage==7.8.0 2 | docutils==0.21.2 3 | graphviz==0.20.3 4 | ipython==9.1.0 5 | pdf2image==1.17.0 6 | pillow==11.2.1 7 | pydot-ng==2.0.0 8 | Pygments==2.19.1 9 | pyparsing==3.2.3 10 | Sphinx==8.1.3 11 | sphinx-reredirects==0.1.6 12 | sphinx-rtd-theme==3.0.2 13 | sphinxcontrib-bibtex==2.6.3 14 | sphinxcontrib-plantuml==0.30 15 | websocket-client==1.8.0 16 | -------------------------------------------------------------------------------- /frontend/requirements_frozen.txt: -------------------------------------------------------------------------------- 1 | alabaster==1.0.0 2 | asttokens==3.0.0 3 | babel==2.17.0 4 | certifi==2025.1.31 5 | charset-normalizer==3.4.1 6 | coverage==7.8.0 7 | decorator==5.2.1 8 | docutils==0.21.2 9 | executing==2.2.0 10 | graphviz==0.20.3 11 | idna==3.10 12 | imagesize==1.4.1 13 | ipython==9.1.0 14 | ipython_pygments_lexers==1.1.1 15 | jedi==0.19.2 16 | Jinja2==3.1.6 17 | latexcodec==3.0.0 18 | MarkupSafe==3.0.2 19 | matplotlib-inline==0.1.7 20 | packaging==25.0 21 | parso==0.8.4 22 | pdf2image==1.17.0 23 | pexpect==4.9.0 24 | pillow==11.2.1 25 | prompt_toolkit==3.0.51 26 | ptyprocess==0.7.0 27 | pure-eval==0.2.3 28 | pybtex==0.24.0 29 | pybtex-docutils==1.0.3 30 | pydot-ng==2.0.0 31 | Pygments==2.19.1 32 | pyparsing==3.2.3 33 | PyYAML==6.0.2 34 | requests==2.32.3 35 | roman-numerals-py==3.1.0 36 | setuptools==79.0.1 37 | six==1.17.0 38 | snowballstemmer==2.2.0 39 | Sphinx==8.1.3 40 | sphinx-reredirects==0.1.6 41 | sphinx-rtd-theme==3.0.2 42 | sphinxcontrib-applehelp==2.0.0 43 | sphinxcontrib-bibtex==2.6.3 44 | sphinxcontrib-devhelp==2.0.0 45 | sphinxcontrib-htmlhelp==2.1.0 46 | sphinxcontrib-jquery==4.1 47 | sphinxcontrib-jsmath==1.0.1 48 | sphinxcontrib-plantuml==0.30 49 | sphinxcontrib-qthelp==2.0.0 50 | sphinxcontrib-serializinghtml==2.0.0 51 | stack-data==0.6.3 52 | traitlets==5.14.3 53 | typing_extensions==4.13.2 54 | urllib3==2.4.0 55 | wcwidth==0.2.13 56 | websocket-client==1.8.0 57 | -------------------------------------------------------------------------------- /frontend/sphinx/_epub_theme/epub-cover.html: -------------------------------------------------------------------------------- 1 | {# 2 | epub/epub-cover.html 3 | ~~~~~~~~~~~~~~~~~~~~ 4 | 5 | Sample template for the html cover page. 6 | 7 | :copyright: Copyright 2007-2021 by the Sphinx team, see AUTHORS. 8 | :license: BSD, see LICENSE for details. 9 | #} 10 | {%- extends "layout.html" %} 11 | {%- block header %}{% endblock %} 12 | {%- block rootrellink %}{% endblock %} 13 | {%- block relbaritems %}{% endblock %} 14 | {%- block sidebarlogo %}{% endblock %} 15 | {%- block linktags %}{% endblock %} 16 | {%- block relbar1 %}{% endblock %} 17 | {%- block sidebar1 %}{% endblock %} 18 | {%- block sidebar2 %}{% endblock %} 19 | {%- block footer %}{% endblock %} 20 | 21 | {% block content %} 22 |
23 | Cover image 24 |
25 | {% endblock %} 26 | -------------------------------------------------------------------------------- /frontend/sphinx/_epub_theme/layout.html: -------------------------------------------------------------------------------- 1 | {# 2 | epub/layout.html 3 | ~~~~~~~~~~~~~~~~ 4 | 5 | Sphinx layout template for the epub theme. 6 | 7 | :copyright: Copyright 2007-2021 by the Sphinx team, see AUTHORS. 8 | :license: BSD, see LICENSE for details. 9 | #} 10 | {%- extends "basic/layout.html" %} 11 | 12 | {%- block doctype -%} 13 | {{ doctype }} 14 | {%- endblock -%} 15 | {# add only basic navigation links #} 16 | {% block sidebar1 %}{% endblock %} 17 | {% block sidebar2 %}{% endblock %} 18 | {% block relbar1 %}{% endblock %} 19 | {% block relbar2 %}{% endblock %} 20 | {% block linktags %}{% endblock %} 21 | {% block footer %}{% endblock %} 22 | -------------------------------------------------------------------------------- /frontend/sphinx/_epub_theme/static/graphviz.css_t: -------------------------------------------------------------------------------- 1 | /* 2 | * graphviz.css 3 | * ~~~~~~~~~~~~ 4 | * 5 | * Sphinx stylesheet -- graphviz extension. 6 | * 7 | * :copyright: Copyright 2007-2021 by the Sphinx team, see AUTHORS. 8 | * :license: BSD, see LICENSE for details. 9 | * 10 | */ 11 | 12 | img.graphviz { 13 | border: 0; 14 | max-width: 100%; 15 | } 16 | 17 | object.graphviz { 18 | max-width: 100%; 19 | } 20 | -------------------------------------------------------------------------------- /frontend/sphinx/_epub_theme/theme.conf: -------------------------------------------------------------------------------- 1 | [theme] 2 | inherit = basic 3 | stylesheet = epub.css 4 | pygments_style = none 5 | 6 | [options] 7 | relbar1 = true 8 | footer = true 9 | -------------------------------------------------------------------------------- /frontend/sphinx/_templates/layout.html: -------------------------------------------------------------------------------- 1 | {% extends "!layout.html" %} 2 | 3 | {%- block extrahead %} 4 | {% include "analytics.html" %} 5 | {% include "metatags.html" %} 6 | {% endblock %} 7 | 8 | {% block extrabody %} 9 | 10 | 12 | 13 | 14 | 15 | 16 | {% endblock %} 17 | 18 | {%- block mobile_nav %} 19 | 20 | {%- if logo and theme_logo_only %} 21 | 22 | {%- else %} 23 | {{ project }} 24 | {%- endif %} 25 | 26 | {%- if logo %} 27 | {#- Not strictly valid HTML, but it's the only way to display/scale 28 | it properly, without weird scripting or heaps of work 29 | #} 30 | 31 | {%- endif %} 32 | 33 | {%- endblock %} 34 | 35 | {% block footer %} 36 | 37 | 38 | 43 | {% endblock %} 44 | -------------------------------------------------------------------------------- /frontend/sphinx/_templates/metatags.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /frontend/sphinx/img/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AdaCore/learn/e381c7badaed0c96ef1b8f95b1f8e5a6fdd755be/frontend/sphinx/img/favicon.ico -------------------------------------------------------------------------------- /frontend/sphinx/img/learn_meta_img.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AdaCore/learn/e381c7badaed0c96ef1b8f95b1f8e5a6fdd755be/frontend/sphinx/img/learn_meta_img.jpeg -------------------------------------------------------------------------------- /frontend/sphinx/img/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AdaCore/learn/e381c7badaed0c96ef1b8f95b1f8e5a6fdd755be/frontend/sphinx/img/logo.png -------------------------------------------------------------------------------- /frontend/sphinx/tests/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AdaCore/learn/e381c7badaed0c96ef1b8f95b1f8e5a6fdd755be/frontend/sphinx/tests/__init__.py -------------------------------------------------------------------------------- /frontend/sphinx/tests/test_button.py: -------------------------------------------------------------------------------- 1 | import unittest 2 | 3 | from widget.button import Button, button_dictionary 4 | 5 | 6 | class TestButton(unittest.TestCase): 7 | def test_constructor(self): 8 | button = Button("run_button") 9 | self.assertEqual(button.name, button_dictionary["run_button"]["name"], msg="button name != dictionary lookup") 10 | self.assertEqual(button.title, button_dictionary["run_button"]["title"], msg="button title != dictionary lookup") 11 | self.assertEqual(button.mode, button_dictionary["run_button"]["mode"], msg="button mode != dictionary lookup") 12 | 13 | 14 | if __name__ == '__main__': 15 | unittest.main() -------------------------------------------------------------------------------- /frontend/sphinx/tests/test_resource.py: -------------------------------------------------------------------------------- 1 | import unittest 2 | 3 | from widget.resource import Resource 4 | 5 | 6 | class TestResource(unittest.TestCase): 7 | def test_constructor(self): 8 | resourceA = Resource("ResourceA", ["A", "B"]) 9 | resourceB = Resource("ResourceB") 10 | self.assertEqual(resourceA.basename, "ResourceA", msg="basename not stored properly") 11 | self.assertEqual(resourceB.basename, "ResourceB", msg="basename not stored properly") 12 | self.assertEqual(resourceA.content, "A\nB", msg="content not parsed correctly") 13 | self.assertEqual(resourceB.content, "", msg="content not parsed correctly") 14 | 15 | def test_append(self): 16 | resourceC = Resource("ResourceC", ["A", "B"]) 17 | resourceC.append("C") 18 | self.assertEqual(resourceC.content, "A\nB\nC", msg="string not appended properly") 19 | 20 | 21 | if __name__ == '__main__': 22 | unittest.main() -------------------------------------------------------------------------------- /frontend/sphinx/widget/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AdaCore/learn/e381c7badaed0c96ef1b8f95b1f8e5a6fdd755be/frontend/sphinx/widget/__init__.py -------------------------------------------------------------------------------- /frontend/sphinx/widget/button.py: -------------------------------------------------------------------------------- 1 | button_dictionary = { 2 | "prove_button": { 3 | "name": 'Prove', 4 | "title": 'Prove SPARK code', 5 | "mode": "prove" 6 | }, 7 | "prove_flow_button": { 8 | "name": 'Examine', 9 | "title": 'Examine SPARK data and control flow', 10 | "mode": "prove_flow" 11 | }, 12 | "prove_flow_report_all_button": { 13 | "name": 'Examine (report=all)', 14 | "title": 'Examine SPARK data and control flow and report all findings', 15 | "mode": "prove_flow_report_all" 16 | }, 17 | "prove_report_all_button": { 18 | "name": 'Prove (report=all)', 19 | "title": 'Prove SPARK code and report all findings', 20 | "mode": "prove_report_all" 21 | }, 22 | "run_button": { 23 | "name": 'Run', 24 | "title": 'Run code in editor', 25 | "mode": "run" 26 | }, 27 | "submit_button": { 28 | "name": 'Submit', 29 | "title": 'Submit code for lab', 30 | "mode": "submit" 31 | }, 32 | "compile_button": { 33 | "name": 'Compile', 34 | "title": 'Compile code to check syntax', 35 | "mode": "compile" 36 | }, 37 | } 38 | 39 | class Button: 40 | def __init__(self, button: str): 41 | """Constructs a button 42 | 43 | The name supplied in the constructor will be used to lookup the 44 | button's information in the button_dictionary lookup table. 45 | 46 | Args: 47 | button (str): The name of a button to create 48 | """ 49 | self.name = button_dictionary[button]["name"] 50 | self.title = button_dictionary[button]["title"] 51 | self.mode = button_dictionary[button]["mode"] 52 | -------------------------------------------------------------------------------- /frontend/sphinx/widget/resource.py: -------------------------------------------------------------------------------- 1 | from typing import List 2 | 3 | class Resource: 4 | """A Resource, or file 5 | 6 | Resource represents a file object and has a filename (basename) and 7 | contents. 8 | """ 9 | def __init__(self, basename: str, content: List[str] = None): 10 | """Constructs a Resource 11 | 12 | Args: 13 | basename (str): The filename to give the Resource 14 | content (List[str], optional): Initial contents. Defaults to []. 15 | """ 16 | self.basename = basename 17 | if content: 18 | self.__content = content 19 | else: 20 | self.__content = [] 21 | 22 | def append(self, content: str): 23 | """Appends a string to the Resource's contents 24 | 25 | Args: 26 | content (str): The content to append 27 | """ 28 | self.__content.append(content) 29 | 30 | @property 31 | def content(self) -> str: 32 | """Property to get Resource contents 33 | 34 | Returns: 35 | str: The contents of the Resource as a string 36 | """ 37 | return "\n".join(self.__content) 38 | -------------------------------------------------------------------------------- /frontend/src/index.ts: -------------------------------------------------------------------------------- 1 | import './styles/learn.scss'; 2 | import './styles/learn-dark.scss'; 3 | import {getElemsByClass, getElemById} from './ts/dom-utils'; 4 | import {widgetFactory} from './ts/widget'; 5 | import {scrollTop} from './ts/scrolltop'; 6 | 7 | // #if SANDBOX 8 | import {sandboxRedirect} from './ts/sandbox-redirect'; 9 | // #endif 10 | 11 | /** 12 | * Entrypoint 13 | * The main entrypoint for the application 14 | */ 15 | function entrypoint(): void { 16 | // get list of all widgets on the page 17 | const we = getElemsByClass(document, 'widget'); 18 | 19 | widgetFactory(we as Array); 20 | 21 | // register scroll to top btn functionality 22 | const btn = getElemById('scrollToTopBtn'); 23 | scrollTop(btn as HTMLButtonElement); 24 | 25 | // #if SANDBOX 26 | // This is used to redirect non AdaCore staff to the main site if 27 | // the staging site is accidentally reached 28 | sandboxRedirect(); 29 | // #endif 30 | } 31 | 32 | (function(): void { 33 | if (document.readyState != 'loading') { 34 | entrypoint(); 35 | } else { 36 | document.addEventListener('DOMContentLoaded', entrypoint); 37 | } 38 | }()); 39 | -------------------------------------------------------------------------------- /frontend/src/styles/_variables-dark.scss: -------------------------------------------------------------------------------- 1 | // colors 2 | @use 'sass:color'; 3 | 4 | $color-theme-bg-dark: #C34C01; // dark orange 5 | 6 | $color-theme-bg-light: rgb(252, 252, 252); 7 | 8 | $color-theme-alt-bg: #222222; 9 | 10 | $color-bg-dark: #111111; 11 | 12 | $color-content-bg: black; 13 | $color-content-font: #edc; 14 | 15 | $color-border: #444; 16 | 17 | $color-code-font: #DE935F; 18 | $color-code-bg: $color-bg-dark; 19 | $color-code-border: color.scale($color-border, $lightness: -50%); 20 | 21 | $color-menu-bg-l1: #222222; 22 | $color-menu-bg-l2: color.scale($color-menu-bg-l1, $lightness: 5%); 23 | $color-menu-bg-l3: color.scale($color-menu-bg-l1, $lightness: 10%); 24 | $color-menu-bg-hover: color.scale($color-menu-bg-l1, $lightness: -20%); 25 | 26 | $color-menu-font: #f0f0f0; 27 | $color-menu-alt-font: #e8e8e8; 28 | $color-menu-alt-font-hover: color.scale($color-menu-alt-font, $lightness: 20%); 29 | 30 | $color-tab-active-font: rgb(200, 200, 200); 31 | $color-tab-hover-font: color.scale($color-tab-active-font, $lightness: 20%); 32 | $color-tab-font: color.scale($color-tab-active-font, $lightness: -30%); 33 | 34 | $color-widget-border: $color-border; 35 | 36 | $color-widget-output-area: rgb(23, 23, 23); 37 | 38 | $color-widget-info: rgb(234, 234, 234); 39 | 40 | $color-settingsbar-bg: rgb(50, 50, 50); 41 | -------------------------------------------------------------------------------- /frontend/src/ts/dom-utils.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Safely gets an element by its id from the document. 3 | * If an element with the ID is not found, an exception is thrown. 4 | * @param {string} id - The id to find 5 | * @returns {HTMLElement} - The found element 6 | */ 7 | export function getElemById(id: string): HTMLElement { 8 | const res = document.getElementById(id); 9 | if (res == null) { 10 | throw Error('Malformed DOM. Cannot find elem ' + id); 11 | } 12 | return res; 13 | } 14 | 15 | /** 16 | * Gets all child elements of root with a specific class. 17 | * This wraps the HTMLCollectionOf, which is the return of 18 | * getElementsByClassName, in an array so that it is iterable. 19 | * @param {(HTMLElement | Document)} root - The root element to search 20 | * @param {string} name - The class name to find 21 | * @returns {Array} - The list of found elements with the class 22 | */ 23 | export function getElemsByClass(root: HTMLElement | Document, name: string): 24 | Array { 25 | const coll = root.getElementsByClassName(name) as 26 | HTMLCollectionOf; 27 | return Array.from(coll); 28 | } 29 | /** 30 | * Gets all elements of root with a specific tag. 31 | * This wraps the HTMLCollectionOf, which is the return of 32 | * getElementByTagName, in an array so that it is iterable. 33 | * @param {(HTMLElement | Document)} root - The root element to search 34 | * @param {string} tag - The tag name to find 35 | * @returns {Array} - The list of found elements with the tag 36 | */ 37 | export function getElemsByTag(root: HTMLElement | Document, tag: string): 38 | Array { 39 | const coll = root.getElementsByTagName(tag) as HTMLCollectionOf; 40 | return Array.from(coll); 41 | } 42 | -------------------------------------------------------------------------------- /frontend/src/ts/resource.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Corresponds to a text file 3 | * 4 | * @export 5 | */ 6 | export type Resource = { 7 | basename: string; 8 | contents: string; 9 | } 10 | 11 | /** 12 | * Corresponds to a list of Resources 13 | * 14 | * @export 15 | */ 16 | export type ResourceList = Array; 17 | -------------------------------------------------------------------------------- /frontend/src/ts/sandbox-redirect.ts: -------------------------------------------------------------------------------- 1 | import {Cookies} from 'typescript-cookies' 2 | 3 | const cookies = new Cookies({ 4 | path: '/', 5 | secure: true, 6 | samesite: 'none', 7 | }) 8 | 9 | /** 10 | * Redirects the user to main learn site if not authenticated 11 | */ 12 | export function sandboxRedirect(): void { 13 | /* istanbul ignore next */ 14 | const cookieName = "Learn_Sandbox_Authenticated"; 15 | const cookieValue = cookies.get(cookieName) as string; 16 | const cookieReferenceValue = "true"; 17 | 18 | if (cookieValue != cookieReferenceValue) { 19 | const passw = prompt("Enter site password:") 20 | 21 | if (passw != "Ada") { 22 | const msg = 'You have reached learn-sandbox, the learn testing site. ' + 23 | 'This is reserved for testers only. You will be directed to the main ' + 24 | 'learn.adacore.com site after pressing OK.'; 25 | alert(msg); 26 | window.location.href = 'http://learn.adacore.com'; 27 | } 28 | else 29 | { 30 | cookies.set(cookieName, cookieReferenceValue, {expires: 3650}); 31 | } 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /frontend/src/ts/scrolltop.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Enables the scroll-to-top functionality 3 | * @param {HTMLButtonElement} btn Button element 4 | */ 5 | export function scrollTop(btn: HTMLButtonElement): void { 6 | btn.classList.add('hide'); 7 | 8 | window.addEventListener('scroll', () => { 9 | /* istanbul ignore next */ 10 | if (document.body.scrollTop > 300) { 11 | btn.classList.remove('hide'); 12 | btn.classList.add('show'); 13 | } else { 14 | btn.classList.remove('show'); 15 | btn.classList.add('hide'); 16 | } 17 | }); 18 | 19 | btn.addEventListener('click', () => { 20 | window.scrollTo(0, 0); 21 | }); 22 | } 23 | -------------------------------------------------------------------------------- /frontend/src/ts/server-types.ts: -------------------------------------------------------------------------------- 1 | /* eslint-disable */ 2 | 3 | import {ResourceList} from './resource'; 4 | 5 | // FS - From Server 6 | // TS - To Server 7 | 8 | export namespace RunProgram { 9 | 10 | export interface SwitchType { 11 | [key : string]: Array; 12 | } 13 | 14 | export interface TSData { 15 | files: ResourceList; 16 | main: string; 17 | mode: string; 18 | switches: SwitchType; 19 | name: string; 20 | lab: boolean; 21 | } 22 | 23 | export interface TS { 24 | action: string, 25 | data: TSData 26 | } 27 | } 28 | 29 | export namespace CheckOutput { 30 | export interface TestResult { 31 | status: string; 32 | out: string; 33 | actual: string; 34 | in: string; 35 | } 36 | 37 | export interface TestCase { 38 | [key: string]: TestResult; 39 | } 40 | 41 | export interface LabOutput { 42 | success: boolean; 43 | cases: Array; 44 | } 45 | 46 | export type MessageData = string | LabOutput; 47 | 48 | export interface RunMsg { 49 | type: string; 50 | data: MessageData; 51 | } 52 | 53 | export interface FS { 54 | output: Array; 55 | status: number; 56 | completed: boolean; 57 | message: string; 58 | ref?: number; 59 | } 60 | 61 | export interface FS_Error { 62 | message : string; 63 | connectionId: string; 64 | requestId: string; 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /frontend/tests/.gitignore: -------------------------------------------------------------------------------- 1 | html -------------------------------------------------------------------------------- /frontend/tests/rst/index.rst: -------------------------------------------------------------------------------- 1 | Index 2 | ======== 3 | 4 | This is the main html page for HTML test template generation 5 | 6 | .. toctree:: 7 | :maxdepth: 4 8 | 9 | Single 10 | Lab 11 | -------------------------------------------------------------------------------- /frontend/tests/rst/lab.rst: -------------------------------------------------------------------------------- 1 | Single Lab 2 | =========== 3 | 4 | This page has a single LabWidget for test purposes. 5 | 6 | .. code:: ada lab=Test.Lab 7 | 8 | -- START LAB IO BLOCK 9 | Lab IO Block 10 | -- END LAB IO BLOCK 11 | 12 | procedure Test is 13 | 14 | begin 15 | 16 | null; 17 | 18 | end Test; 19 | -------------------------------------------------------------------------------- /frontend/tests/rst/single.rst: -------------------------------------------------------------------------------- 1 | Single 2 | ======= 3 | 4 | This page has a single Widget for test purposes. 5 | 6 | .. code:: ada run_button project=Test.Single switches=Compiler(-gnatX);Builder(-g) 7 | 8 | procedure Test is 9 | 10 | begin 11 | 12 | null; 13 | 14 | end Test; 15 | -------------------------------------------------------------------------------- /frontend/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "allowSyntheticDefaultImports": true, 4 | "sourceMap": true, 5 | "allowJs": true, 6 | "esModuleInterop": true, 7 | "downlevelIteration": true, 8 | "strict": true, 9 | "lib": ["es2023"], 10 | "module": "es2020", 11 | "target": "es2022", 12 | "moduleResolution": "bundler" 13 | }, 14 | "include": [ 15 | "./src/**/*" 16 | ] 17 | } 18 | -------------------------------------------------------------------------------- /frontend/webpack.dev.cjs: -------------------------------------------------------------------------------- 1 | const path = require('path'); 2 | const { merge } = require('webpack-merge'); 3 | const exec = require('child_process').exec; 4 | const WatchPlugin = require('webpack-watch-files-plugin').default; 5 | const ShellPlugin = require('webpack-shell-plugin-next'); 6 | const common = require('./webpack.common.cjs'); 7 | 8 | module.exports = function(env) { 9 | const common_config = common(env); 10 | 11 | const dev_config = { 12 | mode: 'development', 13 | devServer: { 14 | static: [path.join(__dirname, 'dist', 'html'), path.join(__dirname, 'dist')], 15 | compress: false, 16 | host: '0.0.0.0', 17 | port: 8080, 18 | hot: true, 19 | liveReload: false, 20 | // devMiddleware: { 21 | // index: 'index.html', 22 | // }, 23 | }, 24 | output: { 25 | publicPath: '/_static/' 26 | }, 27 | devtool: 'source-map', 28 | plugins: [ 29 | new ShellPlugin({ 30 | onBuildStart:{ 31 | scripts: ['make cleanall'], 32 | blocking: true, 33 | parallel: false 34 | }, 35 | onBuildExit:{ 36 | scripts: ['make local'], 37 | blocking: false, 38 | parallel: false 39 | }, 40 | // dev=false here to force every build to trigger make, the default is 41 | // first build only. 42 | dev: false, 43 | }), 44 | ] 45 | }; 46 | 47 | return merge(common_config, dev_config); 48 | } 49 | -------------------------------------------------------------------------------- /frontend/webpack.prod.cjs: -------------------------------------------------------------------------------- 1 | const { merge } = require('webpack-merge'); 2 | const CssMinimizerPlugin = require("css-minimizer-webpack-plugin"); 3 | const TerserPlugin = require('terser-webpack-plugin'); 4 | const common = require('./webpack.common.cjs'); 5 | 6 | const terser_config = function(env) { 7 | const staging = (env && env.staging); 8 | return { 9 | // cache: true, 10 | parallel: true, 11 | // sourceMap: staging, 12 | terserOptions: { 13 | output: { 14 | comments: staging, 15 | } 16 | } 17 | }; 18 | }; 19 | 20 | module.exports = function(env) { 21 | const common_config = common(env); 22 | const prod_config = { 23 | mode: 'production', 24 | optimization: { 25 | minimizer: [ 26 | (compiler) => { 27 | new TerserPlugin(terser_config(env)).apply(compiler); 28 | }, 29 | new CssMinimizerPlugin({}), 30 | ], 31 | } 32 | }; 33 | 34 | return merge(common_config, prod_config); 35 | }; 36 | --------------------------------------------------------------------------------