From 8e43bffda5069aecdd2375eb409e9c03b7ff692b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Gustavsson?= Date: Mon, 13 Oct 2014 15:59:27 +0200 Subject: Simplify handling of an empty object definition When the parser sees: something SOMETHING ::= {} it has no way of knowing whether 'something' is an value or an object. It depends on how SOMETHING is defined. For example: SOMETHING ::= SEQUENCE {} or SOMETHING ::= CLASS { &id OPTIONAL } Because of that ambiguity, there is no way to avoid a special case when we check an object definition. However, there is no need to invent an entire new checking function for this special case. It is much easier to just pretend that the parser gave us {object,defaultsyntax,[]} and let check_objectdefn/3 check it in the usual way. --- lib/asn1/src/asn1ct_check.erl | 28 ++++------------------------ lib/asn1/test/error_SUITE.erl | 7 ++++++- 2 files changed, 10 insertions(+), 25 deletions(-) (limited to 'lib') diff --git a/lib/asn1/src/asn1ct_check.erl b/lib/asn1/src/asn1ct_check.erl index 79d55feb9f..aba0e6a9ef 100644 --- a/lib/asn1/src/asn1ct_check.erl +++ b/lib/asn1/src/asn1ct_check.erl @@ -796,13 +796,10 @@ check_object(S,_ObjDef,#'Object'{classname=ClassRef,def=ObjectDef}) -> {_,Object} = get_referenced_type(S,ObjectDef), check_object(S, Object, object_to_check(Object)); [] -> - %% An object with no fields. All class fields must be - %% optional or default. Check that all fields in - %% class are 'OPTIONAL' or 'DEFAULT' - class_fields_optional_check(S,ClassDef), - #'Object'{def={object,defaultsyntax,[]}}; - _ -> - exit({error,{no_object,ObjectDef},S}) + %% An object with no fields (parsed as a value). + Def = {object,defaultsyntax,[]}, + NewSettingList = check_objectdefn(S, Def, ClassDef), + #'Object'{def=NewSettingList} end, Gen = gen_incl(S,NewObj#'Object'.def, (ClassDef#classdef.typespec)#objectclass.fields), @@ -967,23 +964,6 @@ prepare_objset({#type{}=Type,#type{}=Ext}) -> prepare_objset(Ret) -> Ret. -class_fields_optional_check(S,#classdef{typespec=ClassSpec}) -> - Fields = ClassSpec#objectclass.fields, - class_fields_optional_check1(S,Fields). - -class_fields_optional_check1(_S,[]) -> - ok; -class_fields_optional_check1(S,[{typefield,_,'OPTIONAL'}|Rest]) -> - class_fields_optional_check1(S,Rest); -class_fields_optional_check1(S,[{fixedtypevaluefield,_,_,_,'OPTIONAL'}|Rest]) -> - class_fields_optional_check1(S,Rest); -class_fields_optional_check1(S,[{fixedtypevaluesetfield,_,_,'OPTIONAL'}|Rest]) -> - class_fields_optional_check1(S,Rest); -class_fields_optional_check1(S,[{objectfield,_,_,_,'OPTIONAL'}|Rest]) -> - class_fields_optional_check1(S,Rest); -class_fields_optional_check1(S,[{objectsetfield,_,_,'OPTIONAL'}|Rest]) -> - class_fields_optional_check1(S,Rest). - %% ObjectSetFromObjects functionality %% The fieldname is a list of field names.They may be objects or diff --git a/lib/asn1/test/error_SUITE.erl b/lib/asn1/test/error_SUITE.erl index 630daf75c6..f03c2eab16 100644 --- a/lib/asn1/test/error_SUITE.erl +++ b/lib/asn1/test/error_SUITE.erl @@ -227,6 +227,7 @@ objects(Config) -> " obj3 CL ::= { &Data OCTET STRING }\n" " obj4 SMALL ::= { &code 42 }\n" " InvalidSet CL ::= { obj1 }\n" + " obj5 CL ::= {}\n" " CL ::= CLASS {\n" " &code INTEGER UNIQUE,\n" @@ -255,7 +256,11 @@ objects(Config) -> {structured_error,{M,5},asn1ct_check, {missing_mandatory_fields,[i],obj4}}, {structured_error,{M,6},asn1ct_check, - {invalid_fields,[wrong],'InvalidSet'}} + {invalid_fields,[wrong],'InvalidSet'}}, + {structured_error,{M,7},asn1ct_check, + {missing_mandatory_fields, + ['Data','Set','VarTypeValue',code,enum,object, + vartypevalue],obj5}} ] } = run(P, Config), ok. -- cgit v1.2.3