class BOAST::Dim
Attributes
size[R]
val1[R]
val2[R]
Public Class Methods
new(v1=nil,v2=nil)
click to toggle source
Creates a new {Dimension}. @overload initialize()
Creates a {Dimension} of unknown {#size}, used to declare an array of unknown size.
@overload initialize( size )
Creates a {Dimension} of size *size*, {#start} is computed at evaluation as {BOAST.get_array_start}. @param [Object] size can be an integer or a {Variable} or {Expression}
@overload initialize( lower, upper )
Creates a {Dimension} with a lower and upper bound. {#size} is computed as 'upper - lower + 1' and can be an {Expression} @param [Object] lower bound of the {Dimension} @param [Object] upper bound of the {Dimension}
# File lib/BOAST/Language/Variable.rb, line 23 def initialize(v1=nil,v2=nil) if v1 then if v2 then begin @size = v2-v1+1 rescue @size = Expression::new(Subtraction, v2, v1) + 1 end else @size = v1 end else @size = nil end @val1 = v1 @val2 = v2 end
Public Instance Methods
finish()
click to toggle source
Returns the end of the {Dimension} if the size is known.
# File lib/BOAST/Language/Variable.rb, line 64 def finish if @val2 then return @val2 elsif @size if 0.equal?(get_array_start) then return @size - 1 else if 1.equal?(get_array_start) then return @size else begin return @size + get_array_start - 1 rescue return Expression::new(Addition, @size, get_array_start) - 1 end end end else return nil end end
start()
click to toggle source
Returns the start of the {Dimension} as given at initialization or as computed {BOAST.get_array_start}.
# File lib/BOAST/Language/Variable.rb, line 55 def start if @val2 then return @val1 else return get_array_start end end
to_s()
click to toggle source
Returns a String representation of the {Dimension}
# File lib/BOAST/Language/Variable.rb, line 42 def to_s if lang == FORTRAN and @val2 then return "#{@val1}:#{@val2}" elsif lang == FORTRAN and size.nil? return "*" elsif lang == FORTRAN and get_array_start != 1 then return "#{get_array_start}:#{@size-(1+get_array_start)}" else return @size.to_s end end