|
26 | 26 | SECTION_RE = re.compile(r"---(\w+)---") |
27 | 27 | LAYER_RE = re.compile(r"//\sLAYER\s(\d+)") |
28 | 28 | COMBINATOR_RE = re.compile(r"^([\w.]+)#([0-9a-f]+)\s(?:.*)=\s([\w<>.]+);(?: // Docs: (.+))?$", re.MULTILINE) |
29 | | -ARGS_RE = re.compile("[^{](\w+):([\w?!.<>]+)") |
| 29 | +ARGS_RE = re.compile("[^{](\w+):([\w?!.<>#]+)") |
30 | 30 | FLAGS_RE = re.compile(r"flags\.(\d+)\?") |
31 | 31 | FLAGS_RE_2 = re.compile(r"flags\.(\d+)\?([\w<>.]+)") |
32 | 32 | FLAGS_RE_3 = re.compile(r"flags:#") |
@@ -288,17 +288,20 @@ def start(): |
288 | 288 | sorted_args = sort_args(c.args) |
289 | 289 |
|
290 | 290 | arguments = ", " + ", ".join( |
291 | | - [get_argument_type(i) for i in sorted_args] |
| 291 | + [get_argument_type(i) for i in sorted_args if i != ("flags", "#")] |
292 | 292 | ) if c.args else "" |
293 | 293 |
|
294 | 294 | fields = "\n ".join( |
295 | | - ["self.{0} = {0} # {1}".format(i[0], i[1]) for i in c.args] |
| 295 | + ["self.{0} = {0} # {1}".format(i[0], i[1]) for i in c.args if i != ("flags", "#")] |
296 | 296 | ) if c.args else "pass" |
297 | 297 |
|
298 | 298 | docstring_args = [] |
299 | 299 | docs = c.docs.split("|")[1:] if c.docs else None |
300 | 300 |
|
301 | 301 | for i, arg in enumerate(sorted_args): |
| 302 | + if arg == ("flags", "#"): |
| 303 | + continue |
| 304 | + |
302 | 305 | arg_name, arg_type = arg |
303 | 306 | is_optional = FLAGS_RE.match(arg_type) |
304 | 307 | flag_number = is_optional.group(1) if is_optional else -1 |
@@ -338,28 +341,31 @@ def start(): |
338 | 341 | if references: |
339 | 342 | docstring_args += "\n\n See Also:\n This object can be returned by " + references + "." |
340 | 343 |
|
341 | | - if c.has_flags: |
342 | | - write_flags = [] |
343 | | - for i in c.args: |
344 | | - flag = FLAGS_RE.match(i[1]) |
345 | | - if flag: |
346 | | - write_flags.append("flags |= (1 << {}) if self.{} is not None else 0".format(flag.group(1), i[0])) |
347 | | - |
348 | | - write_flags = "\n ".join([ |
349 | | - "flags = 0", |
350 | | - "\n ".join(write_flags), |
351 | | - "b.write(Int(flags))" |
352 | | - ]) |
353 | | - else: |
354 | | - write_flags = "# No flags" |
355 | | - |
356 | | - read_flags = "flags = Int.read(b)" if c.has_flags else "# No flags" |
357 | | - |
358 | | - write_types = read_types = "" |
| 344 | + write_types = read_types = "" if c.has_flags else "# No flags\n " |
359 | 345 |
|
360 | 346 | for arg_name, arg_type in c.args: |
361 | 347 | flag = FLAGS_RE_2.findall(arg_type) |
362 | 348 |
|
| 349 | + if arg_name == "flags" and arg_type == "#": |
| 350 | + write_flags = [] |
| 351 | + |
| 352 | + for i in c.args: |
| 353 | + flag = FLAGS_RE.match(i[1]) |
| 354 | + if flag: |
| 355 | + write_flags.append( |
| 356 | + "flags |= (1 << {}) if self.{} is not None else 0".format(flag.group(1), i[0])) |
| 357 | + |
| 358 | + write_flags = "\n ".join([ |
| 359 | + "flags = 0", |
| 360 | + "\n ".join(write_flags), |
| 361 | + "b.write(Int(flags))\n " |
| 362 | + ]) |
| 363 | + |
| 364 | + write_types += write_flags |
| 365 | + read_types += "flags = Int.read(b)\n " |
| 366 | + |
| 367 | + continue |
| 368 | + |
363 | 369 | if flag: |
364 | 370 | index, flag_type = flag[0] |
365 | 371 |
|
@@ -448,11 +454,9 @@ def start(): |
448 | 454 | object_id=c.id, |
449 | 455 | arguments=arguments, |
450 | 456 | fields=fields, |
451 | | - read_flags=read_flags, |
452 | 457 | read_types=read_types, |
453 | | - write_flags=write_flags, |
454 | 458 | write_types=write_types, |
455 | | - return_arguments=", ".join([i[0] for i in sorted_args]) |
| 459 | + return_arguments=", ".join([i[0] for i in sorted_args if i != ("flags", "#")]) |
456 | 460 | ) |
457 | 461 | ) |
458 | 462 |
|
|
0 commit comments