Class: IDL::Delegator

Inherits:
Object
  • Object
show all
Defined in:
lib/ridl/delegate.rb

Constant Summary collapse

@@pragma_handlers =

#pragma handler registry each keyed entry a callable object:

  • responds to #call(delegator, cur_node, pragma_string)

  • returns boolean to indicate pragma recognized and handled (true) or not (false)

{}

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(params = {}) ⇒ Delegator

Returns a new instance of Delegator.



35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/ridl/delegate.rb', line 35

def initialize(params = {})
  @annotation_stack = IDL::AST::Annotations.new
  @includes = {}
  @expand_includes = params[:expand_includes] || false
  @preprocess = params[:preprocess] || false
  @preprocout = params[:output] if @preprocess
  @ignore_pidl = params[:ignore_pidl] || false
  @root_namespace = nil
  unless params[:namespace].nil?
    @root_namespace = IDL::AST::Module.new(params[:namespace], nil, {})
  end
end

Instance Attribute Details

#rootObject (readonly)

Returns the value of attribute root.



48
49
50
# File 'lib/ridl/delegate.rb', line 48

def root
  @root
end

#root_namespaceObject (readonly)

Returns the value of attribute root_namespace.



48
49
50
# File 'lib/ridl/delegate.rb', line 48

def root_namespace
  @root_namespace
end

Class Method Details

.add_pragma_handler(key, h = nil, &block) ⇒ Object



25
26
27
28
29
# File 'lib/ridl/delegate.rb', line 25

def self.add_pragma_handler(key, h = nil, &block)
  raise 'add_pragma_handler requires a callable object or a block' unless h&.respond_to?(:call) || block_given?

  @@pragma_handlers[key] = block_given? ? block : h
end

.get_pragma_handler(key) ⇒ Object



31
32
33
# File 'lib/ridl/delegate.rb', line 31

def self.get_pragma_handler(key)
  @@pragma_handlers[key]
end

Instance Method Details

#declare_attribute(_type, _name, _readonly = false) ⇒ Object



702
703
704
705
706
707
708
709
# File 'lib/ridl/delegate.rb', line 702

def declare_attribute(_type, _name, _readonly = false)
  params = {}
  params[:type] = _type
  params[:readonly] = _readonly
  params[:annotations] = @annotation_stack
  @annotation_stack = IDL::AST::Annotations.new
  set_last(@cur.define(IDL::AST::Attribute, _name, params))
end

#declare_bitfield(name_, bits_, idltype_) ⇒ Object



872
873
874
875
876
877
878
879
880
881
882
# File 'lib/ridl/delegate.rb', line 872

def declare_bitfield(name_, bits_, idltype_)
  params = {
    bits: bits_,
    bitset: @cur,
    idltype: idltype_
  }
  params[:annotations] = @annotation_stack
  @annotation_stack = IDL::AST::Annotations.new
  set_last(@cur.define(IDL::AST::BitField, name_, params))
  @cur
end

#declare_bitvalue(name) ⇒ Object



840
841
842
843
844
845
846
847
848
849
850
851
852
853
# File 'lib/ridl/delegate.rb', line 840

def declare_bitvalue(name)
  p = 0
  unless @cur.bitvalues.empty?
    p = @cur.bitvalues.last.position.next
  end
  params = {
    position: p,
    bitmask: @cur,
    annotations: @annotation_stack
  }
  @annotation_stack = IDL::AST::Annotations.new
  set_last(@cur.define(IDL::AST::BitValue, name, params))
  @cur
end

#declare_component(name) ⇒ Object



413
414
415
416
417
418
419
420
# File 'lib/ridl/delegate.rb', line 413

def declare_component(name)
  params = {}
  params[:forward] = true
  raise "annotations with forward declaration of #{name} not allowed" unless @annotation_stack.empty?

  set_last
  @cur.define(IDL::AST::Component, name, params)
end

#declare_enumerator(_name) ⇒ Object



812
813
814
815
816
817
818
819
820
821
822
# File 'lib/ridl/delegate.rb', line 812

def declare_enumerator(_name)
  n = @cur.enumerators.length
  params = {
    value: n,
    enum: @cur
  }
  params[:annotations] = @annotation_stack
  @annotation_stack = IDL::AST::Annotations.new
  set_last(@cur.enclosure.define(IDL::AST::Enumerator, _name, params))
  @cur
end

#declare_eventtype(name, attrib = nil) ⇒ Object



475
476
477
478
479
480
481
482
483
484
# File 'lib/ridl/delegate.rb', line 475

