Class: Rbind::GeneratorC::OperationsHelper::OperationHelper

Inherits:
SimpleDelegator
  • Object
show all
Defined in:
lib/rbind/generator_c.rb

Instance Method Summary collapse

Instance Method Details

#bindingObject



278
279
280
# File 'lib/rbind/generator_c.rb', line 278

def binding
    Kernel.binding
end

#wrap_callObject



194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
# File 'lib/rbind/generator_c.rb', line 194

def wrap_call
		   str = overwrite_c()
		   return str if str
    paras = parameters.map do |arg|
        "#{"*" if (!arg.type.ptr? && !arg.type.basic_type?)}#{arg.name}#{"_" if !arg.type.basic_type?}"
    end.join(", ")
    fct = if attribute?
              if return_type.name == "void" && !return_type.ptr?
                  "rbind_obj_->#{attribute.name} = #{paras};"
              else
                  if return_type.basic_type?
                      "return rbind_obj_->#{attribute.name};"
                  elsif return_type.ptr?
                      "return toC(rbind_obj_->#{attribute.name},false);"
                  else
                      "return toC(&rbind_obj_->#{attribute.name},false);"
                  end
              end
          elsif __getobj__.is_a?(RCastOperation)
			     param1,param2,param3 = if parameters.size == 1
						 ["rbind_obj_",paras,"rbind_obj"]
					     else
						 a = paras.split(",")
						 a << parameters.first.name
						 a
					     end
			     str = "#{return_type} *__rbind_temp_ = dynamic_cast<#{return_type}*>(#{param1});\n"
			     str += "\tif(!__rbind_temp_)\n"
			     str += "\t\t throw std::runtime_error(\"Typecast failed, incompatible types\");\n"
			     str += "\tif(#{param2})\n"
			     str += "\t{\n"
			     str += "\t\tif(!#{param3}->bowner)\n"
			     str += "\t\t    throw std::runtime_error(\"Cannot pass ownership. Object is owned by someone else. \");\n"
			     str += "\t\telse\n"
			     str += "\t\t    #{param3}->bowner = false;\n"
			     str += "\t}\n"
			     str + "\treturn toC(__rbind_temp_,#{param2});"
          else
              fct = if !constructor? && (return_type.name != "void" || return_type.ptr?)
                        # operator+, operator++ etc
                        if operator? && parameters.size == 1
                            if return_type.basic_type?
                                "return *rbind_obj_ #{operator} #{paras};"
                            elsif return_type.ref?
                                # the returned value is not the owner of the object
                                "return toC(&(*rbind_obj_ #{operator} #{paras}),false);"
                            else
                                "return toC(new #{return_type.full_name}(*rbind_obj_ #{operator} #{paras}));"
                            end
                        elsif return_type.basic_type?
                            "return #{full_name}(#{paras});"
                        elsif return_type.ptr?
                            "return toC(#{full_name}(#{paras}),#{return_type.ownership?});"
                        elsif return_type.ref?
                            # the returned value is never owner of the memory
                            "return toC(&#{full_name}(#{paras}),false);"
                        else
                            "return toC(new #{return_type.full_name}(#{full_name}(#{paras})));"
                        end
                    else
                        if constructor?
                            "return toC(new #{namespace}(#{paras}));"
                        else
                            if operator?
                                "*rbind_obj_ #{operator} #{paras};"
                            else
                                "#{full_name}(#{paras});"
                            end
                        end
                    end
              #convert call to member call 
              if instance_method?
                  #add base class name space
                  if((inherit? && !abstract?) || ambiguous_name?)
                      fct.gsub(full_name,"rbind_obj_->#{base_class.name}::#{name}")
                  else
                      fct.gsub(full_name,"rbind_obj_->#{name}")
                  end
              else
                  fct
              end
          end
end

#wrap_parametersObject



187
188
189
190
191
192
# File 'lib/rbind/generator_c.rb', line 187

def wrap_parameters
    cparameters.map do |arg|
        next if arg.type.basic_type?
		       "#{arg.type.to_single_ptr.signature} #{arg.name}_ = fromC(#{arg.name},#{arg.parse_ownership?});\n\t"
    end.compact.join("")
end