summaryrefslogtreecommitdiff
path: root/trace_model.cpp
diff options
context:
space:
mode:
authorJosé Fonseca <jfonseca@vmware.com>2010-11-20 09:03:10 +0000
committerJosé Fonseca <jfonseca@vmware.com>2010-11-20 09:03:10 +0000
commitc9edb83044ae17a35c42c10504ffffd0f12f3598 (patch)
tree640d82914980fb47b1d06f782097fc3b19aba541 /trace_model.cpp
parent3d4b626a639abd846f65938052fbd2c9f9fdceed (diff)
Make better use of C++ implicit casts. Support arrays.
Diffstat (limited to 'trace_model.cpp')
-rw-r--r--trace_model.cpp31
1 files changed, 21 insertions, 10 deletions
diff --git a/trace_model.cpp b/trace_model.cpp
index 8f102247..b8325878 100644
--- a/trace_model.cpp
+++ b/trace_model.cpp
@@ -121,26 +121,27 @@ std::ostream & operator <<(std::ostream &os, Value *value) {
}
-static const Value *unwrap(const Value &node) {
- const Const *c = dynamic_cast<const Const *>(&node);
+static inline const Value *unwrap(const Value *node) {
+ const Const *c = dynamic_cast<const Const *>(node);
if (c)
return c->value;
- return &node;
+ return node;
}
-signed long long asSInt(const Value &node) {
- const SInt *sint = dynamic_cast<const SInt *>(unwrap(node));
+
+Value::operator signed long long(void) const {
+ const SInt *sint = dynamic_cast<const SInt *>(unwrap(this));
if (sint)
return sint->value;
- const UInt *uint = dynamic_cast<const UInt *>(unwrap(node));
+ const UInt *uint = dynamic_cast<const UInt *>(unwrap(this));
if (uint)
return uint->value;
assert(0);
return 0;
}
-unsigned long long asUInt(const Value &node) {
- const UInt *uint = dynamic_cast<const UInt *>(unwrap(node));
+Value::operator unsigned long long(void) const {
+ const UInt *uint = dynamic_cast<const UInt *>(unwrap(this));
if (uint)
return uint->value;
assert(0);
@@ -148,14 +149,24 @@ unsigned long long asUInt(const Value &node) {
}
-double asFloat(const Value &node) {
- const Float *fl = dynamic_cast<const Float *>(unwrap(node));
+Value::operator double(void) const {
+ const Float *fl = dynamic_cast<const Float *>(unwrap(this));
assert(fl);
return fl->value;
}
static Void void_;
+const Value & Value::operator[](size_t index) const {
+ const Array *array = dynamic_cast<const Array *>(unwrap(this));
+ if (array) {
+ if (index < array->values.size()) {
+ return *array->values[index];
+ }
+ }
+ return void_;
+}
+
Value & Call::arg(const char *name) {
for (std::list<Arg>::iterator it = args.begin(); it != args.end(); ++it) {
if (it->first == name) {