Class: C::Parameter

Inherits:
Node
  • Object
show all
Defined in:
lib/cast/to_s.rb,
lib/cast/parse.rb,
lib/cast/c_nodes.rb,
lib/cast/c_nodes.rb

Constant Summary

Constants inherited from Node

Node::INSPECT_TAB

Instance Attribute Summary

Attributes inherited from Node

#parent, #pos, #subclasses

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Node

#==, #=~, abstract, add_field, #assert_invariants, #attached?, child, #clone, #depth_first, #detach, #detached?, #dup, #each, #eql?, field, #fields, fields, #hash, inherited, initializer, #insert_next, #insert_prev, #inspect, inspect1, #list_next, #list_prev, #match?, #method_missing, new_at, #next, #node_after, #node_before, #postorder, #preorder, #prev, #remove_node, #replace_node, #replace_with, #reverse_depth_first, #reverse_each, #reverse_postorder, #reverse_preorder, subclasses_recursive, #swap_with

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class C::Node

Class Method Details

.parse(s, parser = nil) ⇒ Object



75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
# File 'lib/cast/parse.rb', line 75

def self.parse(s, parser=nil)
  parser ||= C.default_parser
  ents = parser.parse("void f(#{s}) {}").entities
  if ents.length == 1              &&  # ) {} void (
      ents[0].is_a?(FunctionDef)   &&  # ); void(
      ents[0].type.params          &&  #
      ents[0].type.params.length <= 1  # x,y
    param = ents[0].type.params[0]
    if param.nil?
      return Parameter.new(Void.new)
    else
      return param.detach
    end
  else
    raise ParseError, "invalid Parameter"
  end
end

Instance Method Details

#to_sObject



478
479
480
481
482
483
484
485
# File 'lib/cast/to_s.rb', line 478

def to_s
  str = register? ? 'register ' : ''
  if type
    str << type.to_s(name)
  else
    str << name.to_s
  end
end