Skip to content

Commit 1ca3735

Browse files
committed
refactoring the IDL field name specifications into the IDL article.
1 parent 88c0211 commit 1ca3735

File tree

2 files changed

+79
-96
lines changed

2 files changed

+79
-96
lines changed

articles/110_interface_definition.md

Lines changed: 79 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,11 +126,88 @@ Both file names must use an upper camel case name and only consist of alphanumer
126126
Field names must be lowercase alphanumeric characters with underscores for separating words.
127127
They must start with an alphabetic character, they must not end with an underscore and never have two consecutive underscores.
128128

129-
### Naming of constants
129+
#### Naming Conflicts
130130

131-
Constant names must be uppercase alphanumeric characters with underscores for separating words.
131+
When defining field names it has been recommended to avoid language keywords and other reserved symbols.
132+
However since we cannot be guaranteed to know all conflicts of potential future languages or implementations we must have a way to systematically deal with these conflicts without disrupting existing code bases and implementations.
133+
To that end we will require that language bindings provide a reproducable name mangling mapping that will prevent conflicts with reserved keywords or other conflicts.
134+
135+
##### Background
136+
137+
This has come up specifically as we're adding support for Windows for ROS2.
138+
`winnt.h` defines several macros that conflict with existing enumerations.
139+
It is also expected to happen as support for new languages are added.
140+
We cannot know all the potential future keywords and restrictions from a language which is selected to add support for in the future so we must have a generic solution which will allow future languages to be added without disrupting the existing usages.
141+
142+
##### Language Generator Requirements
143+
144+
In the case that a new language is added and there is a detected conflicting name for a field, the language specific generator is expected to implement a basic deconfliction mangling of the symbol to avoid the conflict.
145+
146+
Each generator will define the mangling procedure and provide a list of symbols for which the procedure will be applied.
147+
This list should be all known keywords or otherwise conflicting symbols.
148+
149+
##### Example Deconfliction Policy
150+
151+
A example of a simple name mangling policy would be to append a trailing underscore for conflicting symbols.
152+
So that would mean that `FOO` if declared as a conflicting symbol would be used in generated code as `FOO_`.
153+
154+
Clearly this would collide if someone defined `class` and `class_`, so slightly more unique string is recommended for clarity and uniqueness.
155+
The mangling should be designed so that accidental collisions between names and mangled names cannot happen.
156+
One easy way to do this would be to a language specific valid character not valid in the standard field name specification.
157+
158+
159+
##### Table of deconfliction
160+
161+
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.
162+
163+
For example if the language had conflicts for `FOO`, `new`, and `delete` it's yaml file would like like this:
164+
165+
```
166+
FOO: FOO_
167+
new: new_
168+
delete: delete_
169+
```
170+
171+
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.
172+
173+
##### Stability
174+
Each language generator will provide a standard name deconfliction policy so that users can use the symbols in a stable manner.
175+
176+
This table will remain stable so that codebases can rely on using the mangled symbols.
177+
Appending to the table may be necessary if the first pass did not catch all the conflicting keywords.
178+
179+
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.
180+
181+
##### Legacy Support
182+
183+
There are a number of known conflicts with the existing ROS1 codebase.
184+
In these few cases we will undefine the matching C/C++ preprocessor macros which are conflicting in the definition and define the old value.
185+
This will be done only inside the declaration header and the definition will be restored before returning to the user's code.
186+
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.
187+
188+
For an easy migration path.
189+
The mangled version of the constants will be made available in ROS Melodic by manually defining them in parallel so that code can be ported and use the same constant values while the codebase is spanning ROS1 and ROS2 implementations.
190+
191+
It is recommended to move to the deconflicted version immediately.
192+
193+
Constants known to be at issue:
194+
195+
* `NO_ERROR`
196+
* `DELETE`
197+
* `ERROR`
198+
199+
#### Naming Constants
200+
201+
Constant names must be uppercase alphanumeric characters with underscores for separating words except the first character which should be a lowercase k.
132202
They must start with an alphabetic character, they must not end with an underscore and never have two consecutive underscores.
133203

204+
To avoid conflicts generally all constants should be prefixed with a `k`.
205+
This will avoid almost all conflicts in all languages.
206+
This is designed to follow the Google Style Guide: [https://google.github.io/styleguide/cppguide.html#Constant_Names](https://google.github.io/styleguide/cppguide.html#Constant_Names)
207+
208+
This should be used for newly defined constants.
209+
When migrating messages from ROS1 if there are existing constants in use the new version should be defined side by side with the old name to provide backwards compatibility for a full deprecation cycle.
210+
134211
## Syntax
135212

136213
The message and service definitions are text files.

articles/150_message_field_names.md

Lines changed: 0 additions & 94 deletions
This file was deleted.

0 commit comments

Comments
 (0)