corba.js 0.2.0 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (78) hide show
  1. package/README.md +15 -14
  2. package/lib/idl/idl.cjs +1049 -1272
  3. package/lib/idl/idl.cjs.map +1 -1
  4. package/lib/idl/src/idl/cc/typeIDLtoCC.d.ts +4 -2
  5. package/lib/idl/src/idl/cc/typeIDLtoGIOPCC.d.ts +2 -2
  6. package/lib/idl/src/idl/cc/write-code.d.ts +2 -2
  7. package/lib/idl/src/idl/cc/write-interface.d.ts +4 -4
  8. package/lib/idl/src/idl/cc/write-skeleton.d.ts +2 -2
  9. package/lib/idl/src/idl/cc/write-stub.d.ts +2 -2
  10. package/lib/idl/src/idl/idl-lexer.d.ts +9 -4
  11. package/lib/idl/src/idl/idl-node.d.ts +157 -28
  12. package/lib/idl/src/idl/idl-parser.d.ts +2 -2
  13. package/lib/idl/src/idl/ts/typeIDLtoGIOPTS.d.ts +2 -2
  14. package/lib/idl/src/idl/ts/typeIDLtoTS.d.ts +3 -2
  15. package/lib/idl/src/idl/ts/write-interface.d.ts +2 -2
  16. package/lib/idl/src/idl/ts/write-skeleton.d.ts +2 -2
  17. package/lib/idl/src/idl/ts/write-stub.d.ts +2 -2
  18. package/lib/idl/src/idl/ts/write-value.d.ts +2 -2
  19. package/lib/idl/src/idl/ts/write-valueimpl.d.ts +2 -2
  20. package/lib/idl/src/idl/ts/write-valuetype.d.ts +2 -2
  21. package/lib/idl/src/idl/util.d.ts +11 -4
  22. package/lib/src/idl/cc/typeIDLtoCC.d.ts +4 -2
  23. package/lib/src/idl/cc/typeIDLtoCC.js +32 -29
  24. package/lib/src/idl/cc/typeIDLtoCC.js.map +1 -1
  25. package/lib/src/idl/cc/typeIDLtoGIOPCC.d.ts +2 -2
  26. package/lib/src/idl/cc/typeIDLtoGIOPCC.js +14 -18
  27. package/lib/src/idl/cc/typeIDLtoGIOPCC.js.map +1 -1
  28. package/lib/src/idl/cc/write-code.d.ts +2 -2
  29. package/lib/src/idl/cc/write-code.js +42 -69
  30. package/lib/src/idl/cc/write-code.js.map +1 -1
  31. package/lib/src/idl/cc/write-interface.d.ts +4 -4
  32. package/lib/src/idl/cc/write-interface.js +64 -65
  33. package/lib/src/idl/cc/write-interface.js.map +1 -1
  34. package/lib/src/idl/cc/write-skeleton.d.ts +2 -2
  35. package/lib/src/idl/cc/write-skeleton.js +6 -7
  36. package/lib/src/idl/cc/write-skeleton.js.map +1 -1
  37. package/lib/src/idl/cc/write-stub.d.ts +2 -2
  38. package/lib/src/idl/cc/write-stub.js +17 -26
  39. package/lib/src/idl/cc/write-stub.js.map +1 -1
  40. package/lib/src/idl/idl-lexer.d.ts +9 -4
  41. package/lib/src/idl/idl-lexer.js +124 -76
  42. package/lib/src/idl/idl-lexer.js.map +1 -1
  43. package/lib/src/idl/idl-node.d.ts +157 -28
  44. package/lib/src/idl/idl-node.js +12 -142
  45. package/lib/src/idl/idl-node.js.map +1 -1
  46. package/lib/src/idl/idl-parser.d.ts +2 -2
  47. package/lib/src/idl/idl-parser.js +379 -454
  48. package/lib/src/idl/idl-parser.js.map +1 -1
  49. package/lib/src/idl/idl.js +0 -2
  50. package/lib/src/idl/idl.js.map +1 -1
  51. package/lib/src/idl/ts/typeIDLtoGIOPTS.d.ts +2 -2
  52. package/lib/src/idl/ts/typeIDLtoGIOPTS.js +16 -21
  53. package/lib/src/idl/ts/typeIDLtoGIOPTS.js.map +1 -1
  54. package/lib/src/idl/ts/typeIDLtoTS.d.ts +3 -2
  55. package/lib/src/idl/ts/typeIDLtoTS.js +54 -69
  56. package/lib/src/idl/ts/typeIDLtoTS.js.map +1 -1
  57. package/lib/src/idl/ts/write-interface.d.ts +2 -2
  58. package/lib/src/idl/ts/write-interface.js +89 -90
  59. package/lib/src/idl/ts/write-interface.js.map +1 -1
  60. package/lib/src/idl/ts/write-skeleton.d.ts +2 -2
  61. package/lib/src/idl/ts/write-skeleton.js +24 -33
  62. package/lib/src/idl/ts/write-skeleton.js.map +1 -1
  63. package/lib/src/idl/ts/write-stub.d.ts +2 -2
  64. package/lib/src/idl/ts/write-stub.js +26 -35
  65. package/lib/src/idl/ts/write-stub.js.map +1 -1
  66. package/lib/src/idl/ts/write-value.d.ts +2 -2
  67. package/lib/src/idl/ts/write-value.js +39 -59
  68. package/lib/src/idl/ts/write-value.js.map +1 -1
  69. package/lib/src/idl/ts/write-valueimpl.d.ts +2 -2
  70. package/lib/src/idl/ts/write-valueimpl.js +33 -50
  71. package/lib/src/idl/ts/write-valueimpl.js.map +1 -1
  72. package/lib/src/idl/ts/write-valuetype.d.ts +2 -2
  73. package/lib/src/idl/ts/write-valuetype.js +20 -29
  74. package/lib/src/idl/ts/write-valuetype.js.map +1 -1
  75. package/lib/src/idl/util.d.ts +11 -4
  76. package/lib/src/idl/util.js +71 -12
  77. package/lib/src/idl/util.js.map +1 -1
  78. package/package.json +10 -10
package/lib/idl/idl.cjs CHANGED
@@ -93,150 +93,105 @@ var Type;
93
93
  Type[Type["TKN_WSTRING"] = 67] = "TKN_WSTRING";
94
94
  Type[Type["SYN_SPECIFICATION"] = 68] = "SYN_SPECIFICATION";
95
95
  Type[Type["SYN_INTERFACE"] = 69] = "SYN_INTERFACE";
96
- Type[Type["SYN_INTERFACE_HEADER"] = 70] = "SYN_INTERFACE_HEADER";
97
- Type[Type["SYN_INTERFACE_BODY"] = 71] = "SYN_INTERFACE_BODY";
98
- Type[Type["SYN_VALUE_HEADER"] = 72] = "SYN_VALUE_HEADER";
99
- Type[Type["SYN_VALUE_INHERITANCE_SPEC"] = 73] = "SYN_VALUE_INHERITANCE_SPEC";
100
- Type[Type["SYN_STATE_MEMBER"] = 74] = "SYN_STATE_MEMBER";
101
- Type[Type["SYN_TYPE_DECLARATOR"] = 75] = "SYN_TYPE_DECLARATOR";
102
- Type[Type["SYN_DECLARATORS"] = 76] = "SYN_DECLARATORS";
103
- Type[Type["SYN_MEMBER_LIST"] = 77] = "SYN_MEMBER_LIST";
104
- Type[Type["SYN_MEMBER"] = 78] = "SYN_MEMBER";
105
- Type[Type["SYN_SWITCH_BODY"] = 79] = "SYN_SWITCH_BODY";
106
- Type[Type["SYN_OPERATION_DECLARATION"] = 80] = "SYN_OPERATION_DECLARATION";
107
- Type[Type["SYN_PARAMETER_DECLARATIONS"] = 81] = "SYN_PARAMETER_DECLARATIONS";
108
- Type[Type["SYN_PARAMETER_DECLARATION"] = 82] = "SYN_PARAMETER_DECLARATION";
109
- Type[Type["SYN_ANNOTAION"] = 83] = "SYN_ANNOTAION";
110
- Type[Type["SYN_TYPENAME"] = 84] = "SYN_TYPENAME";
111
- Type[Type["SYN_LONGLONG"] = 85] = "SYN_LONGLONG";
112
- Type[Type["SYN_UNSIGNED_SHORT"] = 86] = "SYN_UNSIGNED_SHORT";
113
- Type[Type["SYN_UNSIGNED_LONG"] = 87] = "SYN_UNSIGNED_LONG";
114
- Type[Type["SYN_UNSIGNED_LONGLONG"] = 88] = "SYN_UNSIGNED_LONGLONG";
115
- Type[Type["SYN_LONG_DOUBLE"] = 89] = "SYN_LONG_DOUBLE";
96
+ Type[Type["SYN_OPERATION_DECLARATION"] = 70] = "SYN_OPERATION_DECLARATION";
97
+ Type[Type["SYN_STATE_MEMBER"] = 71] = "SYN_STATE_MEMBER";
98
+ Type[Type["SYN_MEMBER"] = 72] = "SYN_MEMBER";
99
+ Type[Type["SYN_PARAMETER_DECLARATION"] = 73] = "SYN_PARAMETER_DECLARATION";
100
+ Type[Type["SYN_ANNOTAION"] = 74] = "SYN_ANNOTAION";
101
+ Type[Type["SYN_SCOPED_NAME"] = 75] = "SYN_SCOPED_NAME";
102
+ Type[Type["SYN_ENUMERATOR"] = 76] = "SYN_ENUMERATOR";
103
+ Type[Type["SYN_LONGLONG"] = 77] = "SYN_LONGLONG";
104
+ Type[Type["SYN_UNSIGNED_SHORT"] = 78] = "SYN_UNSIGNED_SHORT";
105
+ Type[Type["SYN_UNSIGNED_LONG"] = 79] = "SYN_UNSIGNED_LONG";
106
+ Type[Type["SYN_UNSIGNED_LONGLONG"] = 80] = "SYN_UNSIGNED_LONGLONG";
107
+ Type[Type["SYN_LONG_DOUBLE"] = 81] = "SYN_LONG_DOUBLE";
116
108
  })(Type || (Type = {}));
117
- class Node {
118
- constructor(type, text) {
119
- this.type = type;
120
- this.text = text;
121
- this.child = new Array();
122
- }
123
- toString() {
124
- switch (this.type) {
125
- case Type.NONE: return "none";
126
- case Type.TKN_TEXT: return "text '" + this.text + "'";
127
- case Type.TKN_IDENTIFIER: return "identifier '" + this.text + "'";
128
- case Type.TKN_COLON_COLON: return "::";
129
- case Type.TKN_ABSTRACT: return "abstract";
130
- case Type.TKN_ANY: return "any";
131
- case Type.TKN_ATTRIBUTE: return "attribute";
132
- case Type.TKN_BOOLEAN: return "boolean";
133
- case Type.TKN_CASE: return "case";
134
- case Type.TKN_CHAR: return "char";
135
- case Type.TKN_COMPONENT: return "component";
136
- case Type.TKN_CONST: return "const";
137
- case Type.TKN_CONSUMES: return "consumes";
138
- case Type.TKN_CONTEXT: return "context";
139
- case Type.TKN_CUSTOM: return "custom";
140
- case Type.TKN_DEFAULT: return "default";
141
- case Type.TKN_DOUBLE: return "double";
142
- case Type.TKN_EXCEPTION: return "exception";
143
- case Type.TKN_EMITS: return "emits";
144
- case Type.TKN_ENUM: return "enum";
145
- case Type.TKN_EVENTTYPE: return "eventtype";
146
- case Type.TKN_FACTORY: return "factory";
147
- case Type.TKN_FALSE: return "FALSE";
148
- case Type.TKN_FINDER: return "finder";
149
- case Type.TKN_FIXED: return "fixed";
150
- case Type.TKN_FLOAT: return "float";
151
- case Type.TKN_GETRAISES: return "getraises";
152
- case Type.TKN_HOME: return "home";
153
- case Type.TKN_IMPORT: return "import";
154
- case Type.TKN_IN: return "in";
155
- case Type.TKN_INOUT: return "inout";
156
- case Type.TKN_INTERFACE: return "interface";
157
- case Type.TKN_LOCAL: return "local";
158
- case Type.TKN_LONG: return "long";
159
- case Type.TKN_MODULE: return "module";
160
- case Type.TKN_MULTIPLE: return "multiple";
161
- case Type.TKN_NATIVE: return "native";
162
- case Type.TKN_OBJECT: return "Object";
163
- case Type.TKN_OCTET: return "octet";
164
- case Type.TKN_ONEWAY: return "oneway";
165
- case Type.TKN_OUT: return "out";
166
- case Type.TKN_PRIMARYKEY: return "primarykey";
167
- case Type.TKN_PRIVATE: return "private";
168
- case Type.TKN_PROVIDES: return "provides";
169
- case Type.TKN_PUBLIC: return "public";
170
- case Type.TKN_PUBLISHES: return "publishes";
171
- case Type.TKN_RAISES: return "raises";
172
- case Type.TKN_READONLY: return "readonly";
173
- case Type.TKN_SETRAISES: return "setraises";
174
- case Type.TKN_SEQUENCE: return "sequence";
175
- case Type.TKN_SHORT: return "short";
176
- case Type.TKN_STRING: return "string";
177
- case Type.TKN_STRUCT: return "struct";
178
- case Type.TKN_SUPPORTS: return "supports";
179
- case Type.TKN_SWITCH: return "switch";
180
- case Type.TKN_TRUE: return "TRUE";
181
- case Type.TKN_TRUNCATABLE: return "truncatable";
182
- case Type.TKN_TYPEDEF: return "typedef";
183
- case Type.TKN_TYPEID: return "typeid";
184
- case Type.TKN_TYPEPREFIX: return "typeprefix";
185
- case Type.TKN_UNSIGNED: return "unsigned";
186
- case Type.TKN_UNION: return "union";
187
- case Type.TKN_USES: return "uses";
188
- case Type.TKN_VALUEBASE: return "ValueBase";
189
- case Type.TKN_VALUETYPE: return "valuetype";
190
- case Type.TKN_VOID: return "void";
191
- case Type.TKN_WCHAR: return "wchar";
192
- case Type.TKN_WSTRING: return "wstring";
193
- case Type.SYN_SPECIFICATION: return "SYN_SPECIFICATION";
194
- case Type.SYN_INTERFACE: return "SYN_INTERFACE";
195
- case Type.SYN_INTERFACE_HEADER: return "SYN_INTERFACE_HEADER";
196
- case Type.SYN_INTERFACE_BODY: return "SYN_INTERFACE_BODY";
197
- case Type.SYN_VALUE_HEADER: return "SYN_VALUE_HEADER";
198
- case Type.SYN_VALUE_INHERITANCE_SPEC: return "SYN_VALUE_INHERITANCE_SPEC";
199
- case Type.SYN_STATE_MEMBER: return "SYN_STATE_MEMBER";
200
- case Type.SYN_TYPE_DECLARATOR: return "SYN_TYPE_DECLARATOR";
201
- case Type.SYN_DECLARATORS: return "SYN_DECLARATORS";
202
- case Type.SYN_MEMBER_LIST: return "SYN_MEMBER_LIST";
203
- case Type.SYN_MEMBER: return "SYN_MEMBER";
204
- case Type.SYN_SWITCH_BODY: return "SYN_SWITCH_BODY";
205
- case Type.SYN_OPERATION_DECLARATION: return "SYN_OPERATION_DECLARATION";
206
- case Type.SYN_PARAMETER_DECLARATIONS: return "SYN_PARAMETER_DECLARATIONS";
207
- case Type.SYN_PARAMETER_DECLARATION: return "SYN_PARAMETER_DECLARATION";
208
- case Type.SYN_ANNOTAION: return "SYN_ANNOTATION";
209
- case Type.SYN_TYPENAME: return "SYN_TYPENAME";
210
- case Type.SYN_LONGLONG: return "long long";
211
- case Type.SYN_UNSIGNED_SHORT: return "unsigned short";
212
- case Type.SYN_UNSIGNED_LONG: return "unsigned long";
213
- case Type.SYN_UNSIGNED_LONGLONG: return "unsigned long long";
214
- case Type.SYN_LONG_DOUBLE: return "long double";
215
- }
216
- throw Error("Node.toString(): unknown type " + String(this.type));
217
- }
218
- printTree(depth = 0) {
219
- let indent = "";
220
- for (let i = 0; i < depth; ++i)
221
- indent = indent + " ";
222
- console.log(indent + this.toString());
223
- for (let c of this.child) {
224
- if (c === undefined) {
225
- console.log(indent + " undefined");
226
- }
227
- else {
228
- c.printTree(depth + 1);
229
- }
230
- }
231
- }
232
- append(node) {
233
- this.child.push(node);
234
- }
235
- prepend(node) {
236
- this.child.unshift(node);
237
- }
238
- }
239
109
 
