summaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
authorPatrick Williams <patrick@stwcx.xyz>2016-12-12 12:13:48 -0600
committerPatrick Williams <patrick@stwcx.xyz>2016-12-12 12:22:34 -0600
commitcf078c43c3c05347bd9285c4e5bc43278c07d8ff (patch)
tree6273e1c0709956c2ab39bf3333839e78b0323e4a /tools
parentabf5f78d0f277663ad5804a8f66213178ce5417c (diff)
downloadsdbusplus-cf078c43c3c05347bd9285c4e5bc43278c07d8ff.tar.gz
sdbusplus-cf078c43c3c05347bd9285c4e5bc43278c07d8ff.zip
sdbus++: Avoid using C++ reserved words
Some words are reserved in C++, so they cannot be used as function or variable names. If a YAML file specifies these we must come up with an alternative name for the generated C++ function. Do this by adding underscore characters to the generated name. Fixes openbmc/sdbusplus#10. Change-Id: I992caafb02fe71ea6ac2cf3c555a9956e4ba616a Signed-off-by: Patrick Williams <patrick@stwcx.xyz>
Diffstat (limited to 'tools')
-rw-r--r--tools/sdbusplus/namedelement.py30
1 files changed, 29 insertions, 1 deletions
diff --git a/tools/sdbusplus/namedelement.py b/tools/sdbusplus/namedelement.py
index 438043d..ffc3541 100644
--- a/tools/sdbusplus/namedelement.py
+++ b/tools/sdbusplus/namedelement.py
@@ -14,9 +14,37 @@ class NamedElement(object):
.get(name)
if l:
- return l()
+ return NamedElement.__fixup_name(l())
try:
return super(NamedElement, self).__getattr__(name)
except:
raise AttributeError("Attribute '%s' not found in %s.NamedElement"
% (name, self.__module__))
+
+ """ Some names are reserved in some languages. Fixup names to avoid using
+ reserved words.
+ """
+ @staticmethod
+ def __fixup_name(name):
+ # List of reserved words from http://en.cppreference.com/w/cpp/keyword
+ cppReserved = frozenset({
+ "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", "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"})
+
+ while(name in cppReserved):
+ name = name + "_"
+
+ return name
OpenPOWER on IntegriCloud