def declare_eventtype(name, attrib = nil)
  params = {}
  params[:abstract] = attrib == :abstract
  params[:forward] = true
  raise "annotations with forward declaration of #{name} not allowed" unless @annotation_stack.empty?

  set_last
  @cur.define(IDL::AST::Eventtype, name, params)
  @cur
end

#declare_finder(name, params_, raises_) ⇒ Object



560
561
562
563
564
565
566
567
568
# File 'lib/ridl/delegate.rb', line 560

def declare_finder(name, params_, raises_)
  params = {}
  params[:params] = params_
  params[:raises] = raises_
  params[:annotations] = @annotation_stack
  @annotation_stack = IDL::AST::Annotations.new
  set_last(@cur.define(IDL::AST::Finder, name, params))
  @cur
end

#declare_include(s) ⇒ Object



238
239
240
241
242
243
# File 'lib/ridl/delegate.rb', line 238

def declare_include(s)
  params = { filename: s, fullpath: @includes[s].fullpath }
  params[:defined] = false
  params[:preprocessed] = @includes[s].is_preprocessed?
  @cur.define(IDL::AST::Include, "$INC:" + s, params)
end

#declare_initializer(name, params_, raises_) ⇒ Object



550
551
552
553
554
555
556
557
558
# File 'lib/ridl/delegate.rb', line 550

def declare_initializer(name, params_, raises_)
  params = {}
  params[:params] = params_
  params[:raises] = raises_
  params[:annotations] = @annotation_stack
  @annotation_stack = IDL::AST::Annotations.new
  set_last(@cur.define(IDL::AST::Initializer, name, params))
  @cur
end

#declare_interface(name, attrib = nil) ⇒ Object



365
366
367
368
369
370
371
372
373
374
375
376
# File 'lib/ridl/delegate.rb', line 365

def declare_interface(name, attrib = nil)
  params = {}
  params[:abstract] = attrib == :abstract
  params[:local] = attrib == :local
  params[:forward] = true
  params[:pseudo] = false
  raise "annotations with forward declaration of #{name} not allowed" unless @annotation_stack.empty?

  @cur.define(IDL::AST::Interface, name, params)
  set_last
  @cur
end

#declare_member(_type, name) ⇒ Object



729
730
731
732
733
734
735
736
# File 'lib/ridl/delegate.rb', line 729

def declare_member(_type, name)
  params = {}
  params[:type] = _type
  params[:annotations] = @annotation_stack
  @annotation_stack = IDL::AST::Annotations.new
  set_last(@cur.define(IDL::AST::Member, name, params))
  @cur
end


691
692
693
694
695
696
697
698
699
700
# File 'lib/ridl/delegate.rb', line 691

def declare_op_footer(_raises, instantiation_context)
  @cur.raises = _raises || []
  @cur.context = instantiation_context
  unless @cur.context.nil?
    raise "context phrase's not supported"
  end

  set_last(@cur)
  @cur = @cur.enclosure
end

#declare_op_header(_oneway, _type, _name) ⇒ Object



671
672
673
674
675
676
677
678
679
# File 'lib/ridl/delegate.rb', line 671

def declare_op_header(_oneway, _type, _name)
  params = {}
  params[:oneway] = (_oneway == :oneway)
  params[:type]   = _type
  params[:annotations] = @annotation_stack
  @annotation_stack = IDL::AST::Annotations.new
  set_last
  @cur = @cur.define(IDL::AST::Operation, _name, params)
end

#declare_op_parameter(_attribute, _type, _name) ⇒ Object



681
682
683
684
685
686
687
688
689
# File 'lib/ridl/delegate.rb', line 681

def declare_op_parameter(_attribute, _type, _name)
  params = {}
  params[:attribute] = _attribute
  params[:type] = _type
  params[:annotations] = @annotation_stack
  @annotation_stack = IDL::AST::Annotations.new
  set_last(@cur.define(IDL::AST::Parameter, _name, params))
  @cur
end

#declare_port(name, porttype, type, multiple = false) ⇒ Object



464
465
466
467
468
469
470
471
472
473
# File 'lib/ridl/delegate.rb', line 464

def declare_port(name, porttype, type, multiple = false)
  params = {}
  params[:porttype] = porttype
  params[:type] = type
  params[:multiple] = multiple
  params[:annotations] = @annotation_stack
  @annotation_stack = IDL::AST::Annotations.new
  set_last(@cur.define(IDL::AST::Port, name, params))
  @cur
end

#declare_state_member(type, name, public_) ⇒ Object



532
533
534
535
536
537
538
539
540
# File 'lib/ridl/delegate.rb', line 532

