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
Returns true if the type provides a well-defined equality test function.
-
#constructible? ⇒ Boolean
Returns true if the type provides a well-defined parameterless default type constructor.
-
#copyable? ⇒ Boolean
Returns true if the type provides a well-defined copy constructor to create a clone of an instance.
-
#destructible? ⇒ Boolean
Returns true if the type provides a well-defined type destructor.
- #entities ⇒ Object
-
#extern ⇒ Object
def write_impls(stream, define).
- #free ⇒ Object
- #hash ⇒ Object
-
#hashable? ⇒ Boolean
Returns true if the type provides a well-defined hash calculation function.
-
#initializable? ⇒ Boolean
Returns true if the type provides a well-defined type constructor which can have extra arguments.
-
#initialize(type, visibility = :public) ⇒ Type
constructor
A new instance of Type.
- #inline ⇒ Object
- #malloc ⇒ Object
- #method_missing(method, *args) ⇒ Object
-
#orderable? ⇒ Boolean
Returns true if the type provides a well-defined 'less than' test function.
- #prefix ⇒ Object
- #private? ⇒ Boolean
- #public? ⇒ Boolean
-
#sortable? ⇒ Boolean
Returns true if the type provides corrset soritng routines.
- #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
170 171 172 173 174 175 176 177 178 179 180 181 182 183 |
# File 'lib/autoc/type.rb', line 170 def initialize(type, visibility = :public) @type = type.to_s @type_ref = "#{self.type}*" @visibility = [:public, :private, :static].include?(visibility) ? visibility : raise("unsupported visibility") # Canonic special method signatures @signature = { :ctor => Function::Signature.new([type^:self]), :dtor => Function::Signature.new([type^:self]), :copy => Function::Signature.new([type^:dst, type^:src]), :equal => Function::Signature.new([type^:lt, type^:rt], :int), :identify => Function::Signature.new([type^:self], :size_t), :less => 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
185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 |
# File 'lib/autoc/type.rb', line 185 def method_missing(method, *args) str = method.to_s str = str.sub(/[\!\?]$/, '') # Strip trailing ? or ! x = false # Have leading underscore if /_(.*)/ =~ str str = $1 x = true end fn = prefix + str[0,1].capitalize + str[1..-1] # Ruby 1.8 compatible fn = "_" << fn if x # Carry over the leading underscore 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
162 163 164 |
# File 'lib/autoc/type.rb', line 162 def type @type end |
#type_ref ⇒ Object (readonly)
Returns the value of attribute type_ref
162 163 164 |
# File 'lib/autoc/type.rb', line 162 def type_ref @type_ref end |
Class Method Details
.coerce(type) ⇒ Object
150 151 152 |
# File 'lib/autoc/type.rb', line 150 def self.coerce(type) type.is_a?(Type) ? type : UserDefinedType.new(type) end |
Instance Method Details
#==(other) ⇒ Object Also known as: eql?
156 |
# File 'lib/autoc/type.rb', line 156 def ==(other) self.class == other.class && type == other.type end |
#abort ⇒ Object
251 |
# File 'lib/autoc/type.rb', line 251 def abort; :abort end |
#assert ⇒ Object
243 |
# File 'lib/autoc/type.rb', line 243 def assert; :assert end |
#calloc ⇒ Object
247 |
# File 'lib/autoc/type.rb', line 247 def calloc; :calloc end |
#comparable? ⇒ Boolean
Returns true if the type provides a well-defined equality test function
275 |
# File 'lib/autoc/type.rb', line 275 def comparable?; false end |
#constructible? ⇒ Boolean
Returns true if the type provides a well-defined parameterless default type constructor
263 |
# File 'lib/autoc/type.rb', line 263 def constructible?; false end |
#copyable? ⇒ Boolean
Returns true if the type provides a well-defined copy constructor to create a clone of an instance
272 |
# File 'lib/autoc/type.rb', line 272 def copyable?; false end |
#destructible? ⇒ Boolean
Returns true if the type provides a well-defined type destructor
269 |
# File 'lib/autoc/type.rb', line 269 def destructible?; false end |
#entities ⇒ Object
160 |
# File 'lib/autoc/type.rb', line 160 def entities; super << CommonCode end |
#extern ⇒ Object
def write_impls(stream, define)
237 |
# File 'lib/autoc/type.rb', line 237 def extern; :AUTOC_EXTERN end |
#free ⇒ Object
249 |
# File 'lib/autoc/type.rb', line 249 def free; :free end |
#hash ⇒ Object
154 |
# File 'lib/autoc/type.rb', line 154 def hash; self.class.hash ^ type.hash end |
#hashable? ⇒ Boolean
Returns true if the type provides a well-defined hash calculation function
284 |
# File 'lib/autoc/type.rb', line 284 def hashable?; false end |
#initializable? ⇒ Boolean
Returns true if the type provides a well-defined type constructor which can have extra arguments
266 |
# File 'lib/autoc/type.rb', line 266 def initializable?; false end |
#inline ⇒ Object
239 |
# File 'lib/autoc/type.rb', line 239 def inline; :AUTOC_INLINE end |
#malloc ⇒ Object
245 |
# File 'lib/autoc/type.rb', line 245 def malloc; :malloc end |
#orderable? ⇒ Boolean
Returns true if the type provides a well-defined 'less than' test function
278 |
# File 'lib/autoc/type.rb', line 278 def orderable?; false end |
#prefix ⇒ Object
164 165 166 167 168 |
# File 'lib/autoc/type.rb', line 164 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 a valid C identifier AutoC.c_id(type) end |
#private? ⇒ Boolean
255 |
# File 'lib/autoc/type.rb', line 255 def private?; @visibility == :private end |
#public? ⇒ Boolean
253 |
# File 'lib/autoc/type.rb', line 253 def public?; @visibility == :public end |
#sortable? ⇒ Boolean
Returns true if the type provides corrset soritng routines
281 |
# File 'lib/autoc/type.rb', line 281 def sortable?; comparable? && orderable? end |
#static ⇒ Object
241 |
# File 'lib/autoc/type.rb', line 241 def static; :AUTOC_STATIC end |
#static? ⇒ Boolean
257 |
# File 'lib/autoc/type.rb', line 257 def static?; @visibility == :static end |
#write_decls(stream) ⇒ Object
211 212 213 214 215 216 217 218 219 |
# File 'lib/autoc/type.rb', line 211 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
221 222 223 224 225 226 227 |
# File 'lib/autoc/type.rb', line 221 def write_defs(stream) if public? || private? write_impls(stream, nil) elsif static? write_impls(stream, static) end end |
#write_intf(stream) ⇒ Object
204 205 206 207 208 209 |
# File 'lib/autoc/type.rb', line 204 def write_intf(stream) if public? write_intf_types(stream) write_intf_decls(stream, extern, inline) end end |