corba.js 0.0.9 → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +70 -83
- package/README.IDL.txt +285 -0
- package/README.md +67 -39
- package/bin/corba-idl +15 -2
- package/lib/idl/idl.cjs +2732 -0
- package/lib/idl/idl.cjs.map +1 -0
- package/lib/idl/src/idl/idl-lexer.d.ts +19 -0
- package/lib/idl/src/idl/idl-node.d.ts +101 -0
- package/lib/idl/src/idl/idl-parser.d.ts +3 -0
- package/lib/idl/src/idl/idl.d.ts +1 -0
- package/lib/idl/src/idl/util.d.ts +25 -0
- package/lib/idl/src/idl/write-interface.d.ts +2 -0
- package/lib/idl/src/idl/write-skeleton.d.ts +2 -0
- package/lib/idl/src/idl/write-stub.d.ts +2 -0
- package/lib/idl/src/idl/write-value.d.ts +2 -0
- package/lib/idl/src/idl/write-valueimpl.d.ts +2 -0
- package/lib/idl/src/idl/write-valuetype.d.ts +2 -0
- package/lib/idl/src/index.d.ts +5 -0
- package/lib/idl/src/net/browser.d.ts +7 -0
- package/lib/idl/src/net/index.d.ts +3 -0
- package/lib/idl/src/net/tcp.d.ts +11 -0
- package/lib/idl/src/net/tls.d.ts +24 -0
- package/lib/idl/src/net/ws.d.ts +42 -0
- package/lib/idl/src/orb/asn1.d.ts +48 -0
- package/lib/idl/src/orb/connection.d.ts +24 -0
- package/lib/idl/src/orb/giop.d.ts +273 -0
- package/lib/idl/src/orb/index.d.ts +3 -0
- package/lib/idl/src/orb/ior.d.ts +89 -0
- package/lib/idl/src/orb/orb.d.ts +143 -0
- package/lib/idl/src/orb/protocol.d.ts +6 -0
- package/lib/idl/src/orb/uint8map.d.ts +14 -0
- package/lib/idl/src/orb/url.d.ts +55 -0
- package/lib/idl/test/access.spec.d.ts +1 -0
- package/lib/idl/test/attribute.spec.d.ts +1 -0
- package/lib/idl/test/basics.spec.d.ts +1 -0
- package/lib/idl/test/disconnect.spec.d.ts +1 -0
- package/lib/idl/test/eventtarget.spec.d.ts +1 -0
- package/lib/idl/test/fake.d.ts +31 -0
- package/lib/idl/test/giop.spec.d.ts +1 -0
- package/lib/idl/test/idl/idl.spec.d.ts +1 -0
- package/lib/idl/test/idl_module.spec.d.ts +1 -0
- package/lib/idl/test/initialreferences.spec.d.ts +1 -0
- package/lib/idl/test/net/tls.spec.d.ts +1 -0
- package/lib/idl/test/net/ws.spec.d.ts +1 -0
- package/lib/idl/test/net/wss.spec.d.ts +1 -0
- package/lib/idl/test/object_by_reference.spec.d.ts +1 -0
- package/lib/idl/test/orb/asn1.spec.d.ts +1 -0
- package/lib/idl/test/orb/url.spec.d.ts +1 -0
- package/lib/idl/test/stub.spec.d.ts +1 -0
- package/lib/idl/test/util.d.ts +5 -0
- package/lib/idl/test/valuetype.spec.d.ts +1 -0
- package/lib/{idl → src/idl}/idl-lexer.d.ts +0 -0
- package/lib/src/idl/idl-lexer.js +234 -0
- package/lib/src/idl/idl-lexer.js.map +1 -0
- package/lib/{idl → src/idl}/idl-node.d.ts +13 -10
- package/lib/{idl → src/idl}/idl-node.js +30 -48
- package/lib/src/idl/idl-node.js.map +1 -0
- package/lib/{idl → src/idl}/idl-parser.d.ts +0 -0
- package/lib/{idl → src/idl}/idl-parser.js +367 -290
- package/lib/src/idl/idl-parser.js.map +1 -0
- package/lib/{idl → src/idl}/idl.d.ts +0 -0
- package/lib/src/idl/idl.js +180 -0
- package/lib/src/idl/idl.js.map +1 -0
- package/lib/src/idl/util.d.ts +25 -0
- package/lib/src/idl/util.js +239 -0
- package/lib/src/idl/util.js.map +1 -0
- package/lib/src/idl/write-interface.d.ts +2 -0
- package/lib/src/idl/write-interface.js +111 -0
- package/lib/src/idl/write-interface.js.map +1 -0
- package/lib/src/idl/write-skeleton.d.ts +2 -0
- package/lib/src/idl/write-skeleton.js +116 -0
- package/lib/src/idl/write-skeleton.js.map +1 -0
- package/lib/src/idl/write-stub.d.ts +2 -0
- package/lib/src/idl/write-stub.js +116 -0
- package/lib/src/idl/write-stub.js.map +1 -0
- package/lib/src/idl/write-value.d.ts +2 -0
- package/lib/src/idl/write-value.js +205 -0
- package/lib/src/idl/write-value.js.map +1 -0
- package/lib/src/idl/write-valueimpl.d.ts +2 -0
- package/lib/src/idl/write-valueimpl.js +158 -0
- package/lib/src/idl/write-valueimpl.js.map +1 -0
- package/lib/src/idl/write-valuetype.d.ts +2 -0
- package/lib/src/idl/write-valuetype.js +98 -0
- package/lib/src/idl/write-valuetype.js.map +1 -0
- package/lib/src/index.d.ts +5 -0
- package/lib/src/index.js +6 -0
- package/lib/src/index.js.map +1 -0
- package/lib/src/net/browser.d.ts +7 -0
- package/lib/src/net/browser.js +54 -0
- package/lib/src/net/browser.js.map +1 -0
- package/lib/src/net/index.d.ts +3 -0
- package/lib/src/net/index.js +4 -0
- package/lib/src/net/index.js.map +1 -0
- package/lib/src/net/tcp.d.ts +11 -0
- package/lib/src/net/tcp.js +66 -0
- package/lib/src/net/tcp.js.map +1 -0
- package/lib/src/net/tls.d.ts +24 -0
- package/lib/src/net/tls.js +69 -0
- package/lib/src/net/tls.js.map +1 -0
- package/lib/src/net/ws.d.ts +42 -0
- package/lib/src/net/ws.js +158 -0
- package/lib/src/net/ws.js.map +1 -0
- package/lib/src/orb/asn1.d.ts +48 -0
- package/lib/src/orb/asn1.js +60 -0
- package/lib/src/orb/asn1.js.map +1 -0
- package/lib/src/orb/connection.d.ts +24 -0
- package/lib/src/orb/connection.js +19 -0
- package/lib/src/orb/connection.js.map +1 -0
- package/lib/src/orb/giop.d.ts +273 -0
- package/lib/src/orb/giop.js +1160 -0
- package/lib/src/orb/giop.js.map +1 -0
- package/lib/src/orb/index.d.ts +3 -0
- package/lib/src/orb/index.js +4 -0
- package/lib/src/orb/index.js.map +1 -0
- package/lib/src/orb/ior.d.ts +89 -0
- package/lib/src/orb/ior.js +110 -0
- package/lib/src/orb/ior.js.map +1 -0
- package/lib/src/orb/orb.d.ts +143 -0
- package/lib/src/orb/orb.js +693 -0
- package/lib/src/orb/orb.js.map +1 -0
- package/lib/src/orb/protocol.d.ts +6 -0
- package/lib/src/orb/protocol.js +2 -0
- package/lib/src/orb/protocol.js.map +1 -0
- package/lib/src/orb/uint8map.d.ts +14 -0
- package/lib/src/orb/uint8map.js +48 -0
- package/lib/src/orb/uint8map.js.map +1 -0
- package/lib/src/orb/url.d.ts +55 -0
- package/lib/src/orb/url.js +252 -0
- package/lib/src/orb/url.js.map +1 -0
- package/package.json +51 -26
- package/karma.conf.js +0 -27
- package/lib/idl/idl-lexer.js +0 -256
- package/lib/idl/idl-lexer.js.map +0 -1
- package/lib/idl/idl-node.js.map +0 -1
- package/lib/idl/idl-parser.js.map +0 -1
- package/lib/idl/idl.js +0 -926
- package/lib/idl/idl.js.map +0 -1
- package/lib/orb/orb-nodejs.d.ts +0 -7
- package/lib/orb/orb-nodejs.js +0 -109
- package/lib/orb/orb-nodejs.js.map +0 -1
- package/lib/orb/orb.d.ts +0 -62
- package/lib/orb/orb.js +0 -509
- package/lib/orb/orb.js.map +0 -1
- package/tsconfig.json +0 -23
|
@@ -1,102 +1,27 @@
|
|
|
1
|
-
|
|
2
|
-
/*
|
|
3
|
-
* corba.js Object Request Broker (ORB) and Interface Definition Language (IDL) compiler
|
|
4
|
-
* Copyright (C) 2018, 20202 Mark-André Hopf <mhopf@mark13.org>
|
|
5
|
-
*
|
|
6
|
-
* This program is free software: you can redistribute it and/or modify
|
|
7
|
-
* it under the terms of the GNU General Public License as published by
|
|
8
|
-
* the Free Software Foundation, either version 3 of the License, or
|
|
9
|
-
* (at your option) any later version.
|
|
10
|
-
*
|
|
11
|
-
* This program is distributed in the hope that it will be useful,
|
|
12
|
-
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
13
|
-
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
14
|
-
* GNU General Public License for more details.
|
|
15
|
-
*
|
|
16
|
-
* You should have received a copy of the GNU General Public License
|
|
17
|
-
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
18
|
-
*/
|
|
19
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
20
|
-
const idl_node_1 = require("./idl-node");
|
|
1
|
+
import { Type, Node } from "./idl-node.js";
|
|
21
2
|
let lexer;
|
|
22
|
-
class Scope {
|
|
23
|
-
constructor(node) {
|
|
24
|
-
this.node = node;
|
|
25
|
-
this.types = new Map();
|
|
26
|
-
this.modules = new Map();
|
|
27
|
-
}
|
|
28
|
-
addType(name, type) {
|
|
29
|
-
if (this.types.has(name))
|
|
30
|
-
throw Error("duplicate typename '" + name + "'");
|
|
31
|
-
this.types.set(name, type);
|
|
32
|
-
type.typeParent = this.node;
|
|
33
|
-
}
|
|
34
|
-
getType(name) {
|
|
35
|
-
return this.types.get(name);
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
class ScopeManager {
|
|
39
|
-
constructor() {
|
|
40
|
-
this.stack = new Array();
|
|
41
|
-
this.stack.push(new Scope(undefined));
|
|
42
|
-
}
|
|
43
|
-
getGlobalScope() {
|
|
44
|
-
return this.stack[0];
|
|
45
|
-
}
|
|
46
|
-
getCurrentScope() {
|
|
47
|
-
return this.stack[this.stack.length - 1];
|
|
48
|
-
}
|
|
49
|
-
addType(name, type) {
|
|
50
|
-
this.getCurrentScope().addType(name, type);
|
|
51
|
-
}
|
|
52
|
-
getType(name) {
|
|
53
|
-
for (let i = this.stack.length - 1; i >= 0; --i) {
|
|
54
|
-
let type = this.stack[i].getType(name);
|
|
55
|
-
if (type !== undefined)
|
|
56
|
-
return type;
|
|
57
|
-
}
|
|
58
|
-
return undefined;
|
|
59
|
-
}
|
|
60
|
-
enterModule(node) {
|
|
61
|
-
this.getCurrentScope().addType(node.text, node);
|
|
62
|
-
this.stack.push(new Scope(node));
|
|
63
|
-
}
|
|
64
|
-
leaveModule(node) {
|
|
65
|
-
this.stack.pop();
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
3
|
let scoper;
|
|
69
|
-
function
|
|
70
|
-
let t0 = lexer.lex();
|
|
71
|
-
let errorMessage;
|
|
72
|
-
if (customMessage === undefined)
|
|
73
|
-
errorMessage = `expected '${text}' but got ${t0 === null || t0 === void 0 ? void 0 : t0.toString()}`;
|
|
74
|
-
else
|
|
75
|
-
errorMessage = customMessage;
|
|
76
|
-
if (t0 === undefined)
|
|
77
|
-
throw Error(errorMessage + " but found end of file");
|
|
78
|
-
if (t0.type !== idl_node_1.Type.TKN_TEXT || t0.text !== text) {
|
|
79
|
-
throw Error(errorMessage); // "expected '"+text+"' but found "+t0.toString())
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
// 1
|
|
83
|
-
function specification(aLexer) {
|
|
4
|
+
export function specification(aLexer) {
|
|
84
5
|
lexer = aLexer;
|
|
85
6
|
scoper = new ScopeManager();
|
|
86
|
-
let node = new
|
|
7
|
+
let node = new Node(Type.SYN_SPECIFICATION);
|
|
87
8
|
while (true) {
|
|
88
9
|
let t0 = definition();
|
|
89
10
|
if (t0 === undefined)
|
|
90
11
|
break;
|
|
91
12
|
node.append(t0);
|
|
92
13
|
}
|
|
14
|
+
const tail = lexer.lex();
|
|
15
|
+
if (tail !== undefined) {
|
|
16
|
+
throw Error(`Unparsed token '${tail.toString()}' at end of specification.`);
|
|
17
|
+
}
|
|
93
18
|
return node;
|
|
94
19
|
}
|
|
95
|
-
exports.specification = specification;
|
|
96
|
-
// 2
|
|
97
20
|
function definition() {
|
|
98
21
|
let t0;
|
|
99
22
|
t0 = type_dcl();
|
|
23
|
+
if (t0 === undefined)
|
|
24
|
+
t0 = except_dcl();
|
|
100
25
|
if (t0 === undefined)
|
|
101
26
|
t0 = _interface();
|
|
102
27
|
if (t0 === undefined)
|
|
@@ -108,13 +33,12 @@ function definition() {
|
|
|
108
33
|
}
|
|
109
34
|
return t0;
|
|
110
35
|
}
|
|
111
|
-
// 3
|
|
112
36
|
function _module() {
|
|
113
37
|
let t0 = lexer.lex();
|
|
114
|
-
if (t0 !== undefined && t0.type ===
|
|
38
|
+
if (t0 !== undefined && t0.type === Type.TKN_MODULE) {
|
|
115
39
|
let t1 = identifier();
|
|
116
40
|
if (t1 === undefined)
|
|
117
|
-
throw Error("
|
|
41
|
+
throw Error("expected identifier after 'module'");
|
|
118
42
|
t0.text = t1.text;
|
|
119
43
|
expect("{");
|
|
120
44
|
scoper.enterModule(t0);
|
|
@@ -122,7 +46,7 @@ function _module() {
|
|
|
122
46
|
let t2 = definition();
|
|
123
47
|
if (t2 === undefined)
|
|
124
48
|
break;
|
|
125
|
-
if (t2.type ==
|
|
49
|
+
if (t2.type == Type.TKN_NATIVE)
|
|
126
50
|
throw Error("'native' can not be used within 'module'");
|
|
127
51
|
t0.append(t2);
|
|
128
52
|
}
|
|
@@ -133,11 +57,9 @@ function _module() {
|
|
|
133
57
|
lexer.unlex(t0);
|
|
134
58
|
return undefined;
|
|
135
59
|
}
|
|
136
|
-
// 4
|
|
137
60
|
function _interface() {
|
|
138
61
|
return interface_dcl();
|
|
139
62
|
}
|
|
140
|
-
// 5
|
|
141
63
|
function interface_dcl() {
|
|
142
64
|
let t0 = interface_header();
|
|
143
65
|
if (!t0) {
|
|
@@ -150,27 +72,26 @@ function interface_dcl() {
|
|
|
150
72
|
let t1 = lexer.lex();
|
|
151
73
|
if (t1 === undefined)
|
|
152
74
|
throw Error("expected { after interface header but got end of file");
|
|
153
|
-
if (t1.type !==
|
|
154
|
-
throw Error(
|
|
75
|
+
if (t1.type !== Type.TKN_TEXT && t1.text != '{')
|
|
76
|
+
throw Error(`expected { after interface header but got ${t0}`);
|
|
77
|
+
let node = new Node(Type.SYN_INTERFACE, t0.child[1].text);
|
|
78
|
+
scoper.addType(t0.child[1].text, node);
|
|
79
|
+
node.append(t0);
|
|
155
80
|
let t2 = interface_body();
|
|
81
|
+
node.append(t2);
|
|
156
82
|
let t3 = lexer.lex();
|
|
157
83
|
if (!t3)
|
|
158
84
|
throw Error("unexpected end of file");
|
|
159
|
-
if (t3.type !==
|
|
160
|
-
throw Error(
|
|
161
|
-
let node = new idl_node_1.Node(idl_node_1.Type.SYN_INTERFACE, t0.child[1].text);
|
|
162
|
-
node.append(t0);
|
|
163
|
-
node.append(t2);
|
|
164
|
-
scoper.addType(t0.child[1].text, node);
|
|
85
|
+
if (t3.type !== Type.TKN_TEXT && t3.text != '}')
|
|
86
|
+
throw Error(`expected } after interface body but got '${t3}'`);
|
|
165
87
|
return node;
|
|
166
88
|
}
|
|
167
|
-
// 7
|
|
168
89
|
function interface_header() {
|
|
169
90
|
let t0 = lexer.lex();
|
|
170
91
|
if (t0 === undefined)
|
|
171
92
|
return undefined;
|
|
172
93
|
let t1;
|
|
173
|
-
if (t0.type !==
|
|
94
|
+
if (t0.type !== Type.TKN_ABSTRACT && t0.type !== Type.TKN_LOCAL) {
|
|
174
95
|
t1 = t0;
|
|
175
96
|
t0 = undefined;
|
|
176
97
|
}
|
|
@@ -181,7 +102,7 @@ function interface_header() {
|
|
|
181
102
|
lexer.unlex(t0);
|
|
182
103
|
return undefined;
|
|
183
104
|
}
|
|
184
|
-
if (t1.type !==
|
|
105
|
+
if (t1.type !== Type.TKN_INTERFACE) {
|
|
185
106
|
lexer.unlex(t1);
|
|
186
107
|
lexer.unlex(t0);
|
|
187
108
|
return undefined;
|
|
@@ -189,16 +110,14 @@ function interface_header() {
|
|
|
189
110
|
let t2 = identifier();
|
|
190
111
|
if (t2 === undefined)
|
|
191
112
|
throw Error("expected identifier after 'interface'");
|
|
192
|
-
|
|
193
|
-
let header = new idl_node_1.Node(idl_node_1.Type.SYN_INTERFACE_HEADER);
|
|
113
|
+
let header = new Node(Type.SYN_INTERFACE_HEADER);
|
|
194
114
|
header.append(t0);
|
|
195
115
|
header.append(t2);
|
|
196
116
|
header.append(undefined);
|
|
197
117
|
return header;
|
|
198
118
|
}
|
|
199
|
-
// 8
|
|
200
119
|
function interface_body() {
|
|
201
|
-
let body = new
|
|
120
|
+
let body = new Node(Type.SYN_INTERFACE_BODY);
|
|
202
121
|
while (true) {
|
|
203
122
|
let t0 = _export();
|
|
204
123
|
if (t0 === undefined)
|
|
@@ -206,7 +125,6 @@ function interface_body() {
|
|
|
206
125
|
body.append(t0);
|
|
207
126
|
}
|
|
208
127
|
}
|
|
209
|
-
// 9
|
|
210
128
|
function _export() {
|
|
211
129
|
let t0 = attr_dcl();
|
|
212
130
|
if (t0 === undefined)
|
|
@@ -216,13 +134,12 @@ function _export() {
|
|
|
216
134
|
expect(';');
|
|
217
135
|
return t0;
|
|
218
136
|
}
|
|
219
|
-
// 12
|
|
220
137
|
function scoped_name() {
|
|
221
138
|
let globalNamespaceToken = undefined;
|
|
222
139
|
let identifierToken = lexer.lex();
|
|
223
140
|
if (identifierToken === undefined)
|
|
224
141
|
return undefined;
|
|
225
|
-
if (identifierToken.type ===
|
|
142
|
+
if (identifierToken.type === Type.TKN_COLON_COLON) {
|
|
226
143
|
globalNamespaceToken = identifierToken;
|
|
227
144
|
identifierToken = lexer.lex();
|
|
228
145
|
if (identifierToken === undefined) {
|
|
@@ -230,7 +147,7 @@ function scoped_name() {
|
|
|
230
147
|
return undefined;
|
|
231
148
|
}
|
|
232
149
|
}
|
|
233
|
-
if (identifierToken.type !==
|
|
150
|
+
if (identifierToken.type !== Type.TKN_IDENTIFIER) {
|
|
234
151
|
lexer.unlex(identifierToken);
|
|
235
152
|
lexer.unlex(globalNamespaceToken);
|
|
236
153
|
return undefined;
|
|
@@ -247,10 +164,10 @@ function scoped_name() {
|
|
|
247
164
|
throw Error(`unknown type ${identifierToken}`);
|
|
248
165
|
}
|
|
249
166
|
identifierToken.append(type);
|
|
250
|
-
if (type.type ===
|
|
167
|
+
if (type.type === Type.TKN_MODULE) {
|
|
251
168
|
resolve_module(identifierToken, type);
|
|
252
169
|
}
|
|
253
|
-
if (type.type ===
|
|
170
|
+
if (type.type === Type.TKN_NATIVE &&
|
|
254
171
|
type.text.length > 4 &&
|
|
255
172
|
type.text.substring(type.text.length - 4) === "_ptr" &&
|
|
256
173
|
type.typeParent === undefined) {
|
|
@@ -258,40 +175,6 @@ function scoped_name() {
|
|
|
258
175
|
}
|
|
259
176
|
return identifierToken;
|
|
260
177
|
}
|
|
261
|
-
function resolve_module(identifierToken, module) {
|
|
262
|
-
let paamayimNekudotayim = lexer.lex();
|
|
263
|
-
if (paamayimNekudotayim === undefined || paamayimNekudotayim.type !== idl_node_1.Type.TKN_COLON_COLON)
|
|
264
|
-
throw Error(`Expected :: after module identifier '${identifierToken.text}'`);
|
|
265
|
-
let identifier = lexer.lex();
|
|
266
|
-
if (identifier === undefined || identifier.type !== idl_node_1.Type.TKN_IDENTIFIER)
|
|
267
|
-
throw Error(`Expected identifier after ::'`);
|
|
268
|
-
for (let child of module.child) {
|
|
269
|
-
switch (child === null || child === void 0 ? void 0 : child.type) {
|
|
270
|
-
case idl_node_1.Type.TKN_MODULE:
|
|
271
|
-
if (child.text === identifier.text) {
|
|
272
|
-
identifierToken.append(child);
|
|
273
|
-
resolve_module(identifierToken, child);
|
|
274
|
-
return;
|
|
275
|
-
}
|
|
276
|
-
break;
|
|
277
|
-
case idl_node_1.Type.TKN_NATIVE:
|
|
278
|
-
case idl_node_1.Type.TKN_VALUETYPE:
|
|
279
|
-
if (child.text === identifier.text) {
|
|
280
|
-
identifierToken.append(child);
|
|
281
|
-
return;
|
|
282
|
-
}
|
|
283
|
-
break;
|
|
284
|
-
case idl_node_1.Type.SYN_INTERFACE:
|
|
285
|
-
if (child.child[0].child[1].text === identifier.text) {
|
|
286
|
-
identifierToken.append(child);
|
|
287
|
-
return;
|
|
288
|
-
}
|
|
289
|
-
break;
|
|
290
|
-
}
|
|
291
|
-
}
|
|
292
|
-
throw Error(`failed to lookup ${identifier.text}`);
|
|
293
|
-
}
|
|
294
|
-
// 13
|
|
295
178
|
function value() {
|
|
296
179
|
let t0;
|
|
297
180
|
t0 = value_dcl();
|
|
@@ -308,26 +191,22 @@ function value() {
|
|
|
308
191
|
return t0;
|
|
309
192
|
return undefined;
|
|
310
193
|
}
|
|
311
|
-
// 14
|
|
312
194
|
function value_forward_dcl() {
|
|
313
195
|
return undefined;
|
|
314
196
|
}
|
|
315
|
-
// 15
|
|
316
197
|
function value_box_dcl() {
|
|
317
198
|
return undefined;
|
|
318
199
|
}
|
|
319
|
-
// 16
|
|
320
200
|
function value_abs_dcl() {
|
|
321
201
|
return undefined;
|
|
322
202
|
}
|
|
323
|
-
// 17
|
|
324
203
|
function value_dcl() {
|
|
325
204
|
let header = value_header();
|
|
326
205
|
if (header === undefined) {
|
|
327
206
|
return undefined;
|
|
328
207
|
}
|
|
329
208
|
expect('{');
|
|
330
|
-
let node = new
|
|
209
|
+
let node = new Node(Type.TKN_VALUETYPE);
|
|
331
210
|
node.append(header);
|
|
332
211
|
let identifier = header.child[1].text;
|
|
333
212
|
node.text = identifier;
|
|
@@ -338,28 +217,26 @@ function value_dcl() {
|
|
|
338
217
|
break;
|
|
339
218
|
node.append(t1);
|
|
340
219
|
}
|
|
341
|
-
expect('}');
|
|
220
|
+
expect('}');
|
|
342
221
|
return node;
|
|
343
222
|
}
|
|
344
|
-
// 18
|
|
345
223
|
function value_header() {
|
|
346
224
|
let t0 = lexer.lex();
|
|
347
225
|
if (t0 !== undefined) {
|
|
348
226
|
let t1;
|
|
349
|
-
if (t0.type ===
|
|
227
|
+
if (t0.type === Type.TKN_CUSTOM) {
|
|
350
228
|
throw Error("corba.js currently does not support custom valuetypes");
|
|
351
|
-
// t1 = lexer.lex()
|
|
352
229
|
}
|
|
353
230
|
else {
|
|
354
231
|
t1 = t0;
|
|
355
232
|
t0 = undefined;
|
|
356
233
|
}
|
|
357
|
-
if (t1 !== undefined && t1.type ===
|
|
234
|
+
if (t1 !== undefined && t1.type === Type.TKN_VALUETYPE) {
|
|
358
235
|
let t2 = identifier();
|
|
359
236
|
if (t2 === undefined)
|
|
360
237
|
throw Error("expected an identifier after valuetype");
|
|
361
238
|
let t3 = value_inheritance_spec();
|
|
362
|
-
let node = new
|
|
239
|
+
let node = new Node(Type.SYN_VALUE_HEADER);
|
|
363
240
|
node.append(t0);
|
|
364
241
|
node.append(t2);
|
|
365
242
|
node.append(t3);
|
|
@@ -370,21 +247,20 @@ function value_header() {
|
|
|
370
247
|
lexer.unlex(t0);
|
|
371
248
|
return undefined;
|
|
372
249
|
}
|
|
373
|
-
// 19
|
|
374
250
|
function value_inheritance_spec() {
|
|
375
251
|
let t0 = lexer.lex();
|
|
376
|
-
if (t0 === undefined || t0.type !==
|
|
252
|
+
if (t0 === undefined || t0.type !== Type.TKN_TEXT || t0.text !== ":") {
|
|
377
253
|
lexer.unlex(t0);
|
|
378
254
|
return undefined;
|
|
379
255
|
}
|
|
380
256
|
let t1 = lexer.lex();
|
|
381
|
-
if (t1 !== undefined && t1.type !==
|
|
257
|
+
if (t1 !== undefined && t1.type !== Type.TKN_TRUNCATABLE) {
|
|
382
258
|
lexer.unlex(t1);
|
|
383
259
|
t1 = undefined;
|
|
384
260
|
}
|
|
385
261
|
if (t1 !== undefined)
|
|
386
262
|
throw Error("'truncatable' is not supported");
|
|
387
|
-
let node = new
|
|
263
|
+
let node = new Node(Type.SYN_VALUE_INHERITANCE_SPEC);
|
|
388
264
|
node.append(t1);
|
|
389
265
|
while (true) {
|
|
390
266
|
let t2 = value_name();
|
|
@@ -395,7 +271,7 @@ function value_inheritance_spec() {
|
|
|
395
271
|
let t3 = lexer.lex();
|
|
396
272
|
if (t3 === undefined)
|
|
397
273
|
throw Error("unexpected end of file");
|
|
398
|
-
if (t3.type !==
|
|
274
|
+
if (t3.type !== Type.TKN_TEXT || t3.text !== ",") {
|
|
399
275
|
lexer.unlex(t3);
|
|
400
276
|
break;
|
|
401
277
|
}
|
|
@@ -405,27 +281,20 @@ function value_inheritance_spec() {
|
|
|
405
281
|
}
|
|
406
282
|
return node;
|
|
407
283
|
}
|
|
408
|
-
// 20
|
|
409
284
|
function value_name() {
|
|
410
285
|
return scoped_name();
|
|
411
286
|
}
|
|
412
|
-
// 21
|
|
413
287
|
function value_element() {
|
|
414
288
|
let t0 = _export();
|
|
415
289
|
if (t0 === undefined)
|
|
416
290
|
t0 = state_member();
|
|
417
|
-
/*
|
|
418
|
-
if (t0 === undefined)
|
|
419
|
-
t0 = init_dcl()
|
|
420
|
-
*/
|
|
421
291
|
return t0;
|
|
422
292
|
}
|
|
423
|
-
// 22
|
|
424
293
|
function state_member() {
|
|
425
294
|
let t0 = lexer.lex();
|
|
426
295
|
if (t0 === undefined)
|
|
427
296
|
return undefined;
|
|
428
|
-
if (t0.type !==
|
|
297
|
+
if (t0.type !== Type.TKN_PUBLIC && t0.type !== Type.TKN_PRIVATE) {
|
|
429
298
|
lexer.unlex(t0);
|
|
430
299
|
return undefined;
|
|
431
300
|
}
|
|
@@ -439,16 +308,36 @@ function state_member() {
|
|
|
439
308
|
throw Error("expected declarators");
|
|
440
309
|
}
|
|
441
310
|
expect(";");
|
|
442
|
-
let node = new
|
|
311
|
+
let node = new Node(Type.SYN_STATE_MEMBER);
|
|
443
312
|
node.append(t0);
|
|
444
313
|
node.append(t1);
|
|
445
314
|
node.append(t2);
|
|
446
315
|
return node;
|
|
447
316
|
}
|
|
448
|
-
// 42
|
|
449
317
|
function type_dcl() {
|
|
450
318
|
let t0 = lexer.lex();
|
|
451
|
-
if (t0 !== undefined && t0.type ===
|
|
319
|
+
if (t0 !== undefined && t0.type === Type.TKN_TYPEDEF) {
|
|
320
|
+
let t1 = type_declarator();
|
|
321
|
+
if (t1 === undefined) {
|
|
322
|
+
lexer.unlex(t0);
|
|
323
|
+
return undefined;
|
|
324
|
+
}
|
|
325
|
+
const identifiers = t1.child[1].child;
|
|
326
|
+
for (const id of identifiers) {
|
|
327
|
+
scoper.addType(id.text, t1.child[0]);
|
|
328
|
+
}
|
|
329
|
+
t1.type = t0.type;
|
|
330
|
+
return t1;
|
|
331
|
+
}
|
|
332
|
+
lexer.unlex(t0);
|
|
333
|
+
t0 = struct_type();
|
|
334
|
+
if (t0 !== undefined)
|
|
335
|
+
return t0;
|
|
336
|
+
t0 = enum_type();
|
|
337
|
+
if (t0 !== undefined)
|
|
338
|
+
return t0;
|
|
339
|
+
t0 = lexer.lex();
|
|
340
|
+
if (t0 !== undefined && t0.type === Type.TKN_NATIVE) {
|
|
452
341
|
let t1 = simple_declarator();
|
|
453
342
|
if (t1 === undefined) {
|
|
454
343
|
throw Error("expected simple declarator after 'native'");
|
|
@@ -461,17 +350,26 @@ function type_dcl() {
|
|
|
461
350
|
lexer.unlex(t0);
|
|
462
351
|
return undefined;
|
|
463
352
|
}
|
|
464
|
-
|
|
353
|
+
function type_declarator() {
|
|
354
|
+
const t0 = type_spec();
|
|
355
|
+
if (t0 === undefined)
|
|
356
|
+
return undefined;
|
|
357
|
+
const t1 = declarators();
|
|
358
|
+
if (t1 == undefined) {
|
|
359
|
+
throw Error("expected at least one declarator");
|
|
360
|
+
}
|
|
361
|
+
const n = new Node(Type.SYN_TYPE_DECLARATOR);
|
|
362
|
+
n.append(t0);
|
|
363
|
+
n.append(t1);
|
|
364
|
+
return n;
|
|
365
|
+
}
|
|
465
366
|
function type_spec() {
|
|
466
367
|
let t0;
|
|
467
368
|
t0 = simple_type_spec();
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
t0 = constr_type_spec()
|
|
471
|
-
*/
|
|
369
|
+
if (t0 === undefined)
|
|
370
|
+
t0 = constr_type_spec();
|
|
472
371
|
return t0;
|
|
473
372
|
}
|
|
474
|
-
// 45
|
|
475
373
|
function simple_type_spec() {
|
|
476
374
|
let t0;
|
|
477
375
|
t0 = base_type_spec();
|
|
@@ -481,7 +379,6 @@ function simple_type_spec() {
|
|
|
481
379
|
t0 = scoped_name();
|
|
482
380
|
return t0;
|
|
483
381
|
}
|
|
484
|
-
// 46
|
|
485
382
|
function base_type_spec() {
|
|
486
383
|
let t0;
|
|
487
384
|
t0 = floating_pt_type();
|
|
@@ -507,7 +404,6 @@ function base_type_spec() {
|
|
|
507
404
|
return t0;
|
|
508
405
|
return undefined;
|
|
509
406
|
}
|
|
510
|
-
// 47
|
|
511
407
|
function template_type_spec() {
|
|
512
408
|
let t0;
|
|
513
409
|
t0 = sequence_type();
|
|
@@ -519,23 +415,23 @@ function template_type_spec() {
|
|
|
519
415
|
t0 = wide_string_type();
|
|
520
416
|
if (t0 !== undefined)
|
|
521
417
|
return t0;
|
|
522
|
-
/*
|
|
523
|
-
t0 = fixed_pt_type()
|
|
524
|
-
if (t0 !== undefined)
|
|
525
|
-
return t0
|
|
526
|
-
*/
|
|
527
418
|
return undefined;
|
|
528
419
|
}
|
|
529
|
-
|
|
420
|
+
function constr_type_spec() {
|
|
421
|
+
let t0 = struct_type();
|
|
422
|
+
if (t0 === undefined)
|
|
423
|
+
t0 = enum_type();
|
|
424
|
+
return t0;
|
|
425
|
+
}
|
|
530
426
|
function declarators() {
|
|
531
427
|
let t0 = declarator();
|
|
532
428
|
if (t0 === undefined)
|
|
533
429
|
return undefined;
|
|
534
|
-
let node = new
|
|
430
|
+
let node = new Node(Type.SYN_DECLARATORS);
|
|
535
431
|
while (true) {
|
|
536
432
|
node.append(t0);
|
|
537
433
|
let t1 = lexer.lex();
|
|
538
|
-
if (t1 === undefined || t1.type !==
|
|
434
|
+
if (t1 === undefined || t1.type !== Type.TKN_TEXT || t1.text !== ",") {
|
|
539
435
|
lexer.unlex(t1);
|
|
540
436
|
break;
|
|
541
437
|
}
|
|
@@ -545,33 +441,26 @@ function declarators() {
|
|
|
545
441
|
}
|
|
546
442
|
return node;
|
|
547
443
|
}
|
|
548
|
-
// 50
|
|
549
444
|
function declarator() {
|
|
550
445
|
let t0;
|
|
551
446
|
t0 = simple_declarator();
|
|
552
|
-
/*
|
|
553
|
-
if (t0 === undefined)
|
|
554
|
-
t0 = complex_declarator()
|
|
555
|
-
*/
|
|
556
447
|
return t0;
|
|
557
448
|
}
|
|
558
|
-
// 51
|
|
559
449
|
function simple_declarator() {
|
|
560
450
|
return identifier();
|
|
561
451
|
}
|
|
562
|
-
// 53
|
|
563
452
|
function floating_pt_type() {
|
|
564
453
|
let t0 = lexer.lex();
|
|
565
454
|
if (t0 === undefined)
|
|
566
455
|
return undefined;
|
|
567
|
-
if (t0.type ===
|
|
456
|
+
if (t0.type === Type.TKN_FLOAT)
|
|
568
457
|
return t0;
|
|
569
|
-
if (t0.type ===
|
|
458
|
+
if (t0.type === Type.TKN_DOUBLE)
|
|
570
459
|
return t0;
|
|
571
|
-
if (t0.type ===
|
|
460
|
+
if (t0.type === Type.TKN_LONG) {
|
|
572
461
|
let t1 = lexer.lex();
|
|
573
|
-
if (t1 !== undefined && t1.type ===
|
|
574
|
-
t1.type =
|
|
462
|
+
if (t1 !== undefined && t1.type === Type.TKN_DOUBLE) {
|
|
463
|
+
t1.type = Type.SYN_LONG_DOUBLE;
|
|
575
464
|
return t1;
|
|
576
465
|
}
|
|
577
466
|
lexer.unlex(t1);
|
|
@@ -579,7 +468,6 @@ function floating_pt_type() {
|
|
|
579
468
|
lexer.unlex(t0);
|
|
580
469
|
return undefined;
|
|
581
470
|
}
|
|
582
|
-
// 54
|
|
583
471
|
function integer_type() {
|
|
584
472
|
let t0;
|
|
585
473
|
t0 = signed_int();
|
|
@@ -589,9 +477,13 @@ function integer_type() {
|
|
|
589
477
|
if (t0 !== undefined) {
|
|
590
478
|
return t0;
|
|
591
479
|
}
|
|
480
|
+
t0 = lexer.lex();
|
|
481
|
+
if (t0 !== undefined && [Type.TKN_SHORT, Type.TKN_LONG, Type.TKN_UNSIGNED].includes(t0.type)) {
|
|
482
|
+
throw Error('valid integer types are: short, unsigned short, long, unsigned long, long long, unsigned long long');
|
|
483
|
+
}
|
|
484
|
+
lexer.unlex(t0);
|
|
592
485
|
return undefined;
|
|
593
486
|
}
|
|
594
|
-
// 55
|
|
595
487
|
function signed_int() {
|
|
596
488
|
let t0;
|
|
597
489
|
t0 = signed_short_int();
|
|
@@ -605,31 +497,28 @@ function signed_int() {
|
|
|
605
497
|
return t0;
|
|
606
498
|
return undefined;
|
|
607
499
|
}
|
|
608
|
-
// 56
|
|
609
500
|
function signed_short_int() {
|
|
610
501
|
let t0 = lexer.lex();
|
|
611
|
-
if (t0 !== undefined && t0.type ===
|
|
502
|
+
if (t0 !== undefined && t0.type === Type.TKN_SHORT)
|
|
612
503
|
return t0;
|
|
613
504
|
lexer.unlex(t0);
|
|
614
505
|
return undefined;
|
|
615
506
|
}
|
|
616
|
-
// 57
|
|
617
507
|
function signed_long_int() {
|
|
618
508
|
let t0 = lexer.lex();
|
|
619
509
|
if (t0 === undefined)
|
|
620
510
|
return undefined;
|
|
621
|
-
if (t0.type ===
|
|
511
|
+
if (t0.type === Type.TKN_LONG)
|
|
622
512
|
return t0;
|
|
623
513
|
lexer.unlex(t0);
|
|
624
514
|
return undefined;
|
|
625
515
|
}
|
|
626
|
-
// 58
|
|
627
516
|
function signed_longlong_int() {
|
|
628
517
|
let t0 = lexer.lex();
|
|
629
|
-
if (t0 !== undefined && t0.type ===
|
|
518
|
+
if (t0 !== undefined && t0.type === Type.TKN_LONG) {
|
|
630
519
|
let t1 = lexer.lex();
|
|
631
|
-
if (t1 !== undefined && t1.type ===
|
|
632
|
-
t0.type =
|
|
520
|
+
if (t1 !== undefined && t1.type === Type.TKN_LONG) {
|
|
521
|
+
t0.type = Type.SYN_LONGLONG;
|
|
633
522
|
return t0;
|
|
634
523
|
}
|
|
635
524
|
lexer.unlex(t1);
|
|
@@ -637,7 +526,6 @@ function signed_longlong_int() {
|
|
|
637
526
|
lexer.unlex(t0);
|
|
638
527
|
return undefined;
|
|
639
528
|
}
|
|
640
|
-
// 59
|
|
641
529
|
function unsigned_int() {
|
|
642
530
|
let t0;
|
|
643
531
|
t0 = unsigned_short_int();
|
|
@@ -651,13 +539,12 @@ function unsigned_int() {
|
|
|
651
539
|
return t0;
|
|
652
540
|
return undefined;
|
|
653
541
|
}
|
|
654
|
-
// 60
|
|
655
542
|
function unsigned_short_int() {
|
|
656
543
|
let t0 = lexer.lex();
|
|
657
|
-
if (t0 !== undefined && t0.type ===
|
|
544
|
+
if (t0 !== undefined && t0.type === Type.TKN_UNSIGNED) {
|
|
658
545
|
let t1 = lexer.lex();
|
|
659
|
-
if (t1 !== undefined && t1.type ===
|
|
660
|
-
t0.type =
|
|
546
|
+
if (t1 !== undefined && t1.type === Type.TKN_SHORT) {
|
|
547
|
+
t0.type = Type.SYN_UNSIGNED_SHORT;
|
|
661
548
|
return t0;
|
|
662
549
|
}
|
|
663
550
|
lexer.unlex(t1);
|
|
@@ -665,13 +552,12 @@ function unsigned_short_int() {
|
|
|
665
552
|
lexer.unlex(t0);
|
|
666
553
|
return undefined;
|
|
667
554
|
}
|
|
668
|
-
// 61
|
|
669
555
|
function unsigned_long_int() {
|
|
670
556
|
let t0 = lexer.lex();
|
|
671
|
-
if (t0 !== undefined && t0.type ===
|
|
557
|
+
if (t0 !== undefined && t0.type === Type.TKN_UNSIGNED) {
|
|
672
558
|
let t1 = lexer.lex();
|
|
673
|
-
if (t1 !== undefined && t1.type ===
|
|
674
|
-
t0.type =
|
|
559
|
+
if (t1 !== undefined && t1.type === Type.TKN_LONG) {
|
|
560
|
+
t0.type = Type.SYN_UNSIGNED_LONG;
|
|
675
561
|
return t0;
|
|
676
562
|
}
|
|
677
563
|
lexer.unlex(t1);
|
|
@@ -679,15 +565,14 @@ function unsigned_long_int() {
|
|
|
679
565
|
lexer.unlex(t0);
|
|
680
566
|
return undefined;
|
|
681
567
|
}
|
|
682
|
-
// 62
|
|
683
568
|
function unsigned_longlong_int() {
|
|
684
569
|
let t0 = lexer.lex();
|
|
685
|
-
if (t0 !== undefined && t0.type ===
|
|
570
|
+
if (t0 !== undefined && t0.type === Type.TKN_UNSIGNED) {
|
|
686
571
|
let t1 = lexer.lex();
|
|
687
|
-
if (t1 !== undefined && t1.type ===
|
|
572
|
+
if (t1 !== undefined && t1.type === Type.TKN_LONG) {
|
|
688
573
|
let t2 = lexer.lex();
|
|
689
|
-
if (t2 !== undefined && t2.type ===
|
|
690
|
-
t0.type =
|
|
574
|
+
if (t2 !== undefined && t2.type === Type.TKN_LONG) {
|
|
575
|
+
t0.type = Type.SYN_UNSIGNED_LONGLONG;
|
|
691
576
|
return t0;
|
|
692
577
|
}
|
|
693
578
|
lexer.unlex(t2);
|
|
@@ -697,51 +582,124 @@ function unsigned_longlong_int() {
|
|
|
697
582
|
lexer.unlex(t0);
|
|
698
583
|
return undefined;
|
|
699
584
|
}
|
|
700
|
-
// 63
|
|
701
585
|
function char_type() {
|
|
702
586
|
let t0 = lexer.lex();
|
|
703
|
-
if (t0 !== undefined && t0.type ==
|
|
587
|
+
if (t0 !== undefined && t0.type == Type.TKN_CHAR)
|
|
704
588
|
return t0;
|
|
705
589
|
lexer.unlex(t0);
|
|
706
590
|
return undefined;
|
|
707
591
|
}
|
|
708
|
-
// 64
|
|
709
592
|
function wide_char_type() {
|
|
710
593
|
let t0 = lexer.lex();
|
|
711
|
-
if (t0 !== undefined && t0.type ==
|
|
594
|
+
if (t0 !== undefined && t0.type == Type.TKN_WCHAR)
|
|
712
595
|
return t0;
|
|
713
596
|
lexer.unlex(t0);
|
|
714
597
|
return undefined;
|
|
715
598
|
}
|
|
716
|
-
// 65
|
|
717
599
|
function boolean_type() {
|
|
718
600
|
let t0 = lexer.lex();
|
|
719
|
-
if (t0 !== undefined && t0.type ==
|
|
601
|
+
if (t0 !== undefined && t0.type == Type.TKN_BOOLEAN)
|
|
720
602
|
return t0;
|
|
721
603
|
lexer.unlex(t0);
|
|
722
604
|
return undefined;
|
|
723
605
|
}
|
|
724
|
-
// 66
|
|
725
606
|
function octet_type() {
|
|
726
607
|
let t0 = lexer.lex();
|
|
727
|
-
if (t0 !== undefined && t0.type ==
|
|
608
|
+
if (t0 !== undefined && t0.type == Type.TKN_OCTET)
|
|
728
609
|
return t0;
|
|
729
610
|
lexer.unlex(t0);
|
|
730
611
|
return undefined;
|
|
731
612
|
}
|
|
732
|
-
// 67
|
|
733
613
|
function any_type() {
|
|
614
|
+
const t0 = lexer.lex();
|
|
615
|
+
if (t0 !== undefined && t0.type == Type.TKN_ANY)
|
|
616
|
+
return t0;
|
|
617
|
+
lexer.unlex(t0);
|
|
618
|
+
return undefined;
|
|
619
|
+
}
|
|
620
|
+
function struct_type() {
|
|
621
|
+
const t0 = lexer.lex();
|
|
622
|
+
if (t0 === undefined || t0.type !== Type.TKN_STRUCT) {
|
|
623
|
+
lexer.unlex(t0);
|
|
624
|
+
return undefined;
|
|
625
|
+
}
|
|
626
|
+
const t1 = identifier();
|
|
627
|
+
if (t1 === undefined)
|
|
628
|
+
throw Error("expected identifier after 'struct'");
|
|
629
|
+
expect('{');
|
|
630
|
+
const t2 = member_list();
|
|
631
|
+
if (t2 === undefined)
|
|
632
|
+
throw Error("expected at least one member within 'struct'");
|
|
633
|
+
expect('}');
|
|
634
|
+
t2.type = t0.type;
|
|
635
|
+
t2.text = t1.text;
|
|
636
|
+
scoper.addType(t2.text, t0);
|
|
637
|
+
return t2;
|
|
638
|
+
}
|
|
639
|
+
function member_list() {
|
|
640
|
+
const t0 = member();
|
|
641
|
+
if (t0 === undefined)
|
|
642
|
+
return undefined;
|
|
643
|
+
const node = new Node(Type.SYN_MEMBER_LIST);
|
|
644
|
+
node.append(t0);
|
|
645
|
+
while (true) {
|
|
646
|
+
const t1 = member();
|
|
647
|
+
if (t1 === undefined)
|
|
648
|
+
break;
|
|
649
|
+
node.append(t1);
|
|
650
|
+
}
|
|
651
|
+
return node;
|
|
652
|
+
}
|
|
653
|
+
function member() {
|
|
654
|
+
const node = new Node(Type.SYN_MEMBER);
|
|
655
|
+
const t0 = type_spec();
|
|
656
|
+
if (t0 === undefined)
|
|
657
|
+
return undefined;
|
|
658
|
+
const t1 = declarators();
|
|
659
|
+
if (t1 === undefined)
|
|
660
|
+
throw Error(`expected declarators after type_spec ${t0.toString()}`);
|
|
661
|
+
expect(";");
|
|
662
|
+
node.append(t0);
|
|
663
|
+
node.append(t1);
|
|
664
|
+
return node;
|
|
665
|
+
}
|
|
666
|
+
function enum_type() {
|
|
734
667
|
let t0 = lexer.lex();
|
|
735
|
-
if (t0 !== undefined && t0.type ==
|
|
668
|
+
if (t0 !== undefined && t0.type == Type.TKN_ENUM) {
|
|
669
|
+
const t1 = identifier();
|
|
670
|
+
if (t1 === undefined)
|
|
671
|
+
throw Error("expected identifier after 'enum'");
|
|
672
|
+
t0.text = t1.text;
|
|
673
|
+
expect("{");
|
|
674
|
+
const set = new Set();
|
|
675
|
+
while (true) {
|
|
676
|
+
let t2 = lexer.lex();
|
|
677
|
+
if (t2 === undefined)
|
|
678
|
+
throw Error("unexpected end of file");
|
|
679
|
+
if (t2.type !== Type.TKN_IDENTIFIER)
|
|
680
|
+
throw Error("expected identifier but got ${t2}");
|
|
681
|
+
if (set.has(t2.text)) {
|
|
682
|
+
throw Error(`Declaration of enumerator '${t2.text}' clashes with earlier declaration of enumerator '${t2.text}'`);
|
|
683
|
+
}
|
|
684
|
+
set.add(t2.text);
|
|
685
|
+
t0.append(t2);
|
|
686
|
+
let t3 = lexer.lex();
|
|
687
|
+
if (t3 === undefined)
|
|
688
|
+
throw Error("unexpected end of file");
|
|
689
|
+
if (t3.type !== Type.TKN_TEXT)
|
|
690
|
+
throw Error("expected ',' or '}' but got ${t2}");
|
|
691
|
+
if (t3.text === "}")
|
|
692
|
+
break;
|
|
693
|
+
}
|
|
694
|
+
scoper.addType(t0.text, t0);
|
|
736
695
|
return t0;
|
|
696
|
+
}
|
|
737
697
|
lexer.unlex(t0);
|
|
738
698
|
return undefined;
|
|
739
699
|
}
|
|
740
|
-
// 80
|
|
741
700
|
function sequence_type() {
|
|
742
701
|
let t0 = lexer.lex();
|
|
743
|
-
if (t0 !== undefined && t0.type ===
|
|
744
|
-
// "sequence" "<" simple_type_spec "," positive_int_const ">"
|
|
702
|
+
if (t0 !== undefined && t0.type === Type.TKN_SEQUENCE) {
|
|
745
703
|
expect("<");
|
|
746
704
|
let t1 = simple_type_spec();
|
|
747
705
|
if (t1 === undefined)
|
|
@@ -754,27 +712,22 @@ function sequence_type() {
|
|
|
754
712
|
lexer.unlex(t0);
|
|
755
713
|
return undefined;
|
|
756
714
|
}
|
|
757
|
-
// 81
|
|
758
715
|
function string_type() {
|
|
759
716
|
let t0 = lexer.lex();
|
|
760
|
-
if (t0 !== undefined && t0.type ===
|
|
761
|
-
// 'string' '<' <positive_int_const> '>'
|
|
717
|
+
if (t0 !== undefined && t0.type === Type.TKN_STRING) {
|
|
762
718
|
return t0;
|
|
763
719
|
}
|
|
764
720
|
lexer.unlex(t0);
|
|
765
721
|
return undefined;
|
|
766
722
|
}
|
|
767
|
-
// 82
|
|
768
723
|
function wide_string_type() {
|
|
769
724
|
let t0 = lexer.lex();
|
|
770
|
-
if (t0 !== undefined && t0.type ===
|
|
771
|
-
// 'wstring' '<' <positive_int_const> '>'
|
|
725
|
+
if (t0 !== undefined && t0.type === Type.TKN_WSTRING) {
|
|
772
726
|
return t0;
|
|
773
727
|
}
|
|
774
728
|
lexer.unlex(t0);
|
|
775
729
|
return undefined;
|
|
776
730
|
}
|
|
777
|
-
// 85
|
|
778
731
|
function attr_dcl() {
|
|
779
732
|
let t0;
|
|
780
733
|
t0 = readonly_attr_spec();
|
|
@@ -782,77 +735,94 @@ function attr_dcl() {
|
|
|
782
735
|
t0 = attr_spec();
|
|
783
736
|
return t0;
|
|
784
737
|
}
|
|
785
|
-
|
|
738
|
+
function except_dcl() {
|
|
739
|
+
let t0 = lexer.lex();
|
|
740
|
+
if (t0 === undefined || t0.type != Type.TKN_EXCEPTION) {
|
|
741
|
+
lexer.unlex(t0);
|
|
742
|
+
return undefined;
|
|
743
|
+
}
|
|
744
|
+
let t1 = identifier();
|
|
745
|
+
if (t1 === undefined)
|
|
746
|
+
throw Error(`expected identifier after '${t0.toString()}'`);
|
|
747
|
+
t0.text = t1.text;
|
|
748
|
+
expect("{");
|
|
749
|
+
while (true) {
|
|
750
|
+
let t2 = member();
|
|
751
|
+
if (t2 === undefined)
|
|
752
|
+
break;
|
|
753
|
+
t0.append(t2);
|
|
754
|
+
}
|
|
755
|
+
expect("}");
|
|
756
|
+
scoper.addType(t0.text, t0);
|
|
757
|
+
return t0;
|
|
758
|
+
}
|
|
786
759
|
function op_dcl() {
|
|
787
|
-
|
|
788
|
-
|
|
760
|
+
const t0 = op_attribute();
|
|
761
|
+
const t1 = op_type_spec();
|
|
789
762
|
if (t1 === undefined) {
|
|
790
763
|
lexer.unlex(t0);
|
|
791
764
|
return undefined;
|
|
792
765
|
}
|
|
793
|
-
|
|
766
|
+
const t2 = identifier();
|
|
794
767
|
if (t2 === undefined) {
|
|
795
|
-
throw Error(
|
|
768
|
+
throw Error(`expected identifier after '${t1.toString()}'`);
|
|
796
769
|
}
|
|
797
|
-
|
|
770
|
+
const t3 = parameter_dcls();
|
|
798
771
|
if (t3 === undefined) {
|
|
799
|
-
// throw Error("expected parameter declaration after "+t2.toString())
|
|
800
772
|
lexer.unlex(t2);
|
|
801
773
|
lexer.unlex(t1);
|
|
802
774
|
lexer.unlex(t0);
|
|
803
775
|
return undefined;
|
|
804
776
|
}
|
|
805
|
-
|
|
777
|
+
const t4 = raises_expr();
|
|
778
|
+
let node = new Node(Type.SYN_OPERATION_DECLARATION);
|
|
806
779
|
node.append(t0);
|
|
807
780
|
node.append(t1);
|
|
808
781
|
node.append(t2);
|
|
809
782
|
node.append(t3);
|
|
810
|
-
node.append(
|
|
783
|
+
node.append(t4);
|
|
811
784
|
node.append(undefined);
|
|
812
785
|
return node;
|
|
813
786
|
}
|
|
814
|
-
// 88
|
|
815
787
|
function op_attribute() {
|
|
816
788
|
let t0 = lexer.lex();
|
|
817
789
|
if (!t0)
|
|
818
790
|
return undefined;
|
|
819
|
-
if (t0.type !==
|
|
791
|
+
if (t0.type !== Type.TKN_ONEWAY) {
|
|
820
792
|
lexer.unlex(t0);
|
|
821
793
|
return undefined;
|
|
822
794
|
}
|
|
823
795
|
return t0;
|
|
824
796
|
}
|
|
825
|
-
// 89
|
|
826
797
|
function op_type_spec() {
|
|
827
798
|
let t0 = param_type_spec();
|
|
828
799
|
if (t0 !== undefined)
|
|
829
800
|
return t0;
|
|
830
801
|
t0 = lexer.lex();
|
|
831
|
-
if (t0 !== undefined && t0.type ===
|
|
802
|
+
if (t0 !== undefined && t0.type === Type.TKN_VOID)
|
|
832
803
|
return t0;
|
|
833
804
|
lexer.unlex(t0);
|
|
834
805
|
return undefined;
|
|
835
806
|
}
|
|
836
|
-
// 90
|
|
837
807
|
function parameter_dcls() {
|
|
838
808
|
let t0 = lexer.lex();
|
|
839
809
|
if (!t0) {
|
|
840
810
|
return undefined;
|
|
841
811
|
}
|
|
842
|
-
if (t0.type !==
|
|
812
|
+
if (t0.type !== Type.TKN_TEXT || t0.text !== '(') {
|
|
843
813
|
lexer.unlex(t0);
|
|
844
814
|
return undefined;
|
|
845
815
|
}
|
|
846
|
-
let declarations = new
|
|
816
|
+
let declarations = new Node(Type.SYN_PARAMETER_DECLARATIONS);
|
|
847
817
|
while (true) {
|
|
848
818
|
let t1 = param_dcl();
|
|
849
819
|
if (t1 !== undefined)
|
|
850
820
|
declarations.append(t1);
|
|
851
821
|
let t2 = lexer.lex();
|
|
852
|
-
if (t2 !== undefined && t2.type ===
|
|
822
|
+
if (t2 !== undefined && t2.type === Type.TKN_TEXT && t2.text === ')') {
|
|
853
823
|
break;
|
|
854
824
|
}
|
|
855
|
-
if (t2 !== undefined && t2.type ===
|
|
825
|
+
if (t2 !== undefined && t2.type === Type.TKN_TEXT && t2.text === ",") {
|
|
856
826
|
continue;
|
|
857
827
|
}
|
|
858
828
|
if (t2 !== undefined)
|
|
@@ -862,7 +832,6 @@ function parameter_dcls() {
|
|
|
862
832
|
}
|
|
863
833
|
return declarations;
|
|
864
834
|
}
|
|
865
|
-
// 91
|
|
866
835
|
function param_dcl() {
|
|
867
836
|
let t0 = param_attribute();
|
|
868
837
|
if (t0 === undefined)
|
|
@@ -879,54 +848,73 @@ function param_dcl() {
|
|
|
879
848
|
if (t2 === undefined) {
|
|
880
849
|
throw Error("Missing parameter name.");
|
|
881
850
|
}
|
|
882
|
-
let declaration = new
|
|
851
|
+
let declaration = new Node(Type.SYN_PARAMETER_DECLARATION);
|
|
883
852
|
declaration.append(t0);
|
|
884
853
|
declaration.append(t1);
|
|
885
854
|
declaration.append(t2);
|
|
886
855
|
return declaration;
|
|
887
856
|
}
|
|
888
|
-
// 92
|
|
889
857
|
function param_attribute() {
|
|
890
858
|
let t0 = lexer.lex();
|
|
891
859
|
if (t0 === undefined)
|
|
892
860
|
return undefined;
|
|
893
861
|
switch (t0.type) {
|
|
894
|
-
case
|
|
895
|
-
case
|
|
896
|
-
case
|
|
862
|
+
case Type.TKN_IN:
|
|
863
|
+
case Type.TKN_OUT:
|
|
864
|
+
case Type.TKN_INOUT:
|
|
897
865
|
return t0;
|
|
898
866
|
}
|
|
899
867
|
lexer.unlex(t0);
|
|
900
868
|
return undefined;
|
|
901
869
|
}
|
|
902
|
-
|
|
870
|
+
function raises_expr() {
|
|
871
|
+
let t0 = lexer.lex();
|
|
872
|
+
if (t0 === undefined || t0.type !== Type.TKN_RAISES) {
|
|
873
|
+
lexer.unlex(t0);
|
|
874
|
+
return undefined;
|
|
875
|
+
}
|
|
876
|
+
expect("(");
|
|
877
|
+
let t1 = scoped_name();
|
|
878
|
+
if (t1 === undefined)
|
|
879
|
+
throw Error(`expected exception name after 'raises('`);
|
|
880
|
+
if (t1.child[0] === undefined || t1.child[0].type !== Type.TKN_EXCEPTION)
|
|
881
|
+
throw Error(`expected ${t1.toString()} to be an exception`);
|
|
882
|
+
if (t1.type)
|
|
883
|
+
t0.append(t1);
|
|
884
|
+
while (true) {
|
|
885
|
+
let t2 = lexer.lex();
|
|
886
|
+
if (t2 === undefined || t2.type !== Type.TKN_TEXT || t0.text !== ",") {
|
|
887
|
+
lexer.unlex(t2);
|
|
888
|
+
break;
|
|
889
|
+
}
|
|
890
|
+
t1 = scoped_name();
|
|
891
|
+
if (t1 === undefined)
|
|
892
|
+
throw Error(`expected exception name after 'raises(..., '`);
|
|
893
|
+
if (t1.child[0] === undefined || t1.child[0].type !== Type.TKN_EXCEPTION)
|
|
894
|
+
throw Error(`expected ${t1.toString()} to be an exception`);
|
|
895
|
+
t0.append(t1);
|
|
896
|
+
}
|
|
897
|
+
expect(")");
|
|
898
|
+
return t0;
|
|
899
|
+
}
|
|
903
900
|
function param_type_spec() {
|
|
904
901
|
let t0;
|
|
905
902
|
t0 = base_type_spec();
|
|
906
903
|
if (t0 !== undefined)
|
|
907
904
|
return t0;
|
|
908
|
-
t0 = template_type_spec();
|
|
905
|
+
t0 = template_type_spec();
|
|
909
906
|
if (t0 !== undefined)
|
|
910
907
|
return t0;
|
|
911
|
-
/*
|
|
912
|
-
t0 = string_type()
|
|
913
|
-
if (t0 !== undefined)
|
|
914
|
-
return t0
|
|
915
|
-
t0 = wide_string_type()
|
|
916
|
-
if (t0 !== undefined)
|
|
917
|
-
return t0
|
|
918
|
-
*/
|
|
919
908
|
t0 = scoped_name();
|
|
920
909
|
if (t0)
|
|
921
910
|
return t0;
|
|
922
911
|
return undefined;
|
|
923
912
|
}
|
|
924
|
-
// 104
|
|
925
913
|
function readonly_attr_spec() {
|
|
926
914
|
let t0 = lexer.lex();
|
|
927
|
-
if (t0 !== undefined && t0.type ===
|
|
915
|
+
if (t0 !== undefined && t0.type === Type.TKN_READONLY) {
|
|
928
916
|
let t1 = lexer.lex();
|
|
929
|
-
if (t1 !== undefined && t1.type ===
|
|
917
|
+
if (t1 !== undefined && t1.type === Type.TKN_ATTRIBUTE) {
|
|
930
918
|
let t2 = param_type_spec();
|
|
931
919
|
if (t2 === undefined)
|
|
932
920
|
throw Error("expected type specifier after 'readonly attribute'");
|
|
@@ -943,16 +931,15 @@ function readonly_attr_spec() {
|
|
|
943
931
|
lexer.unlex(t0);
|
|
944
932
|
return undefined;
|
|
945
933
|
}
|
|
946
|
-
// 105
|
|
947
934
|
function readonly_attr_declarator() {
|
|
948
935
|
let t0 = simple_declarator();
|
|
949
936
|
if (t0 === undefined)
|
|
950
937
|
return undefined;
|
|
951
|
-
let node = new
|
|
938
|
+
let node = new Node(Type.SYN_DECLARATORS);
|
|
952
939
|
while (true) {
|
|
953
940
|
node.append(t0);
|
|
954
941
|
let t1 = lexer.lex();
|
|
955
|
-
if (t1 === undefined || t1.type !==
|
|
942
|
+
if (t1 === undefined || t1.type !== Type.TKN_TEXT || t1.text !== ",") {
|
|
956
943
|
lexer.unlex(t1);
|
|
957
944
|
return node;
|
|
958
945
|
}
|
|
@@ -961,10 +948,9 @@ function readonly_attr_declarator() {
|
|
|
961
948
|
throw Error("expected another declarator after ','");
|
|
962
949
|
}
|
|
963
950
|
}
|
|
964
|
-
// 106
|
|
965
951
|
function attr_spec() {
|
|
966
952
|
let t0 = lexer.lex();
|
|
967
|
-
if (t0 !== undefined && t0.type ===
|
|
953
|
+
if (t0 !== undefined && t0.type === Type.TKN_ATTRIBUTE) {
|
|
968
954
|
let t1 = param_type_spec();
|
|
969
955
|
if (t1 === undefined)
|
|
970
956
|
throw Error("expected type specifier after 'attribute'");
|
|
@@ -979,16 +965,15 @@ function attr_spec() {
|
|
|
979
965
|
lexer.unlex(t0);
|
|
980
966
|
return undefined;
|
|
981
967
|
}
|
|
982
|
-
// 107
|
|
983
968
|
function attr_declarator() {
|
|
984
969
|
let t0 = simple_declarator();
|
|
985
970
|
if (t0 === undefined)
|
|
986
971
|
return undefined;
|
|
987
|
-
let node = new
|
|
972
|
+
let node = new Node(Type.SYN_DECLARATORS);
|
|
988
973
|
while (true) {
|
|
989
974
|
node.append(t0);
|
|
990
975
|
let t1 = lexer.lex();
|
|
991
|
-
if (t1 === undefined || t1.type !==
|
|
976
|
+
if (t1 === undefined || t1.type !== Type.TKN_TEXT || t1.text !== ",") {
|
|
992
977
|
lexer.unlex(t1);
|
|
993
978
|
return node;
|
|
994
979
|
}
|
|
@@ -999,9 +984,101 @@ function attr_declarator() {
|
|
|
999
984
|
}
|
|
1000
985
|
function identifier() {
|
|
1001
986
|
let t0 = lexer.lex();
|
|
1002
|
-
if (t0 !== undefined && t0.type ===
|
|
987
|
+
if (t0 !== undefined && t0.type === Type.TKN_IDENTIFIER)
|
|
1003
988
|
return t0;
|
|
1004
989
|
lexer.unlex(t0);
|
|
1005
990
|
return undefined;
|
|
1006
991
|
}
|
|
992
|
+
function expect(text, customMessage) {
|
|
993
|
+
let t0 = lexer.lex();
|
|
994
|
+
let errorMessage;
|
|
995
|
+
if (customMessage === undefined)
|
|
996
|
+
errorMessage = `expected '${text}' but got '${t0?.toString()}'`;
|
|
997
|
+
else
|
|
998
|
+
errorMessage = customMessage;
|
|
999
|
+
if (t0 === undefined)
|
|
1000
|
+
throw Error(errorMessage + " but found end of file");
|
|
1001
|
+
if (t0.type !== Type.TKN_TEXT || t0.text !== text) {
|
|
1002
|
+
throw Error(errorMessage);
|
|
1003
|
+
}
|
|
1004
|
+
}
|
|
1005
|
+
class Scope {
|
|
1006
|
+
constructor(node) {
|
|
1007
|
+
this.node = node;
|
|
1008
|
+
this.types = new Map();
|
|
1009
|
+
this.modules = new Map();
|
|
1010
|
+
}
|
|
1011
|
+
addType(name, type) {
|
|
1012
|
+
if (this.types.has(name))
|
|
1013
|
+
throw Error("duplicate typename '" + name + "'");
|
|
1014
|
+
this.types.set(name, type);
|
|
1015
|
+
type.typeParent = this.node;
|
|
1016
|
+
}
|
|
1017
|
+
getType(name) {
|
|
1018
|
+
return this.types.get(name);
|
|
1019
|
+
}
|
|
1020
|
+
}
|
|
1021
|
+
class ScopeManager {
|
|
1022
|
+
constructor() {
|
|
1023
|
+
this.stack = new Array();
|
|
1024
|
+
this.stack.push(new Scope(undefined));
|
|
1025
|
+
}
|
|
1026
|
+
getGlobalScope() {
|
|
1027
|
+
return this.stack[0];
|
|
1028
|
+
}
|
|
1029
|
+
getCurrentScope() {
|
|
1030
|
+
return this.stack[this.stack.length - 1];
|
|
1031
|
+
}
|
|
1032
|
+
addType(name, type) {
|
|
1033
|
+
this.getCurrentScope().addType(name, type);
|
|
1034
|
+
}
|
|
1035
|
+
getType(name) {
|
|
1036
|
+
for (let i = this.stack.length - 1; i >= 0; --i) {
|
|
1037
|
+
let type = this.stack[i].getType(name);
|
|
1038
|
+
if (type !== undefined)
|
|
1039
|
+
return type;
|
|
1040
|
+
}
|
|
1041
|
+
return undefined;
|
|
1042
|
+
}
|
|
1043
|
+
enterModule(node) {
|
|
1044
|
+
this.getCurrentScope().addType(node.text, node);
|
|
1045
|
+
this.stack.push(new Scope(node));
|
|
1046
|
+
}
|
|
1047
|
+
leaveModule(node) {
|
|
1048
|
+
this.stack.pop();
|
|
1049
|
+
}
|
|
1050
|
+
}
|
|
1051
|
+
function resolve_module(identifierToken, module) {
|
|
1052
|
+
const paamayimNekudotayim = lexer.lex();
|
|
1053
|
+
if (paamayimNekudotayim === undefined || paamayimNekudotayim.type !== Type.TKN_COLON_COLON)
|
|
1054
|
+
throw Error(`Expected :: after module identifier '${identifierToken.text}'`);
|
|
1055
|
+
const identifier = lexer.lex();
|
|
1056
|
+
if (identifier === undefined || identifier.type !== Type.TKN_IDENTIFIER)
|
|
1057
|
+
throw Error(`Expected identifier after ::'`);
|
|
1058
|
+
for (let child of module.child) {
|
|
1059
|
+
switch (child?.type) {
|
|
1060
|
+
case Type.TKN_MODULE:
|
|
1061
|
+
if (child.text === identifier.text) {
|
|
1062
|
+
identifierToken.append(child);
|
|
1063
|
+
resolve_module(identifierToken, child);
|
|
1064
|
+
return;
|
|
1065
|
+
}
|
|
1066
|
+
break;
|
|
1067
|
+
case Type.TKN_NATIVE:
|
|
1068
|
+
case Type.TKN_VALUETYPE:
|
|
1069
|
+
if (child.text === identifier.text) {
|
|
1070
|
+
identifierToken.append(child);
|
|
1071
|
+
return;
|
|
1072
|
+
}
|
|
1073
|
+
break;
|
|
1074
|
+
case Type.SYN_INTERFACE:
|
|
1075
|
+
if (child.child[0].child[1].text === identifier.text) {
|
|
1076
|
+
identifierToken.append(child);
|
|
1077
|
+
return;
|
|
1078
|
+
}
|
|
1079
|
+
break;
|
|
1080
|
+
}
|
|
1081
|
+
}
|
|
1082
|
+
throw Error(`failed to lookup ${identifier.text}`);
|
|
1083
|
+
}
|
|
1007
1084
|
//# sourceMappingURL=idl-parser.js.map
|