blob: 75cbff189f5e51dce152dbf5d7aff88f41ef7455 [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 Confidential Information as defined by the Khronos
19# Membership Agreement until designated non-confidential by Khronos, at which
20# point this condition clause shall be removed.
21#
22# THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
Tobin Ehlisfde2fc32015-06-12 12:49:01 -060023# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
Karl Schultzc85a02f2016-02-02 19:32:33 -070024# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
25#
26# IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
27# DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
28# OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE MATERIALS OR THE
29# USE OR OTHER DEALINGS IN THE MATERIALS
Courtney Goeltzenleuchter96cd7952015-10-30 11:14:30 -060030#
31# Author: Tobin Ehlis <tobin@lunarg.com>
Tobin Ehlisfde2fc32015-06-12 12:49:01 -060032
33from inspect import currentframe, getframeinfo
34
35# This is a wrapper class for inspect module that returns a formatted line
36# with details of the source file and line number of python code who called
37# into this class. The result can them be added to codegen to simplify
38# debug as it shows where code was generated from.
39class sourcelineinfo():
40 def __init__(self):
41 self.general_prefix = "// CODEGEN : "
42 self.file_prefix = "file "
43 self.line_prefix = "line #"
44 self.enabled = True
45
46 def get(self):
47 if self.enabled:
48 frameinfo = getframeinfo(currentframe().f_back)
49 return "%s%s%s %s%s" % (self.general_prefix, self.file_prefix, frameinfo.filename, self.line_prefix, frameinfo.lineno)
50 return ""