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 * Object hierarchy for describing the traces in memory.
30 #ifndef _TRACE_MODEL_HPP_
31 #define _TRACE_MODEL_HPP_
55 virtual void visit(Visitor &visitor) = 0;
57 virtual operator bool (void) const = 0;
58 virtual operator signed long long (void) const;
59 virtual operator unsigned long long (void) const;
60 virtual operator double (void) const;
62 virtual void *blob(void) const;
63 const char *string(void) const;
65 inline operator signed char (void) const {
66 return static_cast<signed long long>(*this);
69 inline operator unsigned char (void) const {
70 return static_cast<signed long long>(*this);
73 inline operator signed short (void) const {
74 return static_cast<signed long long>(*this);
77 inline operator unsigned short (void) const {
78 return static_cast<unsigned long long>(*this);
81 inline operator signed (void) const {
82 return static_cast<signed long long>(*this);
85 inline operator unsigned (void) const {
86 return static_cast<unsigned long long>(*this);
89 inline operator signed long (void) const {
90 return static_cast<signed long long>(*this);
93 inline operator unsigned long (void) const {
94 return static_cast<unsigned long long>(*this);
97 inline operator float (void) const {
98 return static_cast<double>(*this);
101 const Value & operator[](size_t index) const;
105 class Null : public Value
108 operator bool (void) const;
109 operator signed long long (void) const;
110 operator unsigned long long (void) const;
111 operator double (void) const;
112 void *blob(void) const;
113 void visit(Visitor &visitor);
119 class Bool : public Value
122 Bool(bool _value) : value(_value) {}
124 operator bool (void) const;
125 operator signed long long (void) const;
126 operator unsigned long long (void) const;
127 operator double (void) const;
128 void visit(Visitor &visitor);
134 class SInt : public Value
137 SInt(signed long long _value) : value(_value) {}
139 operator bool (void) const;
140 operator signed long long (void) const;
141 operator unsigned long long (void) const;
142 operator double (void) const;
143 void visit(Visitor &visitor);
145 signed long long value;
149 class UInt : public Value
152 UInt(unsigned long long _value) : value(_value) {}
154 operator bool (void) const;
155 operator signed long long (void) const;
156 operator unsigned long long (void) const;
157 operator double (void) const;
158 void visit(Visitor &visitor);
160 unsigned long long value;
164 class Float : public Value
167 Float(double _value) : value(_value) {}
169 operator bool (void) const;
170 operator signed long long (void) const;
171 operator unsigned long long (void) const;
172 operator double (void) const;
173 void visit(Visitor &visitor);
179 class String : public Value
182 String(std::string _value) : value(_value) {}
184 operator bool (void) const;
185 void visit(Visitor &visitor);
191 class Enum : public Value
194 typedef std::pair<std::string, Value *> Signature;
196 Enum(const Signature *_sig) : sig(_sig) {}
198 operator bool (void) const;
199 operator signed long long (void) const;
200 operator unsigned long long (void) const;
201 operator double (void) const;
202 void visit(Visitor &visitor);
204 const Signature *sig;
208 class Bitmask : public UInt
211 typedef std::pair<std::string, unsigned long long> Pair;
212 typedef std::vector<Pair> Signature;
214 Bitmask(const Signature *_sig, unsigned long long _value) : UInt(_value), sig(_sig) {}
216 void visit(Visitor &visitor);
218 const Signature *sig;
222 class Struct : public Value
227 std::vector<std::string> member_names;
230 Struct(Signature *_sig) : sig(_sig), members(_sig->member_names.size()) { }
233 operator bool (void) const;
234 void visit(Visitor &visitor);
236 const Signature *sig;
237 std::vector<Value *> members;
241 class Array : public Value
244 Array(size_t len) : values(len) {}
247 operator bool (void) const;
248 void visit(Visitor &visitor);
250 std::vector<Value *> values;
254 class Blob : public Value
259 buf = new char[_size];
264 operator bool (void) const;
265 void *blob(void) const;
266 void visit(Visitor &visitor);
273 class Pointer : public UInt
276 Pointer(unsigned long long value) : UInt(value) {}
278 operator bool (void) const;
279 void *blob(void) const;
280 void visit(Visitor &visitor);
287 virtual void visit(Null *);
288 virtual void visit(Bool *);
289 virtual void visit(SInt *);
290 virtual void visit(UInt *);
291 virtual void visit(Float *);
292 virtual void visit(String *);
293 virtual void visit(Enum *);
294 virtual void visit(Bitmask *);
295 virtual void visit(Struct *);
296 virtual void visit(Array *);
297 virtual void visit(Blob *);
298 virtual void visit(Pointer *);
301 inline void _visit(Value *value) {
309 std::ostream & operator <<(std::ostream &os, Value *value);
312 signed long long asSInt(const Value &node);
313 unsigned long long asUInt(const Value &node);
314 double asFloat(const Value &node);
322 std::vector<std::string> arg_names;
326 const Signature *sig;
327 std::vector<Value *> args;
330 Call(Signature *_sig) : sig(_sig), args(_sig->arg_names.size()), ret(0) { }
333 inline const std::string name(void) const {
337 inline Value & arg(unsigned index) {
338 return *(args[index]);
343 std::ostream & operator <<(std::ostream &os, Call &call);
346 } /* namespace Trace */
348 #endif /* _TRACE_MODEL_HPP_ */