diff options
author | Dan Gudmundsson <[email protected]> | 2014-11-27 13:41:00 +0100 |
---|---|---|
committer | Björn Gustavsson <[email protected]> | 2015-01-12 11:40:28 +0100 |
commit | a008779a0d8b602a56c63d333f692f51e0b64994 (patch) | |
tree | aff89e6295d2f5199f90a78e2677e50c995bbbba | |
parent | 411f2d2c42ab86872186c0ea015f2e76a84c30ab (diff) | |
download | otp-a008779a0d8b602a56c63d333f692f51e0b64994.tar.gz otp-a008779a0d8b602a56c63d333f692f51e0b64994.tar.bz2 otp-a008779a0d8b602a56c63d333f692f51e0b64994.zip |
asn1: Rewrite error handling for EXPORT to new style
-rw-r--r-- | lib/asn1/src/asn1ct_check.erl | 37 | ||||
-rw-r--r-- | lib/asn1/test/asn1_SUITE.erl | 7 | ||||
-rw-r--r-- | lib/asn1/test/asn1_SUITE_data/IllegalExport.asn1 | 7 | ||||
-rw-r--r-- | lib/asn1/test/error_SUITE.erl | 21 |
4 files changed, 25 insertions, 47 deletions
diff --git a/lib/asn1/src/asn1ct_check.erl b/lib/asn1/src/asn1ct_check.erl index 68b1a499e3..d76ecee3b9 100644 --- a/lib/asn1/src/asn1ct_check.erl +++ b/lib/asn1/src/asn1ct_check.erl @@ -241,26 +241,18 @@ check_exports(S,Module = #module{}) -> {exports,all} -> []; {exports,ExportList} when is_list(ExportList) -> - IsNotDefined = + IsNotDefined = fun(X) -> - case catch get_referenced_type(S,X) of - {error,{asn1,_}} -> - true; - _ -> false + try + _ = get_referenced_type(S,X), + false + catch {error,_} -> + true end end, - case lists:filter(IsNotDefined,ExportList) of - [] -> - []; - NoDefExp -> - GetName = - fun(T = #'Externaltypereference'{type=N})-> - %%{exported,undefined,entity,N} - NewS=S#state{type=T,tname=N}, - error({export,"exported undefined entity",NewS}) - end, - lists:map(GetName,NoDefExp) - end + [return_asn1_error(S, Ext, {undefined_export, Undef}) || + Ext = #'Externaltypereference'{type=Undef} <- ExportList, + IsNotDefined(Ext)] end. check_imports(S, #module{imports={imports,Imports}}) -> @@ -5992,6 +5984,8 @@ format_error({syntax_undefined_field,Field}) -> [Field]); format_error({undefined,Name}) -> io_lib:format("'~s' is referenced, but is not defined", [Name]); +format_error({undefined_export,Ref}) -> + io_lib:format("'~s' is exported but is not defined", [Ref]); format_error({undefined_field,FieldName}) -> io_lib:format("the field '&~s' is undefined", [FieldName]); format_error({undefined_import,Ref,Module}) -> @@ -6011,15 +6005,6 @@ format_fields([H|T]) -> error({_,{structured_error,_,_,_}=SE,_}) -> SE; -error({export,Msg,#state{mname=Mname,type=Ref,tname=Typename}}) -> - Pos = Ref#'Externaltypereference'.pos, - io:format("asn1error:~p:~p:~p~n~p~n",[Pos,Mname,Typename,Msg]), - {error,{export,Pos,Mname,Typename,Msg}}; -% error({type,{Msg1,Msg2},#state{mname=Mname,type=Type,tname=Typename}}) -% when is_record(Type,typedef) -> -% io:format("asn1error:~p:~p:~p ~p~n", -% [Type#typedef.pos,Mname,Typename,Msg1]), -% {error,{type,Type#typedef.pos,Mname,Typename,Msg1,Msg2}}; error({type,Msg,#state{mname=Mname,type=Type,tname=Typename}}) when is_record(Type,type) -> io:format("asn1error:~p:~p~n~p~n", diff --git a/lib/asn1/test/asn1_SUITE.erl b/lib/asn1/test/asn1_SUITE.erl index 79925f9ddf..3b6e18c46d 100644 --- a/lib/asn1/test/asn1_SUITE.erl +++ b/lib/asn1/test/asn1_SUITE.erl @@ -142,7 +142,6 @@ groups() -> testMergeCompile, testobj, testDeepTConstr, - testExport, testImport, testDER, testDEFAULT, @@ -827,12 +826,6 @@ testDeepTConstr(Config, Rule, Opts) -> [Rule|Opts]), testDeepTConstr:main(Rule). -testExport(Config) -> - {error, _} = - asn1ct:compile(filename:join(?config(data_dir, Config), - "IllegalExport"), - [{outdir, ?config(case_dir, Config)}]). - testImport(Config) -> test(Config, fun testImport/3). testImport(Config, Rule, Opts) -> diff --git a/lib/asn1/test/asn1_SUITE_data/IllegalExport.asn1 b/lib/asn1/test/asn1_SUITE_data/IllegalExport.asn1 deleted file mode 100644 index 1b5e42ad3c..0000000000 --- a/lib/asn1/test/asn1_SUITE_data/IllegalExport.asn1 +++ /dev/null @@ -1,7 +0,0 @@ -IllegalExport DEFINITIONS ::= -BEGIN -EXPORTS T, KalleAnka; - -T ::= INTEGER - -END diff --git a/lib/asn1/test/error_SUITE.erl b/lib/asn1/test/error_SUITE.erl index db997d569d..c386fd6d31 100644 --- a/lib/asn1/test/error_SUITE.erl +++ b/lib/asn1/test/error_SUITE.erl @@ -21,7 +21,7 @@ -export([suite/0,all/0,groups/0, already_defined/1,bitstrings/1, classes/1,constraints/1,enumerated/1, - imports/1,instance_of/1,integers/1,objects/1, + imports_exports/1,instance_of/1,integers/1,objects/1, object_field_extraction/1,oids/1,rel_oids/1, object_sets/1,parameterization/1, syntax/1,table_constraints/1,values/1]). @@ -40,7 +40,7 @@ groups() -> classes, constraints, enumerated, - imports, + imports_exports, instance_of, integers, objects, @@ -170,7 +170,7 @@ enumerated(Config) -> } = run(P, Config), ok. -imports(Config) -> +imports_exports(Config) -> Ext = 'ExternalModule', ExtP = {Ext, <<"ExternalModule DEFINITIONS AUTOMATIC TAGS ::= BEGIN\n" @@ -189,23 +189,30 @@ imports(Config) -> M = 'Imports', P = {M, <<"Imports DEFINITIONS AUTOMATIC TAGS ::= BEGIN\n" + "EXPORTS\n" + " T, UndefinedType;\n" + "IMPORTS\n" " NotDefined, Existing, Int, NonExistingImport\n" " FROM ExternalModule\n" " X FROM UndefinedModule objid\n" " Y, Z FROM UndefinedModule2;\n" + "objid OBJECT IDENTIFIER ::= {joint-iso-ccitt(2) remote-operations(4)\n" " notation(0)}\n" + "T ::= INTEGER\n" "END\n">>}, {error,[{structured_error,{M,3},asn1ct_check, + {undefined_export, 'UndefinedType'}}, + {structured_error,{M,5},asn1ct_check, {undefined_import,'NonExistingImport',Ext}}, - {structured_error,{M,3},asn1ct_check, - {undefined_import,'NotDefined',Ext}}, {structured_error,{M,5},asn1ct_check, + {undefined_import,'NotDefined',Ext}}, + {structured_error,{M,7},asn1ct_check, {undefined_import,'X','UndefinedModule'}}, - {structured_error,{M,6},asn1ct_check, + {structured_error,{M,8},asn1ct_check, {undefined_import,'Y','UndefinedModule2'}}, - {structured_error,{M,6},asn1ct_check, + {structured_error,{M,8},asn1ct_check, {undefined_import,'Z','UndefinedModule2'}} ]} = run(P, Config), ok. |