OILS / _devbuild / gen / hnode_asdl.py View on Github | oilshell.org

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