| 1 | from asdl import pybase
 | 
| 2 | from mycpp import mops
 | 
| 3 | from typing import Optional, List, Tuple, Dict, Any, cast, TYPE_CHECKING
 | 
| 4 | 
 | 
| 5 | class color_t(pybase.SimpleObj):
 | 
| 6 |   pass
 | 
| 7 | 
 | 
| 8 | class color_e(object):
 | 
| 9 |   TypeName = color_t(1)
 | 
| 10 |   StringConst = color_t(2)
 | 
| 11 |   OtherConst = color_t(3)
 | 
| 12 |   UserType = color_t(4)
 | 
| 13 |   External = color_t(5)
 | 
| 14 | 
 | 
| 15 | _color_str = {
 | 
| 16 |   1: 'color.TypeName',
 | 
| 17 |   2: 'color.StringConst',
 | 
| 18 |   3: 'color.OtherConst',
 | 
| 19 |   4: 'color.UserType',
 | 
| 20 |   5: 'color.External',
 | 
| 21 | }
 | 
| 22 | 
 | 
| 23 | def color_str(val):
 | 
| 24 |   # type: (color_t) -> str
 | 
| 25 |   return _color_str[val]
 | 
| 26 | 
 | 
| 27 | class hnode_e(object):
 | 
| 28 |   AlreadySeen = 1
 | 
| 29 |   Record = 2
 | 
| 30 |   Array = 3
 | 
| 31 |   Leaf = 4
 | 
| 32 |   External = 5
 | 
| 33 | 
 | 
| 34 | _hnode_str = {
 | 
| 35 |   1: 'AlreadySeen',
 | 
| 36 |   2: 'Record',
 | 
| 37 |   3: 'Array',
 | 
| 38 |   4: 'Leaf',
 | 
| 39 |   5: 'External',
 | 
| 40 | }
 | 
| 41 | 
 | 
| 42 | def hnode_str(tag, dot=True):
 | 
| 43 |   # type: (int, bool) -> str
 | 
| 44 |   v = _hnode_str[tag]
 | 
| 45 |   if dot:
 | 
| 46 |     return "hnode.%s" % v
 | 
| 47 |   else:
 | 
| 48 |     return v
 | 
| 49 | 
 | 
| 50 | class hnode_t(pybase.CompoundObj):
 | 
| 51 |   def tag(self):
 | 
| 52 |     # type: () -> int
 | 
| 53 |     return self._type_tag
 | 
| 54 |   pass
 | 
| 55 | 
 | 
| 56 | class hnode(object):
 | 
| 57 |   class AlreadySeen(hnode_t):
 | 
| 58 |     _type_tag = 1
 | 
| 59 |     __slots__ = ('heap_id',)
 | 
| 60 |   
 | 
| 61 |     def __init__(self, heap_id):
 | 
| 62 |       # type: (int) -> None
 | 
| 63 |       self.heap_id = heap_id
 | 
| 64 |   
 | 
| 65 |   class Record(hnode_t):
 | 
| 66 |     _type_tag = 2
 | 
| 67 |     __slots__ = ('node_type', 'fields', 'abbrev', 'left', 'right',
 | 
| 68 |                  'unnamed_fields')
 | 
| 69 |   
 | 
| 70 |     def __init__(self, node_type, fields, abbrev, left, right, unnamed_fields):
 | 
| 71 |       # type: (str, List[Field], bool, str, str, List[hnode_t]) -> None
 | 
| 72 |       self.node_type = node_type
 | 
| 73 |       self.fields = fields
 | 
| 74 |       self.abbrev = abbrev
 | 
| 75 |       self.left = left
 | 
| 76 |       self.right = right
 | 
| 77 |       self.unnamed_fields = unnamed_fields
 | 
| 78 |   
 | 
| 79 |   class Array(hnode_t):
 | 
| 80 |     _type_tag = 3
 | 
| 81 |     __slots__ = ('children',)
 | 
| 82 |   
 | 
| 83 |     def __init__(self, children):
 | 
| 84 |       # type: (List[hnode_t]) -> None
 | 
| 85 |       self.children = children
 | 
| 86 |   
 | 
| 87 |   class Leaf(hnode_t):
 | 
| 88 |     _type_tag = 4
 | 
| 89 |     __slots__ = ('s', 'color')
 | 
| 90 |   
 | 
| 91 |     def __init__(self, s, color):
 | 
| 92 |       # type: (str, color_t) -> None
 | 
| 93 |       self.s = s
 | 
| 94 |       self.color = color
 | 
| 95 |   
 | 
| 96 |   class External(hnode_t):
 | 
| 97 |     _type_tag = 5
 | 
| 98 |     __slots__ = ('obj',)
 | 
| 99 |   
 | 
| 100 |     def __init__(self, obj):
 | 
| 101 |       # type: (Any) -> None
 | 
| 102 |       self.obj = obj
 | 
| 103 |   
 | 
| 104 |   pass
 | 
| 105 | 
 | 
| 106 | class alloc_members_t(pybase.SimpleObj):
 | 
| 107 |   pass
 | 
| 108 | 
 | 
| 109 | class alloc_members_e(object):
 | 
| 110 |   List = alloc_members_t(1)
 | 
| 111 |   Dict = alloc_members_t(2)
 | 
| 112 |   Struct = alloc_members_t(3)
 | 
| 113 | 
 | 
| 114 | _alloc_members_str = {
 | 
| 115 |   1: 'alloc_members.List',
 | 
| 116 |   2: 'alloc_members.Dict',
 | 
| 117 |   3: 'alloc_members.Struct',
 | 
| 118 | }
 | 
| 119 | 
 | 
| 120 | def alloc_members_str(val):
 | 
| 121 |   # type: (alloc_members_t) -> str
 | 
| 122 |   return _alloc_members_str[val]
 | 
| 123 | 
 | 
| 124 | class Field(pybase.CompoundObj):
 | 
| 125 |   _type_tag = 64
 | 
| 126 |   __slots__ = ('name', 'val')
 | 
| 127 | 
 | 
| 128 |   def __init__(self, name, val):
 | 
| 129 |     # type: (str, hnode_t) -> None
 | 
| 130 |     self.name = name
 | 
| 131 |     self.val = val
 | 
| 132 | 
 |