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.



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

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
  if not 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.



50
51
52
# File 'lib/ridl/delegate.rb', line 50

def root
  @root
end

#root_namespaceObject (readonly)

Returns the value of attribute root_namespace.



50
51
52
# File 'lib/ridl/delegate.rb', line 50

def root_namespace
  @root_namespace
end

Class Method Details

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

Raises:

  • (RuntimeError)


28
29
30
31
# File 'lib/ridl/delegate.rb', line 28

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

.get_pragma_handler(key) ⇒ Object



33
34
35
# File 'lib/ridl/delegate.rb', line 33

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

Instance Method Details

#cur_parsed_name_scopeObject



209
210
211
# File 'lib/ridl/delegate.rb', line 209

def cur_parsed_name_scope
  @cur ? @cur.parsed_name_scope : ''
end

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



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

def declare_attribute(_type, _name, _readonly=false)
  params = Hash.new
  params[:type] = _type
  params[:readonly] = _readonly
  params[:annotations] = @annotation_stack.dup unless @annotation_stack.empty?
  @annotation_stack.clear
  set_last(@cur.define(IDL::AST::Attribute, _name, params))
end

#declare_component(name) ⇒ Object

Raises:

  • (RuntimeError)


403
404
405
406
407
408
409
410
# File 'lib/ridl/delegate.rb', line 403

def declare_component(name)
  params = {}
  params[:forward] = true
  raise RuntimeError,
     "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



780
781
782
783
784
785
786
787
788
789
790
# File 'lib/ridl/delegate.rb', line 780

def declare_enumerator(_name)
  n = @cur.enumerators.length
  params = {
    :value => n,
    :enum => @cur
  }
  params[:annotations] = @annotation_stack.dup unless @annotation_stack.empty?
  @annotation_stack.clear
  set_last(@cur.enclosure.define(IDL::AST::Enumerator, _name, params))
  @cur
end

#declare_eventtype(name, attrib = nil) ⇒ Object

Raises:

  • (RuntimeError)


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

def declare_eventtype(name, attrib=nil)
  params = {}
  params[:abstract] = attrib == :abstract
  params[:forward] = true
  raise RuntimeError,
     "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



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

def declare_finder(name, params_, raises_)
  params = {}
  params[:params] = params_
  params[:raises] = raises_
  params[:annotations] = @annotation_stack.dup unless @annotation_stack.empty?
  @annotation_stack.clear
  set_last(@cur.define(IDL::AST::Finder, name, params))
  @cur
end

#declare_include(s) ⇒ Object



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

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



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

def declare_initializer(name, params_, raises_)
  params = {}
  params[:params] = params_
  params[:raises] = raises_
  params[:annotations] = @annotation_stack.dup unless @annotation_stack.empty?
  @annotation_stack.clear
  set_last(@cur.define(IDL::AST::Initializer, name, params))
  @cur
end

#declare_interface(name, attrib = nil) ⇒ Object

Raises:

  • (RuntimeError)


356
357
358
359
360
361
362
363
364
365
366
367
# File 'lib/ridl/delegate.rb', line 356

def declare_interface(name, attrib=nil)
  params = {}
  params[:abstract] = attrib == :abstract
  params[:local] = attrib == :local
  params[:forward] = true
  params[:pseudo] = false
  raise RuntimeError,
     "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



705
706
707
708
709
710
711
712
# File 'lib/ridl/delegate.rb', line 705

def declare_member(_type, _name)
  params = Hash.new
  params[:type] = _type
  params[:annotations] = @annotation_stack.dup unless @annotation_stack.empty?
  @annotation_stack.clear
  set_last(@cur.define(IDL::AST::Member, _name, params))
  @cur
end


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

def declare_op_footer(_raises, _context)
  @cur.raises = _raises || []
  @cur.context = _context
  if not @cur.context.nil?
    raise RuntimeError, "context phrase's not supported"
  end
  set_last(@cur)
  @cur = @cur.enclosure
end

#declare_op_header(_oneway, _type, _name) ⇒ Object



653
654
655
656
657
658
659
660
661
# File 'lib/ridl/delegate.rb', line 653

