diff options
author | Brad Bishop <bradleyb@fuzziesquirrel.com> | 2017-02-23 12:37:56 -0500 |
---|---|---|
committer | Brad Bishop <bradleyb@fuzziesquirrel.com> | 2017-02-25 00:45:21 -0500 |
commit | 134d2cb2b679ed64aee8d5d841de41577928c6d2 (patch) | |
tree | 04186072f77d49fa77f9904d5c8673d46c1ac145 | |
parent | efb7885e0bb97a0e2f65457ff4f931cc5a3a1fc8 (diff) | |
download | phosphor-inventory-manager-134d2cb2b679ed64aee8d5d841de41577928c6d2.tar.gz phosphor-inventory-manager-134d2cb2b679ed64aee8d5d841de41577928c6d2.zip |
pimgen: Use cast instead of integer literals
This ends up being more portable.
Change-Id: I9e4e0414329878316a110a5234aeea4677b877e8
Signed-off-by: Brad Bishop <bradleyb@fuzziesquirrel.com>
-rwxr-xr-x | pimgen.py | 27 | ||||
-rw-r--r-- | test/test.cpp | 4 |
2 files changed, 22 insertions, 9 deletions
@@ -104,20 +104,31 @@ class Cast(object): class Literal(object): '''Decorate an argument with a literal operator.''' - literals = { - 'string': 's', - 'int64': 'll', - 'uint64': 'ull' - } + integer_types = [ + 'int8', + 'int16', + 'int32', + 'int64', + 'uint8', + 'uint16', + 'uint32', + 'uint64' + ] def __init__(self, type): self.type = type def __call__(self, arg): - literal = self.literals.get(self.type) + if 'uint' in self.type: + arg = '{0}ull'.format(arg) + elif 'int' in self.type: + arg = '{0}ll'.format(arg) + + if self.type in self.integer_types: + return Cast('static', '{0}_t'.format(self.type))(arg) - if literal: - return '{0}{1}'.format(arg, literal) + if self.type == 'string': + return '{0}s'.format(arg) return arg diff --git a/test/test.cpp b/test/test.cpp index d36aa24..407a0cc 100644 --- a/test/test.cpp +++ b/test/test.cpp @@ -207,7 +207,9 @@ void runTests() }, { "xyz.openbmc_project.Example.Iface2", - {{"ExampleProperty2", "test2"s}, {"ExampleProperty3", 0ll}} + { {"ExampleProperty2", "test2"s}, + {"ExampleProperty3", static_cast<int64_t>(0ll)} + } }, }; |