trijezdci
2016-03-14 07:12:31 UTC
With work on M2C having moved to the code generator, the question of how to translate identifiers had come up. Since it is desired that the intermediate C code is human readable, it would also be desirable that it would be familiar to those who code in C but not in Pascal or M2. But it is also desirable to accommodate M2/Pascal practitioners.
In other words, it is desirable that M2C can generate both C and M2 style in its intermediate C output, and the style should be user selectable by compiler switch. For C style translations are all-lowercase with lowline "_" separators (foo_bar_baz) and for M2 style they are title case for module and type identifiers and camel-case for other user defined identifiers. In either style, language defined all-uppercase names are translated case by case, as there may be 1:1 C equivalents (INTEGER => integer).
The current name translation library covers all scenarios documented in
https://bitbucket.org/trijezdci/m2c-rework/downloads/m2c-ident-conversions.txt
This assumes that the Modula-2 input sources also use one of the two styles.
If somebody used fooType and fooVar, instead of FooType and fooVar) that alone wouldn't cause an issue, but if there were both FooType and fooType or both fooVar and FooVar in the same scope, that would cause name conflicts in the output.
VAR foo : Foo; => foo_t foo; or Foo foo;
but VAR foo, Foo : Bar; => bar_t foo, foo; or Bar foo, foo;
We discussed a scheme whereby
* module identifiers not starting with an uppercase letter would be rejected
* type identifiers not starting with an uppercase letter would be considered prefixed with T
* constant, variable and procedure identifiers not starting with a lowercase letter would be considered prefixed with c, v and fn respectively.
This would then bring such identifiers in line with the presumed title-case/camel-case name convention. If the input uses all lowercase with _ separators, it can simply be copied verbatim for C style or converted to M2 style in the output.
However, it would be interesting to know what kind of naming styles are used. What are your naming conventions in your M2 source code? Thanks in advance.
In other words, it is desirable that M2C can generate both C and M2 style in its intermediate C output, and the style should be user selectable by compiler switch. For C style translations are all-lowercase with lowline "_" separators (foo_bar_baz) and for M2 style they are title case for module and type identifiers and camel-case for other user defined identifiers. In either style, language defined all-uppercase names are translated case by case, as there may be 1:1 C equivalents (INTEGER => integer).
The current name translation library covers all scenarios documented in
https://bitbucket.org/trijezdci/m2c-rework/downloads/m2c-ident-conversions.txt
This assumes that the Modula-2 input sources also use one of the two styles.
If somebody used fooType and fooVar, instead of FooType and fooVar) that alone wouldn't cause an issue, but if there were both FooType and fooType or both fooVar and FooVar in the same scope, that would cause name conflicts in the output.
VAR foo : Foo; => foo_t foo; or Foo foo;
but VAR foo, Foo : Bar; => bar_t foo, foo; or Bar foo, foo;
We discussed a scheme whereby
* module identifiers not starting with an uppercase letter would be rejected
* type identifiers not starting with an uppercase letter would be considered prefixed with T
* constant, variable and procedure identifiers not starting with a lowercase letter would be considered prefixed with c, v and fn respectively.
This would then bring such identifiers in line with the presumed title-case/camel-case name convention. If the input uses all lowercase with _ separators, it can simply be copied verbatim for C style or converted to M2 style in the output.
However, it would be interesting to know what kind of naming styles are used. What are your naming conventions in your M2 source code? Thanks in advance.