|
| 1 | +--- |
| 2 | +layout: default |
| 3 | +title: Message Field Name Conflicts |
| 4 | +permalink: articles/message_field_conflicts.html |
| 5 | +abstract: |
| 6 | + As we move to support more platforms there are we are running into predefined fields and constants that conflict with languages or implementation keywords and macros. |
| 7 | + This defines how to deal with existing and potential future conflicts. |
| 8 | +published: true |
| 9 | +author: '[Tully Foote](https://github.com/tfoote)' |
| 10 | +categories: Interfaces |
| 11 | +--- |
| 12 | + |
| 13 | +{:toc} |
| 14 | + |
| 15 | +# {{ page.title }} |
| 16 | + |
| 17 | +<div class="abstract" markdown="1"> |
| 18 | +{{ page.abstract }} |
| 19 | +</div> |
| 20 | + |
| 21 | +Original Author: {{ page.author }} |
| 22 | + |
| 23 | +## Scope |
| 24 | + |
| 25 | +This article specifies how we will deal with conflicting fields and constants for different languages. |
| 26 | +In the use of the IDL (TODO (tfoote) reference) there will inevitably be conflicting symbols, keywords, or definitions. |
| 27 | + |
| 28 | +## Background |
| 29 | + |
| 30 | +This has come up specifically as we're adding support for Windows for ROS2. |
| 31 | +`winnt.h` defines several macros that conflict with existing enumerations. |
| 32 | +It is also expected to happen as support for new languages are added. |
| 33 | + |
| 34 | +## New constants |
| 35 | + |
| 36 | +To avoid conflicts generally all constants should be prefixed with a `k`. This will avoid almost all conflicts. |
| 37 | + |
| 38 | +Google Style Guide: https://google.github.io/styleguide/cppguide.html#Constant_Names |
| 39 | + |
| 40 | +TODO(tfoote) Reference ROS2 style guide |
| 41 | + |
| 42 | +## Language Generator Requirements |
| 43 | + |
| 44 | +In the case that a new language is added and there is a detected existing symbol, the language specific generator is expected to implement a basic deconfliction mangling of the symbol to avoid the conflict. |
| 45 | + |
| 46 | +Each generator will define the mangling procedure and provide a list of symbols for which the procedure will be applied. |
| 47 | +This list should be all known keywords or otherwise conflicting symbols. |
| 48 | + |
| 49 | +### Example Deconfliction Policy |
| 50 | + |
| 51 | +A example of a simple name mangling policy would be to append a trailing underscore for conflicting symbols. |
| 52 | +So that would mean that `FOO` if declared as a conflicting symbol would be used in generated code as `FOO_`. |
| 53 | + |
| 54 | +A slightly more unique string is recommended for clarity. |
| 55 | + |
| 56 | +### Stability |
| 57 | +Each language generator will provide a standard name deconfliction policy so that users can use the symbols in a stable manner. |
| 58 | +If a change is needed the generated code should provide a full cycle of backwards compatibility to support changes. |
| 59 | + |
| 60 | +This table will remain stable so that codebases can rely on using the mangled symbols. |
| 61 | +Appending to the table may be necessary if the first pass did not catch all the conflicting keywords. |
| 62 | + |
| 63 | +The removal of any protected keywords should be avoided if at all possible as it will require all code using that field or constant to be updated. |
| 64 | + |
| 65 | +### Table of deconfliction |
| 66 | + |
| 67 | +The language support package will provide a yaml file with a list of all the protected keywords and their mangled version in a dictionary as key and value respectively. |
| 68 | + |
| 69 | +For example if the language had conflicts for `FOO`, `new`, and `delete` it's yaml file would like like this: |
| 70 | + |
| 71 | +``` |
| 72 | +FOO: FOO_ |
| 73 | +new: new_ |
| 74 | +delete: delete_ |
| 75 | +``` |
| 76 | + |
| 77 | +This yaml file will be considered the authority for deconflicting and should be exported in a way that will allow downstream code generators to automatically apply the deconfliction policy. |
| 78 | + |
| 79 | +## Legacy Support |
| 80 | + |
| 81 | +There are a number of known conflicts with the existing ROS1 codebase. |
| 82 | +In these few cases we will undefine the matching C/C++ preprocessor macros which are conflicting in the definition and define the old value. |
| 83 | +This will be done only inside the declaration header and the definition will be restored before returning to the user's code. |
| 84 | +If you are using the legacy defines it's required to use the namespaced reference instead of using a shorthand version as those are know to conflict. |
| 85 | + |
| 86 | +These values will also provide the new version with the deconfliction mangling applied. |
| 87 | +It is recommended to move to the deconflicted version immediately. |
| 88 | + |
| 89 | +The backwards compatibility will be maintained for one year after Bouncy. |
| 90 | + |
| 91 | +* `NO_ERROR` |
| 92 | +* `DELETE` |
| 93 | +* `ERROR` |
0 commit comments