1%%
2%% %CopyrightBegin%
3%%
4%% Copyright Ericsson AB 1997-2017. All Rights Reserved.
5%%
6%% Licensed under the Apache License, Version 2.0 (the "License");
7%% you may not use this file except in compliance with the License.
8%% You may obtain a copy of the License at
9%%
10%%     http://www.apache.org/licenses/LICENSE-2.0
11%%
12%% Unless required by applicable law or agreed to in writing, software
13%% distributed under the License is distributed on an "AS IS" BASIS,
14%% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15%% See the License for the specific language governing permissions and
16%% limitations under the License.
17%%
18%% %CopyrightEnd%
19%%
20%%
21
22-ifdef(debug).
23-define(dbg(Fmt, Args), ok=io:format("~p: " ++ Fmt, [?LINE|Args])).
24-else.
25-define(dbg(Fmt, Args), no_debug).
26-endif.
27
28-define('COMPLETE_ENCODE',1).
29-define('TLV_DECODE',2).
30
31-define(MISSING_IN_MAP, asn1__MISSING_IN_MAP).
32
33-record(module,{pos,name,defid,tagdefault='EXPLICIT',exports={exports,[]},imports={imports,[]}, extensiondefault=empty,typeorval}).
34
35-record('ExtensionAdditionGroup',{number}).
36-record('SEQUENCE',{pname=false,tablecinf=false,extaddgroup,components=[]}).
37-record('SET',{pname=false,sorted=false,tablecinf=false,components=[]}).
38-record('ComponentType',{pos,name,typespec,prop,tags,textual_order}).
39-record('ObjectClassFieldType',{classname,class,fieldname,type}).
40
41-record(typedef,{checked=false,pos,name,typespec}).
42-record(classdef, {checked=false,pos,name,module,typespec}).
43-record(valuedef,{checked=false,pos,name,type,value,module}).
44-record(ptypedef,{checked=false,pos,name,args,typespec}).
45-record(pvaluedef,{checked=false,pos,name,args,type,value}).
46-record(pvaluesetdef,{checked=false,pos,name,args,type,valueset}).
47-record(pobjectdef,{checked=false,pos,name,args,class,def}).
48-record(pobjectsetdef,{checked=false,pos,name,args,class,def}).
49
50-record('Constraint',{'SingleValue'=no,'SizeConstraint'=no,'ValueRange'=no,'PermittedAlphabet'=no,
51		      'ContainedSubtype'=no, 'TypeConstraint'=no,'InnerSubtyping'=no,e=no,'Other'=no}).
52-record(simpletableattributes,{objectsetname,c_name,c_index,usedclassfield,
53			       uniqueclassfield,valueindex}).
54-record(type,{tag=[],def,constraint=[],tablecinf=[],inlined=no}).
55
56-record(objectclass,{fields=[],syntax}).
57-record('Object',{classname,gen=true,def}).
58-record('ObjectSet',{class,gen=true,uniquefname,set}).
59
60-record(tag,{class,number,type,form=32}). % form = ?CONSTRUCTED
61% This record holds information about allowed constraint types per type
62-record(cmap,{single_value=no,contained_subtype=no,value_range=no,
63		size=no,permitted_alphabet=no,type_constraint=no,
64		inner_subtyping=no}).
65
66
67-record('EXTENSIONMARK',{pos,val}).
68
69% each IMPORT contains a list of 'SymbolsFromModule'
70-record('SymbolsFromModule',{symbols,module,objid}).
71
72% Externaltypereference -> modulename '.' typename
73-record('Externaltypereference',{pos,module,type}).
74% Externalvaluereference -> modulename '.' typename
75-record('Externalvaluereference',{pos,module,value}).
76
77%% Used to hold a tag for a field in a SEQUENCE/SET. It can also
78%% be used for identifiers in OBJECT IDENTIFIER values, since the
79%% parser cannot always distinguish a SEQUENCE with one element from
80%% an OBJECT IDENTIFIER.
81-record(seqtag,
82	{pos :: integer(),
83	 module :: atom(),
84	 val :: atom()}).
85
86-record(state,
87	{module,
88	 mname,
89	 tname,
90	 erule,
91	 parameters=[],
92	 inputmodules=[],
93	 abscomppath=[],
94	 recordtopname=[],
95	 options,
96	 sourcedir,
97	 error_context				%Top-level thingie (contains line numbers)
98	}).
99
100%% Code generation parameters and options.
101-record(gen,
102        {erule=ber :: 'ber' | 'per',
103         der=false :: boolean(),
104         aligned=false :: boolean(),
105         rec_prefix="" :: string(),
106         macro_prefix="" :: string(),
107         pack=record :: 'record' | 'map',
108         options=[] :: [any()]
109        }).
110
111%% Abstract intermediate representation.
112-record(abst,
113        {name :: module(),                      %Name of module.
114         types,                                 %Types.
115         values,                                %Values.
116         ptypes,                                %Parameterized types.
117         classes,                               %Classes.
118         objects,                               %Objects.
119         objsets                                %Object sets.
120        }).
121
122%% state record used by back-end at partial decode
123%% active is set to 'yes' when a partial decode function is generated.
124%% prefix is set to 'dec-inc-' or 'dec-partial-' is for
125%% incomplete partial decode or partial decode respectively
126%% inc_tag_pattern holds the tags of the significant types/components
127%% for incomplete partial decode.
128%% tag_pattern holds the tags for partial decode.
129%% inc_type_pattern and type_pattern holds the names of the
130%% significant types/components.
131%% func_name holds the name of the function for the toptype.
132%% namelist holds the list of names of types/components that still
133%% haven't been generated.
134%% tobe_refed_funcs is a list of tuples {function names
135%% (Types),namelist of incomplete decode spec}, with function names
136%% that are referenced within other generated partial incomplete
137%% decode functions. They shall be generated as partial incomplete
138%% decode functions.
139%% gen_refed_funcs is as list of tuples with function names,type etc
140%% that have been generated. It is to prevent duplicates of referenced
141%% functions, and to generate the correct decode_inc_disp functions.
142%% suffix_index is a number that is used as a suffix to make function
143%% names unique. It is increased for each additional step into a
144%% constructed type in an exclusive decode.
145%% current_suffix_index is the index of the top type that is generated
146%% at the moment. It may be the same as the current suffix_index or an
147%% earlier value of it.
148-record(gen_state,{active=false,prefix,inc_tag_pattern,
149		  tag_pattern,inc_type_pattern,
150		  type_pattern,func_name,namelist,
151		  tobe_refed_funcs=[],gen_refed_funcs=[],
152		  generated_functions=[],suffix_index=1,
153		  current_suffix_index}).
154