Merge PR99 and its fixes to support parsing Information Object and Information Object Set

This is a collection of works :

1. Based on @zhanglei002's pull request 99.

2. A fix by @AuthenticEshkinKot and merged by @mouse07410 at
   commit 2c8d366bbe1fc4e4c041e9b0eb9779f8a42d754b of https://github.com/mouse07410/asn1c
   to support parsing of Information Object and Information Object Set

3. A fix by @Uri Blumenthal in asn1fix_derefv.c at :
   commit ec0ade4f87c807e763e3f35fc5466adb6dda3473 of https://github.com/mouse07410/asn1c
   to solve crash on asn1p_value_free().

4. My pull request 18 to @mouse07410's https://github.com/mouse07410/asn1c to solve
   problems found during parsing ASN.1 modules of S1AP, RANAP and J2735-201603.

5. My pull request 22 to @mouse07410's https://github.com/mouse07410/asn1c to solve issue 147
   and to solve the problem during parsing ASN.1 module of NBAP.

6. My pull request 23 to @mouse07410's https://github.com/mouse07410/asn1c to fix memory leakage
   introduced in aforementioned commits.
   Most code changes are the same as pull request 153 to this repository.

7. A fix of my bug in item 6 which result asn1c crash, fixed by @mouse07410.
diff --git a/libasn1parser/asn1p_y.y b/libasn1parser/asn1p_y.y
index b8406b6..61b1e3e 100644
--- a/libasn1parser/asn1p_y.y
+++ b/libasn1parser/asn1p_y.y
@@ -48,7 +48,7 @@
 #define	CONSTRAINT_INSERT(root, constr_type, arg1, arg2) do {		\
 		if(arg1->type != constr_type) {				\
 			int __ret;					\
-			root = asn1p_constraint_new(yylineno);		\
+			root = asn1p_constraint_new(yylineno, currentModule);	\
 			checkmem(root);					\
 			root->type = constr_type;			\
 			__ret = asn1p_constraint_insert(root,		\
@@ -315,6 +315,7 @@
 %type	<a_constr>		optConstraints
 %type	<a_constr>		Constraint
 %type	<a_constr>		SubtypeConstraint
+%type	<a_constr>		ConstraintSpecs
 %type	<a_constr>		GeneralConstraint
 %type	<a_constr>		SetOfConstraints
 %type	<a_constr>		ElementSetSpecs		/* 1..2,...,3 */
@@ -875,7 +876,7 @@
 	}
 	| TypeRefName ':' Identifier {
 		int ret;
-		$$.governor = asn1p_ref_new(yylineno);
+		$$.governor = asn1p_ref_new(yylineno, currentModule);
 		ret = asn1p_ref_add_component($$.governor, $1, 0);
 		checkmem(ret == 0);
 		$$.argument = $3;
@@ -883,7 +884,7 @@
 	}
 	| TypeRefName ':' TypeRefName {
 		int ret;
-		$$.governor = asn1p_ref_new(yylineno);
+		$$.governor = asn1p_ref_new(yylineno, currentModule);
 		ret = asn1p_ref_add_component($$.governor, $1, 0);
 		checkmem(ret == 0);
 		$$.argument = $3;
@@ -891,7 +892,7 @@
 	}
 	| BasicTypeId ':' Identifier {
 		int ret;
-		$$.governor = asn1p_ref_new(yylineno);
+		$$.governor = asn1p_ref_new(yylineno, currentModule);
 		ret = asn1p_ref_add_component($$.governor,
 			ASN_EXPR_TYPE2STR($1), 1);
 		checkmem(ret == 0);
@@ -899,7 +900,7 @@
 	}
 	| BasicTypeId ':' TypeRefName {
 		int ret;
-		$$.governor = asn1p_ref_new(yylineno);
+		$$.governor = asn1p_ref_new(yylineno, currentModule);
 		ret = asn1p_ref_add_component($$.governor,
 			ASN_EXPR_TYPE2STR($1), 1);
 		checkmem(ret == 0);
@@ -938,7 +939,7 @@
 		$$->Identifier = $1;
 		$$->expr_type = A1TC_REFERENCE;
 		$$->meta_type = AMT_VALUE;
-		ref = asn1p_ref_new(yylineno);
+		ref = asn1p_ref_new(yylineno, currentModule);
 		asn1p_ref_add_component(ref, $1, RLT_lowercase);
 		$$->value = asn1p_value_fromref(ref, 0);
 	}
@@ -1320,7 +1321,7 @@
 		int ret;
 		$$ = NEW_EXPR();
 		checkmem($$);
-		$$->reference = asn1p_ref_new(yylineno);
+		$$->reference = asn1p_ref_new(yylineno, currentModule);
 		ret = asn1p_ref_add_component($$->reference,
 			$4, RLT_lowercase);
 		checkmem(ret == 0);
@@ -1345,7 +1346,7 @@
 ComplexTypeReference:
 	TOK_typereference {
 		int ret;
-		$$ = asn1p_ref_new(yylineno);
+		$$ = asn1p_ref_new(yylineno, currentModule);
 		checkmem($$);
 		ret = asn1p_ref_add_component($$, $1, RLT_UNKNOWN);
 		checkmem(ret == 0);
@@ -1353,7 +1354,7 @@
 	}
 	| TOK_typereference '.' TypeRefName {
 		int ret;
-		$$ = asn1p_ref_new(yylineno);
+		$$ = asn1p_ref_new(yylineno, currentModule);
 		checkmem($$);
 		ret = asn1p_ref_add_component($$, $1, RLT_UNKNOWN);
 		checkmem(ret == 0);
@@ -1364,7 +1365,7 @@
 	}
 	| ObjectClassReference '.' TypeRefName {
 		int ret;
-		$$ = asn1p_ref_new(yylineno);
+		$$ = asn1p_ref_new(yylineno, currentModule);
 		checkmem($$);
 		ret = asn1p_ref_add_component($$, $1, RLT_UNKNOWN);
 		checkmem(ret == 0);
@@ -1375,7 +1376,7 @@
 	}
 	| TOK_typereference '.' Identifier {
 		int ret;
-		$$ = asn1p_ref_new(yylineno);
+		$$ = asn1p_ref_new(yylineno, currentModule);
 		checkmem($$);
 		ret = asn1p_ref_add_component($$, $1, RLT_UNKNOWN);
 		checkmem(ret == 0);
@@ -1386,7 +1387,7 @@
 	}
 	| ObjectClassReference {
 		int ret;
-		$$ = asn1p_ref_new(yylineno);
+		$$ = asn1p_ref_new(yylineno, currentModule);
 		checkmem($$);
 		ret = asn1p_ref_add_component($$, $1, RLT_CAPITALS);
 		free($1);
@@ -1416,7 +1417,7 @@
 ComplexTypeReferenceAmpList:
 	ComplexTypeReferenceElement {
 		int ret;
-		$$ = asn1p_ref_new(yylineno);
+		$$ = asn1p_ref_new(yylineno, currentModule);
 		checkmem($$);
 		ret = asn1p_ref_add_component($$, $1.name, $1.lex_type);
 		free($1.name);
@@ -1450,7 +1451,7 @@
 FieldName:
 	/* "&Type1" */
 	TOK_typefieldreference {
-		$$ = asn1p_ref_new(yylineno);
+		$$ = asn1p_ref_new(yylineno, currentModule);
 		asn1p_ref_add_component($$, $1, RLT_AmpUppercase);
 		free($1);
 	}
@@ -1468,13 +1469,13 @@
 
 DefinedObjectClass:
 	TOK_capitalreference {
-		$$ = asn1p_ref_new(yylineno);
+		$$ = asn1p_ref_new(yylineno, currentModule);
 		asn1p_ref_add_component($$, $1, RLT_CAPITALS);
 		free($1);
 	}
 /*
 	| TypeRefName '.' TOK_capitalreference {
-		$$ = asn1p_ref_new(yylineno);
+		$$ = asn1p_ref_new(yylineno, currentModule);
 		asn1p_ref_add_component($$, $1, RLT_AmpUppercase);
 		asn1p_ref_add_component($$, $3, RLT_CAPITALS);
 		free($1);
@@ -1554,7 +1555,7 @@
 	Identifier {
 		asn1p_ref_t *ref;
 		int ret;
-		ref = asn1p_ref_new(yylineno);
+		ref = asn1p_ref_new(yylineno, currentModule);
 		checkmem(ref);
 		ret = asn1p_ref_add_component(ref, $1, RLT_lowercase);
 		checkmem(ret == 0);
@@ -1565,7 +1566,7 @@
 	| TypeRefName '.' Identifier {
 		asn1p_ref_t *ref;
 		int ret;
-		ref = asn1p_ref_new(yylineno);
+		ref = asn1p_ref_new(yylineno, currentModule);
 		checkmem(ref);
 		ret = asn1p_ref_add_component(ref, $1, RLT_UNKNOWN);
 		checkmem(ret == 0);
@@ -1715,7 +1716,7 @@
 	SetOfConstraints {
 		CONSTRAINT_INSERT($$, ACT_CA_SET, $1, 0);
 	}
-	| TOK_SIZE '('  ElementSetSpecs ')' {
+	| TOK_SIZE '('  ConstraintSpecs ')' {
 		/*
 		 * This is a special case, for compatibility purposes.
 		 * It goes without parentheses.
@@ -1725,17 +1726,26 @@
 	;
 
 SetOfConstraints:
-	'(' ElementSetSpecs ')' {
+	'(' ConstraintSpecs ')' {
 		$$ = $2;
 	}
-	| SetOfConstraints '(' ElementSetSpecs ')' {
+	| SetOfConstraints '(' ConstraintSpecs ')' {
 		CONSTRAINT_INSERT($$, ACT_CA_SET, $1, $3);
 	}
 	;
 
+ConstraintSpecs:
+	ElementSetSpecs {
+		$$ = $1;
+	}
+	| GeneralConstraint {
+		$$ = $1;
+	}
+	;
+
 ElementSetSpecs:
 	TOK_ThreeDots  {
-		$$ = asn1p_constraint_new(yylineno);
+		$$ = asn1p_constraint_new(yylineno, currentModule);
 		$$->type = ACT_EL_EXT;
 	}
 	| ElementSetSpec {
@@ -1743,21 +1753,18 @@
 	}
 	| ElementSetSpec ',' TOK_ThreeDots {
 		asn1p_constraint_t *ct;
-		ct = asn1p_constraint_new(yylineno);
+		ct = asn1p_constraint_new(yylineno, currentModule);
 		ct->type = ACT_EL_EXT;
 		CONSTRAINT_INSERT($$, ACT_CA_CSV, $1, ct);
 	}
 	| ElementSetSpec ',' TOK_ThreeDots ',' ElementSetSpec {
 		asn1p_constraint_t *ct;
-		ct = asn1p_constraint_new(yylineno);
+		ct = asn1p_constraint_new(yylineno, currentModule);
 		ct->type = ACT_EL_EXT;
 		CONSTRAINT_INSERT($$, ACT_CA_CSV, $1, ct);
 		ct = $$;
 		CONSTRAINT_INSERT($$, ACT_CA_CSV, ct, $5);
 	}
-	| GeneralConstraint {
-		$$ = $1;
-	}
 	;
 
 ElementSetSpec:
@@ -1792,7 +1799,7 @@
 ConstraintSubtypeElement:
 	ConstraintSpec '(' ElementSetSpecs ')' {
 		int ret;
-		$$ = asn1p_constraint_new(yylineno);
+		$$ = asn1p_constraint_new(yylineno, currentModule);
 		checkmem($$);
 		$$->type = $1;
 		ret = asn1p_constraint_insert($$, $3);
@@ -1800,33 +1807,33 @@
 	}
 	| '(' ElementSetSpecs ')' {
 		int ret;
-		$$ = asn1p_constraint_new(yylineno);
+		$$ = asn1p_constraint_new(yylineno, currentModule);
 		checkmem($$);
 		$$->type = ACT_CA_SET;
 		ret = asn1p_constraint_insert($$, $2);
 		checkmem(ret == 0);
 	}
 	| SingleValue {
-		$$ = asn1p_constraint_new(yylineno);
+		$$ = asn1p_constraint_new(yylineno, currentModule);
 		checkmem($$);
 		$$->type = ACT_EL_VALUE;
 		$$->value = $1;
 	}
 	| ContainedSubtype {
-		$$ = asn1p_constraint_new(yylineno);
+		$$ = asn1p_constraint_new(yylineno, currentModule);
 		checkmem($$);
 		$$->type = ACT_EL_TYPE;
 		$$->containedSubtype = $1;
 	}
 	| SingleValue ConstraintRangeSpec SingleValue {
-		$$ = asn1p_constraint_new(yylineno);
+		$$ = asn1p_constraint_new(yylineno, currentModule);
 		checkmem($$);
 		$$->type = $2;
 		$$->range_start = $1;
 		$$->range_stop = $3;
 	}
 	| TOK_MIN ConstraintRangeSpec SingleValue {
-		$$ = asn1p_constraint_new(yylineno);
+		$$ = asn1p_constraint_new(yylineno, currentModule);
 		checkmem($$);
 		$$->type = $2;
 		$$->range_start = asn1p_value_fromint(-123);
@@ -1834,7 +1841,7 @@
 		$$->range_start->type = ATV_MIN;
 	}
 	| SingleValue ConstraintRangeSpec TOK_MAX {
-		$$ = asn1p_constraint_new(yylineno);
+		$$ = asn1p_constraint_new(yylineno, currentModule);
 		checkmem($$);
 		$$->type = $2;
 		$$->range_start = $1;
@@ -1842,7 +1849,7 @@
 		$$->range_stop->type = ATV_MAX;
 	}
 	| TOK_MIN ConstraintRangeSpec TOK_MAX {
-		$$ = asn1p_constraint_new(yylineno);
+		$$ = asn1p_constraint_new(yylineno, currentModule);
 		checkmem($$);
 		$$->type = $2;
 		$$->range_start = asn1p_value_fromint(-123);
@@ -1856,19 +1863,26 @@
 	| PatternConstraint {
 		$$ = $1;
 	}
+	| '{' { asn1p_lexer_hack_push_opaque_state(); } Opaque /* '}' */ {
+		$$ = asn1p_constraint_new(yylineno, currentModule);
+		checkmem($$);
+		$$->type = ACT_EL_VALUE;
+		$$->value = asn1p_value_frombuf($3.buf, $3.len, 0);
+		$$->value->type = ATV_UNPARSED;
+	}
 	;
 
 PatternConstraint:
 	TOK_PATTERN TOK_cstring {
-		$$ = asn1p_constraint_new(yylineno);
+		$$ = asn1p_constraint_new(yylineno, currentModule);
 		$$->type = ACT_CT_PATTERN;
 		$$->value = asn1p_value_frombuf($2.buf, $2.len, 0);
 	}
 	| TOK_PATTERN Identifier {
 		asn1p_ref_t *ref;
-		$$ = asn1p_constraint_new(yylineno);
+		$$ = asn1p_constraint_new(yylineno, currentModule);
 		$$->type = ACT_CT_PATTERN;
-		ref = asn1p_ref_new(yylineno);
+		ref = asn1p_ref_new(yylineno, currentModule);
 		asn1p_ref_add_component(ref, $2, RLT_lowercase);
 		$$->value = asn1p_value_fromref(ref, 0);
 		free($2);
@@ -1901,7 +1915,7 @@
 	| Identifier {
 		asn1p_ref_t *ref;
 		int ret;
-		ref = asn1p_ref_new(yylineno);
+		ref = asn1p_ref_new(yylineno, currentModule);
 		checkmem(ref);
 		ret = asn1p_ref_add_component(ref, $1, RLT_lowercase);
 		checkmem(ret == 0);
@@ -1925,10 +1939,15 @@
 	;
 
 ContainedSubtype:
+	ComplexTypeReference {
+		$$ = asn1p_value_fromref($1, 0);
+		checkmem($$);
+	}
+/*
 	TypeRefName {
 		asn1p_ref_t *ref;
 		int ret;
-		ref = asn1p_ref_new(yylineno);
+		ref = asn1p_ref_new(yylineno, currentModule);
 		checkmem(ref);
 		ret = asn1p_ref_add_component(ref, $1, RLT_UNKNOWN);
 		checkmem(ret == 0);
@@ -1936,6 +1955,7 @@
 		checkmem($$);
 		free($1);
 	}
+*/
 	;
 
 InnerTypeConstraint:
@@ -1958,13 +1978,13 @@
 
 WithComponentsElement:
 	TOK_ThreeDots {
-		$$ = asn1p_constraint_new(yylineno);
+		$$ = asn1p_constraint_new(yylineno, currentModule);
 		checkmem($$);
 		$$->type = ACT_EL_EXT;
 		$$->value = asn1p_value_frombuf("...", 3, 1);
 	}
 	| Identifier optConstraints optPresenceConstraint {
-		$$ = asn1p_constraint_new(yylineno);
+		$$ = asn1p_constraint_new(yylineno, currentModule);
 		checkmem($$);
 		$$->type = ACT_EL_VALUE;
 		$$->value = asn1p_value_frombuf($1, strlen($1), 0);
@@ -2004,7 +2024,7 @@
 UserDefinedConstraint:
 	TOK_CONSTRAINED TOK_BY '{'
 		{ asn1p_lexer_hack_push_opaque_state(); } Opaque /* '}' */ {
-		$$ = asn1p_constraint_new(yylineno);
+		$$ = asn1p_constraint_new(yylineno, currentModule);
 		checkmem($$);
 		$$->type = ACT_CT_CTDBY;
 		$$->value = asn1p_value_frombuf($5.buf, $5.len, 0);
@@ -2015,7 +2035,7 @@
 
 ContentsConstraint:
 	TOK_CONTAINING Type {
-		$$ = asn1p_constraint_new(yylineno);
+		$$ = asn1p_constraint_new(yylineno, currentModule);
 		$$->type = ACT_CT_CTNG;
 		$$->value = asn1p_value_fromtype($2);
 		asn1p_expr_free($2);
@@ -2042,12 +2062,12 @@
  */
 SimpleTableConstraint:
 	'{' TypeRefName '}' {
-		asn1p_ref_t *ref = asn1p_ref_new(yylineno);
+		asn1p_ref_t *ref = asn1p_ref_new(yylineno, currentModule);
 		asn1p_constraint_t *ct;
 		int ret;
 		ret = asn1p_ref_add_component(ref, $2, 0);
 		checkmem(ret == 0);
-		ct = asn1p_constraint_new(yylineno);
+		ct = asn1p_constraint_new(yylineno, currentModule);
 		checkmem($$);
 		ct->type = ACT_EL_VALUE;
 		ct->value = asn1p_value_fromref(ref, 0);
@@ -2064,14 +2084,14 @@
 
 AtNotationList:
 	AtNotationElement {
-		$$ = asn1p_constraint_new(yylineno);
+		$$ = asn1p_constraint_new(yylineno, currentModule);
 		checkmem($$);
 		$$->type = ACT_EL_VALUE;
 		$$->value = asn1p_value_fromref($1, 0);
 	}
 	| AtNotationList ',' AtNotationElement {
 		asn1p_constraint_t *ct;
-		ct = asn1p_constraint_new(yylineno);
+		ct = asn1p_constraint_new(yylineno, currentModule);
 		checkmem(ct);
 		ct->type = ACT_EL_VALUE;
 		ct->value = asn1p_value_fromref($3, 0);
@@ -2088,7 +2108,7 @@
 		int ret;
 		*p = '@';
 		strcpy(p + 1, $2);
-		$$ = asn1p_ref_new(yylineno);
+		$$ = asn1p_ref_new(yylineno, currentModule);
 		ret = asn1p_ref_add_component($$, p, 0);
 		checkmem(ret == 0);
 		free(p);
@@ -2100,7 +2120,7 @@
 		p[0] = '@';
 		p[1] = '.';
 		strcpy(p + 2, $3);
-		$$ = asn1p_ref_new(yylineno);
+		$$ = asn1p_ref_new(yylineno, currentModule);
 		ret = asn1p_ref_add_component($$, p, 0);
 		checkmem(ret == 0);
 		free(p);