3 # 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.
8 # Licensed under the Apache License, Version 2.0 (the "License");
9 # you may not use this file except in compliance with the License.
10 # You may obtain a copy of the License at
12 # http://www.apache.org/licenses/LICENSE-2.0
14 # Unless required by applicable law or agreed to in writing, software
15 # distributed under the License is distributed on an "AS IS" BASIS,
16 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 # See the License for the specific language governing permissions and
18 # limitations under the License.
20 # Author: Tobin Ehlis <tobin@lunarg.com>
22 from inspect import currentframe, getframeinfo
24 # This is a wrapper class for inspect module that returns a formatted line
25 # with details of the source file and line number of python code who called
26 # into this class. The result can them be added to codegen to simplify
27 # debug as it shows where code was generated from.
28 class sourcelineinfo():
30 self.general_prefix = "// CODEGEN : "
31 self.file_prefix = "file "
32 self.line_prefix = "line #"
37 frameinfo = getframeinfo(currentframe().f_back)
38 return "%s%s%s %s%s" % (self.general_prefix, self.file_prefix, frameinfo.filename, self.line_prefix, frameinfo.lineno)