Class: LazyPP::ClassDecl

Inherits:
TypeDecl show all
Defined in:
lib/readable-cpp/nodes.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(n, t, b, p) ⇒ ClassDecl

Returns a new instance of ClassDecl.



344
345
346
# File 'lib/readable-cpp/nodes.rb', line 344

def initialize(n,t,b,p)
  self.name=n;self.type=t;self.body=b;self.parents=p
end

Instance Attribute Details

#bodyObject

Returns the value of attribute body.



343
344
345
# File 'lib/readable-cpp/nodes.rb', line 343

def body
  @body
end

#parentsObject

Returns the value of attribute parents.



343
344
345
# File 'lib/readable-cpp/nodes.rb', line 343

def parents
  @parents
end

Instance Method Details

#scan(p) ⇒ Object



348
# File 'lib/readable-cpp/nodes.rb', line 348

def scan p; body.scan(p) unless body.nil? end

#to_cpp(rs) ⇒ Object



355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
# File 'lib/readable-cpp/nodes.rb', line 355

def to_cpp rs
  #rs = rs.add_parent(self)
  ##rs = rs.new(parent: rs.p#rent<<self)
  "\#{\nto_hpp(rs.add_parent(self)) unless rs.gen_header?\n}\#{  ##mark it as generating headers so nested classes arent declared twice\nbody.to_cpp(rs.gen_header!.add_parent(self)){|n|\nif n.is_a?(VarDeclInitializer) || n.is_a?(VarDeclSimple) ||\n   n.instance_of?(TypeDecl) || n.is_a?(EnumDecl)\n  false\nelse\n  n\nend\n} unless body.nil?}\n  C++\nend\n"

#to_hpp(rs) ⇒ Object



372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
# File 'lib/readable-cpp/nodes.rb', line 372

def to_hpp(rs)
  rs = rs.add_parent(self)
  ##rs = rs.new parent: self
  "\#{rs.indentation}\#{type}\#{\" \#{name} \" if name}\#{\nunless parents.nil?\n  \": \#{parents.map { |p| \"\#{p[:vis].to_cpp(rs)} \#{p[:parent].to_cpp(rs)}\" }.join', '} \\n\"\nend\n}\#{if body.nil?\n';'\nelse\n\"\\n\#{rs.indentation}{\\n\#{body.to_hpp(rs.indent)}\\n\#{rs.indentation}};\"\nend}\n  C++\n  # \"\#{rs.indentation}\#{type} \#{name} \#{\n  #   \": \#{\n  #     parents.map { |p| \n  #       \"\#{p[:vis].to_cpp(rs)} \#{p[:parent].to_cpp(rs)}\"\n  #     }.join', '} \\n\" unless parents.nil?}\" +\n  #   (body.nil? ? ';' : \"{\\n\#{\n  #     body.to_hpp(rs.indent) unless body.nil?\n  #   }\\n\"\\\n  #   \"\#{rs.indentation}};\")\nend\n"

#type=(val) ⇒ Object



349
350
351
# File 'lib/readable-cpp/nodes.rb', line 349

def type= val
  @type = (val.to_s.downcase.intern rescue :class)
end