X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=ovsdb%2Fovsdb-idlc.in;h=4e402888d17c06539a761b305cc39b359dd1dc26;hb=98c50f96801d3159aad2de02407305463c68f51a;hp=e8371aa1d619b68729df109c3c1746cd44116850;hpb=991559357f6a03c3a5b70c053c8c2554aa8d5ee4;p=openvswitch diff --git a/ovsdb/ovsdb-idlc.in b/ovsdb/ovsdb-idlc.in index e8371aa1..4e402888 100755 --- a/ovsdb/ovsdb-idlc.in +++ b/ovsdb/ovsdb-idlc.in @@ -20,15 +20,15 @@ def annotateSchema(schemaFile, annotationFile): ovs.json.to_stream(schemaJson, sys.stdout) def constify(cType, const): - if (const - and cType.endswith('*') and not cType.endswith('**') - and (cType.startswith('struct uuid') or cType.startswith('char'))): + if (const and cType.endswith('*') and not cType.endswith('**')): return 'const %s' % cType else: return cType def cMembers(prefix, columnName, column, const): type = column.type + if is_optional_bool(type): + const = True if type.n_min == 1 and type.n_max == 1: singleton = True pointer = '' @@ -167,6 +167,10 @@ def printEnum(members): print " %s" % members[-1] print "};" +def is_optional_bool(type): + return (type.key.type == ovs.db.types.BooleanType and not type.value + and type.n_min == 0 and type.n_max == 1) + def printCIDLSource(schemaFile): schema = parseSchema(schemaFile) prefix = schema.idlPrefix @@ -217,20 +221,36 @@ static void keyVar = "row->%s" % columnName valueVar = None - if (type.n_min == 1 and type.n_max == 1) or type.is_optional_pointer(): + if is_optional_bool(type): + # Special case for an optional bool. This is only here because + # sparse does not like the "normal" case below ("warning: + # expression using sizeof bool"). + print + print " assert(inited);" + print " if (datum->n >= 1) {" + print " static const bool false_value = false;" + print " static const bool true_value = true;" + print + print " row->n_%s = 1;" % columnName + print " %s = datum->keys[0].boolean ? &true_value : &false_value;" % keyVar + print " } else {" + print " row->n_%s = 0;" % columnName + print " %s = NULL;" % keyVar + print " }" + elif (type.n_min == 1 and type.n_max == 1) or type.is_optional_pointer(): print print " assert(inited);" print " if (datum->n >= 1) {" if not type.key.ref_table: print " %s = datum->keys[0].%s;" % (keyVar, type.key.type.to_string()) else: - print " %s = %s%s_cast(ovsdb_idl_get_row_arc(row_, &%stable_classes[%sTABLE_%s], &datum->keys[0].uuid));" % (keyVar, prefix, type.key.ref_table.lower(), prefix, prefix.upper(), type.key.ref_table.upper()) + print " %s = %s%s_cast(ovsdb_idl_get_row_arc(row_, &%stable_classes[%sTABLE_%s], &datum->keys[0].uuid));" % (keyVar, prefix, type.key.ref_table.name.lower(), prefix, prefix.upper(), type.key.ref_table.name.upper()) if valueVar: if type.value.ref_table: print " %s = datum->values[0].%s;" % (valueVar, type.value.type.to_string()) else: - print " %s = %s%s_cast(ovsdb_idl_get_row_arc(row_, &%stable_classes[%sTABLE_%s], &datum->values[0].uuid));" % (valueVar, prefix, type.value.ref_table.lower(), prefix, prefix.upper(), type.value.ref_table.upper()) + print " %s = %s%s_cast(ovsdb_idl_get_row_arc(row_, &%stable_classes[%sTABLE_%s], &datum->values[0].uuid));" % (valueVar, prefix, type.value.ref_table.name.lower(), prefix, prefix.upper(), type.value.ref_table.name.upper()) print " } else {" print " %s" % type.key.initCDefault(keyVar, type.n_min == 0) if valueVar: @@ -252,13 +272,13 @@ static void print " for (i = 0; i < %s; i++) {" % nMax refs = [] if type.key.ref_table: - print " struct %s%s *keyRow = %s%s_cast(ovsdb_idl_get_row_arc(row_, &%stable_classes[%sTABLE_%s], &datum->keys[i].uuid));" % (prefix, type.key.ref_table.lower(), prefix, type.key.ref_table.lower(), prefix, prefix.upper(), type.key.ref_table.upper()) + print " struct %s%s *keyRow = %s%s_cast(ovsdb_idl_get_row_arc(row_, &%stable_classes[%sTABLE_%s], &datum->keys[i].uuid));" % (prefix, type.key.ref_table.name.lower(), prefix, type.key.ref_table.name.lower(), prefix, prefix.upper(), type.key.ref_table.name.upper()) keySrc = "keyRow" refs.append('keyRow') else: keySrc = "datum->keys[i].%s" % type.key.type.to_string() if type.value and type.value.ref_table: - print " struct %s%s *valueRow = %s%s_cast(ovsdb_idl_get_row_arc(row_, &%stable_classes[%sTABLE_%s], &datum->values[i].uuid));" % (prefix, type.value.ref_table.lower(), prefix, type.value.ref_table.lower(), prefix, prefix.upper(), type.value.ref_table.upper()) + print " struct %s%s *valueRow = %s%s_cast(ovsdb_idl_get_row_arc(row_, &%stable_classes[%sTABLE_%s], &datum->values[i].uuid));" % (prefix, type.value.ref_table.name.lower(), prefix, type.value.ref_table.name.lower(), prefix, prefix.upper(), type.value.ref_table.name.upper()) valueSrc = "valueRow" refs.append('valueRow') elif valueVar: @@ -285,7 +305,15 @@ static void # Unparse functions. for columnName, column in sorted(table.columns.iteritems()): type = column.type - if (type.n_min != 1 or type.n_max != 1) and not type.is_optional_pointer(): + if (type.key.type == ovs.db.types.BooleanType and not type.value + and type.n_min == 0 and type.n_max == 1): + print ''' +static void +%(s)s_unparse_%(c)s(struct ovsdb_idl_row *row OVS_UNUSED) +{ + /* Nothing to do. */ +}''' % {'s': structName, 'c': columnName} + elif (type.n_min != 1 or type.n_max != 1) and not type.is_optional_pointer(): print ''' static void %(s)s_unparse_%(c)s(struct ovsdb_idl_row *row_) @@ -310,7 +338,7 @@ static void { /* Nothing to do. */ }''' % {'s': structName, 'c': columnName} - + # First, next functions. print ''' const struct %(s)s * @@ -489,7 +517,11 @@ static void\n%s_columns_init(void) print "struct ovsdb_idl_table_class %stable_classes[%sN_TABLES] = {" % (prefix, prefix.upper()) for tableName, table in sorted(schema.tables.iteritems()): structName = "%s%s" % (prefix, tableName.lower()) - print " {\"%s\"," % tableName + if table.is_root: + is_root = "true" + else: + is_root = "false" + print " {\"%s\", %s," % (tableName, is_root) print " %s_columns, ARRAY_SIZE(%s_columns)," % ( structName, structName) print " sizeof(struct %s)}," % structName @@ -516,6 +548,21 @@ void print " %s_columns_init();" % structName print "}" +def print_python_module(schema_file): + schema = ovs.db.schema.DbSchema.from_json(ovs.json.from_file(schema_file)) + print """\ +# Generated automatically -- do not modify! -*- buffer-read-only: t -*- + +import ovs.db.schema +import ovs.json + +__schema_json = \"\"\" +%s +\"\"\" + +schema = ovs.db.schema.DbSchema.from_json(ovs.json.from_string(__schema_json)) +""" % ovs.json.to_string(schema.to_json(), pretty=True) + def ovsdb_escape(string): def escape(match): c = match.group(0) @@ -537,8 +584,6 @@ def ovsdb_escape(string): return '\\x%02x' % ord(c) return re.sub(r'["\\\000-\037]', escape, string) - - def usage(): print """\ %(argv0)s: ovsdb schema compiler @@ -548,6 +593,7 @@ The following commands are supported: annotate SCHEMA ANNOTATIONS print SCHEMA combined with ANNOTATIONS c-idl-header IDL print C header file for IDL c-idl-source IDL print C source file for IDL implementation + python-module IDL print Python module for IDL nroff IDL print schema documentation in nroff format The following options are also available: @@ -566,7 +612,7 @@ if __name__ == "__main__": except getopt.GetoptError, geo: sys.stderr.write("%s: %s\n" % (argv0, geo.msg)) sys.exit(1) - + for key, value in options: if key in ['-h', '--help']: usage() @@ -576,7 +622,7 @@ if __name__ == "__main__": os.chdir(value) else: sys.exit(0) - + optKeys = [key for key, value in options] if not args: @@ -586,7 +632,8 @@ if __name__ == "__main__": commands = {"annotate": (annotateSchema, 2), "c-idl-header": (printCIDLHeader, 1), - "c-idl-source": (printCIDLSource, 1)} + "c-idl-source": (printCIDLSource, 1), + "python-module": (print_python_module, 1)} if not args[0] in commands: sys.stderr.write("%s: unknown command \"%s\" "