소스 검색

Delay initialization since types may be in list after encoding id

Stefan Profanter 6 년 전
부모
커밋
11ec0a4a70
1개의 변경된 파일16개의 추가작업 그리고 4개의 파일을 삭제
  1. 16 4
      tools/generate_datatypes.py

+ 16 - 4
tools/generate_datatypes.py

@@ -318,6 +318,9 @@ def parseTypeDescriptions(f, namespaceid):
     input_str = f.read()
     input_str = input_str.replace('\r','')
     rows = map(lambda x:tuple(x.split(',')), input_str.split('\n'))
+
+    delay_init = []
+
     for index, row in enumerate(rows):
         if len(row) < 3:
             continue
@@ -328,10 +331,12 @@ def parseTypeDescriptions(f, namespaceid):
                 baseType = m.group(1)
                 if baseType not in types:
                     continue
-                if m.group(2) == "Xml":
-                    definitions[baseType].xmlEncodingId = row[1]
-                else:
-                    definitions[baseType].binaryEncodingId = row[1]
+
+                delay_init.append({
+                    "baseType": baseType,
+                    "encoding": m.group(2),
+                    "id": row[1]
+                })
             continue
         if row[2] != "DataType":
             continue
@@ -343,6 +348,13 @@ def parseTypeDescriptions(f, namespaceid):
             continue
         else:
             definitions[row[0]] = TypeDescription(row[0], row[1], namespaceid)
+    for i in delay_init:
+        if i["baseType"] not in definitions:
+            raise Exception("Type {} not found in definitions file.".format(i["baseType"]))
+        if i["encoding"] == "Xml":
+            definitions[i["baseType"]].xmlEncodingId = i["id"]
+        else:
+            definitions[i["baseType"]].binaryEncodingId = i["id"]
     return definitions
 
 def merge_dicts(*dict_args):