Module: FuncParser
- Included in:
- DefGslMethod, DefGslModuleFunction, SfTemplate, StatsBasic
- Defined in:
- ext/numo/gsl/gen/func_parser.rb
Overview
Constant Summary collapse
- PARAM_DESC =
{}
- PARAM_NAMES =
{}
Instance Attribute Summary collapse
-
#args_in ⇒ Object
readonly
attr_reader :name.
-
#args_out ⇒ Object
readonly
attr_reader :name.
-
#args_param ⇒ Object
readonly
attr_reader :name.
-
#counter ⇒ Object
readonly
Returns the value of attribute counter.
-
#generate_array ⇒ Object
readonly
Returns the value of attribute generate_array.
Class Method Summary collapse
Instance Method Summary collapse
- #argument_property(type, name) ⇒ Object
- #c_args ⇒ Object
- #cdef_args ⇒ Object
- #def_ain ⇒ Object
- #def_aout ⇒ Object
- #desc_param ⇒ Object
- #desc_param_scalar ⇒ Object
- #find_name(name) ⇒ Object
- #is_param(tp, nm) ⇒ Object
- #method_args ⇒ Object
- #n_in ⇒ Object
- #n_input ⇒ Object
- #n_out ⇒ Object
- #n_param ⇒ Object
- #ndl_args ⇒ Object
- #param_desc ⇒ Object
- #param_names ⇒ Object
- #parse_args(h) ⇒ Object
- #recv ⇒ Object
Instance Attribute Details
#args_in ⇒ Object (readonly)
attr_reader :name
403 404 405 |
# File 'ext/numo/gsl/gen/func_parser.rb', line 403 def args_in @args_in end |
#args_out ⇒ Object (readonly)
attr_reader :name
403 404 405 |
# File 'ext/numo/gsl/gen/func_parser.rb', line 403 def args_out @args_out end |
#args_param ⇒ Object (readonly)
attr_reader :name
403 404 405 |
# File 'ext/numo/gsl/gen/func_parser.rb', line 403 def args_param @args_param end |
#counter ⇒ Object (readonly)
Returns the value of attribute counter.
405 406 407 |
# File 'ext/numo/gsl/gen/func_parser.rb', line 405 def counter @counter end |
#generate_array ⇒ Object (readonly)
Returns the value of attribute generate_array.
404 405 406 |
# File 'ext/numo/gsl/gen/func_parser.rb', line 404 def generate_array @generate_array end |
Class Method Details
.lookup(h) ⇒ Object
350 351 352 |
# File 'ext/numo/gsl/gen/func_parser.rb', line 350 def self.lookup(h) false end |
Instance Method Details
#argument_property(type, name) ⇒ Object
407 408 409 410 411 412 413 414 415 416 417 418 419 |
# File 'ext/numo/gsl/gen/func_parser.rb', line 407 def argument_property(type,name) if name == "return" {output:true, narray:true, pass: :return} elsif /\[\]$/ =~ name {output:true, narray:true, pass: :array} elsif is_param(type,name) {input:true, param:true} elsif /\*$/ =~ type {output:true, narray:true, pass: :pointer} else {input:true, narray:true} end end |
#c_args ⇒ Object
462 463 464 465 |
# File 'ext/numo/gsl/gen/func_parser.rb', line 462 def c_args @parsed_args.select{|a| a.pass != :return}. map{|a| a.c_arg}.join(",") end |
#cdef_args ⇒ Object
481 482 483 484 485 486 487 488 |
# File 'ext/numo/gsl/gen/func_parser.rb', line 481 def cdef_args if n_arg == -1 "int argc, VALUE *v, VALUE mod" else "VALUE mod," + @args_input.map{|a|"VALUE #{a.v_var}"}.join(",") end end |
#def_ain ⇒ Object
450 451 452 |
# File 'ext/numo/gsl/gen/func_parser.rb', line 450 def def_ain @args_in.map{|a| a.ain_def}.join(",") end |
#def_aout ⇒ Object
454 455 456 |
# File 'ext/numo/gsl/gen/func_parser.rb', line 454 def def_aout @args_out.map{|a| a.aout_def}.join(",") end |
#desc_param ⇒ Object
494 495 496 497 498 499 500 501 502 503 504 |
# File 'ext/numo/gsl/gen/func_parser.rb', line 494 def desc_param #t = (["Numo::DFloat"]*n_out).join(",") t = @args_out.map{|a| a.na_class}.flatten.join(", ") v = @args_out.map{|a| a.ret_val}.flatten.join(", ") if n_out > 1 r = "@return [[#{t}]] array of [#{v}]" else r = "@return [#{t}] #{v}" end @args_input.map{|a| a.description}+[r] end |
#desc_param_scalar ⇒ Object
506 507 508 509 510 511 512 513 514 515 516 |
# File 'ext/numo/gsl/gen/func_parser.rb', line 506 def desc_param_scalar #t = (["Numo::DFloat"]*n_out).join(",") t = @args_out.map{|a| a.rb_class}.flatten.join(", ") v = @args_out.map{|a| a.ret_val}.flatten.join(", ") if n_out > 1 r = "@return [[#{t}]] array of [#{v}]" else r = "@return [#{t}] #{v}" end @args_input.map{|a| a.description}+[r] end |
#find_name(name) ⇒ Object
458 459 460 |
# File 'ext/numo/gsl/gen/func_parser.rb', line 458 def find_name(name) @parsed_args.find{|a| a.name==name} end |
#is_param(tp, nm) ⇒ Object
421 422 423 424 425 426 427 428 429 430 |
# File 'ext/numo/gsl/gen/func_parser.rb', line 421 def is_param(tp,nm) #$stderr.puts "type='#{tp}' name='#{nm}'" a = self.class::PARAM_NAMES[tp] case a when Array a.include?(nm) else a end end |
#method_args ⇒ Object
476 477 478 479 |
# File 'ext/numo/gsl/gen/func_parser.rb', line 476 def method_args s = @args_input.map{|a| a.name}.join(",") s.sub(/,mode$/,",[mode]") end |
#n_in ⇒ Object
436 437 438 |
# File 'ext/numo/gsl/gen/func_parser.rb', line 436 def n_in @args_in.size end |
#n_input ⇒ Object
440 441 442 |
# File 'ext/numo/gsl/gen/func_parser.rb', line 440 def n_input @args_input.size end |
#n_out ⇒ Object
444 445 446 447 448 |
# File 'ext/numo/gsl/gen/func_parser.rb', line 444 def n_out n = 0 @args_out.each{|a| n+=a.n_out} n end |
#n_param ⇒ Object
432 433 434 |
# File 'ext/numo/gsl/gen/func_parser.rb', line 432 def n_param @args_param.size end |
#ndl_args ⇒ Object
490 491 492 |
# File 'ext/numo/gsl/gen/func_parser.rb', line 490 def ndl_args @args_in.map{|a| a.v_var}.join(",") end |
#param_desc ⇒ Object
357 358 359 |
# File 'ext/numo/gsl/gen/func_parser.rb', line 357 def param_desc self.class::PARAM_DESC end |
#param_names ⇒ Object
361 362 363 |
# File 'ext/numo/gsl/gen/func_parser.rb', line 361 def param_names self.class::PARAM_NAMES end |
#parse_args(h) ⇒ Object
365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 |
# File 'ext/numo/gsl/gen/func_parser.rb', line 365 def parse_args(h) i = 0 @parsed_args = [] h[:args].each do |type,name| type = type.sub(/^const\s+/,"").strip if /_array$/ =~ name && /(.+)\*$/ =~ type type = $1.strip name = name+"[]" end prop = argument_property(type,name) @parsed_args << Argument.new(self,i,type,name,prop) i += 1 end t = h[:func_type] if t != "void" prop = argument_property(t,"return") @parsed_args << Argument.new(self,i,t,"return",prop) end # @args_param = @parsed_args.select{|a|a.param} @args_input = @parsed_args.select{|a|a.input} @args_in = @parsed_args.select{|a|a.narray && a.input} @args_out = @parsed_args.select{|a|a.narray && a.output} @parsed_args.each do |a| if a.pass == :array @generate_array = true break end end @counter = Counter.new if @args_param.any?{|a| a.type=="gsl_mode_t"} set n_arg: -1 else set n_arg: @args_param.size+@args_in.size end end |
#recv ⇒ Object
467 468 469 470 471 472 473 474 |
# File 'ext/numo/gsl/gen/func_parser.rb', line 467 def recv a = args_out.last if a && a.pass == :return a.c_var + " = " else "" end end |