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 Void::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) {
66 class Dumper : public Visitor
71 Dumper() : os(std::cout) {}
73 Dumper(std::ostream &_os) : os(_os) {}
75 void visit(Void *node) {
78 void visit(Bool *node) {
79 os << (node->value ? "true" : "false");
82 void visit(SInt *node) {
86 void visit(UInt *node) {
90 void visit(Float *node) {
94 void visit(String *node) {
95 os << '"' << node->value << '"';
98 void visit(Const *node) {
102 void visit(Array *node) {
103 const char *sep = "";
105 for (std::vector<Value *>::iterator it = node->values.begin(); it != node->values.end(); ++it) {
115 std::ostream & operator <<(std::ostream &os, Value *value) {
124 static const Value *unwrap(const Value *node) {
125 const Const *c = dynamic_cast<const Const *>(node);
131 signed long long asSInt(const Value *node) {
133 const SInt *sint = dynamic_cast<const SInt *>(node);
136 const UInt *uint = dynamic_cast<const UInt *>(node);
143 unsigned long long asUInt(const Value *node) {
145 const UInt *uint = dynamic_cast<const UInt *>(node);
153 double asFloat(const Value *node) {
155 const Float *fl = dynamic_cast<const Float *>(node);
161 std::ostream & operator <<(std::ostream &os, Call &call) {
162 const char *sep = "";
163 os << call.name << "(";
164 for (std::list<Arg>::iterator it = call.args.begin(); it != call.args.end(); ++it) {
165 os << sep << it->first << " = " << it->second;
170 os << " = " << call.ret;
177 } /* namespace Trace */