├── .bazelrc ├── .github ├── scripts │ └── set_release_version.py └── workflows │ ├── release.yml │ └── verify-pull-request.yml ├── .gitignore ├── BUILD ├── CONTRIBUTING.md ├── LICENSE ├── MODULE.bazel ├── README.md ├── build_defs.bzl ├── compiler ├── __init__.py ├── back_end │ ├── __init__.py │ ├── cpp │ │ ├── BUILD │ │ ├── __init__.py │ │ ├── attributes.py │ │ ├── build_defs.bzl │ │ ├── emboss_codegen_cpp.py │ │ ├── generated_code_templates │ │ ├── header_generator.py │ │ ├── header_generator_test.py │ │ └── testcode │ │ │ ├── alignments_test.cc │ │ │ ├── anonymous_bits_test.cc │ │ │ ├── auto_array_size_test.cc │ │ │ ├── bcd_test.cc │ │ │ ├── bits_test.cc │ │ │ ├── complex_offset_test.cc │ │ │ ├── complex_structure_test.cc │ │ │ ├── condition_test.cc │ │ │ ├── dynamic_size_test.cc │ │ │ ├── enum_case_test.cc │ │ │ ├── enum_test.cc │ │ │ ├── explicit_sizes_test.cc │ │ │ ├── float_test.cc │ │ │ ├── importer2_test.cc │ │ │ ├── importer_test.cc │ │ │ ├── inline_type_test.cc │ │ │ ├── int_sizes_test.cc │ │ │ ├── namespace_test.cc │ │ │ ├── nested_structure_test.cc │ │ │ ├── next_keyword_test.cc │ │ │ ├── no_enum_traits_test.cc │ │ │ ├── parameters_test.cc │ │ │ ├── read_log_file_status_test.cc │ │ │ ├── requires_test.cc │ │ │ ├── start_size_range_test.cc │ │ │ ├── subtypes_test.cc │ │ │ ├── text_format_test.cc │ │ │ ├── uint_sizes_test.cc │ │ │ └── virtual_field_test.cc │ └── util │ │ ├── BUILD │ │ ├── __init__.py │ │ ├── code_template.py │ │ └── code_template_test.py ├── front_end │ ├── BUILD │ ├── __init__.py │ ├── attribute_checker.py │ ├── attribute_checker_test.py │ ├── attributes.py │ ├── cached_parser_is_up_to_date_test.py │ ├── constraints.py │ ├── constraints_test.py │ ├── dependency_checker.py │ ├── dependency_checker_test.py │ ├── docs_are_up_to_date_test.py │ ├── emboss_front_end.py │ ├── error_examples │ ├── expression_bounds.py │ ├── expression_bounds_test.py │ ├── format.py │ ├── format_emb.py │ ├── format_emb_test.py │ ├── generate_cached_parser.py │ ├── generate_grammar_md.py │ ├── generated │ │ └── cached_parser.py │ ├── glue.py │ ├── glue_test.py │ ├── lr1.py │ ├── lr1_test.py │ ├── make_parser.py │ ├── make_parser_test.py │ ├── module_ir.py │ ├── module_ir_test.py │ ├── parser.py │ ├── parser_test.py │ ├── prelude.emb │ ├── reserved_words │ ├── symbol_resolver.py │ ├── symbol_resolver_test.py │ ├── synthetics.py │ ├── synthetics_test.py │ ├── tokenizer.py │ ├── tokenizer_test.py │ ├── type_check.py │ ├── type_check_test.py │ ├── write_inference.py │ └── write_inference_test.py └── util │ ├── BUILD │ ├── __init__.py │ ├── attribute_util.py │ ├── error.py │ ├── error_test.py │ ├── expression_parser.py │ ├── ir_data.py │ ├── ir_data_fields.py │ ├── ir_data_fields_test.py │ ├── ir_data_utils.py │ ├── ir_data_utils_test.py │ ├── ir_util.py │ ├── ir_util_test.py │ ├── name_conversion.py │ ├── name_conversion_test.py │ ├── parser_types.py │ ├── parser_types_test.py │ ├── parser_util.py │ ├── resources.py │ ├── simple_memoizer.py │ ├── simple_memoizer_test.py │ ├── test_util.py │ ├── test_util_test.py │ ├── traverse_ir.py │ └── traverse_ir_test.py ├── doc ├── BUILD ├── BogoNEL_BN-P-6000404_User_Guide.pdf ├── __init__.py ├── contributing.md ├── cpp-dark-corners.md ├── cpp-guide.md ├── cpp-reference.md ├── design.md ├── design_docs │ ├── archive │ │ ├── alternate_enum_cases.md │ │ ├── explicitly_size_enums.md │ │ └── next_keyword.md │ ├── bit_shift.md │ ├── bit_shift │ │ ├── precedence.dot │ │ └── precedence.svg │ ├── default_values.md │ ├── division_and_modulus.md │ ├── proto.md │ ├── strings.md │ └── value_of_enum_function.md ├── developer_resources.md ├── grammar.md ├── guide.md ├── how-to-design.md ├── how-to-implement.md ├── index.md ├── language-reference.md ├── modular_congruence_multiplication_proof.pdf ├── modular_congruence_multiplication_proof.tex ├── roadmap.md ├── sitemap.md ├── text-format.md └── todo.md ├── embossc ├── integration ├── googletest │ ├── BUILD │ ├── emboss_test_util.h │ └── emboss_test_util_test.cc └── vim │ └── ft-emboss │ ├── ftdetect │ └── emboss.vim │ ├── ftplugin │ └── emboss.vim │ └── syntax │ └── emboss.vim ├── license_header ├── pyproject.toml ├── runtime └── cpp │ ├── BUILD │ ├── emboss_arithmetic.h │ ├── emboss_arithmetic_all_known_generated.h │ ├── emboss_arithmetic_maximum_operation_generated.h │ ├── emboss_array_view.h │ ├── emboss_bit_util.h │ ├── emboss_constant_view.h │ ├── emboss_cpp_types.h │ ├── emboss_cpp_util.h │ ├── emboss_defines.h │ ├── emboss_enum_view.h │ ├── emboss_maybe.h │ ├── emboss_memory_util.h │ ├── emboss_prelude.h │ ├── emboss_text_util.h │ ├── emboss_view_parameters.h │ ├── generators │ ├── all_known.py │ └── maximum_operation_do.py │ └── test │ ├── BUILD │ ├── build_defs.bzl │ ├── emboss_arithmetic_test.cc │ ├── emboss_array_view_test.cc │ ├── emboss_bit_util_test.cc │ ├── emboss_constant_view_test.cc │ ├── emboss_cpp_types_test.cc │ ├── emboss_cpp_util_google_integration_test.cc │ ├── emboss_defines_test.cc │ ├── emboss_enum_view_test.cc │ ├── emboss_maybe_test.cc │ ├── emboss_memory_util_test.cc │ ├── emboss_prelude_test.cc │ └── emboss_text_util_test.cc └── testdata ├── BUILD ├── __init__.py ├── absolute_cpp_namespace.emb ├── alignments.emb ├── anonymous_bits.emb ├── auto_array_size.emb ├── bcd.emb ├── bits.emb ├── complex_offset.emb ├── complex_structure.emb ├── condition.emb ├── cpp_namespace.emb ├── dynamic_size.emb ├── enum.emb ├── enum_case.emb ├── explicit_sizes.emb ├── float.emb ├── format ├── __init__.py ├── abbreviations.emb ├── abbreviations.emb.formatted ├── abbreviations.emb.formatted_indent_4 ├── anonymous_bits_formatting.emb ├── anonymous_bits_formatting.emb.formatted ├── anonymous_bits_formatting.emb.formatted_indent_4 ├── arithmetic_expressions.emb ├── arithmetic_expressions.emb.formatted ├── arithmetic_expressions.emb.formatted_indent_4 ├── array_length.emb ├── array_length.emb.formatted ├── array_length.emb.formatted_indent_4 ├── attributes.emb ├── attributes.emb.formatted ├── attributes.emb.formatted_indent_4 ├── choice_expression.emb ├── choice_expression.emb.formatted ├── choice_expression.emb.formatted_indent_4 ├── comparison_expressions.emb ├── comparison_expressions.emb.formatted ├── comparison_expressions.emb.formatted_indent_4 ├── conditional_field_formatting.emb ├── conditional_field_formatting.emb.formatted ├── conditional_field_formatting.emb.formatted_indent_4 ├── conditional_inline_bits_formatting.emb ├── conditional_inline_bits_formatting.emb.formatted ├── conditional_inline_bits_formatting.emb.formatted_indent_4 ├── dotted_names.emb ├── dotted_names.emb.formatted ├── dotted_names.emb.formatted_indent_4 ├── empty.emb ├── empty.emb.formatted ├── empty.emb.formatted_indent_4 ├── enum_value_attributes.emb ├── enum_value_attributes.emb.formatted ├── enum_value_attributes.emb.formatted_indent_4 ├── enum_value_bodies.emb ├── enum_value_bodies.emb.formatted ├── enum_value_bodies.emb.formatted_indent_4 ├── enum_values_aligned.emb ├── enum_values_aligned.emb.formatted ├── enum_values_aligned.emb.formatted_indent_4 ├── equality_expressions.emb ├── equality_expressions.emb.formatted ├── equality_expressions.emb.formatted_indent_4 ├── external.emb ├── external.emb.formatted ├── external.emb.formatted_indent_4 ├── extra_newlines.emb ├── extra_newlines.emb.formatted ├── extra_newlines.emb.formatted_indent_4 ├── fields_aligned.emb ├── fields_aligned.emb.formatted ├── fields_aligned.emb.formatted_indent_4 ├── functions.emb ├── functions.emb.formatted ├── functions.emb.formatted_indent_4 ├── header_and_type.emb ├── header_and_type.emb.formatted ├── header_and_type.emb.formatted_indent_4 ├── indent.emb ├── indent.emb.formatted ├── indent.emb.formatted_indent_4 ├── inline_attributes_get_a_column.emb ├── inline_attributes_get_a_column.emb.formatted ├── inline_attributes_get_a_column.emb.formatted_indent_4 ├── inline_bits.emb ├── inline_bits.emb.formatted ├── inline_bits.emb.formatted_indent_4 ├── inline_documentation_gets_a_column.emb ├── inline_documentation_gets_a_column.emb.formatted ├── inline_documentation_gets_a_column.emb.formatted_indent_4 ├── inline_enum.emb ├── inline_enum.emb.formatted ├── inline_enum.emb.formatted_indent_4 ├── inline_struct.emb ├── inline_struct.emb.formatted ├── inline_struct.emb.formatted_indent_4 ├── lines_not_spaced_out_with_excess_trailing_noise_lines.emb ├── lines_not_spaced_out_with_excess_trailing_noise_lines.emb.formatted ├── lines_not_spaced_out_with_excess_trailing_noise_lines.emb.formatted_indent_4 ├── lines_not_spaced_out_with_not_enough_noise_lines.emb ├── lines_not_spaced_out_with_not_enough_noise_lines.emb.formatted ├── lines_not_spaced_out_with_not_enough_noise_lines.emb.formatted_indent_4 ├── lines_spaced_out_with_noise_lines.emb ├── lines_spaced_out_with_noise_lines.emb.formatted ├── lines_spaced_out_with_noise_lines.emb.formatted_indent_4 ├── logical_expressions.emb ├── logical_expressions.emb.formatted ├── logical_expressions.emb.formatted_indent_4 ├── multiline_ifs.emb ├── multiline_ifs.emb.formatted ├── multiline_ifs.emb.formatted_indent_4 ├── multiple_header_sections.emb ├── multiple_header_sections.emb.formatted ├── multiple_header_sections.emb.formatted_indent_4 ├── nested_types_are_columnized_independently.emb ├── nested_types_are_columnized_independently.emb.formatted ├── nested_types_are_columnized_independently.emb.formatted_indent_4 ├── one_type.emb ├── one_type.emb.formatted ├── one_type.emb.formatted_indent_4 ├── parameterized_struct.emb ├── parameterized_struct.emb.formatted ├── parameterized_struct.emb.formatted_indent_4 ├── sanity_check.emb ├── sanity_check.emb.formatted ├── sanity_check.emb.formatted_indent_4 ├── spacing_between_types.emb ├── spacing_between_types.emb.formatted ├── spacing_between_types.emb.formatted_indent_4 ├── trailing_spaces.emb ├── trailing_spaces.emb.formatted ├── trailing_spaces.emb.formatted_indent_4 ├── virtual_fields.emb ├── virtual_fields.emb.formatted └── virtual_fields.emb.formatted_indent_4 ├── golden ├── README.md ├── __init__.py ├── span_se_log_file_status.emb ├── span_se_log_file_status.ir.txt ├── span_se_log_file_status.parse_tree.txt └── span_se_log_file_status.tokens.txt ├── import_dir └── project │ ├── imported.emb │ └── importer.emb ├── imported.emb ├── importer.emb ├── importer2.emb ├── inline_type.emb ├── int_sizes.emb ├── large_array.emb ├── nested_structure.emb ├── next_keyword.emb ├── no_cpp_namespace.emb ├── no_enum_traits.emb ├── parameters.emb ├── requires.emb ├── start_size_range.emb ├── subtypes.emb ├── text_format.emb ├── uint_sizes.emb └── virtual_field.emb /.bazelrc: -------------------------------------------------------------------------------- 1 | # Emboss (at least notionally) supports C++11 until (at least) 2027. However, 2 | # Googletest requires C++14, which means that all of the Emboss unit tests 3 | # require C++14 to run. 4 | # 5 | # TODO(bolms): Find and port to a C++11-compatible unit test framework. 6 | build --copt=-std=c++14 7 | -------------------------------------------------------------------------------- /.github/scripts/set_release_version.py: -------------------------------------------------------------------------------- 1 | # Obtains a date-based version for the release workflow. 2 | 3 | import datetime 4 | 5 | now_utc = datetime.datetime.now(datetime.timezone.utc) 6 | version = now_utc.strftime("%Y.%m%d.%H%M%S") 7 | print("::set-output name=version::v{}".format(version)) 8 | -------------------------------------------------------------------------------- /.github/workflows/release.yml: -------------------------------------------------------------------------------- 1 | --- 2 | name: Release 3 | on: 4 | push: 5 | branches: 6 | - 'master' 7 | 8 | jobs: 9 | release: 10 | runs-on: ubuntu-latest 11 | steps: 12 | - uses: actions/checkout@master 13 | - uses: actions/setup-python@master 14 | with: 15 | python-version: '3.x' 16 | - name: Set Release Version 17 | id: set_release_version 18 | run: python ./.github/scripts/set_release_version.py 19 | - name: Create Archive Release 20 | uses: thedoctor0/zip-release@master 21 | with: 22 | filename: 'emboss.zip' 23 | exclusions: '*.git*' 24 | - name: Automatic Release Upload 25 | id: automatic_release 26 | uses: 'marvinpinto/action-automatic-releases@latest' 27 | with: 28 | repo_token: '${{ secrets.GITHUB_TOKEN }}' 29 | automatic_release_tag: ${{ steps.set_release_version.outputs.version }} 30 | prerelease: false 31 | title: ${{ steps.set_release_version.outputs.version }} 32 | files: | 33 | emboss.zip 34 | -------------------------------------------------------------------------------- /.github/workflows/verify-pull-request.yml: -------------------------------------------------------------------------------- 1 | name: Verify PR 2 | on: [pull_request] 3 | 4 | jobs: 5 | run-bazel-tests: 6 | name: "Run Bazel tests" 7 | runs-on: ubuntu-latest 8 | strategy: 9 | matrix: 10 | cpp-compiler: ["clang", "gcc"] 11 | options: ["-c opt", ""] 12 | steps: 13 | - uses: actions/checkout@v4 14 | - uses: bazel-contrib/setup-bazel@0.8.5 15 | with: 16 | bazelisk-cache: true 17 | disk-cache: "verify-pr:run-bazel-tests:${{ matrix.cpp-compiler }}" 18 | repository-cache: true 19 | - run: echo "CC=${{ matrix.cpp-compiler }}" >> $GITHUB_ENV 20 | - run: bazel test --test_output=errors ${{ matrix.options }} ... 21 | check-formatting: 22 | name: "Check Python formatting" 23 | runs-on: ubuntu-latest 24 | steps: 25 | - uses: actions/checkout@v4 26 | - uses: psf/black@stable 27 | with: 28 | options: "--check --verbose" 29 | version: "24.8.0" 30 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Bazel 2 | bazel-* 3 | MODULE.bazel.lock 4 | 5 | # Python 6 | __pycache__ 7 | .venv 8 | 9 | # IDEs 10 | .vscode 11 | 12 | -------------------------------------------------------------------------------- /BUILD: -------------------------------------------------------------------------------- 1 | # Copyright 2019 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # https://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | exports_files([ 16 | "build_defs.bzl", 17 | "LICENSE", 18 | ]) 19 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # How to Contribute 2 | 3 | We'd love to accept your patches and contributions to this project. There are 4 | just a few small guidelines you need to follow. 5 | 6 | ## Contributor License Agreement 7 | 8 | Contributions to this project must be accompanied by a Contributor License 9 | Agreement. You (or your employer) retain the copyright to your contribution; 10 | this simply gives us permission to use and redistribute your contributions as 11 | part of the project. Head over to to see 12 | your current agreements on file or to sign a new one. 13 | 14 | You generally only need to submit a CLA once, so if you've already submitted one 15 | (even if it was for a different project), you probably don't need to do it 16 | again. 17 | 18 | ## Code reviews 19 | 20 | All submissions, including submissions by project members, require review. We 21 | use GitHub pull requests for this purpose. Consult 22 | [GitHub Help](https://help.github.com/articles/about-pull-requests/) for more 23 | information on using pull requests. 24 | 25 | ## Community Guidelines 26 | 27 | This project follows [Google's Open Source Community 28 | Guidelines](https://opensource.google.com/conduct/). 29 | -------------------------------------------------------------------------------- /MODULE.bazel: -------------------------------------------------------------------------------- 1 | module( 2 | name = "emboss", 3 | version = "0.0.0", 4 | repo_name = "com_google_emboss", 5 | ) 6 | 7 | bazel_dep( 8 | name = "abseil-cpp", 9 | version = "20230125.1", 10 | repo_name = "com_google_absl", 11 | ) 12 | bazel_dep( 13 | name = "googletest", 14 | version = "1.14.0.bcr.1", 15 | repo_name = "com_google_googletest", 16 | ) 17 | bazel_dep(name = "rules_python", version = "0.31.0") 18 | -------------------------------------------------------------------------------- /compiler/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/google/emboss/3e621d71b78968d1f14760c4ac92b473f7278772/compiler/__init__.py -------------------------------------------------------------------------------- /compiler/back_end/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright 2019 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # https://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | -------------------------------------------------------------------------------- /compiler/back_end/cpp/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright 2019 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # https://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | -------------------------------------------------------------------------------- /compiler/back_end/cpp/attributes.py: -------------------------------------------------------------------------------- 1 | # Copyright 2023 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # https://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | """Attributes in the C++ backend and associated metadata.""" 16 | 17 | import enum 18 | from compiler.util import attribute_util 19 | 20 | 21 | class Attribute(str, enum.Enum): 22 | """Attributes available in the C++ backend.""" 23 | 24 | NAMESPACE = "namespace" 25 | ENUM_CASE = "enum_case" 26 | 27 | 28 | # Types associated with C++ backend attributes. 29 | TYPES = { 30 | Attribute.NAMESPACE: attribute_util.STRING, 31 | Attribute.ENUM_CASE: attribute_util.STRING, 32 | } 33 | 34 | 35 | class Scope(set, enum.Enum): 36 | """Allowed scopes for C++ backend attributes. 37 | 38 | Each entry is a set of (Attribute, default?) tuples, the first value being 39 | the attribute itself, the second value being a boolean value indicating 40 | whether the attribute is allowed to be defaulted in that scope.""" 41 | 42 | BITS = { 43 | # Bits may contain an enum definition. 44 | (Attribute.ENUM_CASE, True) 45 | } 46 | ENUM = { 47 | (Attribute.ENUM_CASE, True), 48 | } 49 | ENUM_VALUE = { 50 | (Attribute.ENUM_CASE, False), 51 | } 52 | MODULE = ( 53 | { 54 | (Attribute.NAMESPACE, False), 55 | (Attribute.ENUM_CASE, True), 56 | }, 57 | ) 58 | STRUCT = { 59 | # Struct may contain an enum definition. 60 | (Attribute.ENUM_CASE, True), 61 | } 62 | -------------------------------------------------------------------------------- /compiler/back_end/cpp/build_defs.bzl: -------------------------------------------------------------------------------- 1 | # Copyright 2019 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # https://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | # -*- mode: python; -*- 16 | # vim:set ft=blazebuild: 17 | """Rule to generate cc_tests with and without system-specific optimizations.""" 18 | 19 | def emboss_cc_test(name, copts = None, no_w_sign_compare = False, **kwargs): 20 | """Generates cc_test rules with and without -DEMBOSS_NO_OPTIMIZATIONS.""" 21 | native.cc_test( 22 | name = name, 23 | copts = copts or [], 24 | **kwargs 25 | ) 26 | native.cc_test( 27 | name = name + "_no_opts", 28 | copts = [ 29 | "-DEMBOSS_NO_OPTIMIZATIONS", 30 | ] + ([] if no_w_sign_compare else ["-Wsign-compare"]) + (copts or []), 31 | **kwargs 32 | ) 33 | native.cc_test( 34 | name = name + "_no_checks", 35 | copts = ["-DEMBOSS_SKIP_CHECKS"] + (copts or []), 36 | **kwargs 37 | ) 38 | native.cc_test( 39 | name = name + "_no_checks_no_opts", 40 | copts = [ 41 | "-DEMBOSS_NO_OPTIMIZATIONS", 42 | "-DEMBOSS_SKIP_CHECKS", 43 | ] + ([] if no_w_sign_compare else ["-Wsign-compare"]) + (copts or []), 44 | **kwargs 45 | ) 46 | -------------------------------------------------------------------------------- /compiler/back_end/cpp/testcode/complex_offset_test.cc: -------------------------------------------------------------------------------- 1 | // Copyright 2019 Google LLC 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // https://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | // Tests of packed field support. 16 | #include 17 | 18 | #include 19 | #include 20 | #include 21 | 22 | #include "gtest/gtest.h" 23 | #include "testdata/complex_offset.emb.h" 24 | 25 | namespace emboss { 26 | namespace test { 27 | namespace { 28 | 29 | TEST(PackedFields, PerformanceOfOk) { 30 | ::std::array values = {0}; 31 | const auto view = MakePackedFieldsView(&values); 32 | EXPECT_TRUE(view.Ok()); 33 | EXPECT_TRUE(view.length6().Ok()); 34 | EXPECT_TRUE(view.data6().Ok()); 35 | } 36 | 37 | } // namespace 38 | } // namespace test 39 | } // namespace emboss 40 | -------------------------------------------------------------------------------- /compiler/back_end/cpp/testcode/complex_structure_test.cc: -------------------------------------------------------------------------------- 1 | // Copyright 2019 Google LLC 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // https://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | // Tests of generated code for text format. 16 | #include 17 | 18 | #include 19 | #include 20 | #include 21 | 22 | #include "gtest/gtest.h" 23 | #include "testdata/complex_structure.emb.h" 24 | 25 | namespace emboss_test { 26 | namespace { 27 | 28 | TEST(InvalidTextInput, PrematureEnd) { 29 | ::std::array values = {0}; 30 | const auto view = ::emboss_test::MakeComplexView(&values); 31 | ::emboss::UpdateFromText(view, "{a:"); 32 | } 33 | 34 | TEST(InvalidTextInput, ReallyPrematureEnd) { 35 | ::std::array values = {0}; 36 | const auto view = ::emboss_test::MakeComplexView(&values); 37 | ::emboss::UpdateFromText(view, "\x01"); 38 | } 39 | 40 | TEST(InvalidTextInput, WeirdInputDoesNotHang) { 41 | ::std::string text{0x7b, 0x78, 0x32, 0x3a, 0x30, 0x0d, 0x0d, 0x62, 0x32, 42 | 0x7f, 0x30, 0x0d, 0x0d, 0x62, 0x32, 0x3a, 0x30, 0x0d, 43 | 0x0d, 0x62, 0x32, 0x3a, 0x30, 0x0d, 0x0c, 0x30, 0x0d, 44 | 0x0d, 0x63, 0x32, 0x3a, 0x30, 0x0d, 0x0d, 0x62, 0x36, 45 | 0x3a, 0x30, 0x0d, 0x32, 0x3a, 0x30, 0x0d}; 46 | ::std::array values = {0}; 47 | const auto view = ::emboss_test::MakeComplexView(&values); 48 | ::emboss::UpdateFromText(view, text); 49 | } 50 | 51 | } // namespace 52 | } // namespace emboss_test 53 | -------------------------------------------------------------------------------- /compiler/back_end/cpp/testcode/explicit_sizes_test.cc: -------------------------------------------------------------------------------- 1 | // Copyright 2019 Google LLC 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // https://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | // Tests for the generated View class for Container and Box from 16 | // nested_structure.emb. 17 | // 18 | // These tests check that nested structures work. 19 | #include 20 | 21 | #include 22 | 23 | #include "gtest/gtest.h" 24 | #include "testdata/explicit_sizes.emb.h" 25 | 26 | namespace emboss { 27 | namespace test { 28 | namespace { 29 | 30 | static const ::std::uint8_t kUIntArrays[21] = { 31 | 0x21, // one_nibble == { 0x1, 0x2 } 32 | 0x10, 0x20, // two_nibble == { 0x10, 0x20 } 33 | 0x10, 0x11, 0x20, 0x22, // four_nibble == { 0x1110, 0x2220 } 34 | }; 35 | 36 | TEST(SizesView, CanReadSizes) { 37 | auto outer_view = BitArrayContainerView(kUIntArrays, sizeof kUIntArrays); 38 | auto view = outer_view.uint_arrays(); 39 | EXPECT_EQ(0x1, view.one_nibble()[0].Read()); 40 | EXPECT_EQ(0x2, view.one_nibble()[1].Read()); 41 | EXPECT_EQ(0x10, view.two_nibble()[0].Read()); 42 | EXPECT_EQ(0x20, view.two_nibble()[1].Read()); 43 | EXPECT_EQ(0x1110, view.four_nibble()[0].Read()); 44 | EXPECT_EQ(0x2220, view.four_nibble()[1].Read()); 45 | } 46 | 47 | } // namespace 48 | } // namespace test 49 | } // namespace emboss 50 | -------------------------------------------------------------------------------- /compiler/back_end/cpp/testcode/importer2_test.cc: -------------------------------------------------------------------------------- 1 | // Copyright 2023 Google LLC 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // https://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | // Tests for using types that are imported from imports. 16 | 17 | #include 18 | 19 | #include 20 | 21 | #include "gtest/gtest.h" 22 | #include "testdata/importer2.emb.h" 23 | 24 | namespace emboss { 25 | namespace test { 26 | namespace { 27 | 28 | const ::std::uint8_t kOuter2[16] = { 29 | 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, // inner 30 | 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10, // inner_gen 31 | }; 32 | 33 | TEST(Importer, CanAccessInner) { 34 | auto view = Outer2View(kOuter2, sizeof kOuter2); 35 | EXPECT_EQ(0x0807060504030201UL, view.outer().inner().value().Read()); 36 | EXPECT_EQ(0x100f0e0d0c0b0a09UL, view.outer().inner_gen().value().Read()); 37 | } 38 | 39 | } // namespace 40 | } // namespace test 41 | } // namespace emboss 42 | -------------------------------------------------------------------------------- /compiler/back_end/cpp/testcode/importer_test.cc: -------------------------------------------------------------------------------- 1 | // Copyright 2019 Google LLC 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // https://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | // Tests for using imported types. 16 | 17 | #include 18 | 19 | #include 20 | 21 | #include "gtest/gtest.h" 22 | #include "testdata/importer.emb.h" 23 | 24 | namespace emboss { 25 | namespace test { 26 | namespace { 27 | 28 | const ::std::uint8_t kOuter[16] = { 29 | 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, // inner 30 | 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10, // inner_gen 31 | }; 32 | 33 | TEST(Importer, CanAccessInner) { 34 | auto view = OuterView(kOuter, sizeof kOuter); 35 | EXPECT_EQ(0x0807060504030201UL, view.inner().value().Read()); 36 | EXPECT_EQ(0x100f0e0d0c0b0a09UL, view.inner_gen().value().Read()); 37 | } 38 | 39 | } // namespace 40 | } // namespace test 41 | } // namespace emboss 42 | -------------------------------------------------------------------------------- /compiler/back_end/cpp/testcode/inline_type_test.cc: -------------------------------------------------------------------------------- 1 | // Copyright 2019 Google LLC 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // https://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | // Tests for types defined inline. 16 | #include 17 | 18 | #include 19 | 20 | #include "gtest/gtest.h" 21 | #include "testdata/inline_type.emb.h" 22 | 23 | namespace emboss { 24 | namespace test { 25 | namespace { 26 | 27 | static const ::std::uint8_t kFoo[2] = {0, 12}; 28 | 29 | static const ::std::uint8_t kFooOnFire[2] = {12, 0}; 30 | 31 | // Tests that inline-defined enums have correct, independent values. 32 | TEST(FooView, EnumValuesAreAsExpected) { 33 | EXPECT_EQ(0, static_cast(Foo::Status::OK)); 34 | EXPECT_EQ(12, static_cast(Foo::Status::FAILURE)); 35 | EXPECT_EQ(12, static_cast(Foo::SecondaryStatus::OK)); 36 | EXPECT_EQ(0, static_cast(Foo::SecondaryStatus::FAILURE)); 37 | } 38 | 39 | // Tests that a structure containing inline-defined enums can be read correctly. 40 | TEST(FooView, ReadsCorrectly) { 41 | auto ok_view = FooView(kFoo, sizeof kFoo); 42 | EXPECT_EQ(Foo::Status::OK, ok_view.status().Read()); 43 | EXPECT_EQ(Foo::SecondaryStatus::OK, ok_view.secondary_status().Read()); 44 | auto on_fire_view = FooView(kFooOnFire, sizeof kFooOnFire); 45 | EXPECT_EQ(Foo::Status::FAILURE, on_fire_view.status().Read()); 46 | EXPECT_EQ(Foo::SecondaryStatus::FAILURE, 47 | on_fire_view.secondary_status().Read()); 48 | } 49 | 50 | } // namespace 51 | } // namespace test 52 | } // namespace emboss 53 | -------------------------------------------------------------------------------- /compiler/back_end/cpp/testcode/namespace_test.cc: -------------------------------------------------------------------------------- 1 | // Copyright 2019 Google LLC 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // https://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | // Tests that generated code ends up in the correct C++ namespaces. 16 | #include 17 | 18 | #include 19 | 20 | #include "gtest/gtest.h" 21 | #include "testdata/absolute_cpp_namespace.emb.h" 22 | #include "testdata/cpp_namespace.emb.h" 23 | #include "testdata/no_cpp_namespace.emb.h" 24 | 25 | namespace emboss { 26 | namespace test { 27 | namespace { 28 | 29 | TEST(Namespace, FooValueHasCorrectValueInDifferentNamespaces) { 30 | EXPECT_EQ(static_cast(10), 31 | ::emboss_generated_code::Foo::VALUE); 32 | EXPECT_EQ(static_cast(11), 33 | ::emboss::test::no_leading_double_colon::Foo::VALUE); 34 | EXPECT_EQ(static_cast(12), 35 | ::emboss::test::leading_double_colon::Foo::VALUE); 36 | } 37 | 38 | } // namespace 39 | } // namespace test 40 | } // namespace emboss 41 | -------------------------------------------------------------------------------- /compiler/back_end/cpp/testcode/next_keyword_test.cc: -------------------------------------------------------------------------------- 1 | // Copyright 2022 Google LLC 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // https://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | // Tests of generated code for structures using the `$next` keyword. 16 | // Note that `$next` is removed from the IR before it reaches the back end, so 17 | // this is really testing that the front end desugared correctly. 18 | #include 19 | 20 | #include 21 | #include 22 | #include 23 | 24 | #include "gtest/gtest.h" 25 | #include "testdata/next_keyword.emb.h" 26 | 27 | namespace emboss { 28 | namespace test { 29 | namespace { 30 | 31 | // For reference in the code below, the NextKeyword structure is defined as: 32 | // 33 | // [$default byte_order: "LittleEndian"] 34 | // struct NextKeyword: 35 | // 0 [+4] UInt value32 36 | // $next [+2] UInt value16 37 | // $next [+1] UInt value8 38 | // $next+3 [+1] UInt value8_offset 39 | TEST(NextKeyword, FieldsAreCorrectlyLocated) { 40 | ::std::array values = { 41 | 1, 0, 0, 0, 42 | 2, 0, 43 | 3, 44 | 5, 6, 7, 4, 45 | }; 46 | const auto view = MakeNextKeywordView(&values); 47 | ASSERT_TRUE(view.Ok()); 48 | EXPECT_EQ(1, view.value32().Read()); 49 | EXPECT_EQ(2, view.value16().Read()); 50 | EXPECT_EQ(3, view.value8().Read()); 51 | EXPECT_EQ(4, view.value8_offset().Read()); 52 | } 53 | 54 | } // namespace 55 | } // namespace test 56 | } // namespace emboss 57 | -------------------------------------------------------------------------------- /compiler/back_end/cpp/testcode/no_enum_traits_test.cc: -------------------------------------------------------------------------------- 1 | // Copyright 2024 Google LLC 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // https://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | // Tests that an emb compiled with enable_enum_traits = False actually compiles. 16 | 17 | #include 18 | 19 | #include 20 | 21 | #include "gmock/gmock.h" 22 | #include "gtest/gtest.h" 23 | #include "testdata/no_enum_traits.emb.h" 24 | 25 | namespace emboss { 26 | namespace test { 27 | namespace { 28 | 29 | TEST(NoEnumTraits, Compiles) { 30 | ::std::vector backing_store(1); 31 | auto view = MakeBarView(&backing_store); 32 | view.foo().Write(Foo::VALUE); 33 | EXPECT_TRUE(view.Ok()); 34 | 35 | // Check that we don't accidentally include `emboss_text_util.h` via our 36 | // generated header. 37 | #ifdef EMBOSS_RUNTIME_CPP_EMBOSS_TEXT_UTIL_H_ 38 | const bool emboss_text_util_is_present = true; 39 | #else 40 | const bool emboss_text_util_is_present = false; 41 | #endif 42 | 43 | EXPECT_FALSE(emboss_text_util_is_present); 44 | } 45 | 46 | } // namespace 47 | } // namespace test 48 | } // namespace emboss 49 | -------------------------------------------------------------------------------- /compiler/back_end/cpp/testcode/start_size_range_test.cc: -------------------------------------------------------------------------------- 1 | // Copyright 2019 Google LLC 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // https://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | // Test for the generated View class for StartSize from start_size_range.emb. 16 | 17 | #include 18 | 19 | #include "gtest/gtest.h" 20 | #include "testdata/start_size_range.emb.h" 21 | 22 | namespace emboss { 23 | namespace test { 24 | namespace { 25 | 26 | static const ::std::uint8_t kStartSizeRange[9] = { 27 | 0x02, // 0:1 0:1 size == 4 28 | 0xe8, 0x03, // 1:3 1 [+2] start_size_constants == 1000 29 | 0x11, 0x22, // 3:5 3 [+s] payload 30 | 0x21, 0x43, 0x65, 0x87, // 5:9 3+s [+4] counter == 0x87654321 31 | }; 32 | 33 | TEST(StartSizeView, EverythingInPlace) { 34 | auto view = StartSizeView(kStartSizeRange, sizeof kStartSizeRange); 35 | EXPECT_EQ(9U, view.SizeInBytes()); 36 | EXPECT_EQ(2, view.size().Read()); 37 | EXPECT_EQ(1000, view.start_size_constants().Read()); 38 | EXPECT_EQ(0x11, view.payload()[0].Read()); 39 | EXPECT_EQ(0x22, view.payload()[1].Read()); 40 | EXPECT_EQ(0x87654321, view.counter().Read()); 41 | } 42 | 43 | } // namespace 44 | } // namespace test 45 | } // namespace emboss 46 | -------------------------------------------------------------------------------- /compiler/back_end/util/BUILD: -------------------------------------------------------------------------------- 1 | # Copyright 2019 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # https://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | # Shared utilities for Emboss back ends. 16 | 17 | load("@rules_python//python:py_library.bzl", "py_library") 18 | load("@rules_python//python:py_test.bzl", "py_test") 19 | 20 | package( 21 | default_visibility = ["//compiler:__subpackages__"], 22 | ) 23 | 24 | py_library( 25 | name = "code_template", 26 | srcs = ["code_template.py"], 27 | deps = [ 28 | ], 29 | ) 30 | 31 | py_test( 32 | name = "code_template_test", 33 | srcs = ["code_template_test.py"], 34 | python_version = "PY3", 35 | deps = [ 36 | ":code_template", 37 | ], 38 | ) 39 | -------------------------------------------------------------------------------- /compiler/back_end/util/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright 2019 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # https://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | -------------------------------------------------------------------------------- /compiler/front_end/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright 2019 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # https://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | -------------------------------------------------------------------------------- /compiler/front_end/attributes.py: -------------------------------------------------------------------------------- 1 | # Copyright 2019 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # https://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | """Well-known attribute names.""" 16 | 17 | # Attribute names which may be used by other parts of the front end. 18 | ADDRESSABLE_UNIT_SIZE = "addressable_unit_size" 19 | BYTE_ORDER = "byte_order" 20 | RANGE = "range" 21 | FIXED_SIZE = "fixed_size_in_bits" 22 | IS_INTEGER = "is_integer" 23 | REQUIRES = "requires" 24 | STATIC_REQUIREMENTS = "static_requirements" 25 | TEXT_OUTPUT = "text_output" 26 | ENUM_MAXIMUM_BITS = "maximum_bits" 27 | IS_SIGNED = "is_signed" 28 | BACK_ENDS = "expected_back_ends" 29 | -------------------------------------------------------------------------------- /compiler/front_end/cached_parser_is_up_to_date_test.py: -------------------------------------------------------------------------------- 1 | # Copyright 2024 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # https://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | """Tests that compiler/front_end/generated/cached_parser.py is up to date.""" 16 | 17 | import pkgutil 18 | import unittest 19 | 20 | from compiler.front_end import generate_cached_parser 21 | 22 | 23 | class CachedParserIsUpToDateTest(unittest.TestCase): 24 | """Tests that the generated, checked-in parser is up to date.""" 25 | 26 | def test_cached_parser(self): 27 | cached_parser_text = pkgutil.get_data( 28 | "compiler.front_end.generated", "cached_parser.py" 29 | ).decode(encoding="UTF-8") 30 | correct_parser_text = generate_cached_parser.generate_parser_file_text() 31 | self.assertEqual( 32 | cached_parser_text, 33 | correct_parser_text, 34 | msg="Run\n\nbazel run //compiler/front_end:generate_cached_parser > compiler/front_end/generated/cached_parser.py", 35 | ) 36 | 37 | 38 | if __name__ == "__main__": 39 | unittest.main() 40 | -------------------------------------------------------------------------------- /compiler/front_end/docs_are_up_to_date_test.py: -------------------------------------------------------------------------------- 1 | # Copyright 2019 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # https://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | """Tests that doc/grammar.md is up to date.""" 16 | 17 | import pkgutil 18 | 19 | import unittest 20 | from compiler.front_end import generate_grammar_md 21 | 22 | 23 | class DocsAreUpToDateTest(unittest.TestCase): 24 | """Tests that auto-generated, checked-in documentation is up to date.""" 25 | 26 | def test_grammar_md(self): 27 | doc_md = pkgutil.get_data("doc", "grammar.md").decode(encoding="UTF-8") 28 | correct_md = generate_grammar_md.generate_grammar_md() 29 | msg = "Run:\n\nbazel run //compiler/front_end:generate_grammar_md > doc/grammar.md" 30 | doc_md_lines = doc_md.splitlines() 31 | correct_md_lines = correct_md.splitlines() 32 | for i in range(len(doc_md_lines)): 33 | self.assertEqual(correct_md_lines[i], doc_md_lines[i], msg=msg) 34 | self.assertEqual(correct_md, doc_md, msg=msg) 35 | 36 | 37 | if __name__ == "__main__": 38 | unittest.main() 39 | -------------------------------------------------------------------------------- /compiler/util/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/google/emboss/3e621d71b78968d1f14760c4ac92b473f7278772/compiler/util/__init__.py -------------------------------------------------------------------------------- /compiler/util/expression_parser.py: -------------------------------------------------------------------------------- 1 | # Copyright 2019 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # https://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | """Utility function to parse text into an ir_data.Expression.""" 16 | 17 | from compiler.front_end import module_ir 18 | from compiler.front_end import parser 19 | from compiler.front_end import tokenizer 20 | 21 | 22 | def parse(text): 23 | """Parses text as an Expression. 24 | 25 | This parses text using the expression subset of the Emboss grammar, and 26 | returns an ir_data.Expression. The expression only needs to be syntactically 27 | valid; it will not go through symbol resolution or type checking. This 28 | function is not intended to be called on arbitrary input; it asserts that the 29 | text successfully parses, but does not return errors. 30 | 31 | Arguments: 32 | text: The text of an Emboss expression, like "4 + 5" or "$max(1, a, b)". 33 | 34 | Returns: 35 | An ir_data.Expression corresponding to the textual form. 36 | 37 | Raises: 38 | AssertionError if text is not a well-formed Emboss expression, and 39 | assertions are enabled. 40 | """ 41 | tokens, errors = tokenizer.tokenize(text, "") 42 | assert not errors, "{!r}".format(errors) 43 | # tokenizer.tokenize always inserts a newline token at the end, which breaks 44 | # expression parsing. 45 | parse_result = parser.parse_expression(tokens[:-1]) 46 | assert not parse_result.error, "{!r}".format(parse_result.error) 47 | return module_ir.build_ir(parse_result.parse_tree) 48 | -------------------------------------------------------------------------------- /compiler/util/resources.py: -------------------------------------------------------------------------------- 1 | # Copyright 2024 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # https://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | """Routines to load resource files from within the compiler.""" 16 | 17 | import importlib.resources 18 | 19 | 20 | def load(package, file, encoding="utf-8"): 21 | """Returns the contents of `file` from the Python package loader.""" 22 | with importlib.resources.files(package).joinpath(file).open( 23 | "r", encoding=encoding 24 | ) as f: 25 | return f.read() 26 | -------------------------------------------------------------------------------- /doc/BUILD: -------------------------------------------------------------------------------- 1 | # Copyright 2019 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # https://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | # Documentation for Emboss. 16 | # 17 | # This BUILD file only exists to export grammar.md for use in a test in 18 | # emboss/misc. 19 | 20 | filegroup( 21 | name = "grammar_md", 22 | srcs = [ 23 | "__init__.py", 24 | "grammar.md", 25 | ], 26 | # This should only be needed by docs_are_up_to_date_test. 27 | visibility = ["//:__subpackages__"], 28 | ) 29 | -------------------------------------------------------------------------------- /doc/BogoNEL_BN-P-6000404_User_Guide.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/google/emboss/3e621d71b78968d1f14760c4ac92b473f7278772/doc/BogoNEL_BN-P-6000404_User_Guide.pdf -------------------------------------------------------------------------------- /doc/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright 2019 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # https://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | -------------------------------------------------------------------------------- /doc/design_docs/bit_shift/precedence.dot: -------------------------------------------------------------------------------- 1 | strict digraph { 2 | bgcolor = "white" 3 | ordering = "out" 4 | edge [color = "black"] 5 | node [ 6 | color = "black" 7 | fontcolor = "black" 8 | shape = box 9 | ordering = "out" 10 | ] 11 | subgraph { 12 | // rank = same 13 | rankdir = LR 14 | 15 | paren [ordering = "out"; label="() $max() $present()"] 16 | unary_plus [ordering = "out"; label="unary + -"] 17 | mult [ordering = "out"; label="*"] 18 | add [ordering = "out"; label="+ -"] 19 | shift [ordering = "out"; label=">> <<"] 20 | ne [ordering = "out"; label="!="] 21 | le [ordering = "out"; label="< <= =="] 22 | ge [ordering = "out"; label="> >= =="] 23 | land [ordering = "out"; label="&&"] 24 | lor [ordering = "out"; label="||"] 25 | choice [ordering = "out"; label="?:"] 26 | paren -> unary_plus 27 | unary_plus -> mult 28 | mult -> add 29 | mult -> shift 30 | add -> ne 31 | add -> le 32 | add -> ge 33 | shift -> ne 34 | shift -> le 35 | shift -> ge 36 | ne -> land 37 | ne -> lor 38 | le -> land 39 | le -> lor 40 | ge -> land 41 | ge -> lor 42 | land -> choice 43 | lor -> choice 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /doc/index.md: -------------------------------------------------------------------------------- 1 | Welcome to Emboss, the Embedded Systems Binary Structure Tool. 2 | 3 | If you are new to Emboss, a good place to start would be the [User 4 | Guide](guide.md). 5 | 6 | The [C++ User Guide](cpp-guide.md) has an (incomplete) explanation of the 7 | generated C++ code. 8 | 9 | Details of the Emboss language can be found in the [Emboss Language 10 | Reference](language-reference.md). 11 | 12 | A reference to the C++ code that Emboss generates can be found in the [Emboss 13 | C++ Generated Code Reference](cpp-reference.md). 14 | 15 | Details of the textual representation Emboss uses for structures can be found in 16 | the [Emboss Text Format Reference](text-format.md). 17 | 18 | There is a tentative [roadmap of future development](roadmap.md). 19 | 20 | If you are interested in contributing to Emboss, please read [Contributing to 21 | Emboss](contributing.md), and you may wish to read [How to Design Features for 22 | Emboss](how-to-design.md) and [How to Implement Changes to 23 | Emboss](how-to-implement.md). 24 | -------------------------------------------------------------------------------- /doc/modular_congruence_multiplication_proof.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/google/emboss/3e621d71b78968d1f14760c4ac92b473f7278772/doc/modular_congruence_multiplication_proof.pdf -------------------------------------------------------------------------------- /doc/sitemap.md: -------------------------------------------------------------------------------- 1 | * [Home](index.md) 2 | * [User Guide](guide.md) 3 | * [Emboss Language Reference](language-reference.md) 4 | * [Emboss C++ Generated Code Reference](cpp-reference.md) 5 | * [Grammar Specification](grammar.md) 6 | * [Design of the Emboss tool](design.md) 7 | * [Emboss Text Format Reference](text-format.md) 8 | -------------------------------------------------------------------------------- /doc/todo.md: -------------------------------------------------------------------------------- 1 | * Syntax files: 2 | * TODO(bolms): Emacs syntax file 3 | -------------------------------------------------------------------------------- /integration/googletest/BUILD: -------------------------------------------------------------------------------- 1 | # Copyright 2019 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # https://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | cc_library( 16 | name = "emboss_test_util", 17 | testonly = 1, 18 | hdrs = ["emboss_test_util.h"], 19 | visibility = ["//visibility:public"], 20 | deps = [ 21 | "//runtime/cpp:cpp_utils", 22 | "@com_google_absl//absl/memory", 23 | "@com_google_googletest//:gtest", 24 | ], 25 | ) 26 | 27 | cc_test( 28 | name = "emboss_test_util_test", 29 | srcs = [ 30 | "emboss_test_util_test.cc", 31 | ], 32 | copts = ["-Wsign-compare"], 33 | deps = [ 34 | ":emboss_test_util", 35 | "//testdata:complex_structure_emboss", 36 | "@com_google_googletest//:gtest_main", 37 | ], 38 | ) 39 | -------------------------------------------------------------------------------- /integration/vim/ft-emboss/ftdetect/emboss.vim: -------------------------------------------------------------------------------- 1 | " Copyright 2019 Google LLC 2 | " 3 | " Licensed under the Apache License, Version 2.0 (the "License"); 4 | " you may not use this file except in compliance with the License. 5 | " You may obtain a copy of the License at 6 | " 7 | " https://www.apache.org/licenses/LICENSE-2.0 8 | " 9 | " Unless required by applicable law or agreed to in writing, software 10 | " distributed under the License is distributed on an "AS IS" BASIS, 11 | " WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | " See the License for the specific language governing permissions and 13 | " limitations under the License. 14 | 15 | " Vim file detection for Emboss. 16 | 17 | autocmd BufRead,BufNewFile *.emb setfiletype emboss 18 | -------------------------------------------------------------------------------- /integration/vim/ft-emboss/ftplugin/emboss.vim: -------------------------------------------------------------------------------- 1 | " Copyright 2019 Google LLC 2 | " 3 | " Licensed under the Apache License, Version 2.0 (the "License"); 4 | " you may not use this file except in compliance with the License. 5 | " You may obtain a copy of the License at 6 | " 7 | " https://www.apache.org/licenses/LICENSE-2.0 8 | " 9 | " Unless required by applicable law or agreed to in writing, software 10 | " distributed under the License is distributed on an "AS IS" BASIS, 11 | " WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | " See the License for the specific language governing permissions and 13 | " limitations under the License. 14 | 15 | " Emboss-specific Vim settings. 16 | 17 | if exists('b:did_ftplugin') 18 | finish 19 | endif 20 | 21 | let b:did_ftplugin = 1 22 | let b:undo_ftplugin = 'setlocal comments< commentstring< formatoptions< iskeyword<' 23 | 24 | setlocal formatoptions-=t 25 | setlocal comments=b:--,:# 26 | setlocal iskeyword+=$ 27 | setlocal commentstring=#\ %s 28 | -------------------------------------------------------------------------------- /license_header: -------------------------------------------------------------------------------- 1 | Copyright 2019 Google LLC 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | https://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | -------------------------------------------------------------------------------- /pyproject.toml: -------------------------------------------------------------------------------- 1 | [tool.black] 2 | extend-exclude = ''' 3 | ^/compiler/front_end/generated/cached_parser\.py$ 4 | ''' 5 | -------------------------------------------------------------------------------- /runtime/cpp/BUILD: -------------------------------------------------------------------------------- 1 | # Copyright 2019 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # https://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | # Emboss C++ Runtime. 16 | 17 | filegroup( 18 | name = "raw_headers", 19 | srcs = [ 20 | "emboss_arithmetic.h", 21 | "emboss_arithmetic_all_known_generated.h", 22 | "emboss_arithmetic_maximum_operation_generated.h", 23 | "emboss_array_view.h", 24 | "emboss_bit_util.h", 25 | "emboss_constant_view.h", 26 | "emboss_cpp_types.h", 27 | "emboss_cpp_util.h", 28 | "emboss_defines.h", 29 | "emboss_enum_view.h", 30 | "emboss_maybe.h", 31 | "emboss_memory_util.h", 32 | "emboss_prelude.h", 33 | "emboss_text_util.h", 34 | "emboss_view_parameters.h", 35 | ], 36 | visibility = ["//:__subpackages__"], 37 | ) 38 | 39 | cc_library( 40 | name = "cpp_utils", 41 | hdrs = [ 42 | ":raw_headers", 43 | ], 44 | visibility = ["//visibility:public"], 45 | deps = [ 46 | # BEGIN INSERT_MY_SITE_DEFINES_TARGET_HERE 47 | # "//MY_SITE_DEFINES:TARGET", 48 | # END INSERT_MY_SITE_DEFINES_TARGET_HERE 49 | ], 50 | ) 51 | -------------------------------------------------------------------------------- /runtime/cpp/emboss_constant_view.h: -------------------------------------------------------------------------------- 1 | // Copyright 2019 Google LLC 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // https://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #ifndef EMBOSS_RUNTIME_CPP_EMBOSS_CONSTANT_VIEW_H_ 16 | #define EMBOSS_RUNTIME_CPP_EMBOSS_CONSTANT_VIEW_H_ 17 | 18 | #include "runtime/cpp/emboss_maybe.h" 19 | 20 | namespace emboss { 21 | namespace support { 22 | 23 | // MaybeConstantView is a "view" type that "reads" a value passed into its 24 | // constructor. 25 | // 26 | // This is used internally by generated structure view classes to provide views 27 | // of parameters; in this way, parameters can be treated like fields in the 28 | // generated code. 29 | template 30 | class MaybeConstantView { 31 | public: 32 | MaybeConstantView() : value_() {} 33 | constexpr explicit MaybeConstantView(ValueT value) : value_(value) {} 34 | MaybeConstantView(const MaybeConstantView &) = default; 35 | MaybeConstantView(MaybeConstantView &&) = default; 36 | MaybeConstantView &operator=(const MaybeConstantView &) = default; 37 | MaybeConstantView &operator=(MaybeConstantView &&) = default; 38 | ~MaybeConstantView() = default; 39 | 40 | constexpr ValueT Read() const { return value_.Value(); } 41 | constexpr ValueT UncheckedRead() const { return value_.ValueOrDefault(); } 42 | constexpr bool Ok() const { return value_.Known(); } 43 | 44 | private: 45 | ::emboss::support::Maybe value_; 46 | }; 47 | 48 | } // namespace support 49 | } // namespace emboss 50 | 51 | #endif // EMBOSS_RUNTIME_CPP_EMBOSS_CONSTANT_VIEW_H_ 52 | -------------------------------------------------------------------------------- /runtime/cpp/emboss_cpp_util.h: -------------------------------------------------------------------------------- 1 | // Copyright 2019 Google LLC 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // https://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | // This header exports utilities that are needed for all Emboss-generated C++ 16 | // code. 17 | #ifndef EMBOSS_RUNTIME_CPP_EMBOSS_CPP_UTIL_H_ 18 | #define EMBOSS_RUNTIME_CPP_EMBOSS_CPP_UTIL_H_ 19 | 20 | #include "runtime/cpp/emboss_arithmetic.h" 21 | #include "runtime/cpp/emboss_array_view.h" 22 | #include "runtime/cpp/emboss_bit_util.h" 23 | #include "runtime/cpp/emboss_constant_view.h" 24 | #include "runtime/cpp/emboss_cpp_types.h" 25 | #include "runtime/cpp/emboss_defines.h" 26 | #include "runtime/cpp/emboss_enum_view.h" 27 | #include "runtime/cpp/emboss_memory_util.h" 28 | #include "runtime/cpp/emboss_view_parameters.h" 29 | 30 | #endif // EMBOSS_RUNTIME_CPP_EMBOSS_CPP_UTIL_H_ 31 | -------------------------------------------------------------------------------- /runtime/cpp/emboss_view_parameters.h: -------------------------------------------------------------------------------- 1 | // Copyright 2019 Google LLC 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // https://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | // Helper classes for constructing the `Parameters` template argument to view 16 | // classes. 17 | 18 | #ifndef EMBOSS_RUNTIME_CPP_EMBOSS_VIEW_PARAMETERS_H_ 19 | #define EMBOSS_RUNTIME_CPP_EMBOSS_VIEW_PARAMETERS_H_ 20 | 21 | namespace emboss { 22 | namespace support { 23 | 24 | template 25 | struct FixedSizeViewParameters { 26 | static constexpr int kBits = kBitsParam; 27 | template 28 | static constexpr bool ValueIsOk(ValueType value) { 29 | return Verifier::ValueIsOk(value); 30 | } 31 | // TODO(bolms): add AllValuesAreOk(), and use it to shortcut Ok() processing 32 | // for arrays and other compound objects. 33 | }; 34 | 35 | struct AllValuesAreOk { 36 | template 37 | static constexpr bool ValueIsOk(ValueType) { 38 | return true; 39 | } 40 | }; 41 | 42 | } // namespace support 43 | } // namespace emboss 44 | 45 | #endif // EMBOSS_RUNTIME_CPP_EMBOSS_VIEW_PARAMETERS_H_ 46 | -------------------------------------------------------------------------------- /runtime/cpp/test/build_defs.bzl: -------------------------------------------------------------------------------- 1 | # Copyright 2019 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # https://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | # -*- mode: python; -*- 16 | # vim:set ft=blazebuild: 17 | 18 | """Macro to run tests both with and without optimizations.""" 19 | 20 | def emboss_cc_util_test(name, copts = [], **kwargs): 21 | """Constructs two cc_test targets, with and without optimizations.""" 22 | native.cc_test( 23 | name = name, 24 | copts = copts + ["-Wsign-compare"], 25 | **kwargs 26 | ) 27 | native.cc_test( 28 | name = name + "_no_opts", 29 | copts = copts + [ 30 | # This is generally a dangerous flag for an individual target, but 31 | # these tests do not depend on any other .cc files that might 32 | # #include any Emboss headers. 33 | "-DEMBOSS_NO_OPTIMIZATIONS", 34 | ], 35 | **kwargs 36 | ) 37 | -------------------------------------------------------------------------------- /runtime/cpp/test/emboss_cpp_util_google_integration_test.cc: -------------------------------------------------------------------------------- 1 | // Copyright 2019 Google LLC 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // https://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #include "absl/strings/string_view.h" 16 | #include "gtest/gtest.h" 17 | #include "runtime/cpp/emboss_cpp_util.h" 18 | #include "runtime/cpp/emboss_text_util.h" 19 | 20 | namespace emboss { 21 | namespace support { 22 | namespace test { 23 | 24 | TEST(TextStream, Construction) { 25 | absl::string_view view_text = "gh"; 26 | auto text_stream = TextStream(view_text); 27 | char result; 28 | EXPECT_TRUE(text_stream.Read(&result)); 29 | EXPECT_EQ('g', result); 30 | EXPECT_TRUE(text_stream.Read(&result)); 31 | EXPECT_EQ('h', result); 32 | EXPECT_FALSE(text_stream.Read(&result)); 33 | } 34 | 35 | } // namespace test 36 | } // namespace support 37 | } // namespace emboss 38 | -------------------------------------------------------------------------------- /runtime/cpp/test/emboss_maybe_test.cc: -------------------------------------------------------------------------------- 1 | // Copyright 2019 Google LLC 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // https://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #include "runtime/cpp/emboss_maybe.h" 16 | 17 | #include "gmock/gmock.h" 18 | #include "gtest/gtest.h" 19 | 20 | namespace emboss { 21 | namespace support { 22 | namespace test { 23 | 24 | enum class Foo : ::std::int64_t { 25 | BAR = 1, 26 | BAZ = 2, 27 | }; 28 | 29 | TEST(Maybe, Known) { 30 | EXPECT_TRUE(Maybe(10).Known()); 31 | EXPECT_EQ(10, Maybe(10).ValueOr(3)); 32 | EXPECT_EQ(10, Maybe(10).ValueOrDefault()); 33 | EXPECT_EQ(10, Maybe(10).Value()); 34 | EXPECT_TRUE(Maybe(true).Value()); 35 | EXPECT_EQ(Foo::BAZ, Maybe(Foo::BAZ).ValueOrDefault()); 36 | 37 | Maybe x = Maybe(1000); 38 | Maybe y = Maybe(); 39 | y = x; 40 | EXPECT_TRUE(y.Known()); 41 | EXPECT_EQ(1000, y.Value()); 42 | } 43 | 44 | TEST(Maybe, Unknown) { 45 | EXPECT_FALSE(Maybe().Known()); 46 | EXPECT_EQ(3, Maybe().ValueOr(3)); 47 | EXPECT_EQ(0, Maybe().ValueOrDefault()); 48 | EXPECT_FALSE(Maybe().ValueOrDefault()); 49 | #if EMBOSS_CHECK_ABORTS 50 | EXPECT_DEATH(Maybe().Value(), "Known()"); 51 | #endif // EMBOSS_CHECK_ABORTS 52 | EXPECT_FALSE(Maybe().ValueOrDefault()); 53 | EXPECT_EQ(static_cast(0), Maybe().ValueOrDefault()); 54 | 55 | Maybe x = Maybe(); 56 | Maybe y = Maybe(1000); 57 | y = x; 58 | EXPECT_FALSE(y.Known()); 59 | } 60 | 61 | } // namespace test 62 | } // namespace support 63 | } // namespace emboss 64 | -------------------------------------------------------------------------------- /testdata/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright 2019 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # https://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | -------------------------------------------------------------------------------- /testdata/absolute_cpp_namespace.emb: -------------------------------------------------------------------------------- 1 | # Copyright 2019 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # https://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | -- Test .emb to ensure that the generated type ends up in the given namespace 16 | -- when the [(cpp) namespace] attribute is set to a valid value with leading 17 | -- "::". 18 | 19 | [(cpp) namespace: "::emboss::test::leading_double_colon"] 20 | 21 | 22 | enum Foo: 23 | VALUE = 12 24 | -------------------------------------------------------------------------------- /testdata/alignments.emb: -------------------------------------------------------------------------------- 1 | # Copyright 2019 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # https://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | -- Structures which can be used be test code to check that alignment 16 | -- information is properly propagated through Emboss views. 17 | 18 | [$default byte_order: "BigEndian"] 19 | [(cpp) namespace: "emboss::test"] 20 | 21 | 22 | struct Alignments: 23 | 0 [+4] Placeholder4 zero_offset 24 | 0 [+6] Placeholder6 zero_offset_substructure 25 | 2 [+6] Placeholder6 two_offset_substructure 26 | 3 [+4] Placeholder4 three_offset 27 | 4 [+4] Placeholder4 four_offset 28 | 11 [+4] Placeholder4 eleven_offset 29 | 12 [+4] Placeholder4 twelve_offset 30 | 0 [+12] Placeholder4[3] zero_offset_four_stride_array 31 | 0 [+24] Placeholder6[4] zero_offset_six_stride_array 32 | 3 [+12] Placeholder4[3] three_offset_four_stride_array 33 | 4 [+24] Placeholder6[4] four_offset_six_stride_array 34 | 35 | 36 | struct Placeholder4: 37 | -- Four-byte structure used as a byte-oriented placeholder so that type 38 | -- alignment can be tested without any of the bit/byte interface types. 39 | 0 [+4] UInt dummy 40 | 41 | 42 | struct Placeholder6: 43 | -- Six-byte structure. Includes Placeholder4 so that substructure alignments 44 | -- can be checked. 45 | 0 [+4] Placeholder4 zero_offset 46 | 2 [+4] Placeholder4 two_offset 47 | -------------------------------------------------------------------------------- /testdata/anonymous_bits.emb: -------------------------------------------------------------------------------- 1 | # Copyright 2019 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # https://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | [$default byte_order: "LittleEndian"] 16 | [(cpp) namespace: "emboss::test"] 17 | 18 | 19 | struct Foo: 20 | 0 [+4] bits: 21 | 31 [+1] Flag high_bit 22 | 14 [+4] enum bar: 23 | BAR = 0 24 | BAZ = 1 25 | 26 | 0 [+1] Flag first_bit 27 | 28 | 4 [+4] bits: 29 | # The last byte is intentionally unused, in order to test that Ok() checks 30 | # the readability of all the bits, not just the ones that have names. 31 | 23 [+1] Flag bit_23 32 | 0 [+1] Flag low_bit 33 | -------------------------------------------------------------------------------- /testdata/auto_array_size.emb: -------------------------------------------------------------------------------- 1 | # Copyright 2019 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # https://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | [$default byte_order: "LittleEndian"] 16 | [(cpp) namespace: "emboss::test"] 17 | 18 | 19 | struct Element: 20 | 0 [+1] UInt a 21 | 1 [+1] UInt b 22 | 23 | 24 | struct AutoSize: 25 | 0 [+1] UInt array_size (a) 26 | 1 [+4] UInt:8[] four_byte_array 27 | 5 [+8] Element[] four_struct_array 28 | 13 [+a] UInt:8[] dynamic_byte_array 29 | 13+a [+2*a] Element[] dynamic_struct_array 30 | -------------------------------------------------------------------------------- /testdata/bcd.emb: -------------------------------------------------------------------------------- 1 | # Copyright 2019 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # https://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | -- Tests for various sizes of Binary-Coded Decimal (BCD) integers. 16 | 17 | [$default byte_order: "LittleEndian"] 18 | [(cpp) namespace: "emboss::test"] 19 | 20 | 21 | struct BcdSizes: 22 | 0 [+1] Bcd one_byte 23 | 1 [+2] Bcd two_byte 24 | 3 [+3] Bcd three_byte 25 | 6 [+4] Bcd four_byte 26 | 10 [+5] Bcd five_byte 27 | 15 [+6] Bcd six_byte 28 | 21 [+7] Bcd seven_byte 29 | 28 [+8] Bcd eight_byte 30 | 36 [+4] bits: 31 | 0 [+4] Bcd four_bit 32 | 4 [+6] Bcd six_bit 33 | 10 [+10] Bcd ten_bit 34 | 20 [+12] Bcd twelve_bit 35 | 36 | 37 | struct BcdBigEndian: 38 | [$default byte_order: "BigEndian"] 39 | 0 [+4] Bcd four_byte 40 | -------------------------------------------------------------------------------- /testdata/bits.emb: -------------------------------------------------------------------------------- 1 | # Copyright 2019 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # https://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | -- Test `.emb` for the `bits` construct. 16 | 17 | [$default byte_order: "LittleEndian"] 18 | [(cpp) namespace: "emboss::test"] 19 | 20 | 21 | bits OneByte: 22 | 7 [+1] Flag high_bit 23 | 6 [+1] Flag less_high_bit 24 | 2 [+4] UInt mid_nibble 25 | 1 [+1] Flag less_low_bit 26 | 0 [+1] Flag low_bit 27 | 28 | 29 | bits FourByte: 30 | bits TwoByteWithGaps: 31 | 15 [+1] Flag high_bit 32 | 6 [+4] UInt mid_nibble 33 | 0 [+1] Flag low_bit 34 | 35 | 28 [+4] UInt high_nibble 36 | 20 [+8] OneByte one_byte 37 | 4 [+16] TwoByteWithGaps two_byte 38 | 0 [+4] UInt raw_low_nibble 39 | # Check that the [requires] attribute works on bits fields just like it does 40 | # on struct fields. 41 | [requires: 1 <= this <= 15] 42 | let low_nibble = raw_low_nibble + 100 43 | 44 | 45 | bits ArrayInBits: 46 | 15 [+1] Flag lone_flag 47 | 0 [+12] Flag[] flags 48 | 49 | 50 | struct ArrayInBitsInStruct: 51 | 0 [+2] ArrayInBits array_in_bits 52 | 53 | 54 | struct StructOfBits: 55 | 0 [+1] OneByte one_byte 56 | 1 [+2] FourByte.TwoByteWithGaps two_byte 57 | 3 [+4] FourByte four_byte 58 | one_byte.mid_nibble [+1] UInt located_byte 59 | 60 | 61 | struct BitArray: 62 | 0 [+8] OneByte[8] one_byte 63 | -------------------------------------------------------------------------------- /testdata/complex_offset.emb: -------------------------------------------------------------------------------- 1 | # Copyright 2019 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # https://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | -- Test .emb with a struct with several consecutive packed fields. 16 | -- 17 | -- This particular case stresses generated code; common subexpression 18 | -- elimination is needed in the code generator or else the generated code is 19 | -- very, *very* slow when compiled without optimizations. 20 | 21 | [$default byte_order: "BigEndian"] 22 | [(cpp) namespace: "emboss::test"] 23 | 24 | struct Length: 25 | 0 [+1] UInt length 26 | 27 | struct Data: 28 | 0 [+1] Length length 29 | 1 [+length.length] UInt:8[] data 30 | 31 | struct PackedFields: 32 | 0 [+1] Length length1 (l1) 33 | 0 [+l1.length+1] Data data1 (d1) 34 | let o1 = d1.$size_in_bytes 35 | o1 [+1] Length length2 (l2) 36 | o1 [+l2.length+1] Data data2 (d2) 37 | let o2 = o1 + d2.$size_in_bytes 38 | o2 [+1] Length length3 (l3) 39 | o2 [+l3.length+1] Data data3 (d3) 40 | let o3 = o2 + d3.$size_in_bytes 41 | o3 [+1] Length length4 (l4) 42 | o3 [+l4.length+1] Data data4 (d4) 43 | let o4 = o3 + d4.$size_in_bytes 44 | o4 [+1] Length length5 (l5) 45 | o4 [+l5.length+1] Data data5 (d5) 46 | let o5 = o4 + d5.$size_in_bytes 47 | o5 [+1] Length length6 (l6) 48 | o5 [+l6.length+1] Data data6 (d6) 49 | -------------------------------------------------------------------------------- /testdata/complex_structure.emb: -------------------------------------------------------------------------------- 1 | # Copyright 2019 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # https://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | -- Relatively complex structure intended for use in fuzz testing. 16 | -- 17 | -- Note that field names are intentionally very short; this helps American 18 | -- Fuzzy Lop (go/afl) find new code paths more quickly. 19 | 20 | [$default byte_order: "LittleEndian"] 21 | [(cpp) namespace: "emboss_test"] 22 | 23 | 24 | bits RegisterLayout: 25 | 0 [+8] Int x 26 | 0 [+4] UInt l 27 | 4 [+4] UInt h 28 | 29 | 30 | struct ArrayElement: 31 | 0 [+1] RegisterLayout a 32 | 33 | 34 | struct Complex: 35 | 0 [+1] UInt s 36 | 1 [+8] UInt u 37 | 1 [+8] Int i 38 | 1 [+8] Bcd b 39 | 1 [+s*4] ArrayElement[4][] a 40 | 1 [+1] bits: 41 | 0 [+8] UInt a0 42 | 7 [+1] Flag s0 43 | 0 [+4] Int l0 44 | 4 [+4] Int h0 45 | 46 | 2 [+1] ArrayElement e1 47 | if a0 >= 0x80: 48 | 3 [+1] ArrayElement e2 49 | 50 | if a0 < 0x80: 51 | 3 [+1] Bcd b2 52 | 53 | if b2 > 25: 54 | 4 [+1] Int e3 55 | 56 | if s >= 4 && (a0 >= 80 ? e3 >= 0x80 : b2 < 50): 57 | 5 [+1] Int e4 58 | 59 | if s >= 5 && e4 > 0: 60 | 6 [+1] Int e5 61 | 62 | if s < 2 || a0 < 4: 63 | 1 [+1] Int e0 64 | -------------------------------------------------------------------------------- /testdata/cpp_namespace.emb: -------------------------------------------------------------------------------- 1 | # Copyright 2019 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # https://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | -- Test .emb to ensure that the generated type ends up in the given namespace 16 | -- when the [(cpp) namespace] attribute is set to a valid value with no leading 17 | -- "::". 18 | 19 | [$default byte_order: "LittleEndian"] 20 | [(cpp) namespace: "emboss::test::no_leading_double_colon"] 21 | 22 | 23 | enum Foo: 24 | VALUE = 11 25 | -------------------------------------------------------------------------------- /testdata/enum_case.emb: -------------------------------------------------------------------------------- 1 | # Copyright 2023 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # https://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | [$default byte_order: "LittleEndian"] 16 | [(cpp) namespace: "emboss::test"] 17 | [(cpp) $default enum_case: "kCamelCase"] 18 | 19 | enum EnumShouty: 20 | [(cpp) $default enum_case: "SHOUTY_CASE"] 21 | FIRST = 0 22 | SECOND = 1 23 | TWO_WORD = 2 24 | THREE_WORD_ENUM = 4 25 | LONG_ENUM_VALUE_NAME = 8 26 | 27 | enum EnumDefault: 28 | FIRST = 0 29 | SECOND = 1 30 | TWO_WORD = 2 31 | THREE_WORD_ENUM = 4 32 | LONG_ENUM_VALUE_NAME = 8 33 | 34 | struct UseKCamelEnumCase: 35 | 0 [+4] EnumDefault v 36 | let first = EnumDefault.FIRST 37 | let v_is_first = v == EnumDefault.FIRST 38 | 39 | enum EnumShoutyAndKCamel: 40 | [(cpp) $default enum_case: "SHOUTY_CASE, kCamelCase"] 41 | FIRST = 0 42 | SECOND = 1 43 | TWO_WORD = 2 44 | THREE_WORD_ENUM = 4 45 | LONG_ENUM_VALUE_NAME = 8 46 | 47 | enum EnumMixed: 48 | -- Tests mixing various `enum_case` values in the same enum definition. 49 | FIRST = 0 [(cpp) enum_case: "SHOUTY_CASE, kCamelCase"] 50 | SECOND = 1 [(cpp) enum_case: "SHOUTY_CASE"] 51 | TWO_WORD = 2 52 | [(cpp) enum_case: "kCamelCase"] 53 | THREE_WORD_ENUM = 4 54 | [(cpp) enum_case: "kCamelCase, SHOUTY_CASE"] 55 | LONG_ENUM_VALUE_NAME = 8 56 | -------------------------------------------------------------------------------- /testdata/explicit_sizes.emb: -------------------------------------------------------------------------------- 1 | # Copyright 2019 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # https://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | -- Test structs for arrays of Ints, UInts, and enums. 16 | # TODO(bolms): Arrays of bit-level entities directly in structs. 17 | 18 | [$default byte_order: "LittleEndian"] 19 | [(cpp) namespace: "emboss::test"] 20 | 21 | 22 | bits SizedUIntArrays: 23 | 0 [+8] UInt:4[2] one_nibble 24 | 8 [+16] UInt:8[2] two_nibble 25 | 24 [+32] UInt:16[2] four_nibble 26 | 27 | 28 | bits SizedIntArrays: 29 | 0 [+8] Int:4[2] one_nibble 30 | 8 [+16] Int:8[2] two_nibble 31 | 24 [+32] Int:16[2] four_nibble 32 | 33 | 34 | bits SizedEnumArrays: 35 | 0 [+8] Enum:4[2] one_nibble 36 | 8 [+16] Enum:8[2] two_nibble 37 | 24 [+32] Enum:16[2] four_nibble 38 | 39 | 40 | struct BitArrayContainer: 41 | 0 [+7] SizedUIntArrays uint_arrays 42 | 43 | 44 | enum Enum: 45 | VALUE1 = 1 46 | VALUE10 = 10 47 | VALUE100 = 100 48 | VALUE1000 = 1000 49 | VALUE10000 = 10000 50 | VALUE100000 = 100000 51 | VALUE1000000 = 1000000 52 | VALUE10000000 = 10000000 53 | -------------------------------------------------------------------------------- /testdata/float.emb: -------------------------------------------------------------------------------- 1 | # Copyright 2019 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # https://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | -- Test struct for IEEE floats. 16 | 17 | [(cpp) namespace: "emboss::test"] 18 | 19 | 20 | struct Floats: 21 | 0 [+4] Float float_little_endian 22 | [byte_order: "LittleEndian"] 23 | 24 | 4 [+4] Float float_big_endian 25 | [byte_order: "BigEndian"] 26 | 27 | 28 | struct Doubles: 29 | 0 [+8] Float double_little_endian 30 | [byte_order: "LittleEndian"] 31 | 32 | 8 [+8] Float double_big_endian 33 | [byte_order: "BigEndian"] 34 | -------------------------------------------------------------------------------- /testdata/format/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright 2019 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # https://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | -------------------------------------------------------------------------------- /testdata/format/abbreviations.emb: -------------------------------------------------------------------------------- 1 | # Copyright 2019 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # https://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | -- Field abbreviations are treated as part of field names. 16 | 17 | struct Foo: 18 | 0 [+1] UInt abcdefghijklmnopqrstuv (a) 19 | 1 [+1] UInt short (s) 20 | -------------------------------------------------------------------------------- /testdata/format/abbreviations.emb.formatted: -------------------------------------------------------------------------------- 1 | # Copyright 2019 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # https://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | -- Field abbreviations are treated as part of field names. 16 | 17 | 18 | struct Foo: 19 | 0 [+1] UInt abcdefghijklmnopqrstuv (a) 20 | 1 [+1] UInt short (s) 21 | -------------------------------------------------------------------------------- /testdata/format/abbreviations.emb.formatted_indent_4: -------------------------------------------------------------------------------- 1 | # Copyright 2019 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # https://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | -- Field abbreviations are treated as part of field names. 16 | 17 | 18 | struct Foo: 19 | 0 [+1] UInt abcdefghijklmnopqrstuv (a) 20 | 1 [+1] UInt short (s) 21 | -------------------------------------------------------------------------------- /testdata/format/anonymous_bits_formatting.emb: -------------------------------------------------------------------------------- 1 | # Copyright 2019 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # https://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | -- Inline `bits` should be formatted as if their fields were part of the 16 | -- surrounding `struct`, except that their full locations should be indented one 17 | -- indentation level. 18 | -- 19 | -- Also, the `bits:` designator should be treated as part of the field size 20 | -- column on its line. 21 | struct Foo: 22 | 0 [+4] bits: 23 | 0 [+4] UInt offset 24 | 4 [+32] UInt reserved 25 | if offset 4?false : true : 20 | 10 [+10] UInt:8[] data2 21 | 22 | -------------------------------------------------------------------------------- /testdata/format/choice_expression.emb.formatted: -------------------------------------------------------------------------------- 1 | # Copyright 2019 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # https://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | -- The choice operator `?:` should be formatted with spaces between its 16 | -- components, but not after. 17 | 18 | 19 | struct Foo: 20 | 0 [+4] UInt data1 21 | if data1 > 4 ? false : true: 22 | 10 [+10] UInt:8[] data2 23 | -------------------------------------------------------------------------------- /testdata/format/choice_expression.emb.formatted_indent_4: -------------------------------------------------------------------------------- 1 | # Copyright 2019 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # https://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | -- The choice operator `?:` should be formatted with spaces between its 16 | -- components, but not after. 17 | 18 | 19 | struct Foo: 20 | 0 [+4] UInt data1 21 | if data1 > 4 ? false : true: 22 | 10 [+10] UInt:8[] data2 23 | -------------------------------------------------------------------------------- /testdata/format/comparison_expressions.emb: -------------------------------------------------------------------------------- 1 | # Copyright 2019 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # https://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | -- Comparison expressions should have one space around operators. 16 | struct Foo: 17 | if 0<0: 18 | 0 [+4] UInt a 19 | if 0 <= 0: 20 | 4 [+4] UInt b 21 | if 0>=0 >0==0: 22 | 0 [+4] UInt a 23 | if 0==0<0<=0== 0: 24 | 0 [+4] UInt a 25 | -------------------------------------------------------------------------------- /testdata/format/comparison_expressions.emb.formatted: -------------------------------------------------------------------------------- 1 | # Copyright 2019 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # https://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | -- Comparison expressions should have one space around operators. 16 | 17 | 18 | struct Foo: 19 | if 0 < 0: 20 | 0 [+4] UInt a 21 | 22 | if 0 <= 0: 23 | 4 [+4] UInt b 24 | 25 | if 0 >= 0 > 0 == 0: 26 | 0 [+4] UInt a 27 | 28 | if 0 == 0 < 0 <= 0 == 0: 29 | 0 [+4] UInt a 30 | -------------------------------------------------------------------------------- /testdata/format/comparison_expressions.emb.formatted_indent_4: -------------------------------------------------------------------------------- 1 | # Copyright 2019 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # https://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | -- Comparison expressions should have one space around operators. 16 | 17 | 18 | struct Foo: 19 | if 0 < 0: 20 | 0 [+4] UInt a 21 | 22 | if 0 <= 0: 23 | 4 [+4] UInt b 24 | 25 | if 0 >= 0 > 0 == 0: 26 | 0 [+4] UInt a 27 | 28 | if 0 == 0 < 0 <= 0 == 0: 29 | 0 [+4] UInt a 30 | -------------------------------------------------------------------------------- /testdata/format/conditional_field_formatting.emb: -------------------------------------------------------------------------------- 1 | # Copyright 2019 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # https://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | -- Conditional fields should be aligned with unconditional fields, except that 16 | -- their full locations should be indented one indentation level. 17 | struct Foo: 18 | 0 [+4] UInt data1 19 | if true: 20 | 10 [+10] UInt:8[] data2 21 | -------------------------------------------------------------------------------- /testdata/format/conditional_field_formatting.emb.formatted: -------------------------------------------------------------------------------- 1 | # Copyright 2019 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # https://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | -- Conditional fields should be aligned with unconditional fields, except that 16 | -- their full locations should be indented one indentation level. 17 | 18 | 19 | struct Foo: 20 | 0 [+4] UInt data1 21 | if true: 22 | 10 [+10] UInt:8[] data2 23 | -------------------------------------------------------------------------------- /testdata/format/conditional_field_formatting.emb.formatted_indent_4: -------------------------------------------------------------------------------- 1 | # Copyright 2019 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # https://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | -- Conditional fields should be aligned with unconditional fields, except that 16 | -- their full locations should be indented one indentation level. 17 | 18 | 19 | struct Foo: 20 | 0 [+4] UInt data1 21 | if true: 22 | 10 [+10] UInt:8[] data2 23 | -------------------------------------------------------------------------------- /testdata/format/conditional_inline_bits_formatting.emb: -------------------------------------------------------------------------------- 1 | # Copyright 2019 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # https://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | -- Conditional inline `bits` should be formatted as if their fields were part 16 | -- of the surrounding `struct`, except that their full locations should be 17 | -- indented two indentation levels. 18 | struct Foo: 19 | if true: 20 | 0 [+4] bits: 21 | 0 [+4] UInt offset 22 | 4 [+32] UInt reserved 23 | offset [+10] UInt:8[] data 24 | -------------------------------------------------------------------------------- /testdata/format/conditional_inline_bits_formatting.emb.formatted: -------------------------------------------------------------------------------- 1 | # Copyright 2019 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # https://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | -- Conditional inline `bits` should be formatted as if their fields were part 16 | -- of the surrounding `struct`, except that their full locations should be 17 | -- indented two indentation levels. 18 | 19 | 20 | struct Foo: 21 | if true: 22 | 0 [+4] bits: 23 | 0 [+4] UInt offset 24 | 4 [+32] UInt reserved 25 | 26 | offset [+10] UInt:8[] data 27 | -------------------------------------------------------------------------------- /testdata/format/conditional_inline_bits_formatting.emb.formatted_indent_4: -------------------------------------------------------------------------------- 1 | # Copyright 2019 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # https://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | -- Conditional inline `bits` should be formatted as if their fields were part 16 | -- of the surrounding `struct`, except that their full locations should be 17 | -- indented two indentation levels. 18 | 19 | 20 | struct Foo: 21 | if true: 22 | 0 [+4] bits: 23 | 0 [+4] UInt offset 24 | 4 [+32] UInt reserved 25 | 26 | offset [+10] UInt:8[] data 27 | -------------------------------------------------------------------------------- /testdata/format/dotted_names.emb: -------------------------------------------------------------------------------- 1 | # Copyright 2019 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # https://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | -- '.'-separated names are formatted with no spaces. 16 | 17 | import "foo.emb" as f 18 | 19 | enum Foo: 20 | FOUR = 4 21 | 22 | struct Bar: 23 | struct Baz: 24 | 0 [+4] UInt field 25 | 26 | struct Qux: 27 | 0 [+Foo . FOUR] Bar .Baz field 28 | field.field [+4] UInt thing 29 | if f. Bar .BAZ==f . Bar.BAZ: 30 | 0 [+4] f.Bar other 31 | -------------------------------------------------------------------------------- /testdata/format/dotted_names.emb.formatted: -------------------------------------------------------------------------------- 1 | # Copyright 2019 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # https://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | -- '.'-separated names are formatted with no spaces. 16 | 17 | import "foo.emb" as f 18 | 19 | 20 | enum Foo: 21 | FOUR = 4 22 | 23 | 24 | struct Bar: 25 | struct Baz: 26 | 0 [+4] UInt field 27 | 28 | 29 | struct Qux: 30 | 0 [+Foo.FOUR] Bar.Baz field 31 | field.field [+4] UInt thing 32 | if f.Bar.BAZ == f.Bar.BAZ: 33 | 0 [+4] f.Bar other 34 | -------------------------------------------------------------------------------- /testdata/format/dotted_names.emb.formatted_indent_4: -------------------------------------------------------------------------------- 1 | # Copyright 2019 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # https://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | -- '.'-separated names are formatted with no spaces. 16 | 17 | import "foo.emb" as f 18 | 19 | 20 | enum Foo: 21 | FOUR = 4 22 | 23 | 24 | struct Bar: 25 | struct Baz: 26 | 0 [+4] UInt field 27 | 28 | 29 | struct Qux: 30 | 0 [+Foo.FOUR] Bar.Baz field 31 | field.field [+4] UInt thing 32 | if f.Bar.BAZ == f.Bar.BAZ: 33 | 0 [+4] f.Bar other 34 | -------------------------------------------------------------------------------- /testdata/format/empty.emb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/google/emboss/3e621d71b78968d1f14760c4ac92b473f7278772/testdata/format/empty.emb -------------------------------------------------------------------------------- /testdata/format/empty.emb.formatted: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/google/emboss/3e621d71b78968d1f14760c4ac92b473f7278772/testdata/format/empty.emb.formatted -------------------------------------------------------------------------------- /testdata/format/empty.emb.formatted_indent_4: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/google/emboss/3e621d71b78968d1f14760c4ac92b473f7278772/testdata/format/empty.emb.formatted_indent_4 -------------------------------------------------------------------------------- /testdata/format/enum_value_attributes.emb: -------------------------------------------------------------------------------- 1 | # Copyright 2023 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # https://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | -- Attributes on `enum` values should be properly indented and spaced. 16 | 17 | enum Foo: 18 | BAR = 0 [attribute: true] -- Bar doc 1. 19 | -- Bar doc 2. 20 | BAZ = 1 [attribute: false] 21 | -- Baz doc. 22 | [different: "test"] 23 | -------------------------------------------------------------------------------- /testdata/format/enum_value_attributes.emb.formatted: -------------------------------------------------------------------------------- 1 | # Copyright 2023 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # https://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | -- Attributes on `enum` values should be properly indented and spaced. 16 | 17 | 18 | enum Foo: 19 | BAR = 0 [attribute: true] -- Bar doc 1. 20 | -- Bar doc 2. 21 | 22 | BAZ = 1 [attribute: false] 23 | -- Baz doc. 24 | [different: "test"] 25 | -------------------------------------------------------------------------------- /testdata/format/enum_value_attributes.emb.formatted_indent_4: -------------------------------------------------------------------------------- 1 | # Copyright 2023 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # https://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | -- Attributes on `enum` values should be properly indented and spaced. 16 | 17 | 18 | enum Foo: 19 | BAR = 0 [attribute: true] -- Bar doc 1. 20 | -- Bar doc 2. 21 | 22 | BAZ = 1 [attribute: false] 23 | -- Baz doc. 24 | [different: "test"] 25 | -------------------------------------------------------------------------------- /testdata/format/enum_value_bodies.emb: -------------------------------------------------------------------------------- 1 | # Copyright 2019 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # https://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | -- Documentation on `enum` values should be properly indented. 16 | 17 | enum Foo: 18 | BAR = 0 19 | -- Bar is a bar. 20 | BAZ = 1 21 | -- Baz requires more documentation. 22 | -- Baz requires more documentation. 23 | -- Baz requires more documentation. 24 | -- Baz requires more documentation. 25 | -- Baz requires more documentation. 26 | -------------------------------------------------------------------------------- /testdata/format/enum_value_bodies.emb.formatted: -------------------------------------------------------------------------------- 1 | # Copyright 2019 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # https://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | -- Documentation on `enum` values should be properly indented. 16 | 17 | 18 | enum Foo: 19 | BAR = 0 20 | -- Bar is a bar. 21 | 22 | BAZ = 1 23 | -- Baz requires more documentation. 24 | -- Baz requires more documentation. 25 | -- Baz requires more documentation. 26 | -- Baz requires more documentation. 27 | -- Baz requires more documentation. 28 | -------------------------------------------------------------------------------- /testdata/format/enum_value_bodies.emb.formatted_indent_4: -------------------------------------------------------------------------------- 1 | # Copyright 2019 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # https://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | -- Documentation on `enum` values should be properly indented. 16 | 17 | 18 | enum Foo: 19 | BAR = 0 20 | -- Bar is a bar. 21 | 22 | BAZ = 1 23 | -- Baz requires more documentation. 24 | -- Baz requires more documentation. 25 | -- Baz requires more documentation. 26 | -- Baz requires more documentation. 27 | -- Baz requires more documentation. 28 | -------------------------------------------------------------------------------- /testdata/format/enum_values_aligned.emb: -------------------------------------------------------------------------------- 1 | # Copyright 2019 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # https://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | enum Foo: 16 | SHORT = 1 17 | MEDIUM = 2 18 | SOMEWHAT_LONG = 30 19 | VERY_VERY_VERY_VERY_VERY_VERY_VERY_VERY_VERY_LONG = 1_000_000_000_000_000 20 | -------------------------------------------------------------------------------- /testdata/format/enum_values_aligned.emb.formatted: -------------------------------------------------------------------------------- 1 | # Copyright 2019 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # https://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | 16 | enum Foo: 17 | SHORT = 1 18 | MEDIUM = 2 19 | SOMEWHAT_LONG = 30 20 | VERY_VERY_VERY_VERY_VERY_VERY_VERY_VERY_VERY_LONG = 1_000_000_000_000_000 21 | -------------------------------------------------------------------------------- /testdata/format/enum_values_aligned.emb.formatted_indent_4: -------------------------------------------------------------------------------- 1 | # Copyright 2019 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # https://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | 16 | enum Foo: 17 | SHORT = 1 18 | MEDIUM = 2 19 | SOMEWHAT_LONG = 30 20 | VERY_VERY_VERY_VERY_VERY_VERY_VERY_VERY_VERY_LONG = 1_000_000_000_000_000 21 | -------------------------------------------------------------------------------- /testdata/format/equality_expressions.emb: -------------------------------------------------------------------------------- 1 | # Copyright 2019 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # https://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | -- Equality expressions should have one space around operators. 16 | struct Foo: 17 | if 0==0: 18 | 0 [+4] UInt a 19 | if 0 != 0: 20 | 4 [+4] UInt b 21 | if 0==0 ==0: 22 | 0 [+4] UInt a 23 | if 0!=0: 24 | 0 [+4] UInt a 25 | -------------------------------------------------------------------------------- /testdata/format/equality_expressions.emb.formatted: -------------------------------------------------------------------------------- 1 | # Copyright 2019 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # https://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | -- Equality expressions should have one space around operators. 16 | 17 | 18 | struct Foo: 19 | if 0 == 0: 20 | 0 [+4] UInt a 21 | 22 | if 0 != 0: 23 | 4 [+4] UInt b 24 | 25 | if 0 == 0 == 0: 26 | 0 [+4] UInt a 27 | 28 | if 0 != 0: 29 | 0 [+4] UInt a 30 | -------------------------------------------------------------------------------- /testdata/format/equality_expressions.emb.formatted_indent_4: -------------------------------------------------------------------------------- 1 | # Copyright 2019 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # https://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | -- Equality expressions should have one space around operators. 16 | 17 | 18 | struct Foo: 19 | if 0 == 0: 20 | 0 [+4] UInt a 21 | 22 | if 0 != 0: 23 | 4 [+4] UInt b 24 | 25 | if 0 == 0 == 0: 26 | 0 [+4] UInt a 27 | 28 | if 0 != 0: 29 | 0 [+4] UInt a 30 | -------------------------------------------------------------------------------- /testdata/format/external.emb: -------------------------------------------------------------------------------- 1 | # Copyright 2019 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # https://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | -- Externals get minimal formatting. 16 | 17 | external Foo: 18 | -- documentation 19 | [requires: $is_statically_sized && 1 <= $static_size_in_bits <= 64] 20 | [is_integer: true] 21 | [addressable_unit_size: 1] 22 | -------------------------------------------------------------------------------- /testdata/format/external.emb.formatted: -------------------------------------------------------------------------------- 1 | # Copyright 2019 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # https://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | -- Externals get minimal formatting. 16 | 17 | 18 | external Foo: 19 | -- documentation 20 | 21 | [requires: $is_statically_sized && 1 <= $static_size_in_bits <= 64] 22 | [is_integer: true] 23 | [addressable_unit_size: 1] 24 | -------------------------------------------------------------------------------- /testdata/format/external.emb.formatted_indent_4: -------------------------------------------------------------------------------- 1 | # Copyright 2019 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # https://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | -- Externals get minimal formatting. 16 | 17 | 18 | external Foo: 19 | -- documentation 20 | 21 | [requires: $is_statically_sized && 1 <= $static_size_in_bits <= 64] 22 | [is_integer: true] 23 | [addressable_unit_size: 1] 24 | -------------------------------------------------------------------------------- /testdata/format/extra_newlines.emb: -------------------------------------------------------------------------------- 1 | # Copyright 2019 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # https://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | -- Leading and trailing newlines should be stripped. 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | -------------------------------------------------------------------------------- /testdata/format/extra_newlines.emb.formatted: -------------------------------------------------------------------------------- 1 | # Copyright 2019 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # https://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | -- Leading and trailing newlines should be stripped. 16 | -------------------------------------------------------------------------------- /testdata/format/extra_newlines.emb.formatted_indent_4: -------------------------------------------------------------------------------- 1 | # Copyright 2019 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # https://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | -- Leading and trailing newlines should be stripped. 16 | -------------------------------------------------------------------------------- /testdata/format/fields_aligned.emb: -------------------------------------------------------------------------------- 1 | # Copyright 2019 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # https://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | struct Foo: 16 | # Field columns should be aligned, with one space betwen start and size, and 17 | # two spaces between other columns. 18 | 0 [+1] UInt short 19 | 10 [+1] UInt:8 medium 20 | 1_000_000 [+8] UInt:64 long 21 | $next [+2] UInt packed 22 | -------------------------------------------------------------------------------- /testdata/format/fields_aligned.emb.formatted: -------------------------------------------------------------------------------- 1 | # Copyright 2019 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # https://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | 16 | struct Foo: 17 | # Field columns should be aligned, with one space betwen start and size, and 18 | # two spaces between other columns. 19 | 0 [+1] UInt short 20 | 10 [+1] UInt:8 medium 21 | 1_000_000 [+8] UInt:64 long 22 | $next [+2] UInt packed 23 | -------------------------------------------------------------------------------- /testdata/format/fields_aligned.emb.formatted_indent_4: -------------------------------------------------------------------------------- 1 | # Copyright 2019 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # https://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | 16 | struct Foo: 17 | # Field columns should be aligned, with one space betwen start and size, and 18 | # two spaces between other columns. 19 | 0 [+1] UInt short 20 | 10 [+1] UInt:8 medium 21 | 1_000_000 [+8] UInt:64 long 22 | $next [+2] UInt packed 23 | -------------------------------------------------------------------------------- /testdata/format/functions.emb: -------------------------------------------------------------------------------- 1 | # Copyright 2019 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # https://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | -- Functions should be formatted like `$func(arg)`, `$func(arg, arg, arg)`, or 16 | -- `$func()`. 17 | 18 | struct Foo: 19 | $max ( ) [+1] UInt foo 20 | if $present (foo ) : 21 | $max ( 1 ) [ + 3 ] UInt bar 22 | $max ( 1 , 2 ) [ + 3 ] UInt baz 23 | $max ( 1 , 2,3,4,5,6 ) [ + 3 ] UInt qux 24 | $upper_bound(foo ) [+1] UInt quux 25 | $lower_bound(quux ) [ +1 ] UInt quuux 26 | -------------------------------------------------------------------------------- /testdata/format/functions.emb.formatted: -------------------------------------------------------------------------------- 1 | # Copyright 2019 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # https://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | -- Functions should be formatted like `$func(arg)`, `$func(arg, arg, arg)`, or 16 | -- `$func()`. 17 | 18 | 19 | struct Foo: 20 | $max() [+1] UInt foo 21 | if $present(foo): 22 | $max(1) [+3] UInt bar 23 | 24 | $max(1, 2) [+3] UInt baz 25 | $max(1, 2, 3, 4, 5, 6) [+3] UInt qux 26 | $upper_bound(foo) [+1] UInt quux 27 | $lower_bound(quux) [+1] UInt quuux 28 | -------------------------------------------------------------------------------- /testdata/format/functions.emb.formatted_indent_4: -------------------------------------------------------------------------------- 1 | # Copyright 2019 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # https://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | -- Functions should be formatted like `$func(arg)`, `$func(arg, arg, arg)`, or 16 | -- `$func()`. 17 | 18 | 19 | struct Foo: 20 | $max() [+1] UInt foo 21 | if $present(foo): 22 | $max(1) [+3] UInt bar 23 | 24 | $max(1, 2) [+3] UInt baz 25 | $max(1, 2, 3, 4, 5, 6) [+3] UInt qux 26 | $upper_bound(foo) [+1] UInt quux 27 | $lower_bound(quux) [+1] UInt quuux 28 | -------------------------------------------------------------------------------- /testdata/format/header_and_type.emb: -------------------------------------------------------------------------------- 1 | # Copyright 2019 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # https://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | -- Header lines should be separated from type definitions by two blank lines. 16 | struct Foo: 17 | 0 [+1] UInt bar 18 | -------------------------------------------------------------------------------- /testdata/format/header_and_type.emb.formatted: -------------------------------------------------------------------------------- 1 | # Copyright 2019 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # https://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | -- Header lines should be separated from type definitions by two blank lines. 16 | 17 | 18 | struct Foo: 19 | 0 [+1] UInt bar 20 | -------------------------------------------------------------------------------- /testdata/format/header_and_type.emb.formatted_indent_4: -------------------------------------------------------------------------------- 1 | # Copyright 2019 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # https://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | -- Header lines should be separated from type definitions by two blank lines. 16 | 17 | 18 | struct Foo: 19 | 0 [+1] UInt bar 20 | -------------------------------------------------------------------------------- /testdata/format/indent.emb: -------------------------------------------------------------------------------- 1 | # Copyright 2019 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # https://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | # All indentation should be set to 2 spaces. 16 | struct Foo: 17 | 0 [+1] bits: 18 | 0 [+1] UInt x 19 | 10 [+1] UInt:8 medium 20 | 21 | enum Bar: 22 | VAL = 1 23 | VV = 2 24 | -------------------------------------------------------------------------------- /testdata/format/indent.emb.formatted: -------------------------------------------------------------------------------- 1 | # Copyright 2019 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # https://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | # All indentation should be set to 2 spaces. 16 | 17 | 18 | struct Foo: 19 | 0 [+1] bits: 20 | 0 [+1] UInt x 21 | 22 | 10 [+1] UInt:8 medium 23 | 24 | 25 | enum Bar: 26 | VAL = 1 27 | VV = 2 28 | -------------------------------------------------------------------------------- /testdata/format/indent.emb.formatted_indent_4: -------------------------------------------------------------------------------- 1 | # Copyright 2019 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # https://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | # All indentation should be set to 2 spaces. 16 | 17 | 18 | struct Foo: 19 | 0 [+1] bits: 20 | 0 [+1] UInt x 21 | 22 | 10 [+1] UInt:8 medium 23 | 24 | 25 | enum Bar: 26 | VAL = 1 27 | VV = 2 28 | -------------------------------------------------------------------------------- /testdata/format/inline_attributes_get_a_column.emb: -------------------------------------------------------------------------------- 1 | # Copyright 2019 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # https://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | -- Inline attributes on fields are aligned in a column. 16 | bits Foo: 17 | 0 [+4] UInt a [requires: 0 <= this <= 10] 18 | 4 [+4] UInt bc [requires: 0 <= this <= 4] [byte_order: "LittleEndian"] 19 | 8 [+4] UInt def [requires: 1000 <= this <= 1020] 20 | 8 [+4] UInt ghij [requires: 10 <= this <= 10] 21 | -------------------------------------------------------------------------------- /testdata/format/inline_attributes_get_a_column.emb.formatted: -------------------------------------------------------------------------------- 1 | # Copyright 2019 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # https://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | -- Inline attributes on fields are aligned in a column. 16 | 17 | 18 | bits Foo: 19 | 0 [+4] UInt a [requires: 0 <= this <= 10] 20 | 4 [+4] UInt bc [requires: 0 <= this <= 4] [byte_order: "LittleEndian"] 21 | 8 [+4] UInt def [requires: 1000 <= this <= 1020] 22 | 8 [+4] UInt ghij [requires: 10 <= this <= 10] 23 | -------------------------------------------------------------------------------- /testdata/format/inline_attributes_get_a_column.emb.formatted_indent_4: -------------------------------------------------------------------------------- 1 | # Copyright 2019 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # https://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | -- Inline attributes on fields are aligned in a column. 16 | 17 | 18 | bits Foo: 19 | 0 [+4] UInt a [requires: 0 <= this <= 10] 20 | 4 [+4] UInt bc [requires: 0 <= this <= 4] [byte_order: "LittleEndian"] 21 | 8 [+4] UInt def [requires: 1000 <= this <= 1020] 22 | 8 [+4] UInt ghij [requires: 10 <= this <= 10] 23 | -------------------------------------------------------------------------------- /testdata/format/inline_bits.emb: -------------------------------------------------------------------------------- 1 | # Copyright 2019 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # https://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | -- Inline bits are columnized separately from their surrounding structure. 16 | 17 | bits Foo: 18 | 0 [+5] bits bler: 19 | 0[+1] Flag xxx # comment 20 | 1 [+1]Flag yy 21 | 2 [+1] Flag zzzzzzzzzzz 22 | 10 [+6] UInt length 23 | 16 [+16] UInt width 24 | if width == 1000: 25 | 32 [+10] UInt depth # comment 26 | 42 [+6] UInt checksum # other comment 27 | 28 | struct Foo2: 29 | 8 [+4] UInt length # comment 30 | 12 [+4] UInt width # comment 31 | 0 [+5] bits bler: 32 | 0[+1] Flag xxx # comment 33 | 1 [+1]Flag yy 34 | 2 [+1] Flag zzzzzzzzzzz 35 | -------------------------------------------------------------------------------- /testdata/format/inline_bits.emb.formatted: -------------------------------------------------------------------------------- 1 | # Copyright 2019 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # https://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | -- Inline bits are columnized separately from their surrounding structure. 16 | 17 | 18 | bits Foo: 19 | 0 [+5] bits bler: 20 | 0 [+1] Flag xxx # comment 21 | 1 [+1] Flag yy 22 | 2 [+1] Flag zzzzzzzzzzz 23 | 24 | 10 [+6] UInt length 25 | 16 [+16] UInt width 26 | if width == 1000: 27 | 32 [+10] UInt depth # comment 28 | 42 [+6] UInt checksum # other comment 29 | 30 | 31 | struct Foo2: 32 | 8 [+4] UInt length # comment 33 | 12 [+4] UInt width # comment 34 | 0 [+5] bits bler: 35 | 0 [+1] Flag xxx # comment 36 | 1 [+1] Flag yy 37 | 2 [+1] Flag zzzzzzzzzzz 38 | -------------------------------------------------------------------------------- /testdata/format/inline_bits.emb.formatted_indent_4: -------------------------------------------------------------------------------- 1 | # Copyright 2019 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # https://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | -- Inline bits are columnized separately from their surrounding structure. 16 | 17 | 18 | bits Foo: 19 | 0 [+5] bits bler: 20 | 0 [+1] Flag xxx # comment 21 | 1 [+1] Flag yy 22 | 2 [+1] Flag zzzzzzzzzzz 23 | 24 | 10 [+6] UInt length 25 | 16 [+16] UInt width 26 | if width == 1000: 27 | 32 [+10] UInt depth # comment 28 | 42 [+6] UInt checksum # other comment 29 | 30 | 31 | struct Foo2: 32 | 8 [+4] UInt length # comment 33 | 12 [+4] UInt width # comment 34 | 0 [+5] bits bler: 35 | 0 [+1] Flag xxx # comment 36 | 1 [+1] Flag yy 37 | 2 [+1] Flag zzzzzzzzzzz 38 | -------------------------------------------------------------------------------- /testdata/format/inline_documentation_gets_a_column.emb: -------------------------------------------------------------------------------- 1 | # Copyright 2019 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # https://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | -- Inline documentation on fields is aligned in a column. 16 | bits Foo: 17 | 0 [+4] UInt a -- a 18 | 4 [+4] UInt bc -- bc 19 | 8 [+4] UInt def -- def 20 | 8 [+4] UInt ghij -- ghi 21 | 22 | -------------------------------------------------------------------------------- /testdata/format/inline_documentation_gets_a_column.emb.formatted: -------------------------------------------------------------------------------- 1 | # Copyright 2019 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # https://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | -- Inline documentation on fields is aligned in a column. 16 | 17 | 18 | bits Foo: 19 | 0 [+4] UInt a -- a 20 | 4 [+4] UInt bc -- bc 21 | 8 [+4] UInt def -- def 22 | 8 [+4] UInt ghij -- ghi 23 | -------------------------------------------------------------------------------- /testdata/format/inline_documentation_gets_a_column.emb.formatted_indent_4: -------------------------------------------------------------------------------- 1 | # Copyright 2019 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # https://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | -- Inline documentation on fields is aligned in a column. 16 | 17 | 18 | bits Foo: 19 | 0 [+4] UInt a -- a 20 | 4 [+4] UInt bc -- bc 21 | 8 [+4] UInt def -- def 22 | 8 [+4] UInt ghij -- ghi 23 | -------------------------------------------------------------------------------- /testdata/format/inline_enum.emb: -------------------------------------------------------------------------------- 1 | # Copyright 2019 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # https://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | -- Inline enums are columnized separately from their surrounding structure. 16 | 17 | bits Foo: 18 | 0 [+5] enum bler: 19 | XXX = 0 # comment 20 | YY = 1 21 | ZZZZZZZZZZZ = 2 22 | 10 [+6] UInt length 23 | 16 [+16] UInt width 24 | if width == 1000: 25 | 32 [+10] UInt depth # comment 26 | 42 [+6] UInt checksum # other comment 27 | 28 | struct Foo2: 29 | 8 [+4] UInt length # comment 30 | 12 [+4] UInt width # comment 31 | 0 [+5] enum bler: 32 | XXX = 0 # comment 33 | YY = 1 34 | ZZZZZZZZZZZ = 2 35 | -------------------------------------------------------------------------------- /testdata/format/inline_enum.emb.formatted: -------------------------------------------------------------------------------- 1 | # Copyright 2019 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # https://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | -- Inline enums are columnized separately from their surrounding structure. 16 | 17 | 18 | bits Foo: 19 | 0 [+5] enum bler: 20 | XXX = 0 # comment 21 | YY = 1 22 | ZZZZZZZZZZZ = 2 23 | 24 | 10 [+6] UInt length 25 | 16 [+16] UInt width 26 | if width == 1000: 27 | 32 [+10] UInt depth # comment 28 | 42 [+6] UInt checksum # other comment 29 | 30 | 31 | struct Foo2: 32 | 8 [+4] UInt length # comment 33 | 12 [+4] UInt width # comment 34 | 0 [+5] enum bler: 35 | XXX = 0 # comment 36 | YY = 1 37 | ZZZZZZZZZZZ = 2 38 | -------------------------------------------------------------------------------- /testdata/format/inline_enum.emb.formatted_indent_4: -------------------------------------------------------------------------------- 1 | # Copyright 2019 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # https://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | -- Inline enums are columnized separately from their surrounding structure. 16 | 17 | 18 | bits Foo: 19 | 0 [+5] enum bler: 20 | XXX = 0 # comment 21 | YY = 1 22 | ZZZZZZZZZZZ = 2 23 | 24 | 10 [+6] UInt length 25 | 16 [+16] UInt width 26 | if width == 1000: 27 | 32 [+10] UInt depth # comment 28 | 42 [+6] UInt checksum # other comment 29 | 30 | 31 | struct Foo2: 32 | 8 [+4] UInt length # comment 33 | 12 [+4] UInt width # comment 34 | 0 [+5] enum bler: 35 | XXX = 0 # comment 36 | YY = 1 37 | ZZZZZZZZZZZ = 2 38 | -------------------------------------------------------------------------------- /testdata/format/inline_struct.emb: -------------------------------------------------------------------------------- 1 | # Copyright 2019 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # https://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | -- Inline structs are columnized separately from their surrounding structure. 16 | 17 | struct Foo2: 18 | 8 [+4] UInt length # comment 19 | 0 [+5] struct bler: 20 | 0[+1] UInt xxx # comment 21 | 1 [+1]UInt yy 22 | 2 [+ 1] UInt zzzzzzzzzzz 23 | 12 [+4] UInt width # comment 24 | -------------------------------------------------------------------------------- /testdata/format/inline_struct.emb.formatted: -------------------------------------------------------------------------------- 1 | # Copyright 2019 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # https://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | -- Inline structs are columnized separately from their surrounding structure. 16 | 17 | 18 | struct Foo2: 19 | 8 [+4] UInt length # comment 20 | 21 | 0 [+5] struct bler: 22 | 0 [+1] UInt xxx # comment 23 | 1 [+1] UInt yy 24 | 2 [+1] UInt zzzzzzzzzzz 25 | 26 | 12 [+4] UInt width # comment 27 | -------------------------------------------------------------------------------- /testdata/format/inline_struct.emb.formatted_indent_4: -------------------------------------------------------------------------------- 1 | # Copyright 2019 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # https://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | -- Inline structs are columnized separately from their surrounding structure. 16 | 17 | 18 | struct Foo2: 19 | 8 [+4] UInt length # comment 20 | 21 | 0 [+5] struct bler: 22 | 0 [+1] UInt xxx # comment 23 | 1 [+1] UInt yy 24 | 2 [+1] UInt zzzzzzzzzzz 25 | 26 | 12 [+4] UInt width # comment 27 | -------------------------------------------------------------------------------- /testdata/format/lines_not_spaced_out_with_excess_trailing_noise_lines.emb: -------------------------------------------------------------------------------- 1 | # Copyright 2019 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # https://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | -- If there are fewer noise lines than primary lines in a block, *not counting 16 | -- trailing noise lines*, then extra newlines should not be inserted between 17 | -- other elements of the block. 18 | struct Foo: 19 | 0 [+4] UInt a 20 | 4 [+4] UInt b 21 | -- some doc 22 | -- some doc 23 | 8 [+4] UInt c 24 | -- some doc 25 | -- some doc 26 | -- some doc 27 | -- some doc 28 | -- some doc 29 | -- some doc 30 | -------------------------------------------------------------------------------- /testdata/format/lines_not_spaced_out_with_excess_trailing_noise_lines.emb.formatted: -------------------------------------------------------------------------------- 1 | # Copyright 2019 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # https://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | -- If there are fewer noise lines than primary lines in a block, *not counting 16 | -- trailing noise lines*, then extra newlines should not be inserted between 17 | -- other elements of the block. 18 | 19 | 20 | struct Foo: 21 | 0 [+4] UInt a 22 | 4 [+4] UInt b 23 | -- some doc 24 | -- some doc 25 | 26 | 8 [+4] UInt c 27 | -- some doc 28 | -- some doc 29 | -- some doc 30 | -- some doc 31 | -- some doc 32 | -- some doc 33 | -------------------------------------------------------------------------------- /testdata/format/lines_not_spaced_out_with_excess_trailing_noise_lines.emb.formatted_indent_4: -------------------------------------------------------------------------------- 1 | # Copyright 2019 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # https://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | -- If there are fewer noise lines than primary lines in a block, *not counting 16 | -- trailing noise lines*, then extra newlines should not be inserted between 17 | -- other elements of the block. 18 | 19 | 20 | struct Foo: 21 | 0 [+4] UInt a 22 | 4 [+4] UInt b 23 | -- some doc 24 | -- some doc 25 | 26 | 8 [+4] UInt c 27 | -- some doc 28 | -- some doc 29 | -- some doc 30 | -- some doc 31 | -- some doc 32 | -- some doc 33 | -------------------------------------------------------------------------------- /testdata/format/lines_not_spaced_out_with_not_enough_noise_lines.emb: -------------------------------------------------------------------------------- 1 | # Copyright 2019 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # https://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | -- If there are fewer noise lines than primary lines in a block, then extra 16 | -- newlines should not be inserted between other elements of the block. 17 | struct Foo: 18 | 0 [+4] UInt a 19 | 4 [+4] UInt b 20 | -- some doc 21 | -- some doc 22 | 8 [+4] UInt c 23 | -------------------------------------------------------------------------------- /testdata/format/lines_not_spaced_out_with_not_enough_noise_lines.emb.formatted: -------------------------------------------------------------------------------- 1 | # Copyright 2019 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # https://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | -- If there are fewer noise lines than primary lines in a block, then extra 16 | -- newlines should not be inserted between other elements of the block. 17 | 18 | 19 | struct Foo: 20 | 0 [+4] UInt a 21 | 4 [+4] UInt b 22 | -- some doc 23 | -- some doc 24 | 25 | 8 [+4] UInt c 26 | -------------------------------------------------------------------------------- /testdata/format/lines_not_spaced_out_with_not_enough_noise_lines.emb.formatted_indent_4: -------------------------------------------------------------------------------- 1 | # Copyright 2019 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # https://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | -- If there are fewer noise lines than primary lines in a block, then extra 16 | -- newlines should not be inserted between other elements of the block. 17 | 18 | 19 | struct Foo: 20 | 0 [+4] UInt a 21 | 4 [+4] UInt b 22 | -- some doc 23 | -- some doc 24 | 25 | 8 [+4] UInt c 26 | -------------------------------------------------------------------------------- /testdata/format/lines_spaced_out_with_noise_lines.emb: -------------------------------------------------------------------------------- 1 | # Copyright 2019 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # https://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | -- If there are more non-primary lines than primary lines inside of a block, 16 | -- then all elements in the block should have blank lines between them. 17 | struct Foo: 18 | 0 [+4] UInt a 19 | 4 [+4] UInt b 20 | -- some doc 21 | -- some doc 22 | -- some doc 23 | -- some doc 24 | 8 [+4] UInt c 25 | -------------------------------------------------------------------------------- /testdata/format/lines_spaced_out_with_noise_lines.emb.formatted: -------------------------------------------------------------------------------- 1 | # Copyright 2019 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # https://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | -- If there are more non-primary lines than primary lines inside of a block, 16 | -- then all elements in the block should have blank lines between them. 17 | 18 | 19 | struct Foo: 20 | 0 [+4] UInt a 21 | 22 | 4 [+4] UInt b 23 | -- some doc 24 | -- some doc 25 | -- some doc 26 | -- some doc 27 | 28 | 8 [+4] UInt c 29 | -------------------------------------------------------------------------------- /testdata/format/lines_spaced_out_with_noise_lines.emb.formatted_indent_4: -------------------------------------------------------------------------------- 1 | # Copyright 2019 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # https://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | -- If there are more non-primary lines than primary lines inside of a block, 16 | -- then all elements in the block should have blank lines between them. 17 | 18 | 19 | struct Foo: 20 | 0 [+4] UInt a 21 | 22 | 4 [+4] UInt b 23 | -- some doc 24 | -- some doc 25 | -- some doc 26 | -- some doc 27 | 28 | 8 [+4] UInt c 29 | -------------------------------------------------------------------------------- /testdata/format/logical_expressions.emb: -------------------------------------------------------------------------------- 1 | # Copyright 2019 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # https://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | -- Equality expressions should have one space around operators. 16 | struct Foo: 17 | if true&&false: 18 | 0 [+4] UInt a 19 | if false || true: 20 | 4 [+4] UInt b 21 | if true||false ||true: 22 | 0 [+4] UInt a 23 | if false&&true &&false: 24 | 0 [+4] UInt a 25 | if (false&&true) ||false: 26 | 0 [+4] UInt a 27 | -------------------------------------------------------------------------------- /testdata/format/logical_expressions.emb.formatted: -------------------------------------------------------------------------------- 1 | # Copyright 2019 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # https://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | -- Equality expressions should have one space around operators. 16 | 17 | 18 | struct Foo: 19 | if true && false: 20 | 0 [+4] UInt a 21 | 22 | if false || true: 23 | 4 [+4] UInt b 24 | 25 | if true || false || true: 26 | 0 [+4] UInt a 27 | 28 | if false && true && false: 29 | 0 [+4] UInt a 30 | 31 | if (false && true) || false: 32 | 0 [+4] UInt a 33 | -------------------------------------------------------------------------------- /testdata/format/logical_expressions.emb.formatted_indent_4: -------------------------------------------------------------------------------- 1 | # Copyright 2019 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # https://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | -- Equality expressions should have one space around operators. 16 | 17 | 18 | struct Foo: 19 | if true && false: 20 | 0 [+4] UInt a 21 | 22 | if false || true: 23 | 4 [+4] UInt b 24 | 25 | if true || false || true: 26 | 0 [+4] UInt a 27 | 28 | if false && true && false: 29 | 0 [+4] UInt a 30 | 31 | if (false && true) || false: 32 | 0 [+4] UInt a 33 | -------------------------------------------------------------------------------- /testdata/format/multiline_ifs.emb: -------------------------------------------------------------------------------- 1 | # Copyright 2019 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # https://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | -- Multiline ifs should have their bodies properly indented. 16 | struct Foo: 17 | if 0==0: 18 | 0 [+4] UInt a 19 | 4 [+4] UInt b 20 | -------------------------------------------------------------------------------- /testdata/format/multiline_ifs.emb.formatted: -------------------------------------------------------------------------------- 1 | # Copyright 2019 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # https://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | -- Multiline ifs should have their bodies properly indented. 16 | 17 | 18 | struct Foo: 19 | if 0 == 0: 20 | 0 [+4] UInt a 21 | 4 [+4] UInt b 22 | -------------------------------------------------------------------------------- /testdata/format/multiline_ifs.emb.formatted_indent_4: -------------------------------------------------------------------------------- 1 | # Copyright 2019 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # https://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | -- Multiline ifs should have their bodies properly indented. 16 | 17 | 18 | struct Foo: 19 | if 0 == 0: 20 | 0 [+4] UInt a 21 | 4 [+4] UInt b 22 | -------------------------------------------------------------------------------- /testdata/format/multiple_header_sections.emb: -------------------------------------------------------------------------------- 1 | # Copyright 2019 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # https://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | # .Emb with multiple header sections. First, a comment. 16 | -- Some documentation. 17 | import "foo" as bar # An import 18 | [$default byte_order: "LittleEndian"] # An attribute. 19 | -------------------------------------------------------------------------------- /testdata/format/multiple_header_sections.emb.formatted: -------------------------------------------------------------------------------- 1 | # Copyright 2019 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # https://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | # .Emb with multiple header sections. First, a comment. 16 | 17 | -- Some documentation. 18 | 19 | import "foo" as bar # An import 20 | 21 | [$default byte_order: "LittleEndian"] # An attribute. 22 | -------------------------------------------------------------------------------- /testdata/format/multiple_header_sections.emb.formatted_indent_4: -------------------------------------------------------------------------------- 1 | # Copyright 2019 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # https://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | # .Emb with multiple header sections. First, a comment. 16 | 17 | -- Some documentation. 18 | 19 | import "foo" as bar # An import 20 | 21 | [$default byte_order: "LittleEndian"] # An attribute. 22 | -------------------------------------------------------------------------------- /testdata/format/nested_types_are_columnized_independently.emb: -------------------------------------------------------------------------------- 1 | # Copyright 2019 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # https://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | -- Nested types are columnized independently of each other and of the 16 | -- surrounding type. 17 | struct Foo: 18 | struct Bar: 19 | 0 [+4] UInt very_very_long 20 | very_very_long [+4] UInt v 21 | struct Baz: 22 | 0 [+4] UInt:32 long 23 | 4 [+long] UInt:8[long] data 24 | 0 [+4] UInt field 25 | -------------------------------------------------------------------------------- /testdata/format/nested_types_are_columnized_independently.emb.formatted: -------------------------------------------------------------------------------- 1 | # Copyright 2019 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # https://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | -- Nested types are columnized independently of each other and of the 16 | -- surrounding type. 17 | 18 | 19 | struct Foo: 20 | struct Bar: 21 | 0 [+4] UInt very_very_long 22 | very_very_long [+4] UInt v 23 | 24 | struct Baz: 25 | 0 [+4] UInt:32 long 26 | 4 [+long] UInt:8[long] data 27 | 28 | 0 [+4] UInt field 29 | -------------------------------------------------------------------------------- /testdata/format/nested_types_are_columnized_independently.emb.formatted_indent_4: -------------------------------------------------------------------------------- 1 | # Copyright 2019 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # https://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | -- Nested types are columnized independently of each other and of the 16 | -- surrounding type. 17 | 18 | 19 | struct Foo: 20 | struct Bar: 21 | 0 [+4] UInt very_very_long 22 | very_very_long [+4] UInt v 23 | 24 | struct Baz: 25 | 0 [+4] UInt:32 long 26 | 4 [+long] UInt:8[long] data 27 | 28 | 0 [+4] UInt field 29 | -------------------------------------------------------------------------------- /testdata/format/one_type.emb: -------------------------------------------------------------------------------- 1 | # Copyright 2019 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # https://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | struct Foo: 16 | -- A single type with no header lines. 17 | 0 [+1] UInt bar 18 | -------------------------------------------------------------------------------- /testdata/format/one_type.emb.formatted: -------------------------------------------------------------------------------- 1 | # Copyright 2019 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # https://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | 16 | struct Foo: 17 | -- A single type with no header lines. 18 | 0 [+1] UInt bar 19 | -------------------------------------------------------------------------------- /testdata/format/one_type.emb.formatted_indent_4: -------------------------------------------------------------------------------- 1 | # Copyright 2019 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # https://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | 16 | struct Foo: 17 | -- A single type with no header lines. 18 | 0 [+1] UInt bar 19 | -------------------------------------------------------------------------------- /testdata/format/parameterized_struct.emb: -------------------------------------------------------------------------------- 1 | # Copyright 2019 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # https://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | -- Test for parameterized structures: definition and use. 16 | 17 | struct TwoParameters(a:UInt:8,b:UInt:32): 18 | 0 [+1] UInt a_field 19 | 20 | bits OneParameter(a:UInt:8): 21 | 0 [+1] UInt a_field 22 | 23 | struct NoParameters(): 24 | 0 [+1] UInt a_field 25 | 26 | struct UsingParameters: 27 | 0 [+1] TwoParameters(0, 1+10) two 28 | 1 [+1] OneParameter(0) one 29 | 2 [+5] NoParameters()[5] zero 30 | -------------------------------------------------------------------------------- /testdata/format/parameterized_struct.emb.formatted: -------------------------------------------------------------------------------- 1 | # Copyright 2019 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # https://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | -- Test for parameterized structures: definition and use. 16 | 17 | 18 | struct TwoParameters(a: UInt:8, b: UInt:32): 19 | 0 [+1] UInt a_field 20 | 21 | 22 | bits OneParameter(a: UInt:8): 23 | 0 [+1] UInt a_field 24 | 25 | 26 | struct NoParameters(): 27 | 0 [+1] UInt a_field 28 | 29 | 30 | struct UsingParameters: 31 | 0 [+1] TwoParameters(0, 1+10) two 32 | 1 [+1] OneParameter(0) one 33 | 2 [+5] NoParameters()[5] zero 34 | -------------------------------------------------------------------------------- /testdata/format/parameterized_struct.emb.formatted_indent_4: -------------------------------------------------------------------------------- 1 | # Copyright 2019 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # https://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | -- Test for parameterized structures: definition and use. 16 | 17 | 18 | struct TwoParameters(a: UInt:8, b: UInt:32): 19 | 0 [+1] UInt a_field 20 | 21 | 22 | bits OneParameter(a: UInt:8): 23 | 0 [+1] UInt a_field 24 | 25 | 26 | struct NoParameters(): 27 | 0 [+1] UInt a_field 28 | 29 | 30 | struct UsingParameters: 31 | 0 [+1] TwoParameters(0, 1+10) two 32 | 1 [+1] OneParameter(0) one 33 | 2 [+5] NoParameters()[5] zero 34 | -------------------------------------------------------------------------------- /testdata/format/sanity_check.emb: -------------------------------------------------------------------------------- 1 | # Copyright 2019 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # https://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | -- Minimal .emb. 16 | -------------------------------------------------------------------------------- /testdata/format/sanity_check.emb.formatted: -------------------------------------------------------------------------------- 1 | # Copyright 2019 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # https://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | -- Minimal .emb. 16 | -------------------------------------------------------------------------------- /testdata/format/sanity_check.emb.formatted_indent_4: -------------------------------------------------------------------------------- 1 | # Copyright 2019 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # https://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | -- Minimal .emb. 16 | -------------------------------------------------------------------------------- /testdata/format/spacing_between_types.emb: -------------------------------------------------------------------------------- 1 | # Copyright 2019 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # https://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | -- Top-level types get two blank lines between them. 16 | 17 | struct Foo: 18 | 0 [+1] UInt a 19 | 20 | struct Bar: 21 | 0 [+1] UInt b 22 | -------------------------------------------------------------------------------- /testdata/format/spacing_between_types.emb.formatted: -------------------------------------------------------------------------------- 1 | # Copyright 2019 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # https://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | -- Top-level types get two blank lines between them. 16 | 17 | 18 | struct Foo: 19 | 0 [+1] UInt a 20 | 21 | 22 | struct Bar: 23 | 0 [+1] UInt b 24 | -------------------------------------------------------------------------------- /testdata/format/spacing_between_types.emb.formatted_indent_4: -------------------------------------------------------------------------------- 1 | # Copyright 2019 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # https://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | -- Top-level types get two blank lines between them. 16 | 17 | 18 | struct Foo: 19 | 0 [+1] UInt a 20 | 21 | 22 | struct Bar: 23 | 0 [+1] UInt b 24 | -------------------------------------------------------------------------------- /testdata/format/trailing_spaces.emb: -------------------------------------------------------------------------------- 1 | # Copyright 2019 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # https://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | 16 | 17 | # Leading and trailing whitespace should be removed, even from comments 18 | -- ... and documentation 19 | 20 | import "x" as y 21 | -------------------------------------------------------------------------------- /testdata/format/trailing_spaces.emb.formatted: -------------------------------------------------------------------------------- 1 | # Copyright 2019 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # https://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | 16 | 17 | # Leading and trailing whitespace should be removed, even from comments 18 | 19 | -- ... and documentation 20 | 21 | import "x" as y 22 | -------------------------------------------------------------------------------- /testdata/format/trailing_spaces.emb.formatted_indent_4: -------------------------------------------------------------------------------- 1 | # Copyright 2019 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # https://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | 16 | 17 | # Leading and trailing whitespace should be removed, even from comments 18 | 19 | -- ... and documentation 20 | 21 | import "x" as y 22 | -------------------------------------------------------------------------------- /testdata/format/virtual_fields.emb: -------------------------------------------------------------------------------- 1 | # Copyright 2019 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # https://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | -- Formatting of virtual fields, mixed in with nonvirtual fields. 16 | 17 | enum Values: 18 | FOO = 1 19 | BAR = 2 20 | 21 | struct Foo: 22 | let important_constant = Values.FOO# comm 23 | 0 [+1]UInt len # comment 24 | # comment comment comment 25 | 1[+2] LongTypeName long_value_name # comment? 26 | let s = len - 2 27 | if($size_in_bytes )> 10 : 28 | 2[+s] SubMessage submessage 29 | let truth=Bar . top 30 | if Bar .$max_size_in_bits < 2: 31 | Bar. $min_size_in_bits [+1] Int x 32 | 33 | bits Bar: 34 | let top = true 35 | 0 [+1]Flag allowed 36 | if $size_in_bits>10: 37 | let s = 100 38 | 2[+s] SubMessage submessage 39 | if Foo .$max_size_in_bytes < 2: 40 | Foo. $min_size_in_bytes [+1] Int x 41 | -------------------------------------------------------------------------------- /testdata/format/virtual_fields.emb.formatted: -------------------------------------------------------------------------------- 1 | # Copyright 2019 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # https://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | -- Formatting of virtual fields, mixed in with nonvirtual fields. 16 | 17 | 18 | enum Values: 19 | FOO = 1 20 | BAR = 2 21 | 22 | 23 | struct Foo: 24 | let important_constant = Values.FOO # comm 25 | 0 [+1] UInt len # comment 26 | # comment comment comment 27 | 1 [+2] LongTypeName long_value_name # comment? 28 | let s = len-2 29 | if ($size_in_bytes) > 10: 30 | 2 [+s] SubMessage submessage 31 | 32 | let truth = Bar.top 33 | if Bar.$max_size_in_bits < 2: 34 | Bar.$min_size_in_bits [+1] Int x 35 | 36 | 37 | bits Bar: 38 | let top = true 39 | 0 [+1] Flag allowed 40 | if $size_in_bits > 10: 41 | let s = 100 42 | 2 [+s] SubMessage submessage 43 | 44 | if Foo.$max_size_in_bytes < 2: 45 | Foo.$min_size_in_bytes [+1] Int x 46 | -------------------------------------------------------------------------------- /testdata/format/virtual_fields.emb.formatted_indent_4: -------------------------------------------------------------------------------- 1 | # Copyright 2019 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # https://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | -- Formatting of virtual fields, mixed in with nonvirtual fields. 16 | 17 | 18 | enum Values: 19 | FOO = 1 20 | BAR = 2 21 | 22 | 23 | struct Foo: 24 | let important_constant = Values.FOO # comm 25 | 0 [+1] UInt len # comment 26 | # comment comment comment 27 | 1 [+2] LongTypeName long_value_name # comment? 28 | let s = len-2 29 | if ($size_in_bytes) > 10: 30 | 2 [+s] SubMessage submessage 31 | 32 | let truth = Bar.top 33 | if Bar.$max_size_in_bits < 2: 34 | Bar.$min_size_in_bits [+1] Int x 35 | 36 | 37 | bits Bar: 38 | let top = true 39 | 0 [+1] Flag allowed 40 | if $size_in_bits > 10: 41 | let s = 100 42 | 2 [+s] SubMessage submessage 43 | 44 | if Foo.$max_size_in_bytes < 2: 45 | Foo.$min_size_in_bytes [+1] Int x 46 | -------------------------------------------------------------------------------- /testdata/golden/README.md: -------------------------------------------------------------------------------- 1 | This directory contains an `.emb` and a set of golden files which correspond to 2 | various parsing stages of the `.emb`. The primary purpose is to highlight 3 | changes to the parse tree, tokenization, or (uncooked) intermediate 4 | representation in a code review, where the before/after can be seen in 5 | side-by-side diffs. The golden files *are* checked by unit tests, but test 6 | failures generally just mean that the files need to be regenerated, not that 7 | there is an actual bug. 8 | 9 | 10 | ## `span_se_log_file_status.emb` 11 | 12 | The .emb file from which the other files are derived. 13 | 14 | 15 | ## `span_se_log_file_status.tokens.txt` 16 | 17 | The tokenization. This file should change very rarely. From the workspace root 18 | directory, it can be generated with: 19 | 20 | bazel run //front_end:emboss_front_end \ 21 | -- --no-debug-show-header-lines --debug-show-tokenization \ 22 | $(pwd)/testdata/golden/span_se_log_file_status.emb \ 23 | > $(pwd)/testdata/golden/span_se_log_file_status.tokens.txt 24 | 25 | 26 | ## `span_se_log_file_status.parse_tree.txt` 27 | 28 | The syntactic parse tree. From the workspace root directory, it can be 29 | generated with: 30 | 31 | bazel run //front_end:emboss_front_end \ 32 | -- --no-debug-show-header-lines --debug-show-parse-tree \ 33 | $(pwd)/testdata/golden/span_se_log_file_status.emb \ 34 | > $(pwd)/testdata/golden/span_se_log_file_status.parse_tree.txt 35 | 36 | 37 | ## `span_se_log_file_status.ir.txt` 38 | 39 | The "uncooked" module-level IR: that is, the IR of *only* 40 | `span_se_log_file_status.emb` (without the prelude or any imports), straight out 41 | of `module_ir.py` with no "middle end" transformations. From the workspace root 42 | directory, it can be generated with: 43 | 44 | blaze run //front_end:emboss_front_end \ 45 | -- --no-debug-show-header-lines --debug-show-module-ir \ 46 | $(pwd)/testdata/golden/span_se_log_file_status.emb \ 47 | > $(pwd)/testdata/golden/span_se_log_file_status.ir.txt 48 | -------------------------------------------------------------------------------- /testdata/golden/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright 2019 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # https://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | -------------------------------------------------------------------------------- /testdata/golden/span_se_log_file_status.emb: -------------------------------------------------------------------------------- 1 | # Copyright 2019 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # https://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | -- This is a simple, real-world example structure. 16 | 17 | [$default byte_order: "LittleEndian"] 18 | [(cpp) namespace: "emboss::test"] 19 | 20 | 21 | struct LogFileStatus: 22 | 0 [+4] UInt file_state 23 | 4 [+12] UInt:8[12] file_name 24 | 16 [+4] UInt file_size_kb 25 | 20 [+4] UInt media 26 | -------------------------------------------------------------------------------- /testdata/import_dir/project/imported.emb: -------------------------------------------------------------------------------- 1 | # Copyright 2019 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # https://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | [$default byte_order: "LittleEndian"] 16 | [(cpp) namespace: "emboss::test"] 17 | 18 | 19 | struct Inner: 20 | 0 [+8] UInt value 21 | -------------------------------------------------------------------------------- /testdata/import_dir/project/importer.emb: -------------------------------------------------------------------------------- 1 | # Copyright 2019 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # https://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | # Test .emb to ensure that the import system works. 16 | # 17 | # The file imported_genfiles.emb is identical to imported.emb except for the 18 | # [(cpp) namespace] attribute; it is used to ensure that generated .embs can be 19 | # used by the emboss_cc_library build rule. 20 | 21 | # These imports intentionally use names that do not match the file names, as a 22 | # test that the file names aren't being used. 23 | 24 | import "project/imported.emb" as imp 25 | 26 | [(cpp) namespace: "emboss::test"] 27 | 28 | 29 | struct Outer: 30 | 0 [+8] imp.Inner inner 31 | -------------------------------------------------------------------------------- /testdata/imported.emb: -------------------------------------------------------------------------------- 1 | # Copyright 2019 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # https://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | [$default byte_order: "LittleEndian"] 16 | [(cpp) namespace: "emboss::test"] 17 | 18 | 19 | struct Inner: 20 | 0 [+8] UInt value 21 | -------------------------------------------------------------------------------- /testdata/importer.emb: -------------------------------------------------------------------------------- 1 | # Copyright 2019 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # https://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | # Test .emb to ensure that the import system works. 16 | # 17 | # The file imported_genfiles.emb is identical to imported.emb except for the 18 | # [(cpp) namespace] attribute; it is used to ensure that generated .embs can be 19 | # used by the emboss_cc_library build rule. 20 | 21 | # These imports intentionally use names that do not match the file names, as a 22 | # test that the file names aren't being used. 23 | 24 | import "testdata/imported.emb" as imp 25 | import "testdata/imported_genfiles.emb" as imp_gen 26 | 27 | [(cpp) namespace: "emboss::test"] 28 | 29 | 30 | struct Outer: 31 | 0 [+8] imp.Inner inner 32 | 8 [+8] imp_gen.Inner inner_gen 33 | -------------------------------------------------------------------------------- /testdata/importer2.emb: -------------------------------------------------------------------------------- 1 | # Copyright 2023 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # https://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | # Test .emb to ensure that the import system works. 16 | # 17 | # The file imported_genfiles.emb is identical to imported.emb except for the 18 | # [(cpp) namespace] attribute; it is used to ensure that generated .embs can be 19 | # used by the emboss_cc_library build rule. 20 | 21 | # These imports intentionally use names that do not match the file names, as a 22 | # test that the file names aren't being used. 23 | 24 | import "testdata/importer.emb" as imp 25 | 26 | [(cpp) namespace: "emboss::test"] 27 | 28 | 29 | struct Outer2: 30 | 0 [+16] imp.Outer outer 31 | -------------------------------------------------------------------------------- /testdata/inline_type.emb: -------------------------------------------------------------------------------- 1 | # Copyright 2019 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # https://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | -- Test definitions for inline types. 16 | 17 | [$default byte_order: "LittleEndian"] 18 | [(cpp) namespace: "emboss::test"] 19 | 20 | 21 | struct Foo: 22 | 0 [+1] enum status: 23 | OK = 0 24 | FAILURE = 12 25 | 26 | 1 [+1] enum secondary_status: 27 | OK = 12 28 | FAILURE = 0 29 | -------------------------------------------------------------------------------- /testdata/int_sizes.emb: -------------------------------------------------------------------------------- 1 | # Copyright 2019 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # https://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | -- Test struct for 8, 16, 32, and 64 bit Ints. 16 | 17 | [$default byte_order: "LittleEndian"] 18 | [(cpp) namespace: "emboss::test"] 19 | 20 | 21 | struct Sizes: 22 | 0 [+1] Int one_byte 23 | 1 [+2] Int two_byte 24 | 3 [+3] Int three_byte 25 | 6 [+4] Int four_byte 26 | 10 [+5] Int five_byte 27 | 15 [+6] Int six_byte 28 | 21 [+7] Int seven_byte 29 | 28 [+8] Int eight_byte 30 | -------------------------------------------------------------------------------- /testdata/large_array.emb: -------------------------------------------------------------------------------- 1 | # Copyright 2019 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # https://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | -- Structure used for performance testing: Emboss-mediated access vs. 16 | -- reinterpret_cast<>-style access. 17 | 18 | [$default byte_order: "LittleEndian"] 19 | [(cpp) namespace: "emboss::test"] 20 | 21 | 22 | struct UIntArray: 23 | 0 [+4] UInt element_count (e) 24 | 4 [+4*e] UInt:32[e] elements 25 | -------------------------------------------------------------------------------- /testdata/nested_structure.emb: -------------------------------------------------------------------------------- 1 | # Copyright 2019 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # https://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | [$default byte_order: "LittleEndian"] 16 | [(cpp) namespace: "emboss::test"] 17 | 18 | 19 | struct Container: 20 | 0 [+4] UInt weight 21 | 4 [+8] Box important_box 22 | 12 [+8] Box other_box 23 | 24 | 25 | struct Box: 26 | 0 [+4] UInt id 27 | 4 [+4] UInt count 28 | 29 | 30 | struct Truck: 31 | 0 [+4] UInt id 32 | 4 [+40] Container[2] cargo 33 | -------------------------------------------------------------------------------- /testdata/next_keyword.emb: -------------------------------------------------------------------------------- 1 | # Copyright 2022 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # https://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | -- Test structures for the `$next` keyword. 16 | 17 | [$default byte_order: "LittleEndian"] 18 | [(cpp) namespace: "emboss::test"] 19 | 20 | 21 | struct NextKeyword: 22 | 0 [+4] UInt value32 23 | $next [+2] UInt value16 24 | $next [+1] UInt value8 25 | $next+3 [+1] UInt value8_offset 26 | -------------------------------------------------------------------------------- /testdata/no_cpp_namespace.emb: -------------------------------------------------------------------------------- 1 | # Copyright 2019 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # https://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | -- Test .emb to ensure that the generated type ends up in the 16 | -- ::emboss_generated_code namespace when the [(cpp) namespace] attribute is not 17 | -- set. 18 | 19 | 20 | enum Foo: 21 | VALUE = 10 22 | -------------------------------------------------------------------------------- /testdata/no_enum_traits.emb: -------------------------------------------------------------------------------- 1 | # Copyright 2019 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # https://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | -- Test .emb to ensure that compilation succedes if enum traits are disabled. 16 | 17 | [$default byte_order: "LittleEndian"] 18 | [(cpp) namespace: "emboss::test"] 19 | 20 | enum Foo: 21 | VALUE = 10 22 | 23 | struct Bar: 24 | 0 [+1] Foo foo -------------------------------------------------------------------------------- /testdata/start_size_range.emb: -------------------------------------------------------------------------------- 1 | # Copyright 2019 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # https://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | [$default byte_order: "LittleEndian"] 16 | [(cpp) namespace: "emboss::test"] 17 | 18 | 19 | struct StartSize: 20 | 0 [+1] UInt size (s) 21 | 1 [+2] UInt start_size_constants 22 | 3 [+s] UInt:8[s] payload 23 | 3+s [+4] UInt counter 24 | -------------------------------------------------------------------------------- /testdata/text_format.emb: -------------------------------------------------------------------------------- 1 | # Copyright 2019 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # https://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | -- Structures used specifically to test text format input and output. 16 | 17 | [(cpp) namespace: "emboss::test"] 18 | 19 | 20 | struct Vanilla: 21 | 0 [+1] UInt a 22 | 1 [+1] UInt b 23 | 24 | 25 | struct StructWithSkippedFields: 26 | 0 [+1] UInt a 27 | 1 [+1] UInt b 28 | [text_output: "Skip"] 29 | 2 [+1] UInt c 30 | 31 | 32 | struct StructWithSkippedStructureFields: 33 | 0 [+2] Vanilla a 34 | 2 [+2] Vanilla b 35 | [text_output: "Skip"] 36 | 4 [+2] Vanilla c 37 | --------------------------------------------------------------------------------