From ec91114dc4f14d787eeb07d7332b8803298b575c Mon Sep 17 00:00:00 2001 From: Anders Svensson Date: Mon, 23 Sep 2013 16:49:44 +0200 Subject: 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. --- lib/diameter/src/compiler/diameter_make.erl | 34 ++++++++++++++++------------- 1 file changed, 19 insertions(+), 15 deletions(-) (limited to 'lib/diameter/src/compiler') 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). %% =========================================================================== -- cgit v1.2.3