diff options
author | Dan Gudmundsson <[email protected]> | 2012-10-16 13:13:05 +0200 |
---|---|---|
committer | Dan Gudmundsson <[email protected]> | 2013-01-09 11:41:40 +0100 |
commit | 5382426b0fb7fe5e6bd452015436eb3e7c689f31 (patch) | |
tree | 0ac8615990cdb4e71714c62417c09c1e73e336d0 /lib | |
parent | ec68166e7512cb442f4995c0e3044a106f1a6372 (diff) | |
download | otp-5382426b0fb7fe5e6bd452015436eb3e7c689f31.tar.gz otp-5382426b0fb7fe5e6bd452015436eb3e7c689f31.tar.bz2 otp-5382426b0fb7fe5e6bd452015436eb3e7c689f31.zip |
wx: Fix xml-parsing with new doxygen version
Diffstat (limited to 'lib')
-rw-r--r-- | lib/wx/api_gen/gen_util.erl | 2 | ||||
-rw-r--r-- | lib/wx/api_gen/gl_gen.erl | 25 | ||||
-rw-r--r-- | lib/wx/api_gen/wx_gen.erl | 74 |
3 files changed, 70 insertions, 31 deletions
diff --git a/lib/wx/api_gen/gen_util.erl b/lib/wx/api_gen/gen_util.erl index 4638d4c7ea..d4941d4fdb 100644 --- a/lib/wx/api_gen/gen_util.erl +++ b/lib/wx/api_gen/gen_util.erl @@ -187,6 +187,8 @@ replace_and_remove([$| | R], Acc) -> replace_and_remove(R, ["|"|Acc]); replace_and_remove([$* | R], Acc) -> replace_and_remove(R, ["*"|Acc]); +replace_and_remove([$+ | R], Acc) -> + replace_and_remove(R, ["+"|Acc]); replace_and_remove([$& | R], Acc) -> replace_and_remove(R, [$&|Acc]); replace_and_remove([$<,$< | R], Acc) -> diff --git a/lib/wx/api_gen/gl_gen.erl b/lib/wx/api_gen/gl_gen.erl index 331ba32ba4..ea967c958f 100644 --- a/lib/wx/api_gen/gl_gen.erl +++ b/lib/wx/api_gen/gl_gen.erl @@ -185,11 +185,11 @@ parse_define([#xmlElement{name=name,content=[#xmlText{value="WINGDIAPI"++_}]}|_] throw(skip); parse_define([#xmlElement{name=name,content=[#xmlText{value=Name}]}|R], Def, Os) -> parse_define(R, Def#def{name=Name}, Os); -parse_define([#xmlElement{name=initializer,content=[#xmlText{value=V}]}|_],Def,_Os) -> - Val0 = string:strip(V), - try +parse_define([#xmlElement{name=initializer,content=Contents}|_R],Def,_Os) -> + Val0 = extract_def2(Contents), + try case Val0 of - "0x" ++ Val1 -> + "0x" ++ Val1 -> _ = http_util:hexlist_to_integer(Val1), Def#def{val=Val1, type=hex}; _ -> @@ -207,6 +207,23 @@ parse_define([_|R], D, Opts) -> parse_define([], D, _Opts) -> D. +extract_def2([#xmlText{value=Val}|R]) -> + strip_comment(string:strip(Val)) ++ extract_def2(R); +extract_def2([#xmlElement{content=Cs}|R]) -> + extract_def2(Cs) ++ extract_def2(R); +extract_def2([]) -> []. + +strip_comment("/*" ++ Rest) -> + strip_comment_until_end(Rest); +strip_comment("//" ++ _) -> []; +strip_comment([H|R]) -> [H | strip_comment(R)]; +strip_comment([]) -> []. + +strip_comment_until_end("*/" ++ Rest) -> + strip_comment(Rest); +strip_comment_until_end([_|R]) -> + strip_comment_until_end(R). + parse_func(Xml, Opts) -> {Func,_} = foldl(fun(X,Acc) -> parse_func(X,Acc,Opts) end, {#func{},1}, Xml), put(current_func, Func#func.name), diff --git a/lib/wx/api_gen/wx_gen.erl b/lib/wx/api_gen/wx_gen.erl index 7f85151d03..8c3b97f38e 100644 --- a/lib/wx/api_gen/wx_gen.erl +++ b/lib/wx/api_gen/wx_gen.erl @@ -654,6 +654,12 @@ extract_type_info(#xmlElement{name=ref,attributes=As,content=[#xmlText{value=V}] {value, #xmlAttribute{value = Kind}} = keysearch(kindref,#xmlAttribute.name,As), {reverse(foldl(fun extract_type_info2/2, [], string:tokens(V, " "))) ++ Acc, {Kind,Refid}}; +extract_type_info(#xmlElement{name=ref,attributes=As,content=[#xmlText{value=V}]}, + {Acc,_}) -> + {value, #xmlAttribute{value = Refid}} = keysearch(refid,#xmlAttribute.name,As), + {value, #xmlAttribute{value = Kind}} = keysearch(kindref,#xmlAttribute.name,As), + {reverse(foldl(fun extract_type_info2/2, [], string:tokens(V, " "))) ++ Acc, + {Kind,Refid}}; extract_type_info(What,Acc) -> ?error({parse_error,What,Acc}). @@ -1251,7 +1257,7 @@ parse_enums([File|Files], Parsed) -> case gb_sets:is_member(File,Parsed) of false -> FileName = filename:join(["wx_xml",File ++ "_8h.xml"]), -%% io:format("Parse Enums in ~s ~n", [FileName]), + %%io:format("Parse Enums in ~s ~n", [FileName]), case xmerl_scan:file(FileName, [{space, normalize}]) of {error, enoent} -> parse_enums(Files, gb_sets:add(File,Parsed)); @@ -1318,41 +1324,37 @@ extract_enum2([], N, _Id, Acc) -> extract_enum3([#xmlElement{name=name,content=[#xmlText{value=Name}]}|R], Id, Acc) -> case lists:keymember(Name, 1, Acc) of - true -> %% Doxygen double includes some defs. + true -> %% Doxygen double includes some defs. {Acc,Id}; false -> case Id of - This = {Str,Num} -> + This = {Str,Num} -> extract_enum3(R, {Str, Num+1}, [{Name,This}|Acc]); Val -> extract_enum3(R, Val+1, [{Name,Val}|Acc]) end end; -extract_enum3([#xmlElement{name=initializer, - content=Cs=[#xmlText{}|_]}|_],_Id,[{Name,_}|Acc]) -> - - String = lists:append([string:strip(C#xmlText.value) || C <- Cs]), - +extract_enum3([#xmlElement{name=initializer,content=Cs}|_],_Id,[{Name,_}|Acc]) -> + String = extract_def2(Cs), Val0 = gen_util:tokens(String,"<& "), - - try + try case Val0 of - ["0x" ++ Val1] -> + ["0x" ++ Val1] -> Val = http_util:hexlist_to_integer(Val1), {[{Name, Val}|Acc], Val+1}; - [Single] -> - Val = list_to_integer(Single), - {[{Name, Val}|Acc], Val+1}; ["1", "<<", Shift] -> Val = 1 bsl list_to_integer(Shift), {[{Name, Val}|Acc], Val+1}; - [_Str, "+", _What] -> - Val = lists:append(Val0), - {[{Name, {Val, 0}}|Acc], {Val,1}}; - _What -> - %% io:format("~p Name ~p ~p~n",[?LINE, Name, Val0]), - throw(below) + [Str, "+", What] -> + Val = list_to_integer(What), + {[{Name, {Str, Val}}|Acc], {Str,Val+1}}; + [Single] -> + Val = list_to_integer(Single), + {[{Name, Val}|Acc], Val+1}; + _ -> + %% io:format("~p Name ~p ~p ~p~n",[?LINE, Name, Val0, String]), + throw(below) end catch _:_ -> {[{Name,{String,0}}|Acc], {String,1}} @@ -1372,7 +1374,7 @@ extract_defs(Defs, File) -> end. extract_defs2(#xmlElement{name=memberdef,content=C},{Acc,Skip}) -> - try + try Res = {Name,_} = extract_def(C,undefined,Skip), case gb_sets:is_member(Name,Skip) orelse lists:keymember(Name, 1, Acc) of true -> {Acc,Skip}; @@ -1380,30 +1382,31 @@ extract_defs2(#xmlElement{name=memberdef,content=C},{Acc,Skip}) -> end catch throw:SkipName -> {Acc, gb_sets:add(SkipName,Skip)} end. - + extract_def([#xmlElement{name=name,content=[#xmlText{value=Name}]}|R], _N, Skip) -> case Name of "wxUSE" ++ _ -> throw(Name); "wx" ++ _ -> extract_def(R, Name, Skip); - _ -> + _ -> throw(Name) end; extract_def([#xmlElement{name=param}|_],Name,_) -> throw(Name); -extract_def([#xmlElement{name=initializer,content=[#xmlText{value=Val0}]}|_],N,Skip) -> +extract_def([#xmlElement{name=initializer,content=Cs}|_R],N,Skip) -> + Val0 = extract_def2(Cs), case Val0 of "0x" ++ Val1 -> {N, http_util:hexlist_to_integer(Val1)}; _ -> try Val = list_to_integer(Val0), {N, Val} - catch _:_ -> + catch _:_ -> case def_is_ok(Val0, Skip) of false -> throw(N); - NVal when is_integer(NVal) -> + NVal when is_integer(NVal) -> {N, NVal}; NVal -> {N, {NVal,0}} @@ -1414,7 +1417,24 @@ extract_def([_|R],N,Skip) -> extract_def(R,N,Skip); extract_def(_,N,_) -> throw(N). - + +extract_def2([#xmlText{value=Val}|R]) -> + strip_comment(string:strip(Val)) ++ extract_def2(R); +extract_def2([#xmlElement{content=Cs}|R]) -> + extract_def2(Cs) ++ extract_def2(R); +extract_def2([]) -> []. + +strip_comment("/*" ++ Rest) -> + strip_comment_until_end(Rest); +strip_comment("//" ++ _) -> []; +strip_comment([H|R]) -> [H | strip_comment(R)]; +strip_comment([]) -> []. + +strip_comment_until_end("*/" ++ Rest) -> + strip_comment(Rest); +strip_comment_until_end([_|R]) -> + strip_comment_until_end(R). + def_is_ok(Name, Skip) -> Toks = gen_util:tokens(Name,"()| \\:"), R = def_is_ok(Toks, Skip, []), |