ridl 2.2.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,40 @@
1
+ // $Id$
2
+ // $Id$
3
+
4
+ #ifndef _TIME_BASE_IDL
5
+ #define _TIME_BASE_IDL
6
+ #pragma prefix "omg.org"
7
+
8
+ #include <orb.idl>
9
+
10
+ module TimeBase
11
+ {
12
+
13
+ #ifdef NOLONGLONG
14
+ struct ulonglong {
15
+ unsigned long low;
16
+ unsigned long high;
17
+ };
18
+ typedef ulonglong TimeT;
19
+ #else
20
+ typedef unsigned long long TimeT;
21
+ #endif
22
+
23
+ typedef TimeT InaccuracyT;
24
+ typedef short TdfT;
25
+
26
+ struct UtcT {
27
+ TimeT time; // 8 octets
28
+ unsigned long inacclo; // 4 octets
29
+ unsigned short inacchi; // 4 octets
30
+ TdfT tdf; // 2 octets
31
+ // total 16 octets
32
+ };
33
+
34
+ struct IntervalT {
35
+ TimeT lower_bound;
36
+ TimeT upper_bound;
37
+ };
38
+
39
+ };
40
+ #endif /* _TIME_BASE_IDL */
@@ -0,0 +1,200 @@
1
+ /*--------------------------------------------------------------------
2
+ * orb.idl - R2CORBA orb.idl
3
+ *
4
+ * Author: Martin Corino
5
+ *
6
+ * $Id$
7
+ *
8
+ * This program is free software; you can redistribute it and/or
9
+ * modify it under the terms of the R2CORBA LICENSE which is
10
+ * included with this program.
11
+ *
12
+ * Copyright (c) Remedy IT Expertise BV
13
+ * Chamber of commerce Rotterdam nr.276339, The Netherlands
14
+ *--------------------------------------------------------------------*/
15
+
16
+ #ifndef R2CORBA_ORB_IDL
17
+ #define R2CORBA_ORB_IDL
18
+
19
+ #pragma prefix "omg.org"
20
+
21
+ module CORBA
22
+ {
23
+ /* Basic Sequence types
24
+ */
25
+ typedef sequence<any> AnySeq;
26
+ typedef sequence<boolean> BooleanSeq;
27
+ typedef sequence<char> CharSeq;
28
+ typedef sequence<double> DoubleSeq;
29
+ typedef sequence<float> FloatSeq;
30
+ typedef sequence<long> LongSeq;
31
+ typedef sequence<long long> LongLongSeq;
32
+ typedef sequence<short> ShortSeq;
33
+ typedef sequence<unsigned long> ULongSeq;
34
+ typedef sequence<unsigned long long> ULongLongSeq;
35
+ typedef sequence<unsigned short> UShortSeq;
36
+ typedef sequence<wchar> WCharSeq;
37
+ typedef sequence<string> StringSeq;
38
+ typedef sequence<wstring> WStringSeq;
39
+ typedef sequence<octet> OctetSeq;
40
+
41
+ /* Policy types and interfaces
42
+ */
43
+ typedef unsigned long PolicyType;
44
+
45
+ interface Policy
46
+ {
47
+ readonly attribute PolicyType policy_type;
48
+ Policy copy();
49
+ void destroy();
50
+ };
51
+
52
+ typedef sequence <Policy> PolicyList;
53
+ typedef sequence <PolicyType> PolicyTypeSeq;
54
+ exception InvalidPolicies { UShortSeq indices; };
55
+
56
+ local interface DomainManager
57
+ {
58
+ Policy get_domain_policy(in PolicyType policy_type);
59
+ };
60
+
61
+
62
+ interface InterfaceDef; /* forward */
63
+
64
+ interface ConstructionPolicy: Policy
65
+ {
66
+ void make_domain_manager(in InterfaceDef object_type,
67
+ in boolean constr_policy);
68
+ };
69
+
70
+ typedef sequence <DomainManager> DomainManagersList;
71
+
72
+ typedef short PolicyErrorCode;
73
+ const PolicyErrorCode BAD_POLICY = 0;
74
+ const PolicyErrorCode UNSUPPORTED_POLICY = 1;
75
+ const PolicyErrorCode BAD_POLICY_TYPE = 2;
76
+ const PolicyErrorCode BAD_POLICY_VALUE = 3;
77
+ const PolicyErrorCode UNSUPPORTED_POLICY_VALUE = 4;
78
+
79
+ exception PolicyError
80
+ {
81
+ PolicyErrorCode reason;
82
+ };
83
+
84
+ enum SetOverrideType {SET_OVERRIDE, ADD_OVERRIDE};
85
+
86
+ local interface PolicyManager
87
+ {
88
+ PolicyList get_policy_overrides(in PolicyTypeSeq ts);
89
+
90
+ void set_policy_overrides(in PolicyList policies,
91
+ in SetOverrideType set_add
92
+ ) raises (InvalidPolicies);
93
+ };
94
+
95
+ local interface Current {}; // dummy
96
+
97
+ local interface PolicyCurrent : PolicyManager, Current {
98
+ };
99
+
100
+ /* Service types and interfaces
101
+ */
102
+ typedef unsigned short ServiceType;
103
+ typedef unsigned long ServiceOption;
104
+ typedef unsigned long ServiceDetailType;
105
+ typedef OctetSeq ServiceDetailData;
106
+ typedef sequence<ServiceOption> ServiceOptionSeq;
107
+
108
+ const ServiceType Security = 1;
109
+
110
+ struct ServiceDetail
111
+ {
112
+ ServiceDetailType service_detail_type;
113
+ ServiceDetailData service_detail;
114
+ };
115
+
116
+ typedef sequence<ServiceDetail> ServiceDetailSeq;
117
+
118
+ struct ServiceInformation
119
+ {
120
+ ServiceOptionSeq service_options;
121
+ ServiceDetailSeq service_details;
122
+ };
123
+
124
+ /* ORB types
125
+ */
126
+ typedef string ORBid;
127
+ typedef unsigned long Flags;
128
+ typedef string Identifier;
129
+ typedef string RepositoryId;
130
+
131
+ /* TypeCode types
132
+ */
133
+ interface TypeCode;
134
+
135
+ enum TCKind
136
+ {
137
+ tk_null,
138
+ tk_void,
139
+ tk_short,
140
+ tk_long,
141
+ tk_ushort,
142
+ tk_ulong,
143
+ tk_float,
144
+ tk_double,
145
+ tk_boolean,
146
+ tk_char,
147
+ tk_octet,
148
+ tk_any,
149
+ tk_TypeCode,
150
+ tk_Principal,
151
+ tk_objref,
152
+ tk_struct,
153
+ tk_union,
154
+ tk_enum,
155
+ tk_string,
156
+ tk_sequence,
157
+ tk_array,
158
+ tk_alias,
159
+ tk_except,
160
+ tk_longlong,
161
+ tk_ulonglong,
162
+ tk_longdouble,
163
+ tk_wchar,
164
+ tk_wstring,
165
+ tk_fixed,
166
+ tk_value,
167
+ tk_value_box,
168
+ tk_native,
169
+ tk_abstract_interface,
170
+ tk_local_interface,
171
+ tk_component,
172
+ tk_home,
173
+ tk_event
174
+ };
175
+
176
+ /* misc
177
+ */
178
+ exception WrongTransaction {};
179
+
180
+ module ORB
181
+ {
182
+ exception InvalidName {};
183
+ };
184
+
185
+ native ExceptionList;
186
+ native NamedValue;
187
+
188
+ enum exception_type
189
+ {
190
+ NO_EXCEPTION,
191
+ USER_EXCEPTION,
192
+ SYSTEM_EXCEPTION
193
+ };
194
+
195
+ native ValueFactory;
196
+ };
197
+
198
+ #pragma prefix ""
199
+
200
+ #endif /* R2CORBA_ORB_IDL */
@@ -0,0 +1,124 @@
1
+ #--------------------------------------------------------------------
2
+ # backend.rb - RIDL backend configurations
3
+ #
4
+ # Author: Martin Corino
5
+ #
6
+ # This program is free software; you can redistribute it and/or
7
+ # modify it under the terms of the RIDL LICENSE which is
8
+ # included with this program.
9
+ #
10
+ # Copyright (c) Remedy IT Expertise BV
11
+ # Chamber of commerce Rotterdam nr.276339, The Netherlands
12
+ #--------------------------------------------------------------------
13
+
14
+ module IDL
15
+
16
+ class Backend
17
+
18
+ @@backends = {}
19
+
20
+ class ProcessStop < RuntimeError; end
21
+
22
+ class Configurator
23
+ attr_reader :backend
24
+ def initialize(be_name, root, title, copyright, version)
25
+ @backend = IDL::Backend.new(be_name, root, title, copyright, version)
26
+ @be_ext_klass = class << @backend; self; end
27
+ end
28
+
29
+ def add_backend(be_name)
30
+ @backend.instance_variable_get('@base_backends') << IDL::Backend.load(be_name)
31
+ end
32
+
33
+ def on_setup(&block)
34
+ @be_ext_klass.send(:define_method, :_setup_be, &block)
35
+ @be_ext_klass.send(:private, :_setup_be)
36
+ end
37
+
38
+ def on_process_input(&block)
39
+ @be_ext_klass.send(:define_method, :_process_input, &block)
40
+ @be_ext_klass.send(:private, :_process_input)
41
+ end
42
+ end
43
+
44
+ def self.load(be_name)
45
+ begin
46
+ # load mapping from standard extension dir in Ruby search path
47
+ require "ridlbe/#{be_name}/require"
48
+ IDL.log(1, "> loaded RIDL backend :#{be_name} from #{@@backends[be_name.to_sym].root}")
49
+ # return backend
50
+ return @@backends[be_name.to_sym]
51
+ rescue LoadError => ex
52
+ IDL.error "ERROR: Cannot load RIDL backend [:#{be_name}]"
53
+ IDL.error ex.inspect
54
+ IDL.error(ex.backtrace.join("\n")) if $VERBOSE
55
+ exit 1
56
+ end
57
+ end
58
+
59
+ def self.configure(be_name, root, title, copyright, version, &block)
60
+ cfg = Configurator.new(be_name, root, title, copyright, version)
61
+ block.call(cfg)
62
+ @@backends[cfg.backend.name] = cfg.backend
63
+ end
64
+
65
+ def self.stop_processing
66
+ raise ProcessStop, caller(1).first
67
+ end
68
+
69
+ def initialize(be_name, root, ttl, cpr, ver)
70
+ @name = be_name.to_sym
71
+ @root = root
72
+ @title = ttl
73
+ @copyright = cpr
74
+ @version = (Hash === ver ? ver : { :major => ver.to_i, :minor => 0, :release => 0 })
75
+ @base_backends = []
76
+ end
77
+
78
+ attr_reader :name, :root, :title, :copyright
79
+
80
+ def version
81
+ "#{@version[:major]}.#{@version[:minor]}.#{@version[:release]}"
82
+ end
83
+
84
+ def print_version
85
+ puts "#{title} #{version}"
86
+ puts copyright
87
+ @base_backends.each {|be| puts '---'; be.print_version }
88
+ end
89
+
90
+ def lookup_path
91
+ @base_backends.inject([@root]) {|paths, bbe| paths.concat(bbe.lookup_path) }
92
+ end
93
+
94
+ def setup_be(optlist, idl_options)
95
+ # initialize base backends in reverse order so each dependent BE can overrule its
96
+ # base settings
97
+ @base_backends.reverse.each {|be| be.setup_be(optlist, idl_options) }
98
+ # initialize this backend
99
+ _setup_be(optlist, idl_options)
100
+ end
101
+
102
+ def process_input(parser, params)
103
+ # process input top-down; return true when input handled
104
+ unless _process_input(parser, params)
105
+ return @base_backends.each {|be| be.process_input(parser, params) } != nil
106
+ end
107
+ end
108
+
109
+ @@null_be = nil
110
+
111
+ def self.null_be
112
+ @@null_be ||= self.configure('null', '.', 'RIDL Null backend', 'Copyright (c) 2013 Remedy IT Expertise BV, The Netherlands', 1) do |becfg|
113
+ becfg.on_setup do |optlist, params|
114
+ # noop
115
+ IDL.log(0, "Setup called for #{becfg.backend.title}")
116
+ end
117
+ becfg.on_process_input do |parser, params|
118
+ # noop
119
+ end
120
+ end
121
+ end
122
+
123
+ end
124
+ end
@@ -0,0 +1,740 @@
1
+ #--------------------------------------------------------------------
2
+ # delegate.rb - IDL delegator
3
+ #
4
+ # Author: Martin Corino
5
+ #
6
+ # This program is free software; you can redistribute it and/or
7
+ # modify it under the terms of the RIDL LICENSE which is
8
+ # included with this program.
9
+ #
10
+ # Copyright (c) Remedy IT Expertise BV
11
+ # Chamber of commerce Rotterdam nr.276339, The Netherlands
12
+ #--------------------------------------------------------------------
13
+ require 'ridl/node'
14
+ require 'ridl/expression'
15
+
16
+ module IDL
17
+
18
+ ORB_PIDL = 'orb.pidlc'
19
+
20
+ class Delegator
21
+
22
+ # #pragma handler registry
23
+ # each keyed entry a callable object:
24
+ # - responds to #call(delegator, cur_node, pragma_string)
25
+ # - returns boolean to indicate pragma recognized and handled (true) or not (false)
26
+ @@pragma_handlers = {}
27
+
28
+ def self.add_pragma_handler(key, h = nil, &block)
29
+ raise RuntimeError, 'add_pragma_handler requires a callable object or a block' unless (h && h.respond_to?(:call)) || block_given?
30
+ @@pragma_handlers[key] = block_given? ? block : h
31
+ end
32
+
33
+ def self.get_pragma_handler(key)
34
+ @@pragma_handlers[key]
35
+ end
36
+
37
+ def initialize(params = {})
38
+ @annotation_stack = IDL::AST::Annotations.new
39
+ @includes = {}
40
+ @expand_includes = params[:expand_includes] || false
41
+ @preprocess = params[:preprocess] || false
42
+ @preprocout = params[:output] if @preprocess
43
+ @ignore_pidl = params[:ignore_pidl] || false
44
+ @root_namespace = nil
45
+ if not params[:namespace].nil?
46
+ @root_namespace = IDL::AST::Module.new(params[:namespace], nil, {})
47
+ end
48
+ end
49
+
50
+ attr_reader :root, :root_namespace
51
+
52
+ def pre_parse
53
+ @root = nil
54
+ unless @preprocess || @ignore_pidl
55
+ IDL.backend.lookup_path.each do |be_root|
56
+ pidl_file = File.join(be_root, ORB_PIDL)
57
+ if File.file?(pidl_file) && File.readable?(pidl_file)
58
+ f = File.open(pidl_file, 'r')
59
+ begin
60
+ @root, @includes = Marshal.load(f)
61
+ @cur = @root
62
+ ensure
63
+ f.close
64
+ end
65
+ break
66
+ end
67
+ end
68
+ return if @root
69
+ end
70
+ @root = @cur = IDL::AST::Module.new(nil, nil, {}) # global root
71
+ end
72
+ def post_parse
73
+ if @preprocess
74
+ Marshal.dump([@root, @includes], @preprocout)
75
+ end
76
+ end
77
+
78
+ def visit_nodes(walker)
79
+ walker.visit_nodes(self)
80
+ end
81
+
82
+ def walk_nodes(walker, root_node = nil)
83
+ (root_node || @root).walk_members { |m| walk_member(m, walker) }
84
+ end
85
+
86
+ def walk_member(m, w)
87
+ case m
88
+ when IDL::AST::Include
89
+ if !m.is_preprocessed?
90
+ if @expand_includes
91
+ if m.is_defined?
92
+ w.enter_include(m)
93
+ m.walk_members { |cm| walk_member(cm, w) }
94
+ w.leave_include(m)
95
+ end
96
+ else
97
+ w.visit_include(m)
98
+ end
99
+ end
100
+ when IDL::AST::Porttype, IDL::AST::TemplateModule
101
+ # these are template types and do not generally generate
102
+ # code by themselves but only when 'instantiated' (used)
103
+ # in another type
104
+ when IDL::AST::Module
105
+ w.enter_module(m)
106
+ m.walk_members { |cm| walk_member(cm, w) }
107
+ w.leave_module(m)
108
+ when IDL::AST::Interface
109
+ if m.is_forward?
110
+ w.declare_interface(m)
111
+ else
112
+ w.enter_interface(m)
113
+ m.walk_members { |cm| walk_member(cm, w) }
114
+ w.leave_interface(m)
115
+ end
116
+ when IDL::AST::Home
117
+ _te = w.respond_to?(:enter_home)
118
+ _tl = w.respond_to?(:leave_home)
119
+ return unless _te || _tl
120
+ w.enter_home(m) if _te
121
+ m.walk_members { |cm| walk_member(cm, w) }
122
+ w.leave_home(m) if _tl
123
+ when IDL::AST::Component
124
+ if m.is_forward?
125
+ w.declare_component(m) if w.respond_to?(:declare_component)
126
+ else
127
+ _te = w.respond_to?(:enter_component)
128
+ _tl = w.respond_to?(:leave_component)
129
+ return unless _te || _tl
130
+ w.enter_component(m) if _te
131
+ m.walk_members { |cm| walk_member(cm, w) }
132
+ w.leave_component(m) if _tl
133
+ end
134
+ when IDL::AST::Connector
135
+ _te = w.respond_to?(:enter_connector)
136
+ _tl = w.respond_to?(:leave_connector)
137
+ return unless _te || _tl
138
+ w.enter_connector(m) if _te
139
+ m.walk_members { |cm| walk_member(cm, w) }
140
+ w.leave_connector(m) if _tl
141
+ when IDL::AST::Port
142
+ w.visit_port(m) if w.respond_to?(:visit_port)
143
+ when IDL::AST::Valuebox
144
+ w.visit_valuebox(m)
145
+ when IDL::AST::Valuetype, IDL::AST::Eventtype
146
+ if m.is_forward?
147
+ w.declare_valuetype(m)
148
+ else
149
+ w.enter_valuetype(m)
150
+ m.walk_members { |cm| walk_member(cm, w) }
151
+ w.leave_valuetype(m)
152
+ end
153
+ when IDL::AST::Finder
154
+ w.visit_finder(m) if w.respond_to?(:visit_finder)
155
+ when IDL::AST::Initializer
156
+ w.visit_factory(m) if w.respond_to?(:visit_factory)
157
+ when IDL::AST::Const
158
+ w.visit_const(m)
159
+ when IDL::AST::Operation
160
+ w.visit_operation(m)
161
+ when IDL::AST::Attribute
162
+ w.visit_attribute(m)
163
+ when IDL::AST::Exception
164
+ w.enter_exception(m)
165
+ m.walk_members { |cm| walk_member(cm, w) }
166
+ w.leave_exception(m)
167
+ when IDL::AST::Struct
168
+ if m.is_forward?
169
+ w.declare_struct(m)
170
+ else
171
+ w.enter_struct(m)
172
+ m.walk_members { |cm| walk_member(cm, w) }
173
+ w.leave_struct(m)
174
+ end
175
+ when IDL::AST::Union
176
+ if m.is_forward?
177
+ w.declare_union(m)
178
+ else
179
+ w.enter_union(m)
180
+ m.walk_members { |cm| walk_member(cm, w) }
181
+ w.leave_union(m)
182
+ end
183
+ when IDL::AST::Typedef
184
+ w.visit_typedef(m)
185
+ when IDL::AST::Enum
186
+ w.visit_enum(m)
187
+ when IDL::AST::Enumerator
188
+ w.visit_enumerator(m)
189
+ else
190
+ raise RuntimeError, "Invalid IDL member type for walkthrough: #{m.class.name}"
191
+ end
192
+ end
193
+
194
+ def cur_parsed_name_scope
195
+ @cur ? @cur.parsed_name_scope : ''
196
+ end
197
+
198
+ def is_included?(s)
199
+ @includes.has_key?(s)
200
+ end
201
+
202
+ def enter_include(s)
203
+ params = { :filename => s }
204
+ params[:defined] = true
205
+ params[:preprocessed] = @preprocess
206
+ @cur = @cur.define(IDL::AST::Include, "$INC:"+s, params)
207
+ @includes[s] = @cur
208
+ @cur
209
+ end
210
+
211
+ def leave_include()
212
+ @cur = @cur.enclosure
213
+ end
214
+
215
+ def declare_include(s)
216
+ params = { :filename => s }
217
+ params[:defined] = false
218
+ params[:preprocessed] = @includes[s].is_preprocessed?
219
+ @cur.define(IDL::AST::Include, "$INC:"+s, params)
220
+ end
221
+
222
+ def pragma_prefix(s)
223
+ @cur.prefix = s
224
+ end
225
+
226
+ def pragma_version(id, major, minor)
227
+ ids = id.split('::')
228
+ global = false
229
+ if ids.first.empty?
230
+ global = true
231
+ ids.shift
232
+ end
233
+ t = parse_scopedname(global, ids)
234
+ t.node.set_repo_version(major, minor)
235
+ end
236
+
237
+ def pragma_id(id, repo_id)
238
+ ids = id.split('::')
239
+ global = false
240
+ if ids.first.empty?
241
+ global = true
242
+ ids.shift
243
+ end
244
+ t = parse_scopedname(global, ids)
245
+ t.node.set_repo_id(repo_id)
246
+ end
247
+
248
+ def handle_pragma(pragma_string)
249
+ unless @@pragma_handlers.values.any? {|h| h.call(self, @cur, pragma_string)}
250
+ IDL.log(1, "RIDL - unrecognized pragma encountered: #{pragma_string}.")
251
+ end
252
+ end
253
+
254
+ def define_typeprefix(type, pfx)
255
+ type.node.replace_prefix(pfx.to_s)
256
+ end
257
+
258
+ def define_typeid(type, tid)
259
+ type.node.set_repo_id(tid.to_s)
260
+ end
261
+
262
+ def define_annotation(annid, annbody)
263
+ IDL.log(3, "parsed Annotation #{annid}(#{annbody})")
264
+ @annotation_stack << IDL::AST::Annotation.new(annid, annbody)
265
+ end
266
+
267
+ def define_module(name)
268
+ @cur = @cur.define(IDL::AST::Module, name)
269
+ @cur.annotations.concat(@annotation_stack) unless @annotation_stack.empty?
270
+ @annotation_stack.clear
271
+ @cur
272
+ end
273
+ def end_module(node)
274
+ @cur = @cur.enclosure # must equals to argument mod
275
+ end
276
+
277
+ def register_template_module_name(name_spec)
278
+ @template_module_name = name_spec
279
+ end
280
+
281
+ def define_template_module(global, names)
282
+ if global || names.size>1
283
+ raise RuntimeError, "no scoped identifier allowed for template module: #{(global ? '::' : '')+names.join('::')}"
284
+ end
285
+ @cur = @cur.define(IDL::AST::TemplateModule, names[0])
286
+ @cur.annotations.concat(@annotation_stack) unless @annotation_stack.empty?
287
+ @annotation_stack.clear
288
+ @cur
289
+ end
290
+ alias :end_template_module :end_module
291
+
292
+ def define_template_parameter(name, type)
293
+ if @template_module_name
294
+ tmp = @template_module_name
295
+ @template_module_name = nil # reset
296
+ define_template_module(*tmp)
297
+ end
298
+ params = { :type => type }
299
+ params[:annotations] = @annotation_stack.dup unless @annotation_stack.empty?
300
+ @annotation_stack.clear
301
+ @cur.define(IDL::AST::TemplateParam, name, params)
302
+ end
303
+
304
+ def instantiate_template_module(name, parameters)
305
+ tmp = @template_module_name
306
+ @template_module_name = nil # reset
307
+ template_type = parse_scopedname(*tmp)
308
+ mod_inst = @cur.define(IDL::AST::Module, name)
309
+ mod_inst.annotations.concat(@annotation_stack) unless @annotation_stack.empty?
310
+ @annotation_stack.clear
311
+ unless template_type.node.is_a?(IDL::AST::TemplateModule)
312
+ raise RuntimeError, "invalid module template specification: #{template_type.node.typename} #{template_type.node.scoped_lm_name}"
313
+ end
314
+ template_type.node.instantiate(mod_inst, parameters)
315
+ end
316
+
317
+ def declare_template_reference(name, type, tpl_params)
318
+ params = {}
319
+ params[:tpl_type] = type
320
+ params[:tpl_params] = tpl_params || []
321
+ params[:annotations] = @annotation_stack.dup unless @annotation_stack.empty?
322
+ @annotation_stack.clear
323
+ @cur.define(IDL::AST::TemplateModuleReference, name, params)
324
+ end
325
+
326
+ def declare_interface(name, attrib=nil)
327
+ params = {}
328
+ params[:abstract] = attrib == :abstract
329
+ params[:local] = attrib == :local
330
+ params[:forward] = true
331
+ params[:pseudo] = false
332
+ raise RuntimeError,
333
+ "annotations with forward declaration of #{name} not allowed" unless @annotation_stack.empty?
334
+ @cur.define(IDL::AST::Interface, name, params)
335
+ end
336
+
337
+ def define_interface(name, attrib, inherits = [])
338
+ params = {}
339
+ params[:abstract] = attrib == :abstract
340
+ params[:local] = attrib == :local
341
+ params[:pseudo] = attrib == :pseudo
342
+ params[:forward] = false
343
+ params[:inherits] = inherits
344
+ params[:annotations] = @annotation_stack.dup unless @annotation_stack.empty?
345
+ @annotation_stack.clear
346
+ @cur = @cur.define(IDL::AST::Interface, name, params)
347
+ end
348
+ def end_interface(node)
349
+ @cur = @cur.enclosure # must equals to argument mod
350
+ end
351
+
352
+ def define_home(name, base, component, key = nil, supports = nil)
353
+ params = {}
354
+ params[:base] = base
355
+ params[:component] = component
356
+ params[:key] = key
357
+ params[:supports] = supports || []
358
+ params[:annotations] = @annotation_stack.dup unless @annotation_stack.empty?
359
+ @annotation_stack.clear
360
+ @cur = @cur.define(IDL::AST::Home, name, params)
361
+ end
362
+
363
+ def end_home(node)
364
+ @cur = @cur.enclosure
365
+ end
366
+
367
+ def declare_component(name)
368
+ params = {}
369
+ params[:forward] = true
370
+ raise RuntimeError,
371
+ "annotations with forward declaration of #{name} not allowed" unless @annotation_stack.empty?
372
+ @cur.define(IDL::AST::Component, name, params)
373
+ end
374
+
375
+ def define_component(name, base, supports = nil)
376
+ params = {}
377
+ params[:base] = base
378
+ params[:supports] = supports || []
379
+ params[:annotations] = @annotation_stack.dup unless @annotation_stack.empty?
380
+ @annotation_stack.clear
381
+ @cur = @cur.define(IDL::AST::Component, name, params)
382
+ end
383
+
384
+ def end_component(node)
385
+ @cur = @cur.enclosure
386
+ end
387
+
388
+ def define_connector(name, base = nil)
389
+ params = {}
390
+ params[:base] = base
391
+ params[:annotations] = @annotation_stack.dup unless @annotation_stack.empty?
392
+ @annotation_stack.clear
393
+ @cur = @cur.define(IDL::AST::Connector, name, params)
394
+ end
395
+
396
+ def end_connector(node)
397
+ @cur = @cur.enclosure
398
+ end
399
+
400
+ def define_porttype(name)
401
+ params = {}
402
+ params[:annotations] = @annotation_stack.dup unless @annotation_stack.empty?
403
+ @annotation_stack.clear
404
+ @cur = @cur.define(IDL::AST::Porttype, name, params)
405
+ end
406
+
407
+ def end_porttype(node)
408
+ @cur = @cur.enclosure
409
+ end
410
+
411
+ def declare_port(name, porttype, type, multiple = false)
412
+ params = {}
413
+ params[:porttype] = porttype
414
+ params[:type] = type
415
+ params[:multiple] = multiple
416
+ params[:annotations] = @annotation_stack.dup unless @annotation_stack.empty?
417
+ @annotation_stack.clear
418
+ @cur.define(IDL::AST::Port, name, params)
419
+ end
420
+
421
+ def declare_eventtype(name, attrib=nil)
422
+ params = {}
423
+ params[:abstract] = attrib == :abstract
424
+ params[:forward] = true
425
+ raise RuntimeError,
426
+ "annotations with forward declaration of #{name} not allowed" unless @annotation_stack.empty?
427
+ @cur.define(IDL::AST::Eventtype, name, params)
428
+ @cur
429
+ end
430
+
431
+ def define_eventtype(name, attrib, inherits={})
432
+ params = {}
433
+ params[:abstract] = attrib == :abstract
434
+ params[:custom] = attrib == :custom
435
+ params[:forward] = false
436
+ params[:inherits] = inherits
437
+ params[:annotations] = @annotation_stack.dup unless @annotation_stack.empty?
438
+ @annotation_stack.clear
439
+ @cur = @cur.define(IDL::AST::Eventtype, name, params)
440
+ @cur
441
+ end
442
+
443
+ def declare_valuetype(name, attrib=nil)
444
+ params = {}
445
+ params[:abstract] = attrib == :abstract
446
+ params[:forward] = true
447
+ raise RuntimeError,
448
+ "annotations with forward declaration of #{name} not allowed" unless @annotation_stack.empty?
449
+ @cur.define(IDL::AST::Valuetype, name, params)
450
+ @cur
451
+ end
452
+
453
+ def define_valuetype(name, attrib, inherits={})
454
+ params = {}
455
+ params[:abstract] = attrib == :abstract
456
+ params[:custom] = attrib == :custom
457
+ params[:forward] = false
458
+ params[:inherits] = inherits
459
+ params[:annotations] = @annotation_stack.dup unless @annotation_stack.empty?
460
+ @annotation_stack.clear
461
+ @cur = @cur.define(IDL::AST::Valuetype, name, params)
462
+ @cur
463
+ end
464
+
465
+ def end_valuetype(node)
466
+ node.defined = true
467
+ ret = IDL::Type::ScopedName.new(@cur)
468
+ @cur = @cur.enclosure # must equals to argument mod
469
+ ret
470
+ end
471
+ alias :end_eventtype :end_valuetype
472
+
473
+ def declare_state_member(type, name, public_)
474
+ params = {}
475
+ params[:type] = type
476
+ params[:visibility] = (public_ ? :public : :private)
477
+ params[:annotations] = @annotation_stack.dup unless @annotation_stack.empty?
478
+ @annotation_stack.clear
479
+ @cur.define(IDL::AST::StateMember, name, params)
480
+ @cur
481
+ end
482
+
483
+ def define_valuebox(name, type)
484
+ params = { :type => type }
485
+ params[:annotations] = @annotation_stack.dup unless @annotation_stack.empty?
486
+ @annotation_stack.clear
487
+ @cur.define(IDL::AST::Valuebox, name, params)
488
+ @cur
489
+ end
490
+
491
+ def declare_initializer(name, params_, raises_)
492
+ params = {}
493
+ params[:params] = params_
494
+ params[:raises] = raises_
495
+ params[:annotations] = @annotation_stack.dup unless @annotation_stack.empty?
496
+ @annotation_stack.clear
497
+ @cur.define(IDL::AST::Initializer, name, params)
498
+ @cur
499
+ end
500
+
501
+ def declare_finder(name, params_, raises_)
502
+ params = {}
503
+ params[:params] = params_
504
+ params[:raises] = raises_
505
+ params[:annotations] = @annotation_stack.dup unless @annotation_stack.empty?
506
+ @annotation_stack.clear
507
+ @cur.define(IDL::AST::Finder, name, params)
508
+ @cur
509
+ end
510
+
511
+ def parse_scopedname(global, namelist)
512
+ node = root = if global then @root else @cur end
513
+ first = nil
514
+ namelist.each do |nm|
515
+ n = node.resolve(nm)
516
+ if n.nil?
517
+ raise RuntimeError,
518
+ "cannot find type name '#{nm}' in scope '#{node.scoped_name}'"
519
+ end
520
+ node = n
521
+ first = node if first.nil?
522
+ end
523
+ root.introduce(first)
524
+ case node
525
+ when IDL::AST::Module, IDL::AST::TemplateModule,
526
+ IDL::AST::Interface,IDL::AST::Home, IDL::AST::Component,
527
+ IDL::AST::Porttype, IDL::AST::Connector,
528
+ IDL::AST::Struct, IDL::AST::Union, IDL::AST::Typedef,
529
+ IDL::AST::Exception, IDL::AST::Enum,
530
+ IDL::AST::Valuetype, IDL::AST::Valuebox
531
+ Type::ScopedName.new(node)
532
+ when IDL::AST::TemplateParam
533
+ if node.idltype.is_a?(IDL::Type::Const)
534
+ Expression::ScopedName.new(node)
535
+ else
536
+ Type::ScopedName.new(node)
537
+ end
538
+ when IDL::AST::Const
539
+ Expression::ScopedName.new(node)
540
+ when IDL::AST::Enumerator
541
+ Expression::Enumerator.new(node)
542
+ else
543
+ raise RuntimeError,
544
+ "invalid reference to #{node.class.name}: #{node.scoped_name}"
545
+ end
546
+ end
547
+
548
+ def parse_literal(_typestring, _value)
549
+ k = Expression::Value
550
+ case _typestring
551
+ when :boolean
552
+ k.new(Type::Boolean.new, _value)
553
+ when :integer
554
+ _type = [
555
+ Type::Octet,
556
+ Type::Short,
557
+ Type::Long,
558
+ Type::LongLong,
559
+ Type::ULongLong,
560
+ ].detect {|t| t::Range === _value }
561
+ if _type.nil?
562
+ raise RuntimeError,
563
+ "it's not a valid integer: #{v.to_s}"
564
+ end
565
+ k.new(_type.new, _value)
566
+ when :string
567
+ k.new(Type::String.new, _value)
568
+ when :wstring
569
+ k.new(Type::WString.new, _value)
570
+ when :char
571
+ k.new(Type::Char.new, _value)
572
+ when :wchar
573
+ k.new(Type::WChar.new, _value)
574
+ when :fixed
575
+ k.new(Type::Fixed.new, _value)
576
+ when :float
577
+ k.new(Type::Float.new, _value)
578
+ else
579
+ raise ParseError, "unknown literal type: #{type}"
580
+ end
581
+ end
582
+
583
+ def parse_positive_int(_expression)
584
+ if _expression.is_template?
585
+ _expression
586
+ else
587
+ if not ::Integer === _expression.value
588
+ raise RuntimeError, "must be integer: #{_expression.value.inspect}"
589
+ elsif _expression.value < 0
590
+ raise RuntimeError, "must be positive integer: #{_expression.value.to_s}"
591
+ end
592
+ _expression.value
593
+ end
594
+ end
595
+
596
+ def define_const(_type, _name, _expression)
597
+ params = { :type => _type, :expression => _expression }
598
+ params[:annotations] = @annotation_stack.dup unless @annotation_stack.empty?
599
+ @annotation_stack.clear
600
+ node = @cur.define(IDL::AST::Const, _name, params)
601
+ @cur
602
+ end
603
+
604
+ def declare_op_header(_oneway, _type, _name)
605
+ params = Hash.new
606
+ params[:oneway] = (_oneway == :oneway)
607
+ params[:type] = _type
608
+ params[:annotations] = @annotation_stack.dup unless @annotation_stack.empty?
609
+ @annotation_stack.clear
610
+ @cur = @cur.define(IDL::AST::Operation, _name, params)
611
+ end
612
+ def declare_op_parameter(_attribute, _type, _name)
613
+ params = Hash.new
614
+ params[:attribute] = _attribute
615
+ params[:type] = _type
616
+ params[:annotations] = @annotation_stack.dup unless @annotation_stack.empty?
617
+ @annotation_stack.clear
618
+ @cur.define(IDL::AST::Parameter, _name, params)
619
+ end
620
+ def declare_op_footer(_raises, _context)
621
+ @cur.raises = _raises || []
622
+ @cur.context = _context
623
+ if not @cur.context.nil?
624
+ raise RuntimeError, "context phrase's not supported"
625
+ end
626
+ @cur = @cur.enclosure
627
+ end
628
+
629
+ def declare_attribute(_type, _name, _readonly=false)
630
+ params = Hash.new
631
+ params[:type] = _type
632
+ params[:readonly] = _readonly
633
+ params[:annotations] = @annotation_stack.dup unless @annotation_stack.empty?
634
+ @annotation_stack.clear
635
+ @cur.define(IDL::AST::Attribute, _name, params)
636
+ end
637
+
638
+ def declare_struct(_name)
639
+ params = { :forward => true }
640
+ raise RuntimeError,
641
+ "annotations with forward declaration of #{name} not allowed" unless @annotation_stack.empty?
642
+ @cur.define(IDL::AST::Struct, _name, params)
643
+ @cur
644
+ end
645
+ def define_struct(_name)
646
+ params = { :forward => false }
647
+ params[:annotations] = @annotation_stack.dup unless @annotation_stack.empty?
648
+ @annotation_stack.clear
649
+ @cur = @cur.define(IDL::AST::Struct, _name, params)
650
+ end
651
+ def declare_member(_type, _name)
652
+ params = Hash.new
653
+ params[:type] = _type
654
+ params[:annotations] = @annotation_stack.dup unless @annotation_stack.empty?
655
+ @annotation_stack.clear
656
+ @cur.define(IDL::AST::Member, _name, params)
657
+ end
658
+ def end_struct(node)
659
+ node.defined = true
660
+ ret = IDL::Type::ScopedName.new(@cur)
661
+ @cur = @cur.enclosure
662
+ ret
663
+ end
664
+ def define_exception(_name)
665
+ params = { :forward => false }
666
+ params[:annotations] = @annotation_stack.dup unless @annotation_stack.empty?
667
+ @annotation_stack.clear
668
+ @cur = @cur.define(IDL::AST::Exception, _name, params)
669
+ end
670
+ def end_exception(node)
671
+ ret = IDL::Type::ScopedName.new(@cur)
672
+ @cur = @cur.enclosure
673
+ ret
674
+ end
675
+
676
+ def declare_union(_name)
677
+ params = { :forward => true }
678
+ raise RuntimeError,
679
+ "annotations with forward declaration of #{name} not allowed" unless @annotation_stack.empty?
680
+ @cur.define(IDL::AST::Union, _name, params)
681
+ @cur
682
+ end
683
+ def define_union(_name)
684
+ params = { :forward => false }
685
+ params[:annotations] = @annotation_stack.dup unless @annotation_stack.empty?
686
+ @annotation_stack.clear
687
+ @cur = @cur.define(IDL::AST::Union, _name, params)
688
+ end
689
+ def define_union_switchtype(union_node, switchtype)
690
+ union_node.set_switchtype(switchtype)
691
+ union_node
692
+ end
693
+ def define_case(_labels, _type, _name)
694
+ params = Hash.new
695
+ params[:type] = _type
696
+ params[:labels] = _labels
697
+ params[:annotations] = @annotation_stack.dup unless @annotation_stack.empty?
698
+ @annotation_stack.clear
699
+ @cur.define(IDL::AST::UnionMember, _name, params)
700
+ end
701
+ def end_union(node)
702
+ node.validate_labels
703
+ node.defined = true
704
+ ret = IDL::Type::ScopedName.new(@cur)
705
+ @cur = @cur.enclosure
706
+ ret
707
+ end
708
+
709
+ def define_enum(_name)
710
+ params = {}
711
+ params[:annotations] = @annotation_stack.dup unless @annotation_stack.empty?
712
+ @annotation_stack.clear
713
+ @cur = @cur.define(IDL::AST::Enum, _name, params)
714
+ end
715
+ def declare_enumerator(_name)
716
+ n = @cur.enumerators.length
717
+ params = {
718
+ :value => n,
719
+ :enum => @cur
720
+ }
721
+ params[:annotations] = @annotation_stack.dup unless @annotation_stack.empty?
722
+ @annotation_stack.clear
723
+ @cur.enclosure.define(IDL::AST::Enumerator, _name, params)
724
+ @cur
725
+ end
726
+ def end_enum(node)
727
+ ret = IDL::Type::ScopedName.new(@cur)
728
+ @cur = @cur.enclosure
729
+ ret
730
+ end
731
+
732
+ def declare_typedef(_type, _name)
733
+ params = Hash.new
734
+ params[:type] = _type
735
+ params[:annotations] = @annotation_stack.dup unless @annotation_stack.empty?
736
+ @annotation_stack.clear
737
+ @cur.define(IDL::AST::Typedef, _name, params)
738
+ end
739
+ end # Delegator
740
+ end # IDL