Class: C::Member

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



159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
# File 'lib/cast/parse.rb', line 159

def self.parse(s, parser=nil)
  parser ||= C.default_parser
  ents = parser.parse("int f() {struct s x = {.#{s} = 1};}").entities
  if ents.length == 1                              &&  # a = 1};} int f() {struct s x = {a
      ents[0].def.stmts.length == 1                &&  # a = 1}; struct s y = {.a
      #ents[0].def.stmts[0].length == 1            &&  # a = 1}, x = {.a
      ents[0].def.stmts[0].declarators.length == 1 &&  # a = 1}, x = {.a
      ents[0].def.stmts[0].declarators[0].init.member_inits.length == 1 &&        # x = 1, y
      ents[0].def.stmts[0].declarators[0].init.member_inits[0].member   &&        # 1
      ents[0].def.stmts[0].declarators[0].init.member_inits[0].member.length == 1 # a .b
    return ents[0].def.stmts[0].declarators[0].init.member_inits[0].member[0].detach
  else
    raise ParseError, "invalid Member"
  end
end

Instance Method Details

#to_sObject



524
525
526
# File 'lib/cast/to_s.rb', line 524

def to_s
  name.dup
end