class TypedSexp

Public Class Methods

new(*args) click to toggle source
Calls superclass method
# File lib/typed_sexp.rb, line 41
def initialize(*args)
  # TODO: should probably be CType.unknown
  @c_type = CType === args.last ? args.pop : nil
  super(*args)
end

Public Instance Methods

==(obj) click to toggle source
Calls superclass method
# File lib/typed_sexp.rb, line 22
def ==(obj)
  case obj
  when TypedSexp
    super && c_type == obj.c_type
  else
    false
  end
end
_set_c_type(o) click to toggle source
# File lib/typed_sexp.rb, line 37
def _set_c_type(o)
  @c_type = o
end
c_type() click to toggle source
# File lib/typed_sexp.rb, line 68
def c_type
  unless array_type? then
    defined?(@c_type) && @c_type
  else
    types = self.c_types.flatten.uniq

    if types.size > 1 then
      CType.hetero
    else
      CType.homo
    end
  end
end
c_type=(o) click to toggle source
# File lib/typed_sexp.rb, line 82
def c_type=(o)
  # HACK raise "You shouldn't call this on an #{first}" if array_type?
  # c_type is different in ruby2c than from sexp_processor. need renames
  raise "You shouldn't call this a second time, ever" unless
    @c_type.nil? or @c_type == CType.unknown
  _set_c_type(o)
end
c_types() click to toggle source
# File lib/typed_sexp.rb, line 90
def c_types
  raise "You shouldn't call this if not an #{@@array_types.join(' or ')}, was #{first} (#{self.inspect})" unless array_type?
  self.grep(Sexp).map { |x| x.c_type }
end
inspect() click to toggle source
# File lib/typed_sexp.rb, line 47
def inspect
  sexp_str = self.map {|x|x.inspect}.join(', ')
  c_type_str = (sexp_str.empty? ? "" : ", ") + "#{array_type? ? c_types.inspect : c_type}" unless c_type.nil?
  nnd = ")"
  nnd << ".line(#{line})" if line && ENV["VERBOSE"]
  "t(#{sexp_str}#{c_type_str}#{nnd}"
end
new(*stuff) click to toggle source
Calls superclass method
# File lib/typed_sexp.rb, line 31
def new(*stuff)
  r = super
  r.c_type = self.c_type if self.c_type
  r
end
pretty_print(q) click to toggle source
# File lib/typed_sexp.rb, line 55
def pretty_print(q)
  nnd = ")"
  nnd << ".line(#{line})" if line && ENV["VERBOSE"]

  q.group(1, 't(', nnd) do
    q.seplist(self) {|v| q.pp v }
    unless @c_type.nil? then
      q.text ", " unless self.empty?
      q.pp @c_type
    end
  end
end
to_a() click to toggle source
Calls superclass method
# File lib/typed_sexp.rb, line 95
def to_a
  result = super
  if defined?(@c_type) and not @c_type.nil? then
    result += [ @c_type ]
  end
  result
end
to_s() click to toggle source
# File lib/typed_sexp.rb, line 103
def to_s
  inspect
end