Class: AutoC::Type

Inherits:
Code
  • Object
show all
Defined in:
lib/autoc/type.rb

Direct Known Subclasses

Collection, UserDefinedType

Constant Summary

Instance Attribute Summary (collapse)

Instance Method Summary (collapse)

Methods inherited from Code

#attach, #priority, #source_size

Constructor Details

- (Type) initialize(type, visibility = :public)

Returns a new instance of Type



57
58
59
60
# File 'lib/autoc/type.rb', line 57

def initialize(type, visibility = :public)
  @type = type.to_s
  @visibility = [:public, :private, :static].include?(visibility) ? visibility : raise("unsupported visibility")
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

- (Object) method_missing(method, *args)



62
63
64
65
66
67
68
69
70
71
72
# File 'lib/autoc/type.rb', line 62

def method_missing(method, *args)
  str = method.to_s
  func = @type + str[0,1].capitalize + str[1..-1] # Ruby 1.8 compatible
  if args.empty?
    func # Emit bare function name
  elsif args.size == 1 && args.first == nil
    func + "()" # Use sole nil argument to emit function call with no arguments
  else
    func + "(" + args.join(", ") + ")" # Emit normal function call with supplied arguments
  end
end

Instance Attribute Details

- (Object) type (readonly)

Returns the value of attribute type



53
54
55
# File 'lib/autoc/type.rb', line 53

def type
  @type
end

Instance Method Details

- (Object) abort



122
# File 'lib/autoc/type.rb', line 122

def abort; "abort" end

- (Object) assert



114
# File 'lib/autoc/type.rb', line 114

def assert; "assert" end

- (Object) calloc



118
# File 'lib/autoc/type.rb', line 118

def calloc; "calloc" end

- (Object) entities



55
# File 'lib/autoc/type.rb', line 55

def entities; [CommonCode] end

- (Object) extern



108
# File 'lib/autoc/type.rb', line 108

def extern; "AUTOC_EXTERN" end

- (Object) free



120
# File 'lib/autoc/type.rb', line 120

def free; "free" end

- (Object) inline



110
# File 'lib/autoc/type.rb', line 110

def inline; "AUTOC_INLINE" end

- (Object) malloc



116
# File 'lib/autoc/type.rb', line 116

def malloc; "malloc" end

- (Object) static



112
# File 'lib/autoc/type.rb', line 112

def static; "AUTOC_STATIC" end

- (Object) write_decls(stream)



82
83
84
85
86
87
88
89
90
91
# File 'lib/autoc/type.rb', line 82

def write_decls(stream)
  case @visibility
    when :private
      write_exported_types(stream)
      write_exported_declarations(stream, extern, inline)
    when :static
      write_exported_types(stream)
      write_exported_declarations(stream, static, inline)
  end
end

- (Object) write_defs(stream)



93
94
95
96
97
98
99
100
# File 'lib/autoc/type.rb', line 93

def write_defs(stream)
  case @visibility
    when :public, :private
      write_implementations(stream, nil)
    when :static
      write_implementations(stream, static)
  end
end

- (Object) write_exported_declarations(stream, declare, define)



104
# File 'lib/autoc/type.rb', line 104

def write_exported_declarations(stream, declare, define) end

- (Object) write_exported_types(stream)



102
# File 'lib/autoc/type.rb', line 102

def write_exported_types(stream) end

- (Object) write_implementations(stream, define)



106
# File 'lib/autoc/type.rb', line 106

def write_implementations(stream, define) end

- (Object) write_intf(stream)



74
75
76
77
78
79
80
# File 'lib/autoc/type.rb', line 74

def write_intf(stream)
  case @visibility
    when :public
      write_exported_types(stream)
      write_exported_declarations(stream, extern, inline)
  end
end