Maintain ModuleReference in DefinedType
authorKim Grasman <kim.grasman@gmail.com>
Fri, 4 Aug 2017 17:54:56 +0000 (19:54 +0200)
committerKim Grasman <kim.grasman@gmail.com>
Fri, 4 Aug 2017 17:54:56 +0000 (19:54 +0200)
... instead of just name.

asn1ate/pyasn1gen.py
asn1ate/sema.py

index 34ac9369c85ab127d161c94a76039fcf87d75f62..2968cc880e1f4427f8443cfaa97b7196c28db96a 100644 (file)
@@ -293,8 +293,8 @@ class Pyasn1Backend(object):
 
     def inline_defined_type(self, t):
         translated_type = _translate_type(t.type_name) + '()'
-        if t.module_name and t.module_name != self.sema_module.name:
-            translated_type = _sanitize_module(t.module_name) + '.' + translated_type
+        if t.module_ref and t.module_ref.name != self.sema_module.name:
+            translated_type = _sanitize_module(t.module_ref.name) + '.' + translated_type
         return translated_type
 
     def inline_constructed_type(self, t):
index 81c123b2b9a8d03d6ebdeea98d7d9d82e58e39a9..b02e2ca6e843dd05e70773c28f08ab18b51b6256 100644 (file)
@@ -290,16 +290,16 @@ class Module(SemaNode):
         """
         if isinstance(type_decl, ReferencedType):
             module = None
-            if not type_decl.module_name or type_decl.module_name == self.name:
+            if not type_decl.module_ref or type_decl.module_ref.name == self.name:
                 module = self
             else:
                 # Find the referenced module
                 for ref_mod in referenced_modules:
-                    if ref_mod.name == type_decl.module_name:
+                    if ref_mod.name == type_decl.module_ref.name:
                         module = ref_mod
                         break
             if not module:
-                raise Exception('Unrecognized referenced module %s in %s.' % (type_decl.module_name,
+                raise Exception('Unrecognized referenced module %s in %s.' % (type_decl.module_ref.name,
                                                                               [module.name for module in
                                                                                referenced_modules]))
             return module.resolve_type_decl(module.user_types()[type_decl.type_name], referenced_modules)
@@ -610,22 +610,17 @@ class ReferencedType(SemaNode):
 
 class DefinedType(ReferencedType):
     def __init__(self, elements):
-        self.constraint = None
-        self.module_name = None
-
         module_ref, type_ref, size_constraint = elements
-        if module_ref:
-            self.module_name = module_ref.elements[0]
+        self.module_ref = _maybe_create_sema_node(module_ref)
         self.type_name = type_ref
-        if size_constraint:
-            self.constraint = _create_sema_node(size_constraint)
+        self.constraint = _maybe_create_sema_node(size_constraint)
 
     def reference_name(self):
         return self.type_name
 
     def __str__(self):
-        if self.module_name:
-            type_name = self.module_name + '.' + self.type_name
+        if self.module_ref:
+            type_name = self.module_ref.name + '.' + self.type_name
         else:
             type_name = self.type_name