def declare_state_member(type, name, public_)
  params = {}
  params[:type] = type
  params[:visibility] = (public_ ? :public : :private)
  params[:annotations] = @annotation_stack
  @annotation_stack = IDL::AST::Annotations.new
  set_last(@cur.define(IDL::AST::StateMember, name, params))
  @cur
end

#declare_struct(name) ⇒ Object



711
712
713
714
715
716
717
718
# File 'lib/ridl/delegate.rb', line 711

def declare_struct(name)
  params = { forward: true }
  raise "annotations with forward declaration of #{name} not allowed" unless @annotation_stack.empty?

  set_last
  @cur.define(IDL::AST::Struct, name, params)
  @cur
end

#declare_template_reference(name, type, tpl_params) ⇒ Object



355
356
357
358
359
360
361
362
363
# File 'lib/ridl/delegate.rb', line 355

def declare_template_reference(name, type, tpl_params)
  params = {}
  params[:tpl_type] = type
  params[:tpl_params] = tpl_params || []
  params[:annotations] = @annotation_stack
  @annotation_stack = IDL::AST::Annotations.new
  set_last(@cur.define(IDL::AST::TemplateModuleReference, name, params))
  @cur
end

#declare_typedef(_type, _name) ⇒ Object



891
892
893
894
895
896
897
898
# File 'lib/ridl/delegate.rb', line 891

def declare_typedef(_type, _name)
  params = {}
  params[:type] = _type
  params[:annotations] = @annotation_stack
  @annotation_stack = IDL::AST::Annotations.new
  set_last(@cur.define(IDL::AST::Typedef, _name, params))
  @cur
end

#declare_union(name) ⇒ Object



761
762
763
764
765
766
767
768
# File 'lib/ridl/delegate.rb', line 761

def declare_union(name)
  params = { forward: true }
  raise "annotations with forward declaration of #{name} not allowed" unless @annotation_stack.empty?

  set_last
  @cur.define(IDL::AST::Union, name, params)
  @cur
end

#declare_valuetype(name, attrib = nil) ⇒ Object



499
500
501
502
503
504
505
506
507
508
# File 'lib/ridl/delegate.rb', line 499

def declare_valuetype(name, attrib = nil)
  params = {}
  params[:abstract] = attrib == :abstract
  params[:forward] = true
  raise "annotations with forward declaration of #{name} not allowed" unless @annotation_stack.empty?

  set_last
  @cur.define(IDL::AST::Valuetype, name, params)
  @cur
end

#define_annotation(annid, annpos, anncomment, annbody) ⇒ Object



285
286
287
288
289
290
291
292
293
294
# File 'lib/ridl/delegate.rb', line 285

def define_annotation(annid, annpos, anncomment, annbody)
  IDL.log(3, "parsed #{anncomment ? 'commented ' : ''}Annotation #{annid}(#{annbody}) @ #{annpos}")
  if anncomment && @last && (@last_pos.line == annpos.line) && (@last_pos.name == annpos.name)
    IDL.log(3, 'adding annotation to last node')
    @last.annotations << IDL::AST::Annotation.new(annid, annbody)
  else
    IDL.log(3, 'appending annotation cached stack')
    @annotation_stack << IDL::AST::Annotation.new(annid, annbody)
  end
end

#define_bitmask(name) ⇒ Object



832
833
834
835
836
837
838
# File 'lib/ridl/delegate.rb', line 832

def define_bitmask(name)
  params = {}
  params[:annotations] = @annotation_stack
  @annotation_stack = IDL::AST::Annotations.new
  set_last
  @cur = @cur.define(IDL::AST::BitMask, name, params)
end

#define_bitset(_name, inherits = nil) ⇒ Object



863
864
865
866
867
868
869
870
# File 'lib/ridl/delegate.rb', line 863

def define_bitset(_name, inherits = nil)
  params = {}
  params[:annotations] = @annotation_stack
  params[:inherits] = inherits
  @annotation_stack = IDL::AST::Annotations.new
  set_last
  @cur = @cur.define(IDL::AST::BitSet, _name, params)
end

#define_case(_labels, _type, _name) ⇒ Object



785
786
787
788
789
790
791
792
793
# File 'lib/ridl/delegate.rb', line 785

def define_case(_labels, _type, _name)
  params = {}
  params[:type] = _type
  params[:labels] = _labels
  params[:annotations] = @annotation_stack
  @annotation_stack = IDL::AST::Annotations.new
  set_last(@cur.define(IDL::AST::UnionMember, _name, params))
  @cur
end

#define_component(name, base, supports = nil) ⇒ Object



422
423
424
425
426
427
428
429
430
# File 'lib/ridl/delegate.rb', line 422

