Skip to content

Commit

Permalink
Disallow reserved keywords as config names
Browse files Browse the repository at this point in the history
The resulting code won't compile anyway, this provides a better error message.

PUBLISHED_FROM=5c65991fa1c832a02db6eac61e47f0cd2781f33f
  • Loading branch information
Deomid Ryabkov authored and cesantabot committed May 14, 2018
1 parent b8405af commit a2a2edb
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions fw/tools/gen_sys_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,18 @@
parser.add_argument("schema_files", nargs="+", help="YAML schema files")


RESERVED_WORDS = set(
("alignas alignof and and_eq asm auto bitand bitor bool break case catch char "
"char16_t char32_t class compl const constexpr const_cast 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 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").split())


class SchemaEntry(object):
V_INT = "i"
V_BOOL = "b"
Expand Down Expand Up @@ -121,6 +133,9 @@ def __init__(self, e):
if not isinstance(self.path, basestring):
raise TypeError("Path is not a string (%s)" % e)

if self.path in RESERVED_WORDS:
raise NameError("Cannot use '%s' as a config key, it's a C/C++ reserved keyword" % self.path)

if self.vtype is not None:
if self.vtype not in (self.V_OBJECT, self.V_BOOL, self.V_INT, self.V_DOUBLE, self.V_STRING):
raise TypeError("%s: Invalid value type '%s'" % (self.path, self.vtype))
Expand Down

0 comments on commit a2a2edb

Please sign in to comment.