Sfoglia il codice sorgente

M code generator: structured variables are now passed as pointers!

Stasik0 11 anni fa
parent
commit
d3999c17a7
1 ha cambiato i file con 17 aggiunte e 18 eliminazioni
  1. 17 18
      tool/generate_builtin.py

+ 17 - 18
tool/generate_builtin.py

@@ -33,6 +33,7 @@ elementary_size["StatusCode"] = 4;
 # indefinite_types = ["NodeId", "ExpandedNodeId", "QualifiedName", "LocalizedText", "ExtensionObject", "DataValue", "Variant", "DiagnosticInfo"]
 indefinite_types = ["ExpandedNodeId", "QualifiedName", "ExtensionObject", "DataValue", "Variant", "DiagnosticInfo"]
 enum_types = []
+structured_types = []
                    
 # indefinite types cannot be directly contained in a record as they don't have a definite size
 printed_types = exclude_types # types that were already printed and which we can use in the structures to come
@@ -48,10 +49,6 @@ def skipType(name):
 def stripTypename(tn):
     return tn[tn.find(":")+1:]
 
-def camlCase2AdaCase(item):
-    (newitem, n) = re.subn("(?<!^)(?<![A-Z])([A-Z])", "_\\1", item)
-    return newitem
-
 # are the prerequisites in place? if not, postpone.
 def printableStructuredType(element):
     for child in element:
@@ -102,13 +99,13 @@ def createStructured(element):
         elif child.tag == "{http://opcfoundation.org/BinarySchema/}Field":
             if child.get("Name") in lengthfields:
                 continue
-            childname = camlCase2AdaCase(child.get("Name"))
-            if childname in printed_types:
-                childname = childname + "_Value" # attributes may not have the name of a type
+            childname = child.get("Name")
+            #if childname in printed_types:
+            #    childname = childname + "_Value" # attributes may not have the name of a type
             typename = stripTypename(child.get("TypeName"))
-            if childname == "Response_Header" or childname == "Request_Header":
-                continue
-            if typename in indefinite_types:
+            if typename in structured_types:
+                valuemap[childname] = typename + "*"
+            elif typename in indefinite_types:
                 valuemap[childname] = typename + "*"
             elif child.get("LengthField"):
                 valuemap[childname] = typename + "**"
@@ -125,10 +122,11 @@ def createStructured(element):
     if len(valuemap) > 0:
         for n,t in valuemap.iteritems():
             if t.find("**") != -1:
-	        print("\t" + "UInt32 " + n + "_size;", end='\n', file=fh)
+	        print("\t" + "UInt32 " + n + "Size;", end='\n', file=fh)
             print("\t" + "UA_" + t + " " + n + ";", end='\n', file=fh)
     else:
-        print("// null record", end='\n', file=fh)
+        print("\t/* null record */", end='\n', file=fh)
+        print("\tUA_Int32 NullRecord; /* avoiding warnings */", end='\n', file=fh)
     print("} " + name + ";", end='\n', file=fh)
 
     print("Int32 " + name + "_calcSize(" + name + " const * ptr);", end='\n', file=fh)
@@ -155,8 +153,8 @@ def createStructured(element):
             if t in enum_types:
                 print('\n\t + 4 //' + n, end='', file=fc) # enums are all 32 bit
             elif t.find("**") != -1:
-		print("\n\t + 4 //" + n + "_size", end='', file=fc),
-		print("\n\t + UA_Array_calcSize(ptr->" + n + "_size, UA_" + t[0:t.find("*")].upper() + ", (void const**) ptr->" + n +")", end='', file=fc)
+		print("\n\t + 4 //" + n + "Size", end='', file=fc),
+		print("\n\t + UA_Array_calcSize(ptr->" + n + "Size, UA_" + t[0:t.find("*")].upper() + ", (void const**) ptr->" + n +")", end='', file=fc)
             elif t.find("*") != -1:
                 print('\n\t + ' + "UA_" + t[0:t.find("*")] + "_calcSize(ptr->" + n + ')', end='', file=fc)
             else:
@@ -173,8 +171,8 @@ def createStructured(element):
             if t in enum_types:
                 print('\tretval |= UA_'+t+'_encode(&(src->'+n+'),pos,dst);', end='\n', file=fc)
             elif t.find("**") != -1:
-                print('\tretval |= UA_Int32_encode(&(src->'+n+'_size),pos,dst); // encode size', end='\n', file=fc)
-		print("\tretval |= UA_Array_encode((void const**) (src->"+n+"),src->"+n+"_size, UA_" + t[0:t.find("*")].upper()+",pos,dst);", end='\n', file=fc)
+                print('\tretval |= UA_Int32_encode(&(src->'+n+'Size),pos,dst); // encode size', end='\n', file=fc)
+		print("\tretval |= UA_Array_encode((void const**) (src->"+n+"),src->"+n+"Size, UA_" + t[0:t.find("*")].upper()+",pos,dst);", end='\n', file=fc)
             elif t.find("*") != -1:
                 print('\tretval |= UA_' + t[0:t.find("*")] + "_encode(src->" + n + ',pos,dst);', end='\n', file=fc)
             else:
@@ -190,8 +188,8 @@ def createStructured(element):
             if t in enum_types:
                 print('\tretval |= UA_'+t+'_decode(src,pos,&(dst->'+n+'));', end='\n', file=fc)
             elif t.find("**") != -1:
-                print('\tretval |= UA_Int32_decode(src,pos,&(dst->'+n+'_size)); // decode size', end='\n', file=fc)
-		print("\tretval |= UA_Array_decode(src,dst->"+n+"_size, UA_" + t[0:t.find("*")].upper()+",pos,(void const**) (dst->"+n+"));", end='\n', file=fc) #not tested
+                print('\tretval |= UA_Int32_decode(src,pos,&(dst->'+n+'Size)); // decode size', end='\n', file=fc)
+		print("\tretval |= UA_Array_decode(src,dst->"+n+"Size, UA_" + t[0:t.find("*")].upper()+",pos,(void const**) (dst->"+n+"));", end='\n', file=fc) #not tested
             elif t.find("*") != -1:
                 print('\tretval |= UA_' + t[0:t.find("*")] + "_decode(src,pos,dst->"+ n +");", end='\n', file=fc)
             else:
@@ -247,6 +245,7 @@ for element in types:
     elif element.tag == "{http://opcfoundation.org/BinarySchema/}StructuredType":
         if printableStructuredType(element):
             createStructured(element)
+            structured_types.append(name)
             printed_types.add(name)
         else: # the record contains types that were not yet detailed
             deferred_types[name] = element