corba.js 0.1.5 → 0.1.6
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/lib/idl/idl.cjs +2735 -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 +276 -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/src/idl/idl-lexer.d.ts +19 -0
- package/lib/src/idl/idl-lexer.js +234 -0
- package/lib/src/idl/idl-lexer.js.map +1 -0
- package/lib/src/idl/idl-node.d.ts +101 -0
- package/lib/src/idl/idl-node.js +212 -0
- package/lib/src/idl/idl-node.js.map +1 -0
- package/lib/src/idl/idl-parser.d.ts +3 -0
- package/lib/src/idl/idl-parser.js +1087 -0
- package/lib/src/idl/idl-parser.js.map +1 -0
- package/lib/src/idl/idl.d.ts +1 -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 +55 -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 +276 -0
- package/lib/src/orb/giop.js +1205 -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 +6 -6
package/lib/idl/idl.cjs
ADDED
|
@@ -0,0 +1,2735 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var fs = require('fs');
|
|
4
|
+
|
|
5
|
+
function _interopNamespace(e) {
|
|
6
|
+
if (e && e.__esModule) return e;
|
|
7
|
+
var n = Object.create(null);
|
|
8
|
+
if (e) {
|
|
9
|
+
Object.keys(e).forEach(function (k) {
|
|
10
|
+
if (k !== 'default') {
|
|
11
|
+
var d = Object.getOwnPropertyDescriptor(e, k);
|
|
12
|
+
Object.defineProperty(n, k, d.get ? d : {
|
|
13
|
+
enumerable: true,
|
|
14
|
+
get: function () { return e[k]; }
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
n["default"] = e;
|
|
20
|
+
return Object.freeze(n);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
var fs__namespace = /*#__PURE__*/_interopNamespace(fs);
|
|
24
|
+
|
|
25
|
+
var Type;
|
|
26
|
+
(function (Type) {
|
|
27
|
+
Type[Type["NONE"] = 0] = "NONE";
|
|
28
|
+
Type[Type["TKN_IDENTIFIER"] = 1] = "TKN_IDENTIFIER";
|
|
29
|
+
Type[Type["TKN_TEXT"] = 2] = "TKN_TEXT";
|
|
30
|
+
Type[Type["TKN_COLON_COLON"] = 3] = "TKN_COLON_COLON";
|
|
31
|
+
Type[Type["TKN_ABSTRACT"] = 4] = "TKN_ABSTRACT";
|
|
32
|
+
Type[Type["TKN_ANY"] = 5] = "TKN_ANY";
|
|
33
|
+
Type[Type["TKN_ATTRIBUTE"] = 6] = "TKN_ATTRIBUTE";
|
|
34
|
+
Type[Type["TKN_BOOLEAN"] = 7] = "TKN_BOOLEAN";
|
|
35
|
+
Type[Type["TKN_CASE"] = 8] = "TKN_CASE";
|
|
36
|
+
Type[Type["TKN_CHAR"] = 9] = "TKN_CHAR";
|
|
37
|
+
Type[Type["TKN_COMPONENT"] = 10] = "TKN_COMPONENT";
|
|
38
|
+
Type[Type["TKN_CONST"] = 11] = "TKN_CONST";
|
|
39
|
+
Type[Type["TKN_CONSUMES"] = 12] = "TKN_CONSUMES";
|
|
40
|
+
Type[Type["TKN_CONTEXT"] = 13] = "TKN_CONTEXT";
|
|
41
|
+
Type[Type["TKN_CUSTOM"] = 14] = "TKN_CUSTOM";
|
|
42
|
+
Type[Type["TKN_DEFAULT"] = 15] = "TKN_DEFAULT";
|
|
43
|
+
Type[Type["TKN_DOUBLE"] = 16] = "TKN_DOUBLE";
|
|
44
|
+
Type[Type["TKN_EXCEPTION"] = 17] = "TKN_EXCEPTION";
|
|
45
|
+
Type[Type["TKN_EMITS"] = 18] = "TKN_EMITS";
|
|
46
|
+
Type[Type["TKN_ENUM"] = 19] = "TKN_ENUM";
|
|
47
|
+
Type[Type["TKN_EVENTTYPE"] = 20] = "TKN_EVENTTYPE";
|
|
48
|
+
Type[Type["TKN_FACTORY"] = 21] = "TKN_FACTORY";
|
|
49
|
+
Type[Type["TKN_FALSE"] = 22] = "TKN_FALSE";
|
|
50
|
+
Type[Type["TKN_FINDER"] = 23] = "TKN_FINDER";
|
|
51
|
+
Type[Type["TKN_FIXED"] = 24] = "TKN_FIXED";
|
|
52
|
+
Type[Type["TKN_FLOAT"] = 25] = "TKN_FLOAT";
|
|
53
|
+
Type[Type["TKN_GETRAISES"] = 26] = "TKN_GETRAISES";
|
|
54
|
+
Type[Type["TKN_HOME"] = 27] = "TKN_HOME";
|
|
55
|
+
Type[Type["TKN_IMPORT"] = 28] = "TKN_IMPORT";
|
|
56
|
+
Type[Type["TKN_IN"] = 29] = "TKN_IN";
|
|
57
|
+
Type[Type["TKN_INOUT"] = 30] = "TKN_INOUT";
|
|
58
|
+
Type[Type["TKN_INTERFACE"] = 31] = "TKN_INTERFACE";
|
|
59
|
+
Type[Type["TKN_LOCAL"] = 32] = "TKN_LOCAL";
|
|
60
|
+
Type[Type["TKN_LONG"] = 33] = "TKN_LONG";
|
|
61
|
+
Type[Type["TKN_MODULE"] = 34] = "TKN_MODULE";
|
|
62
|
+
Type[Type["TKN_MULTIPLE"] = 35] = "TKN_MULTIPLE";
|
|
63
|
+
Type[Type["TKN_NATIVE"] = 36] = "TKN_NATIVE";
|
|
64
|
+
Type[Type["TKN_OBJECT"] = 37] = "TKN_OBJECT";
|
|
65
|
+
Type[Type["TKN_OCTET"] = 38] = "TKN_OCTET";
|
|
66
|
+
Type[Type["TKN_ONEWAY"] = 39] = "TKN_ONEWAY";
|
|
67
|
+
Type[Type["TKN_OUT"] = 40] = "TKN_OUT";
|
|
68
|
+
Type[Type["TKN_PRIMARYKEY"] = 41] = "TKN_PRIMARYKEY";
|
|
69
|
+
Type[Type["TKN_PRIVATE"] = 42] = "TKN_PRIVATE";
|
|
70
|
+
Type[Type["TKN_PROVIDES"] = 43] = "TKN_PROVIDES";
|
|
71
|
+
Type[Type["TKN_PUBLIC"] = 44] = "TKN_PUBLIC";
|
|
72
|
+
Type[Type["TKN_PUBLISHES"] = 45] = "TKN_PUBLISHES";
|
|
73
|
+
Type[Type["TKN_RAISES"] = 46] = "TKN_RAISES";
|
|
74
|
+
Type[Type["TKN_READONLY"] = 47] = "TKN_READONLY";
|
|
75
|
+
Type[Type["TKN_SETRAISES"] = 48] = "TKN_SETRAISES";
|
|
76
|
+
Type[Type["TKN_SEQUENCE"] = 49] = "TKN_SEQUENCE";
|
|
77
|
+
Type[Type["TKN_SHORT"] = 50] = "TKN_SHORT";
|
|
78
|
+
Type[Type["TKN_STRING"] = 51] = "TKN_STRING";
|
|
79
|
+
Type[Type["TKN_STRUCT"] = 52] = "TKN_STRUCT";
|
|
80
|
+
Type[Type["TKN_SUPPORTS"] = 53] = "TKN_SUPPORTS";
|
|
81
|
+
Type[Type["TKN_SWITCH"] = 54] = "TKN_SWITCH";
|
|
82
|
+
Type[Type["TKN_TRUE"] = 55] = "TKN_TRUE";
|
|
83
|
+
Type[Type["TKN_TRUNCATABLE"] = 56] = "TKN_TRUNCATABLE";
|
|
84
|
+
Type[Type["TKN_TYPEDEF"] = 57] = "TKN_TYPEDEF";
|
|
85
|
+
Type[Type["TKN_TYPEID"] = 58] = "TKN_TYPEID";
|
|
86
|
+
Type[Type["TKN_TYPEPREFIX"] = 59] = "TKN_TYPEPREFIX";
|
|
87
|
+
Type[Type["TKN_UNSIGNED"] = 60] = "TKN_UNSIGNED";
|
|
88
|
+
Type[Type["TKN_UNION"] = 61] = "TKN_UNION";
|
|
89
|
+
Type[Type["TKN_USES"] = 62] = "TKN_USES";
|
|
90
|
+
Type[Type["TKN_VALUEBASE"] = 63] = "TKN_VALUEBASE";
|
|
91
|
+
Type[Type["TKN_VALUETYPE"] = 64] = "TKN_VALUETYPE";
|
|
92
|
+
Type[Type["TKN_VOID"] = 65] = "TKN_VOID";
|
|
93
|
+
Type[Type["TKN_WCHAR"] = 66] = "TKN_WCHAR";
|
|
94
|
+
Type[Type["TKN_WSTRING"] = 67] = "TKN_WSTRING";
|
|
95
|
+
Type[Type["SYN_SPECIFICATION"] = 68] = "SYN_SPECIFICATION";
|
|
96
|
+
Type[Type["SYN_INTERFACE"] = 69] = "SYN_INTERFACE";
|
|
97
|
+
Type[Type["SYN_INTERFACE_HEADER"] = 70] = "SYN_INTERFACE_HEADER";
|
|
98
|
+
Type[Type["SYN_INTERFACE_BODY"] = 71] = "SYN_INTERFACE_BODY";
|
|
99
|
+
Type[Type["SYN_VALUE_HEADER"] = 72] = "SYN_VALUE_HEADER";
|
|
100
|
+
Type[Type["SYN_VALUE_INHERITANCE_SPEC"] = 73] = "SYN_VALUE_INHERITANCE_SPEC";
|
|
101
|
+
Type[Type["SYN_STATE_MEMBER"] = 74] = "SYN_STATE_MEMBER";
|
|
102
|
+
Type[Type["SYN_TYPE_DECLARATOR"] = 75] = "SYN_TYPE_DECLARATOR";
|
|
103
|
+
Type[Type["SYN_DECLARATORS"] = 76] = "SYN_DECLARATORS";
|
|
104
|
+
Type[Type["SYN_MEMBER_LIST"] = 77] = "SYN_MEMBER_LIST";
|
|
105
|
+
Type[Type["SYN_MEMBER"] = 78] = "SYN_MEMBER";
|
|
106
|
+
Type[Type["SYN_OPERATION_DECLARATION"] = 79] = "SYN_OPERATION_DECLARATION";
|
|
107
|
+
Type[Type["SYN_PARAMETER_DECLARATIONS"] = 80] = "SYN_PARAMETER_DECLARATIONS";
|
|
108
|
+
Type[Type["SYN_PARAMETER_DECLARATION"] = 81] = "SYN_PARAMETER_DECLARATION";
|
|
109
|
+
Type[Type["SYN_TYPENAME"] = 82] = "SYN_TYPENAME";
|
|
110
|
+
Type[Type["SYN_LONGLONG"] = 83] = "SYN_LONGLONG";
|
|
111
|
+
Type[Type["SYN_UNSIGNED_SHORT"] = 84] = "SYN_UNSIGNED_SHORT";
|
|
112
|
+
Type[Type["SYN_UNSIGNED_LONG"] = 85] = "SYN_UNSIGNED_LONG";
|
|
113
|
+
Type[Type["SYN_UNSIGNED_LONGLONG"] = 86] = "SYN_UNSIGNED_LONGLONG";
|
|
114
|
+
Type[Type["SYN_LONG_DOUBLE"] = 87] = "SYN_LONG_DOUBLE";
|
|
115
|
+
})(Type || (Type = {}));
|
|
116
|
+
class Node {
|
|
117
|
+
constructor(type, text) {
|
|
118
|
+
this.type = type;
|
|
119
|
+
this.text = text;
|
|
120
|
+
this.child = new Array();
|
|
121
|
+
}
|
|
122
|
+
toString() {
|
|
123
|
+
switch (this.type) {
|
|
124
|
+
case Type.NONE: return "none";
|
|
125
|
+
case Type.TKN_TEXT: return "text '" + this.text + "'";
|
|
126
|
+
case Type.TKN_IDENTIFIER: return "identifier '" + this.text + "'";
|
|
127
|
+
case Type.TKN_COLON_COLON: return "::";
|
|
128
|
+
case Type.TKN_ABSTRACT: return "abstract";
|
|
129
|
+
case Type.TKN_ANY: return "any";
|
|
130
|
+
case Type.TKN_ATTRIBUTE: return "attribute";
|
|
131
|
+
case Type.TKN_BOOLEAN: return "boolean";
|
|
132
|
+
case Type.TKN_CASE: return "case";
|
|
133
|
+
case Type.TKN_CHAR: return "char";
|
|
134
|
+
case Type.TKN_COMPONENT: return "component";
|
|
135
|
+
case Type.TKN_CONST: return "const";
|
|
136
|
+
case Type.TKN_CONSUMES: return "consumes";
|
|
137
|
+
case Type.TKN_CONTEXT: return "context";
|
|
138
|
+
case Type.TKN_CUSTOM: return "custom";
|
|
139
|
+
case Type.TKN_DEFAULT: return "default";
|
|
140
|
+
case Type.TKN_DOUBLE: return "double";
|
|
141
|
+
case Type.TKN_EXCEPTION: return "exception";
|
|
142
|
+
case Type.TKN_EMITS: return "emits";
|
|
143
|
+
case Type.TKN_ENUM: return "enum";
|
|
144
|
+
case Type.TKN_EVENTTYPE: return "eventtype";
|
|
145
|
+
case Type.TKN_FACTORY: return "factory";
|
|
146
|
+
case Type.TKN_FALSE: return "FALSE";
|
|
147
|
+
case Type.TKN_FINDER: return "finder";
|
|
148
|
+
case Type.TKN_FIXED: return "fixed";
|
|
149
|
+
case Type.TKN_FLOAT: return "float";
|
|
150
|
+
case Type.TKN_GETRAISES: return "getraises";
|
|
151
|
+
case Type.TKN_HOME: return "home";
|
|
152
|
+
case Type.TKN_IMPORT: return "import";
|
|
153
|
+
case Type.TKN_IN: return "in";
|
|
154
|
+
case Type.TKN_INOUT: return "inout";
|
|
155
|
+
case Type.TKN_INTERFACE: return "interface";
|
|
156
|
+
case Type.TKN_LOCAL: return "local";
|
|
157
|
+
case Type.TKN_LONG: return "long";
|
|
158
|
+
case Type.TKN_MODULE: return "module";
|
|
159
|
+
case Type.TKN_MULTIPLE: return "multiple";
|
|
160
|
+
case Type.TKN_NATIVE: return "native";
|
|
161
|
+
case Type.TKN_OBJECT: return "Object";
|
|
162
|
+
case Type.TKN_OCTET: return "octet";
|
|
163
|
+
case Type.TKN_ONEWAY: return "oneway";
|
|
164
|
+
case Type.TKN_OUT: return "out";
|
|
165
|
+
case Type.TKN_PRIMARYKEY: return "primarykey";
|
|
166
|
+
case Type.TKN_PRIVATE: return "private";
|
|
167
|
+
case Type.TKN_PROVIDES: return "provides";
|
|
168
|
+
case Type.TKN_PUBLIC: return "public";
|
|
169
|
+
case Type.TKN_PUBLISHES: return "publishes";
|
|
170
|
+
case Type.TKN_RAISES: return "raises";
|
|
171
|
+
case Type.TKN_READONLY: return "readonly";
|
|
172
|
+
case Type.TKN_SETRAISES: return "setraises";
|
|
173
|
+
case Type.TKN_SEQUENCE: return "sequence";
|
|
174
|
+
case Type.TKN_SHORT: return "short";
|
|
175
|
+
case Type.TKN_STRING: return "string";
|
|
176
|
+
case Type.TKN_STRUCT: return "struct";
|
|
177
|
+
case Type.TKN_SUPPORTS: return "supports";
|
|
178
|
+
case Type.TKN_SWITCH: return "switch";
|
|
179
|
+
case Type.TKN_TRUE: return "TRUE";
|
|
180
|
+
case Type.TKN_TRUNCATABLE: return "truncatable";
|
|
181
|
+
case Type.TKN_TYPEDEF: return "typedef";
|
|
182
|
+
case Type.TKN_TYPEID: return "typeid";
|
|
183
|
+
case Type.TKN_TYPEPREFIX: return "typeprefix";
|
|
184
|
+
case Type.TKN_UNSIGNED: return "unsigned";
|
|
185
|
+
case Type.TKN_UNION: return "union";
|
|
186
|
+
case Type.TKN_USES: return "uses";
|
|
187
|
+
case Type.TKN_VALUEBASE: return "ValueBase";
|
|
188
|
+
case Type.TKN_VALUETYPE: return "valuetype";
|
|
189
|
+
case Type.TKN_VOID: return "void";
|
|
190
|
+
case Type.TKN_WCHAR: return "wchar";
|
|
191
|
+
case Type.TKN_WSTRING: return "wstring";
|
|
192
|
+
case Type.SYN_SPECIFICATION: return "SYN_SPECIFICATION";
|
|
193
|
+
case Type.SYN_INTERFACE: return "SYN_INTERFACE";
|
|
194
|
+
case Type.SYN_INTERFACE_HEADER: return "SYN_INTERFACE_HEADER";
|
|
195
|
+
case Type.SYN_INTERFACE_BODY: return "SYN_INTERFACE_BODY";
|
|
196
|
+
case Type.SYN_VALUE_HEADER: return "SYN_VALUE_HEADER";
|
|
197
|
+
case Type.SYN_VALUE_INHERITANCE_SPEC: return "SYN_VALUE_INHERITANCE_SPEC";
|
|
198
|
+
case Type.SYN_STATE_MEMBER: return "SYN_STATE_MEMBER";
|
|
199
|
+
case Type.SYN_TYPE_DECLARATOR: return "SYN_TYPE_DECLARATOR";
|
|
200
|
+
case Type.SYN_DECLARATORS: return "SYN_DECLARATORS";
|
|
201
|
+
case Type.SYN_MEMBER_LIST: return "SYN_MEMBER_LIST";
|
|
202
|
+
case Type.SYN_MEMBER: return "SYN_MEMBER";
|
|
203
|
+
case Type.SYN_OPERATION_DECLARATION: return "SYN_OPERATION_DECLARATION";
|
|
204
|
+
case Type.SYN_PARAMETER_DECLARATIONS: return "SYN_PARAMETER_DECLARATIONS";
|
|
205
|
+
case Type.SYN_PARAMETER_DECLARATION: return "SYN_PARAMETER_DECLARATION";
|
|
206
|
+
case Type.SYN_TYPENAME: return "SYN_TYPENAME";
|
|
207
|
+
case Type.SYN_LONGLONG: return "long long";
|
|
208
|
+
case Type.SYN_UNSIGNED_SHORT: return "unsigned short";
|
|
209
|
+
case Type.SYN_UNSIGNED_LONG: return "unsigned long";
|
|
210
|
+
case Type.SYN_UNSIGNED_LONGLONG: return "unsigned long long";
|
|
211
|
+
case Type.SYN_LONG_DOUBLE: return "long double";
|
|
212
|
+
}
|
|
213
|
+
throw Error("Node.toString(): unknown type " + String(this.type));
|
|
214
|
+
}
|
|
215
|
+
printTree(depth = 0) {
|
|
216
|
+
let indent = "";
|
|
217
|
+
for (let i = 0; i < depth; ++i)
|
|
218
|
+
indent = indent + " ";
|
|
219
|
+
console.log(indent + this.toString());
|
|
220
|
+
for (let c of this.child) {
|
|
221
|
+
if (c === undefined) {
|
|
222
|
+
console.log(indent + " undefined");
|
|
223
|
+
}
|
|
224
|
+
else {
|
|
225
|
+
c.printTree(depth + 1);
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
append(node) {
|
|
230
|
+
this.child.push(node);
|
|
231
|
+
}
|
|
232
|
+
prepend(node) {
|
|
233
|
+
this.child.unshift(node);
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
class Lexer {
|
|
238
|
+
constructor(data) {
|
|
239
|
+
this.data = data;
|
|
240
|
+
this.line = 1;
|
|
241
|
+
this.column = 1;
|
|
242
|
+
this.pos = 0;
|
|
243
|
+
this.state = 0;
|
|
244
|
+
this.tokenStack = new Array();
|
|
245
|
+
}
|
|
246
|
+
static isAlpha(c) {
|
|
247
|
+
let n = c.charCodeAt(0);
|
|
248
|
+
return ((0x41 <= n && n <= 0x5a) ||
|
|
249
|
+
(0x61 <= n && n <= 0x7a));
|
|
250
|
+
}
|
|
251
|
+
static isDigit(c) {
|
|
252
|
+
let n = c.charCodeAt(0);
|
|
253
|
+
return (0x30 <= n && n <= 0x39);
|
|
254
|
+
}
|
|
255
|
+
static isAlphaNumeric(c) {
|
|
256
|
+
return Lexer.isAlpha(c) || Lexer.isDigit(c);
|
|
257
|
+
}
|
|
258
|
+
eof() {
|
|
259
|
+
return this.pos >= this.data.length;
|
|
260
|
+
}
|
|
261
|
+
getc() {
|
|
262
|
+
let c = this.data[this.pos++];
|
|
263
|
+
if (c == '\n') {
|
|
264
|
+
++this.line;
|
|
265
|
+
this.column = 1;
|
|
266
|
+
}
|
|
267
|
+
else {
|
|
268
|
+
++this.column;
|
|
269
|
+
}
|
|
270
|
+
return c;
|
|
271
|
+
}
|
|
272
|
+
ungetc() {
|
|
273
|
+
let c = this.data[--this.pos];
|
|
274
|
+
if (c == '\n') {
|
|
275
|
+
let i;
|
|
276
|
+
for (i = this.pos; i > 0; --i) {
|
|
277
|
+
if (this.data[i] == '\n')
|
|
278
|
+
break;
|
|
279
|
+
}
|
|
280
|
+
this.column = i;
|
|
281
|
+
--this.line;
|
|
282
|
+
}
|
|
283
|
+
else {
|
|
284
|
+
--this.column;
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
unlex(token) {
|
|
288
|
+
if (token === undefined)
|
|
289
|
+
return;
|
|
290
|
+
if (token.child.length !== 0)
|
|
291
|
+
throw Error("can not unlex token " + token.toString() + " with children");
|
|
292
|
+
this.tokenStack.push(token);
|
|
293
|
+
}
|
|
294
|
+
lex() {
|
|
295
|
+
if (this.tokenStack.length > 0) {
|
|
296
|
+
return this.tokenStack.pop();
|
|
297
|
+
}
|
|
298
|
+
while (!this.eof()) {
|
|
299
|
+
let c = this.getc();
|
|
300
|
+
let oldstate = this.state;
|
|
301
|
+
switch (this.state) {
|
|
302
|
+
case 0:
|
|
303
|
+
switch (c) {
|
|
304
|
+
case ' ':
|
|
305
|
+
case '\r':
|
|
306
|
+
case '\n':
|
|
307
|
+
case '\t':
|
|
308
|
+
case '\v':
|
|
309
|
+
break;
|
|
310
|
+
case '/':
|
|
311
|
+
this.state = 3;
|
|
312
|
+
break;
|
|
313
|
+
case '_':
|
|
314
|
+
this.state = 1;
|
|
315
|
+
this.text = "";
|
|
316
|
+
continue;
|
|
317
|
+
case ':':
|
|
318
|
+
this.state = 7;
|
|
319
|
+
break;
|
|
320
|
+
default:
|
|
321
|
+
if (Lexer.isAlpha(c)) {
|
|
322
|
+
this.state = 2;
|
|
323
|
+
}
|
|
324
|
+
else {
|
|
325
|
+
return new Node(Type.TKN_TEXT, c);
|
|
326
|
+
}
|
|
327
|
+
break;
|
|
328
|
+
}
|
|
329
|
+
break;
|
|
330
|
+
case 1:
|
|
331
|
+
if (!Lexer.isAlpha(c)) {
|
|
332
|
+
this.ungetc();
|
|
333
|
+
this.state = 0;
|
|
334
|
+
return new Node(Type.TKN_IDENTIFIER, this.text);
|
|
335
|
+
}
|
|
336
|
+
break;
|
|
337
|
+
case 2:
|
|
338
|
+
if (!Lexer.isAlphaNumeric(c) && c !== "_") {
|
|
339
|
+
this.ungetc();
|
|
340
|
+
this.state = 0;
|
|
341
|
+
switch (this.text) {
|
|
342
|
+
case "abstract": return new Node(Type.TKN_ABSTRACT);
|
|
343
|
+
case "any": return new Node(Type.TKN_ANY);
|
|
344
|
+
case "attribute": return new Node(Type.TKN_ATTRIBUTE);
|
|
345
|
+
case "boolean": return new Node(Type.TKN_BOOLEAN);
|
|
346
|
+
case "case": return new Node(Type.TKN_CASE);
|
|
347
|
+
case "char": return new Node(Type.TKN_CHAR);
|
|
348
|
+
case "component": return new Node(Type.TKN_COMPONENT);
|
|
349
|
+
case "const": return new Node(Type.TKN_CONST);
|
|
350
|
+
case "consumes": return new Node(Type.TKN_CONSUMES);
|
|
351
|
+
case "context": return new Node(Type.TKN_CONTEXT);
|
|
352
|
+
case "custom": return new Node(Type.TKN_CUSTOM);
|
|
353
|
+
case "default": return new Node(Type.TKN_DEFAULT);
|
|
354
|
+
case "double": return new Node(Type.TKN_DOUBLE);
|
|
355
|
+
case "exception": return new Node(Type.TKN_EXCEPTION);
|
|
356
|
+
case "emits": return new Node(Type.TKN_EMITS);
|
|
357
|
+
case "enum": return new Node(Type.TKN_ENUM);
|
|
358
|
+
case "eventtype": return new Node(Type.TKN_EVENTTYPE);
|
|
359
|
+
case "factory": return new Node(Type.TKN_FACTORY);
|
|
360
|
+
case "FALSE": return new Node(Type.TKN_FALSE);
|
|
361
|
+
case "finder": return new Node(Type.TKN_FINDER);
|
|
362
|
+
case "fixed": return new Node(Type.TKN_FIXED);
|
|
363
|
+
case "float": return new Node(Type.TKN_FLOAT);
|
|
364
|
+
case "getraises": return new Node(Type.TKN_GETRAISES);
|
|
365
|
+
case "home": return new Node(Type.TKN_HOME);
|
|
366
|
+
case "import": return new Node(Type.TKN_IMPORT);
|
|
367
|
+
case "in": return new Node(Type.TKN_IN);
|
|
368
|
+
case "inout": return new Node(Type.TKN_INOUT);
|
|
369
|
+
case "interface": return new Node(Type.TKN_INTERFACE);
|
|
370
|
+
case "local": return new Node(Type.TKN_LOCAL);
|
|
371
|
+
case "long": return new Node(Type.TKN_LONG);
|
|
372
|
+
case "module": return new Node(Type.TKN_MODULE);
|
|
373
|
+
case "multiple": return new Node(Type.TKN_MULTIPLE);
|
|
374
|
+
case "native": return new Node(Type.TKN_NATIVE);
|
|
375
|
+
case "Object": return new Node(Type.TKN_OBJECT);
|
|
376
|
+
case "octet": return new Node(Type.TKN_OCTET);
|
|
377
|
+
case "oneway": return new Node(Type.TKN_ONEWAY);
|
|
378
|
+
case "out": return new Node(Type.TKN_OUT);
|
|
379
|
+
case "primarykey": return new Node(Type.TKN_PRIMARYKEY);
|
|
380
|
+
case "private": return new Node(Type.TKN_PRIVATE);
|
|
381
|
+
case "provides": return new Node(Type.TKN_PROVIDES);
|
|
382
|
+
case "public": return new Node(Type.TKN_PUBLIC);
|
|
383
|
+
case "publishes": return new Node(Type.TKN_PUBLISHES);
|
|
384
|
+
case "raises": return new Node(Type.TKN_RAISES);
|
|
385
|
+
case "readonly": return new Node(Type.TKN_READONLY);
|
|
386
|
+
case "setraises": return new Node(Type.TKN_SETRAISES);
|
|
387
|
+
case "sequence": return new Node(Type.TKN_SEQUENCE);
|
|
388
|
+
case "short": return new Node(Type.TKN_SHORT);
|
|
389
|
+
case "string": return new Node(Type.TKN_STRING);
|
|
390
|
+
case "struct": return new Node(Type.TKN_STRUCT);
|
|
391
|
+
case "supports": return new Node(Type.TKN_SUPPORTS);
|
|
392
|
+
case "switch": return new Node(Type.TKN_SWITCH);
|
|
393
|
+
case "TRUE": return new Node(Type.TKN_TRUE);
|
|
394
|
+
case "truncatable": return new Node(Type.TKN_TRUNCATABLE);
|
|
395
|
+
case "typedef": return new Node(Type.TKN_TYPEDEF);
|
|
396
|
+
case "typeid": return new Node(Type.TKN_TYPEID);
|
|
397
|
+
case "typeprefix": return new Node(Type.TKN_TYPEPREFIX);
|
|
398
|
+
case "unsigned": return new Node(Type.TKN_UNSIGNED);
|
|
399
|
+
case "union": return new Node(Type.TKN_UNION);
|
|
400
|
+
case "uses": return new Node(Type.TKN_USES);
|
|
401
|
+
case "ValueBase": return new Node(Type.TKN_VALUEBASE);
|
|
402
|
+
case "valuetype": return new Node(Type.TKN_VALUETYPE);
|
|
403
|
+
case "void": return new Node(Type.TKN_VOID);
|
|
404
|
+
case "wchar": return new Node(Type.TKN_WCHAR);
|
|
405
|
+
case "wstring": return new Node(Type.TKN_WSTRING);
|
|
406
|
+
default:
|
|
407
|
+
return new Node(Type.TKN_IDENTIFIER, this.text);
|
|
408
|
+
}
|
|
409
|
+
}
|
|
410
|
+
break;
|
|
411
|
+
case 3:
|
|
412
|
+
switch (c) {
|
|
413
|
+
case '/':
|
|
414
|
+
this.state = 4;
|
|
415
|
+
break;
|
|
416
|
+
case '*':
|
|
417
|
+
this.state = 5;
|
|
418
|
+
break;
|
|
419
|
+
default:
|
|
420
|
+
this.ungetc();
|
|
421
|
+
return new Node(Type.TKN_TEXT, '/');
|
|
422
|
+
}
|
|
423
|
+
break;
|
|
424
|
+
case 4:
|
|
425
|
+
switch (c) {
|
|
426
|
+
case '\n':
|
|
427
|
+
this.state = 0;
|
|
428
|
+
break;
|
|
429
|
+
}
|
|
430
|
+
break;
|
|
431
|
+
case 5:
|
|
432
|
+
switch (c) {
|
|
433
|
+
case '*':
|
|
434
|
+
this.state = 6;
|
|
435
|
+
break;
|
|
436
|
+
}
|
|
437
|
+
break;
|
|
438
|
+
case 6:
|
|
439
|
+
switch (c) {
|
|
440
|
+
case '/':
|
|
441
|
+
this.state = 0;
|
|
442
|
+
break;
|
|
443
|
+
case '*':
|
|
444
|
+
break;
|
|
445
|
+
default:
|
|
446
|
+
this.state = 5;
|
|
447
|
+
}
|
|
448
|
+
break;
|
|
449
|
+
case 7:
|
|
450
|
+
this.state = 0;
|
|
451
|
+
if (c == ':') {
|
|
452
|
+
return new Node(Type.TKN_COLON_COLON, "::");
|
|
453
|
+
}
|
|
454
|
+
else {
|
|
455
|
+
this.ungetc();
|
|
456
|
+
return new Node(Type.TKN_TEXT, ':');
|
|
457
|
+
}
|
|
458
|
+
}
|
|
459
|
+
if (oldstate == 0) {
|
|
460
|
+
this.text = c;
|
|
461
|
+
}
|
|
462
|
+
else {
|
|
463
|
+
this.text += c;
|
|
464
|
+
}
|
|
465
|
+
}
|
|
466
|
+
return undefined;
|
|
467
|
+
}
|
|
468
|
+
}
|
|
469
|
+
|
|
470
|
+
let lexer;
|
|
471
|
+
let scoper;
|
|
472
|
+
function specification(aLexer) {
|
|
473
|
+
lexer = aLexer;
|
|
474
|
+
scoper = new ScopeManager();
|
|
475
|
+
let node = new Node(Type.SYN_SPECIFICATION);
|
|
476
|
+
while (true) {
|
|
477
|
+
let t0 = definition();
|
|
478
|
+
if (t0 === undefined)
|
|
479
|
+
break;
|
|
480
|
+
node.append(t0);
|
|
481
|
+
}
|
|
482
|
+
const tail = lexer.lex();
|
|
483
|
+
if (tail !== undefined) {
|
|
484
|
+
throw Error(`Unparsed token '${tail.toString()}' at end of specification.`);
|
|
485
|
+
}
|
|
486
|
+
return node;
|
|
487
|
+
}
|
|
488
|
+
function definition() {
|
|
489
|
+
let t0;
|
|
490
|
+
t0 = type_dcl();
|
|
491
|
+
if (t0 === undefined)
|
|
492
|
+
t0 = except_dcl();
|
|
493
|
+
if (t0 === undefined)
|
|
494
|
+
t0 = _interface();
|
|
495
|
+
if (t0 === undefined)
|
|
496
|
+
t0 = _module();
|
|
497
|
+
if (t0 === undefined)
|
|
498
|
+
t0 = value();
|
|
499
|
+
if (t0 !== undefined) {
|
|
500
|
+
expect(';');
|
|
501
|
+
}
|
|
502
|
+
return t0;
|
|
503
|
+
}
|
|
504
|
+
function _module() {
|
|
505
|
+
let t0 = lexer.lex();
|
|
506
|
+
if (t0 !== undefined && t0.type === Type.TKN_MODULE) {
|
|
507
|
+
let t1 = identifier();
|
|
508
|
+
if (t1 === undefined)
|
|
509
|
+
throw Error("expected identifier after 'module'");
|
|
510
|
+
t0.text = t1.text;
|
|
511
|
+
expect("{");
|
|
512
|
+
scoper.enterModule(t0);
|
|
513
|
+
while (true) {
|
|
514
|
+
let t2 = definition();
|
|
515
|
+
if (t2 === undefined)
|
|
516
|
+
break;
|
|
517
|
+
if (t2.type == Type.TKN_NATIVE)
|
|
518
|
+
throw Error("'native' can not be used within 'module'");
|
|
519
|
+
t0.append(t2);
|
|
520
|
+
}
|
|
521
|
+
expect("}");
|
|
522
|
+
scoper.leaveModule(t0);
|
|
523
|
+
return t0;
|
|
524
|
+
}
|
|
525
|
+
lexer.unlex(t0);
|
|
526
|
+
return undefined;
|
|
527
|
+
}
|
|
528
|
+
function _interface() {
|
|
529
|
+
return interface_dcl();
|
|
530
|
+
}
|
|
531
|
+
function interface_dcl() {
|
|
532
|
+
let t0 = interface_header();
|
|
533
|
+
if (!t0) {
|
|
534
|
+
t0 = lexer.lex();
|
|
535
|
+
if (t0) {
|
|
536
|
+
lexer.unlex(t0);
|
|
537
|
+
}
|
|
538
|
+
return undefined;
|
|
539
|
+
}
|
|
540
|
+
let t1 = lexer.lex();
|
|
541
|
+
if (t1 === undefined)
|
|
542
|
+
throw Error("expected { after interface header but got end of file");
|
|
543
|
+
if (t1.type !== Type.TKN_TEXT && t1.text != '{')
|
|
544
|
+
throw Error(`expected { after interface header but got ${t0}`);
|
|
545
|
+
let node = new Node(Type.SYN_INTERFACE, t0.child[1].text);
|
|
546
|
+
scoper.addType(t0.child[1].text, node);
|
|
547
|
+
node.append(t0);
|
|
548
|
+
let t2 = interface_body();
|
|
549
|
+
node.append(t2);
|
|
550
|
+
let t3 = lexer.lex();
|
|
551
|
+
if (!t3)
|
|
552
|
+
throw Error("unexpected end of file");
|
|
553
|
+
if (t3.type !== Type.TKN_TEXT && t3.text != '}')
|
|
554
|
+
throw Error(`expected } after interface body but got '${t3}'`);
|
|
555
|
+
return node;
|
|
556
|
+
}
|
|
557
|
+
function interface_header() {
|
|
558
|
+
let t0 = lexer.lex();
|
|
559
|
+
if (t0 === undefined)
|
|
560
|
+
return undefined;
|
|
561
|
+
let t1;
|
|
562
|
+
if (t0.type !== Type.TKN_ABSTRACT && t0.type !== Type.TKN_LOCAL) {
|
|
563
|
+
t1 = t0;
|
|
564
|
+
t0 = undefined;
|
|
565
|
+
}
|
|
566
|
+
else {
|
|
567
|
+
t1 = lexer.lex();
|
|
568
|
+
}
|
|
569
|
+
if (t1 === undefined) {
|
|
570
|
+
lexer.unlex(t0);
|
|
571
|
+
return undefined;
|
|
572
|
+
}
|
|
573
|
+
if (t1.type !== Type.TKN_INTERFACE) {
|
|
574
|
+
lexer.unlex(t1);
|
|
575
|
+
lexer.unlex(t0);
|
|
576
|
+
return undefined;
|
|
577
|
+
}
|
|
578
|
+
let t2 = identifier();
|
|
579
|
+
if (t2 === undefined)
|
|
580
|
+
throw Error("expected identifier after 'interface'");
|
|
581
|
+
let header = new Node(Type.SYN_INTERFACE_HEADER);
|
|
582
|
+
header.append(t0);
|
|
583
|
+
header.append(t2);
|
|
584
|
+
header.append(undefined);
|
|
585
|
+
return header;
|
|
586
|
+
}
|
|
587
|
+
function interface_body() {
|
|
588
|
+
let body = new Node(Type.SYN_INTERFACE_BODY);
|
|
589
|
+
while (true) {
|
|
590
|
+
let t0 = _export();
|
|
591
|
+
if (t0 === undefined)
|
|
592
|
+
return body;
|
|
593
|
+
body.append(t0);
|
|
594
|
+
}
|
|
595
|
+
}
|
|
596
|
+
function _export() {
|
|
597
|
+
let t0 = attr_dcl();
|
|
598
|
+
if (t0 === undefined)
|
|
599
|
+
t0 = op_dcl();
|
|
600
|
+
if (t0 === undefined)
|
|
601
|
+
return undefined;
|
|
602
|
+
expect(';');
|
|
603
|
+
return t0;
|
|
604
|
+
}
|
|
605
|
+
function scoped_name() {
|
|
606
|
+
let globalNamespaceToken = undefined;
|
|
607
|
+
let identifierToken = lexer.lex();
|
|
608
|
+
if (identifierToken === undefined)
|
|
609
|
+
return undefined;
|
|
610
|
+
if (identifierToken.type === Type.TKN_COLON_COLON) {
|
|
611
|
+
globalNamespaceToken = identifierToken;
|
|
612
|
+
identifierToken = lexer.lex();
|
|
613
|
+
if (identifierToken === undefined) {
|
|
614
|
+
lexer.unlex(globalNamespaceToken);
|
|
615
|
+
return undefined;
|
|
616
|
+
}
|
|
617
|
+
}
|
|
618
|
+
if (identifierToken.type !== Type.TKN_IDENTIFIER) {
|
|
619
|
+
lexer.unlex(identifierToken);
|
|
620
|
+
lexer.unlex(globalNamespaceToken);
|
|
621
|
+
return undefined;
|
|
622
|
+
}
|
|
623
|
+
let type;
|
|
624
|
+
if (globalNamespaceToken === undefined) {
|
|
625
|
+
type = scoper.getType(identifierToken.text);
|
|
626
|
+
}
|
|
627
|
+
else {
|
|
628
|
+
type = scoper.getGlobalScope().getType(identifierToken.text);
|
|
629
|
+
throw Error(`No way known to translate '::${identifierToken.text}' to TypeScript`);
|
|
630
|
+
}
|
|
631
|
+
if (type === undefined) {
|
|
632
|
+
throw Error(`unknown type ${identifierToken}`);
|
|
633
|
+
}
|
|
634
|
+
identifierToken.append(type);
|
|
635
|
+
if (type.type === Type.TKN_MODULE) {
|
|
636
|
+
resolve_module(identifierToken, type);
|
|
637
|
+
}
|
|
638
|
+
if (type.type === Type.TKN_NATIVE &&
|
|
639
|
+
type.text.length > 4 &&
|
|
640
|
+
type.text.substring(type.text.length - 4) === "_ptr" &&
|
|
641
|
+
type.typeParent === undefined) {
|
|
642
|
+
type.typeParent = scoper.getType(type.text.substring(0, type.text.length - 4));
|
|
643
|
+
}
|
|
644
|
+
return identifierToken;
|
|
645
|
+
}
|
|
646
|
+
function value() {
|
|
647
|
+
let t0;
|
|
648
|
+
t0 = value_dcl();
|
|
649
|
+
if (t0 !== undefined)
|
|
650
|
+
return t0;
|
|
651
|
+
t0 = value_abs_dcl();
|
|
652
|
+
if (t0 !== undefined)
|
|
653
|
+
return t0;
|
|
654
|
+
t0 = value_box_dcl();
|
|
655
|
+
if (t0 !== undefined)
|
|
656
|
+
return t0;
|
|
657
|
+
t0 = value_forward_dcl();
|
|
658
|
+
if (t0 !== undefined)
|
|
659
|
+
return t0;
|
|
660
|
+
return undefined;
|
|
661
|
+
}
|
|
662
|
+
function value_forward_dcl() {
|
|
663
|
+
return undefined;
|
|
664
|
+
}
|
|
665
|
+
function value_box_dcl() {
|
|
666
|
+
return undefined;
|
|
667
|
+
}
|
|
668
|
+
function value_abs_dcl() {
|
|
669
|
+
return undefined;
|
|
670
|
+
}
|
|
671
|
+
function value_dcl() {
|
|
672
|
+
let header = value_header();
|
|
673
|
+
if (header === undefined) {
|
|
674
|
+
return undefined;
|
|
675
|
+
}
|
|
676
|
+
expect('{');
|
|
677
|
+
let node = new Node(Type.TKN_VALUETYPE);
|
|
678
|
+
node.append(header);
|
|
679
|
+
let identifier = header.child[1].text;
|
|
680
|
+
node.text = identifier;
|
|
681
|
+
scoper.addType(identifier, node);
|
|
682
|
+
while (true) {
|
|
683
|
+
let t1 = value_element();
|
|
684
|
+
if (t1 === undefined)
|
|
685
|
+
break;
|
|
686
|
+
node.append(t1);
|
|
687
|
+
}
|
|
688
|
+
expect('}');
|
|
689
|
+
return node;
|
|
690
|
+
}
|
|
691
|
+
function value_header() {
|
|
692
|
+
let t0 = lexer.lex();
|
|
693
|
+
if (t0 !== undefined) {
|
|
694
|
+
let t1;
|
|
695
|
+
if (t0.type === Type.TKN_CUSTOM) {
|
|
696
|
+
throw Error("corba.js currently does not support custom valuetypes");
|
|
697
|
+
}
|
|
698
|
+
else {
|
|
699
|
+
t1 = t0;
|
|
700
|
+
t0 = undefined;
|
|
701
|
+
}
|
|
702
|
+
if (t1 !== undefined && t1.type === Type.TKN_VALUETYPE) {
|
|
703
|
+
let t2 = identifier();
|
|
704
|
+
if (t2 === undefined)
|
|
705
|
+
throw Error("expected an identifier after valuetype");
|
|
706
|
+
let t3 = value_inheritance_spec();
|
|
707
|
+
let node = new Node(Type.SYN_VALUE_HEADER);
|
|
708
|
+
node.append(t0);
|
|
709
|
+
node.append(t2);
|
|
710
|
+
node.append(t3);
|
|
711
|
+
return node;
|
|
712
|
+
}
|
|
713
|
+
lexer.unlex(t1);
|
|
714
|
+
}
|
|
715
|
+
lexer.unlex(t0);
|
|
716
|
+
return undefined;
|
|
717
|
+
}
|
|
718
|
+
function value_inheritance_spec() {
|
|
719
|
+
let t0 = lexer.lex();
|
|
720
|
+
if (t0 === undefined || t0.type !== Type.TKN_TEXT || t0.text !== ":") {
|
|
721
|
+
lexer.unlex(t0);
|
|
722
|
+
return undefined;
|
|
723
|
+
}
|
|
724
|
+
let t1 = lexer.lex();
|
|
725
|
+
if (t1 !== undefined && t1.type !== Type.TKN_TRUNCATABLE) {
|
|
726
|
+
lexer.unlex(t1);
|
|
727
|
+
t1 = undefined;
|
|
728
|
+
}
|
|
729
|
+
if (t1 !== undefined)
|
|
730
|
+
throw Error("'truncatable' is not supported");
|
|
731
|
+
let node = new Node(Type.SYN_VALUE_INHERITANCE_SPEC);
|
|
732
|
+
node.append(t1);
|
|
733
|
+
while (true) {
|
|
734
|
+
let t2 = value_name();
|
|
735
|
+
if (t2 === undefined) {
|
|
736
|
+
throw Error("expected a value name after '" + t0.text + "'");
|
|
737
|
+
}
|
|
738
|
+
node.append(t2);
|
|
739
|
+
let t3 = lexer.lex();
|
|
740
|
+
if (t3 === undefined)
|
|
741
|
+
throw Error("unexpected end of file");
|
|
742
|
+
if (t3.type !== Type.TKN_TEXT || t3.text !== ",") {
|
|
743
|
+
lexer.unlex(t3);
|
|
744
|
+
break;
|
|
745
|
+
}
|
|
746
|
+
t0 = value_name();
|
|
747
|
+
if (t0 === undefined)
|
|
748
|
+
throw Error("expected a value name after ':'");
|
|
749
|
+
}
|
|
750
|
+
return node;
|
|
751
|
+
}
|
|
752
|
+
function value_name() {
|
|
753
|
+
return scoped_name();
|
|
754
|
+
}
|
|
755
|
+
function value_element() {
|
|
756
|
+
let t0 = _export();
|
|
757
|
+
if (t0 === undefined)
|
|
758
|
+
t0 = state_member();
|
|
759
|
+
return t0;
|
|
760
|
+
}
|
|
761
|
+
function state_member() {
|
|
762
|
+
let t0 = lexer.lex();
|
|
763
|
+
if (t0 === undefined)
|
|
764
|
+
return undefined;
|
|
765
|
+
if (t0.type !== Type.TKN_PUBLIC && t0.type !== Type.TKN_PRIVATE) {
|
|
766
|
+
lexer.unlex(t0);
|
|
767
|
+
return undefined;
|
|
768
|
+
}
|
|
769
|
+
let t1 = type_spec();
|
|
770
|
+
if (t1 === undefined) {
|
|
771
|
+
lexer.unlex(t0);
|
|
772
|
+
return undefined;
|
|
773
|
+
}
|
|
774
|
+
let t2 = declarators();
|
|
775
|
+
if (t2 === undefined) {
|
|
776
|
+
throw Error("expected declarators");
|
|
777
|
+
}
|
|
778
|
+
expect(";");
|
|
779
|
+
let node = new Node(Type.SYN_STATE_MEMBER);
|
|
780
|
+
node.append(t0);
|
|
781
|
+
node.append(t1);
|
|
782
|
+
node.append(t2);
|
|
783
|
+
return node;
|
|
784
|
+
}
|
|
785
|
+
function type_dcl() {
|
|
786
|
+
let t0 = lexer.lex();
|
|
787
|
+
if (t0 !== undefined && t0.type === Type.TKN_TYPEDEF) {
|
|
788
|
+
let t1 = type_declarator();
|
|
789
|
+
if (t1 === undefined) {
|
|
790
|
+
lexer.unlex(t0);
|
|
791
|
+
return undefined;
|
|
792
|
+
}
|
|
793
|
+
const identifiers = t1.child[1].child;
|
|
794
|
+
for (const id of identifiers) {
|
|
795
|
+
scoper.addType(id.text, t1.child[0]);
|
|
796
|
+
}
|
|
797
|
+
t1.type = t0.type;
|
|
798
|
+
return t1;
|
|
799
|
+
}
|
|
800
|
+
lexer.unlex(t0);
|
|
801
|
+
t0 = struct_type();
|
|
802
|
+
if (t0 !== undefined)
|
|
803
|
+
return t0;
|
|
804
|
+
t0 = enum_type();
|
|
805
|
+
if (t0 !== undefined)
|
|
806
|
+
return t0;
|
|
807
|
+
t0 = lexer.lex();
|
|
808
|
+
if (t0 !== undefined && t0.type === Type.TKN_NATIVE) {
|
|
809
|
+
let t1 = simple_declarator();
|
|
810
|
+
if (t1 === undefined) {
|
|
811
|
+
throw Error("expected simple declarator after 'native'");
|
|
812
|
+
}
|
|
813
|
+
t0.append(t1);
|
|
814
|
+
t0.text = t1.text;
|
|
815
|
+
scoper.addType(t1.text, t0);
|
|
816
|
+
return t0;
|
|
817
|
+
}
|
|
818
|
+
lexer.unlex(t0);
|
|
819
|
+
return undefined;
|
|
820
|
+
}
|
|
821
|
+
function type_declarator() {
|
|
822
|
+
const t0 = type_spec();
|
|
823
|
+
if (t0 === undefined)
|
|
824
|
+
return undefined;
|
|
825
|
+
const t1 = declarators();
|
|
826
|
+
if (t1 == undefined) {
|
|
827
|
+
throw Error("expected at least one declarator");
|
|
828
|
+
}
|
|
829
|
+
const n = new Node(Type.SYN_TYPE_DECLARATOR);
|
|
830
|
+
n.append(t0);
|
|
831
|
+
n.append(t1);
|
|
832
|
+
return n;
|
|
833
|
+
}
|
|
834
|
+
function type_spec() {
|
|
835
|
+
let t0;
|
|
836
|
+
t0 = simple_type_spec();
|
|
837
|
+
if (t0 === undefined)
|
|
838
|
+
t0 = constr_type_spec();
|
|
839
|
+
return t0;
|
|
840
|
+
}
|
|
841
|
+
function simple_type_spec() {
|
|
842
|
+
let t0;
|
|
843
|
+
t0 = base_type_spec();
|
|
844
|
+
if (t0 === undefined)
|
|
845
|
+
t0 = template_type_spec();
|
|
846
|
+
if (t0 === undefined)
|
|
847
|
+
t0 = scoped_name();
|
|
848
|
+
return t0;
|
|
849
|
+
}
|
|
850
|
+
function base_type_spec() {
|
|
851
|
+
let t0;
|
|
852
|
+
t0 = floating_pt_type();
|
|
853
|
+
if (t0 !== undefined)
|
|
854
|
+
return t0;
|
|
855
|
+
t0 = integer_type();
|
|
856
|
+
if (t0 !== undefined)
|
|
857
|
+
return t0;
|
|
858
|
+
t0 = char_type();
|
|
859
|
+
if (t0 !== undefined)
|
|
860
|
+
return t0;
|
|
861
|
+
t0 = wide_char_type();
|
|
862
|
+
if (t0 !== undefined)
|
|
863
|
+
return t0;
|
|
864
|
+
t0 = boolean_type();
|
|
865
|
+
if (t0 !== undefined)
|
|
866
|
+
return t0;
|
|
867
|
+
t0 = octet_type();
|
|
868
|
+
if (t0 !== undefined)
|
|
869
|
+
return t0;
|
|
870
|
+
t0 = any_type();
|
|
871
|
+
if (t0 !== undefined)
|
|
872
|
+
return t0;
|
|
873
|
+
return undefined;
|
|
874
|
+
}
|
|
875
|
+
function template_type_spec() {
|
|
876
|
+
let t0;
|
|
877
|
+
t0 = sequence_type();
|
|
878
|
+
if (t0 !== undefined)
|
|
879
|
+
return t0;
|
|
880
|
+
t0 = string_type();
|
|
881
|
+
if (t0 !== undefined)
|
|
882
|
+
return t0;
|
|
883
|
+
t0 = wide_string_type();
|
|
884
|
+
if (t0 !== undefined)
|
|
885
|
+
return t0;
|
|
886
|
+
return undefined;
|
|
887
|
+
}
|
|
888
|
+
function constr_type_spec() {
|
|
889
|
+
let t0 = struct_type();
|
|
890
|
+
if (t0 === undefined)
|
|
891
|
+
t0 = enum_type();
|
|
892
|
+
return t0;
|
|
893
|
+
}
|
|
894
|
+
function declarators() {
|
|
895
|
+
let t0 = declarator();
|
|
896
|
+
if (t0 === undefined)
|
|
897
|
+
return undefined;
|
|
898
|
+
let node = new Node(Type.SYN_DECLARATORS);
|
|
899
|
+
while (true) {
|
|
900
|
+
node.append(t0);
|
|
901
|
+
let t1 = lexer.lex();
|
|
902
|
+
if (t1 === undefined || t1.type !== Type.TKN_TEXT || t1.text !== ",") {
|
|
903
|
+
lexer.unlex(t1);
|
|
904
|
+
break;
|
|
905
|
+
}
|
|
906
|
+
t0 = declarator();
|
|
907
|
+
if (t0 === undefined)
|
|
908
|
+
throw Error("expected another declarator after ','");
|
|
909
|
+
}
|
|
910
|
+
return node;
|
|
911
|
+
}
|
|
912
|
+
function declarator() {
|
|
913
|
+
let t0;
|
|
914
|
+
t0 = simple_declarator();
|
|
915
|
+
return t0;
|
|
916
|
+
}
|
|
917
|
+
function simple_declarator() {
|
|
918
|
+
return identifier();
|
|
919
|
+
}
|
|
920
|
+
function floating_pt_type() {
|
|
921
|
+
let t0 = lexer.lex();
|
|
922
|
+
if (t0 === undefined)
|
|
923
|
+
return undefined;
|
|
924
|
+
if (t0.type === Type.TKN_FLOAT)
|
|
925
|
+
return t0;
|
|
926
|
+
if (t0.type === Type.TKN_DOUBLE)
|
|
927
|
+
return t0;
|
|
928
|
+
if (t0.type === Type.TKN_LONG) {
|
|
929
|
+
let t1 = lexer.lex();
|
|
930
|
+
if (t1 !== undefined && t1.type === Type.TKN_DOUBLE) {
|
|
931
|
+
t1.type = Type.SYN_LONG_DOUBLE;
|
|
932
|
+
return t1;
|
|
933
|
+
}
|
|
934
|
+
lexer.unlex(t1);
|
|
935
|
+
}
|
|
936
|
+
lexer.unlex(t0);
|
|
937
|
+
return undefined;
|
|
938
|
+
}
|
|
939
|
+
function integer_type() {
|
|
940
|
+
let t0;
|
|
941
|
+
t0 = signed_int();
|
|
942
|
+
if (t0 !== undefined)
|
|
943
|
+
return t0;
|
|
944
|
+
t0 = unsigned_int();
|
|
945
|
+
if (t0 !== undefined) {
|
|
946
|
+
return t0;
|
|
947
|
+
}
|
|
948
|
+
t0 = lexer.lex();
|
|
949
|
+
if (t0 !== undefined && [Type.TKN_SHORT, Type.TKN_LONG, Type.TKN_UNSIGNED].includes(t0.type)) {
|
|
950
|
+
throw Error('valid integer types are: short, unsigned short, long, unsigned long, long long, unsigned long long');
|
|
951
|
+
}
|
|
952
|
+
lexer.unlex(t0);
|
|
953
|
+
return undefined;
|
|
954
|
+
}
|
|
955
|
+
function signed_int() {
|
|
956
|
+
let t0;
|
|
957
|
+
t0 = signed_short_int();
|
|
958
|
+
if (t0 !== undefined)
|
|
959
|
+
return t0;
|
|
960
|
+
t0 = signed_longlong_int();
|
|
961
|
+
if (t0 !== undefined)
|
|
962
|
+
return t0;
|
|
963
|
+
t0 = signed_long_int();
|
|
964
|
+
if (t0 !== undefined)
|
|
965
|
+
return t0;
|
|
966
|
+
return undefined;
|
|
967
|
+
}
|
|
968
|
+
function signed_short_int() {
|
|
969
|
+
let t0 = lexer.lex();
|
|
970
|
+
if (t0 !== undefined && t0.type === Type.TKN_SHORT)
|
|
971
|
+
return t0;
|
|
972
|
+
lexer.unlex(t0);
|
|
973
|
+
return undefined;
|
|
974
|
+
}
|
|
975
|
+
function signed_long_int() {
|
|
976
|
+
let t0 = lexer.lex();
|
|
977
|
+
if (t0 === undefined)
|
|
978
|
+
return undefined;
|
|
979
|
+
if (t0.type === Type.TKN_LONG)
|
|
980
|
+
return t0;
|
|
981
|
+
lexer.unlex(t0);
|
|
982
|
+
return undefined;
|
|
983
|
+
}
|
|
984
|
+
function signed_longlong_int() {
|
|
985
|
+
let t0 = lexer.lex();
|
|
986
|
+
if (t0 !== undefined && t0.type === Type.TKN_LONG) {
|
|
987
|
+
let t1 = lexer.lex();
|
|
988
|
+
if (t1 !== undefined && t1.type === Type.TKN_LONG) {
|
|
989
|
+
t0.type = Type.SYN_LONGLONG;
|
|
990
|
+
return t0;
|
|
991
|
+
}
|
|
992
|
+
lexer.unlex(t1);
|
|
993
|
+
}
|
|
994
|
+
lexer.unlex(t0);
|
|
995
|
+
return undefined;
|
|
996
|
+
}
|
|
997
|
+
function unsigned_int() {
|
|
998
|
+
let t0;
|
|
999
|
+
t0 = unsigned_short_int();
|
|
1000
|
+
if (t0 !== undefined)
|
|
1001
|
+
return t0;
|
|
1002
|
+
t0 = unsigned_longlong_int();
|
|
1003
|
+
if (t0 !== undefined)
|
|
1004
|
+
return t0;
|
|
1005
|
+
t0 = unsigned_long_int();
|
|
1006
|
+
if (t0 !== undefined)
|
|
1007
|
+
return t0;
|
|
1008
|
+
return undefined;
|
|
1009
|
+
}
|
|
1010
|
+
function unsigned_short_int() {
|
|
1011
|
+
let t0 = lexer.lex();
|
|
1012
|
+
if (t0 !== undefined && t0.type === Type.TKN_UNSIGNED) {
|
|
1013
|
+
let t1 = lexer.lex();
|
|
1014
|
+
if (t1 !== undefined && t1.type === Type.TKN_SHORT) {
|
|
1015
|
+
t0.type = Type.SYN_UNSIGNED_SHORT;
|
|
1016
|
+
return t0;
|
|
1017
|
+
}
|
|
1018
|
+
lexer.unlex(t1);
|
|
1019
|
+
}
|
|
1020
|
+
lexer.unlex(t0);
|
|
1021
|
+
return undefined;
|
|
1022
|
+
}
|
|
1023
|
+
function unsigned_long_int() {
|
|
1024
|
+
let t0 = lexer.lex();
|
|
1025
|
+
if (t0 !== undefined && t0.type === Type.TKN_UNSIGNED) {
|
|
1026
|
+
let t1 = lexer.lex();
|
|
1027
|
+
if (t1 !== undefined && t1.type === Type.TKN_LONG) {
|
|
1028
|
+
t0.type = Type.SYN_UNSIGNED_LONG;
|
|
1029
|
+
return t0;
|
|
1030
|
+
}
|
|
1031
|
+
lexer.unlex(t1);
|
|
1032
|
+
}
|
|
1033
|
+
lexer.unlex(t0);
|
|
1034
|
+
return undefined;
|
|
1035
|
+
}
|
|
1036
|
+
function unsigned_longlong_int() {
|
|
1037
|
+
let t0 = lexer.lex();
|
|
1038
|
+
if (t0 !== undefined && t0.type === Type.TKN_UNSIGNED) {
|
|
1039
|
+
let t1 = lexer.lex();
|
|
1040
|
+
if (t1 !== undefined && t1.type === Type.TKN_LONG) {
|
|
1041
|
+
let t2 = lexer.lex();
|
|
1042
|
+
if (t2 !== undefined && t2.type === Type.TKN_LONG) {
|
|
1043
|
+
t0.type = Type.SYN_UNSIGNED_LONGLONG;
|
|
1044
|
+
return t0;
|
|
1045
|
+
}
|
|
1046
|
+
lexer.unlex(t2);
|
|
1047
|
+
}
|
|
1048
|
+
lexer.unlex(t1);
|
|
1049
|
+
}
|
|
1050
|
+
lexer.unlex(t0);
|
|
1051
|
+
return undefined;
|
|
1052
|
+
}
|
|
1053
|
+
function char_type() {
|
|
1054
|
+
let t0 = lexer.lex();
|
|
1055
|
+
if (t0 !== undefined && t0.type == Type.TKN_CHAR)
|
|
1056
|
+
return t0;
|
|
1057
|
+
lexer.unlex(t0);
|
|
1058
|
+
return undefined;
|
|
1059
|
+
}
|
|
1060
|
+
function wide_char_type() {
|
|
1061
|
+
let t0 = lexer.lex();
|
|
1062
|
+
if (t0 !== undefined && t0.type == Type.TKN_WCHAR)
|
|
1063
|
+
return t0;
|
|
1064
|
+
lexer.unlex(t0);
|
|
1065
|
+
return undefined;
|
|
1066
|
+
}
|
|
1067
|
+
function boolean_type() {
|
|
1068
|
+
let t0 = lexer.lex();
|
|
1069
|
+
if (t0 !== undefined && t0.type == Type.TKN_BOOLEAN)
|
|
1070
|
+
return t0;
|
|
1071
|
+
lexer.unlex(t0);
|
|
1072
|
+
return undefined;
|
|
1073
|
+
}
|
|
1074
|
+
function octet_type() {
|
|
1075
|
+
let t0 = lexer.lex();
|
|
1076
|
+
if (t0 !== undefined && t0.type == Type.TKN_OCTET)
|
|
1077
|
+
return t0;
|
|
1078
|
+
lexer.unlex(t0);
|
|
1079
|
+
return undefined;
|
|
1080
|
+
}
|
|
1081
|
+
function any_type() {
|
|
1082
|
+
const t0 = lexer.lex();
|
|
1083
|
+
if (t0 !== undefined && t0.type == Type.TKN_ANY)
|
|
1084
|
+
return t0;
|
|
1085
|
+
lexer.unlex(t0);
|
|
1086
|
+
return undefined;
|
|
1087
|
+
}
|
|
1088
|
+
function struct_type() {
|
|
1089
|
+
const t0 = lexer.lex();
|
|
1090
|
+
if (t0 === undefined || t0.type !== Type.TKN_STRUCT) {
|
|
1091
|
+
lexer.unlex(t0);
|
|
1092
|
+
return undefined;
|
|
1093
|
+
}
|
|
1094
|
+
const t1 = identifier();
|
|
1095
|
+
if (t1 === undefined)
|
|
1096
|
+
throw Error("expected identifier after 'struct'");
|
|
1097
|
+
expect('{');
|
|
1098
|
+
const t2 = member_list();
|
|
1099
|
+
if (t2 === undefined)
|
|
1100
|
+
throw Error("expected at least one member within 'struct'");
|
|
1101
|
+
expect('}');
|
|
1102
|
+
t2.type = t0.type;
|
|
1103
|
+
t2.text = t1.text;
|
|
1104
|
+
scoper.addType(t2.text, t0);
|
|
1105
|
+
return t2;
|
|
1106
|
+
}
|
|
1107
|
+
function member_list() {
|
|
1108
|
+
const t0 = member();
|
|
1109
|
+
if (t0 === undefined)
|
|
1110
|
+
return undefined;
|
|
1111
|
+
const node = new Node(Type.SYN_MEMBER_LIST);
|
|
1112
|
+
node.append(t0);
|
|
1113
|
+
while (true) {
|
|
1114
|
+
const t1 = member();
|
|
1115
|
+
if (t1 === undefined)
|
|
1116
|
+
break;
|
|
1117
|
+
node.append(t1);
|
|
1118
|
+
}
|
|
1119
|
+
return node;
|
|
1120
|
+
}
|
|
1121
|
+
function member() {
|
|
1122
|
+
const node = new Node(Type.SYN_MEMBER);
|
|
1123
|
+
const t0 = type_spec();
|
|
1124
|
+
if (t0 === undefined)
|
|
1125
|
+
return undefined;
|
|
1126
|
+
const t1 = declarators();
|
|
1127
|
+
if (t1 === undefined)
|
|
1128
|
+
throw Error(`expected declarators after type_spec ${t0.toString()}`);
|
|
1129
|
+
expect(";");
|
|
1130
|
+
node.append(t0);
|
|
1131
|
+
node.append(t1);
|
|
1132
|
+
return node;
|
|
1133
|
+
}
|
|
1134
|
+
function enum_type() {
|
|
1135
|
+
let t0 = lexer.lex();
|
|
1136
|
+
if (t0 !== undefined && t0.type == Type.TKN_ENUM) {
|
|
1137
|
+
const t1 = identifier();
|
|
1138
|
+
if (t1 === undefined)
|
|
1139
|
+
throw Error("expected identifier after 'enum'");
|
|
1140
|
+
t0.text = t1.text;
|
|
1141
|
+
expect("{");
|
|
1142
|
+
const set = new Set();
|
|
1143
|
+
while (true) {
|
|
1144
|
+
let t2 = lexer.lex();
|
|
1145
|
+
if (t2 === undefined)
|
|
1146
|
+
throw Error("unexpected end of file");
|
|
1147
|
+
if (t2.type !== Type.TKN_IDENTIFIER)
|
|
1148
|
+
throw Error("expected identifier but got ${t2}");
|
|
1149
|
+
if (set.has(t2.text)) {
|
|
1150
|
+
throw Error(`Declaration of enumerator '${t2.text}' clashes with earlier declaration of enumerator '${t2.text}'`);
|
|
1151
|
+
}
|
|
1152
|
+
set.add(t2.text);
|
|
1153
|
+
t0.append(t2);
|
|
1154
|
+
let t3 = lexer.lex();
|
|
1155
|
+
if (t3 === undefined)
|
|
1156
|
+
throw Error("unexpected end of file");
|
|
1157
|
+
if (t3.type !== Type.TKN_TEXT)
|
|
1158
|
+
throw Error("expected ',' or '}' but got ${t2}");
|
|
1159
|
+
if (t3.text === "}")
|
|
1160
|
+
break;
|
|
1161
|
+
}
|
|
1162
|
+
scoper.addType(t0.text, t0);
|
|
1163
|
+
return t0;
|
|
1164
|
+
}
|
|
1165
|
+
lexer.unlex(t0);
|
|
1166
|
+
return undefined;
|
|
1167
|
+
}
|
|
1168
|
+
function sequence_type() {
|
|
1169
|
+
let t0 = lexer.lex();
|
|
1170
|
+
if (t0 !== undefined && t0.type === Type.TKN_SEQUENCE) {
|
|
1171
|
+
expect("<");
|
|
1172
|
+
let t1 = simple_type_spec();
|
|
1173
|
+
if (t1 === undefined)
|
|
1174
|
+
throw Error("expected type after 'sequence <'");
|
|
1175
|
+
expect(">");
|
|
1176
|
+
t0.append(t1);
|
|
1177
|
+
t0.append(undefined);
|
|
1178
|
+
return t0;
|
|
1179
|
+
}
|
|
1180
|
+
lexer.unlex(t0);
|
|
1181
|
+
return undefined;
|
|
1182
|
+
}
|
|
1183
|
+
function string_type() {
|
|
1184
|
+
let t0 = lexer.lex();
|
|
1185
|
+
if (t0 !== undefined && t0.type === Type.TKN_STRING) {
|
|
1186
|
+
return t0;
|
|
1187
|
+
}
|
|
1188
|
+
lexer.unlex(t0);
|
|
1189
|
+
return undefined;
|
|
1190
|
+
}
|
|
1191
|
+
function wide_string_type() {
|
|
1192
|
+
let t0 = lexer.lex();
|
|
1193
|
+
if (t0 !== undefined && t0.type === Type.TKN_WSTRING) {
|
|
1194
|
+
return t0;
|
|
1195
|
+
}
|
|
1196
|
+
lexer.unlex(t0);
|
|
1197
|
+
return undefined;
|
|
1198
|
+
}
|
|
1199
|
+
function attr_dcl() {
|
|
1200
|
+
let t0;
|
|
1201
|
+
t0 = readonly_attr_spec();
|
|
1202
|
+
if (t0 === undefined)
|
|
1203
|
+
t0 = attr_spec();
|
|
1204
|
+
return t0;
|
|
1205
|
+
}
|
|
1206
|
+
function except_dcl() {
|
|
1207
|
+
let t0 = lexer.lex();
|
|
1208
|
+
if (t0 === undefined || t0.type != Type.TKN_EXCEPTION) {
|
|
1209
|
+
lexer.unlex(t0);
|
|
1210
|
+
return undefined;
|
|
1211
|
+
}
|
|
1212
|
+
let t1 = identifier();
|
|
1213
|
+
if (t1 === undefined)
|
|
1214
|
+
throw Error(`expected identifier after '${t0.toString()}'`);
|
|
1215
|
+
t0.text = t1.text;
|
|
1216
|
+
expect("{");
|
|
1217
|
+
while (true) {
|
|
1218
|
+
let t2 = member();
|
|
1219
|
+
if (t2 === undefined)
|
|
1220
|
+
break;
|
|
1221
|
+
t0.append(t2);
|
|
1222
|
+
}
|
|
1223
|
+
expect("}");
|
|
1224
|
+
scoper.addType(t0.text, t0);
|
|
1225
|
+
return t0;
|
|
1226
|
+
}
|
|
1227
|
+
function op_dcl() {
|
|
1228
|
+
const t0 = op_attribute();
|
|
1229
|
+
const t1 = op_type_spec();
|
|
1230
|
+
if (t1 === undefined) {
|
|
1231
|
+
lexer.unlex(t0);
|
|
1232
|
+
return undefined;
|
|
1233
|
+
}
|
|
1234
|
+
const t2 = identifier();
|
|
1235
|
+
if (t2 === undefined) {
|
|
1236
|
+
throw Error(`expected identifier after '${t1.toString()}'`);
|
|
1237
|
+
}
|
|
1238
|
+
const t3 = parameter_dcls();
|
|
1239
|
+
if (t3 === undefined) {
|
|
1240
|
+
lexer.unlex(t2);
|
|
1241
|
+
if (t1.child.length != 0) {
|
|
1242
|
+
throw Error("expected parameter declaration after " + t2.toString());
|
|
1243
|
+
}
|
|
1244
|
+
lexer.unlex(t1);
|
|
1245
|
+
lexer.unlex(t0);
|
|
1246
|
+
return undefined;
|
|
1247
|
+
}
|
|
1248
|
+
const t4 = raises_expr();
|
|
1249
|
+
let node = new Node(Type.SYN_OPERATION_DECLARATION);
|
|
1250
|
+
node.append(t0);
|
|
1251
|
+
node.append(t1);
|
|
1252
|
+
node.append(t2);
|
|
1253
|
+
node.append(t3);
|
|
1254
|
+
node.append(t4);
|
|
1255
|
+
node.append(undefined);
|
|
1256
|
+
return node;
|
|
1257
|
+
}
|
|
1258
|
+
function op_attribute() {
|
|
1259
|
+
let t0 = lexer.lex();
|
|
1260
|
+
if (!t0)
|
|
1261
|
+
return undefined;
|
|
1262
|
+
if (t0.type !== Type.TKN_ONEWAY) {
|
|
1263
|
+
lexer.unlex(t0);
|
|
1264
|
+
return undefined;
|
|
1265
|
+
}
|
|
1266
|
+
return t0;
|
|
1267
|
+
}
|
|
1268
|
+
function op_type_spec() {
|
|
1269
|
+
let t0 = param_type_spec();
|
|
1270
|
+
if (t0 !== undefined)
|
|
1271
|
+
return t0;
|
|
1272
|
+
t0 = lexer.lex();
|
|
1273
|
+
if (t0 !== undefined && t0.type === Type.TKN_VOID)
|
|
1274
|
+
return t0;
|
|
1275
|
+
lexer.unlex(t0);
|
|
1276
|
+
return undefined;
|
|
1277
|
+
}
|
|
1278
|
+
function parameter_dcls() {
|
|
1279
|
+
let t0 = lexer.lex();
|
|
1280
|
+
if (!t0) {
|
|
1281
|
+
return undefined;
|
|
1282
|
+
}
|
|
1283
|
+
if (t0.type !== Type.TKN_TEXT || t0.text !== '(') {
|
|
1284
|
+
lexer.unlex(t0);
|
|
1285
|
+
return undefined;
|
|
1286
|
+
}
|
|
1287
|
+
let declarations = new Node(Type.SYN_PARAMETER_DECLARATIONS);
|
|
1288
|
+
while (true) {
|
|
1289
|
+
let t1 = param_dcl();
|
|
1290
|
+
if (t1 !== undefined)
|
|
1291
|
+
declarations.append(t1);
|
|
1292
|
+
let t2 = lexer.lex();
|
|
1293
|
+
if (t2 !== undefined && t2.type === Type.TKN_TEXT && t2.text === ')') {
|
|
1294
|
+
break;
|
|
1295
|
+
}
|
|
1296
|
+
if (t2 !== undefined && t2.type === Type.TKN_TEXT && t2.text === ",") {
|
|
1297
|
+
continue;
|
|
1298
|
+
}
|
|
1299
|
+
if (t2 !== undefined)
|
|
1300
|
+
throw Error("expected 'in', 'out', 'inout' or ')' to end for parameter declaration but got " + t2.toString());
|
|
1301
|
+
else
|
|
1302
|
+
throw Error("expected 'in', 'out', 'inout' or ')' to end for parameter declaration but end of file");
|
|
1303
|
+
}
|
|
1304
|
+
return declarations;
|
|
1305
|
+
}
|
|
1306
|
+
function param_dcl() {
|
|
1307
|
+
let t0 = param_attribute();
|
|
1308
|
+
if (t0 === undefined)
|
|
1309
|
+
return undefined;
|
|
1310
|
+
let t1 = param_type_spec();
|
|
1311
|
+
if (t1 === undefined) {
|
|
1312
|
+
t1 = lexer.lex();
|
|
1313
|
+
if (t1 !== undefined)
|
|
1314
|
+
throw Error("expected type specification but got " + t1.toString());
|
|
1315
|
+
else
|
|
1316
|
+
throw Error("expected type specification but found end of file");
|
|
1317
|
+
}
|
|
1318
|
+
let t2 = simple_declarator();
|
|
1319
|
+
if (t2 === undefined) {
|
|
1320
|
+
throw Error("Missing parameter name.");
|
|
1321
|
+
}
|
|
1322
|
+
let declaration = new Node(Type.SYN_PARAMETER_DECLARATION);
|
|
1323
|
+
declaration.append(t0);
|
|
1324
|
+
declaration.append(t1);
|
|
1325
|
+
declaration.append(t2);
|
|
1326
|
+
return declaration;
|
|
1327
|
+
}
|
|
1328
|
+
function param_attribute() {
|
|
1329
|
+
let t0 = lexer.lex();
|
|
1330
|
+
if (t0 === undefined)
|
|
1331
|
+
return undefined;
|
|
1332
|
+
switch (t0.type) {
|
|
1333
|
+
case Type.TKN_IN:
|
|
1334
|
+
case Type.TKN_OUT:
|
|
1335
|
+
case Type.TKN_INOUT:
|
|
1336
|
+
return t0;
|
|
1337
|
+
}
|
|
1338
|
+
lexer.unlex(t0);
|
|
1339
|
+
return undefined;
|
|
1340
|
+
}
|
|
1341
|
+
function raises_expr() {
|
|
1342
|
+
let t0 = lexer.lex();
|
|
1343
|
+
if (t0 === undefined || t0.type !== Type.TKN_RAISES) {
|
|
1344
|
+
lexer.unlex(t0);
|
|
1345
|
+
return undefined;
|
|
1346
|
+
}
|
|
1347
|
+
expect("(");
|
|
1348
|
+
let t1 = scoped_name();
|
|
1349
|
+
if (t1 === undefined)
|
|
1350
|
+
throw Error(`expected exception name after 'raises('`);
|
|
1351
|
+
if (t1.child[0] === undefined || t1.child[0].type !== Type.TKN_EXCEPTION)
|
|
1352
|
+
throw Error(`expected ${t1.toString()} to be an exception`);
|
|
1353
|
+
if (t1.type)
|
|
1354
|
+
t0.append(t1);
|
|
1355
|
+
while (true) {
|
|
1356
|
+
let t2 = lexer.lex();
|
|
1357
|
+
if (t2 === undefined || t2.type !== Type.TKN_TEXT || t0.text !== ",") {
|
|
1358
|
+
lexer.unlex(t2);
|
|
1359
|
+
break;
|
|
1360
|
+
}
|
|
1361
|
+
t1 = scoped_name();
|
|
1362
|
+
if (t1 === undefined)
|
|
1363
|
+
throw Error(`expected exception name after 'raises(..., '`);
|
|
1364
|
+
if (t1.child[0] === undefined || t1.child[0].type !== Type.TKN_EXCEPTION)
|
|
1365
|
+
throw Error(`expected ${t1.toString()} to be an exception`);
|
|
1366
|
+
t0.append(t1);
|
|
1367
|
+
}
|
|
1368
|
+
expect(")");
|
|
1369
|
+
return t0;
|
|
1370
|
+
}
|
|
1371
|
+
function param_type_spec() {
|
|
1372
|
+
let t0;
|
|
1373
|
+
t0 = base_type_spec();
|
|
1374
|
+
if (t0 !== undefined)
|
|
1375
|
+
return t0;
|
|
1376
|
+
t0 = template_type_spec();
|
|
1377
|
+
if (t0 !== undefined)
|
|
1378
|
+
return t0;
|
|
1379
|
+
t0 = scoped_name();
|
|
1380
|
+
if (t0)
|
|
1381
|
+
return t0;
|
|
1382
|
+
return undefined;
|
|
1383
|
+
}
|
|
1384
|
+
function readonly_attr_spec() {
|
|
1385
|
+
let t0 = lexer.lex();
|
|
1386
|
+
if (t0 !== undefined && t0.type === Type.TKN_READONLY) {
|
|
1387
|
+
let t1 = lexer.lex();
|
|
1388
|
+
if (t1 !== undefined && t1.type === Type.TKN_ATTRIBUTE) {
|
|
1389
|
+
let t2 = param_type_spec();
|
|
1390
|
+
if (t2 === undefined)
|
|
1391
|
+
throw Error("expected type specifier after 'readonly attribute'");
|
|
1392
|
+
let t3 = readonly_attr_declarator();
|
|
1393
|
+
if (t3 === undefined)
|
|
1394
|
+
throw Error("expected declarator for 'readonly attribute'");
|
|
1395
|
+
t1.append(t0);
|
|
1396
|
+
t1.append(t2);
|
|
1397
|
+
t1.append(t3);
|
|
1398
|
+
return t1;
|
|
1399
|
+
}
|
|
1400
|
+
lexer.unlex(t1);
|
|
1401
|
+
}
|
|
1402
|
+
lexer.unlex(t0);
|
|
1403
|
+
return undefined;
|
|
1404
|
+
}
|
|
1405
|
+
function readonly_attr_declarator() {
|
|
1406
|
+
let t0 = simple_declarator();
|
|
1407
|
+
if (t0 === undefined)
|
|
1408
|
+
return undefined;
|
|
1409
|
+
let node = new Node(Type.SYN_DECLARATORS);
|
|
1410
|
+
while (true) {
|
|
1411
|
+
node.append(t0);
|
|
1412
|
+
let t1 = lexer.lex();
|
|
1413
|
+
if (t1 === undefined || t1.type !== Type.TKN_TEXT || t1.text !== ",") {
|
|
1414
|
+
lexer.unlex(t1);
|
|
1415
|
+
return node;
|
|
1416
|
+
}
|
|
1417
|
+
t0 = simple_declarator();
|
|
1418
|
+
if (t0 === undefined)
|
|
1419
|
+
throw Error("expected another declarator after ','");
|
|
1420
|
+
}
|
|
1421
|
+
}
|
|
1422
|
+
function attr_spec() {
|
|
1423
|
+
let t0 = lexer.lex();
|
|
1424
|
+
if (t0 !== undefined && t0.type === Type.TKN_ATTRIBUTE) {
|
|
1425
|
+
let t1 = param_type_spec();
|
|
1426
|
+
if (t1 === undefined)
|
|
1427
|
+
throw Error("expected type specifier after 'attribute'");
|
|
1428
|
+
let t2 = attr_declarator();
|
|
1429
|
+
if (t2 === undefined)
|
|
1430
|
+
throw Error("expected declarator for 'attribute'");
|
|
1431
|
+
t0.append(undefined);
|
|
1432
|
+
t0.append(t1);
|
|
1433
|
+
t0.append(t2);
|
|
1434
|
+
return t0;
|
|
1435
|
+
}
|
|
1436
|
+
lexer.unlex(t0);
|
|
1437
|
+
return undefined;
|
|
1438
|
+
}
|
|
1439
|
+
function attr_declarator() {
|
|
1440
|
+
let t0 = simple_declarator();
|
|
1441
|
+
if (t0 === undefined)
|
|
1442
|
+
return undefined;
|
|
1443
|
+
let node = new Node(Type.SYN_DECLARATORS);
|
|
1444
|
+
while (true) {
|
|
1445
|
+
node.append(t0);
|
|
1446
|
+
let t1 = lexer.lex();
|
|
1447
|
+
if (t1 === undefined || t1.type !== Type.TKN_TEXT || t1.text !== ",") {
|
|
1448
|
+
lexer.unlex(t1);
|
|
1449
|
+
return node;
|
|
1450
|
+
}
|
|
1451
|
+
t0 = simple_declarator();
|
|
1452
|
+
if (t0 === undefined)
|
|
1453
|
+
throw Error("expected another declarator after ','");
|
|
1454
|
+
}
|
|
1455
|
+
}
|
|
1456
|
+
function identifier() {
|
|
1457
|
+
let t0 = lexer.lex();
|
|
1458
|
+
if (t0 !== undefined && t0.type === Type.TKN_IDENTIFIER)
|
|
1459
|
+
return t0;
|
|
1460
|
+
lexer.unlex(t0);
|
|
1461
|
+
return undefined;
|
|
1462
|
+
}
|
|
1463
|
+
function expect(text, customMessage) {
|
|
1464
|
+
let t0 = lexer.lex();
|
|
1465
|
+
let errorMessage;
|
|
1466
|
+
if (customMessage === undefined)
|
|
1467
|
+
errorMessage = `expected '${text}' but got '${t0?.toString()}'`;
|
|
1468
|
+
else
|
|
1469
|
+
errorMessage = customMessage;
|
|
1470
|
+
if (t0 === undefined)
|
|
1471
|
+
throw Error(errorMessage + " but found end of file");
|
|
1472
|
+
if (t0.type !== Type.TKN_TEXT || t0.text !== text) {
|
|
1473
|
+
throw Error(errorMessage);
|
|
1474
|
+
}
|
|
1475
|
+
}
|
|
1476
|
+
class Scope {
|
|
1477
|
+
constructor(node) {
|
|
1478
|
+
this.node = node;
|
|
1479
|
+
this.types = new Map();
|
|
1480
|
+
this.modules = new Map();
|
|
1481
|
+
}
|
|
1482
|
+
addType(name, type) {
|
|
1483
|
+
if (this.types.has(name))
|
|
1484
|
+
throw Error("duplicate typename '" + name + "'");
|
|
1485
|
+
this.types.set(name, type);
|
|
1486
|
+
type.typeParent = this.node;
|
|
1487
|
+
}
|
|
1488
|
+
getType(name) {
|
|
1489
|
+
return this.types.get(name);
|
|
1490
|
+
}
|
|
1491
|
+
}
|
|
1492
|
+
class ScopeManager {
|
|
1493
|
+
constructor() {
|
|
1494
|
+
this.stack = new Array();
|
|
1495
|
+
this.stack.push(new Scope(undefined));
|
|
1496
|
+
}
|
|
1497
|
+
getGlobalScope() {
|
|
1498
|
+
return this.stack[0];
|
|
1499
|
+
}
|
|
1500
|
+
getCurrentScope() {
|
|
1501
|
+
return this.stack[this.stack.length - 1];
|
|
1502
|
+
}
|
|
1503
|
+
addType(name, type) {
|
|
1504
|
+
this.getCurrentScope().addType(name, type);
|
|
1505
|
+
}
|
|
1506
|
+
getType(name) {
|
|
1507
|
+
for (let i = this.stack.length - 1; i >= 0; --i) {
|
|
1508
|
+
let type = this.stack[i].getType(name);
|
|
1509
|
+
if (type !== undefined)
|
|
1510
|
+
return type;
|
|
1511
|
+
}
|
|
1512
|
+
return undefined;
|
|
1513
|
+
}
|
|
1514
|
+
enterModule(node) {
|
|
1515
|
+
this.getCurrentScope().addType(node.text, node);
|
|
1516
|
+
this.stack.push(new Scope(node));
|
|
1517
|
+
}
|
|
1518
|
+
leaveModule(node) {
|
|
1519
|
+
this.stack.pop();
|
|
1520
|
+
}
|
|
1521
|
+
}
|
|
1522
|
+
function resolve_module(identifierToken, module) {
|
|
1523
|
+
const paamayimNekudotayim = lexer.lex();
|
|
1524
|
+
if (paamayimNekudotayim === undefined || paamayimNekudotayim.type !== Type.TKN_COLON_COLON)
|
|
1525
|
+
throw Error(`Expected :: after module identifier '${identifierToken.text}'`);
|
|
1526
|
+
const identifier = lexer.lex();
|
|
1527
|
+
if (identifier === undefined || identifier.type !== Type.TKN_IDENTIFIER)
|
|
1528
|
+
throw Error(`Expected identifier after ::'`);
|
|
1529
|
+
for (let child of module.child) {
|
|
1530
|
+
switch (child?.type) {
|
|
1531
|
+
case Type.TKN_MODULE:
|
|
1532
|
+
if (child.text === identifier.text) {
|
|
1533
|
+
identifierToken.append(child);
|
|
1534
|
+
resolve_module(identifierToken, child);
|
|
1535
|
+
return;
|
|
1536
|
+
}
|
|
1537
|
+
break;
|
|
1538
|
+
case Type.TKN_NATIVE:
|
|
1539
|
+
case Type.TKN_VALUETYPE:
|
|
1540
|
+
if (child.text === identifier.text) {
|
|
1541
|
+
identifierToken.append(child);
|
|
1542
|
+
return;
|
|
1543
|
+
}
|
|
1544
|
+
break;
|
|
1545
|
+
case Type.SYN_INTERFACE:
|
|
1546
|
+
if (child.child[0].child[1].text === identifier.text) {
|
|
1547
|
+
identifierToken.append(child);
|
|
1548
|
+
return;
|
|
1549
|
+
}
|
|
1550
|
+
break;
|
|
1551
|
+
}
|
|
1552
|
+
}
|
|
1553
|
+
throw Error(`failed to lookup ${identifier.text}`);
|
|
1554
|
+
}
|
|
1555
|
+
|
|
1556
|
+
let filename = "";
|
|
1557
|
+
let filenamePrefix = "";
|
|
1558
|
+
let filenameLocal = "";
|
|
1559
|
+
function setFilename(name) {
|
|
1560
|
+
filename = name;
|
|
1561
|
+
}
|
|
1562
|
+
function setFilenamePrefix(prefix) {
|
|
1563
|
+
filenamePrefix = prefix;
|
|
1564
|
+
}
|
|
1565
|
+
function setFilenameLocal(name) {
|
|
1566
|
+
filenameLocal = name;
|
|
1567
|
+
}
|
|
1568
|
+
let classAttributes = new Map();
|
|
1569
|
+
function writeIndent(out, indent) {
|
|
1570
|
+
for (let i = 0; i < indent; ++i)
|
|
1571
|
+
out.write(" ");
|
|
1572
|
+
}
|
|
1573
|
+
var FileType;
|
|
1574
|
+
(function (FileType) {
|
|
1575
|
+
FileType[FileType["NONE"] = 0] = "NONE";
|
|
1576
|
+
FileType[FileType["VALUE"] = 1] = "VALUE";
|
|
1577
|
+
FileType[FileType["VALUETYPE"] = 2] = "VALUETYPE";
|
|
1578
|
+
FileType[FileType["VALUEIMPL"] = 3] = "VALUEIMPL";
|
|
1579
|
+
FileType[FileType["INTERFACE"] = 4] = "INTERFACE";
|
|
1580
|
+
FileType[FileType["SKELETON"] = 5] = "SKELETON";
|
|
1581
|
+
FileType[FileType["STUB"] = 6] = "STUB";
|
|
1582
|
+
})(FileType || (FileType = {}));
|
|
1583
|
+
function typeIDLtoTS(type, filetype = FileType.NONE) {
|
|
1584
|
+
if (type === undefined)
|
|
1585
|
+
throw Error("internal error: parser delivered no type information");
|
|
1586
|
+
switch (type.type) {
|
|
1587
|
+
case Type.TKN_IDENTIFIER:
|
|
1588
|
+
{
|
|
1589
|
+
let identifierType = type.child[type.child.length - 1];
|
|
1590
|
+
let relativeName = "";
|
|
1591
|
+
for (let x of type.child) {
|
|
1592
|
+
relativeName = `${relativeName}.${x.text}`;
|
|
1593
|
+
}
|
|
1594
|
+
relativeName = relativeName.substring(1);
|
|
1595
|
+
let absolutePrefix = "";
|
|
1596
|
+
for (let x = type.child[0]?.typeParent; x; x = x.typeParent) {
|
|
1597
|
+
absolutePrefix = `.${x.text}${absolutePrefix}`;
|
|
1598
|
+
}
|
|
1599
|
+
if (type.child.length > 0 &&
|
|
1600
|
+
type.child[0].type === Type.TKN_NATIVE &&
|
|
1601
|
+
type.text.length > 4 &&
|
|
1602
|
+
type.text.substring(type.text.length - 4) === "_ptr") {
|
|
1603
|
+
return `${absolutePrefix.substring(1)} | undefined`;
|
|
1604
|
+
}
|
|
1605
|
+
let name;
|
|
1606
|
+
switch (identifierType.type) {
|
|
1607
|
+
case Type.TKN_VALUETYPE:
|
|
1608
|
+
if (filetype !== FileType.VALUETYPE && filetype !== FileType.VALUE)
|
|
1609
|
+
name = `valuetype${absolutePrefix}.${relativeName}`;
|
|
1610
|
+
else
|
|
1611
|
+
name = absolutePrefix.length == 0 ? relativeName : `${absolutePrefix.substring(1)}.${relativeName}`;
|
|
1612
|
+
break;
|
|
1613
|
+
case Type.SYN_INTERFACE:
|
|
1614
|
+
case Type.TKN_ENUM:
|
|
1615
|
+
if (filetype !== FileType.INTERFACE)
|
|
1616
|
+
name = `_interface${absolutePrefix}.${relativeName}`;
|
|
1617
|
+
else
|
|
1618
|
+
name = absolutePrefix.length == 0 ? relativeName : `${absolutePrefix.substring(1)}.${relativeName}`;
|
|
1619
|
+
break;
|
|
1620
|
+
case Type.TKN_STRUCT:
|
|
1621
|
+
name = type.text;
|
|
1622
|
+
if (filetype !== FileType.INTERFACE)
|
|
1623
|
+
name = `_interface${absolutePrefix}.${name}`;
|
|
1624
|
+
break;
|
|
1625
|
+
case Type.TKN_NATIVE:
|
|
1626
|
+
name = absolutePrefix.length == 0 ? relativeName : `${absolutePrefix.substring(1)}.${relativeName}`;
|
|
1627
|
+
break;
|
|
1628
|
+
case Type.TKN_SEQUENCE:
|
|
1629
|
+
name = typeIDLtoTS(type.child[0], filetype);
|
|
1630
|
+
break;
|
|
1631
|
+
default:
|
|
1632
|
+
throw Error(`Internal Error in typeIDLtoTS(): type ${identifierType.toString()} is not implemented`);
|
|
1633
|
+
}
|
|
1634
|
+
return name;
|
|
1635
|
+
}
|
|
1636
|
+
case Type.TKN_VOID:
|
|
1637
|
+
return "void";
|
|
1638
|
+
case Type.TKN_BOOLEAN:
|
|
1639
|
+
return "boolean";
|
|
1640
|
+
case Type.TKN_CHAR:
|
|
1641
|
+
case Type.TKN_STRING:
|
|
1642
|
+
return "string";
|
|
1643
|
+
case Type.TKN_OCTET:
|
|
1644
|
+
case Type.TKN_SHORT:
|
|
1645
|
+
case Type.TKN_LONG:
|
|
1646
|
+
case Type.SYN_UNSIGNED_SHORT:
|
|
1647
|
+
case Type.SYN_UNSIGNED_LONG:
|
|
1648
|
+
case Type.TKN_FLOAT:
|
|
1649
|
+
case Type.TKN_DOUBLE:
|
|
1650
|
+
case Type.SYN_LONG_DOUBLE:
|
|
1651
|
+
return "number";
|
|
1652
|
+
case Type.SYN_LONGLONG:
|
|
1653
|
+
case Type.SYN_UNSIGNED_LONGLONG:
|
|
1654
|
+
return "bigint";
|
|
1655
|
+
case Type.TKN_SEQUENCE:
|
|
1656
|
+
return `Array<${typeIDLtoTS(type.child[0], filetype)}>`;
|
|
1657
|
+
default:
|
|
1658
|
+
throw Error(`no mapping from IDL type to TS type for ${type.toString()}`);
|
|
1659
|
+
}
|
|
1660
|
+
}
|
|
1661
|
+
function typeIDLtoGIOP(type, arg = undefined) {
|
|
1662
|
+
if (type === undefined)
|
|
1663
|
+
throw Error("internal error: parser delivered no type information");
|
|
1664
|
+
let name;
|
|
1665
|
+
switch (type.type) {
|
|
1666
|
+
case Type.TKN_SEQUENCE:
|
|
1667
|
+
return arg === undefined ?
|
|
1668
|
+
`decoder.sequence(() => ${typeIDLtoGIOP(type.child[0])})` :
|
|
1669
|
+
`encoder.sequence(${arg}, (item) => ${typeIDLtoGIOP(type.child[0], "item")})`;
|
|
1670
|
+
case Type.TKN_IDENTIFIER:
|
|
1671
|
+
case Type.TKN_MODULE:
|
|
1672
|
+
return typeIDLtoGIOP(type.child[0], arg);
|
|
1673
|
+
case Type.TKN_VALUETYPE:
|
|
1674
|
+
return arg === undefined ? `decoder.value("${type.text}")` : `encoder.value(${arg})`;
|
|
1675
|
+
case Type.SYN_INTERFACE:
|
|
1676
|
+
case Type.TKN_STRUCT:
|
|
1677
|
+
name = "object";
|
|
1678
|
+
break;
|
|
1679
|
+
case Type.TKN_NATIVE:
|
|
1680
|
+
{
|
|
1681
|
+
const id = type.child[0].text;
|
|
1682
|
+
if (id.length > 4 && id.substring(id.length - 4) === "_ptr") {
|
|
1683
|
+
return arg === undefined ? `decoder.value("${id.substring(0, id.length - 4)}")` : `encoder.value(${arg})`;
|
|
1684
|
+
}
|
|
1685
|
+
else {
|
|
1686
|
+
return `undefined`;
|
|
1687
|
+
}
|
|
1688
|
+
}
|
|
1689
|
+
case Type.TKN_VOID:
|
|
1690
|
+
name = "void";
|
|
1691
|
+
break;
|
|
1692
|
+
case Type.TKN_BOOLEAN:
|
|
1693
|
+
name = "bool";
|
|
1694
|
+
break;
|
|
1695
|
+
case Type.TKN_STRING:
|
|
1696
|
+
name = "string";
|
|
1697
|
+
break;
|
|
1698
|
+
case Type.TKN_CHAR:
|
|
1699
|
+
name = "char";
|
|
1700
|
+
break;
|
|
1701
|
+
case Type.TKN_OCTET:
|
|
1702
|
+
name = "octet";
|
|
1703
|
+
break;
|
|
1704
|
+
case Type.TKN_SHORT:
|
|
1705
|
+
name = "short";
|
|
1706
|
+
break;
|
|
1707
|
+
case Type.TKN_LONG:
|
|
1708
|
+
name = "long";
|
|
1709
|
+
break;
|
|
1710
|
+
case Type.SYN_LONGLONG:
|
|
1711
|
+
name = "longlong";
|
|
1712
|
+
break;
|
|
1713
|
+
case Type.SYN_UNSIGNED_SHORT:
|
|
1714
|
+
name = "ushort";
|
|
1715
|
+
break;
|
|
1716
|
+
case Type.SYN_UNSIGNED_LONG:
|
|
1717
|
+
case Type.TKN_ENUM:
|
|
1718
|
+
name = "ulong";
|
|
1719
|
+
break;
|
|
1720
|
+
case Type.SYN_UNSIGNED_LONGLONG:
|
|
1721
|
+
name = "ulonglong";
|
|
1722
|
+
break;
|
|
1723
|
+
case Type.TKN_FLOAT:
|
|
1724
|
+
name = "float";
|
|
1725
|
+
break;
|
|
1726
|
+
case Type.TKN_DOUBLE:
|
|
1727
|
+
name = "double";
|
|
1728
|
+
break;
|
|
1729
|
+
case Type.SYN_LONG_DOUBLE:
|
|
1730
|
+
throw Error("long double is not supported yet");
|
|
1731
|
+
default:
|
|
1732
|
+
type.printTree();
|
|
1733
|
+
throw Error(`no mapping from IDL type '${type.toString()}' to GIOP encoder/decoder`);
|
|
1734
|
+
}
|
|
1735
|
+
return arg === undefined ? `decoder.${name}()` : `encoder.${name}(${arg})`;
|
|
1736
|
+
}
|
|
1737
|
+
function defaultValueIDLtoTS(type, filetype = FileType.NONE) {
|
|
1738
|
+
if (type === undefined)
|
|
1739
|
+
throw Error("internal error: parser delivered no type information");
|
|
1740
|
+
switch (type.type) {
|
|
1741
|
+
case Type.TKN_IDENTIFIER:
|
|
1742
|
+
return "new " + type.text + "()";
|
|
1743
|
+
case Type.TKN_BOOLEAN:
|
|
1744
|
+
return "false";
|
|
1745
|
+
case Type.TKN_CHAR:
|
|
1746
|
+
return "\"\0\"";
|
|
1747
|
+
case Type.TKN_STRING:
|
|
1748
|
+
return "\"\"";
|
|
1749
|
+
case Type.TKN_OCTET:
|
|
1750
|
+
case Type.TKN_SHORT:
|
|
1751
|
+
case Type.TKN_LONG:
|
|
1752
|
+
case Type.SYN_LONGLONG:
|
|
1753
|
+
case Type.SYN_UNSIGNED_SHORT:
|
|
1754
|
+
case Type.SYN_UNSIGNED_LONG:
|
|
1755
|
+
case Type.SYN_UNSIGNED_LONGLONG:
|
|
1756
|
+
case Type.TKN_FLOAT:
|
|
1757
|
+
case Type.TKN_DOUBLE:
|
|
1758
|
+
case Type.SYN_LONG_DOUBLE:
|
|
1759
|
+
return "0";
|
|
1760
|
+
case Type.TKN_SEQUENCE:
|
|
1761
|
+
return `new Array<${typeIDLtoTS(type.child[0], filetype)}>()`;
|
|
1762
|
+
default:
|
|
1763
|
+
throw Error(`no default value from IDL type '${type.toString()}' to default value`);
|
|
1764
|
+
}
|
|
1765
|
+
}
|
|
1766
|
+
function hasValueType(specification) {
|
|
1767
|
+
for (let definition of specification.child) {
|
|
1768
|
+
switch (definition.type) {
|
|
1769
|
+
case Type.TKN_VALUETYPE:
|
|
1770
|
+
return true;
|
|
1771
|
+
case Type.TKN_MODULE:
|
|
1772
|
+
if (hasValueType(definition))
|
|
1773
|
+
return true;
|
|
1774
|
+
}
|
|
1775
|
+
}
|
|
1776
|
+
return false;
|
|
1777
|
+
}
|
|
1778
|
+
function hasNative(specification) {
|
|
1779
|
+
for (let definition of specification.child) {
|
|
1780
|
+
if (definition.type === Type.TKN_NATIVE) {
|
|
1781
|
+
let native = definition;
|
|
1782
|
+
let nativeName = native.text;
|
|
1783
|
+
if (nativeName.length <= 4 ||
|
|
1784
|
+
nativeName.substring(nativeName.length - 4) !== "_ptr") {
|
|
1785
|
+
return true;
|
|
1786
|
+
}
|
|
1787
|
+
}
|
|
1788
|
+
}
|
|
1789
|
+
return false;
|
|
1790
|
+
}
|
|
1791
|
+
|
|
1792
|
+
function writeTSInterface(specification) {
|
|
1793
|
+
let out = fs__namespace.createWriteStream(filenamePrefix + ".ts");
|
|
1794
|
+
out.write("// This file is generated by the corba.js IDL compiler from '" + filename + "'.\n\n");
|
|
1795
|
+
if (hasValueType(specification)) {
|
|
1796
|
+
out.write("import * as valuetype from \"./" + filenameLocal + "_valuetype\"\n\n");
|
|
1797
|
+
}
|
|
1798
|
+
writeTSInterfaceDefinitions(out, specification);
|
|
1799
|
+
}
|
|
1800
|
+
function writeTSInterfaceDefinitions(out, specification, prefix = "", indent = 0) {
|
|
1801
|
+
for (let definition of specification.child) {
|
|
1802
|
+
switch (definition.type) {
|
|
1803
|
+
case Type.TKN_MODULE:
|
|
1804
|
+
out.write("export namespace " + definition.text + " {\n\n");
|
|
1805
|
+
writeTSInterfaceDefinitions(out, definition, prefix + definition.text + ".", indent + 1);
|
|
1806
|
+
out.write("} // namespace " + definition.text + "\n\n");
|
|
1807
|
+
break;
|
|
1808
|
+
case Type.SYN_INTERFACE:
|
|
1809
|
+
{
|
|
1810
|
+
let interface_dcl = definition;
|
|
1811
|
+
let identifier = interface_dcl.child[0].child[1].text;
|
|
1812
|
+
let interface_body = interface_dcl.child[1];
|
|
1813
|
+
out.write(`export interface ${identifier} {\n`);
|
|
1814
|
+
for (let _export of interface_body.child) {
|
|
1815
|
+
switch (_export.type) {
|
|
1816
|
+
case Type.SYN_OPERATION_DECLARATION:
|
|
1817
|
+
{
|
|
1818
|
+
let op_dcl = _export;
|
|
1819
|
+
let attribute = op_dcl.child[0];
|
|
1820
|
+
let type = op_dcl.child[1];
|
|
1821
|
+
let oneway = false;
|
|
1822
|
+
if (attribute !== undefined && attribute.type === Type.TKN_ONEWAY)
|
|
1823
|
+
oneway = true;
|
|
1824
|
+
if (oneway && type.type !== Type.TKN_VOID)
|
|
1825
|
+
throw Error("oneway methods must return void");
|
|
1826
|
+
let identifier = op_dcl.child[2].text;
|
|
1827
|
+
let parameter_decls = op_dcl.child[3].child;
|
|
1828
|
+
out.write(" ");
|
|
1829
|
+
out.write(identifier + "(");
|
|
1830
|
+
let comma = false;
|
|
1831
|
+
for (let parameter_dcl of parameter_decls) {
|
|
1832
|
+
let attribute = parameter_dcl.child[0].type;
|
|
1833
|
+
let type = parameter_dcl.child[1];
|
|
1834
|
+
let identifier = parameter_dcl.child[2].text;
|
|
1835
|
+
if (attribute !== Type.TKN_IN) {
|
|
1836
|
+
throw Error("corba.js currently only supports 'in' parameters");
|
|
1837
|
+
}
|
|
1838
|
+
if (!comma) {
|
|
1839
|
+
comma = true;
|
|
1840
|
+
}
|
|
1841
|
+
else {
|
|
1842
|
+
out.write(", ");
|
|
1843
|
+
}
|
|
1844
|
+
out.write(identifier + ": " + typeIDLtoTS(type, FileType.INTERFACE));
|
|
1845
|
+
}
|
|
1846
|
+
if (oneway) {
|
|
1847
|
+
out.write(`): ${typeIDLtoTS(type, FileType.INTERFACE)}\n`);
|
|
1848
|
+
}
|
|
1849
|
+
else {
|
|
1850
|
+
out.write(`): Promise<${typeIDLtoTS(type, FileType.INTERFACE)}>\n`);
|
|
1851
|
+
}
|
|
1852
|
+
}
|
|
1853
|
+
break;
|
|
1854
|
+
case Type.TKN_ATTRIBUTE:
|
|
1855
|
+
break;
|
|
1856
|
+
default:
|
|
1857
|
+
throw Error("fuck");
|
|
1858
|
+
}
|
|
1859
|
+
}
|
|
1860
|
+
out.write("}\n\n");
|
|
1861
|
+
}
|
|
1862
|
+
break;
|
|
1863
|
+
case Type.TKN_STRUCT:
|
|
1864
|
+
{
|
|
1865
|
+
const identifier = definition.text;
|
|
1866
|
+
writeIndent(out, indent);
|
|
1867
|
+
out.write(`export interface ${identifier} {\n`);
|
|
1868
|
+
const member_list = definition.child;
|
|
1869
|
+
for (const member of member_list) {
|
|
1870
|
+
const type_spec = member.child[0];
|
|
1871
|
+
const declarators = member.child[1];
|
|
1872
|
+
for (const declarator of declarators.child) {
|
|
1873
|
+
writeIndent(out, indent + 1);
|
|
1874
|
+
out.write(`${declarator.text}: ${typeIDLtoTS(type_spec, FileType.INTERFACE)}\n`);
|
|
1875
|
+
}
|
|
1876
|
+
}
|
|
1877
|
+
writeIndent(out, indent);
|
|
1878
|
+
out.write("}\n\n");
|
|
1879
|
+
}
|
|
1880
|
+
break;
|
|
1881
|
+
case Type.TKN_ENUM:
|
|
1882
|
+
{
|
|
1883
|
+
const identifier = definition.text;
|
|
1884
|
+
writeIndent(out, indent);
|
|
1885
|
+
out.write(`export enum ${identifier} {\n`);
|
|
1886
|
+
for (const enumerator of definition.child) {
|
|
1887
|
+
writeIndent(out, indent + 1);
|
|
1888
|
+
out.write(`${enumerator.text},\n`);
|
|
1889
|
+
}
|
|
1890
|
+
writeIndent(out, indent);
|
|
1891
|
+
out.write("}\n\n");
|
|
1892
|
+
}
|
|
1893
|
+
break;
|
|
1894
|
+
}
|
|
1895
|
+
}
|
|
1896
|
+
}
|
|
1897
|
+
|
|
1898
|
+
function writeTSSkeleton(specification) {
|
|
1899
|
+
let out = fs__namespace.createWriteStream(filenamePrefix + "_skel.ts");
|
|
1900
|
+
out.write("// This file is generated by the corba.js IDL compiler from '" + filename + "'.\n\n");
|
|
1901
|
+
out.write("import { ORB, Skeleton, GIOPEncoder, GIOPDecoder } from 'corba.js'\n");
|
|
1902
|
+
if (hasValueType(specification)) {
|
|
1903
|
+
out.write(`import * as valuetype from \"./${filenameLocal}_valuetype\"\n`);
|
|
1904
|
+
}
|
|
1905
|
+
out.write(`import * as _interface from \"./${filenameLocal}\"\n\n`);
|
|
1906
|
+
writeTSSkeletonDefinitions(out, specification);
|
|
1907
|
+
}
|
|
1908
|
+
function writeTSSkeletonDefinitions(out, specification, prefix = "", indent = 0) {
|
|
1909
|
+
for (let definition of specification.child) {
|
|
1910
|
+
switch (definition.type) {
|
|
1911
|
+
case Type.TKN_MODULE:
|
|
1912
|
+
out.write(`export namespace ${definition.text}{\n\n`);
|
|
1913
|
+
writeTSSkeletonDefinitions(out, definition, prefix + definition.text + ".", indent + 1);
|
|
1914
|
+
out.write(`} // namespace ${definition.text}\n\n`);
|
|
1915
|
+
break;
|
|
1916
|
+
case Type.SYN_INTERFACE:
|
|
1917
|
+
{
|
|
1918
|
+
let interface_dcl = definition;
|
|
1919
|
+
let identifier = interface_dcl.child[0].child[1].text;
|
|
1920
|
+
let interface_body = interface_dcl.child[1];
|
|
1921
|
+
out.write(`export abstract class ${identifier} extends Skeleton implements _interface.${prefix}${identifier} {\n`);
|
|
1922
|
+
out.write(` constructor(orb: ORB) { super(orb) }\n`);
|
|
1923
|
+
out.write(" static _idlClassName(): string {\n");
|
|
1924
|
+
out.write(` return "${prefix}${identifier}"\n`);
|
|
1925
|
+
out.write(" }\n\n");
|
|
1926
|
+
for (let _export of interface_body.child) {
|
|
1927
|
+
switch (_export.type) {
|
|
1928
|
+
case Type.SYN_OPERATION_DECLARATION:
|
|
1929
|
+
{
|
|
1930
|
+
let op_dcl = _export;
|
|
1931
|
+
let attribute = op_dcl.child[0];
|
|
1932
|
+
let type = op_dcl.child[1];
|
|
1933
|
+
let oneway = false;
|
|
1934
|
+
if (attribute !== undefined && attribute.type === Type.TKN_ONEWAY)
|
|
1935
|
+
oneway = true;
|
|
1936
|
+
if (oneway && type.type !== Type.TKN_VOID)
|
|
1937
|
+
throw Error("oneway methods must return void");
|
|
1938
|
+
let identifier = op_dcl.child[2].text;
|
|
1939
|
+
let parameter_decls = op_dcl.child[3].child;
|
|
1940
|
+
out.write(` abstract ${identifier}(`);
|
|
1941
|
+
let comma = false;
|
|
1942
|
+
for (let parameter_dcl of parameter_decls) {
|
|
1943
|
+
let attribute = parameter_dcl.child[0].type;
|
|
1944
|
+
let type = parameter_dcl.child[1];
|
|
1945
|
+
let identifier = parameter_dcl.child[2].text;
|
|
1946
|
+
if (attribute !== Type.TKN_IN) {
|
|
1947
|
+
throw Error("corba.js currently only supports 'in' parameters");
|
|
1948
|
+
}
|
|
1949
|
+
if (!comma) {
|
|
1950
|
+
comma = true;
|
|
1951
|
+
}
|
|
1952
|
+
else {
|
|
1953
|
+
out.write(", ");
|
|
1954
|
+
}
|
|
1955
|
+
out.write(`${identifier}: ${typeIDLtoTS(type, FileType.SKELETON)}`);
|
|
1956
|
+
}
|
|
1957
|
+
if (oneway)
|
|
1958
|
+
out.write(`): void\n`);
|
|
1959
|
+
else
|
|
1960
|
+
out.write(`): Promise<${typeIDLtoTS(type, FileType.SKELETON)}>\n`);
|
|
1961
|
+
out.write(` private async _orb_${identifier}(decoder: GIOPDecoder, encoder: GIOPEncoder) {\n`);
|
|
1962
|
+
switch (type.type) {
|
|
1963
|
+
case Type.TKN_VOID:
|
|
1964
|
+
if (oneway) {
|
|
1965
|
+
out.write(` this.${identifier}(`);
|
|
1966
|
+
}
|
|
1967
|
+
else {
|
|
1968
|
+
out.write(` await this.${identifier}(`);
|
|
1969
|
+
}
|
|
1970
|
+
break;
|
|
1971
|
+
default:
|
|
1972
|
+
out.write(` const result = await this.${identifier}(`);
|
|
1973
|
+
}
|
|
1974
|
+
comma = false;
|
|
1975
|
+
for (let parameter_dcl of parameter_decls) {
|
|
1976
|
+
let attribute = parameter_dcl.child[0].type;
|
|
1977
|
+
let type = parameter_dcl.child[1];
|
|
1978
|
+
if (attribute !== Type.TKN_IN) {
|
|
1979
|
+
throw Error("corba.js currently only supports 'in' parameters");
|
|
1980
|
+
}
|
|
1981
|
+
if (!comma) {
|
|
1982
|
+
comma = true;
|
|
1983
|
+
}
|
|
1984
|
+
else {
|
|
1985
|
+
out.write(", ");
|
|
1986
|
+
}
|
|
1987
|
+
out.write(`${typeIDLtoGIOP(type)}`);
|
|
1988
|
+
}
|
|
1989
|
+
out.write(`)\n`);
|
|
1990
|
+
if (type.type !== Type.TKN_VOID) {
|
|
1991
|
+
out.write(` ${typeIDLtoGIOP(type, "result")}\n`);
|
|
1992
|
+
}
|
|
1993
|
+
out.write(` }\n`);
|
|
1994
|
+
}
|
|
1995
|
+
break;
|
|
1996
|
+
case Type.TKN_ATTRIBUTE:
|
|
1997
|
+
break;
|
|
1998
|
+
default:
|
|
1999
|
+
throw Error("yikes");
|
|
2000
|
+
}
|
|
2001
|
+
}
|
|
2002
|
+
out.write("}\n\n");
|
|
2003
|
+
}
|
|
2004
|
+
break;
|
|
2005
|
+
}
|
|
2006
|
+
}
|
|
2007
|
+
}
|
|
2008
|
+
|
|
2009
|
+
function writeTSStub(specification) {
|
|
2010
|
+
let out = fs__namespace.createWriteStream(filenamePrefix + "_stub.ts");
|
|
2011
|
+
out.write("// This file is generated by the corba.js IDL compiler from '" + filename + "'.\n\n");
|
|
2012
|
+
out.write("import { ORB, Stub } from 'corba.js'\n");
|
|
2013
|
+
if (hasValueType(specification)) {
|
|
2014
|
+
out.write("import * as valuetype from \"./" + filenameLocal + "_valuetype\"\n");
|
|
2015
|
+
}
|
|
2016
|
+
out.write("import * as _interface from \"./" + filenameLocal + "\"\n\n");
|
|
2017
|
+
writeTSStubDefinitions(out, specification);
|
|
2018
|
+
}
|
|
2019
|
+
function writeTSStubDefinitions(out, specification, prefix = "", indent = 0) {
|
|
2020
|
+
for (let definition of specification.child) {
|
|
2021
|
+
switch (definition.type) {
|
|
2022
|
+
case Type.TKN_MODULE:
|
|
2023
|
+
out.write("export namespace " + definition.text + " {\n\n");
|
|
2024
|
+
writeTSStubDefinitions(out, definition, prefix + definition.text + ".", indent + 1);
|
|
2025
|
+
out.write("} // namespace " + definition.text + "\n\n");
|
|
2026
|
+
break;
|
|
2027
|
+
case Type.SYN_INTERFACE:
|
|
2028
|
+
{
|
|
2029
|
+
let interface_dcl = definition;
|
|
2030
|
+
let identifier = interface_dcl.child[0].child[1].text;
|
|
2031
|
+
let interface_body = interface_dcl.child[1];
|
|
2032
|
+
out.write(`export class ${identifier} extends Stub implements _interface.${prefix}${identifier} {\n`);
|
|
2033
|
+
out.write(` static _idlClassName(): string {\n`);
|
|
2034
|
+
out.write(` return "${prefix}${identifier}"\n`);
|
|
2035
|
+
out.write(` }\n\n`);
|
|
2036
|
+
out.write(` static narrow(object: any): ${prefix}${identifier} {\n`);
|
|
2037
|
+
out.write(` if (object instanceof ${prefix}${identifier})\n`);
|
|
2038
|
+
out.write(` return object as ${prefix}${identifier}\n`);
|
|
2039
|
+
out.write(` throw Error("${prefix}${identifier}.narrow() failed")\n`);
|
|
2040
|
+
out.write(` }\n\n`);
|
|
2041
|
+
for (let _export of interface_body.child) {
|
|
2042
|
+
switch (_export.type) {
|
|
2043
|
+
case Type.SYN_OPERATION_DECLARATION:
|
|
2044
|
+
{
|
|
2045
|
+
let op_dcl = _export;
|
|
2046
|
+
let attribute = op_dcl.child[0];
|
|
2047
|
+
let returnType = op_dcl.child[1];
|
|
2048
|
+
let oneway = false;
|
|
2049
|
+
if (attribute !== undefined && attribute.type === Type.TKN_ONEWAY)
|
|
2050
|
+
oneway = true;
|
|
2051
|
+
if (oneway && returnType.type !== Type.TKN_VOID)
|
|
2052
|
+
console.log("WARNING: corba.js currently requires every oneway function to return void");
|
|
2053
|
+
let identifier = op_dcl.child[2].text;
|
|
2054
|
+
let parameter_decls = op_dcl.child[3].child;
|
|
2055
|
+
out.write(" async ");
|
|
2056
|
+
out.write(identifier + "(");
|
|
2057
|
+
let comma = false;
|
|
2058
|
+
for (let parameter_dcl of parameter_decls) {
|
|
2059
|
+
let attribute = parameter_dcl.child[0].type;
|
|
2060
|
+
let type = parameter_dcl.child[1];
|
|
2061
|
+
let identifier = parameter_dcl.child[2].text;
|
|
2062
|
+
if (attribute !== Type.TKN_IN) {
|
|
2063
|
+
throw Error("corba.js currently only supports 'in' parameters");
|
|
2064
|
+
}
|
|
2065
|
+
if (!comma) {
|
|
2066
|
+
comma = true;
|
|
2067
|
+
}
|
|
2068
|
+
else {
|
|
2069
|
+
out.write(", ");
|
|
2070
|
+
}
|
|
2071
|
+
out.write(`${identifier}: ${typeIDLtoTS(type, FileType.STUB)}`);
|
|
2072
|
+
}
|
|
2073
|
+
out.write(`): Promise<${typeIDLtoTS(returnType, FileType.STUB)}> {\n`);
|
|
2074
|
+
out.write(" ");
|
|
2075
|
+
if (returnType.type !== Type.TKN_VOID)
|
|
2076
|
+
out.write("return ");
|
|
2077
|
+
if (!oneway)
|
|
2078
|
+
out.write("await ");
|
|
2079
|
+
if (oneway) {
|
|
2080
|
+
out.write(`this.orb.onewayCall(this, "${identifier}", `);
|
|
2081
|
+
}
|
|
2082
|
+
else {
|
|
2083
|
+
out.write(`this.orb.twowayCall(this, "${identifier}", `);
|
|
2084
|
+
}
|
|
2085
|
+
out.write(`(encoder) => {\n`);
|
|
2086
|
+
for (let parameter_dcl of parameter_decls) {
|
|
2087
|
+
let type = parameter_dcl.child[1];
|
|
2088
|
+
let identifier = parameter_dcl.child[2].text;
|
|
2089
|
+
out.write(` ${typeIDLtoGIOP(type, identifier)}\n`);
|
|
2090
|
+
}
|
|
2091
|
+
if (oneway) {
|
|
2092
|
+
out.write(` })\n`);
|
|
2093
|
+
}
|
|
2094
|
+
else {
|
|
2095
|
+
out.write(` },\n`);
|
|
2096
|
+
out.write(` `);
|
|
2097
|
+
if (returnType.type !== Type.TKN_VOID) {
|
|
2098
|
+
out.write(`(decoder) => ${typeIDLtoGIOP(returnType)})\n`);
|
|
2099
|
+
}
|
|
2100
|
+
else {
|
|
2101
|
+
out.write(`(decoder) => {})\n`);
|
|
2102
|
+
}
|
|
2103
|
+
}
|
|
2104
|
+
out.write(" }\n");
|
|
2105
|
+
}
|
|
2106
|
+
break;
|
|
2107
|
+
case Type.TKN_ATTRIBUTE:
|
|
2108
|
+
break;
|
|
2109
|
+
default:
|
|
2110
|
+
throw Error("yikes");
|
|
2111
|
+
}
|
|
2112
|
+
}
|
|
2113
|
+
out.write("}\n\n");
|
|
2114
|
+
}
|
|
2115
|
+
break;
|
|
2116
|
+
}
|
|
2117
|
+
}
|
|
2118
|
+
}
|
|
2119
|
+
|
|
2120
|
+
let initCalls = "";
|
|
2121
|
+
function writeTSValue(specification) {
|
|
2122
|
+
initCalls = "";
|
|
2123
|
+
let out = fs__namespace.createWriteStream(filenamePrefix + "_value.ts");
|
|
2124
|
+
out.write(`// This file is generated by the corba.js IDL compiler from '${filename}'.\n\n`);
|
|
2125
|
+
out.write(`import { ORB, GIOPDecoder, GIOPEncoder } from 'corba.js'\n`);
|
|
2126
|
+
if (!hasValueType(specification)) {
|
|
2127
|
+
out.write("// no valuetype's defined in IDL");
|
|
2128
|
+
return;
|
|
2129
|
+
}
|
|
2130
|
+
if (hasNative(specification)) {
|
|
2131
|
+
out.write("declare global {\n");
|
|
2132
|
+
for (let definition of specification.child) {
|
|
2133
|
+
if (definition.type === Type.TKN_NATIVE) {
|
|
2134
|
+
let native = definition;
|
|
2135
|
+
let nativeName = native.text;
|
|
2136
|
+
if (nativeName.length <= 4 ||
|
|
2137
|
+
nativeName.substring(nativeName.length - 4) !== "_ptr") {
|
|
2138
|
+
out.write(` interface ${nativeName} {}\n`);
|
|
2139
|
+
}
|
|
2140
|
+
}
|
|
2141
|
+
}
|
|
2142
|
+
out.write("}\n\n");
|
|
2143
|
+
}
|
|
2144
|
+
writeTSValueDefinitions(out, specification);
|
|
2145
|
+
out.write("let initialized = false\n");
|
|
2146
|
+
out.write("export function _init() {\n");
|
|
2147
|
+
out.write(" if (initialized)\n");
|
|
2148
|
+
out.write(" return\n");
|
|
2149
|
+
out.write(" initialized = true\n");
|
|
2150
|
+
out.write(initCalls);
|
|
2151
|
+
out.write("}\n");
|
|
2152
|
+
out.write("_init()\n");
|
|
2153
|
+
}
|
|
2154
|
+
function writeTSValueDefinitions(out, specification, prefix = "", indent = 0) {
|
|
2155
|
+
for (let definition of specification.child) {
|
|
2156
|
+
switch (definition.type) {
|
|
2157
|
+
case Type.TKN_MODULE:
|
|
2158
|
+
{
|
|
2159
|
+
writeIndent(out, indent);
|
|
2160
|
+
out.write(`export namespace ${definition.text} {\n\n`);
|
|
2161
|
+
writeTSValueDefinitions(out, definition, prefix + definition.text + ".", indent + 1);
|
|
2162
|
+
writeIndent(out, indent);
|
|
2163
|
+
out.write(`} // namespace ${definition.text}\n\n`);
|
|
2164
|
+
}
|
|
2165
|
+
break;
|
|
2166
|
+
case Type.TKN_NATIVE:
|
|
2167
|
+
break;
|
|
2168
|
+
case Type.TKN_VALUETYPE:
|
|
2169
|
+
{
|
|
2170
|
+
let value_dcl = definition;
|
|
2171
|
+
let value_header = value_dcl.child[0];
|
|
2172
|
+
value_header.child[0];
|
|
2173
|
+
let identifier = value_header.child[1].text;
|
|
2174
|
+
let inheritance_spec = value_header.child[2];
|
|
2175
|
+
writeIndent(out, indent);
|
|
2176
|
+
out.write(`export interface ${identifier}`);
|
|
2177
|
+
let attributes = new Array();
|
|
2178
|
+
classAttributes.set(prefix + identifier, attributes);
|
|
2179
|
+
if (inheritance_spec !== undefined) {
|
|
2180
|
+
if (inheritance_spec.child.length > 2)
|
|
2181
|
+
throw Error("multiple inheritance is not supported for TypeScript");
|
|
2182
|
+
out.write(` extends ${inheritance_spec.child[1].text}`);
|
|
2183
|
+
let superAttributes = classAttributes.get(prefix + inheritance_spec.child[1].text);
|
|
2184
|
+
if (superAttributes === undefined) {
|
|
2185
|
+
superAttributes = classAttributes.get(inheritance_spec.child[1].text);
|
|
2186
|
+
}
|
|
2187
|
+
if (superAttributes === undefined) {
|
|
2188
|
+
throw Error("failed to find attributes for super class");
|
|
2189
|
+
}
|
|
2190
|
+
for (let attribute of superAttributes) {
|
|
2191
|
+
attributes.push(attribute);
|
|
2192
|
+
}
|
|
2193
|
+
}
|
|
2194
|
+
out.write(" {\n");
|
|
2195
|
+
for (let i = 1; i < value_dcl.child.length; ++i) {
|
|
2196
|
+
let value_element = value_dcl.child[i];
|
|
2197
|
+
if (value_element.type === Type.SYN_STATE_MEMBER) {
|
|
2198
|
+
let state_member = value_element;
|
|
2199
|
+
state_member.child[0];
|
|
2200
|
+
let type = state_member.child[1];
|
|
2201
|
+
let declarators = state_member.child[2];
|
|
2202
|
+
for (let declarator of declarators.child) {
|
|
2203
|
+
writeIndent(out, indent + 1);
|
|
2204
|
+
out.write(declarator.text + ": " + typeIDLtoTS(type, FileType.VALUE) + "\n");
|
|
2205
|
+
attributes.push(declarator.text);
|
|
2206
|
+
}
|
|
2207
|
+
}
|
|
2208
|
+
}
|
|
2209
|
+
writeIndent(out, indent);
|
|
2210
|
+
out.write("}\n");
|
|
2211
|
+
writeIndent(out, indent);
|
|
2212
|
+
out.write(`export function init${identifier}(object: ${identifier}, init?: Partial<${identifier}> | GIOPDecoder) {\n`);
|
|
2213
|
+
++indent;
|
|
2214
|
+
writeIndent(out, indent);
|
|
2215
|
+
out.write(`if (init instanceof GIOPDecoder) {\n`);
|
|
2216
|
+
writeIndent(out, indent + 1);
|
|
2217
|
+
out.write(`const decoder = init\n`);
|
|
2218
|
+
writeTSInitValueFromGIOP(value_dcl, out, indent + 1);
|
|
2219
|
+
writeIndent(out, indent);
|
|
2220
|
+
out.write(`} else {\n`);
|
|
2221
|
+
writeTSInitValueFromPOJO(value_dcl, out, indent + 1);
|
|
2222
|
+
writeIndent(out, indent);
|
|
2223
|
+
out.write("}\n");
|
|
2224
|
+
--indent;
|
|
2225
|
+
writeIndent(out, indent);
|
|
2226
|
+
out.write("}\n");
|
|
2227
|
+
writeIndent(out, indent);
|
|
2228
|
+
out.write(`export function encode${identifier}(encoder: GIOPEncoder, obj: ${identifier}) {\n`);
|
|
2229
|
+
++indent;
|
|
2230
|
+
if (inheritance_spec !== undefined) {
|
|
2231
|
+
writeIndent(out, indent);
|
|
2232
|
+
out.write(`encode${inheritance_spec.child[1].text}(encoder, obj)\n`);
|
|
2233
|
+
}
|
|
2234
|
+
for (let i = 1; i < value_dcl.child.length; ++i) {
|
|
2235
|
+
let value_element = value_dcl.child[i];
|
|
2236
|
+
if (value_element.type === Type.SYN_STATE_MEMBER) {
|
|
2237
|
+
let state_member = value_element;
|
|
2238
|
+
state_member.child[0];
|
|
2239
|
+
let type = state_member.child[1];
|
|
2240
|
+
let declarators = state_member.child[2];
|
|
2241
|
+
for (let declarator of declarators.child) {
|
|
2242
|
+
writeIndent(out, indent);
|
|
2243
|
+
out.write(`${typeIDLtoGIOP(type, "obj." + declarator.text)}\n`);
|
|
2244
|
+
}
|
|
2245
|
+
}
|
|
2246
|
+
}
|
|
2247
|
+
--indent;
|
|
2248
|
+
writeIndent(out, indent);
|
|
2249
|
+
out.write("}\n\n");
|
|
2250
|
+
initCalls += ` ORB.valueTypeByName.set("${prefix}${identifier}", {attributes:[`;
|
|
2251
|
+
let comma = false;
|
|
2252
|
+
for (let attribute of attributes) {
|
|
2253
|
+
if (comma) {
|
|
2254
|
+
initCalls += ", ";
|
|
2255
|
+
}
|
|
2256
|
+
else {
|
|
2257
|
+
comma = true;
|
|
2258
|
+
}
|
|
2259
|
+
initCalls += `"${attribute}"`;
|
|
2260
|
+
}
|
|
2261
|
+
initCalls += `],encode:${prefix}encode${identifier}})\n`;
|
|
2262
|
+
}
|
|
2263
|
+
break;
|
|
2264
|
+
}
|
|
2265
|
+
}
|
|
2266
|
+
}
|
|
2267
|
+
function writeTSInitValueFromGIOP(value_dcl, out, indent) {
|
|
2268
|
+
for (let i = 1; i < value_dcl.child.length; ++i) {
|
|
2269
|
+
let value_element = value_dcl.child[i];
|
|
2270
|
+
if (value_element.type === Type.SYN_STATE_MEMBER) {
|
|
2271
|
+
let state_member = value_element;
|
|
2272
|
+
let type = state_member.child[1];
|
|
2273
|
+
let declarators = state_member.child[2];
|
|
2274
|
+
for (let declarator of declarators.child) {
|
|
2275
|
+
let decl_identifier = declarator.text;
|
|
2276
|
+
writeIndent(out, indent);
|
|
2277
|
+
out.write(`object.${decl_identifier} = ${typeIDLtoGIOP(type)}\n`);
|
|
2278
|
+
}
|
|
2279
|
+
}
|
|
2280
|
+
}
|
|
2281
|
+
}
|
|
2282
|
+
function writeTSInitValueFromPOJO(value_dcl, out, indent) {
|
|
2283
|
+
for (let i = 1; i < value_dcl.child.length; ++i) {
|
|
2284
|
+
let value_element = value_dcl.child[i];
|
|
2285
|
+
if (value_element.type === Type.SYN_STATE_MEMBER) {
|
|
2286
|
+
let state_member = value_element;
|
|
2287
|
+
state_member.child[0];
|
|
2288
|
+
let type = state_member.child[1];
|
|
2289
|
+
let declarators = state_member.child[2];
|
|
2290
|
+
for (let declarator of declarators.child) {
|
|
2291
|
+
let decl_identifier = declarator.text;
|
|
2292
|
+
writeIndent(out, indent);
|
|
2293
|
+
if (type.type === Type.TKN_IDENTIFIER) {
|
|
2294
|
+
if (type.child[0]?.type == Type.TKN_NATIVE &&
|
|
2295
|
+
type.text.length > 4 &&
|
|
2296
|
+
type.text.substring(type.text.length - 4) === "_ptr") {
|
|
2297
|
+
let name = typeIDLtoTS(type, FileType.VALUE);
|
|
2298
|
+
out.write(`if (init !== undefined && init.${decl_identifier} !== undefined) object.${decl_identifier} = new (ORB.lookupValueType("${name}"))(init.${decl_identifier})\n`);
|
|
2299
|
+
}
|
|
2300
|
+
else if (type.child[0]?.type == Type.TKN_SEQUENCE) {
|
|
2301
|
+
out.write(`object.${decl_identifier} = init?.${decl_identifier} instanceof Array ? init!.${decl_identifier} : []\n`);
|
|
2302
|
+
}
|
|
2303
|
+
else {
|
|
2304
|
+
let name = typeIDLtoTS(type, FileType.VALUE);
|
|
2305
|
+
out.write(`const vt${decl_identifier} = ORB.lookupValueType("${name}")\n`);
|
|
2306
|
+
writeIndent(out, indent);
|
|
2307
|
+
out.write(`object.${decl_identifier} = vt${decl_identifier}.prototype.isPrototypeOf(init?.${decl_identifier}) ? init!.${decl_identifier} : new (vt${decl_identifier})(init?.${decl_identifier})\n`);
|
|
2308
|
+
}
|
|
2309
|
+
}
|
|
2310
|
+
else {
|
|
2311
|
+
out.write(`object.${decl_identifier} = (init === undefined || init.${decl_identifier} === undefined) ? `);
|
|
2312
|
+
out.write(defaultValueIDLtoTS(type, FileType.VALUETYPE));
|
|
2313
|
+
out.write(` : init.${decl_identifier}\n`);
|
|
2314
|
+
}
|
|
2315
|
+
}
|
|
2316
|
+
}
|
|
2317
|
+
}
|
|
2318
|
+
}
|
|
2319
|
+
|
|
2320
|
+
function writeTSValueType(specification) {
|
|
2321
|
+
let out = fs__namespace.createWriteStream(filenamePrefix + "_valuetype.ts");
|
|
2322
|
+
out.write("// This file is generated by the corba.js IDL compiler from '" + filename + "'.\n\n");
|
|
2323
|
+
out.write("import { ORB } from 'corba.js'\n");
|
|
2324
|
+
if (!hasValueType(specification)) {
|
|
2325
|
+
out.write("// no valuetype's defined in IDL");
|
|
2326
|
+
return;
|
|
2327
|
+
}
|
|
2328
|
+
out.write(`import * as value from "./${filenameLocal}_value\"\n\n`);
|
|
2329
|
+
if (hasNative(specification)) {
|
|
2330
|
+
out.write("declare global {\n");
|
|
2331
|
+
for (let definition of specification.child) {
|
|
2332
|
+
if (definition.type === Type.TKN_NATIVE) {
|
|
2333
|
+
let native = definition;
|
|
2334
|
+
let nativeName = native.text;
|
|
2335
|
+
if (nativeName.length <= 4 ||
|
|
2336
|
+
nativeName.substring(nativeName.length - 4) !== "_ptr") {
|
|
2337
|
+
out.write(" interface " + nativeName + " {}\n");
|
|
2338
|
+
}
|
|
2339
|
+
}
|
|
2340
|
+
}
|
|
2341
|
+
out.write("}\n\n");
|
|
2342
|
+
}
|
|
2343
|
+
writeTSValueTypeDefinitions(out, specification);
|
|
2344
|
+
}
|
|
2345
|
+
function writeTSValueTypeDefinitions(out, specification, prefix = "", indent = 0) {
|
|
2346
|
+
for (let definition of specification.child) {
|
|
2347
|
+
switch (definition.type) {
|
|
2348
|
+
case Type.TKN_MODULE:
|
|
2349
|
+
{
|
|
2350
|
+
out.write(`export namespace ${definition.text} {\n\n`);
|
|
2351
|
+
writeTSValueTypeDefinitions(out, definition, prefix + definition.text + ".", indent + 1);
|
|
2352
|
+
out.write(`} // namespace ${definition.text}\n\n`);
|
|
2353
|
+
}
|
|
2354
|
+
break;
|
|
2355
|
+
case Type.TKN_NATIVE:
|
|
2356
|
+
break;
|
|
2357
|
+
case Type.TKN_VALUETYPE:
|
|
2358
|
+
{
|
|
2359
|
+
let value_dcl = definition;
|
|
2360
|
+
let value_header = value_dcl.child[0];
|
|
2361
|
+
value_header.child[0];
|
|
2362
|
+
let identifier = value_header.child[1].text;
|
|
2363
|
+
let inheritance_spec = value_header.child[2];
|
|
2364
|
+
writeIndent(out, indent);
|
|
2365
|
+
out.write(`export interface ${identifier} extends value.${prefix}${identifier}`);
|
|
2366
|
+
if (inheritance_spec !== undefined) {
|
|
2367
|
+
if (inheritance_spec.child.length > 2)
|
|
2368
|
+
throw Error("multiple inheritance is not supported for TypeScript");
|
|
2369
|
+
out.write(", " + inheritance_spec.child[1].text);
|
|
2370
|
+
}
|
|
2371
|
+
out.write(" {\n");
|
|
2372
|
+
for (let i = 1; i < value_dcl.child.length; ++i) {
|
|
2373
|
+
let value_element = value_dcl.child[i];
|
|
2374
|
+
if (value_element.type === Type.SYN_OPERATION_DECLARATION) {
|
|
2375
|
+
let op_decl = value_element;
|
|
2376
|
+
op_decl.child[0];
|
|
2377
|
+
let type = op_decl.child[1];
|
|
2378
|
+
let op_identifier = op_decl.child[2].text;
|
|
2379
|
+
let parameter_decls = op_decl.child[3].child;
|
|
2380
|
+
writeIndent(out, indent + 1);
|
|
2381
|
+
out.write(op_identifier + "(");
|
|
2382
|
+
let comma = false;
|
|
2383
|
+
for (let parameter_dcl of parameter_decls) {
|
|
2384
|
+
let attribute = parameter_dcl.child[0].type;
|
|
2385
|
+
let type = parameter_dcl.child[1];
|
|
2386
|
+
let param_identifier = parameter_dcl.child[2].text;
|
|
2387
|
+
if (attribute !== Type.TKN_IN) {
|
|
2388
|
+
throw Error("corba.js currently only supports 'in' parameters");
|
|
2389
|
+
}
|
|
2390
|
+
if (comma) {
|
|
2391
|
+
out.write(", ");
|
|
2392
|
+
}
|
|
2393
|
+
else {
|
|
2394
|
+
comma = true;
|
|
2395
|
+
}
|
|
2396
|
+
out.write(param_identifier);
|
|
2397
|
+
out.write(": ");
|
|
2398
|
+
out.write(typeIDLtoTS(type, FileType.VALUETYPE));
|
|
2399
|
+
}
|
|
2400
|
+
out.write("): ");
|
|
2401
|
+
out.write(typeIDLtoTS(type, FileType.VALUETYPE));
|
|
2402
|
+
out.write("\n");
|
|
2403
|
+
}
|
|
2404
|
+
}
|
|
2405
|
+
writeIndent(out, indent);
|
|
2406
|
+
out.write("}\n\n");
|
|
2407
|
+
}
|
|
2408
|
+
break;
|
|
2409
|
+
}
|
|
2410
|
+
}
|
|
2411
|
+
}
|
|
2412
|
+
|
|
2413
|
+
function writeTSValueImpl(specification) {
|
|
2414
|
+
let out = fs__namespace.createWriteStream(filenamePrefix + "_valueimpl.ts");
|
|
2415
|
+
out.write(`// This file is generated by the corba.js IDL compiler from '${filename}'.\n\n`);
|
|
2416
|
+
out.write("import { ORB } from 'corba.js'\n");
|
|
2417
|
+
if (!hasValueType(specification)) {
|
|
2418
|
+
out.write("// no valuetype's defined in IDL");
|
|
2419
|
+
return;
|
|
2420
|
+
}
|
|
2421
|
+
out.write(`import * as value from "./${filenameLocal}_value"\n\n`);
|
|
2422
|
+
out.write(`import * as valuetype from "./${filenameLocal}_valuetype"\n\n`);
|
|
2423
|
+
out.write(`import * as _interface from "./${filenameLocal}"\n\n`);
|
|
2424
|
+
if (hasNative(specification)) {
|
|
2425
|
+
out.write("declare global {\n");
|
|
2426
|
+
for (let definition of specification.child) {
|
|
2427
|
+
switch (definition.type) {
|
|
2428
|
+
case Type.TKN_NATIVE:
|
|
2429
|
+
{
|
|
2430
|
+
let native = definition;
|
|
2431
|
+
let nativeName = native.text;
|
|
2432
|
+
if (nativeName.length <= 4 ||
|
|
2433
|
+
nativeName.substring(nativeName.length - 4) !== "_ptr") {
|
|
2434
|
+
out.write(" interface " + nativeName + " {}\n");
|
|
2435
|
+
}
|
|
2436
|
+
}
|
|
2437
|
+
break;
|
|
2438
|
+
}
|
|
2439
|
+
}
|
|
2440
|
+
out.write("}\n\n");
|
|
2441
|
+
}
|
|
2442
|
+
writeTSValueImplDefinitions(out, specification);
|
|
2443
|
+
}
|
|
2444
|
+
function hasOperationDeclarations(value_dcl) {
|
|
2445
|
+
for (let i = 1; i < value_dcl.child.length; ++i) {
|
|
2446
|
+
let value_element = value_dcl.child[i];
|
|
2447
|
+
if (value_element.type === Type.SYN_OPERATION_DECLARATION) {
|
|
2448
|
+
return true;
|
|
2449
|
+
}
|
|
2450
|
+
}
|
|
2451
|
+
let value_header = value_dcl.child[0];
|
|
2452
|
+
let inheritance_spec = value_header.child[2];
|
|
2453
|
+
if (inheritance_spec !== undefined) {
|
|
2454
|
+
if (inheritance_spec.child[1].child[0].type === Type.TKN_VALUETYPE) {
|
|
2455
|
+
let value_dcl = inheritance_spec.child[1].child[0];
|
|
2456
|
+
if (hasOperationDeclarations(value_dcl)) {
|
|
2457
|
+
return true;
|
|
2458
|
+
}
|
|
2459
|
+
}
|
|
2460
|
+
}
|
|
2461
|
+
return false;
|
|
2462
|
+
}
|
|
2463
|
+
function writeTSValueImplDefinitions(out, specification, prefix = "", indent = 0) {
|
|
2464
|
+
for (let definition of specification.child) {
|
|
2465
|
+
switch (definition.type) {
|
|
2466
|
+
case Type.TKN_MODULE:
|
|
2467
|
+
{
|
|
2468
|
+
out.write("export namespace " + definition.text + " {\n\n");
|
|
2469
|
+
writeTSValueImplDefinitions(out, definition, prefix + definition.text + ".", indent + 1);
|
|
2470
|
+
out.write("} // namespace " + definition.text + "\n\n");
|
|
2471
|
+
}
|
|
2472
|
+
break;
|
|
2473
|
+
case Type.TKN_NATIVE:
|
|
2474
|
+
break;
|
|
2475
|
+
case Type.TKN_VALUETYPE:
|
|
2476
|
+
{
|
|
2477
|
+
let value_dcl = definition;
|
|
2478
|
+
let value_header = value_dcl.child[0];
|
|
2479
|
+
value_header.child[0];
|
|
2480
|
+
let identifier = value_header.child[1].text;
|
|
2481
|
+
let inheritance_spec = value_header.child[2];
|
|
2482
|
+
writeIndent(out, indent);
|
|
2483
|
+
out.write("export ");
|
|
2484
|
+
if (hasOperationDeclarations(value_dcl))
|
|
2485
|
+
out.write("abstract ");
|
|
2486
|
+
else if (inheritance_spec !== undefined) {
|
|
2487
|
+
if (inheritance_spec.child[1].child[0].type === Type.TKN_VALUETYPE) {
|
|
2488
|
+
let value_dcl = inheritance_spec.child[1].child[0];
|
|
2489
|
+
if (hasOperationDeclarations(value_dcl))
|
|
2490
|
+
out.write("abstract ");
|
|
2491
|
+
}
|
|
2492
|
+
}
|
|
2493
|
+
out.write("class " + identifier);
|
|
2494
|
+
if (inheritance_spec !== undefined) {
|
|
2495
|
+
if (inheritance_spec.child.length > 2)
|
|
2496
|
+
throw Error("multiple inheritance is not supported for TypeScript");
|
|
2497
|
+
out.write(" extends " + inheritance_spec.child[1].text);
|
|
2498
|
+
}
|
|
2499
|
+
out.write(` implements valuetype.${prefix}${identifier} {\n`);
|
|
2500
|
+
for (let i = 1; i < value_dcl.child.length; ++i) {
|
|
2501
|
+
let value_element = value_dcl.child[i];
|
|
2502
|
+
if (value_element.type === Type.SYN_STATE_MEMBER) {
|
|
2503
|
+
let state_member = value_element;
|
|
2504
|
+
state_member.child[0];
|
|
2505
|
+
let type = state_member.child[1];
|
|
2506
|
+
let declarators = state_member.child[2];
|
|
2507
|
+
for (let declarator of declarators.child) {
|
|
2508
|
+
writeIndent(out, indent + 1);
|
|
2509
|
+
out.write(declarator.text + "!: " + typeIDLtoTS(type, FileType.VALUETYPE) + "\n");
|
|
2510
|
+
}
|
|
2511
|
+
}
|
|
2512
|
+
}
|
|
2513
|
+
out.write("\n");
|
|
2514
|
+
writeIndent(out, indent + 1);
|
|
2515
|
+
out.write(`constructor(init?: Partial<value.${prefix}${identifier}>) {\n`);
|
|
2516
|
+
if (inheritance_spec) {
|
|
2517
|
+
writeIndent(out, indent + 2);
|
|
2518
|
+
out.write("super(init)\n");
|
|
2519
|
+
}
|
|
2520
|
+
writeIndent(out, indent + 2);
|
|
2521
|
+
out.write(`value.${prefix}init${identifier}(this, init)\n`);
|
|
2522
|
+
writeIndent(out, indent + 1);
|
|
2523
|
+
out.write("}\n");
|
|
2524
|
+
for (let i = 1; i < value_dcl.child.length; ++i) {
|
|
2525
|
+
let value_element = value_dcl.child[i];
|
|
2526
|
+
if (value_element.type === Type.SYN_OPERATION_DECLARATION) {
|
|
2527
|
+
let op_decl = value_element;
|
|
2528
|
+
op_decl.child[0];
|
|
2529
|
+
let type = op_decl.child[1];
|
|
2530
|
+
let op_identifier = op_decl.child[2].text;
|
|
2531
|
+
let parameter_decls = op_decl.child[3].child;
|
|
2532
|
+
writeIndent(out, indent + 1);
|
|
2533
|
+
out.write("abstract ");
|
|
2534
|
+
out.write(op_identifier + "(");
|
|
2535
|
+
let comma = false;
|
|
2536
|
+
for (let parameter_dcl of parameter_decls) {
|
|
2537
|
+
let attribute = parameter_dcl.child[0].type;
|
|
2538
|
+
let type = parameter_dcl.child[1];
|
|
2539
|
+
let param_identifier = parameter_dcl.child[2].text;
|
|
2540
|
+
if (attribute !== Type.TKN_IN) {
|
|
2541
|
+
throw Error("corba.js currently only supports 'in' parameters");
|
|
2542
|
+
}
|
|
2543
|
+
if (comma) {
|
|
2544
|
+
out.write(", ");
|
|
2545
|
+
}
|
|
2546
|
+
else {
|
|
2547
|
+
comma = true;
|
|
2548
|
+
}
|
|
2549
|
+
out.write(param_identifier);
|
|
2550
|
+
out.write(": ");
|
|
2551
|
+
out.write(typeIDLtoTS(type));
|
|
2552
|
+
}
|
|
2553
|
+
out.write("): ");
|
|
2554
|
+
out.write(typeIDLtoTS(type));
|
|
2555
|
+
out.write("\n");
|
|
2556
|
+
}
|
|
2557
|
+
}
|
|
2558
|
+
writeIndent(out, indent);
|
|
2559
|
+
out.write("}\n\n");
|
|
2560
|
+
}
|
|
2561
|
+
break;
|
|
2562
|
+
}
|
|
2563
|
+
}
|
|
2564
|
+
}
|
|
2565
|
+
|
|
2566
|
+
function printHelp() {
|
|
2567
|
+
console.log(`corba.js IDL compiler
|
|
2568
|
+
Copyright (C) 2018, 2020, 2021 Mark-André Hopf <mhopf@mark13.org>
|
|
2569
|
+
This is free software; see the source for copying conditions. There is
|
|
2570
|
+
ABSOLUTELY NO WARRANTY; not even for MERCHANTABILITY or FITNESS FOR A
|
|
2571
|
+
PARTICULAR PURPOSE.
|
|
2572
|
+
|
|
2573
|
+
Usage: corba-idl [options] file...
|
|
2574
|
+
Options:
|
|
2575
|
+
--ts-all create all TypeScript files
|
|
2576
|
+
--ts-interface create TypeScript interface file for stub and skeleton
|
|
2577
|
+
--ts-stub create TypeScript stub file
|
|
2578
|
+
--ts-skeleton create TypeScript skeleton file
|
|
2579
|
+
--ts-valuetype create TypeScript valuetype file
|
|
2580
|
+
--verbose|-v increase verbosity level
|
|
2581
|
+
--output-directory|-o <dir>
|
|
2582
|
+
create files in <dir>
|
|
2583
|
+
--help|-h this page
|
|
2584
|
+
`);
|
|
2585
|
+
}
|
|
2586
|
+
let verbose = 0, outputDirectory, tsInterface = false, tsStub = false, tsSkeleton = false, tsValueType = false, tsValueImpl = false;
|
|
2587
|
+
function main() {
|
|
2588
|
+
let i = parseArguments();
|
|
2589
|
+
for (; i < process.argv.length; ++i) {
|
|
2590
|
+
setupFilenameVars(process.argv[i]);
|
|
2591
|
+
let syntaxTree = parseIDLFile();
|
|
2592
|
+
if (verbose > 1)
|
|
2593
|
+
syntaxTree.printTree();
|
|
2594
|
+
createOutputFiles(syntaxTree);
|
|
2595
|
+
}
|
|
2596
|
+
}
|
|
2597
|
+
main();
|
|
2598
|
+
function parseArguments() {
|
|
2599
|
+
let i;
|
|
2600
|
+
argloop: for (i = 2; i < process.argv.length; ++i) {
|
|
2601
|
+
switch (process.argv[i]) {
|
|
2602
|
+
case "--":
|
|
2603
|
+
++i;
|
|
2604
|
+
break argloop;
|
|
2605
|
+
case "--ts-all":
|
|
2606
|
+
tsInterface = tsStub = tsSkeleton = tsValueType = true;
|
|
2607
|
+
break;
|
|
2608
|
+
case "--ts-interface":
|
|
2609
|
+
tsInterface = true;
|
|
2610
|
+
break;
|
|
2611
|
+
case "--ts-stub":
|
|
2612
|
+
tsStub = true;
|
|
2613
|
+
break;
|
|
2614
|
+
case "--ts-skeleton":
|
|
2615
|
+
tsSkeleton = true;
|
|
2616
|
+
break;
|
|
2617
|
+
case "--ts-valuetype":
|
|
2618
|
+
tsValueType = true;
|
|
2619
|
+
break;
|
|
2620
|
+
case "--output-directory":
|
|
2621
|
+
case "-o":
|
|
2622
|
+
outputDirectory = process.argv[++i];
|
|
2623
|
+
break;
|
|
2624
|
+
case "--verbose":
|
|
2625
|
+
case "-v":
|
|
2626
|
+
++verbose;
|
|
2627
|
+
break;
|
|
2628
|
+
case "--help":
|
|
2629
|
+
case "-h":
|
|
2630
|
+
printHelp();
|
|
2631
|
+
process.exit(0);
|
|
2632
|
+
default:
|
|
2633
|
+
if (process.argv[i].length > 0 && process.argv[i].charAt(0) == "-") {
|
|
2634
|
+
console.log(`corba-idl: error: unrecognized command line option '${process.argv[i]}'`);
|
|
2635
|
+
process.exit(1);
|
|
2636
|
+
}
|
|
2637
|
+
break argloop;
|
|
2638
|
+
}
|
|
2639
|
+
}
|
|
2640
|
+
if (i === process.argv.length) {
|
|
2641
|
+
console.log("corba-idl: no input files");
|
|
2642
|
+
process.exit(1);
|
|
2643
|
+
}
|
|
2644
|
+
return i;
|
|
2645
|
+
}
|
|
2646
|
+
function setupFilenameVars(idlFilename) {
|
|
2647
|
+
setFilename(idlFilename);
|
|
2648
|
+
let n;
|
|
2649
|
+
n = filename.lastIndexOf(".");
|
|
2650
|
+
if (n === -1) {
|
|
2651
|
+
console.log(`corba-idl: error: filename '${filename}' must at least contain one dot ('.')`);
|
|
2652
|
+
process.exit(1);
|
|
2653
|
+
}
|
|
2654
|
+
if (outputDirectory) {
|
|
2655
|
+
fs__namespace.mkdirSync(outputDirectory, { recursive: true });
|
|
2656
|
+
if (outputDirectory.charAt(outputDirectory.length - 1) !== "/")
|
|
2657
|
+
outputDirectory += "/";
|
|
2658
|
+
let noSuffix = filename.substr(0, n);
|
|
2659
|
+
n = noSuffix.lastIndexOf("/");
|
|
2660
|
+
if (n === -1)
|
|
2661
|
+
setFilenamePrefix(outputDirectory + noSuffix);
|
|
2662
|
+
else
|
|
2663
|
+
setFilenamePrefix(outputDirectory + noSuffix.substr(n + 1));
|
|
2664
|
+
}
|
|
2665
|
+
else {
|
|
2666
|
+
setFilenamePrefix(filename.substr(0, n));
|
|
2667
|
+
}
|
|
2668
|
+
n = filenamePrefix.lastIndexOf("/");
|
|
2669
|
+
if (n === -1)
|
|
2670
|
+
setFilenameLocal(filenamePrefix);
|
|
2671
|
+
else
|
|
2672
|
+
setFilenameLocal(filenamePrefix.substr(n + 1));
|
|
2673
|
+
}
|
|
2674
|
+
function parseIDLFile() {
|
|
2675
|
+
let filedata;
|
|
2676
|
+
try {
|
|
2677
|
+
filedata = fs__namespace.readFileSync(filename, "utf8");
|
|
2678
|
+
}
|
|
2679
|
+
catch (error) {
|
|
2680
|
+
if (error instanceof Error)
|
|
2681
|
+
console.log(`corba-idl: error: failed to read file '${filename}': ${error.message}`);
|
|
2682
|
+
else
|
|
2683
|
+
console.log(error);
|
|
2684
|
+
process.exit(1);
|
|
2685
|
+
}
|
|
2686
|
+
let lexer = new Lexer(filedata);
|
|
2687
|
+
let syntaxTree;
|
|
2688
|
+
try {
|
|
2689
|
+
syntaxTree = specification(lexer);
|
|
2690
|
+
}
|
|
2691
|
+
catch (error) {
|
|
2692
|
+
if (error instanceof Error) {
|
|
2693
|
+
console.log(`corba-idl: error: ${error.message} in file '${filename}' at line ${lexer.line}, column ${lexer.column}`);
|
|
2694
|
+
if (verbose)
|
|
2695
|
+
console.log(error.stack);
|
|
2696
|
+
}
|
|
2697
|
+
else {
|
|
2698
|
+
console.log(error);
|
|
2699
|
+
}
|
|
2700
|
+
process.exit(1);
|
|
2701
|
+
}
|
|
2702
|
+
if (syntaxTree === undefined) {
|
|
2703
|
+
console.log("corba-idl: error: empty file or unexpected internal failure");
|
|
2704
|
+
process.exit(1);
|
|
2705
|
+
}
|
|
2706
|
+
return syntaxTree;
|
|
2707
|
+
}
|
|
2708
|
+
function createOutputFiles(syntaxTree) {
|
|
2709
|
+
try {
|
|
2710
|
+
if (tsInterface)
|
|
2711
|
+
writeTSInterface(syntaxTree);
|
|
2712
|
+
if (tsSkeleton)
|
|
2713
|
+
writeTSSkeleton(syntaxTree);
|
|
2714
|
+
if (tsStub)
|
|
2715
|
+
writeTSStub(syntaxTree);
|
|
2716
|
+
if (tsValueType) {
|
|
2717
|
+
writeTSValue(syntaxTree);
|
|
2718
|
+
writeTSValueType(syntaxTree);
|
|
2719
|
+
}
|
|
2720
|
+
if (tsValueImpl)
|
|
2721
|
+
;
|
|
2722
|
+
}
|
|
2723
|
+
catch (error) {
|
|
2724
|
+
if (error instanceof Error) {
|
|
2725
|
+
console.log(`corba-idl: error: ${error.message} in file '${filename}'`);
|
|
2726
|
+
if (verbose)
|
|
2727
|
+
console.log(error.stack);
|
|
2728
|
+
}
|
|
2729
|
+
else {
|
|
2730
|
+
console.log(error);
|
|
2731
|
+
}
|
|
2732
|
+
process.exit(1);
|
|
2733
|
+
}
|
|
2734
|
+
}
|
|
2735
|
+
//# sourceMappingURL=idl.cjs.map
|