corba.js 0.1.17 → 0.1.19

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 CHANGED
@@ -557,8 +557,9 @@ function interface_dcl() {
557
557
  }
558
558
  function interface_header() {
559
559
  let t0 = lexer.lex();
560
- if (t0 === undefined)
560
+ if (t0 === undefined) {
561
561
  return undefined;
562
+ }
562
563
  let t1;
563
564
  if (t0.type !== Type.TKN_ABSTRACT && t0.type !== Type.TKN_LOCAL) {
564
565
  t1 = t0;
@@ -577,12 +578,14 @@ function interface_header() {
577
578
  return undefined;
578
579
  }
579
580
  let t2 = identifier();
580
- if (t2 === undefined)
581
+ if (t2 === undefined) {
581
582
  throw Error("expected identifier after 'interface'");
583
+ }
584
+ let t3 = interface_inheritance_spec();
582
585
  let header = new Node(Type.SYN_INTERFACE_HEADER);
583
586
  header.append(t0);
584
587
  header.append(t2);
585
- header.append(undefined);
588
+ header.append(t3);
586
589
  return header;
587
590
  }
588
591
  function interface_body() {
@@ -603,11 +606,37 @@ function _export() {
603
606
  expect(';');
604
607
  return t0;
605
608
  }
609
+ function interface_inheritance_spec() {
610
+ let token = lexer.lex();
611
+ if (token === undefined) {
612
+ return undefined;
613
+ }
614
+ if (token.type !== Type.TKN_TEXT || token.text !== ':') {
615
+ lexer.unlex(token);
616
+ return undefined;
617
+ }
618
+ const id = identifier();
619
+ if (id === undefined) {
620
+ throw Error("expected identifier naming the super class after ':'");
621
+ }
622
+ token = lexer.lex();
623
+ if (token !== undefined && token.type === Type.TKN_TEXT && token.text === ",") {
624
+ throw Error("multiple inheritance is not implemented in corba.js");
625
+ }
626
+ lexer.unlex(token);
627
+ const n = scoper.getType(id.text);
628
+ if (n === undefined) {
629
+ throw Error(`undefined interface ${id.text}`);
630
+ }
631
+ id.append(n);
632
+ return id;
633
+ }
606
634
  function scoped_name() {
607
635
  let globalNamespaceToken = undefined;
608
636
  let identifierToken = lexer.lex();
609
- if (identifierToken === undefined)
637
+ if (identifierToken === undefined) {
610
638
  return undefined;
639
+ }
611
640
  if (identifierToken.type === Type.TKN_COLON_COLON) {
612
641
  globalNamespaceToken = identifierToken;
613
642
  identifierToken = lexer.lex();
@@ -1572,23 +1601,28 @@ function attr_declarator() {
1572
1601
  return node;
1573
1602
  }
1574
1603
  t0 = simple_declarator();
1575
- if (t0 === undefined)
1604
+ if (t0 === undefined) {
1576
1605
  throw Error("expected another declarator after ','");
1606
+ }
1577
1607
  }
1578
1608
  }
1579
1609
  function identifier() {
1580
1610
  let t0 = lexer.lex();
1581
- if (t0 !== undefined && t0.type === Type.TKN_IDENTIFIER)
1611
+ if (t0 !== undefined && t0.type === Type.TKN_IDENTIFIER) {
1582
1612
  return t0;
1613
+ }
1583
1614
  lexer.unlex(t0);
1584
1615
  return undefined;
1585
1616
  }
1586
1617
  function expect(text, customMessage) {
1587
1618
  let t0 = lexer.lex();
1588
1619
  let errorMessage;
1589
- errorMessage = `expected '${text}' but got '${t0?.toString()}'`;
1590
- if (t0 === undefined)
1620
+ {
1621
+ errorMessage = `expected '${text}' but got '${t0?.toString()}'`;
1622
+ }
1623
+ if (t0 === undefined) {
1591
1624
  throw Error(errorMessage + " but found end of file");
1625
+ }
1592
1626
  if (t0.type !== Type.TKN_TEXT || t0.text !== text) {
1593
1627
  throw Error(errorMessage);
1594
1628
  }
@@ -1968,8 +2002,13 @@ function writeTSInterfaceDefinitions(out, specification, prefix = "", indent = 0
1968
2002
  {
1969
2003
  let interface_dcl = definition;
1970
2004
  let identifier = interface_dcl.child[0].child[1].text;
2005
+ let inheritance_spec = interface_dcl.child[0].child[2]?.text;
1971
2006
  let interface_body = interface_dcl.child[1];
1972
- out.write(`export interface ${identifier} {\n`);
2007
+ out.write(`export interface ${identifier}`);
2008
+ if (inheritance_spec) {
2009
+ out.write(` extends ${inheritance_spec}`);
2010
+ }
2011
+ out.write(` {\n`);
1973
2012
  for (let _export of interface_body.child) {
1974
2013
  switch (_export.type) {
1975
2014
  case Type.SYN_OPERATION_DECLARATION:
@@ -2045,7 +2084,7 @@ function writeTSInterfaceDefinitions(out, specification, prefix = "", indent = 0
2045
2084
  let declarators = member.child[1];
2046
2085
  for (let declarator of declarators.child) {
2047
2086
  writeIndent(out, indent + 1);
2048
- out.write(declarator.text + ": " + typeIDLtoTS(type, FileType.VALUE) + "\n");
2087
+ out.write(declarator.text + ": " + typeIDLtoTS(type, FileType.INTERFACE) + "\n");
2049
2088
  }
2050
2089
  }
2051
2090
  }
@@ -2189,10 +2228,11 @@ function writeTSSkeletonDefinitions(out, specification, prefix = "", indent = 0)
2189
2228
  {
2190
2229
  let interface_dcl = definition;
2191
2230
  let identifier = interface_dcl.child[0].child[1].text;
2231
+ let inheritance_spec = interface_dcl.child[0].child[2]?.text;
2192
2232
  let interface_body = interface_dcl.child[1];
2193
- out.write(`export abstract class ${identifier} extends Skeleton implements _interface.${prefix}${identifier} {\n`);
2233
+ out.write(`export abstract class ${identifier} extends ${inheritance_spec ? inheritance_spec : "Skeleton"} implements _interface.${prefix}${identifier} {\n`);
2194
2234
  out.write(` constructor(orb: ORB) { super(orb) }\n`);
2195
- out.write(" static _idlClassName(): string {\n");
2235
+ out.write(` static ${inheritance_spec ? "override " : ""}_idlClassName(): string {\n`);
2196
2236
  out.write(` return "${prefix}${identifier}"\n`);
2197
2237
  out.write(" }\n\n");
2198
2238
  for (let _export of interface_body.child) {
@@ -2270,7 +2310,7 @@ function writeTSSkeletonDefinitions(out, specification, prefix = "", indent = 0)
2270
2310
  const readonly = _export.child[0]?.type == Type.TKN_READONLY;
2271
2311
  const param_type_spec = _export.child[1];
2272
2312
  const attr_declarator = _export.child[2];
2273
- const type = typeIDLtoTS(param_type_spec, FileType.INTERFACE);
2313
+ const type = typeIDLtoTS(param_type_spec, FileType.SKELETON);
2274
2314
  for (const n of attr_declarator.child) {
2275
2315
  const identifier = n.text;
2276
2316
  out.write(` abstract ${identifier}(): Promise<${type}>\n`);
@@ -2320,12 +2360,13 @@ function writeTSStubDefinitions(out, specification, prefix = "", indent = 0) {
2320
2360
  {
2321
2361
  let interface_dcl = definition;
2322
2362
  let identifier = interface_dcl.child[0].child[1].text;
2363
+ let inheritance_spec = interface_dcl.child[0].child[2]?.text;
2323
2364
  let interface_body = interface_dcl.child[1];
2324
- out.write(`export class ${identifier} extends Stub implements _interface.${prefix}${identifier} {\n`);
2325
- out.write(` static _idlClassName(): string {\n`);
2365
+ out.write(`export class ${identifier} extends ${inheritance_spec ? inheritance_spec : "Stub"} implements _interface.${prefix}${identifier} {\n`);
2366
+ out.write(` static ${inheritance_spec ? "override " : ""}_idlClassName(): string {\n`);
2326
2367
  out.write(` return "${prefix}${identifier}"\n`);
2327
2368
  out.write(` }\n\n`);
2328
- out.write(` static narrow(object: any): ${prefix}${identifier} {\n`);
2369
+ out.write(` static ${inheritance_spec ? "override " : ""}narrow(object: any): ${prefix}${identifier} {\n`);
2329
2370
  out.write(` if (object instanceof ${prefix}${identifier})\n`);
2330
2371
  out.write(` return object as ${prefix}${identifier}\n`);
2331
2372
  out.write(` throw Error("${prefix}${identifier}.narrow() failed")\n`);
@@ -2403,27 +2444,27 @@ function writeTSStubDefinitions(out, specification, prefix = "", indent = 0) {
2403
2444
  const attr_declarator = _export.child[2];
2404
2445
  for (const n of attr_declarator.child) {
2405
2446
  const identifier = n.text;
2406
- const type = typeIDLtoTS(param_type_spec, FileType.INTERFACE);
2447
+ const type = typeIDLtoTS(param_type_spec, FileType.STUB);
2407
2448
  if (readonly) {
2408
2449
  out.write(` async ${identifier}(): Promise<${type}> {\n`);
2409
2450
  out.write(` return this._orb.twowayCall(this, "_get_${identifier}",\n`);
2410
2451
  out.write(` (encoder) => { },\n`);
2411
- out.write(` (decoder) => decoder.string()\n`);
2452
+ out.write(` (decoder) => ${typeIDLtoGIOPTS(param_type_spec)}\n`);
2412
2453
  out.write(` )\n`);
2413
2454
  out.write(` }\n`);
2414
2455
  }
2415
2456
  else {
2416
2457
  out.write(` async ${identifier}(): Promise<${type}>\n`);
2417
2458
  out.write(` async ${identifier}(value: ${type}): Promise<void>\n`);
2418
- out.write(` async ${identifier}(value?: ${type}): Promise<void | ${type}> {\n`);
2419
- out.write(` if (value === undefined) {\n`);
2459
+ out.write(` async ${identifier}(...args: any[]): Promise<void | ${type}> {\n`);
2460
+ out.write(` if (args.length === 0) {\n`);
2420
2461
  out.write(` return this._orb.twowayCall(this, "_get_${identifier}",\n`);
2421
2462
  out.write(` (encoder) => { },\n`);
2422
- out.write(` (decoder) => decoder.string()\n`);
2463
+ out.write(` (decoder) => ${typeIDLtoGIOPTS(param_type_spec)}\n`);
2423
2464
  out.write(` )\n`);
2424
2465
  out.write(` } else {\n`);
2425
2466
  out.write(` return this._orb.twowayCall(this, "_set_${identifier}",\n`);
2426
- out.write(` (encoder) => { encoder.string(value) },\n`);
2467
+ out.write(` (encoder) => {${typeIDLtoGIOPTS(param_type_spec, "args[0]")}},\n`);
2427
2468
  out.write(` (decoder) => { }\n`);
2428
2469
  out.write(` )\n`);
2429
2470
  out.write(` }\n`);
@@ -3193,70 +3234,13 @@ function writeCCInterfaceDefinitions(out, specification, prefix = "", indent = 0
3193
3234
  {
3194
3235
  let interface_dcl = definition;
3195
3236
  let identifier = interface_dcl.child[0].child[1].text;
3237
+ let inheritance_spec = interface_dcl.child[0].child[2]?.text;
3196
3238
  let interface_body = interface_dcl.child[1];
3197
- out.write(`class ${identifier}: public virtual CORBA::Object {\n`);
3198
- out.write(` static std::string_view _rid;\n`);
3239
+ out.write(`class ${identifier}: public virtual ${inheritance_spec ? inheritance_spec : "CORBA::Object"} {\n`);
3199
3240
  out.write(`public:\n`);
3200
- for (let _export of interface_body.child) {
3201
- switch (_export.type) {
3202
- case Type.SYN_OPERATION_DECLARATION:
3203
- {
3204
- let op_dcl = _export;
3205
- let attribute = op_dcl.child[0];
3206
- let type = op_dcl.child[1];
3207
- let oneway = false;
3208
- if (attribute !== undefined && attribute.type === Type.TKN_ONEWAY)
3209
- oneway = true;
3210
- if (oneway && type.type !== Type.TKN_VOID)
3211
- throw Error("oneway methods must return void");
3212
- let identifier = op_dcl.child[2].text;
3213
- let parameter_decls = op_dcl.child[3].child;
3214
- out.write(" virtual ");
3215
- if (oneway) {
3216
- out.write(`${typeIDLtoCC(type, Direction.OUT)}`);
3217
- }
3218
- else {
3219
- out.write(`CORBA::async<${typeIDLtoCC(type, Direction.OUT)}>`);
3220
- }
3221
- out.write(` ${identifier}(`);
3222
- let comma = false;
3223
- for (let parameter_dcl of parameter_decls) {
3224
- let attribute = parameter_dcl.child[0].type;
3225
- let type = parameter_dcl.child[1];
3226
- let identifier = parameter_dcl.child[2].text;
3227
- if (attribute !== Type.TKN_IN) {
3228
- throw Error("corba.js currently only supports 'in' parameters");
3229
- }
3230
- if (!comma) {
3231
- comma = true;
3232
- }
3233
- else {
3234
- out.write(", ");
3235
- }
3236
- out.write(`${typeIDLtoCC(type, Direction.IN)} ${identifier}`);
3237
- }
3238
- out.write(`) = 0;\n`);
3239
- }
3240
- break;
3241
- case Type.TKN_ATTRIBUTE:
3242
- {
3243
- const readonly = _export.child[0]?.type == Type.TKN_READONLY;
3244
- const param_type_spec = _export.child[1];
3245
- const attr_declarator = _export.child[2];
3246
- for (const n of attr_declarator.child) {
3247
- const identifier = n.text;
3248
- out.write(` virtual CORBA::async<${typeIDLtoCC(param_type_spec, Direction.OUT)}> ${identifier}() = 0;\n`);
3249
- if (!readonly) {
3250
- out.write(` virtual CORBA::async<void> ${identifier}(${typeIDLtoCC(param_type_spec, Direction.IN)}) = 0;\n`);
3251
- }
3252
- }
3253
- }
3254
- break;
3255
- default:
3256
- throw Error("yikes");
3257
- }
3258
- }
3241
+ writeCCInterfaceBody(out, interface_body);
3259
3242
  out.write(` std::string_view repository_id() const override;\n`);
3243
+ out.write(` bool _is_a(const std::string_view &repository_id) const override;\n`);
3260
3244
  out.write(` static std::shared_ptr<${identifier}> _narrow(std::shared_ptr<CORBA::Object> pointer);\n`);
3261
3245
  out.write("};\n\n");
3262
3246
  }
@@ -3274,7 +3258,7 @@ function writeCCInterfaceDefinitions(out, specification, prefix = "", indent = 0
3274
3258
  let declarators = member.child[1];
3275
3259
  for (let declarator of declarators.child) {
3276
3260
  writeIndent(out, indent + 1);
3277
- out.write(typeIDLtoCC(type, Direction.IN) + " " + declarator.text + ";\n");
3261
+ out.write(typeIDLtoCC(type, Direction.OUT) + " " + declarator.text + ";\n");
3278
3262
  }
3279
3263
  }
3280
3264
  }
@@ -3367,6 +3351,67 @@ function writeCCInterfaceDefinitions(out, specification, prefix = "", indent = 0
3367
3351
  }
3368
3352
  }
3369
3353
  }
3354
+ function writeCCInterfaceBody(out, interface_body) {
3355
+ for (let _export of interface_body.child) {
3356
+ switch (_export.type) {
3357
+ case Type.SYN_OPERATION_DECLARATION:
3358
+ {
3359
+ let op_dcl = _export;
3360
+ let attribute = op_dcl.child[0];
3361
+ let type = op_dcl.child[1];
3362
+ let oneway = false;
3363
+ if (attribute !== undefined && attribute.type === Type.TKN_ONEWAY)
3364
+ oneway = true;
3365
+ if (oneway && type.type !== Type.TKN_VOID)
3366
+ throw Error("oneway methods must return void");
3367
+ let identifier = op_dcl.child[2].text;
3368
+ let parameter_decls = op_dcl.child[3].child;
3369
+ out.write(" virtual ");
3370
+ if (oneway) {
3371
+ out.write(`${typeIDLtoCC(type, Direction.OUT)}`);
3372
+ }
3373
+ else {
3374
+ out.write(`CORBA::async<${typeIDLtoCC(type, Direction.OUT)}>`);
3375
+ }
3376
+ out.write(` ${identifier}(`);
3377
+ let comma = false;
3378
+ for (let parameter_dcl of parameter_decls) {
3379
+ let attribute = parameter_dcl.child[0].type;
3380
+ let type = parameter_dcl.child[1];
3381
+ let identifier = parameter_dcl.child[2].text;
3382
+ if (attribute !== Type.TKN_IN) {
3383
+ throw Error("corba.js currently only supports 'in' parameters");
3384
+ }
3385
+ if (!comma) {
3386
+ comma = true;
3387
+ }
3388
+ else {
3389
+ out.write(", ");
3390
+ }
3391
+ out.write(`${typeIDLtoCC(type, Direction.IN)} ${identifier}`);
3392
+ }
3393
+ out.write(`) = 0;\n`);
3394
+ }
3395
+ break;
3396
+ case Type.TKN_ATTRIBUTE:
3397
+ {
3398
+ const readonly = _export.child[0]?.type == Type.TKN_READONLY;
3399
+ const param_type_spec = _export.child[1];
3400
+ const attr_declarator = _export.child[2];
3401
+ for (const n of attr_declarator.child) {
3402
+ const identifier = n.text;
3403
+ out.write(` virtual CORBA::async<${typeIDLtoCC(param_type_spec, Direction.OUT)}> ${identifier}() = 0;\n`);
3404
+ if (!readonly) {
3405
+ out.write(` virtual CORBA::async<void> ${identifier}(${typeIDLtoCC(param_type_spec, Direction.IN)}) = 0;\n`);
3406
+ }
3407
+ }
3408
+ }
3409
+ break;
3410
+ default:
3411
+ throw Error("yikes");
3412
+ }
3413
+ }
3414
+ }
3370
3415
 
3371
3416
  function writeCCSkeleton(specification) {
3372
3417
  let out = fs__namespace.createWriteStream(filenamePrefix + "_skel.hh");
@@ -3395,12 +3440,12 @@ function writeCCSkeletonDefinitions(out, specification, prefix = "", indent = 0)
3395
3440
  {
3396
3441
  let interface_dcl = definition;
3397
3442
  let identifier = interface_dcl.child[0].child[1].text;
3398
- interface_dcl.child[1];
3399
- out.write(`class ${identifier}_skel: public CORBA::Skeleton, public ${prefix}${identifier} {\n`);
3443
+ let inheritance_spec = interface_dcl.child[0].child[2]?.text;
3444
+ out.write(`class ${identifier}_skel: public virtual ${prefix}${identifier}, public virtual ${inheritance_spec ? inheritance_spec + "_skel" : "CORBA::Skeleton"} {\n`);
3400
3445
  out.write(`public:\n`);
3401
3446
  out.write(` ${identifier}_skel() : Skeleton() {}\n`);
3402
3447
  out.write(`private:\n`);
3403
- out.write(` CORBA::async<> _call(const std::string_view &operation, CORBA::GIOPDecoder &decoder, CORBA::GIOPEncoder &encoder) override;\n`);
3448
+ out.write(` CORBA::async<> _dispatch(const std::string_view &operation, CORBA::GIOPDecoder &decoder, CORBA::GIOPEncoder &encoder) override;\n`);
3404
3449
  out.write("};\n\n");
3405
3450
  }
3406
3451
  break;
@@ -3435,10 +3480,10 @@ function writeCCStubDefinitions(out, specification, prefix = "", indent = 0) {
3435
3480
  {
3436
3481
  let interface_dcl = definition;
3437
3482
  let identifier = interface_dcl.child[0].child[1].text;
3483
+ let inheritance_spec = interface_dcl.child[0].child[2]?.text;
3438
3484
  let interface_body = interface_dcl.child[1];
3439
- out.write(`class ${identifier}_stub: public ${prefix}${identifier}, public CORBA::Stub {\n`);
3485
+ out.write(`class ${identifier}_stub: public virtual ${prefix}${identifier}, public virtual ${inheritance_spec ? inheritance_spec + "_stub" : "CORBA::Stub"} {\n`);
3440
3486
  out.write(`public:\n`);
3441
- out.write(` ${identifier}_stub(std::shared_ptr<CORBA::ORB> orb, CORBA::blob_view objectKey, std::shared_ptr<CORBA::detail::Connection> connection): Stub(orb, objectKey, connection) {}\n`);
3442
3487
  for (let _export of interface_body.child) {
3443
3488
  switch (_export.type) {
3444
3489
  case Type.SYN_OPERATION_DECLARATION:
@@ -3535,6 +3580,8 @@ function writeCCCodeDefinitions(out, specification, prefix = "", indent = 0) {
3535
3580
  {
3536
3581
  const interface_dcl = definition;
3537
3582
  const if_identifier = interface_dcl.child[0].child[1].text;
3583
+ let inheritance_spec_raw = interface_dcl.child[0].child[2];
3584
+ let inheritance_spec = interface_dcl.child[0].child[2]?.text;
3538
3585
  const interface_body = interface_dcl.child[1];
3539
3586
  for (let _export of interface_body.child) {
3540
3587
  switch (_export.type) {
@@ -3552,8 +3599,7 @@ function writeCCCodeDefinitions(out, specification, prefix = "", indent = 0) {
3552
3599
  }
3553
3600
  let identifier = op_dcl.child[2].text;
3554
3601
  let parameter_decls = op_dcl.child[3].child;
3555
- out.write(`static CORBA::async<>`);
3556
- out.write(` _${if_identifier}_${identifier}(${if_identifier} *obj, CORBA::GIOPDecoder &decoder, CORBA::GIOPEncoder &encoder) {\n`);
3602
+ out.write(`static CORBA::async<> _${if_identifier}_${identifier}(${if_identifier} *obj, CORBA::GIOPDecoder &decoder, CORBA::GIOPEncoder &encoder) {\n`);
3557
3603
  switch (type.type) {
3558
3604
  case Type.TKN_VOID:
3559
3605
  if (oneway) {
@@ -3659,8 +3705,8 @@ function writeCCCodeDefinitions(out, specification, prefix = "", indent = 0) {
3659
3705
  for (const n of attr_declarator.child) {
3660
3706
  const identifier = n.text;
3661
3707
  out.write(`static CORBA::async<> _${if_identifier}_get_${identifier}(${if_identifier} *obj, CORBA::GIOPDecoder &decoder, CORBA::GIOPEncoder &encoder) {\n`);
3662
- out.write(` ${typeIDLtoGIOPCC(param_type_spec, `co_await obj->${identifier}()`, Direction.OUT)};\n`);
3663
- out.write(` co_return;\n`);
3708
+ out.write(` auto result = co_await obj->${identifier}();\n`);
3709
+ out.write(` ${typeIDLtoGIOPCC(param_type_spec, "result", Direction.OUT)};\n`);
3664
3710
  out.write(`}\n`);
3665
3711
  out.write(`CORBA::async<${typeIDLtoCC(param_type_spec, Direction.OUT)}> ${if_identifier}_stub::${identifier}() {\n`);
3666
3712
  out.write(` return get_ORB()->twowayCall<${typeIDLtoCC(param_type_spec, Direction.OUT)}>(\n`);
@@ -3688,52 +3734,46 @@ function writeCCCodeDefinitions(out, specification, prefix = "", indent = 0) {
3688
3734
  }
3689
3735
  }
3690
3736
  out.write(`std::map<std::string_view, std::function<CORBA::async<>(${if_identifier} *obj, CORBA::GIOPDecoder &decoder, CORBA::GIOPEncoder &encoder)>> _op_${if_identifier} = {\n`);
3691
- for (let _export of interface_body.child) {
3692
- switch (_export.type) {
3693
- case Type.SYN_OPERATION_DECLARATION:
3694
- {
3695
- const op_dcl = _export;
3696
- op_dcl.child[0];
3697
- op_dcl.child[1];
3698
- let identifier = op_dcl.child[2].text;
3699
- out.write(` {"${identifier}", _${if_identifier}_${identifier}},\n`);
3700
- }
3701
- break;
3702
- case Type.TKN_ATTRIBUTE:
3703
- {
3704
- const readonly = _export.child[0]?.type == Type.TKN_READONLY;
3705
- _export.child[1];
3706
- const attr_declarator = _export.child[2];
3707
- for (const n of attr_declarator.child) {
3708
- const identifier = n.text;
3709
- if (!readonly) {
3710
- out.write(` {"_set_${identifier}", _${if_identifier}_set_${identifier}},\n`);
3711
- }
3712
- out.write(` {"_get_${identifier}", _${if_identifier}_get_${identifier}},\n`);
3713
- }
3714
- }
3715
- break;
3716
- default:
3717
- throw Error("yikes");
3718
- }
3737
+ const operationsWritten = new Set();
3738
+ writeDispatchBody(out, operationsWritten, if_identifier, interface_body);
3739
+ let inheritance_spec_iterator = inheritance_spec_raw;
3740
+ while (inheritance_spec_iterator) {
3741
+ const interface_dcl = inheritance_spec_iterator.child[0];
3742
+ const if_identifier = interface_dcl.child[0].child[1].text;
3743
+ let inheritance_spec_raw = interface_dcl.child[0].child[2];
3744
+ const interface_body = interface_dcl.child[1];
3745
+ writeDispatchBody(out, operationsWritten, if_identifier, interface_body);
3746
+ inheritance_spec_iterator = inheritance_spec_raw;
3719
3747
  }
3720
3748
  out.write("};\n");
3721
- out.write(`CORBA::async<> ${if_identifier}_skel::_call(const std::string_view &operation, CORBA::GIOPDecoder &decoder, CORBA::GIOPEncoder &encoder) {\n`);
3749
+ out.write(`CORBA::async<> ${if_identifier}_skel::_dispatch(const std::string_view &operation, CORBA::GIOPDecoder &decoder, CORBA::GIOPEncoder &encoder) {\n`);
3722
3750
  out.write(` auto it = _op_${if_identifier}.find(operation);\n`);
3723
3751
  out.write(` if (it == _op_${if_identifier}.end()) {\n`);
3724
3752
  out.write(` throw CORBA::BAD_OPERATION(0, CORBA::YES);\n`);
3725
3753
  out.write(` }\n`);
3726
3754
  out.write(` co_await it->second(this, decoder, encoder);\n`);
3727
3755
  out.write("};\n\n");
3728
- out.write(`std::string_view ${if_identifier}::_rid("IDL:${if_identifier}:1.0");\n`);
3729
- out.write(`std::string_view ${if_identifier}::repository_id() const { return _rid;}\n\n`);
3756
+ out.write(`std::string_view ${if_identifier}::repository_id() const {\n`);
3757
+ out.write(` static std::string_view rid("IDL:${if_identifier}:1.0");\n`);
3758
+ out.write(` return rid;\n`);
3759
+ out.write(`}\n\n`);
3760
+ out.write(`bool ${if_identifier}::_is_a(const std::string_view &logical_type_id) const {\n`);
3761
+ out.write(` static std::string_view rid("IDL:${if_identifier}:1.0");\n`);
3762
+ out.write(` if (logical_type_id == rid) {\n`);
3763
+ out.write(` return true;\n`);
3764
+ out.write(` }\n`);
3765
+ out.write(` return ${inheritance_spec ? inheritance_spec : "Object"}::_is_a(logical_type_id);\n`);
3766
+ out.write(`}\n\n`);
3730
3767
  out.write(`std::shared_ptr<${if_identifier}> ${if_identifier}::_narrow(std::shared_ptr<CORBA::Object> pointer) {\n`);
3731
3768
  out.write(` auto ptr = pointer.get();\n`);
3732
3769
  out.write(` auto ref = dynamic_cast<CORBA::IOR *>(ptr);\n`);
3733
3770
  out.write(` if (ref) {\n`);
3734
- out.write(` if (ref->repository_id() != "IDL:${if_identifier}:1.0") {\n`);
3771
+ out.write(` if (ref->repository_id().empty()) {\n`);
3735
3772
  out.write(` return std::shared_ptr<${if_identifier}>();\n`);
3736
3773
  out.write(` }\n`);
3774
+ out.write(` if (ref->repository_id() != "IDL:${if_identifier}:1.0") {\n`);
3775
+ out.write(` std::println("TODO: CHECK INHERITANCE FOR ${if_identifier}::_narrow(...): '{}' != '{}'", ref->repository_id(), "IDL:${if_identifier}:1.0");\n`);
3776
+ out.write(` }\n`);
3737
3777
  out.write(` std::shared_ptr<CORBA::ORB> orb = ref->get_ORB();\n`);
3738
3778
  out.write(` auto servant = orb->_narrow_servant(ref);\n`);
3739
3779
  out.write(` if (servant) {\n`);
@@ -3745,7 +3785,8 @@ function writeCCCodeDefinitions(out, specification, prefix = "", indent = 0) {
3745
3785
  out.write(` auto conn = orb->getConnection(ref->host, ref->port);\n`);
3746
3786
  out.write(` auto stub = conn->stubsById[ref->objectKey];\n`);
3747
3787
  out.write(` if (!stub) {\n`);
3748
- out.write(` stub = std::make_shared<${if_identifier}_stub>(orb, CORBA::blob_view(ref->objectKey), conn);\n`);
3788
+ out.write(` stub = std::make_shared<${if_identifier}_stub>();\n`);
3789
+ out.write(` stub->initStub(orb, CORBA::blob_view(ref->objectKey), conn);\n`);
3749
3790
  out.write(` conn->stubsById[ref->objectKey] = stub;\n`);
3750
3791
  out.write(` }\n`);
3751
3792
  out.write(` return std::dynamic_pointer_cast<${if_identifier}>(stub);\n`);
@@ -3793,6 +3834,43 @@ function writeCCCodeDefinitions(out, specification, prefix = "", indent = 0) {
3793
3834
  }
3794
3835
  }
3795
3836
  }
3837
+ function writeDispatchBody(out, operationsWritten, if_identifier, interface_body) {
3838
+ for (let _export of interface_body.child) {
3839
+ switch (_export.type) {
3840
+ case Type.SYN_OPERATION_DECLARATION:
3841
+ {
3842
+ const op_dcl = _export;
3843
+ op_dcl.child[0];
3844
+ op_dcl.child[1];
3845
+ let identifier = op_dcl.child[2].text;
3846
+ if (!operationsWritten.has(identifier)) {
3847
+ operationsWritten.add(identifier);
3848
+ out.write(` {"${identifier}", _${if_identifier}_${identifier}},\n`);
3849
+ }
3850
+ }
3851
+ break;
3852
+ case Type.TKN_ATTRIBUTE:
3853
+ {
3854
+ const readonly = _export.child[0]?.type == Type.TKN_READONLY;
3855
+ _export.child[1];
3856
+ const attr_declarator = _export.child[2];
3857
+ for (const n of attr_declarator.child) {
3858
+ const identifier = n.text;
3859
+ if (!operationsWritten.has(`_get_${identifier}`)) {
3860
+ operationsWritten.add(`_get_${identifier}`);
3861
+ if (!readonly) {
3862
+ out.write(` {"_set_${identifier}", _${if_identifier}_set_${identifier}},\n`);
3863
+ }
3864
+ out.write(` {"_get_${identifier}", _${if_identifier}_get_${identifier}},\n`);
3865
+ }
3866
+ }
3867
+ }
3868
+ break;
3869
+ default:
3870
+ throw Error("yikes");
3871
+ }
3872
+ }
3873
+ }
3796
3874
 
3797
3875
  function printHelp() {
3798
3876
  console.log(`corba.js IDL compiler