Class: BOAST::If
- Inherits:
-
ControlStructure
- Object
- ControlStructure
- BOAST::If
- Defined in:
- lib/BOAST/If.rb
Constant Summary collapse
- @@c_strings =
{ :if => '"if (#{cond}) {"', :else_if => '"} else if (#{cond}) {"', :else => '"} else {"', :end => '"}"' }
- @@f_strings =
{ :if => '"if (#{cond}) then"', :elsif => '"else if (#{cond}) then"', :else => '"else"', :end => '"end if"' }
- @@strings =
{ C => @@c_strings, CL => @@c_strings, CUDA => @@c_strings, FORTRAN => @@f_strings }
Instance Attribute Summary collapse
-
#conditions ⇒ Object
readonly
Returns the value of attribute conditions.
Instance Method Summary collapse
- #close ⇒ Object
-
#initialize(*conditions, &block) ⇒ If
constructor
A new instance of If.
- #open ⇒ Object
- #pr(*args) ⇒ Object
- #to_s(condition_number = 0) ⇒ Object
Methods inherited from ControlStructure
inherited, token_string_generator
Methods included from Inspectable
Methods included from PrivateStateAccessor
private_boolean_state_accessor, private_state_accessor
Constructor Details
#initialize(*conditions, &block) ⇒ If
Returns a new instance of If.
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/BOAST/If.rb', line 7 def initialize(*conditions, &block) @conditions = [] @blocks = [] if conditions.size == 0 then raise "Illegal if construct!" elsif conditions.size == 1 then @conditions.push(conditions[0]) @blocks.push(block) elsif conditions.size.even? then (0..conditions.size-1).step(2) { |i| @conditions[i/2] = conditions[i] @blocks[i/2] = conditions[i+1] } else (0..conditions.size-2).step(2) { |i| @conditions[i/2] = conditions[i] @blocks[i/2] = conditions[i+1] } @blocks.push(conditions.last) end end |
Instance Attribute Details
#conditions ⇒ Object (readonly)
Returns the value of attribute conditions.
5 6 7 |
# File 'lib/BOAST/If.rb', line 5 def conditions @conditions end |
Instance Method Details
#close ⇒ Object
97 98 99 100 101 102 103 104 |
# File 'lib/BOAST/If.rb', line 97 def close decrement_indent_level s = "" s += indent s += end_string output.puts s return self end |
#open ⇒ Object
69 70 71 72 73 74 75 76 |
# File 'lib/BOAST/If.rb', line 69 def open s="" s += indent s += to_s output.puts s increment_indent_level return self end |
#pr(*args) ⇒ Object
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 |
# File 'lib/BOAST/If.rb', line 78 def pr(*args) if @blocks.size > 0 then increment_indent_level @blocks.each_index { |indx| decrement_indent_level s="" s += indent s += to_s(indx) output.puts s increment_indent_level @blocks[indx].call(*args) } close else open end return self end |
#to_s(condition_number = 0) ⇒ Object
55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/BOAST/If.rb', line 55 def to_s(condition_number = 0) s = "" if condition_number == 0 then s += if_string(@conditions.first) else if @conditions[condition_number] then s += elsif_string(@conditions[condition_number]) else s += else_string end end return s end |