Skip to content

Commit

Permalink
make sure constant names are consistent (snake-case uppercased)
Browse files Browse the repository at this point in the history
  • Loading branch information
mcorino committed Oct 23, 2023
1 parent 4129958 commit c5050d8
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 11 deletions.
7 changes: 4 additions & 3 deletions rakelib/lib/generate/interface.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
18 changes: 10 additions & 8 deletions rakelib/lib/util/string.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
Expand All @@ -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
Expand All @@ -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)}"
Expand Down

0 comments on commit c5050d8

Please sign in to comment.