jaclang 0.0.1__py3-none-any.whl → 0.0.3__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of jaclang might be problematic. Click here for more details.
- jaclang/__init__.py +4 -0
- jaclang/cli/__init__.py +7 -0
- jaclang/cli/cli.jac +46 -0
- jaclang/cli/cmds.jac +14 -0
- jaclang/cli/impl/__init__.py +1 -0
- jaclang/cli/impl/cli_impl.jac +93 -0
- jaclang/cli/impl/cmds_impl.jac +26 -0
- jaclang/core/__init__.py +12 -0
- jaclang/core/impl/__init__.py +1 -0
- jaclang/core/impl/arch_impl.jac +112 -0
- jaclang/core/impl/element_impl.jac +95 -0
- jaclang/core/impl/exec_ctx_impl.jac +17 -0
- jaclang/core/impl/memory_impl.jac +57 -0
- jaclang/core/primitives.jac +104 -0
- jaclang/jac/__init__.py +1 -0
- jaclang/jac/absyntree.py +1787 -0
- jaclang/jac/constant.py +46 -0
- jaclang/jac/importer.py +130 -0
- jaclang/jac/lexer.py +538 -0
- jaclang/jac/parser.py +1474 -0
- jaclang/jac/passes/__init__.py +5 -0
- jaclang/jac/passes/blue/__init__.py +25 -0
- jaclang/jac/passes/blue/ast_build_pass.py +3190 -0
- jaclang/jac/passes/blue/blue_pygen_pass.py +1335 -0
- jaclang/jac/passes/blue/decl_def_match_pass.py +278 -0
- jaclang/jac/passes/blue/import_pass.py +75 -0
- jaclang/jac/passes/blue/sub_node_tab_pass.py +30 -0
- jaclang/jac/passes/blue/tests/__init__.py +1 -0
- jaclang/jac/passes/blue/tests/test_ast_build_pass.py +61 -0
- jaclang/jac/passes/blue/tests/test_blue_pygen_pass.py +117 -0
- jaclang/jac/passes/blue/tests/test_decl_def_match_pass.py +43 -0
- jaclang/jac/passes/blue/tests/test_import_pass.py +18 -0
- jaclang/jac/passes/blue/tests/test_sub_node_pass.py +26 -0
- jaclang/jac/passes/blue/tests/test_type_analyze_pass.py +53 -0
- jaclang/jac/passes/blue/type_analyze_pass.py +731 -0
- jaclang/jac/passes/ir_pass.py +154 -0
- jaclang/jac/passes/purple/__init__.py +17 -0
- jaclang/jac/passes/purple/impl/__init__.py +1 -0
- jaclang/jac/passes/purple/impl/purple_pygen_pass_impl.jac +289 -0
- jaclang/jac/passes/purple/purple_pygen_pass.jac +35 -0
- jaclang/jac/sym_table.py +127 -0
- jaclang/jac/tests/__init__.py +1 -0
- jaclang/jac/tests/fixtures/__init__.py +1 -0
- jaclang/jac/tests/fixtures/activity.py +10 -0
- jaclang/jac/tests/fixtures/fam.jac +68 -0
- jaclang/jac/tests/fixtures/hello_world.jac +5 -0
- jaclang/jac/tests/fixtures/lexer_fam.jac +61 -0
- jaclang/jac/tests/fixtures/stuff.jac +6 -0
- jaclang/jac/tests/test_importer.py +24 -0
- jaclang/jac/tests/test_lexer.py +57 -0
- jaclang/jac/tests/test_parser.py +50 -0
- jaclang/jac/tests/test_utils.py +12 -0
- jaclang/jac/transform.py +63 -0
- jaclang/jac/transpiler.py +69 -0
- jaclang/jac/utils.py +120 -0
- jaclang/utils/__init__.py +1 -0
- jaclang/utils/fstring_parser.py +73 -0
- jaclang/utils/log.py +9 -0
- jaclang/utils/sly/__init__.py +6 -0
- jaclang/utils/sly/docparse.py +62 -0
- jaclang/utils/sly/lex.py +510 -0
- jaclang/utils/sly/yacc.py +2398 -0
- jaclang/utils/test.py +81 -0
- jaclang/utils/tests/__init__.py +1 -0
- jaclang/utils/tests/test_fstring_parser.py +55 -0
- jaclang-0.0.3.dist-info/METADATA +12 -0
- jaclang-0.0.3.dist-info/RECORD +70 -0
- {jaclang-0.0.1.dist-info → jaclang-0.0.3.dist-info}/WHEEL +1 -1
- jaclang-0.0.3.dist-info/entry_points.txt +3 -0
- jaclang-0.0.3.dist-info/top_level.txt +1 -0
- jaclang-0.0.1.dist-info/METADATA +0 -7
- jaclang-0.0.1.dist-info/RECORD +0 -4
- jaclang-0.0.1.dist-info/top_level.txt +0 -1
|
@@ -0,0 +1,731 @@
|
|
|
1
|
+
"""Type Analyze Pass."""
|
|
2
|
+
from types import ModuleType
|
|
3
|
+
from typing import Any
|
|
4
|
+
|
|
5
|
+
import jaclang.jac.absyntree as ast
|
|
6
|
+
from jaclang.jac.passes import Pass
|
|
7
|
+
from jaclang.jac.sym_table import SymbolTable, TypedSymbol
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
class TypeAnalyzePass(Pass, SymbolTable):
|
|
11
|
+
"""Type inference and checking pass."""
|
|
12
|
+
|
|
13
|
+
def before_pass(self) -> None:
|
|
14
|
+
"""Initialize pass."""
|
|
15
|
+
self.sym_tab = SymbolTable(scope_name="global")
|
|
16
|
+
|
|
17
|
+
def exit_parse(self, node: ast.Parse) -> None:
|
|
18
|
+
"""Sub objects.
|
|
19
|
+
|
|
20
|
+
name: str,
|
|
21
|
+
"""
|
|
22
|
+
|
|
23
|
+
def exit_token(self, node: ast.Token) -> None:
|
|
24
|
+
"""Sub objects.
|
|
25
|
+
|
|
26
|
+
name: str,
|
|
27
|
+
value: str,
|
|
28
|
+
col_start: int,
|
|
29
|
+
col_end: int,
|
|
30
|
+
"""
|
|
31
|
+
|
|
32
|
+
def exit_name(self, node: ast.Name) -> None:
|
|
33
|
+
"""Sub objects.
|
|
34
|
+
|
|
35
|
+
name: str,
|
|
36
|
+
value: str,
|
|
37
|
+
col_start: int,
|
|
38
|
+
col_end: int,
|
|
39
|
+
already_declared: bool,
|
|
40
|
+
"""
|
|
41
|
+
|
|
42
|
+
def exit_constant(self, node: ast.Constant) -> None:
|
|
43
|
+
"""Sub objects.
|
|
44
|
+
|
|
45
|
+
name: str,
|
|
46
|
+
value: str,
|
|
47
|
+
col_start: int,
|
|
48
|
+
col_end: int,
|
|
49
|
+
typ: type,
|
|
50
|
+
"""
|
|
51
|
+
|
|
52
|
+
def exit_module(self, node: ast.Module) -> None:
|
|
53
|
+
"""Sub objects.
|
|
54
|
+
|
|
55
|
+
name: str,
|
|
56
|
+
doc: Token,
|
|
57
|
+
body: Elements,
|
|
58
|
+
mod_path: str,
|
|
59
|
+
"""
|
|
60
|
+
|
|
61
|
+
def exit_elements(self, node: ast.Elements) -> None:
|
|
62
|
+
"""Sub objects.
|
|
63
|
+
|
|
64
|
+
elements: list['GlobalVars | Test | ModuleCode | Import | Architype | Ability | AbilitySpec'],
|
|
65
|
+
"""
|
|
66
|
+
|
|
67
|
+
def exit_global_vars(self, node: ast.GlobalVars) -> None:
|
|
68
|
+
"""Sub objects.
|
|
69
|
+
|
|
70
|
+
doc: Optional[DocString],
|
|
71
|
+
access: Optional[Token],
|
|
72
|
+
assignments: AssignmentList,
|
|
73
|
+
"""
|
|
74
|
+
if node.access:
|
|
75
|
+
for i in self.get_all_sub_nodes(node, typ=ast.Assignment):
|
|
76
|
+
if isinstance(i.target, ast.Name) and not self.sym_tab.update(
|
|
77
|
+
TypedSymbol(
|
|
78
|
+
name=i.target.value,
|
|
79
|
+
access=node.access.value,
|
|
80
|
+
node=i,
|
|
81
|
+
typ=i._typ,
|
|
82
|
+
)
|
|
83
|
+
):
|
|
84
|
+
self.ice(
|
|
85
|
+
f"ICE: Variable {i.target.value} not seen as declared in pass {self.__class__.__name__}"
|
|
86
|
+
)
|
|
87
|
+
|
|
88
|
+
def exit_test(self, node: ast.Test) -> None:
|
|
89
|
+
"""Sub objects.
|
|
90
|
+
|
|
91
|
+
name: Name,
|
|
92
|
+
doc: Optional[DocString],
|
|
93
|
+
description: Token,
|
|
94
|
+
body: CodeBlock,
|
|
95
|
+
"""
|
|
96
|
+
|
|
97
|
+
def exit_module_code(self, node: ast.ModuleCode) -> None:
|
|
98
|
+
"""Sub objects.
|
|
99
|
+
|
|
100
|
+
doc: Optional[DocString],
|
|
101
|
+
body: CodeBlock,
|
|
102
|
+
"""
|
|
103
|
+
|
|
104
|
+
def exit_import(self, node: ast.Import) -> None:
|
|
105
|
+
"""Sub objects.
|
|
106
|
+
|
|
107
|
+
lang: Name,
|
|
108
|
+
path: ModulePath,
|
|
109
|
+
alias: Optional[Name],
|
|
110
|
+
items: Optional[ModuleItems],
|
|
111
|
+
is_absorb: bool,
|
|
112
|
+
self.sub_module = None
|
|
113
|
+
"""
|
|
114
|
+
if node.lang.value == "jac" and not node.sub_module:
|
|
115
|
+
self.ice(f"Jac module not loaded by pass {self.__class__.__name__}")
|
|
116
|
+
if node.items:
|
|
117
|
+
for i in node.items.items:
|
|
118
|
+
if i.alias:
|
|
119
|
+
self.sym_tab.set(
|
|
120
|
+
TypedSymbol(
|
|
121
|
+
name=i.alias.value,
|
|
122
|
+
typ=Any, # TODO: Backpatch analysis for module itmes
|
|
123
|
+
node=node,
|
|
124
|
+
),
|
|
125
|
+
fresh_only=True,
|
|
126
|
+
)
|
|
127
|
+
else:
|
|
128
|
+
self.sym_tab.set(
|
|
129
|
+
TypedSymbol(
|
|
130
|
+
name=i.name.value,
|
|
131
|
+
typ=Any, # TODO: Backpatch analysis for module itmes
|
|
132
|
+
node=node,
|
|
133
|
+
),
|
|
134
|
+
fresh_only=True,
|
|
135
|
+
)
|
|
136
|
+
else:
|
|
137
|
+
self.sym_tab.set(
|
|
138
|
+
TypedSymbol(
|
|
139
|
+
name=node.path.path[-1].value,
|
|
140
|
+
typ=ModuleType,
|
|
141
|
+
node=node,
|
|
142
|
+
),
|
|
143
|
+
fresh_only=True,
|
|
144
|
+
)
|
|
145
|
+
|
|
146
|
+
def exit_module_path(self, node: ast.ModulePath) -> None:
|
|
147
|
+
"""Sub objects.
|
|
148
|
+
|
|
149
|
+
path: list[Token],
|
|
150
|
+
"""
|
|
151
|
+
|
|
152
|
+
def exit_module_item(self, node: ast.ModuleItem) -> None:
|
|
153
|
+
"""Sub objects.
|
|
154
|
+
|
|
155
|
+
name: Name,
|
|
156
|
+
alias: Optional[Token],
|
|
157
|
+
self.body: Optional[AstNode] = None
|
|
158
|
+
"""
|
|
159
|
+
|
|
160
|
+
def exit_module_items(self, node: ast.ModuleItems) -> None:
|
|
161
|
+
"""Sub objects.
|
|
162
|
+
|
|
163
|
+
items: list['ModuleItem'],
|
|
164
|
+
"""
|
|
165
|
+
|
|
166
|
+
def exit_architype(self, node: ast.Architype) -> None:
|
|
167
|
+
"""Sub objects.
|
|
168
|
+
|
|
169
|
+
name: Name,
|
|
170
|
+
arch_type: Token,
|
|
171
|
+
doc: Optional[DocString],
|
|
172
|
+
decorators: Optional[Decorators],
|
|
173
|
+
access: Optional[Token],
|
|
174
|
+
base_classes: BaseClasses,
|
|
175
|
+
body: Optional[ArchBlock],
|
|
176
|
+
"""
|
|
177
|
+
node._typ = type
|
|
178
|
+
exists = self.sym_tab.lookup(name=node.name.value, deep=False)
|
|
179
|
+
# TODO: if exists and type(exists.def_node) == ast.ArchDef and not node.body: # This should be own pass
|
|
180
|
+
# node.body = exists.def_node.body
|
|
181
|
+
if exists and not self.assert_type_match(sym=exists, node=node):
|
|
182
|
+
return
|
|
183
|
+
self.sym_tab.set(
|
|
184
|
+
TypedSymbol(
|
|
185
|
+
name=node.name.value,
|
|
186
|
+
typ=type,
|
|
187
|
+
node=node,
|
|
188
|
+
access=node.access.value if node.access else None,
|
|
189
|
+
),
|
|
190
|
+
)
|
|
191
|
+
|
|
192
|
+
def exit_arch_def(self, node: ast.ArchDef) -> None:
|
|
193
|
+
"""Sub objects.
|
|
194
|
+
|
|
195
|
+
doc: Optional[DocString],
|
|
196
|
+
mod: Optional[NameList],
|
|
197
|
+
arch: ObjectRef | NodeRef | EdgeRef | WalkerRef,
|
|
198
|
+
body: ArchBlock,
|
|
199
|
+
"""
|
|
200
|
+
|
|
201
|
+
def exit_decorators(self, node: ast.Decorators) -> None:
|
|
202
|
+
"""Sub objects.
|
|
203
|
+
|
|
204
|
+
calls: list['ExprType'],
|
|
205
|
+
"""
|
|
206
|
+
|
|
207
|
+
def exit_base_classes(self, node: ast.BaseClasses) -> None:
|
|
208
|
+
"""Sub objects.
|
|
209
|
+
|
|
210
|
+
base_classes: list['NameList'],
|
|
211
|
+
"""
|
|
212
|
+
|
|
213
|
+
def exit_ability(self, node: ast.Ability) -> None:
|
|
214
|
+
"""Sub objects.
|
|
215
|
+
|
|
216
|
+
name: Name,
|
|
217
|
+
is_func: bool,
|
|
218
|
+
doc: Optional[DocString],
|
|
219
|
+
decorators: Optional[Decorators],
|
|
220
|
+
access: Optional[Token],
|
|
221
|
+
signature: FuncSignature | TypeSpec | EventSignature,
|
|
222
|
+
body: CodeBlock,
|
|
223
|
+
"""
|
|
224
|
+
|
|
225
|
+
def exit_ability_def(self, node: ast.AbilityDef) -> None:
|
|
226
|
+
"""Sub objects.
|
|
227
|
+
|
|
228
|
+
doc: Optional[DocString],
|
|
229
|
+
mod: Optional[NameList],
|
|
230
|
+
ability: AbilityRef,
|
|
231
|
+
body: CodeBlock,
|
|
232
|
+
"""
|
|
233
|
+
|
|
234
|
+
def exit_arch_block(self, node: ast.ArchBlock) -> None:
|
|
235
|
+
"""Sub objects.
|
|
236
|
+
|
|
237
|
+
members: list['ArchHas | Ability'],
|
|
238
|
+
"""
|
|
239
|
+
|
|
240
|
+
def exit_arch_has(self, node: ast.ArchHas) -> None:
|
|
241
|
+
"""Sub objects.
|
|
242
|
+
|
|
243
|
+
doc: Optional[DocString],
|
|
244
|
+
access: Optional[Token],
|
|
245
|
+
vars: HasVarList,
|
|
246
|
+
"""
|
|
247
|
+
|
|
248
|
+
def exit_has_var(self, node: ast.HasVar) -> None:
|
|
249
|
+
"""Sub objects.
|
|
250
|
+
|
|
251
|
+
name: Name,
|
|
252
|
+
type_tag: TypeSpec,
|
|
253
|
+
value: Optional[ExprType],
|
|
254
|
+
"""
|
|
255
|
+
|
|
256
|
+
def exit_has_var_list(self, node: ast.HasVarList) -> None:
|
|
257
|
+
"""Sub objects.
|
|
258
|
+
|
|
259
|
+
vars: list['HasVar'],
|
|
260
|
+
"""
|
|
261
|
+
|
|
262
|
+
def exit_type_spec_list(self, node: ast.TypeSpecList) -> None:
|
|
263
|
+
"""Sub objects.
|
|
264
|
+
|
|
265
|
+
types: list[TypeSpec],
|
|
266
|
+
"""
|
|
267
|
+
|
|
268
|
+
def exit_type_spec(self, node: ast.TypeSpec) -> None:
|
|
269
|
+
"""Sub objects.
|
|
270
|
+
|
|
271
|
+
typ: Token | NameList,
|
|
272
|
+
list_nest: TypeSpec,
|
|
273
|
+
dict_nest: TypeSpec,
|
|
274
|
+
"""
|
|
275
|
+
|
|
276
|
+
def exit_event_signature(self, node: ast.EventSignature) -> None:
|
|
277
|
+
"""Sub objects.
|
|
278
|
+
|
|
279
|
+
event: Token,
|
|
280
|
+
arch_tag_info: Optional[NameList | Token],
|
|
281
|
+
"""
|
|
282
|
+
|
|
283
|
+
def exit_name_list(self, node: ast.NameList) -> None:
|
|
284
|
+
"""Sub objects.
|
|
285
|
+
|
|
286
|
+
names: list[Token],
|
|
287
|
+
dotted: bool,
|
|
288
|
+
"""
|
|
289
|
+
|
|
290
|
+
def exit_func_signature(self, node: ast.FuncSignature) -> None:
|
|
291
|
+
"""Sub objects.
|
|
292
|
+
|
|
293
|
+
params: Optional[FuncParams],
|
|
294
|
+
return_type: Optional[TypeSpec],
|
|
295
|
+
"""
|
|
296
|
+
|
|
297
|
+
def exit_func_params(self, node: ast.FuncParams) -> None:
|
|
298
|
+
"""Sub objects.
|
|
299
|
+
|
|
300
|
+
params: list['ParamVar'],
|
|
301
|
+
"""
|
|
302
|
+
|
|
303
|
+
def exit_param_var(self, node: ast.ParamVar) -> None:
|
|
304
|
+
"""Sub objects.
|
|
305
|
+
|
|
306
|
+
name: Name,
|
|
307
|
+
unpack: Optional[Token],
|
|
308
|
+
type_tag: TypeSpec,
|
|
309
|
+
value: Optional[ExprType],
|
|
310
|
+
"""
|
|
311
|
+
|
|
312
|
+
def exit_enum(self, node: ast.Enum) -> None:
|
|
313
|
+
"""Sub objects.
|
|
314
|
+
|
|
315
|
+
name: Name,
|
|
316
|
+
doc: Optional[DocString],
|
|
317
|
+
decorators: Optional[Decorators],
|
|
318
|
+
access: Optional[Token],
|
|
319
|
+
base_classes: BaseClasses,
|
|
320
|
+
body: Optional[EnumBlock],
|
|
321
|
+
"""
|
|
322
|
+
|
|
323
|
+
def exit_enum_def(self, node: ast.EnumDef) -> None:
|
|
324
|
+
"""Sub objects.
|
|
325
|
+
|
|
326
|
+
doc: Optional[DocString],
|
|
327
|
+
mod: Optional[NameList],
|
|
328
|
+
body: EnumBlock,
|
|
329
|
+
"""
|
|
330
|
+
|
|
331
|
+
def exit_enum_block(self, node: ast.EnumBlock) -> None:
|
|
332
|
+
"""Sub objects.
|
|
333
|
+
|
|
334
|
+
stmts: list['Name|Assignment'],
|
|
335
|
+
"""
|
|
336
|
+
|
|
337
|
+
def exit_code_block(self, node: ast.CodeBlock) -> None:
|
|
338
|
+
"""Sub objects.
|
|
339
|
+
|
|
340
|
+
stmts: list['StmtType'],
|
|
341
|
+
"""
|
|
342
|
+
|
|
343
|
+
def exit_typed_ctx_block(self, node: ast.TypedCtxBlock) -> None:
|
|
344
|
+
"""Sub objects.
|
|
345
|
+
|
|
346
|
+
type_ctx: TypeList,
|
|
347
|
+
body: CodeBlock,
|
|
348
|
+
"""
|
|
349
|
+
|
|
350
|
+
def exit_if_stmt(self, node: ast.IfStmt) -> None:
|
|
351
|
+
"""Sub objects.
|
|
352
|
+
|
|
353
|
+
condition: ExprType,
|
|
354
|
+
body: CodeBlock,
|
|
355
|
+
elseifs: Optional[ElseIfs],
|
|
356
|
+
else_body: Optional[ElseStmt],
|
|
357
|
+
"""
|
|
358
|
+
|
|
359
|
+
def exit_else_ifs(self, node: ast.ElseIfs) -> None:
|
|
360
|
+
"""Sub objects.
|
|
361
|
+
|
|
362
|
+
elseifs: list['IfStmt'],
|
|
363
|
+
"""
|
|
364
|
+
|
|
365
|
+
def exit_else_stmt(self, node: ast.ElseStmt) -> None:
|
|
366
|
+
"""Sub objects.
|
|
367
|
+
|
|
368
|
+
body: CodeBlock,
|
|
369
|
+
"""
|
|
370
|
+
|
|
371
|
+
def exit_try_stmt(self, node: ast.TryStmt) -> None:
|
|
372
|
+
"""Sub objects.
|
|
373
|
+
|
|
374
|
+
body: CodeBlock,
|
|
375
|
+
excepts: Optional[ExceptList],
|
|
376
|
+
finally_body: Optional[FinallyStmt],
|
|
377
|
+
"""
|
|
378
|
+
|
|
379
|
+
def exit_except(self, node: ast.Except) -> None:
|
|
380
|
+
"""Sub objects.
|
|
381
|
+
|
|
382
|
+
typ: ExprType,
|
|
383
|
+
name: Optional[Token],
|
|
384
|
+
body: CodeBlock,
|
|
385
|
+
"""
|
|
386
|
+
|
|
387
|
+
def exit_except_list(self, node: ast.ExceptList) -> None:
|
|
388
|
+
"""Sub objects.
|
|
389
|
+
|
|
390
|
+
excepts: list['Except'],
|
|
391
|
+
"""
|
|
392
|
+
|
|
393
|
+
def exit_finally_stmt(self, node: ast.FinallyStmt) -> None:
|
|
394
|
+
"""Sub objects.
|
|
395
|
+
|
|
396
|
+
body: CodeBlock,
|
|
397
|
+
"""
|
|
398
|
+
|
|
399
|
+
def exit_iter_for_stmt(self, node: ast.IterForStmt) -> None:
|
|
400
|
+
"""Sub objects.
|
|
401
|
+
|
|
402
|
+
iter: Assignment,
|
|
403
|
+
condition: ExprType,
|
|
404
|
+
count_by: ExprType,
|
|
405
|
+
body: CodeBlock,
|
|
406
|
+
"""
|
|
407
|
+
|
|
408
|
+
def exit_in_for_stmt(self, node: ast.InForStmt) -> None:
|
|
409
|
+
"""Sub objects.
|
|
410
|
+
|
|
411
|
+
name: Name,
|
|
412
|
+
collection: ExprType,
|
|
413
|
+
body: CodeBlock,
|
|
414
|
+
"""
|
|
415
|
+
|
|
416
|
+
def exit_dict_for_stmt(self, node: ast.DictForStmt) -> None:
|
|
417
|
+
"""Sub objects.
|
|
418
|
+
|
|
419
|
+
k_name: Name,
|
|
420
|
+
v_name: Name,
|
|
421
|
+
collection: ExprType,
|
|
422
|
+
body: CodeBlock,
|
|
423
|
+
"""
|
|
424
|
+
|
|
425
|
+
def exit_while_stmt(self, node: ast.WhileStmt) -> None:
|
|
426
|
+
"""Sub objects.
|
|
427
|
+
|
|
428
|
+
condition: ExprType,
|
|
429
|
+
body: CodeBlock,
|
|
430
|
+
"""
|
|
431
|
+
|
|
432
|
+
def exit_with_stmt(self, node: ast.WithStmt) -> None:
|
|
433
|
+
"""Sub objects.
|
|
434
|
+
|
|
435
|
+
exprs: "ExprAsItemList",
|
|
436
|
+
body: "CodeBlock",
|
|
437
|
+
"""
|
|
438
|
+
|
|
439
|
+
def exit_expr_as_item_list(self, node: ast.ExprAsItemList) -> None:
|
|
440
|
+
"""Sub objects.
|
|
441
|
+
|
|
442
|
+
items: list["ExprAsItem"],
|
|
443
|
+
"""
|
|
444
|
+
|
|
445
|
+
def exit_expr_as_item(self, node: ast.ExprAsItem) -> None:
|
|
446
|
+
"""Sub objects.
|
|
447
|
+
|
|
448
|
+
expr: "ExprType",
|
|
449
|
+
alias: Optional[Token],
|
|
450
|
+
"""
|
|
451
|
+
|
|
452
|
+
def exit_raise_stmt(self, node: ast.RaiseStmt) -> None:
|
|
453
|
+
"""Sub objects.
|
|
454
|
+
|
|
455
|
+
cause: Optional[ExprType],
|
|
456
|
+
"""
|
|
457
|
+
|
|
458
|
+
def exit_assert_stmt(self, node: ast.AssertStmt) -> None:
|
|
459
|
+
"""Sub objects.
|
|
460
|
+
|
|
461
|
+
condition: ExprType,
|
|
462
|
+
error_msg: Optional[ExprType],
|
|
463
|
+
"""
|
|
464
|
+
|
|
465
|
+
def exit_ctrl_stmt(self, node: ast.CtrlStmt) -> None:
|
|
466
|
+
"""Sub objects.
|
|
467
|
+
|
|
468
|
+
ctrl: Token,
|
|
469
|
+
"""
|
|
470
|
+
|
|
471
|
+
def exit_delete_stmt(self, node: ast.DeleteStmt) -> None:
|
|
472
|
+
"""Sub objects.
|
|
473
|
+
|
|
474
|
+
target: ExprType,
|
|
475
|
+
"""
|
|
476
|
+
|
|
477
|
+
def exit_report_stmt(self, node: ast.ReportStmt) -> None:
|
|
478
|
+
"""Sub objects.
|
|
479
|
+
|
|
480
|
+
expr: ExprType,
|
|
481
|
+
"""
|
|
482
|
+
|
|
483
|
+
def exit_return_stmt(self, node: ast.ReturnStmt) -> None:
|
|
484
|
+
"""Sub objects.
|
|
485
|
+
|
|
486
|
+
expr: Optional[ExprType],
|
|
487
|
+
"""
|
|
488
|
+
|
|
489
|
+
def exit_yield_stmt(self, node: ast.YieldStmt) -> None:
|
|
490
|
+
"""Sub objects.
|
|
491
|
+
|
|
492
|
+
expr: Optional[ExprType],
|
|
493
|
+
"""
|
|
494
|
+
|
|
495
|
+
def exit_ignore_stmt(self, node: ast.IgnoreStmt) -> None:
|
|
496
|
+
"""Sub objects.
|
|
497
|
+
|
|
498
|
+
target: ExprType,
|
|
499
|
+
"""
|
|
500
|
+
|
|
501
|
+
def exit_visit_stmt(self, node: ast.VisitStmt) -> None:
|
|
502
|
+
"""Sub objects.
|
|
503
|
+
|
|
504
|
+
typ: Optional[Token],
|
|
505
|
+
target: Optional[ExprType],
|
|
506
|
+
else_body: Optional[ElseStmt],
|
|
507
|
+
"""
|
|
508
|
+
|
|
509
|
+
def exit_revisit_stmt(self, node: ast.RevisitStmt) -> None:
|
|
510
|
+
"""Sub objects.
|
|
511
|
+
|
|
512
|
+
hops: Optional[ExprType],
|
|
513
|
+
else_body: Optional[ElseStmt],
|
|
514
|
+
"""
|
|
515
|
+
|
|
516
|
+
def exit_disengage_stmt(self, node: ast.DisengageStmt) -> None:
|
|
517
|
+
"""Sub objects."""
|
|
518
|
+
|
|
519
|
+
def exit_await_stmt(self, node: ast.AwaitStmt) -> None:
|
|
520
|
+
"""Sub objects.
|
|
521
|
+
|
|
522
|
+
target: ExprType,
|
|
523
|
+
"""
|
|
524
|
+
|
|
525
|
+
def exit_assignment(self, node: ast.Assignment) -> None:
|
|
526
|
+
"""Sub objects.
|
|
527
|
+
|
|
528
|
+
is_static: bool,
|
|
529
|
+
target: AtomType,
|
|
530
|
+
value: ExprType,
|
|
531
|
+
"""
|
|
532
|
+
|
|
533
|
+
def exit_binary_expr(self, node: ast.BinaryExpr) -> None:
|
|
534
|
+
"""Sub objects.
|
|
535
|
+
|
|
536
|
+
left: ExprType,
|
|
537
|
+
right: ExprType,
|
|
538
|
+
op: Token,
|
|
539
|
+
"""
|
|
540
|
+
|
|
541
|
+
def exit_if_else_expr(self, node: ast.IfElseExpr) -> None:
|
|
542
|
+
"""Sub objects.
|
|
543
|
+
|
|
544
|
+
condition: BinaryExpr | IfElseExpr,
|
|
545
|
+
value: ExprType,
|
|
546
|
+
else_value: ExprType,
|
|
547
|
+
"""
|
|
548
|
+
|
|
549
|
+
def exit_unary_expr(self, node: ast.UnaryExpr) -> None:
|
|
550
|
+
"""Sub objects.
|
|
551
|
+
|
|
552
|
+
operand: ExprType,
|
|
553
|
+
op: Token,
|
|
554
|
+
"""
|
|
555
|
+
|
|
556
|
+
def exit_unpack_expr(self, node: ast.UnpackExpr) -> None:
|
|
557
|
+
"""Sub objects.
|
|
558
|
+
|
|
559
|
+
target: ExprType,
|
|
560
|
+
is_dict: bool,
|
|
561
|
+
"""
|
|
562
|
+
|
|
563
|
+
def exit_multi_string(self, node: ast.MultiString) -> None:
|
|
564
|
+
"""Sub objects.
|
|
565
|
+
|
|
566
|
+
strings: list['Token | FString'],
|
|
567
|
+
"""
|
|
568
|
+
|
|
569
|
+
def exit_list_val(self, node: ast.ListVal) -> None:
|
|
570
|
+
"""Sub objects.
|
|
571
|
+
|
|
572
|
+
values: list['ExprType'],
|
|
573
|
+
"""
|
|
574
|
+
|
|
575
|
+
def exit_set_val(self, node: ast.ListVal) -> None:
|
|
576
|
+
"""Sub objects.
|
|
577
|
+
|
|
578
|
+
values: list[ExprType],
|
|
579
|
+
"""
|
|
580
|
+
|
|
581
|
+
def exit_tuple_val(self, node: ast.TupleVal) -> None:
|
|
582
|
+
"""Sub objects.
|
|
583
|
+
|
|
584
|
+
first_expr: Optional["ExprType"],
|
|
585
|
+
exprs: Optional[ExprList],
|
|
586
|
+
assigns: Optional[AssignmentList],
|
|
587
|
+
"""
|
|
588
|
+
|
|
589
|
+
def exit_expr_list(self, node: ast.ExprList) -> None:
|
|
590
|
+
"""Sub objects.
|
|
591
|
+
|
|
592
|
+
values: list['ExprType'],
|
|
593
|
+
"""
|
|
594
|
+
|
|
595
|
+
def exit_dict_val(self, node: ast.DictVal) -> None:
|
|
596
|
+
"""Sub objects.
|
|
597
|
+
|
|
598
|
+
kv_pairs: list['KVPair'],
|
|
599
|
+
"""
|
|
600
|
+
|
|
601
|
+
def exit_inner_compr(self, node: ast.InnerCompr) -> None:
|
|
602
|
+
"""Sub objects.
|
|
603
|
+
|
|
604
|
+
out_expr: "ExprType",
|
|
605
|
+
name: Name,
|
|
606
|
+
collection: "ExprType",
|
|
607
|
+
conditional: Optional["ExprType"],
|
|
608
|
+
is_list: bool,
|
|
609
|
+
is_gen: bool,
|
|
610
|
+
is_set: bool,
|
|
611
|
+
"""
|
|
612
|
+
|
|
613
|
+
def exit_dict_compr(self, node: ast.DictCompr) -> None:
|
|
614
|
+
"""Sub objects.
|
|
615
|
+
|
|
616
|
+
outk_expr: ExprType,
|
|
617
|
+
outv_expr: ExprType,
|
|
618
|
+
k_name: Name,
|
|
619
|
+
v_name: Optional[Token],
|
|
620
|
+
collection: ExprType,
|
|
621
|
+
conditional: Optional[ExprType],
|
|
622
|
+
"""
|
|
623
|
+
|
|
624
|
+
def exit_k_v_pair(self, node: ast.KVPair) -> None:
|
|
625
|
+
"""Sub objects.
|
|
626
|
+
|
|
627
|
+
key: ExprType,
|
|
628
|
+
value: ExprType,
|
|
629
|
+
"""
|
|
630
|
+
|
|
631
|
+
def exit_atom_trailer(self, node: ast.AtomTrailer) -> None:
|
|
632
|
+
"""Sub objects.
|
|
633
|
+
|
|
634
|
+
target: AtomType,
|
|
635
|
+
right: IndexSlice | ArchRefType | Token,
|
|
636
|
+
null_ok: bool,
|
|
637
|
+
"""
|
|
638
|
+
|
|
639
|
+
def exit_func_call(self, node: ast.FuncCall) -> None:
|
|
640
|
+
"""Sub objects.
|
|
641
|
+
|
|
642
|
+
target: AtomType,
|
|
643
|
+
params: Optional[ParamList],
|
|
644
|
+
"""
|
|
645
|
+
|
|
646
|
+
def exit_param_list(self, node: ast.ParamList) -> None:
|
|
647
|
+
"""Sub objects.
|
|
648
|
+
|
|
649
|
+
p_args: Optional[ExprList],
|
|
650
|
+
p_kwargs: Optional[AssignmentList],
|
|
651
|
+
"""
|
|
652
|
+
|
|
653
|
+
def exit_assignment_list(self, node: ast.AssignmentList) -> None:
|
|
654
|
+
"""Sub objects.
|
|
655
|
+
|
|
656
|
+
values: list['ExprType'],
|
|
657
|
+
"""
|
|
658
|
+
|
|
659
|
+
def exit_index_slice(self, node: ast.IndexSlice) -> None:
|
|
660
|
+
"""Sub objects.
|
|
661
|
+
|
|
662
|
+
start: ExprType,
|
|
663
|
+
stop: Optional[ExprType],
|
|
664
|
+
"""
|
|
665
|
+
|
|
666
|
+
def exit_arch_ref(self, node: ast.ArchRef) -> None:
|
|
667
|
+
"""Sub objects.
|
|
668
|
+
|
|
669
|
+
name: Name,
|
|
670
|
+
"""
|
|
671
|
+
|
|
672
|
+
def exit_special_var_ref(self, node: ast.SpecialVarRef) -> None:
|
|
673
|
+
"""Sub objects.
|
|
674
|
+
|
|
675
|
+
name: Optional[Token],
|
|
676
|
+
"""
|
|
677
|
+
|
|
678
|
+
def exit_edge_op_ref(self, node: ast.EdgeOpRef) -> None:
|
|
679
|
+
"""Sub objects.
|
|
680
|
+
|
|
681
|
+
filter_cond: Optional[ExprType],
|
|
682
|
+
edge_dir: EdgeDir,
|
|
683
|
+
"""
|
|
684
|
+
|
|
685
|
+
def exit_disconnect_op(self, node: ast.DisconnectOp) -> None:
|
|
686
|
+
"""Sub objects.
|
|
687
|
+
|
|
688
|
+
filter_cond: Optional[ExprType],
|
|
689
|
+
edge_dir: EdgeDir,
|
|
690
|
+
"""
|
|
691
|
+
|
|
692
|
+
def exit_connect_op(self, node: ast.ConnectOp) -> None:
|
|
693
|
+
"""Sub objects.
|
|
694
|
+
|
|
695
|
+
spawn: Optional[ExprType],
|
|
696
|
+
edge_dir: EdgeDir,
|
|
697
|
+
"""
|
|
698
|
+
|
|
699
|
+
def exit_filter_compr(self, node: ast.FilterCompr) -> None:
|
|
700
|
+
"""Sub objects.
|
|
701
|
+
|
|
702
|
+
compares: list[BinaryExpr],
|
|
703
|
+
"""
|
|
704
|
+
|
|
705
|
+
def exit_f_string(self, node: ast.FString) -> None:
|
|
706
|
+
"""Sub objects.
|
|
707
|
+
|
|
708
|
+
parts: list['Token | ExprType'],
|
|
709
|
+
"""
|
|
710
|
+
|
|
711
|
+
# Checks and validations
|
|
712
|
+
# ----------------------
|
|
713
|
+
|
|
714
|
+
def assert_type_match(self, sym: TypedSymbol, node: ast.AstNode) -> bool:
|
|
715
|
+
"""Check if two types match."""
|
|
716
|
+
if isinstance(sym.typ, node._typ):
|
|
717
|
+
return True
|
|
718
|
+
self.error(
|
|
719
|
+
f"Type mismatch, {sym.name} already defined on line "
|
|
720
|
+
f"{sym.node.line if sym.node else 'unknown'} as {sym.typ} not compatible with"
|
|
721
|
+
f"{node._typ} on line {node.line}!"
|
|
722
|
+
)
|
|
723
|
+
return False
|
|
724
|
+
|
|
725
|
+
def not_defined_err(self, name: str) -> None:
|
|
726
|
+
"""Check if a symbol is defined."""
|
|
727
|
+
self.error(f"Symbol {name} not defined!")
|
|
728
|
+
|
|
729
|
+
def already_defined_err(self, name: str) -> None:
|
|
730
|
+
"""Check if a symbol is defined."""
|
|
731
|
+
self.error(f"Symbol {name} already in use in this scope!")
|