jaclang 0.7.2__py3-none-any.whl → 0.7.5__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/cli/cli.py +2 -2
- jaclang/compiler/absyntree.py +337 -273
- jaclang/compiler/codeloc.py +2 -2
- jaclang/compiler/constant.py +2 -0
- jaclang/compiler/jac.lark +25 -19
- jaclang/compiler/parser.py +115 -92
- jaclang/compiler/passes/main/access_modifier_pass.py +15 -9
- jaclang/compiler/passes/main/def_impl_match_pass.py +25 -13
- jaclang/compiler/passes/main/def_use_pass.py +48 -17
- jaclang/compiler/passes/main/fuse_typeinfo_pass.py +34 -34
- jaclang/compiler/passes/main/import_pass.py +8 -6
- jaclang/compiler/passes/main/pyast_gen_pass.py +97 -42
- jaclang/compiler/passes/main/pyast_load_pass.py +47 -12
- jaclang/compiler/passes/main/pyjac_ast_link_pass.py +19 -10
- jaclang/compiler/passes/main/registry_pass.py +6 -6
- jaclang/compiler/passes/main/sym_tab_build_pass.py +30 -72
- jaclang/compiler/passes/main/tests/test_decl_def_match_pass.py +21 -4
- jaclang/compiler/passes/main/tests/test_def_use_pass.py +5 -10
- jaclang/compiler/passes/main/type_check_pass.py +2 -1
- jaclang/compiler/passes/tool/jac_formatter_pass.py +30 -9
- jaclang/compiler/passes/tool/tests/fixtures/corelib.jac +16 -0
- jaclang/compiler/passes/tool/tests/fixtures/corelib_fmt.jac +16 -0
- jaclang/compiler/passes/transform.py +2 -4
- jaclang/{core/registry.py → compiler/semtable.py} +1 -3
- jaclang/compiler/symtable.py +25 -37
- jaclang/compiler/tests/test_parser.py +2 -2
- jaclang/core/aott.py +8 -8
- jaclang/core/{construct.py → architype.py} +25 -240
- jaclang/core/constructs.py +44 -0
- jaclang/core/context.py +157 -0
- jaclang/core/importer.py +18 -9
- jaclang/core/memory.py +99 -0
- jaclang/core/test.py +90 -0
- jaclang/core/utils.py +2 -2
- jaclang/langserve/engine.py +32 -19
- jaclang/langserve/tests/fixtures/circle.jac +16 -12
- jaclang/langserve/tests/fixtures/circle_err.jac +3 -3
- jaclang/langserve/tests/test_server.py +3 -12
- jaclang/langserve/utils.py +10 -6
- jaclang/plugin/builtin.py +1 -1
- jaclang/plugin/default.py +21 -7
- jaclang/plugin/feature.py +24 -6
- jaclang/plugin/spec.py +17 -19
- jaclang/settings.py +3 -0
- jaclang/tests/fixtures/abc.jac +16 -12
- jaclang/tests/fixtures/byllmissue.jac +9 -0
- jaclang/tests/fixtures/edgetypetest.jac +16 -0
- jaclang/tests/fixtures/impl_match_confused.impl.jac +1 -0
- jaclang/tests/fixtures/impl_match_confused.jac +5 -0
- jaclang/tests/fixtures/maxfail_run_test.jac +17 -5
- jaclang/tests/fixtures/run_test.jac +17 -5
- jaclang/tests/test_bugs.py +19 -0
- jaclang/tests/test_cli.py +1 -1
- jaclang/tests/test_language.py +56 -1
- jaclang/tests/test_reference.py +1 -1
- jaclang/utils/lang_tools.py +5 -4
- jaclang/utils/test.py +2 -1
- jaclang/utils/treeprinter.py +22 -8
- {jaclang-0.7.2.dist-info → jaclang-0.7.5.dist-info}/METADATA +1 -1
- {jaclang-0.7.2.dist-info → jaclang-0.7.5.dist-info}/RECORD +62 -54
- {jaclang-0.7.2.dist-info → jaclang-0.7.5.dist-info}/WHEEL +0 -0
- {jaclang-0.7.2.dist-info → jaclang-0.7.5.dist-info}/entry_points.txt +0 -0
jaclang/compiler/absyntree.py
CHANGED
|
@@ -12,14 +12,13 @@ from jaclang.compiler import TOKEN_MAP
|
|
|
12
12
|
from jaclang.compiler.codeloc import CodeGenTarget, CodeLocInfo
|
|
13
13
|
from jaclang.compiler.constant import Constants as Con, EdgeDir
|
|
14
14
|
from jaclang.compiler.constant import DELIM_MAP, Tokens as Tok
|
|
15
|
+
from jaclang.compiler.semtable import SemRegistry
|
|
15
16
|
from jaclang.compiler.symtable import (
|
|
16
17
|
Symbol,
|
|
17
18
|
SymbolAccess,
|
|
18
|
-
SymbolInfo,
|
|
19
19
|
SymbolTable,
|
|
20
20
|
SymbolType,
|
|
21
21
|
)
|
|
22
|
-
from jaclang.core.registry import SemRegistry
|
|
23
22
|
from jaclang.utils.treeprinter import dotgen_ast_tree, print_ast_tree
|
|
24
23
|
|
|
25
24
|
|
|
@@ -58,6 +57,17 @@ class AstNode:
|
|
|
58
57
|
self.loc.update_last_token(self.kid[-1].loc.last_tok)
|
|
59
58
|
return self
|
|
60
59
|
|
|
60
|
+
def insert_kids_at_pos(
|
|
61
|
+
self, nodes: Sequence[AstNode], pos: int, pos_update: bool = True
|
|
62
|
+
) -> AstNode:
|
|
63
|
+
"""Insert kids at position."""
|
|
64
|
+
self.kid = [*self.kid[:pos], *nodes, *self.kid[pos:]]
|
|
65
|
+
if pos_update:
|
|
66
|
+
for i in nodes:
|
|
67
|
+
i.parent = self
|
|
68
|
+
self.loc.update_token_range(*self.resolve_tok_range())
|
|
69
|
+
return self
|
|
70
|
+
|
|
61
71
|
def set_kids(self, nodes: Sequence[AstNode]) -> AstNode:
|
|
62
72
|
"""Set kids."""
|
|
63
73
|
self.kid = [*nodes]
|
|
@@ -101,6 +111,7 @@ class AstNode:
|
|
|
101
111
|
col_start=self.loc.col_start,
|
|
102
112
|
col_end=0,
|
|
103
113
|
line=self.loc.first_line,
|
|
114
|
+
end_line=self.loc.last_line,
|
|
104
115
|
pos_start=0,
|
|
105
116
|
pos_end=0,
|
|
106
117
|
)
|
|
@@ -176,17 +187,56 @@ class AstSymbolNode(AstNode):
|
|
|
176
187
|
"""Nodes that have link to a symbol in symbol table."""
|
|
177
188
|
|
|
178
189
|
def __init__(
|
|
179
|
-
self, sym_name: str,
|
|
190
|
+
self, sym_name: str, name_spec: NameAtom, sym_category: SymbolType
|
|
180
191
|
) -> None:
|
|
181
192
|
"""Initialize ast."""
|
|
182
|
-
self.
|
|
183
|
-
self.
|
|
184
|
-
self.
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
193
|
+
self.name_spec = name_spec
|
|
194
|
+
self.name_spec.name_of = self
|
|
195
|
+
self.name_spec._sym_name = sym_name
|
|
196
|
+
self.name_spec._sym_category = sym_category
|
|
197
|
+
|
|
198
|
+
@property
|
|
199
|
+
def sym(self) -> Optional[Symbol]:
|
|
200
|
+
"""Get symbol."""
|
|
201
|
+
return self.name_spec.sym
|
|
202
|
+
|
|
203
|
+
@property
|
|
204
|
+
def sym_name(self) -> str:
|
|
205
|
+
"""Get symbol name."""
|
|
206
|
+
return self.name_spec.sym_name
|
|
207
|
+
|
|
208
|
+
@property
|
|
209
|
+
def sym_category(self) -> SymbolType:
|
|
210
|
+
"""Get symbol category."""
|
|
211
|
+
return self.name_spec.sym_category
|
|
212
|
+
|
|
213
|
+
@property
|
|
214
|
+
def py_ctx_func(self) -> Type[ast3.AST]:
|
|
215
|
+
"""Get python context function."""
|
|
216
|
+
return self.name_spec.py_ctx_func
|
|
217
|
+
|
|
218
|
+
@property
|
|
219
|
+
def sym_type(self) -> str:
|
|
220
|
+
"""Get symbol type."""
|
|
221
|
+
return self.name_spec.sym_type
|
|
222
|
+
|
|
223
|
+
@property
|
|
224
|
+
def type_sym_tab(self) -> Optional[SymbolTable]:
|
|
225
|
+
"""Get type symbol table."""
|
|
226
|
+
return self.name_spec.type_sym_tab
|
|
227
|
+
|
|
228
|
+
|
|
229
|
+
class AstSymbolStubNode(AstSymbolNode):
|
|
230
|
+
"""Nodes that have link to a symbol in symbol table."""
|
|
231
|
+
|
|
232
|
+
def __init__(self, sym_type: SymbolType) -> None:
|
|
233
|
+
"""Initialize ast."""
|
|
234
|
+
AstSymbolNode.__init__(
|
|
235
|
+
self,
|
|
236
|
+
sym_name=f"[{self.__class__.__name__}]",
|
|
237
|
+
name_spec=Name.gen_stub_from_node(self, f"[{self.__class__.__name__}]"),
|
|
238
|
+
sym_category=sym_type,
|
|
239
|
+
)
|
|
190
240
|
|
|
191
241
|
|
|
192
242
|
class AstAccessNode(AstNode):
|
|
@@ -261,7 +311,31 @@ class WalkerStmtOnlyNode(AstNode):
|
|
|
261
311
|
self.from_walker: bool = False
|
|
262
312
|
|
|
263
313
|
|
|
264
|
-
class
|
|
314
|
+
class Expr(AstNode):
|
|
315
|
+
"""Expr node type for Jac Ast."""
|
|
316
|
+
|
|
317
|
+
|
|
318
|
+
class AtomExpr(Expr, AstSymbolStubNode):
|
|
319
|
+
"""AtomExpr node type for Jac Ast."""
|
|
320
|
+
|
|
321
|
+
|
|
322
|
+
class ElementStmt(AstDocNode):
|
|
323
|
+
"""ElementStmt node type for Jac Ast."""
|
|
324
|
+
|
|
325
|
+
|
|
326
|
+
class ArchBlockStmt(AstNode):
|
|
327
|
+
"""ArchBlockStmt node type for Jac Ast."""
|
|
328
|
+
|
|
329
|
+
|
|
330
|
+
class EnumBlockStmt(AstNode):
|
|
331
|
+
"""EnumBlockStmt node type for Jac Ast."""
|
|
332
|
+
|
|
333
|
+
|
|
334
|
+
class CodeBlockStmt(AstNode):
|
|
335
|
+
"""CodeBlockStmt node type for Jac Ast."""
|
|
336
|
+
|
|
337
|
+
|
|
338
|
+
class AstImplOnlyNode(CodeBlockStmt, ElementStmt, AstSymbolNode):
|
|
265
339
|
"""ImplOnly node type for Jac Ast."""
|
|
266
340
|
|
|
267
341
|
def __init__(
|
|
@@ -271,6 +345,28 @@ class AstImplOnlyNode(AstNode):
|
|
|
271
345
|
self.target = target
|
|
272
346
|
self.body = body
|
|
273
347
|
self.decl_link = decl_link
|
|
348
|
+
AstSymbolNode.__init__(
|
|
349
|
+
self,
|
|
350
|
+
sym_name=self.target.py_resolve_name(),
|
|
351
|
+
name_spec=self.create_impl_name_node(),
|
|
352
|
+
sym_category=SymbolType.IMPL,
|
|
353
|
+
)
|
|
354
|
+
|
|
355
|
+
def create_impl_name_node(self) -> Name:
|
|
356
|
+
"""Create impl name."""
|
|
357
|
+
ret = Name(
|
|
358
|
+
file_path=self.target.archs[-1].loc.mod_path,
|
|
359
|
+
name=Tok.NAME.value,
|
|
360
|
+
value=self.target.py_resolve_name(),
|
|
361
|
+
col_start=self.target.archs[0].loc.col_start,
|
|
362
|
+
col_end=self.target.archs[-1].loc.col_end,
|
|
363
|
+
line=self.target.archs[0].loc.first_line,
|
|
364
|
+
end_line=self.target.archs[-1].loc.last_line,
|
|
365
|
+
pos_start=self.target.archs[0].loc.pos_start,
|
|
366
|
+
pos_end=self.target.archs[-1].loc.pos_end,
|
|
367
|
+
)
|
|
368
|
+
ret.name_of = self
|
|
369
|
+
return ret
|
|
274
370
|
|
|
275
371
|
|
|
276
372
|
class AstImplNeedingNode(AstSymbolNode, Generic[T]):
|
|
@@ -286,36 +382,74 @@ class AstImplNeedingNode(AstSymbolNode, Generic[T]):
|
|
|
286
382
|
return self.body is None
|
|
287
383
|
|
|
288
384
|
|
|
289
|
-
class
|
|
290
|
-
"""
|
|
291
|
-
|
|
385
|
+
class NameAtom(AtomExpr, EnumBlockStmt):
|
|
386
|
+
"""NameSpec node type for Jac Ast."""
|
|
292
387
|
|
|
293
|
-
|
|
294
|
-
|
|
388
|
+
def __init__(self) -> None:
|
|
389
|
+
"""Initialize name spec node."""
|
|
390
|
+
self.name_of: AstSymbolNode = self
|
|
391
|
+
self._sym: Optional[Symbol] = None
|
|
392
|
+
self._sym_name: str = ""
|
|
393
|
+
self._sym_category: SymbolType = SymbolType.UNKNOWN
|
|
394
|
+
self._py_ctx_func: Type[ast3.AST] = ast3.Load
|
|
395
|
+
self._sym_type: str = "NoType"
|
|
396
|
+
self._type_sym_tab: Optional[SymbolTable] = None
|
|
295
397
|
|
|
398
|
+
@property
|
|
399
|
+
def sym(self) -> Optional[Symbol]:
|
|
400
|
+
"""Get symbol."""
|
|
401
|
+
return self._sym
|
|
296
402
|
|
|
297
|
-
|
|
298
|
-
|
|
403
|
+
@sym.setter
|
|
404
|
+
def sym(self, sym: Symbol) -> None:
|
|
405
|
+
"""Set symbol."""
|
|
406
|
+
self._sym = sym
|
|
299
407
|
|
|
408
|
+
@property
|
|
409
|
+
def sym_name(self) -> str:
|
|
410
|
+
"""Get symbol name."""
|
|
411
|
+
return self._sym_name
|
|
300
412
|
|
|
301
|
-
|
|
302
|
-
|
|
413
|
+
@property
|
|
414
|
+
def sym_category(self) -> SymbolType:
|
|
415
|
+
"""Get symbol category."""
|
|
416
|
+
return self._sym_category
|
|
303
417
|
|
|
418
|
+
@property
|
|
419
|
+
def clean_type(self) -> str:
|
|
420
|
+
"""Get clean type."""
|
|
421
|
+
ret_type = self.sym_type.replace("builtins.", "").replace("NoType", "")
|
|
422
|
+
return ret_type
|
|
304
423
|
|
|
305
|
-
|
|
306
|
-
|
|
424
|
+
@property
|
|
425
|
+
def py_ctx_func(self) -> Type[ast3.AST]:
|
|
426
|
+
"""Get python context function."""
|
|
427
|
+
return self._py_ctx_func
|
|
307
428
|
|
|
429
|
+
@py_ctx_func.setter
|
|
430
|
+
def py_ctx_func(self, py_ctx_func: Type[ast3.AST]) -> None:
|
|
431
|
+
"""Set python context function."""
|
|
432
|
+
self._py_ctx_func = py_ctx_func
|
|
308
433
|
|
|
309
|
-
|
|
310
|
-
|
|
434
|
+
@property
|
|
435
|
+
def sym_type(self) -> str:
|
|
436
|
+
"""Get symbol type."""
|
|
437
|
+
return self._sym_type
|
|
311
438
|
|
|
439
|
+
@sym_type.setter
|
|
440
|
+
def sym_type(self, sym_type: str) -> None:
|
|
441
|
+
"""Set symbol type."""
|
|
442
|
+
self._sym_type = sym_type
|
|
312
443
|
|
|
313
|
-
|
|
314
|
-
|
|
444
|
+
@property
|
|
445
|
+
def type_sym_tab(self) -> Optional[SymbolTable]:
|
|
446
|
+
"""Get type symbol table."""
|
|
447
|
+
return self._type_sym_tab
|
|
315
448
|
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
449
|
+
@type_sym_tab.setter
|
|
450
|
+
def type_sym_tab(self, type_sym_tab: SymbolTable) -> None:
|
|
451
|
+
"""Set type symbol table."""
|
|
452
|
+
self._type_sym_tab = type_sym_tab
|
|
319
453
|
|
|
320
454
|
|
|
321
455
|
class ArchSpec(ElementStmt, CodeBlockStmt, AstSymbolNode, AstDocNode, AstSemStrNode):
|
|
@@ -522,26 +656,31 @@ class Test(AstSymbolNode, ElementStmt):
|
|
|
522
656
|
if isinstance(name, Name)
|
|
523
657
|
else Name(
|
|
524
658
|
file_path=name.file_path,
|
|
525
|
-
name=
|
|
526
|
-
value=f"
|
|
659
|
+
name=Tok.NAME.value,
|
|
660
|
+
value=f"_jac_gen_{Test.TEST_COUNT}",
|
|
527
661
|
col_start=name.loc.col_start,
|
|
528
662
|
col_end=name.loc.col_end,
|
|
529
663
|
line=name.loc.first_line,
|
|
664
|
+
end_line=name.loc.last_line,
|
|
530
665
|
pos_start=name.pos_start,
|
|
531
666
|
pos_end=name.pos_end,
|
|
532
667
|
)
|
|
533
668
|
)
|
|
534
669
|
self.name.parent = self
|
|
535
|
-
|
|
670
|
+
self.name._sym_name = (
|
|
671
|
+
f"test_{self.name.value}"
|
|
672
|
+
if not self.name.value.startswith("test_")
|
|
673
|
+
else self.name.value
|
|
674
|
+
)
|
|
536
675
|
self.body = body
|
|
537
676
|
AstNode.__init__(self, kid=kid)
|
|
538
677
|
if self.name not in self.kid:
|
|
539
|
-
self.
|
|
678
|
+
self.insert_kids_at_pos([self.name], pos=1, pos_update=False)
|
|
540
679
|
AstSymbolNode.__init__(
|
|
541
680
|
self,
|
|
542
681
|
sym_name=self.name.sym_name,
|
|
543
|
-
|
|
544
|
-
|
|
682
|
+
name_spec=self.name,
|
|
683
|
+
sym_category=SymbolType.TEST,
|
|
545
684
|
)
|
|
546
685
|
AstDocNode.__init__(self, doc=doc)
|
|
547
686
|
|
|
@@ -690,12 +829,15 @@ class ModulePath(AstSymbolNode):
|
|
|
690
829
|
self.alias = alias
|
|
691
830
|
self.sub_module = sub_module
|
|
692
831
|
|
|
832
|
+
name_spec = alias if alias else path[0] if path else None
|
|
833
|
+
if not isinstance(name_spec, Name):
|
|
834
|
+
raise ValueError("ModulePath should have a name spec. Impossible.")
|
|
693
835
|
AstNode.__init__(self, kid=kid)
|
|
694
836
|
AstSymbolNode.__init__(
|
|
695
837
|
self,
|
|
696
|
-
sym_name=
|
|
697
|
-
|
|
698
|
-
|
|
838
|
+
sym_name=name_spec.sym_name,
|
|
839
|
+
name_spec=name_spec,
|
|
840
|
+
sym_category=SymbolType.MODULE,
|
|
699
841
|
)
|
|
700
842
|
|
|
701
843
|
@property
|
|
@@ -748,8 +890,8 @@ class ModuleItem(AstSymbolNode):
|
|
|
748
890
|
AstSymbolNode.__init__(
|
|
749
891
|
self,
|
|
750
892
|
sym_name=alias.sym_name if alias else name.sym_name,
|
|
751
|
-
|
|
752
|
-
|
|
893
|
+
name_spec=alias if alias else name,
|
|
894
|
+
sym_category=SymbolType.MOD_VAR,
|
|
753
895
|
)
|
|
754
896
|
|
|
755
897
|
def normalize(self, deep: bool = False) -> bool:
|
|
@@ -789,8 +931,8 @@ class Architype(ArchSpec, AstAccessNode, ArchBlockStmt, AstImplNeedingNode):
|
|
|
789
931
|
AstSymbolNode.__init__(
|
|
790
932
|
self,
|
|
791
933
|
sym_name=name.value,
|
|
792
|
-
|
|
793
|
-
|
|
934
|
+
name_spec=name,
|
|
935
|
+
sym_category=(
|
|
794
936
|
SymbolType.OBJECT_ARCH
|
|
795
937
|
if arch_type.name == Tok.KW_OBJECT
|
|
796
938
|
else (
|
|
@@ -865,7 +1007,7 @@ class Architype(ArchSpec, AstAccessNode, ArchBlockStmt, AstImplNeedingNode):
|
|
|
865
1007
|
return res
|
|
866
1008
|
|
|
867
1009
|
|
|
868
|
-
class ArchDef(
|
|
1010
|
+
class ArchDef(AstImplOnlyNode):
|
|
869
1011
|
"""ArchDef node type for Jac Ast."""
|
|
870
1012
|
|
|
871
1013
|
def __init__(
|
|
@@ -879,14 +1021,7 @@ class ArchDef(ArchSpec, AstImplOnlyNode):
|
|
|
879
1021
|
) -> None:
|
|
880
1022
|
"""Initialize arch def node."""
|
|
881
1023
|
AstNode.__init__(self, kid=kid)
|
|
882
|
-
AstSymbolNode.__init__(
|
|
883
|
-
self,
|
|
884
|
-
sym_name=target.py_resolve_name(),
|
|
885
|
-
sym_name_node=target,
|
|
886
|
-
sym_type=SymbolType.IMPL,
|
|
887
|
-
)
|
|
888
1024
|
AstDocNode.__init__(self, doc=doc)
|
|
889
|
-
ArchSpec.__init__(self, decorators=decorators)
|
|
890
1025
|
AstImplOnlyNode.__init__(self, target=target, body=body, decl_link=decl_link)
|
|
891
1026
|
|
|
892
1027
|
def normalize(self, deep: bool = False) -> bool:
|
|
@@ -896,7 +1031,6 @@ class ArchDef(ArchSpec, AstImplOnlyNode):
|
|
|
896
1031
|
res = self.target.normalize(deep)
|
|
897
1032
|
res = res and self.body.normalize(deep)
|
|
898
1033
|
res = res and self.doc.normalize(deep) if self.doc else res
|
|
899
|
-
res = res and self.decorators.normalize(deep) if self.decorators else res
|
|
900
1034
|
new_kid: list[AstNode] = []
|
|
901
1035
|
if self.doc:
|
|
902
1036
|
new_kid.append(self.doc)
|
|
@@ -927,8 +1061,8 @@ class Enum(ArchSpec, AstAccessNode, AstImplNeedingNode, ArchBlockStmt):
|
|
|
927
1061
|
AstSymbolNode.__init__(
|
|
928
1062
|
self,
|
|
929
1063
|
sym_name=name.value,
|
|
930
|
-
|
|
931
|
-
|
|
1064
|
+
name_spec=name,
|
|
1065
|
+
sym_category=SymbolType.ENUM_ARCH,
|
|
932
1066
|
)
|
|
933
1067
|
AstImplNeedingNode.__init__(self, body=body)
|
|
934
1068
|
AstAccessNode.__init__(self, access=access)
|
|
@@ -975,7 +1109,7 @@ class Enum(ArchSpec, AstAccessNode, AstImplNeedingNode, ArchBlockStmt):
|
|
|
975
1109
|
return res
|
|
976
1110
|
|
|
977
1111
|
|
|
978
|
-
class EnumDef(
|
|
1112
|
+
class EnumDef(AstImplOnlyNode):
|
|
979
1113
|
"""EnumDef node type for Jac Ast."""
|
|
980
1114
|
|
|
981
1115
|
def __init__(
|
|
@@ -989,14 +1123,7 @@ class EnumDef(ArchSpec, AstImplOnlyNode):
|
|
|
989
1123
|
) -> None:
|
|
990
1124
|
"""Initialize arch def node."""
|
|
991
1125
|
AstNode.__init__(self, kid=kid)
|
|
992
|
-
AstSymbolNode.__init__(
|
|
993
|
-
self,
|
|
994
|
-
sym_name=target.py_resolve_name(),
|
|
995
|
-
sym_name_node=target,
|
|
996
|
-
sym_type=SymbolType.IMPL,
|
|
997
|
-
)
|
|
998
1126
|
AstDocNode.__init__(self, doc=doc)
|
|
999
|
-
ArchSpec.__init__(self, decorators=decorators)
|
|
1000
1127
|
AstImplOnlyNode.__init__(self, target=target, body=body, decl_link=decl_link)
|
|
1001
1128
|
|
|
1002
1129
|
def normalize(self, deep: bool = False) -> bool:
|
|
@@ -1006,7 +1133,6 @@ class EnumDef(ArchSpec, AstImplOnlyNode):
|
|
|
1006
1133
|
res = self.target.normalize(deep)
|
|
1007
1134
|
res = res and self.body.normalize(deep)
|
|
1008
1135
|
res = res and self.doc.normalize(deep) if self.doc else res
|
|
1009
|
-
res = res and self.decorators.normalize(deep) if self.decorators else res
|
|
1010
1136
|
new_kid: list[AstNode] = []
|
|
1011
1137
|
if self.doc:
|
|
1012
1138
|
new_kid.append(self.doc)
|
|
@@ -1031,7 +1157,7 @@ class Ability(
|
|
|
1031
1157
|
|
|
1032
1158
|
def __init__(
|
|
1033
1159
|
self,
|
|
1034
|
-
name_ref:
|
|
1160
|
+
name_ref: NameAtom,
|
|
1035
1161
|
is_async: bool,
|
|
1036
1162
|
is_override: bool,
|
|
1037
1163
|
is_static: bool,
|
|
@@ -1057,17 +1183,17 @@ class Ability(
|
|
|
1057
1183
|
AstSymbolNode.__init__(
|
|
1058
1184
|
self,
|
|
1059
1185
|
sym_name=self.py_resolve_name(),
|
|
1060
|
-
|
|
1061
|
-
|
|
1186
|
+
name_spec=name_ref,
|
|
1187
|
+
sym_category=SymbolType.ABILITY,
|
|
1062
1188
|
)
|
|
1063
1189
|
AstAccessNode.__init__(self, access=access)
|
|
1064
1190
|
AstDocNode.__init__(self, doc=doc)
|
|
1065
1191
|
AstAsyncNode.__init__(self, is_async=is_async)
|
|
1066
1192
|
|
|
1067
1193
|
@property
|
|
1068
|
-
def
|
|
1194
|
+
def is_method(self) -> bool:
|
|
1069
1195
|
"""Check if is func."""
|
|
1070
|
-
return
|
|
1196
|
+
return self.signature.is_method
|
|
1071
1197
|
|
|
1072
1198
|
@property
|
|
1073
1199
|
def is_genai_ability(self) -> bool:
|
|
@@ -1132,7 +1258,7 @@ class Ability(
|
|
|
1132
1258
|
return res
|
|
1133
1259
|
|
|
1134
1260
|
|
|
1135
|
-
class AbilityDef(
|
|
1261
|
+
class AbilityDef(AstImplOnlyNode):
|
|
1136
1262
|
"""AbilityDef node type for Jac Ast."""
|
|
1137
1263
|
|
|
1138
1264
|
def __init__(
|
|
@@ -1149,12 +1275,6 @@ class AbilityDef(AstSymbolNode, ElementStmt, AstImplOnlyNode, CodeBlockStmt):
|
|
|
1149
1275
|
self.signature = signature
|
|
1150
1276
|
self.decorators = decorators
|
|
1151
1277
|
AstNode.__init__(self, kid=kid)
|
|
1152
|
-
AstSymbolNode.__init__(
|
|
1153
|
-
self,
|
|
1154
|
-
sym_name=target.py_resolve_name(),
|
|
1155
|
-
sym_name_node=target,
|
|
1156
|
-
sym_type=SymbolType.IMPL,
|
|
1157
|
-
)
|
|
1158
1278
|
AstDocNode.__init__(self, doc=doc)
|
|
1159
1279
|
AstImplOnlyNode.__init__(self, target=target, body=body, decl_link=decl_link)
|
|
1160
1280
|
|
|
@@ -1192,6 +1312,7 @@ class FuncSignature(AstSemStrNode):
|
|
|
1192
1312
|
"""Initialize method signature node."""
|
|
1193
1313
|
self.params = params
|
|
1194
1314
|
self.return_type = return_type
|
|
1315
|
+
self.is_method = False
|
|
1195
1316
|
AstNode.__init__(self, kid=kid)
|
|
1196
1317
|
AstSemStrNode.__init__(self, semstr=semstr)
|
|
1197
1318
|
|
|
@@ -1240,6 +1361,7 @@ class EventSignature(AstSemStrNode):
|
|
|
1240
1361
|
self.event = event
|
|
1241
1362
|
self.arch_tag_info = arch_tag_info
|
|
1242
1363
|
self.return_type = return_type
|
|
1364
|
+
self.is_method = False
|
|
1243
1365
|
AstNode.__init__(self, kid=kid)
|
|
1244
1366
|
AstSemStrNode.__init__(self, semstr=semstr)
|
|
1245
1367
|
|
|
@@ -1298,11 +1420,11 @@ class ArchRefChain(AstNode):
|
|
|
1298
1420
|
def get_tag(x: ArchRef) -> str:
|
|
1299
1421
|
return (
|
|
1300
1422
|
"en"
|
|
1301
|
-
if x.
|
|
1302
|
-
else "cls" if x.
|
|
1423
|
+
if x.arch_type.value == "enum"
|
|
1424
|
+
else "cls" if x.arch_type.value == "class" else x.arch_type.value[1]
|
|
1303
1425
|
)
|
|
1304
1426
|
|
|
1305
|
-
return ".".join([f"({get_tag(x)}){x.
|
|
1427
|
+
return ".".join([f"({get_tag(x)}){x.sym_name}" for x in self.archs])
|
|
1306
1428
|
|
|
1307
1429
|
def flat_name(self) -> str:
|
|
1308
1430
|
"""Resolve name for python gen."""
|
|
@@ -1331,8 +1453,8 @@ class ParamVar(AstSymbolNode, AstTypedVarNode, AstSemStrNode):
|
|
|
1331
1453
|
AstSymbolNode.__init__(
|
|
1332
1454
|
self,
|
|
1333
1455
|
sym_name=name.value,
|
|
1334
|
-
|
|
1335
|
-
|
|
1456
|
+
name_spec=name,
|
|
1457
|
+
sym_category=SymbolType.VAR,
|
|
1336
1458
|
)
|
|
1337
1459
|
AstTypedVarNode.__init__(self, type_tag=type_tag)
|
|
1338
1460
|
AstSemStrNode.__init__(self, semstr=semstr)
|
|
@@ -1427,8 +1549,8 @@ class HasVar(AstSymbolNode, AstTypedVarNode, AstSemStrNode):
|
|
|
1427
1549
|
AstSymbolNode.__init__(
|
|
1428
1550
|
self,
|
|
1429
1551
|
sym_name=name.value,
|
|
1430
|
-
|
|
1431
|
-
|
|
1552
|
+
name_spec=name,
|
|
1553
|
+
sym_category=SymbolType.HAS_VAR,
|
|
1432
1554
|
)
|
|
1433
1555
|
AstTypedVarNode.__init__(self, type_tag=type_tag)
|
|
1434
1556
|
AstSemStrNode.__init__(self, semstr=semstr)
|
|
@@ -1943,6 +2065,32 @@ class AssertStmt(CodeBlockStmt):
|
|
|
1943
2065
|
return res
|
|
1944
2066
|
|
|
1945
2067
|
|
|
2068
|
+
class CheckStmt(CodeBlockStmt):
|
|
2069
|
+
"""DeleteStmt node type for Jac Ast."""
|
|
2070
|
+
|
|
2071
|
+
def __init__(
|
|
2072
|
+
self,
|
|
2073
|
+
target: Expr,
|
|
2074
|
+
kid: Sequence[AstNode],
|
|
2075
|
+
) -> None:
|
|
2076
|
+
"""Initialize delete statement node."""
|
|
2077
|
+
self.target = target
|
|
2078
|
+
AstNode.__init__(self, kid=kid)
|
|
2079
|
+
|
|
2080
|
+
def normalize(self, deep: bool = False) -> bool:
|
|
2081
|
+
"""Normalize delete statement node."""
|
|
2082
|
+
res = True
|
|
2083
|
+
if deep:
|
|
2084
|
+
res = self.target.normalize(deep)
|
|
2085
|
+
new_kid: list[AstNode] = [
|
|
2086
|
+
self.gen_token(Tok.KW_CHECK),
|
|
2087
|
+
self.target,
|
|
2088
|
+
self.gen_token(Tok.SEMI),
|
|
2089
|
+
]
|
|
2090
|
+
self.set_kids(nodes=new_kid)
|
|
2091
|
+
return res
|
|
2092
|
+
|
|
2093
|
+
|
|
1946
2094
|
class CtrlStmt(CodeBlockStmt):
|
|
1947
2095
|
"""CtrlStmt node type for Jac Ast."""
|
|
1948
2096
|
|
|
@@ -2192,7 +2340,7 @@ class GlobalStmt(CodeBlockStmt):
|
|
|
2192
2340
|
|
|
2193
2341
|
def __init__(
|
|
2194
2342
|
self,
|
|
2195
|
-
target: SubNodeList[
|
|
2343
|
+
target: SubNodeList[NameAtom],
|
|
2196
2344
|
kid: Sequence[AstNode],
|
|
2197
2345
|
) -> None:
|
|
2198
2346
|
"""Initialize global statement node."""
|
|
@@ -2485,12 +2633,7 @@ class MultiString(AtomExpr):
|
|
|
2485
2633
|
"""Initialize multi string expression node."""
|
|
2486
2634
|
self.strings = strings
|
|
2487
2635
|
AstNode.__init__(self, kid=kid)
|
|
2488
|
-
|
|
2489
|
-
self,
|
|
2490
|
-
sym_name=f"[{self.__class__.__name__}]",
|
|
2491
|
-
sym_name_node=self,
|
|
2492
|
-
sym_type=SymbolType.STRING,
|
|
2493
|
-
)
|
|
2636
|
+
AstSymbolStubNode.__init__(self, sym_type=SymbolType.STRING)
|
|
2494
2637
|
|
|
2495
2638
|
def normalize(self, deep: bool = False) -> bool:
|
|
2496
2639
|
"""Normalize ast node."""
|
|
@@ -2516,12 +2659,7 @@ class FString(AtomExpr):
|
|
|
2516
2659
|
"""Initialize fstring expression node."""
|
|
2517
2660
|
self.parts = parts
|
|
2518
2661
|
AstNode.__init__(self, kid=kid)
|
|
2519
|
-
|
|
2520
|
-
self,
|
|
2521
|
-
sym_name=f"[{self.__class__.__name__}]",
|
|
2522
|
-
sym_name_node=self,
|
|
2523
|
-
sym_type=SymbolType.STRING,
|
|
2524
|
-
)
|
|
2662
|
+
AstSymbolStubNode.__init__(self, sym_type=SymbolType.STRING)
|
|
2525
2663
|
|
|
2526
2664
|
def normalize(self, deep: bool = False) -> bool:
|
|
2527
2665
|
"""Normalize ast node."""
|
|
@@ -2551,12 +2689,7 @@ class ListVal(AtomExpr):
|
|
|
2551
2689
|
"""Initialize value node."""
|
|
2552
2690
|
self.values = values
|
|
2553
2691
|
AstNode.__init__(self, kid=kid)
|
|
2554
|
-
|
|
2555
|
-
self,
|
|
2556
|
-
sym_name=f"[{self.__class__.__name__}]",
|
|
2557
|
-
sym_name_node=self,
|
|
2558
|
-
sym_type=SymbolType.SEQUENCE,
|
|
2559
|
-
)
|
|
2692
|
+
AstSymbolStubNode.__init__(self, sym_type=SymbolType.SEQUENCE)
|
|
2560
2693
|
|
|
2561
2694
|
def normalize(self, deep: bool = False) -> bool:
|
|
2562
2695
|
"""Normalize ast node."""
|
|
@@ -2584,12 +2717,7 @@ class SetVal(AtomExpr):
|
|
|
2584
2717
|
"""Initialize value node."""
|
|
2585
2718
|
self.values = values
|
|
2586
2719
|
AstNode.__init__(self, kid=kid)
|
|
2587
|
-
|
|
2588
|
-
self,
|
|
2589
|
-
sym_name=f"[{self.__class__.__name__}]",
|
|
2590
|
-
sym_name_node=self,
|
|
2591
|
-
sym_type=SymbolType.SEQUENCE,
|
|
2592
|
-
)
|
|
2720
|
+
AstSymbolStubNode.__init__(self, sym_type=SymbolType.SEQUENCE)
|
|
2593
2721
|
|
|
2594
2722
|
def normalize(self, deep: bool = False) -> bool:
|
|
2595
2723
|
"""Normalize ast node."""
|
|
@@ -2617,12 +2745,7 @@ class TupleVal(AtomExpr):
|
|
|
2617
2745
|
"""Initialize tuple value node."""
|
|
2618
2746
|
self.values = values
|
|
2619
2747
|
AstNode.__init__(self, kid=kid)
|
|
2620
|
-
|
|
2621
|
-
self,
|
|
2622
|
-
sym_name=f"[{self.__class__.__name__}]",
|
|
2623
|
-
sym_name_node=self,
|
|
2624
|
-
sym_type=SymbolType.SEQUENCE,
|
|
2625
|
-
)
|
|
2748
|
+
AstSymbolStubNode.__init__(self, sym_type=SymbolType.SEQUENCE)
|
|
2626
2749
|
|
|
2627
2750
|
def normalize(self, deep: bool = False) -> bool:
|
|
2628
2751
|
"""Normalize ast node."""
|
|
@@ -2665,12 +2788,7 @@ class DictVal(AtomExpr):
|
|
|
2665
2788
|
"""Initialize dict expression node."""
|
|
2666
2789
|
self.kv_pairs = kv_pairs
|
|
2667
2790
|
AstNode.__init__(self, kid=kid)
|
|
2668
|
-
|
|
2669
|
-
self,
|
|
2670
|
-
sym_name=f"[{self.__class__.__name__}]",
|
|
2671
|
-
sym_name_node=self,
|
|
2672
|
-
sym_type=SymbolType.SEQUENCE,
|
|
2673
|
-
)
|
|
2791
|
+
AstSymbolStubNode.__init__(self, sym_type=SymbolType.SEQUENCE)
|
|
2674
2792
|
|
|
2675
2793
|
def normalize(self, deep: bool = False) -> bool:
|
|
2676
2794
|
"""Normalize ast node."""
|
|
@@ -2726,7 +2844,7 @@ class KWPair(AstNode):
|
|
|
2726
2844
|
|
|
2727
2845
|
def __init__(
|
|
2728
2846
|
self,
|
|
2729
|
-
key: Optional[
|
|
2847
|
+
key: Optional[NameAtom], # is **value if blank
|
|
2730
2848
|
value: Expr,
|
|
2731
2849
|
kid: Sequence[AstNode],
|
|
2732
2850
|
) -> None:
|
|
@@ -2803,12 +2921,7 @@ class ListCompr(AtomExpr):
|
|
|
2803
2921
|
self.out_expr = out_expr
|
|
2804
2922
|
self.compr = compr
|
|
2805
2923
|
AstNode.__init__(self, kid=kid)
|
|
2806
|
-
|
|
2807
|
-
self,
|
|
2808
|
-
sym_name=f"[{self.__class__.__name__}]",
|
|
2809
|
-
sym_name_node=self,
|
|
2810
|
-
sym_type=SymbolType.SEQUENCE,
|
|
2811
|
-
)
|
|
2924
|
+
AstSymbolStubNode.__init__(self, sym_type=SymbolType.SEQUENCE)
|
|
2812
2925
|
|
|
2813
2926
|
def normalize(self, deep: bool = False) -> bool:
|
|
2814
2927
|
"""Normalize ast node."""
|
|
@@ -2883,12 +2996,7 @@ class DictCompr(AtomExpr):
|
|
|
2883
2996
|
self.kv_pair = kv_pair
|
|
2884
2997
|
self.compr = compr
|
|
2885
2998
|
AstNode.__init__(self, kid=kid)
|
|
2886
|
-
|
|
2887
|
-
self,
|
|
2888
|
-
sym_name=f"[{self.__class__.__name__}]",
|
|
2889
|
-
sym_name_node=self,
|
|
2890
|
-
sym_type=SymbolType.SEQUENCE,
|
|
2891
|
-
)
|
|
2999
|
+
AstSymbolStubNode.__init__(self, sym_type=SymbolType.SEQUENCE)
|
|
2892
3000
|
|
|
2893
3001
|
def normalize(self, deep: bool = False) -> bool:
|
|
2894
3002
|
"""Normalize ast node."""
|
|
@@ -3047,12 +3155,7 @@ class IndexSlice(AtomExpr):
|
|
|
3047
3155
|
self.step = step
|
|
3048
3156
|
self.is_range = is_range
|
|
3049
3157
|
AstNode.__init__(self, kid=kid)
|
|
3050
|
-
|
|
3051
|
-
self,
|
|
3052
|
-
sym_name=f"[{self.__class__.__name__}]",
|
|
3053
|
-
sym_type=SymbolType.SEQUENCE,
|
|
3054
|
-
sym_name_node=self,
|
|
3055
|
-
)
|
|
3158
|
+
AstSymbolStubNode.__init__(self, sym_type=SymbolType.SEQUENCE)
|
|
3056
3159
|
|
|
3057
3160
|
def normalize(self, deep: bool = True) -> bool:
|
|
3058
3161
|
"""Normalize ast node."""
|
|
@@ -3081,91 +3184,35 @@ class IndexSlice(AtomExpr):
|
|
|
3081
3184
|
return res
|
|
3082
3185
|
|
|
3083
3186
|
|
|
3084
|
-
class ArchRef(
|
|
3187
|
+
class ArchRef(AtomExpr):
|
|
3085
3188
|
"""ArchRef node type for Jac Ast."""
|
|
3086
3189
|
|
|
3087
3190
|
def __init__(
|
|
3088
3191
|
self,
|
|
3089
|
-
|
|
3090
|
-
|
|
3192
|
+
arch_name: NameAtom,
|
|
3193
|
+
arch_type: Token,
|
|
3091
3194
|
kid: Sequence[AstNode],
|
|
3092
3195
|
) -> None:
|
|
3093
3196
|
"""Initialize architype reference expression node."""
|
|
3094
|
-
self.
|
|
3095
|
-
self.
|
|
3096
|
-
AstNode.__init__(self, kid=kid)
|
|
3097
|
-
AstSymbolNode.__init__(
|
|
3098
|
-
self,
|
|
3099
|
-
sym_name=self.py_resolve_name(),
|
|
3100
|
-
sym_name_node=name_ref,
|
|
3101
|
-
sym_type=SymbolType.TYPE,
|
|
3102
|
-
)
|
|
3103
|
-
NameSpec.__init__(self)
|
|
3104
|
-
|
|
3105
|
-
def normalize(self, deep: bool = False) -> bool:
|
|
3106
|
-
"""Normalize ast node."""
|
|
3107
|
-
res = True
|
|
3108
|
-
if deep:
|
|
3109
|
-
res = self.name_ref.normalize(deep)
|
|
3110
|
-
new_kid: list[AstNode] = [self.arch, self.name_ref]
|
|
3111
|
-
self.set_kids(nodes=new_kid)
|
|
3112
|
-
return res
|
|
3113
|
-
|
|
3114
|
-
def py_resolve_name(self) -> str:
|
|
3115
|
-
"""Resolve name."""
|
|
3116
|
-
if isinstance(self.name_ref, Name):
|
|
3117
|
-
return self.name_ref.value
|
|
3118
|
-
elif isinstance(self.name_ref, SpecialVarRef):
|
|
3119
|
-
return self.name_ref.py_resolve_name()
|
|
3120
|
-
else:
|
|
3121
|
-
raise NotImplementedError
|
|
3122
|
-
|
|
3123
|
-
|
|
3124
|
-
class SpecialVarRef(NameSpec):
|
|
3125
|
-
"""HereRef node type for Jac Ast."""
|
|
3126
|
-
|
|
3127
|
-
def __init__(
|
|
3128
|
-
self,
|
|
3129
|
-
var: Token,
|
|
3130
|
-
kid: Sequence[AstNode],
|
|
3131
|
-
) -> None:
|
|
3132
|
-
"""Initialize special var reference expression node."""
|
|
3133
|
-
self.var = var
|
|
3197
|
+
self.arch_name = arch_name
|
|
3198
|
+
self.arch_type = arch_type
|
|
3134
3199
|
AstNode.__init__(self, kid=kid)
|
|
3135
3200
|
AstSymbolNode.__init__(
|
|
3136
3201
|
self,
|
|
3137
|
-
sym_name=
|
|
3138
|
-
|
|
3139
|
-
|
|
3202
|
+
sym_name=arch_name.sym_name,
|
|
3203
|
+
name_spec=arch_name,
|
|
3204
|
+
sym_category=SymbolType.TYPE,
|
|
3140
3205
|
)
|
|
3141
|
-
NameSpec.__init__(self)
|
|
3142
3206
|
|
|
3143
3207
|
def normalize(self, deep: bool = False) -> bool:
|
|
3144
3208
|
"""Normalize ast node."""
|
|
3145
3209
|
res = True
|
|
3146
3210
|
if deep:
|
|
3147
|
-
res = self.
|
|
3148
|
-
new_kid: list[AstNode] = [self.
|
|
3211
|
+
res = self.arch_name.normalize(deep)
|
|
3212
|
+
new_kid: list[AstNode] = [self.arch_type, self.arch_name]
|
|
3149
3213
|
self.set_kids(nodes=new_kid)
|
|
3150
3214
|
return res
|
|
3151
3215
|
|
|
3152
|
-
def py_resolve_name(self) -> str:
|
|
3153
|
-
"""Resolve name."""
|
|
3154
|
-
if self.var.name == Tok.KW_SELF:
|
|
3155
|
-
return "self"
|
|
3156
|
-
elif self.var.name == Tok.KW_SUPER:
|
|
3157
|
-
return "super()"
|
|
3158
|
-
elif self.var.name == Tok.KW_ROOT:
|
|
3159
|
-
return Con.ROOT.value
|
|
3160
|
-
elif self.var.name == Tok.KW_HERE:
|
|
3161
|
-
return Con.HERE.value
|
|
3162
|
-
elif self.var.name == Tok.KW_INIT:
|
|
3163
|
-
return "__init__"
|
|
3164
|
-
elif self.var.name == Tok.KW_POST_INIT:
|
|
3165
|
-
return "__post_init__"
|
|
3166
|
-
else:
|
|
3167
|
-
raise NotImplementedError("ICE: Special var reference not implemented")
|
|
3168
|
-
|
|
3169
3216
|
|
|
3170
3217
|
class EdgeRefTrailer(Expr):
|
|
3171
3218
|
"""EdgeRefTrailer node type for Jac Ast."""
|
|
@@ -3210,12 +3257,7 @@ class EdgeOpRef(WalkerStmtOnlyNode, AtomExpr):
|
|
|
3210
3257
|
self.edge_dir = edge_dir
|
|
3211
3258
|
AstNode.__init__(self, kid=kid)
|
|
3212
3259
|
WalkerStmtOnlyNode.__init__(self)
|
|
3213
|
-
|
|
3214
|
-
self,
|
|
3215
|
-
sym_name=f"[{self.__class__.__name__}]",
|
|
3216
|
-
sym_name_node=self,
|
|
3217
|
-
sym_type=SymbolType.SEQUENCE,
|
|
3218
|
-
)
|
|
3260
|
+
AstSymbolStubNode.__init__(self, sym_type=SymbolType.SEQUENCE)
|
|
3219
3261
|
|
|
3220
3262
|
def normalize(self, deep: bool = False) -> bool:
|
|
3221
3263
|
"""Normalize ast node."""
|
|
@@ -3344,12 +3386,7 @@ class FilterCompr(AtomExpr):
|
|
|
3344
3386
|
self.f_type = f_type
|
|
3345
3387
|
self.compares = compares
|
|
3346
3388
|
AstNode.__init__(self, kid=kid)
|
|
3347
|
-
|
|
3348
|
-
self,
|
|
3349
|
-
sym_name=f"[{self.__class__.__name__}]",
|
|
3350
|
-
sym_name_node=self,
|
|
3351
|
-
sym_type=SymbolType.SEQUENCE,
|
|
3352
|
-
)
|
|
3389
|
+
AstSymbolStubNode.__init__(self, sym_type=SymbolType.SEQUENCE)
|
|
3353
3390
|
|
|
3354
3391
|
def normalize(self, deep: bool = False) -> bool:
|
|
3355
3392
|
"""Normalize ast node."""
|
|
@@ -3386,12 +3423,7 @@ class AssignCompr(AtomExpr):
|
|
|
3386
3423
|
"""Initialize assign compr expression node."""
|
|
3387
3424
|
self.assigns = assigns
|
|
3388
3425
|
AstNode.__init__(self, kid=kid)
|
|
3389
|
-
|
|
3390
|
-
self,
|
|
3391
|
-
sym_name=f"[{self.__class__.__name__}]",
|
|
3392
|
-
sym_name_node=self,
|
|
3393
|
-
sym_type=SymbolType.SEQUENCE,
|
|
3394
|
-
)
|
|
3426
|
+
AstSymbolStubNode.__init__(self, sym_type=SymbolType.SEQUENCE)
|
|
3395
3427
|
|
|
3396
3428
|
def normalize(self, deep: bool = False) -> bool:
|
|
3397
3429
|
"""Normalize ast node."""
|
|
@@ -3515,7 +3547,7 @@ class MatchAs(MatchPattern):
|
|
|
3515
3547
|
|
|
3516
3548
|
def __init__(
|
|
3517
3549
|
self,
|
|
3518
|
-
name:
|
|
3550
|
+
name: NameAtom,
|
|
3519
3551
|
pattern: Optional[MatchPattern],
|
|
3520
3552
|
kid: Sequence[AstNode],
|
|
3521
3553
|
) -> None:
|
|
@@ -3554,6 +3586,7 @@ class MatchWild(MatchPattern):
|
|
|
3554
3586
|
col_start=self.loc.col_start,
|
|
3555
3587
|
col_end=self.loc.col_end,
|
|
3556
3588
|
line=self.loc.first_line,
|
|
3589
|
+
end_line=self.loc.last_line,
|
|
3557
3590
|
pos_start=self.loc.pos_start,
|
|
3558
3591
|
pos_end=self.loc.pos_end,
|
|
3559
3592
|
)
|
|
@@ -3663,7 +3696,7 @@ class MatchKVPair(MatchPattern):
|
|
|
3663
3696
|
|
|
3664
3697
|
def __init__(
|
|
3665
3698
|
self,
|
|
3666
|
-
key: MatchPattern |
|
|
3699
|
+
key: MatchPattern | NameAtom,
|
|
3667
3700
|
value: MatchPattern,
|
|
3668
3701
|
kid: Sequence[AstNode],
|
|
3669
3702
|
) -> None:
|
|
@@ -3691,7 +3724,7 @@ class MatchStar(MatchPattern):
|
|
|
3691
3724
|
|
|
3692
3725
|
def __init__(
|
|
3693
3726
|
self,
|
|
3694
|
-
name:
|
|
3727
|
+
name: NameAtom,
|
|
3695
3728
|
is_list: bool,
|
|
3696
3729
|
kid: Sequence[AstNode],
|
|
3697
3730
|
) -> None:
|
|
@@ -3718,7 +3751,7 @@ class MatchArch(MatchPattern):
|
|
|
3718
3751
|
|
|
3719
3752
|
def __init__(
|
|
3720
3753
|
self,
|
|
3721
|
-
name: AtomTrailer |
|
|
3754
|
+
name: AtomTrailer | NameAtom,
|
|
3722
3755
|
arg_patterns: Optional[SubNodeList[MatchPattern]],
|
|
3723
3756
|
kw_patterns: Optional[SubNodeList[MatchKVPair]],
|
|
3724
3757
|
kid: Sequence[AstNode],
|
|
@@ -3761,6 +3794,7 @@ class Token(AstNode):
|
|
|
3761
3794
|
name: str,
|
|
3762
3795
|
value: str,
|
|
3763
3796
|
line: int,
|
|
3797
|
+
end_line: int,
|
|
3764
3798
|
col_start: int,
|
|
3765
3799
|
col_end: int,
|
|
3766
3800
|
pos_start: int,
|
|
@@ -3771,6 +3805,7 @@ class Token(AstNode):
|
|
|
3771
3805
|
self.name = name
|
|
3772
3806
|
self.value = value
|
|
3773
3807
|
self.line_no = line
|
|
3808
|
+
self.end_line = end_line
|
|
3774
3809
|
self.c_start = col_start
|
|
3775
3810
|
self.c_end = col_end
|
|
3776
3811
|
self.pos_start = pos_start
|
|
@@ -3786,7 +3821,7 @@ class Token(AstNode):
|
|
|
3786
3821
|
return self.value
|
|
3787
3822
|
|
|
3788
3823
|
|
|
3789
|
-
class Name(Token,
|
|
3824
|
+
class Name(Token, NameAtom):
|
|
3790
3825
|
"""Name node type for Jac Ast."""
|
|
3791
3826
|
|
|
3792
3827
|
def __init__(
|
|
@@ -3795,6 +3830,7 @@ class Name(Token, NameSpec):
|
|
|
3795
3830
|
name: str,
|
|
3796
3831
|
value: str,
|
|
3797
3832
|
line: int,
|
|
3833
|
+
end_line: int,
|
|
3798
3834
|
col_start: int,
|
|
3799
3835
|
col_end: int,
|
|
3800
3836
|
pos_start: int,
|
|
@@ -3811,18 +3847,19 @@ class Name(Token, NameSpec):
|
|
|
3811
3847
|
name=name,
|
|
3812
3848
|
value=value,
|
|
3813
3849
|
line=line,
|
|
3850
|
+
end_line=end_line,
|
|
3814
3851
|
col_start=col_start,
|
|
3815
3852
|
col_end=col_end,
|
|
3816
3853
|
pos_start=pos_start,
|
|
3817
3854
|
pos_end=pos_end,
|
|
3818
3855
|
)
|
|
3856
|
+
NameAtom.__init__(self)
|
|
3819
3857
|
AstSymbolNode.__init__(
|
|
3820
3858
|
self,
|
|
3821
3859
|
sym_name=value,
|
|
3822
|
-
|
|
3823
|
-
|
|
3860
|
+
name_spec=self,
|
|
3861
|
+
sym_category=SymbolType.VAR,
|
|
3824
3862
|
)
|
|
3825
|
-
NameSpec.__init__(self)
|
|
3826
3863
|
|
|
3827
3864
|
def unparse(self) -> str:
|
|
3828
3865
|
"""Unparse name."""
|
|
@@ -3831,6 +3868,71 @@ class Name(Token, NameSpec):
|
|
|
3831
3868
|
",\n" if self.is_enum_singleton else ""
|
|
3832
3869
|
)
|
|
3833
3870
|
|
|
3871
|
+
@staticmethod
|
|
3872
|
+
def gen_stub_from_node(node: AstSymbolNode, name_str: str) -> Name:
|
|
3873
|
+
"""Generate name from node."""
|
|
3874
|
+
ret = Name(
|
|
3875
|
+
file_path=node.loc.mod_path,
|
|
3876
|
+
name=Tok.NAME.value,
|
|
3877
|
+
value=name_str,
|
|
3878
|
+
col_start=node.loc.col_start,
|
|
3879
|
+
col_end=node.loc.col_end,
|
|
3880
|
+
line=node.loc.first_line,
|
|
3881
|
+
end_line=node.loc.last_line,
|
|
3882
|
+
pos_start=node.loc.pos_start,
|
|
3883
|
+
pos_end=node.loc.pos_end,
|
|
3884
|
+
)
|
|
3885
|
+
ret.name_of = node
|
|
3886
|
+
ret.sym_tab = node.sym_tab
|
|
3887
|
+
return ret
|
|
3888
|
+
|
|
3889
|
+
|
|
3890
|
+
class SpecialVarRef(Name):
|
|
3891
|
+
"""HereRef node type for Jac Ast."""
|
|
3892
|
+
|
|
3893
|
+
def __init__(
|
|
3894
|
+
self,
|
|
3895
|
+
var: Name,
|
|
3896
|
+
) -> None:
|
|
3897
|
+
"""Initialize special var reference expression node."""
|
|
3898
|
+
self.orig = var
|
|
3899
|
+
Name.__init__(
|
|
3900
|
+
self,
|
|
3901
|
+
file_path=var.file_path,
|
|
3902
|
+
name=var.name,
|
|
3903
|
+
value=self.py_resolve_name(), # TODO: This shouldnt be necessary
|
|
3904
|
+
line=var.line_no,
|
|
3905
|
+
end_line=var.end_line,
|
|
3906
|
+
col_start=var.c_start,
|
|
3907
|
+
col_end=var.c_end,
|
|
3908
|
+
pos_start=var.pos_start,
|
|
3909
|
+
pos_end=var.pos_end,
|
|
3910
|
+
)
|
|
3911
|
+
NameAtom.__init__(self)
|
|
3912
|
+
AstSymbolNode.__init__(
|
|
3913
|
+
self,
|
|
3914
|
+
sym_name=self.py_resolve_name(),
|
|
3915
|
+
name_spec=self,
|
|
3916
|
+
sym_category=SymbolType.VAR,
|
|
3917
|
+
)
|
|
3918
|
+
|
|
3919
|
+
def py_resolve_name(self) -> str:
|
|
3920
|
+
"""Resolve name."""
|
|
3921
|
+
if self.orig.name == Tok.KW_SELF:
|
|
3922
|
+
return "self"
|
|
3923
|
+
elif self.orig.name == Tok.KW_SUPER:
|
|
3924
|
+
return "super"
|
|
3925
|
+
elif self.orig.name == Tok.KW_ROOT:
|
|
3926
|
+
return Con.ROOT.value
|
|
3927
|
+
elif self.orig.name == Tok.KW_HERE:
|
|
3928
|
+
return Con.HERE.value
|
|
3929
|
+
elif self.orig.name == Tok.KW_INIT:
|
|
3930
|
+
return "__init__"
|
|
3931
|
+
elif self.orig.name == Tok.KW_POST_INIT:
|
|
3932
|
+
return "__post_init__"
|
|
3933
|
+
else:
|
|
3934
|
+
raise NotImplementedError("ICE: Special var reference not implemented")
|
|
3935
|
+
|
|
3834
3936
|
|
|
3835
3937
|
class Literal(Token, AtomExpr):
|
|
3836
3938
|
"""Literal node type for Jac Ast."""
|
|
@@ -3856,6 +3958,7 @@ class Literal(Token, AtomExpr):
|
|
|
3856
3958
|
name: str,
|
|
3857
3959
|
value: str,
|
|
3858
3960
|
line: int,
|
|
3961
|
+
end_line: int,
|
|
3859
3962
|
col_start: int,
|
|
3860
3963
|
col_end: int,
|
|
3861
3964
|
pos_start: int,
|
|
@@ -3868,17 +3971,13 @@ class Literal(Token, AtomExpr):
|
|
|
3868
3971
|
name=name,
|
|
3869
3972
|
value=value,
|
|
3870
3973
|
line=line,
|
|
3974
|
+
end_line=end_line,
|
|
3871
3975
|
col_start=col_start,
|
|
3872
3976
|
col_end=col_end,
|
|
3873
3977
|
pos_start=pos_start,
|
|
3874
3978
|
pos_end=pos_end,
|
|
3875
3979
|
)
|
|
3876
|
-
|
|
3877
|
-
self,
|
|
3878
|
-
sym_name=f"[{self.__class__.__name__}]",
|
|
3879
|
-
sym_name_node=self,
|
|
3880
|
-
sym_type=self.SYMBOL_TYPE,
|
|
3881
|
-
)
|
|
3980
|
+
AstSymbolStubNode.__init__(self, sym_type=self.SYMBOL_TYPE)
|
|
3882
3981
|
|
|
3883
3982
|
@property
|
|
3884
3983
|
def lit_value(
|
|
@@ -3888,43 +3987,7 @@ class Literal(Token, AtomExpr):
|
|
|
3888
3987
|
raise NotImplementedError
|
|
3889
3988
|
|
|
3890
3989
|
|
|
3891
|
-
class
|
|
3892
|
-
"""TokenSymbol node type for Jac Ast."""
|
|
3893
|
-
|
|
3894
|
-
SYMBOL_TYPE = SymbolType.VAR
|
|
3895
|
-
|
|
3896
|
-
def __init__(
|
|
3897
|
-
self,
|
|
3898
|
-
file_path: str,
|
|
3899
|
-
name: str,
|
|
3900
|
-
value: str,
|
|
3901
|
-
line: int,
|
|
3902
|
-
col_start: int,
|
|
3903
|
-
col_end: int,
|
|
3904
|
-
pos_start: int,
|
|
3905
|
-
pos_end: int,
|
|
3906
|
-
) -> None:
|
|
3907
|
-
"""Initialize token."""
|
|
3908
|
-
Token.__init__(
|
|
3909
|
-
self,
|
|
3910
|
-
file_path=file_path,
|
|
3911
|
-
name=name,
|
|
3912
|
-
value=value,
|
|
3913
|
-
line=line,
|
|
3914
|
-
col_start=col_start,
|
|
3915
|
-
col_end=col_end,
|
|
3916
|
-
pos_start=pos_start,
|
|
3917
|
-
pos_end=pos_end,
|
|
3918
|
-
)
|
|
3919
|
-
AstSymbolNode.__init__(
|
|
3920
|
-
self,
|
|
3921
|
-
sym_name=f"[{self.__class__.__name__}]",
|
|
3922
|
-
sym_name_node=self,
|
|
3923
|
-
sym_type=self.SYMBOL_TYPE,
|
|
3924
|
-
)
|
|
3925
|
-
|
|
3926
|
-
|
|
3927
|
-
class BuiltinType(Name, Literal, NameSpec):
|
|
3990
|
+
class BuiltinType(Name, Literal, NameAtom):
|
|
3928
3991
|
"""Type node type for Jac Ast."""
|
|
3929
3992
|
|
|
3930
3993
|
SYMBOL_TYPE = SymbolType.VAR
|
|
@@ -4037,6 +4100,7 @@ class EmptyToken(Token):
|
|
|
4037
4100
|
file_path="",
|
|
4038
4101
|
value="",
|
|
4039
4102
|
line=0,
|
|
4103
|
+
end_line=0,
|
|
4040
4104
|
col_start=0,
|
|
4041
4105
|
col_end=0,
|
|
4042
4106
|
pos_start=0,
|