def define_component(name, base, supports = nil)
  params = {}
  params[:base] = base
  params[:supports] = supports || []
  params[:annotations] = @annotation_stack
  @annotation_stack = IDL::AST::Annotations.new
  set_last
  @cur = @cur.define(IDL::AST::Component, name, params)
end

#define_connector(name, base = nil) ⇒ Object



437
438
439
440
441
442
443
444
# File 'lib/ridl/delegate.rb', line 437

def define_connector(name, base = nil)
  params = {}
  params[:base] = base
  params[:annotations] = @annotation_stack
  @annotation_stack = IDL::AST::Annotations.new
  set_last
  @cur = @cur.define(IDL::AST::Connector, name, params)
end

#define_const(_type, _name, _expression) ⇒ Object



663
664
665
666
667
668
669
# File 'lib/ridl/delegate.rb', line 663

def define_const(_type, _name, _expression)
  params = { type: _type, expression: _expression }
  params[:annotations] = @annotation_stack
  @annotation_stack = IDL::AST::Annotations.new
  set_last(@cur.define(IDL::AST::Const, _name, params))
  @cur
end

#define_enum(_name) ⇒ Object



804
805
806
807
808
809
810
# File 'lib/ridl/delegate.rb', line 804

def define_enum(_name)
  params = {}
  params[:annotations] = @annotation_stack
  @annotation_stack = IDL::AST::Annotations.new
  set_last
  @cur = @cur.define(IDL::AST::Enum, _name, params)
end

#define_eventtype(name, attrib, inherits = {}) ⇒ Object



486
487
488
489
490
491
492
493
494
495
496
497
# File 'lib/ridl/delegate.rb', line 486

def define_eventtype(name, attrib, inherits = {})
  params = {}
  params[:abstract] = attrib == :abstract
  params[:custom] = attrib == :custom
  params[:forward] = false
  params[:inherits] = inherits
  params[:annotations] = @annotation_stack
  @annotation_stack = IDL::AST::Annotations.new
  set_last
  @cur = @cur.define(IDL::AST::Eventtype, name, params)
  @cur
end

#define_exception(name) ⇒ Object



746
747
748
749
750
751
752
# File 'lib/ridl/delegate.rb', line 746

def define_exception(name)
  params = { forward: false }
  params[:annotations] = @annotation_stack
  @annotation_stack = IDL::AST::Annotations.new
  set_last
  @cur = @cur.define(IDL::AST::Exception, name, params)
end

#define_home(name, base, component, key = nil, supports = nil) ⇒ Object



396
397
398
399
400
401
402
403
404
405
406
# File 'lib/ridl/delegate.rb', line 396

def define_home(name, base, component, key = nil, supports = nil)
  params = {}
  params[:base] = base
  params[:component] = component
  params[:key] = key
  params[:supports] = supports || []
  params[:annotations] = @annotation_stack
  @annotation_stack = IDL::AST::Annotations.new
  set_last
  @cur = @cur.define(IDL::AST::Home, name, params)
end

#define_interface(name, attrib, inherits = []) ⇒ Object



378
379
380
381
382
383
384
385
386
387
388
389
# File 'lib/ridl/delegate.rb', line 378

def define_interface(name, attrib, inherits = [])
  params = {}
  params[:abstract] = attrib == :abstract
  params[:local] = attrib == :local
  params[:pseudo] = attrib == :pseudo
  params[:forward] = false
  params[:inherits] = inherits
  params[:annotations] = @annotation_stack
  @annotation_stack = IDL::AST::Annotations.new
  set_last
  @cur = @cur.define(IDL::AST::Interface, name, params)
end

#define_module(name) ⇒ Object



296
297
298
299
300
301
302
# File 'lib/ridl/delegate.rb', line 296

def define_module(name)
  @cur = @cur.define(IDL::AST::Module, name)
  @cur.annotations.concat(@annotation_stack)
  @annotation_stack = IDL::AST::Annotations.new
  set_last
  @cur
end

#define_porttype(name) ⇒ Object



451
452
453
454
455
456
457
# File 'lib/ridl/delegate.rb', line 451

def define_porttype(name)
  params = {}
  params[:annotations] = @annotation_stack
  @annotation_stack = IDL::AST::Annotations.new
  set_last
  @cur = @cur.define(IDL::AST::Porttype, name, params)
end

#define_struct(name, inherits = nil) ⇒ Object



720
721
722
723
724
725
726
727
# File 'lib/ridl/delegate.rb', line 720

def define_struct(name, inherits = nil)
  params = { forward: false }
  params[:annotations] = @annotation_stack
  params[:inherits] = inherits
  @annotation_stack = IDL::AST::Annotations.new
  set_last
  @cur = @cur.define(IDL::AST::Struct, name, params)
end

