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 *array) {
108 if (array->values.size() == 1) {
110 array->values[0]->visit(*this);
113 const char *sep = "";
115 for (std::vector<Value *>::iterator it = array->values.begin(); it != array->values.end(); ++it) {
124 void visit(Blob *blob) {
125 os << "... " << blob->size;
130 std::ostream & operator <<(std::ostream &os, Value *value) {
139 static inline const Value *unwrap(const Value *node) {
140 const Const *c = dynamic_cast<const Const *>(node);
147 Value::operator signed long long(void) const {
148 const SInt *sint = dynamic_cast<const SInt *>(unwrap(this));
151 const UInt *uint = dynamic_cast<const UInt *>(unwrap(this));
158 Value::operator unsigned long long(void) const {
159 const UInt *uint = dynamic_cast<const UInt *>(unwrap(this));
167 Value::operator double(void) const {
168 const Float *fl = dynamic_cast<const Float *>(unwrap(this));
175 const Value & Value::operator[](size_t index) const {
176 const Array *array = dynamic_cast<const Array *>(unwrap(this));
178 if (index < array->values.size()) {
179 return *array->values[index];
185 Value::operator void *(void) const {
186 const Blob *blob = dynamic_cast<const Blob *>(unwrap(this));
189 const Null *null = dynamic_cast<const Null *>(unwrap(this));
196 Value & Call::arg(const char *name) {
197 for (std::list<Arg>::iterator it = args.begin(); it != args.end(); ++it) {
198 if (it->first == name) {
205 std::ostream & operator <<(std::ostream &os, Call &call) {
206 const char *sep = "";
207 os << call.name << "(";
208 for (std::list<Arg>::iterator it = call.args.begin(); it != call.args.end(); ++it) {
209 os << sep << it->first << " = " << it->second;
214 os << " = " << call.ret;
221 } /* namespace Trace */