OILS / _devbuild / gen / hnode_asdl.py View on Github | oils.pub

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