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 | # |
Karl Schultz | 8e42f40 | 2016-02-02 19:32:33 -0700 | [diff] [blame] | 8 | # 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 Ehlis | 08fafd0 | 2015-06-12 12:49:01 -0600 | [diff] [blame] | 14 | # |
Karl Schultz | 8e42f40 | 2016-02-02 19:32:33 -0700 | [diff] [blame] | 15 | # The above copyright notice(s) and this permission notice shall be included |
| 16 | # in all copies or substantial portions of the Materials. |
Tobin Ehlis | 08fafd0 | 2015-06-12 12:49:01 -0600 | [diff] [blame] | 17 | # |
Karl Schultz | 8e42f40 | 2016-02-02 19:32:33 -0700 | [diff] [blame] | 18 | # THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
Tobin Ehlis | 08fafd0 | 2015-06-12 12:49:01 -0600 | [diff] [blame] | 19 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
Karl Schultz | 8e42f40 | 2016-02-02 19:32:33 -0700 | [diff] [blame] | 20 | # 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 Goeltzenleuchter | 0555952 | 2015-10-30 11:14:30 -0600 | [diff] [blame] | 26 | # |
| 27 | # Author: Tobin Ehlis <tobin@lunarg.com> |
Tobin Ehlis | 08fafd0 | 2015-06-12 12:49:01 -0600 | [diff] [blame] | 28 | |
| 29 | from 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. |
| 35 | class 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 "" |