Tobin Ehlis | 08fafd0 | 2015-06-12 12:49:01 -0600 | [diff] [blame] | 1 | #!/usr/bin/env python3 |
| 2 | # |
Karl Schultz | 8e42f40 | 2016-02-02 19:32:33 -0700 | [diff] [blame] | 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. |
Tobin Ehlis | 08fafd0 | 2015-06-12 12:49:01 -0600 | [diff] [blame] | 7 | # |
Jon Ashburn | 3ebf125 | 2016-04-19 11:30:31 -0600 | [diff] [blame] | 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 |
Tobin Ehlis | 08fafd0 | 2015-06-12 12:49:01 -0600 | [diff] [blame] | 11 | # |
Jon Ashburn | 3ebf125 | 2016-04-19 11:30:31 -0600 | [diff] [blame] | 12 | # http://www.apache.org/licenses/LICENSE-2.0 |
Tobin Ehlis | 08fafd0 | 2015-06-12 12:49:01 -0600 | [diff] [blame] | 13 | # |
Jon Ashburn | 3ebf125 | 2016-04-19 11:30:31 -0600 | [diff] [blame] | 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. |
Courtney Goeltzenleuchter | 0555952 | 2015-10-30 11:14:30 -0600 | [diff] [blame] | 19 | # |
| 20 | # Author: Tobin Ehlis <tobin@lunarg.com> |
Tobin Ehlis | 08fafd0 | 2015-06-12 12:49:01 -0600 | [diff] [blame] | 21 | |
| 22 | from 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. |
| 28 | class 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 "" |