Class: AutoC::Type
Constant Summary
collapse
- CommonCode =
Class.new(Code) do
def write_intf(stream)
stream << %$
#ifndef AUTOC_INLINE
#ifdef _MSC_VER
#define AUTOC_INLINE __inline
#elif __STDC_VERSION__ >= 199901L
#define AUTOC_INLINE inline AUTOC_STATIC
#else
#define AUTOC_INLINE AUTOC_STATIC
#endif
#endif
#ifndef AUTOC_EXTERN
#ifdef __cplusplus
#define AUTOC_EXTERN extern "C"
#else
#define AUTOC_EXTERN extern
#endif
#endif
#ifndef AUTOC_STATIC
#ifdef _MSC_VER
#define AUTOC_STATIC __pragma(warning(suppress:4100)) static
#elif defined(__GNUC__)
#define AUTOC_STATIC __attribute__((__used__)) static
#else
#define AUTOC_STATIC static
#endif
#endif
#include <stddef.h>
#include <stdlib.h>
#include <assert.h>
$
end
def write_decls(stream)
stream << %$
#include <limits.h>
#define AUTOC_MIN(a,b) ((a) > (b) ? (b) : (a))
#define AUTOC_MAX(a,b) ((a) > (b) ? (a) : (b))
#define AUTOC_RCYCLE(x) (((x) << 1) | ((x) >> (sizeof(x)*CHAR_BIT - 1))) /* NOTE : valid for unsigned types only */
$
end
end.new
Instance Attribute Summary collapse
Instance Method Summary
collapse
Methods inherited from Code
#attach, #priority, #source_size
Constructor Details
#initialize(type, visibility = :public) ⇒ Type
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
#method_missing(method, *args) ⇒ Object
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] if args.empty?
func elsif args.size == 1 && args.first == nil
func + "()" else
func + "(" + args.join(", ") + ")" end
end
|
Instance Attribute Details
#type ⇒ Object
Returns the value of attribute type.
53
54
55
|
# File 'lib/autoc/type.rb', line 53
def type
@type
end
|
Instance Method Details
#abort ⇒ Object
122
|
# File 'lib/autoc/type.rb', line 122
def abort; "abort" end
|
#assert ⇒ Object
114
|
# File 'lib/autoc/type.rb', line 114
def assert; "assert" end
|
#calloc ⇒ Object
118
|
# File 'lib/autoc/type.rb', line 118
def calloc; "calloc" end
|
#entities ⇒ Object
55
|
# File 'lib/autoc/type.rb', line 55
def entities; [CommonCode] end
|
#extern ⇒ Object
108
|
# File 'lib/autoc/type.rb', line 108
def extern; "AUTOC_EXTERN" end
|
#free ⇒ Object
120
|
# File 'lib/autoc/type.rb', line 120
def free; "free" end
|
#inline ⇒ Object
110
|
# File 'lib/autoc/type.rb', line 110
def inline; "AUTOC_INLINE" end
|
#malloc ⇒ Object
116
|
# File 'lib/autoc/type.rb', line 116
def malloc; "malloc" end
|
#static ⇒ Object
112
|
# File 'lib/autoc/type.rb', line 112
def static; "AUTOC_STATIC" end
|
#write_decls(stream) ⇒ Object
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
|
#write_defs(stream) ⇒ Object
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
|
#write_exported_declarations(stream, declare, define) ⇒ Object
104
|
# File 'lib/autoc/type.rb', line 104
def write_exported_declarations(stream, declare, define) end
|
#write_exported_types(stream) ⇒ Object
102
|
# File 'lib/autoc/type.rb', line 102
def write_exported_types(stream) end
|
#write_implementations(stream, define) ⇒ Object
106
|
# File 'lib/autoc/type.rb', line 106
def write_implementations(stream, define) end
|
#write_intf(stream) ⇒ Object
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
|