From c5050d87361fbfcdb55cb8dbe736d018b8f40e45 Mon Sep 17 00:00:00 2001 From: Martin Corino Date: Mon, 23 Oct 2023 14:02:21 +0200 Subject: [PATCH] make sure constant names are consistent (snake-case uppercased) --- rakelib/lib/generate/interface.rb | 7 ++++--- rakelib/lib/util/string.rb | 18 ++++++++++-------- 2 files changed, 14 insertions(+), 11 deletions(-) diff --git a/rakelib/lib/generate/interface.rb b/rakelib/lib/generate/interface.rb index 8e22a6cb..2bf68ebd 100644 --- a/rakelib/lib/generate/interface.rb +++ b/rakelib/lib/generate/interface.rb @@ -590,19 +590,20 @@ def gen_defines(fout) fout.puts "%constant char* #{item.name} = #{$2};" elsif item.value =~ /wx(Size|Point)(\(.*\))/ frbext = init_rb_ext_file unless frbext - frbext.indent { frbext.puts "#{rb_wx_name(item.name)} = Wx::#{$1}.new#{$2}" } + frbext.indent { frbext.puts "#{rb_constant_name(item.name)} = Wx::#{$1}.new#{$2}" } frbext.puts elsif item.value =~ /wx(Colour|Font)(\(.*\))/ frbext = init_rb_ext_file unless frbext frbext.indent do - frbext.puts "Wx.add_delayed_constant(self, :#{rb_wx_name(item.name)}) { Wx::#{$1}.new#{$2} }" + frbext.puts "Wx.add_delayed_constant(self, :#{rb_constant_name(item.name)}) { Wx::#{$1}.new#{$2} }" end frbext.puts elsif item.value =~ /wxSystemSettings::(\w+)\((.*)\)/ frbext = init_rb_ext_file unless frbext + setting_mtd = $1 args = $2.split(',').collect {|a| rb_constant_value(a) }.join(', ') frbext.indent do - frbext.puts "Wx.add_delayed_constant(self, :#{rb_wx_name(item.name)}) { Wx::SystemSettings.#{rb_method_name($1)}(#{args}) }" + frbext.puts "Wx.add_delayed_constant(self, :#{rb_constant_name(item.name)}) { Wx::SystemSettings.#{rb_method_name(setting_mtd)}(#{args}) }" end frbext.puts else diff --git a/rakelib/lib/util/string.rb b/rakelib/lib/util/string.rb index cdbca872..df3f7bd2 100644 --- a/rakelib/lib/util/string.rb +++ b/rakelib/lib/util/string.rb @@ -91,14 +91,18 @@ def rb_module_name(name) end def rb_constant_value(name) - val = name.sub(/\Awx/, 'Wx::') - case val - when /NULL|nullptr/ + name = name.strip + case name + when /\A(null|nullptr)\Z/i 'nil' + when /\A(true|false)\Z/i + name.downcase when /EmptyString/ %q[''] + when /\A\"/ + name else - val + "#{name.start_with?('wx') ? 'Wx::' : ''}#{rb_constant_name(name)}" end end @@ -110,7 +114,7 @@ def rb_constant_expression(exp, const_xref) ids = idstr.split('::') if ids.size > 1 is_scoped = true - scoped_name = rb_constant_value(ids.shift) + scoped_name = rb_wx_name(ids.shift) while ids.size > 1 scoped_name << '::' << ids.shift end @@ -127,7 +131,7 @@ def rb_constant_expression(exp, const_xref) when 'wxString' '(' else - "#{rb_constant_value(idstr)}.new(" + "#{idstr.start_with?('wx') ? 'Wx::' : ''}#{rb_wx_name(idstr)}.new(" end end else @@ -143,8 +147,6 @@ def rb_constant_expression(exp, const_xref) # constant if /[\-\+\.\d]+/ =~ idstr idstr # numeric constant - elsif /\A(true|false|NULL|nullptr)/ =~ idstr - ($1 == 'NULL' || $1 == 'nullptr') ? 'nil' : $1 else if const_xref.has_key?(rb_constant_name(idstr)) "#{const_xref[rb_constant_name(idstr)]['mod']}::#{rb_constant_name(idstr)}"