LEFT | RIGHT |
(no file at all) | |
1 # This file is part of LilyPond, the GNU music typesetter. | 1 # This file is part of LilyPond, the GNU music typesetter. |
2 # | 2 # |
3 # Copyright (C) 2012--2020 Joe Neeman <joeneeman@gmail.com> | 3 # Copyright (C) 2012--2020 Joe Neeman <joeneeman@gmail.com> |
4 # | 4 # |
5 # LilyPond is free software: you can redistribute it and/or modify | 5 # LilyPond is free software: you can redistribute it and/or modify |
6 # it under the terms of the GNU General Public License as published by | 6 # it under the terms of the GNU General Public License as published by |
7 # the Free Software Foundation, either version 3 of the License, or | 7 # the Free Software Foundation, either version 3 of the License, or |
8 # (at your option) any later version. | 8 # (at your option) any later version. |
9 # | 9 # |
10 # LilyPond is distributed in the hope that it will be useful, | 10 # LilyPond is distributed in the hope that it will be useful, |
(...skipping 23 matching lines...) Expand all Loading... |
34 search = str(typ) + '::' + name | 34 search = str(typ) + '::' + name |
35 try: | 35 try: |
36 return gdb.lookup_type(search) | 36 return gdb.lookup_type(search) |
37 except RuntimeError: | 37 except RuntimeError: |
38 pass | 38 pass |
39 # The type was not found, so try the superclass. We only need | 39 # The type was not found, so try the superclass. We only need |
40 # to check the first superclass, so we don't bother with | 40 # to check the first superclass, so we don't bother with |
41 # anything fancier here. | 41 # anything fancier here. |
42 field = typ.fields()[0] | 42 field = typ.fields()[0] |
43 if not field.is_base_class: | 43 if not field.is_base_class: |
44 raise ValueError, "Cannot find type %s::%s" % (str(orig), name) | 44 raise ValueError("Cannot find type %s::%s" % (str(orig), name)) |
45 typ = field.type | 45 typ = field.type |
46 | 46 |
47 # Class adapted from GCC | 47 # Class adapted from GCC |
48 class ListIterator: | 48 class ListIterator: |
49 def __init__ (self, val): | 49 def __init__ (self, val): |
50 self.val = val | 50 self.val = val |
51 self.nodetype = find_type (val.type, '_Node') | 51 self.nodetype = find_type (val.type, '_Node') |
52 self.nodetype = self.nodetype.strip_typedefs ().pointer () | 52 self.nodetype = self.nodetype.strip_typedefs ().pointer () |
53 | 53 |
54 head = val['_M_impl']['_M_node'] | 54 head = val['_M_impl']['_M_node'] |
55 self.base = head['_M_next'] | 55 self.base = head['_M_next'] |
56 self.head = head.address | 56 self.head = head.address |
57 | 57 |
58 def __iter__ (self): | 58 def __iter__ (self): |
59 return self | 59 return self |
60 | 60 |
61 def next (self): | 61 def __next__ (self): |
62 if self.base == self.head: | 62 if self.base == self.head: |
63 raise StopIteration | 63 raise StopIteration |
64 elt = self.base.cast (self.nodetype).dereference () | 64 elt = self.base.cast (self.nodetype).dereference () |
65 self.base = elt['_M_next'] | 65 self.base = elt['_M_next'] |
66 return elt['_M_data'] | 66 return elt['_M_data'] |
67 | 67 |
68 def to_list (list_val): | 68 def to_list (list_val): |
69 return list (ListIterator (list_val)) | 69 return list (ListIterator (list_val)) |
70 | 70 |
71 def skyline_to_lines (sky_value): | 71 def skyline_to_lines (sky_value): |
72 """Turns a gdb.Value into a list of line segments.""" | 72 """Turns a gdb.Value into a list of line segments.""" |
73 sky_d = int (sky_value['sky_']) | 73 sky_d = int (sky_value['sky_']) |
74 buildings = to_list (sky_value['buildings_']) | 74 buildings = to_list (sky_value['buildings_']) |
75 | 75 |
76 def bld_to_line (bld): | 76 def bld_to_line (bld): |
77 y_intercept = float (bld['y_intercept_']) * sky_d | 77 y_intercept = float (bld['y_intercept_']) * sky_d |
78 slope = float (bld['slope_']) * sky_d | 78 slope = float (bld['slope_']) * sky_d |
79 x1 = float (bld['start_']) | 79 x1 = float (bld['start_']) |
80 x2 = float (bld['end_']) | 80 x2 = float (bld['end_']) |
81 | 81 |
82 if isinf (y_intercept) or isinf (x1) or isinf (x2): | 82 if isinf (y_intercept) or isinf (x1) or isinf (x2): |
83 return None | 83 return None |
84 return (x1, y_intercept + slope * x1, x2, y_intercept + slope * x2) | 84 return (x1, y_intercept + slope * x1, x2, y_intercept + slope * x2) |
85 | 85 |
86 ret = map (bld_to_line, buildings) | 86 ret = list(map (bld_to_line, buildings)) |
87 return [r for r in ret if r is not None] | 87 return [r for r in ret if r is not None] |
88 | 88 |
89 viewer = Popen(SKYLINE_VIEWER, stdin=PIPE) | 89 viewer = Popen(SKYLINE_VIEWER, stdin=PIPE) |
90 def add_skyline(lines): | 90 def add_skyline(lines): |
91 global viewer | 91 global viewer |
92 try: | 92 try: |
93 for line in lines: | 93 for line in lines: |
94 x1, y1, x2, y2 = line | 94 x1, y1, x2, y2 = line |
95 viewer.stdin.write('(%f,%f) (%f,%f)\n' % (x1, y1, x2, y2)) | 95 viewer.stdin.write('(%f,%f) (%f,%f)\n' % (x1, y1, x2, y2)) |
96 viewer.stdin.write('\n') | 96 viewer.stdin.write('\n') |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
147 def __init__ (self): | 147 def __init__ (self): |
148 super (ShowHSkylineCommand, self).__init__ ("hsky") | 148 super (ShowHSkylineCommand, self).__init__ ("hsky") |
149 | 149 |
150 def to_lines (self, skyline): | 150 def to_lines (self, skyline): |
151 lines = skyline_to_lines (skyline) | 151 lines = skyline_to_lines (skyline) |
152 # Because it is a horizontal skyline, reflect around the line y=x. | 152 # Because it is a horizontal skyline, reflect around the line y=x. |
153 return [(y1, x1, y2, x2) for (x1, y1, x2, y2) in lines] | 153 return [(y1, x1, y2, x2) for (x1, y1, x2, y2) in lines] |
154 | 154 |
155 ShowHSkylineCommand() | 155 ShowHSkylineCommand() |
156 ShowVSkylineCommand() | 156 ShowVSkylineCommand() |
LEFT | RIGHT |