jaclang 0.7.1__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 +378 -277
- 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 +29 -11
- jaclang/compiler/passes/main/def_use_pass.py +48 -17
- jaclang/compiler/passes/main/fuse_typeinfo_pass.py +49 -30
- jaclang/compiler/passes/main/import_pass.py +12 -7
- jaclang/compiler/passes/main/pyast_gen_pass.py +110 -47
- jaclang/compiler/passes/main/pyast_load_pass.py +49 -13
- jaclang/compiler/passes/main/pyjac_ast_link_pass.py +25 -11
- jaclang/compiler/passes/main/pyout_pass.py +3 -1
- 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/tests/test_import_pass.py +8 -0
- jaclang/compiler/passes/main/tests/test_type_check_pass.py +1 -1
- jaclang/compiler/passes/main/type_check_pass.py +2 -1
- jaclang/compiler/passes/tool/jac_formatter_pass.py +44 -11
- jaclang/compiler/passes/tool/tests/fixtures/corelib.jac +16 -0
- jaclang/compiler/passes/tool/tests/fixtures/corelib_fmt.jac +16 -0
- jaclang/compiler/passes/tool/tests/fixtures/doc_string.jac +15 -0
- jaclang/compiler/passes/tool/tests/test_jac_format_pass.py +7 -5
- jaclang/compiler/passes/tool/tests/test_unparse_validate.py +1 -2
- jaclang/compiler/passes/transform.py +2 -4
- jaclang/{core/registry.py → compiler/semtable.py} +1 -3
- jaclang/compiler/symtable.py +39 -31
- jaclang/compiler/tests/test_parser.py +2 -2
- jaclang/core/aott.py +112 -16
- jaclang/core/{construct.py → architype.py} +44 -93
- jaclang/core/constructs.py +44 -0
- jaclang/core/context.py +157 -0
- jaclang/core/importer.py +18 -9
- jaclang/core/llms/anthropic.py +31 -2
- jaclang/core/llms/base.py +3 -3
- jaclang/core/llms/groq.py +4 -1
- jaclang/core/llms/huggingface.py +4 -1
- jaclang/core/llms/ollama.py +4 -1
- jaclang/core/llms/openai.py +6 -2
- jaclang/core/llms/togetherai.py +4 -1
- jaclang/core/memory.py +53 -2
- jaclang/core/test.py +90 -0
- jaclang/core/utils.py +2 -2
- jaclang/langserve/engine.py +119 -122
- jaclang/langserve/server.py +27 -5
- jaclang/langserve/tests/fixtures/circle.jac +16 -12
- jaclang/langserve/tests/fixtures/circle_err.jac +3 -3
- jaclang/langserve/tests/fixtures/circle_pure.impl.jac +8 -4
- jaclang/langserve/tests/fixtures/circle_pure.jac +2 -2
- jaclang/langserve/tests/test_server.py +114 -0
- jaclang/langserve/utils.py +104 -10
- jaclang/plugin/builtin.py +1 -1
- jaclang/plugin/default.py +46 -90
- jaclang/plugin/feature.py +32 -16
- jaclang/plugin/spec.py +17 -19
- jaclang/plugin/tests/test_features.py +0 -33
- jaclang/settings.py +4 -0
- jaclang/tests/fixtures/abc.jac +16 -12
- jaclang/tests/fixtures/byllmissue.jac +12 -0
- jaclang/tests/fixtures/edgetypetest.jac +16 -0
- jaclang/tests/fixtures/hash_init_check.jac +17 -0
- jaclang/tests/fixtures/impl_match_confused.impl.jac +1 -0
- jaclang/tests/fixtures/impl_match_confused.jac +5 -0
- jaclang/tests/fixtures/math_question.jpg +0 -0
- jaclang/tests/fixtures/maxfail_run_test.jac +17 -5
- jaclang/tests/fixtures/nosigself.jac +19 -0
- jaclang/tests/fixtures/run_test.jac +17 -5
- jaclang/tests/fixtures/walker_override.jac +21 -0
- jaclang/tests/fixtures/with_llm_vision.jac +25 -0
- jaclang/tests/test_bugs.py +19 -0
- jaclang/tests/test_cli.py +1 -1
- jaclang/tests/test_language.py +116 -11
- jaclang/tests/test_reference.py +1 -1
- jaclang/utils/lang_tools.py +5 -4
- jaclang/utils/test.py +2 -1
- jaclang/utils/treeprinter.py +35 -4
- {jaclang-0.7.1.dist-info → jaclang-0.7.5.dist-info}/METADATA +3 -2
- {jaclang-0.7.1.dist-info → jaclang-0.7.5.dist-info}/RECORD +84 -71
- jaclang/core/shelve_storage.py +0 -55
- {jaclang-0.7.1.dist-info → jaclang-0.7.5.dist-info}/WHEEL +0 -0
- {jaclang-0.7.1.dist-info → jaclang-0.7.5.dist-info}/entry_points.txt +0 -0
jaclang/compiler/absyntree.py
CHANGED
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
from __future__ import annotations
|
|
4
4
|
|
|
5
5
|
import ast as ast3
|
|
6
|
+
import os
|
|
6
7
|
from hashlib import md5
|
|
7
8
|
from types import EllipsisType
|
|
8
9
|
from typing import Any, Callable, Generic, Optional, Sequence, Type, TypeVar
|
|
@@ -11,14 +12,13 @@ from jaclang.compiler import TOKEN_MAP
|
|
|
11
12
|
from jaclang.compiler.codeloc import CodeGenTarget, CodeLocInfo
|
|
12
13
|
from jaclang.compiler.constant import Constants as Con, EdgeDir
|
|
13
14
|
from jaclang.compiler.constant import DELIM_MAP, Tokens as Tok
|
|
15
|
+
from jaclang.compiler.semtable import SemRegistry
|
|
14
16
|
from jaclang.compiler.symtable import (
|
|
15
17
|
Symbol,
|
|
16
18
|
SymbolAccess,
|
|
17
|
-
SymbolInfo,
|
|
18
19
|
SymbolTable,
|
|
19
20
|
SymbolType,
|
|
20
21
|
)
|
|
21
|
-
from jaclang.core.registry import SemRegistry
|
|
22
22
|
from jaclang.utils.treeprinter import dotgen_ast_tree, print_ast_tree
|
|
23
23
|
|
|
24
24
|
|
|
@@ -31,7 +31,6 @@ class AstNode:
|
|
|
31
31
|
self.kid: list[AstNode] = [x.set_parent(self) for x in kid]
|
|
32
32
|
self.sym_tab: Optional[SymbolTable] = None
|
|
33
33
|
self._sub_node_tab: dict[type, list[AstNode]] = {}
|
|
34
|
-
self._typ: type = type(None)
|
|
35
34
|
self.gen: CodeGenTarget = CodeGenTarget()
|
|
36
35
|
self.meta: dict[str, str] = {}
|
|
37
36
|
self.loc: CodeLocInfo = CodeLocInfo(*self.resolve_tok_range())
|
|
@@ -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
|
)
|
|
@@ -111,11 +122,15 @@ class AstNode:
|
|
|
111
122
|
|
|
112
123
|
return Pass.get_all_sub_nodes(node=self, typ=typ, brute_force=brute_force)
|
|
113
124
|
|
|
114
|
-
def
|
|
125
|
+
def find_parent_of_type(self, typ: Type[T]) -> Optional[T]:
|
|
115
126
|
"""Get parent of type."""
|
|
116
127
|
from jaclang.compiler.passes import Pass
|
|
117
128
|
|
|
118
|
-
|
|
129
|
+
return Pass.has_parent_of_type(node=self, typ=typ)
|
|
130
|
+
|
|
131
|
+
def parent_of_type(self, typ: Type[T]) -> T:
|
|
132
|
+
"""Get parent of type."""
|
|
133
|
+
ret = self.find_parent_of_type(typ)
|
|
119
134
|
if isinstance(ret, typ):
|
|
120
135
|
return ret
|
|
121
136
|
else:
|
|
@@ -172,15 +187,56 @@ class AstSymbolNode(AstNode):
|
|
|
172
187
|
"""Nodes that have link to a symbol in symbol table."""
|
|
173
188
|
|
|
174
189
|
def __init__(
|
|
175
|
-
self, sym_name: str,
|
|
190
|
+
self, sym_name: str, name_spec: NameAtom, sym_category: SymbolType
|
|
176
191
|
) -> None:
|
|
177
192
|
"""Initialize ast."""
|
|
178
|
-
self.
|
|
179
|
-
self.
|
|
180
|
-
self.
|
|
181
|
-
self.
|
|
182
|
-
|
|
183
|
-
|
|
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
|
+
)
|
|
184
240
|
|
|
185
241
|
|
|
186
242
|
class AstAccessNode(AstNode):
|
|
@@ -255,13 +311,62 @@ class WalkerStmtOnlyNode(AstNode):
|
|
|
255
311
|
self.from_walker: bool = False
|
|
256
312
|
|
|
257
313
|
|
|
258
|
-
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):
|
|
259
339
|
"""ImplOnly node type for Jac Ast."""
|
|
260
340
|
|
|
261
|
-
def __init__(
|
|
341
|
+
def __init__(
|
|
342
|
+
self, target: ArchRefChain, body: SubNodeList, decl_link: Optional[AstNode]
|
|
343
|
+
) -> None:
|
|
262
344
|
"""Initialize impl only node."""
|
|
345
|
+
self.target = target
|
|
263
346
|
self.body = body
|
|
264
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
|
|
265
370
|
|
|
266
371
|
|
|
267
372
|
class AstImplNeedingNode(AstSymbolNode, Generic[T]):
|
|
@@ -277,32 +382,74 @@ class AstImplNeedingNode(AstSymbolNode, Generic[T]):
|
|
|
277
382
|
return self.body is None
|
|
278
383
|
|
|
279
384
|
|
|
280
|
-
class
|
|
281
|
-
"""
|
|
385
|
+
class NameAtom(AtomExpr, EnumBlockStmt):
|
|
386
|
+
"""NameSpec node type for Jac Ast."""
|
|
282
387
|
|
|
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
|
|
283
397
|
|
|
284
|
-
|
|
285
|
-
|
|
398
|
+
@property
|
|
399
|
+
def sym(self) -> Optional[Symbol]:
|
|
400
|
+
"""Get symbol."""
|
|
401
|
+
return self._sym
|
|
286
402
|
|
|
403
|
+
@sym.setter
|
|
404
|
+
def sym(self, sym: Symbol) -> None:
|
|
405
|
+
"""Set symbol."""
|
|
406
|
+
self._sym = sym
|
|
287
407
|
|
|
288
|
-
|
|
289
|
-
|
|
408
|
+
@property
|
|
409
|
+
def sym_name(self) -> str:
|
|
410
|
+
"""Get symbol name."""
|
|
411
|
+
return self._sym_name
|
|
290
412
|
|
|
413
|
+
@property
|
|
414
|
+
def sym_category(self) -> SymbolType:
|
|
415
|
+
"""Get symbol category."""
|
|
416
|
+
return self._sym_category
|
|
291
417
|
|
|
292
|
-
|
|
293
|
-
|
|
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
|
|
294
423
|
|
|
424
|
+
@property
|
|
425
|
+
def py_ctx_func(self) -> Type[ast3.AST]:
|
|
426
|
+
"""Get python context function."""
|
|
427
|
+
return self._py_ctx_func
|
|
295
428
|
|
|
296
|
-
|
|
297
|
-
|
|
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
|
|
298
433
|
|
|
434
|
+
@property
|
|
435
|
+
def sym_type(self) -> str:
|
|
436
|
+
"""Get symbol type."""
|
|
437
|
+
return self._sym_type
|
|
299
438
|
|
|
300
|
-
|
|
301
|
-
|
|
439
|
+
@sym_type.setter
|
|
440
|
+
def sym_type(self, sym_type: str) -> None:
|
|
441
|
+
"""Set symbol type."""
|
|
442
|
+
self._sym_type = sym_type
|
|
302
443
|
|
|
444
|
+
@property
|
|
445
|
+
def type_sym_tab(self) -> Optional[SymbolTable]:
|
|
446
|
+
"""Get type symbol table."""
|
|
447
|
+
return self._type_sym_tab
|
|
303
448
|
|
|
304
|
-
|
|
305
|
-
|
|
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
|
|
306
453
|
|
|
307
454
|
|
|
308
455
|
class ArchSpec(ElementStmt, CodeBlockStmt, AstSymbolNode, AstDocNode, AstSemStrNode):
|
|
@@ -392,7 +539,7 @@ class Module(AstDocNode):
|
|
|
392
539
|
body: Sequence[ElementStmt | String | EmptyToken],
|
|
393
540
|
is_imported: bool,
|
|
394
541
|
kid: Sequence[AstNode],
|
|
395
|
-
|
|
542
|
+
stub_only: bool = False,
|
|
396
543
|
registry: Optional[SemRegistry] = None,
|
|
397
544
|
) -> None:
|
|
398
545
|
"""Initialize whole program node."""
|
|
@@ -400,13 +547,37 @@ class Module(AstDocNode):
|
|
|
400
547
|
self.source = source
|
|
401
548
|
self.body = body
|
|
402
549
|
self.is_imported = is_imported
|
|
550
|
+
self.stub_only = stub_only
|
|
403
551
|
self.impl_mod: list[Module] = []
|
|
404
|
-
self.test_mod =
|
|
552
|
+
self.test_mod: list[Module] = []
|
|
405
553
|
self.mod_deps: dict[str, Module] = {}
|
|
406
554
|
self.registry = registry
|
|
407
555
|
AstNode.__init__(self, kid=kid)
|
|
408
556
|
AstDocNode.__init__(self, doc=doc)
|
|
409
557
|
|
|
558
|
+
@property
|
|
559
|
+
def annexable_by(self) -> Optional[str]:
|
|
560
|
+
"""Get annexable by."""
|
|
561
|
+
if not self.stub_only and self.loc.mod_path.endswith("impl.jac"):
|
|
562
|
+
head_mod_name = self.name.split(".")[0]
|
|
563
|
+
potential_path = os.path.join(
|
|
564
|
+
os.path.dirname(self.loc.mod_path),
|
|
565
|
+
f"{head_mod_name}.jac",
|
|
566
|
+
)
|
|
567
|
+
if os.path.exists(potential_path):
|
|
568
|
+
return potential_path
|
|
569
|
+
if os.path.split(os.path.dirname(self.loc.mod_path))[-1].endswith(".impl"):
|
|
570
|
+
head_mod_name = os.path.split(os.path.dirname(self.loc.mod_path))[
|
|
571
|
+
-1
|
|
572
|
+
].split(".")[0]
|
|
573
|
+
potential_path = os.path.join(
|
|
574
|
+
os.path.dirname(os.path.dirname(self.loc.mod_path)),
|
|
575
|
+
f"{head_mod_name}.jac",
|
|
576
|
+
)
|
|
577
|
+
if os.path.exists(potential_path):
|
|
578
|
+
return potential_path
|
|
579
|
+
return None
|
|
580
|
+
|
|
410
581
|
def normalize(self, deep: bool = False) -> bool:
|
|
411
582
|
"""Normalize module node."""
|
|
412
583
|
res = True
|
|
@@ -485,26 +656,31 @@ class Test(AstSymbolNode, ElementStmt):
|
|
|
485
656
|
if isinstance(name, Name)
|
|
486
657
|
else Name(
|
|
487
658
|
file_path=name.file_path,
|
|
488
|
-
name=
|
|
489
|
-
value=f"
|
|
659
|
+
name=Tok.NAME.value,
|
|
660
|
+
value=f"_jac_gen_{Test.TEST_COUNT}",
|
|
490
661
|
col_start=name.loc.col_start,
|
|
491
662
|
col_end=name.loc.col_end,
|
|
492
663
|
line=name.loc.first_line,
|
|
664
|
+
end_line=name.loc.last_line,
|
|
493
665
|
pos_start=name.pos_start,
|
|
494
666
|
pos_end=name.pos_end,
|
|
495
667
|
)
|
|
496
668
|
)
|
|
497
669
|
self.name.parent = self
|
|
498
|
-
|
|
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
|
+
)
|
|
499
675
|
self.body = body
|
|
500
676
|
AstNode.__init__(self, kid=kid)
|
|
501
677
|
if self.name not in self.kid:
|
|
502
|
-
self.
|
|
678
|
+
self.insert_kids_at_pos([self.name], pos=1, pos_update=False)
|
|
503
679
|
AstSymbolNode.__init__(
|
|
504
680
|
self,
|
|
505
681
|
sym_name=self.name.sym_name,
|
|
506
|
-
|
|
507
|
-
|
|
682
|
+
name_spec=self.name,
|
|
683
|
+
sym_category=SymbolType.TEST,
|
|
508
684
|
)
|
|
509
685
|
AstDocNode.__init__(self, doc=doc)
|
|
510
686
|
|
|
@@ -653,12 +829,15 @@ class ModulePath(AstSymbolNode):
|
|
|
653
829
|
self.alias = alias
|
|
654
830
|
self.sub_module = sub_module
|
|
655
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.")
|
|
656
835
|
AstNode.__init__(self, kid=kid)
|
|
657
836
|
AstSymbolNode.__init__(
|
|
658
837
|
self,
|
|
659
|
-
sym_name=
|
|
660
|
-
|
|
661
|
-
|
|
838
|
+
sym_name=name_spec.sym_name,
|
|
839
|
+
name_spec=name_spec,
|
|
840
|
+
sym_category=SymbolType.MODULE,
|
|
662
841
|
)
|
|
663
842
|
|
|
664
843
|
@property
|
|
@@ -711,8 +890,8 @@ class ModuleItem(AstSymbolNode):
|
|
|
711
890
|
AstSymbolNode.__init__(
|
|
712
891
|
self,
|
|
713
892
|
sym_name=alias.sym_name if alias else name.sym_name,
|
|
714
|
-
|
|
715
|
-
|
|
893
|
+
name_spec=alias if alias else name,
|
|
894
|
+
sym_category=SymbolType.MOD_VAR,
|
|
716
895
|
)
|
|
717
896
|
|
|
718
897
|
def normalize(self, deep: bool = False) -> bool:
|
|
@@ -752,8 +931,8 @@ class Architype(ArchSpec, AstAccessNode, ArchBlockStmt, AstImplNeedingNode):
|
|
|
752
931
|
AstSymbolNode.__init__(
|
|
753
932
|
self,
|
|
754
933
|
sym_name=name.value,
|
|
755
|
-
|
|
756
|
-
|
|
934
|
+
name_spec=name,
|
|
935
|
+
sym_category=(
|
|
757
936
|
SymbolType.OBJECT_ARCH
|
|
758
937
|
if arch_type.name == Tok.KW_OBJECT
|
|
759
938
|
else (
|
|
@@ -828,7 +1007,7 @@ class Architype(ArchSpec, AstAccessNode, ArchBlockStmt, AstImplNeedingNode):
|
|
|
828
1007
|
return res
|
|
829
1008
|
|
|
830
1009
|
|
|
831
|
-
class ArchDef(
|
|
1010
|
+
class ArchDef(AstImplOnlyNode):
|
|
832
1011
|
"""ArchDef node type for Jac Ast."""
|
|
833
1012
|
|
|
834
1013
|
def __init__(
|
|
@@ -841,17 +1020,9 @@ class ArchDef(ArchSpec, AstImplOnlyNode):
|
|
|
841
1020
|
decl_link: Optional[Architype] = None,
|
|
842
1021
|
) -> None:
|
|
843
1022
|
"""Initialize arch def node."""
|
|
844
|
-
self.target = target
|
|
845
1023
|
AstNode.__init__(self, kid=kid)
|
|
846
|
-
AstSymbolNode.__init__(
|
|
847
|
-
self,
|
|
848
|
-
sym_name=target.py_resolve_name(),
|
|
849
|
-
sym_name_node=target,
|
|
850
|
-
sym_type=SymbolType.IMPL,
|
|
851
|
-
)
|
|
852
1024
|
AstDocNode.__init__(self, doc=doc)
|
|
853
|
-
|
|
854
|
-
AstImplOnlyNode.__init__(self, body=body, decl_link=decl_link)
|
|
1025
|
+
AstImplOnlyNode.__init__(self, target=target, body=body, decl_link=decl_link)
|
|
855
1026
|
|
|
856
1027
|
def normalize(self, deep: bool = False) -> bool:
|
|
857
1028
|
"""Normalize arch def node."""
|
|
@@ -860,7 +1031,6 @@ class ArchDef(ArchSpec, AstImplOnlyNode):
|
|
|
860
1031
|
res = self.target.normalize(deep)
|
|
861
1032
|
res = res and self.body.normalize(deep)
|
|
862
1033
|
res = res and self.doc.normalize(deep) if self.doc else res
|
|
863
|
-
res = res and self.decorators.normalize(deep) if self.decorators else res
|
|
864
1034
|
new_kid: list[AstNode] = []
|
|
865
1035
|
if self.doc:
|
|
866
1036
|
new_kid.append(self.doc)
|
|
@@ -891,8 +1061,8 @@ class Enum(ArchSpec, AstAccessNode, AstImplNeedingNode, ArchBlockStmt):
|
|
|
891
1061
|
AstSymbolNode.__init__(
|
|
892
1062
|
self,
|
|
893
1063
|
sym_name=name.value,
|
|
894
|
-
|
|
895
|
-
|
|
1064
|
+
name_spec=name,
|
|
1065
|
+
sym_category=SymbolType.ENUM_ARCH,
|
|
896
1066
|
)
|
|
897
1067
|
AstImplNeedingNode.__init__(self, body=body)
|
|
898
1068
|
AstAccessNode.__init__(self, access=access)
|
|
@@ -939,7 +1109,7 @@ class Enum(ArchSpec, AstAccessNode, AstImplNeedingNode, ArchBlockStmt):
|
|
|
939
1109
|
return res
|
|
940
1110
|
|
|
941
1111
|
|
|
942
|
-
class EnumDef(
|
|
1112
|
+
class EnumDef(AstImplOnlyNode):
|
|
943
1113
|
"""EnumDef node type for Jac Ast."""
|
|
944
1114
|
|
|
945
1115
|
def __init__(
|
|
@@ -952,17 +1122,9 @@ class EnumDef(ArchSpec, AstImplOnlyNode):
|
|
|
952
1122
|
decl_link: Optional[Enum] = None,
|
|
953
1123
|
) -> None:
|
|
954
1124
|
"""Initialize arch def node."""
|
|
955
|
-
self.target = target
|
|
956
1125
|
AstNode.__init__(self, kid=kid)
|
|
957
|
-
AstSymbolNode.__init__(
|
|
958
|
-
self,
|
|
959
|
-
sym_name=target.py_resolve_name(),
|
|
960
|
-
sym_name_node=target,
|
|
961
|
-
sym_type=SymbolType.IMPL,
|
|
962
|
-
)
|
|
963
1126
|
AstDocNode.__init__(self, doc=doc)
|
|
964
|
-
|
|
965
|
-
AstImplOnlyNode.__init__(self, body=body, decl_link=decl_link)
|
|
1127
|
+
AstImplOnlyNode.__init__(self, target=target, body=body, decl_link=decl_link)
|
|
966
1128
|
|
|
967
1129
|
def normalize(self, deep: bool = False) -> bool:
|
|
968
1130
|
"""Normalize enum def node."""
|
|
@@ -971,7 +1133,6 @@ class EnumDef(ArchSpec, AstImplOnlyNode):
|
|
|
971
1133
|
res = self.target.normalize(deep)
|
|
972
1134
|
res = res and self.body.normalize(deep)
|
|
973
1135
|
res = res and self.doc.normalize(deep) if self.doc else res
|
|
974
|
-
res = res and self.decorators.normalize(deep) if self.decorators else res
|
|
975
1136
|
new_kid: list[AstNode] = []
|
|
976
1137
|
if self.doc:
|
|
977
1138
|
new_kid.append(self.doc)
|
|
@@ -996,13 +1157,13 @@ class Ability(
|
|
|
996
1157
|
|
|
997
1158
|
def __init__(
|
|
998
1159
|
self,
|
|
999
|
-
name_ref:
|
|
1160
|
+
name_ref: NameAtom,
|
|
1000
1161
|
is_async: bool,
|
|
1001
1162
|
is_override: bool,
|
|
1002
1163
|
is_static: bool,
|
|
1003
1164
|
is_abstract: bool,
|
|
1004
1165
|
access: Optional[SubTag[Token]],
|
|
1005
|
-
signature:
|
|
1166
|
+
signature: FuncSignature | EventSignature,
|
|
1006
1167
|
body: Optional[SubNodeList[CodeBlockStmt] | AbilityDef | FuncCall],
|
|
1007
1168
|
kid: Sequence[AstNode],
|
|
1008
1169
|
semstr: Optional[String] = None,
|
|
@@ -1022,17 +1183,17 @@ class Ability(
|
|
|
1022
1183
|
AstSymbolNode.__init__(
|
|
1023
1184
|
self,
|
|
1024
1185
|
sym_name=self.py_resolve_name(),
|
|
1025
|
-
|
|
1026
|
-
|
|
1186
|
+
name_spec=name_ref,
|
|
1187
|
+
sym_category=SymbolType.ABILITY,
|
|
1027
1188
|
)
|
|
1028
1189
|
AstAccessNode.__init__(self, access=access)
|
|
1029
1190
|
AstDocNode.__init__(self, doc=doc)
|
|
1030
1191
|
AstAsyncNode.__init__(self, is_async=is_async)
|
|
1031
1192
|
|
|
1032
1193
|
@property
|
|
1033
|
-
def
|
|
1194
|
+
def is_method(self) -> bool:
|
|
1034
1195
|
"""Check if is func."""
|
|
1035
|
-
return
|
|
1196
|
+
return self.signature.is_method
|
|
1036
1197
|
|
|
1037
1198
|
@property
|
|
1038
1199
|
def is_genai_ability(self) -> bool:
|
|
@@ -1097,7 +1258,7 @@ class Ability(
|
|
|
1097
1258
|
return res
|
|
1098
1259
|
|
|
1099
1260
|
|
|
1100
|
-
class AbilityDef(
|
|
1261
|
+
class AbilityDef(AstImplOnlyNode):
|
|
1101
1262
|
"""AbilityDef node type for Jac Ast."""
|
|
1102
1263
|
|
|
1103
1264
|
def __init__(
|
|
@@ -1111,18 +1272,11 @@ class AbilityDef(AstSymbolNode, ElementStmt, AstImplOnlyNode, CodeBlockStmt):
|
|
|
1111
1272
|
decl_link: Optional[Ability] = None,
|
|
1112
1273
|
) -> None:
|
|
1113
1274
|
"""Initialize ability def node."""
|
|
1114
|
-
self.target = target
|
|
1115
1275
|
self.signature = signature
|
|
1116
1276
|
self.decorators = decorators
|
|
1117
1277
|
AstNode.__init__(self, kid=kid)
|
|
1118
|
-
AstSymbolNode.__init__(
|
|
1119
|
-
self,
|
|
1120
|
-
sym_name=target.py_resolve_name(),
|
|
1121
|
-
sym_name_node=target,
|
|
1122
|
-
sym_type=SymbolType.IMPL,
|
|
1123
|
-
)
|
|
1124
1278
|
AstDocNode.__init__(self, doc=doc)
|
|
1125
|
-
AstImplOnlyNode.__init__(self, body=body, decl_link=decl_link)
|
|
1279
|
+
AstImplOnlyNode.__init__(self, target=target, body=body, decl_link=decl_link)
|
|
1126
1280
|
|
|
1127
1281
|
def normalize(self, deep: bool = False) -> bool:
|
|
1128
1282
|
"""Normalize ability def node."""
|
|
@@ -1158,6 +1312,7 @@ class FuncSignature(AstSemStrNode):
|
|
|
1158
1312
|
"""Initialize method signature node."""
|
|
1159
1313
|
self.params = params
|
|
1160
1314
|
self.return_type = return_type
|
|
1315
|
+
self.is_method = False
|
|
1161
1316
|
AstNode.__init__(self, kid=kid)
|
|
1162
1317
|
AstSemStrNode.__init__(self, semstr=semstr)
|
|
1163
1318
|
|
|
@@ -1206,6 +1361,7 @@ class EventSignature(AstSemStrNode):
|
|
|
1206
1361
|
self.event = event
|
|
1207
1362
|
self.arch_tag_info = arch_tag_info
|
|
1208
1363
|
self.return_type = return_type
|
|
1364
|
+
self.is_method = False
|
|
1209
1365
|
AstNode.__init__(self, kid=kid)
|
|
1210
1366
|
AstSemStrNode.__init__(self, semstr=semstr)
|
|
1211
1367
|
|
|
@@ -1264,11 +1420,11 @@ class ArchRefChain(AstNode):
|
|
|
1264
1420
|
def get_tag(x: ArchRef) -> str:
|
|
1265
1421
|
return (
|
|
1266
1422
|
"en"
|
|
1267
|
-
if x.
|
|
1268
|
-
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]
|
|
1269
1425
|
)
|
|
1270
1426
|
|
|
1271
|
-
return ".".join([f"({get_tag(x)}){x.
|
|
1427
|
+
return ".".join([f"({get_tag(x)}){x.sym_name}" for x in self.archs])
|
|
1272
1428
|
|
|
1273
1429
|
def flat_name(self) -> str:
|
|
1274
1430
|
"""Resolve name for python gen."""
|
|
@@ -1297,8 +1453,8 @@ class ParamVar(AstSymbolNode, AstTypedVarNode, AstSemStrNode):
|
|
|
1297
1453
|
AstSymbolNode.__init__(
|
|
1298
1454
|
self,
|
|
1299
1455
|
sym_name=name.value,
|
|
1300
|
-
|
|
1301
|
-
|
|
1456
|
+
name_spec=name,
|
|
1457
|
+
sym_category=SymbolType.VAR,
|
|
1302
1458
|
)
|
|
1303
1459
|
AstTypedVarNode.__init__(self, type_tag=type_tag)
|
|
1304
1460
|
AstSemStrNode.__init__(self, semstr=semstr)
|
|
@@ -1393,8 +1549,8 @@ class HasVar(AstSymbolNode, AstTypedVarNode, AstSemStrNode):
|
|
|
1393
1549
|
AstSymbolNode.__init__(
|
|
1394
1550
|
self,
|
|
1395
1551
|
sym_name=name.value,
|
|
1396
|
-
|
|
1397
|
-
|
|
1552
|
+
name_spec=name,
|
|
1553
|
+
sym_category=SymbolType.HAS_VAR,
|
|
1398
1554
|
)
|
|
1399
1555
|
AstTypedVarNode.__init__(self, type_tag=type_tag)
|
|
1400
1556
|
AstSemStrNode.__init__(self, semstr=semstr)
|
|
@@ -1909,6 +2065,32 @@ class AssertStmt(CodeBlockStmt):
|
|
|
1909
2065
|
return res
|
|
1910
2066
|
|
|
1911
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
|
+
|
|
1912
2094
|
class CtrlStmt(CodeBlockStmt):
|
|
1913
2095
|
"""CtrlStmt node type for Jac Ast."""
|
|
1914
2096
|
|
|
@@ -2158,7 +2340,7 @@ class GlobalStmt(CodeBlockStmt):
|
|
|
2158
2340
|
|
|
2159
2341
|
def __init__(
|
|
2160
2342
|
self,
|
|
2161
|
-
target: SubNodeList[
|
|
2343
|
+
target: SubNodeList[NameAtom],
|
|
2162
2344
|
kid: Sequence[AstNode],
|
|
2163
2345
|
) -> None:
|
|
2164
2346
|
"""Initialize global statement node."""
|
|
@@ -2451,12 +2633,7 @@ class MultiString(AtomExpr):
|
|
|
2451
2633
|
"""Initialize multi string expression node."""
|
|
2452
2634
|
self.strings = strings
|
|
2453
2635
|
AstNode.__init__(self, kid=kid)
|
|
2454
|
-
|
|
2455
|
-
self,
|
|
2456
|
-
sym_name=f"[{self.__class__.__name__}]",
|
|
2457
|
-
sym_name_node=self,
|
|
2458
|
-
sym_type=SymbolType.STRING,
|
|
2459
|
-
)
|
|
2636
|
+
AstSymbolStubNode.__init__(self, sym_type=SymbolType.STRING)
|
|
2460
2637
|
|
|
2461
2638
|
def normalize(self, deep: bool = False) -> bool:
|
|
2462
2639
|
"""Normalize ast node."""
|
|
@@ -2482,12 +2659,7 @@ class FString(AtomExpr):
|
|
|
2482
2659
|
"""Initialize fstring expression node."""
|
|
2483
2660
|
self.parts = parts
|
|
2484
2661
|
AstNode.__init__(self, kid=kid)
|
|
2485
|
-
|
|
2486
|
-
self,
|
|
2487
|
-
sym_name=f"[{self.__class__.__name__}]",
|
|
2488
|
-
sym_name_node=self,
|
|
2489
|
-
sym_type=SymbolType.STRING,
|
|
2490
|
-
)
|
|
2662
|
+
AstSymbolStubNode.__init__(self, sym_type=SymbolType.STRING)
|
|
2491
2663
|
|
|
2492
2664
|
def normalize(self, deep: bool = False) -> bool:
|
|
2493
2665
|
"""Normalize ast node."""
|
|
@@ -2517,12 +2689,7 @@ class ListVal(AtomExpr):
|
|
|
2517
2689
|
"""Initialize value node."""
|
|
2518
2690
|
self.values = values
|
|
2519
2691
|
AstNode.__init__(self, kid=kid)
|
|
2520
|
-
|
|
2521
|
-
self,
|
|
2522
|
-
sym_name=f"[{self.__class__.__name__}]",
|
|
2523
|
-
sym_name_node=self,
|
|
2524
|
-
sym_type=SymbolType.SEQUENCE,
|
|
2525
|
-
)
|
|
2692
|
+
AstSymbolStubNode.__init__(self, sym_type=SymbolType.SEQUENCE)
|
|
2526
2693
|
|
|
2527
2694
|
def normalize(self, deep: bool = False) -> bool:
|
|
2528
2695
|
"""Normalize ast node."""
|
|
@@ -2550,12 +2717,7 @@ class SetVal(AtomExpr):
|
|
|
2550
2717
|
"""Initialize value node."""
|
|
2551
2718
|
self.values = values
|
|
2552
2719
|
AstNode.__init__(self, kid=kid)
|
|
2553
|
-
|
|
2554
|
-
self,
|
|
2555
|
-
sym_name=f"[{self.__class__.__name__}]",
|
|
2556
|
-
sym_name_node=self,
|
|
2557
|
-
sym_type=SymbolType.SEQUENCE,
|
|
2558
|
-
)
|
|
2720
|
+
AstSymbolStubNode.__init__(self, sym_type=SymbolType.SEQUENCE)
|
|
2559
2721
|
|
|
2560
2722
|
def normalize(self, deep: bool = False) -> bool:
|
|
2561
2723
|
"""Normalize ast node."""
|
|
@@ -2583,12 +2745,7 @@ class TupleVal(AtomExpr):
|
|
|
2583
2745
|
"""Initialize tuple value node."""
|
|
2584
2746
|
self.values = values
|
|
2585
2747
|
AstNode.__init__(self, kid=kid)
|
|
2586
|
-
|
|
2587
|
-
self,
|
|
2588
|
-
sym_name=f"[{self.__class__.__name__}]",
|
|
2589
|
-
sym_name_node=self,
|
|
2590
|
-
sym_type=SymbolType.SEQUENCE,
|
|
2591
|
-
)
|
|
2748
|
+
AstSymbolStubNode.__init__(self, sym_type=SymbolType.SEQUENCE)
|
|
2592
2749
|
|
|
2593
2750
|
def normalize(self, deep: bool = False) -> bool:
|
|
2594
2751
|
"""Normalize ast node."""
|
|
@@ -2631,12 +2788,7 @@ class DictVal(AtomExpr):
|
|
|
2631
2788
|
"""Initialize dict expression node."""
|
|
2632
2789
|
self.kv_pairs = kv_pairs
|
|
2633
2790
|
AstNode.__init__(self, kid=kid)
|
|
2634
|
-
|
|
2635
|
-
self,
|
|
2636
|
-
sym_name=f"[{self.__class__.__name__}]",
|
|
2637
|
-
sym_name_node=self,
|
|
2638
|
-
sym_type=SymbolType.SEQUENCE,
|
|
2639
|
-
)
|
|
2791
|
+
AstSymbolStubNode.__init__(self, sym_type=SymbolType.SEQUENCE)
|
|
2640
2792
|
|
|
2641
2793
|
def normalize(self, deep: bool = False) -> bool:
|
|
2642
2794
|
"""Normalize ast node."""
|
|
@@ -2692,7 +2844,7 @@ class KWPair(AstNode):
|
|
|
2692
2844
|
|
|
2693
2845
|
def __init__(
|
|
2694
2846
|
self,
|
|
2695
|
-
key: Optional[
|
|
2847
|
+
key: Optional[NameAtom], # is **value if blank
|
|
2696
2848
|
value: Expr,
|
|
2697
2849
|
kid: Sequence[AstNode],
|
|
2698
2850
|
) -> None:
|
|
@@ -2769,12 +2921,7 @@ class ListCompr(AtomExpr):
|
|
|
2769
2921
|
self.out_expr = out_expr
|
|
2770
2922
|
self.compr = compr
|
|
2771
2923
|
AstNode.__init__(self, kid=kid)
|
|
2772
|
-
|
|
2773
|
-
self,
|
|
2774
|
-
sym_name=f"[{self.__class__.__name__}]",
|
|
2775
|
-
sym_name_node=self,
|
|
2776
|
-
sym_type=SymbolType.SEQUENCE,
|
|
2777
|
-
)
|
|
2924
|
+
AstSymbolStubNode.__init__(self, sym_type=SymbolType.SEQUENCE)
|
|
2778
2925
|
|
|
2779
2926
|
def normalize(self, deep: bool = False) -> bool:
|
|
2780
2927
|
"""Normalize ast node."""
|
|
@@ -2849,12 +2996,7 @@ class DictCompr(AtomExpr):
|
|
|
2849
2996
|
self.kv_pair = kv_pair
|
|
2850
2997
|
self.compr = compr
|
|
2851
2998
|
AstNode.__init__(self, kid=kid)
|
|
2852
|
-
|
|
2853
|
-
self,
|
|
2854
|
-
sym_name=f"[{self.__class__.__name__}]",
|
|
2855
|
-
sym_name_node=self,
|
|
2856
|
-
sym_type=SymbolType.SEQUENCE,
|
|
2857
|
-
)
|
|
2999
|
+
AstSymbolStubNode.__init__(self, sym_type=SymbolType.SEQUENCE)
|
|
2858
3000
|
|
|
2859
3001
|
def normalize(self, deep: bool = False) -> bool:
|
|
2860
3002
|
"""Normalize ast node."""
|
|
@@ -3013,12 +3155,7 @@ class IndexSlice(AtomExpr):
|
|
|
3013
3155
|
self.step = step
|
|
3014
3156
|
self.is_range = is_range
|
|
3015
3157
|
AstNode.__init__(self, kid=kid)
|
|
3016
|
-
|
|
3017
|
-
self,
|
|
3018
|
-
sym_name=f"[{self.__class__.__name__}]",
|
|
3019
|
-
sym_type=SymbolType.SEQUENCE,
|
|
3020
|
-
sym_name_node=self,
|
|
3021
|
-
)
|
|
3158
|
+
AstSymbolStubNode.__init__(self, sym_type=SymbolType.SEQUENCE)
|
|
3022
3159
|
|
|
3023
3160
|
def normalize(self, deep: bool = True) -> bool:
|
|
3024
3161
|
"""Normalize ast node."""
|
|
@@ -3047,89 +3184,35 @@ class IndexSlice(AtomExpr):
|
|
|
3047
3184
|
return res
|
|
3048
3185
|
|
|
3049
3186
|
|
|
3050
|
-
class ArchRef(
|
|
3187
|
+
class ArchRef(AtomExpr):
|
|
3051
3188
|
"""ArchRef node type for Jac Ast."""
|
|
3052
3189
|
|
|
3053
3190
|
def __init__(
|
|
3054
3191
|
self,
|
|
3055
|
-
|
|
3056
|
-
|
|
3192
|
+
arch_name: NameAtom,
|
|
3193
|
+
arch_type: Token,
|
|
3057
3194
|
kid: Sequence[AstNode],
|
|
3058
3195
|
) -> None:
|
|
3059
3196
|
"""Initialize architype reference expression node."""
|
|
3060
|
-
self.
|
|
3061
|
-
self.
|
|
3062
|
-
AstNode.__init__(self, kid=kid)
|
|
3063
|
-
AstSymbolNode.__init__(
|
|
3064
|
-
self,
|
|
3065
|
-
sym_name=self.py_resolve_name(),
|
|
3066
|
-
sym_name_node=name_ref,
|
|
3067
|
-
sym_type=SymbolType.TYPE,
|
|
3068
|
-
)
|
|
3069
|
-
|
|
3070
|
-
def normalize(self, deep: bool = False) -> bool:
|
|
3071
|
-
"""Normalize ast node."""
|
|
3072
|
-
res = True
|
|
3073
|
-
if deep:
|
|
3074
|
-
res = self.name_ref.normalize(deep)
|
|
3075
|
-
new_kid: list[AstNode] = [self.arch, self.name_ref]
|
|
3076
|
-
self.set_kids(nodes=new_kid)
|
|
3077
|
-
return res
|
|
3078
|
-
|
|
3079
|
-
def py_resolve_name(self) -> str:
|
|
3080
|
-
"""Resolve name."""
|
|
3081
|
-
if isinstance(self.name_ref, Name):
|
|
3082
|
-
return self.name_ref.value
|
|
3083
|
-
elif isinstance(self.name_ref, SpecialVarRef):
|
|
3084
|
-
return self.name_ref.py_resolve_name()
|
|
3085
|
-
else:
|
|
3086
|
-
raise NotImplementedError
|
|
3087
|
-
|
|
3088
|
-
|
|
3089
|
-
class SpecialVarRef(NameSpec):
|
|
3090
|
-
"""HereRef node type for Jac Ast."""
|
|
3091
|
-
|
|
3092
|
-
def __init__(
|
|
3093
|
-
self,
|
|
3094
|
-
var: Token,
|
|
3095
|
-
kid: Sequence[AstNode],
|
|
3096
|
-
) -> None:
|
|
3097
|
-
"""Initialize special var reference expression node."""
|
|
3098
|
-
self.var = var
|
|
3197
|
+
self.arch_name = arch_name
|
|
3198
|
+
self.arch_type = arch_type
|
|
3099
3199
|
AstNode.__init__(self, kid=kid)
|
|
3100
3200
|
AstSymbolNode.__init__(
|
|
3101
3201
|
self,
|
|
3102
|
-
sym_name=
|
|
3103
|
-
|
|
3104
|
-
|
|
3202
|
+
sym_name=arch_name.sym_name,
|
|
3203
|
+
name_spec=arch_name,
|
|
3204
|
+
sym_category=SymbolType.TYPE,
|
|
3105
3205
|
)
|
|
3106
3206
|
|
|
3107
3207
|
def normalize(self, deep: bool = False) -> bool:
|
|
3108
3208
|
"""Normalize ast node."""
|
|
3109
3209
|
res = True
|
|
3110
3210
|
if deep:
|
|
3111
|
-
res = self.
|
|
3112
|
-
new_kid: list[AstNode] = [self.
|
|
3211
|
+
res = self.arch_name.normalize(deep)
|
|
3212
|
+
new_kid: list[AstNode] = [self.arch_type, self.arch_name]
|
|
3113
3213
|
self.set_kids(nodes=new_kid)
|
|
3114
3214
|
return res
|
|
3115
3215
|
|
|
3116
|
-
def py_resolve_name(self) -> str:
|
|
3117
|
-
"""Resolve name."""
|
|
3118
|
-
if self.var.name == Tok.KW_SELF:
|
|
3119
|
-
return "self"
|
|
3120
|
-
elif self.var.name == Tok.KW_SUPER:
|
|
3121
|
-
return "super()"
|
|
3122
|
-
elif self.var.name == Tok.KW_ROOT:
|
|
3123
|
-
return Con.ROOT.value
|
|
3124
|
-
elif self.var.name == Tok.KW_HERE:
|
|
3125
|
-
return Con.HERE.value
|
|
3126
|
-
elif self.var.name == Tok.KW_INIT:
|
|
3127
|
-
return "__init__"
|
|
3128
|
-
elif self.var.name == Tok.KW_POST_INIT:
|
|
3129
|
-
return "__post_init__"
|
|
3130
|
-
else:
|
|
3131
|
-
raise NotImplementedError("ICE: Special var reference not implemented")
|
|
3132
|
-
|
|
3133
3216
|
|
|
3134
3217
|
class EdgeRefTrailer(Expr):
|
|
3135
3218
|
"""EdgeRefTrailer node type for Jac Ast."""
|
|
@@ -3174,12 +3257,7 @@ class EdgeOpRef(WalkerStmtOnlyNode, AtomExpr):
|
|
|
3174
3257
|
self.edge_dir = edge_dir
|
|
3175
3258
|
AstNode.__init__(self, kid=kid)
|
|
3176
3259
|
WalkerStmtOnlyNode.__init__(self)
|
|
3177
|
-
|
|
3178
|
-
self,
|
|
3179
|
-
sym_name=f"[{self.__class__.__name__}]",
|
|
3180
|
-
sym_name_node=self,
|
|
3181
|
-
sym_type=SymbolType.SEQUENCE,
|
|
3182
|
-
)
|
|
3260
|
+
AstSymbolStubNode.__init__(self, sym_type=SymbolType.SEQUENCE)
|
|
3183
3261
|
|
|
3184
3262
|
def normalize(self, deep: bool = False) -> bool:
|
|
3185
3263
|
"""Normalize ast node."""
|
|
@@ -3308,12 +3386,7 @@ class FilterCompr(AtomExpr):
|
|
|
3308
3386
|
self.f_type = f_type
|
|
3309
3387
|
self.compares = compares
|
|
3310
3388
|
AstNode.__init__(self, kid=kid)
|
|
3311
|
-
|
|
3312
|
-
self,
|
|
3313
|
-
sym_name=f"[{self.__class__.__name__}]",
|
|
3314
|
-
sym_name_node=self,
|
|
3315
|
-
sym_type=SymbolType.SEQUENCE,
|
|
3316
|
-
)
|
|
3389
|
+
AstSymbolStubNode.__init__(self, sym_type=SymbolType.SEQUENCE)
|
|
3317
3390
|
|
|
3318
3391
|
def normalize(self, deep: bool = False) -> bool:
|
|
3319
3392
|
"""Normalize ast node."""
|
|
@@ -3350,12 +3423,7 @@ class AssignCompr(AtomExpr):
|
|
|
3350
3423
|
"""Initialize assign compr expression node."""
|
|
3351
3424
|
self.assigns = assigns
|
|
3352
3425
|
AstNode.__init__(self, kid=kid)
|
|
3353
|
-
|
|
3354
|
-
self,
|
|
3355
|
-
sym_name=f"[{self.__class__.__name__}]",
|
|
3356
|
-
sym_name_node=self,
|
|
3357
|
-
sym_type=SymbolType.SEQUENCE,
|
|
3358
|
-
)
|
|
3426
|
+
AstSymbolStubNode.__init__(self, sym_type=SymbolType.SEQUENCE)
|
|
3359
3427
|
|
|
3360
3428
|
def normalize(self, deep: bool = False) -> bool:
|
|
3361
3429
|
"""Normalize ast node."""
|
|
@@ -3479,7 +3547,7 @@ class MatchAs(MatchPattern):
|
|
|
3479
3547
|
|
|
3480
3548
|
def __init__(
|
|
3481
3549
|
self,
|
|
3482
|
-
name:
|
|
3550
|
+
name: NameAtom,
|
|
3483
3551
|
pattern: Optional[MatchPattern],
|
|
3484
3552
|
kid: Sequence[AstNode],
|
|
3485
3553
|
) -> None:
|
|
@@ -3518,6 +3586,7 @@ class MatchWild(MatchPattern):
|
|
|
3518
3586
|
col_start=self.loc.col_start,
|
|
3519
3587
|
col_end=self.loc.col_end,
|
|
3520
3588
|
line=self.loc.first_line,
|
|
3589
|
+
end_line=self.loc.last_line,
|
|
3521
3590
|
pos_start=self.loc.pos_start,
|
|
3522
3591
|
pos_end=self.loc.pos_end,
|
|
3523
3592
|
)
|
|
@@ -3627,7 +3696,7 @@ class MatchKVPair(MatchPattern):
|
|
|
3627
3696
|
|
|
3628
3697
|
def __init__(
|
|
3629
3698
|
self,
|
|
3630
|
-
key: MatchPattern |
|
|
3699
|
+
key: MatchPattern | NameAtom,
|
|
3631
3700
|
value: MatchPattern,
|
|
3632
3701
|
kid: Sequence[AstNode],
|
|
3633
3702
|
) -> None:
|
|
@@ -3655,7 +3724,7 @@ class MatchStar(MatchPattern):
|
|
|
3655
3724
|
|
|
3656
3725
|
def __init__(
|
|
3657
3726
|
self,
|
|
3658
|
-
name:
|
|
3727
|
+
name: NameAtom,
|
|
3659
3728
|
is_list: bool,
|
|
3660
3729
|
kid: Sequence[AstNode],
|
|
3661
3730
|
) -> None:
|
|
@@ -3682,7 +3751,7 @@ class MatchArch(MatchPattern):
|
|
|
3682
3751
|
|
|
3683
3752
|
def __init__(
|
|
3684
3753
|
self,
|
|
3685
|
-
name: AtomTrailer |
|
|
3754
|
+
name: AtomTrailer | NameAtom,
|
|
3686
3755
|
arg_patterns: Optional[SubNodeList[MatchPattern]],
|
|
3687
3756
|
kw_patterns: Optional[SubNodeList[MatchKVPair]],
|
|
3688
3757
|
kid: Sequence[AstNode],
|
|
@@ -3725,6 +3794,7 @@ class Token(AstNode):
|
|
|
3725
3794
|
name: str,
|
|
3726
3795
|
value: str,
|
|
3727
3796
|
line: int,
|
|
3797
|
+
end_line: int,
|
|
3728
3798
|
col_start: int,
|
|
3729
3799
|
col_end: int,
|
|
3730
3800
|
pos_start: int,
|
|
@@ -3735,6 +3805,7 @@ class Token(AstNode):
|
|
|
3735
3805
|
self.name = name
|
|
3736
3806
|
self.value = value
|
|
3737
3807
|
self.line_no = line
|
|
3808
|
+
self.end_line = end_line
|
|
3738
3809
|
self.c_start = col_start
|
|
3739
3810
|
self.c_end = col_end
|
|
3740
3811
|
self.pos_start = pos_start
|
|
@@ -3750,7 +3821,7 @@ class Token(AstNode):
|
|
|
3750
3821
|
return self.value
|
|
3751
3822
|
|
|
3752
3823
|
|
|
3753
|
-
class Name(Token,
|
|
3824
|
+
class Name(Token, NameAtom):
|
|
3754
3825
|
"""Name node type for Jac Ast."""
|
|
3755
3826
|
|
|
3756
3827
|
def __init__(
|
|
@@ -3759,6 +3830,7 @@ class Name(Token, NameSpec):
|
|
|
3759
3830
|
name: str,
|
|
3760
3831
|
value: str,
|
|
3761
3832
|
line: int,
|
|
3833
|
+
end_line: int,
|
|
3762
3834
|
col_start: int,
|
|
3763
3835
|
col_end: int,
|
|
3764
3836
|
pos_start: int,
|
|
@@ -3775,16 +3847,18 @@ class Name(Token, NameSpec):
|
|
|
3775
3847
|
name=name,
|
|
3776
3848
|
value=value,
|
|
3777
3849
|
line=line,
|
|
3850
|
+
end_line=end_line,
|
|
3778
3851
|
col_start=col_start,
|
|
3779
3852
|
col_end=col_end,
|
|
3780
3853
|
pos_start=pos_start,
|
|
3781
3854
|
pos_end=pos_end,
|
|
3782
3855
|
)
|
|
3856
|
+
NameAtom.__init__(self)
|
|
3783
3857
|
AstSymbolNode.__init__(
|
|
3784
3858
|
self,
|
|
3785
3859
|
sym_name=value,
|
|
3786
|
-
|
|
3787
|
-
|
|
3860
|
+
name_spec=self,
|
|
3861
|
+
sym_category=SymbolType.VAR,
|
|
3788
3862
|
)
|
|
3789
3863
|
|
|
3790
3864
|
def unparse(self) -> str:
|
|
@@ -3794,6 +3868,71 @@ class Name(Token, NameSpec):
|
|
|
3794
3868
|
",\n" if self.is_enum_singleton else ""
|
|
3795
3869
|
)
|
|
3796
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
|
+
|
|
3797
3936
|
|
|
3798
3937
|
class Literal(Token, AtomExpr):
|
|
3799
3938
|
"""Literal node type for Jac Ast."""
|
|
@@ -3819,6 +3958,7 @@ class Literal(Token, AtomExpr):
|
|
|
3819
3958
|
name: str,
|
|
3820
3959
|
value: str,
|
|
3821
3960
|
line: int,
|
|
3961
|
+
end_line: int,
|
|
3822
3962
|
col_start: int,
|
|
3823
3963
|
col_end: int,
|
|
3824
3964
|
pos_start: int,
|
|
@@ -3831,17 +3971,13 @@ class Literal(Token, AtomExpr):
|
|
|
3831
3971
|
name=name,
|
|
3832
3972
|
value=value,
|
|
3833
3973
|
line=line,
|
|
3974
|
+
end_line=end_line,
|
|
3834
3975
|
col_start=col_start,
|
|
3835
3976
|
col_end=col_end,
|
|
3836
3977
|
pos_start=pos_start,
|
|
3837
3978
|
pos_end=pos_end,
|
|
3838
3979
|
)
|
|
3839
|
-
|
|
3840
|
-
self,
|
|
3841
|
-
sym_name=f"[{self.__class__.__name__}]",
|
|
3842
|
-
sym_name_node=self,
|
|
3843
|
-
sym_type=self.SYMBOL_TYPE,
|
|
3844
|
-
)
|
|
3980
|
+
AstSymbolStubNode.__init__(self, sym_type=self.SYMBOL_TYPE)
|
|
3845
3981
|
|
|
3846
3982
|
@property
|
|
3847
3983
|
def lit_value(
|
|
@@ -3851,43 +3987,7 @@ class Literal(Token, AtomExpr):
|
|
|
3851
3987
|
raise NotImplementedError
|
|
3852
3988
|
|
|
3853
3989
|
|
|
3854
|
-
class
|
|
3855
|
-
"""TokenSymbol node type for Jac Ast."""
|
|
3856
|
-
|
|
3857
|
-
SYMBOL_TYPE = SymbolType.VAR
|
|
3858
|
-
|
|
3859
|
-
def __init__(
|
|
3860
|
-
self,
|
|
3861
|
-
file_path: str,
|
|
3862
|
-
name: str,
|
|
3863
|
-
value: str,
|
|
3864
|
-
line: int,
|
|
3865
|
-
col_start: int,
|
|
3866
|
-
col_end: int,
|
|
3867
|
-
pos_start: int,
|
|
3868
|
-
pos_end: int,
|
|
3869
|
-
) -> None:
|
|
3870
|
-
"""Initialize token."""
|
|
3871
|
-
Token.__init__(
|
|
3872
|
-
self,
|
|
3873
|
-
file_path=file_path,
|
|
3874
|
-
name=name,
|
|
3875
|
-
value=value,
|
|
3876
|
-
line=line,
|
|
3877
|
-
col_start=col_start,
|
|
3878
|
-
col_end=col_end,
|
|
3879
|
-
pos_start=pos_start,
|
|
3880
|
-
pos_end=pos_end,
|
|
3881
|
-
)
|
|
3882
|
-
AstSymbolNode.__init__(
|
|
3883
|
-
self,
|
|
3884
|
-
sym_name=f"[{self.__class__.__name__}]",
|
|
3885
|
-
sym_name_node=self,
|
|
3886
|
-
sym_type=self.SYMBOL_TYPE,
|
|
3887
|
-
)
|
|
3888
|
-
|
|
3889
|
-
|
|
3890
|
-
class BuiltinType(Name, Literal, NameSpec):
|
|
3990
|
+
class BuiltinType(Name, Literal, NameAtom):
|
|
3891
3991
|
"""Type node type for Jac Ast."""
|
|
3892
3992
|
|
|
3893
3993
|
SYMBOL_TYPE = SymbolType.VAR
|
|
@@ -4000,6 +4100,7 @@ class EmptyToken(Token):
|
|
|
4000
4100
|
file_path="",
|
|
4001
4101
|
value="",
|
|
4002
4102
|
line=0,
|
|
4103
|
+
end_line=0,
|
|
4003
4104
|
col_start=0,
|
|
4004
4105
|
col_end=0,
|
|
4005
4106
|
pos_start=0,
|