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