Hi ddunbar,

The following types can be encoded and decoded by the json library:
`dict`, `list`, `tuple`, `str`, `unicode`, `int`, `long`, `float`, `bool`, 
`NoneType`. 

`NativeMetricValue` can be constructed with any of these types, and used as 
part of Test.Result.
This patch also adds a toMetricValue function that converts a value into a 
MetricValue.

http://reviews.llvm.org/D6576

Files:
  utils/lit/lit/Test.py
Index: utils/lit/lit/Test.py
===================================================================
--- utils/lit/lit/Test.py
+++ utils/lit/lit/Test.py
@@ -73,6 +73,35 @@
     def todata(self):
         return self.value
 
+def isNativeMetricValue(value):
+    return type(value) in [dict, list, tuple, str, unicode, int, long, float,
+                           bool, type(None)]
+
+class NativeMetricValue(MetricValue):
+    def __init__(self, value):
+        if not isNativeMetricValue(value):
+            raise RuntimeError("Invalid Type %s" % type(value))
+        self.value = value
+
+    def format(self):
+        return str(self.value)
+
+    def todata(self):
+        return self.value
+
+def toMetricValue(value):
+    if isinstance(value, MetricValue):
+        return value
+    elif type(value) in [int, long]:
+        return IntMetricValue(value)
+    elif type(value) is float:
+        return RealMetricValue(value)
+    elif isNativeMetricValue(value):
+        return NativeMetricValue(value)
+    else:
+        raise RuntimeError("Invalid Type %s" % type(value))
+
+
 # Test results.
 
 class Result(object):
_______________________________________________
cfe-commits mailing list
[email protected]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits

Reply via email to