Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
D
dmt
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
TASTE
dmt
Commits
3a8606f4
Commit
3a8606f4
authored
Jun 12, 2016
by
Thanassis Tsiodras
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Annotated range verification logic with types.
parent
bbaf2e6e
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
12 additions
and
21 deletions
+12
-21
commonPy/configMT.py
commonPy/configMT.py
+0
-2
commonPy/verify.py
commonPy/verify.py
+12
-19
No files found.
commonPy/configMT.py
View file @
3a8606f4
...
...
@@ -40,8 +40,6 @@
import
os
g_bOnlySubprograms
=
False
debugParser
=
False
inputAadlAST
=
None
verbose
=
False
showCode
=
False
args
=
[]
outputDir
=
"."
+
os
.
sep
commonPy/verify.py
View file @
3a8606f4
...
...
@@ -20,9 +20,13 @@
#
__doc__
=
'''This module checks that all ASN.1 types are using the appropriate constraint (ASSERT-wise).'''
from
typing
import
Dict
,
Union
from
commonPy.utility
import
panic
import
commonPy.asnAST
from
commonPy.asnAST
import
AsnNode
import
commonPy.configMT
from
functools
import
reduce
...
...
@@ -38,29 +42,16 @@ def VerifyNodeRange(node):
If they are not, a runtime error is generated, with a report
on the exact location of the offending type in the ASN.1 grammar.'''
if
isinstance
(
node
,
commonPy
.
asnAST
.
AsnInt
):
if
"-ignoreINTEGERranges"
in
commonPy
.
configMT
.
args
:
return
if
node
.
_range
==
[]:
panic
(
"INTEGER (in %s) must have a range constraint inside ASN.1,
\n
"
"or else we might lose accuracy during runtime!"
%
node
.
Location
())
# else:
# # asn1c uses C long for ASN.1 INTEGER. Assuming that our platform is 32 bit,
# # this allows values from -2147483648 to 2147483647
# if node._range[0] < -2147483648L:
# panic("INTEGER (in %s) must have a low limit >= -2147483648\n"
# % node.Location())
# if node._range[1] > 2147483647L:
# panic("INTEGER (in %s) must have a high limit <= 2147483647\n"
# % node.Location())
elif
isinstance
(
node
,
commonPy
.
asnAST
.
AsnReal
):
if
"-ignoreREALranges"
in
commonPy
.
configMT
.
args
:
return
if
node
.
_range
==
[]:
panic
(
"REAL (in %s) must have a range constraint inside ASN.1,
\n
"
"or else we might lose accuracy during runtime!"
%
node
.
Location
())
else
:
#
asn1c
uses C double for ASN.1 REAL.
#
ASN1SCC
uses C double for ASN.1 REAL.
# this allows values from -1.7976931348623157E308 to 1.7976931348623157E308
if
node
.
_range
[
0
]
<
-
1.7976931348623157E308
:
panic
(
"REAL (in %s) must have a low limit >= -1.7976931348623157E308
\n
"
%
...
...
@@ -82,17 +73,19 @@ on the exact location of the offending type in the ASN.1 grammar.'''
panic
(
"ENUMERATED must have integer value for each enum! (%s)"
%
node
.
Location
())
def
VerifyRanges
(
node
,
names
)
:
def
VerifyRanges
(
node
_or_str
:
Union
[
str
,
AsnNode
],
names
:
Dict
[
str
,
AsnNode
])
->
None
:
'''This function recursively traverses the AST,
calling VerifyNodeRange for each Node.'''
if
isinstance
(
node
,
str
):
node
=
names
[
node
]
if
isinstance
(
node_or_str
,
str
):
node
=
names
[
node_or_str
]
# type: AsnNode
else
:
node
=
node_or_str
if
isinstance
(
node
,
commonPy
.
asnAST
.
AsnMetaMember
):
node
=
names
[
node
.
_containedType
]
if
isinstance
(
node
,
commonPy
.
asnAST
.
AsnBasicNode
):
VerifyNodeRange
(
node
)
elif
isinstance
(
node
,
commonPy
.
asnAST
.
AsnSequence
)
or
isinstance
(
node
,
commonPy
.
asnAST
.
AsnChoice
)
or
isinstance
(
node
,
commonPy
.
asnAST
.
AsnSet
):
elif
isinstance
(
node
,
(
commonPy
.
asnAST
.
AsnSequence
,
commonPy
.
asnAST
.
AsnChoice
,
commonPy
.
asnAST
.
AsnSet
)
):
#Bug fixed in ASN1SCC - this check is no longer needed
#if 0 == len(node._members):
# panic(
...
...
@@ -100,7 +93,7 @@ calling VerifyNodeRange for each Node.'''
# % node.Location())
for
child
in
node
.
_members
:
VerifyRanges
(
child
[
1
],
names
)
elif
isinstance
(
node
,
commonPy
.
asnAST
.
AsnSequenceOf
)
or
isinstance
(
node
,
commonPy
.
asnAST
.
AsnSetOf
):
elif
isinstance
(
node
,
(
commonPy
.
asnAST
.
AsnSequenceOf
,
commonPy
.
asnAST
.
AsnSetOf
)
):
VerifyNodeRange
(
node
)
VerifyRanges
(
node
.
_containedType
,
names
)
elif
isinstance
(
node
,
commonPy
.
asnAST
.
AsnEnumerated
):
...
...
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