-
Notifications
You must be signed in to change notification settings - Fork 0
/
Mapping M2 Names to C.txt
165 lines (101 loc) · 6.26 KB
/
Mapping M2 Names to C.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
Mapping Identifiers from Modula-2 to C
All Modula-2 identifiers are converted to a C representation in snake_case or MACRO_CASE, depending
on the object they represent. In order to convert a Modula-2 identifier to its C representation,
it is first split at word boundaries, the resulting components are then converted to all-lowercase
or all-uppercase, and are then rejoined by inserting a lowline _ between any two components.
Certain types of identifiers are additionally prefixed or suffixed or both.
Word Boundaries
Word boundaries in the Modula-2 identifier are determined as follows:
(1) a sequence of lowercase letters and digits preceding a capital letter, or
(2) a sequence of capital letters and digits preceding a sequence of a capital letter followed by
lowercase letters and digits
sets the word boundary before the capital letter;
(3) a sequence of a capital letters followed by digits preceding a sequence of lowercase letters
sets the word boundary before the first lowercase letter.
(4) where lowlines are enabled and used, any lowline sets the word boundary at the lowline.
Module Prefixes
The C representations of all exported and all imported Modula-2 identifiers are qualified with a
module prefix, derived from the module identifier of the module that exports the identifier.
To derive the module prefix for C macro identifiers, the module identifier is converted to
MACRO_CASE. To derive the module prefix for all other C identifiers, the module identifier
is converted to snake_case. To obtain the C representation of the fully qualified identifier,
the derived module prefix is prepended to the C representation of the unqualified identifier
while two lowlines __ are inserted between them.
Local Suffixes
With the exception of local variable identifiers, the C representation of all other local
identifiers are qualified with a local suffix, derived from the base-36 representation of a hash
value computed from the identifier of the surrounding procedure.
To obtain the C representation of the fully qualified identifier, the derived local suffix is
appended to the C representation of the unqualified identifier while two lowlines __ are
inserted between them. The suffix always starts with a decimal digit.
Constant Identifiers
To obtain the C representation of a Modula-2 constant identifier, the identifier is converted
to MACRO_CASE.
Examples
* A non-local non-exported Modula-2 constant FooBar is mapped to FOO_BAR.
* A Modula-2 constant BazBam exported by module FooBar is mapped to FOO_BAR__BAZ_BAM.
* A local Modula-2 constant BazBam in procedure FooBar is mapped to BAZ_BAM__DXXXXX
where DXXXXX is the base-36 hash value of FooBar.
Enumerated Value Identifiers
The C representations of all Modula-2 enumerated value identifiers are qualified with an
enumeration prefix, derived from the type identifier of their respective enumeration type
converted to MACRO_CASE.
To obtain the C representation of a Modula-2 enumerated value identifier, the identifier
is converted to MACRO_CASE and the enumeration prefix is prepended while a lowline _ is
inserted between them.
Examples
Given the enumeration type declaration TYPE Color = ( Red, Green, Blue );
* If type Color is non-local and non-exported, Red is mapped to COLOR_RED.
* If type Color is exported by module Graphics, Red is mapped to GRAPHICS__COLOR_RED.
* If type Color is declared local in procedure Draw, Red is mapped to COLOR_RED__DXXXXX
where DXXXXX is the base-36 hash value of Draw.
Type Identifiers
The C representations of all Modula-2 type identifiers are marked with the type suffix _t.
To obtain the C representation of a type identifier, the identifier is converted to
snake_case and the type suffix is appended.
Examples
* A non-local non-exported Modula-2 type identifier FooBar is mapped to foo_bar_t.
* A Modula-2 type identifier BazBam exported by module FooBar is mapped to foo_bar__baz_bam_t.
* A local Modula-2 type identifier BazBam in procedure FooBar is mapped to baz_bam_t__DXXXXX
where DXXXXX is the base-36 hash value of FooBar.
Variable Identifiers
To obtain the C representation of a Modula-2 variable identifier, the identifier is converted
to snake_case.
Examples
* A non-local non-exported Modula-2 variable identifier fooBar is mapped to foo_bar.
* A Modula-2 variable identifier bazBam exported by module FooBar is mapped to foo_bar__baz_bam.
* A local Modula-2 variable identifier bazBam in procedure FooBar is mapped to baz_bam without
local suffix.
Function Identifiers
To obtain the C representation of a Modula-2 function identifier, the identifier is converted
to snake_case.
Examples
* A non-local non-exported Modula-2 function identifier fooBar is mapped to foo_bar.
* A Modula-2 function identifier bazBam exported by module FooBar is mapped to foo_bar__baz_bam.
* A local Modula-2 function identifier bazBam in procedure FooBar is mapped to baz_bam__DXXXXX
where DXXXXX is the base-36 hash value of FooBar.
Procedure Identifiers
The C representations of all Modula-2 procedure identifiers are marked with the procedure
prefix do_.
To obtain the C representation of a procedure identifier, the identifier is converted to
snake_case and the procedure prefix is prepended.
Examples
* A non-local non-exported Modula-2 procedure identifier FooBar is mapped to do_foo_bar.
* A Modula-2 procedure identifier BazBam exported by module FooBar is mapped to foo_bar__do_baz_bam.
* A local Modula-2 procedure identifier BazBam in procedure FooBar is mapped to do_baz_bam__DXXXXX
where DXXXXX is the base-36 hash value of FooBar.
Identifiers whose Mapping coincides with Reserved Words of C
Where the final C representation of a Modula-2 identifier coincides with a reserved word of C,
its first letter is capitalised.
Examples
* A local Modula-2 variable switch is mapped to Switch.
* A non-exported Modula-2 function float is mapped to Float.
Naming Convention
This mapping scheme was designed with the common Modula-2 naming convention in mind, under which:
* Module, type and procedure identifiers are in TitleCase,
* Math constant, variable and function identifiers are in camelCase,
* Other constant identifiers are consistently either in camelCase or TitleCase.
Legend
In the placeholder DXXXXX, representing a local suffix,
D represents a decimal digit, X a base-36 digit.
[END OF DOCUMENT]