aboutsummaryrefslogtreecommitdiffstats
path: root/lib/diameter/src/compiler/diameter_make.erl
diff options
context:
space:
mode:
authorAnders Svensson <anders@erlang.org>2013-09-23 16:49:44 +0200
committerAnders Svensson <anders@erlang.org>2013-12-01 14:21:35 +0100
commitec91114dc4f14d787eeb07d7332b8803298b575c (patch)
tree374c197b9700fd9b647533cfab58801ddf1b4bdd /lib/diameter/src/compiler/diameter_make.erl
parent742e83daafafd95b31643f9f2a702da725e1ec18 (diff)
downloadotp-ec91114dc4f14d787eeb07d7332b8803298b575c.tar.gz
otp-ec91114dc4f14d787eeb07d7332b8803298b575c.tar.bz2
otp-ec91114dc4f14d787eeb07d7332b8803298b575c.zip
Add diameter_make:flatten/1, remove reformat/1
The latter is now unnecessary given that codec/2 can return a parse and format/1 can return the dictionary format.
Diffstat (limited to 'lib/diameter/src/compiler/diameter_make.erl')
-rw-r--r--lib/diameter/src/compiler/diameter_make.erl34
1 files changed, 19 insertions, 15 deletions
diff --git a/lib/diameter/src/compiler/diameter_make.erl b/lib/diameter/src/compiler/diameter_make.erl
index c883eb91a9..0d8cdec7f2 100644
--- a/lib/diameter/src/compiler/diameter_make.erl
+++ b/lib/diameter/src/compiler/diameter_make.erl
@@ -35,7 +35,7 @@
dict/1,
dict/2,
format/1,
- reformat/1]).
+ flatten/1]).
-export_type([opt/0]).
@@ -144,23 +144,27 @@ is_path(Bin) ->
format(Dict) ->
diameter_dict_util:format(Dict).
-%% reformat/1
+%% flatten/1
%%
-%% Parse a dictionary file and return its formatted equivalent.
+%% Reconstitute a dictionary without @inherits.
--spec reformat(File)
- -> {ok, iolist()}
- | {error, Reason}
- when File :: dict(),
- Reason :: string().
+-spec flatten(orddict:orddict())
+ -> orddict:orddict().
-reformat(File) ->
- case dict(File) of
- {ok, Dict} ->
- {ok, format(Dict)};
- {error, _} = No ->
- No
- end.
+flatten(Dict) ->
+ lists:foldl(fun flatten/2, Dict, [[avp_types, import_avps],
+ [grouped, import_groups],
+ [enum, import_enums]]).
+
+flatten([_,_] = Keys, Dict) ->
+ [Values, Imports] = [orddict:fetch(K, Dict) || K <- Keys],
+ Vs = lists:append([Values | [V || {_,V} <- Imports]]),
+ lists:foldl(fun store/2,
+ Dict,
+ lists:zip([inherits | Keys], [[], Vs, []])).
+
+store({Key, Value}, Dict) ->
+ orddict:store(Key, Value, Dict).
%% ===========================================================================