blob: eb8b2eba9a1291f03e8d14cdd329427858104ab5 [file] [log] [blame]
Tobin Ehlis08fafd02015-06-12 12:49:01 -06001#!/usr/bin/env python3
2#
Courtney Goeltzenleuchterfcbe16f2015-10-29 13:50:34 -06003# Copyright (C) 2015 Valve Corporation
Tobin Ehlis08fafd02015-06-12 12:49:01 -06004#
5# Permission is hereby granted, free of charge, to any person obtaining a
6# copy of this software and associated documentation files (the "Software"),
7# to deal in the Software without restriction, including without limitation
8# the rights to use, copy, modify, merge, publish, distribute, sublicense,
9# and/or sell copies of the Software, and to permit persons to whom the
10# Software is furnished to do so, subject to the following conditions:
11#
12# The above copyright notice and this permission notice shall be included
13# in all copies or substantial portions of the Software.
14#
15# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21# DEALINGS IN THE SOFTWARE.
Courtney Goeltzenleuchter05559522015-10-30 11:14:30 -060022#
23# Author: Tobin Ehlis <tobin@lunarg.com>
Tobin Ehlis08fafd02015-06-12 12:49:01 -060024
25from inspect import currentframe, getframeinfo
26
27# This is a wrapper class for inspect module that returns a formatted line
28# with details of the source file and line number of python code who called
29# into this class. The result can them be added to codegen to simplify
30# debug as it shows where code was generated from.
31class sourcelineinfo():
32 def __init__(self):
33 self.general_prefix = "// CODEGEN : "
34 self.file_prefix = "file "
35 self.line_prefix = "line #"
36 self.enabled = True
37
38 def get(self):
39 if self.enabled:
40 frameinfo = getframeinfo(currentframe().f_back)
41 return "%s%s%s %s%s" % (self.general_prefix, self.file_prefix, frameinfo.filename, self.line_prefix, frameinfo.lineno)
42 return ""