Sapan Bhatia | 3cfdf63 | 2017-06-08 05:14:03 +0200 | [diff] [blame] | 1 | import plyxproto.model as m |
Sapan Bhatia | ff1b8fa | 2017-04-10 19:44:38 -0700 | [diff] [blame] | 2 | import pdb |
| 3 | import argparse |
Sapan Bhatia | 3cfdf63 | 2017-06-08 05:14:03 +0200 | [diff] [blame] | 4 | import plyxproto.parser as plyxproto |
Sapan Bhatia | ff1b8fa | 2017-04-10 19:44:38 -0700 | [diff] [blame] | 5 | import traceback |
| 6 | import sys |
| 7 | import jinja2 |
| 8 | import os |
Sapan Bhatia | 1e397df | 2017-05-24 12:17:28 +0200 | [diff] [blame] | 9 | import copy |
Sapan Bhatia | ff1b8fa | 2017-04-10 19:44:38 -0700 | [diff] [blame] | 10 | |
Matteo Scandolo | 67654fa | 2017-06-09 09:33:17 -0700 | [diff] [blame] | 11 | |
Sapan Bhatia | 3cfdf63 | 2017-06-08 05:14:03 +0200 | [diff] [blame] | 12 | def dotname_to_fqn(dotname): |
| 13 | b_names = [part.pval for part in dotname] |
| 14 | package = '.'.join(b_names[:-1]) |
| 15 | name = b_names[-1] |
| 16 | if package: |
| 17 | fqn = package + '.' + name |
| 18 | else: |
| 19 | fqn = name |
Matteo Scandolo | 67654fa | 2017-06-09 09:33:17 -0700 | [diff] [blame] | 20 | return {'name': name, 'fqn': fqn, 'package': package} |
| 21 | |
Sapan Bhatia | 3cfdf63 | 2017-06-08 05:14:03 +0200 | [diff] [blame] | 22 | |
| 23 | def dotname_to_name(dotname): |
| 24 | b_names = [part.pval for part in dotname] |
| 25 | return '.'.join(b_names) |
| 26 | |
| 27 | |
Sapan Bhatia | 504cc97 | 2017-04-27 01:56:28 +0200 | [diff] [blame] | 28 | def count_messages(body): |
| 29 | count = 0 |
| 30 | for e in body: |
Matteo Scandolo | 67654fa | 2017-06-09 09:33:17 -0700 | [diff] [blame] | 31 | if (type(e) == m.MessageDefinition): |
| 32 | count += 1 |
Sapan Bhatia | 504cc97 | 2017-04-27 01:56:28 +0200 | [diff] [blame] | 33 | return count |
| 34 | |
Matteo Scandolo | 67654fa | 2017-06-09 09:33:17 -0700 | [diff] [blame] | 35 | |
Sapan Bhatia | 504cc97 | 2017-04-27 01:56:28 +0200 | [diff] [blame] | 36 | def count_fields(body): |
| 37 | count = 0 |
| 38 | for e in body: |
Matteo Scandolo | 67654fa | 2017-06-09 09:33:17 -0700 | [diff] [blame] | 39 | if (type(e) in [m.LinkDefinition, m.FieldDefinition, m.LinkSpec]): |
| 40 | count += 1 |
Sapan Bhatia | 504cc97 | 2017-04-27 01:56:28 +0200 | [diff] [blame] | 41 | return count |
| 42 | |
Sapan Bhatia | cb35e7f | 2017-05-24 12:17:28 +0200 | [diff] [blame] | 43 | def compute_rlinks(messages, message_dict): |
Sapan Bhatia | 1e397df | 2017-05-24 12:17:28 +0200 | [diff] [blame] | 44 | rev_links = {} |
| 45 | |
| 46 | link_opposite = { |
Matteo Scandolo | 67654fa | 2017-06-09 09:33:17 -0700 | [diff] [blame] | 47 | 'manytomany': 'manytomany', |
| 48 | 'manytoone': 'onetomany', |
| 49 | 'onetoone': 'onetoone', |
| 50 | 'onetomany': 'manytoone' |
Sapan Bhatia | 1e397df | 2017-05-24 12:17:28 +0200 | [diff] [blame] | 51 | } |
| 52 | |
| 53 | for m in messages: |
| 54 | for l in m['links']: |
| 55 | rlink = copy.deepcopy(l) |
Sapan Bhatia | 3cfdf63 | 2017-06-08 05:14:03 +0200 | [diff] [blame] | 56 | |
Matteo Scandolo | 67654fa | 2017-06-09 09:33:17 -0700 | [diff] [blame] | 57 | rlink['_type'] = 'rlink' # An implicit link, not declared in the model |
Sapan Bhatia | 1e397df | 2017-05-24 12:17:28 +0200 | [diff] [blame] | 58 | rlink['src_port'] = l['dst_port'] |
| 59 | rlink['dst_port'] = l['src_port'] |
Matteo Scandolo | 67654fa | 2017-06-09 09:33:17 -0700 | [diff] [blame] | 60 | rlink['peer'] = {'name': m['name'], 'package': m['package'], 'fqn': m['fqn']} |
Sapan Bhatia | 1e397df | 2017-05-24 12:17:28 +0200 | [diff] [blame] | 61 | rlink['link_type'] = link_opposite[l['link_type']] |
| 62 | |
| 63 | try: |
Sapan Bhatia | 3cfdf63 | 2017-06-08 05:14:03 +0200 | [diff] [blame] | 64 | try: |
| 65 | rev_links[l['peer']['fqn']].append(rlink) |
| 66 | except TypeError: |
| 67 | pdb.set_trace() |
| 68 | pass |
Sapan Bhatia | 1e397df | 2017-05-24 12:17:28 +0200 | [diff] [blame] | 69 | except KeyError: |
Sapan Bhatia | 3cfdf63 | 2017-06-08 05:14:03 +0200 | [diff] [blame] | 70 | rev_links[l['peer']['fqn']] = [rlink] |
Sapan Bhatia | 1e397df | 2017-05-24 12:17:28 +0200 | [diff] [blame] | 71 | |
| 72 | for m in messages: |
| 73 | try: |
| 74 | m['rlinks'] = rev_links[m['name']] |
Sapan Bhatia | cb35e7f | 2017-05-24 12:17:28 +0200 | [diff] [blame] | 75 | message_dict[m['name']]['rlinks'] = m['rlinks'] |
Sapan Bhatia | 1e397df | 2017-05-24 12:17:28 +0200 | [diff] [blame] | 76 | except KeyError: |
| 77 | pass |
| 78 | |
Matteo Scandolo | 67654fa | 2017-06-09 09:33:17 -0700 | [diff] [blame] | 79 | |
Sapan Bhatia | 3cfdf63 | 2017-06-08 05:14:03 +0200 | [diff] [blame] | 80 | def name_to_value(obj): |
| 81 | try: |
| 82 | value = obj.value.value.pval |
| 83 | except AttributeError: |
| 84 | try: |
| 85 | value = obj.value.value |
| 86 | except AttributeError: |
| 87 | value = obj.value.pval |
| 88 | |
| 89 | return value |
| 90 | |
Matteo Scandolo | 67654fa | 2017-06-09 09:33:17 -0700 | [diff] [blame] | 91 | |
Sapan Bhatia | ff1b8fa | 2017-04-10 19:44:38 -0700 | [diff] [blame] | 92 | class Stack(list): |
Matteo Scandolo | 67654fa | 2017-06-09 09:33:17 -0700 | [diff] [blame] | 93 | def push(self, x): |
Sapan Bhatia | ff1b8fa | 2017-04-10 19:44:38 -0700 | [diff] [blame] | 94 | self.append(x) |
| 95 | |
Matteo Scandolo | 67654fa | 2017-06-09 09:33:17 -0700 | [diff] [blame] | 96 | |
Sapan Bhatia | ff1b8fa | 2017-04-10 19:44:38 -0700 | [diff] [blame] | 97 | ''' XOS2Jinja overrides the underlying visitor pattern to transform the tree |
| 98 | in addition to traversing it ''' |
Matteo Scandolo | 67654fa | 2017-06-09 09:33:17 -0700 | [diff] [blame] | 99 | |
| 100 | |
Sapan Bhatia | ff1b8fa | 2017-04-10 19:44:38 -0700 | [diff] [blame] | 101 | class XOS2Jinja(m.Visitor): |
Sapan Bhatia | ff1b8fa | 2017-04-10 19:44:38 -0700 | [diff] [blame] | 102 | |
| 103 | def get_stack(self): |
Matteo Scandolo | 67654fa | 2017-06-09 09:33:17 -0700 | [diff] [blame] | 104 | return self.stack |
Sapan Bhatia | ff1b8fa | 2017-04-10 19:44:38 -0700 | [diff] [blame] | 105 | |
| 106 | def __init__(self): |
| 107 | super(XOS2Jinja, self).__init__() |
| 108 | |
Matteo Scandolo | 67654fa | 2017-06-09 09:33:17 -0700 | [diff] [blame] | 109 | self.stack = Stack() |
| 110 | self.models = {} |
| 111 | self.options = {} |
| 112 | self.package = None |
| 113 | self.message_options = {} |
| 114 | self.count_stack = Stack() |
| 115 | self.content = "" |
| 116 | self.offset = 0 |
| 117 | self.current_message_name = None |
Sapan Bhatia | ff1b8fa | 2017-04-10 19:44:38 -0700 | [diff] [blame] | 118 | self.verbose = 0 |
| 119 | self.first_field = True |
| 120 | self.first_method = True |
| 121 | |
| 122 | def visit_PackageStatement(self, obj): |
Sapan Bhatia | 3cfdf63 | 2017-06-08 05:14:03 +0200 | [diff] [blame] | 123 | dotlist = obj.name.value |
| 124 | dotlist2 = [f.pval for f in dotlist] |
| 125 | dotstr = '.'.join(dotlist2) |
| 126 | self.package = dotstr |
Sapan Bhatia | ff1b8fa | 2017-04-10 19:44:38 -0700 | [diff] [blame] | 127 | return True |
| 128 | |
| 129 | def visit_ImportStatement(self, obj): |
| 130 | '''Ignore''' |
| 131 | return True |
| 132 | |
| 133 | def visit_OptionStatement(self, obj): |
Matteo Scandolo | 67654fa | 2017-06-09 09:33:17 -0700 | [diff] [blame] | 134 | if not hasattr(obj, 'mark_for_deletion'): |
Sapan Bhatia | ae9645c | 2017-05-05 15:35:54 +0200 | [diff] [blame] | 135 | if (self.current_message_name): |
| 136 | self.message_options[obj.name.value.pval] = obj.value.value.pval |
| 137 | else: |
| 138 | self.options[obj.name.value.pval] = obj.value.value.pval |
Sapan Bhatia | 504cc97 | 2017-04-27 01:56:28 +0200 | [diff] [blame] | 139 | |
Sapan Bhatia | ff1b8fa | 2017-04-10 19:44:38 -0700 | [diff] [blame] | 140 | return True |
| 141 | |
| 142 | def visit_LU(self, obj): |
| 143 | return True |
| 144 | |
| 145 | def visit_default(self, obj): |
| 146 | return True |
| 147 | |
| 148 | def visit_FieldDirective(self, obj): |
| 149 | return True |
| 150 | |
| 151 | def visit_FieldDirective_post(self, obj): |
| 152 | |
| 153 | try: |
| 154 | name = obj.name.value.pval |
| 155 | except AttributeError: |
| 156 | name = obj.name.value |
| 157 | |
Matteo Scandolo | 67654fa | 2017-06-09 09:33:17 -0700 | [diff] [blame] | 158 | if type(obj.value) == list: |
Sapan Bhatia | 3cfdf63 | 2017-06-08 05:14:03 +0200 | [diff] [blame] | 159 | value = dotname_to_name(obj.value) |
| 160 | else: |
| 161 | value = name_to_value(obj) |
Sapan Bhatia | ff1b8fa | 2017-04-10 19:44:38 -0700 | [diff] [blame] | 162 | |
Matteo Scandolo | 67654fa | 2017-06-09 09:33:17 -0700 | [diff] [blame] | 163 | self.stack.push([name, value]) |
Sapan Bhatia | ff1b8fa | 2017-04-10 19:44:38 -0700 | [diff] [blame] | 164 | return True |
| 165 | |
| 166 | def visit_FieldType(self, obj): |
| 167 | '''Field type, if type is name, then it may need refactoring consistent with refactoring rules according to the table''' |
| 168 | return True |
| 169 | |
| 170 | def visit_LinkDefinition(self, obj): |
Matteo Scandolo | 67654fa | 2017-06-09 09:33:17 -0700 | [diff] [blame] | 171 | s = {} |
Sapan Bhatia | 8a57c66 | 2017-04-11 10:39:47 -0700 | [diff] [blame] | 172 | |
Sapan Bhatia | ae9645c | 2017-05-05 15:35:54 +0200 | [diff] [blame] | 173 | try: |
| 174 | s['link_type'] = obj.link_type.pval |
| 175 | except AttributeError: |
| 176 | s['link_type'] = obj.link_type |
| 177 | |
Sapan Bhatia | ff1b8fa | 2017-04-10 19:44:38 -0700 | [diff] [blame] | 178 | s['src_port'] = obj.src_port.value.pval |
| 179 | s['name'] = obj.src_port.value.pval |
Sapan Bhatia | c4f803f | 2017-04-21 11:50:39 +0200 | [diff] [blame] | 180 | |
Sapan Bhatia | ff1b8fa | 2017-04-10 19:44:38 -0700 | [diff] [blame] | 181 | try: |
| 182 | s['dst_port'] = obj.dst_port.value.pval |
| 183 | except AttributeError: |
Sapan Bhatia | ae9645c | 2017-05-05 15:35:54 +0200 | [diff] [blame] | 184 | s['dst_port'] = obj.dst_port |
Sapan Bhatia | c4f803f | 2017-04-21 11:50:39 +0200 | [diff] [blame] | 185 | |
Matteo Scandolo | 67654fa | 2017-06-09 09:33:17 -0700 | [diff] [blame] | 186 | if type(obj.through) == list: |
Sapan Bhatia | 3cfdf63 | 2017-06-08 05:14:03 +0200 | [diff] [blame] | 187 | s['through'] = dotname_to_fqn(obj.through) |
| 188 | else: |
| 189 | try: |
| 190 | s['through'] = obj.through.pval |
| 191 | except AttributeError: |
| 192 | s['through'] = obj.through |
Sapan Bhatia | c4f803f | 2017-04-21 11:50:39 +0200 | [diff] [blame] | 193 | |
Matteo Scandolo | 67654fa | 2017-06-09 09:33:17 -0700 | [diff] [blame] | 194 | if type(obj.name) == list: |
Sapan Bhatia | 3cfdf63 | 2017-06-08 05:14:03 +0200 | [diff] [blame] | 195 | s['peer'] = dotname_to_fqn(obj.name) |
| 196 | else: |
| 197 | try: |
| 198 | s['peer'] = obj.name.pval |
| 199 | except AttributeError: |
| 200 | s['peer'] = obj.name |
Sapan Bhatia | ae9645c | 2017-05-05 15:35:54 +0200 | [diff] [blame] | 201 | |
Sapan Bhatia | ff1b8fa | 2017-04-10 19:44:38 -0700 | [diff] [blame] | 202 | s['_type'] = 'link' |
Matteo Scandolo | 67654fa | 2017-06-09 09:33:17 -0700 | [diff] [blame] | 203 | s['options'] = {'modifier': 'optional'} |
Sapan Bhatia | ff1b8fa | 2017-04-10 19:44:38 -0700 | [diff] [blame] | 204 | |
| 205 | self.stack.push(s) |
| 206 | return True |
| 207 | |
| 208 | def visit_FieldDefinition(self, obj): |
| 209 | self.count_stack.push(len(obj.fieldDirective)) |
| 210 | return True |
| 211 | |
| 212 | def visit_FieldDefinition_post(self, obj): |
Matteo Scandolo | 67654fa | 2017-06-09 09:33:17 -0700 | [diff] [blame] | 213 | s = {} |
| 214 | |
Sapan Bhatia | ff1b8fa | 2017-04-10 19:44:38 -0700 | [diff] [blame] | 215 | if isinstance(obj.ftype, m.Name): |
| 216 | s['type'] = obj.ftype.value |
| 217 | else: |
| 218 | s['type'] = obj.ftype.name.pval |
Sapan Bhatia | 3cfdf63 | 2017-06-08 05:14:03 +0200 | [diff] [blame] | 219 | |
Sapan Bhatia | ff1b8fa | 2017-04-10 19:44:38 -0700 | [diff] [blame] | 220 | s['name'] = obj.name.value.pval |
| 221 | s['modifier'] = obj.field_modifier.pval |
| 222 | s['id'] = obj.fieldId.pval |
| 223 | |
Matteo Scandolo | 67654fa | 2017-06-09 09:33:17 -0700 | [diff] [blame] | 224 | opts = {'modifier': s['modifier']} |
Sapan Bhatia | ff1b8fa | 2017-04-10 19:44:38 -0700 | [diff] [blame] | 225 | n = self.count_stack.pop() |
| 226 | for i in range(0, n): |
Matteo Scandolo | 67654fa | 2017-06-09 09:33:17 -0700 | [diff] [blame] | 227 | k, v = self.stack.pop() |
Sapan Bhatia | 5769d93 | 2017-05-17 11:10:54 +0200 | [diff] [blame] | 228 | |
Matteo Scandolo | 67654fa | 2017-06-09 09:33:17 -0700 | [diff] [blame] | 229 | # The two lines below may be added to eliminate "" around an option. |
Sapan Bhatia | 5769d93 | 2017-05-17 11:10:54 +0200 | [diff] [blame] | 230 | # Right now, this is handled in targets. FIXME |
| 231 | # |
| 232 | # if (v.startswith('"') and v.endswith('"')): |
| 233 | # v = v[1:-1] |
| 234 | |
Sapan Bhatia | ff1b8fa | 2017-04-10 19:44:38 -0700 | [diff] [blame] | 235 | opts[k] = v |
| 236 | |
| 237 | s['options'] = opts |
Sapan Bhatia | 8a57c66 | 2017-04-11 10:39:47 -0700 | [diff] [blame] | 238 | try: |
| 239 | last_link = self.stack[-1]['_type'] |
Matteo Scandolo | 67654fa | 2017-06-09 09:33:17 -0700 | [diff] [blame] | 240 | if (last_link == 'link'): |
Sapan Bhatia | 8a57c66 | 2017-04-11 10:39:47 -0700 | [diff] [blame] | 241 | s['link'] = True |
| 242 | except: |
| 243 | pass |
| 244 | s['_type'] = 'field' |
| 245 | |
Sapan Bhatia | ff1b8fa | 2017-04-10 19:44:38 -0700 | [diff] [blame] | 246 | self.stack.push(s) |
| 247 | return True |
| 248 | |
| 249 | def visit_EnumFieldDefinition(self, obj): |
| 250 | if self.verbose > 4: |
| 251 | print "\tEnumField: name=%s, %s" % (obj.name, obj) |
| 252 | |
| 253 | return True |
| 254 | |
| 255 | def visit_EnumDefinition(self, obj): |
| 256 | '''New enum definition, refactor name''' |
| 257 | if self.verbose > 3: |
| 258 | print "Enum, [%s] body=%s\n\n" % (obj.name, obj.body) |
| 259 | |
Sapan Bhatia | ff1b8fa | 2017-04-10 19:44:38 -0700 | [diff] [blame] | 260 | return True |
| 261 | |
| 262 | def visit_MessageDefinition(self, obj): |
Sapan Bhatia | 504cc97 | 2017-04-27 01:56:28 +0200 | [diff] [blame] | 263 | self.current_message_name = obj.name.value.pval |
| 264 | self.message_options = {} |
| 265 | self.count_stack.push(count_fields(obj.body)) |
Sapan Bhatia | ff1b8fa | 2017-04-10 19:44:38 -0700 | [diff] [blame] | 266 | return True |
Matteo Scandolo | 67654fa | 2017-06-09 09:33:17 -0700 | [diff] [blame] | 267 | |
Sapan Bhatia | ff1b8fa | 2017-04-10 19:44:38 -0700 | [diff] [blame] | 268 | def visit_MessageDefinition_post(self, obj): |
| 269 | stack_num = self.count_stack.pop() |
| 270 | fields = [] |
| 271 | links = [] |
| 272 | last_field = None |
Sapan Bhatia | ae9645c | 2017-05-05 15:35:54 +0200 | [diff] [blame] | 273 | try: |
Sapan Bhatia | 3cfdf63 | 2017-06-08 05:14:03 +0200 | [diff] [blame] | 274 | obj.bases = map(dotname_to_fqn, obj.bases) |
Sapan Bhatia | ae9645c | 2017-05-05 15:35:54 +0200 | [diff] [blame] | 275 | except AttributeError: |
| 276 | pass |
Sapan Bhatia | ff1b8fa | 2017-04-10 19:44:38 -0700 | [diff] [blame] | 277 | |
Sapan Bhatia | 3cfdf63 | 2017-06-08 05:14:03 +0200 | [diff] [blame] | 278 | last_field = {} |
Matteo Scandolo | 67654fa | 2017-06-09 09:33:17 -0700 | [diff] [blame] | 279 | for i in range(0, stack_num): |
Sapan Bhatia | ff1b8fa | 2017-04-10 19:44:38 -0700 | [diff] [blame] | 280 | f = self.stack.pop() |
Matteo Scandolo | 67654fa | 2017-06-09 09:33:17 -0700 | [diff] [blame] | 281 | if (f['_type'] == 'link'): |
| 282 | f['options'] = {i: d[i] for d in [f['options'], last_field['options']] for i in d} |
| 283 | assert (last_field == fields[0]) |
Sapan Bhatia | d022aeb | 2017-06-07 15:49:55 +0200 | [diff] [blame] | 284 | fields[0].setdefault('options', {})['link_type'] = f['link_type'] |
Matteo Scandolo | 67654fa | 2017-06-09 09:33:17 -0700 | [diff] [blame] | 285 | links.insert(0, f) |
Sapan Bhatia | ff1b8fa | 2017-04-10 19:44:38 -0700 | [diff] [blame] | 286 | else: |
Matteo Scandolo | 67654fa | 2017-06-09 09:33:17 -0700 | [diff] [blame] | 287 | fields.insert(0, f) |
Sapan Bhatia | ff1b8fa | 2017-04-10 19:44:38 -0700 | [diff] [blame] | 288 | last_field = f |
| 289 | |
Sapan Bhatia | 3cfdf63 | 2017-06-08 05:14:03 +0200 | [diff] [blame] | 290 | if self.package: |
| 291 | model_name = '.'.join([self.package, obj.name.value.pval]) |
| 292 | else: |
| 293 | model_name = obj.name.value.pval |
| 294 | |
Sapan Bhatia | cb35e7f | 2017-05-24 12:17:28 +0200 | [diff] [blame] | 295 | model_def = {'name':obj.name.value.pval,'fields':fields,'links':links, 'bases':obj.bases, 'options':self.message_options, 'package':self.package, 'fqn': model_name, 'rlinks': []} |
Sapan Bhatia | 943dad5 | 2017-05-19 18:41:01 +0200 | [diff] [blame] | 296 | self.stack.push(model_def) |
Sapan Bhatia | cb35e7f | 2017-05-24 12:17:28 +0200 | [diff] [blame] | 297 | |
Sapan Bhatia | 3cfdf63 | 2017-06-08 05:14:03 +0200 | [diff] [blame] | 298 | self.models[model_name] = model_def |
| 299 | |
| 300 | # Set message options |
Matteo Scandolo | 67654fa | 2017-06-09 09:33:17 -0700 | [diff] [blame] | 301 | for k, v in self.options.iteritems(): |
Sapan Bhatia | 3cfdf63 | 2017-06-08 05:14:03 +0200 | [diff] [blame] | 302 | try: |
Sapan Bhatia | cb35e7f | 2017-05-24 12:17:28 +0200 | [diff] [blame] | 303 | if k not in self.message_options: |
| 304 | self.message_options[k] = v |
Sapan Bhatia | 3cfdf63 | 2017-06-08 05:14:03 +0200 | [diff] [blame] | 305 | except KeyError: |
| 306 | pass |
| 307 | |
Sapan Bhatia | 504cc97 | 2017-04-27 01:56:28 +0200 | [diff] [blame] | 308 | self.current_message_name = None |
Sapan Bhatia | ff1b8fa | 2017-04-10 19:44:38 -0700 | [diff] [blame] | 309 | return True |
| 310 | |
| 311 | def visit_MessageExtension(self, obj): |
| 312 | return True |
| 313 | |
| 314 | def visit_MethodDefinition(self, obj): |
| 315 | return True |
| 316 | |
| 317 | def visit_ServiceDefinition(self, obj): |
| 318 | return True |
| 319 | |
| 320 | def visit_ExtensionsDirective(self, obj): |
| 321 | return True |
| 322 | |
| 323 | def visit_Literal(self, obj): |
| 324 | return True |
| 325 | |
| 326 | def visit_Name(self, obj): |
| 327 | return True |
| 328 | |
| 329 | def visit_DotName(self, obj): |
| 330 | return True |
| 331 | |
| 332 | def visit_Proto(self, obj): |
Sapan Bhatia | 504cc97 | 2017-04-27 01:56:28 +0200 | [diff] [blame] | 333 | self.count_stack.push(count_messages(obj.body)) |
Sapan Bhatia | ff1b8fa | 2017-04-10 19:44:38 -0700 | [diff] [blame] | 334 | return True |
Matteo Scandolo | 67654fa | 2017-06-09 09:33:17 -0700 | [diff] [blame] | 335 | |
Sapan Bhatia | ff1b8fa | 2017-04-10 19:44:38 -0700 | [diff] [blame] | 336 | def visit_Proto_post(self, obj): |
| 337 | count = self.count_stack.pop() |
| 338 | messages = [] |
Matteo Scandolo | 67654fa | 2017-06-09 09:33:17 -0700 | [diff] [blame] | 339 | for i in range(0, count): |
Sapan Bhatia | c4f803f | 2017-04-21 11:50:39 +0200 | [diff] [blame] | 340 | try: |
| 341 | m = self.stack.pop() |
| 342 | except IndexError: |
Sapan Bhatia | 504cc97 | 2017-04-27 01:56:28 +0200 | [diff] [blame] | 343 | pass |
Sapan Bhatia | c4f803f | 2017-04-21 11:50:39 +0200 | [diff] [blame] | 344 | |
Matteo Scandolo | 67654fa | 2017-06-09 09:33:17 -0700 | [diff] [blame] | 345 | messages.insert(0, m) |
Sapan Bhatia | ff1b8fa | 2017-04-10 19:44:38 -0700 | [diff] [blame] | 346 | |
Sapan Bhatia | cb35e7f | 2017-05-24 12:17:28 +0200 | [diff] [blame] | 347 | compute_rlinks(messages, self.models) |
| 348 | |
Sapan Bhatia | ff1b8fa | 2017-04-10 19:44:38 -0700 | [diff] [blame] | 349 | self.messages = messages |
| 350 | return True |
| 351 | |
| 352 | def visit_LinkSpec(self, obj): |
| 353 | count = self.count_stack.pop() |
Matteo Scandolo | 67654fa | 2017-06-09 09:33:17 -0700 | [diff] [blame] | 354 | self.count_stack.push(count + 1) |
| 355 | return True |