def declare_op_header(_oneway, _type, _name)
  params = Hash.new
  params[:oneway] = (_oneway == :oneway)
  params[:type]   = _type
  params[:annotations] = @annotation_stack.dup unless @annotation_stack.empty?
  @annotation_stack.clear
  set_last
  @cur = @cur.define(IDL::AST::Operation, _name, params)
end

#declare_op_parameter(_attribute, _type, _name) ⇒ Object



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

def declare_op_parameter(_attribute, _type, _name)
  params = Hash.new
  params[:attribute] = _attribute
  params[:type] = _type
  params[:annotations] = @annotation_stack.dup unless @annotation_stack.empty?
  @annotation_stack.clear
  set_last(@cur.define(IDL::AST::Parameter, _name, params))
  @cur
end

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



454
455
456
457
458
459
460
461
462
463
# File 'lib/ridl/delegate.rb', line 454

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

#declare_state_member(type, name, public_) ⇒ Object



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

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

#declare_struct(_name) ⇒ Object

Raises:

  • (RuntimeError)


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

def declare_struct(_name)
  params = { :forward => true }
  raise RuntimeError,
     "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



346
347
348
349
350
351
352
353
354
# File 'lib/ridl/delegate.rb', line 346

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

#declare_typedef(_type, _name) ⇒ Object



798
799
800
801
802
803
804
805
# File 'lib/ridl/delegate.rb', line 798

def declare_typedef(_type, _name)
  params = Hash.new
  params[:type] = _type
  params[:annotations] = @annotation_stack.dup unless @annotation_stack.empty?
  @annotation_stack.clear
  set_last(@cur.define(IDL::AST::Typedef, _name, params))
  @cur
end

#declare_union(_name) ⇒ Object

Raises:

  • (RuntimeError)


734
735
736
737
738
739
740
741
# File 'lib/ridl/delegate.rb', line 734

def declare_union(_name)
  params = { :forward => true }
  raise RuntimeError,
     "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

Raises:

  • (RuntimeError)


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

def declare_valuetype(name, attrib=nil)
  params = {}
  params[:abstract] = attrib == :abstract
  params[:forward] = true
  raise RuntimeError,
     "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



279
280
281
282
283
284
285
286
287
288
# File 'lib/ridl/delegate.rb', line 279

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_case(_labels, _type, _name) ⇒ Object



755
756
757
758
759
760
761
762
763
# File 'lib/ridl/delegate.rb', line 755

def define_case(_labels, _type, _name)
  params = Hash.new
  params[:type] = _type
  params[:labels] = _labels
  params[:annotations] = @annotation_stack.dup unless @annotation_stack.empty?
  @annotation_stack.clear
  set_last(@cur.define(IDL::AST::UnionMember, _name, params))
  @cur
end

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



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

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

#define_connector(name, base = nil) ⇒ Object



427
428
429
430
431
432
433
434
# File 'lib/ridl/delegate.rb', line 427

def define_connector(name, base = nil)
  params = {}
  params[:base] = base
  params[:annotations] = @annotation_stack.dup unless @annotation_stack.empty?
  @annotation_stack.clear
  set_last
  @cur = @cur.define(IDL::AST::Connector, name, params)
end

#define_const(_type, _name, _expression) ⇒ Object



645
646
647
648
649
650
651
# File 'lib/ridl/delegate.rb', line 645

def define_const(_type, _name, _expression)
  params = { :type => _type, :expression => _expression }
  params[:annotations] = @annotation_stack.dup unless @annotation_stack.empty?
  @annotation_stack.clear
  set_last(@cur.define(IDL::AST::Const, _name, params))
  @cur
end

#define_enum(_name) ⇒ Object



773
774
775
776
777
778
779
# File 'lib/ridl/delegate.rb', line 773

def define_enum(_name)
  params = {}
  params[:annotations] = @annotation_stack.dup unless @annotation_stack.empty?
  @annotation_stack.clear
  set_last
  @cur = @cur.define(IDL::AST::Enum, _name, params)
end

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



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

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.dup unless @annotation_stack.empty?
  @annotation_stack.clear
  set_last
  @cur = @cur.define(IDL::AST::Eventtype, name, params)
  @cur
end

#define_exception(_name) ⇒ Object



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

def define_exception(_name)
  params = { :forward => false }
  params[:annotations] = @annotation_stack.dup unless @annotation_stack.empty?
  @annotation_stack.clear
  set_last
  @cur = @cur.define(IDL::AST::Exception, _name, params)
