objdictgen/gen_cfile.py
changeset 182 988f2b302aa6
parent 176 5d57fe1e3a5b
child 188 00245bc2e6fe
equal deleted inserted replaced
181:44d812a41d49 182:988f2b302aa6
    50 # Extract the informations from a given type name
    50 # Extract the informations from a given type name
    51 def GetValidTypeInfos(typename):
    51 def GetValidTypeInfos(typename):
    52     result = type_model.match(typename)
    52     result = type_model.match(typename)
    53     if result:
    53     if result:
    54         values = result.groups()
    54         values = result.groups()
    55         if values[0] in ("UNSIGNED", "INTEGER") and eval(values[1]) in [i * 8 for i in xrange(1, 9)]:
    55         if values[0] == "UNSIGNED" and int(values[1]) in [i * 8 for i in xrange(1, 9)]:
    56             return "UNS%s"%values[1], "", "uint%s"%values[1]
    56             return "UNS%s"%values[1], "", "uint%s"%values[1]
    57         elif values[0] == "REAL" and eval(values[1]) in (32, 64):
    57         if values[0] == "INTEGER" and int(values[1]) in [i * 8 for i in xrange(1, 9)]:
       
    58             return "INTEGER%s"%values[1], "", "int%s"%values[1]
       
    59         elif values[0] == "REAL" and int(values[1]) in (32, 64):
    58             return "%s%s"%(values[0], values[1]), "", "real%s"%values[1]
    60             return "%s%s"%(values[0], values[1]), "", "real%s"%values[1]
    59         elif values[0] == "VISIBLE_STRING":
    61         elif values[0] == "VISIBLE_STRING":
    60             if values[1] == "":
    62             if values[1] == "":
    61                 return "UNS8", "[10]", "visible_string"
    63                 return "UNS8", "[10]", "visible_string"
    62             else:
    64             else:
   213                         if subIndex > 0:
   215                         if subIndex > 0:
   214                             if subIndex == len(values)-1:
   216                             if subIndex == len(values)-1:
   215                                 sep = ""
   217                                 sep = ""
   216                             if typeinfos[2] == "visible_string":
   218                             if typeinfos[2] == "visible_string":
   217                                 value = "\"%s\""%value
   219                                 value = "\"%s\""%value
   218                             if typeinfos[2] == "domain":
   220                             elif typeinfos[2] == "domain":
   219                                 value = "\"%s\""%''.join(["\\x%2.2x"%ord(char) for char in value])
   221                                 value = "\"%s\""%''.join(["\\x%2.2x"%ord(char) for char in value])
   220                             else:
   222                             else:
   221                                 comment = "\t/* %s */"%str(value)
   223                                 comment = "\t/* %s */"%str(value)
   222                                 value = "0x%X"%value
   224                                 value = "0x%X"%value
   223                             strIndex += "                      %s%s%s\n"%(value, sep, comment)
   225                             strIndex += "                      %s%s%s\n"%(value, sep, comment)