Giter Site home page Giter Site logo

Comments (4)

aholtzma avatar aholtzma commented on July 18, 2024

There are actually two cases, one where the default is for a defined type, and one for an inline enum.

  Mysequence-with-enum  ::=      SEQUENCE
  {
    foo Myenum DEFAULT two,
    bar ENUMERATED { a, b, c} DEFAULT c
  }

I can fix the latter, but not the former.

--- a/asn1ate/pyasn1gen.py
+++ b/asn1ate/pyasn1gen.py
@@ -419,6 +419,8 @@ class Pyasn1Backend(object):
         if t.optional:
             return "namedtype.OptionalNamedType('%s', %s)" % (t.identifier, self.generate_expr(t.type_decl))
         elif t.default_value is not None:
+            if _translate_type(t.type_decl.type_name) == 'univ.Enumerated':
+                t.default_value = '\'%s\'' % t.default_value
             type_expr = self.generate_expr(t.type_decl)
             type_expr += '.subtype(value=%s)' % _translate_value(t.default_value)

How to resolve a defined type to a single basic type?

from asn1ate.

kimgr avatar kimgr commented on July 18, 2024

I think you may be looking for sema.Module.resolve_type_decl. That unravels a chain of declarations back to the built-in type.

from asn1ate.

aholtzma avatar aholtzma commented on July 18, 2024

I had some trouble making resolve_type_decl work. It turns out it doesn't unwrap objects that are tagged. I was able to work around this by manually unwrapping the tag (with .type_decl.type_decl), but it's not clear to me what the right way to do this is.

--- a/asn1ate/pyasn1gen.py
+++ b/asn1ate/pyasn1gen.py
@@ -419,6 +419,9 @@ class Pyasn1Backend(object):
         if t.optional:
             return "namedtype.OptionalNamedType('%s', %s)" % (t.identifier, self.generate_expr(t.type_decl))
         elif t.default_value is not None:
+            xx = self.sema_module.resolve_type_decl(t.type_decl.type_decl, self.referenced_modules)
+            if _translate_type(xx.type_name) == 'univ.Enumerated':
+                t.default_value = '\'%s\'' % t.default_value
             type_expr = self.generate_expr(t.type_decl)
             type_expr += '.subtype(value=%s)' % _translate_value(t.default_value)

from asn1ate.

kimgr avatar kimgr commented on July 18, 2024

Hmm. It's not clear to me why you end up in inline_component_type rather than inline_tagged_type. Or is this code called from inline_tagged_type? It's been too long since I thought about this code to be sure what's going on.

But your patch as-is will definitely break things for non-tagged types, I don't think any other sema-types have two levels of type_decl members.

from asn1ate.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.