pimgen: Use cast instead of integer literals
This ends up being more portable.
Change-Id: I9e4e0414329878316a110a5234aeea4677b877e8
Signed-off-by: Brad Bishop <bradleyb@fuzziesquirrel.com>
diff --git a/pimgen.py b/pimgen.py
index 353dc15..2d47376 100755
--- a/pimgen.py
+++ b/pimgen.py
@@ -104,20 +104,31 @@
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 literal:
- return '{0}{1}'.format(arg, literal)
+ if self.type in self.integer_types:
+ return Cast('static', '{0}_t'.format(self.type))(arg)
+
+ 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 @@
},
{
"xyz.openbmc_project.Example.Iface2",
- {{"ExampleProperty2", "test2"s}, {"ExampleProperty3", 0ll}}
+ { {"ExampleProperty2", "test2"s},
+ {"ExampleProperty3", static_cast<int64_t>(0ll)}
+ }
},
};