Class: AutoC::Type
Direct Known Subclasses
Instance Attribute Summary collapse
-
#type ⇒ Object
readonly
Returns the value of attribute type.
-
#type_ref ⇒ Object
readonly
Returns the value of attribute type_ref.
Class Method Summary collapse
Instance Method Summary collapse
- #==(other) ⇒ Object (also: #eql?)
- #abort ⇒ Object
- #assert ⇒ Object
- #calloc ⇒ Object
- #comparable? ⇒ Boolean
- #constructible? ⇒ Boolean
- #copyable? ⇒ Boolean
- #destructible? ⇒ Boolean
- #entities ⇒ Object
-
#extern ⇒ Object
def write_impls(stream, define).
- #free ⇒ Object
- #hash ⇒ Object
- #hashable? ⇒ Boolean
-
#initialize(type, visibility = :public) ⇒ Type
constructor
A new instance of Type.
- #inline ⇒ Object
- #malloc ⇒ Object
- #method_missing(method, *args) ⇒ Object
- #orderable? ⇒ Boolean
- #prefix ⇒ Object
- #private? ⇒ Boolean
- #public? ⇒ Boolean
- #static ⇒ Object
- #static? ⇒ Boolean
- #write_decls(stream) ⇒ Object
- #write_defs(stream) ⇒ Object
- #write_intf(stream) ⇒ Object
Methods inherited from Code
#attach, #priority, #source_size
Constructor Details
#initialize(type, visibility = :public) ⇒ Type
Returns a new instance of Type.
168 169 170 171 172 173 174 175 176 177 178 179 180 |
# File 'lib/autoc/type.rb', line 168 def initialize(type, visibility = :public) @type = type.to_s @type_ref = "#{self.type}*" @visibility = [:public, :private, :static].include?(visibility) ? visibility : raise("unsupported visibility") @capability = Set[:constructible, :destructible, :copyable, :comparable, :hashable, :orderable] # Can be used to disable specific capabilities for a type # Canonic special method signatures @ctor_signature = Function::Signature.new([type^:self]) @dtor_signature = Function::Signature.new([type^:self]) @copy_signature = Function::Signature.new([type^:dst, type^:src]) @equal_signature = Function::Signature.new([type^:lt, type^:rt], :int) @identify_signature = Function::Signature.new([type^:self], :size_t) @less_signature = Function::Signature.new([type^:lt, type^:rt], :int) end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args) ⇒ Object
182 183 184 185 186 187 188 189 190 191 192 193 |
# File 'lib/autoc/type.rb', line 182 def method_missing(method, *args) str = method.to_s str = str.sub(/[\!\?]$/, '') # Strip trailing ? or ! fn = prefix + str[0,1].capitalize + str[1..-1] # Ruby 1.8 compatible if args.empty? fn # Emit bare function name elsif args.size == 1 && args.first == nil fn + '()' # Use sole nil argument to emit function call with no arguments else fn + '(' + args.join(',') + ')' # Emit normal function call with supplied arguments end end |
Instance Attribute Details
#type ⇒ Object (readonly)
Returns the value of attribute type.
160 161 162 |
# File 'lib/autoc/type.rb', line 160 def type @type end |
#type_ref ⇒ Object (readonly)
Returns the value of attribute type_ref.
160 161 162 |
# File 'lib/autoc/type.rb', line 160 def type_ref @type_ref end |
Class Method Details
.coerce(type) ⇒ Object
148 149 150 |
# File 'lib/autoc/type.rb', line 148 def self.coerce(type) type.is_a?(Type) ? type : UserDefinedType.new(type) end |
Instance Method Details
#==(other) ⇒ Object Also known as: eql?
154 |
# File 'lib/autoc/type.rb', line 154 def ==(other) self.class == other.class && type == other.type end |
#abort ⇒ Object
240 |
# File 'lib/autoc/type.rb', line 240 def abort; "abort" end |
#assert ⇒ Object
232 |
# File 'lib/autoc/type.rb', line 232 def assert; "assert" end |
#calloc ⇒ Object
236 |
# File 'lib/autoc/type.rb', line 236 def calloc; "calloc" end |
#comparable? ⇒ Boolean
254 |
# File 'lib/autoc/type.rb', line 254 def comparable?; @capability.include?(:comparable) end |
#constructible? ⇒ Boolean
248 |
# File 'lib/autoc/type.rb', line 248 def constructible?; @capability.include?(:constructible) end |
#copyable? ⇒ Boolean
252 |
# File 'lib/autoc/type.rb', line 252 def copyable?; @capability.include?(:copyable) end |
#destructible? ⇒ Boolean
250 |
# File 'lib/autoc/type.rb', line 250 def destructible?; @capability.include?(:destructible) end |
#entities ⇒ Object
158 |
# File 'lib/autoc/type.rb', line 158 def entities; super << CommonCode end |
#extern ⇒ Object
def write_impls(stream, define)
226 |
# File 'lib/autoc/type.rb', line 226 def extern; "AUTOC_EXTERN" end |
#free ⇒ Object
238 |
# File 'lib/autoc/type.rb', line 238 def free; "free" end |
#hash ⇒ Object
152 |
# File 'lib/autoc/type.rb', line 152 def hash; self.class.hash ^ type.hash end |
#hashable? ⇒ Boolean
258 |
# File 'lib/autoc/type.rb', line 258 def hashable?; @capability.include?(:hashable) && comparable? end |
#inline ⇒ Object
228 |
# File 'lib/autoc/type.rb', line 228 def inline; "AUTOC_INLINE" end |
#malloc ⇒ Object
234 |
# File 'lib/autoc/type.rb', line 234 def malloc; "malloc" end |
#orderable? ⇒ Boolean
256 |
# File 'lib/autoc/type.rb', line 256 def orderable?; @capability.include?(:orderable) && comparable? end |
#prefix ⇒ Object
162 163 164 165 166 |
# File 'lib/autoc/type.rb', line 162 def prefix # Lazy evaluator for simple types like char* which do not actually use # this method and hence do not require the prefix to be valid C identifier AutoC.c_id(type) end |
#private? ⇒ Boolean
244 |
# File 'lib/autoc/type.rb', line 244 def private?; @visibility == :private end |
#public? ⇒ Boolean
242 |
# File 'lib/autoc/type.rb', line 242 def public?; @visibility == :public end |
#static ⇒ Object
230 |
# File 'lib/autoc/type.rb', line 230 def static; "AUTOC_STATIC" end |
#static? ⇒ Boolean
246 |
# File 'lib/autoc/type.rb', line 246 def static?; @visibility == :static end |
#write_decls(stream) ⇒ Object
202 203 204 205 206 207 208 209 210 |
# File 'lib/autoc/type.rb', line 202 def write_decls(stream) if private? write_intf_types(stream) write_intf_decls(stream, extern, inline) elsif static? write_intf_types(stream) write_intf_decls(stream, static, inline) end end |
#write_defs(stream) ⇒ Object
212 213 214 215 216 217 218 |
# File 'lib/autoc/type.rb', line 212 def write_defs(stream) if public? || private? write_impls(stream, nil) elsif static? write_impls(stream, static) end end |
#write_intf(stream) ⇒ Object
195 196 197 198 199 200 |
# File 'lib/autoc/type.rb', line 195 def write_intf(stream) if public? write_intf_types(stream) write_intf_decls(stream, extern, inline) end end |