1 /**************************************************************************
3 * Copyright 2010 VMware, Inc.
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to deal
8 * in the Software without restriction, including without limitation the rights
9 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 * copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24 **************************************************************************/
27 #include "trace_model.hpp"
33 void Null::visit(Visitor &visitor) {
37 void Bool::visit(Visitor &visitor) {
41 void SInt::visit(Visitor &visitor) {
45 void UInt::visit(Visitor &visitor) {
49 void Float::visit(Visitor &visitor) {
53 void String::visit(Visitor &visitor) {
57 void Const::visit(Visitor &visitor) {
61 void Array::visit(Visitor &visitor) {
65 void Blob::visit(Visitor &visitor) {
70 class Dumper : public Visitor
75 Dumper() : os(std::cout) {}
77 Dumper(std::ostream &_os) : os(_os) {}
79 void visit(Null *node) {
83 void visit(Bool *node) {
84 os << (node->value ? "true" : "false");
87 void visit(SInt *node) {
91 void visit(UInt *node) {
95 void visit(Float *node) {
99 void visit(String *node) {
100 os << '"' << node->value << '"';
103 void visit(Const *node) {
107 void visit(Array *node) {
108 const char *sep = "";
110 for (std::vector<Value *>::iterator it = node->values.begin(); it != node->values.end(); ++it) {
118 void visit(Blob *blob) {
119 os << "... " << blob->size;
124 std::ostream & operator <<(std::ostream &os, Value *value) {
133 static inline const Value *unwrap(const Value *node) {
134 const Const *c = dynamic_cast<const Const *>(node);
141 Value::operator signed long long(void) const {
142 const SInt *sint = dynamic_cast<const SInt *>(unwrap(this));
145 const UInt *uint = dynamic_cast<const UInt *>(unwrap(this));
152 Value::operator unsigned long long(void) const {
153 const UInt *uint = dynamic_cast<const UInt *>(unwrap(this));
161 Value::operator double(void) const {
162 const Float *fl = dynamic_cast<const Float *>(unwrap(this));
169 const Value & Value::operator[](size_t index) const {
170 const Array *array = dynamic_cast<const Array *>(unwrap(this));
172 if (index < array->values.size()) {
173 return *array->values[index];
179 Value::operator void *(void) const {
180 const Blob *blob = dynamic_cast<const Blob *>(unwrap(this));
183 const Null *null = dynamic_cast<const Null *>(unwrap(this));
190 Value & Call::arg(const char *name) {
191 for (std::list<Arg>::iterator it = args.begin(); it != args.end(); ++it) {
192 if (it->first == name) {
199 std::ostream & operator <<(std::ostream &os, Call &call) {
200 const char *sep = "";
201 os << call.name << "(";
202 for (std::list<Arg>::iterator it = call.args.begin(); it != call.args.end(); ++it) {
203 os << sep << it->first << " = " << it->second;
208 os << " = " << call.ret;
215 } /* namespace Trace */