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
|
@@ -1,21 +1,22 @@
|
|
|
1
|
-
import { Type
|
|
1
|
+
import { Type } from "./idl-node.js";
|
|
2
|
+
import { describeToken } from "./idl-lexer.js";
|
|
2
3
|
let lexer;
|
|
3
4
|
let scoper;
|
|
4
5
|
export function specification(aLexer) {
|
|
5
6
|
lexer = aLexer;
|
|
6
7
|
scoper = new ScopeManager();
|
|
7
|
-
|
|
8
|
+
const definitions = [];
|
|
8
9
|
while (true) {
|
|
9
|
-
|
|
10
|
+
const t0 = definition();
|
|
10
11
|
if (t0 === undefined)
|
|
11
12
|
break;
|
|
12
|
-
|
|
13
|
+
definitions.push(t0);
|
|
13
14
|
}
|
|
14
15
|
const tail = lexer.lex();
|
|
15
16
|
if (tail !== undefined) {
|
|
16
|
-
throw Error(`Unparsed token '${tail
|
|
17
|
+
throw Error(`Unparsed token '${describeToken(tail)}' at end of specification.`);
|
|
17
18
|
}
|
|
18
|
-
return
|
|
19
|
+
return { type: Type.SYN_SPECIFICATION, definitions };
|
|
19
20
|
}
|
|
20
21
|
function definition() {
|
|
21
22
|
let t0;
|
|
@@ -34,25 +35,25 @@ function definition() {
|
|
|
34
35
|
return t0;
|
|
35
36
|
}
|
|
36
37
|
function _module() {
|
|
37
|
-
|
|
38
|
+
const t0 = lexer.lex();
|
|
38
39
|
if (t0 !== undefined && t0.type === Type.TKN_MODULE) {
|
|
39
|
-
|
|
40
|
+
const t1 = identifier();
|
|
40
41
|
if (t1 === undefined)
|
|
41
42
|
throw Error("expected identifier after 'module'");
|
|
42
|
-
|
|
43
|
+
const node = { type: Type.TKN_MODULE, name: t1.text, parent: scoper.getCurrentScope().node, definitions: [] };
|
|
43
44
|
expect("{");
|
|
44
|
-
scoper.enterModule(
|
|
45
|
+
scoper.enterModule(node);
|
|
45
46
|
while (true) {
|
|
46
|
-
|
|
47
|
+
const t2 = definition();
|
|
47
48
|
if (t2 === undefined)
|
|
48
49
|
break;
|
|
49
50
|
if (t2.type == Type.TKN_NATIVE)
|
|
50
51
|
throw Error("'native' can not be used within 'module'");
|
|
51
|
-
|
|
52
|
+
node.definitions.push(t2);
|
|
52
53
|
}
|
|
53
54
|
expect("}");
|
|
54
|
-
scoper.leaveModule(
|
|
55
|
-
return
|
|
55
|
+
scoper.leaveModule();
|
|
56
|
+
return node;
|
|
56
57
|
}
|
|
57
58
|
lexer.unlex(t0);
|
|
58
59
|
return undefined;
|
|
@@ -61,42 +62,39 @@ function _interface() {
|
|
|
61
62
|
return interface_dcl();
|
|
62
63
|
}
|
|
63
64
|
function interface_dcl() {
|
|
64
|
-
|
|
65
|
+
const doc = docBefore();
|
|
66
|
+
const t0 = interface_header();
|
|
65
67
|
if (!t0) {
|
|
66
|
-
|
|
67
|
-
if (
|
|
68
|
-
lexer.unlex(
|
|
68
|
+
const t = lexer.lex();
|
|
69
|
+
if (t) {
|
|
70
|
+
lexer.unlex(t);
|
|
69
71
|
}
|
|
70
72
|
return undefined;
|
|
71
73
|
}
|
|
72
|
-
|
|
74
|
+
const t1 = lexer.lex();
|
|
73
75
|
if (t1 === undefined)
|
|
74
76
|
throw Error("expected { after interface header but got end of file");
|
|
75
77
|
if (t1.type !== Type.TKN_TEXT && t1.text != '{')
|
|
76
|
-
throw Error(`expected { after interface header but got ${
|
|
77
|
-
|
|
78
|
-
scoper.addType(
|
|
79
|
-
node.
|
|
80
|
-
|
|
81
|
-
node.append(t2);
|
|
82
|
-
let t3 = lexer.lex();
|
|
78
|
+
throw Error(`expected { after interface header but got ${describeToken(t1)}`);
|
|
79
|
+
const node = { type: Type.SYN_INTERFACE, name: t0.name, modifier: t0.modifier, base: t0.base, body: [], doc };
|
|
80
|
+
scoper.addType(node.name, node);
|
|
81
|
+
node.body = interface_body();
|
|
82
|
+
const t3 = lexer.lex();
|
|
83
83
|
if (!t3)
|
|
84
84
|
throw Error("unexpected end of file");
|
|
85
85
|
if (t3.type !== Type.TKN_TEXT && t3.text != '}')
|
|
86
|
-
throw Error(`expected } after interface body but got '${t3}'`);
|
|
86
|
+
throw Error(`expected } after interface body but got '${describeToken(t3)}'`);
|
|
87
87
|
return node;
|
|
88
88
|
}
|
|
89
89
|
function interface_header() {
|
|
90
|
-
|
|
90
|
+
const t0 = lexer.lex();
|
|
91
91
|
if (t0 === undefined) {
|
|
92
92
|
return undefined;
|
|
93
93
|
}
|
|
94
|
-
let
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
}
|
|
99
|
-
else {
|
|
94
|
+
let modifier = undefined;
|
|
95
|
+
let t1 = t0;
|
|
96
|
+
if (t0.type === Type.TKN_ABSTRACT || t0.type === Type.TKN_LOCAL) {
|
|
97
|
+
modifier = t0.type;
|
|
100
98
|
t1 = lexer.lex();
|
|
101
99
|
}
|
|
102
100
|
if (t1 === undefined) {
|
|
@@ -105,27 +103,24 @@ function interface_header() {
|
|
|
105
103
|
}
|
|
106
104
|
if (t1.type !== Type.TKN_INTERFACE) {
|
|
107
105
|
lexer.unlex(t1);
|
|
108
|
-
|
|
106
|
+
if (modifier !== undefined)
|
|
107
|
+
lexer.unlex(t0);
|
|
109
108
|
return undefined;
|
|
110
109
|
}
|
|
111
|
-
|
|
110
|
+
const t2 = identifier();
|
|
112
111
|
if (t2 === undefined) {
|
|
113
112
|
throw Error("expected identifier after 'interface'");
|
|
114
113
|
}
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
header.append(t0);
|
|
118
|
-
header.append(t2);
|
|
119
|
-
header.append(t3);
|
|
120
|
-
return header;
|
|
114
|
+
const base = interface_inheritance_spec();
|
|
115
|
+
return { name: t2.text, modifier, base };
|
|
121
116
|
}
|
|
122
117
|
function interface_body() {
|
|
123
|
-
|
|
118
|
+
const body = [];
|
|
124
119
|
while (true) {
|
|
125
|
-
|
|
120
|
+
const t0 = _export();
|
|
126
121
|
if (t0 === undefined)
|
|
127
122
|
return body;
|
|
128
|
-
body.
|
|
123
|
+
body.push(t0);
|
|
129
124
|
}
|
|
130
125
|
}
|
|
131
126
|
function _export() {
|
|
@@ -155,12 +150,11 @@ function interface_inheritance_spec() {
|
|
|
155
150
|
throw Error("multiple inheritance is not implemented in corba.js");
|
|
156
151
|
}
|
|
157
152
|
lexer.unlex(token);
|
|
158
|
-
const
|
|
159
|
-
if (
|
|
153
|
+
const entry = scoper.getType(id.text);
|
|
154
|
+
if (entry === undefined) {
|
|
160
155
|
throw Error(`undefined interface ${id.text}`);
|
|
161
156
|
}
|
|
162
|
-
id.
|
|
163
|
-
return id;
|
|
157
|
+
return makeScopedName(id.text, [], entry);
|
|
164
158
|
}
|
|
165
159
|
function scoped_name() {
|
|
166
160
|
let globalNamespaceToken = undefined;
|
|
@@ -181,28 +175,33 @@ function scoped_name() {
|
|
|
181
175
|
lexer.unlex(globalNamespaceToken);
|
|
182
176
|
return undefined;
|
|
183
177
|
}
|
|
184
|
-
|
|
185
|
-
if (globalNamespaceToken === undefined) {
|
|
186
|
-
type = scoper.getType(identifierToken.text);
|
|
187
|
-
}
|
|
188
|
-
else {
|
|
189
|
-
type = scoper.getGlobalScope().getType(identifierToken.text);
|
|
178
|
+
if (globalNamespaceToken !== undefined) {
|
|
190
179
|
throw Error(`No way known to translate '::${identifierToken.text}' to TypeScript`);
|
|
191
180
|
}
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
if (
|
|
197
|
-
|
|
198
|
-
}
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
181
|
+
const entry = scoper.getType(identifierToken.text);
|
|
182
|
+
if (entry === undefined) {
|
|
183
|
+
throw Error(`unknown type ${describeToken(identifierToken)}`);
|
|
184
|
+
}
|
|
185
|
+
if (entry.target.type === Type.TKN_NATIVE) {
|
|
186
|
+
resolve_native_ptr(entry.target, entry.scope);
|
|
187
|
+
}
|
|
188
|
+
let current = entry;
|
|
189
|
+
let name = identifierToken.text;
|
|
190
|
+
const path = [];
|
|
191
|
+
while (current.target.type === Type.TKN_MODULE) {
|
|
192
|
+
const module = current.target;
|
|
193
|
+
path.push(module);
|
|
194
|
+
resolve_module_separator(name);
|
|
195
|
+
const identifier = lexer.lex();
|
|
196
|
+
if (identifier === undefined || identifier.type !== Type.TKN_IDENTIFIER)
|
|
197
|
+
throw Error(`Expected identifier after ::'`);
|
|
198
|
+
const child = find_in_module(module, identifier.text);
|
|
199
|
+
if (child === undefined)
|
|
200
|
+
throw Error(`failed to lookup ${identifier.text}`);
|
|
201
|
+
name = identifier.text;
|
|
202
|
+
current = { target: child, scope: module };
|
|
203
|
+
}
|
|
204
|
+
return makeScopedName(name, path, current);
|
|
206
205
|
}
|
|
207
206
|
function value() {
|
|
208
207
|
let t0;
|
|
@@ -230,85 +229,67 @@ function value_abs_dcl() {
|
|
|
230
229
|
return undefined;
|
|
231
230
|
}
|
|
232
231
|
function value_dcl() {
|
|
233
|
-
|
|
232
|
+
const doc = docBefore();
|
|
233
|
+
const header = value_header();
|
|
234
234
|
if (header === undefined) {
|
|
235
235
|
return undefined;
|
|
236
236
|
}
|
|
237
237
|
expect('{');
|
|
238
|
-
|
|
239
|
-
node.
|
|
240
|
-
let identifier = header.child[1].text;
|
|
241
|
-
node.text = identifier;
|
|
242
|
-
scoper.addType(identifier, node);
|
|
238
|
+
const node = { type: Type.TKN_VALUETYPE, name: header.name, base: header.base, elements: [], doc };
|
|
239
|
+
scoper.addType(node.name, node);
|
|
243
240
|
while (true) {
|
|
244
|
-
|
|
241
|
+
const t1 = value_element();
|
|
245
242
|
if (t1 === undefined)
|
|
246
243
|
break;
|
|
247
|
-
node.
|
|
244
|
+
node.elements.push(t1);
|
|
248
245
|
}
|
|
249
246
|
expect('}');
|
|
250
247
|
return node;
|
|
251
248
|
}
|
|
252
249
|
function value_header() {
|
|
253
|
-
|
|
250
|
+
const t0 = lexer.lex();
|
|
254
251
|
if (t0 !== undefined) {
|
|
255
|
-
|
|
256
|
-
if (t0.type === Type.TKN_CUSTOM) {
|
|
252
|
+
if (t0.type === Type.TKN_CUSTOM)
|
|
257
253
|
throw Error("corba.js currently does not support custom valuetypes");
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
t1 = t0;
|
|
261
|
-
t0 = undefined;
|
|
262
|
-
}
|
|
263
|
-
if (t1 !== undefined && t1.type === Type.TKN_VALUETYPE) {
|
|
264
|
-
let t2 = identifier();
|
|
254
|
+
if (t0.type === Type.TKN_VALUETYPE) {
|
|
255
|
+
const t2 = identifier();
|
|
265
256
|
if (t2 === undefined)
|
|
266
257
|
throw Error("expected an identifier after valuetype");
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
node.append(t0);
|
|
270
|
-
node.append(t2);
|
|
271
|
-
node.append(t3);
|
|
272
|
-
return node;
|
|
258
|
+
const base = value_inheritance_spec();
|
|
259
|
+
return { name: t2.text, base };
|
|
273
260
|
}
|
|
274
|
-
lexer.unlex(
|
|
261
|
+
lexer.unlex(t0);
|
|
275
262
|
}
|
|
276
|
-
lexer.unlex(t0);
|
|
277
263
|
return undefined;
|
|
278
264
|
}
|
|
279
265
|
function value_inheritance_spec() {
|
|
280
|
-
|
|
266
|
+
const t0 = lexer.lex();
|
|
281
267
|
if (t0 === undefined || t0.type !== Type.TKN_TEXT || t0.text !== ":") {
|
|
282
268
|
lexer.unlex(t0);
|
|
283
|
-
return
|
|
284
|
-
}
|
|
285
|
-
let t1 = lexer.lex();
|
|
286
|
-
if (t1 !== undefined && t1.type !== Type.TKN_TRUNCATABLE) {
|
|
287
|
-
lexer.unlex(t1);
|
|
288
|
-
t1 = undefined;
|
|
269
|
+
return [];
|
|
289
270
|
}
|
|
290
|
-
|
|
271
|
+
const t1 = lexer.lex();
|
|
272
|
+
if (t1 !== undefined && t1.type === Type.TKN_TRUNCATABLE)
|
|
291
273
|
throw Error("'truncatable' is not supported");
|
|
292
|
-
|
|
293
|
-
|
|
274
|
+
lexer.unlex(t1);
|
|
275
|
+
const base = [];
|
|
276
|
+
let separator = t0.text;
|
|
294
277
|
while (true) {
|
|
295
|
-
|
|
278
|
+
const t2 = value_name();
|
|
296
279
|
if (t2 === undefined) {
|
|
297
|
-
throw Error("expected a value name after '" +
|
|
280
|
+
throw Error("expected a value name after '" + separator + "'");
|
|
298
281
|
}
|
|
299
|
-
|
|
300
|
-
|
|
282
|
+
base.push(t2);
|
|
283
|
+
const t3 = lexer.lex();
|
|
301
284
|
if (t3 === undefined)
|
|
302
285
|
throw Error("unexpected end of file");
|
|
303
286
|
if (t3.type !== Type.TKN_TEXT || t3.text !== ",") {
|
|
304
287
|
lexer.unlex(t3);
|
|
305
288
|
break;
|
|
306
289
|
}
|
|
307
|
-
|
|
308
|
-
if (t0 === undefined)
|
|
309
|
-
throw Error("expected a value name after ':'");
|
|
290
|
+
separator = ",";
|
|
310
291
|
}
|
|
311
|
-
return
|
|
292
|
+
return base;
|
|
312
293
|
}
|
|
313
294
|
function value_name() {
|
|
314
295
|
return scoped_name();
|
|
@@ -320,80 +301,71 @@ function value_element() {
|
|
|
320
301
|
return t0;
|
|
321
302
|
}
|
|
322
303
|
function state_member() {
|
|
323
|
-
|
|
304
|
+
const doc = docBefore();
|
|
305
|
+
const t0 = lexer.lex();
|
|
324
306
|
if (t0 === undefined)
|
|
325
307
|
return undefined;
|
|
326
308
|
if (t0.type !== Type.TKN_PUBLIC && t0.type !== Type.TKN_PRIVATE) {
|
|
327
309
|
lexer.unlex(t0);
|
|
328
310
|
return undefined;
|
|
329
311
|
}
|
|
330
|
-
|
|
312
|
+
const t1 = type_spec();
|
|
331
313
|
if (t1 === undefined) {
|
|
332
314
|
lexer.unlex(t0);
|
|
333
315
|
return undefined;
|
|
334
316
|
}
|
|
335
|
-
|
|
336
|
-
if (
|
|
317
|
+
const names = declarators();
|
|
318
|
+
if (names === undefined) {
|
|
337
319
|
throw Error("expected declarators");
|
|
338
320
|
}
|
|
339
321
|
expect(";");
|
|
340
|
-
|
|
341
|
-
node.append(t0);
|
|
342
|
-
node.append(t1);
|
|
343
|
-
node.append(t2);
|
|
344
|
-
return node;
|
|
322
|
+
return { type: Type.SYN_STATE_MEMBER, visibility: t0.type, typeSpec: t1, names, doc };
|
|
345
323
|
}
|
|
346
324
|
function type_dcl() {
|
|
347
|
-
|
|
325
|
+
const t0 = lexer.lex();
|
|
348
326
|
if (t0 !== undefined && t0.type === Type.TKN_TYPEDEF) {
|
|
349
|
-
|
|
327
|
+
const t1 = type_declarator();
|
|
350
328
|
if (t1 === undefined) {
|
|
351
329
|
lexer.unlex(t0);
|
|
352
330
|
return undefined;
|
|
353
331
|
}
|
|
354
|
-
const
|
|
355
|
-
|
|
356
|
-
scoper.addType(id.text, t1.child[0]);
|
|
332
|
+
for (const name of t1.names) {
|
|
333
|
+
scoper.addType(name, t1.typeSpec);
|
|
357
334
|
}
|
|
358
|
-
t1.type = t0.type;
|
|
359
335
|
return t1;
|
|
360
336
|
}
|
|
361
337
|
lexer.unlex(t0);
|
|
362
|
-
|
|
363
|
-
if (
|
|
364
|
-
return
|
|
365
|
-
|
|
366
|
-
if (
|
|
367
|
-
return
|
|
368
|
-
|
|
369
|
-
if (
|
|
370
|
-
return
|
|
371
|
-
|
|
372
|
-
if (
|
|
373
|
-
|
|
374
|
-
if (
|
|
338
|
+
const t2 = struct_type();
|
|
339
|
+
if (t2 !== undefined)
|
|
340
|
+
return t2;
|
|
341
|
+
const t3 = union_type();
|
|
342
|
+
if (t3 !== undefined)
|
|
343
|
+
return t3;
|
|
344
|
+
const t4 = enum_type();
|
|
345
|
+
if (t4 !== undefined)
|
|
346
|
+
return t4;
|
|
347
|
+
const t5 = lexer.lex();
|
|
348
|
+
if (t5 !== undefined && t5.type === Type.TKN_NATIVE) {
|
|
349
|
+
const t6 = simple_declarator();
|
|
350
|
+
if (t6 === undefined) {
|
|
375
351
|
throw Error("expected simple declarator after 'native'");
|
|
376
352
|
}
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
return t0;
|
|
353
|
+
const node = { type: Type.TKN_NATIVE, name: t6.text };
|
|
354
|
+
scoper.addType(node.name, node);
|
|
355
|
+
return node;
|
|
381
356
|
}
|
|
382
|
-
lexer.unlex(
|
|
357
|
+
lexer.unlex(t5);
|
|
383
358
|
return undefined;
|
|
384
359
|
}
|
|
385
360
|
function type_declarator() {
|
|
386
361
|
const t0 = type_spec();
|
|
387
362
|
if (t0 === undefined)
|
|
388
363
|
return undefined;
|
|
389
|
-
const
|
|
390
|
-
if (
|
|
364
|
+
const names = declarators();
|
|
365
|
+
if (names === undefined) {
|
|
391
366
|
throw Error("expected at least one declarator");
|
|
392
367
|
}
|
|
393
|
-
|
|
394
|
-
n.append(t0);
|
|
395
|
-
n.append(t1);
|
|
396
|
-
return n;
|
|
368
|
+
return { type: Type.TKN_TYPEDEF, typeSpec: t0, names };
|
|
397
369
|
}
|
|
398
370
|
function type_spec() {
|
|
399
371
|
let t0;
|
|
@@ -461,10 +433,10 @@ function declarators() {
|
|
|
461
433
|
let t0 = declarator();
|
|
462
434
|
if (t0 === undefined)
|
|
463
435
|
return undefined;
|
|
464
|
-
|
|
436
|
+
const names = [];
|
|
465
437
|
while (true) {
|
|
466
|
-
|
|
467
|
-
|
|
438
|
+
names.push(t0.text);
|
|
439
|
+
const t1 = lexer.lex();
|
|
468
440
|
if (t1 === undefined || t1.type !== Type.TKN_TEXT || t1.text !== ",") {
|
|
469
441
|
lexer.unlex(t1);
|
|
470
442
|
break;
|
|
@@ -473,7 +445,7 @@ function declarators() {
|
|
|
473
445
|
if (t0 === undefined)
|
|
474
446
|
throw Error("expected another declarator after ','");
|
|
475
447
|
}
|
|
476
|
-
return
|
|
448
|
+
return names;
|
|
477
449
|
}
|
|
478
450
|
function declarator() {
|
|
479
451
|
let t0;
|
|
@@ -484,18 +456,17 @@ function simple_declarator() {
|
|
|
484
456
|
return identifier();
|
|
485
457
|
}
|
|
486
458
|
function floating_pt_type() {
|
|
487
|
-
|
|
459
|
+
const t0 = lexer.lex();
|
|
488
460
|
if (t0 === undefined)
|
|
489
461
|
return undefined;
|
|
490
462
|
if (t0.type === Type.TKN_FLOAT)
|
|
491
|
-
return
|
|
463
|
+
return { type: Type.TKN_FLOAT };
|
|
492
464
|
if (t0.type === Type.TKN_DOUBLE)
|
|
493
|
-
return
|
|
465
|
+
return { type: Type.TKN_DOUBLE };
|
|
494
466
|
if (t0.type === Type.TKN_LONG) {
|
|
495
|
-
|
|
467
|
+
const t1 = lexer.lex();
|
|
496
468
|
if (t1 !== undefined && t1.type === Type.TKN_DOUBLE) {
|
|
497
|
-
|
|
498
|
-
return t1;
|
|
469
|
+
return { type: Type.SYN_LONG_DOUBLE };
|
|
499
470
|
}
|
|
500
471
|
lexer.unlex(t1);
|
|
501
472
|
}
|
|
@@ -511,11 +482,11 @@ function integer_type() {
|
|
|
511
482
|
if (t0 !== undefined) {
|
|
512
483
|
return t0;
|
|
513
484
|
}
|
|
514
|
-
|
|
515
|
-
if (
|
|
485
|
+
const t1 = lexer.lex();
|
|
486
|
+
if (t1 !== undefined && [Type.TKN_SHORT, Type.TKN_LONG, Type.TKN_UNSIGNED].includes(t1.type)) {
|
|
516
487
|
throw Error('valid integer types are: short, unsigned short, long, unsigned long, long long, unsigned long long');
|
|
517
488
|
}
|
|
518
|
-
lexer.unlex(
|
|
489
|
+
lexer.unlex(t1);
|
|
519
490
|
return undefined;
|
|
520
491
|
}
|
|
521
492
|
function signed_int() {
|
|
@@ -532,28 +503,27 @@ function signed_int() {
|
|
|
532
503
|
return undefined;
|
|
533
504
|
}
|
|
534
505
|
function signed_short_int() {
|
|
535
|
-
|
|
506
|
+
const t0 = lexer.lex();
|
|
536
507
|
if (t0 !== undefined && t0.type === Type.TKN_SHORT)
|
|
537
|
-
return
|
|
508
|
+
return { type: Type.TKN_SHORT };
|
|
538
509
|
lexer.unlex(t0);
|
|
539
510
|
return undefined;
|
|
540
511
|
}
|
|
541
512
|
function signed_long_int() {
|
|
542
|
-
|
|
513
|
+
const t0 = lexer.lex();
|
|
543
514
|
if (t0 === undefined)
|
|
544
515
|
return undefined;
|
|
545
516
|
if (t0.type === Type.TKN_LONG)
|
|
546
|
-
return
|
|
517
|
+
return { type: Type.TKN_LONG };
|
|
547
518
|
lexer.unlex(t0);
|
|
548
519
|
return undefined;
|
|
549
520
|
}
|
|
550
521
|
function signed_longlong_int() {
|
|
551
|
-
|
|
522
|
+
const t0 = lexer.lex();
|
|
552
523
|
if (t0 !== undefined && t0.type === Type.TKN_LONG) {
|
|
553
|
-
|
|
524
|
+
const t1 = lexer.lex();
|
|
554
525
|
if (t1 !== undefined && t1.type === Type.TKN_LONG) {
|
|
555
|
-
|
|
556
|
-
return t0;
|
|
526
|
+
return { type: Type.SYN_LONGLONG };
|
|
557
527
|
}
|
|
558
528
|
lexer.unlex(t1);
|
|
559
529
|
}
|
|
@@ -574,12 +544,11 @@ function unsigned_int() {
|
|
|
574
544
|
return undefined;
|
|
575
545
|
}
|
|
576
546
|
function unsigned_short_int() {
|
|
577
|
-
|
|
547
|
+
const t0 = lexer.lex();
|
|
578
548
|
if (t0 !== undefined && t0.type === Type.TKN_UNSIGNED) {
|
|
579
|
-
|
|
549
|
+
const t1 = lexer.lex();
|
|
580
550
|
if (t1 !== undefined && t1.type === Type.TKN_SHORT) {
|
|
581
|
-
|
|
582
|
-
return t0;
|
|
551
|
+
return { type: Type.SYN_UNSIGNED_SHORT };
|
|
583
552
|
}
|
|
584
553
|
lexer.unlex(t1);
|
|
585
554
|
}
|
|
@@ -587,12 +556,11 @@ function unsigned_short_int() {
|
|
|
587
556
|
return undefined;
|
|
588
557
|
}
|
|
589
558
|
function unsigned_long_int() {
|
|
590
|
-
|
|
559
|
+
const t0 = lexer.lex();
|
|
591
560
|
if (t0 !== undefined && t0.type === Type.TKN_UNSIGNED) {
|
|
592
|
-
|
|
561
|
+
const t1 = lexer.lex();
|
|
593
562
|
if (t1 !== undefined && t1.type === Type.TKN_LONG) {
|
|
594
|
-
|
|
595
|
-
return t0;
|
|
563
|
+
return { type: Type.SYN_UNSIGNED_LONG };
|
|
596
564
|
}
|
|
597
565
|
lexer.unlex(t1);
|
|
598
566
|
}
|
|
@@ -600,14 +568,13 @@ function unsigned_long_int() {
|
|
|
600
568
|
return undefined;
|
|
601
569
|
}
|
|
602
570
|
function unsigned_longlong_int() {
|
|
603
|
-
|
|
571
|
+
const t0 = lexer.lex();
|
|
604
572
|
if (t0 !== undefined && t0.type === Type.TKN_UNSIGNED) {
|
|
605
|
-
|
|
573
|
+
const t1 = lexer.lex();
|
|
606
574
|
if (t1 !== undefined && t1.type === Type.TKN_LONG) {
|
|
607
|
-
|
|
575
|
+
const t2 = lexer.lex();
|
|
608
576
|
if (t2 !== undefined && t2.type === Type.TKN_LONG) {
|
|
609
|
-
|
|
610
|
-
return t0;
|
|
577
|
+
return { type: Type.SYN_UNSIGNED_LONGLONG };
|
|
611
578
|
}
|
|
612
579
|
lexer.unlex(t2);
|
|
613
580
|
}
|
|
@@ -617,41 +584,42 @@ function unsigned_longlong_int() {
|
|
|
617
584
|
return undefined;
|
|
618
585
|
}
|
|
619
586
|
function char_type() {
|
|
620
|
-
|
|
587
|
+
const t0 = lexer.lex();
|
|
621
588
|
if (t0 !== undefined && t0.type == Type.TKN_CHAR)
|
|
622
|
-
return
|
|
589
|
+
return { type: Type.TKN_CHAR };
|
|
623
590
|
lexer.unlex(t0);
|
|
624
591
|
return undefined;
|
|
625
592
|
}
|
|
626
593
|
function wide_char_type() {
|
|
627
|
-
|
|
594
|
+
const t0 = lexer.lex();
|
|
628
595
|
if (t0 !== undefined && t0.type == Type.TKN_WCHAR)
|
|
629
|
-
return
|
|
596
|
+
return { type: Type.TKN_WCHAR };
|
|
630
597
|
lexer.unlex(t0);
|
|
631
598
|
return undefined;
|
|
632
599
|
}
|
|
633
600
|
function boolean_type() {
|
|
634
|
-
|
|
601
|
+
const t0 = lexer.lex();
|
|
635
602
|
if (t0 !== undefined && t0.type == Type.TKN_BOOLEAN)
|
|
636
|
-
return
|
|
603
|
+
return { type: Type.TKN_BOOLEAN };
|
|
637
604
|
lexer.unlex(t0);
|
|
638
605
|
return undefined;
|
|
639
606
|
}
|
|
640
607
|
function octet_type() {
|
|
641
|
-
|
|
608
|
+
const t0 = lexer.lex();
|
|
642
609
|
if (t0 !== undefined && t0.type == Type.TKN_OCTET)
|
|
643
|
-
return
|
|
610
|
+
return { type: Type.TKN_OCTET };
|
|
644
611
|
lexer.unlex(t0);
|
|
645
612
|
return undefined;
|
|
646
613
|
}
|
|
647
614
|
function any_type() {
|
|
648
615
|
const t0 = lexer.lex();
|
|
649
616
|
if (t0 !== undefined && t0.type == Type.TKN_ANY)
|
|
650
|
-
return
|
|
617
|
+
return { type: Type.TKN_ANY };
|
|
651
618
|
lexer.unlex(t0);
|
|
652
619
|
return undefined;
|
|
653
620
|
}
|
|
654
621
|
function struct_type() {
|
|
622
|
+
const doc = docBefore();
|
|
655
623
|
const t0 = lexer.lex();
|
|
656
624
|
if (t0 === undefined || t0.type !== Type.TKN_STRUCT) {
|
|
657
625
|
lexer.unlex(t0);
|
|
@@ -661,71 +629,63 @@ function struct_type() {
|
|
|
661
629
|
if (t1 === undefined)
|
|
662
630
|
throw Error("expected identifier after 'struct'");
|
|
663
631
|
expect('{');
|
|
664
|
-
const
|
|
665
|
-
if (
|
|
632
|
+
const members = member_list();
|
|
633
|
+
if (members === undefined)
|
|
666
634
|
throw Error("expected at least one member within 'struct'");
|
|
667
635
|
expect('}');
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
return t2;
|
|
636
|
+
const node = { type: Type.TKN_STRUCT, name: t1.text, members, doc };
|
|
637
|
+
scoper.addType(node.name, node);
|
|
638
|
+
return node;
|
|
672
639
|
}
|
|
673
640
|
function member_list() {
|
|
674
|
-
const
|
|
675
|
-
if (t0 === undefined)
|
|
676
|
-
return undefined;
|
|
677
|
-
const node = new Node(Type.SYN_MEMBER_LIST);
|
|
678
|
-
node.append(t0);
|
|
641
|
+
const members = [];
|
|
679
642
|
while (true) {
|
|
680
643
|
const t1 = member();
|
|
681
644
|
if (t1 === undefined)
|
|
682
645
|
break;
|
|
683
|
-
|
|
646
|
+
members.push(t1);
|
|
684
647
|
}
|
|
685
|
-
return
|
|
648
|
+
return members.length > 0 ? members : undefined;
|
|
686
649
|
}
|
|
687
650
|
function member() {
|
|
688
|
-
const
|
|
651
|
+
const doc = docBefore();
|
|
689
652
|
const t0 = type_spec();
|
|
690
653
|
if (t0 === undefined)
|
|
691
654
|
return undefined;
|
|
692
|
-
const
|
|
693
|
-
if (
|
|
694
|
-
throw Error(`expected declarators after type_spec ${t0
|
|
655
|
+
const names = declarators();
|
|
656
|
+
if (names === undefined)
|
|
657
|
+
throw Error(`expected declarators after type_spec ${describeTypeSpec(t0)}`);
|
|
695
658
|
expect(";");
|
|
696
|
-
|
|
697
|
-
node.append(t1);
|
|
698
|
-
return node;
|
|
659
|
+
return { type: Type.SYN_MEMBER, typeSpec: t0, names, doc };
|
|
699
660
|
}
|
|
700
661
|
function union_type() {
|
|
701
|
-
|
|
662
|
+
const doc = docBefore();
|
|
663
|
+
const t0 = lexer.lex();
|
|
702
664
|
if (t0 === undefined)
|
|
703
665
|
return undefined;
|
|
704
666
|
if (t0.type !== Type.TKN_UNION) {
|
|
705
667
|
lexer.unlex(t0);
|
|
706
668
|
return undefined;
|
|
707
669
|
}
|
|
708
|
-
|
|
670
|
+
const t1 = identifier();
|
|
709
671
|
if (t1 === undefined)
|
|
710
672
|
throw Error(`expected identifier after 'union'`);
|
|
711
|
-
|
|
673
|
+
const t2 = lexer.lex();
|
|
712
674
|
if (t2 === undefined || t2.type !== Type.TKN_SWITCH) {
|
|
713
675
|
throw Error(`expected 'switch' after union <identifier>`);
|
|
714
676
|
}
|
|
715
677
|
expect("(");
|
|
716
|
-
|
|
717
|
-
if (
|
|
678
|
+
const switchType = switch_type_spec();
|
|
679
|
+
if (switchType === undefined) {
|
|
718
680
|
throw Error(`expected switch type specifier after union <identifier> switch(`);
|
|
719
681
|
}
|
|
720
682
|
expect(")");
|
|
721
683
|
expect("{");
|
|
722
|
-
|
|
684
|
+
const cases = switch_body();
|
|
723
685
|
expect("}");
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
scoper.addType(t0.text, t0);
|
|
728
|
-
return t0;
|
|
686
|
+
const node = { type: Type.TKN_UNION, name: t1.text, switchType, cases, doc };
|
|
687
|
+
scoper.addType(node.name, node);
|
|
688
|
+
return node;
|
|
729
689
|
}
|
|
730
690
|
function switch_type_spec() {
|
|
731
691
|
let t0 = integer_type();
|
|
@@ -743,204 +703,203 @@ function switch_type_spec() {
|
|
|
743
703
|
return scoped_name();
|
|
744
704
|
}
|
|
745
705
|
function switch_body() {
|
|
746
|
-
|
|
706
|
+
const cases = [];
|
|
747
707
|
while (true) {
|
|
748
708
|
const t1 = _case();
|
|
749
709
|
if (t1 === undefined)
|
|
750
710
|
break;
|
|
751
|
-
|
|
711
|
+
cases.push(t1);
|
|
752
712
|
}
|
|
753
|
-
return
|
|
713
|
+
return cases;
|
|
754
714
|
}
|
|
755
715
|
function _case() {
|
|
756
|
-
|
|
757
|
-
if (
|
|
758
|
-
return
|
|
759
|
-
|
|
760
|
-
if (
|
|
761
|
-
throw Error(`expected element specification after '${
|
|
762
|
-
t0.append(t1.child[0]);
|
|
763
|
-
t0.append(t1.child[1]);
|
|
716
|
+
const label = case_label();
|
|
717
|
+
if (label === undefined)
|
|
718
|
+
return undefined;
|
|
719
|
+
const element = element_spec();
|
|
720
|
+
if (element === undefined)
|
|
721
|
+
throw Error(`expected element specification after '${label.type === Type.TKN_CASE ? "case" : "default"}'`);
|
|
764
722
|
expect(";");
|
|
765
|
-
return
|
|
723
|
+
return { ...label, typeSpec: element.typeSpec, name: element.name };
|
|
766
724
|
}
|
|
767
725
|
function case_label() {
|
|
768
|
-
|
|
726
|
+
const t0 = lexer.lex();
|
|
769
727
|
if (t0 === undefined)
|
|
770
728
|
return undefined;
|
|
771
729
|
if (t0.type === Type.TKN_CASE) {
|
|
772
|
-
|
|
730
|
+
const t1 = identifier();
|
|
773
731
|
if (t1 === undefined) {
|
|
774
732
|
throw Error(`expected enum identifier after 'case'`);
|
|
775
733
|
}
|
|
776
|
-
const
|
|
777
|
-
if (
|
|
778
|
-
}
|
|
779
|
-
else {
|
|
734
|
+
const target = scoper.getType(t1.text)?.target;
|
|
735
|
+
if (target === undefined || target.type !== Type.SYN_ENUMERATOR) {
|
|
780
736
|
throw Error(`unsupported value after 'case'`);
|
|
781
737
|
}
|
|
782
738
|
expect(":");
|
|
783
|
-
|
|
784
|
-
return t0;
|
|
739
|
+
return { type: Type.TKN_CASE, label: target };
|
|
785
740
|
}
|
|
786
741
|
if (t0.type === Type.TKN_DEFAULT) {
|
|
787
742
|
expect(":");
|
|
788
|
-
return
|
|
743
|
+
return { type: Type.TKN_DEFAULT };
|
|
789
744
|
}
|
|
790
745
|
lexer.unlex(t0);
|
|
791
746
|
return undefined;
|
|
792
747
|
}
|
|
793
748
|
function element_spec() {
|
|
794
|
-
|
|
749
|
+
const t0 = type_spec();
|
|
795
750
|
if (t0 === undefined)
|
|
796
751
|
return undefined;
|
|
797
|
-
|
|
752
|
+
const t1 = declarator();
|
|
798
753
|
if (t1 === undefined)
|
|
799
|
-
throw Error(`expected declarator after ${t0}`);
|
|
800
|
-
|
|
801
|
-
t2.append(t0);
|
|
802
|
-
t2.append(t1);
|
|
803
|
-
return t2;
|
|
754
|
+
throw Error(`expected declarator after ${describeTypeSpec(t0)}`);
|
|
755
|
+
return { typeSpec: t0, name: t1.text };
|
|
804
756
|
}
|
|
805
757
|
function enum_type() {
|
|
806
|
-
|
|
758
|
+
const doc = docBefore();
|
|
759
|
+
const t0 = lexer.lex();
|
|
807
760
|
if (t0 !== undefined && t0.type == Type.TKN_ENUM) {
|
|
808
761
|
const t1 = identifier();
|
|
809
762
|
if (t1 === undefined)
|
|
810
763
|
throw Error("expected identifier after 'enum'");
|
|
811
|
-
|
|
764
|
+
const node = { type: Type.TKN_ENUM, name: t1.text, enumerators: [], doc };
|
|
812
765
|
expect("{");
|
|
813
766
|
const usedNames = new Set();
|
|
814
767
|
let t3;
|
|
815
768
|
while (true) {
|
|
816
|
-
|
|
769
|
+
const t2 = lexer.lex();
|
|
817
770
|
if (t2 === undefined) {
|
|
818
771
|
throw Error("unexpected end of file");
|
|
819
772
|
}
|
|
820
773
|
if (t2.type !== Type.TKN_IDENTIFIER) {
|
|
821
774
|
if (t3) {
|
|
822
|
-
throw Error(`expected identifier after ',' but got ${t2})`);
|
|
775
|
+
throw Error(`expected identifier after ',' but got ${describeToken(t2)})`);
|
|
823
776
|
}
|
|
824
777
|
else {
|
|
825
|
-
throw Error(`expected identifier but got ${t2})`);
|
|
778
|
+
throw Error(`expected identifier but got ${describeToken(t2)})`);
|
|
826
779
|
}
|
|
827
780
|
}
|
|
828
781
|
if (usedNames.has(t2.text)) {
|
|
829
782
|
throw Error(`Declaration of enumerator '${t2.text}' clashes with earlier declaration of enumerator '${t2.text}'`);
|
|
830
783
|
}
|
|
831
784
|
usedNames.add(t2.text);
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
785
|
+
const enumerator = { type: Type.SYN_ENUMERATOR, name: t2.text, enum: node, doc: t2.doc };
|
|
786
|
+
scoper.addType(enumerator.name, enumerator);
|
|
787
|
+
node.enumerators.push(enumerator);
|
|
835
788
|
t3 = lexer.lex();
|
|
836
789
|
if (t3 === undefined)
|
|
837
790
|
throw Error("unexpected end of file");
|
|
838
791
|
if (t3.type !== Type.TKN_TEXT)
|
|
839
|
-
throw Error(`expected ',' or '}' but got ${t3}`);
|
|
792
|
+
throw Error(`expected ',' or '}' but got ${describeToken(t3)}`);
|
|
840
793
|
if (t3.text === "}")
|
|
841
794
|
break;
|
|
842
795
|
if (t3.text !== ",") {
|
|
843
|
-
throw Error(`expected ',' or '}' but got ${t3}`);
|
|
796
|
+
throw Error(`expected ',' or '}' but got ${describeToken(t3)}`);
|
|
844
797
|
}
|
|
845
798
|
}
|
|
846
|
-
scoper.addType(
|
|
847
|
-
return
|
|
799
|
+
scoper.addType(node.name, node);
|
|
800
|
+
return node;
|
|
848
801
|
}
|
|
849
802
|
lexer.unlex(t0);
|
|
850
803
|
return undefined;
|
|
851
804
|
}
|
|
852
805
|
function sequence_type() {
|
|
853
|
-
|
|
806
|
+
const t0 = lexer.lex();
|
|
854
807
|
if (t0 !== undefined && t0.type === Type.TKN_SEQUENCE) {
|
|
855
808
|
expect("<");
|
|
856
|
-
|
|
857
|
-
if (
|
|
809
|
+
const elementType = simple_type_spec();
|
|
810
|
+
if (elementType === undefined)
|
|
858
811
|
throw Error("expected type after 'sequence <'");
|
|
859
812
|
expect(">");
|
|
860
|
-
|
|
861
|
-
t0.append(undefined);
|
|
862
|
-
return t0;
|
|
813
|
+
return { type: Type.TKN_SEQUENCE, elementType };
|
|
863
814
|
}
|
|
864
815
|
lexer.unlex(t0);
|
|
865
816
|
return undefined;
|
|
866
817
|
}
|
|
867
818
|
function string_type() {
|
|
868
|
-
|
|
819
|
+
const t0 = lexer.lex();
|
|
869
820
|
if (t0 !== undefined && t0.type === Type.TKN_STRING) {
|
|
870
|
-
return
|
|
821
|
+
return { type: Type.TKN_STRING };
|
|
871
822
|
}
|
|
872
823
|
lexer.unlex(t0);
|
|
873
824
|
return undefined;
|
|
874
825
|
}
|
|
875
826
|
function wide_string_type() {
|
|
876
|
-
|
|
827
|
+
const t0 = lexer.lex();
|
|
877
828
|
if (t0 !== undefined && t0.type === Type.TKN_WSTRING) {
|
|
878
|
-
return
|
|
829
|
+
return { type: Type.TKN_WSTRING };
|
|
879
830
|
}
|
|
880
831
|
lexer.unlex(t0);
|
|
881
832
|
return undefined;
|
|
882
833
|
}
|
|
883
834
|
function attr_dcl() {
|
|
835
|
+
const doc = docBefore();
|
|
884
836
|
let t0;
|
|
885
837
|
t0 = readonly_attr_spec();
|
|
886
838
|
if (t0 === undefined)
|
|
887
839
|
t0 = attr_spec();
|
|
840
|
+
if (t0 !== undefined)
|
|
841
|
+
t0.doc = doc;
|
|
888
842
|
return t0;
|
|
889
843
|
}
|
|
890
844
|
function except_dcl() {
|
|
891
|
-
|
|
845
|
+
const doc = docBefore();
|
|
846
|
+
const t0 = lexer.lex();
|
|
892
847
|
if (t0 === undefined || t0.type != Type.TKN_EXCEPTION) {
|
|
893
848
|
lexer.unlex(t0);
|
|
894
849
|
return undefined;
|
|
895
850
|
}
|
|
896
|
-
|
|
851
|
+
const t1 = identifier();
|
|
897
852
|
if (t1 === undefined)
|
|
898
|
-
throw Error(`expected identifier after '${t0
|
|
899
|
-
t0.text = t1.text;
|
|
853
|
+
throw Error(`expected identifier after '${describeToken(t0)}'`);
|
|
900
854
|
expect("{");
|
|
855
|
+
const members = [];
|
|
901
856
|
while (true) {
|
|
902
|
-
|
|
857
|
+
const t2 = member();
|
|
903
858
|
if (t2 === undefined)
|
|
904
859
|
break;
|
|
905
|
-
|
|
860
|
+
members.push(t2);
|
|
906
861
|
}
|
|
907
862
|
expect("}");
|
|
908
|
-
|
|
909
|
-
|
|
863
|
+
const node = { type: Type.TKN_EXCEPTION, name: t1.text, members, doc };
|
|
864
|
+
scoper.addType(node.name, node);
|
|
865
|
+
return node;
|
|
910
866
|
}
|
|
911
867
|
function op_dcl() {
|
|
912
|
-
const
|
|
913
|
-
const
|
|
914
|
-
|
|
915
|
-
|
|
868
|
+
const doc = docBefore();
|
|
869
|
+
const node_attribute = op_attribute();
|
|
870
|
+
const node_type = op_type_spec();
|
|
871
|
+
if (node_type === undefined) {
|
|
872
|
+
lexer.unlex(node_attribute);
|
|
916
873
|
return undefined;
|
|
917
874
|
}
|
|
918
|
-
const
|
|
919
|
-
if (
|
|
920
|
-
throw Error(`expected identifier after '${
|
|
875
|
+
const node_identifier = identifier();
|
|
876
|
+
if (node_identifier === undefined) {
|
|
877
|
+
throw Error(`expected identifier after '${describeTypeSpec(node_type)}'`);
|
|
921
878
|
}
|
|
922
|
-
const
|
|
923
|
-
if (
|
|
924
|
-
lexer.unlex(
|
|
925
|
-
if (
|
|
926
|
-
|
|
879
|
+
const node_parameter_dcls = parameter_dcls();
|
|
880
|
+
if (node_parameter_dcls === undefined) {
|
|
881
|
+
lexer.unlex(node_identifier);
|
|
882
|
+
if (node_type.type === Type.SYN_SCOPED_NAME || node_type.type === Type.TKN_SEQUENCE
|
|
883
|
+
|| node_type.type === Type.TKN_STRUCT || node_type.type === Type.TKN_UNION || node_type.type === Type.TKN_ENUM) {
|
|
884
|
+
throw Error("expected parameter declaration after " + describeToken(node_identifier));
|
|
927
885
|
}
|
|
928
|
-
lexer.unlex(
|
|
929
|
-
lexer.unlex(
|
|
886
|
+
lexer.unlex({ type: node_type.type });
|
|
887
|
+
lexer.unlex(node_attribute);
|
|
930
888
|
return undefined;
|
|
931
889
|
}
|
|
932
|
-
const
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
890
|
+
const raises = raises_expr() ?? [];
|
|
891
|
+
return {
|
|
892
|
+
type: Type.SYN_OPERATION_DECLARATION,
|
|
893
|
+
oneway: node_attribute !== undefined,
|
|
894
|
+
returnType: node_type,
|
|
895
|
+
name: node_identifier.text,
|
|
896
|
+
params: node_parameter_dcls,
|
|
897
|
+
raises,
|
|
898
|
+
doc
|
|
899
|
+
};
|
|
941
900
|
}
|
|
942
901
|
function op_attribute() {
|
|
943
|
-
|
|
902
|
+
const t0 = lexer.lex();
|
|
944
903
|
if (!t0)
|
|
945
904
|
return undefined;
|
|
946
905
|
if (t0.type !== Type.TKN_ONEWAY) {
|
|
@@ -950,17 +909,18 @@ function op_attribute() {
|
|
|
950
909
|
return t0;
|
|
951
910
|
}
|
|
952
911
|
function op_type_spec() {
|
|
953
|
-
|
|
954
|
-
if (t0 !== undefined)
|
|
955
|
-
return t0;
|
|
956
|
-
t0 = lexer.lex();
|
|
957
|
-
if (t0 !== undefined && t0.type === Type.TKN_VOID)
|
|
912
|
+
const t0 = param_type_spec();
|
|
913
|
+
if (t0 !== undefined) {
|
|
958
914
|
return t0;
|
|
959
|
-
|
|
915
|
+
}
|
|
916
|
+
const t1 = lexer.lex();
|
|
917
|
+
if (t1 !== undefined && t1.type === Type.TKN_VOID)
|
|
918
|
+
return { type: Type.TKN_VOID };
|
|
919
|
+
lexer.unlex(t1);
|
|
960
920
|
return undefined;
|
|
961
921
|
}
|
|
962
922
|
function parameter_dcls() {
|
|
963
|
-
|
|
923
|
+
const t0 = lexer.lex();
|
|
964
924
|
if (!t0) {
|
|
965
925
|
return undefined;
|
|
966
926
|
}
|
|
@@ -968,12 +928,12 @@ function parameter_dcls() {
|
|
|
968
928
|
lexer.unlex(t0);
|
|
969
929
|
return undefined;
|
|
970
930
|
}
|
|
971
|
-
|
|
931
|
+
const declarations = [];
|
|
972
932
|
while (true) {
|
|
973
|
-
|
|
933
|
+
const t1 = param_dcl();
|
|
974
934
|
if (t1 !== undefined)
|
|
975
|
-
declarations.
|
|
976
|
-
|
|
935
|
+
declarations.push(t1);
|
|
936
|
+
const t2 = lexer.lex();
|
|
977
937
|
if (t2 !== undefined && t2.type === Type.TKN_TEXT && t2.text === ')') {
|
|
978
938
|
break;
|
|
979
939
|
}
|
|
@@ -981,176 +941,227 @@ function parameter_dcls() {
|
|
|
981
941
|
continue;
|
|
982
942
|
}
|
|
983
943
|
if (t2 !== undefined)
|
|
984
|
-
throw Error("expected 'in', 'out', 'inout' or ')' to end for parameter declaration but got " + t2
|
|
944
|
+
throw Error("expected 'in', 'out', 'inout' or ')' to end for parameter declaration but got " + describeToken(t2));
|
|
985
945
|
else
|
|
986
946
|
throw Error("expected 'in', 'out', 'inout' or ')' to end for parameter declaration but end of file");
|
|
987
947
|
}
|
|
988
948
|
return declarations;
|
|
989
949
|
}
|
|
990
950
|
function param_dcl() {
|
|
991
|
-
|
|
992
|
-
|
|
951
|
+
const doc = docBefore();
|
|
952
|
+
const annotation = annotation_appl();
|
|
953
|
+
const attribute = param_attribute();
|
|
954
|
+
if (attribute === undefined)
|
|
993
955
|
return undefined;
|
|
994
|
-
|
|
995
|
-
if (
|
|
996
|
-
t1 = lexer.lex();
|
|
956
|
+
const typeSpec = param_type_spec();
|
|
957
|
+
if (typeSpec === undefined) {
|
|
958
|
+
const t1 = lexer.lex();
|
|
997
959
|
if (t1 !== undefined)
|
|
998
|
-
throw Error("expected type specification but got " + t1
|
|
960
|
+
throw Error("expected type specification but got " + describeToken(t1));
|
|
999
961
|
else
|
|
1000
962
|
throw Error("expected type specification but found end of file");
|
|
1001
963
|
}
|
|
1002
|
-
|
|
964
|
+
const t2 = simple_declarator();
|
|
1003
965
|
if (t2 === undefined) {
|
|
1004
966
|
throw Error("Missing parameter name.");
|
|
1005
967
|
}
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
return declaration;
|
|
968
|
+
if (annotation !== undefined && typeSpec.type === Type.TKN_SEQUENCE) {
|
|
969
|
+
typeSpec.annotation = annotation;
|
|
970
|
+
}
|
|
971
|
+
return { type: Type.SYN_PARAMETER_DECLARATION, attribute, typeSpec, name: t2.text, annotation, doc };
|
|
1011
972
|
}
|
|
1012
973
|
function param_attribute() {
|
|
1013
|
-
|
|
974
|
+
const t0 = lexer.lex();
|
|
1014
975
|
if (t0 === undefined)
|
|
1015
976
|
return undefined;
|
|
1016
977
|
switch (t0.type) {
|
|
1017
978
|
case Type.TKN_IN:
|
|
1018
979
|
case Type.TKN_OUT:
|
|
1019
980
|
case Type.TKN_INOUT:
|
|
1020
|
-
return t0;
|
|
981
|
+
return t0.type;
|
|
1021
982
|
}
|
|
1022
983
|
lexer.unlex(t0);
|
|
1023
984
|
return undefined;
|
|
1024
985
|
}
|
|
1025
986
|
function raises_expr() {
|
|
1026
|
-
|
|
987
|
+
const t0 = lexer.lex();
|
|
1027
988
|
if (t0 === undefined || t0.type !== Type.TKN_RAISES) {
|
|
1028
989
|
lexer.unlex(t0);
|
|
1029
990
|
return undefined;
|
|
1030
991
|
}
|
|
1031
992
|
expect("(");
|
|
1032
|
-
|
|
993
|
+
const raises = [];
|
|
994
|
+
const t1 = scoped_name();
|
|
1033
995
|
if (t1 === undefined)
|
|
1034
996
|
throw Error(`expected exception name after 'raises('`);
|
|
1035
|
-
if (t1.
|
|
1036
|
-
throw Error(`expected ${t1.
|
|
1037
|
-
|
|
1038
|
-
t0.append(t1);
|
|
997
|
+
if (t1.target.type !== Type.TKN_EXCEPTION)
|
|
998
|
+
throw Error(`expected ${t1.name} to be an exception`);
|
|
999
|
+
raises.push(t1);
|
|
1039
1000
|
while (true) {
|
|
1040
|
-
|
|
1041
|
-
if (t2 === undefined || t2.type !== Type.TKN_TEXT ||
|
|
1001
|
+
const t2 = lexer.lex();
|
|
1002
|
+
if (t2 === undefined || t2.type !== Type.TKN_TEXT || t2.text !== ",") {
|
|
1042
1003
|
lexer.unlex(t2);
|
|
1043
1004
|
break;
|
|
1044
1005
|
}
|
|
1045
|
-
|
|
1046
|
-
if (
|
|
1006
|
+
const t3 = scoped_name();
|
|
1007
|
+
if (t3 === undefined)
|
|
1047
1008
|
throw Error(`expected exception name after 'raises(..., '`);
|
|
1048
|
-
if (
|
|
1049
|
-
throw Error(`expected ${
|
|
1050
|
-
|
|
1009
|
+
if (t3.target.type !== Type.TKN_EXCEPTION)
|
|
1010
|
+
throw Error(`expected ${t3.name} to be an exception`);
|
|
1011
|
+
raises.push(t3);
|
|
1051
1012
|
}
|
|
1052
1013
|
expect(")");
|
|
1053
|
-
return
|
|
1014
|
+
return raises;
|
|
1054
1015
|
}
|
|
1055
1016
|
function param_type_spec() {
|
|
1056
|
-
|
|
1057
|
-
t0 = base_type_spec();
|
|
1058
|
-
if (t0
|
|
1059
|
-
|
|
1060
|
-
t0
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
return undefined;
|
|
1017
|
+
const annotation = annotation_appl();
|
|
1018
|
+
let t0 = base_type_spec();
|
|
1019
|
+
if (t0 === undefined)
|
|
1020
|
+
t0 = template_type_spec();
|
|
1021
|
+
if (t0 === undefined)
|
|
1022
|
+
t0 = scoped_name();
|
|
1023
|
+
if (t0 !== undefined && annotation !== undefined && t0.type === Type.TKN_SEQUENCE) {
|
|
1024
|
+
t0.annotation = annotation;
|
|
1025
|
+
}
|
|
1026
|
+
return t0;
|
|
1067
1027
|
}
|
|
1068
1028
|
function readonly_attr_spec() {
|
|
1069
|
-
|
|
1029
|
+
const t0 = lexer.lex();
|
|
1070
1030
|
if (t0 !== undefined && t0.type === Type.TKN_READONLY) {
|
|
1071
|
-
|
|
1031
|
+
const t1 = lexer.lex();
|
|
1072
1032
|
if (t1 !== undefined && t1.type === Type.TKN_ATTRIBUTE) {
|
|
1073
|
-
|
|
1074
|
-
if (
|
|
1033
|
+
const typeSpec = param_type_spec();
|
|
1034
|
+
if (typeSpec === undefined)
|
|
1075
1035
|
throw Error("expected type specifier after 'readonly attribute'");
|
|
1076
|
-
|
|
1077
|
-
if (
|
|
1036
|
+
const names = declarators();
|
|
1037
|
+
if (names === undefined)
|
|
1078
1038
|
throw Error("expected declarator for 'readonly attribute'");
|
|
1079
|
-
|
|
1080
|
-
t1.append(t2);
|
|
1081
|
-
t1.append(t3);
|
|
1082
|
-
return t1;
|
|
1039
|
+
return { type: Type.TKN_ATTRIBUTE, readonly: true, typeSpec, names };
|
|
1083
1040
|
}
|
|
1084
1041
|
lexer.unlex(t1);
|
|
1085
1042
|
}
|
|
1086
1043
|
lexer.unlex(t0);
|
|
1087
1044
|
return undefined;
|
|
1088
1045
|
}
|
|
1089
|
-
function readonly_attr_declarator() {
|
|
1090
|
-
let t0 = simple_declarator();
|
|
1091
|
-
if (t0 === undefined)
|
|
1092
|
-
return undefined;
|
|
1093
|
-
let node = new Node(Type.SYN_DECLARATORS);
|
|
1094
|
-
while (true) {
|
|
1095
|
-
node.append(t0);
|
|
1096
|
-
let t1 = lexer.lex();
|
|
1097
|
-
if (t1 === undefined || t1.type !== Type.TKN_TEXT || t1.text !== ",") {
|
|
1098
|
-
lexer.unlex(t1);
|
|
1099
|
-
return node;
|
|
1100
|
-
}
|
|
1101
|
-
t0 = simple_declarator();
|
|
1102
|
-
if (t0 === undefined)
|
|
1103
|
-
throw Error("expected another declarator after ','");
|
|
1104
|
-
}
|
|
1105
|
-
}
|
|
1106
1046
|
function attr_spec() {
|
|
1107
|
-
|
|
1047
|
+
const t0 = lexer.lex();
|
|
1108
1048
|
if (t0 !== undefined && t0.type === Type.TKN_ATTRIBUTE) {
|
|
1109
|
-
|
|
1110
|
-
if (
|
|
1049
|
+
const typeSpec = param_type_spec();
|
|
1050
|
+
if (typeSpec === undefined)
|
|
1111
1051
|
throw Error("expected type specifier after 'attribute'");
|
|
1112
|
-
|
|
1113
|
-
if (
|
|
1052
|
+
const names = declarators();
|
|
1053
|
+
if (names === undefined)
|
|
1114
1054
|
throw Error("expected declarator for 'attribute'");
|
|
1115
|
-
|
|
1116
|
-
t0.append(t1);
|
|
1117
|
-
t0.append(t2);
|
|
1118
|
-
return t0;
|
|
1055
|
+
return { type: Type.TKN_ATTRIBUTE, readonly: false, typeSpec, names };
|
|
1119
1056
|
}
|
|
1120
1057
|
lexer.unlex(t0);
|
|
1121
1058
|
return undefined;
|
|
1122
1059
|
}
|
|
1123
|
-
function
|
|
1124
|
-
|
|
1125
|
-
if (t0
|
|
1060
|
+
function annotation_appl() {
|
|
1061
|
+
const t0 = lexer.lex();
|
|
1062
|
+
if (t0?.text !== "@") {
|
|
1063
|
+
lexer.unlex(t0);
|
|
1126
1064
|
return undefined;
|
|
1127
|
-
|
|
1065
|
+
}
|
|
1066
|
+
const t1 = identifier();
|
|
1067
|
+
if (t1 === undefined) {
|
|
1068
|
+
throw Error("expeced identifier after @");
|
|
1069
|
+
}
|
|
1070
|
+
expect("(");
|
|
1071
|
+
const params = annotation_appl_params();
|
|
1072
|
+
expect(")");
|
|
1073
|
+
return { type: Type.SYN_ANNOTAION, name: t1.text, params };
|
|
1074
|
+
}
|
|
1075
|
+
function annotation_appl_params() {
|
|
1076
|
+
const params = [];
|
|
1128
1077
|
while (true) {
|
|
1129
|
-
|
|
1130
|
-
|
|
1131
|
-
if (t1
|
|
1078
|
+
params.push(annotation_appl_param());
|
|
1079
|
+
const t1 = lexer.lex();
|
|
1080
|
+
if (t1?.text !== ',') {
|
|
1132
1081
|
lexer.unlex(t1);
|
|
1133
|
-
|
|
1134
|
-
}
|
|
1135
|
-
t0 = simple_declarator();
|
|
1136
|
-
if (t0 === undefined) {
|
|
1137
|
-
throw Error("expected another declarator after ','");
|
|
1082
|
+
break;
|
|
1138
1083
|
}
|
|
1139
1084
|
}
|
|
1085
|
+
return params;
|
|
1086
|
+
}
|
|
1087
|
+
function annotation_appl_param() {
|
|
1088
|
+
const id = identifier();
|
|
1089
|
+
if (id === undefined) {
|
|
1090
|
+
throw Error(`expected identifier`);
|
|
1091
|
+
}
|
|
1092
|
+
expect("=");
|
|
1093
|
+
const val = identifier();
|
|
1094
|
+
if (val === undefined) {
|
|
1095
|
+
throw Error(`expected value`);
|
|
1096
|
+
}
|
|
1097
|
+
return { name: id.text, value: val.text };
|
|
1098
|
+
}
|
|
1099
|
+
function docBefore() {
|
|
1100
|
+
const t = lexer.lex();
|
|
1101
|
+
lexer.unlex(t);
|
|
1102
|
+
return t?.doc;
|
|
1140
1103
|
}
|
|
1141
1104
|
function identifier() {
|
|
1142
|
-
|
|
1105
|
+
const t0 = lexer.lex();
|
|
1143
1106
|
if (t0 !== undefined && t0.type === Type.TKN_IDENTIFIER) {
|
|
1144
1107
|
return t0;
|
|
1145
1108
|
}
|
|
1146
1109
|
lexer.unlex(t0);
|
|
1147
1110
|
return undefined;
|
|
1148
1111
|
}
|
|
1112
|
+
function describeTypeSpec(typeSpec) {
|
|
1113
|
+
if (typeSpec.type === Type.SYN_SCOPED_NAME)
|
|
1114
|
+
return `identifier '${typeSpec.name}'`;
|
|
1115
|
+
return describeToken({ type: typeSpec.type });
|
|
1116
|
+
}
|
|
1117
|
+
function resolve_module_separator(name) {
|
|
1118
|
+
const paamayimNekudotayim = lexer.lex();
|
|
1119
|
+
if (paamayimNekudotayim === undefined || paamayimNekudotayim.type !== Type.TKN_COLON_COLON)
|
|
1120
|
+
throw Error(`Expected :: after module identifier '${name}'`);
|
|
1121
|
+
}
|
|
1122
|
+
function find_in_module(module, name) {
|
|
1123
|
+
for (const child of module.definitions) {
|
|
1124
|
+
switch (child.type) {
|
|
1125
|
+
case Type.TKN_MODULE:
|
|
1126
|
+
case Type.TKN_NATIVE:
|
|
1127
|
+
case Type.TKN_VALUETYPE:
|
|
1128
|
+
case Type.SYN_INTERFACE:
|
|
1129
|
+
case Type.TKN_STRUCT:
|
|
1130
|
+
case Type.TKN_UNION:
|
|
1131
|
+
case Type.TKN_ENUM:
|
|
1132
|
+
case Type.TKN_EXCEPTION:
|
|
1133
|
+
if (child.name === name)
|
|
1134
|
+
return child;
|
|
1135
|
+
break;
|
|
1136
|
+
case Type.TKN_TYPEDEF:
|
|
1137
|
+
if (child.names.includes(name))
|
|
1138
|
+
return child.typeSpec;
|
|
1139
|
+
break;
|
|
1140
|
+
}
|
|
1141
|
+
}
|
|
1142
|
+
return undefined;
|
|
1143
|
+
}
|
|
1144
|
+
function resolve_native_ptr(native, scope) {
|
|
1145
|
+
if (scope !== undefined || native.ptrTarget !== undefined)
|
|
1146
|
+
return;
|
|
1147
|
+
if (native.name.length <= 4 || native.name.substring(native.name.length - 4) !== "_ptr")
|
|
1148
|
+
return;
|
|
1149
|
+
const stem = native.name.substring(0, native.name.length - 4);
|
|
1150
|
+
const referenced = scoper.getType(stem);
|
|
1151
|
+
if (referenced === undefined || referenced.target.type === Type.SYN_ENUMERATOR)
|
|
1152
|
+
return;
|
|
1153
|
+
native.ptrTarget = makeScopedName(stem, [], referenced);
|
|
1154
|
+
}
|
|
1155
|
+
function makeScopedName(name, path, entry) {
|
|
1156
|
+
if (entry.target.type === Type.SYN_ENUMERATOR)
|
|
1157
|
+
throw Error(`enumerator '${name}' can not be used as a type`);
|
|
1158
|
+
return { type: Type.SYN_SCOPED_NAME, name, path, scope: entry.scope, target: entry.target };
|
|
1159
|
+
}
|
|
1149
1160
|
function expect(text, customMessage) {
|
|
1150
|
-
|
|
1161
|
+
const t0 = lexer.lex();
|
|
1151
1162
|
let errorMessage;
|
|
1152
1163
|
if (customMessage === undefined) {
|
|
1153
|
-
errorMessage = `expected '${text}' but got '${t0
|
|
1164
|
+
errorMessage = `expected '${text}' but got '${describeToken(t0)}'`;
|
|
1154
1165
|
}
|
|
1155
1166
|
else {
|
|
1156
1167
|
errorMessage = customMessage;
|
|
@@ -1166,13 +1177,11 @@ class Scope {
|
|
|
1166
1177
|
constructor(node) {
|
|
1167
1178
|
this.node = node;
|
|
1168
1179
|
this.types = new Map();
|
|
1169
|
-
this.modules = new Map();
|
|
1170
1180
|
}
|
|
1171
|
-
addType(name,
|
|
1181
|
+
addType(name, target) {
|
|
1172
1182
|
if (this.types.has(name))
|
|
1173
1183
|
throw Error("duplicate typename '" + name + "'");
|
|
1174
|
-
this.types.set(name,
|
|
1175
|
-
type.typeParent = this.node;
|
|
1184
|
+
this.types.set(name, { target, scope: this.node });
|
|
1176
1185
|
}
|
|
1177
1186
|
getType(name) {
|
|
1178
1187
|
return this.types.get(name);
|
|
@@ -1194,51 +1203,18 @@ class ScopeManager {
|
|
|
1194
1203
|
}
|
|
1195
1204
|
getType(name) {
|
|
1196
1205
|
for (let i = this.stack.length - 1; i >= 0; --i) {
|
|
1197
|
-
|
|
1206
|
+
const type = this.stack[i].getType(name);
|
|
1198
1207
|
if (type !== undefined)
|
|
1199
1208
|
return type;
|
|
1200
1209
|
}
|
|
1201
1210
|
return undefined;
|
|
1202
1211
|
}
|
|
1203
1212
|
enterModule(node) {
|
|
1204
|
-
this.getCurrentScope().addType(node.
|
|
1213
|
+
this.getCurrentScope().addType(node.name, node);
|
|
1205
1214
|
this.stack.push(new Scope(node));
|
|
1206
1215
|
}
|
|
1207
|
-
leaveModule(
|
|
1216
|
+
leaveModule() {
|
|
1208
1217
|
this.stack.pop();
|
|
1209
1218
|
}
|
|
1210
1219
|
}
|
|
1211
|
-
function resolve_module(identifierToken, module) {
|
|
1212
|
-
const paamayimNekudotayim = lexer.lex();
|
|
1213
|
-
if (paamayimNekudotayim === undefined || paamayimNekudotayim.type !== Type.TKN_COLON_COLON)
|
|
1214
|
-
throw Error(`Expected :: after module identifier '${identifierToken.text}'`);
|
|
1215
|
-
const identifier = lexer.lex();
|
|
1216
|
-
if (identifier === undefined || identifier.type !== Type.TKN_IDENTIFIER)
|
|
1217
|
-
throw Error(`Expected identifier after ::'`);
|
|
1218
|
-
for (let child of module.child) {
|
|
1219
|
-
switch (child?.type) {
|
|
1220
|
-
case Type.TKN_MODULE:
|
|
1221
|
-
if (child.text === identifier.text) {
|
|
1222
|
-
identifierToken.append(child);
|
|
1223
|
-
resolve_module(identifierToken, child);
|
|
1224
|
-
return;
|
|
1225
|
-
}
|
|
1226
|
-
break;
|
|
1227
|
-
case Type.TKN_NATIVE:
|
|
1228
|
-
case Type.TKN_VALUETYPE:
|
|
1229
|
-
if (child.text === identifier.text) {
|
|
1230
|
-
identifierToken.append(child);
|
|
1231
|
-
return;
|
|
1232
|
-
}
|
|
1233
|
-
break;
|
|
1234
|
-
case Type.SYN_INTERFACE:
|
|
1235
|
-
if (child.child[0].child[1].text === identifier.text) {
|
|
1236
|
-
identifierToken.append(child);
|
|
1237
|
-
return;
|
|
1238
|
-
}
|
|
1239
|
-
break;
|
|
1240
|
-
}
|
|
1241
|
-
}
|
|
1242
|
-
throw Error(`failed to lookup ${identifier.text}`);
|
|
1243
|
-
}
|
|
1244
1220
|
//# sourceMappingURL=idl-parser.js.map
|