2
##########################################################################
4
# Copyright 2008 Tungsten Graphics, Inc., Cedar Park, Texas.
7
# Permission is hereby granted, free of charge, to any person obtaining a
8
# copy of this software and associated documentation files (the
9
# "Software"), to deal in the Software without restriction, including
10
# without limitation the rights to use, copy, modify, merge, publish,
11
# distribute, sub license, and/or sell copies of the Software, and to
12
# permit persons to whom the Software is furnished to do so, subject to
13
# the following conditions:
15
# The above copyright notice and this permission notice (including the
16
# next paragraph) shall be included in all copies or substantial portions
19
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
20
# OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
21
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
22
# IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
23
# ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
24
# TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
25
# SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27
##########################################################################
30
'''Trace data model.'''
38
from cStringIO import StringIO
40
from StringIO import StringIO
45
def visit(self, visitor):
46
raise NotImplementedError
50
formatter = format.DefaultFormatter(stream)
51
pretty_printer = PrettyPrinter(formatter)
52
self.visit(pretty_printer)
53
return stream.getvalue()
58
def __init__(self, value):
61
def visit(self, visitor):
62
visitor.visit_literal(self)
65
class NamedConstant(Node):
67
def __init__(self, name):
70
def visit(self, visitor):
71
visitor.visit_named_constant(self)
76
def __init__(self, elements):
77
self.elements = elements
79
def visit(self, visitor):
80
visitor.visit_array(self)
85
def __init__(self, name, members):
87
self.members = members
89
def visit(self, visitor):
90
visitor.visit_struct(self)
95
def __init__(self, address):
96
self.address = address
98
def visit(self, visitor):
99
visitor.visit_pointer(self)
104
def __init__(self, no, klass, method, args, ret):
111
def visit(self, visitor):
112
visitor.visit_call(self)
117
def __init__(self, calls):
120
def visit(self, visitor):
121
visitor.visit_trace(self)
126
def visit_literal(self, node):
127
raise NotImplementedError
129
def visit_named_constant(self, node):
130
raise NotImplementedError
132
def visit_array(self, node):
133
raise NotImplementedError
135
def visit_struct(self, node):
136
raise NotImplementedError
138
def visit_pointer(self, node):
139
raise NotImplementedError
141
def visit_call(self, node):
142
raise NotImplementedError
144
def visit_trace(self, node):
145
raise NotImplementedError
150
def __init__(self, formatter):
151
self.formatter = formatter
153
def visit_literal(self, node):
154
if isinstance(node.value, basestring):
155
if len(node.value) >= 4096 or node.value.strip(string.printable):
156
self.formatter.text('...')
159
self.formatter.literal('"' + node.value + '"')
162
self.formatter.literal(repr(node.value))
164
def visit_named_constant(self, node):
165
self.formatter.literal(node.name)
167
def visit_array(self, node):
168
self.formatter.text('{')
170
for value in node.elements:
171
self.formatter.text(sep)
174
self.formatter.text('}')
176
def visit_struct(self, node):
177
self.formatter.text('{')
179
for name, value in node.members:
180
self.formatter.text(sep)
181
self.formatter.variable(name)
182
self.formatter.text(' = ')
185
self.formatter.text('}')
187
def visit_pointer(self, node):
188
self.formatter.address(node.address)
190
def visit_call(self, node):
191
self.formatter.text('%s ' % node.no)
192
if node.klass is not None:
193
self.formatter.function(node.klass + '::' + node.method)
195
self.formatter.function(node.method)
196
self.formatter.text('(')
198
for name, value in node.args:
199
self.formatter.text(sep)
200
self.formatter.variable(name)
201
self.formatter.text(' = ')
204
self.formatter.text(')')
205
if node.ret is not None:
206
self.formatter.text(' = ')
209
def visit_trace(self, node):
210
for call in node.calls:
212
self.formatter.newline()