diff options
author | Pascal Quantin <pascal.quantin@gmail.com> | 2015-01-18 13:13:00 +0100 |
---|---|---|
committer | Pascal Quantin <pascal.quantin@gmail.com> | 2015-01-18 13:30:56 +0000 |
commit | e7593ea19de8df681f19e59b3a9a5f69e67693ba (patch) | |
tree | 5a9487da6648c88e1672c8baf9dae470b3b8ff22 /tools/asn2wrs.py | |
parent | 12d17d2ceaad8ea12171bfbf97c8483063430788 (diff) |
asn2wrs: autodetect if 64 bits variant is required for constrained integers
It does not work with defines, but is already a great step forward
Change-Id: I346d4124690ec46a2299d4eae8031bbb19a3db8e
Reviewed-on: https://code.wireshark.org/review/6617
Reviewed-by: Anders Broman <a.broman58@gmail.com>
Reviewed-by: Pascal Quantin <pascal.quantin@gmail.com>
Diffstat (limited to 'tools/asn2wrs.py')
-rwxr-xr-x | tools/asn2wrs.py | 16 |
1 files changed, 15 insertions, 1 deletions
diff --git a/tools/asn2wrs.py b/tools/asn2wrs.py index 203f9d5f79..a3c066e39b 100755 --- a/tools/asn2wrs.py +++ b/tools/asn2wrs.py @@ -3636,6 +3636,12 @@ class Constraint (Node): self.constr_num = constr_cnt return 'CONSTR%03d%s' % (self.constr_num, ext) + def Needs64b(self, ectx): + (minv, maxv, ext) = self.GetValue(ectx) + if (str(minv).isdigit() or ((str(minv)[0] == "-") and str(minv)[1:].isdigit())) \ + and str(maxv).isdigit() and (abs(int(maxv) - int(minv)) >= 2**32): + return True + return False class Module (Node): def to_python (self, ctx): @@ -5384,7 +5390,12 @@ class IntegerType (Type): def eth_ftype(self, ectx): if self.HasConstraint(): if not self.constr.IsNegativ(): - return ('FT_UINT32', 'BASE_DEC') + if self.constr.Needs64b(ectx): + return ('FT_UINT64', 'BASE_DEC') + else: + return ('FT_UINT32', 'BASE_DEC') + if self.constr.Needs64b(ectx): + return ('FT_INT64', 'BASE_DEC') return ('FT_INT32', 'BASE_DEC') def eth_strings(self): @@ -5428,6 +5439,9 @@ class IntegerType (Type): pars = Type.eth_type_default_pars(self, ectx, tname) if self.HasValueConstraint(): (pars['MIN_VAL'], pars['MAX_VAL'], pars['EXT']) = self.eth_get_value_constr(ectx) + if (pars['FN_VARIANT'] == '') and self.constr.Needs64b(ectx): + if ectx.Ber(): pars['FN_VARIANT'] = '64' + else: pars['FN_VARIANT'] = '_64b' return pars def eth_type_default_body(self, ectx, tname): |