#define_template_module(global, names) ⇒ Object



313
314
315
316
317
318
319
320
321
322
323
# File 'lib/ridl/delegate.rb', line 313

def define_template_module(global, names)
  if global || names.size > 1
    raise "no scoped identifier allowed for template module: #{(global ? '::' : '') + names.join('::')}"
  end

  @cur = @cur.define(IDL::AST::TemplateModule, names[0])
  @cur.annotations.concat(@annotation_stack)
  @annotation_stack = IDL::AST::Annotations.new
  set_last
  @cur
end

#define_template_parameter(name, type) ⇒ Object



326
327
328
329
330
331
332
333
334
335
336
337
# File 'lib/ridl/delegate.rb', line 326

def define_template_parameter(name, type)
  if @template_module_name
    tmp = @template_module_name
    @template_module_name = nil # reset
    define_template_module(*tmp)
  end
  params = { type: type }
  params[:annotations] = @annotation_stack
  @annotation_stack = IDL::AST::Annotations.new
  set_last(@cur.define(IDL::AST::TemplateParam, name, params))
  @cur
end

#define_typeid(type, tid) ⇒ Object



281
282
283
# File 'lib/ridl/delegate.rb', line 281

def define_typeid(type, tid)
  type.node.set_repo_id(tid.to_s)
end

#define_typeprefix(type, pfx) ⇒ Object



277
278
279
# File 'lib/ridl/delegate.rb', line 277

def define_typeprefix(type, pfx)
  type.node.replace_prefix(pfx.to_s)
end

#define_union(name) ⇒ Object



770
771
772
773
774
775
776
# File 'lib/ridl/delegate.rb', line 770

def define_union(name)
  params = { forward: false }
  params[:annotations] = @annotation_stack
  @annotation_stack = IDL::AST::Annotations.new
  set_last
  @cur = @cur.define(IDL::AST::Union, name, params)
end

#define_union_switchtype(union_node, switchtype) ⇒ Object



778
779
780
781
782
783
# File 'lib/ridl/delegate.rb', line 778

def define_union_switchtype(union_node, switchtype)
  union_node.set_switchtype(switchtype)
  union_node.annotations.concat(@annotation_stack)
  @annotation_stack = IDL::AST::Annotations.new
  union_node
end

#define_valuebox(name, type) ⇒ Object



542
543
544
545
546
547
548
# File 'lib/ridl/delegate.rb', line 542

def define_valuebox(name, type)
  params = { type: type }
  params[:annotations] = @annotation_stack
  @annotation_stack = IDL::AST::Annotations.new
  set_last(@cur.define(IDL::AST::Valuebox, name, params))
  @cur
end

#define_valuetype(name, attrib, inherits = {}) ⇒ Object



510
511
512
513
514
515
516
517
518
519
520
521
# File 'lib/ridl/delegate.rb', line 510

def define_valuetype(name, attrib, inherits = {})
  params = {}
  params[:abstract] = attrib == :abstract
  params[:custom] = attrib == :custom
  params[:forward] = false
  params[:inherits] = inherits
  params[:annotations] = @annotation_stack
  @annotation_stack = IDL::AST::Annotations.new
  set_last
  @cur = @cur.define(IDL::AST::Valuetype, name, params)
  @cur
end

#end_bitmask(node) ⇒ Object



855
856
857
858
859
860
861
# File 'lib/ridl/delegate.rb', line 855

def end_bitmask(node)
  node.determine_bitbound
  set_last(@cur)
  ret = IDL::Type::ScopedName.new(@cur)
  @cur = @cur.enclosure
  ret
end

#end_bitset(_node) ⇒ Object



884
885
886
887
888
889
# File 'lib/ridl/delegate.rb', line 884

def end_bitset(_node)
  set_last(@cur)
  ret = IDL::Type::ScopedName.new(@cur)
  @cur = @cur.enclosure
  ret
end

#end_component(_node) ⇒ Object



432
433
434
435
# File 'lib/ridl/delegate.rb', line 432

def end_component(_node)
  set_last(@cur)
  @cur = @cur.enclosure
end

#end_connector(_node) ⇒ Object



446
447
448
449
# File 'lib/ridl/delegate.rb', line 446

def end_connector(_node)
  set_last(@cur)
  @cur = @cur.enclosure
end

#end_enum(node) ⇒ Object



824
825
826
827
828
829
830
# File 'lib/ridl/delegate.rb', line 824

def end_enum(node)
  node.determine_bitbound
  set_last(@cur)
  ret = IDL::Type::ScopedName.new(@cur)
  @cur = @cur.enclosure
  ret
end

#end_exception(_node) ⇒ Object



