Class: AutoC::Function
- Inherits:
-
Object
show all
- Includes:
- Entity
- Defined in:
- lib/autoc/function.rb
Overview
Standalone C side function The generated function is meant to be the C89-compliant NOTE: This function does not track parameter and result types as its dependencies This can be done manually by appending to #dependencies property with <<
Defined Under Namespace
Classes: Parameters
Constant Summary
Constants included
from Entity
Entity::ReferenceSet
Instance Attribute Summary collapse
Instance Method Summary
collapse
Methods included from Entity
#<=>, #complexity, #dependencies, #forward_declarations, #implementation, #interface, #position, #references, #total_dependencies, #total_references
Constructor Details
#initialize(result, name, parameters, inline: false, visibility: :public, constraint: true, variadic: false, abstract: false) ⇒ Function
Returns a new instance of Function.
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
|
# File 'lib/autoc/function.rb', line 93
def initialize(result, name, parameters, inline: false, visibility: :public, constraint: true, variadic: false, abstract: false)
@name = name.to_s
@result = result
@inline = inline
@visibility = visibility
@constraint = constraint
@abstract = abstract
@variadic = variadic
@parameters = Parameters.new(self)
if parameters.is_a?(Hash)
parameters.each do |name, descriptor|
x = Parameter.new(descriptor, name)
@parameters[x.name] = x
end
else
i = -1
parameters.each do |descriptor|
x = Parameter.new(descriptor, "_#{i+=1}")
@parameters[x.name] = x
end
end
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(meth, *args) ⇒ Object
This allows to call other functions with this function’s individual parameters as arguments A call to unknown method results in the method’s name being emitted
174
|
# File 'lib/autoc/function.rb', line 174
def method_missing(meth, *args) = parameters.has_key?(meth) ? parameters[meth] : meth
|
Instance Attribute Details
#inline=(value) ⇒ Object
Sets the attribute inline
91
92
93
|
# File 'lib/autoc/function.rb', line 91
def inline=(value)
@inline = value
end
|
#name ⇒ Object
Returns the value of attribute name.
83
84
85
|
# File 'lib/autoc/function.rb', line 83
def name
@name
end
|
#parameters ⇒ Object
Returns the value of attribute parameters.
87
88
89
|
# File 'lib/autoc/function.rb', line 87
def parameters
@parameters
end
|
#result ⇒ Object
Returns the value of attribute result.
85
86
87
|
# File 'lib/autoc/function.rb', line 85
def result
@result
end
|
#visibility ⇒ Object
Returns the value of attribute visibility.
89
90
91
|
# File 'lib/autoc/function.rb', line 89
def visibility
@visibility
end
|
Instance Method Details
#abstract? ⇒ Boolean
142
|
# File 'lib/autoc/function.rb', line 142
def abstract? = @abstract == true
|
#call(*arguments) ⇒ Object
156
157
158
159
160
161
162
163
164
165
|
# File 'lib/autoc/function.rb', line 156
def call(*arguments)
xs = []
ps = parameters.to_a
(0...arguments.size).each do |i|
a = arguments[i]
v = a.is_a?(Parameter) ? a.to_value_argument : a
xs << (i < ps.size ? ps[i].value.(v) : v)
end
'%s(%s)' % [name, xs.join(',')]
end
|
#code(code) ⇒ Object
130
|
# File 'lib/autoc/function.rb', line 130
def code(code) = @code = code
|
167
168
169
170
|
# File 'lib/autoc/function.rb', line 167
def configure(&block)
instance_eval(&block)
self
end
|
#definition ⇒ Object
152
|
# File 'lib/autoc/function.rb', line 152
def definition = '%s {%s}' % [prototype, @code]
|
#external_code(code) ⇒ Object
121
122
123
124
|
# File 'lib/autoc/function.rb', line 121
def external_code(code)
@inline = false
code(code)
end
|
128
|
# File 'lib/autoc/function.rb', line 128
def () = @header =
|
#inline? ⇒ Boolean
134
|
# File 'lib/autoc/function.rb', line 134
def inline? = @inline == true
|
#inline_code(code) ⇒ Object
116
117
118
119
|
# File 'lib/autoc/function.rb', line 116
def inline_code(code)
@inline = true
code(code)
end
|
#inspect ⇒ Object
132
|
# File 'lib/autoc/function.rb', line 132
def inspect = "#{prototype} <#{self.class}>"
|
#internal? ⇒ Boolean
140
|
# File 'lib/autoc/function.rb', line 140
def internal? = @visibility == :internal
|
#live? ⇒ Boolean
146
|
# File 'lib/autoc/function.rb', line 146
def live? = (@constraint.is_a?(Proc) ? @constraint.() : @constraint) == true
|
#parameter(name) ⇒ Object
154
|
# File 'lib/autoc/function.rb', line 154
def parameter(name) = @values[name]
|
#private? ⇒ Boolean
138
|
# File 'lib/autoc/function.rb', line 138
def private? = @visibility == :private
|
#prototype ⇒ Object
150
|
# File 'lib/autoc/function.rb', line 150
def prototype = '%s %s(%s)' % [result, name, (parameters.to_a.collect(&:declaration) << (variadic? ? '...' : nil)).compact.join(',')]
|
#public? ⇒ Boolean
136
|
# File 'lib/autoc/function.rb', line 136
def public? = @visibility == :public
|
#signature ⇒ Object
148
|
# File 'lib/autoc/function.rb', line 148
def signature = '%s(%s)' % [result, (parameters.to_a.collect(&:signature) << (variadic? ? '...' : nil)).compact.join(',')]
|
#to_s ⇒ Object
126
|
# File 'lib/autoc/function.rb', line 126
def to_s = name
|
#variadic? ⇒ Boolean
144
|
# File 'lib/autoc/function.rb', line 144
def variadic? = @variadic == true
|