retro_idl 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (44) hide show
  1. checksums.yaml +7 -0
  2. data/ext/retro_idl/asn/ext_parser/ext_common.h +27 -0
  3. data/ext/retro_idl/asn/ext_parser/ext_parser.l +201 -0
  4. data/ext/retro_idl/asn/ext_parser/ext_parser.y +1207 -0
  5. data/ext/retro_idl/asn/ext_parser/extconf.rb +3 -0
  6. data/ext/retro_idl/asn/ext_parser/lexer.c +2873 -0
  7. data/ext/retro_idl/asn/ext_parser/lexer.h +366 -0
  8. data/ext/retro_idl/asn/ext_parser/parser.c +2963 -0
  9. data/ext/retro_idl/asn/ext_parser/parser.h +175 -0
  10. data/lib/retro_idl/asn/alternative_type.rb +43 -0
  11. data/lib/retro_idl/asn/asn.rb +309 -0
  12. data/lib/retro_idl/asn/asn_error.rb +2 -0
  13. data/lib/retro_idl/asn/base_type.rb +87 -0
  14. data/lib/retro_idl/asn/base_value.rb +75 -0
  15. data/lib/retro_idl/asn/bit_string.rb +44 -0
  16. data/lib/retro_idl/asn/boolean.rb +50 -0
  17. data/lib/retro_idl/asn/builtin_value.rb +51 -0
  18. data/lib/retro_idl/asn/choice.rb +95 -0
  19. data/lib/retro_idl/asn/component_type.rb +56 -0
  20. data/lib/retro_idl/asn/constraint.rb +162 -0
  21. data/lib/retro_idl/asn/defined_type.rb +61 -0
  22. data/lib/retro_idl/asn/defined_value.rb +82 -0
  23. data/lib/retro_idl/asn/enumerated.rb +127 -0
  24. data/lib/retro_idl/asn/enumeration_item.rb +103 -0
  25. data/lib/retro_idl/asn/integer.rb +84 -0
  26. data/lib/retro_idl/asn/location.rb +10 -0
  27. data/lib/retro_idl/asn/named_number.rb +83 -0
  28. data/lib/retro_idl/asn/null.rb +41 -0
  29. data/lib/retro_idl/asn/octetstring.rb +48 -0
  30. data/lib/retro_idl/asn/real.rb +36 -0
  31. data/lib/retro_idl/asn/sequence.rb +132 -0
  32. data/lib/retro_idl/asn/sequenceof.rb +62 -0
  33. data/lib/retro_idl/asn/single_value.rb +26 -0
  34. data/lib/retro_idl/asn/tag.rb +163 -0
  35. data/lib/retro_idl/asn/type_list.rb +121 -0
  36. data/lib/retro_idl/asn/value_assignment.rb +21 -0
  37. data/lib/retro_idl/asn/value_list.rb +48 -0
  38. data/lib/retro_idl.rb +20 -0
  39. data/rakefile +33 -0
  40. data/test/asn/ext_parser/capture_stderr.rb +20 -0
  41. data/test/asn/ext_parser/tc_ext_parser.rb +94 -0
  42. data/test/asn/parser/capture_stderr.rb +20 -0
  43. data/test/asn/parser/tc_parser.rb +90 -0
  44. metadata +133 -0
