4
%% Copyright Ericsson AB 1997-2009. All Rights Reserved.
4
%% Copyright Ericsson AB 1997-2011. All Rights Reserved.
6
6
%% The contents of this file are subject to the Erlang Public License,
7
7
%% Version 1.1, (the "License"); you may not use this file except in
8
8
%% compliance with the License. You should have received a copy of the
9
9
%% Erlang Public License along with this software. If not, it can be
10
10
%% retrieved online at http://www.erlang.org/.
12
12
%% Software distributed under the License is distributed on an "AS IS"
13
13
%% basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
14
14
%% the License for the specific language governing rights and limitations
15
15
%% under the License.
39
39
add_tobe_refed_func/1,add_generated_refed_func/1,
40
40
maybe_rename_function/3,latest_sindex/0,current_sindex/0,
41
41
set_current_sindex/1,next_sindex/0,maybe_saved_sindex/2,
42
parse_and_save/2,verbose/3,warning/3,error/3]).
44
44
-include("asn1_records.hrl").
45
45
-include_lib("stdlib/include/erl_compile.hrl").
105
105
compile1(File,Options) when is_list(Options) ->
106
io:format("Erlang ASN.1 version ~p compiling ~p ~n",[?vsn,File]),
107
io:format("Compiler Options: ~p~n",[Options]),
106
verbose("Erlang ASN.1 version ~p compiling ~p ~n",[?vsn,File],Options),
107
verbose("Compiler Options: ~p~n",[Options],Options),
108
108
Ext = filename:extension(File),
109
109
Base = filename:basename(File,Ext),
110
110
OutFile = outfile(Base,"",Options),
149
149
inline(true,Name,Module,Options) ->
150
150
RTmodule = get_runtime_mod(Options),
151
151
IgorOptions = igorify_options(remove_asn_flags(Options)),
152
IgorName = filename:rootname(filename:basename(Name)),
152
IgorName = list_to_atom(filename:rootname(filename:basename(Name))),
153
153
% io:format("*****~nName: ~p~nModules: ~p~nIgorOptions: ~p~n*****~n",
154
154
% [IgorName,Modules++RTmodule,IgorOptions]),
155
io:format("Inlining modules: ~p in ~p~n",[[Module]++RTmodule,IgorName]),
155
verbose("Inlining modules: ~p in ~p~n",[[Module]++RTmodule,IgorName],Options),
156
156
case catch igor:merge(IgorName,[Module]++RTmodule,[{preprocess,true},{stubs,false},{backups,false}]++IgorOptions) of
157
157
{'EXIT',{undef,Reason}} -> %% module igor first in R10B
158
io:format("Module igor in syntax_tools must be available:~n~p~n",
158
error("Module igor in syntax_tools must be available:~n~p~n",
160
160
{error,'no_compilation'};
161
161
{'EXIT',Reason} ->
162
io:format("Merge by igor module failed due to ~p~n",[Reason]),
162
error("Merge by igor module failed due to ~p~n",[Reason],Options),
163
163
{error,'no_compilation'};
165
165
%% io:format("compiling output module: ~p~n",[generated_file(Name,IgorOptions)]),
173
173
compile_set(SetBase,Files,Options)
174
174
when is_list(hd(Files)),is_list(Options) ->
175
175
%% case when there are several input files in a list
176
io:format("Erlang ASN.1 version ~p compiling ~p ~n",[?vsn,Files]),
177
io:format("Compiler Options: ~p~n",[Options]),
176
verbose("Erlang ASN.1 version ~p compiling ~p ~n",[?vsn,Files],Options),
177
verbose("Compiler Options: ~p~n",[Options],Options),
178
178
OutFile = outfile(SetBase,"",Options),
179
179
DbFile = outfile(SetBase,"asn1db",Options),
180
180
Includes = [I || {i,I} <- Options],
728
728
scan(File,Options) ->
729
729
case asn1ct_tok:file(File) of
730
730
{error,Reason} ->
731
io:format("~p~n",[Reason]),
731
error("~p~n",[Reason],Options),
732
732
{false,{error,Reason}};
734
734
case lists:member(ss,Options) of
754
754
is_integer(Line) ->
755
755
BaseName = filename:basename(File),
756
io:format("syntax error at line ~p in module ~s:~n",
756
error("syntax error at line ~p in module ~s:~n",
757
[Line,BaseName],Options);
759
io:format("syntax error in module ~p:~n",[File])
759
error("syntax error in module ~p:~n",
761
762
print_error_message(Message),
762
763
{false,{error,Message}};
763
764
{error,{Line,_Mod,[Message,Token]}} ->
764
io:format("syntax error: ~p ~p at line ~p~n",
765
[Message,Token,Line]),
765
error("syntax error: ~p ~p at line ~p~n",
766
[Message,Token,Line],Options),
766
767
{false,{error,{Line,[Message,Token]}}};
768
769
case lists:member(sp,Options) of
775
io:format("~p~n",[OtherError])
776
error("~p~n",[OtherError],Options)
777
778
parse({false,Tokens},_,_) ->
802
803
NewM = Module#module{typeorval=NewTypeOrVal},
803
804
asn1_db:dbput(NewM#module.name,'MODULE',NewM),
804
805
asn1_db:dbsave(DbFile,M#module.name),
805
io:format("--~p--~n",[{generated,DbFile}]),
806
verbose("--~p--~n",[{generated,DbFile}],Options),
806
807
{true,{M,NewM,GenTypeOrVal}}
823
824
% io:format("Options: ~p~n",[Options]),
824
825
case catch specialized_decode_prepare(EncodingRule,M,GenTOrV,Options) of
825
826
{error, enoent} -> ok;
826
{error, Reason} -> io:format("WARNING: Error in configuration"
827
"file: ~n~p~n",[Reason]);
828
{'EXIT',Reason} -> io:format("WARNING: Internal error when "
829
"analyzing configuration"
830
"file: ~n~p~n",[Reason]);
827
{error, Reason} -> warning("Error in configuration "
828
"file: ~n~p~n",[Reason],Options);
829
{'EXIT',Reason} -> warning("Internal error when "
830
"analyzing configuration "
831
"file: ~n~p~n",[Reason],Options);
835
836
case (catch asn1ct_gen:pgen(OutFile,EncodingRule,
836
M#module.name,GenTOrV)) of
837
M#module.name,GenTOrV,Options)) of
837
838
{'EXIT',Reason2} ->
838
io:format("ERROR: ~p~n",[Reason2]),
839
error("~p~n",[Reason2],Options),
881
io:format("Warning: could not do a consistency check of the ~p file: no asn1 source file was found.~n",[lists:concat([Module,".asn1db"])]),
882
warning("could not do a consistency check of the ~p file: no asn1 source file was found.~n",
883
[lists:concat([Module,".asn1db"])],Options),
882
884
{error,{asn1,input_file_error,Err}}
884
886
parse_and_save1(S,File,Options,Includes) ->
1184
1186
lists:keymember(inline,1,Options)
1186
1189
inline_output(Options,Default) ->
1187
1190
case [X||{inline,X}<-Options] of
1188
1191
[OutputName] ->
1207
1210
compile(File, _OutFile, Options) ->
1208
1211
case catch compile(File, make_erl_options(Options)) of
1209
1212
Exit = {'EXIT',_Reason} ->
1210
io:format("~p~n~s~n",[Exit,"error"]),
1213
error("~p~n~s~n",[Exit,"error"],Options),
1212
1215
{error,_Reason} ->
1213
1216
%% case occurs due to error in asn1ct_parser2,asn1ct_check
1215
1218
%% io:format("~p~n~s~n",[_Reason,"error"]),
1220
1222
ParseRes when is_tuple(ParseRes) ->
1221
1223
io:format("~p~n",[ParseRes]),
1224
1226
io:format("~p~n",[ScanRes]),
1227
io:format("~p~n~s~n",[Unknown,"error"]),
1229
error("~p~n~s~n",[Unknown,"error"],Options),
1238
1240
Includes = Opts#options.includes,
1239
1241
Defines = Opts#options.defines,
1240
1242
Outdir = Opts#options.outdir,
1241
%% Warning = Opts#options.warning,
1243
Warning = Opts#options.warning,
1242
1244
Verbose = Opts#options.verbose,
1243
1245
Specific = Opts#options.specific,
1244
1246
Optimize = Opts#options.optimize,
1277
1279
uper_bin -> [uper_bin]
1280
Options++[report_errors, {cwd, Cwd}, {outdir, Outdir}|
1282
Options++[errors, {cwd, Cwd}, {outdir, Outdir}|
1281
1283
lists:map(fun(Dir) -> {i, Dir} end, Includes)]++Specific.
1283
1285
pretty2(Module,AbsFile) ->
1675
1677
% [concat_sequential(lists:reverse(Comms),
1676
1678
% [LastComm,CompAcc])|Acc]
1677
1679
case lists:reverse(TagCommand) of
1678
[Atom|Comms]�when is_atom(Atom) ->
1680
[Atom|Comms] when is_atom(Atom) ->
1679
1681
[concat_sequential(lists:reverse(Comms),
1680
1682
[Atom,CompAcc])|Acc];
1681
1683
[[Command2,Tag2]|Comms] ->
2518
2520
lists:concat(["_",I]);
2519
2521
make_suffix(_) ->
2524
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2525
%% Report functions.
2527
%% Errors messages are controlled with the 'errors' compiler option
2528
%% Warning messages are controlled with the 'warnings' compiler option
2529
%% Verbose messages are controlled with the 'verbose' compiler option
2531
error(Format, Args, S) ->
2534
io:format("Error: " ++ Format, Args);
2539
warning(Format, Args, S) ->
2540
case is_warning(S) of
2542
io:format("Warning: " ++ Format, Args);
2547
verbose(Format, Args, S) ->
2548
case is_verbose(S) of
2550
io:format(Format, Args);
2555
is_error(S) when is_record(S, state) ->
2556
is_error(S#state.options);
2558
lists:member(errors, O) orelse is_verbose(O).
2560
is_warning(S) when is_record(S, state) ->
2561
is_warning(S#state.options);
2563
lists:member(warnings, O) orelse is_verbose(O).
2565
is_verbose(S) when is_record(S, state) ->
2566
is_verbose(S#state.options);
2568
lists:member(verbose, O).