754
755
756
757
758
759
# File 'lib/ridl/delegate.rb', line 754

def end_exception(_node)
  set_last(@cur)
  ret = IDL::Type::ScopedName.new(@cur)
  @cur = @cur.enclosure
  ret
end

#end_home(_node) ⇒ Object



408
409
410
411
# File 'lib/ridl/delegate.rb', line 408

def end_home(_node)
  set_last(@cur)
  @cur = @cur.enclosure
end

#end_interface(_node) ⇒ Object



391
392
393
394
# File 'lib/ridl/delegate.rb', line 391

def end_interface(_node)
  set_last(@cur)
  @cur = @cur.enclosure # must equals to argument mod
end

#end_module(_node) ⇒ Object Also known as: end_template_module



304
305
306
307
# File 'lib/ridl/delegate.rb', line 304

def end_module(_node)
  set_last(@cur)
  @cur = @cur.enclosure # must equals to argument mod
end

#end_porttype(_node) ⇒ Object



459
460
461
462
# File 'lib/ridl/delegate.rb', line 459

def end_porttype(_node)
  set_last(@cur)
  @cur = @cur.enclosure
end

#end_struct(node) ⇒ Object



738
739
740
741
742
743
744
# File 'lib/ridl/delegate.rb', line 738

def end_struct(node)
  node.defined = true
  set_last(@cur)
  ret = IDL::Type::ScopedName.new(@cur)
  @cur = @cur.enclosure
  ret
end

#end_union(node) ⇒ Object



795
796
797
798
799
800
801
802
# File 'lib/ridl/delegate.rb', line 795

def end_union(node)
  node.validate_labels
  node.defined = true
  set_last(@cur)
  ret = IDL::Type::ScopedName.new(@cur)
  @cur = @cur.enclosure
  ret
end

#end_valuetype(node) ⇒ Object Also known as: end_eventtype



523
524
525
526
527
528
529
# File 'lib/ridl/delegate.rb', line 523

def end_valuetype(node)
  node.defined = true
  set_last(@cur)
  ret = IDL::Type::ScopedName.new(@cur)
  @cur = @cur.enclosure # must equals to argument mod
  ret
end

#enter_include(s, fullpath) ⇒ Object



223
224
225
226
227
228
229
230
231
# File 'lib/ridl/delegate.rb', line 223

def enter_include(s, fullpath)
  params = { filename: s, fullpath: fullpath }
  params[:defined] = true
  params[:preprocessed] = @preprocess
  @cur = @cur.define(IDL::AST::Include, "$INC:" + s, params)
  @includes[s] = @cur
  set_last
  @cur
end

#handle_pragma(pragma_string) ⇒ Object



271
272
273
274
275
# File 'lib/ridl/delegate.rb', line 271

def handle_pragma(pragma_string)
  unless @@pragma_handlers.values.reduce(false) { |rc, h| h.call(self, @cur, pragma_string) || rc }
    IDL.log(1, "RIDL - unrecognized pragma encountered: #{pragma_string}.")
  end
end

#instantiate_template_module(name, parameters) ⇒ Object



339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
# File 'lib/ridl/delegate.rb', line 339

def instantiate_template_module(name, parameters)
  tmp = @template_module_name
  @template_module_name = nil # reset
  template_type = parse_scopedname(*tmp)
  unless template_type.node.is_a?(IDL::AST::TemplateModule)
    raise "invalid module template specification: #{template_type.node.typename} #{template_type.node.scoped_lm_name}"
  end

  params = { template: template_type.node, template_params: parameters }
  mod_inst = @cur.define(IDL::AST::Module, name, params)
  mod_inst.annotations.concat(@annotation_stack)
  @annotation_stack = IDL::AST::Annotations.new
  set_last(mod_inst.template.instantiate(mod_inst))
  @cur
end

#is_included?(s) ⇒ Boolean

Returns:

  • (Boolean)


219
220
221
# File 'lib/ridl/delegate.rb', line 219

def is_included?(s)
  @includes.has_key?(s)
end

#leave_includeObject



233
234
235
236
# File 'lib/ridl/delegate.rb', line 233

def leave_include
  set_last
  @cur = @cur.enclosure
end

#parse_literal(_typestring, _value) ⇒ Object



610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
# File 'lib/ridl/delegate.rb', line 610

