HDLRuby 2.4.29 → 2.6.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (46) hide show
  1. checksums.yaml +4 -4
  2. data/lib/HDLRuby/drivers/xcd.rb +79 -0
  3. data/lib/HDLRuby/drivers/xcd/dummy.xcd +4 -0
  4. data/lib/HDLRuby/hdr_samples/adder.rb +1 -1
  5. data/lib/HDLRuby/hdr_samples/adder_bench.rb +1 -1
  6. data/lib/HDLRuby/hdr_samples/adder_gen.rb +1 -1
  7. data/lib/HDLRuby/hdr_samples/constant_in_function.rb +27 -0
  8. data/lib/HDLRuby/hdr_samples/dff_properties.rb +19 -0
  9. data/lib/HDLRuby/hdr_samples/dff_unit.rb +54 -0
  10. data/lib/HDLRuby/hdr_samples/huge_rom.rb +25 -0
  11. data/lib/HDLRuby/hdr_samples/logic_bench.rb +21 -0
  12. data/lib/HDLRuby/hdr_samples/mei8_bench.rb +1 -1
  13. data/lib/HDLRuby/hdr_samples/multi_timed_bench.rb +54 -0
  14. data/lib/HDLRuby/hdr_samples/music.rb +79 -0
  15. data/lib/HDLRuby/hdr_samples/named_sub.rb +42 -0
  16. data/lib/HDLRuby/hdr_samples/rom.rb +16 -0
  17. data/lib/HDLRuby/hdr_samples/with_function_generator.rb +25 -0
  18. data/lib/HDLRuby/hdrcc.rb +162 -26
  19. data/lib/HDLRuby/hruby_decorator.rb +250 -0
  20. data/lib/HDLRuby/hruby_high.rb +468 -91
  21. data/lib/HDLRuby/hruby_low.rb +913 -45
  22. data/lib/HDLRuby/hruby_low2c.rb +122 -168
  23. data/lib/HDLRuby/hruby_low2hdr.rb +738 -0
  24. data/lib/HDLRuby/hruby_low2high.rb +331 -549
  25. data/lib/HDLRuby/hruby_low2vhd.rb +39 -2
  26. data/lib/HDLRuby/hruby_low_bool2select.rb +29 -0
  27. data/lib/HDLRuby/hruby_low_casts_without_expression.rb +27 -0
  28. data/lib/HDLRuby/hruby_low_fix_types.rb +25 -0
  29. data/lib/HDLRuby/hruby_low_mutable.rb +70 -0
  30. data/lib/HDLRuby/hruby_low_resolve.rb +28 -0
  31. data/lib/HDLRuby/hruby_low_without_connection.rb +6 -3
  32. data/lib/HDLRuby/hruby_low_without_namespace.rb +7 -4
  33. data/lib/HDLRuby/hruby_low_without_select.rb +13 -0
  34. data/lib/HDLRuby/hruby_tools.rb +11 -1
  35. data/lib/HDLRuby/hruby_verilog.rb +1577 -1709
  36. data/lib/HDLRuby/sim/hruby_sim.h +29 -3
  37. data/lib/HDLRuby/sim/hruby_sim_calc.c +63 -6
  38. data/lib/HDLRuby/sim/hruby_sim_core.c +24 -9
  39. data/lib/HDLRuby/sim/hruby_sim_vcd.c +5 -1
  40. data/lib/HDLRuby/sim/hruby_sim_vizualize.c +22 -6
  41. data/lib/HDLRuby/std/fixpoint.rb +9 -0
  42. data/lib/HDLRuby/std/function_generator.rb +139 -0
  43. data/lib/HDLRuby/std/hruby_unit.rb +75 -0
  44. data/lib/HDLRuby/template_expander.rb +61 -0
  45. data/lib/HDLRuby/version.rb +1 -1
  46. metadata +21 -5
