corba.js 0.1.14 → 0.1.15

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