def parse_literal(_typestring, _value)
  k = Expression::Value
  case _typestring
  when :boolean
    k.new(Type::Boolean.new, _value)
  when :integer
    _type = [
      Type::Octet,
      Type::TinyShort,
      Type::Short,
      Type::Long,
      Type::LongLong,
      Type::UTinyShort,
      Type::ULongLong
    ].detect { |t| t::Range === _value }
    if _type.nil?
      raise "it's not a valid integer: #{v.to_s}"
    end

    k.new(_type.new, _value)
  when :string
    k.new(Type::String.new, _value)
  when :wstring
    k.new(Type::WString.new, _value)
  when :char
    k.new(Type::Char.new, _value)
  when :wchar
    k.new(Type::WChar.new, _value)
  when :fixed
    k.new(Type::Fixed.new, _value)
  when :float
    k.new(Type::Float.new, _value)
  else
    raise ParseError, "unknown literal type: #{type}"
  end
end

#parse_positive_int(_expression) ⇒ Object



647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
# File 'lib/ridl/delegate.rb', line 647

def parse_positive_int(_expression)
  if _expression.is_template?
    _expression
  else
    if not ::Integer === _expression.value
      raise "must be integer: #{_expression.value.inspect}"
    elsif _expression.value.negative?
      raise "must be positive integer: #{_expression.value}"
    elsif _expression.value.zero?
      raise "must be positive integer"
    end

    _expression.value
  end
end

#parse_scopedname(global, namelist) ⇒ Object



570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
# File 'lib/ridl/delegate.rb', line 570

def parse_scopedname(global, namelist)
  node = root = if global then @root else @cur end
  first = nil
  namelist.each do |nm|
    n = node.resolve(nm)
    if n.nil?
      raise "cannot find type name '#{nm}' in scope '#{node.scoped_name}'"
    end

    node = n
    first = node if first.nil?
  end
  root.introduce(first)
  case node
  when IDL::AST::Module, IDL::AST::TemplateModule,
       IDL::AST::Interface, IDL::AST::Home, IDL::AST::Component,
       IDL::AST::Porttype, IDL::AST::Connector,
       IDL::AST::Struct, IDL::AST::Union, IDL::AST::Typedef,
       IDL::AST::Exception, IDL::AST::Enum, IDL::AST::BitMask,
       IDL::AST::Valuetype, IDL::AST::Valuebox, IDL::AST::BitSet
    Type::ScopedName.new(node)
  when IDL::AST::TemplateParam
    if node.idltype.is_a?(IDL::Type::Const)
      Expression::ScopedName.new(node)
    else
      Type::ScopedName.new(node)
    end
  when IDL::AST::Const
    Expression::ScopedName.new(node)
  when IDL::AST::Enumerator
    Expression::Enumerator.new(node)
  when IDL::AST::BitValue
    Expression::BitValue.new(node)
  when IDL::AST::BitField
    Expression::BitField.new(node)
  else
    raise "invalid reference to #{node.class.name}: #{node.scoped_name}"
  end
end

#post_parseObject



76
77
78
79
80
# File 'lib/ridl/delegate.rb', line 76

def post_parse
  if @preprocess
    Marshal.dump([@root, @includes], @preprocout)
  end
end

#pragma_id(id, repo_id) ⇒ Object



260
261
262
263
264
265
266
267
268
269
# File 'lib/ridl/delegate.rb', line 260

def pragma_id(id, repo_id)
  ids = id.split('::')
  global = false
  if ids.first.empty?
    global = true
    ids.shift
  end
  t = parse_scopedname(global, ids)
  t.node.set_repo_id(repo_id)
end

#pragma_prefix(s) ⇒ Object



245
246
247
# File 'lib/ridl/delegate.rb', line 245

def pragma_prefix(s)
  @cur.prefix = s
end

#pragma_version(id, major, minor) ⇒ Object



249
250
251
252
253
254
255
256
257
258
# File 'lib/ridl/delegate.rb', line 249

def pragma_version(id, major, minor)
  ids = id.split('::')
  global = false
  if ids.first.empty?
    global = true
    ids.shift
  end
  t = parse_scopedname(global, ids)
  t.node.set_repo_version(major, minor)
end

#pre_parseObject



50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/ridl/delegate.rb', line 50

def pre_parse
  @root = nil
  unless @preprocess || @ignore_pidl
    IDL.backend.lookup_path.each do |be_root|
      pidl_file = File.join(be_root, ORB_PIDL)
      if File.file?(pidl_file) && File.readable?(pidl_file)
        f = File.open(pidl_file, 'r')
        begin
          @root, @includes = Marshal.load(f)
          @cur = @root
        rescue Exception => e
          IDL.error("RIDL - failed to load ORB pidlc [#{e}]\n You probably need to rebuild the bootstrap file (compile orb.idl to orb.pidlc).")
          exit(1)
        ensure
          f.close
        end
        break
      end
    end
    return if @root
  end
  @root = @cur = IDL::AST::Module.new(nil, nil, {}) # global root
  @last = nil
  @last_pos = nil
