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
801fabc3
Commit
801fabc3
authored
Jan 28, 2005
by
Lev Walkin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
checking reserved keywords and double identifiers
parent
23fd2fa6
Changes
5
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
151 additions
and
66 deletions
+151
-66
libasn1compiler/asn1c_C.c
libasn1compiler/asn1c_C.c
+89
-51
libasn1compiler/asn1c_constraint.c
libasn1compiler/asn1c_constraint.c
+0
-2
libasn1compiler/asn1c_misc.c
libasn1compiler/asn1c_misc.c
+46
-7
libasn1compiler/asn1c_misc.h
libasn1compiler/asn1c_misc.h
+12
-6
libasn1compiler/asn1compiler.h
libasn1compiler/asn1compiler.h
+4
-0
No files found.
libasn1compiler/asn1c_C.c
View file @
801fabc3
This diff is collapsed.
Click to expand it.
libasn1compiler/asn1c_constraint.c
View file @
801fabc3
...
...
@@ -13,8 +13,6 @@ static int emit_size_determination_code(arg_t *arg, asn1p_expr_type_e etype);
static
asn1p_expr_type_e
_find_terminal_type
(
arg_t
*
arg
);
static
int
emit_range_comparison_code
(
arg_t
*
arg
,
asn1cnst_range_t
*
range
,
const
char
*
varname
,
asn1c_integer_t
natural_start
,
asn1c_integer_t
natural_stop
);
#define MKID(id) asn1c_make_identifier(0, (id), 0)
static
int
global_compile_mark
;
int
...
...
libasn1compiler/asn1c_misc.c
View file @
801fabc3
...
...
@@ -3,17 +3,35 @@
#include <asn1fix_export.h>
/*
* Checks that the given string is not a reserved C/C++ keyword.
*/
static
char
*
res_kwd
[]
=
{
"char"
,
"int"
,
"long"
,
"float"
,
"double"
,
"struct"
,
"typedef"
,
"class"
};
static
int
reserved_keyword
(
const
char
*
str
)
{
int
i
;
for
(
i
=
0
;
i
<
sizeof
(
res_kwd
)
/
sizeof
(
res_kwd
[
0
]);
i
++
)
{
if
(
strcmp
(
str
,
res_kwd
[
i
])
==
0
)
return
1
;
}
return
0
;
}
/*
* Construct identifier from multiple parts.
* Convert unsafe characters to underscores.
*/
char
*
asn1c_make_identifier
(
int
unsafe_only_space
s
,
char
*
arg1
,
...)
{
asn1c_make_identifier
(
enum
ami_flags_e
flag
s
,
char
*
arg1
,
...)
{
static
char
*
storage
;
static
int
storage_size
;
int
nodelimiter
=
0
;
va_list
ap
;
char
*
str
;
char
*
nextstr
;
int
size
;
char
*
p
;
...
...
@@ -49,8 +67,9 @@ asn1c_make_identifier(int unsafe_only_spaces, char *arg1, ...) {
va_start
(
ap
,
arg1
);
str
=
arg1
;
p
=
storage
;
for
(
str
=
arg1
;
str
;
str
=
va_arg
(
ap
,
char
*
)
)
{
for
(
str
=
arg1
;
str
;
str
=
nextstr
)
{
int
subst_made
=
0
;
nextstr
=
va_arg
(
ap
,
char
*
);
if
(
str
[
0
]
==
' '
&&
str
[
1
]
==
'\0'
)
{
*
p
++
=
' '
;
...
...
@@ -62,12 +81,23 @@ asn1c_make_identifier(int unsafe_only_spaces, char *arg1, ...) {
*
p
++
=
'_'
;
/* Delimiter between tokens */
nodelimiter
=
0
;
/*
* If it is a single argument, check that it does not clash
* with C/C++ language keywords.
*/
if
((
flags
&
AMI_CHECK_RESERVED
)
&&
str
==
arg1
&&
!
nextstr
&&
reserved_keyword
(
str
))
{
*
p
++
=
toupper
(
*
str
++
);
/* Fall through */
}
for
(;
*
str
;
str
++
)
{
if
(
isalnum
(
*
str
))
{
*
p
++
=
*
str
;
subst_made
=
0
;
}
else
if
(
!
subst_made
++
)
{
if
(
unsafe_only_spaces
&&
!
isspace
(
*
str
))
{
if
((
flags
&
AMI_MASK_ONLY_SPACES
)
&&
!
isspace
(
*
str
))
{
*
p
++
=
*
str
;
}
else
{
*
p
++
=
'_'
;
...
...
@@ -87,6 +117,9 @@ char *
asn1c_type_name
(
arg_t
*
arg
,
asn1p_expr_t
*
expr
,
enum
tnfmt
_format
)
{
asn1p_expr_t
*
top_parent
;
char
*
typename
;
enum
ami_flags_e
ami_flags
=
(
_format
&
TNF_CHECK
)
?
AMI_CHECK_RESERVED
:
0
;
_format
&=
~
TNF_CHECK
;
/* Rewind to the topmost parent expression */
if
((
top_parent
=
expr
->
parent_expr
))
...
...
@@ -180,13 +213,19 @@ asn1c_type_name(arg_t *arg, asn1p_expr_t *expr, enum tnfmt _format) {
switch
(
_format
)
{
case
TNF_UNMODIFIED
:
case
TNF_INCLUDE
:
return
asn1c_make_identifier
(
1
,
typename
,
0
);
assert
(
ami_flags
==
0
);
/* (TNF_INCLUDE | TNF_CHECK)?! */
ami_flags
|=
AMI_MASK_ONLY_SPACES
;
return
asn1c_make_identifier
(
ami_flags
,
typename
,
0
);
case
TNF_SAFE
:
return
asn1c_make_identifier
(
0
,
typename
,
0
);
return
asn1c_make_identifier
(
ami_flags
,
typename
,
0
);
case
TNF_CTYPE
:
return
asn1c_make_identifier
(
0
,
typename
,
"t"
,
0
);
return
asn1c_make_identifier
(
ami_flags
,
typename
,
"t"
,
0
);
case
TNF_RSAFE
:
return
asn1c_make_identifier
(
0
,
"struct"
,
" "
,
typename
,
0
);
return
asn1c_make_identifier
(
ami_flags
,
"struct"
,
" "
,
typename
,
0
);
case
TNF_NORCHECK
:
case
TNF_CHECK
:
assert
(
_format
!=
TNF_NORCHECK
);
assert
(
_format
!=
TNF_CHECK
);
}
assert
(
!
"unreachable"
);
...
...
libasn1compiler/asn1c_misc.h
View file @
801fabc3
...
...
@@ -6,17 +6,23 @@
* The function will concatenate the names and replace unsafe characters
* with safe ones.
*/
char
*
asn1c_make_identifier
(
int
unsafe_only_spaces
,
char
*
arg1
,
...);
enum
ami_flags_e
{
AMI_MASK_ONLY_SPACES
=
1
,
/* Mask only spaces, everything else's safe */
AMI_CHECK_RESERVED
=
2
,
/* Check against reserved keywords */
};
char
*
asn1c_make_identifier
(
enum
ami_flags_e
,
char
*
arg1
,
...);
/*
* Return the type name of the specified expression.
*/
enum
tnfmt
{
TNF_UNMODIFIED
,
/* Return unmodified type name */
TNF_INCLUDE
,
/* Format for #include <> */
TNF_CTYPE
,
/* Format as normal C-ish type (append "_t") */
TNF_SAFE
,
/* Replace unsafe characters with _ */
TNF_RSAFE
,
/* Recursion-safe C type format */
TNF_NORCHECK
=
0x00
,
TNF_CHECK
=
0x01
,
TNF_UNMODIFIED
=
0x10
,
/* Return unmodified type name */
TNF_INCLUDE
=
0x20
,
/* Format for #include <> */
TNF_CTYPE
=
0x30
,
/* Format as normal C-ish type (append "_t") */
TNF_SAFE
=
0x40
,
/* Replace unsafe characters with _ */
TNF_RSAFE
=
0x50
,
/* Recursion-safe C type format */
};
char
*
asn1c_type_name
(
arg_t
*
arg
,
asn1p_expr_t
*
expr
,
enum
tnfmt
_format
);
...
...
libasn1compiler/asn1compiler.h
View file @
801fabc3
...
...
@@ -39,6 +39,10 @@ enum asn1c_flags {
* Do not generate constraint checking code.
*/
A1C_NO_CONSTRAINTS
=
0x0080
,
/*
* Generate type_id_PR_member things identifiers of id_PR_member.
*/
A1C_DOUBLE_IDENTIFIERS
=
0x0100
,
};
/*
...
...
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