Class: C::Declaration

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



62
63
64
65
66
67
68
69
70
71
# File 'lib/cast/parse.rb', line 62

def self.parse(s, parser=nil)
  parser ||= C.default_parser
  ents = parser.parse(s).entities
  if ents.length == 1 &&          # int i; int j;
      ents[0].is_a?(Declaration)  # void f() {}
    return ents[0].detach
  else
    raise ParseError, "invalid Declaration"
  end
end

Instance Method Details

#auto?Boolean

Returns:

  • (Boolean)


156
157
158
# File 'lib/cast/c_nodes.rb', line 156

def auto?
  storage.equal? :auto
end

#extern?Boolean

Returns:

  • (Boolean)


150
151
152
# File 'lib/cast/c_nodes.rb', line 150

def extern?
  storage.equal? :extern
end

#register?Boolean

Returns:

  • (Boolean)


159
160
161
# File 'lib/cast/c_nodes.rb', line 159

def register?
  storage.equal? :register
end

#static?Boolean

Returns:

  • (Boolean)


153
154
155
# File 'lib/cast/c_nodes.rb', line 153

def static?
  storage.equal? :static
end

#to_sObject



35
36
37
38
39
40
41
42
43
44
# File 'lib/cast/to_s.rb', line 35

def to_s
  str = ''
  inline? and str << "inline "
  storage and str << "#{storage} "
  if declarators.empty?
    return str << "#{type};"
  else
    return str << "#{type} " << declarators.join(', ') << ';'
  end
end

#typedef?Boolean

Returns:

  • (Boolean)


147
148
149
# File 'lib/cast/c_nodes.rb', line 147

def typedef?
  storage.equal? :typedef
end