end

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



386
387
388
389
390
391
392
393
394
395
396
# File 'lib/ridl/delegate.rb', line 386

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.dup unless @annotation_stack.empty?
  @annotation_stack.clear
  set_last
  @cur = @cur.define(IDL::AST::Home, name, params)
end

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



369
370
371
372
373
374
375
376
377
378
379
380
# File 'lib/ridl/delegate.rb', line 369

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.dup unless @annotation_stack.empty?
  @annotation_stack.clear
  set_last
  @cur = @cur.define(IDL::AST::Interface, name, params)
end

#define_module(name) ⇒ Object



290
291
292
293
294
295
296
# File 'lib/ridl/delegate.rb', line 290

def define_module(name)
  @cur = @cur.define(IDL::AST::Module, name)
  @cur.annotations.concat(@annotation_stack) unless @annotation_stack.empty?
  @annotation_stack.clear
  set_last
  @cur
end

#define_porttype(name) ⇒ Object



441
442
443
444
445
446
447
# File 'lib/ridl/delegate.rb', line 441

def define_porttype(name)
  params = {}
  params[:annotations] = @annotation_stack.dup unless @annotation_stack.empty?
  @annotation_stack.clear
  set_last
  @cur = @cur.define(IDL::AST::Porttype, name, params)
end

#define_struct(_name) ⇒ Object



698
699
700
701
702
703
704
# File 'lib/ridl/delegate.rb', line 698

def define_struct(_name)
  params = { :forward => false }
  params[:annotations] = @annotation_stack.dup unless @annotation_stack.empty?
  @annotation_stack.clear
  set_last
  @cur = @cur.define(IDL::AST::Struct, _name, params)
end

#define_template_module(global, names) ⇒ Object



306
307
308
309
310
311
312
313
314
315
# File 'lib/ridl/delegate.rb', line 306

def define_template_module(global, names)
  if global || names.size>1
    raise RuntimeError, "no scoped identifier allowed for template module: #{(global ? '::' : '')+names.join('::')}"
  end
  @cur = @cur.define(IDL::AST::TemplateModule, names[0])
  @cur.annotations.concat(@annotation_stack) unless @annotation_stack.empty?
  @annotation_stack.clear
  set_last
  @cur
end

#define_template_parameter(name, type) ⇒ Object



318
319
320
321
322
323
324
325
326
327
328
329
# File 'lib/ridl/delegate.rb', line 318

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.dup unless @annotation_stack.empty?
  @annotation_stack.clear
  set_last(@cur.define(IDL::AST::TemplateParam, name, params))
  @cur
end

#define_typeid(type, tid) ⇒ Object



275
276
277
# File 'lib/ridl/delegate.rb', line 275

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

#define_typeprefix(type, pfx) ⇒ Object



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

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

#define_union(_name) ⇒ Object



742
743
744
745
746
747
748
# File 'lib/ridl/delegate.rb', line 742

def define_union(_name)
  params = { :forward => false }
  params[:annotations] = @annotation_stack.dup unless @annotation_stack.empty?
  @annotation_stack.clear
  set_last
  @cur = @cur.define(IDL::AST::Union, _name, params)
end

#define_union_switchtype(union_node, switchtype) ⇒ Object



749
750
751
752
753
754
# File 'lib/ridl/delegate.rb', line 749

def define_union_switchtype(union_node, switchtype)
  union_node.set_switchtype(switchtype)
  union_node.annotations.concat(@annotation_stack) unless @annotation_stack.empty?
  @annotation_stack.clear
  union_node
end

#define_valuebox(name, type) ⇒ Object



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

def define_valuebox(name, type)
  params = { :type => type }
  params[:annotations] = @annotation_stack.dup unless @annotation_stack.empty?
  @annotation_stack.clear
  set_last(@cur.define(IDL::AST::Valuebox, name, params))
  @cur
end

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



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

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.dup unless @annotation_stack.empty?
  @annotation_stack.clear
  set_last
  @cur = @cur.define(IDL::AST::Valuetype, name, params)
  @cur
end

#end_component(node) ⇒ Object



422
423
424
425
# File 'lib/ridl/delegate.rb', line 422

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