end

#register_template_module_name(name_spec) ⇒ Object



309
310
311
# File 'lib/ridl/delegate.rb', line 309

def register_template_module_name(name_spec)
  @template_module_name = name_spec
end

#visit_nodes(walker) ⇒ Object



92
93
94
# File 'lib/ridl/delegate.rb', line 92

def visit_nodes(walker)
  walker.visit_nodes(self)
end

#walk_member(m, w) ⇒ Object



100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
# File 'lib/ridl/delegate.rb', line 100

def walk_member(m, w)
  case m
  when IDL::AST::Include
    unless m.is_preprocessed?
      if @expand_includes
        if m.is_defined?
          w.enter_include(m)
          m.walk_members { |cm| walk_member(cm, w) }
          w.leave_include(m)
        end
      else
        w.visit_include(m)
      end
    end
  when IDL::AST::Porttype, IDL::AST::TemplateModule
    # these are template types and do not generally generate
    # code by themselves but only when 'instantiated' (used)
    # in another type
  when IDL::AST::Module
    w.enter_module(m)
    m.walk_members { |cm| walk_member(cm, w) }
    w.leave_module(m)
  when IDL::AST::Interface
    if m.is_forward?
      w.declare_interface(m)
    else
      w.enter_interface(m)
      m.walk_members { |cm| walk_member(cm, w) }
      w.leave_interface(m)
    end
  when IDL::AST::Home
    _te = w.respond_to?(:enter_home)
    _tl = w.respond_to?(:leave_home)
    return unless _te || _tl

    w.enter_home(m) if _te
    m.walk_members { |cm| walk_member(cm, w) }
    w.leave_home(m) if _tl
  when IDL::AST::Component
    if m.is_forward?
      w.declare_component(m) if w.respond_to?(:declare_component)
    else
      _te = w.respond_to?(:enter_component)
      _tl = w.respond_to?(:leave_component)
      return unless _te || _tl

      w.enter_component(m) if _te
      m.walk_members { |cm| walk_member(cm, w) }
      w.leave_component(m) if _tl
    end
  when IDL::AST::Connector
    _te = w.respond_to?(:enter_connector)
    _tl = w.respond_to?(:leave_connector)
    return unless _te || _tl

    w.enter_connector(m) if _te
    m.walk_members { |cm| walk_member(cm, w) }
    w.leave_connector(m) if _tl
  when IDL::AST::Port
    w.visit_port(m) if w.respond_to?(:visit_port)
  when IDL::AST::Valuebox
    w.visit_valuebox(m)
  when IDL::AST::Valuetype, IDL::AST::Eventtype
    if m.is_forward?
      w.declare_valuetype(m)
    else
      w.enter_valuetype(m)
      m.walk_members { |cm| walk_member(cm, w) }
      w.leave_valuetype(m)
    end
  when IDL::AST::Finder
    w.visit_finder(m) if w.respond_to?(:visit_finder)
  when IDL::AST::Initializer
    w.visit_factory(m) if w.respond_to?(:visit_factory)
  when IDL::AST::Const
    w.visit_const(m)
  when IDL::AST::Operation
    w.visit_operation(m)
  when IDL::AST::Attribute
    w.visit_attribute(m)
  when IDL::AST::Exception
    w.enter_exception(m)
    m.walk_members { |cm| walk_member(cm, w) }
    w.leave_exception(m)
  when IDL::AST::Struct
    if m.is_forward?
      w.declare_struct(m)
    else
      w.enter_struct(m)
      m.walk_members { |cm| walk_member(cm, w) }
      w.leave_struct(m)
    end
  when IDL::AST::Union
    if m.is_forward?
      w.declare_union(m)
    else
      w.enter_union(m)
      m.walk_members { |cm| walk_member(cm, w) }
      w.leave_union(m)
    end
  when IDL::AST::Typedef
    w.visit_typedef(m)
  when IDL::AST::Enum
    w.visit_enum(m)
  when IDL::AST::Enumerator
    w.visit_enumerator(m)
  when IDL::AST::BitMask
    w.visit_bitmask(m)
  when IDL::AST::BitValue
    w.visit_bitvalue(m)
  when IDL::AST::BitSet
    w.visit_bitset(m)
  when IDL::AST::BitField
    w.visit_bitfield(m)
  else
    raise "Invalid IDL member type for walkthrough: #{m.class.name}"
  end
end

#walk_nodes(walker, root_node = nil) ⇒ Object



96
97
98
# File 'lib/ridl/delegate.rb', line 96

def walk_nodes(walker, root_node = nil)
  (root_node || @root).walk_members { |m| walk_member(m, walker) }
end