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