#end_connector(node) ⇒ Object



436
437
438
439
# File 'lib/ridl/delegate.rb', line 436

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

#end_enum(node) ⇒ Object



791
792
793
794
795
796
# File 'lib/ridl/delegate.rb', line 791

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

#end_exception(node) ⇒ Object



727
728
729
730
731
732
# File 'lib/ridl/delegate.rb', line 727

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

#end_home(node) ⇒ Object



398
399
400
401
# File 'lib/ridl/delegate.rb', line 398

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

#end_interface(node) ⇒ Object



381
382
383
384
# File 'lib/ridl/delegate.rb', line 381

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



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

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

#end_porttype(node) ⇒ Object



449
450
451
452
# File 'lib/ridl/delegate.rb', line 449

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

#end_struct(node) ⇒ Object



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

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



764
765
766
767
768
769
770
771
# File 'lib/ridl/delegate.rb', line 764

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



513
514
515
516
517
518
519
# File 'lib/ridl/delegate.rb', line 513

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



217
218
219
220
221
222
223
224
225
# File 'lib/ridl/delegate.rb', line 217

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



265
266
267
268
269
# File 'lib/ridl/delegate.rb', line 265

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

#instantiate_template_module(name, parameters) ⇒ Object



331
332
333
334
335
336
337
338
339
340
341
342
343
344
# File 'lib/ridl/delegate.rb', line 331

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 RuntimeError, "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) unless @annotation_stack.empty?
  @annotation_stack.clear
  set_last(mod_inst.template.instantiate(mod_inst))
  @cur
end

#is_included?(s) ⇒ Boolean

Returns:

  • (Boolean)


213
214
215
# File 'lib/ridl/delegate.rb', line 213

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

#leave_includeObject



227
228
229
230
# File 'lib/ridl/delegate.rb', line 227

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

#parse_literal(_typestring, _value) ⇒ Object



597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
# File 'lib/ridl/delegate.rb', line 597

def parse_literal(_typestring, _value)
  k = Expression::Value
  case _typestring
  when :boolean
    k.new(Type::Boolean.new, _value)
  when :integer
    _type = [
      Type::Octet,
      Type::Short,
      Type::Long,
      Type::LongLong,
      Type::ULongLong,
    ].detect {|t| t::Range === _value }
    if _type.nil?
      raise RuntimeError,
        "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



632
633
634
635
636
637
638
639
640
641
642
643
# File 'lib/ridl/delegate.rb', line 632

def parse_positive_int(_expression)
  if _expression.is_template?
    _expression
  else
    if not ::Integer === _expression.value
      raise RuntimeError, "must be integer: #{_expression.value.inspect}"
    elsif _expression.value < 0
      raise RuntimeError, "must be positive integer: #{_expression.value.to_s}"
    end
    _expression.value
  end
end

#parse_scopedname(global, namelist) ⇒ Object



560
561
562
563
564
565
566
567
568
569
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
# File 'lib/ridl/delegate.rb', line 560

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 RuntimeError,
        "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::Valuetype, IDL::AST::Valuebox
    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)
  else
    raise RuntimeError,
       "invalid reference to #{node.class.name}: #{node.scoped_name}"
  end
end

#post_parseObject



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

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

#pragma_id(id, repo_id) ⇒ Object



254
255
256
257
258
259
260
261
262
263
# File 'lib/ridl/delegate.rb', line 254

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



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

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

#pragma_version(id, major, minor) ⇒ Object



243
244
245
246
247
248
249
250
251
252
# File 'lib/ridl/delegate.rb', line 243

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



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

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 => ex
          IDL.error("RIDL - failed to load ORB pidlc [#{ex}]\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



302
303
304
# File 'lib/ridl/delegate.rb', line 302

def register_template_module_name(name_spec)
  @template_module_name = name_spec
end

#visit_nodes(walker) ⇒ Object



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

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

#walk_member(m, w) ⇒ Object



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
# File 'lib/ridl/delegate.rb', line 101

def walk_member(m, w)
  case m
  when IDL::AST::Include
    if !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)
  else
    raise RuntimeError, "Invalid IDL member type for walkthrough: #{m.class.name}"
  end
end

#walk_nodes(walker, root_node = nil) ⇒ Object



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

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