Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
A
asn1c
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Libraries
asn1c
Commits
082cadca
Commit
082cadca
authored
Aug 14, 2005
by
Lev Walkin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
PER visible constraints are used to select the native representation for INTEGER types
parent
b02a8835
Changes
10
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
4395 additions
and
17 deletions
+4395
-17
ChangeLog
ChangeLog
+2
-0
libasn1compiler/asn1c_C.c
libasn1compiler/asn1c_C.c
+10
-13
libasn1compiler/asn1c_constraint.c
libasn1compiler/asn1c_constraint.c
+4
-1
libasn1compiler/asn1c_misc.c
libasn1compiler/asn1c_misc.c
+86
-2
libasn1compiler/asn1c_misc.h
libasn1compiler/asn1c_misc.h
+15
-0
tests/89-bit-string-enum-OK.asn1
tests/89-bit-string-enum-OK.asn1
+1
-1
tests/90-cond-int-type-OK.asn1
tests/90-cond-int-type-OK.asn1
+32
-0
tests/90-cond-int-type-OK.asn1.-EFprint-constraints
tests/90-cond-int-type-OK.asn1.-EFprint-constraints
+80
-0
tests/90-cond-int-type-OK.asn1.-P
tests/90-cond-int-type-OK.asn1.-P
+2083
-0
tests/90-cond-int-type-OK.asn1.-Pfnative-types
tests/90-cond-int-type-OK.asn1.-Pfnative-types
+2082
-0
No files found.
ChangeLog
View file @
082cadca
...
@@ -5,6 +5,8 @@
...
@@ -5,6 +5,8 @@
member names are invented on the fly). (Test case 87).
member names are invented on the fly). (Test case 87).
* Generating enumeration tables for INTEGER types (Test case 88).
* Generating enumeration tables for INTEGER types (Test case 88).
* Generating enumeration tables for BIT STRING types (Test case 89).
* Generating enumeration tables for BIT STRING types (Test case 89).
* Conditional INTEGER/ENUMERATED representation: long vs. INTEGER_t
type is chosen based on PER visible constraints (Test case 90).
0.9.17: 2005-Aug-07
0.9.17: 2005-Aug-07
...
...
libasn1compiler/asn1c_C.c
View file @
082cadca
...
@@ -218,29 +218,26 @@ asn1c_lang_C_type_BIT_STRING(arg_t *arg) {
...
@@ -218,29 +218,26 @@ asn1c_lang_C_type_BIT_STRING(arg_t *arg) {
asn1p_expr_t
*
expr
=
arg
->
expr
;
asn1p_expr_t
*
expr
=
arg
->
expr
;
asn1p_expr_t
*
v
;
asn1p_expr_t
*
v
;
int
el_count
=
expr_elements_count
(
arg
,
expr
);
int
el_count
=
expr_elements_count
(
arg
,
expr
);
int
eidx
=
0
;
if
(
el_count
)
{
if
(
el_count
)
{
int
eidx
=
0
;
REDIR
(
OT_DEPS
);
REDIR
(
OT_DEPS
);
OUT
(
"typedef enum "
);
OUT
(
"typedef enum "
);
out_name_chain
(
arg
,
1
);
out_name_chain
(
arg
,
1
);
OUT
(
" {
\n
"
);
OUT
(
" {
\n
"
);
TQ_FOR
(
v
,
&
(
expr
->
members
),
next
)
{
TQ_FOR
(
v
,
&
(
expr
->
members
),
next
)
{
switch
(
v
->
expr_type
)
{
eidx
++
;
case
A1TC_UNIVERVAL
:
if
(
v
->
expr_type
!=
A1TC_UNIVERVAL
)
{
OUT
(
"
\t
"
);
out_name_chain
(
arg
,
0
);
OUT
(
"_%s"
,
MKID
(
v
->
Identifier
));
OUT
(
"
\t
= %"
PRIdASN
"%s
\n
"
,
v
->
value
->
value
.
v_integer
,
(
eidx
+
1
<
el_count
)
?
","
:
""
);
eidx
++
;
break
;
default:
OUT
(
"/* Unexpected BIT STRING element: %s */
\n
"
,
OUT
(
"/* Unexpected BIT STRING element: %s */
\n
"
,
v
->
Identifier
);
v
->
Identifier
);
break
;
continue
;
}
}
OUT
(
"
\t
"
);
out_name_chain
(
arg
,
0
);
OUT
(
"_%s"
,
MKID
(
v
->
Identifier
));
OUT
(
"
\t
= %"
PRIdASN
"%s
\n
"
,
v
->
value
->
value
.
v_integer
,
(
eidx
<
el_count
)
?
","
:
""
);
}
}
OUT
(
"} "
);
OUT
(
"} "
);
out_name_chain
(
arg
,
0
);
out_name_chain
(
arg
,
0
);
...
...
libasn1compiler/asn1c_constraint.c
View file @
082cadca
...
@@ -62,6 +62,9 @@ asn1c_emit_constraint_checking_code(arg_t *arg) {
...
@@ -62,6 +62,9 @@ asn1c_emit_constraint_checking_code(arg_t *arg) {
switch
(
etype
)
{
switch
(
etype
)
{
case
ASN_BASIC_INTEGER
:
case
ASN_BASIC_INTEGER
:
case
ASN_BASIC_ENUMERATED
:
case
ASN_BASIC_ENUMERATED
:
if
(
asn1c_type_fits_long
(
arg
,
arg
->
expr
)
==
FL_NOTFIT
)
produce_st
=
1
;
break
;
case
ASN_BASIC_REAL
:
case
ASN_BASIC_REAL
:
if
(
!
(
arg
->
flags
&
A1C_USE_NATIVE_TYPES
))
if
(
!
(
arg
->
flags
&
A1C_USE_NATIVE_TYPES
))
produce_st
=
1
;
produce_st
=
1
;
...
@@ -556,7 +559,7 @@ emit_value_determination_code(arg_t *arg, asn1p_expr_type_e etype, asn1cnst_rang
...
@@ -556,7 +559,7 @@ emit_value_determination_code(arg_t *arg, asn1p_expr_type_e etype, asn1cnst_rang
switch
(
etype
)
{
switch
(
etype
)
{
case
ASN_BASIC_INTEGER
:
case
ASN_BASIC_INTEGER
:
case
ASN_BASIC_ENUMERATED
:
case
ASN_BASIC_ENUMERATED
:
if
(
a
rg
->
flags
&
A1C_USE_NATIVE_TYPES
)
{
if
(
a
sn1c_type_fits_long
(
arg
,
arg
->
expr
)
!=
FL_NOTFIT
)
{
OUT
(
"value = *(const long *)sptr;
\n
"
);
OUT
(
"value = *(const long *)sptr;
\n
"
);
}
else
{
}
else
{
if
(
r_value
->
el_count
==
0
if
(
r_value
->
el_count
==
0
...
...
libasn1compiler/asn1c_misc.c
View file @
082cadca
#include "asn1c_internal.h"
#include "asn1c_internal.h"
#include "asn1c_misc.h"
#include "asn1c_misc.h"
#include <asn1fix_export.h>
#include <asn1fix_crange.h>
/* constraint groker from libasn1fix */
#include <asn1fix_export.h>
/* other exportable stuff from libasn1fix */
/*
/*
* Checks that the given string is not a reserved C/C++ keyword.
* Checks that the given string is not a reserved C/C++ keyword.
...
@@ -189,7 +190,9 @@ asn1c_type_name(arg_t *arg, asn1p_expr_t *expr, enum tnfmt _format) {
...
@@ -189,7 +190,9 @@ asn1c_type_name(arg_t *arg, asn1p_expr_t *expr, enum tnfmt _format) {
case
ASN_BASIC_INTEGER
:
case
ASN_BASIC_INTEGER
:
case
ASN_BASIC_ENUMERATED
:
case
ASN_BASIC_ENUMERATED
:
case
ASN_BASIC_REAL
:
case
ASN_BASIC_REAL
:
if
((
arg
->
flags
&
A1C_USE_NATIVE_TYPES
))
{
if
((
expr
->
expr_type
==
ASN_BASIC_REAL
&&
(
arg
->
flags
&
A1C_USE_NATIVE_TYPES
))
||
asn1c_type_fits_long
(
arg
,
expr
))
{
switch
(
_format
)
{
switch
(
_format
)
{
case
TNF_CTYPE
:
case
TNF_CTYPE
:
case
TNF_RSAFE
:
case
TNF_RSAFE
:
...
@@ -239,3 +242,84 @@ asn1c_type_name(arg_t *arg, asn1p_expr_t *expr, enum tnfmt _format) {
...
@@ -239,3 +242,84 @@ asn1c_type_name(arg_t *arg, asn1p_expr_t *expr, enum tnfmt _format) {
return
typename
;
return
typename
;
}
}
/*
* Check whether the specified INTEGER or ENUMERATED type can be represented
* using the generic 'long' type.
*/
enum
asn1c_fitslong_e
asn1c_type_fits_long
(
arg_t
*
arg
,
asn1p_expr_t
*
expr
)
{
asn1cnst_range_t
*
range
=
0
;
asn1cnst_edge_t
left
;
asn1cnst_edge_t
right
;
asn1p_expr_t
*
v
;
/*
* Since we don't know the sizeof(long) on the possible target platform
* which will be compiling the code generated by asn1c, let's play it
* simple: long's range is equal to or greater than int32_t.
*/
#define LEFTMIN INT32_MIN
#define RIGHTMAX INT32_MAX
/* Descend to the terminal type */
expr
=
asn1f_find_terminal_type_ex
(
arg
->
asn
,
expr
);
if
(
expr
==
0
)
return
FL_NOTFIT
;
/* The "fits into long" operation is relevant only for integer types */
switch
(
expr
->
expr_type
)
{
case
ASN_BASIC_INTEGER
:
case
ASN_BASIC_ENUMERATED
:
break
;
default:
return
FL_NOTFIT
;
}
/*
* First, evaluate the range of explicitly given identifiers.
*/
TQ_FOR
(
v
,
&
(
expr
->
members
),
next
)
{
if
(
v
->
expr_type
!=
A1TC_UNIVERVAL
)
continue
;
if
(
v
->
value
->
value
.
v_integer
<
LEFTMIN
||
v
->
value
->
value
.
v_integer
>
RIGHTMAX
)
return
FL_NOTFIT
;
}
/*
* Second, pull up the PER visible range of the INTEGER.
*/
if
(
expr
->
combined_constraints
)
range
=
asn1constraint_compute_PER_range
(
expr
->
expr_type
,
expr
->
combined_constraints
,
ACT_EL_RANGE
,
0
,
0
,
0
);
if
(
!
range
||
range
->
empty_constraint
||
range
->
extensible
||
range
->
incompatible
||
range
->
not_PER_visible
)
{
asn1constraint_range_free
(
range
);
return
(
arg
->
flags
&
A1C_USE_NATIVE_TYPES
)
?
FL_FORCED
:
FL_NOTFIT
;
}
left
=
range
->
left
;
right
=
range
->
right
;
asn1constraint_range_free
(
range
);
/* If some fixed value is outside of target range, not fit */
if
(
left
.
type
==
ARE_VALUE
&&
(
left
.
value
<
LEFTMIN
||
left
.
value
>
RIGHTMAX
))
return
FL_NOTFIT
;
if
(
right
.
type
==
ARE_VALUE
&&
(
right
.
value
>
RIGHTMAX
||
right
.
value
<
LEFTMIN
))
return
FL_NOTFIT
;
/* If the range is open, fits only if -fnative-types is given */
if
(
left
.
type
!=
ARE_VALUE
||
right
.
type
!=
ARE_VALUE
)
{
return
(
arg
->
flags
&
A1C_USE_NATIVE_TYPES
)
?
FL_FORCED
:
FL_NOTFIT
;
}
return
FL_FITSOK
;
}
libasn1compiler/asn1c_misc.h
View file @
082cadca
...
@@ -24,4 +24,19 @@ enum tnfmt {
...
@@ -24,4 +24,19 @@ enum tnfmt {
};
};
char
*
asn1c_type_name
(
arg_t
*
arg
,
asn1p_expr_t
*
expr
,
enum
tnfmt
_format
);
char
*
asn1c_type_name
(
arg_t
*
arg
,
asn1p_expr_t
*
expr
,
enum
tnfmt
_format
);
/*
* Check whether the specified INTEGER or ENUMERATED type can be represented
* using the generic 'long' type.
* Return values:
* FL_NOTFIT: No, it cannot be represented using long.
* FL_FITSOK: It can be represented using long.
* FL_FORCED: Probably can't, but -fnative-types is in force.
*/
enum
asn1c_fitslong_e
{
FL_NOTFIT
,
FL_FITSOK
,
FL_FORCED
,
};
enum
asn1c_fitslong_e
asn1c_type_fits_long
(
arg_t
*
arg
,
asn1p_expr_t
*
expr
);
#endif
/* _ASN1_COMPILER_MISC_H_ */
#endif
/* _ASN1_COMPILER_MISC_H_ */
tests/89-bit-string-enum-OK.asn1
View file @
082cadca
...
@@ -5,7 +5,7 @@
...
@@ -5,7 +5,7 @@
-- .spelio.software.asn1c.test (9363.1.5.1)
-- .spelio.software.asn1c.test (9363.1.5.1)
-- .89
-- .89
Module
Integer
Enumeration
Module
BitString
Enumeration
{ iso org(3) dod(6) internet (1) private(4) enterprise(1)
{ iso org(3) dod(6) internet (1) private(4) enterprise(1)
spelio(9363) software(1) asn1c(5) test(1) 89 }
spelio(9363) software(1) asn1c(5) test(1) 89 }
DEFINITIONS ::=
DEFINITIONS ::=
...
...
tests/90-cond-int-type-OK.asn1
0 → 100644
View file @
082cadca
-- OK: Everything is fine
-- iso.org.dod.internet.private.enterprise (1.3.6.1.4.1)
-- .spelio.software.asn1c.test (9363.1.5.1)
-- .90
ModuleConditionalIntegerType
{ iso org(3) dod(6) internet (1) private(4) enterprise(1)
spelio(9363) software(1) asn1c(5) test(1) 90 }
DEFINITIONS ::=
BEGIN
CN-IntegerUnlimited ::= INTEGER
CN-IntegerMinMax ::= INTEGER (MIN..MAX)
CN-IntegerMinLow ::= INTEGER (MIN..1)
NO-IntegerMinHigh ::= INTEGER (MIN..5000000000)
NO-IntegerLowHigh ::= INTEGER (1..5000000000)
CN-IntegerLowMax ::= INTEGER (1..MAX)
NO-IntegerHighMax ::= INTEGER (5000000000..MAX)
NO-IntegerLowestMax ::= INTEGER (-5000000000..MAX)
NO-IntegerOutRange ::= INTEGER (5000000000..5000000001)
NO-IntegerOutValue ::= INTEGER (5000000000)
OK-IntegerInRange1 ::= INTEGER (-100..100)
OK-IntegerInRange2 ::= INTEGER (-100|100)
OK-IntegerInRange3 ::= INTEGER (-2147483648..2147483647)
OK-IntegerInRange4 ::= INTEGER (-2147483648|2147483647)
OK-IntegerInRange5 ::= INTEGER (-2147483648|2147483647,...)
CN-IntegerEnumerated1 ::= INTEGER { a(1), b(2) }
NO-IntegerEnumerated2 ::= INTEGER { a(1), b(5000000000) }
END
tests/90-cond-int-type-OK.asn1.-EFprint-constraints
0 → 100644
View file @
082cadca
ModuleConditionalIntegerType { iso org(3) dod(6) internet(1) private(4)
enterprise(1) spelio(9363) software(1) asn1c(5) test(1) 90 }
DEFINITIONS ::=
BEGIN
CN-IntegerUnlimited ::= INTEGER
-- Practical constraints (CN-IntegerUnlimited): (MIN..MAX)
-- PER-visible constraints (CN-IntegerUnlimited): (MIN..MAX)
CN-IntegerMinMax ::= INTEGER (MIN..MAX)
-- Combined constraints: (MIN..MAX)
-- Practical constraints (CN-IntegerMinMax): (MIN..MAX)
-- PER-visible constraints (CN-IntegerMinMax): (MIN..MAX)
CN-IntegerMinLow ::= INTEGER (MIN..1)
-- Combined constraints: (MIN..1)
-- Practical constraints (CN-IntegerMinLow): (MIN..1)
-- PER-visible constraints (CN-IntegerMinLow): (MIN..1)
NO-IntegerMinHigh ::= INTEGER (MIN..5000000000)
-- Combined constraints: (MIN..5000000000)
-- Practical constraints (NO-IntegerMinHigh): (MIN..5000000000)
-- PER-visible constraints (NO-IntegerMinHigh): (MIN..5000000000)
NO-IntegerLowHigh ::= INTEGER (1..5000000000)
-- Combined constraints: (1..5000000000)
-- Practical constraints (NO-IntegerLowHigh): (1..5000000000)
-- PER-visible constraints (NO-IntegerLowHigh): (1..5000000000)
CN-IntegerLowMax ::= INTEGER (1..MAX)
-- Combined constraints: (1..MAX)
-- Practical constraints (CN-IntegerLowMax): (1..MAX)
-- PER-visible constraints (CN-IntegerLowMax): (1..MAX)
NO-IntegerHighMax ::= INTEGER (5000000000..MAX)
-- Combined constraints: (5000000000..MAX)
-- Practical constraints (NO-IntegerHighMax): (5000000000..MAX)
-- PER-visible constraints (NO-IntegerHighMax): (5000000000..MAX)
NO-IntegerLowestMax ::= INTEGER (-5000000000..MAX)
-- Combined constraints: (-5000000000..MAX)
-- Practical constraints (NO-IntegerLowestMax): (-5000000000..MAX)
-- PER-visible constraints (NO-IntegerLowestMax): (-5000000000..MAX)
NO-IntegerOutRange ::= INTEGER (5000000000..5000000001)
-- Combined constraints: (5000000000..5000000001)
-- Practical constraints (NO-IntegerOutRange): (5000000000..5000000001)
-- PER-visible constraints (NO-IntegerOutRange): (5000000000..5000000001)
NO-IntegerOutValue ::= INTEGER (5000000000)
-- Combined constraints: (5000000000)
-- Practical constraints (NO-IntegerOutValue): (5000000000)
-- PER-visible constraints (NO-IntegerOutValue): (5000000000)
OK-IntegerInRange1 ::= INTEGER (-100..100)
-- Combined constraints: (-100..100)
-- Practical constraints (OK-IntegerInRange1): (-100..100)
-- PER-visible constraints (OK-IntegerInRange1): (-100..100)
OK-IntegerInRange2 ::= INTEGER (-100 | 100)
-- Combined constraints: (-100 | 100)
-- Practical constraints (OK-IntegerInRange2): (-100 | 100)
-- PER-visible constraints (OK-IntegerInRange2): (-100 | 100)
OK-IntegerInRange3 ::= INTEGER (-2147483648..2147483647)
-- Combined constraints: (-2147483648..2147483647)
-- Practical constraints (OK-IntegerInRange3): (-2147483648..2147483647)
-- PER-visible constraints (OK-IntegerInRange3): (-2147483648..2147483647)
OK-IntegerInRange4 ::= INTEGER (-2147483648 | 2147483647)
-- Combined constraints: (-2147483648 | 2147483647)
-- Practical constraints (OK-IntegerInRange4): (-2147483648 | 2147483647)
-- PER-visible constraints (OK-IntegerInRange4): (-2147483648 | 2147483647)
OK-IntegerInRange5 ::= INTEGER (-2147483648 | 2147483647,...)
-- Combined constraints: (-2147483648 | 2147483647,...)
-- Practical constraints (OK-IntegerInRange5): (-2147483648 | 2147483647,...)
-- PER-visible constraints (OK-IntegerInRange5): (-2147483648 | 2147483647,...)
END
tests/90-cond-int-type-OK.asn1.-P
0 → 100644
View file @
082cadca
This diff is collapsed.
Click to expand it.
tests/90-cond-int-type-OK.asn1.-Pfnative-types
0 → 100644
View file @
082cadca
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment