aboutsummaryrefslogtreecommitdiffstats
path: root/lib/wx/api_gen
diff options
context:
space:
mode:
authorDan Gudmundsson <[email protected]>2012-03-06 12:21:51 +0100
committerDan Gudmundsson <[email protected]>2012-03-06 12:21:51 +0100
commit2738f881102a6c291c8fb1f2305677dba57fa87d (patch)
tree634e8bc7666af4b19f7baeabd474202bbefd2762 /lib/wx/api_gen
parentdf8cd79bef0ca7178efcda97401c892d24f920bc (diff)
downloadotp-2738f881102a6c291c8fb1f2305677dba57fa87d.tar.gz
otp-2738f881102a6c291c8fb1f2305677dba57fa87d.tar.bz2
otp-2738f881102a6c291c8fb1f2305677dba57fa87d.zip
[wx] Fix bad defines
Reported by Vlad Dumitrescu.
Diffstat (limited to 'lib/wx/api_gen')
-rw-r--r--lib/wx/api_gen/gl_gen.erl11
-rw-r--r--lib/wx/api_gen/gl_gen_erl.erl4
-rw-r--r--lib/wx/api_gen/wx_gen_erl.erl19
3 files changed, 25 insertions, 9 deletions
diff --git a/lib/wx/api_gen/gl_gen.erl b/lib/wx/api_gen/gl_gen.erl
index ce0cb922e9..331ba32ba4 100644
--- a/lib/wx/api_gen/gl_gen.erl
+++ b/lib/wx/api_gen/gl_gen.erl
@@ -190,14 +190,17 @@ parse_define([#xmlElement{name=initializer,content=[#xmlText{value=V}]}|_],Def,_
try
case Val0 of
"0x" ++ Val1 ->
- Val = http_util:hexlist_to_integer(Val1),
- Def#def{val=Val, type=hex};
+ _ = http_util:hexlist_to_integer(Val1),
+ Def#def{val=Val1, type=hex};
_ ->
Val = list_to_integer(Val0),
Def#def{val=Val, type=int}
end
- catch _:_ ->
- Def#def{val=Val0, type=string}
+ catch _:_ ->
+ case catch list_to_float(Val0) of
+ {'EXIT', _} -> Def#def{val=Val0, type=string};
+ _ -> Def#def{val=Val0, type=float_str}
+ end
end;
parse_define([_|R], D, Opts) ->
parse_define(R, D, Opts);
diff --git a/lib/wx/api_gen/gl_gen_erl.erl b/lib/wx/api_gen/gl_gen_erl.erl
index f77b2d8e24..25f89e4ad4 100644
--- a/lib/wx/api_gen/gl_gen_erl.erl
+++ b/lib/wx/api_gen/gl_gen_erl.erl
@@ -54,8 +54,10 @@ glu_defines(Defs) ->
gen_define(#def{name=N, val=Val, type=int}) ->
w("-define(~s, ~p).~n", [N,Val]);
+gen_define(#def{name=N, val=Val, type=float_str}) ->
+ w("-define(~s, ~s).~n", [N,Val]);
gen_define(#def{name=N, val=Val, type=hex}) ->
- w("-define(~s, ~.16#).~n", [N,Val]);
+ w("-define(~s, 16#~s).~n", [N,Val]);
gen_define(#def{name=N, val=Val, type=string}) ->
w("-define(~s, ?~s).~n", [N,Val]);
gen_define(#def{name="GLEXT_64_TYPES"++_, val=undefined, type=undefined}) ->
diff --git a/lib/wx/api_gen/wx_gen_erl.erl b/lib/wx/api_gen/wx_gen_erl.erl
index 59a4d3d8e7..1a616ed876 100644
--- a/lib/wx/api_gen/wx_gen_erl.erl
+++ b/lib/wx/api_gen/wx_gen_erl.erl
@@ -1059,16 +1059,16 @@ build_enum_ints(#enum{from=From, vals=Vals},Done) ->
Format = fun(#const{name="wxEVT_" ++ _}) ->
ignore; %% Ignore event macros they are not valid in our event model
- (#const{name=Name,val=Value,is_const=true}) when is_integer(Value) ->
+ (#const{name=Name,val=Value,is_const=true}) when is_number(Value) ->
w("-define(~s, ~p).~n", [enum_name(Name),Value]);
- (#const{name=Name,val=Value,is_const=false}) when is_integer(Value) ->
+ (#const{name=Name,val=Value,is_const=false}) when is_number(Value) ->
w("-define(~s, wxe_util:get_const(~s)).~n", [enum_name(Name),enum_name(Name)]);
(#const{name=Name,val={Str,0}}) ->
case string:tokens(Str, " |()") of
[Token] ->
- w("-define(~s, ?~s).~n", [enum_name(Name),Token]);
+ w("-define(~s, ~s).~n", [enum_name(Name),const_value(Token)]);
Tokens ->
- Def = args(fun(T) -> [$?|T] end, " bor ", Tokens),
+ Def = args(fun(T) -> const_value(T) end, " bor ", Tokens),
w("-define(~s, (~s)).~n", [enum_name(Name),Def])
end;
(#const{name=Name,val={Str,N}}) ->
@@ -1093,6 +1093,17 @@ build_enum_ints(#enum{from=From, vals=Vals},Done) ->
end,
lists:foldl(Write, Done, Vals).
+const_value(V) when is_integer(V) -> integer_to_list(V);
+const_value(V = "16#" ++ IntList) ->
+ _ = http_util:hexlist_to_integer(IntList), %% ASSERT
+ V;
+const_value(V0) ->
+ try
+ _ = list_to_integer(V0),
+ V0
+ catch _:_ -> [$?|V0]
+ end.
+
gen_event_recs() ->
open_write("../include/wx.hrl"),
erl_copyright(),