110
+ const keywords = new Map([
111
+ ["abstract", Type.TKN_ABSTRACT],
112
+ ["any", Type.TKN_ANY],
113
+ ["attribute", Type.TKN_ATTRIBUTE],
114
+ ["boolean", Type.TKN_BOOLEAN],
115
+ ["case", Type.TKN_CASE],
116
+ ["char", Type.TKN_CHAR],
117
+ ["component", Type.TKN_COMPONENT],
118
+ ["const", Type.TKN_CONST],
119
+ ["consumes", Type.TKN_CONSUMES],
120
+ ["context", Type.TKN_CONTEXT],
121
+ ["custom", Type.TKN_CUSTOM],
122
+ ["default", Type.TKN_DEFAULT],
123
+ ["double", Type.TKN_DOUBLE],
124
+ ["exception", Type.TKN_EXCEPTION],
125
+ ["emits", Type.TKN_EMITS],
126
+ ["enum", Type.TKN_ENUM],
127
+ ["eventtype", Type.TKN_EVENTTYPE],
128
+ ["factory", Type.TKN_FACTORY],
129
+ ["FALSE", Type.TKN_FALSE],
130
+ ["finder", Type.TKN_FINDER],
131
+ ["fixed", Type.TKN_FIXED],
132
+ ["float", Type.TKN_FLOAT],
133
+ ["getraises", Type.TKN_GETRAISES],
134
+ ["home", Type.TKN_HOME],
135
+ ["import", Type.TKN_IMPORT],
136
+ ["in", Type.TKN_IN],
137
+ ["inout", Type.TKN_INOUT],
138
+ ["interface", Type.TKN_INTERFACE],
139
+ ["local", Type.TKN_LOCAL],
140
+ ["long", Type.TKN_LONG],
141
+ ["module", Type.TKN_MODULE],
142
+ ["multiple", Type.TKN_MULTIPLE],
143
+ ["native", Type.TKN_NATIVE],
144
+ ["Object", Type.TKN_OBJECT],
145
+ ["octet", Type.TKN_OCTET],
146
+ ["oneway", Type.TKN_ONEWAY],
147
+ ["out", Type.TKN_OUT],
148
+ ["primarykey", Type.TKN_PRIMARYKEY],
149
+ ["private", Type.TKN_PRIVATE],
150
+ ["provides", Type.TKN_PROVIDES],
151
+ ["public", Type.TKN_PUBLIC],
152
+ ["publishes", Type.TKN_PUBLISHES],
153
+ ["raises", Type.TKN_RAISES],
154
+ ["readonly", Type.TKN_READONLY],
155
+ ["setraises", Type.TKN_SETRAISES],
156
+ ["sequence", Type.TKN_SEQUENCE],
157
+ ["short", Type.TKN_SHORT],
158
+ ["string", Type.TKN_STRING],
159
+ ["struct", Type.TKN_STRUCT],
160
+ ["supports", Type.TKN_SUPPORTS],
161
+ ["switch", Type.TKN_SWITCH],
162
+ ["TRUE", Type.TKN_TRUE],
163
+ ["truncatable", Type.TKN_TRUNCATABLE],
164
+ ["typedef", Type.TKN_TYPEDEF],
165
+ ["typeid", Type.TKN_TYPEID],
166
+ ["typeprefix", Type.TKN_TYPEPREFIX],
167
+ ["unsigned", Type.TKN_UNSIGNED],
168
+ ["union", Type.TKN_UNION],
169
+ ["uses", Type.TKN_USES],
170
+ ["ValueBase", Type.TKN_VALUEBASE],
171
+ ["valuetype", Type.TKN_VALUETYPE],
172
+ ["void", Type.TKN_VOID],
173
+ ["wchar", Type.TKN_WCHAR],
174
+ ["wstring", Type.TKN_WSTRING]
175
+ ]);
176
+ function describeToken(token) {
177
+ if (token === undefined)
178
+ return "undefined";
179
+ switch (token.type) {
180
+ case Type.TKN_TEXT: return `text '${token.text}'`;
181
+ case Type.TKN_IDENTIFIER: return `identifier '${token.text}'`;
182
+ case Type.TKN_COLON_COLON: return "::";
183
+ case Type.SYN_LONGLONG: return "long long";
184
+ case Type.SYN_UNSIGNED_SHORT: return "unsigned short";
185
+ case Type.SYN_UNSIGNED_LONG: return "unsigned long";
186
+ case Type.SYN_UNSIGNED_LONGLONG: return "unsigned long long";
187
+ case Type.SYN_LONG_DOUBLE: return "long double";
188
+ }
189
+ for (const [text, type] of keywords) {
190
+ if (type === token.type)
191
+ return text;
192
+ }
193
+ return Type[token.type];
194
+ }
240
195
  class Lexer {
241
196
  static isAlpha(c) {
242
197
  let n = c.charCodeAt(0);
@@ -251,6 +206,7 @@ class Lexer {
251
206
  return Lexer.isAlpha(c) || Lexer.isDigit(c);
252
207
  }
253
208
  constructor(data) {
209
+ this.doc = [];
254
210
  this.data = data;
255
211
  this.line = 1;
256
212
  this.column = 1;
@@ -290,14 +246,38 @@ class Lexer {
290
246
  unlex(token) {
291
247
  if (token === undefined)
292
248
  return;
293
- if (token.child.length !== 0)
294
- throw Error("can not unlex token " + token.toString() + " with children");
295
249
  this.tokenStack.push(token);
296
250
  }
297
251
  lex() {
298
252
  if (this.tokenStack.length > 0) {
299
253
  return this.tokenStack.pop();
300
254
  }
255
+ const token = this.lexToken();
256
+ if (token !== undefined && this.doc.length > 0) {
257
+ token.doc = this.doc;
258
+ this.doc = [];
259
+ }
260
+ return token;
261
+ }
262
+ collectDoc(comment) {
263
+ let lines;
264
+ if (comment.startsWith("///") && !comment.startsWith("////") || comment.startsWith("//!")) {
265
+ lines = [comment.substring(3)];
266
+ }
267
+ else if (comment.startsWith("/**") || comment.startsWith("/*!")) {
268
+ lines = comment.substring(3, comment.length - 1).split("\n");
269
+ }
270
+ else {
271
+ return;
272
+ }
273
+ lines = lines.map(line => line.replace(/^\s*\*?\s*/, "").trimEnd());
274
+ while (lines.length > 0 && lines[0] === "")
275
+ lines.shift();
276
+ while (lines.length > 0 && lines[lines.length - 1] === "")
277
+ lines.pop();
278
+ this.doc.push(...lines);
279
+ }
280
+ lexToken() {
301
281
  while (!this.eof()) {
302
282
  let c = this.getc();
303
283
  let oldstate = this.state;
@@ -325,7 +305,7 @@ class Lexer {
325
305
  this.state = 2;
326
306
  }
327
307
  else {
328
- return new Node(Type.TKN_TEXT, c);
308
+ return { type: Type.TKN_TEXT, text: c };
329
309
  }
330
310
  break;
331
311
  }
@@ -334,81 +314,17 @@ class Lexer {
334
314
  if (!Lexer.isAlpha(c)) {
335
315
  this.ungetc();
336
316
  this.state = 0;
337
- return new Node(Type.TKN_IDENTIFIER, this.text);
317
+ return { type: Type.TKN_IDENTIFIER, text: this.text };
338
318
  }
339
319
  break;
340
320
  case 2:
341
321
  if (!Lexer.isAlphaNumeric(c) && c !== "_") {
342
322
  this.ungetc();
343
323
  this.state = 0;
344
- switch (this.text) {
345
- case "abstract": return new Node(Type.TKN_ABSTRACT);
346
- case "any": return new Node(Type.TKN_ANY);
347
- case "attribute": return new Node(Type.TKN_ATTRIBUTE);
348
- case "boolean": return new Node(Type.TKN_BOOLEAN);
349
- case "case": return new Node(Type.TKN_CASE);
350
- case "char": return new Node(Type.TKN_CHAR);
351
- case "component": return new Node(Type.TKN_COMPONENT);
352
- case "const": return new Node(Type.TKN_CONST);
353
- case "consumes": return new Node(Type.TKN_CONSUMES);
354
- case "context": return new Node(Type.TKN_CONTEXT);
355
- case "custom": return new Node(Type.TKN_CUSTOM);
356
- case "default": return new Node(Type.TKN_DEFAULT);
357
- case "double": return new Node(Type.TKN_DOUBLE);
358
- case "exception": return new Node(Type.TKN_EXCEPTION);
359
- case "emits": return new Node(Type.TKN_EMITS);
360
- case "enum": return new Node(Type.TKN_ENUM);
361
- case "eventtype": return new Node(Type.TKN_EVENTTYPE);
362
- case "factory": return new Node(Type.TKN_FACTORY);
363
- case "FALSE": return new Node(Type.TKN_FALSE);
364
- case "finder": return new Node(Type.TKN_FINDER);
365
- case "fixed": return new Node(Type.TKN_FIXED);
366
- case "float": return new Node(Type.TKN_FLOAT);
367
- case "getraises": return new Node(Type.TKN_GETRAISES);
368
- case "home": return new Node(Type.TKN_HOME);
369
- case "import": return new Node(Type.TKN_IMPORT);
370
- case "in": return new Node(Type.TKN_IN);
371
- case "inout": return new Node(Type.TKN_INOUT);
372
- case "interface": return new Node(Type.TKN_INTERFACE);
373
- case "local": return new Node(Type.TKN_LOCAL);
374
- case "long": return new Node(Type.TKN_LONG);
375
- case "module": return new Node(Type.TKN_MODULE);
376
- case "multiple": return new Node(Type.TKN_MULTIPLE);
377
- case "native": return new Node(Type.TKN_NATIVE);
378
- case "Object": return new Node(Type.TKN_OBJECT);
379
- case "octet": return new Node(Type.TKN_OCTET);
380
- case "oneway": return new Node(Type.TKN_ONEWAY);
381
- case "out": return new Node(Type.TKN_OUT);
382
- case "primarykey": return new Node(Type.TKN_PRIMARYKEY);
383
- case "private": return new Node(Type.TKN_PRIVATE);
384
- case "provides": return new Node(Type.TKN_PROVIDES);
385
- case "public": return new Node(Type.TKN_PUBLIC);
386
- case "publishes": return new Node(Type.TKN_PUBLISHES);
387
- case "raises": return new Node(Type.TKN_RAISES);
388
- case "readonly": return new Node(Type.TKN_READONLY);
389
- case "setraises": return new Node(Type.TKN_SETRAISES);
390
- case "sequence": return new Node(Type.TKN_SEQUENCE);
391
- case "short": return new Node(Type.TKN_SHORT);
392
- case "string": return new Node(Type.TKN_STRING);
393
- case "struct": return new Node(Type.TKN_STRUCT);
394
- case "supports": return new Node(Type.TKN_SUPPORTS);
395
- case "switch": return new Node(Type.TKN_SWITCH);
396
- case "TRUE": return new Node(Type.TKN_TRUE);
397
- case "truncatable": return new Node(Type.TKN_TRUNCATABLE);
398
- case "typedef": return new Node(Type.TKN_TYPEDEF);
399
- case "typeid": return new Node(Type.TKN_TYPEID);
400
- case "typeprefix": return new Node(Type.TKN_TYPEPREFIX);
401
- case "unsigned": return new Node(Type.TKN_UNSIGNED);
402
- case "union": return new Node(Type.TKN_UNION);
403
- case "uses": return new Node(Type.TKN_USES);
404
- case "ValueBase": return new Node(Type.TKN_VALUEBASE);
405
- case "valuetype": return new Node(Type.TKN_VALUETYPE);
406
- case "void": return new Node(Type.TKN_VOID);
407
- case "wchar": return new Node(Type.TKN_WCHAR);
408
- case "wstring": return new Node(Type.TKN_WSTRING);
409
- default:
410
- return new Node(Type.TKN_IDENTIFIER, this.text);
411
- }
324
+ const keyword = keywords.get(this.text);
325
+ if (keyword !== undefined)
326
+ return { type: keyword };
327
+ return { type: Type.TKN_IDENTIFIER, text: this.text };
412
328
  }
413
329
  break;
414
330
  case 3:
@@ -421,13 +337,14 @@ class Lexer {
421
337
  break;
422
338
  default:
423
339
  this.ungetc();
424
- return new Node(Type.TKN_TEXT, '/');
340
+ return { type: Type.TKN_TEXT, text: '/' };
425
341
  }
426
342
  break;
427
343
  case 4:
428
344
  switch (c) {
429
345
  case '\n':
430
346
  this.state = 0;
347
+ this.collectDoc(this.text);
431
348
  break;
432
349
  }
433
350
  break;
@@ -442,6 +359,7 @@ class Lexer {
442
359
  switch (c) {
443
360
  case '/':
444
361
  this.state = 0;
362
+ this.collectDoc(this.text);
445
363
  break;
446
364
  case '*':
447
365
  break;
@@ -452,11 +370,11 @@ class Lexer {
452
370
  case 7:
453
371
  this.state = 0;
454
372
  if (c == ':') {
455
- return new Node(Type.TKN_COLON_COLON, "::");
373
+ return { type: Type.TKN_COLON_COLON, text: "::" };
456
374
  }
457
375
  else {
458
376
  this.ungetc();
459
- return new Node(Type.TKN_TEXT, ':');
377
+ return { type: Type.TKN_TEXT, text: ':' };
460
378
  }
461
379
  }
462
380
  if (oldstate == 0) {
@@ -475,18 +393,18 @@ let scoper;
475
393
  function specification(aLexer) {
476
394
  lexer = aLexer;
477
395
  scoper = new ScopeManager();
478
- let node = new Node(Type.SYN_SPECIFICATION);
396
+ const definitions = [];
479
397
  while (true) {
480
- let t0 = definition();
398
+ const t0 = definition();
481
399
  if (t0 === undefined)
482
400
  break;
483
- node.append(t0);
401
+ definitions.push(t0);
484
402
  }
485
403
  const tail = lexer.lex();
486
404
  if (tail !== undefined) {
487
- throw Error(`Unparsed token '${tail.toString()}' at end of specification.`);
405
+ throw Error(`Unparsed token '${describeToken(tail)}' at end of specification.`);
488
406
  }
489
- return node;
407
+ return { type: Type.SYN_SPECIFICATION, definitions };
490
408
  }
491
409
  function definition() {
492
410
  let t0;
@@ -505,25 +423,25 @@ function definition() {
505
423
  return t0;
506
424
  }
507
425
  function _module() {
508
- let t0 = lexer.lex();
426
+ const t0 = lexer.lex();
509
427
  if (t0 !== undefined && t0.type === Type.TKN_MODULE) {
510
- let t1 = identifier();
428
+ const t1 = identifier();
511
429
  if (t1 === undefined)
512
430
  throw Error("expected identifier after 'module'");
513
- t0.text = t1.text;
431
+ const node = { type: Type.TKN_MODULE, name: t1.text, parent: scoper.getCurrentScope().node, definitions: [] };
514
432
  expect("{");
515
- scoper.enterModule(t0);
433
+ scoper.enterModule(node);
516
434
  while (true) {
517
- let t2 = definition();
435
+ const t2 = definition();
518
436
  if (t2 === undefined)
519
437
  break;
520
438
  if (t2.type == Type.TKN_NATIVE)
521
439
  throw Error("'native' can not be used within 'module'");
522
- t0.append(t2);
440
+ node.definitions.push(t2);
523
441
  }
524
442
  expect("}");
525
- scoper.leaveModule(t0);
526
- return t0;
443
+ scoper.leaveModule();
444
+ return node;
527
445
  }
528
446
  lexer.unlex(t0);
529
447
  return undefined;
@@ -532,42 +450,39 @@ function _interface() {
532
450
  return interface_dcl();
533
451
  }
534
452
  function interface_dcl() {
535
- let t0 = interface_header();
453
+ const doc = docBefore();
454
+ const t0 = interface_header();
536
455
  if (!t0) {
537
- t0 = lexer.lex();
538
- if (t0) {
539
- lexer.unlex(t0);
456
+ const t = lexer.lex();
457
+ if (t) {
458
+ lexer.unlex(t);
540
459
  }
541
460
  return undefined;
542
461
  }
543
- let t1 = lexer.lex();
462
+ const t1 = lexer.lex();
544
463
  if (t1 === undefined)
545
464
  throw Error("expected { after interface header but got end of file");
546
465
  if (t1.type !== Type.TKN_TEXT && t1.text != '{')
547
- throw Error(`expected { after interface header but got ${t0}`);
548
- let node = new Node(Type.SYN_INTERFACE, t0.child[1].text);
549
- scoper.addType(t0.child[1].text, node);
550
- node.append(t0);
551
- let t2 = interface_body();
552
- node.append(t2);
553
- let t3 = lexer.lex();
466
+ throw Error(`expected { after interface header but got ${describeToken(t1)}`);
467
+ const node = { type: Type.SYN_INTERFACE, name: t0.name, modifier: t0.modifier, base: t0.base, body: [], doc };
468
+ scoper.addType(node.name, node);
469
+ node.body = interface_body();
470
+ const t3 = lexer.lex();
554
471
  if (!t3)
555
472
  throw Error("unexpected end of file");
556
473
  if (t3.type !== Type.TKN_TEXT && t3.text != '}')
557
- throw Error(`expected } after interface body but got '${t3}'`);
474
+ throw Error(`expected } after interface body but got '${describeToken(t3)}'`);
558
475
  return node;
559
476
  }
560
477
  function interface_header() {
561
- let t0 = lexer.lex();
478
+ const t0 = lexer.lex();
562
479
  if (t0 === undefined) {
563
480
  return undefined;
564
481
  }
565
- let t1;
566
- if (t0.type !== Type.TKN_ABSTRACT && t0.type !== Type.TKN_LOCAL) {
567
- t1 = t0;
568
- t0 = undefined;
569
- }
570
- else {
482
+ let modifier = undefined;
483
+ let t1 = t0;
484
+ if (t0.type === Type.TKN_ABSTRACT || t0.type === Type.TKN_LOCAL) {
485
+ modifier = t0.type;
571
486
  t1 = lexer.lex();
572
487
  }
573
488
  if (t1 === undefined) {
@@ -576,27 +491,24 @@ function interface_header() {
576
491
  }
577
492
  if (t1.type !== Type.TKN_INTERFACE) {
578
493
  lexer.unlex(t1);
579
- lexer.unlex(t0);
494
+ if (modifier !== undefined)
495
+ lexer.unlex(t0);
580
496
  return undefined;
581
497
  }
582
- let t2 = identifier();
498
+ const t2 = identifier();
583
499
  if (t2 === undefined) {
584
500
  throw Error("expected identifier after 'interface'");
585
501
  }
586
- let t3 = interface_inheritance_spec();
587
- let header = new Node(Type.SYN_INTERFACE_HEADER);
588
- header.append(t0);
589
- header.append(t2);
590
- header.append(t3);
591
- return header;
502
+ const base = interface_inheritance_spec();
503
+ return { name: t2.text, modifier, base };
592
504
  }
593
505
  function interface_body() {
594
- let body = new Node(Type.SYN_INTERFACE_BODY);
506
+ const body = [];
595
507
  while (true) {
596
- let t0 = _export();
508
+ const t0 = _export();
597
509
  if (t0 === undefined)
598
510
  return body;
599
- body.append(t0);
511
+ body.push(t0);
600
512
  }
601
513
  }
602
514
  function _export() {
@@ -626,12 +538,11 @@ function interface_inheritance_spec() {
626
538
  throw Error("multiple inheritance is not implemented in corba.js");
627
539
  }
628
540
  lexer.unlex(token);
629
- const n = scoper.getType(id.text);
630
- if (n === undefined) {
541
+ const entry = scoper.getType(id.text);
542
+ if (entry === undefined) {
631
543
  throw Error(`undefined interface ${id.text}`);
632
544
  }
633
- id.append(n);
634
- return id;
545
+ return makeScopedName(id.text, [], entry);
635
546
  }
636
547
  function scoped_name() {
637
548
  let globalNamespaceToken = undefined;
@@ -652,28 +563,33 @@ function scoped_name() {
652
563
  lexer.unlex(globalNamespaceToken);
653
564
  return undefined;
654
565
  }
655
- let type;
656
- if (globalNamespaceToken === undefined) {
657
- type = scoper.getType(identifierToken.text);
658
- }
659
- else {
660
- type = scoper.getGlobalScope().getType(identifierToken.text);
566
+ if (globalNamespaceToken !== undefined) {
661
567
  throw Error(`No way known to translate '::${identifierToken.text}' to TypeScript`);
662
568
  }
663
- if (type === undefined) {
664
- throw Error(`unknown type ${identifierToken}`);
665
- }
666
- identifierToken.append(type);
667
- if (type.type === Type.TKN_MODULE) {
668
- resolve_module(identifierToken, type);
669
- }
670
- if (type.type === Type.TKN_NATIVE &&
671
- type.text.length > 4 &&
672
- type.text.substring(type.text.length - 4) === "_ptr" &&
673
- type.typeParent === undefined) {
674
- type.typeParent = scoper.getType(type.text.substring(0, type.text.length - 4));
675
- }
676
- return identifierToken;
569
+ const entry = scoper.getType(identifierToken.text);
570
+ if (entry === undefined) {
571
+ throw Error(`unknown type ${describeToken(identifierToken)}`);
572
+ }
573
+ if (entry.target.type === Type.TKN_NATIVE) {
574
+ resolve_native_ptr(entry.target, entry.scope);
575
+ }
576
+ let current = entry;
577
+ let name = identifierToken.text;
578
+ const path = [];
579
+ while (current.target.type === Type.TKN_MODULE) {
580
+ const module = current.target;
581
+ path.push(module);
582
+ resolve_module_separator(name);
583
+ const identifier = lexer.lex();
584
+ if (identifier === undefined || identifier.type !== Type.TKN_IDENTIFIER)
585
+ throw Error(`Expected identifier after ::'`);
586
+ const child = find_in_module(module, identifier.text);
587
+ if (child === undefined)
588
+ throw Error(`failed to lookup ${identifier.text}`);
589
+ name = identifier.text;
590
+ current = { target: child, scope: module };
591
+ }
592
+ return makeScopedName(name, path, current);
677
593
  }
678
594
  function value() {
679
595
  let t0;
@@ -701,85 +617,67 @@ function value_abs_dcl() {
701
617
  return undefined;
702
618
  }
703
619
  function value_dcl() {
704
- let header = value_header();
620
+ const doc = docBefore();
621
+ const header = value_header();
705
622
  if (header === undefined) {
706
623
  return undefined;
707
624
  }
708
625
  expect('{');
709
- let node = new Node(Type.TKN_VALUETYPE);
710
- node.append(header);
711
- let identifier = header.child[1].text;
712
- node.text = identifier;
713
- scoper.addType(identifier, node);
626
+ const node = { type: Type.TKN_VALUETYPE, name: header.name, base: header.base, elements: [], doc };
627
+ scoper.addType(node.name, node);
714
628
  while (true) {
715
- let t1 = value_element();
629
+ const t1 = value_element();
716
630
  if (t1 === undefined)
717
631
  break;
718
- node.append(t1);
632
+ node.elements.push(t1);
719
633
  }
720
634
  expect('}');
721
635
  return node;
722
636
  }
723
637
  function value_header() {
724
- let t0 = lexer.lex();
638
+ const t0 = lexer.lex();
725
639
  if (t0 !== undefined) {
726
- let t1;
727
- if (t0.type === Type.TKN_CUSTOM) {
640
+ if (t0.type === Type.TKN_CUSTOM)
728
641
  throw Error("corba.js currently does not support custom valuetypes");
729
- }
730
- else {
731
- t1 = t0;
732
- t0 = undefined;
733
- }
734
- if (t1 !== undefined && t1.type === Type.TKN_VALUETYPE) {
735
- let t2 = identifier();
642
+ if (t0.type === Type.TKN_VALUETYPE) {
643
+ const t2 = identifier();
736
644
  if (t2 === undefined)
737
645
  throw Error("expected an identifier after valuetype");
738
- let t3 = value_inheritance_spec();
739
- let node = new Node(Type.SYN_VALUE_HEADER);
740
- node.append(t0);
741
- node.append(t2);
742
- node.append(t3);
743
- return node;
646
+ const base = value_inheritance_spec();
647
+ return { name: t2.text, base };
744
648
  }
745
- lexer.unlex(t1);
649
+ lexer.unlex(t0);
746
650
  }
747
- lexer.unlex(t0);
748
651
  return undefined;
749
652
  }
750
653
  function value_inheritance_spec() {
751
- let t0 = lexer.lex();
654
+ const t0 = lexer.lex();
752
655
  if (t0 === undefined || t0.type !== Type.TKN_TEXT || t0.text !== ":") {
753
656
  lexer.unlex(t0);
754
- return undefined;
755
- }
756
- let t1 = lexer.lex();
757
- if (t1 !== undefined && t1.type !== Type.TKN_TRUNCATABLE) {
758
- lexer.unlex(t1);
759
- t1 = undefined;
657
+ return [];
760
658
  }
761
- if (t1 !== undefined)
659
+ const t1 = lexer.lex();
660
+ if (t1 !== undefined && t1.type === Type.TKN_TRUNCATABLE)
762
661
  throw Error("'truncatable' is not supported");
763
- let node = new Node(Type.SYN_VALUE_INHERITANCE_SPEC);
764
- node.append(t1);
662
+ lexer.unlex(t1);
663
+ const base = [];
664
+ let separator = t0.text;
765
665
  while (true) {
766
- let t2 = value_name();
666
+ const t2 = value_name();
767
667
  if (t2 === undefined) {
768
- throw Error("expected a value name after '" + t0.text + "'");
668
+ throw Error("expected a value name after '" + separator + "'");
769
669
  }
770
- node.append(t2);
771
- let t3 = lexer.lex();
670
+ base.push(t2);
671
+ const t3 = lexer.lex();
772
672
  if (t3 === undefined)
773
673
  throw Error("unexpected end of file");
774
674
  if (t3.type !== Type.TKN_TEXT || t3.text !== ",") {
775
675
  lexer.unlex(t3);
776
676
  break;
777
677
  }
778
- t0 = value_name();
779
- if (t0 === undefined)
780
- throw Error("expected a value name after ':'");
678
+ separator = ",";
781
679
  }
782
- return node;
680
+ return base;
783
681
  }
784
682
  function value_name() {
785
683
  return scoped_name();
@@ -791,80 +689,71 @@ function value_element() {
791
689
  return t0;
792
690
  }
793
691
  function state_member() {
794
- let t0 = lexer.lex();
692
+ const doc = docBefore();
693
+ const t0 = lexer.lex();
795
694
  if (t0 === undefined)
796
695
  return undefined;
797
696
  if (t0.type !== Type.TKN_PUBLIC && t0.type !== Type.TKN_PRIVATE) {
798
697
  lexer.unlex(t0);
799
698
  return undefined;
800
699
  }
801
- let t1 = type_spec();
700
+ const t1 = type_spec();
802
701
  if (t1 === undefined) {
803
702
  lexer.unlex(t0);
804
703
  return undefined;
805
704
  }
806
- let t2 = declarators();
807
- if (t2 === undefined) {
705
+ const names = declarators();
706
+ if (names === undefined) {
808
707
  throw Error("expected declarators");
809
708
  }
810
709
  expect(";");
811
- let node = new Node(Type.SYN_STATE_MEMBER);
812
- node.append(t0);
813
- node.append(t1);
814
- node.append(t2);
815
- return node;
710
+ return { type: Type.SYN_STATE_MEMBER, visibility: t0.type, typeSpec: t1, names, doc };
816
711
  }
817
712
  function type_dcl() {
818
- let t0 = lexer.lex();
713
+ const t0 = lexer.lex();
819
714
  if (t0 !== undefined && t0.type === Type.TKN_TYPEDEF) {
820
- let t1 = type_declarator();
715
+ const t1 = type_declarator();
821
716
  if (t1 === undefined) {
822
717
  lexer.unlex(t0);
823
718
  return undefined;
824
719
  }
825
- const identifiers = t1.child[1].child;
826
- for (const id of identifiers) {
827
- scoper.addType(id.text, t1.child[0]);
720
+ for (const name of t1.names) {
721
+ scoper.addType(name, t1.typeSpec);
828
722
  }
829
- t1.type = t0.type;
830
723
  return t1;
831
724
  }
832
725
  lexer.unlex(t0);
833
- t0 = struct_type();
834
- if (t0 !== undefined)
835
- return t0;
836
- t0 = union_type();
837
- if (t0 !== undefined)
838
- return t0;
839
- t0 = enum_type();
840
- if (t0 !== undefined)
841
- return t0;
842
- t0 = lexer.lex();
843
- if (t0 !== undefined && t0.type === Type.TKN_NATIVE) {
844
- let t1 = simple_declarator();
845
- if (t1 === undefined) {
726
+ const t2 = struct_type();
727
+ if (t2 !== undefined)
728
+ return t2;
729
+ const t3 = union_type();
730
+ if (t3 !== undefined)
731
+ return t3;
732
+ const t4 = enum_type();
733
+ if (t4 !== undefined)
734
+ return t4;
735
+ const t5 = lexer.lex();
736
+ if (t5 !== undefined && t5.type === Type.TKN_NATIVE) {
737
+ const t6 = simple_declarator();
738
+ if (t6 === undefined) {
846
739
  throw Error("expected simple declarator after 'native'");
847
740
  }
848
- t0.append(t1);
849
- t0.text = t1.text;
850
- scoper.addType(t1.text, t0);
851
- return t0;
741
+ const node = { type: Type.TKN_NATIVE, name: t6.text };
742
+ scoper.addType(node.name, node);
743
+ return node;
852
744
  }
853
- lexer.unlex(t0);
745
+ lexer.unlex(t5);
854
746
  return undefined;
855
747
  }
856
748
  function type_declarator() {
857
749
  const t0 = type_spec();
858
750
  if (t0 === undefined)
859
751
  return undefined;
860
- const t1 = declarators();
861
- if (t1 == undefined) {
752
+ const names = declarators();
753
+ if (names === undefined) {
862
754
  throw Error("expected at least one declarator");
863
755
  }
864
- const n = new Node(Type.SYN_TYPE_DECLARATOR);
865
- n.append(t0);
866
- n.append(t1);
867
- return n;
756
+ return { type: Type.TKN_TYPEDEF, typeSpec: t0, names };
868
757
  }
869
758
  function type_spec() {
870
759
  let t0;
@@ -932,10 +821,10 @@ function declarators() {
932
821
  let t0 = declarator();
933
822
  if (t0 === undefined)
934
823
  return undefined;
935
- let node = new Node(Type.SYN_DECLARATORS);
824
+ const names = [];
936
825
  while (true) {
937
- node.append(t0);
938
- let t1 = lexer.lex();
826
+ names.push(t0.text);
827
+ const t1 = lexer.lex();
939
828
  if (t1 === undefined || t1.type !== Type.TKN_TEXT || t1.text !== ",") {
940
829
  lexer.unlex(t1);
941
830
  break;
@@ -944,7 +833,7 @@ function declarators() {
944
833
  if (t0 === undefined)
945
834
  throw Error("expected another declarator after ','");
946
835
  }
947
- return node;
836
+ return names;
948
837
  }
949
838
  function declarator() {
950
839
  let t0;
@@ -955,18 +844,17 @@ function simple_declarator() {
955
844
  return identifier();
956
845
  }
957
846
  function floating_pt_type() {
958
- let t0 = lexer.lex();
847
+ const t0 = lexer.lex();
959
848
  if (t0 === undefined)
960
849
  return undefined;
961
850
  if (t0.type === Type.TKN_FLOAT)
962
- return t0;
851
+ return { type: Type.TKN_FLOAT };
963
852
  if (t0.type === Type.TKN_DOUBLE)
964
- return t0;
853
+ return { type: Type.TKN_DOUBLE };
965
854
  if (t0.type === Type.TKN_LONG) {
966
- let t1 = lexer.lex();
855
+ const t1 = lexer.lex();
967
856
  if (t1 !== undefined && t1.type === Type.TKN_DOUBLE) {
968
- t1.type = Type.SYN_LONG_DOUBLE;
969
- return t1;
857
+ return { type: Type.SYN_LONG_DOUBLE };
970
858
  }
971
859
  lexer.unlex(t1);
972
860
  }
@@ -982,11 +870,11 @@ function integer_type() {
982
870
  if (t0 !== undefined) {
983
871
  return t0;
984
872
  }
985
- t0 = lexer.lex();
986
- if (t0 !== undefined && [Type.TKN_SHORT, Type.TKN_LONG, Type.TKN_UNSIGNED].includes(t0.type)) {
873
+ const t1 = lexer.lex();
874
+ if (t1 !== undefined && [Type.TKN_SHORT, Type.TKN_LONG, Type.TKN_UNSIGNED].includes(t1.type)) {
987
875
  throw Error('valid integer types are: short, unsigned short, long, unsigned long, long long, unsigned long long');
988
876
  }
989
- lexer.unlex(t0);
877
+ lexer.unlex(t1);
990
878
  return undefined;
991
879
  }
992
880
  function signed_int() {
@@ -1003,28 +891,27 @@ function signed_int() {
1003
891
  return undefined;
1004
892
  }
1005
893
  function signed_short_int() {
1006
- let t0 = lexer.lex();
894
+ const t0 = lexer.lex();
1007
895
  if (t0 !== undefined && t0.type === Type.TKN_SHORT)
1008
- return t0;
896
+ return { type: Type.TKN_SHORT };
1009
897
  lexer.unlex(t0);
1010
898
  return undefined;
1011
899
  }
1012
900
  function signed_long_int() {
1013
- let t0 = lexer.lex();
901
+ const t0 = lexer.lex();
1014
902
  if (t0 === undefined)
1015
903
  return undefined;
1016
904
  if (t0.type === Type.TKN_LONG)
1017
- return t0;
905
+ return { type: Type.TKN_LONG };
1018
906
  lexer.unlex(t0);
1019
907
  return undefined;
1020
908
  }
1021
909
  function signed_longlong_int() {
1022
- let t0 = lexer.lex();
910
+ const t0 = lexer.lex();
1023
911
  if (t0 !== undefined && t0.type === Type.TKN_LONG) {
1024
- let t1 = lexer.lex();
912
+ const t1 = lexer.lex();
1025
913
  if (t1 !== undefined && t1.type === Type.TKN_LONG) {
1026
- t0.type = Type.SYN_LONGLONG;
1027
- return t0;
914
+ return { type: Type.SYN_LONGLONG };
1028
915
  }
1029
916
  lexer.unlex(t1);
1030
917
  }
@@ -1045,12 +932,11 @@ function unsigned_int() {
1045
932
  return undefined;
1046
933
  }
1047
934
  function unsigned_short_int() {
1048
- let t0 = lexer.lex();
935
+ const t0 = lexer.lex();
1049
936
  if (t0 !== undefined && t0.type === Type.TKN_UNSIGNED) {
1050
- let t1 = lexer.lex();
937
+ const t1 = lexer.lex();
1051
938
  if (t1 !== undefined && t1.type === Type.TKN_SHORT) {
1052
- t0.type = Type.SYN_UNSIGNED_SHORT;
1053
- return t0;
939
+ return { type: Type.SYN_UNSIGNED_SHORT };
1054
940
  }
1055
941
  lexer.unlex(t1);
1056
942
  }
@@ -1058,12 +944,11 @@ function unsigned_short_int() {
1058
944
  return undefined;
1059
945
  }
1060
946
  function unsigned_long_int() {
1061
- let t0 = lexer.lex();
947
+ const t0 = lexer.lex();
1062
948
  if (t0 !== undefined && t0.type === Type.TKN_UNSIGNED) {
1063
- let t1 = lexer.lex();
949
+ const t1 = lexer.lex();
1064
950
  if (t1 !== undefined && t1.type === Type.TKN_LONG) {
1065
- t0.type = Type.SYN_UNSIGNED_LONG;
1066
- return t0;
951
+ return { type: Type.SYN_UNSIGNED_LONG };
1067
952
  }
1068
953
  lexer.unlex(t1);
1069
954
  }
@@ -1071,14 +956,13 @@ function unsigned_long_int() {
1071
956
  return undefined;
1072
957
  }
1073
958
  function unsigned_longlong_int() {
1074
- let t0 = lexer.lex();
959
+ const t0 = lexer.lex();
1075
960
  if (t0 !== undefined && t0.type === Type.TKN_UNSIGNED) {
1076
- let t1 = lexer.lex();
961
+ const t1 = lexer.lex();
1077
962
  if (t1 !== undefined && t1.type === Type.TKN_LONG) {
1078
- let t2 = lexer.lex();
963
+ const t2 = lexer.lex();
1079
964
  if (t2 !== undefined && t2.type === Type.TKN_LONG) {
1080
- t0.type = Type.SYN_UNSIGNED_LONGLONG;
1081
- return t0;
965
+ return { type: Type.SYN_UNSIGNED_LONGLONG };
1082
966
  }
1083
967
  lexer.unlex(t2);
1084
968
  }
@@ -1088,41 +972,42 @@ function unsigned_longlong_int() {
1088
972
  return undefined;
1089
973
  }
1090
974
  function char_type() {
1091
- let t0 = lexer.lex();
975
+ const t0 = lexer.lex();
1092
976
  if (t0 !== undefined && t0.type == Type.TKN_CHAR)
1093
- return t0;
977
+ return { type: Type.TKN_CHAR };
1094
978
  lexer.unlex(t0);
1095
979
  return undefined;
1096
980
  }
1097
981
  function wide_char_type() {
1098
- let t0 = lexer.lex();
982
+ const t0 = lexer.lex();
1099
983
  if (t0 !== undefined && t0.type == Type.TKN_WCHAR)
1100
- return t0;
984
+ return { type: Type.TKN_WCHAR };
1101
985
  lexer.unlex(t0);
1102
986
  return undefined;
1103
987
  }
1104
988
  function boolean_type() {
1105
- let t0 = lexer.lex();
989
+ const t0 = lexer.lex();
1106
990
  if (t0 !== undefined && t0.type == Type.TKN_BOOLEAN)
1107
- return t0;
991
+ return { type: Type.TKN_BOOLEAN };
1108
992
  lexer.unlex(t0);
1109
993
  return undefined;
1110
994
  }
1111
995
  function octet_type() {
1112
- let t0 = lexer.lex();
996
+ const t0 = lexer.lex();
1113
997
  if (t0 !== undefined && t0.type == Type.TKN_OCTET)
1114
- return t0;
998
+ return { type: Type.TKN_OCTET };
1115
999
  lexer.unlex(t0);
1116
1000
  return undefined;
1117
1001
  }
1118
1002
  function any_type() {
1119
1003
  const t0 = lexer.lex();
1120
1004
  if (t0 !== undefined && t0.type == Type.TKN_ANY)
1121
- return t0;
1005
+ return { type: Type.TKN_ANY };
1122
1006
  lexer.unlex(t0);
1123
1007
  return undefined;
1124
1008
  }
1125
1009
  function struct_type() {
1010
+ const doc = docBefore();
1126
1011
  const t0 = lexer.lex();
1127
1012
  if (t0 === undefined || t0.type !== Type.TKN_STRUCT) {
1128
1013
  lexer.unlex(t0);
@@ -1132,71 +1017,63 @@ function struct_type() {
1132
1017
  if (t1 === undefined)
1133
1018
  throw Error("expected identifier after 'struct'");
1134
1019
  expect('{');
1135
- const t2 = member_list();
1136
- if (t2 === undefined)
1020
+ const members = member_list();
1021
+ if (members === undefined)
1137
1022
  throw Error("expected at least one member within 'struct'");
1138
1023
  expect('}');
1139
- t2.type = t0.type;
1140
- t2.text = t1.text;
1141
- scoper.addType(t2.text, t2);
1142
- return t2;
1024
+ const node = { type: Type.TKN_STRUCT, name: t1.text, members, doc };
1025
+ scoper.addType(node.name, node);
1026
+ return node;
1143
1027
  }
1144
1028
  function member_list() {
1145
- const t0 = member();
1146
- if (t0 === undefined)
1147
- return undefined;
1148
- const node = new Node(Type.SYN_MEMBER_LIST);
1149
- node.append(t0);
1029
+ const members = [];
1150
1030
  while (true) {
1151
1031
  const t1 = member();
1152
1032
  if (t1 === undefined)
1153
1033
  break;
1154
- node.append(t1);
1034
+ members.push(t1);
1155
1035
  }
1156
- return node;
1036
+ return members.length > 0 ? members : undefined;
1157
1037
  }
1158
1038
  function member() {
1159
- const node = new Node(Type.SYN_MEMBER);
1039
+ const doc = docBefore();
1160
1040
  const t0 = type_spec();
1161
1041
  if (t0 === undefined)
1162
1042
  return undefined;
1163
- const t1 = declarators();
1164
- if (t1 === undefined)
1165
- throw Error(`expected declarators after type_spec ${t0.toString()}`);
1043
+ const names = declarators();
1044
+ if (names === undefined)
1045
+ throw Error(`expected declarators after type_spec ${describeTypeSpec(t0)}`);
1166
1046
  expect(";");
1167
- node.append(t0);
1168
- node.append(t1);
1169
- return node;
1047
+ return { type: Type.SYN_MEMBER, typeSpec: t0, names, doc };
1170
1048
  }
1171
1049
  function union_type() {
1172
- let t0 = lexer.lex();
1050
+ const doc = docBefore();
1051
+ const t0 = lexer.lex();
1173
1052
  if (t0 === undefined)
1174
1053
  return undefined;
1175
1054
  if (t0.type !== Type.TKN_UNION) {
1176
1055
  lexer.unlex(t0);
1177
1056
  return undefined;
1178
1057
  }
1179
- let t1 = identifier();
1058
+ const t1 = identifier();
1180
1059
  if (t1 === undefined)
1181
1060
  throw Error(`expected identifier after 'union'`);
1182
- let t2 = lexer.lex();
1061
+ const t2 = lexer.lex();
1183
1062
  if (t2 === undefined || t2.type !== Type.TKN_SWITCH) {
1184
1063
  throw Error(`expected 'switch' after union <identifier>`);
1185
1064
  }
1186
1065
  expect("(");
1187
- let t3 = switch_type_spec();
1188
- if (t3 === undefined) {
1066
+ const switchType = switch_type_spec();
1067
+ if (switchType === undefined) {
1189
1068
  throw Error(`expected switch type specifier after union <identifier> switch(`);
1190
1069
  }
1191
1070
  expect(")");
1192
1071
  expect("{");
1193
- let t4 = switch_body();
1072
+ const cases = switch_body();
1194
1073
  expect("}");
1195
- t0.text = t1.text;
1196
- t0.append(t3);
1197
- t0.append(t4);
1198
- scoper.addType(t0.text, t0);
1199
- return t0;
1074
+ const node = { type: Type.TKN_UNION, name: t1.text, switchType, cases, doc };
1075
+ scoper.addType(node.name, node);
1076
+ return node;
1200
1077
  }
1201
1078
  function switch_type_spec() {
1202
1079
  let t0 = integer_type();
@@ -1214,171 +1091,169 @@ function switch_type_spec() {
1214
1091
  return scoped_name();
1215
1092
  }
1216
1093
  function switch_body() {
1217
- let t0 = new Node(Type.SYN_SWITCH_BODY);
1094
+ const cases = [];
1218
1095
  while (true) {
1219
1096
  const t1 = _case();
1220
1097
  if (t1 === undefined)
1221
1098
  break;
1222
- t0.append(t1);
1099
+ cases.push(t1);
1223
1100
  }
1224
- return t0;
1101
+ return cases;
1225
1102
  }
1226
1103
  function _case() {
1227
- let t0 = case_label();
1228
- if (t0 === undefined)
1229
- return t0;
1230
- let t1 = element_spec();
1231
- if (t1 === undefined)
1232
- throw Error(`expected element specification after '${t0}'`);
1233
- t0.append(t1.child[0]);
1234
- t0.append(t1.child[1]);
1104
+ const label = case_label();
1105
+ if (label === undefined)
1106
+ return undefined;
1107
+ const element = element_spec();
1108
+ if (element === undefined)
1109
+ throw Error(`expected element specification after '${label.type === Type.TKN_CASE ? "case" : "default"}'`);
1235
1110
  expect(";");
1236
- return t0;
1111
+ return { ...label, typeSpec: element.typeSpec, name: element.name };
1237
1112
  }
1238
1113
  function case_label() {
1239
- let t0 = lexer.lex();
1114
+ const t0 = lexer.lex();
1240
1115
  if (t0 === undefined)
1241
1116
  return undefined;
1242
1117
  if (t0.type === Type.TKN_CASE) {
1243
- let t1 = identifier();
1118
+ const t1 = identifier();
1244
1119
  if (t1 === undefined) {
1245
1120
  throw Error(`expected enum identifier after 'case'`);
1246
1121
  }
1247
- const t = scoper.getType(t1.text);
1248
- if (t?.typeParent?.type === Type.TKN_ENUM) ;
1249
- else {
1122
+ const target = scoper.getType(t1.text)?.target;
1123
+ if (target === undefined || target.type !== Type.SYN_ENUMERATOR) {
1250
1124
  throw Error(`unsupported value after 'case'`);
1251
1125
  }
1252
1126
  expect(":");
1253
- t0.append(t);
1254
- return t0;
1127
+ return { type: Type.TKN_CASE, label: target };
1255
1128
  }
1256
1129
  if (t0.type === Type.TKN_DEFAULT) {
1257
1130
  expect(":");
1258
- return t0;
1131
+ return { type: Type.TKN_DEFAULT };
1259
1132
  }
1260
1133
  lexer.unlex(t0);
1261
1134
  return undefined;
1262
1135
  }
1263
1136
  function element_spec() {
1264
- let t0 = type_spec();
1137
+ const t0 = type_spec();
1265
1138
  if (t0 === undefined)
1266
1139
  return undefined;
1267
- let t1 = declarator();
1140
+ const t1 = declarator();
1268
1141
  if (t1 === undefined)
1269
- throw Error(`expected declarator after ${t0}`);
1270
- let t2 = new Node(Type.NONE);
1271
- t2.append(t0);
1272
- t2.append(t1);
1273
- return t2;
1142
+ throw Error(`expected declarator after ${describeTypeSpec(t0)}`);
1143
+ return { typeSpec: t0, name: t1.text };
1274
1144
  }
1275
1145
  function enum_type() {
1276
- let t0 = lexer.lex();
1146
+ const doc = docBefore();
1147
+ const t0 = lexer.lex();
1277
1148
  if (t0 !== undefined && t0.type == Type.TKN_ENUM) {
1278
1149
  const t1 = identifier();
1279
1150
  if (t1 === undefined)
1280
1151
  throw Error("expected identifier after 'enum'");
1281
- t0.text = t1.text;
1152
+ const node = { type: Type.TKN_ENUM, name: t1.text, enumerators: [], doc };
1282
1153
  expect("{");
1283
1154
  const usedNames = new Set();
1284
1155
  let t3;
1285
1156
  while (true) {
1286
- let t2 = lexer.lex();
1157
+ const t2 = lexer.lex();
1287
1158
  if (t2 === undefined) {
1288
1159
  throw Error("unexpected end of file");
1289
1160
  }
1290
1161
  if (t2.type !== Type.TKN_IDENTIFIER) {
1291
1162
  if (t3) {
1292
- throw Error(`expected identifier after ',' but got ${t2})`);
1163
+ throw Error(`expected identifier after ',' but got ${describeToken(t2)})`);
1293
1164
  }
1294
1165
  else {
1295
- throw Error(`expected identifier but got ${t2})`);
1166
+ throw Error(`expected identifier but got ${describeToken(t2)})`);
1296
1167
  }
1297
1168
  }
1298
1169
  if (usedNames.has(t2.text)) {
1299
1170
  throw Error(`Declaration of enumerator '${t2.text}' clashes with earlier declaration of enumerator '${t2.text}'`);
1300
1171
  }
1301
1172
  usedNames.add(t2.text);
1302
- scoper.addType(t2.text, t2);
1303
- t0.append(t2);
1304
- t2.typeParent = t0;
1173
+ const enumerator = { type: Type.SYN_ENUMERATOR, name: t2.text, enum: node, doc: t2.doc };
1174
+ scoper.addType(enumerator.name, enumerator);
1175
+ node.enumerators.push(enumerator);
1305
1176
  t3 = lexer.lex();
1306
1177
  if (t3 === undefined)
1307
1178
  throw Error("unexpected end of file");
1308
1179
  if (t3.type !== Type.TKN_TEXT)
1309
- throw Error(`expected ',' or '}' but got ${t3}`);
1180
+ throw Error(`expected ',' or '}' but got ${describeToken(t3)}`);
1310
1181
  if (t3.text === "}")
1311
1182
  break;
1312
1183
  if (t3.text !== ",") {
1313
- throw Error(`expected ',' or '}' but got ${t3}`);
1184
+ throw Error(`expected ',' or '}' but got ${describeToken(t3)}`);
1314
1185
  }
1315
1186
  }
1316
- scoper.addType(t0.text, t0);
1317
- return t0;
1187
+ scoper.addType(node.name, node);
1188
+ return node;
1318
1189
  }
1319
1190
  lexer.unlex(t0);
1320
1191
  return undefined;
1321
1192
  }
1322
1193
  function sequence_type() {
1323
- let t0 = lexer.lex();
1194
+ const t0 = lexer.lex();
1324
1195
  if (t0 !== undefined && t0.type === Type.TKN_SEQUENCE) {
1325
1196
  expect("<");
1326
- let t1 = simple_type_spec();
1327
- if (t1 === undefined)
1197
+ const elementType = simple_type_spec();
1198
+ if (elementType === undefined)
1328
1199
  throw Error("expected type after 'sequence <'");
1329
1200
  expect(">");
1330
- t0.append(t1);
1331
- t0.append(undefined);
1332
- return t0;
1201
+ return { type: Type.TKN_SEQUENCE, elementType };
1333
1202
  }
1334
1203
  lexer.unlex(t0);
1335
1204
  return undefined;
1336
1205
  }
1337
1206
  function string_type() {
1338
- let t0 = lexer.lex();
1207
+ const t0 = lexer.lex();
1339
1208
  if (t0 !== undefined && t0.type === Type.TKN_STRING) {
1340
- return t0;
1209
+ return { type: Type.TKN_STRING };
1341
1210
  }
1342
1211
  lexer.unlex(t0);
1343
1212
  return undefined;
1344
1213
  }
1345
1214
  function wide_string_type() {
1346
- let t0 = lexer.lex();
1215
+ const t0 = lexer.lex();
1347
1216
  if (t0 !== undefined && t0.type === Type.TKN_WSTRING) {
1348
- return t0;
1217
+ return { type: Type.TKN_WSTRING };
1349
1218
  }
1350
1219
  lexer.unlex(t0);
1351
1220
  return undefined;
1352
1221
  }
1353
1222
  function attr_dcl() {
1223
+ const doc = docBefore();
1354
1224
  let t0;
1355
1225
  t0 = readonly_attr_spec();
1356
1226
  if (t0 === undefined)
1357
1227
  t0 = attr_spec();
1228
+ if (t0 !== undefined)
1229
+ t0.doc = doc;
1358
1230
  return t0;
1359
1231
  }
1360
1232
  function except_dcl() {
1361
- let t0 = lexer.lex();
1233
+ const doc = docBefore();
1234
+ const t0 = lexer.lex();
1362
1235
  if (t0 === undefined || t0.type != Type.TKN_EXCEPTION) {
1363
1236
  lexer.unlex(t0);
1364
1237
  return undefined;
1365
1238
  }
1366
- let t1 = identifier();
1239
+ const t1 = identifier();
1367
1240
  if (t1 === undefined)
1368
- throw Error(`expected identifier after '${t0.toString()}'`);
1369
- t0.text = t1.text;
1241
+ throw Error(`expected identifier after '${describeToken(t0)}'`);
1370
1242
  expect("{");
1243
+ const members = [];
1371
1244
  while (true) {
1372
- let t2 = member();
1245
+ const t2 = member();
1373
1246
  if (t2 === undefined)
1374
1247
  break;
1375
- t0.append(t2);
1248
+ members.push(t2);
1376
1249
  }
1377
1250
  expect("}");
1378
- scoper.addType(t0.text, t0);
1379
- return t0;
1251
+ const node = { type: Type.TKN_EXCEPTION, name: t1.text, members, doc };
1252
+ scoper.addType(node.name, node);
1253
+ return node;
1380
1254
  }
1381
1255
  function op_dcl() {
1256
+ const doc = docBefore();
1382
1257
  const node_attribute = op_attribute();
1383
1258
  const node_type = op_type_spec();
1384
1259
  if (node_type === undefined) {
@@ -1387,30 +1262,32 @@ function op_dcl() {
1387
1262
  }
1388
1263
  const node_identifier = identifier();
1389
1264
  if (node_identifier === undefined) {
1390
- throw Error(`expected identifier after '${node_type.toString()}'`);
1265
+ throw Error(`expected identifier after '${describeTypeSpec(node_type)}'`);
1391
1266
  }
1392
1267
  const node_parameter_dcls = parameter_dcls();
1393
1268
  if (node_parameter_dcls === undefined) {
1394
1269
  lexer.unlex(node_identifier);
1395
- if (node_type.child.length != 0) {
1396
- throw Error("expected parameter declaration after " + node_identifier.toString());
1270
+ if (node_type.type === Type.SYN_SCOPED_NAME || node_type.type === Type.TKN_SEQUENCE
1271
+ || node_type.type === Type.TKN_STRUCT || node_type.type === Type.TKN_UNION || node_type.type === Type.TKN_ENUM) {
1272
+ throw Error("expected parameter declaration after " + describeToken(node_identifier));
1397
1273
  }
1398
- lexer.unlex(node_type);
1274
+ lexer.unlex({ type: node_type.type });
1399
1275
  lexer.unlex(node_attribute);
1400
1276
  return undefined;
1401
1277
  }
1402
- const t4 = raises_expr();
1403
- let node = new Node(Type.SYN_OPERATION_DECLARATION);
1404
- node.append(node_attribute);
1405
- node.append(node_type);
1406
- node.append(node_identifier);
1407
- node.append(node_parameter_dcls);
1408
- node.append(t4);
1409
- node.append(undefined);
1410
- return node;
1278
+ const raises = raises_expr() ?? [];
1279
+ return {
1280
+ type: Type.SYN_OPERATION_DECLARATION,
1281
+ oneway: node_attribute !== undefined,
1282
+ returnType: node_type,
1283
+ name: node_identifier.text,
1284
+ params: node_parameter_dcls,
1285
+ raises,
1286
+ doc
1287
+ };
1411
1288
  }
1412
1289
  function op_attribute() {
1413
- let t0 = lexer.lex();
1290
+ const t0 = lexer.lex();
1414
1291
  if (!t0)
1415
1292
  return undefined;
1416
1293
  if (t0.type !== Type.TKN_ONEWAY) {
@@ -1420,18 +1297,18 @@ function op_attribute() {
1420
1297
  return t0;
1421
1298
  }
1422
1299
  function op_type_spec() {
1423
- let t0 = param_type_spec();
1300
+ const t0 = param_type_spec();
1424
1301
  if (t0 !== undefined) {
1425
1302
  return t0;
1426
1303
  }
1427
- t0 = lexer.lex();
1428
- if (t0 !== undefined && t0.type === Type.TKN_VOID)
1429
- return t0;
1430
- lexer.unlex(t0);
1304
+ const t1 = lexer.lex();
1305
+ if (t1 !== undefined && t1.type === Type.TKN_VOID)
1306
+ return { type: Type.TKN_VOID };
1307
+ lexer.unlex(t1);
1431
1308
  return undefined;
1432
1309
  }
1433
1310
  function parameter_dcls() {
1434
- let t0 = lexer.lex();
1311
+ const t0 = lexer.lex();
1435
1312
  if (!t0) {
1436
1313
  return undefined;
1437
1314
  }
@@ -1439,12 +1316,12 @@ function parameter_dcls() {
1439
1316
  lexer.unlex(t0);
1440
1317
  return undefined;
1441
1318
  }
1442
- let declarations = new Node(Type.SYN_PARAMETER_DECLARATIONS);
1319
+ const declarations = [];
1443
1320
  while (true) {
1444
- let t1 = param_dcl();
1321
+ const t1 = param_dcl();
1445
1322
  if (t1 !== undefined)
1446
- declarations.append(t1);
1447
- let t2 = lexer.lex();
1323
+ declarations.push(t1);
1324
+ const t2 = lexer.lex();
1448
1325
  if (t2 !== undefined && t2.type === Type.TKN_TEXT && t2.text === ')') {
1449
1326
  break;
1450
1327
  }
@@ -1452,169 +1329,124 @@ function parameter_dcls() {
1452
1329
  continue;
1453
1330
  }
1454
1331
  if (t2 !== undefined)
1455
- throw Error("expected 'in', 'out', 'inout' or ')' to end for parameter declaration but got " + t2.toString());
1332
+ throw Error("expected 'in', 'out', 'inout' or ')' to end for parameter declaration but got " + describeToken(t2));
1456
1333
  else
1457
1334
  throw Error("expected 'in', 'out', 'inout' or ')' to end for parameter declaration but end of file");
1458
1335
  }
1459
1336
  return declarations;
1460
1337
  }
1461
1338
  function param_dcl() {
1462
- let annotation = annotation_appl();
1463
- let t0 = param_attribute();
1464
- if (t0 === undefined)
1339
+ const doc = docBefore();
1340
+ const annotation = annotation_appl();
1341
+ const attribute = param_attribute();
1342
+ if (attribute === undefined)
1465
1343
  return undefined;
1466
- let t1 = param_type_spec();
1467
- if (t1 === undefined) {
1468
- t1 = lexer.lex();
1344
+ const typeSpec = param_type_spec();
1345
+ if (typeSpec === undefined) {
1346
+ const t1 = lexer.lex();
1469
1347
  if (t1 !== undefined)
1470
- throw Error("expected type specification but got " + t1.toString());
1348
+ throw Error("expected type specification but got " + describeToken(t1));
1471
1349
  else
1472
1350
  throw Error("expected type specification but found end of file");
1473
1351
  }
1474
- let t2 = simple_declarator();
1352
+ const t2 = simple_declarator();
1475
1353
  if (t2 === undefined) {
1476
1354
  throw Error("Missing parameter name.");
1477
1355
  }
1478
- let declaration = new Node(Type.SYN_PARAMETER_DECLARATION);
1479
- declaration.append(t0);
1480
- declaration.append(t1);
1481
- declaration.append(t2);
1482
- if (annotation) {
1483
- t1.append(annotation);
1356
+ if (annotation !== undefined && typeSpec.type === Type.TKN_SEQUENCE) {
1357
+ typeSpec.annotation = annotation;
1484
1358
  }
1485
- return declaration;
1359
+ return { type: Type.SYN_PARAMETER_DECLARATION, attribute, typeSpec, name: t2.text, annotation, doc };
1486
1360
  }
1487
1361
  function param_attribute() {
1488
- let t0 = lexer.lex();
1362
+ const t0 = lexer.lex();
1489
1363
  if (t0 === undefined)
1490
1364
  return undefined;
1491
1365
  switch (t0.type) {
1492
1366
  case Type.TKN_IN:
1493
1367
  case Type.TKN_OUT:
1494
1368
  case Type.TKN_INOUT:
1495
- return t0;
1369
+ return t0.type;
1496
1370
  }
1497
1371
  lexer.unlex(t0);
1498
1372
  return undefined;
1499
1373
  }
1500
1374
  function raises_expr() {
1501
- let t0 = lexer.lex();
1375
+ const t0 = lexer.lex();
1502
1376
  if (t0 === undefined || t0.type !== Type.TKN_RAISES) {
1503
1377
  lexer.unlex(t0);
1504
1378
  return undefined;
1505
1379
  }
1506
1380
  expect("(");
1507
- let t1 = scoped_name();
1381
+ const raises = [];
1382
+ const t1 = scoped_name();
1508
1383
  if (t1 === undefined)
1509
1384
  throw Error(`expected exception name after 'raises('`);
1510
- if (t1.child[0] === undefined || t1.child[0].type !== Type.TKN_EXCEPTION)
1511
- throw Error(`expected ${t1.toString()} to be an exception`);
1512
- if (t1.type)
1513
- t0.append(t1);
1385
+ if (t1.target.type !== Type.TKN_EXCEPTION)
1386
+ throw Error(`expected ${t1.name} to be an exception`);
1387
+ raises.push(t1);
1514
1388
  while (true) {
1515
- let t2 = lexer.lex();
1516
- if (t2 === undefined || t2.type !== Type.TKN_TEXT || t0.text !== ",") {
1389
+ const t2 = lexer.lex();
1390
+ if (t2 === undefined || t2.type !== Type.TKN_TEXT || t2.text !== ",") {
1517
1391
  lexer.unlex(t2);
1518
1392
  break;
1519
1393
  }
1520
- t1 = scoped_name();
1521
- if (t1 === undefined)
1394
+ const t3 = scoped_name();
1395
+ if (t3 === undefined)
1522
1396
  throw Error(`expected exception name after 'raises(..., '`);
1523
- if (t1.child[0] === undefined || t1.child[0].type !== Type.TKN_EXCEPTION)
1524
- throw Error(`expected ${t1.toString()} to be an exception`);
1525
- t0.append(t1);
1397
+ if (t3.target.type !== Type.TKN_EXCEPTION)
1398
+ throw Error(`expected ${t3.name} to be an exception`);
1399
+ raises.push(t3);
1526
1400
  }
1527
1401
  expect(")");
1528
- return t0;
1402
+ return raises;
1529
1403
  }
1530
1404
  function param_type_spec() {
1531
- let t0;
1532
1405
  const annotation = annotation_appl();
1533
- t0 = base_type_spec();
1406
+ let t0 = base_type_spec();
1534
1407
  if (t0 === undefined)
1535
1408
  t0 = template_type_spec();
1536
1409
  if (t0 === undefined)
1537
1410
  t0 = scoped_name();
1538
- if (t0 !== undefined && annotation) {
1539
- t0.append(annotation);
1411
+ if (t0 !== undefined && annotation !== undefined && t0.type === Type.TKN_SEQUENCE) {
1412
+ t0.annotation = annotation;
1540
1413
  }
1541
1414
  return t0;
1542
1415
  }
1543
1416
  function readonly_attr_spec() {
1544
- let t0 = lexer.lex();
1417
+ const t0 = lexer.lex();
1545
1418
  if (t0 !== undefined && t0.type === Type.TKN_READONLY) {
1546
- let t1 = lexer.lex();
1419
+ const t1 = lexer.lex();
1547
1420
  if (t1 !== undefined && t1.type === Type.TKN_ATTRIBUTE) {
1548
- let t2 = param_type_spec();
1549
- if (t2 === undefined)
1421
+ const typeSpec = param_type_spec();
1422
+ if (typeSpec === undefined)
1550
1423
  throw Error("expected type specifier after 'readonly attribute'");
1551
- let t3 = readonly_attr_declarator();
1552
- if (t3 === undefined)
1424
+ const names = declarators();
1425
+ if (names === undefined)
1553
1426
  throw Error("expected declarator for 'readonly attribute'");
1554
- t1.append(t0);
1555
- t1.append(t2);
1556
- t1.append(t3);
1557
- return t1;
1427
+ return { type: Type.TKN_ATTRIBUTE, readonly: true, typeSpec, names };
1558
1428
  }
1559
1429
  lexer.unlex(t1);
1560
1430
  }
1561
1431
  lexer.unlex(t0);
1562
1432
  return undefined;
1563
1433
  }
1564
- function readonly_attr_declarator() {
1565
- let t0 = simple_declarator();
1566
- if (t0 === undefined)
1567
- return undefined;
1568
- let node = new Node(Type.SYN_DECLARATORS);
1569
- while (true) {
1570
- node.append(t0);
1571
- let t1 = lexer.lex();
1572
- if (t1 === undefined || t1.type !== Type.TKN_TEXT || t1.text !== ",") {
1573
- lexer.unlex(t1);
1574
- return node;
1575
- }
1576
- t0 = simple_declarator();
1577
- if (t0 === undefined)
1578
- throw Error("expected another declarator after ','");
1579
- }
1580
- }
1581
1434
  function attr_spec() {
1582
- let t0 = lexer.lex();
1435
+ const t0 = lexer.lex();
1583
1436
  if (t0 !== undefined && t0.type === Type.TKN_ATTRIBUTE) {
1584
- let t1 = param_type_spec();
1585
- if (t1 === undefined)
1437
+ const typeSpec = param_type_spec();
1438
+ if (typeSpec === undefined)
1586
1439
  throw Error("expected type specifier after 'attribute'");
1587
- let t2 = attr_declarator();
1588
- if (t2 === undefined)
1440
+ const names = declarators();
1441
+ if (names === undefined)
1589
1442
  throw Error("expected declarator for 'attribute'");
1590
- t0.append(undefined);
1591
- t0.append(t1);
1592
- t0.append(t2);
1593
- return t0;
1443
+ return { type: Type.TKN_ATTRIBUTE, readonly: false, typeSpec, names };
1594
1444
  }
1595
1445
  lexer.unlex(t0);
1596
1446
  return undefined;
1597
1447
  }
1598
- function attr_declarator() {
1599
- let t0 = simple_declarator();
1600
- if (t0 === undefined)
1601
- return undefined;
1602
- let node = new Node(Type.SYN_DECLARATORS);
1603
- while (true) {
1604
- node.append(t0);
1605
- let t1 = lexer.lex();
1606
- if (t1 === undefined || t1.type !== Type.TKN_TEXT || t1.text !== ",") {
1607
- lexer.unlex(t1);
1608
- return node;
1609
- }
1610
- t0 = simple_declarator();
1611
- if (t0 === undefined) {
1612
- throw Error("expected another declarator after ','");
1613
- }
1614
- }
1615
- }
1616
1448
  function annotation_appl() {
1617
- let t0 = lexer.lex();
1449
+ const t0 = lexer.lex();
1618
1450
  if (t0?.text !== "@") {
1619
1451
  lexer.unlex(t0);
1620
1452
  return undefined;
@@ -1624,20 +1456,14 @@ function annotation_appl() {
1624
1456
  throw Error("expeced identifier after @");
1625
1457
  }
1626
1458
  expect("(");
1627
- const t3 = annotation_appl_params();
1459
+ const params = annotation_appl_params();
1628
1460
  expect(")");
1629
- t1.append(t3);
1630
- t1.type = Type.SYN_ANNOTAION;
1631
- return t1;
1461
+ return { type: Type.SYN_ANNOTAION, name: t1.text, params };
1632
1462
  }
1633
1463
  function annotation_appl_params() {
1634
- const params = new Node(Type.SYN_PARAMETER_DECLARATIONS);
1464
+ const params = [];
1635
1465
  while (true) {
1636
- const param = annotation_appl_param();
1637
- if (param === undefined) {
1638
- break;
1639
- }
1640
- params.append(param);
1466
+ params.push(annotation_appl_param());
1641
1467
  const t1 = lexer.lex();
1642
1468
  if (t1?.text !== ',') {
1643
1469
  lexer.unlex(t1);
@@ -1656,22 +1482,74 @@ function annotation_appl_param() {
1656
1482
  if (val === undefined) {
1657
1483
  throw Error(`expected value`);
1658
1484
  }
1659
- id.append(val);
1660
- return id;
1485
+ return { name: id.text, value: val.text };
1486
+ }
1487
+ function docBefore() {
1488
+ const t = lexer.lex();
1489
+ lexer.unlex(t);
1490
+ return t?.doc;
1661
1491
  }
1662
1492
  function identifier() {
1663
- let t0 = lexer.lex();
1493
+ const t0 = lexer.lex();
1664
1494
  if (t0 !== undefined && t0.type === Type.TKN_IDENTIFIER) {
1665
1495
  return t0;
1666
1496
  }
1667
1497
  lexer.unlex(t0);
1668
1498
  return undefined;
1669
1499
  }
1500
+ function describeTypeSpec(typeSpec) {
1501
+ if (typeSpec.type === Type.SYN_SCOPED_NAME)
1502
+ return `identifier '${typeSpec.name}'`;
1503
+ return describeToken({ type: typeSpec.type });
1504
+ }
1505
+ function resolve_module_separator(name) {
1506
+ const paamayimNekudotayim = lexer.lex();
1507
+ if (paamayimNekudotayim === undefined || paamayimNekudotayim.type !== Type.TKN_COLON_COLON)
1508
+ throw Error(`Expected :: after module identifier '${name}'`);
1509
+ }
1510
+ function find_in_module(module, name) {
1511
+ for (const child of module.definitions) {
1512
+ switch (child.type) {
1513
+ case Type.TKN_MODULE:
1514
+ case Type.TKN_NATIVE:
1515
+ case Type.TKN_VALUETYPE:
1516
+ case Type.SYN_INTERFACE:
1517
+ case Type.TKN_STRUCT:
1518
+ case Type.TKN_UNION:
1519
+ case Type.TKN_ENUM:
1520
+ case Type.TKN_EXCEPTION:
1521
+ if (child.name === name)
1522
+ return child;
1523
+ break;
1524
+ case Type.TKN_TYPEDEF:
1525
+ if (child.names.includes(name))
1526
+ return child.typeSpec;
1527
+ break;
1528
+ }
1529
+ }
1530
+ return undefined;
1531
+ }
1532
+ function resolve_native_ptr(native, scope) {
1533
+ if (scope !== undefined || native.ptrTarget !== undefined)
1534
+ return;
1535
+ if (native.name.length <= 4 || native.name.substring(native.name.length - 4) !== "_ptr")
1536
+ return;
1537
+ const stem = native.name.substring(0, native.name.length - 4);
1538
+ const referenced = scoper.getType(stem);
1539
+ if (referenced === undefined || referenced.target.type === Type.SYN_ENUMERATOR)
1540
+ return;
1541
+ native.ptrTarget = makeScopedName(stem, [], referenced);
1542
+ }
1543
+ function makeScopedName(name, path, entry) {
1544
+ if (entry.target.type === Type.SYN_ENUMERATOR)
1545
+ throw Error(`enumerator '${name}' can not be used as a type`);
1546
+ return { type: Type.SYN_SCOPED_NAME, name, path, scope: entry.scope, target: entry.target };
1547
+ }
1670
1548
  function expect(text, customMessage) {
1671
- let t0 = lexer.lex();
1549
+ const t0 = lexer.lex();
1672
1550
  let errorMessage;
1673
1551
  {
1674
- errorMessage = `expected '${text}' but got '${t0?.toString()}'`;
1552
+ errorMessage = `expected '${text}' but got '${describeToken(t0)}'`;
1675
1553
  }
1676
1554
  if (t0 === undefined) {
1677
1555
  throw Error(errorMessage + " but found end of file");
@@ -1684,13 +1562,11 @@ class Scope {
1684
1562
  constructor(node) {
1685
1563
  this.node = node;
1686
1564
  this.types = new Map();
1687
- this.modules = new Map();
1688
1565
  }
1689
- addType(name, type) {
1566
+ addType(name, target) {
1690
1567
  if (this.types.has(name))
1691
1568
  throw Error("duplicate typename '" + name + "'");
1692
- this.types.set(name, type);
1693
- type.typeParent = this.node;
1569
+ this.types.set(name, { target, scope: this.node });
1694
1570
  }
1695
1571
  getType(name) {
1696
1572
  return this.types.get(name);
@@ -1712,117 +1588,73 @@ class ScopeManager {
1712
1588
  }
1713
1589
  getType(name) {
1714
1590
  for (let i = this.stack.length - 1; i >= 0; --i) {
1715
- let type = this.stack[i].getType(name);
1591
+ const type = this.stack[i].getType(name);
1716
1592
  if (type !== undefined)
1717
1593
  return type;
1718
1594
  }
1719
1595
  return undefined;
1720
1596
  }
1721
1597
  enterModule(node) {
1722
- this.getCurrentScope().addType(node.text, node);
1598
+ this.getCurrentScope().addType(node.name, node);
1723
1599
  this.stack.push(new Scope(node));
1724
1600
  }
1725
- leaveModule(node) {
1601
+ leaveModule() {
1726
1602
  this.stack.pop();
1727
1603
  }
1728
1604
  }
1729
- function resolve_module(identifierToken, module) {
1730
- const paamayimNekudotayim = lexer.lex();
1731
- if (paamayimNekudotayim === undefined || paamayimNekudotayim.type !== Type.TKN_COLON_COLON)
1732
- throw Error(`Expected :: after module identifier '${identifierToken.text}'`);
1733
- const identifier = lexer.lex();
1734
- if (identifier === undefined || identifier.type !== Type.TKN_IDENTIFIER)
1735
- throw Error(`Expected identifier after ::'`);
1736
- for (let child of module.child) {
1737
- switch (child?.type) {
1738
- case Type.TKN_MODULE:
1739
- if (child.text === identifier.text) {
1740
- identifierToken.append(child);
1741
- resolve_module(identifierToken, child);
1742
- return;
1743
- }
1744
- break;
1745
- case Type.TKN_NATIVE:
1746
- case Type.TKN_VALUETYPE:
1747
- if (child.text === identifier.text) {
1748
- identifierToken.append(child);
1749
- return;
1750
- }
1751
- break;
1752
- case Type.SYN_INTERFACE:
1753
- if (child.child[0].child[1].text === identifier.text) {
1754
- identifierToken.append(child);
1755
- return;
1756
- }
1757
- break;
1758
- }
1759
- }
1760
- throw Error(`failed to lookup ${identifier.text}`);
1761
- }
1762
1605
 
1763
1606
  function typeIDLtoTS(type, filetype = FileType.NONE) {
1764
1607
  if (type === undefined)
1765
1608
  throw Error("internal error: parser delivered no type information");
1766
1609
  switch (type.type) {
1767
- case Type.TKN_IDENTIFIER:
1768
- {
1769
- let identifierType = type.child[type.child.length - 1];
1770
- let relativeName = "";
1771
- for (let x of type.child) {
1772
- if (x === undefined) {
1773
- type.printTree();
1774
- throw Error("undefined child unexpected");
1610
+ case Type.SYN_SCOPED_NAME: {
1611
+ const target = type.target;
1612
+ const relativeName = [...type.path.map(module => module.name), "name" in target ? target.name : undefined].join(".");
1613
+ if (target.type === Type.TKN_NATIVE &&
1614
+ type.path.length === 0 &&
1615
+ isPointerName(type.name)) {
1616
+ const ptrTarget = target.ptrTarget;
1617
+ const absoluteName = ptrTarget === undefined ? "" : `${scopePrefix(ptrTarget.scope)}.${ptrTarget.name}`;
1618
+ return `${absoluteName.substring(1)} | undefined`;
1619
+ }
1620
+ const absolutePrefix = scopePrefix(type.path.length > 0 ? type.path[0].parent : type.scope);
1621
+ let name;
1622
+ switch (target.type) {
1623
+ case Type.TKN_VALUETYPE:
1624
+ if (filetype !== FileType.VALUETYPE && filetype !== FileType.VALUE) {
1625
+ name = `valuetype${absolutePrefix}.${relativeName}`;
1775
1626
  }
1776
- relativeName = `${relativeName}.${x.text}`;
1777
- }
1778
- relativeName = relativeName.substring(1);
1779
- let absolutePrefix = "";
1780
- for (let x = type.child[0]?.typeParent; x; x = x.typeParent) {
1781
- absolutePrefix = `.${x.text}${absolutePrefix}`;
1782
- }
1783
- if (type.child.length > 0 &&
1784
- type.child[0].type === Type.TKN_NATIVE &&
1785
- type.text.length > 4 &&
1786
- type.text.substring(type.text.length - 4) === "_ptr") {
1787
- return `${absolutePrefix.substring(1)} | undefined`;
1788
- }
1789
- let name;
1790
- switch (identifierType.type) {
1791
- case Type.TKN_VALUETYPE:
1792
- if (filetype !== FileType.VALUETYPE && filetype !== FileType.VALUE) {
1793
- name = `valuetype${absolutePrefix}.${relativeName}`;
1794
- }
1795
- else {
1796
- name = absolutePrefix.length == 0 ? relativeName : `${absolutePrefix.substring(1)}.${relativeName}`;
1797
- }
1798
- break;
1799
- case Type.SYN_INTERFACE:
1800
- case Type.TKN_ENUM:
1801
- case Type.TKN_UNION:
1802
- if (filetype !== FileType.INTERFACE) {
1803
- name = `_interface${absolutePrefix}.${relativeName}`;
1804
- }
1805
- else {
1806
- name = absolutePrefix.length == 0 ? relativeName : `${absolutePrefix.substring(1)}.${relativeName}`;
1807
- }
1808
- break;
1809
- case Type.TKN_STRUCT:
1810
- name = type.text;
1811
- if (filetype !== FileType.INTERFACE) {
1812
- name = `_interface${absolutePrefix}.${name}`;
1813
- }
1814
- break;
1815
- case Type.TKN_NATIVE:
1627
+ else {
1816
1628
  name = absolutePrefix.length == 0 ? relativeName : `${absolutePrefix.substring(1)}.${relativeName}`;
1817
- break;
1818
- case Type.TKN_SEQUENCE:
1819
- name = typeIDLtoTS(type.child[0], filetype);
1820
- break;
1821
- default:
1822
- throw Error(`Internal Error in typeIDLtoTS(): type ${identifierType.toString()} is not implemented`);
1823
- }
1824
- return name;
1629
+ }
1630
+ break;
1631
+ case Type.SYN_INTERFACE:
1632
+ case Type.TKN_ENUM:
1633
+ case Type.TKN_UNION:
1634
+ if (filetype !== FileType.INTERFACE) {
1635
+ name = `_interface${absolutePrefix}.${relativeName}`;
1636
+ }
1637
+ else {
1638
+ name = absolutePrefix.length == 0 ? relativeName : `${absolutePrefix.substring(1)}.${relativeName}`;
1639
+ }
1640
+ break;
1641
+ case Type.TKN_STRUCT:
1642
+ name = relativeName;
1643
+ if (filetype !== FileType.INTERFACE) {
1644
+ name = `_interface${absolutePrefix}.${name}`;
1645
+ }
1646
+ break;
1647
+ case Type.TKN_NATIVE:
1648
+ name = absolutePrefix.length == 0 ? relativeName : `${absolutePrefix.substring(1)}.${relativeName}`;
1649
+ break;
1650
+ case Type.TKN_SEQUENCE:
1651
+ name = typeIDLtoTS(target, filetype);
1652
+ break;
1653
+ default:
1654
+ return typeIDLtoTS(target, filetype);
1825
1655
  }
1656
+ return name;
1657
+ }
1826
1658
  case Type.TKN_VOID:
1827
1659
  return "void";
1828
1660
  case Type.TKN_BOOLEAN:
@@ -1842,19 +1674,15 @@ function typeIDLtoTS(type, filetype = FileType.NONE) {
1842
1674
  case Type.SYN_LONGLONG:
1843
1675
  case Type.SYN_UNSIGNED_LONGLONG:
1844
1676
  return "bigint";
1845
- case Type.TKN_SEQUENCE:
1677
+ case Type.TKN_SEQUENCE: {
1846
1678
  let specialType;
1847
- if (type.child[2]?.type === Type.SYN_ANNOTAION) {
1848
- const annotation = type.child[2];
1849
- if (annotation.text === "js_mapping") {
1850
- if (annotation.child[0]?.child[0]?.text === "type") {
1851
- specialType = annotation.child[0]?.child[0]?.child[0]?.text;
1852
- }
1853
- }
1679
+ const annotation = type.annotation;
1680
+ if (annotation?.name === "js_mapping" && annotation.params[0]?.name === "type") {
1681
+ specialType = annotation.params[0].value;
1854
1682
  }
1855
1683
  if (specialType) {
1856
1684
  let typedArray;
1857
- switch (type.child[0].type) {
1685
+ switch (type.elementType.type) {
1858
1686
  case Type.TKN_OCTET:
1859
1687
  typedArray = "Uint8Array";
1860
1688
  break;
@@ -1870,9 +1698,10 @@ function typeIDLtoTS(type, filetype = FileType.NONE) {
1870
1698
  }
1871
1699
  return typedArray;
1872
1700
  }
1873
- return `Array<${typeIDLtoTS(type.child[0], filetype)}>`;
1701
+ return `Array<${typeIDLtoTS(type.elementType, filetype)}>`;
1702
+ }
1874
1703
  default:
1875
- throw Error(`no mapping from IDL type to TS type for ${type.toString()}`);
1704
+ throw Error(`no mapping from IDL type to TS type for ${Type[type.type]}`);
1876
1705
  }
1877
1706
  }
1878
1707
 
@@ -1893,6 +1722,32 @@ function writeIndent(out, indent) {
1893
1722
  for (let i = 0; i < indent; ++i)
1894
1723
  out.write(" ");
1895
1724
  }
1725
+ function operationDoc(op) {
1726
+ const params = [];
1727
+ for (const param of op.params) {
1728
+ if (param.doc === undefined || param.doc.length === 0)
1729
+ continue;
1730
+ const [first, ...rest] = param.doc;
1731
+ params.push(`@param ${param.name} ${first}`.trimEnd(), ...rest);
1732
+ }
1733
+ if (params.length === 0)
1734
+ return op.doc;
1735
+ if (op.doc === undefined || op.doc.length === 0)
1736
+ return params;
1737
+ return [...op.doc, "", ...params];
1738
+ }
1739
+ function writeDoc(out, doc, indent) {
1740
+ if (doc === undefined || doc.length === 0)
1741
+ return;
1742
+ writeIndent(out, indent);
1743
+ out.write("/**\n");
1744
+ for (const line of doc) {
1745
+ writeIndent(out, indent);
1746
+ out.write(line === "" ? " *\n" : ` * ${line.replace(/\*\//g, "*\\/")}\n`);
1747
+ }
1748
+ writeIndent(out, indent);
1749
+ out.write(" */\n");
1750
+ }
1896
1751
  var FileType;
1897
1752
  (function (FileType) {
1898
1753
  FileType[FileType["NONE"] = 0] = "NONE";
@@ -1903,12 +1758,49 @@ var FileType;
1903
1758
  FileType[FileType["SKELETON"] = 5] = "SKELETON";
1904
1759
  FileType[FileType["STUB"] = 6] = "STUB";
1905
1760
  })(FileType || (FileType = {}));
1761
+ function writtenName(name) {
1762
+ return [...name.path.map(module => module.name), name.name].join(".");
1763
+ }
1764
+ function resolvedTarget(name) {
1765
+ let target = name.target;
1766
+ while (target.type === Type.SYN_SCOPED_NAME)
1767
+ target = target.target;
1768
+ return target;
1769
+ }
1770
+ const predefinedTypes = [
1771
+ Type.TKN_FLOAT, Type.TKN_DOUBLE, Type.SYN_LONG_DOUBLE,
1772
+ Type.TKN_SHORT, Type.TKN_LONG, Type.SYN_LONGLONG,
1773
+ Type.SYN_UNSIGNED_SHORT, Type.SYN_UNSIGNED_LONG, Type.SYN_UNSIGNED_LONGLONG,
1774
+ Type.TKN_CHAR, Type.TKN_WCHAR, Type.TKN_BOOLEAN, Type.TKN_OCTET, Type.TKN_ANY,
1775
+ Type.TKN_STRING, Type.TKN_WSTRING
1776
+ ];
1777
+ function isPointerName(name) {
1778
+ return name.length > 4 && name.substring(name.length - 4) === "_ptr";
1779
+ }
1780
+ function scopePrefix(scope) {
1781
+ let prefix = "";
1782
+ for (let x = scope; x; x = x.parent)
1783
+ prefix = `.${x.name}${prefix}`;
1784
+ return prefix;
1785
+ }
1906
1786
  function defaultValueIDLtoTS(type, filetype = FileType.NONE) {
1907
1787
  if (type === undefined)
1908
1788
  throw Error("internal error: parser delivered no type information");
1909
1789
  switch (type.type) {
1910
- case Type.TKN_IDENTIFIER:
1911
- return "new " + type.text + "()";
1790
+ case Type.SYN_SCOPED_NAME:
1791
+ switch (type.target.type) {
1792
+ case Type.TKN_VALUETYPE:
1793
+ case Type.SYN_INTERFACE:
1794
+ case Type.TKN_STRUCT:
1795
+ case Type.TKN_UNION:
1796
+ case Type.TKN_ENUM:
1797
+ case Type.TKN_NATIVE:
1798
+ case Type.TKN_EXCEPTION:
1799
+ case Type.TKN_MODULE:
1800
+ return "new " + writtenName(type) + "()";
1801
+ default:
1802
+ return defaultValueIDLtoTS(type.target, filetype);
1803
+ }
1912
1804
  case Type.TKN_BOOLEAN:
1913
1805
  return "false";
1914
1806
  case Type.TKN_CHAR:
@@ -1927,13 +1819,13 @@ function defaultValueIDLtoTS(type, filetype = FileType.NONE) {
1927
1819
  case Type.SYN_LONG_DOUBLE:
1928
1820
  return "0";
1929
1821
  case Type.TKN_SEQUENCE:
1930
- return `new Array<${typeIDLtoTS(type.child[0], filetype)}>()`;
1822
+ return `new Array<${typeIDLtoTS(type.elementType, filetype)}>()`;
1931
1823
  default:
1932
- throw Error(`no default value from IDL type '${type.toString()}' to default value`);
1824
+ throw Error(`no default value from IDL type '${Type[type.type]}' to default value`);
1933
1825
  }
1934
1826
  }
1935
- function hasValueType(specification) {
1936
- for (let definition of specification.child) {
1827
+ function hasValueType(scope) {
1828
+ for (let definition of scope.definitions) {
1937
1829
  switch (definition.type) {
1938
1830
  case Type.TKN_VALUETYPE:
1939
1831
  return true;
@@ -1945,14 +1837,10 @@ function hasValueType(specification) {
1945
1837
  return false;
1946
1838
  }
1947
1839
  function hasNative(specification) {
1948
- for (let definition of specification.child) {
1840
+ for (let definition of specification.definitions) {
1949
1841
  if (definition.type === Type.TKN_NATIVE) {
1950
- let native = definition;
1951
- let nativeName = native.text;
1952
- if (nativeName.length <= 4 ||
1953
- nativeName.substring(nativeName.length - 4) !== "_ptr") {
1842
+ if (!isPointerName(definition.name))
1954
1843
  return true;
1955
- }
1956
1844
  }
1957
1845
  }
1958
1846
  return false;
@@ -1963,11 +1851,10 @@ function typeIDLtoGIOPTS(type, arg = undefined, filetype = FileType.NONE) {
1963
1851
  throw Error("internal error: parser delivered no type information");
1964
1852
  let name;
1965
1853
  switch (type.type) {
1966
- case Type.TKN_IDENTIFIER:
1967
- case Type.TKN_MODULE:
1968
- return typeIDLtoGIOPTS(type.child[0], arg, filetype);
1854
+ case Type.SYN_SCOPED_NAME:
1855
+ return typeIDLtoGIOPTS(type.target, arg, filetype);
1969
1856
  case Type.TKN_VALUETYPE:
1970
- return arg === undefined ? `decoder.value("${type.text}")` : `encoder.value(${arg})`;
1857
+ return arg === undefined ? `decoder.value("${type.name}")` : `encoder.value(${arg})`;
1971
1858
  case Type.SYN_INTERFACE:
1972
1859
  name = "object";
1973
1860
  break;
@@ -1975,13 +1862,13 @@ function typeIDLtoGIOPTS(type, arg = undefined, filetype = FileType.NONE) {
1975
1862
  case Type.TKN_STRUCT: {
1976
1863
  const prefix = filetype === FileType.INTERFACE ? "" : "_interface.";
1977
1864
  return arg === undefined
1978
- ? `${prefix}decode${type.text}(decoder)`
1979
- : `${prefix}encode${type.text}(encoder,${arg})`;
1865
+ ? `${prefix}decode${type.name}(decoder)`
1866
+ : `${prefix}encode${type.name}(encoder,${arg})`;
1980
1867
  }
1981
1868
  case Type.TKN_NATIVE:
1982
1869
  {
1983
- const id = type.child[0].text;
1984
- if (id.length > 4 && id.substring(id.length - 4) === "_ptr") {
1870
+ const id = type.name;
1871
+ if (isPointerName(id)) {
1985
1872
  return arg === undefined
1986
1873
  ? `decoder.value("${id.substring(0, id.length - 4)}")`
1987
1874
  : `encoder.value(${arg})`;
@@ -2032,15 +1919,11 @@ function typeIDLtoGIOPTS(type, arg = undefined, filetype = FileType.NONE) {
2032
1919
  break;
2033
1920
  case Type.SYN_LONG_DOUBLE:
2034
1921
  throw Error("long double is not supported yet");
2035
- case Type.TKN_SEQUENCE:
1922
+ case Type.TKN_SEQUENCE: {
2036
1923
  let specialType;
2037
- if (type.child[2]?.type === Type.SYN_ANNOTAION) {
2038
- const annotation = type.child[2];
2039
- if (annotation.text === "js_mapping") {
2040
- if (annotation.child[0]?.child[0]?.text === "type") {
2041
- specialType = annotation.child[0]?.child[0]?.child[0]?.text;
2042
- }
2043
- }
1924
+ const annotation = type.annotation;
1925
+ if (annotation?.name === "js_mapping" && annotation.params[0]?.name === "type") {
1926
+ specialType = annotation.params[0].value;
2044
1927
  }
2045
1928
  switch (specialType) {
2046
1929
  case "Uint8Array":
@@ -2054,13 +1937,13 @@ function typeIDLtoGIOPTS(type, arg = undefined, filetype = FileType.NONE) {
2054
1937
  break;
2055
1938
  default:
2056
1939
  return arg === undefined
2057
- ? `decoder.sequence(() => ${typeIDLtoGIOPTS(type.child[0], undefined, filetype)})`
2058
- : `encoder.sequence(${arg}, (item) => ${typeIDLtoGIOPTS(type.child[0], "item", filetype)})`;
1940
+ ? `decoder.sequence(() => ${typeIDLtoGIOPTS(type.elementType, undefined, filetype)})`
1941
+ : `encoder.sequence(${arg}, (item) => ${typeIDLtoGIOPTS(type.elementType, "item", filetype)})`;
2059
1942
  }
2060
1943
  break;
1944
+ }
2061
1945
  default:
2062
- type.printTree();
2063
- throw Error(`no mapping from IDL type '${type.toString()}' to GIOP encoder/decoder`);
1946
+ throw Error(`no mapping from IDL type '${Type[type.type]}' to GIOP encoder/decoder`);
2064
1947
  }
2065
1948
  return arg === undefined ? `decoder.${name}()` : `encoder.${name}(${arg})`;
2066
1949
  }
@@ -2072,49 +1955,60 @@ function writeTSInterface(specification) {
2072
1955
  if (hasValueType(specification)) {
2073
1956
  out.write("import * as valuetype from \"./" + filenameLocal + "_valuetype\"\n\n");
2074
1957
  }
2075
- writeTSInterfaceDefinitions(out, specification);
1958
+ writeTSInterfaceDefinitions(out, specification.definitions);
1959
+ }
1960
+ function caseLabel(switchCase) {
1961
+ if (switchCase.type !== Type.TKN_CASE)
1962
+ throw Error("'default' is not supported in union");
1963
+ return switchCase.label;
1964
+ }
1965
+ function switchTypeName(switchType) {
1966
+ switch (switchType.type) {
1967
+ case Type.SYN_SCOPED_NAME:
1968
+ return writtenName(switchType);
1969
+ case Type.TKN_ENUM:
1970
+ return switchType.name;
1971
+ default:
1972
+ return undefined;
1973
+ }
2076
1974
  }
2077
- function writeTSInterfaceDefinitions(out, specification, prefix = "", indent = 0) {
2078
- for (let definition of specification.child) {
1975
+ function writeTSInterfaceDefinitions(out, definitions, prefix = "", indent = 0) {
1976
+ for (let definition of definitions) {
2079
1977
  switch (definition.type) {
2080
1978
  case Type.TKN_MODULE:
2081
- out.write("export namespace " + definition.text + " {\n\n");
2082
- writeTSInterfaceDefinitions(out, definition, prefix + definition.text + ".", indent + 1);
2083
- out.write("} // namespace " + definition.text + "\n\n");
1979
+ out.write("export namespace " + definition.name + " {\n\n");
1980
+ writeTSInterfaceDefinitions(out, definition.definitions, prefix + definition.name + ".", indent + 1);
1981
+ out.write("} // namespace " + definition.name + "\n\n");
2084
1982
  break;
2085
1983
  case Type.SYN_INTERFACE:
2086
1984
  {
2087
1985
  let interface_dcl = definition;
2088
- let identifier = interface_dcl.child[0].child[1].text;
2089
- let inheritance_spec = interface_dcl.child[0].child[2]?.text;
2090
- let interface_body = interface_dcl.child[1];
1986
+ let identifier = interface_dcl.name;
1987
+ let inheritance_spec = interface_dcl.base === undefined ? undefined : writtenName(interface_dcl.base);
1988
+ let interface_body = interface_dcl.body;
1989
+ writeDoc(out, interface_dcl.doc, 0);
2091
1990
  out.write(`export interface ${identifier}`);
2092
1991
  if (inheritance_spec) {
2093
1992
  out.write(` extends ${inheritance_spec}`);
2094
1993
  }
2095
1994
  out.write(` {\n`);
2096
- for (let _export of interface_body.child) {
1995
+ for (let _export of interface_body) {
2097
1996
  switch (_export.type) {
2098
1997
  case Type.SYN_OPERATION_DECLARATION:
2099
1998
  {
2100
1999
  let op_dcl = _export;
2101
- let attribute = op_dcl.child[0];
2102
- let type = op_dcl.child[1];
2103
- let oneway = false;
2104
- if (attribute !== undefined && attribute.type === Type.TKN_ONEWAY)
2105
- oneway = true;
2106
- if (oneway && type.type !== Type.TKN_VOID)
2000
+ writeDoc(out, operationDoc(op_dcl), 1);
2001
+ let oneway = op_dcl.oneway;
2002
+ if (oneway && op_dcl.returnType.type !== Type.TKN_VOID)
2107
2003
  throw Error("oneway methods must return void");
2108
- let identifier = op_dcl.child[2].text;
2109
- let parameter_decls = op_dcl.child[3].child;
2004
+ let identifier = op_dcl.name;
2005
+ let parameter_decls = op_dcl.params;
2110
2006
  out.write(" ");
2111
2007
  out.write(identifier + "(");
2112
2008
  let comma = false;
2113
2009
  for (let parameter_dcl of parameter_decls) {
2114
- let attribute = parameter_dcl.child[0].type;
2115
- let type = parameter_dcl.child[1];
2116
- let identifier = parameter_dcl.child[2].text;
2117
- if (attribute !== Type.TKN_IN) {
2010
+ let identifier = parameter_dcl.name;
2011
+ if (parameter_dcl.attribute !== Type.TKN_IN) {
2118
2012
  throw Error("corba.js currently only supports 'in' parameters");
2119
2013
  }
2120
2014
  if (!comma) {
@@ -2123,24 +2017,22 @@ function writeTSInterfaceDefinitions(out, specification, prefix = "", indent = 0
2123
2017
  else {
2124
2018
  out.write(", ");
2125
2019
  }
2126
- out.write(identifier + ": " + typeIDLtoTS(type, FileType.INTERFACE));
2020
+ out.write(identifier + ": " + typeIDLtoTS(parameter_dcl.typeSpec, FileType.INTERFACE));
2127
2021
  }
2128
2022
  if (oneway) {
2129
- out.write(`): ${typeIDLtoTS(type, FileType.INTERFACE)}\n`);
2023
+ out.write(`): ${typeIDLtoTS(op_dcl.returnType, FileType.INTERFACE)}\n`);
2130
2024
  }
2131
2025
  else {
2132
- out.write(`): Promise<${typeIDLtoTS(type, FileType.INTERFACE)}>\n`);
2026
+ out.write(`): Promise<${typeIDLtoTS(op_dcl.returnType, FileType.INTERFACE)}>\n`);
2133
2027
  }
2134
2028
  }
2135
2029
  break;
2136
2030
  case Type.TKN_ATTRIBUTE:
2137
2031
  {
2138
- const readonly = _export.child[0]?.type == Type.TKN_READONLY;
2139
- const param_type_spec = _export.child[1];
2140
- const attr_declarator = _export.child[2];
2141
- const type = typeIDLtoTS(param_type_spec, FileType.INTERFACE);
2142
- for (const n of attr_declarator.child) {
2143
- const identifier = n.text;
2032
+ const readonly = _export.readonly;
2033
+ writeDoc(out, _export.doc, 1);
2034
+ const type = typeIDLtoTS(_export.typeSpec, FileType.INTERFACE);
2035
+ for (const identifier of _export.names) {
2144
2036
  if (!readonly) {
2145
2037
  out.write(` ${identifier}(value: ${type}): Promise<void>\n`);
2146
2038
  }
@@ -2158,47 +2050,34 @@ function writeTSInterfaceDefinitions(out, specification, prefix = "", indent = 0
2158
2050
  case Type.TKN_STRUCT:
2159
2051
  {
2160
2052
  let struct_type = definition;
2161
- let identifier = struct_type.text;
2053
+ let identifier = struct_type.name;
2054
+ writeDoc(out, struct_type.doc, indent);
2162
2055
  writeIndent(out, indent);
2163
2056
  out.write(`export interface ${identifier} {\n`);
2164
- for (let i = 0; i < struct_type.child.length; ++i) {
2165
- const member = struct_type.child[i];
2166
- if (member.type === Type.SYN_MEMBER) {
2167
- let type = member.child[0];
2168
- let declarators = member.child[1];
2169
- for (let declarator of declarators.child) {
2170
- writeIndent(out, indent + 1);
2171
- out.write(declarator.text + ": " + typeIDLtoTS(type, FileType.INTERFACE) + "\n");
2172
- }
2057
+ for (const member of struct_type.members) {
2058
+ writeDoc(out, member.doc, indent + 1);
2059
+ for (const declarator of member.names) {
2060
+ writeIndent(out, indent + 1);
2061
+ out.write(declarator + ": " + typeIDLtoTS(member.typeSpec, FileType.INTERFACE) + "\n");
2173
2062
  }
2174
2063
  }
2175
2064
  writeIndent(out, indent);
2176
2065
  out.write("}\n");
2177
2066
  out.write(`export function decode${identifier}(decoder: GIOPDecoder): ${identifier} {\n`);
2178
2067
  out.write(` return {\n`);
2179
- for (let i = 0; i < struct_type.child.length; ++i) {
2180
- const member = struct_type.child[i];
2181
- if (member.type === Type.SYN_MEMBER) {
2182
- let type = member.child[0];
2183
- let declarators = member.child[1];
2184
- for (let declarator of declarators.child) {
2185
- writeIndent(out, indent + 2);
2186
- out.write(declarator.text + ": " + typeIDLtoGIOPTS(type) + ",\n");
2187
- }
2068
+ for (const member of struct_type.members) {
2069
+ for (const declarator of member.names) {
2070
+ writeIndent(out, indent + 2);
2071
+ out.write(declarator + ": " + typeIDLtoGIOPTS(member.typeSpec) + ",\n");
2188
2072
  }
2189
2073
  }
2190
2074
  out.write(` }\n`);
2191
2075
  out.write(`}\n`);
2192
2076
  out.write(`export function encode${identifier}(encoder: GIOPEncoder, obj: ${identifier}) {\n`);
2193
- for (let i = 0; i < struct_type.child.length; ++i) {
2194
- const member = struct_type.child[i];
2195
- if (member.type === Type.SYN_MEMBER) {
2196
- let type = member.child[0];
2197
- let declarators = member.child[1];
2198
- for (let declarator of declarators.child) {
2199
- writeIndent(out, indent + 1);
2200
- out.write(typeIDLtoGIOPTS(type, `obj.${declarator.text}`) + "\n");
2201
- }
2077
+ for (const member of struct_type.members) {
2078
+ for (const declarator of member.names) {
2079
+ writeIndent(out, indent + 1);
2080
+ out.write(typeIDLtoGIOPTS(member.typeSpec, `obj.${declarator}`) + "\n");
2202
2081
  }
2203
2082
  }
2204
2083
  out.write(`}\n\n`);
@@ -2206,45 +2085,46 @@ function writeTSInterfaceDefinitions(out, specification, prefix = "", indent = 0
2206
2085
  break;
2207
2086
  case Type.TKN_UNION:
2208
2087
  {
2209
- const identifier = definition.text;
2088
+ const identifier = definition.name;
2210
2089
  const union_type = definition;
2211
- const switch_body = union_type.child[1];
2090
+ const switch_body = union_type.cases;
2212
2091
  let composite = "";
2213
- switch_body.child.forEach(x => {
2214
- const case_label = x.child[0];
2215
- const type_spec = x.child[1];
2216
- const declarator = x.child[2];
2092
+ for (const x of switch_body) {
2093
+ const case_label = caseLabel(x);
2094
+ const type_spec = x.typeSpec;
2095
+ const declarator = x.name;
2217
2096
  writeIndent(out, indent);
2218
- out.write(`export type _${identifier}_${declarator.text} = {\n`);
2097
+ out.write(`export type _${identifier}_${declarator} = {\n`);
2219
2098
  writeIndent(out, indent + 1);
2220
- out.write(`type: ${case_label.typeParent.text}.${case_label.text}\n`);
2099
+ out.write(`type: ${case_label.enum.name}.${case_label.name}\n`);
2221
2100
  writeIndent(out, indent + 1);
2222
- out.write(`${declarator.text}: ${typeIDLtoTS(type_spec, FileType.INTERFACE)}\n`);
2101
+ out.write(`${declarator}: ${typeIDLtoTS(type_spec, FileType.INTERFACE)}\n`);
2223
2102
  writeIndent(out, indent);
2224
2103
  out.write(`}\n`);
2225
2104
  if (composite.length !== 0)
2226
2105
  composite = `${composite} | `;
2227
- composite = `${composite}_${identifier}_${declarator.text}`;
2228
- });
2106
+ composite = `${composite}_${identifier}_${declarator}`;
2107
+ }
2108
+ writeDoc(out, union_type.doc, indent);
2229
2109
  writeIndent(out, indent);
2230
2110
  out.write(`export type ${identifier} = ${composite}\n`);
2231
2111
  writeIndent(out, indent);
2232
2112
  out.write(`export function decode${identifier}(decoder: GIOPDecoder): ${identifier} {\n`);
2233
2113
  writeIndent(out, indent + 1);
2234
- out.write(`switch(decoder.ulong() as ${union_type.child[0].text}) {\n`);
2235
- switch_body.child.forEach(x => {
2236
- const case_label = x.child[0];
2237
- const type_spec = x.child[1];
2238
- const declarator = x.child[2];
2114
+ out.write(`switch(decoder.ulong() as ${switchTypeName(union_type.switchType)}) {\n`);
2115
+ for (const x of switch_body) {
2116
+ const case_label = caseLabel(x);
2117
+ const type_spec = x.typeSpec;
2118
+ const declarator = x.name;
2239
2119
  writeIndent(out, indent + 2);
2240
- out.write(`case ${case_label.typeParent.text}.${case_label.text}: return {\n`);
2120
+ out.write(`case ${case_label.enum.name}.${case_label.name}: return {\n`);
2241
2121
  writeIndent(out, indent + 3);
2242
- out.write(`type: ${case_label.typeParent.text}.${case_label.text},\n`);
2122
+ out.write(`type: ${case_label.enum.name}.${case_label.name},\n`);
2243
2123
  writeIndent(out, indent + 3);
2244
- out.write(`${declarator.text}: ${typeIDLtoGIOPTS(type_spec, undefined, FileType.INTERFACE)}\n`);
2124
+ out.write(`${declarator}: ${typeIDLtoGIOPTS(type_spec, undefined, FileType.INTERFACE)}\n`);
2245
2125
  writeIndent(out, indent + 2);
2246
2126
  out.write(`}\n`);
2247
- });
2127
+ }
2248
2128
  writeIndent(out, indent + 1);
2249
2129
  out.write(`}\n`);
2250
2130
  writeIndent(out, indent + 1);
@@ -2257,17 +2137,17 @@ function writeTSInterfaceDefinitions(out, specification, prefix = "", indent = 0
2257
2137
  out.write(`encoder.ulong(obj.type)\n`);
2258
2138
  writeIndent(out, indent + 1);
2259
2139
  out.write(`switch(obj.type) {\n`);
2260
- switch_body.child.forEach(x => {
2261
- const case_label = x.child[0];
2262
- const type_spec = x.child[1];
2263
- const declarator = x.child[2];
2140
+ for (const x of switch_body) {
2141
+ const case_label = caseLabel(x);
2142
+ const type_spec = x.typeSpec;
2143
+ const declarator = x.name;
2264
2144
  writeIndent(out, indent + 2);
2265
- out.write(`case ${case_label.typeParent.text}.${case_label.text}:\n`);
2145
+ out.write(`case ${case_label.enum.name}.${case_label.name}:\n`);
2266
2146
  writeIndent(out, indent + 3);
2267
- out.write(typeIDLtoGIOPTS(type_spec, `obj.${declarator.text}`, FileType.INTERFACE) + "\n");
2147
+ out.write(typeIDLtoGIOPTS(type_spec, `obj.${declarator}`, FileType.INTERFACE) + "\n");
2268
2148
  writeIndent(out, indent + 3);
2269
2149
  out.write(`break\n`);
2270
- });
2150
+ }
2271
2151
  writeIndent(out, indent + 1);
2272
2152
  out.write(`}\n`);
2273
2153
  out.write(`}\n\n`);
@@ -2275,12 +2155,14 @@ function writeTSInterfaceDefinitions(out, specification, prefix = "", indent = 0
2275
2155
  break;
2276
2156
  case Type.TKN_ENUM:
2277
2157
  {
2278
- const identifier = definition.text;
2158
+ const identifier = definition.name;
2159
+ writeDoc(out, definition.doc, indent);
2279
2160
  writeIndent(out, indent);
2280
2161
  out.write(`export enum ${identifier} {\n`);
2281
- for (const enumerator of definition.child) {
2162
+ for (const enumerator of definition.enumerators) {
2163
+ writeDoc(out, enumerator.doc, indent + 1);
2282
2164
  writeIndent(out, indent + 1);
2283
- out.write(`${enumerator.text},\n`);
2165
+ out.write(`${enumerator.name},\n`);
2284
2166
  }
2285
2167
  writeIndent(out, indent);
2286
2168
  out.write("}\n\n");
@@ -2298,48 +2180,43 @@ function writeTSSkeleton(specification) {
2298
2180
  out.write(`import * as valuetype from \"./${filenameLocal}_valuetype\"\n`);
2299
2181
  }
2300
2182
  out.write(`import * as _interface from \"./${filenameLocal}\"\n\n`);
2301
- writeTSSkeletonDefinitions(out, specification);
2183
+ writeTSSkeletonDefinitions(out, specification.definitions);
2302
2184
  }
2303
- function writeTSSkeletonDefinitions(out, specification, prefix = "", indent = 0) {
2304
- for (let definition of specification.child) {
2185
+ function writeTSSkeletonDefinitions(out, definitions, prefix = "", indent = 0) {
2186
+ for (let definition of definitions) {
2305
2187
  switch (definition.type) {
2306
2188
  case Type.TKN_MODULE:
2307
- out.write(`export namespace ${definition.text}{\n\n`);
2308
- writeTSSkeletonDefinitions(out, definition, prefix + definition.text + ".", indent + 1);
2309
- out.write(`} // namespace ${definition.text}\n\n`);
2189
+ out.write(`export namespace ${definition.name}{\n\n`);
2190
+ writeTSSkeletonDefinitions(out, definition.definitions, prefix + definition.name + ".", indent + 1);
2191
+ out.write(`} // namespace ${definition.name}\n\n`);
2310
2192
  break;
2311
2193
  case Type.SYN_INTERFACE:
2312
2194
  {
2313
2195
  let interface_dcl = definition;
2314
- let identifier = interface_dcl.child[0].child[1].text;
2315
- let inheritance_spec = interface_dcl.child[0].child[2]?.text;
2316
- let interface_body = interface_dcl.child[1];
2317
- out.write(`export abstract class ${identifier} extends ${inheritance_spec ? inheritance_spec : "Skeleton"} implements _interface.${prefix}${identifier} {\n`);
2196
+ let identifier = interface_dcl.name;
2197
+ let inheritance_spec = interface_dcl.base === undefined ? undefined : writtenName(interface_dcl.base);
2198
+ let interface_body = interface_dcl.body;
2199
+ out.write(`export abstract class ${identifier}_skel extends ${inheritance_spec ? inheritance_spec + "_skel" : "Skeleton"} implements _interface.${prefix}${identifier} {\n`);
2318
2200
  out.write(` constructor(orb: ORB) { super(orb) }\n`);
2319
2201
  out.write(` static ${inheritance_spec ? "override " : ""}_idlClassName(): string {\n`);
2320
2202
  out.write(` return "${prefix}${identifier}"\n`);
2321
2203
  out.write(" }\n\n");
2322
- for (let _export of interface_body.child) {
2204
+ for (let _export of interface_body) {
2323
2205
  switch (_export.type) {
2324
2206
  case Type.SYN_OPERATION_DECLARATION:
2325
2207
  {
2326
2208
  let op_dcl = _export;
2327
- let attribute = op_dcl.child[0];
2328
- let type = op_dcl.child[1];
2329
- let oneway = false;
2330
- if (attribute !== undefined && attribute.type === Type.TKN_ONEWAY)
2331
- oneway = true;
2209
+ let oneway = op_dcl.oneway;
2210
+ let type = op_dcl.returnType;
2332
2211
  if (oneway && type.type !== Type.TKN_VOID)
2333
2212
  throw Error("oneway methods must return void");
2334
- let identifier = op_dcl.child[2].text;
2335
- let parameter_decls = op_dcl.child[3].child;
2213
+ let identifier = op_dcl.name;
2214
+ let parameter_decls = op_dcl.params;
2336
2215
  out.write(` abstract ${identifier}(`);
2337
2216
  let comma = false;
2338
2217
  for (let parameter_dcl of parameter_decls) {
2339
- let attribute = parameter_dcl.child[0].type;
2340
- let type = parameter_dcl.child[1];
2341
- let identifier = parameter_dcl.child[2].text;
2342
- if (attribute !== Type.TKN_IN) {
2218
+ let identifier = parameter_dcl.name;
2219
+ if (parameter_dcl.attribute !== Type.TKN_IN) {
2343
2220
  throw Error("corba.js currently only supports 'in' parameters");
2344
2221
  }
2345
2222
  if (!comma) {
@@ -2348,7 +2225,7 @@ function writeTSSkeletonDefinitions(out, specification, prefix = "", indent = 0)
2348
2225
  else {
2349
2226
  out.write(", ");
2350
2227
  }
2351
- out.write(`${identifier}: ${typeIDLtoTS(type, FileType.SKELETON)}`);
2228
+ out.write(`${identifier}: ${typeIDLtoTS(parameter_dcl.typeSpec, FileType.SKELETON)}`);
2352
2229
  }
2353
2230
  if (oneway)
2354
2231
  out.write(`): void\n`);
@@ -2369,9 +2246,7 @@ function writeTSSkeletonDefinitions(out, specification, prefix = "", indent = 0)
2369
2246
  }
2370
2247
  comma = false;
2371
2248
  for (let parameter_dcl of parameter_decls) {
2372
- let attribute = parameter_dcl.child[0].type;
2373
- let type = parameter_dcl.child[1];
2374
- if (attribute !== Type.TKN_IN) {
2249
+ if (parameter_dcl.attribute !== Type.TKN_IN) {
2375
2250
  throw Error("corba.js currently only supports 'in' parameters");
2376
2251
  }
2377
2252
  if (!comma) {
@@ -2380,7 +2255,7 @@ function writeTSSkeletonDefinitions(out, specification, prefix = "", indent = 0)
2380
2255
  else {
2381
2256
  out.write(", ");
2382
2257
  }
2383
- out.write(`${typeIDLtoGIOPTS(type)}`);
2258
+ out.write(`${typeIDLtoGIOPTS(parameter_dcl.typeSpec)}`);
2384
2259
  }
2385
2260
  out.write(`)\n`);
2386
2261
  if (type.type !== Type.TKN_VOID) {
@@ -2391,12 +2266,10 @@ function writeTSSkeletonDefinitions(out, specification, prefix = "", indent = 0)
2391
2266
  break;
2392
2267
  case Type.TKN_ATTRIBUTE:
2393
2268
  {
2394
- const readonly = _export.child[0]?.type == Type.TKN_READONLY;
2395
- const param_type_spec = _export.child[1];
2396
- const attr_declarator = _export.child[2];
2269
+ const readonly = _export.readonly;
2270
+ const param_type_spec = _export.typeSpec;
2397
2271
  const type = typeIDLtoTS(param_type_spec, FileType.SKELETON);
2398
- for (const n of attr_declarator.child) {
2399
- const identifier = n.text;
2272
+ for (const identifier of _export.names) {
2400
2273
  out.write(` abstract ${identifier}(): Promise<${type}>\n`);
2401
2274
  if (!readonly) {
2402
2275
  out.write(` abstract ${identifier}(value: ${type}): Promise<void>\n`);
@@ -2430,53 +2303,48 @@ function writeTSStub(specification) {
2430
2303
  out.write("import * as valuetype from \"./" + filenameLocal + "_valuetype\"\n");
2431
2304
  }
2432
2305
  out.write("import * as _interface from \"./" + filenameLocal + "\"\n\n");
2433
- writeTSStubDefinitions(out, specification);
2306
+ writeTSStubDefinitions(out, specification.definitions);
2434
2307
  }
2435
- function writeTSStubDefinitions(out, specification, prefix = "", indent = 0) {
2436
- for (let definition of specification.child) {
2308
+ function writeTSStubDefinitions(out, definitions, prefix = "", indent = 0) {
2309
+ for (let definition of definitions) {
2437
2310
  switch (definition.type) {
2438
2311
  case Type.TKN_MODULE:
2439
- out.write("export namespace " + definition.text + " {\n\n");
2440
- writeTSStubDefinitions(out, definition, prefix + definition.text + ".", indent + 1);
2441
- out.write("} // namespace " + definition.text + "\n\n");
2312
+ out.write("export namespace " + definition.name + " {\n\n");
2313
+ writeTSStubDefinitions(out, definition.definitions, prefix + definition.name + ".", indent + 1);
2314
+ out.write("} // namespace " + definition.name + "\n\n");
2442
2315
  break;
2443
2316
  case Type.SYN_INTERFACE:
2444
2317
  {
2445
2318
  let interface_dcl = definition;
2446
- let identifier = interface_dcl.child[0].child[1].text;
2447
- let inheritance_spec = interface_dcl.child[0].child[2]?.text;
2448
- let interface_body = interface_dcl.child[1];
2449
- out.write(`export class ${identifier} extends ${inheritance_spec ? inheritance_spec : "Stub"} implements _interface.${prefix}${identifier} {\n`);
2319
+ let identifier = interface_dcl.name;
2320
+ let inheritance_spec = interface_dcl.base === undefined ? undefined : writtenName(interface_dcl.base);
2321
+ let interface_body = interface_dcl.body;
2322
+ out.write(`export class ${identifier}_stub extends ${inheritance_spec ? inheritance_spec + "_stub" : "Stub"} implements _interface.${prefix}${identifier} {\n`);
2450
2323
  out.write(` static ${inheritance_spec ? "override " : ""}_idlClassName(): string {\n`);
2451
2324
  out.write(` return "${prefix}${identifier}"\n`);
2452
2325
  out.write(` }\n\n`);
2453
- out.write(` static ${inheritance_spec ? "override " : ""}narrow(object: any): ${prefix}${identifier} {\n`);
2454
- out.write(` if (object instanceof ${prefix}${identifier})\n`);
2455
- out.write(` return object as ${prefix}${identifier}\n`);
2326
+ out.write(` static ${inheritance_spec ? "override " : ""}narrow(object: any): ${prefix}${identifier}_stub {\n`);
2327
+ out.write(` if (object instanceof ${prefix}${identifier}_stub)\n`);
2328
+ out.write(` return object as ${prefix}${identifier}_stub\n`);
2456
2329
  out.write(` throw Error("${prefix}${identifier}.narrow() failed")\n`);
2457
2330
  out.write(` }\n\n`);
2458
- for (let _export of interface_body.child) {
2331
+ for (let _export of interface_body) {
2459
2332
  switch (_export.type) {
2460
2333
  case Type.SYN_OPERATION_DECLARATION:
2461
2334
  {
2462
2335
  let op_dcl = _export;
2463
- let attribute = op_dcl.child[0];
2464
- let returnType = op_dcl.child[1];
2465
- let oneway = false;
2466
- if (attribute !== undefined && attribute.type === Type.TKN_ONEWAY)
2467
- oneway = true;
2336
+ let oneway = op_dcl.oneway;
2337
+ let returnType = op_dcl.returnType;
2468
2338
  if (oneway && returnType.type !== Type.TKN_VOID)
2469
2339
  console.log("WARNING: corba.js currently requires every oneway function to return void");
2470
- let identifier = op_dcl.child[2].text;
2471
- let parameter_decls = op_dcl.child[3].child;
2340
+ let identifier = op_dcl.name;
2341
+ let parameter_decls = op_dcl.params;
2472
2342
  out.write(" async ");
2473
2343
  out.write(identifier + "(");
2474
2344
  let comma = false;
2475
2345
  for (let parameter_dcl of parameter_decls) {
2476
- let attribute = parameter_dcl.child[0].type;
2477
- let type = parameter_dcl.child[1];
2478
- let identifier = parameter_dcl.child[2].text;
2479
- if (attribute !== Type.TKN_IN) {
2346
+ let identifier = parameter_dcl.name;
2347
+ if (parameter_dcl.attribute !== Type.TKN_IN) {
2480
2348
  throw Error("corba.js currently only supports 'in' parameters");
2481
2349
  }
2482
2350
  if (!comma) {
@@ -2485,7 +2353,7 @@ function writeTSStubDefinitions(out, specification, prefix = "", indent = 0) {
2485
2353
  else {
2486
2354
  out.write(", ");
2487
2355
  }
2488
- out.write(`${identifier}: ${typeIDLtoTS(type, FileType.STUB)}`);
2356
+ out.write(`${identifier}: ${typeIDLtoTS(parameter_dcl.typeSpec, FileType.STUB)}`);
2489
2357
  }
2490
2358
  out.write(`): Promise<${typeIDLtoTS(returnType, FileType.STUB)}> {\n`);
2491
2359
  out.write(" ");
@@ -2501,9 +2369,7 @@ function writeTSStubDefinitions(out, specification, prefix = "", indent = 0) {
2501
2369
  }
2502
2370
  out.write(`(encoder) => {\n`);
2503
2371
  for (let parameter_dcl of parameter_decls) {
2504
- let type = parameter_dcl.child[1];
2505
- let identifier = parameter_dcl.child[2].text;
2506
- out.write(` ${typeIDLtoGIOPTS(type, identifier)}\n`);
2372
+ out.write(` ${typeIDLtoGIOPTS(parameter_dcl.typeSpec, parameter_dcl.name)}\n`);
2507
2373
  }
2508
2374
  if (oneway) {
2509
2375
  out.write(` })\n`);
@@ -2523,11 +2389,9 @@ function writeTSStubDefinitions(out, specification, prefix = "", indent = 0) {
2523
2389
  break;
2524
2390
  case Type.TKN_ATTRIBUTE:
2525
2391
  {
2526
- const readonly = _export.child[0]?.type == Type.TKN_READONLY;
2527
- const param_type_spec = _export.child[1];
2528
- const attr_declarator = _export.child[2];
2529
- for (const n of attr_declarator.child) {
2530
- const identifier = n.text;
2392
+ const readonly = _export.readonly;
2393
+ const param_type_spec = _export.typeSpec;
2394
+ for (const identifier of _export.names) {
2531
2395
  const type = typeIDLtoTS(param_type_spec, FileType.STUB);
2532
2396
  if (readonly) {
2533
2397
  out.write(` async ${identifier}(): Promise<${type}> {\n`);
@@ -2581,10 +2445,9 @@ function writeTSValue(specification) {
2581
2445
  }
2582
2446
  if (hasNative(specification)) {
2583
2447
  out.write("declare global {\n");
2584
- for (let definition of specification.child) {
2448
+ for (let definition of specification.definitions) {
2585
2449
  if (definition.type === Type.TKN_NATIVE) {
2586
- let native = definition;
2587
- let nativeName = native.text;
2450
+ let nativeName = definition.name;
2588
2451
  if (nativeName.length <= 4 ||
2589
2452
  nativeName.substring(nativeName.length - 4) !== "_ptr") {
2590
2453
  out.write(` interface ${nativeName} {}\n`);
@@ -2593,7 +2456,7 @@ function writeTSValue(specification) {
2593
2456
  }
2594
2457
  out.write("}\n\n");
2595
2458
  }
2596
- writeTSValueDefinitions(out, specification);
2459
+ writeTSValueDefinitions(out, specification.definitions);
2597
2460
  out.write("let initialized = false\n");
2598
2461
  out.write("export function _init() {\n");
2599
2462
  out.write(" if (initialized)\n");
@@ -2603,16 +2466,16 @@ function writeTSValue(specification) {
2603
2466
  out.write("}\n");
2604
2467
  out.write("_init()\n");
2605
2468
  }
2606
- function writeTSValueDefinitions(out, specification, prefix = "", indent = 0) {
2607
- for (let definition of specification.child) {
2469
+ function writeTSValueDefinitions(out, definitions, prefix = "", indent = 0) {
2470
+ for (let definition of definitions) {
2608
2471
  switch (definition.type) {
2609
2472
  case Type.TKN_MODULE:
2610
2473
  {
2611
2474
  writeIndent(out, indent);
2612
- out.write(`export namespace ${definition.text} {\n\n`);
2613
- writeTSValueDefinitions(out, definition, prefix + definition.text + ".", indent + 1);
2475
+ out.write(`export namespace ${definition.name} {\n\n`);
2476
+ writeTSValueDefinitions(out, definition.definitions, prefix + definition.name + ".", indent + 1);
2614
2477
  writeIndent(out, indent);
2615
- out.write(`} // namespace ${definition.text}\n\n`);
2478
+ out.write(`} // namespace ${definition.name}\n\n`);
2616
2479
  }
2617
2480
  break;
2618
2481
  case Type.TKN_NATIVE:
@@ -2620,21 +2483,20 @@ function writeTSValueDefinitions(out, specification, prefix = "", indent = 0) {
2620
2483
  case Type.TKN_VALUETYPE:
2621
2484
  {
2622
2485
  let value_dcl = definition;
2623
- let value_header = value_dcl.child[0];
2624
- value_header.child[0];
2625
- let identifier = value_header.child[1].text;
2626
- let inheritance_spec = value_header.child[2];
2486
+ let identifier = value_dcl.name;
2487
+ writeDoc(out, value_dcl.doc, indent);
2627
2488
  writeIndent(out, indent);
2628
2489
  out.write(`export interface ${identifier}`);
2629
2490
  let attributes = new Array();
2630
2491
  classAttributes.set(prefix + identifier, attributes);
2631
- if (inheritance_spec !== undefined) {
2632
- if (inheritance_spec.child.length > 2)
2492
+ if (value_dcl.base.length > 0) {
2493
+ if (value_dcl.base.length > 1)
2633
2494
  throw Error("multiple inheritance is not supported for TypeScript");
2634
- out.write(` extends ${inheritance_spec.child[1].text}`);
2635
- let superAttributes = classAttributes.get(prefix + inheritance_spec.child[1].text);
2495
+ const base = writtenName(value_dcl.base[0]);
2496
+ out.write(` extends ${base}`);
2497
+ let superAttributes = classAttributes.get(prefix + base);
2636
2498
  if (superAttributes === undefined) {
2637
- superAttributes = classAttributes.get(inheritance_spec.child[1].text);
2499
+ superAttributes = classAttributes.get(base);
2638
2500
  }
2639
2501
  if (superAttributes === undefined) {
2640
2502
  throw Error("failed to find attributes for super class");
@@ -2644,17 +2506,13 @@ function writeTSValueDefinitions(out, specification, prefix = "", indent = 0) {
2644
2506
  }
2645
2507
  }
2646
2508
  out.write(" {\n");
2647
- for (let i = 1; i < value_dcl.child.length; ++i) {
2648
- let value_element = value_dcl.child[i];
2509
+ for (let value_element of value_dcl.elements) {
2649
2510
  if (value_element.type === Type.SYN_STATE_MEMBER) {
2650
- let state_member = value_element;
2651
- state_member.child[0];
2652
- let type = state_member.child[1];
2653
- let declarators = state_member.child[2];
2654
- for (let declarator of declarators.child) {
2511
+ writeDoc(out, value_element.doc, indent + 1);
2512
+ for (let declarator of value_element.names) {
2655
2513
  writeIndent(out, indent + 1);
2656
- out.write(declarator.text + ": " + typeIDLtoTS(type, FileType.VALUE) + "\n");
2657
- attributes.push(declarator.text);
2514
+ out.write(declarator + ": " + typeIDLtoTS(value_element.typeSpec, FileType.VALUE) + "\n");
2515
+ attributes.push(declarator);
2658
2516
  }
2659
2517
  }
2660
2518
  }
@@ -2679,20 +2537,16 @@ function writeTSValueDefinitions(out, specification, prefix = "", indent = 0) {
2679
2537
  writeIndent(out, indent);
2680
2538
  out.write(`export function encode${identifier}(encoder: GIOPEncoder, obj: ${identifier}) {\n`);
2681
2539
  ++indent;
2682
- if (inheritance_spec !== undefined) {
2540
+ if (value_dcl.base.length > 0) {
2683
2541
  writeIndent(out, indent);
2684
- out.write(`encode${inheritance_spec.child[1].text}(encoder, obj)\n`);
2542
+ const base = value_dcl.base[0];
2543
+ out.write(`${base.path.map(module => module.name + ".").join("")}encode${base.name}(encoder, obj)\n`);
2685
2544
  }
2686
- for (let i = 1; i < value_dcl.child.length; ++i) {
2687
- let value_element = value_dcl.child[i];
2545
+ for (let value_element of value_dcl.elements) {
2688
2546
  if (value_element.type === Type.SYN_STATE_MEMBER) {
2689
- let state_member = value_element;
2690
- state_member.child[0];
2691
- let type = state_member.child[1];
2692
- let declarators = state_member.child[2];
2693
- for (let declarator of declarators.child) {
2547
+ for (let declarator of value_element.names) {
2694
2548
  writeIndent(out, indent);
2695
- out.write(`${typeIDLtoGIOPTS(type, "obj." + declarator.text)}\n`);
2549
+ out.write(`${typeIDLtoGIOPTS(value_element.typeSpec, "obj." + declarator)}\n`);
2696
2550
  }
2697
2551
  }
2698
2552
  }
@@ -2717,39 +2571,29 @@ function writeTSValueDefinitions(out, specification, prefix = "", indent = 0) {
2717
2571
  }
2718
2572
  }
2719
2573
  function writeTSInitValueFromGIOP(value_dcl, out, indent) {
2720
- for (let i = 1; i < value_dcl.child.length; ++i) {
2721
- let value_element = value_dcl.child[i];
2574
+ for (let value_element of value_dcl.elements) {
2722
2575
  if (value_element.type === Type.SYN_STATE_MEMBER) {
2723
- let state_member = value_element;
2724
- let type = state_member.child[1];
2725
- let declarators = state_member.child[2];
2726
- for (let declarator of declarators.child) {
2727
- let decl_identifier = declarator.text;
2576
+ for (let declarator of value_element.names) {
2728
2577
  writeIndent(out, indent);
2729
- out.write(`object.${decl_identifier} = ${typeIDLtoGIOPTS(type)}\n`);
2578
+ out.write(`object.${declarator} = ${typeIDLtoGIOPTS(value_element.typeSpec)}\n`);
2730
2579
  }
2731
2580
  }
2732
2581
  }
2733
2582
  }
2734
2583
  function writeTSInitValueFromPOJO(value_dcl, out, indent) {
2735
- for (let i = 1; i < value_dcl.child.length; ++i) {
2736
- let value_element = value_dcl.child[i];
2584
+ for (let value_element of value_dcl.elements) {
2737
2585
  if (value_element.type === Type.SYN_STATE_MEMBER) {
2738
- let state_member = value_element;
2739
- state_member.child[0];
2740
- let type = state_member.child[1];
2741
- let declarators = state_member.child[2];
2742
- for (let declarator of declarators.child) {
2743
- let decl_identifier = declarator.text;
2586
+ let type = value_element.typeSpec;
2587
+ for (let declarator of value_element.names) {
2588
+ let decl_identifier = declarator;
2744
2589
  writeIndent(out, indent);
2745
- if (type.type === Type.TKN_IDENTIFIER) {
2746
- if (type.child[0]?.type == Type.TKN_NATIVE &&
2747
- type.text.length > 4 &&
2748
- type.text.substring(type.text.length - 4) === "_ptr") {
2590
+ if (type.type === Type.SYN_SCOPED_NAME && !predefinedTypes.includes(resolvedTarget(type).type)) {
2591
+ if (type.target.type == Type.TKN_NATIVE &&
2592
+ isPointerName(type.name)) {
2749
2593
  let name = typeIDLtoTS(type, FileType.VALUE);
2750
2594
  out.write(`if (init !== undefined && init.${decl_identifier} !== undefined) object.${decl_identifier} = new (ORB.lookupValueType("${name}"))(init.${decl_identifier})\n`);
2751
2595
  }
2752
- else if (type.child[0]?.type == Type.TKN_SEQUENCE) {
2596
+ else if (resolvedTarget(type).type == Type.TKN_SEQUENCE) {
2753
2597
  out.write(`object.${decl_identifier} = init?.${decl_identifier} instanceof Array ? init!.${decl_identifier} : []\n`);
2754
2598
  }
2755
2599
  else {
@@ -2780,10 +2624,9 @@ function writeTSValueType(specification) {
2780
2624
  out.write(`import * as value from "./${filenameLocal}_value\"\n\n`);
2781
2625
  if (hasNative(specification)) {
2782
2626
  out.write("declare global {\n");
2783
- for (let definition of specification.child) {
2627
+ for (let definition of specification.definitions) {
2784
2628
  if (definition.type === Type.TKN_NATIVE) {
2785
- let native = definition;
2786
- let nativeName = native.text;
2629
+ let nativeName = definition.name;
2787
2630
  if (nativeName.length <= 4 ||
2788
2631
  nativeName.substring(nativeName.length - 4) !== "_ptr") {
2789
2632
  out.write(" interface " + nativeName + " {}\n");
@@ -2792,16 +2635,16 @@ function writeTSValueType(specification) {
2792
2635
  }
2793
2636
  out.write("}\n\n");
2794
2637
  }
2795
- writeTSValueTypeDefinitions(out, specification);
2638
+ writeTSValueTypeDefinitions(out, specification.definitions);
2796
2639
  }
2797
- function writeTSValueTypeDefinitions(out, specification, prefix = "", indent = 0) {
2798
- for (let definition of specification.child) {
2640
+ function writeTSValueTypeDefinitions(out, definitions, prefix = "", indent = 0) {
2641
+ for (let definition of definitions) {
2799
2642
  switch (definition.type) {
2800
2643
  case Type.TKN_MODULE:
2801
2644
  {
2802
- out.write(`export namespace ${definition.text} {\n\n`);
2803
- writeTSValueTypeDefinitions(out, definition, prefix + definition.text + ".", indent + 1);
2804
- out.write(`} // namespace ${definition.text}\n\n`);
2645
+ out.write(`export namespace ${definition.name} {\n\n`);
2646
+ writeTSValueTypeDefinitions(out, definition.definitions, prefix + definition.name + ".", indent + 1);
2647
+ out.write(`} // namespace ${definition.name}\n\n`);
2805
2648
  }
2806
2649
  break;
2807
2650
  case Type.TKN_NATIVE:
@@ -2809,34 +2652,26 @@ function writeTSValueTypeDefinitions(out, specification, prefix = "", indent = 0
2809
2652
  case Type.TKN_VALUETYPE:
2810
2653
  {
2811
2654
  let value_dcl = definition;
2812
- let value_header = value_dcl.child[0];
2813
- value_header.child[0];
2814
- let identifier = value_header.child[1].text;
2815
- let inheritance_spec = value_header.child[2];
2655
+ let identifier = value_dcl.name;
2816
2656
  writeIndent(out, indent);
2817
2657
  out.write(`export interface ${identifier} extends value.${prefix}${identifier}`);
2818
- if (inheritance_spec !== undefined) {
2819
- if (inheritance_spec.child.length > 2)
2658
+ if (value_dcl.base.length > 0) {
2659
+ if (value_dcl.base.length > 1)
2820
2660
  throw Error("multiple inheritance is not supported for TypeScript");
2821
- out.write(", " + inheritance_spec.child[1].text);
2661
+ out.write(", " + writtenName(value_dcl.base[0]));
2822
2662
  }
2823
2663
  out.write(" {\n");
2824
- for (let i = 1; i < value_dcl.child.length; ++i) {
2825
- let value_element = value_dcl.child[i];
2664
+ for (let value_element of value_dcl.elements) {
2826
2665
  if (value_element.type === Type.SYN_OPERATION_DECLARATION) {
2827
2666
  let op_decl = value_element;
2828
- op_decl.child[0];
2829
- let type = op_decl.child[1];
2830
- let op_identifier = op_decl.child[2].text;
2831
- let parameter_decls = op_decl.child[3].child;
2667
+ let op_identifier = op_decl.name;
2668
+ let parameter_decls = op_decl.params;
2832
2669
  writeIndent(out, indent + 1);
2833
2670
  out.write(op_identifier + "(");
2834
2671
  let comma = false;
2835
2672
  for (let parameter_dcl of parameter_decls) {
2836
- let attribute = parameter_dcl.child[0].type;
2837
- let type = parameter_dcl.child[1];
2838
- let param_identifier = parameter_dcl.child[2].text;
2839
- if (attribute !== Type.TKN_IN) {
2673
+ let param_identifier = parameter_dcl.name;
2674
+ if (parameter_dcl.attribute !== Type.TKN_IN) {
2840
2675
  throw Error("corba.js currently only supports 'in' parameters");
2841
2676
  }
2842
2677
  if (comma) {
@@ -2847,10 +2682,10 @@ function writeTSValueTypeDefinitions(out, specification, prefix = "", indent = 0
2847
2682
  }
2848
2683
  out.write(param_identifier);
2849
2684
  out.write(": ");
2850
- out.write(typeIDLtoTS(type, FileType.VALUETYPE));
2685
+ out.write(typeIDLtoTS(parameter_dcl.typeSpec, FileType.VALUETYPE));
2851
2686
  }
2852
2687
  out.write("): ");
2853
- out.write(typeIDLtoTS(type, FileType.VALUETYPE));
2688
+ out.write(typeIDLtoTS(op_decl.returnType, FileType.VALUETYPE));
2854
2689
  out.write("\n");
2855
2690
  }
2856
2691
  }
@@ -2875,12 +2710,11 @@ function writeTSValueImpl(specification) {
2875
2710
  out.write(`import * as _interface from "./${filenameLocal}"\n\n`);
2876
2711
  if (hasNative(specification)) {
2877
2712
  out.write("declare global {\n");
2878
- for (let definition of specification.child) {
2713
+ for (let definition of specification.definitions) {
2879
2714
  switch (definition.type) {
2880
2715
  case Type.TKN_NATIVE:
2881
2716
  {
2882
- let native = definition;
2883
- let nativeName = native.text;
2717
+ let nativeName = definition.name;
2884
2718
  if (nativeName.length <= 4 ||
2885
2719
  nativeName.substring(nativeName.length - 4) !== "_ptr") {
2886
2720
  out.write(" interface " + nativeName + " {}\n");
@@ -2891,35 +2725,32 @@ function writeTSValueImpl(specification) {
2891
2725
  }
2892
2726
  out.write("}\n\n");
2893
2727
  }
2894
- writeTSValueImplDefinitions(out, specification);
2728
+ writeTSValueImplDefinitions(out, specification.definitions);
2895
2729
  }
2896
2730
  function hasOperationDeclarations(value_dcl) {
2897
- for (let i = 1; i < value_dcl.child.length; ++i) {
2898
- let value_element = value_dcl.child[i];
2731
+ for (let value_element of value_dcl.elements) {
2899
2732
  if (value_element.type === Type.SYN_OPERATION_DECLARATION) {
2900
2733
  return true;
2901
2734
  }
2902
2735
  }
2903
- let value_header = value_dcl.child[0];
2904
- let inheritance_spec = value_header.child[2];
2905
- if (inheritance_spec !== undefined) {
2906
- if (inheritance_spec.child[1].child[0].type === Type.TKN_VALUETYPE) {
2907
- let value_dcl = inheritance_spec.child[1].child[0];
2908
- if (hasOperationDeclarations(value_dcl)) {
2736
+ if (value_dcl.base.length > 0) {
2737
+ const base = value_dcl.base[0].target;
2738
+ if (base.type === Type.TKN_VALUETYPE) {
2739
+ if (hasOperationDeclarations(base)) {
2909
2740
  return true;
2910
2741
  }
2911
2742
  }
2912
2743
  }
2913
2744
  return false;
2914
2745
  }
2915
- function writeTSValueImplDefinitions(out, specification, prefix = "", indent = 0) {
2916
- for (let definition of specification.child) {
2746
+ function writeTSValueImplDefinitions(out, definitions, prefix = "", indent = 0) {
2747
+ for (let definition of definitions) {
2917
2748
  switch (definition.type) {
2918
2749
  case Type.TKN_MODULE:
2919
2750
  {
2920
- out.write("export namespace " + definition.text + " {\n\n");
2921
- writeTSValueImplDefinitions(out, definition, prefix + definition.text + ".", indent + 1);
2922
- out.write("} // namespace " + definition.text + "\n\n");
2751
+ out.write("export namespace " + definition.name + " {\n\n");
2752
+ writeTSValueImplDefinitions(out, definition.definitions, prefix + definition.name + ".", indent + 1);
2753
+ out.write("} // namespace " + definition.name + "\n\n");
2923
2754
  }
2924
2755
  break;
2925
2756
  case Type.TKN_NATIVE:
@@ -2927,45 +2758,37 @@ function writeTSValueImplDefinitions(out, specification, prefix = "", indent = 0
2927
2758
  case Type.TKN_VALUETYPE:
2928
2759
  {
2929
2760
  let value_dcl = definition;
2930
- let value_header = value_dcl.child[0];
2931
- value_header.child[0];
2932
- let identifier = value_header.child[1].text;
2933
- let inheritance_spec = value_header.child[2];
2761
+ let identifier = value_dcl.name;
2934
2762
  writeIndent(out, indent);
2935
2763
  out.write("export ");
2936
2764
  if (hasOperationDeclarations(value_dcl))
2937
2765
  out.write("abstract ");
2938
- else if (inheritance_spec !== undefined) {
2939
- if (inheritance_spec.child[1].child[0].type === Type.TKN_VALUETYPE) {
2940
- let value_dcl = inheritance_spec.child[1].child[0];
2941
- if (hasOperationDeclarations(value_dcl))
2766
+ else if (value_dcl.base.length > 0) {
2767
+ const base = value_dcl.base[0].target;
2768
+ if (base.type === Type.TKN_VALUETYPE) {
2769
+ if (hasOperationDeclarations(base))
2942
2770
  out.write("abstract ");
2943
2771
  }
2944
2772
  }
2945
2773
  out.write("class " + identifier);
2946
- if (inheritance_spec !== undefined) {
2947
- if (inheritance_spec.child.length > 2)
2774
+ if (value_dcl.base.length > 0) {
2775
+ if (value_dcl.base.length > 1)
2948
2776
  throw Error("multiple inheritance is not supported for TypeScript");
2949
- out.write(" extends " + inheritance_spec.child[1].text);
2777
+ out.write(" extends " + writtenName(value_dcl.base[0]));
2950
2778
  }
2951
2779
  out.write(` implements valuetype.${prefix}${identifier} {\n`);
2952
- for (let i = 1; i < value_dcl.child.length; ++i) {
2953
- let value_element = value_dcl.child[i];
2780
+ for (let value_element of value_dcl.elements) {
2954
2781
  if (value_element.type === Type.SYN_STATE_MEMBER) {
2955
- let state_member = value_element;
2956
- state_member.child[0];
2957
- let type = state_member.child[1];
2958
- let declarators = state_member.child[2];
2959
- for (let declarator of declarators.child) {
2782
+ for (let declarator of value_element.names) {
2960
2783
  writeIndent(out, indent + 1);
2961
- out.write(declarator.text + "!: " + typeIDLtoTS(type, FileType.VALUETYPE) + "\n");
2784
+ out.write(declarator + "!: " + typeIDLtoTS(value_element.typeSpec, FileType.VALUETYPE) + "\n");
2962
2785
  }
2963
2786
  }
2964
2787
  }
2965
2788
  out.write("\n");
2966
2789
  writeIndent(out, indent + 1);
2967
2790
  out.write(`constructor(init?: Partial<value.${prefix}${identifier}>) {\n`);
2968
- if (inheritance_spec) {
2791
+ if (value_dcl.base.length > 0) {
2969
2792
  writeIndent(out, indent + 2);
2970
2793
  out.write("super(init)\n");
2971
2794
  }
@@ -2973,23 +2796,18 @@ function writeTSValueImplDefinitions(out, specification, prefix = "", indent = 0
2973
2796
  out.write(`value.${prefix}init${identifier}(this, init)\n`);
2974
2797
  writeIndent(out, indent + 1);
2975
2798
  out.write("}\n");
2976
- for (let i = 1; i < value_dcl.child.length; ++i) {
2977
- let value_element = value_dcl.child[i];
2799
+ for (let value_element of value_dcl.elements) {
2978
2800
  if (value_element.type === Type.SYN_OPERATION_DECLARATION) {
2979
2801
  let op_decl = value_element;
2980
- op_decl.child[0];
2981
- let type = op_decl.child[1];
2982
- let op_identifier = op_decl.child[2].text;
2983
- let parameter_decls = op_decl.child[3].child;
2802
+ let op_identifier = op_decl.name;
2803
+ let parameter_decls = op_decl.params;
2984
2804
  writeIndent(out, indent + 1);
2985
2805
  out.write("abstract ");
2986
2806
  out.write(op_identifier + "(");
2987
2807
  let comma = false;
2988
2808
  for (let parameter_dcl of parameter_decls) {
2989
- let attribute = parameter_dcl.child[0].type;
2990
- let type = parameter_dcl.child[1];
2991
- let param_identifier = parameter_dcl.child[2].text;
2992
- if (attribute !== Type.TKN_IN) {
2809
+ let param_identifier = parameter_dcl.name;
2810
+ if (parameter_dcl.attribute !== Type.TKN_IN) {
2993
2811
  throw Error("corba.js currently only supports 'in' parameters");
2994
2812
  }
2995
2813
  if (comma) {
@@ -3000,10 +2818,10 @@ function writeTSValueImplDefinitions(out, specification, prefix = "", indent = 0
3000
2818
  }
3001
2819
  out.write(param_identifier);
3002
2820
  out.write(": ");
3003
- out.write(typeIDLtoTS(type));
2821
+ out.write(typeIDLtoTS(parameter_dcl.typeSpec));
3004
2822
  }
3005
2823
  out.write("): ");
3006
- out.write(typeIDLtoTS(type));
2824
+ out.write(typeIDLtoTS(op_decl.returnType));
3007
2825
  out.write("\n");
3008
2826
  }
3009
2827
  }
@@ -3021,55 +2839,58 @@ var Direction;
3021
2839
  Direction[Direction["OUT"] = 1] = "OUT";
3022
2840
  Direction[Direction["NESTED"] = 1] = "NESTED";
3023
2841
  })(Direction || (Direction = {}));
2842
+ function resolvedType(type) {
2843
+ return type.type === Type.SYN_SCOPED_NAME ? resolvedType(type.target) : type.type;
2844
+ }
2845
+ function declarationName(declaration) {
2846
+ if (declaration.type === Type.SYN_SCOPED_NAME)
2847
+ return declarationName(declaration.target);
2848
+ return "name" in declaration ? declaration.name : "";
2849
+ }
3024
2850
  function typeIDLtoCC(type, direction) {
3025
- if (type === undefined)
3026
- throw Error("internal error: parser delivered no type information");
3027
2851
  switch (type.type) {
3028
- case Type.TKN_IDENTIFIER:
2852
+ case Type.SYN_SCOPED_NAME:
3029
2853
  {
3030
- let identifierType = type.child[type.child.length - 1];
3031
- let relativeName = "";
3032
- for (let x of type.child) {
3033
- relativeName = `${relativeName}.${x.text}`;
3034
- }
3035
- relativeName = relativeName.substring(1);
2854
+ const identifierType = type.target;
2855
+ let relativeName = [...type.path.map(x => x.name), declarationName(identifierType)].join("::");
3036
2856
  let absolutePrefix = "";
3037
- for (let x = type.child[0]?.typeParent; x; x = x.typeParent) {
3038
- absolutePrefix = `.${x.text}${absolutePrefix}`;
2857
+ for (let x = type.path.length > 0 ? type.path[0].parent : type.scope; x; x = x.parent) {
2858
+ absolutePrefix = `::${x.name}${absolutePrefix}`;
3039
2859
  }
3040
- if (type.child.length > 0 &&
3041
- type.child[0].type === Type.TKN_NATIVE &&
3042
- type.text.length > 4 &&
3043
- type.text.substring(type.text.length - 4) === "_ptr") {
3044
- return `${absolutePrefix.substring(1)} | undefined`;
2860
+ if (type.path.length === 0 &&
2861
+ resolvedType(identifierType) === Type.TKN_NATIVE &&
2862
+ type.name.length > 4 &&
2863
+ type.name.substring(type.name.length - 4) === "_ptr") {
2864
+ const ptrName = type.name.substring(0, type.name.length - 4);
2865
+ return `${absolutePrefix.length == 0 ? ptrName : `${absolutePrefix.substring(2)}::${ptrName}`} | undefined`;
3045
2866
  }
3046
2867
  let name;
3047
2868
  switch (identifierType.type) {
3048
2869
  case Type.TKN_VALUETYPE:
3049
2870
  throw Error("not implemented yet");
3050
2871
  case Type.SYN_INTERFACE:
3051
- name = absolutePrefix.length == 0 ? relativeName : `${absolutePrefix.substring(1)}.${relativeName}`;
2872
+ name = absolutePrefix.length == 0 ? relativeName : `${absolutePrefix.substring(2)}::${relativeName}`;
3052
2873
  name = `std::shared_ptr<${name}>`;
3053
2874
  break;
3054
2875
  case Type.TKN_ENUM:
3055
2876
  case Type.TKN_UNION:
3056
- name = absolutePrefix.length == 0 ? relativeName : `${absolutePrefix.substring(1)}.${relativeName}`;
2877
+ name = absolutePrefix.length == 0 ? relativeName : `${absolutePrefix.substring(2)}::${relativeName}`;
3057
2878
  break;
3058
2879
  case Type.TKN_STRUCT:
3059
- name = absolutePrefix.length == 0 ? relativeName : `${absolutePrefix.substring(1)}.${relativeName}`;
2880
+ name = absolutePrefix.length == 0 ? relativeName : `${absolutePrefix.substring(2)}::${relativeName}`;
3060
2881
  if (direction == Direction.IN) {
3061
2882
  name = `const ${name}&`;
3062
2883
  }
3063
2884
  break;
3064
2885
  case Type.TKN_NATIVE:
3065
2886
  name =
3066
- absolutePrefix.length == 0 ? relativeName : `${absolutePrefix.substring(1)}.${relativeName}`;
2887
+ absolutePrefix.length == 0 ? relativeName : `${absolutePrefix.substring(2)}::${relativeName}`;
3067
2888
  break;
3068
2889
  case Type.TKN_SEQUENCE:
3069
- name = typeIDLtoCC(type.child[0], direction);
2890
+ name = typeIDLtoCC(identifierType, direction);
3070
2891
  break;
3071
2892
  default:
3072
- throw Error(`Internal Error in typeIDLtoCC(): type ${identifierType.toString()} is not implemented`);
2893
+ return typeIDLtoCC(identifierType, direction);
3073
2894
  }
3074
2895
  return name;
3075
2896
  }
@@ -3109,7 +2930,7 @@ function typeIDLtoCC(type, direction) {
3109
2930
  throw Error("yikes");
3110
2931
  }
3111
2932
  case Type.TKN_SEQUENCE:
3112
- switch (type?.child[0]?.type) {
2933
+ switch (resolvedType(type.elementType)) {
3113
2934
  case Type.TKN_OCTET:
3114
2935
  switch (direction) {
3115
2936
  case Direction.IN:
@@ -3124,7 +2945,7 @@ function typeIDLtoCC(type, direction) {
3124
2945
  case Direction.IN:
3125
2946
  return `const std::vector<std::string_view> &`;
3126
2947
  case Direction.OUT:
3127
- return `std::vector<${typeIDLtoCC(type.child[0], direction)}>`;
2948
+ return `std::vector<${typeIDLtoCC(type.elementType, direction)}>`;
3128
2949
  default:
3129
2950
  throw Error("yikes");
3130
2951
  }
@@ -3132,54 +2953,51 @@ function typeIDLtoCC(type, direction) {
3132
2953
  case Type.TKN_DOUBLE:
3133
2954
  switch (direction) {
3134
2955
  case Direction.IN:
3135
- return `const std::span<${typeIDLtoCC(type.child[0], direction)}> &`;
2956
+ return `const std::span<${typeIDLtoCC(type.elementType, direction)}> &`;
3136
2957
  case Direction.OUT:
3137
- return `std::vector<${typeIDLtoCC(type.child[0], direction)}>`;
2958
+ return `std::vector<${typeIDLtoCC(type.elementType, direction)}>`;
3138
2959
  default:
3139
2960
  throw Error("yikes");
3140
2961
  }
3141
2962
  default:
3142
2963
  switch (direction) {
3143
2964
  case Direction.IN:
3144
- return `const std::vector<${typeIDLtoCC(type.child[0], Direction.NESTED)}> &`;
2965
+ return `const std::vector<${typeIDLtoCC(type.elementType, Direction.NESTED)}> &`;
3145
2966
  case Direction.OUT:
3146
- return `std::vector<${typeIDLtoCC(type.child[0], Direction.NESTED)}>`;
2967
+ return `std::vector<${typeIDLtoCC(type.elementType, Direction.NESTED)}>`;
3147
2968
  default:
3148
2969
  throw Error("yikes");
3149
2970
  }
3150
2971
  }
3151
2972
  default:
3152
- throw Error(`no mapping from IDL type to C++ type for ${type.toString()}`);
2973
+ throw Error(`no mapping from IDL type to C++ type for ${Type[type.type]}`);
3153
2974
  }
3154
2975
  }
3155
2976
 
3156
2977
  function typeIDLtoGIOPCC(type, arg, direction, struct = false) {
3157
- if (type === undefined)
3158
- throw Error("internal error: parser delivered no type information");
3159
2978
  let name;
3160
2979
  switch (type.type) {
3161
- case Type.TKN_IDENTIFIER:
3162
- case Type.TKN_MODULE:
3163
- return typeIDLtoGIOPCC(type.child[0], arg, direction, struct);
2980
+ case Type.SYN_SCOPED_NAME:
2981
+ return typeIDLtoGIOPCC(type.target, arg, direction, struct);
3164
2982
  case Type.TKN_VALUETYPE:
3165
- return arg === undefined ? `decoder.value("${type.text}")` : `encoder.value(${arg})`;
2983
+ return arg === undefined ? `decoder.value("${type.name}")` : `encoder.value(${arg})`;
3166
2984
  case Type.SYN_INTERFACE:
3167
2985
  switch (direction) {
3168
2986
  case Direction.IN:
3169
- return arg === undefined ? `${type.text}::_narrow(decoder.readObject(obj->get_ORB()))` : `encoder.writeObject(${arg}.get())`;
2987
+ return arg === undefined ? `${type.name}::_narrow(decoder.readObject(obj->get_ORB()))` : `encoder.writeObject(${arg}.get())`;
3170
2988
  case Direction.OUT:
3171
- return arg === undefined ? `${type.text}::_narrow(decoder.readObject(${struct ? "orb" : "get_ORB()"}))` : `encoder.writeObject(${arg}.get())`;
2989
+ return arg === undefined ? `${type.name}::_narrow(decoder.readObject(${struct ? "orb" : "get_ORB()"}))` : `encoder.writeObject(${arg}.get())`;
3172
2990
  }
3173
2991
  case Type.TKN_UNION:
3174
2992
  throw Error("union is not implemented yet");
3175
2993
  case Type.TKN_STRUCT: {
3176
2994
  return arg === undefined
3177
- ? `_decode${type.text}(get_ORB(), decoder)`
3178
- : `_encode${type.text}(encoder,${arg})`;
2995
+ ? `_decode${type.name}(get_ORB(), decoder)`
2996
+ : `_encode${type.name}(encoder,${arg})`;
3179
2997
  }
3180
2998
  case Type.TKN_NATIVE:
3181
2999
  {
3182
- const id = type.child[0].text;
3000
+ const id = type.name;
3183
3001
  if (id.length > 4 && id.substring(id.length - 4) === "_ptr") {
3184
3002
  return arg === undefined
3185
3003
  ? `decoder.value("${id.substring(0, id.length - 4)}")`
@@ -3237,9 +3055,9 @@ function typeIDLtoGIOPCC(type, arg, direction, struct = false) {
3237
3055
  }
3238
3056
  throw Error("yikes");
3239
3057
  case Type.TKN_ENUM:
3240
- return arg === undefined ? `static_cast<${type.text}>(decoder.readUlong())` : `encoder.writeUlong(std::to_underlying(${arg}))`;
3058
+ return arg === undefined ? `static_cast<${type.name}>(decoder.readUlong())` : `encoder.writeUlong(std::to_underlying(${arg}))`;
3241
3059
  case Type.TKN_SEQUENCE:
3242
- switch (type.child[0].type) {
3060
+ switch (resolvedType(type.elementType)) {
3243
3061
  case Type.TKN_OCTET: {
3244
3062
  switch (direction) {
3245
3063
  case Direction.IN:
@@ -3277,12 +3095,11 @@ function typeIDLtoGIOPCC(type, arg, direction, struct = false) {
3277
3095
  }
3278
3096
  default:
3279
3097
  return arg === undefined
3280
- ? `decoder.readSequence<${typeIDLtoCC(type.child[0], Direction.NESTED)}>([&] { return ${typeIDLtoGIOPCC(type.child[0], undefined, direction, struct)}; })`
3281
- : `encoder.writeSequence<${typeIDLtoCC(type.child[0], Direction.NESTED)}>(${arg}, [&](auto item) { ${typeIDLtoGIOPCC(type.child[0], "item", direction, struct)}; })`;
3098
+ ? `decoder.readSequence<${typeIDLtoCC(type.elementType, Direction.NESTED)}>([&] { return ${typeIDLtoGIOPCC(type.elementType, undefined, direction, struct)}; })`
3099
+ : `encoder.writeSequence<${typeIDLtoCC(type.elementType, Direction.NESTED)}>(${arg}, [&](auto item) { ${typeIDLtoGIOPCC(type.elementType, "item", direction, struct)}; })`;
3282
3100
  }
3283
3101
  default:
3284
- type.printTree();
3285
- throw Error(`no mapping from IDL type '${type.toString()}' to GIOP encoder/decoder`);
3102
+ throw Error(`no mapping from IDL type '${Type[type.type]}' to GIOP encoder/decoder`);
3286
3103
  }
3287
3104
  return arg === undefined ? `decoder.read${name}()` : `encoder.write${name}(${arg})`;
3288
3105
  }
@@ -3307,19 +3124,19 @@ function writeCCInterface(specification) {
3307
3124
  writeCCInterfaceDefinitions(out, specification);
3308
3125
  }
3309
3126
  function writeCCInterfaceDefinitions(out, specification, prefix = "", indent = 0) {
3310
- for (let definition of specification.child) {
3127
+ for (let definition of specification.definitions) {
3311
3128
  switch (definition.type) {
3312
3129
  case Type.TKN_MODULE:
3313
- out.write("namespace " + definition.text + " {\n\n");
3314
- writeCCInterfaceDefinitions(out, definition, prefix + definition.text + ".", indent + 1);
3315
- out.write("} // namespace " + definition.text + "\n\n");
3130
+ out.write("namespace " + definition.name + " {\n\n");
3131
+ writeCCInterfaceDefinitions(out, definition, prefix + definition.name + "::", indent + 1);
3132
+ out.write("} // namespace " + definition.name + "\n\n");
3316
3133
  break;
3317
3134
  case Type.SYN_INTERFACE:
3318
3135
  {
3319
- let interface_dcl = definition;
3320
- let identifier = interface_dcl.child[0].child[1].text;
3321
- let inheritance_spec = interface_dcl.child[0].child[2]?.text;
3322
- let interface_body = interface_dcl.child[1];
3136
+ let identifier = definition.name;
3137
+ let inheritance_spec = definition.base?.name;
3138
+ let interface_body = definition.body;
3139
+ writeDoc(out, definition.doc, 0);
3323
3140
  out.write(`class ${identifier}: public virtual ${inheritance_spec ? inheritance_spec : "CORBA::Object"} {\n`);
3324
3141
  out.write(`public:\n`);
3325
3142
  writeCCInterfaceBody(out, interface_body);
@@ -3331,19 +3148,15 @@ function writeCCInterfaceDefinitions(out, specification, prefix = "", indent = 0
3331
3148
  break;
3332
3149
  case Type.TKN_STRUCT:
3333
3150
  {
3334
- let struct_type = definition;
3335
- let identifier = struct_type.text;
3151
+ let identifier = definition.name;
3152
+ writeDoc(out, definition.doc, indent);
3336
3153
  writeIndent(out, indent);
3337
3154
  out.write(`struct ${identifier} {\n`);
3338
- for (let i = 0; i < struct_type.child.length; ++i) {
3339
- const member = struct_type.child[i];
3340
- if (member.type === Type.SYN_MEMBER) {
3341
- let type = member.child[0];
3342
- let declarators = member.child[1];
3343
- for (let declarator of declarators.child) {
3344
- writeIndent(out, indent + 1);
3345
- out.write(typeIDLtoCC(type, Direction.OUT) + " " + declarator.text + ";\n");
3346
- }
3155
+ for (const member of definition.members) {
3156
+ writeDoc(out, member.doc, indent + 1);
3157
+ for (let declarator of member.names) {
3158
+ writeIndent(out, indent + 1);
3159
+ out.write(typeIDLtoCC(member.typeSpec, Direction.OUT) + " " + declarator + ";\n");
3347
3160
  }
3348
3161
  }
3349
3162
  writeIndent(out, indent);
@@ -3352,42 +3165,49 @@ function writeCCInterfaceDefinitions(out, specification, prefix = "", indent = 0
3352
3165
  break;
3353
3166
  case Type.TKN_UNION:
3354
3167
  {
3355
- const identifier = definition.text;
3168
+ const identifier = definition.name;
3356
3169
  const union_type = definition;
3357
- const switch_body = union_type.child[1];
3170
+ writeDoc(out, union_type.doc, indent);
3171
+ const cases = union_type.cases.map(x => {
3172
+ if (x.type === Type.TKN_DEFAULT) {
3173
+ throw Error("union default branch is not implemented yet");
3174
+ }
3175
+ return x;
3176
+ });
3177
+ const switch_type = union_type.switchType.type === Type.SYN_SCOPED_NAME ? union_type.switchType.name : undefined;
3358
3178
  let composite = "";
3359
- switch_body.child.forEach(x => {
3360
- const case_label = x.child[0];
3361
- const type_spec = x.child[1];
3362
- const declarator = x.child[2];
3179
+ cases.forEach(x => {
3180
+ const case_label = x.label;
3181
+ const type_spec = x.typeSpec;
3182
+ const declarator = x.name;
3363
3183
  writeIndent(out, indent);
3364
- out.write(`export type _${identifier}_${declarator.text} = {\n`);
3184
+ out.write(`export type _${identifier}_${declarator} = {\n`);
3365
3185
  writeIndent(out, indent + 1);
3366
- out.write(`type: ${case_label.typeParent.text}.${case_label.text}\n`);
3186
+ out.write(`type: ${case_label.enum.name}.${case_label.name}\n`);
3367
3187
  writeIndent(out, indent + 1);
3368
- out.write(`${declarator.text}: ${typeIDLtoCC(type_spec, Direction.IN)}\n`);
3188
+ out.write(`${declarator}: ${typeIDLtoCC(type_spec, Direction.IN)}\n`);
3369
3189
  writeIndent(out, indent);
3370
3190
  out.write(`}\n`);
3371
3191
  if (composite.length !== 0)
3372
3192
  composite = `${composite} | `;
3373
- composite = `${composite}_${identifier}_${declarator.text}`;
3193
+ composite = `${composite}_${identifier}_${declarator}`;
3374
3194
  });
3375
3195
  writeIndent(out, indent);
3376
3196
  out.write(`export type ${identifier} = ${composite}\n`);
3377
3197
  writeIndent(out, indent);
3378
3198
  out.write(`export function decode${identifier}(decoder: GIOPDecoder): ${identifier} {\n`);
3379
3199
  writeIndent(out, indent + 1);
3380
- out.write(`switch(decoder.ulong() as ${union_type.child[0].text}) {\n`);
3381
- switch_body.child.forEach(x => {
3382
- const case_label = x.child[0];
3383
- const type_spec = x.child[1];
3384
- const declarator = x.child[2];
3200
+ out.write(`switch(decoder.ulong() as ${switch_type}) {\n`);
3201
+ cases.forEach(x => {
3202
+ const case_label = x.label;
3203
+ const type_spec = x.typeSpec;
3204
+ const declarator = x.name;
3385
3205
  writeIndent(out, indent + 2);
3386
- out.write(`case ${case_label.typeParent.text}.${case_label.text}: return {\n`);
3206
+ out.write(`case ${case_label.enum.name}.${case_label.name}: return {\n`);
3387
3207
  writeIndent(out, indent + 3);
3388
- out.write(`type: ${case_label.typeParent.text}.${case_label.text},\n`);
3208
+ out.write(`type: ${case_label.enum.name}.${case_label.name},\n`);
3389
3209
  writeIndent(out, indent + 3);
3390
- out.write(`${declarator.text}: ${typeIDLtoGIOPCC(type_spec, undefined, Direction.OUT)}\n`);
3210
+ out.write(`${declarator}: ${typeIDLtoGIOPCC(type_spec, undefined, Direction.OUT)}\n`);
3391
3211
  writeIndent(out, indent + 2);
3392
3212
  out.write(`}\n`);
3393
3213
  });
@@ -3403,14 +3223,14 @@ function writeCCInterfaceDefinitions(out, specification, prefix = "", indent = 0
3403
3223
  out.write(`encoder.ulong(obj.type)\n`);
3404
3224
  writeIndent(out, indent + 1);
3405
3225
  out.write(`switch(obj.type) {\n`);
3406
- switch_body.child.forEach(x => {
3407
- const case_label = x.child[0];
3408
- const type_spec = x.child[1];
3409
- const declarator = x.child[2];
3226
+ cases.forEach(x => {
3227
+ const case_label = x.label;
3228
+ const type_spec = x.typeSpec;
3229
+ const declarator = x.name;
3410
3230
  writeIndent(out, indent + 2);
3411
- out.write(`case ${case_label.typeParent.text}.${case_label.text}:\n`);
3231
+ out.write(`case ${case_label.enum.name}.${case_label.name}:\n`);
3412
3232
  writeIndent(out, indent + 3);
3413
- out.write(typeIDLtoGIOPCC(type_spec, `obj.${declarator.text}`, Direction.OUT) + "\n");
3233
+ out.write(typeIDLtoGIOPCC(type_spec, `obj.${declarator}`, Direction.OUT) + "\n");
3414
3234
  writeIndent(out, indent + 3);
3415
3235
  out.write(`break\n`);
3416
3236
  });
@@ -3421,12 +3241,14 @@ function writeCCInterfaceDefinitions(out, specification, prefix = "", indent = 0
3421
3241
  break;
3422
3242
  case Type.TKN_ENUM:
3423
3243
  {
3424
- const identifier = definition.text;
3244
+ const identifier = definition.name;
3245
+ writeDoc(out, definition.doc, indent);
3425
3246
  writeIndent(out, indent);
3426
3247
  out.write(`enum class ${identifier} {\n`);
3427
- for (const enumerator of definition.child) {
3248
+ for (const enumerator of definition.enumerators) {
3249
+ writeDoc(out, enumerator.doc, indent + 1);
3428
3250
  writeIndent(out, indent + 1);
3429
- out.write(`${enumerator.text},\n`);
3251
+ out.write(`${enumerator.name},\n`);
3430
3252
  }
3431
3253
  writeIndent(out, indent);
3432
3254
  out.write("};\n\n");
@@ -3436,20 +3258,18 @@ function writeCCInterfaceDefinitions(out, specification, prefix = "", indent = 0
3436
3258
  }
3437
3259
  }
3438
3260
  function writeCCInterfaceBody(out, interface_body) {
3439
- for (let _export of interface_body.child) {
3261
+ for (let _export of interface_body) {
3440
3262
  switch (_export.type) {
3441
3263
  case Type.SYN_OPERATION_DECLARATION:
3442
3264
  {
3443
3265
  let op_dcl = _export;
3444
- let attribute = op_dcl.child[0];
3445
- let type = op_dcl.child[1];
3446
- let oneway = false;
3447
- if (attribute !== undefined && attribute.type === Type.TKN_ONEWAY)
3448
- oneway = true;
3266
+ writeDoc(out, operationDoc(op_dcl), 1);
3267
+ let type = op_dcl.returnType;
3268
+ let oneway = op_dcl.oneway;
3449
3269
  if (oneway && type.type !== Type.TKN_VOID)
3450
3270
  throw Error("oneway methods must return void");
3451
- let identifier = op_dcl.child[2].text;
3452
- let parameter_decls = op_dcl.child[3].child;
3271
+ let identifier = op_dcl.name;
3272
+ let parameter_decls = op_dcl.params;
3453
3273
  out.write(" virtual ");
3454
3274
  if (oneway) {
3455
3275
  out.write(`${typeIDLtoCC(type, Direction.OUT)}`);
@@ -3460,10 +3280,7 @@ function writeCCInterfaceBody(out, interface_body) {
3460
3280
  out.write(` ${identifier}(`);
3461
3281
  let comma = false;
3462
3282
  for (let parameter_dcl of parameter_decls) {
3463
- let attribute = parameter_dcl.child[0].type;
3464
- let type = parameter_dcl.child[1];
3465
- let identifier = parameter_dcl.child[2].text;
3466
- if (attribute !== Type.TKN_IN) {
3283
+ if (parameter_dcl.attribute !== Type.TKN_IN) {
3467
3284
  throw Error("corba.js currently only supports 'in' parameters");
3468
3285
  }
3469
3286
  if (!comma) {
@@ -3472,18 +3289,17 @@ function writeCCInterfaceBody(out, interface_body) {
3472
3289
  else {
3473
3290
  out.write(", ");
3474
3291
  }
3475
- out.write(`${typeIDLtoCC(type, Direction.IN)} ${identifier}`);
3292
+ out.write(`${typeIDLtoCC(parameter_dcl.typeSpec, Direction.IN)} ${parameter_dcl.name}`);
3476
3293
  }
3477
3294
  out.write(`) = 0;\n`);
3478
3295
  }
3479
3296
  break;
3480
3297
  case Type.TKN_ATTRIBUTE:
3481
3298
  {
3482
- const readonly = _export.child[0]?.type == Type.TKN_READONLY;
3483
- const param_type_spec = _export.child[1];
3484
- const attr_declarator = _export.child[2];
3485
- for (const n of attr_declarator.child) {
3486
- const identifier = n.text;
3299
+ const readonly = _export.readonly;
3300
+ writeDoc(out, _export.doc, 1);
3301
+ const param_type_spec = _export.typeSpec;
3302
+ for (const identifier of _export.names) {
3487
3303
  out.write(` virtual CORBA::async<${typeIDLtoCC(param_type_spec, Direction.OUT)}> ${identifier}() = 0;\n`);
3488
3304
  if (!readonly) {
3489
3305
  out.write(` virtual CORBA::async<void> ${identifier}(${typeIDLtoCC(param_type_spec, Direction.IN)}) = 0;\n`);
@@ -3513,18 +3329,17 @@ function writeCCSkeleton(specification) {
3513
3329
  writeCCSkeletonDefinitions(out, specification);
3514
3330
  }
3515
3331
  function writeCCSkeletonDefinitions(out, specification, prefix = "", indent = 0) {
3516
- for (let definition of specification.child) {
3332
+ for (let definition of specification.definitions) {
3517
3333
  switch (definition.type) {
3518
3334
  case Type.TKN_MODULE:
3519
- out.write(`namespace ${definition.text}{\n\n`);
3520
- writeCCSkeletonDefinitions(out, definition, prefix + definition.text + ".", indent + 1);
3521
- out.write(`} // namespace ${definition.text}\n\n`);
3335
+ out.write(`namespace ${definition.name}{\n\n`);
3336
+ writeCCSkeletonDefinitions(out, definition, prefix + definition.name + "::", indent + 1);
3337
+ out.write(`} // namespace ${definition.name}\n\n`);
3522
3338
  break;
3523
3339
  case Type.SYN_INTERFACE:
3524
3340
  {
3525
- let interface_dcl = definition;
3526
- let identifier = interface_dcl.child[0].child[1].text;
3527
- let inheritance_spec = interface_dcl.child[0].child[2]?.text;
3341
+ let identifier = definition.name;
3342
+ let inheritance_spec = definition.base?.name;
3528
3343
  out.write(`class ${identifier}_skel: public virtual ${prefix}${identifier}, public virtual ${inheritance_spec ? inheritance_spec + "_skel" : "CORBA::Skeleton"} {\n`);
3529
3344
  out.write(`public:\n`);
3530
3345
  out.write(` ${identifier}_skel() : Skeleton() {}\n`);
@@ -3553,35 +3368,31 @@ function writeCCStub(specification) {
3553
3368
  writeCCStubDefinitions(out, specification);
3554
3369
  }
3555
3370
  function writeCCStubDefinitions(out, specification, prefix = "", indent = 0) {
3556
- for (let definition of specification.child) {
3371
+ for (let definition of specification.definitions) {
3557
3372
  switch (definition.type) {
3558
3373
  case Type.TKN_MODULE:
3559
- out.write("namespace " + definition.text + " {\n\n");
3560
- writeCCStubDefinitions(out, definition, prefix + definition.text + ".", indent + 1);
3561
- out.write("} // namespace " + definition.text + "\n\n");
3374
+ out.write("namespace " + definition.name + " {\n\n");
3375
+ writeCCStubDefinitions(out, definition, prefix + definition.name + "::", indent + 1);
3376
+ out.write("} // namespace " + definition.name + "\n\n");
3562
3377
  break;
3563
3378
  case Type.SYN_INTERFACE:
3564
3379
  {
3565
- let interface_dcl = definition;
3566
- let identifier = interface_dcl.child[0].child[1].text;
3567
- let inheritance_spec = interface_dcl.child[0].child[2]?.text;
3568
- let interface_body = interface_dcl.child[1];
3380
+ let identifier = definition.name;
3381
+ let inheritance_spec = definition.base?.name;
3382
+ let interface_body = definition.body;
3569
3383
  out.write(`class ${identifier}_stub: public virtual ${prefix}${identifier}, public virtual ${inheritance_spec ? inheritance_spec + "_stub" : "CORBA::Stub"} {\n`);
3570
3384
  out.write(`public:\n`);
3571
- for (let _export of interface_body.child) {
3385
+ for (let _export of interface_body) {
3572
3386
  switch (_export.type) {
3573
3387
  case Type.SYN_OPERATION_DECLARATION:
3574
3388
  {
3575
3389
  let op_dcl = _export;
3576
- let attribute = op_dcl.child[0];
3577
- let returnType = op_dcl.child[1];
3578
- let oneway = false;
3579
- if (attribute !== undefined && attribute.type === Type.TKN_ONEWAY)
3580
- oneway = true;
3390
+ let returnType = op_dcl.returnType;
3391
+ let oneway = op_dcl.oneway;
3581
3392
  if (oneway && returnType.type !== Type.TKN_VOID)
3582
3393
  console.log("WARNING: corba.js currently requires every oneway function to return void");
3583
- let identifier = op_dcl.child[2].text;
3584
- let parameter_decls = op_dcl.child[3].child;
3394
+ let identifier = op_dcl.name;
3395
+ let parameter_decls = op_dcl.params;
3585
3396
  out.write(" virtual ");
3586
3397
  if (oneway) {
3587
3398
  out.write(`${typeIDLtoCC(returnType, Direction.OUT)}`);
@@ -3592,10 +3403,7 @@ function writeCCStubDefinitions(out, specification, prefix = "", indent = 0) {
3592
3403
  out.write(` ${identifier}(`);
3593
3404
  let comma = false;
3594
3405
  for (let parameter_dcl of parameter_decls) {
3595
- let attribute = parameter_dcl.child[0].type;
3596
- let type = parameter_dcl.child[1];
3597
- let identifier = parameter_dcl.child[2].text;
3598
- if (attribute !== Type.TKN_IN) {
3406
+ if (parameter_dcl.attribute !== Type.TKN_IN) {
3599
3407
  throw Error("corba.js currently only supports 'in' parameters");
3600
3408
  }
3601
3409
  if (!comma) {
@@ -3604,18 +3412,16 @@ function writeCCStubDefinitions(out, specification, prefix = "", indent = 0) {
3604
3412
  else {
3605
3413
  out.write(", ");
3606
3414
  }
3607
- out.write(`${typeIDLtoCC(type, Direction.IN)} ${identifier}`);
3415
+ out.write(`${typeIDLtoCC(parameter_dcl.typeSpec, Direction.IN)} ${parameter_dcl.name}`);
3608
3416
  }
3609
3417
  out.write(`) override;\n`);
3610
3418
  }
3611
3419
  break;
3612
3420
  case Type.TKN_ATTRIBUTE:
3613
3421
  {
3614
- const readonly = _export.child[0]?.type == Type.TKN_READONLY;
3615
- const param_type_spec = _export.child[1];
3616
- const attr_declarator = _export.child[2];
3617
- for (const n of attr_declarator.child) {
3618
- const identifier = n.text;
3422
+ const readonly = _export.readonly;
3423
+ const param_type_spec = _export.typeSpec;
3424
+ for (const identifier of _export.names) {
3619
3425
  out.write(` virtual CORBA::async<${typeIDLtoCC(param_type_spec, Direction.OUT)}> ${identifier}() override;\n`);
3620
3426
  if (!readonly) {
3621
3427
  out.write(` virtual CORBA::async<void> ${identifier}(${typeIDLtoCC(param_type_spec, Direction.IN)}) override;\n`);
@@ -3653,36 +3459,31 @@ function writeCCCode(specification) {
3653
3459
  writeCCCodeDefinitions(out, specification);
3654
3460
  }
3655
3461
  function writeCCCodeDefinitions(out, specification, prefix = "", indent = 0) {
3656
- for (let definition of specification.child) {
3462
+ for (let definition of specification.definitions) {
3657
3463
  switch (definition.type) {
3658
3464
  case Type.TKN_MODULE:
3659
- out.write(`namespace ${definition.text}{\n\n`);
3660
- writeCCCodeDefinitions(out, definition, prefix + definition.text + ".", indent + 1);
3661
- out.write(`} // namespace ${definition.text}\n\n`);
3465
+ out.write(`namespace ${definition.name}{\n\n`);
3466
+ writeCCCodeDefinitions(out, definition, prefix + definition.name + "::", indent + 1);
3467
+ out.write(`} // namespace ${definition.name}\n\n`);
3662
3468
  break;
3663
3469
  case Type.SYN_INTERFACE:
3664
3470
  {
3665
- const interface_dcl = definition;
3666
- const if_identifier = interface_dcl.child[0].child[1].text;
3667
- let inheritance_spec_raw = interface_dcl.child[0].child[2];
3668
- let inheritance_spec = interface_dcl.child[0].child[2]?.text;
3669
- const interface_body = interface_dcl.child[1];
3670
- for (let _export of interface_body.child) {
3471
+ const if_identifier = definition.name;
3472
+ let inheritance_spec_raw = definition.base;
3473
+ let inheritance_spec = definition.base?.name;
3474
+ const interface_body = definition.body;
3475
+ for (let _export of interface_body) {
3671
3476
  switch (_export.type) {
3672
3477
  case Type.SYN_OPERATION_DECLARATION:
3673
3478
  {
3674
3479
  const op_dcl = _export;
3675
- const attribute = op_dcl.child[0];
3676
- const type = op_dcl.child[1];
3677
- let oneway = false;
3678
- if (attribute !== undefined && attribute.type === Type.TKN_ONEWAY) {
3679
- oneway = true;
3680
- }
3480
+ const type = op_dcl.returnType;
3481
+ const oneway = op_dcl.oneway;
3681
3482
  if (oneway && type.type !== Type.TKN_VOID) {
3682
3483
  throw Error("oneway methods must return void");
3683
3484
  }
3684
- let identifier = op_dcl.child[2].text;
3685
- let parameter_decls = op_dcl.child[3].child;
3485
+ let identifier = op_dcl.name;
3486
+ let parameter_decls = op_dcl.params;
3686
3487
  out.write(`static CORBA::async<> _${if_identifier}_${identifier}(${if_identifier} *obj, CORBA::GIOPDecoder &decoder, CORBA::GIOPEncoder &encoder) {\n`);
3687
3488
  switch (type.type) {
3688
3489
  case Type.TKN_VOID:
@@ -3698,9 +3499,7 @@ function writeCCCodeDefinitions(out, specification, prefix = "", indent = 0) {
3698
3499
  }
3699
3500
  let comma = false;
3700
3501
  for (let parameter_dcl of parameter_decls) {
3701
- let attribute = parameter_dcl.child[0].type;
3702
- let type = parameter_dcl.child[1];
3703
- if (attribute !== Type.TKN_IN) {
3502
+ if (parameter_dcl.attribute !== Type.TKN_IN) {
3704
3503
  throw Error("corba.js currently only supports 'in' parameters");
3705
3504
  }
3706
3505
  if (!comma) {
@@ -3709,7 +3508,7 @@ function writeCCCodeDefinitions(out, specification, prefix = "", indent = 0) {
3709
3508
  else {
3710
3509
  out.write(", ");
3711
3510
  }
3712
- out.write(`${typeIDLtoGIOPCC(type, undefined, Direction.IN)}`);
3511
+ out.write(`${typeIDLtoGIOPCC(parameter_dcl.typeSpec, undefined, Direction.IN)}`);
3713
3512
  }
3714
3513
  out.write(`);\n`);
3715
3514
  if (type.type !== Type.TKN_VOID) {
@@ -3719,7 +3518,7 @@ function writeCCCodeDefinitions(out, specification, prefix = "", indent = 0) {
3719
3518
  out.write(` co_return;\n`);
3720
3519
  }
3721
3520
  out.write(`}\n`);
3722
- let returnType = op_dcl.child[1];
3521
+ let returnType = op_dcl.returnType;
3723
3522
  if (oneway) {
3724
3523
  out.write(`${typeIDLtoCC(returnType, Direction.OUT)}`);
3725
3524
  }
@@ -3729,10 +3528,7 @@ function writeCCCodeDefinitions(out, specification, prefix = "", indent = 0) {
3729
3528
  out.write(` ${if_identifier}_stub::${identifier}(`);
3730
3529
  comma = false;
3731
3530
  for (let parameter_dcl of parameter_decls) {
3732
- let attribute = parameter_dcl.child[0].type;
3733
- let type = parameter_dcl.child[1];
3734
- let identifier = parameter_dcl.child[2].text;
3735
- if (attribute !== Type.TKN_IN) {
3531
+ if (parameter_dcl.attribute !== Type.TKN_IN) {
3736
3532
  throw Error("corba.js currently only supports 'in' parameters");
3737
3533
  }
3738
3534
  if (!comma) {
@@ -3741,7 +3537,7 @@ function writeCCCodeDefinitions(out, specification, prefix = "", indent = 0) {
3741
3537
  else {
3742
3538
  out.write(", ");
3743
3539
  }
3744
- out.write(`${typeIDLtoCC(type, Direction.IN)} ${identifier}`);
3540
+ out.write(`${typeIDLtoCC(parameter_dcl.typeSpec, Direction.IN)} ${parameter_dcl.name}`);
3745
3541
  }
3746
3542
  out.write(`) {\n`);
3747
3543
  out.write(" ");
@@ -3761,9 +3557,7 @@ function writeCCCodeDefinitions(out, specification, prefix = "", indent = 0) {
3761
3557
  }
3762
3558
  out.write(`[&](CORBA::GIOPEncoder &encoder) {\n`);
3763
3559
  for (let parameter_dcl of parameter_decls) {
3764
- let type = parameter_dcl.child[1];
3765
- let identifier = parameter_dcl.child[2].text;
3766
- out.write(` ${typeIDLtoGIOPCC(type, identifier, Direction.IN)};\n`);
3560
+ out.write(` ${typeIDLtoGIOPCC(parameter_dcl.typeSpec, parameter_dcl.name, Direction.IN)};\n`);
3767
3561
  }
3768
3562
  if (oneway) {
3769
3563
  out.write(` });\n`);
@@ -3783,11 +3577,9 @@ function writeCCCodeDefinitions(out, specification, prefix = "", indent = 0) {
3783
3577
  break;
3784
3578
  case Type.TKN_ATTRIBUTE:
3785
3579
  {
3786
- const readonly = _export.child[0]?.type == Type.TKN_READONLY;
3787
- const param_type_spec = _export.child[1];
3788
- const attr_declarator = _export.child[2];
3789
- for (const n of attr_declarator.child) {
3790
- const identifier = n.text;
3580
+ const readonly = _export.readonly;
3581
+ const param_type_spec = _export.typeSpec;
3582
+ for (const identifier of _export.names) {
3791
3583
  out.write(`static CORBA::async<> _${if_identifier}_get_${identifier}(${if_identifier} *obj, CORBA::GIOPDecoder &decoder, CORBA::GIOPEncoder &encoder) {\n`);
3792
3584
  out.write(` auto result = co_await obj->${identifier}();\n`);
3793
3585
  out.write(` ${typeIDLtoGIOPCC(param_type_spec, "result", Direction.OUT)};\n`);
@@ -3822,12 +3614,14 @@ function writeCCCodeDefinitions(out, specification, prefix = "", indent = 0) {
3822
3614
  writeDispatchBody(out, operationsWritten, if_identifier, interface_body);
3823
3615
  let inheritance_spec_iterator = inheritance_spec_raw;
3824
3616
  while (inheritance_spec_iterator) {
3825
- const interface_dcl = inheritance_spec_iterator.child[0];
3826
- const if_identifier = interface_dcl.child[0].child[1].text;
3827
- let inheritance_spec_raw = interface_dcl.child[0].child[2];
3828
- const interface_body = interface_dcl.child[1];
3617
+ const interface_dcl = inheritance_spec_iterator.target;
3618
+ if (interface_dcl.type !== Type.SYN_INTERFACE) {
3619
+ throw Error(`'${inheritance_spec_iterator.name}' is not an interface`);
3620
+ }
3621
+ const if_identifier = interface_dcl.name;
3622
+ const interface_body = interface_dcl.body;
3829
3623
  writeDispatchBody(out, operationsWritten, if_identifier, interface_body);
3830
- inheritance_spec_iterator = inheritance_spec_raw;
3624
+ inheritance_spec_iterator = interface_dcl.base;
3831
3625
  }
3832
3626
  out.write("};\n");
3833
3627
  out.write(`CORBA::async<> ${if_identifier}_skel::_dispatch(const std::string_view &operation, CORBA::GIOPDecoder &decoder, CORBA::GIOPEncoder &encoder) {\n`);
@@ -3885,32 +3679,22 @@ function writeCCCodeDefinitions(out, specification, prefix = "", indent = 0) {
3885
3679
  break;
3886
3680
  case Type.TKN_STRUCT: {
3887
3681
  let struct_type = definition;
3888
- let identifier = struct_type.text;
3682
+ let identifier = struct_type.name;
3889
3683
  out.write(`static ${identifier} _decode${identifier}(std::shared_ptr<CORBA::ORB> orb, CORBA::GIOPDecoder &decoder) {\n`);
3890
3684
  out.write(` return {\n`);
3891
- for (let i = 0; i < struct_type.child.length; ++i) {
3892
- const member = struct_type.child[i];
3893
- if (member.type === Type.SYN_MEMBER) {
3894
- let type = member.child[0];
3895
- let declarators = member.child[1];
3896
- for (let declarator of declarators.child) {
3897
- writeIndent(out, indent + 2);
3898
- out.write("." + declarator.text + " = " + typeIDLtoGIOPCC(type, undefined, Direction.OUT, true) + ",\n");
3899
- }
3685
+ for (const member of struct_type.members) {
3686
+ for (let declarator of member.names) {
3687
+ writeIndent(out, indent + 2);
3688
+ out.write("." + declarator + " = " + typeIDLtoGIOPCC(member.typeSpec, undefined, Direction.OUT, true) + ",\n");
3900
3689
  }
3901
3690
  }
3902
3691
  out.write(` };\n`);
3903
3692
  out.write(`}\n`);
3904
3693
  out.write(`static void _encode${identifier}(CORBA::GIOPEncoder &encoder, const ${identifier} &obj) {\n`);
3905
- for (let i = 0; i < struct_type.child.length; ++i) {
3906
- const member = struct_type.child[i];
3907
- if (member.type === Type.SYN_MEMBER) {
3908
- let type = member.child[0];
3909
- let declarators = member.child[1];
3910
- for (let declarator of declarators.child) {
3911
- writeIndent(out, indent + 1);
3912
- out.write(typeIDLtoGIOPCC(type, `obj.${declarator.text}`, Direction.OUT) + ";\n");
3913
- }
3694
+ for (const member of struct_type.members) {
3695
+ for (let declarator of member.names) {
3696
+ writeIndent(out, indent + 1);
3697
+ out.write(typeIDLtoGIOPCC(member.typeSpec, `obj.${declarator}`, Direction.OUT) + ";\n");
3914
3698
  }
3915
3699
  }
3916
3700
  out.write(`}\n`);
@@ -3919,14 +3703,12 @@ function writeCCCodeDefinitions(out, specification, prefix = "", indent = 0) {
3919
3703
  }
3920
3704
  }
3921
3705
  function writeDispatchBody(out, operationsWritten, if_identifier, interface_body) {
3922
- for (let _export of interface_body.child) {
3706
+ for (let _export of interface_body) {
3923
3707
  switch (_export.type) {
3924
3708
  case Type.SYN_OPERATION_DECLARATION:
3925
3709
  {
3926
3710
  const op_dcl = _export;
3927
- op_dcl.child[0];
3928
- op_dcl.child[1];
3929
- let identifier = op_dcl.child[2].text;
3711
+ let identifier = op_dcl.name;
3930
3712
  if (!operationsWritten.has(identifier)) {
3931
3713
  operationsWritten.add(identifier);
3932
3714
  out.write(` {"${identifier}", _${if_identifier}_${identifier}},\n`);
@@ -3935,11 +3717,8 @@ function writeDispatchBody(out, operationsWritten, if_identifier, interface_body
3935
3717
  break;
3936
3718
  case Type.TKN_ATTRIBUTE:
3937
3719
  {
3938
- const readonly = _export.child[0]?.type == Type.TKN_READONLY;
3939
- _export.child[1];
3940
- const attr_declarator = _export.child[2];
3941
- for (const n of attr_declarator.child) {
3942
- const identifier = n.text;
3720
+ const readonly = _export.readonly;
3721
+ for (const identifier of _export.names) {
3943
3722
  if (!operationsWritten.has(`_get_${identifier}`)) {
3944
3723
  operationsWritten.add(`_get_${identifier}`);
3945
3724
  if (!readonly) {
@@ -3983,8 +3762,6 @@ function main() {
3983
3762
  for (; i < process.argv.length; ++i) {
3984
3763
  setupFilenameVars(process.argv[i]);
3985
3764
  let syntaxTree = parseIDLFile();
3986
- if (verbose > 1)
3987
- syntaxTree.printTree();
3988
3765
  createOutputFiles(syntaxTree);
3989
3766
  }
3990
3767
  }