Class: BOAST::CStruct

Inherits:
DataType show all
Defined in:
lib/BOAST/DataTypes.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from DataType

inherited

Methods included from PrivateStateAccessor

private_boolean_state_accessor, private_state_accessor

Constructor Details

#initialize(hash = {}) ⇒ CStruct

Returns a new instance of CStruct.



277
278
279
280
281
282
283
284
285
286
# File 'lib/BOAST/DataTypes.rb', line 277

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.



275
276
277
# File 'lib/BOAST/DataTypes.rb', line 275

def members
  @members
end

#members_arrayObject (readonly)

Returns the value of attribute members_array.



275
276
277
# File 'lib/BOAST/DataTypes.rb', line 275

def members_array
  @members_array
end

#nameObject (readonly)

Returns the value of attribute name.



275
276
277
# File 'lib/BOAST/DataTypes.rb', line 275

def name
  @name
end

Instance Method Details

#declObject



296
297
298
299
# File 'lib/BOAST/DataTypes.rb', line 296

def decl
  return decl_c if [C, CL, CUDA].include?( lang )
  return decl_fortran if lang == FORTRAN
end

#decl_cObject



288
289
290
# File 'lib/BOAST/DataTypes.rb', line 288

def decl_c
  return "struct #{@name}" if [C, CL, CUDA].include?( lang )
end

#decl_fortranObject



292
293
294
# File 'lib/BOAST/DataTypes.rb', line 292

def decl_fortran
  return "TYPE(#{@name})" if lang == FORTRAN
end

#defineObject



308
309
310
311
# File 'lib/BOAST/DataTypes.rb', line 308

def define
  return define_c if [C, CL, CUDA].include?( lang )
  return define_fortran if lang == FORTRAN
end

#define_cObject



313
314
315
316
317
318
319
320
321
322
323
324
325
# File 'lib/BOAST/DataTypes.rb', line 313

def define_c
  s = indent
  s += decl_c + " {"
  output.puts s
  @members_array.each { |value|
     value.decl
  }
  s = indent
  s += "}"
  s += finalize
  output.print s
  return self
end

#define_fortranObject



327
328
329
330
331
332
333
334
335
336
337
338
339
# File 'lib/BOAST/DataTypes.rb', line 327

def define_fortran
  s = indent
  s += "TYPE :: #{@name}\n"
  output.puts s
  @members_array.each { |value|
     value.decl
  }
  s = indent
  s += "END TYPE #{@name}"
  s += finalize
  output.print s
  return self
end

#finalizeObject



301
302
303
304
305
306
# File 'lib/BOAST/DataTypes.rb', line 301

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