module AtCoderFriends::Generator::CxxBuiltinDeclGen
generates C++ variable declarations
Constants
- TYPE_TBL
Public Instance Methods
gen_arr_size(szs)
click to toggle source
# File lib/at_coder_friends/generator/cxx_builtin.rb, line 100 def gen_arr_size(szs) szs.map { |sz| sz.gsub(/([a-z][a-z0-9_]*)/i, '\1_MAX').upcase } end
gen_decl(inpdef)
click to toggle source
# File lib/at_coder_friends/generator/cxx_builtin.rb, line 32 def gen_decl(inpdef) if inpdef.components inpdef.components.map { |cmp| gen_decl(cmp) } else case inpdef.container when :single gen_single_decl(inpdef) when :harray gen_harray_decl(inpdef) when :varray gen_varray_decl(inpdef) when :matrix, :vmatrix, :hmatrix gen_matrix_decl(inpdef) end end end
gen_harray_decl(inpdef)
click to toggle source
# File lib/at_coder_friends/generator/cxx_builtin.rb, line 65 def gen_harray_decl(inpdef) type = TYPE_TBL[inpdef.item] v = inpdef.names[0] sz = gen_arr_size(inpdef.size)[0] case inpdef.item when :number, :decimal "#{type} #{v}[#{sz}];" when :string "#{type} #{v}[#{sz}][#{v.upcase}_MAX + 1];" when :char "#{type} #{v}[#{sz} + 1];" end end
gen_matrix_decl(inpdef)
click to toggle source
# File lib/at_coder_friends/generator/cxx_builtin.rb, line 89 def gen_matrix_decl(inpdef) sz1, sz2 = gen_arr_size(inpdef.size) inpdef.vars.map do |v, item| type = TYPE_TBL[item] dcl = "#{v}[#{sz1}]" dcl += item == :char ? "[#{sz2} + 1]" : "[#{sz2}]" dcl += "[#{v.upcase}_MAX + 1]" if item == :string "#{type} #{dcl};" end end
gen_single_decl(inpdef)
click to toggle source
# File lib/at_coder_friends/generator/cxx_builtin.rb, line 49 def gen_single_decl(inpdef) names, cols = inpdef.vars.transpose if cols.uniq.size == 1 && cols[0] != :string type = TYPE_TBL[cols[0]] dcl = names.join(', ') "#{type} #{dcl};" else inpdef.vars.map do |v, item| type = TYPE_TBL[item] dcl = v dcl += "[#{v.upcase}_MAX + 1]" if item == :string "#{type} #{dcl};" end end end
gen_varray_decl(inpdef)
click to toggle source
# File lib/at_coder_friends/generator/cxx_builtin.rb, line 79 def gen_varray_decl(inpdef) sz = gen_arr_size(inpdef.size)[0] inpdef.vars.map do |v, item| type = TYPE_TBL[item] dcl = "#{v}[#{sz}]" dcl += "[#{v.upcase}_MAX + 1]" if item == :string "#{type} #{dcl};" end end