浏览代码

NodesetCompiler: Handle value encoding correctly and clean up code

Stefan Profanter 5 年之前
父节点
当前提交
feba0f6158
共有 1 个文件被更改,包括 18 次插入19 次删除
  1. 18 19
      tools/nodeset_compiler/nodes.py

+ 18 - 19
tools/nodeset_compiler/nodes.py

@@ -374,12 +374,6 @@ class DataTypeNode(Node):
 
 
         If encodable, the encoding can be retrieved using getEncoding().
         If encodable, the encoding can be retrieved using getEncoding().
     """
     """
-    __isEnum__     = False
-    __xmlDefinition__ = None
-    __baseTypeEncoding__ = []
-    __encodable__ = False
-    __encodingBuilt__ = False
-    __definition__ = []
 
 
     def __init__(self, xmlelement=None):
     def __init__(self, xmlelement=None):
         Node.__init__(self)
         Node.__init__(self)
@@ -387,7 +381,6 @@ class DataTypeNode(Node):
         self.__xmlDefinition__ = None
         self.__xmlDefinition__ = None
         self.__baseTypeEncoding__ = []
         self.__baseTypeEncoding__ = []
         self.__encodable__ = None
         self.__encodable__ = None
-        self.__encodingBuilt__ = False
         self.__definition__ = []
         self.__definition__ = []
         self.__isEnum__     = False
         self.__isEnum__     = False
         self.__isOptionSet__ = False
         self.__isOptionSet__ = False
@@ -409,23 +402,25 @@ class DataTypeNode(Node):
         """ Will return True if buildEncoding() was able to determine which builtin
         """ Will return True if buildEncoding() was able to determine which builtin
             type corresponds to all fields of this DataType.
             type corresponds to all fields of this DataType.
 
 
-            If no encoding has been build yet, this function will call buildEncoding()
-            and return True if it succeeds.
+            If no encoding has been build yet an exception will be thrown.
+            Make sure to call buildEncoding() first.
         """
         """
+        if self.__encodable__ is None:
+            raise Exception("Encoding needs to be built first using buildEncoding()")
         return self.__encodable__
         return self.__encodable__
 
 
     def getEncoding(self):
     def getEncoding(self):
         """ If the dataType is encodable, getEncoding() returns a nested list
         """ If the dataType is encodable, getEncoding() returns a nested list
             containing the encoding the structure definition for this type.
             containing the encoding the structure definition for this type.
 
 
-            If no encoding has been build yet, this function will call buildEncoding()
-            and return the encoding if buildEncoding() succeeds.
+            If no encoding has been build yet an exception will be thrown.
+            Make sure to call buildEncoding() first.
 
 
-            If buildEncoding() fails or has failed, an empty list will be returned.
+            If buildEncoding() has failed, an empty list will be returned.
         """
         """
-        if self.__encodable__ == False:
-            if self.__encodingBuilt__ == False:
-                return self.buildEncoding()
+        if self.__encodable__ is None:
+            raise Exception("Encoding needs to be built first using buildEncoding()")
+        if not self.__encodable__:
             return []
             return []
         else:
         else:
             return self.__baseTypeEncoding__
             return self.__baseTypeEncoding__
@@ -471,15 +466,15 @@ class DataTypeNode(Node):
         prefix = " " + "|" * indent + "+"
         prefix = " " + "|" * indent + "+"
 
 
         if force==True:
         if force==True:
-            self.__encodingBuilt__ = False
+            self.__encodable__ = None
 
 
-        if self.__encodingBuilt__ == True:
+        if self.__encodable__ is not None and self.__encodable__:
             if self.isEncodable():
             if self.isEncodable():
                 logger.debug(prefix + str(self.__baseTypeEncoding__) + " (already analyzed)")
                 logger.debug(prefix + str(self.__baseTypeEncoding__) + " (already analyzed)")
             else:
             else:
                 logger.debug( prefix + str(self.__baseTypeEncoding__) + "(already analyzed, not encodable!)")
                 logger.debug( prefix + str(self.__baseTypeEncoding__) + "(already analyzed, not encodable!)")
             return self.__baseTypeEncoding__
             return self.__baseTypeEncoding__
-        self.__encodingBuilt__ = True # signify that we have attempted to built this type
+
         self.__encodable__ = True
         self.__encodable__ = True
 
 
         if indent==0:
         if indent==0:
@@ -529,6 +524,7 @@ class DataTypeNode(Node):
 
 
         isEnum = True
         isEnum = True
         isSubType = True
         isSubType = True
+        # An option set is at the same time also an enum, at least for the encoding below
         isOptionSet = parentType is not None and parentType.id.ns == 0 and parentType.id.i==12755
         isOptionSet = parentType is not None and parentType.id.ns == 0 and parentType.id.i==12755
 
 
         # We need to store the definition as ordered data, but can't use orderedDict
         # We need to store the definition as ordered data, but can't use orderedDict
@@ -543,6 +539,7 @@ class DataTypeNode(Node):
                 fdtype = ""
                 fdtype = ""
                 enumVal = ""
                 enumVal = ""
                 valueRank = None
                 valueRank = None
+                #symbolicName = None
                 for at,av in x.attributes.items():
                 for at,av in x.attributes.items():
                     if at == "DataType":
                     if at == "DataType":
                         fdtype = str(av)
                         fdtype = str(av)
@@ -551,6 +548,8 @@ class DataTypeNode(Node):
                         isEnum = False
                         isEnum = False
                     elif at == "Name":
                     elif at == "Name":
                         fname = str(av)
                         fname = str(av)
+                    #elif at == "SymbolicName":
+                    #    symbolicName = str(av)
                     elif at == "Value":
                     elif at == "Value":
                         enumVal = int(av)
                         enumVal = int(av)
                         isSubType = False
                         isSubType = False
@@ -603,7 +602,7 @@ class DataTypeNode(Node):
 
 
         if isOptionSet == True:
         if isOptionSet == True:
             self.__isOptionSet__ = True
             self.__isOptionSet__ = True
-            subenc = parentType.getEncoding()
+            subenc = parentType.buildEncoding(nodeset=nodeset)
             if not parentType.isEncodable():
             if not parentType.isEncodable():
                 self.__encodable__ = False
                 self.__encodable__ = False
             else:
             else: