Class: LazyPP::OperDecl

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(n, s, b, p) ⇒ OperDecl

Returns a new instance of OperDecl.



780
781
782
783
784
785
# File 'lib/readable-cpp/nodes.rb', line 780

def initialize n,s,b,p
  self.name = n
  self.body = b
  self.pos = p
  self.sig = s
end

Instance Attribute Details

#posObject

Returns the value of attribute pos.



779
780
781
# File 'lib/readable-cpp/nodes.rb', line 779

def pos
  @pos
end

Instance Method Details

#decl_header(rs, qualify) ⇒ Object



805
806
807
808
809
810
811
812
813
814
815
816
817
# File 'lib/readable-cpp/nodes.rb', line 805

def decl_header rs, qualify
  n = 'operator ' + if name == :implicit
    sig.base_cpp(rs)+(sig.derived_cpp(rs)%'')
  else
    name.to_cpp(rs)
  end
  n.prepend rs.parent.name.to_cpp(rs)+'::' if qualify && !rs.parent.nil?
  
  rs.indentation +
  (name == :implicit ?
    n :
    sig.base_cpp(rs) + ' ' + (sig.derived_cpp(rs) % n))
end

#name=(val) ⇒ Object



786
787
788
789
# File 'lib/readable-cpp/nodes.rb', line 786

def name= val
  @name=val.to_s
  @name=:implicit if name =~ /implicit/i
end

#sig=(val) ⇒ Object



790
791
792
793
794
795
796
797
798
799
800
801
802
803
# File 'lib/readable-cpp/nodes.rb', line 790

def sig= val
  if pos == "post"
    if not val.derived[0][:args] == 'void'
      ## postfix operator with args, find a better way to deal with this later
      binding.pry
    else
      val.derived[0][:args] = Type.new(:int, nil, nil)
    end
  end
  @sig = val
rescue ##one day i'll make :args to a FunctionArgs node
  ##on that day bindings will be pried
  binding.pry
end

#to_cpp(rs) ⇒ Object



818
819
820
# File 'lib/readable-cpp/nodes.rb', line 818

def to_cpp rs
  decl_header(rs, true) + (body.nil? ? ?; : "\n#{rs.indentation}{\n#{body.to_cpp rs.indent}\n#{rs.indentation}}")
end

#to_hpp(rs) ⇒ Object



821
822
823
# File 'lib/readable-cpp/nodes.rb', line 821

def to_hpp rs
  decl_header(rs, false) + ?;
end