Class: BOAST::While

Inherits:
ControlStructure show all
Includes:
Annotation
Defined in:
lib/BOAST/Language/While.rb

Constant Summary collapse

ANNOTATIONS =
[ :condition ]

Instance Attribute Summary collapse

Attributes inherited from ControlStructure

#args

Instance Method Summary collapse

Methods included from Annotation

#annotate_array, #annotate_indepth?, #annotate_scalar, #annotate_var, #annotation, #annotation_identifier

Methods included from PrivateStateAccessor

#address_size, #address_size=, #annotate, #annotate=, #annotate?, #annotate_indepth_list, #annotate_indepth_list=, #annotate_level, #annotate_level=, #annotate_list, #annotate_list=, #architecture, #architecture=, #array_start, #array_start=, #chain_code, #chain_code=, #chain_code?, #debug, #debug=, #debug?, #debug_kernel_source, #debug_kernel_source=, #debug_kernel_source?, #debug_source, #debug_source=, #debug_source?, #decl_module, #decl_module=, #decl_module?, #default_align, #default_align=, #default_int_signed, #default_int_signed=, #default_int_signed?, #default_int_size, #default_int_size=, #default_real_size, #default_real_size=, #default_type, #default_type=, #disable_openmp, #disable_openmp=, #disable_openmp?, #executable, #executable=, #executable?, #ffi, #ffi=, #ffi?, #fortran_line_length, #fortran_line_length=, #get_address_size, #get_annotate, #get_annotate_indepth_list, #get_annotate_level, #get_annotate_list, #get_architecture, #get_array_start, #get_chain_code, #get_debug, #get_debug_kernel_source, #get_debug_source, #get_decl_module, #get_default_align, #get_default_int_signed, #get_default_int_size, #get_default_real_size, #get_default_type, #get_disable_openmp, #get_executable, #get_ffi, #get_fortran_line_length, #get_indent_increment, #get_indent_level, #get_keep_temp, #get_lang, #get_model, #get_optimizer_log, #get_optimizer_log_file, #get_output, #get_replace_constants, #get_synchro, #get_use_vla, #get_verbose, #indent_increment, #indent_increment=, #indent_level, #indent_level=, #keep_temp, #keep_temp=, #keep_temp?, #lang, #lang=, #model, #model=, #optimizer_log, #optimizer_log=, #optimizer_log?, #optimizer_log_file, #optimizer_log_file=, #output, #output=, #replace_constants, #replace_constants=, #replace_constants?, #set_address_size, #set_annotate, #set_annotate_indepth_list, #set_annotate_level, #set_annotate_list, #set_architecture, #set_array_start, #set_chain_code, #set_debug, #set_debug_kernel_source, #set_debug_source, #set_decl_module, #set_default_align, #set_default_int_signed, #set_default_int_size, #set_default_real_size, #set_default_type, #set_disable_openmp, #set_executable, #set_ffi, #set_fortran_line_length, #set_indent_increment, #set_indent_level, #set_keep_temp, #set_lang, #set_model, #set_optimizer_log, #set_optimizer_log_file, #set_output, #set_replace_constants, #set_synchro, #set_use_vla, #set_verbose, #synchro, #synchro=, #use_vla, #use_vla=, #use_vla?, #verbose, #verbose=, #verbose?

Methods inherited from ControlStructure

#[], inherited

Methods included from Inspectable

#inspect

Constructor Details

#initialize(condition, &block) ⇒ While

Creates a new instance of the While construct.

Parameters:

  • condition (Expression)
  • block (Proc, nil)

    if given, will be evaluated when #pr is called



13
14
15
16
17
# File 'lib/BOAST/Language/While.rb', line 13

def initialize(condition, &block)
  super()
  @condition = condition
  @block = block
end

Instance Attribute Details

#conditionObject (readonly)

Returns the value of attribute condition.



8
9
10
# File 'lib/BOAST/Language/While.rb', line 8

def condition
  @condition
end

Instance Method Details

#closeself

Closes the While construct (keyword, closing bracket in C like languages). The result is printed to the BOAST output.

Returns:

  • (self)


71
72
73
74
75
76
77
78
# File 'lib/BOAST/Language/While.rb', line 71

def close
  decrement_indent_level      
  s = ""
  s << indent
  s << end_string
  output.puts s
  return self
end

#openself

Opens the While construct (keyword, condition, opening bracket in C like languages). The result is printed to the BOAST output.

Returns:

  • (self)


44
45
46
47
48
49
50
51
# File 'lib/BOAST/Language/While.rb', line 44

def open
  s=""
  s << indent
  s << to_s
  output.puts s
  increment_indent_level
  return self
end

#pr(*args, &block) ⇒ self

Prints the While construct to the BOAST output (see #open). If a block is provided during initialization, it will be printed and the construct will be closed (see #close).

Parameters:

  • args (Array<Object>)

    any number of arguments to pass to the block

  • block (Proc)

    an optional block to be evaluated. Supersede the one given at initialization

Returns:

  • (self)


58
59
60
61
62
63
64
65
66
67
# File 'lib/BOAST/Language/While.rb', line 58

def pr(*args, &block)
  args = @args if args.length == 0 and @args
  block = @block unless block
  open
  if block then
    block.call(*args)
    close
  end
  return self
end

#to_sObject

Returns a string representation of the While construct.



38
39
40
# File 'lib/BOAST/Language/While.rb', line 38

def to_s
  return while_string(@condition)
end