corba.js 0.0.12 → 0.1.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 (142) hide show
  1. package/LICENSE +70 -83
  2. package/README.IDL.txt +285 -0
  3. package/README.md +67 -39
  4. package/bin/corba-idl +15 -2
  5. package/lib/idl/idl.cjs +2732 -0
  6. package/lib/idl/idl.cjs.map +1 -0
  7. package/lib/idl/src/idl/idl-lexer.d.ts +19 -0
  8. package/lib/idl/src/idl/idl-node.d.ts +101 -0
  9. package/lib/idl/src/idl/idl-parser.d.ts +3 -0
  10. package/lib/idl/src/idl/idl.d.ts +1 -0
  11. package/lib/idl/src/idl/util.d.ts +25 -0
  12. package/lib/idl/src/idl/write-interface.d.ts +2 -0
  13. package/lib/idl/src/idl/write-skeleton.d.ts +2 -0
  14. package/lib/idl/src/idl/write-stub.d.ts +2 -0
  15. package/lib/idl/src/idl/write-value.d.ts +2 -0
  16. package/lib/idl/src/idl/write-valueimpl.d.ts +2 -0
  17. package/lib/idl/src/idl/write-valuetype.d.ts +2 -0
  18. package/lib/idl/src/index.d.ts +5 -0
  19. package/lib/idl/src/net/browser.d.ts +7 -0
  20. package/lib/idl/src/net/index.d.ts +3 -0
  21. package/lib/idl/src/net/tcp.d.ts +11 -0
  22. package/lib/idl/src/net/tls.d.ts +24 -0
  23. package/lib/idl/src/net/ws.d.ts +42 -0
  24. package/lib/idl/src/orb/asn1.d.ts +48 -0
  25. package/lib/idl/src/orb/connection.d.ts +24 -0
  26. package/lib/idl/src/orb/giop.d.ts +273 -0
  27. package/lib/idl/src/orb/index.d.ts +3 -0
  28. package/lib/idl/src/orb/ior.d.ts +89 -0
  29. package/lib/idl/src/orb/orb.d.ts +143 -0
  30. package/lib/idl/src/orb/protocol.d.ts +6 -0
  31. package/lib/idl/src/orb/uint8map.d.ts +14 -0
  32. package/lib/idl/src/orb/url.d.ts +55 -0
  33. package/lib/idl/test/access.spec.d.ts +1 -0
  34. package/lib/idl/test/attribute.spec.d.ts +1 -0
  35. package/lib/idl/test/basics.spec.d.ts +1 -0
  36. package/lib/idl/test/disconnect.spec.d.ts +1 -0
  37. package/lib/idl/test/eventtarget.spec.d.ts +1 -0
  38. package/lib/idl/test/fake.d.ts +31 -0
  39. package/lib/idl/test/giop.spec.d.ts +1 -0
  40. package/lib/idl/test/idl/idl.spec.d.ts +1 -0
  41. package/lib/idl/test/idl_module.spec.d.ts +1 -0
  42. package/lib/idl/test/initialreferences.spec.d.ts +1 -0
  43. package/lib/idl/test/net/tls.spec.d.ts +1 -0
  44. package/lib/idl/test/net/ws.spec.d.ts +1 -0
  45. package/lib/idl/test/net/wss.spec.d.ts +1 -0
  46. package/lib/idl/test/object_by_reference.spec.d.ts +1 -0
  47. package/lib/idl/test/orb/asn1.spec.d.ts +1 -0
  48. package/lib/idl/test/orb/url.spec.d.ts +1 -0
  49. package/lib/idl/test/stub.spec.d.ts +1 -0
  50. package/lib/idl/test/util.d.ts +5 -0
  51. package/lib/idl/test/valuetype.spec.d.ts +1 -0
  52. package/lib/{idl → src/idl}/idl-lexer.d.ts +0 -0
  53. package/lib/src/idl/idl-lexer.js +234 -0
  54. package/lib/src/idl/idl-lexer.js.map +1 -0
  55. package/lib/{idl → src/idl}/idl-node.d.ts +13 -10
  56. package/lib/{idl → src/idl}/idl-node.js +30 -49
  57. package/lib/src/idl/idl-node.js.map +1 -0
  58. package/lib/{idl → src/idl}/idl-parser.d.ts +0 -0
  59. package/lib/{idl → src/idl}/idl-parser.js +367 -291
  60. package/lib/src/idl/idl-parser.js.map +1 -0
  61. package/lib/{idl → src/idl}/idl.d.ts +0 -0
  62. package/lib/src/idl/idl.js +180 -0
  63. package/lib/src/idl/idl.js.map +1 -0
  64. package/lib/src/idl/util.d.ts +25 -0
  65. package/lib/src/idl/util.js +239 -0
  66. package/lib/src/idl/util.js.map +1 -0
  67. package/lib/src/idl/write-interface.d.ts +2 -0
  68. package/lib/src/idl/write-interface.js +111 -0
  69. package/lib/src/idl/write-interface.js.map +1 -0
  70. package/lib/src/idl/write-skeleton.d.ts +2 -0
  71. package/lib/src/idl/write-skeleton.js +116 -0
  72. package/lib/src/idl/write-skeleton.js.map +1 -0
  73. package/lib/src/idl/write-stub.d.ts +2 -0
  74. package/lib/src/idl/write-stub.js +116 -0
  75. package/lib/src/idl/write-stub.js.map +1 -0
  76. package/lib/src/idl/write-value.d.ts +2 -0
  77. package/lib/src/idl/write-value.js +205 -0
  78. package/lib/src/idl/write-value.js.map +1 -0
  79. package/lib/src/idl/write-valueimpl.d.ts +2 -0
  80. package/lib/src/idl/write-valueimpl.js +158 -0
  81. package/lib/src/idl/write-valueimpl.js.map +1 -0
  82. package/lib/src/idl/write-valuetype.d.ts +2 -0
  83. package/lib/src/idl/write-valuetype.js +98 -0
  84. package/lib/src/idl/write-valuetype.js.map +1 -0
  85. package/lib/src/index.d.ts +5 -0
  86. package/lib/src/index.js +6 -0
  87. package/lib/src/index.js.map +1 -0
  88. package/lib/src/net/browser.d.ts +7 -0
  89. package/lib/src/net/browser.js +54 -0
  90. package/lib/src/net/browser.js.map +1 -0
  91. package/lib/src/net/index.d.ts +3 -0
  92. package/lib/src/net/index.js +4 -0
  93. package/lib/src/net/index.js.map +1 -0
  94. package/lib/src/net/tcp.d.ts +11 -0
  95. package/lib/src/net/tcp.js +66 -0
  96. package/lib/src/net/tcp.js.map +1 -0
  97. package/lib/src/net/tls.d.ts +24 -0
  98. package/lib/src/net/tls.js +69 -0
  99. package/lib/src/net/tls.js.map +1 -0
  100. package/lib/src/net/ws.d.ts +42 -0
  101. package/lib/src/net/ws.js +158 -0
  102. package/lib/src/net/ws.js.map +1 -0
  103. package/lib/src/orb/asn1.d.ts +48 -0
  104. package/lib/src/orb/asn1.js +60 -0
  105. package/lib/src/orb/asn1.js.map +1 -0
  106. package/lib/src/orb/connection.d.ts +24 -0
  107. package/lib/src/orb/connection.js +19 -0
  108. package/lib/src/orb/connection.js.map +1 -0
  109. package/lib/src/orb/giop.d.ts +273 -0
  110. package/lib/src/orb/giop.js +1160 -0
  111. package/lib/src/orb/giop.js.map +1 -0
  112. package/lib/src/orb/index.d.ts +3 -0
  113. package/lib/src/orb/index.js +4 -0
  114. package/lib/src/orb/index.js.map +1 -0
  115. package/lib/src/orb/ior.d.ts +89 -0
  116. package/lib/src/orb/ior.js +110 -0
  117. package/lib/src/orb/ior.js.map +1 -0
  118. package/lib/src/orb/orb.d.ts +143 -0
  119. package/lib/src/orb/orb.js +693 -0
  120. package/lib/src/orb/orb.js.map +1 -0
  121. package/lib/src/orb/protocol.d.ts +6 -0
  122. package/lib/src/orb/protocol.js +2 -0
  123. package/lib/src/orb/protocol.js.map +1 -0
  124. package/lib/src/orb/uint8map.d.ts +14 -0
  125. package/lib/src/orb/uint8map.js +48 -0
  126. package/lib/src/orb/uint8map.js.map +1 -0
  127. package/lib/src/orb/url.d.ts +55 -0
  128. package/lib/src/orb/url.js +252 -0
  129. package/lib/src/orb/url.js.map +1 -0
  130. package/package.json +48 -24
  131. package/lib/idl/idl-lexer.js +0 -257
  132. package/lib/idl/idl-lexer.js.map +0 -1
  133. package/lib/idl/idl-node.js.map +0 -1
  134. package/lib/idl/idl-parser.js.map +0 -1
  135. package/lib/idl/idl.js +0 -946
  136. package/lib/idl/idl.js.map +0 -1
  137. package/lib/orb/orb-nodejs.d.ts +0 -7
  138. package/lib/orb/orb-nodejs.js +0 -111
  139. package/lib/orb/orb-nodejs.js.map +0 -1
  140. package/lib/orb/orb.d.ts +0 -62
  141. package/lib/orb/orb.js +0 -514
  142. package/lib/orb/orb.js.map +0 -1
