aboutsummaryrefslogtreecommitdiffstats
path: root/lib/diameter/src/compiler/diameter_make.erl
diff options
context:
space:
mode:
authorAnders Svensson <[email protected]>2011-12-07 16:51:46 +0100
committerAnders Svensson <[email protected]>2011-12-07 16:51:46 +0100
commit24f0d3ee266d56cc83435401230a8bb85a0464d3 (patch)
treeecb3a5e9d8539e87efb5677494894f3ced97a2cb /lib/diameter/src/compiler/diameter_make.erl
parent977f7510818925d9293361c14788fdb872614ac1 (diff)
parentf2a4059d06f8b76d2c1da14197f170deebd64f45 (diff)
downloadotp-24f0d3ee266d56cc83435401230a8bb85a0464d3.tar.gz
otp-24f0d3ee266d56cc83435401230a8bb85a0464d3.tar.bz2
otp-24f0d3ee266d56cc83435401230a8bb85a0464d3.zip
Merge branch 'anders/diameter/dict_error_identification/OTP-9639'
* anders/diameter/dict_error_identification/OTP-9639: (27 commits) Update documentation Improve base_rfc3588.dia formatting Make typo fix backwards compatible Fix base_rfc3588.dia typo Check compiler dependencies in app suite Move type definitions into diameter.erl Fix interpretation of vendor id in @grouped Add range checks on dictionary integers Don't explicitly load inherited modules Tweak diameter_make interface Add format testcase to compiler suite Add diameter_dict_util:format/1 for reconstructing a dictionary file Make diameter_types usable with @codecs Minor codegen tweaks Remove unnecessary includes Add compiler suite Update app suite Update codec suite Vendor id fixes No longer inherit common dictionary in relay dictionary ...
Diffstat (limited to 'lib/diameter/src/compiler/diameter_make.erl')
-rw-r--r--lib/diameter/src/compiler/diameter_make.erl106
1 files changed, 80 insertions, 26 deletions
diff --git a/lib/diameter/src/compiler/diameter_make.erl b/lib/diameter/src/compiler/diameter_make.erl
index 5380ee56ca..16e30c1ffb 100644
--- a/lib/diameter/src/compiler/diameter_make.erl
+++ b/lib/diameter/src/compiler/diameter_make.erl
@@ -20,59 +20,113 @@
%%
%% Module alternative to diameterc for dictionary compilation.
%%
-%% Eg. 1> diameter_make:dict("mydict.dia").
+%% Eg. 1> diameter_make:codec("mydict.dia").
%%
-%% $ erl -noshell \
+%% $ erl -noinput \
%% -boot start_clean \
-%% -s diameter_make dict mydict.dia \
+%% -eval 'ok = diameter_make:codec("mydict.dia")' \
%% -s init stop
%%
-module(diameter_make).
--export([dict/1,
+-export([codec/1,
+ codec/2,
+ dict/1,
dict/2,
- spec/1,
- spec/2]).
+ format/1,
+ reformat/1]).
--type opt() :: {outdir|include|name|prefix|inherits, string()}
+-export_type([opt/0]).
+
+-type opt() :: {include|outdir|name|prefix|inherits, string()}
| verbose
| debug.
-%% dict/1-2
+%% ===========================================================================
+
+%% codec/1-2
+%%
+%% Parse a dictionary file and generate a codec module.
+
+-spec codec(Path, [opt()])
+ -> ok
+ | {error, Reason}
+ when Path :: string(),
+ Reason :: string().
+
+codec(File, Opts) ->
+ case dict(File, Opts) of
+ {ok, Dict} ->
+ make(File,
+ Opts,
+ Dict,
+ [spec || _ <- [1], lists:member(debug, Opts)] ++ [erl, hrl]);
+ {error, _} = E ->
+ E
+ end.
+
+codec(File) ->
+ codec(File, []).
+
+%% dict/2
+%%
+%% Parse a dictionary file and return the orddict that a codec module
+%% returns from dict/0.
-spec dict(string(), [opt()])
- -> ok.
+ -> {ok, orddict:orddict()}
+ | {error, string()}.
-dict(File, Opts) ->
- make(File,
- Opts,
- spec(File, Opts),
- [spec || _ <- [1], lists:member(debug, Opts)] ++ [erl, hrl]).
+dict(Path, Opts) ->
+ case diameter_dict_util:parse({path, Path}, Opts) of
+ {ok, _} = Ok ->
+ Ok;
+ {error = E, Reason} ->
+ {E, diameter_dict_util:format_error(Reason)}
+ end.
dict(File) ->
dict(File, []).
-%% spec/2
+%% format/1
+%%
+%% Turn an orddict returned by dict/1-2 back into a dictionary file
+%% in the form of an iolist().
+
+-spec format(orddict:orddict())
+ -> iolist().
+
+format(Dict) ->
+ diameter_dict_util:format(Dict).
--spec spec(string(), [opt()])
- -> orddict:orddict().
+%% reformat/1
+%%
+%% Parse a dictionary file and return its formatted equivalent.
-spec(File, Opts) ->
- diameter_spec_util:parse(File, Opts).
+-spec reformat(File)
+ -> {ok, iolist()}
+ | {error, Reason}
+ when File :: string(),
+ Reason :: string().
-spec(File) ->
- spec(File, []).
+reformat(File) ->
+ case dict(File) of
+ {ok, Dict} ->
+ {ok, format(Dict)};
+ {error, _} = No ->
+ No
+ end.
%% ===========================================================================
make(_, _, _, []) ->
ok;
-make(File, Opts, Spec, [Mode | Rest]) ->
- try diameter_codegen:from_spec(File, Spec, Opts, Mode) of
- ok ->
- make(File, Opts, Spec, Rest)
+make(File, Opts, Dict, [Mode | Rest]) ->
+ try
+ ok = diameter_codegen:from_dict(File, Dict, Opts, Mode),
+ make(File, Opts, Dict, Rest)
catch
error: Reason ->
- {error, {Reason, Mode, erlang:get_stacktrace()}}
+ erlang:error({Reason, Mode, erlang:get_stacktrace()})
end.