@@ -0,0 +1,175 @@
1
+ /* A Bison parser, made by GNU Bison 3.0.2. */
2
+
3
+ /* Bison interface for Yacc-like parsers in C
4
+
5
+ Copyright (C) 1984, 1989-1990, 2000-2013 Free Software Foundation, Inc.
6
+
7
+ This program is free software: you can redistribute it and/or modify
8
+ it under the terms of the GNU General Public License as published by
9
+ the Free Software Foundation, either version 3 of the License, or
10
+ (at your option) any later version.
11
+
12
+ This program is distributed in the hope that it will be useful,
13
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
14
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
+ GNU General Public License for more details.
16
+
17
+ You should have received a copy of the GNU General Public License
18
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
19
+
20
+ /* As a special exception, you may create a larger work that contains
21
+ part or all of the Bison parser skeleton and distribute that work
22
+ under terms of your choice, so long as that work isn't itself a
23
+ parser generator using the skeleton or a modified version thereof
24
+ as a parser skeleton. Alternatively, if you modify or redistribute
25
+ the parser skeleton itself, you may (at your option) remove this
26
+ special exception, which will cause the skeleton and the resulting
27
+ Bison output files to be licensed under the GNU General Public
28
+ License without this special exception.
29
+
30
+ This special exception was added by the Free Software Foundation in
31
+ version 2.2 of Bison. */
32
+
33
+ #ifndef YY_YY_EXT_RETRO_IDL_ASN_EXT_PARSER_PARSER_H_INCLUDED
34
+ # define YY_YY_EXT_RETRO_IDL_ASN_EXT_PARSER_PARSER_H_INCLUDED
35
+ /* Debug traces. */
36
+ #ifndef YYDEBUG
37
+ # define YYDEBUG 0
38
+ #endif
39
+ #if YYDEBUG
40
+ extern int yydebug;
41
+ #endif
42
+
43
+ /* Token type. */
44
+ #ifndef YYTOKENTYPE
45
+ # define YYTOKENTYPE
46
+ enum yytokentype
47
+ {
48
+ TOK_EXCEPT = 258,
49
+ TOK_CARET = 259,
50
+ TOK_INTERSECTION = 260,
51
+ TOK_PIPE = 261,
52
+ TOK_UNION = 262,
53
+ TOK_ENDL = 263,
54
+ TOK_LVERSION = 264,
55
+ TOK_ASSIGN = 265,
56
+ TOK_RANGE = 266,
57
+ TOK_ELLIPSES = 267,
58
+ TOK_EXCLAIM = 268,
59
+ TOK_OCTET = 269,
60
+ TOK_CHARACTER = 270,
61
+ TOK_BIT = 271,
62
+ TOK_STRING = 272,
63
+ TOK_SIZE = 273,
64
+ TOK_CHOICE = 274,
65
+ TOK_SEQUENCE = 275,
66
+ TOK_SET = 276,
67
+ TOK_OF = 277,
68
+ TOK_ALL = 278,
69
+ TOK_MIN = 279,
70
+ TOK_MAX = 280,
71
+ TOK_COMPONENTS = 281,
72
+ TOK_COMPONENT = 282,
73
+ TOK_ABSENT = 283,
74
+ TOK_CONTAINING = 284,
75
+ TOK_FROM = 285,
76
+ TOK_INCLUDES = 286,
77
+ TOK_SETTINGS = 287,
78
+ TOK_PRESENT = 288,
79
+ TOK_PATTERN = 289,
80
+ TOK_WITH = 290,
81
+ TOK_OPTIONAL = 291,
82
+ TOK_DEFAULT = 292,
83
+ TOK_IMPLICIT = 293,
84
+ TOK_EXPLICIT = 294,
85
+ TOK_APPLICATION = 295,
86
+ TOK_PRIVATE = 296,
87
+ TOK_UNIVERSAL = 297,
88
+ TOK_CHAR = 298,
89
+ TOK_BOOLEAN = 299,
90
+ TOK_INTEGER = 300,
91
+ TOK_REAL = 301,
92
+ TOK_ENUMERATED = 302,
93
+ TOK_BMPString = 303,
94
+ TOK_GeneralString = 304,
95
+ TOK_GraphicString = 305,
96
+ TOK_IA5String = 306,
97
+ TOK_ISO646String = 307,
98
+ TOK_NumericString = 308,
99
+ TOK_PrintableString = 309,
100
+ TOK_TeletexString = 310,
101
+ TOK_T61String = 311,
102
+ TOK_UniversalString = 312,
103
+ TOK_UTF8String = 313,
104
+ TOK_VideotexString = 314,
105
+ TOK_VisibleString = 315,
106
+ TOK_DATE = 316,
107
+ TOK_DATE_TIME = 317,
108
+ TOK_DURATION = 318,
109
+ TOK_EMBEDDED = 319,
110
+ TOK_PDV = 320,
111
+ TOK_EXTERNAL = 321,
112
+ TOK_RELATIVE_OID_IRI = 322,
113
+ TOK_OBJECT = 323,
114
+ TOK_IDENTIFIER = 324,
115
+ TOK_RELATIVE_IRI = 325,
116
+ TOK_RELATIVE_OID = 326,
117
+ TOK_TIME = 327,
118
+ TOK_TIME_OF_DAY = 328,
119
+ TOK_POSINT = 329,
120
+ TOK_NEGINT = 330,
121
+ TOK_HEXINT = 331,
122
+ TOK_ID = 332,
123
+ TOK_RVERSION = 333,
124
+ TOK_PLUS_INFINITY = 334,
125
+ TOK_MINUS_INFINITY = 335,
126
+ TOK_NOT_A_NUMBER = 336,
127
+ TOK_TRUE = 337,
128
+ TOK_FALSE = 338,
129
+ TOK_NULL = 339,
130
+ TOK_CONTAINS = 340,
131
+ TOK_POSREAL = 341,
132
+ TOK_NEGREAL = 342,
133
+ TOK_HSTRING = 343,
134
+ TOK_BSTRING = 344,
135
+ TOK_CSTRING = 345,
136
+ TOK_DEFINITIONS = 346,
137
+ TOK_BEGIN = 347,
138
+ TOK_END = 348,
139
+ TOK_TAGS = 349,
140
+ TOK_INSTRUCTIONS = 350,
141
+ TOK_EXPORTS = 351,
142
+ TOK_IMPORTS = 352,
143
+ TOK_EXTENSIBILITY = 353,
144
+ TOK_IMPLIED = 354,
145
+ TOK_AUTOMATIC = 355,
146
+ TOK_TYPEREF = 356
147
+ };
148
+ #endif
149
+
150
+ /* Value type. */
151
+ #if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED
152
+ typedef VALUE YYSTYPE;
153
+ # define YYSTYPE_IS_TRIVIAL 1
154
+ # define YYSTYPE_IS_DECLARED 1
155
+ #endif
156
+
157
+ /* Location type. */
158
+ #if ! defined YYLTYPE && ! defined YYLTYPE_IS_DECLARED
159
+ typedef struct YYLTYPE YYLTYPE;
160
+ struct YYLTYPE
161
+ {
162
+ int first_line;
163
+ int first_column;
164
+ int last_line;
165
+ int last_column;
166
+ };
167
+ # define YYLTYPE_IS_DECLARED 1
168
+ # define YYLTYPE_IS_TRIVIAL 1
169
+ #endif
170
+
171
+
172
+
173
+ int yyparse (yyscan_t scanner, VALUE filename, VALUE *tree);
174
+
175
+ #endif /* !YY_YY_EXT_RETRO_IDL_ASN_EXT_PARSER_PARSER_H_INCLUDED */
@@ -0,0 +1,43 @@
1
+ # Copyright (c) 2016 Cameron Harper
2
+ #
3
+ # Permission is hereby granted, free of charge, to any person obtaining a copy of
4
+ # this software and associated documentation files (the "Software"), to deal in
5
+ # the Software without restriction, including without limitation the rights to
6
+ # use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
7
+ # the Software, and to permit persons to whom the Software is furnished to do so,
8
+ # subject to the following conditions:
9
+ #
10
+ # The above copyright notice and this permission notice shall be included in all
11
+ # copies or substantial portions of the Software.
12
+ #
13
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
15
+ # FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
16
+ # COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
17
+ # IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
18
+ # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
19
+
20
+ class RetroIDL::ASN::AlternativeType
21
+
22
+ def initialize(**opts)
23
+
24
+ @type = RetroIDL::ASN.const_get(opts[:class]).new(**opts)
25
+ @parent = parent
26
+
27
+ end
28
+
29
+ def link(mod, stack)
30
+
31
+ @type.link(mod, stack)
32
+
33
+ end
34
+
35
+ # @macro common_to_s
36
+ def to_s
37
+
38
+ @type.to_s
39
+
40
+ end
41
+
42
+ end
43
+
@@ -0,0 +1,309 @@
1
+ # Copyright (c) 2016 Cameron Harper
2
+ #
3
+ # Permission is hereby granted, free of charge, to any person obtaining a copy of
4
+ # this software and associated documentation files (the "Software"), to deal in
5
+ # the Software without restriction, including without limitation the rights to
6
+ # use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
7
+ # the Software, and to permit persons to whom the Software is furnished to do so,
8
+ # subject to the following conditions:
9
+ #
10
+ # The above copyright notice and this permission notice shall be included in all
11
+ # copies or substantial portions of the Software.
12
+ #
13
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
15
+ # FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
16
+ # COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
17
+ # IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
18
+ # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
19
+
20
+ module RetroIDL
21
+
22
+ # Module containing the ASN syntax to Ruby parser
23
+ module ASN
24
+
25
+ # @!macro [new] common_evaluate
26
+ #
27
+ # evaluate a native Ruby value against a type definition
28
+ #
29
+ # @note may be called before linking but will raise exception if references to not resolve
30
+ #
31
+ # @param value [String, Numeric] value to test against type definition
32
+ #
33
+ # @return [TrueClass] value fits type definition
34
+ # @return [FalseClass] value does not fit type definition
35
+ #
36
+ # @raise [ASNError] cannot evaluate against unresolved references
37
+ #
38
+
39
+ # @!macro [new] common_link
40
+ #
41
+ # resolve symbols to definitions in module
42
+ #
43
+ # @param mod [MODULE] module this type belongs to
44
+ # @param stack [Array] objects called before this object for depth first search of recursion
45
+ #
46
+ # @return [MODULE] object has been linked
47
+ # @return [nil] object has not been linked
48
+ #
49
+
50
+ # @!macro [new] common_to_s
51
+ #
52
+ # Convert object to ASN.1 syntax representation
53
+ #
54
+ # @return [String] ASN.1 syntax representation
55
+ #
56
+ # @raise [ASNError]
57
+ #
58
+
59
+ LINK_ERROR = "object must be linked"
60
+ SYMBOL_UNDEFINED_ERROR = "symbol is undefined"
61
+
62
+ # Reserved Words
63
+ #
64
+ # X.680 section 12.38
65
+ RESERVED_CHARACTER_SEQUENCE = [
66
+ "ABSENT".freeze,
67
+ "ENCODED".freeze,
68
+ "INTERSECTION".freeze,
69
+ "SEQUENCE".freeze,
70
+ "ABSTRACT-SYNTAX".freeze,
71
+ "ENCODING-CONTROL".freeze,
72
+ "ISO646String".freeze,
73
+ "SET".freeze,
74
+ "ALL".freeze,
75
+ "END".freeze,
76
+ "MAX".freeze,
77
+ "SETTINGS".freeze,
78
+ "APPLICATION".freeze,
79
+ "ENUMERATED".freeze,
80
+ "MIN".freeze,
81
+ "SIZE".freeze,
82
+ "AUTOMATIC".freeze,
83
+ "EXCEPT".freeze,
84
+ "MINUS-INFINITY".freeze,
85
+ "STRING".freeze,
86
+ "BEGIN".freeze,
87
+ "EXPLICIT".freeze,
88
+ "NOT-A-NUMBER".freeze,
89
+ "SYNTAX".freeze,
90
+ "BIT".freeze,
91
+ "EXPORTS".freeze,
92
+ "NULL".freeze,
93
+ "T61String".freeze,
94
+ "BMPString".freeze,
95
+ "EXTENSIBILITY".freeze,
96
+ "NumericString".freeze,
97
+ "TAGS".freeze,
98
+ "BOOLEAN".freeze,
99
+ "EXTERNAL".freeze,
100
+ "OBJECT".freeze,
101
+ "TeletexString".freeze,
102
+ "BY".freeze,
103
+ "FALSE".freeze,
104
+ "ObjectDescriptor".freeze,
105
+ "TIME".freeze,
106
+ "CHARACTER".freeze,
107
+ "FROM".freeze,
108
+ "OCTET".freeze,
109
+ "TIME-OF-DAY".freeze,
110
+ "CHOICE".freeze,
111
+ "GeneralizedTime".freeze,
112
+ "OF".freeze,
113
+ "TRUE".freeze,
114
+ "CLASS".freeze,
115
+ "GeneralString".freeze,
116
+ "OID-IRI".freeze,
117
+ "TYPE-IDENTIFIER".freeze,
118
+ "COMPONENT".freeze,
119
+ "GraphicString".freeze,
120
+ "OPTIONAL".freeze,
121
+ "UNION".freeze,
122
+ "COMPONENTS".freeze,
123
+ "IA5String".freeze,
124
+ "PATTERN".freeze,
125
+ "UNIQUE".freeze,
126
+ "CONSTRAINED".freeze,
127
+ "IDENTIFIER".freeze,
128
+ "PDV".freeze,
129
+ "UNIVERSAL".freeze,
130
+ "CONTAINING".freeze,
131
+ "IMPLICIT".freeze,
132
+ "PLUS-INFINITY".freeze,
133
+ "UniversalString".freeze,
134
+ "DATE".freeze,
135
+ "IMPLIED".freeze,
136
+ "PRESENT".freeze,
137
+ "UTCTime".freeze,
138
+ "DATE-TIME".freeze,
139
+ "IMPORTS".freeze,
140
+ "PrintableString".freeze,
141
+ "UTF8String".freeze,
142
+ "DEFAULT".freeze,
143
+ "INCLUDES".freeze,
144
+ "PRIVATE".freeze,
145
+ "VideotexString".freeze,
146
+ "DEFINITIONS".freeze,
147
+ "INSTANCE".freeze,
148
+ "REAL".freeze,
149
+ "VisibleString".freeze,
150
+ "DURATION".freeze,
151
+ "INSTRUCTIONS".freeze,
152
+ "RELATIVE-OID".freeze,
153
+ "WITH".freeze,
154
+ "EMBEDDED".freeze,
155
+ "INTEGER".freeze,
156
+ "RELATIVE-OID-IRI".freeze
157
+ ]
158
+
159
+ # test a typereference string against requirements
160
+ #
161
+ # @param location [Hash] location of the typereference
162
+ # @param typereference [String] typereference string
163
+ #
164
+ # @return [TrueClass] typereference meets format requirements
165
+ # @return [FalseClass] typereference does not meet format requirements
166
+ #
167
+ def self.is_typereference?(location, typereference)
168
+
169
+ result = true
170
+ if typereference[/^[A-Z]/].nil?
171
+ putError(location, "typereference \"#{typereference}\": The initial character shall be an upper-case letter (12.2.1)")
172
+ result = false
173
+ end
174
+ if typereference[/--/]
175
+ putError(location, "typereference \"#{typereference}\": A hyphen shall not be immediately followed by another hyphen (12.2.1)")
176
+ result = false
177
+ end
178
+ if typereference[/-$/]
179
+ putError(location, "typereference \"#{typereference}\": A hyphen shall not be the last character (12.2.1)")
180
+ result = false
181
+ end
182
+ if RESERVED_CHARACTER_SEQUENCE.include?(typereference)
183
+ putError(location, "typereference \"#{typereference}\": A typereference shall not be one of the reserved character sequences listed in 12.38 (12.2.2)")
184
+ result = false
185
+ end
186
+ return result
187
+
188
+ end
189
+
190
+ def self.putError(location, message)
191
+ STDERR.puts "#{location[:fileName]}:#{location[:firstLine]}:#{location[:firstCol]}: error: #{message}"
192
+ end
193
+
194
+ # test an identifier string against requirements
195
+ #
196
+ # @param location [Hash] location of the identifier
197
+ # @param identifier [String] identifier string
198
+ #
199
+ # @return [TrueClass] identifier meets format requirements
200
+ # @return [FalseClass] identifier does not meet format requirements
201
+ #
202
+ def self.is_identifier?(location, identifier)
203
+ result = true
204
+ if identifier[/^[a-z]/].nil?
205
+ putError(location, "identifier \"#{identifier}\": The initial character shall be a lower-case letter (12.4)")
206
+ result = false
207
+ end
208
+ if identifier[/--/]
209
+ putError(location, "identifier \"#{identifier}\": A hyphen shall not be immediately followed by another hyphen (12.4)")
210
+ result = false
211
+ end
212
+ if identifier[/-$/]
213
+ putError(location, "identifier \"#{identifier}\": A hyphen shall not be the last character (12.4)")
214
+ result = false
215
+ end
216
+ return result
217
+ end
218
+
219
+ class ASN
220
+
221
+ def initialize(input)
222
+
223
+ errors = false
224
+
225
+ @modules = {}
226
+
227
+ # run the parser to produce the syntax tree
228
+ tree = RetroIDL::ASN.parseFileBuffer(input)
229
+
230
+ if tree.nil?
231
+ raise "tree should not be nil"
232
+ end
233
+
234
+ # initialise the assignments
235
+ @assignments = {}
236
+ tree[:assignments].each do |assignment|
237
+
238
+ if @assignments[assignment[:id]]
239
+ ASN.putError(assignment[:location], "duplicate assignment")
240
+ errors = true
241
+ else
242
+ begin
243
+ @assignments[assignment[:id]] = RetroIDL::ASN.const_get(assignment[:class]).new(**assignment)
244
+ rescue ASNError
245
+ errors = true
246
+ end
247
+ end
248
+ end
249
+
250
+ if errors
251
+ raise
252
+ end
253
+
254
+ @assignments.each do |assignment|
255
+ assignment.link(self)
256
+ end
257
+
258
+ end
259
+
260
+ # @macro common_to_s
261
+ def to_s
262
+
263
+ result = ""
264
+
265
+ @assignments.each do |id, assignment|
266
+
267
+ case assignment.class
268
+ when DefinedValue, BuiltinValue
269
+ result << "#{id} #{assignment.governor} ::= #{assignment}"
270
+ else
271
+ result << " #{id} ::= #{assignment}"
272
+ end
273
+
274
+ end
275
+
276
+ result
277
+
278
+ end
279
+
280
+ end
281
+
282
+ end
283
+
284
+ end
285
+
286
+ require 'retro_idl/asn/asn_error'
287
+ require 'retro_idl/asn/location'
288
+ require "retro_idl/asn/ext_parser"
289
+
290
+ require 'retro_idl/asn/tag'
291
+
292
+ require 'retro_idl/asn/base_type'
293
+ require 'retro_idl/asn/component_type'
294
+ require 'retro_idl/asn/type_list'
295
+ require 'retro_idl/asn/alternative_type'
296
+ require 'retro_idl/asn/value_list'
297
+ require 'retro_idl/asn/named_number'
298
+ require 'retro_idl/asn/enumeration_item'
299
+
300
+ require 'retro_idl/asn/null'
301
+ require 'retro_idl/asn/bitstring'
302
+ require 'retro_idl/asn/octetstring'
303
+ require 'retro_idl/asn/real'
304
+ require 'retro_idl/asn/integer'
305
+ require 'retro_idl/asn/enumerated'
306
+ require 'retro_idl/asn/boolean'
307
+ require 'retro_idl/asn/choice'
308
+ require 'retro_idl/asn/sequence'
309
+ require 'retro_idl/asn/sequenceof'
@@ -0,0 +1,2 @@
1
+ class RetroIDL::ASN::ASNError < Exception
2
+ end
@@ -0,0 +1,87 @@
1
+ # Copyright (c) 2016 Cameron Harper
2
+ #
3
+ # Permission is hereby granted, free of charge, to any person obtaining a copy of
4
+ # this software and associated documentation files (the "Software"), to deal in
5
+ # the Software without restriction, including without limitation the rights to
6
+ # use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
7
+ # the Software, and to permit persons to whom the Software is furnished to do so,
8
+ # subject to the following conditions:
9
+ #
10
+ # The above copyright notice and this permission notice shall be included in all
11
+ # copies or substantial portions of the Software.
12
+ #
13
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
15
+ # FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
16
+ # COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
17
+ # IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
18
+ # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
19
+
20
+ class RetroIDL::ASN::BaseType
21
+
22
+ attr_reader :id
23
+
24
+ # Common type object initialisation
25
+ #
26
+ # @param opts [Hash]
27
+ #
28
+ # @option opts [String, NilClass] :id object identifer or type reference (nil for anon objects)
29
+ # @option opts [Location] :location
30
+ # @option opts [Hash] :tag
31
+ #
32
+ # @raise [ASNError]
33
+ #
34
+ def initialize(**opts)
35
+
36
+ @mod = nil
37
+ @tag = nil
38
+ @parent = parent
39
+ @id = opts[:id]
40
+ @location = opts[:location]
41
+ @constraint = nil
42
+
43
+ if opts[:tag]
44
+ @tag = Tag.new(**opts[:tag])
45
+ end
46
+ if opts[:constraint]
47
+ @constraint = Constraint.new(self, **opts[:constraint])
48
+ end
49
+
50
+ end
51
+
52
+ # @macro common_link
53
+ def link(mod, stack)
54
+
55
+ if @mod.nil? or @mod != mod
56
+
57
+ @mod = nil
58
+
59
+ if @tag.nil? or @tag.link(mod, [])
60
+
61
+ @mod = mod
62
+ stack.push self
63
+ @mod.setBranch stack
64
+
65
+ end
66
+
67
+ else
68
+
69
+ @mod
70
+
71
+ end
72
+
73
+ end
74
+
75
+ def self.===(otherClass)
76
+
77
+ if self == otherClass
78
+ true
79
+ else
80
+ false
81
+ end
82
+
83
+ end
84
+
85
+
86
+
87
+ end
@@ -0,0 +1,75 @@
1
+ # Copyright (c) 2016 Cameron Harper
2
+ #
3
+ # Permission is hereby granted, free of charge, to any person obtaining a copy of
4
+ # this software and associated documentation files (the "Software"), to deal in
5
+ # the Software without restriction, including without limitation the rights to
6
+ # use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
7
+ # the Software, and to permit persons to whom the Software is furnished to do so,
8
+ # subject to the following conditions:
9
+ #
10
+ # The above copyright notice and this permission notice shall be included in all
11
+ # copies or substantial portions of the Software.
12
+ #
13
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
15
+ # FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
16
+ # COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
17
+ # IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
18
+ # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
19
+
20
+ # methods and attributes common to ASN.1 values
21
+ class RetroIDL::ASN::BaseValue
22
+
23
+ def initialize(**opts)
24
+ @value = opts[:value]
25
+ end
26
+
27
+ attr_reader :governor
28
+
29
+ # @return [String, NilClass] identifier
30
+ attr_reader :id
31
+
32
+ # @macro common_link
33
+ def link(mod, stack)
34
+
35
+ if @mod.nil? or @mod != mod
36
+
37
+ @mod = nil
38
+
39
+ if @governor.link(mod, stack.push(self))
40
+
41
+ if @governor.evaluate(value)
42
+
43
+ @mod = mod
44
+
45
+ else
46
+
47
+ ASN.putError(@location, "evaluate didn't work")
48
+
49
+ end
50
+
51
+ end
52
+
53
+ else
54
+
55
+ @mod
56
+
57
+ end
58
+
59
+ end
60
+
61
+ def self.===(otherClass)
62
+
63
+ if self == otherClass
64
+
65
+ true
66
+
67
+ else
68
+
69
+ false
70
+
71
+ end
72
+
73
+ end
74
+
75
+ end