package/lib/idl/idl.js DELETED
@@ -1,946 +0,0 @@
1
- "use strict";
2
- /*
3
- * corba.js Object Request Broker (ORB) and Interface Definition Language (IDL) compiler
4
- * Copyright (C) 2018, 2020 Mark-André Hopf <mhopf@mark13.org>
5
- *
6
- * This program is free software: you can redistribute it and/or modify
7
- * it under the terms of the GNU General Public License as published by
8
- * the Free Software Foundation, either version 3 of the License, or
9
- * (at your option) any later version.
10
- *
11
- * This program is distributed in the hope that it will be useful,
12
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
- * GNU General Public License for more details.
15
- *
16
- * You should have received a copy of the GNU General Public License
17
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
18
- */
19
- Object.defineProperty(exports, "__esModule", { value: true });
20
- const fs = require("fs");
21
- const idl_node_1 = require("./idl-node");
22
- const idl_lexer_1 = require("./idl-lexer");
23
- const idl_parser_1 = require("./idl-parser");
24
- let classAttributes = new Map();
25
- function writeIndent(out, indent) {
26
- for (let i = 0; i < indent; ++i)
27
- out.write(" ");
28
- }
29
- var FileType;
30
- (function (FileType) {
31
- FileType[FileType["NONE"] = 0] = "NONE";
32
- FileType[FileType["VALUE"] = 1] = "VALUE";
33
- FileType[FileType["VALUETYPE"] = 2] = "VALUETYPE";
34
- FileType[FileType["VALUEIMPL"] = 3] = "VALUEIMPL";
35
- FileType[FileType["INTERFACE"] = 4] = "INTERFACE";
36
- FileType[FileType["SKELETON"] = 5] = "SKELETON";
37
- FileType[FileType["STUB"] = 6] = "STUB";
38
- })(FileType || (FileType = {}));
39
- function typeIDLtoTS(type, filetype = FileType.NONE) {
40
- var _a;
41
- if (type === undefined)
42
- throw Error("internal error: parser delivered no type information");
43
- switch (type.type) {
44
- case idl_node_1.Type.TKN_IDENTIFIER:
45
- {
46
- let identifierType = type.child[type.child.length - 1];
47
- let relativeName = "";
48
- for (let x of type.child) {
49
- relativeName = `${relativeName}.${x.text}`;
50
- }
51
- relativeName = relativeName.substring(1);
52
- let absolutePrefix = "";
53
- for (let x = (_a = type.child[0]) === null || _a === void 0 ? void 0 : _a.typeParent; x; x = x.typeParent) {
54
- absolutePrefix = `.${x.text}${absolutePrefix}`;
55
- }
56
- if (type.child.length > 0 &&
57
- type.child[0].type === idl_node_1.Type.TKN_NATIVE &&
58
- type.text.length > 4 &&
59
- type.text.substring(type.text.length - 4) === "_ptr") {
60
- return `${absolutePrefix.substring(1)} | undefined`;
61
- }
62
- let name;
63
- switch (identifierType.type) {
64
- case idl_node_1.Type.TKN_VALUETYPE:
65
- if (filetype !== FileType.VALUETYPE)
66
- name = `valuetype${absolutePrefix}.${relativeName}`;
67
- else
68
- name = relativeName;
69
- break;
70
- case idl_node_1.Type.SYN_INTERFACE:
71
- if (filetype !== FileType.INTERFACE)
72
- name = `_interface${absolutePrefix}.${relativeName}`;
73
- else
74
- name = relativeName;
75
- break;
76
- case idl_node_1.Type.TKN_NATIVE:
77
- name = relativeName;
78
- break;
79
- default:
80
- throw Error(`Internal Error in typeIDLtoTS(): not implemented identifierType ${identifierType.toString()}`);
81
- }
82
- return name;
83
- }
84
- break;
85
- case idl_node_1.Type.TKN_VOID:
86
- return "void";
87
- case idl_node_1.Type.TKN_BOOLEAN:
88
- return "boolean";
89
- case idl_node_1.Type.TKN_STRING:
90
- return "string";
91
- case idl_node_1.Type.TKN_SHORT:
92
- case idl_node_1.Type.TKN_LONG:
93
- case idl_node_1.Type.SYN_LONGLONG:
94
- case idl_node_1.Type.SYN_UNSIGNED_SHORT:
95
- case idl_node_1.Type.SYN_UNSIGNED_LONG:
96
- case idl_node_1.Type.SYN_UNSIGNED_LONGLONG:
97
- case idl_node_1.Type.TKN_FLOAT:
98
- case idl_node_1.Type.TKN_DOUBLE:
99
- case idl_node_1.Type.SYN_LONG_DOUBLE:
100
- return "number";
101
- case idl_node_1.Type.TKN_SEQUENCE:
102
- return `Array<${typeIDLtoTS(type.child[0], filetype)}>`;
103
- default:
104
- throw Error(`no mapping from IDL type to TS type for ${type.toString()}`);
105
- }
106
- }
107
- function defaultValueIDLtoTS(type, filetype = FileType.NONE) {
108
- if (type === undefined)
109
- throw Error("internal error: parser delivered no type information");
110
- switch (type.type) {
111
- case idl_node_1.Type.TKN_IDENTIFIER:
112
- return "new " + type.text + "()";
113
- case idl_node_1.Type.TKN_BOOLEAN:
114
- return "false";
115
- case idl_node_1.Type.TKN_STRING:
116
- return "\"\"";
117
- case idl_node_1.Type.TKN_SHORT:
118
- case idl_node_1.Type.TKN_LONG:
119
- case idl_node_1.Type.SYN_LONGLONG:
120
- case idl_node_1.Type.SYN_UNSIGNED_SHORT:
121
- case idl_node_1.Type.SYN_UNSIGNED_LONG:
122
- case idl_node_1.Type.SYN_UNSIGNED_LONGLONG:
123
- case idl_node_1.Type.TKN_FLOAT:
124
- case idl_node_1.Type.TKN_DOUBLE:
125
- case idl_node_1.Type.SYN_LONG_DOUBLE:
126
- return "0";
127
- case idl_node_1.Type.TKN_SEQUENCE:
128
- return `new Array<${typeIDLtoTS(type.child[0], filetype)}>()`;
129
- default:
130
- throw Error(`no default value for IDL type in TS for type ${type.toString()}`);
131
- }
132
- }
133
- function hasValueType(specification) {
134
- for (let definition of specification.child) {
135
- switch (definition.type) {
136
- case idl_node_1.Type.TKN_VALUETYPE:
137
- return true;
138
- case idl_node_1.Type.TKN_MODULE:
139
- if (hasValueType(definition))
140
- return true;
141
- }
142
- }
143
- return false;
144
- }
145
- function hasNative(specification) {
146
- for (let definition of specification.child) {
147
- if (definition.type === idl_node_1.Type.TKN_NATIVE) {
148
- let native = definition;
149
- let nativeName = native.text;
150
- if (nativeName.length <= 4 ||
151
- nativeName.substring(nativeName.length - 4) !== "_ptr") {
152
- return true;
153
- }
154
- }
155
- }
156
- return false;
157
- }
158
- function hasOperationDeclarations(value_dcl) {
159
- for (let i = 1; i < value_dcl.child.length; ++i) {
160
- let value_element = value_dcl.child[i];
161
- if (value_element.type === idl_node_1.Type.SYN_OPERATION_DECLARATION) {
162
- return true;
163
- }
164
- }
165
- let value_header = value_dcl.child[0];
166
- let inheritance_spec = value_header.child[2];
167
- if (inheritance_spec !== undefined) {
168
- if (inheritance_spec.child[1].child[0].type === idl_node_1.Type.TKN_VALUETYPE) {
169
- let value_dcl = inheritance_spec.child[1].child[0];
170
- if (hasOperationDeclarations(value_dcl)) {
171
- return true;
172
- }
173
- }
174
- }
175
- return false;
176
- }
177
- function writeTSInterface(specification) {
178
- let out = fs.createWriteStream(filenamePrefix + ".ts");
179
- out.write("// This file is generated by the corba.js IDL compiler from '" + filename + "'.\n\n");
180
- if (hasValueType(specification)) {
181
- out.write("import * as valuetype from \"./" + filenameLocal + "_valuetype\"\n\n");
182
- }
183
- writeTSInterfaceDefinitions(out, specification);
184
- }
185
- function writeTSInterfaceDefinitions(out, specification, prefix = "", indent = 0) {
186
- for (let definition of specification.child) {
187
- switch (definition.type) {
188
- case idl_node_1.Type.TKN_MODULE:
189
- out.write("export namespace " + definition.text + " {\n\n");
190
- writeTSInterfaceDefinitions(out, definition, prefix + definition.text + ".", indent + 1);
191
- out.write("} // namespace " + definition.text + "\n\n");
192
- break;
193
- case idl_node_1.Type.SYN_INTERFACE:
194
- {
195
- let interface_dcl = definition;
196
- let identifier = interface_dcl.child[0].child[1].text;
197
- let interface_body = interface_dcl.child[1];
198
- out.write(`export interface ${identifier} {\n`);
199
- for (let _export of interface_body.child) {
200
- switch (_export.type) {
201
- case idl_node_1.Type.SYN_OPERATION_DECLARATION:
202
- {
203
- let op_dcl = _export;
204
- let attribute = op_dcl.child[0];
205
- let type = op_dcl.child[1];
206
- let oneway = false;
207
- if (attribute !== undefined && attribute.type === idl_node_1.Type.TKN_ONEWAY)
208
- oneway = true;
209
- if (oneway && type.type !== idl_node_1.Type.TKN_VOID)
210
- throw Error("corba.js currently requires every oneway function to return void");
211
- if (!oneway && type.type === idl_node_1.Type.TKN_VOID)
212
- throw Error("corba.js currently requires operations returning void to be oneway");
213
- let identifier = op_dcl.child[2].text;
214
- let parameter_decls = op_dcl.child[3].child;
215
- out.write(" ");
216
- out.write(identifier + "(");
217
- let comma = false;
218
- for (let parameter_dcl of parameter_decls) {
219
- let attribute = parameter_dcl.child[0].type;
220
- let type = parameter_dcl.child[1];
221
- let identifier = parameter_dcl.child[2].text;
222
- if (attribute !== idl_node_1.Type.TKN_IN) {
223
- throw Error("corba.js currently only supports 'in' parameters");
224
- }
225
- if (!comma) {
226
- comma = true;
227
- }
228
- else {
229
- out.write(", ");
230
- }
231
- out.write(identifier + ": " + typeIDLtoTS(type, FileType.INTERFACE));
232
- }
233
- out.write("): Promise<" + typeIDLtoTS(type, FileType.INTERFACE) + ">\n");
234
- }
235
- break;
236
- case idl_node_1.Type.TKN_ATTRIBUTE:
237
- {
238
- }
239
- break;
240
- default:
241
- throw Error("fuck");
242
- }
243
- }
244
- out.write("}\n\n");
245
- }
246
- break;
247
- }
248
- }
249
- }
250
- function writeTSSkeleton(specification) {
251
- let out = fs.createWriteStream(filenamePrefix + "_skel.ts");
252
- out.write("// This file is generated by the corba.js IDL compiler from '" + filename + "'.\n\n");
253
- out.write("import { ORB, Skeleton } from 'corba.js'\n");
254
- if (hasValueType(specification)) {
255
- out.write("import * as valuetype from \"./" + filenameLocal + "_valuetype\"\n");
256
- }
257
- out.write("import * as _interface from \"./" + filenameLocal + "\"\n\n");
258
- writeTSSkeletonDefitions(out, specification);
259
- }
260
- function writeTSSkeletonDefitions(out, specification, prefix = "", indent = 0) {
261
- for (let definition of specification.child) {
262
- switch (definition.type) {
263
- case idl_node_1.Type.TKN_MODULE:
264
- out.write("export namespace " + definition.text + " {\n\n");
265
- writeTSSkeletonDefitions(out, definition, prefix + definition.text + ".", indent + 1);
266
- out.write("} // namespace " + definition.text + "\n\n");
267
- break;
268
- case idl_node_1.Type.SYN_INTERFACE:
269
- {
270
- let interface_dcl = definition;
271
- let identifier = interface_dcl.child[0].child[1].text;
272
- let interface_body = interface_dcl.child[1];
273
- out.write(`export abstract class ${identifier} extends Skeleton implements _interface.${prefix}${identifier} {\n`);
274
- out.write(` constructor(orb: ORB) { super(orb) }\n`);
275
- out.write(" static _idlClassName(): string {\n");
276
- out.write(` return "${prefix}${identifier}"\n`);
277
- out.write(" }\n\n");
278
- for (let _export of interface_body.child) {
279
- switch (_export.type) {
280
- case idl_node_1.Type.SYN_OPERATION_DECLARATION:
281
- {
282
- let op_dcl = _export;
283
- let attribute = op_dcl.child[0];
284
- let type = op_dcl.child[1];
285
- let oneway = false;
286
- if (attribute !== undefined && attribute.type === idl_node_1.Type.TKN_ONEWAY)
287
- oneway = true;
288
- if (oneway && type.type !== idl_node_1.Type.TKN_VOID)
289
- throw Error("corba.js currently requires every oneway function to return void");
290
- if (!oneway && type.type === idl_node_1.Type.TKN_VOID)
291
- throw Error("corba.js currently requires operations returning void to be oneway");
292
- let identifier = op_dcl.child[2].text;
293
- let parameter_decls = op_dcl.child[3].child;
294
- out.write(` abstract ${identifier}(`);
295
- let comma = false;
296
- for (let parameter_dcl of parameter_decls) {
297
- let attribute = parameter_dcl.child[0].type;
298
- let type = parameter_dcl.child[1];
299
- let identifier = parameter_dcl.child[2].text;
300
- if (attribute !== idl_node_1.Type.TKN_IN) {
301
- throw Error("corba.js currently only supports 'in' parameters");
302
- }
303
- if (!comma) {
304
- comma = true;
305
- }
306
- else {
307
- out.write(", ");
308
- }
309
- out.write(identifier + ": " + typeIDLtoTS(type, FileType.SKELETON));
310
- }
311
- out.write(`): Promise<${typeIDLtoTS(type, FileType.SKELETON)}>\n`);
312
- }
313
- break;
314
- case idl_node_1.Type.TKN_ATTRIBUTE:
315
- {
316
- }
317
- break;
318
- default:
319
- throw Error("fuck");
320
- }
321
- }
322
- out.write("}\n\n");
323
- }
324
- break;
325
- }
326
- }
327
- }
328
- function writeTSStub(specification) {
329
- let out = fs.createWriteStream(filenamePrefix + "_stub.ts");
330
- out.write("// This file is generated by the corba.js IDL compiler from '" + filename + "'.\n\n");
331
- out.write("import { ORB, Stub } from 'corba.js'\n");
332
- if (hasValueType(specification)) {
333
- out.write("import * as valuetype from \"./" + filenameLocal + "_valuetype\"\n");
334
- }
335
- out.write("import * as _interface from \"./" + filenameLocal + "\"\n\n");
336
- writeTSStubDefinitions(out, specification);
337
- }
338
- function writeTSStubDefinitions(out, specification, prefix = "", indent = 0) {
339
- for (let definition of specification.child) {
340
- switch (definition.type) {
341
- case idl_node_1.Type.TKN_MODULE:
342
- out.write("export namespace " + definition.text + " {\n\n");
343
- writeTSStubDefinitions(out, definition, prefix + definition.text + ".", indent + 1);
344
- out.write("} // namespace " + definition.text + "\n\n");
345
- break;
346
- case idl_node_1.Type.SYN_INTERFACE:
347
- {
348
- let interface_dcl = definition;
349
- let identifier = interface_dcl.child[0].child[1].text;
350
- let interface_body = interface_dcl.child[1];
351
- out.write(`export class ${identifier} extends Stub implements _interface.${prefix}${identifier} {\n`);
352
- out.write(` static _idlClassName(): string {\n`);
353
- out.write(` return "${prefix}${identifier}"\n`);
354
- out.write(` }\n\n`);
355
- out.write(` static narrow(object: any): ${prefix}${identifier} {\n`);
356
- out.write(` if (object instanceof ${prefix}${identifier})\n`);
357
- out.write(` return object as ${prefix}${identifier}\n`);
358
- out.write(` throw Error("${prefix}${identifier}.narrow() failed")\n`);
359
- out.write(` }\n\n`);
360
- for (let _export of interface_body.child) {
361
- switch (_export.type) {
362
- case idl_node_1.Type.SYN_OPERATION_DECLARATION:
363
- {
364
- let op_dcl = _export;
365
- let attribute = op_dcl.child[0];
366
- let type = op_dcl.child[1];
367
- let oneway = false;
368
- if (attribute !== undefined && attribute.type === idl_node_1.Type.TKN_ONEWAY)
369
- oneway = true;
370
- if (oneway && type.type !== idl_node_1.Type.TKN_VOID)
371
- throw Error("corba.js currently requires every oneway function to return void");
372
- if (!oneway && type.type === idl_node_1.Type.TKN_VOID)
373
- throw Error("corba.js currently requires operations returning void to be oneway");
374
- let identifier = op_dcl.child[2].text;
375
- let parameter_decls = op_dcl.child[3].child;
376
- out.write(" async ");
377
- out.write(identifier + "(");
378
- let comma = false;
379
- for (let parameter_dcl of parameter_decls) {
380
- let attribute = parameter_dcl.child[0].type;
381
- let type = parameter_dcl.child[1];
382
- let identifier = parameter_dcl.child[2].text;
383
- if (attribute !== idl_node_1.Type.TKN_IN) {
384
- throw Error("corba.js currently only supports 'in' parameters");
385
- }
386
- if (!comma) {
387
- comma = true;
388
- }
389
- else {
390
- out.write(", ");
391
- }
392
- out.write(identifier + ": " + typeIDLtoTS(type, FileType.STUB));
393
- }
394
- out.write("): Promise<" + typeIDLtoTS(type, FileType.STUB) + "> {\n");
395
- out.write(" ");
396
- if (!oneway)
397
- out.write("return ");
398
- out.write(`await this.orb.call(this, ${oneway}, "${identifier}", [`);
399
- comma = false;
400
- for (let parameter_dcl of parameter_decls) {
401
- let identifier = parameter_dcl.child[2].text;
402
- if (!comma) {
403
- comma = true;
404
- }
405
- else {
406
- out.write(", ");
407
- }
408
- out.write(identifier);
409
- }
410
- out.write("])\n");
411
- out.write(" }\n");
412
- }
413
- break;
414
- case idl_node_1.Type.TKN_ATTRIBUTE:
415
- {
416
- }
417
- break;
418
- default:
419
- throw Error("fuck");
420
- }
421
- }
422
- out.write("}\n\n");
423
- }
424
- break;
425
- }
426
- }
427
- }
428
- let initCalls = "";
429
- function writeTSValue(specification) {
430
- initCalls = "";
431
- let out = fs.createWriteStream(filenamePrefix + "_value.ts");
432
- out.write("// This file is generated by the corba.js IDL compiler from '" + filename + "'.\n\n");
433
- out.write("import { ORB } from 'corba.js'\n");
434
- if (!hasValueType(specification)) {
435
- out.write("// no valuetype's defined in IDL");
436
- return;
437
- }
438
- // out.write("import * as _interface from \"./" + filenameLocal + "\"\n\n")
439
- if (hasNative(specification)) {
440
- out.write("declare global {\n");
441
- for (let definition of specification.child) {
442
- if (definition.type === idl_node_1.Type.TKN_NATIVE) {
443
- let native = definition;
444
- let nativeName = native.text;
445
- if (nativeName.length <= 4 ||
446
- nativeName.substring(nativeName.length - 4) !== "_ptr") {
447
- out.write(" interface " + nativeName + " {}\n");
448
- }
449
- }
450
- }
451
- out.write("}\n\n");
452
- }
453
- writeTSValueDefinitions(out, specification);
454
- out.write("\nlet initialized = false\n");
455
- out.write("export function _init() {\n");
456
- out.write(" if (initialized)\n");
457
- out.write(" return\n");
458
- out.write(" initialized = true\n");
459
- out.write(initCalls);
460
- out.write("}\n");
461
- out.write("_init()\n");
462
- }
463
- function writeTSValueDefinitions(out, specification, prefix = "", indent = 0) {
464
- var _a;
465
- for (let definition of specification.child) {
466
- switch (definition.type) {
467
- case idl_node_1.Type.TKN_MODULE:
468
- {
469
- writeIndent(out, indent);
470
- out.write("export namespace " + definition.text + " {\n\n");
471
- writeTSValueDefinitions(out, definition, prefix + definition.text + ".", indent + 1);
472
- writeIndent(out, indent);
473
- out.write("} // namespace " + definition.text + "\n\n");
474
- }
475
- break;
476
- case idl_node_1.Type.TKN_NATIVE:
477
- {
478
- }
479
- break;
480
- case idl_node_1.Type.TKN_VALUETYPE:
481
- {
482
- let value_dcl = definition;
483
- let value_header = value_dcl.child[0];
484
- let custom = value_header.child[0];
485
- let identifier = value_header.child[1].text;
486
- let inheritance_spec = value_header.child[2];
487
- writeIndent(out, indent);
488
- out.write(`export interface ${identifier}`);
489
- let attributes = new Array();
490
- classAttributes.set(prefix + identifier, attributes);
491
- if (inheritance_spec !== undefined) {
492
- if (inheritance_spec.child.length > 2) // FIXME: for interfaces we can
493
- throw Error("multiple inheritance is not supported for TypeScript");
494
- out.write(" extends " + inheritance_spec.child[1].text);
495
- let superAttributes = classAttributes.get(prefix + inheritance_spec.child[1].text);
496
- if (superAttributes === undefined) {
497
- superAttributes = classAttributes.get(inheritance_spec.child[1].text);
498
- }
499
- if (superAttributes === undefined) {
500
- throw Error("failed to find attributes for super class");
501
- }
502
- for (let attribute of superAttributes) {
503
- attributes.push(attribute);
504
- }
505
- }
506
- out.write(" {\n");
507
- for (let i = 1; i < value_dcl.child.length; ++i) {
508
- let value_element = value_dcl.child[i];
509
- if (value_element.type === idl_node_1.Type.SYN_STATE_MEMBER) {
510
- let state_member = value_element;
511
- let attribute = state_member.child[0];
512
- let type = state_member.child[1];
513
- let declarators = state_member.child[2];
514
- for (let declarator of declarators.child) {
515
- writeIndent(out, indent + 1);
516
- out.write(declarator.text + ": " + typeIDLtoTS(type, FileType.VALUETYPE) + "\n");
517
- attributes.push(declarator.text);
518
- }
519
- }
520
- }
521
- writeIndent(out, indent);
522
- out.write("}\n\n");
523
- writeIndent(out, indent);
524
- out.write(`export function init${identifier}(object: ${identifier}, init?: Partial<${identifier}>) {\n`);
525
- for (let i = 1; i < value_dcl.child.length; ++i) {
526
- let value_element = value_dcl.child[i];
527
- if (value_element.type === idl_node_1.Type.SYN_STATE_MEMBER) {
528
- let state_member = value_element;
529
- let attribute = state_member.child[0];
530
- let type = state_member.child[1];
531
- let declarators = state_member.child[2];
532
- for (let declarator of declarators.child) {
533
- let decl_identifier = declarator.text;
534
- writeIndent(out, indent + 1);
535
- if (type.type === idl_node_1.Type.TKN_IDENTIFIER) {
536
- // FIXME: doesn't work for Array<Layer>()
537
- // FIXME: in this case workflow doesn't require a copy, maybe just copy when the prototypes are wrong or a deep copy flag had been set?
538
- // out.write(") ? new "+type.text+"() : new "+type.text+"(init."+decl_identifier+")\n")
539
- // console.log(`writeTSValueDefinitions`, type, typeIDLtoTS(type))
540
- if (((_a = type.child[0]) === null || _a === void 0 ? void 0 : _a.type) == idl_node_1.Type.TKN_NATIVE &&
541
- type.text.length > 4 &&
542
- type.text.substring(type.text.length - 4) === "_ptr") {
543
- let name = typeIDLtoTS(type);
544
- out.write(`if (init !== undefined && init.${decl_identifier} !== undefined) object.${decl_identifier} = new (ORB.lookupValueType("${name}"))(init.${decl_identifier})\n`);
545
- }
546
- else {
547
- let name = typeIDLtoTS(type).substring(10); // hack: strip "valuetype."
548
- out.write(`object.${decl_identifier} = new (ORB.lookupValueType("${name}"))(init === undefined ? undefined : init.${decl_identifier})\n`);
549
- }
550
- }
551
- else {
552
- out.write(`object.${decl_identifier} = (init === undefined || init.${decl_identifier} === undefined) ? `);
553
- out.write(defaultValueIDLtoTS(type, FileType.VALUETYPE));
554
- out.write(` : init.${decl_identifier}\n`);
555
- }
556
- }
557
- }
558
- }
559
- writeIndent(out, indent);
560
- out.write("}\n\n");
561
- initCalls += ` ORB.valueTypeByName.set("${prefix}${identifier}", {attributes:[`;
562
- let comma = false;
563
- for (let attribute of attributes) {
564
- if (comma) {
565
- initCalls += ", ";
566
- }
567
- else {
568
- comma = true;
569
- }
570
- initCalls += `"${attribute}"`;
571
- }
572
- initCalls += "]})\n";
573
- }
574
- break;
575
- }
576
- }
577
- }
578
- function writeTSValueType(specification) {
579
- let out = fs.createWriteStream(filenamePrefix + "_valuetype.ts");
580
- out.write("// This file is generated by the corba.js IDL compiler from '" + filename + "'.\n\n");
581
- out.write("import { ORB } from 'corba.js'\n");
582
- if (!hasValueType(specification)) {
583
- out.write("// no valuetype's defined in IDL");
584
- return;
585
- }
586
- // out.write("import * as _interface from \"./" + filenameLocal + "\"\n\n")
587
- out.write(`import * as value from "./${filenameLocal}_value\"\n\n`);
588
- if (hasNative(specification)) {
589
- out.write("declare global {\n");
590
- for (let definition of specification.child) {
591
- if (definition.type === idl_node_1.Type.TKN_NATIVE) {
592
- let native = definition;
593
- let nativeName = native.text;
594
- if (nativeName.length <= 4 ||
595
- nativeName.substring(nativeName.length - 4) !== "_ptr") {
596
- out.write(" interface " + nativeName + " {}\n");
597
- }
598
- }
599
- }
600
- out.write("}\n\n");
601
- }
602
- writeTSValueTypeDefinitions(out, specification);
603
- }
604
- function writeTSValueTypeDefinitions(out, specification, prefix = "", indent = 0) {
605
- for (let definition of specification.child) {
606
- switch (definition.type) {
607
- case idl_node_1.Type.TKN_MODULE:
608
- {
609
- out.write(`export namespace ${definition.text} {\n\n`);
610
- writeTSValueTypeDefinitions(out, definition, prefix + definition.text + ".", indent + 1);
611
- out.write(`} // namespace ${definition.text}\n\n`);
612
- }
613
- break;
614
- case idl_node_1.Type.TKN_NATIVE:
615
- {
616
- }
617
- break;
618
- case idl_node_1.Type.TKN_VALUETYPE:
619
- {
620
- let value_dcl = definition;
621
- let value_header = value_dcl.child[0];
622
- let custom = value_header.child[0];
623
- let identifier = value_header.child[1].text;
624
- let inheritance_spec = value_header.child[2];
625
- writeIndent(out, indent);
626
- out.write(`export interface ${identifier} extends value.${prefix}${identifier}`); // FIXME: namespace
627
- if (inheritance_spec !== undefined) {
628
- if (inheritance_spec.child.length > 2)
629
- throw Error("multiple inheritance is not supported for TypeScript"); // FIXME: for interfaces we can
630
- out.write(", " + inheritance_spec.child[1].text);
631
- }
632
- out.write(" {\n");
633
- for (let i = 1; i < value_dcl.child.length; ++i) {
634
- let value_element = value_dcl.child[i];
635
- if (value_element.type === idl_node_1.Type.SYN_OPERATION_DECLARATION) {
636
- let op_decl = value_element;
637
- let attribute = op_decl.child[0];
638
- let type = op_decl.child[1];
639
- let op_identifier = op_decl.child[2].text;
640
- let parameter_decls = op_decl.child[3].child;
641
- writeIndent(out, indent + 1);
642
- out.write(op_identifier + "(");
643
- let comma = false;
644
- for (let parameter_dcl of parameter_decls) {
645
- let attribute = parameter_dcl.child[0].type;
646
- let type = parameter_dcl.child[1];
647
- let param_identifier = parameter_dcl.child[2].text;
648
- if (attribute !== idl_node_1.Type.TKN_IN) {
649
- throw Error("corba.js currently only supports 'in' parameters");
650
- }
651
- if (comma) {
652
- out.write(", ");
653
- }
654
- else {
655
- comma = true;
656
- }
657
- out.write(param_identifier);
658
- out.write(": ");
659
- out.write(typeIDLtoTS(type, FileType.VALUETYPE));
660
- }
661
- out.write("): ");
662
- out.write(typeIDLtoTS(type, FileType.VALUETYPE));
663
- out.write("\n");
664
- }
665
- }
666
- writeIndent(out, indent);
667
- out.write("}\n\n");
668
- }
669
- break;
670
- }
671
- }
672
- }
673
- function writeTSValueImpl(specification) {
674
- let out = fs.createWriteStream(filenamePrefix + "_valueimpl.ts");
675
- out.write(`// This file is generated by the corba.js IDL compiler from '${filename}'.\n\n`);
676
- out.write("import { ORB } from 'corba.js'\n");
677
- if (!hasValueType(specification)) {
678
- out.write("// no valuetype's defined in IDL");
679
- return;
680
- }
681
- out.write(`import * as value from "./${filenameLocal}_value"\n\n`);
682
- out.write(`import * as valuetype from "./${filenameLocal}_valuetype"\n\n`);
683
- out.write(`import * as _interface from "./${filenameLocal}"\n\n`);
684
- if (hasNative(specification)) {
685
- out.write("declare global {\n");
686
- for (let definition of specification.child) {
687
- switch (definition.type) {
688
- case idl_node_1.Type.TKN_NATIVE:
689
- {
690
- let native = definition;
691
- let nativeName = native.text;
692
- if (nativeName.length <= 4 ||
693
- nativeName.substring(nativeName.length - 4) !== "_ptr") {
694
- out.write(" interface " + nativeName + " {}\n");
695
- }
696
- }
697
- break;
698
- }
699
- }
700
- out.write("}\n\n");
701
- }
702
- writeTSValueImplDefinitions(out, specification);
703
- }
704
- function writeTSValueImplDefinitions(out, specification, prefix = "", indent = 0) {
705
- for (let definition of specification.child) {
706
- switch (definition.type) {
707
- case idl_node_1.Type.TKN_MODULE:
708
- {
709
- out.write("export namespace " + definition.text + " {\n\n");
710
- writeTSValueImplDefinitions(out, definition, prefix + definition.text + ".", indent + 1);
711
- out.write("} // namespace " + definition.text + "\n\n");
712
- }
713
- break;
714
- case idl_node_1.Type.TKN_NATIVE:
715
- {
716
- }
717
- break;
718
- case idl_node_1.Type.TKN_VALUETYPE:
719
- {
720
- let value_dcl = definition;
721
- let value_header = value_dcl.child[0];
722
- let custom = value_header.child[0];
723
- let identifier = value_header.child[1].text;
724
- let inheritance_spec = value_header.child[2];
725
- writeIndent(out, indent);
726
- out.write("export ");
727
- if (hasOperationDeclarations(value_dcl))
728
- out.write("abstract ");
729
- else if (inheritance_spec !== undefined) { // FIXME: this works only over one inheritance level, make it recursive
730
- if (inheritance_spec.child[1].child[0].type === idl_node_1.Type.TKN_VALUETYPE) {
731
- let value_dcl = inheritance_spec.child[1].child[0];
732
- if (hasOperationDeclarations(value_dcl))
733
- out.write("abstract ");
734
- }
735
- }
736
- out.write("class " + identifier);
737
- if (inheritance_spec !== undefined) {
738
- if (inheritance_spec.child.length > 2)
739
- throw Error("multiple inheritance is not supported for TypeScript");
740
- out.write(" extends " + inheritance_spec.child[1].text);
741
- }
742
- out.write(` implements valuetype.${prefix}${identifier} {\n`);
743
- for (let i = 1; i < value_dcl.child.length; ++i) {
744
- let value_element = value_dcl.child[i];
745
- if (value_element.type === idl_node_1.Type.SYN_STATE_MEMBER) {
746
- let state_member = value_element;
747
- let attribute = state_member.child[0];
748
- let type = state_member.child[1];
749
- let declarators = state_member.child[2];
750
- for (let declarator of declarators.child) {
751
- writeIndent(out, indent + 1);
752
- out.write(declarator.text + "!: " + typeIDLtoTS(type, FileType.VALUETYPE) + "\n");
753
- }
754
- }
755
- }
756
- out.write("\n");
757
- writeIndent(out, indent + 1);
758
- out.write(`constructor(init?: Partial<value.${prefix}${identifier}>) {\n`);
759
- if (inheritance_spec) {
760
- writeIndent(out, indent + 2);
761
- out.write("super(init)\n");
762
- }
763
- writeIndent(out, indent + 2);
764
- out.write(`value.${prefix}init${identifier}(this, init)\n`);
765
- writeIndent(out, indent + 1);
766
- out.write("}\n");
767
- for (let i = 1; i < value_dcl.child.length; ++i) {
768
- let value_element = value_dcl.child[i];
769
- if (value_element.type === idl_node_1.Type.SYN_OPERATION_DECLARATION) {
770
- let op_decl = value_element;
771
- let attribute = op_decl.child[0];
772
- let type = op_decl.child[1];
773
- let op_identifier = op_decl.child[2].text;
774
- let parameter_decls = op_decl.child[3].child;
775
- writeIndent(out, indent + 1);
776
- out.write("abstract ");
777
- out.write(op_identifier + "(");
778
- let comma = false;
779
- for (let parameter_dcl of parameter_decls) {
780
- let attribute = parameter_dcl.child[0].type;
781
- let type = parameter_dcl.child[1];
782
- let param_identifier = parameter_dcl.child[2].text;
783
- if (attribute !== idl_node_1.Type.TKN_IN) {
784
- throw Error("corba.js currently only supports 'in' parameters");
785
- }
786
- if (comma) {
787
- out.write(", ");
788
- }
789
- else {
790
- comma = true;
791
- }
792
- out.write(param_identifier);
793
- out.write(": ");
794
- out.write(typeIDLtoTS(type));
795
- }
796
- out.write("): ");
797
- out.write(typeIDLtoTS(type));
798
- out.write("\n");
799
- }
800
- }
801
- writeIndent(out, indent);
802
- out.write("}\n\n");
803
- }
804
- break;
805
- }
806
- }
807
- }
808
- function printHelp() {
809
- console.log(`corba.js IDL compiler
810
- Copyright (C) 2018, 2020 Mark-André Hopf <mhopf@mark13.org>
811
- This is free software; see the source for copying conditions. There is
812
- ABSOLUTELY NO WARRANTY; not even for MERCHANTABILITY or FITNESS FOR A
813
- PARTICULAR PURPOSE.
814
-
815
- Usage: corba-idl [options] file...
816
- Options:
817
- --ts-all create all TypeScript files
818
- --ts-interface create TypeScript interface file for stub and skeleton
819
- --ts-stub create TypeScript stub file
820
- --ts-skeleton create TypeScript skeleton file
821
- --ts-valuetype create TypeScript valuetype file
822
- --debug|-d increase debug level
823
- --help|-h this page
824
- `);
825
- }
826
- let debug = 0, tsInterface = false, tsStub = false, tsSkeleton = false, tsValueType = false, tsValueImpl = false;
827
- let i;
828
- argloop: for (i = 2; i < process.argv.length; ++i) {
829
- switch (process.argv[i]) {
830
- case "--":
831
- ++i;
832
- break argloop;
833
- case "--ts-all":
834
- tsInterface = tsStub = tsSkeleton = tsValueType = true;
835
- break;
836
- case "--ts-interface":
837
- tsInterface = true;
838
- break;
839
- case "--ts-stub":
840
- tsStub = true;
841
- break;
842
- case "--ts-skeleton":
843
- tsSkeleton = true;
844
- break;
845
- case "--ts-valuetype":
846
- tsValueType = true;
847
- break;
848
- // case "--ts-valueimpl":
849
- // tsValueImpl = true
850
- // break
851
- case "--debug":
852
- case "-d":
853
- ++debug;
854
- break;
855
- case "--help":
856
- case "-h":
857
- printHelp();
858
- process.exit(0);
859
- default:
860
- if (process.argv[i].length > 0 && process.argv[i].charAt(0) == "-") {
861
- console.log(`corba-idl: error: unrecognized command line option '${process.argv[i]}'`);
862
- process.exit(1);
863
- }
864
- break argloop;
865
- }
866
- }
867
- if (i === process.argv.length) {
868
- console.log("corba-idl: no input files");
869
- process.exit(1);
870
- }
871
- let filename = "";
872
- let filenamePrefix = "";
873
- let filenameLocal = "";
874
- for (; i < process.argv.length; ++i) {
875
- filename = process.argv[i];
876
- let n = filename.lastIndexOf(".");
877
- if (n === -1) {
878
- console.log(`corba-idl: error: filename '${filename}' must at least contain one dot ('.')`);
879
- process.exit(1);
880
- }
881
- filenamePrefix = filename.substr(0, n);
882
- n = filenamePrefix.lastIndexOf("/");
883
- if (n === -1)
884
- filenameLocal = filenamePrefix;
885
- else
886
- filenameLocal = filenamePrefix.substr(n + 1);
887
- let filedata;
888
- try {
889
- filedata = fs.readFileSync(filename, "utf8");
890
- }
891
- catch (error) {
892
- if (error instanceof Error)
893
- console.log(`corba-idl: error: failed to read file '${filename}': ${error.message}`);
894
- else
895
- console.log(error);
896
- process.exit(1);
897
- }
898
- let lexer = new idl_lexer_1.Lexer(filedata);
899
- let syntaxTree;
900
- try {
901
- syntaxTree = idl_parser_1.specification(lexer);
902
- }
903
- catch (error) {
904
- if (error instanceof Error) {
905
- console.log(`corba-idl: error: ${error.message} in file '${filename}' at line ${lexer.line}, column ${lexer.column}`);
906
- if (debug)
907
- console.log(error.stack);
908
- }
909
- else {
910
- console.log(error);
911
- }
912
- process.exit(1);
913
- }
914
- if (syntaxTree === undefined) {
915
- console.log("corba-idl: error: empty file or unexpected internal failure");
916
- process.exit(1);
917
- }
918
- if (debug > 1)
919
- syntaxTree.printTree();
920
- try {
921
- if (tsInterface)
922
- writeTSInterface(syntaxTree);
923
- if (tsSkeleton)
924
- writeTSSkeleton(syntaxTree);
925
- if (tsStub)
926
- writeTSStub(syntaxTree);
927
- if (tsValueType) {
928
- writeTSValue(syntaxTree);
929
- writeTSValueType(syntaxTree);
930
- }
931
- if (tsValueImpl)
932
- writeTSValueImpl(syntaxTree);
933
- }
934
- catch (error) {
935
- if (error instanceof Error) {
936
- console.log(`corba-idl: error: ${error.message} in file '${filename}'`);
937
- if (debug)
938
- console.log(error.stack);
939
- }
940
- else {
941
- console.log(error);
942
- }
943
- process.exit(1);
944
- }
945
- }
946
- //# sourceMappingURL=idl.js.map