Class: BOAST::CStruct

Inherits:
Object show all
Defined in:
lib/BOAST/Algorithm.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(hash = {}) ⇒ CStruct

Returns a new instance of CStruct.



476
477
478
479
480
481
482
483
484
485
# File 'lib/BOAST/Algorithm.rb', line 476

def initialize(hash={})
  @name = hash[:type_name]
  @members = {}
  @members_array = []
  hash[:members].each { |m|
    mc = m.copy
    @members_array.push(mc)
    @members[mc.name] = mc
  }
end

Instance Attribute Details

#membersObject (readonly)

Returns the value of attribute members.



471
472
473
# File 'lib/BOAST/Algorithm.rb', line 471

def members
  @members
end

#members_arrayObject (readonly)

Returns the value of attribute members_array.



471
472
473
# File 'lib/BOAST/Algorithm.rb', line 471

def members_array
  @members_array
end

#nameObject (readonly)

Returns the value of attribute name.



471
472
473
# File 'lib/BOAST/Algorithm.rb', line 471

def name
  @name
end

Class Method Details

.parens(*args, &block) ⇒ Object



472
473
474
# File 'lib/BOAST/Algorithm.rb', line 472

def self.parens(*args,&block)
  return Variable::new(args[0], self, *args[1..-1], &block)
end

Instance Method Details

#declObject



487
488
489
490
# File 'lib/BOAST/Algorithm.rb', line 487

def decl
  return "struct #{@name}" if [C, CL, CUDA].include?( BOAST::get_lang )
  return "TYPE(#{@name})" if BOAST::get_lang == FORTRAN
end

#finalizeObject



492
493
494
495
496
497
# File 'lib/BOAST/Algorithm.rb', line 492

def finalize
   s = ""
   s += ";" if [C, CL, CUDA].include?( BOAST::get_lang )
   s+="\n"
   return s
end

#headerObject



503
504
505
506
507
# File 'lib/BOAST/Algorithm.rb', line 503

def header
  return header_c if [C, CL, CUDA].include?( BOAST::get_lang )
  return header_fortran if BOAST::get_lang == FORTRAN
  raise "Unsupported language!"
end

#header_c(final = true) ⇒ Object



509
510
511
512
513
514
515
516
517
518
519
520
521
522
# File 'lib/BOAST/Algorithm.rb', line 509

def header_c(final = true)
  s = ""
  s += self.indent if final
  s += self.decl + " {\n"
  @members_array.each { |value|
     s+= self.indent if final
     s+= " "*BOAST::get_indent_increment + value.decl(false)+";\n"
  }
  s += self.indent if final
  s += "}"
  s += self.finalize if final
  BOAST::get_output.print s if final
  return s
end

#header_fortran(final = true) ⇒ Object



524
525
526
527
528
529
530
531
532
533
534
535
536
537
# File 'lib/BOAST/Algorithm.rb', line 524

def header_fortran(final = true)
  s = ""
  s += self.indent if final
  s += "TYPE :: #{@name}\n"
  members_array.each { |value|
     s+= self.indent if final
     s+= " "*BOAST::get_indent_increment + value.decl(false)+"\n"
  }
  s += self.indent if final
  s += "END TYPE #{@name}"
  s += self.finalize if final
  BOAST::get_output.print s if final
  return s
end

#indentObject



499
500
501
# File 'lib/BOAST/Algorithm.rb', line 499

def indent
   return " "*BOAST::get_indent_level
end