@@ -0,0 +1,738 @@
1
+ require 'HDLRuby'
2
+
3
+
4
+ module HDLRuby::Low
5
+
6
+
7
+ ##
8
+ # Converts a HDLRuby::Low description to hdr text description.
9
+ #
10
+ ########################################################################
11
+
12
+ ## Provides tools for converting HDLRuby::Low objects to hdr text.
13
+ module Low2HDR
14
+
15
+ ## Tells if an HDLRuby::Low +name+ syntax is compatible for
16
+ # hdr text.
17
+ def self.hdr_name?(name)
18
+ return name =~ /^[a-zA-Z_][a-zA-Z_0-9]*$/
19
+ end
20
+
21
+ ## Converts a HDLRuby::Low +name+ for declaration to hdr tex.
22
+ def self.hdr_decl_name(name)
23
+ if hdr_name?(name) then
24
+ # Compatible name return it as is.
25
+ return name.to_s
26
+ else
27
+ # Incompatible, use quotes.
28
+ return "\"#{name}\""
29
+ end
30
+ end
31
+
32
+ ## Converts a HDLRuby::Low +name+ for usage to hdr text.
33
+ def self.hdr_use_name(name)
34
+ if hdr_name?(name) then
35
+ # Compatible name return it as is.
36
+ return name.to_s
37
+ else
38
+ # Incompatible, use the hdr "send" operator.
39
+ # return "(+:\"#{name}\")"
40
+ return "send(:\"#{name}\")"
41
+ end
42
+ end
43
+
44
+ ## Convert a HDLRuby::Low +name+ for instantiation to hdr text
45
+ # with args as argument.
46
+ def self.hdr_call_name(name,args)
47
+ if hdr_name?(name) then
48
+ # Compatible name return it as is.
49
+ return "#{name} #{[*args].join(",")}"
50
+ else
51
+ # Incompatible, use the ruby "send" operator.
52
+ return "send(:\"#{name}\",#{[*args].join(",")})"
53
+ end
54
+ end
55
+ end
56
+
57
+
58
+
59
+ ## Extends the SystemT class with generation of hdr text.
60
+ class SystemT
61
+
62
+ # Generates the text of the equivalent hdr text.
63
+ # +level+ is the hierachical level of the object.
64
+ def to_hdr(level = 0)
65
+ # The resulting string.
66
+ res = ""
67
+ # Generate the header.
68
+ res << " " * (level*3)
69
+ res << "system :#{Low2HDR.hdr_decl_name(self.name)} do\n"
70
+ # Generate the interface.
71
+ # Inputs.
72
+ self.each_input do |input|
73
+ res << " " * ((level+1)*3)
74
+ res << input.type.to_hdr(level+1)
75
+ res << ".input :" << Low2HDR.hdr_decl_name(input.name)
76
+ res << "\n"
77
+ end
78
+ # Outputs.
79
+ self.each_output do |output|
80
+ res << " " * ((level+1)*3)
81
+ res << output.type.to_hdr(level+1)
82
+ res << ".output :" << Low2HDR.hdr_decl_name(output.name)
83
+ res << "\n"
84
+ end
85
+ # Inouts.
86
+ self.each_inout do |inout|
87
+ res << " " * ((level+1)*3)
88
+ res << inout.type.to_hdr(level+1)
89
+ res << ".inout :" << Low2HDR.hdr_decl_name(inout.name)
90
+ res << "\n"
91
+ end
92
+ # Generate the scope.
93
+ res << " " * (level*3)
94
+ res << "\n"
95
+ res << self.scope.to_hdr(level+1,false)
96
+ # End of the system.
97
+ res << " " * (level*3)
98
+ res << "end\n\n"
99
+ # Return the result.
100
+ return res
101
+ end
102
+ end
103
+
104
+
105
+ ## Extends the Scope class with generation of hdr text.
106
+ class Scope
107
+
108
+ # Generates the text of the equivalent hdr text.
109
+ # +level+ is the hierachical level of the object and
110
+ # +header+ tells if the header is to generate or not.
111
+ def to_hdr(level = 0,header = true)
112
+ # The resulting string.
113
+ res = ""
114
+ # Generate the header if required.
115
+ if header then
116
+ res << (" " * (level*3)) << "sub "
117
+ unless self.name.empty? then
118
+ res << ":" << Low2HDR.hdr_decl_name(self.name) << " "
119
+ end
120
+ res << "do\n"
121
+ end
122
+ level = level + 1 if header
123
+ # Generate the sub types.
124
+ # Assume the types are TypeDef.
125
+ self.each_type do |type|
126
+ res << " " * (level*3)
127
+ res << "typedef :#{type.name} do\n"
128
+ res << " " * ((level+1)*3) << type.def.to_hdr(level)
129
+ res << " " * (level*3) << "end\n"
130
+ end
131
+ # Generaste the sub system types.
132
+ self.each_systemT { |systemT| res << systemT.to_hdr(level) }
133
+ # Generate the inners declaration.
134
+ self.each_inner do |inner|
135
+ res << " " * (level*3)
136
+ res << inner.type.to_high(level)
137
+ res << ".inner :" << Low2HDR.hdr_decl_name(inner.name) << "\n"
138
+ end
139
+ # Generate the instances.
140
+ res << "\n" if self.each_inner.any?
141
+ self.each_systemI do |systemI|
142
+ res << " " * (level*3)
143
+ res << systemI.to_hdr(level) << "\n"
144
+ end
145
+ # Generate the sub scopes.
146
+ self.each_scope do |scope|
147
+ res << scope.to_hdr(level)
148
+ end
149
+ # Generate the connections.
150
+ res << "\n" if self.each_scope.any?
151
+ self.each_connection do |connection|
152
+ res << connection.to_hdr(level)
153
+ end
154
+ # Generate the behaviors.
155
+ res << "\n" if self.each_connection.any?
156
+ self.each_behavior do |behavior|
157
+ res << behavior.to_hdr(level)
158
+ end
159
+ # Close the scope if required.
160
+ if header then
161
+ res << " " * ((level-1)*3) << "end\n"
162
+ end
163
+ # Return the result.
164
+ return res
165
+ end
166
+ end
167
+
168
+
169
+ ## Extends the Type class with generation of hdr text.
170
+ class Type
171
+
172
+ # Generates the text of the equivalent hdr text.
173
+ # +level+ is the hierachical level of the object.
174
+ def to_hdr(level = 0)
175
+ return Low2HDR.hdr_use_name(self.name)
176
+ end
177
+ end
178
+
179
+ ## Extends the TypeDef class with generation of hdr text.
180
+ class TypeDef
181
+
182
+ # Generates the text of the equivalent hdr text.
183
+ # +level+ is the hierachical level of the object.
184
+ def to_hdr(level = 0)
185
+ # Simply generates the redefined type.
186
+ self.def.to_hdr(level)
187
+ end
188
+ end
189
+
190
+ ## Extends the TypeVector class with generation of hdr text.
191
+ class TypeVector
192
+
193
+ # Generates the text of the equivalent hdr text.
194
+ # +level+ is the hierachical level of the object.
195
+ def to_hdr(level = 0)
196
+ # The resulting string.
197
+ res = ""
198
+ # Generate the base.
199
+ res << self.base.to_hdr(level)
200
+ # Generate the range.
201
+ res << "[" << self.range.first.to_hdr(level) << ".." <<
202
+ self.range.last.to_hdr(level) << "]"
203
+ # Return the result.
204
+ return res
205
+ end
206
+ end
207
+
208
+ ## Extends the TypeTuple class with generation of hdr text.
209
+ class TypeTuple
210
+
211
+ # Generates the text of the equivalent hdr text.
212
+ # +level+ is the hierachical level of the object.
213
+ def to_hdr(level = 0)
214
+ # The resulting string.
215
+ res = "["
216
+ # Generate each sub type.
217
+ res << self.each_type.map { |type| type.to_hdr(level) }.join(", ")
218
+ # Close the tuple.
219
+ res << "]"
220
+ # Return the result.
221
+ return res
222
+ end
223
+ end
224
+
225
+ ## Extends the TypeStruct class with generation of hdr text.
226
+ class TypeStruct
227
+
228
+ # Generates the text of the equivalent hdr text.
229
+ # +level+ is the hierachical level of the object.
230
+ def to_hdr(level = 0)
231
+ # The resulting string.
232
+ res = "{ "
233
+ # Generate each sub type.
234
+ res << self.each.map do |key,type|
235
+ "#{key}: " + type.to_hdr(level)
236
+ end.join(", ")
237
+ # Close the struct.
238
+ res << " }"
239
+ # Return the result.
240
+ return res
241
+ end
242
+ end
243
+
244
+
245
+ ## Extends the Behavior class with generation of hdr text.
246
+ class Behavior
247
+
248
+ # Generates the text of the equivalent hdr text.
249
+ # +level+ is the hierachical level of the object and +timed+
250
+ # tells if the behavior is a time behavior or not.
251
+ def to_hdr(level = 0,timed = false)
252
+ # The resulting string.
253
+ res = " " * (level*3)
254
+ # Generate the header.
255
+ if timed then
256
+ res << "timed"
257
+ else
258
+ res << self.block.mode.to_s
259
+ end
260
+ if self.each_event.any? then
261
+ res << "( "
262
+ res << self.each_event.map do |event|
263
+ event.to_hdr(level)
264
+ end.join(", ")
265
+ res << " )"
266
+ end
267
+ res << " do\n"
268
+ # Generate the content.
269
+ res << self.block.to_hdr(level+1,false)
270
+ # Close the behavior.
271
+ res << " " * (level*3) << "end\n"
272
+ # Return the result.
273
+ return res
274
+ end
275
+ end
276
+
277
+ ## Extends the TimeBehavior class with generation of hdr text.
278
+ class TimeBehavior
279
+
280
+ # Generates the text of the equivalent hdr text.
281
+ # +level+ is the hierachical level of the object.
282
+ def to_hdr(level = 0)
283
+ super(level,true)
284
+ end
285
+ end
286
+
287
+
288
+ ## Extends the Event class with generation of hdr text.
289
+ class Event
290
+
291
+ # Generates the text of the equivalent hdr text.
292
+ # +level+ is the hierachical level of the object.
293
+ def to_hdr(level = 0)
294
+ return self.ref.to_hdr(level) + ".#{self.type}"
295
+ end
296
+ end
297
+
298
+
299
+ ## Extends the SignalI class with generation of hdr text.
300
+ class SignalI
301
+
302
+ # Generates the text of the equivalent hdr text.
303
+ # +level+ is the hierachical level of the object.
304
+ def to_hdr(level = 0)
305
+ return Low2HDR.hdr_use_name(self.name)
306
+ end
307
+ end
308
+
309
+
310
+ ## Extends the SystemI class with generation of hdr text.
311
+ class SystemI
312
+
313
+ # Generates the text of the equivalent hdr text.
314
+ # +level+ is the hierachical level of the object.
315
+ def to_hdr(level = 0)
316
+ return Low2HDR.hdr_call_name(self.systemT.name,
317
+ ":" + Low2HDR.hdr_decl_name(self.name))
318
+ end
319
+ end
320
+
321
+
322
+ ## Extends the Statement class with generation of hdr text.
323
+ class Statement
324
+
325
+ # Generates the text of the equivalent hdr text.
326
+ # +level+ is the hierachical level of the object.
327
+ def to_hdr(level = 0)
328
+ # Should never be here.
329
+ raise AnyError, "Internal error: to_high should be implemented in class :#{self.class}"
330
+ end
331
+ end
332
+
333
+ ## Extends the Transmit class with generation of hdr text.
334
+ class Transmit
335
+
336
+ # Generates the text of the equivalent hdr text.
337
+ # +level+ is the hierachical level of the object.
338
+ def to_hdr(level = 0)
339
+ return " " * (level*3) +
340
+ self.left.to_hdr(level) + " <= " +
341
+ self.right.to_hdr(level) + "\n"
342
+ end
343
+ end
344
+
345
+ ## Extends the If class with generation of hdr text.
346
+ class If
347
+
348
+ # Generates the text of the equivalent hdr text.
349
+ # +level+ is the hierachical level of the object.
350
+ def to_hdr(level = 0)
351
+ # The result string.
352
+ res = " " * (level*3)
353
+ # Generate the test.
354
+ res << "hif " << self.condition.to_hdr(level) << " do\n"
355
+ # Generate the yes part.
356
+ res << self.yes.to_hdr(level+1)
357
+ res << " " * (level*3) << "end\n"
358
+ # Generate the alternate if parts.
359
+ self.each_noif do |cond,stmnt|
360
+ res << " " * (level*3)
361
+ res << "helsif " << cond.to_hdr(level) << " do\n"
362
+ res << stmnt.to_hdr(level+1)
363
+ res << " " * (level*3) << "end\n"
364
+ end
365
+ # Generate the no part if any.
366
+ if self.no then
367
+ res << " " * (level*3)
368
+ res << "helse do\n" << self.no.to_hdr(level+1)
369
+ res << " " * (level*3) << "end\n"
370
+ end
371
+ # Return the result.
372
+ return res
373
+ end
374
+ end
375
+
376
+ ## Extends the When class with generation of hdr text.
377
+ class When
378
+
379
+ # Generates the text of the equivalent hdr text.
380
+ # +level+ is the hierachical level of the object.
381
+ def to_hdr(level = 0)
382
+ # The result string.
383
+ res = " " * (level*3)
384
+ # Generate the match.
385
+ res << "hwhen " << self.match.to_hdr(level+1) << " do\n"
386
+ # Generate the statement.
387
+ res << self.statement.to_hdr(level+1)
388
+ # Close the when.
389
+ res << " " * (level*3) << "end\n"
390
+ # Returns the result.
391
+ return res
392
+ end
393
+ end
394
+
395
+ ## Extends the Case class with generation of hdr text.
396
+ class Case
397
+
398
+ # Generates the text of the equivalent hdr text.
399
+ # +level+ is the hierachical level of the object.
400
+ def to_hdr(level = 0)
401
+ # The result string.
402
+ res = " " * (level*3)
403
+ # Generate the test.
404
+ res << "hcase " << self.value.to_hdr(level) << "\n"
405
+ # Generate the whens.
406
+ self.each_when do |w|
407
+ res << w.to_hdr(level)
408
+ end
409
+ # Generatethe default.
410
+ if self.default then
411
+ res << " " * (level*3)
412
+ res << "helse do\n"
413
+ res << self.default.to_hdr(level+1)
414
+ res << " " * (level*3)
415
+ res << "end\n"
416
+ end
417
+ # Return the resulting string.
418
+ return res
419
+ end
420
+ end
421
+
422
+
423
+ ## Extends the Delay class with generation of hdr text.
424
+ class Delay
425
+
426
+ # Generates the text of the equivalent hdr text.
427
+ # +level+ is the hierachical level of the object.
428
+ def to_hdr(level = 0)
429
+ return self.value.to_hdr(level) + ".#{self.unit}"
430
+ end
431
+ end
432
+
433
+
434
+ ## Extends the TimeWait class with generation of hdr text.
435
+ class TimeWait
436
+
437
+ # Generates the text of the equivalent hdr text.
438
+ # +level+ is the hierachical level of the object.
439
+ def to_hdr(level = 0)
440
+ # The resulting string.
441
+ res = " " * (level*3)
442
+ # Generate the wait.
443
+ res << "wait " << self.delay.to_hdr(level) << "\n"
444
+ # Return the resulting string.
445
+ return res
446
+ end
447
+ end
448
+
449
+ ## Extends the TimeRepeat class with generation of hdr text.
450
+ class TimeRepeat
451
+
452
+ # Generates the text of the equivalent hdr text.
453
+ # +level+ is the hierachical level of the object.
454
+ def to_hdr(level = 0)
455
+ # The resulting string.
456
+ res = " " * (level*3)
457
+ # Generate the header.
458
+ res << "repeat " << self.delay.to_hdr(level) << " do\n"
459
+ # Generate the statement to repeat.
460
+ res << self.statement.to_hdr(level+1)
461
+ # Close the repeat.
462
+ res << " " * (level*3) << "end\n"
463
+ # Return the resulting string.
464
+ return res
465
+ end
466
+ end
467
+
468
+ ## Extends the Block class with generation of hdr text.
469
+ class Block
470
+
471
+ # Generates the text of the equivalent hdr text.
472
+ # +level+ is the hierachical level of the object.
473
+ # +header+ tells if the header is to generate or not.
474
+ # +timed+ tells if its a timed block.
475
+ def to_hdr(level = 0, header = true, timed = false)
476
+ # The resulting string.
477
+ res = ""
478
+ # Generate the header if required.
479
+ if header then
480
+ if timed then
481
+ res << " " * (level*3) << "timed "
482
+ else
483
+ res << " " * (level*3) << "#{self.mode} "
484
+ end
485
+ unless self.name.empty? then
486
+ res << ":" << Low2HDR.hdr_decl_name(self.name) << " "
487
+ end
488
+ res << "do\n"
489
+ end
490
+ level = level + 1 if header
491
+ # Generate the inners declaration.
492
+ self.each_inner do |inner|
493
+ res << " " * (level*3)
494
+ res << inner.type.to_hdr(level)
495
+ res << ".inner :" << Low2HDR.hdr_decl_name(inner.name) << "\n"
496
+ end
497
+ # Generate the statements.
498
+ self.each_statement do |stmnt|
499
+ res << stmnt.to_hdr(level)
500
+ end
501
+ # Close the block.
502
+ if header then
503
+ res << " " * ((level-1)*3) << "end\n"
504
+ end
505
+ # Return the result.
506
+ return res
507
+ end
508
+ end
509
+
510
+ ## Extends the TimeBlock class with generation of hdr text.
511
+ class TimeBlock
512
+
513
+ # Generates the text of the equivalent hdr text.
514
+ # +level+ is the hierachical level of the object.
515
+ def to_hdr(level = 0, header = true)
516
+ super(level,header,true)
517
+ end
518
+ end
519
+
520
+
521
+ ## Extends the Code class with generation of hdr text.
522
+ class Code
523
+
524
+ # Generates the text of the equivalent hdr text.
525
+ # +level+ is the hierachical level of the object.
526
+ def to_hdr(level = 0)
527
+ return self.content.to_s
528
+ end
529
+ end
530
+
531
+ ## Extends the Connection class with generation of hdr text.
532
+ class Connection
533
+ # Nothing required, Transmit is generated identically.
534
+ end
535
+
536
+
537
+ ## Extends the Expression class with generation of hdr text.
538
+ class Expression
539
+
540
+ # Generates the text of the equivalent hdr text.
541
+ # +level+ is the hierachical level of the object.
542
+ def to_hdr(level = 0)
543
+ # Should never be here.
544
+ raise AnyError, "Internal error: to_high should be implemented in class :#{self.class}"
545
+ end
546
+ end
547
+
548
+ ## Extends the Value class with generation of hdr text.
549
+ class Value
550
+
551
+ # Generates the text of the equivalent hdr text.
552
+ # +level+ is the hierachical level of the object.
553
+ def to_hdr(level = 0)
554
+ if self.content.is_a?(HDLRuby::BitString) then
555
+ return "_#{self.content}"
556
+ else
557
+ return self.content.to_s
558
+ end
559
+ end
560
+ end
561
+
562
+ ## Extends the Cast class with generation of hdr text.
563
+ class Cast
564
+
565
+ # Generates the text of the equivalent hdr text.
566
+ # +level+ is the hierachical level of the object.
567
+ def to_hdr(level = 0)
568
+ return self.child.to_hdr(level) +
569
+ ".as(" + self.type.to_hdr(level) + ")"
570
+ end
571
+ end
572
+
573
+ ## Extends the Operation class with generation of hdr text.
574
+ class Operation
575
+
576
+ # Generates the text of the equivalent hdr text.
577
+ # +level+ is the hierachical level of the object.
578
+ def to_hdr(level = 0)
579
+ # Should never be here.
580
+ raise AnyError, "Internal error: to_high should be implemented in class :#{self.class}"
581
+ end
582
+ end
583
+
584
+ ## Extends the Unary class with generation of hdr text.
585
+ class Unary
586
+
587
+ # Generates the text of the equivalent hdr text.
588
+ # +level+ is the hierachical level of the object.
589
+ def to_hdr(level = 0)
590
+ return "(#{self.operator.to_s[0]}" + self.child.to_hdr(level) + ")"
591
+ end
592
+ end
593
+
594
+ ## Extends the Binary class with generation of hdr text.
595
+ class Binary
596
+
597
+ # Generates the text of the equivalent hdr text.
598
+ # +level+ is the hierachical level of the object.
599
+ def to_hdr(level = 0)
600
+ return "(" + self.left.to_hdr(level) + self.operator.to_s +
601
+ self.right.to_hdr(level) + ")"
602
+ end
603
+ end
604
+
605
+ ## Extends the Select class with generation of hdr text.
606
+ class Select
607
+
608
+ # Generates the text of the equivalent hdr text.
609
+ # +level+ is the hierachical level of the object.
610
+ def to_hdr(level = 0)
611
+ # The resulting string.
612
+ res = ""
613
+ # Generate the header.
614
+ res << "mux(" + self.select.to_hdr(level) << ", "
615
+ # Generate the choices
616
+ res << self.each_choice.map do |choice|
617
+ choice.to_hdr(level+1)
618
+ end.join(", ")
619
+ # Close the select.
620
+ res << ")"
621
+ # Return the resulting string.
622
+ return res
623
+ end
624
+ end
625
+
626
+ ## Extends the Concat class with generation of hdr text.
627
+ class Concat
628
+
629
+ # Generates the text of the equivalent hdr text.
630
+ # +level+ is the hierachical level of the object.
631
+ def to_hdr(level = 0)
632
+ # The resulting string.
633
+ res = ""
634
+ # Generate the header.
635
+ res << "[ "
636
+ # Generate the expressions.
637
+ res << self.each_expression.map do |expression|
638
+ expression.to_hdr(level+1)
639
+ end.join(", ")
640
+ # Close the select.
641
+ res << " ]"
642
+ # Return the resulting string.
643
+ return res
644
+ end
645
+ end
646
+
647
+
648
+ ## Extends the Ref class with generation of hdr text.
649
+ class Ref
650
+
651
+ # Generates the text of the equivalent hdr text.
652
+ # +level+ is the hierachical level of the object.
653
+ def to_hdr(level = 0)
654
+ # Should never be here.
655
+ raise AnyError, "Internal error: to_high should be implemented in class :#{self.class}"
656
+ end
657
+ end
658
+
659
+ ## Extends the RefConcat class with generation of hdr text.
660
+ class RefConcat
661
+
662
+ # Generates the text of the equivalent hdr text.
663
+ # +level+ is the hierachical level of the object.
664
+ def to_hdr(level = 0)
665
+ # The resulting string.
666
+ res = ""
667
+ # Generate the header.
668
+ res << "[ "
669
+ # Generate the references.
670
+ res << self.each_ref.map do |ref|
671
+ ref.to_hdr(level+1)
672
+ end.join(", ")
673
+ # Close the select.
674
+ res << " ]"
675
+ # Return the resulting string.
676
+ return res
677
+ end
678
+ end
679
+
680
+ ## Extends the RefIndex class with generation of hdr text.
681
+ class RefIndex
682
+
683
+ # Generates the text of the equivalent hdr text.
684
+ # +level+ is the hierachical level of the object.
685
+ def to_hdr(level = 0)
686
+ return self.ref.to_hdr(level) + "[#{self.index.to_hdr(level)}]"
687
+ end
688
+ end
689
+
690
+ ## Extends the RefRange class with generation of hdr text.
691
+ class RefRange
692
+
693
+ # Generates the text of the equivalent hdr text.
694
+ # +level+ is the hierachical level of the object.
695
+ def to_hdr(level = 0)
696
+ return self.ref.to_hdr(level) +
697
+ "[(#{self.range.first.to_hdr(level)})..(#{self.range.last.to_hdr(level)})]"
698
+ end
699
+ end
700
+
701
+ ## Extends the RefName class with generation of hdr text.
702
+ class RefName
703
+
704
+ # Generates the text of the equivalent hdr text.
705
+ # +level+ is the hierachical level of the object.
706
+ def to_hdr(level = 0)
707
+ # The resulting string.
708
+ res = ""
709
+ # Generates the sub reference if any.
710
+ res << self.ref.to_hdr(level) << "." unless self.ref.is_a?(RefThis)
711
+ # Generates the current reference.
712
+ res << Low2HDR.hdr_use_name(self.name)
713
+ # Returns the resulting string.
714
+ return res
715
+ end
716
+ end
717
+
718
+ ## Extends the RefThis class with generation of hdr text.
719
+ class RefThis
720
+
721
+ # Generates the text of the equivalent hdr text.
722
+ # +level+ is the hierachical level of the object.
723
+ def to_hdr(level = 0)
724
+ return ""
725
+ end
726
+ end
727
+
728
+ ## Extends the Numeric class with generation of hdr text.
729
+ class ::Numeric
730
+
731
+ # Generates the text of the equivalent hdr text.
732
+ # +level+ is the hierachical level of the object.
733
+ def to_hdr(level = 0)
734
+ return self.to_s
735
+ end
736
+ end
737
+
738
+ end