Skip to content

Commit

Permalink
ovsdb-idlc: Replace C/C++ keyword in column name
Browse files Browse the repository at this point in the history
With this patch, ovs-idlc appends an underscore to a column name
if it is a C or C++ keyword. Therefore, C and C++ compiler will
not get confused.

Signed-off-by: Yi-Hung Wei <[email protected]>
Signed-off-by: Ben Pfaff <[email protected]>
  • Loading branch information
YiHungWei authored and blp committed Dec 13, 2017
1 parent edebc77 commit adb4185
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 5 deletions.
8 changes: 6 additions & 2 deletions ovsdb/ovsdb-idlc.1
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,15 @@ modified is re-serialized as JSON on standard output.
.
.IP "\fBc\-idl\-header\fI idl\fR"
Reads \fIidl\fR and prints on standard output a C header file that
defines a structure for each table defined by the schema.
defines a structure for each table defined by the schema. If a column
name in \fIidl\fR is a C or C++ keyword, it will be appended with an
underscore.
.
.IP "\fBc\-idl\-source\fI idl\fR"
Reads \fIidl\fR and prints on standard output a C source file that
implements C bindings for the database defined by the schema.
implements C bindings for the database defined by the schema. If a column
name in \fIidl\fR is a C or C++ keyword, it will be appended with an
underscore.
.
.SS "Options"
.so lib/common.man
Expand Down
31 changes: 29 additions & 2 deletions ovsdb/ovsdb-idlc.in
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,33 @@ def cMembers(prefix, tableName, columnName, column, const, refTable=True):
def sorted_columns(table):
return sorted(table.columns.items())

# If a column name in the schema is a C or C++ keyword, append an underscore
# to the column name.
def replace_cplusplus_keyword(schema):
keywords = {'alignas', 'alignof', 'and', 'and_eq', 'asm', 'auto', 'bitand',
'bitor', 'bool', 'break', 'case', 'catch', 'char', 'char16_t',
'char32_t', 'class', 'compl', 'concept', 'const', 'const_cast',
'constexpr', 'continue', 'decltype', 'default', 'delete', 'do',
'double', 'dynamic_cast', 'else', 'enum', 'explicit', 'export',
'extern', 'false', 'float', 'for', 'friend', 'goto', 'if',
'inline', 'int', 'long', 'mutable', 'namespace', 'new',
'noexcept', 'not', 'not_eq', 'nullptr', 'operator', 'or',
'or_eq', 'private', 'protected', 'public', 'register',
'reinterpret_cast', 'requires', 'restrict', 'return', 'short',
'signed', 'sizeof', 'static', 'static_assert', 'static_cast',
'struct', 'switch', 'template', 'this', 'thread_local',
'throw', 'true', 'try', 'typedef', 'typeid', 'typename',
'union', 'unsigned', 'using', 'virtual', 'void', 'volatile',
'wchar_t', 'while', 'xor', 'xor_eq'}

for tableName, table in schema.tables.items():
for columnName in table.columns:
if columnName in keywords:
table.columns[columnName + '_'] = table.columns.pop(columnName)

def printCIDLHeader(schemaFile):
schema = parseSchema(schemaFile)
replace_cplusplus_keyword(schema)
prefix = schema.idlPrefix
print('''\
/* Generated automatically -- do not modify! -*- buffer-read-only: t -*- */
Expand Down Expand Up @@ -328,6 +353,7 @@ def printEnum(type, members):

def printCIDLSource(schemaFile):
schema = parseSchema(schemaFile)
replace_cplusplus_keyword(schema)
prefix = schema.idlPrefix
print('''\
/* Generated automatically -- do not modify! -*- buffer-read-only: t -*- */
Expand Down Expand Up @@ -1273,7 +1299,7 @@ void
for x in column.type.cInitType("%s_col_%s" % (tableName, columnName), prereqs))
print("""\
[%(P)s%(T)s_COL_%(C)s] = {
.name = "%(c)s",
.name = "%(column_name_in_schema)s",
.type = {
%(type)s
},
Expand All @@ -1286,7 +1312,8 @@ void
'C': columnName.upper(),
's': structName,
'mutable': mutable,
'type': type_init})
'type': type_init,
'column_name_in_schema': column.name})
print("};")

# Table classes.
Expand Down
2 changes: 1 addition & 1 deletion vswitchd/bridge.c
Original file line number Diff line number Diff line change
Expand Up @@ -1046,7 +1046,7 @@ port_configure(struct port *port)
}

/* Protected port mode */
s.protected = cfg->protected;
s.protected = cfg->protected_;

/* Register. */
ofproto_bundle_register(port->bridge->ofproto, port, &s);
Expand Down

0 comments on commit adb4185

Please sign in to comment.