blob: 66fea08c785677a66cd623f3419d9cdc4444470d [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#
Jon Ashburn43b53e82016-04-19 11:30:31 -06008# 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
Tobin Ehlisfde2fc32015-06-12 12:49:01 -060011#
Jon Ashburn43b53e82016-04-19 11:30:31 -060012# http://www.apache.org/licenses/LICENSE-2.0
Tobin Ehlisfde2fc32015-06-12 12:49:01 -060013#
Jon Ashburn43b53e82016-04-19 11:30:31 -060014# 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.
Courtney Goeltzenleuchter96cd7952015-10-30 11:14:30 -060019#
20# Author: Tobin Ehlis <tobin@lunarg.com>
Tobin Ehlisfde2fc32015-06-12 12:49:01 -060021
22from inspect import currentframe, getframeinfo
23
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.
28class sourcelineinfo():
29 def __init__(self):
30 self.general_prefix = "// CODEGEN : "
31 self.file_prefix = "file "
32 self.line_prefix = "line #"
33 self.enabled = True
34
35 def get(self):
36 if self.enabled:
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)
39 return ""